Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

356 lines
12 KiB

  1. /*++ BUILD Version: 0001 // Increment this if a change has global effects
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. pebteb.w
  5. Abstract:
  6. Declarations of PEB and TEB, and some types contained in them.
  7. Address the maintenance problem that resulted from PEB and TEB being
  8. defined three times, once "native" in ntpsapi.w, and twice, 32bit and 64bit
  9. in wow64t.w.
  10. Author:
  11. Jay Krell (JayKrell) April 2001
  12. Revision History:
  13. --*/
  14. //
  15. // This file deliberately lacks #pragma once or #ifndef guards.
  16. // It is only included by ntpsapi.h and wow64t.h, never directly.
  17. //
  18. //
  19. // This file is #included three times.
  20. //
  21. // 1) by ntpsapi.h, with no "unusual" macros defined, to declare
  22. // PEB and TEB, and some types contained in them
  23. // 2) by wow64t.h to declare PEB32 and TEB32, and some types contained in them
  24. // 3) by wow64t.h to declare PEB64 and TEB64, and some types contained in them
  25. //
  26. // wow64t.h #defines the macro PEBTEB_BITS to guide the declarations.
  27. //
  28. #define PEBTEB_PRIVATE_PASTE(x,y) x##y
  29. #define PEBTEB_PASTE(x,y) PEBTEB_PRIVATE_PASTE(x,y)
  30. #if defined(PEBTEB_BITS) /* This is defined by wow64t.h. */
  31. #if PEBTEB_BITS == 32
  32. #define PEBTEB_STRUCT(x) PEBTEB_PASTE(x, 32) /* FOO32 */
  33. #define PEBTEB_POINTER(x) TYPE32(x) /* ULONG, defined in wow64t.h */
  34. #elif PEBTEB_BITS == 64
  35. #define PEBTEB_STRUCT(x) PEBTEB_PASTE(x, 64) /* FOO64 */
  36. #define PEBTEB_POINTER(x) TYPE64(x) /* ULONGLONG, defined in wow64t.h */
  37. #else
  38. #error Unknown value for pebteb_bits (PEBTEB_BITS).
  39. #endif
  40. #else
  41. //
  42. // Declare and use regular native types.
  43. //
  44. #define PEBTEB_POINTER(x) x
  45. #define PEBTEB_STRUCT(x) x
  46. #endif
  47. /* for searching
  48. typedef struct _PEB
  49. typedef struct _PEB32
  50. typedef struct _PEB64
  51. */
  52. typedef struct PEBTEB_STRUCT(_PEB) {
  53. BOOLEAN InheritedAddressSpace; // These four fields cannot change unless the
  54. BOOLEAN ReadImageFileExecOptions; //
  55. BOOLEAN BeingDebugged; //
  56. BOOLEAN SpareBool; //
  57. PEBTEB_POINTER(HANDLE) Mutant; // INITIAL_PEB structure is also updated.
  58. PEBTEB_POINTER(PVOID) ImageBaseAddress;
  59. PEBTEB_POINTER(PPEB_LDR_DATA) Ldr;
  60. PEBTEB_POINTER(struct _RTL_USER_PROCESS_PARAMETERS*) ProcessParameters;
  61. PEBTEB_POINTER(PVOID) SubSystemData;
  62. PEBTEB_POINTER(PVOID) ProcessHeap;
  63. PEBTEB_POINTER(struct _RTL_CRITICAL_SECTION*) FastPebLock;
  64. PEBTEB_POINTER(PVOID) SparePtr1;
  65. PEBTEB_POINTER(PVOID) SparePtr2;
  66. ULONG EnvironmentUpdateCount;
  67. PEBTEB_POINTER(PVOID) KernelCallbackTable;
  68. ULONG SystemReserved[1];
  69. struct {
  70. ULONG ExecuteOptions : 2;
  71. ULONG SpareBits : 30;
  72. };
  73. PEBTEB_POINTER(PPEB_FREE_BLOCK) FreeList;
  74. ULONG TlsExpansionCounter;
  75. PEBTEB_POINTER(PVOID) TlsBitmap;
  76. ULONG TlsBitmapBits[2]; // TLS_MINIMUM_AVAILABLE bits
  77. PEBTEB_POINTER(PVOID) ReadOnlySharedMemoryBase;
  78. PEBTEB_POINTER(PVOID) ReadOnlySharedMemoryHeap;
  79. PEBTEB_POINTER(PPVOID) ReadOnlyStaticServerData;
  80. PEBTEB_POINTER(PVOID) AnsiCodePageData;
  81. PEBTEB_POINTER(PVOID) OemCodePageData;
  82. PEBTEB_POINTER(PVOID) UnicodeCaseTableData;
  83. //
  84. // Useful information for LdrpInitialize
  85. ULONG NumberOfProcessors;
  86. ULONG NtGlobalFlag;
  87. //
  88. // Passed up from MmCreatePeb from Session Manager registry key
  89. //
  90. LARGE_INTEGER CriticalSectionTimeout;
  91. PEBTEB_POINTER(SIZE_T) HeapSegmentReserve;
  92. PEBTEB_POINTER(SIZE_T) HeapSegmentCommit;
  93. PEBTEB_POINTER(SIZE_T) HeapDeCommitTotalFreeThreshold;
  94. PEBTEB_POINTER(SIZE_T) HeapDeCommitFreeBlockThreshold;
  95. //
  96. // Where heap manager keeps track of all heaps created for a process
  97. // Fields initialized by MmCreatePeb. ProcessHeaps is initialized
  98. // to point to the first free byte after the PEB and MaximumNumberOfHeaps
  99. // is computed from the page size used to hold the PEB, less the fixed
  100. // size of this data structure.
  101. //
  102. ULONG NumberOfHeaps;
  103. ULONG MaximumNumberOfHeaps;
  104. PEBTEB_POINTER(PPVOID) ProcessHeaps;
  105. //
  106. //
  107. PEBTEB_POINTER(PVOID) GdiSharedHandleTable;
  108. PEBTEB_POINTER(PVOID) ProcessStarterHelper;
  109. ULONG GdiDCAttributeList;
  110. PEBTEB_POINTER(struct _RTL_CRITICAL_SECTION*) LoaderLock;
  111. //
  112. // Following fields filled in by MmCreatePeb from system values and/or
  113. // image header.
  114. //
  115. ULONG OSMajorVersion;
  116. ULONG OSMinorVersion;
  117. USHORT OSBuildNumber;
  118. USHORT OSCSDVersion;
  119. ULONG OSPlatformId;
  120. ULONG ImageSubsystem;
  121. ULONG ImageSubsystemMajorVersion;
  122. ULONG ImageSubsystemMinorVersion;
  123. PEBTEB_POINTER(ULONG_PTR) ImageProcessAffinityMask;
  124. PEBTEB_STRUCT(GDI_HANDLE_BUFFER) GdiHandleBuffer;
  125. PEBTEB_POINTER(PPS_POST_PROCESS_INIT_ROUTINE) PostProcessInitRoutine;
  126. PEBTEB_POINTER(PVOID) TlsExpansionBitmap;
  127. ULONG TlsExpansionBitmapBits[32]; // TLS_EXPANSION_SLOTS bits
  128. //
  129. // Id of the Hydra session in which this process is running
  130. //
  131. ULONG SessionId;
  132. //
  133. // Filled in by LdrpInstallAppcompatBackend
  134. //
  135. ULARGE_INTEGER AppCompatFlags;
  136. //
  137. // ntuser appcompat flags
  138. //
  139. ULARGE_INTEGER AppCompatFlagsUser;
  140. //
  141. // Filled in by LdrpInstallAppcompatBackend
  142. //
  143. PEBTEB_POINTER(PVOID) pShimData;
  144. //
  145. // Filled in by LdrQueryImageFileExecutionOptions
  146. //
  147. PEBTEB_POINTER(PVOID) AppCompatInfo;
  148. //
  149. // Used by GetVersionExW as the szCSDVersion string
  150. //
  151. PEBTEB_STRUCT(UNICODE_STRING) CSDVersion;
  152. //
  153. // Fusion stuff
  154. //
  155. PEBTEB_POINTER(const struct _ACTIVATION_CONTEXT_DATA *) ActivationContextData;
  156. PEBTEB_POINTER(struct _ASSEMBLY_STORAGE_MAP *) ProcessAssemblyStorageMap;
  157. PEBTEB_POINTER(const struct _ACTIVATION_CONTEXT_DATA *) SystemDefaultActivationContextData;
  158. PEBTEB_POINTER(struct _ASSEMBLY_STORAGE_MAP *) SystemAssemblyStorageMap;
  159. //
  160. // Enforced minimum initial commit stack
  161. //
  162. PEBTEB_POINTER(SIZE_T) MinimumStackCommit;
  163. //
  164. // Fiber local storage.
  165. //
  166. PEBTEB_POINTER(PPVOID) FlsCallback;
  167. PEBTEB_STRUCT(LIST_ENTRY) FlsListHead;
  168. PEBTEB_POINTER(PVOID) FlsBitmap;
  169. ULONG FlsBitmapBits[FLS_MAXIMUM_AVAILABLE / (sizeof(ULONG) * 8)];
  170. ULONG FlsHighIndex;
  171. } PEBTEB_STRUCT(PEB), * PEBTEB_STRUCT(PPEB);
  172. //
  173. // Fusion/sxs thread state information
  174. //
  175. #define ACTIVATION_CONTEXT_STACK_FLAG_QUERIES_DISABLED (0x00000001)
  176. typedef struct PEBTEB_STRUCT(_ACTIVATION_CONTEXT_STACK) {
  177. ULONG Flags;
  178. ULONG NextCookieSequenceNumber;
  179. PEBTEB_POINTER(struct _RTL_ACTIVATION_CONTEXT_STACK_FRAME *) ActiveFrame;
  180. PEBTEB_STRUCT(LIST_ENTRY) FrameListCache;
  181. } PEBTEB_STRUCT(ACTIVATION_CONTEXT_STACK), * PEBTEB_STRUCT(PACTIVATION_CONTEXT_STACK);
  182. typedef const PEBTEB_STRUCT(ACTIVATION_CONTEXT_STACK) * PEBTEB_STRUCT(PCACTIVATION_CONTEXT_STACK);
  183. #define TEB_ACTIVE_FRAME_CONTEXT_FLAG_EXTENDED (0x00000001)
  184. typedef struct PEBTEB_STRUCT(_TEB_ACTIVE_FRAME_CONTEXT) {
  185. ULONG Flags;
  186. PEBTEB_POINTER(PCSTR) FrameName;
  187. } PEBTEB_STRUCT(TEB_ACTIVE_FRAME_CONTEXT), *PEBTEB_STRUCT(PTEB_ACTIVE_FRAME_CONTEXT);
  188. typedef const PEBTEB_STRUCT(TEB_ACTIVE_FRAME_CONTEXT) *PEBTEB_STRUCT(PCTEB_ACTIVE_FRAME_CONTEXT);
  189. typedef struct PEBTEB_STRUCT(_TEB_ACTIVE_FRAME_CONTEXT_EX) {
  190. PEBTEB_STRUCT(TEB_ACTIVE_FRAME_CONTEXT) BasicContext;
  191. PEBTEB_POINTER(PCSTR) SourceLocation; // e.g. "Z:\foo\bar\baz.c"
  192. } PEBTEB_STRUCT(TEB_ACTIVE_FRAME_CONTEXT_EX), *PEBTEB_STRUCT(PTEB_ACTIVE_FRAME_CONTEXT_EX);
  193. typedef const PEBTEB_STRUCT(TEB_ACTIVE_FRAME_CONTEXT_EX) *PEBTEB_STRUCT(PCTEB_ACTIVE_FRAME_CONTEXT_EX);
  194. #define TEB_ACTIVE_FRAME_FLAG_EXTENDED (0x00000001)
  195. typedef struct PEBTEB_STRUCT(_TEB_ACTIVE_FRAME) {
  196. ULONG Flags;
  197. PEBTEB_POINTER(struct _TEB_ACTIVE_FRAME*) Previous;
  198. PEBTEB_POINTER(PCTEB_ACTIVE_FRAME_CONTEXT) Context;
  199. } PEBTEB_STRUCT(TEB_ACTIVE_FRAME), *PEBTEB_STRUCT(PTEB_ACTIVE_FRAME);
  200. typedef const PEBTEB_STRUCT(TEB_ACTIVE_FRAME) *PEBTEB_STRUCT(PCTEB_ACTIVE_FRAME);
  201. typedef struct PEBTEB_STRUCT(_TEB_ACTIVE_FRAME_EX) {
  202. PEBTEB_STRUCT(TEB_ACTIVE_FRAME) BasicFrame;
  203. PEBTEB_POINTER(PVOID) ExtensionIdentifier; // use address of your DLL Main or something unique to your mapping in the address space
  204. } PEBTEB_STRUCT(TEB_ACTIVE_FRAME_EX), *PEBTEB_STRUCT(PTEB_ACTIVE_FRAME_EX);
  205. typedef const PEBTEB_STRUCT(TEB_ACTIVE_FRAME_EX) *PEBTEB_STRUCT(PCTEB_ACTIVE_FRAME_EX);
  206. /* for searching
  207. typedef struct _TEB
  208. typedef struct _TEB32
  209. typedef struct _TEB64
  210. */
  211. typedef struct PEBTEB_STRUCT(_TEB) {
  212. PEBTEB_STRUCT(NT_TIB) NtTib;
  213. PEBTEB_POINTER(PVOID) EnvironmentPointer;
  214. PEBTEB_STRUCT(CLIENT_ID) ClientId;
  215. PEBTEB_POINTER(PVOID) ActiveRpcHandle;
  216. PEBTEB_POINTER(PVOID) ThreadLocalStoragePointer;
  217. PEBTEB_POINTER(PPEB) ProcessEnvironmentBlock;
  218. ULONG LastErrorValue;
  219. ULONG CountOfOwnedCriticalSections;
  220. PEBTEB_POINTER(PVOID) CsrClientThread;
  221. PEBTEB_POINTER(PVOID) Win32ThreadInfo; // PtiCurrent
  222. ULONG User32Reserved[26]; // user32.dll items
  223. ULONG UserReserved[5]; // Winsrv SwitchStack
  224. PEBTEB_POINTER(PVOID) WOW32Reserved; // used by WOW
  225. LCID CurrentLocale;
  226. ULONG FpSoftwareStatusRegister; // offset known by outsiders!
  227. PEBTEB_POINTER(PVOID) SystemReserved1[54]; // Used by FP emulator
  228. NTSTATUS ExceptionCode; // for RaiseUserException
  229. PEBTEB_STRUCT(ACTIVATION_CONTEXT_STACK) ActivationContextStack; // Fusion activation stack
  230. // sizeof(PEBTEB_POINTER(PVOID)) is a way to express processor-dependence, more generally than #ifdef _WIN64
  231. UCHAR SpareBytes1[48 - sizeof(PEBTEB_POINTER(PVOID)) - sizeof(PEBTEB_STRUCT(ACTIVATION_CONTEXT_STACK))];
  232. PEBTEB_STRUCT(GDI_TEB_BATCH) GdiTebBatch; // Gdi batching
  233. PEBTEB_STRUCT(CLIENT_ID) RealClientId;
  234. PEBTEB_POINTER(HANDLE) GdiCachedProcessHandle;
  235. ULONG GdiClientPID;
  236. ULONG GdiClientTID;
  237. PEBTEB_POINTER(PVOID) GdiThreadLocalInfo;
  238. PEBTEB_POINTER(ULONG_PTR) Win32ClientInfo[WIN32_CLIENT_INFO_LENGTH]; // User32 Client Info
  239. PEBTEB_POINTER(PVOID) glDispatchTable[233]; // OpenGL
  240. PEBTEB_POINTER(ULONG_PTR) glReserved1[29]; // OpenGL
  241. PEBTEB_POINTER(PVOID) glReserved2; // OpenGL
  242. PEBTEB_POINTER(PVOID) glSectionInfo; // OpenGL
  243. PEBTEB_POINTER(PVOID) glSection; // OpenGL
  244. PEBTEB_POINTER(PVOID) glTable; // OpenGL
  245. PEBTEB_POINTER(PVOID) glCurrentRC; // OpenGL
  246. PEBTEB_POINTER(PVOID) glContext; // OpenGL
  247. ULONG LastStatusValue;
  248. PEBTEB_STRUCT(UNICODE_STRING) StaticUnicodeString;
  249. WCHAR StaticUnicodeBuffer[STATIC_UNICODE_BUFFER_LENGTH];
  250. PEBTEB_POINTER(PVOID) DeallocationStack;
  251. PEBTEB_POINTER(PVOID) TlsSlots[TLS_MINIMUM_AVAILABLE];
  252. PEBTEB_STRUCT(LIST_ENTRY) TlsLinks;
  253. PEBTEB_POINTER(PVOID) Vdm;
  254. PEBTEB_POINTER(PVOID) ReservedForNtRpc;
  255. PEBTEB_POINTER(PVOID) DbgSsReserved[2];
  256. ULONG HardErrorMode;
  257. PEBTEB_POINTER(PVOID) Instrumentation[16];
  258. PEBTEB_POINTER(PVOID) WinSockData; // WinSock
  259. ULONG GdiBatchCount;
  260. BOOLEAN InDbgPrint;
  261. BOOLEAN FreeStackOnTermination;
  262. BOOLEAN HasFiberData;
  263. BOOLEAN IdealProcessor;
  264. ULONG Spare3;
  265. PEBTEB_POINTER(PVOID) ReservedForPerf;
  266. PEBTEB_POINTER(PVOID) ReservedForOle;
  267. ULONG WaitingOnLoaderLock;
  268. PEBTEB_STRUCT(WX86THREAD) Wx86Thread;
  269. PEBTEB_POINTER(PPVOID) TlsExpansionSlots;
  270. #if (defined(_WIN64) && !defined(PEBTEB_BITS)) \
  271. || ((defined(_WIN64) || defined(_X86_)) && defined(PEBTEB_BITS) && PEBTEB_BITS == 64)
  272. //
  273. // These are in native Win64 TEB, Win64 TEB64, and x86 TEB64.
  274. //
  275. PEBTEB_POINTER(PVOID) DeallocationBStore;
  276. PEBTEB_POINTER(PVOID) BStoreLimit;
  277. #endif
  278. LCID ImpersonationLocale; // Current locale of impersonated user
  279. ULONG IsImpersonating; // Thread impersonation status
  280. PEBTEB_POINTER(PVOID) NlsCache; // NLS thread cache
  281. PEBTEB_POINTER(PVOID) pShimData; // Per thread data used in the shim
  282. ULONG HeapVirtualAffinity;
  283. PEBTEB_POINTER(HANDLE) CurrentTransactionHandle;// reserved for TxF transaction context
  284. PEBTEB_POINTER(PTEB_ACTIVE_FRAME) ActiveFrame;
  285. PEBTEB_POINTER(PVOID) FlsData;
  286. } PEBTEB_STRUCT(TEB), *PEBTEB_STRUCT(PTEB);
  287. #undef PEBTEB_POINTER
  288. #undef PEBTEB_STRUCT
  289. #undef PEBTEB_PRIVATE_PASTE
  290. #undef PEBTEB_PASTE