Source code of Windows XP (NT5)
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.

452 lines
14 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 is #included three times.
  16. //
  17. // 1) by ntpsapi.h, with no "unusual" macros defined, to declare
  18. // PEB and TEB, and some types contained in them
  19. // 2) by wow64t.h to declare PEB32 and TEB32, and some types contained in them
  20. // 3) by wow64t.h to declare PEB64 and TEB64, and some types contained in them
  21. //
  22. // wow64t.h #defines the macro PEBTEB_BITS to guide the declarations.
  23. //
  24. #if defined(PEBTEB_BITS) /* This is defined by wow64t.h. */
  25. /*
  26. Any type that occurs in this header that changes size between 32bit and 64bit
  27. platforms must have a #define here at the top and an #undef at the bottom.
  28. Any type that is defined this header and changes size between 32bit and 64bit
  29. platforms (structs with pointers), must have a #define and #undef for all
  30. the "flavors" of name -- _FOO, FOO, PFOO, PCFOO, etc.
  31. More "stable" types can be left manually defined three times in ntdef.w, wow64t.w, etc.
  32. Less stable, maintenance problems, like PEB and TEB themselves, should be moved to this header.
  33. Public types, as well, should remain in ntdef.w.
  34. */
  35. #define PEBTEB_PRIVATE_PASTE(x,y) x##y
  36. #define PEBTEB_PASTE(x,y) PEBTEB_PRIVATE_PASTE(x,y)
  37. #if PEBTEB_BITS == 32
  38. #define TYPE1 TYPE32(ignored)
  39. #endif
  40. #if PEBTEB_BITS == 64
  41. #define TYPE1 TYPE64(ignored)
  42. #endif
  43. #define TYPE2(x) PEBTEB_PASTE(x, PEBTEB_BITS) /* FOO32 or FOO64 */
  44. #define HANDLE TYPE1
  45. #define SIZE_T TYPE1
  46. #define PVOID TYPE1
  47. #define PPVOID TYPE1
  48. #define PPEB_FREE_BLOCK TYPE1
  49. #define PPEB_LDR_DATA TYPE1
  50. #define ULONG_PTR TYPE1
  51. #define PPS_POST_PROCESS_INIT_ROUTINE TYPE1
  52. #define PCSTR TYPE1
  53. #define GDI_HANDLE_BUFFER TYPE2(GDI_HANDLE_BUFFER)
  54. #define UNICODE_STRING TYPE2(UNICODE_STRING)
  55. #define _PEB TYPE2(_PEB)
  56. #define PEB TYPE2(PEB)
  57. #define PPEB TYPE2(PPEB)
  58. #define _TEB TYPE2(_TEB)
  59. #define TEB TYPE2(TEB)
  60. #define PTEB TYPE2(PTEB)
  61. #define NT_TIB TYPE2(NT_TIB)
  62. #define LIST_ENTRY TYPE2(LIST_ENTRY)
  63. #define CLIENT_ID TYPE2(CLIENT_ID)
  64. #define GDI_TEB_BATCH TYPE2(GDI_TEB_BATCH)
  65. #define WX86THREAD TYPE2(WX86THREAD)
  66. #define _ACTIVATION_CONTEXT_STACK TYPE2(_ACTIVATION_CONTEXT_STACK)
  67. #define ACTIVATION_CONTEXT_STACK TYPE2(ACTIVATION_CONTEXT_STACK)
  68. #define PACTIVATION_CONTEXT_STACK TYPE2(PACTIVATION_CONTEXT_STACK)
  69. #define PCACTIVATION_CONTEXT_STACK TYPE2(PCACTIVATION_CONTEXT_STACK)
  70. #define _TEB_ACTIVE_FRAME TYPE2(_TEB_ACTIVE_FRAME)
  71. #define TEB_ACTIVE_FRAME TYPE2(TEB_ACTIVE_FRAME)
  72. #define PTEB_ACTIVE_FRAME TYPE2(PTEB_ACTIVE_FRAME)
  73. #define PCTEB_ACTIVE_FRAME TYPE2(PCTEB_ACTIVE_FRAME)
  74. #define _TEB_ACTIVE_FRAME_CONTEXT TYPE2(_TEB_ACTIVE_FRAME_CONTEXT)
  75. #define TEB_ACTIVE_FRAME_CONTEXT TYPE2(TEB_ACTIVE_FRAME_CONTEXT)
  76. #define PTEB_ACTIVE_FRAME_CONTEXT TYPE2(PTEB_ACTIVE_FRAME_CONTEXT)
  77. #define PCTEB_ACTIVE_FRAME_CONTEXT TYPE2(PCTEB_ACTIVE_FRAME_CONTEXT)
  78. #define _TEB_ACTIVE_FRAME_EX TYPE2(_TEB_ACTIVE_FRAME_EX)
  79. #define TEB_ACTIVE_FRAME_EX TYPE2(TEB_ACTIVE_FRAME_EX)
  80. #define PTEB_ACTIVE_FRAME_EX TYPE2(PTEB_ACTIVE_FRAME_EX)
  81. #define PCTEB_ACTIVE_FRAME_EX TYPE2(PCTEB_ACTIVE_FRAME_EX)
  82. #define _TEB_ACTIVE_FRAME_CONTEXT_EX TYPE2(_TEB_ACTIVE_FRAME_CONTEXT_EX)
  83. #define TEB_ACTIVE_FRAME_CONTEXT_EX TYPE2(TEB_ACTIVE_FRAME_CONTEXT_EX)
  84. #define PTEB_ACTIVE_FRAME_CONTEXT_EX TYPE2(PTEB_ACTIVE_FRAME_CONTEXT_EX)
  85. #define PCTEB_ACTIVE_FRAME_CONTEXT_EX TYPE2(PCTEB_ACTIVE_FRAME_CONTEXT_EX)
  86. #define _ACTIVATION_CONTEXT_STACK_PERF_COUNTERS TYPE2(_ACTIVATION_CONTEXT_STACK_PERF_COUNTERS)
  87. #define ACTIVATION_CONTEXT_STACK_PERF_COUNTERS TYPE2(ACTIVATION_CONTEXT_STACK_PERF_COUNTERS)
  88. #define PACTIVATION_CONTEXT_STACK_PERF_COUNTERS TYPE2(PACTIVATION_CONTEXT_STACK_PERF_COUNTERS)
  89. #define PCACTIVATION_CONTEXT_STACK_PERF_COUNTERS TYPE2(PCACTIVATION_CONTEXT_STACK_PERF_COUNTERS)
  90. #define TYPE3(x) TYPE1
  91. #else
  92. #define TYPE3(x) x
  93. #endif
  94. typedef struct _PEB {
  95. BOOLEAN InheritedAddressSpace; // These four fields cannot change unless the
  96. BOOLEAN ReadImageFileExecOptions; //
  97. BOOLEAN BeingDebugged; //
  98. BOOLEAN SpareBool; //
  99. HANDLE Mutant; // INITIAL_PEB structure is also updated.
  100. PVOID ImageBaseAddress;
  101. PPEB_LDR_DATA Ldr;
  102. TYPE3(struct _RTL_USER_PROCESS_PARAMETERS*) ProcessParameters;
  103. PVOID SubSystemData;
  104. PVOID ProcessHeap;
  105. TYPE3(struct _RTL_CRITICAL_SECTION*) FastPebLock;
  106. PVOID FastPebLockRoutine;
  107. PVOID FastPebUnlockRoutine;
  108. ULONG EnvironmentUpdateCount;
  109. PVOID KernelCallbackTable;
  110. ULONG SystemReserved[1];
  111. struct {
  112. ULONG ExecuteOptions : 2;
  113. ULONG SpareBits : 30;
  114. };
  115. PPEB_FREE_BLOCK FreeList;
  116. ULONG TlsExpansionCounter;
  117. PVOID TlsBitmap;
  118. ULONG TlsBitmapBits[2]; // TLS_MINIMUM_AVAILABLE bits
  119. PVOID ReadOnlySharedMemoryBase;
  120. PVOID ReadOnlySharedMemoryHeap;
  121. PPVOID ReadOnlyStaticServerData;
  122. PVOID AnsiCodePageData;
  123. PVOID OemCodePageData;
  124. PVOID UnicodeCaseTableData;
  125. //
  126. // Useful information for LdrpInitialize
  127. ULONG NumberOfProcessors;
  128. ULONG NtGlobalFlag;
  129. //
  130. // Passed up from MmCreatePeb from Session Manager registry key
  131. //
  132. LARGE_INTEGER CriticalSectionTimeout;
  133. SIZE_T HeapSegmentReserve;
  134. SIZE_T HeapSegmentCommit;
  135. SIZE_T HeapDeCommitTotalFreeThreshold;
  136. SIZE_T HeapDeCommitFreeBlockThreshold;
  137. //
  138. // Where heap manager keeps track of all heaps created for a process
  139. // Fields initialized by MmCreatePeb. ProcessHeaps is initialized
  140. // to point to the first free byte after the PEB and MaximumNumberOfHeaps
  141. // is computed from the page size used to hold the PEB, less the fixed
  142. // size of this data structure.
  143. //
  144. ULONG NumberOfHeaps;
  145. ULONG MaximumNumberOfHeaps;
  146. PPVOID ProcessHeaps;
  147. //
  148. //
  149. PVOID GdiSharedHandleTable;
  150. PVOID ProcessStarterHelper;
  151. ULONG GdiDCAttributeList;
  152. PVOID LoaderLock;
  153. //
  154. // Following fields filled in by MmCreatePeb from system values and/or
  155. // image header.
  156. //
  157. ULONG OSMajorVersion;
  158. ULONG OSMinorVersion;
  159. USHORT OSBuildNumber;
  160. USHORT OSCSDVersion;
  161. ULONG OSPlatformId;
  162. ULONG ImageSubsystem;
  163. ULONG ImageSubsystemMajorVersion;
  164. ULONG ImageSubsystemMinorVersion;
  165. ULONG_PTR ImageProcessAffinityMask;
  166. GDI_HANDLE_BUFFER GdiHandleBuffer;
  167. PPS_POST_PROCESS_INIT_ROUTINE PostProcessInitRoutine;
  168. PVOID TlsExpansionBitmap;
  169. ULONG TlsExpansionBitmapBits[32]; // TLS_EXPANSION_SLOTS bits
  170. //
  171. // Id of the Hydra session in which this process is running
  172. //
  173. ULONG SessionId;
  174. //
  175. // Filled in by LdrpInstallAppcompatBackend
  176. //
  177. ULARGE_INTEGER AppCompatFlags;
  178. //
  179. // ntuser appcompat flags
  180. //
  181. ULARGE_INTEGER AppCompatFlagsUser;
  182. //
  183. // Filled in by LdrpInstallAppcompatBackend
  184. //
  185. PVOID pShimData;
  186. //
  187. // Filled in by LdrQueryImageFileExecutionOptions
  188. //
  189. PVOID AppCompatInfo;
  190. //
  191. // Used by GetVersionExW as the szCSDVersion string
  192. //
  193. UNICODE_STRING CSDVersion;
  194. //
  195. // Fusion stuff
  196. //
  197. PVOID ActivationContextData;
  198. PVOID ProcessAssemblyStorageMap;
  199. PVOID SystemDefaultActivationContextData;
  200. PVOID SystemAssemblyStorageMap;
  201. //
  202. // Enforced minimum initial commit stack
  203. //
  204. SIZE_T MinimumStackCommit;
  205. } PEB, *PPEB;
  206. //
  207. // Fusion/sxs thread state information
  208. //
  209. #define ACTIVATION_CONTEXT_STACK_FLAG_QUERIES_DISABLED (0x00000001)
  210. typedef struct _ACTIVATION_CONTEXT_STACK {
  211. ULONG Flags;
  212. ULONG NextCookieSequenceNumber;
  213. PVOID ActiveFrame;
  214. LIST_ENTRY FrameListCache;
  215. #if NT_SXS_PERF_COUNTERS_ENABLED
  216. struct _ACTIVATION_CONTEXT_STACK_PERF_COUNTERS {
  217. ULONGLONG Activations;
  218. ULONGLONG ActivationCycles;
  219. ULONGLONG Deactivations;
  220. ULONGLONG DeactivationCycles;
  221. } Counters;
  222. #endif // NT_SXS_PERF_COUNTERS_ENABLED
  223. } ACTIVATION_CONTEXT_STACK, *PACTIVATION_CONTEXT_STACK;
  224. typedef const ACTIVATION_CONTEXT_STACK *PCACTIVATION_CONTEXT_STACK;
  225. #define TEB_ACTIVE_FRAME_CONTEXT_FLAG_EXTENDED (0x00000001)
  226. typedef struct _TEB_ACTIVE_FRAME_CONTEXT {
  227. ULONG Flags;
  228. PCSTR FrameName;
  229. } TEB_ACTIVE_FRAME_CONTEXT, *PTEB_ACTIVE_FRAME_CONTEXT;
  230. typedef const struct _TEB_ACTIVE_FRAME_CONTEXT *PCTEB_ACTIVE_FRAME_CONTEXT;
  231. typedef struct _TEB_ACTIVE_FRAME_CONTEXT_EX {
  232. TEB_ACTIVE_FRAME_CONTEXT BasicContext;
  233. PCSTR SourceLocation; // e.g. "Z:\foo\bar\baz.c"
  234. } TEB_ACTIVE_FRAME_CONTEXT_EX, *PTEB_ACTIVE_FRAME_CONTEXT_EX;
  235. typedef const struct _TEB_ACTIVE_FRAME_CONTEXT_EX *PCTEB_ACTIVE_FRAME_CONTEXT_EX;
  236. #define TEB_ACTIVE_FRAME_FLAG_EXTENDED (0x00000001)
  237. typedef struct _TEB_ACTIVE_FRAME {
  238. ULONG Flags;
  239. TYPE3(struct _TEB_ACTIVE_FRAME*) Previous;
  240. PCTEB_ACTIVE_FRAME_CONTEXT Context;
  241. } TEB_ACTIVE_FRAME, *PTEB_ACTIVE_FRAME;
  242. typedef const struct _TEB_ACTIVE_FRAME *PCTEB_ACTIVE_FRAME;
  243. typedef struct _TEB_ACTIVE_FRAME_EX {
  244. TEB_ACTIVE_FRAME BasicFrame;
  245. PVOID ExtensionIdentifier; // use address of your DLL Main or something unique to your mapping in the address space
  246. } TEB_ACTIVE_FRAME_EX, *PTEB_ACTIVE_FRAME_EX;
  247. typedef const struct _TEB_ACTIVE_FRAME_EX *PCTEB_ACTIVE_FRAME_EX;
  248. typedef struct _TEB {
  249. NT_TIB NtTib;
  250. PVOID EnvironmentPointer;
  251. CLIENT_ID ClientId;
  252. PVOID ActiveRpcHandle;
  253. PVOID ThreadLocalStoragePointer;
  254. #if defined(PEBTEB_BITS)
  255. PVOID ProcessEnvironmentBlock;
  256. #else
  257. PPEB ProcessEnvironmentBlock;
  258. #endif
  259. ULONG LastErrorValue;
  260. ULONG CountOfOwnedCriticalSections;
  261. PVOID CsrClientThread;
  262. PVOID Win32ThreadInfo; // PtiCurrent
  263. ULONG User32Reserved[26]; // user32.dll items
  264. ULONG UserReserved[5]; // Winsrv SwitchStack
  265. PVOID WOW32Reserved; // used by WOW
  266. LCID CurrentLocale;
  267. ULONG FpSoftwareStatusRegister; // offset known by outsiders!
  268. PVOID SystemReserved1[54]; // Used by FP emulator
  269. NTSTATUS ExceptionCode; // for RaiseUserException
  270. ACTIVATION_CONTEXT_STACK ActivationContextStack; // Fusion activation stack
  271. // sizeof(PVOID) is a way to express processor-dependence, more generally than #ifdef _WIN64
  272. UCHAR SpareBytes1[48 - sizeof(PVOID) - sizeof(ACTIVATION_CONTEXT_STACK)];
  273. GDI_TEB_BATCH GdiTebBatch; // Gdi batching
  274. CLIENT_ID RealClientId;
  275. HANDLE GdiCachedProcessHandle;
  276. ULONG GdiClientPID;
  277. ULONG GdiClientTID;
  278. PVOID GdiThreadLocalInfo;
  279. ULONG_PTR Win32ClientInfo[WIN32_CLIENT_INFO_LENGTH]; // User32 Client Info
  280. PVOID glDispatchTable[233]; // OpenGL
  281. ULONG_PTR glReserved1[29]; // OpenGL
  282. PVOID glReserved2; // OpenGL
  283. PVOID glSectionInfo; // OpenGL
  284. PVOID glSection; // OpenGL
  285. PVOID glTable; // OpenGL
  286. PVOID glCurrentRC; // OpenGL
  287. PVOID glContext; // OpenGL
  288. ULONG LastStatusValue;
  289. UNICODE_STRING StaticUnicodeString;
  290. WCHAR StaticUnicodeBuffer[STATIC_UNICODE_BUFFER_LENGTH];
  291. PVOID DeallocationStack;
  292. PVOID TlsSlots[TLS_MINIMUM_AVAILABLE];
  293. LIST_ENTRY TlsLinks;
  294. PVOID Vdm;
  295. PVOID ReservedForNtRpc;
  296. PVOID DbgSsReserved[2];
  297. ULONG HardErrorsAreDisabled;
  298. PVOID Instrumentation[16];
  299. PVOID WinSockData; // WinSock
  300. ULONG GdiBatchCount;
  301. BOOLEAN InDbgPrint;
  302. BOOLEAN FreeStackOnTermination;
  303. BOOLEAN HasFiberData;
  304. BOOLEAN IdealProcessor;
  305. ULONG Spare3;
  306. PVOID ReservedForPerf;
  307. PVOID ReservedForOle;
  308. ULONG WaitingOnLoaderLock;
  309. WX86THREAD Wx86Thread;
  310. PPVOID TlsExpansionSlots;
  311. #if (defined(_IA64_) && !defined(PEBTEB_BITS)) \
  312. || ((defined(_IA64_) || defined(_X86_)) && defined(PEBTEB_BITS) && PEBTEB_BITS == 64)
  313. //
  314. // These are in the native ia64 TEB, and the TEB64 for ia64 and x86.
  315. //
  316. PVOID DeallocationBStore;
  317. PVOID BStoreLimit;
  318. #endif
  319. LCID ImpersonationLocale; // Current locale of impersonated user
  320. ULONG IsImpersonating; // Thread impersonation status
  321. PVOID NlsCache; // NLS thread cache
  322. PVOID pShimData; // Per thread data used in the shim
  323. ULONG HeapVirtualAffinity;
  324. HANDLE CurrentTransactionHandle;// reserved for TxF transaction context
  325. PTEB_ACTIVE_FRAME ActiveFrame;
  326. } TEB;
  327. typedef TEB *PTEB;
  328. #undef TYPE3
  329. #if defined(PEBTEB_BITS)
  330. #undef PEBTEB_PRIVATE_PASTE
  331. #undef PEBTEB_PASTE
  332. #undef TYPE1
  333. #undef TYPE2
  334. #undef PCSTR
  335. #undef HANDLE
  336. #undef SIZE_T
  337. #undef PVOID
  338. #undef PPVOID
  339. #undef PPEB_FREE_BLOCK
  340. #undef PPEB_LDR_DATA
  341. #undef ULONG_PTR
  342. #undef PPS_POST_PROCESS_INIT_ROUTINE
  343. #undef WX86THREAD
  344. #undef GDI_HANDLE_BUFFER
  345. #undef UNICODE_STRING
  346. #undef _PEB
  347. #undef PEB
  348. #undef PPEB
  349. #undef _TEB
  350. #undef TEB
  351. #undef PTEB
  352. #undef NT_TIB
  353. #undef LIST_ENTRY
  354. #undef CLIENT_ID
  355. #undef GDI_TEB_BATCH
  356. #undef _ACTIVATION_CONTEXT_STACK
  357. #undef ACTIVATION_CONTEXT_STACK
  358. #undef PACTIVATION_CONTEXT_STACK
  359. #undef PCACTIVATION_CONTEXT_STACK
  360. #undef _TEB_ACTIVE_FRAME
  361. #undef TEB_ACTIVE_FRAME
  362. #undef PTEB_ACTIVE_FRAME
  363. #undef PCTEB_ACTIVE_FRAME
  364. #undef _TEB_ACTIVE_FRAME_CONTEXT
  365. #undef TEB_ACTIVE_FRAME_CONTEXT
  366. #undef PTEB_ACTIVE_FRAME_CONTEXT
  367. #undef PCTEB_ACTIVE_FRAME_CONTEXT
  368. #undef _TEB_ACTIVE_FRAME_EX
  369. #undef TEB_ACTIVE_FRAME_EX
  370. #undef PTEB_ACTIVE_FRAME_EX
  371. #undef PCTEB_ACTIVE_FRAME_EX
  372. #undef _TEB_ACTIVE_FRAME_CONTEXT_EX
  373. #undef TEB_ACTIVE_FRAME_CONTEXT_EX
  374. #undef PTEB_ACTIVE_FRAME_CONTEXT_EX
  375. #undef PCTEB_ACTIVE_FRAME_CONTEXT_EX
  376. #undef _ACTIVATION_CONTEXT_STACK_PERF_COUNTERS
  377. #undef ACTIVATION_CONTEXT_STACK_PERF_COUNTERS
  378. #undef PACTIVATION_CONTEXT_STACK_PERF_COUNTERS
  379. #undef PCACTIVATION_CONTEXT_STACK_PERF_COUNTERS
  380. #endif