701de83597252fc04c49cd3f3369255f5fc8e378
[reactos.git] / include / napi / teb.h
1 /* TEB/PEB parameters */
2 #ifndef __INCLUDE_INTERNAL_TEB
3 #define __INCLUDE_INTERNAL_TEB
4
5 #include <napi/types.h>
6
7 #ifdef __USE_W32API
8 #include <ddk/ntapi.h>
9 #endif /* !__USE_W32API */
10
11 #ifndef __USE_W32API
12
13 typedef struct _CLIENT_ID
14 {
15    HANDLE UniqueProcess;
16    HANDLE UniqueThread;
17 } CLIENT_ID, *PCLIENT_ID;
18
19 typedef struct _RTL_USER_PROCESS_PARAMETERS {
20         ULONG  AllocationSize;
21         ULONG  Size;
22         ULONG  Flags;
23         ULONG  DebugFlags;
24         HANDLE  hConsole;
25         ULONG  ProcessGroup;
26         HANDLE  hStdInput;
27         HANDLE  hStdOutput;
28         HANDLE  hStdError;
29         UNICODE_STRING  CurrentDirectoryName;
30         HANDLE  CurrentDirectoryHandle;
31         UNICODE_STRING  DllPath;
32         UNICODE_STRING  ImagePathName;
33         UNICODE_STRING  CommandLine;
34         PWSTR  Environment;
35         ULONG  dwX;
36         ULONG  dwY;
37         ULONG  dwXSize;
38         ULONG  dwYSize;
39         ULONG  dwXCountChars;
40         ULONG  dwYCountChars;
41         ULONG  dwFillAttribute;
42         ULONG  dwFlags;
43         ULONG  wShowWindow;
44         UNICODE_STRING  WindowTitle;
45         UNICODE_STRING  DesktopInfo;
46         UNICODE_STRING  ShellInfo;
47         UNICODE_STRING  RuntimeInfo;
48 } RTL_USER_PROCESS_PARAMETERS, *PRTL_USER_PROCESS_PARAMETERS;
49
50 typedef struct _NT_TIB {
51     struct _EXCEPTION_REGISTRATION_RECORD* ExceptionList;  /* 00h */
52     PVOID StackBase;                                       /* 04h */
53     PVOID StackLimit;                                      /* 08h */
54     PVOID SubSystemTib;                                    /* 0Ch */
55     union {
56         PVOID FiberData;                                   /* 10h */
57         ULONG Version;                                     /* 10h */
58     } Fib;
59     PVOID ArbitraryUserPointer;                            /* 14h */
60     struct _NT_TIB *Self;                                  /* 18h */
61 } NT_TIB, *PNT_TIB;
62
63 #endif /* !__USE_W32API */
64
65 typedef struct _CURDIR
66 {
67    UNICODE_STRING DosPath;
68    PVOID Handle;
69 } CURDIR, *PCURDIR;
70
71 typedef struct RTL_DRIVE_LETTER_CURDIR
72 {
73    USHORT Flags;
74    USHORT Length;
75    ULONG TimeStamp;
76    UNICODE_STRING DosPath;
77 } RTL_DRIVE_LETTER_CURDIR, *PRTL_DRIVE_LETTER_CURDIR;
78
79 typedef struct _PEB_FREE_BLOCK
80 {
81    struct _PEB_FREE_BLOCK* Next;
82    ULONG Size;
83 } PEB_FREE_BLOCK, *PPEB_FREE_BLOCK;
84
85 /* RTL_USER_PROCESS_PARAMETERS.Flags */
86 #define PPF_NORMALIZED  (1)
87
88 #define PEB_BASE        (0x7FFDF000)
89
90 typedef struct _PEB_LDR_DATA
91 {
92    ULONG Length;
93    BOOLEAN Initialized;
94    PVOID SsHandle;
95    LIST_ENTRY InLoadOrderModuleList;
96    LIST_ENTRY InMemoryOrderModuleList;
97    LIST_ENTRY InInitializationOrderModuleList;
98 } PEB_LDR_DATA, *PPEB_LDR_DATA;
99
100 typedef VOID STDCALL_FUNC (*PPEBLOCKROUTINE)(PVOID);
101
102 typedef struct _PEB
103 {
104    UCHAR InheritedAddressSpace;                     /* 00h */
105    UCHAR ReadImageFileExecOptions;                  /* 01h */
106    UCHAR BeingDebugged;                             /* 02h */
107    UCHAR Spare;                                     /* 03h */
108    PVOID Mutant;                                    /* 04h */
109    PVOID ImageBaseAddress;                          /* 08h */
110    PPEB_LDR_DATA Ldr;                               /* 0Ch */
111    PRTL_USER_PROCESS_PARAMETERS ProcessParameters;  /* 10h */
112    PVOID SubSystemData;                             /* 14h */
113    PVOID ProcessHeap;                               /* 18h */
114    PVOID FastPebLock;                               /* 1Ch */
115    PPEBLOCKROUTINE FastPebLockRoutine;              /* 20h */
116    PPEBLOCKROUTINE FastPebUnlockRoutine;            /* 24h */
117    ULONG EnvironmentUpdateCount;                    /* 28h */
118    PVOID* KernelCallbackTable;                      /* 2Ch */
119    PVOID EventLogSection;                           /* 30h */
120    PVOID EventLog;                                  /* 34h */
121    PPEB_FREE_BLOCK FreeList;                        /* 38h */
122    ULONG TlsExpansionCounter;                       /* 3Ch */
123    PVOID TlsBitmap;                                 /* 40h */
124    ULONG TlsBitmapBits[0x2];                        /* 44h */
125    PVOID ReadOnlySharedMemoryBase;                  /* 4Ch */
126    PVOID ReadOnlySharedMemoryHeap;                  /* 50h */
127    PVOID* ReadOnlyStaticServerData;                 /* 54h */
128    PVOID AnsiCodePageData;                          /* 58h */
129    PVOID OemCodePageData;                           /* 5Ch */
130    PVOID UnicodeCaseTableData;                      /* 60h */
131    ULONG NumberOfProcessors;                        /* 64h */
132    ULONG NtGlobalFlag;                              /* 68h */
133    UCHAR Spare2[0x4];                               /* 6Ch */
134    LARGE_INTEGER CriticalSectionTimeout;            /* 70h */
135    ULONG HeapSegmentReserve;                        /* 78h */
136    ULONG HeapSegmentCommit;                         /* 7Ch */
137    ULONG HeapDeCommitTotalFreeThreshold;            /* 80h */
138    ULONG HeapDeCommitFreeBlockThreshold;            /* 84h */
139    ULONG NumberOfHeaps;                             /* 88h */
140    ULONG MaximumNumberOfHeaps;                      /* 8Ch */
141    PVOID** ProcessHeaps;                            /* 90h */
142    PVOID GdiSharedHandleTable;                      /* 94h */
143    PVOID ProcessStarterHelper;                      /* 98h */
144    PVOID GdiDCAttributeList;                        /* 9Ch */
145    PVOID LoaderLock;                                /* A0h */
146    ULONG OSMajorVersion;                            /* A4h */
147    ULONG OSMinorVersion;                            /* A8h */
148    USHORT OSBuildNumber;                            /* ACh */
149    UCHAR SPMajorVersion;                            /* AEh */
150    UCHAR SPMinorVersion;                            /* AFh */
151    ULONG OSPlatformId;                              /* B0h */
152    ULONG ImageSubSystem;                            /* B4h */
153    ULONG ImageSubSystemMajorVersion;                /* B8h */
154    ULONG ImageSubSystemMinorVersion;                /* C0h */
155    ULONG GdiHandleBuffer[0x22];                     /* C4h */
156 } PEB;
157
158 #ifndef __USE_W32API
159
160 typedef PEB *PPEB;
161
162 #endif /* !__USE_W32API */
163
164 typedef struct _GDI_TEB_BATCH
165 {
166    ULONG Offset;
167    ULONG HDC;
168    ULONG Buffer[0x136];
169 } GDI_TEB_BATCH, *PGDI_TEB_BATCH;
170
171 typedef struct _TEB
172 {
173    NT_TIB Tib;                         /* 00h */
174    PVOID EnvironmentPointer;           /* 1Ch */
175    CLIENT_ID Cid;                      /* 20h */
176    PVOID ActiveRpcInfo;                /* 28h */
177    PVOID ThreadLocalStoragePointer;    /* 2Ch */
178    PPEB Peb;                           /* 30h */
179    ULONG LastErrorValue;               /* 34h */
180    ULONG CountOfOwnedCriticalSections; /* 38h */
181    PVOID CsrClientThread;              /* 3Ch */
182    struct _W32THREAD* Win32ThreadInfo; /* 40h */
183    ULONG Win32ClientInfo[0x1F];        /* 44h */
184    PVOID WOW32Reserved;                /* C0h */
185    ULONG CurrentLocale;                /* C4h */
186    ULONG FpSoftwareStatusRegister;     /* C8h */
187    PVOID SystemReserved1[0x36];        /* CCh */
188    PVOID Spare1;                       /* 1A4h */
189    LONG ExceptionCode;                 /* 1A8h */
190    UCHAR SpareBytes1[0x28];            /* 1ACh */
191    PVOID SystemReserved2[0xA];         /* 1D4h */
192    GDI_TEB_BATCH GdiTebBatch;          /* 1FCh */
193    ULONG gdiRgn;                       /* 6DCh */
194    ULONG gdiPen;                       /* 6E0h */
195    ULONG gdiBrush;                     /* 6E4h */
196    CLIENT_ID RealClientId;             /* 6E8h */
197    PVOID GdiCachedProcessHandle;       /* 6F0h */
198    ULONG GdiClientPID;                 /* 6F4h */
199    ULONG GdiClientTID;                 /* 6F8h */
200    PVOID GdiThreadLocaleInfo;          /* 6FCh */
201    PVOID UserReserved[5];              /* 700h */
202    PVOID glDispatchTable[0x118];       /* 714h */
203    ULONG glReserved1[0x1A];            /* B74h */
204    PVOID glReserved2;                  /* BDCh */
205    PVOID glSectionInfo;                /* BE0h */
206    PVOID glSection;                    /* BE4h */
207    PVOID glTable;                      /* BE8h */
208    PVOID glCurrentRC;                  /* BECh */
209    PVOID glContext;                    /* BF0h */
210    NTSTATUS LastStatusValue;           /* BF4h */
211    UNICODE_STRING StaticUnicodeString; /* BF8h */
212    WCHAR StaticUnicodeBuffer[0x105];   /* C00h */
213    PVOID DeallocationStack;            /* E0Ch */
214    PVOID TlsSlots[0x40];               /* E10h */
215    LIST_ENTRY TlsLinks;                /* F10h */
216    PVOID Vdm;                          /* F18h */
217    PVOID ReservedForNtRpc;             /* F1Ch */
218    PVOID DbgSsReserved[0x2];           /* F20h */
219    ULONG HardErrorDisabled;            /* F28h */
220    PVOID Instrumentation[0x10];        /* F2Ch */
221    PVOID WinSockData;                  /* F6Ch */
222    ULONG GdiBatchCount;                /* F70h */
223    USHORT Spare2;                      /* F74h */
224    BOOLEAN IsFiber;                    /* F76h */
225    UCHAR Spare3;                       /* F77h */
226    ULONG Spare4;                       /* F78h */
227    ULONG Spare5;                       /* F7Ch */
228    PVOID ReservedForOle;               /* F80h */
229    ULONG WaitingOnLoaderLock;          /* F84h */
230    ULONG Unknown[11];                  /* F88h */
231    PVOID FlsSlots;                     /* FB4h */
232    PVOID WineDebugInfo;                /* Needed for WINE DLL's  */
233 } TEB, *PTEB;
234
235 /* FIXME: at least NtCurrentTeb should be defined in winnt.h */
236
237 #ifndef NtCurrentTeb
238
239 #if defined(_M_IX86)
240 /* on the x86, the TEB is contained in the FS segment */
241 static inline struct _TEB * NtCurrentTeb(void)
242 {
243  struct _TEB * pTeb;
244
245  /* FIXME: instead of hardcoded offsets, use offsetof() - if possible */
246  __asm__ __volatile__
247  (
248   "movl %%fs:0x18, %0\n" /* fs:18h == Teb->Tib.Self */
249   : "=r" (pTeb) /* can't have two memory operands */
250   : /* no inputs */
251  );
252
253  return pTeb;
254 }
255 #define NtCurrentTeb NtCurrentTeb
256
257 #elif defined(_M_ALPHA)
258
259 void * __rdteb(void);
260 #pragma intrinsic(__rdteb)
261
262 /* on the Alpha AXP, we call the rdteb PAL to retrieve the address of the TEB */
263 #define NtCurrentTeb() ((struct _TEB *)__rdteb())
264
265 #elif defined(_M_MIPS)
266
267 /* on the MIPS R4000, the TEB is loaded at a fixed address */
268 #define NtCurrentTeb() ((struct _TEB *)0x7FFFF4A8)
269
270 #elif defined(_M_PPC)
271
272 unsigned __gregister_get(unsigned const regnum);
273 #pragma intrinsic(__gregister_get)
274
275 /* on the PowerPC, the TEB is pointed to by GPR 13 */
276 #define NtCurrentTeb() ((struct _TEB *)__gregister_get(13))
277
278 #else
279 #error Unsupported architecture or no architecture specified.
280 #endif
281
282 #endif
283
284 #ifdef _M_IX86
285
286 static inline struct _PEB * NtCurrentPeb(void)
287 {
288  struct _PEB * pPeb;
289
290  __asm__ __volatile__
291  (
292   "movl %%fs:0x30, %0\n" /* fs:30h == Teb->Peb */
293   : "=r" (pPeb) /* can't have two memory operands */
294   : /* no inputs */
295  );
296
297  return pPeb;
298 }
299
300 #else
301 /* generic NtCurrentPeb() */
302 #define NtCurrentPeb() (NtCurrentTeb()->Peb)
303 #endif
304
305 #endif /* __INCLUDE_INTERNAL_TEB */