Merge winnt.h
[reactos.git] / reactos / include / ndk / peb_teb.h
1
2 #define PASTE2(x,y) x##y
3 #define PASTE(x,y) PASTE2(x,y)
4
5 #ifdef EXPLICIT_32BIT
6 #define STRUCT(x) PASTE(x,32)
7 #define PTR(x) ULONG
8 #elif defined(EXPLICIT_64BIT)
9 #define STRUCT(x) PASTE(x,64)
10 #define PTR(x) ULONG64
11 #else
12 #define STRUCT(x) x
13 #define PTR(x) x
14 #endif
15
16 #if defined(_WIN64) && !defined(EXPLICIT_32BIT)
17 #define GDI_HANDLE_BUFFER_SIZE 60
18 #else
19 #define GDI_HANDLE_BUFFER_SIZE 34
20 #endif
21
22 typedef struct STRUCT(_PEB)
23 {
24 BOOLEAN InheritedAddressSpace;
25 BOOLEAN ReadImageFileExecOptions;
26 BOOLEAN BeingDebugged;
27 #if (NTDDI_VERSION >= NTDDI_WS03)
28 union
29 {
30 BOOLEAN BitField;
31 struct
32 {
33 BOOLEAN ImageUsesLargePages:1;
34 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
35 BOOLEAN IsProtectedProcess:1;
36 BOOLEAN IsLegacyProcess:1;
37 BOOLEAN IsImageDynamicallyRelocated:1;
38 BOOLEAN SkipPatchingUser32Forwarders:1;
39 BOOLEAN SpareBits:3;
40 #else
41 BOOLEAN SpareBits:7;
42 #endif
43 };
44 };
45 #else
46 BOOLEAN SpareBool;
47 #endif
48 PTR(HANDLE) Mutant;
49 PTR(PVOID) ImageBaseAddress;
50 PTR(PPEB_LDR_DATA) Ldr;
51 PTR(struct _RTL_USER_PROCESS_PARAMETERS*) ProcessParameters;
52 PTR(PVOID) SubSystemData;
53 PTR(PVOID) ProcessHeap;
54 PTR(struct _RTL_CRITICAL_SECTION*) FastPebLock;
55 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
56 PTR(PVOID) AltThunkSListPtr;
57 PTR(PVOID) IFEOKey;
58 union
59 {
60 ULONG CrossProcessFlags;
61 struct
62 {
63 ULONG ProcessInJob:1;
64 ULONG ProcessInitializing:1;
65 ULONG ProcessUsingVEH:1;
66 ULONG ProcessUsingVCH:1;
67 ULONG ReservedBits0:28;
68 };
69 };
70 union
71 {
72 PTR(PVOID) KernelCallbackTable;
73 PTR(PVOID) UserSharedInfoPtr;
74 };
75 #elif (NTDDI_VERSION >= NTDDI_WS03)
76 PTR(PVOID) AltThunkSListPtr;
77 PTR(PVOID) SparePtr2;
78 ULONG EnvironmentUpdateCount;
79 PTR(PVOID) KernelCallbackTable;
80 #else
81 PTR(PPEBLOCKROUTINE) FastPebLockRoutine;
82 PTR(PPEBLOCKROUTINE) FastPebUnlockRoutine;
83 ULONG EnvironmentUpdateCount;
84 PTR(PVOID) KernelCallbackTable;
85 #endif
86 ULONG SystemReserved[1];
87 ULONG SpareUlong; // AtlThunkSListPtr32
88 PTR(PPEB_FREE_BLOCK) FreeList;
89 ULONG TlsExpansionCounter;
90 PTR(PVOID) TlsBitmap;
91 ULONG TlsBitmapBits[2];
92 PTR(PVOID) ReadOnlySharedMemoryBase;
93 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
94 PTR(PVOID) HotpatchInformation;
95 #else
96 PTR(PVOID) ReadOnlySharedMemoryHeap;
97 #endif
98 PTR(PVOID*) ReadOnlyStaticServerData;
99 PTR(PVOID) AnsiCodePageData;
100 PTR(PVOID) OemCodePageData;
101 PTR(PVOID) UnicodeCaseTableData;
102 ULONG NumberOfProcessors;
103 ULONG NtGlobalFlag;
104 LARGE_INTEGER CriticalSectionTimeout;
105 PTR(ULONG_PTR) HeapSegmentReserve;
106 PTR(ULONG_PTR) HeapSegmentCommit;
107 PTR(ULONG_PTR) HeapDeCommitTotalFreeThreshold;
108 PTR(ULONG_PTR) HeapDeCommitFreeBlockThreshold;
109 ULONG NumberOfHeaps;
110 ULONG MaximumNumberOfHeaps;
111 PTR(PVOID*) ProcessHeaps;
112 PTR(PVOID) GdiSharedHandleTable;
113 PTR(PVOID) ProcessStarterHelper;
114 ULONG GdiDCAttributeList;
115 PTR(struct _RTL_CRITICAL_SECTION*) LoaderLock;
116 ULONG OSMajorVersion;
117 ULONG OSMinorVersion;
118 USHORT OSBuildNumber;
119 USHORT OSCSDVersion;
120 ULONG OSPlatformId;
121 ULONG ImageSubsystem;
122 ULONG ImageSubsystemMajorVersion;
123 ULONG ImageSubsystemMinorVersion;
124 PTR(ULONG_PTR) ImageProcessAffinityMask;
125 ULONG GdiHandleBuffer[GDI_HANDLE_BUFFER_SIZE];
126 PTR(PPOST_PROCESS_INIT_ROUTINE) PostProcessInitRoutine;
127 PTR(PVOID) TlsExpansionBitmap;
128 ULONG TlsExpansionBitmapBits[32];
129 ULONG SessionId;
130 #if (NTDDI_VERSION >= NTDDI_WINXP)
131 ULARGE_INTEGER AppCompatFlags;
132 ULARGE_INTEGER AppCompatFlagsUser;
133 PTR(PVOID) pShimData;
134 PTR(PVOID) AppCompatInfo;
135 STRUCT(UNICODE_STRING) CSDVersion;
136 PTR(struct _ACTIVATION_CONTEXT_DATA*) ActivationContextData;
137 PTR(struct _ASSEMBLY_STORAGE_MAP*) ProcessAssemblyStorageMap;
138 PTR(struct _ACTIVATION_CONTEXT_DATA*) SystemDefaultActivationContextData;
139 PTR(struct _ASSEMBLY_STORAGE_MAP*) SystemAssemblyStorageMap;
140 PTR(ULONG_PTR) MinimumStackCommit;
141 #endif
142 #if (NTDDI_VERSION >= NTDDI_WS03)
143 PTR(PVOID*) FlsCallback;
144 STRUCT(LIST_ENTRY) FlsListHead;
145 PTR(PVOID) FlsBitmap;
146 ULONG FlsBitmapBits[4];
147 ULONG FlsHighIndex;
148 #endif
149 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
150 PTR(PVOID) WerRegistrationData;
151 PTR(PVOID) WerShipAssertPtr;
152 #endif
153 } STRUCT(PEB), *STRUCT(PPEB);
154
155
156 #if defined(_WIN64) && !defined(EXPLICIT_32BIT)
157 C_ASSERT(FIELD_OFFSET(STRUCT(PEB), Mutant) == 0x08);
158 C_ASSERT(FIELD_OFFSET(STRUCT(PEB), Ldr) == 0x18);
159 C_ASSERT(FIELD_OFFSET(STRUCT(PEB), FastPebLock) == 0x038);
160 C_ASSERT(FIELD_OFFSET(STRUCT(PEB), TlsExpansionCounter) == 0x070);
161 C_ASSERT(FIELD_OFFSET(STRUCT(PEB), NtGlobalFlag) == 0x0BC);
162 C_ASSERT(FIELD_OFFSET(STRUCT(PEB), GdiSharedHandleTable) == 0x0F8);
163 C_ASSERT(FIELD_OFFSET(STRUCT(PEB), LoaderLock) == 0x110);
164 C_ASSERT(FIELD_OFFSET(STRUCT(PEB), ImageSubsystem) == 0x128);
165 C_ASSERT(FIELD_OFFSET(STRUCT(PEB), ImageProcessAffinityMask) == 0x138);
166 C_ASSERT(FIELD_OFFSET(STRUCT(PEB), PostProcessInitRoutine) == 0x230);
167 C_ASSERT(FIELD_OFFSET(STRUCT(PEB), SessionId) == 0x2C0);
168 #if (NTDDI_VERSION >= NTDDI_WS03)
169 C_ASSERT(FIELD_OFFSET(STRUCT(PEB), FlsHighIndex) == 0x350);
170 #endif
171 #else
172 C_ASSERT(FIELD_OFFSET(STRUCT(PEB), Mutant) == 0x04);
173 C_ASSERT(FIELD_OFFSET(STRUCT(PEB), Ldr) == 0x0C);
174 C_ASSERT(FIELD_OFFSET(STRUCT(PEB), FastPebLock) == 0x01C);
175 C_ASSERT(FIELD_OFFSET(STRUCT(PEB), TlsExpansionCounter) == 0x03C);
176 C_ASSERT(FIELD_OFFSET(STRUCT(PEB), NtGlobalFlag) == 0x068);
177 C_ASSERT(FIELD_OFFSET(STRUCT(PEB), GdiSharedHandleTable) == 0x094);
178 C_ASSERT(FIELD_OFFSET(STRUCT(PEB), LoaderLock) == 0x0A0);
179 C_ASSERT(FIELD_OFFSET(STRUCT(PEB), ImageSubsystem) == 0x0B4);
180 C_ASSERT(FIELD_OFFSET(STRUCT(PEB), ImageProcessAffinityMask) == 0x0C0);
181 C_ASSERT(FIELD_OFFSET(STRUCT(PEB), PostProcessInitRoutine) == 0x14C);
182 C_ASSERT(FIELD_OFFSET(STRUCT(PEB), SessionId) == 0x1D4);
183 #if (NTDDI_VERSION >= NTDDI_WS03)
184 C_ASSERT(FIELD_OFFSET(STRUCT(PEB), FlsHighIndex) == 0x22C);
185 #endif
186 #endif
187
188 //
189 // GDI Batch Descriptor
190 //
191 typedef struct STRUCT(_GDI_TEB_BATCH)
192 {
193 ULONG Offset;
194 PTR(HANDLE) HDC;
195 ULONG Buffer[0x136];
196 } STRUCT(GDI_TEB_BATCH), *STRUCT(PGDI_TEB_BATCH);
197
198 //
199 // Thread Environment Block (TEB)
200 //
201 typedef struct STRUCT(_TEB)
202 {
203 STRUCT(NT_TIB) NtTib;
204 PTR(PVOID) EnvironmentPointer;
205 STRUCT(CLIENT_ID) ClientId;
206 PTR(PVOID) ActiveRpcHandle;
207 PTR(PVOID) ThreadLocalStoragePointer;
208 PTR(STRUCT(PPEB)) ProcessEnvironmentBlock;
209 ULONG LastErrorValue;
210 ULONG CountOfOwnedCriticalSections;
211 PTR(PVOID) CsrClientThread;
212 PTR(PVOID) Win32ThreadInfo;
213 ULONG User32Reserved[26];
214 ULONG UserReserved[5];
215 PTR(PVOID) WOW32Reserved;
216 LCID CurrentLocale;
217 ULONG FpSoftwareStatusRegister;
218 PTR(PVOID) SystemReserved1[54];
219 LONG ExceptionCode;
220 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
221 PTR(struct _ACTIVATION_CONTEXT_STACK*) ActivationContextStackPointer;
222 UCHAR SpareBytes1[0x30 - 3 * sizeof(PTR(PVOID))];
223 ULONG TxFsContext;
224 #elif (NTDDI_VERSION >= NTDDI_WS03)
225 PTR(struct _ACTIVATION_CONTEXT_STACK*) ActivationContextStackPointer;
226 UCHAR SpareBytes1[0x34 - 3 * sizeof(PTR(PVOID))];
227 #else
228 ACTIVATION_CONTEXT_STACK ActivationContextStack;
229 UCHAR SpareBytes1[24];
230 #endif
231 STRUCT(GDI_TEB_BATCH) GdiTebBatch;
232 STRUCT(CLIENT_ID) RealClientId;
233 PTR(PVOID) GdiCachedProcessHandle;
234 ULONG GdiClientPID;
235 ULONG GdiClientTID;
236 PTR(PVOID) GdiThreadLocalInfo;
237 PTR(SIZE_T) Win32ClientInfo[62];
238 PTR(PVOID) glDispatchTable[233];
239 PTR(SIZE_T) glReserved1[29];
240 PTR(PVOID) glReserved2;
241 PTR(PVOID) glSectionInfo;
242 PTR(PVOID) glSection;
243 PTR(PVOID) glTable;
244 PTR(PVOID) glCurrentRC;
245 PTR(PVOID) glContext;
246 NTSTATUS LastStatusValue;
247 STRUCT(UNICODE_STRING) StaticUnicodeString;
248 WCHAR StaticUnicodeBuffer[261];
249 PTR(PVOID) DeallocationStack;
250 PTR(PVOID) TlsSlots[64];
251 STRUCT(LIST_ENTRY) TlsLinks;
252 PTR(PVOID) Vdm;
253 PTR(PVOID) ReservedForNtRpc;
254 PTR(PVOID) DbgSsReserved[2];
255 #if (NTDDI_VERSION >= NTDDI_WS03)
256 ULONG HardErrorMode;
257 #else
258 ULONG HardErrorsAreDisabled;
259 #endif
260 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
261 PTR(PVOID) Instrumentation[13 - sizeof(GUID)/sizeof(PTR(PVOID))];
262 GUID ActivityId;
263 PTR(PVOID) SubProcessTag;
264 PTR(PVOID) EtwLocalData;
265 PTR(PVOID) EtwTraceData;
266 #elif (NTDDI_VERSION >= NTDDI_WS03)
267 PTR(PVOID) Instrumentation[14];
268 PTR(PVOID) SubProcessTag;
269 PTR(PVOID) EtwLocalData;
270 #else
271 PTR(PVOID) Instrumentation[16];
272 #endif
273 PTR(PVOID) WinSockData;
274 ULONG GdiBatchCount;
275 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
276 BOOLEAN SpareBool0;
277 BOOLEAN SpareBool1;
278 BOOLEAN SpareBool2;
279 #else
280 BOOLEAN InDbgPrint;
281 BOOLEAN FreeStackOnTermination;
282 BOOLEAN HasFiberData;
283 #endif
284 UCHAR IdealProcessor;
285 #if (NTDDI_VERSION >= NTDDI_WS03)
286 ULONG GuaranteedStackBytes;
287 #else
288 ULONG Spare3;
289 #endif
290 PTR(PVOID) ReservedForPerf;
291 PTR(PVOID) ReservedForOle;
292 ULONG WaitingOnLoaderLock;
293 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
294 PTR(PVOID) SavedPriorityState;
295 PTR(ULONG_PTR) SoftPatchPtr1;
296 PTR(ULONG_PTR) ThreadPoolData;
297 #elif (NTDDI_VERSION >= NTDDI_WS03)
298 PTR(ULONG_PTR) SparePointer1;
299 PTR(ULONG_PTR) SoftPatchPtr1;
300 PTR(ULONG_PTR) SoftPatchPtr2;
301 #else
302 Wx86ThreadState Wx86Thread;
303 #endif
304 PTR(PVOID*) TlsExpansionSlots;
305 #if defined(_WIN64) && !defined(EXPLICIT_32BIT)
306 PTR(PVOID) DeallocationBStore;
307 PTR(PVOID) BStoreLimit;
308 #endif
309 ULONG ImpersonationLocale;
310 ULONG IsImpersonating;
311 PTR(PVOID) NlsCache;
312 PTR(PVOID) pShimData;
313 ULONG HeapVirtualAffinity;
314 PTR(HANDLE) CurrentTransactionHandle;
315 PTR(PTEB_ACTIVE_FRAME) ActiveFrame;
316 #if (NTDDI_VERSION >= NTDDI_WS03)
317 PVOID FlsData;
318 #endif
319 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
320 PVOID PreferredLangauges;
321 PVOID UserPrefLanguages;
322 PVOID MergedPrefLanguages;
323 ULONG MuiImpersonation;
324 union
325 {
326 struct
327 {
328 USHORT SpareCrossTebFlags:16;
329 };
330 USHORT CrossTebFlags;
331 };
332 union
333 {
334 struct
335 {
336 USHORT DbgSafeThunkCall:1;
337 USHORT DbgInDebugPrint:1;
338 USHORT DbgHasFiberData:1;
339 USHORT DbgSkipThreadAttach:1;
340 USHORT DbgWerInShipAssertCode:1;
341 USHORT DbgIssuedInitialBp:1;
342 USHORT DbgClonedThread:1;
343 USHORT SpareSameTebBits:9;
344 };
345 USHORT SameTebFlags;
346 };
347 PTR(PVOID) TxnScopeEntercallback;
348 PTR(PVOID) TxnScopeExitCAllback;
349 PTR(PVOID) TxnScopeContext;
350 ULONG LockCount;
351 ULONG ProcessRundown;
352 ULONG64 LastSwitchTime;
353 ULONG64 TotalSwitchOutTime;
354 LARGE_INTEGER WaitReasonBitMap;
355 #else
356 BOOLEAN SafeThunkCall;
357 BOOLEAN BooleanSpare[3];
358 #endif
359 } STRUCT(TEB), *STRUCT(PTEB);
360
361 #if defined(_WIN64) && !defined(EXPLICIT_32BIT)
362 C_ASSERT(FIELD_OFFSET(STRUCT(TEB), EnvironmentPointer) == 0x038);
363 C_ASSERT(FIELD_OFFSET(STRUCT(TEB), ExceptionCode) == 0x2C0);
364 C_ASSERT(FIELD_OFFSET(STRUCT(TEB), GdiTebBatch) == 0x2F0);
365 C_ASSERT(FIELD_OFFSET(STRUCT(TEB), LastStatusValue) == 0x1250);
366 C_ASSERT(FIELD_OFFSET(STRUCT(TEB), Vdm) == 0x1690);
367 C_ASSERT(FIELD_OFFSET(STRUCT(TEB), HardErrorMode) == 0x16B0);
368 C_ASSERT(FIELD_OFFSET(STRUCT(TEB), GdiBatchCount) == 0x1740);
369 C_ASSERT(FIELD_OFFSET(STRUCT(TEB), IdealProcessor) == 0x1747);
370 C_ASSERT(FIELD_OFFSET(STRUCT(TEB), WaitingOnLoaderLock) == 0x1760);
371 C_ASSERT(FIELD_OFFSET(STRUCT(TEB), TlsExpansionSlots) == 0x1780);
372 C_ASSERT(FIELD_OFFSET(STRUCT(TEB), WaitingOnLoaderLock) == 0x1760);
373 C_ASSERT(FIELD_OFFSET(STRUCT(TEB), ActiveFrame) == 0x17C0);
374 #else
375 C_ASSERT(FIELD_OFFSET(STRUCT(TEB), EnvironmentPointer) == 0x01C);
376 C_ASSERT(FIELD_OFFSET(STRUCT(TEB), ExceptionCode) == 0x1A4);
377 C_ASSERT(FIELD_OFFSET(STRUCT(TEB), GdiTebBatch) == 0x1D4);
378 C_ASSERT(FIELD_OFFSET(STRUCT(TEB), LastStatusValue) == 0xBF4);
379 C_ASSERT(FIELD_OFFSET(STRUCT(TEB), Vdm) == 0xF18);
380 C_ASSERT(FIELD_OFFSET(STRUCT(TEB), GdiBatchCount) == 0xF70);
381 C_ASSERT(FIELD_OFFSET(STRUCT(TEB), TlsExpansionSlots) == 0xF94);
382 C_ASSERT(FIELD_OFFSET(STRUCT(TEB), ActiveFrame) == 0xFB0);
383 #endif
384
385 #undef PTR
386 #undef STRUCT
387 #undef PASTE
388 #undef PASTE2
389 #undef GDI_HANDLE_BUFFER_SIZE