Documentation update.
[wine] / include / winnt.h
1 /*
2  * Win32 definitions for Windows NT
3  *
4  * Copyright 1996 Alexandre Julliard
5  */
6
7 #ifndef __WINE_WINNT_H
8 #define __WINE_WINNT_H
9
10 #include "basetsd.h"
11
12 #ifndef RC_INVOKED
13 #include <ctype.h>
14 #include <string.h>
15 #include <stddef.h>
16 #endif
17
18
19 /* On Windows winnt.h depends on a few windef.h types and macros and thus 
20  * is not self-contained. Furthermore windef.h includes winnt.h so that it 
21  * would be pointless to try to use winnt.h directly.
22  * But for Wine and Winelib I decided to make winnt.h self-contained by 
23  * moving these definitions to winnt.h. It makes no difference to Winelib 
24  * programs since they are not using winnt.h directly anyway, and it allows 
25  * us to use winnt.h and get a minimal set of definitions.
26  */
27
28 /**** Some Wine specific definitions *****/
29
30 /* Calling conventions definitions */
31
32 #ifdef __i386__
33 # ifndef _X86_
34 #  define _X86_
35 # endif
36 # if defined(__GNUC__) && ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 7)))
37 #  define __stdcall __attribute__((__stdcall__))
38 #  define __cdecl   __attribute__((__cdecl__))
39 # else
40 #  error You need gcc >= 2.7 to build Wine on a 386
41 # endif  /* __GNUC__ */
42 #else  /* __i386__ */
43 # define __stdcall
44 # define __cdecl
45 #endif  /* __i386__ */
46
47 #ifndef __WINE__
48 #define pascal      __stdcall
49 #define _pascal     __stdcall
50 #define _stdcall    __stdcall
51 #define _fastcall   __stdcall
52 #define __fastcall  __stdcall
53 #define __export    __stdcall
54 #define cdecl       __cdecl
55 #define _cdecl      __cdecl
56
57 #define near
58 #define far
59 #define _near
60 #define _far
61 #define NEAR
62 #define FAR
63
64 #ifndef _declspec
65 #define _declspec(x)
66 #endif
67 #ifndef __declspec
68 #define __declspec(x)
69 #endif
70 #endif /* __WINE__ */
71
72 #define CALLBACK    __stdcall
73 #define WINAPI      __stdcall
74 #define APIPRIVATE  __stdcall
75 #define PASCAL      __stdcall
76 #define CDECL       __cdecl
77 #define _CDECL      __cdecl
78 #define WINAPIV     __cdecl
79 #define APIENTRY    WINAPI
80 #define CONST       const
81
82 /* Macro for structure packing and more. */
83
84 #ifdef __GNUC__
85 #define WINE_PACKED   __attribute__((packed))
86 #define WINE_UNUSED   __attribute__((unused))
87 #define WINE_NORETURN __attribute__((noreturn))
88 #else
89 #define WINE_PACKED    /* nothing */
90 #define WINE_UNUSED    /* nothing */
91 #define WINE_NORETURN  /* nothing */
92 #endif
93
94 /* Anonymous union/struct handling */
95
96 #ifdef __WINE__
97 # define NONAMELESSSTRUCT
98 # define NONAMELESSUNION
99 #else
100 /* Anonymous struct support starts with gcc/g++ 2.96 */
101 # if !defined(NONAMELESSSTRUCT) && defined(__GNUC__) && ((__GNUC__ < 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ < 96)))
102 #  define NONAMELESSSTRUCT
103 # endif
104 /* Anonymous unions support starts with gcc 2.96/g++ 2.95 */
105 # if !defined(NONAMELESSUNION) && defined(__GNUC__) && ((__GNUC__ < 2) || ((__GNUC__ == 2) && ((__GNUC_MINOR__ < 95) || ((__GNUC_MINOR__ == 95) && !defined(__cplusplus)))))
106 #  define NONAMELESSUNION
107 # endif
108 #endif
109
110 #ifndef NONAMELESSSTRUCT
111 #define DUMMYSTRUCTNAME
112 #define DUMMYSTRUCTNAME1
113 #define DUMMYSTRUCTNAME2
114 #define DUMMYSTRUCTNAME3
115 #define DUMMYSTRUCTNAME4
116 #define DUMMYSTRUCTNAME5
117 #else /* !defined(NONAMELESSSTRUCT) */
118 #define DUMMYSTRUCTNAME   s
119 #define DUMMYSTRUCTNAME1  s1
120 #define DUMMYSTRUCTNAME2  s2
121 #define DUMMYSTRUCTNAME3  s3
122 #define DUMMYSTRUCTNAME4  s4
123 #define DUMMYSTRUCTNAME5  s5
124 #endif /* !defined(NONAMELESSSTRUCT) */
125
126 #ifndef NONAMELESSUNION
127 #define DUMMYUNIONNAME
128 #define DUMMYUNIONNAME1
129 #define DUMMYUNIONNAME2
130 #define DUMMYUNIONNAME3
131 #define DUMMYUNIONNAME4
132 #define DUMMYUNIONNAME5
133 #define DUMMYUNIONNAME6
134 #define DUMMYUNIONNAME7
135 #define DUMMYUNIONNAME8
136 #else /* !defined(NONAMELESSUNION) */
137 #define DUMMYUNIONNAME   u
138 #define DUMMYUNIONNAME1  u1
139 #define DUMMYUNIONNAME2  u2
140 #define DUMMYUNIONNAME3  u3
141 #define DUMMYUNIONNAME4  u4
142 #define DUMMYUNIONNAME5  u5
143 #define DUMMYUNIONNAME6  u6
144 #define DUMMYUNIONNAME7  u7
145 #define DUMMYUNIONNAME8  u8
146 #endif /* !defined(NONAMELESSUNION) */
147
148
149 /**** Parts of windef.h that are needed here *****/
150
151 /* Misc. constants. */
152
153 #undef NULL
154 #ifdef __cplusplus
155 #define NULL  0
156 #else
157 #define NULL  ((void*)0)
158 #endif
159
160 #ifdef FALSE
161 #undef FALSE
162 #endif
163 #define FALSE 0
164
165 #ifdef TRUE
166 #undef TRUE
167 #endif
168 #define TRUE  1
169
170 #ifndef IN
171 #define IN
172 #endif
173
174 #ifndef OUT
175 #define OUT
176 #endif
177
178 #ifndef OPTIONAL
179 #define OPTIONAL
180 #endif
181
182 /* Standard data types */
183 typedef const void                  *PCVOID,   *LPCVOID;
184 typedef int             BOOL,       *PBOOL,    *LPBOOL;
185 typedef unsigned char   BYTE,       *PBYTE,    *LPBYTE;
186 typedef unsigned char   UCHAR,      *PUCHAR;
187 typedef unsigned short  USHORT,     *PUSHORT,  *LPUSHORT;
188 typedef unsigned short  WORD,       *PWORD,    *LPWORD;
189 typedef int             INT,        *PINT,     *LPINT;
190 typedef unsigned int    UINT,       *PUINT,    *LPUINT;
191 typedef unsigned long   DWORD,      *PDWORD,   *LPDWORD;
192 typedef unsigned long   ULONG,      *PULONG,   *LPULONG;
193 typedef float           FLOAT,      *PFLOAT,   *LPFLOAT;
194 typedef double          DOUBLE,     *PDOUBLE,  *LPDOUBLE;
195 typedef double          DATE;
196
197
198 /**** winnt.h proper *****/
199
200 /* Microsoft's macros for declaring functions */
201
202 #ifdef __cplusplus
203 # define EXTERN_C    extern "C"
204 #else
205 # define EXTERN_C    extern
206 #endif
207
208 #ifndef __WINE__
209 #define STDMETHODCALLTYPE       __stdcall
210 #define STDMETHODVCALLTYPE      __cdecl
211 #define STDAPICALLTYPE          __stdcall
212 #define STDAPIVCALLTYPE         __cdecl
213
214 #define STDAPI                  EXTERN_C HRESULT STDAPICALLTYPE
215 #define STDAPI_(type)           EXTERN_C type STDAPICALLTYPE
216 #define STDMETHODIMP            HRESULT STDMETHODCALLTYPE
217 #define STDMETHODIMP_(type)     type STDMETHODCALLTYPE
218 #define STDAPIV                 EXTERN_C HRESULT STDAPIVCALLTYPE
219 #define STDAPIV_(type)          EXTERN_C type STDAPIVCALLTYPE
220 #define STDMETHODIMPV           HRESULT STDMETHODVCALLTYPE
221 #define STDMETHODIMPV_(type)    type STDMETHODVCALLTYPE
222 #endif
223
224 /* Define the basic types */
225 #ifndef VOID
226 #define VOID void
227 #endif
228 typedef VOID           *PVOID,      *LPVOID;
229 typedef BYTE            BOOLEAN,    *PBOOLEAN;
230 typedef char            CHAR,       *PCHAR;
231 typedef short           SHORT,      *PSHORT;
232 typedef long            LONG,       *PLONG,    *LPLONG;
233
234 /* Some systems might have wchar_t, but we really need 16 bit characters */
235 #ifdef WINE_UNICODE_NATIVE
236 typedef wchar_t         WCHAR,      *PWCHAR;
237 #else
238 typedef unsigned short  WCHAR,      *PWCHAR;
239 #endif
240
241 /* 'Extended/Wide' numerical types */
242 #ifndef _ULONGLONG_
243 #define _ULONGLONG_
244 typedef __int64         LONGLONG,   *PLONGLONG;
245 typedef __uint64        ULONGLONG,  *PULONGLONG;
246 #endif
247
248 #ifndef _DWORDLONG_
249 #define _DWORDLONG_
250 typedef ULONGLONG       DWORDLONG,  *PDWORDLONG;
251 #endif
252
253 /* ANSI string types */
254 typedef CHAR           *PCH,        *LPCH;
255 typedef const CHAR     *PCCH,       *LPCCH;
256 typedef CHAR           *PSTR,       *LPSTR;
257 typedef const CHAR     *PCSTR,      *LPCSTR;
258
259 /* Unicode string types */
260 typedef WCHAR          *PWCH,       *LPWCH;
261 typedef const WCHAR    *PCWCH,      *LPCWCH;
262 typedef WCHAR          *PWSTR,      *LPWSTR;
263 typedef const WCHAR    *PCWSTR,     *LPCWSTR;
264
265 /* Neutral character and string types */
266 /* These are only defined for Winelib, i.e. _not_ defined for 
267  * the emulator. The reason is they depend on the UNICODE 
268  * macro which only exists in the user's code.
269  */
270 #ifndef __WINE__
271 # ifdef WINE_UNICODE_REWRITE
272 EXTERN_C unsigned short* wine_rewrite_s4tos2(const wchar_t* str4);
273 #  ifdef __cplusplus
274 inline WCHAR* wine_unicode_text(const wchar_t* str4)
275 {
276   return (WCHAR*)wine_rewrite_s4tos2(str4);
277 }
278 inline WCHAR wine_unicode_text(wchar_t chr4)
279 {
280   return (WCHAR)chr4;
281 }
282 #   define WINE_UNICODE_TEXT(x)       wine_unicode_text(L##x)
283 #  else  /* __cplusplus */
284 #   define WINE_UNICODE_TEXT(x)       ((sizeof(x)==1) || (sizeof(L##x)>4) ? \
285                                       (WCHAR*)wine_rewrite_s4tos2(L##x) : \
286                                       ((WCHAR)L##x))
287 #  endif  /* __cplusplus */
288 # else  /* WINE_UNICODE_REWRITE */
289 /* WINE_UNICODE_NATIVE or nothing at all */
290 #  define WINE_UNICODE_TEXT(string)   L##string
291 # endif  /* WINE_UNICODE_REWRITE */
292
293 # ifdef UNICODE
294 typedef WCHAR           TCHAR,      *PTCHAR;
295 typedef LPWSTR          PTSTR,       LPTSTR;
296 typedef LPCWSTR         PCTSTR,      LPCTSTR;
297 #  define __TEXT(string) WINE_UNICODE_TEXT(string)
298 # else  /* UNICODE */
299 typedef CHAR            TCHAR,      *PTCHAR;
300 typedef LPSTR           PTSTR,       LPTSTR;
301 typedef LPCSTR          PCTSTR,      LPCTSTR;
302 #  define __TEXT(string) string
303 # endif /* UNICODE */
304 # define TEXT(quote) __TEXT(quote)
305 #endif   /* __WINE__ */
306
307 /* Misc common WIN32 types */
308 typedef LONG            HRESULT;
309 typedef DWORD           LCID,       *PLCID;
310 typedef WORD            LANGID;
311
312 /* Handle type */
313
314 /* FIXME: Wine does not compile with strict on, therefore strict
315  * handles are presently only usable on machines where sizeof(UINT) ==
316  * sizeof(void*).  HANDLEs are supposed to be void* but a large amount
317  * of WINE code operates on HANDLES as if they are UINTs. So to WINE
318  * they exist as UINTs but to the Winelib user who turns on strict,
319  * they exist as void*. If there is a size difference between UINT and
320  * void* then things get ugly.  */
321 #ifdef STRICT
322 typedef VOID*           HANDLE;
323 #else
324 typedef UINT            HANDLE;
325 #endif
326 typedef HANDLE         *LPHANDLE;
327
328 #ifdef STRICT
329 #define DECLARE_HANDLE(a) \
330         typedef struct a##__ { int unused; } *a; \
331         typedef a *P##a; \
332         typedef a *LP##a
333 #else /*STRICT*/
334 #define DECLARE_HANDLE(a) \
335         typedef HANDLE a; \
336         typedef a *P##a; \
337         typedef a *LP##a
338 #endif /*STRICT*/
339
340
341 #include "pshpack1.h"
342 /* Defines */
343
344 /* Argument 1 passed to the DllEntryProc. */
345 #define DLL_PROCESS_DETACH      0       /* detach process (unload library) */
346 #define DLL_PROCESS_ATTACH      1       /* attach process (load library) */
347 #define DLL_THREAD_ATTACH       2       /* attach new thread */
348 #define DLL_THREAD_DETACH       3       /* detach thread */
349
350
351 /* u.x.wProcessorArchitecture (NT) */
352 #define PROCESSOR_ARCHITECTURE_INTEL    0
353 #define PROCESSOR_ARCHITECTURE_MIPS     1
354 #define PROCESSOR_ARCHITECTURE_ALPHA    2
355 #define PROCESSOR_ARCHITECTURE_PPC      3
356 #define PROCESSOR_ARCHITECTURE_SHX      4
357 #define PROCESSOR_ARCHITECTURE_ARM      5
358 #define PROCESSOR_ARCHITECTURE_UNKNOWN  0xFFFF
359
360 /* dwProcessorType */
361 #define PROCESSOR_INTEL_386      386
362 #define PROCESSOR_INTEL_486      486
363 #define PROCESSOR_INTEL_PENTIUM  586
364 #define PROCESSOR_INTEL_860      860
365 #define PROCESSOR_MIPS_R2000     2000
366 #define PROCESSOR_MIPS_R3000     3000
367 #define PROCESSOR_MIPS_R4000     4000
368 #define PROCESSOR_ALPHA_21064    21064
369 #define PROCESSOR_PPC_601        601
370 #define PROCESSOR_PPC_603        603
371 #define PROCESSOR_PPC_604        604
372 #define PROCESSOR_PPC_620        620
373 #define PROCESSOR_HITACHI_SH3    10003
374 #define PROCESSOR_HITACHI_SH3E   10004
375 #define PROCESSOR_HITACHI_SH4    10005
376 #define PROCESSOR_MOTOROLA_821   821
377 #define PROCESSOR_SHx_SH3        103
378 #define PROCESSOR_SHx_SH4        104
379 #define PROCESSOR_STRONGARM      2577
380 #define PROCESSOR_ARM720         1824    /* 0x720 */
381 #define PROCESSOR_ARM820         2080    /* 0x820 */
382 #define PROCESSOR_ARM920         2336    /* 0x920 */
383 #define PROCESSOR_ARM_7TDMI      70001
384
385 typedef struct _MEMORY_BASIC_INFORMATION
386 {
387     LPVOID   BaseAddress;
388     LPVOID   AllocationBase;
389     DWORD    AllocationProtect;
390     DWORD    RegionSize;
391     DWORD    State;
392     DWORD    Protect;
393     DWORD    Type;
394 } MEMORY_BASIC_INFORMATION,*LPMEMORY_BASIC_INFORMATION,*PMEMORY_BASIC_INFORMATION;
395
396 #define PAGE_NOACCESS           0x01
397 #define PAGE_READONLY           0x02
398 #define PAGE_READWRITE          0x04
399 #define PAGE_WRITECOPY          0x08
400 #define PAGE_EXECUTE            0x10
401 #define PAGE_EXECUTE_READ       0x20
402 #define PAGE_EXECUTE_READWRITE  0x40
403 #define PAGE_EXECUTE_WRITECOPY  0x80
404 #define PAGE_GUARD              0x100
405 #define PAGE_NOCACHE            0x200
406
407 #define MEM_COMMIT              0x00001000
408 #define MEM_RESERVE             0x00002000
409 #define MEM_DECOMMIT            0x00004000
410 #define MEM_RELEASE             0x00008000
411 #define MEM_FREE                0x00010000
412 #define MEM_PRIVATE             0x00020000
413 #define MEM_MAPPED              0x00040000
414 #define MEM_RESET               0x00080000
415 #define MEM_TOP_DOWN            0x00100000
416 #ifdef __WINE__
417 #define MEM_SYSTEM              0x80000000
418 #endif
419
420 #define SEC_FILE                0x00800000
421 #define SEC_IMAGE               0x01000000
422 #define SEC_RESERVE             0x04000000
423 #define SEC_COMMIT              0x08000000
424 #define SEC_NOCACHE             0x10000000
425 #define MEM_IMAGE               SEC_IMAGE
426
427
428 #define MINCHAR       0x80
429 #define MAXCHAR       0x7f
430 #define MINSHORT      0x8000
431 #define MAXSHORT      0x7fff
432 #define MINLONG       0x80000000
433 #define MAXLONG       0x7fffffff
434 #define MAXBYTE       0xff
435 #define MAXWORD       0xffff
436 #define MAXDWORD      0xffffffff
437
438 #define FIELD_OFFSET(type, field) \
439   ((LONG)(INT)&(((type *)0)->field))
440
441 #define CONTAINING_RECORD(address, type, field) \
442   ((type *)((PCHAR)(address) - (PCHAR)(&((type *)0)->field)))
443
444 /* Types */
445
446 typedef struct _LIST_ENTRY {
447   struct _LIST_ENTRY *Flink;
448   struct _LIST_ENTRY *Blink;
449 } LIST_ENTRY, *PLIST_ENTRY;
450
451 typedef struct _SINGLE_LIST_ENTRY {
452   struct _SINGLE_LIST_ENTRY *Next;
453 } SINGLE_LIST_ENTRY, *PSINGLE_LIST_ENTRY;
454
455 /* Heap flags */
456
457 #define HEAP_NO_SERIALIZE               0x00000001
458 #define HEAP_GROWABLE                   0x00000002
459 #define HEAP_GENERATE_EXCEPTIONS        0x00000004
460 #define HEAP_ZERO_MEMORY                0x00000008
461 #define HEAP_REALLOC_IN_PLACE_ONLY      0x00000010
462 #define HEAP_TAIL_CHECKING_ENABLED      0x00000020
463 #define HEAP_FREE_CHECKING_ENABLED      0x00000040
464 #define HEAP_DISABLE_COALESCE_ON_FREE   0x00000080
465 #define HEAP_CREATE_ALIGN_16            0x00010000
466 #define HEAP_CREATE_ENABLE_TRACING      0x00020000
467
468 /* This flag allows it to create heaps shared by all processes under win95,
469    FIXME: correct name */
470 #define HEAP_SHARED                     0x04000000  
471
472 #define HEAP_WINE_SEGPTR                0x10000000  /* Not a Win32 flag */
473 #define HEAP_WINE_CODESEG               0x20000000  /* Not a Win32 flag */
474 #define HEAP_WINE_CODE16SEG             0x40000000  /* Not a Win32 flag */
475
476 /* Processor feature flags.  */
477 #define PF_FLOATING_POINT_PRECISION_ERRATA      0
478 #define PF_FLOATING_POINT_EMULATED              1
479 #define PF_COMPARE_EXCHANGE_DOUBLE              2
480 #define PF_MMX_INSTRUCTIONS_AVAILABLE           3
481 #define PF_PPC_MOVEMEM_64BIT_OK                 4
482 #define PF_ALPHA_BYTE_INSTRUCTIONS              5
483
484
485 /* The Win32 register context */
486
487 /* CONTEXT is the CPU-dependent context; it should be used        */
488 /* wherever a platform-specific context is needed (e.g. exception */
489 /* handling, Win32 register functions). */
490
491 /* CONTEXT86 is the i386-specific context; it should be used     */
492 /* wherever only a 386 context makes sense (e.g. DOS interrupts, */
493 /* Win16 register functions), so that this code can be compiled  */
494 /* on all platforms. */
495
496 #define SIZE_OF_80387_REGISTERS      80
497
498 typedef struct _FLOATING_SAVE_AREA
499 {
500     DWORD   ControlWord;
501     DWORD   StatusWord;
502     DWORD   TagWord;    
503     DWORD   ErrorOffset;
504     DWORD   ErrorSelector;
505     DWORD   DataOffset;
506     DWORD   DataSelector;    
507     BYTE    RegisterArea[SIZE_OF_80387_REGISTERS];
508     DWORD   Cr0NpxState;
509 } FLOATING_SAVE_AREA, *PFLOATING_SAVE_AREA;
510
511 typedef struct _CONTEXT86
512 {
513     DWORD   ContextFlags;
514
515     /* These are selected by CONTEXT_DEBUG_REGISTERS */
516     DWORD   Dr0;
517     DWORD   Dr1;
518     DWORD   Dr2;
519     DWORD   Dr3;
520     DWORD   Dr6;
521     DWORD   Dr7;
522
523     /* These are selected by CONTEXT_FLOATING_POINT */
524     FLOATING_SAVE_AREA FloatSave;
525
526     /* These are selected by CONTEXT_SEGMENTS */
527     DWORD   SegGs;
528     DWORD   SegFs;
529     DWORD   SegEs;
530     DWORD   SegDs;    
531
532     /* These are selected by CONTEXT_INTEGER */
533     DWORD   Edi;
534     DWORD   Esi;
535     DWORD   Ebx;
536     DWORD   Edx;    
537     DWORD   Ecx;
538     DWORD   Eax;
539
540     /* These are selected by CONTEXT_CONTROL */
541     DWORD   Ebp;    
542     DWORD   Eip;
543     DWORD   SegCs;
544     DWORD   EFlags;
545     DWORD   Esp;
546     DWORD   SegSs;
547 } CONTEXT86;
548
549 #define CONTEXT_X86       0x00010000
550 #define CONTEXT_i386      CONTEXT_X86
551 #define CONTEXT_i486      CONTEXT_X86
552
553 #define CONTEXT86_CONTROL   (CONTEXT_i386 | 0x0001) /* SS:SP, CS:IP, FLAGS, BP */
554 #define CONTEXT86_INTEGER   (CONTEXT_i386 | 0x0002) /* AX, BX, CX, DX, SI, DI */
555 #define CONTEXT86_SEGMENTS  (CONTEXT_i386 | 0x0004) /* DS, ES, FS, GS */
556 #define CONTEXT86_FLOATING_POINT  (CONTEXT_i386 | 0x0008L) /* 387 state */
557 #define CONTEXT86_DEBUG_REGISTERS (CONTEXT_i386 | 0x0010L) /* DB 0-3,6,7 */
558 #define CONTEXT86_FULL (CONTEXT86_CONTROL | CONTEXT86_INTEGER | CONTEXT86_SEGMENTS)
559
560 /* i386 context definitions */
561 #ifdef __i386__
562
563 #define CONTEXT_CONTROL         CONTEXT86_CONTROL
564 #define CONTEXT_INTEGER         CONTEXT86_INTEGER
565 #define CONTEXT_SEGMENTS        CONTEXT86_SEGMENTS
566 #define CONTEXT_FLOATING_POINT  CONTEXT86_FLOATING_POINT
567 #define CONTEXT_DEBUG_REGISTERS CONTEXT86_DEBUG_REGISTERS
568 #define CONTEXT_FULL            CONTEXT86_FULL
569
570 typedef CONTEXT86 CONTEXT;
571
572 #endif  /* __i386__ */
573
574 /* Alpha context definitions */
575 #ifdef _ALPHA_
576
577 #define CONTEXT_ALPHA   0x00020000
578  
579 #define CONTEXT_CONTROL         (CONTEXT_ALPHA | 0x00000001L)
580 #define CONTEXT_FLOATING_POINT  (CONTEXT_ALPHA | 0x00000002L)
581 #define CONTEXT_INTEGER         (CONTEXT_ALPHA | 0x00000004L)
582 #define CONTEXT_FULL  (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER)
583
584 typedef struct _CONTEXT
585 {
586     /* selected by CONTEXT_FLOATING_POINT */
587     ULONGLONG FltF0;
588     ULONGLONG FltF1;
589     ULONGLONG FltF2;
590     ULONGLONG FltF3;
591     ULONGLONG FltF4;
592     ULONGLONG FltF5;
593     ULONGLONG FltF6;
594     ULONGLONG FltF7;
595     ULONGLONG FltF8;
596     ULONGLONG FltF9;
597     ULONGLONG FltF10;
598     ULONGLONG FltF11;
599     ULONGLONG FltF12;
600     ULONGLONG FltF13;
601     ULONGLONG FltF14;
602     ULONGLONG FltF15;
603     ULONGLONG FltF16;
604     ULONGLONG FltF17;
605     ULONGLONG FltF18;
606     ULONGLONG FltF19;
607     ULONGLONG FltF20;
608     ULONGLONG FltF21;
609     ULONGLONG FltF22;
610     ULONGLONG FltF23;
611     ULONGLONG FltF24;
612     ULONGLONG FltF25;
613     ULONGLONG FltF26;
614     ULONGLONG FltF27;
615     ULONGLONG FltF28;
616     ULONGLONG FltF29;
617     ULONGLONG FltF30;
618     ULONGLONG FltF31;
619
620     /* selected by CONTEXT_INTEGER */
621     ULONGLONG IntV0;
622     ULONGLONG IntT0;
623     ULONGLONG IntT1;
624     ULONGLONG IntT2;
625     ULONGLONG IntT3;
626     ULONGLONG IntT4;
627     ULONGLONG IntT5;
628     ULONGLONG IntT6;
629     ULONGLONG IntT7;
630     ULONGLONG IntS0;
631     ULONGLONG IntS1;
632     ULONGLONG IntS2;
633     ULONGLONG IntS3;
634     ULONGLONG IntS4;
635     ULONGLONG IntS5;
636     ULONGLONG IntFp;
637     ULONGLONG IntA0;
638     ULONGLONG IntA1;
639     ULONGLONG IntA2;
640     ULONGLONG IntA3;
641     ULONGLONG IntA4;
642     ULONGLONG IntA5;
643     ULONGLONG IntT8;
644     ULONGLONG IntT9;
645     ULONGLONG IntT10;
646     ULONGLONG IntT11;
647     ULONGLONG IntRa;
648     ULONGLONG IntT12;
649     ULONGLONG IntAt;
650     ULONGLONG IntGp;
651     ULONGLONG IntSp;
652     ULONGLONG IntZero;
653
654     /* selected by CONTEXT_FLOATING_POINT */
655     ULONGLONG Fpcr;
656     ULONGLONG SoftFpcr;
657
658     /* selected by CONTEXT_CONTROL */
659     ULONGLONG Fir;
660     DWORD Psr;
661     DWORD ContextFlags;
662     DWORD Fill[4];
663 } CONTEXT;
664
665 #define _QUAD_PSR_OFFSET   HighSoftFpcr
666 #define _QUAD_FLAGS_OFFSET HighFir
667
668 #endif  /* _ALPHA_ */
669
670 /* Mips context definitions */
671 #ifdef _MIPS_
672
673 #define CONTEXT_R4000   0x00010000
674
675 #define CONTEXT_CONTROL         (CONTEXT_R4000 | 0x00000001)
676 #define CONTEXT_FLOATING_POINT  (CONTEXT_R4000 | 0x00000002)
677 #define CONTEXT_INTEGER         (CONTEXT_R4000 | 0x00000004)
678
679 #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER)
680
681 typedef struct _CONTEXT
682 {
683     DWORD Argument[4];
684     /* These are selected by CONTEXT_FLOATING_POINT */
685     DWORD FltF0;
686     DWORD FltF1;
687     DWORD FltF2;
688     DWORD FltF3;
689     DWORD FltF4;
690     DWORD FltF5;
691     DWORD FltF6;
692     DWORD FltF7;
693     DWORD FltF8;
694     DWORD FltF9;
695     DWORD FltF10;
696     DWORD FltF11;
697     DWORD FltF12;
698     DWORD FltF13;
699     DWORD FltF14;
700     DWORD FltF15;
701     DWORD FltF16;
702     DWORD FltF17;
703     DWORD FltF18;
704     DWORD FltF19;
705     DWORD FltF20;
706     DWORD FltF21;
707     DWORD FltF22;
708     DWORD FltF23;
709     DWORD FltF24;
710     DWORD FltF25;
711     DWORD FltF26;
712     DWORD FltF27;
713     DWORD FltF28;
714     DWORD FltF29;
715     DWORD FltF30;
716     DWORD FltF31;
717
718     /* These are selected by CONTEXT_INTEGER */
719     DWORD IntZero;
720     DWORD IntAt;
721     DWORD IntV0;
722     DWORD IntV1;
723     DWORD IntA0;
724     DWORD IntA1;
725     DWORD IntA2;
726     DWORD IntA3;
727     DWORD IntT0;
728     DWORD IntT1;
729     DWORD IntT2;
730     DWORD IntT3;
731     DWORD IntT4;
732     DWORD IntT5;
733     DWORD IntT6;
734     DWORD IntT7;
735     DWORD IntS0;
736     DWORD IntS1;
737     DWORD IntS2;
738     DWORD IntS3;
739     DWORD IntS4;
740     DWORD IntS5;
741     DWORD IntS6;
742     DWORD IntS7;
743     DWORD IntT8;
744     DWORD IntT9;
745     DWORD IntK0;
746     DWORD IntK1;
747     DWORD IntGp;
748     DWORD IntSp;
749     DWORD IntS8;
750     DWORD IntRa;
751     DWORD IntLo;
752     DWORD IntHi;
753
754     /* These are selected by CONTEXT_FLOATING_POINT */
755     DWORD Fsr;
756
757     /* These are selected by CONTEXT_CONTROL */
758     DWORD Fir;
759     DWORD Psr;
760
761     DWORD ContextFlags;
762     DWORD Fill[2];
763 } CONTEXT;
764
765 #endif  /* _MIPS_ */
766
767 /* PowerPC context definitions */
768 #ifdef __PPC__
769
770 #define CONTEXT_CONTROL         0x0001
771 #define CONTEXT_FLOATING_POINT  0x0002
772 #define CONTEXT_INTEGER         0x0004
773 #define CONTEXT_DEBUG_REGISTERS 0x0008
774 #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER)
775
776 typedef struct
777 {
778     /* These are selected by CONTEXT_FLOATING_POINT */
779     double Fpr0;
780     double Fpr1;
781     double Fpr2;
782     double Fpr3;
783     double Fpr4;
784     double Fpr5;
785     double Fpr6;
786     double Fpr7;
787     double Fpr8;
788     double Fpr9;
789     double Fpr10;
790     double Fpr11;
791     double Fpr12;
792     double Fpr13;
793     double Fpr14;
794     double Fpr15;
795     double Fpr16;
796     double Fpr17;
797     double Fpr18;
798     double Fpr19;
799     double Fpr20;
800     double Fpr21;
801     double Fpr22;
802     double Fpr23;
803     double Fpr24;
804     double Fpr25;
805     double Fpr26;
806     double Fpr27;
807     double Fpr28;
808     double Fpr29;
809     double Fpr30;
810     double Fpr31;
811     double Fpscr;
812
813     /* These are selected by CONTEXT_INTEGER */
814     DWORD Gpr0;
815     DWORD Gpr1;
816     DWORD Gpr2;
817     DWORD Gpr3;
818     DWORD Gpr4;
819     DWORD Gpr5;
820     DWORD Gpr6;
821     DWORD Gpr7;
822     DWORD Gpr8;
823     DWORD Gpr9;
824     DWORD Gpr10;
825     DWORD Gpr11;
826     DWORD Gpr12;
827     DWORD Gpr13;
828     DWORD Gpr14;
829     DWORD Gpr15;
830     DWORD Gpr16;
831     DWORD Gpr17;
832     DWORD Gpr18;
833     DWORD Gpr19;
834     DWORD Gpr20;
835     DWORD Gpr21;
836     DWORD Gpr22;
837     DWORD Gpr23;
838     DWORD Gpr24;
839     DWORD Gpr25;
840     DWORD Gpr26;
841     DWORD Gpr27;
842     DWORD Gpr28;
843     DWORD Gpr29;
844     DWORD Gpr30;
845     DWORD Gpr31;
846
847     DWORD Cr;
848     DWORD Xer;
849
850     /* These are selected by CONTEXT_CONTROL */
851     DWORD Msr;
852     DWORD Iar;
853     DWORD Lr;
854     DWORD Ctr;
855
856     DWORD ContextFlags;
857     DWORD Fill[3];
858
859     /* These are selected by CONTEXT_DEBUG_REGISTERS */
860     DWORD Dr0;
861     DWORD Dr1;
862     DWORD Dr2;
863     DWORD Dr3;
864     DWORD Dr4;
865     DWORD Dr5;
866     DWORD Dr6;
867     DWORD Dr7;
868 } CONTEXT;
869
870 typedef struct _STACK_FRAME_HEADER
871 {
872     DWORD BackChain;
873     DWORD GlueSaved1;
874     DWORD GlueSaved2;
875     DWORD Reserved1;
876     DWORD Spare1;
877     DWORD Spare2;
878
879     DWORD Parameter0;
880     DWORD Parameter1;
881     DWORD Parameter2;
882     DWORD Parameter3;
883     DWORD Parameter4;
884     DWORD Parameter5;
885     DWORD Parameter6;
886     DWORD Parameter7;
887 } STACK_FRAME_HEADER,*PSTACK_FRAME_HEADER;
888
889 #endif  /* __PPC__ */
890
891 #ifdef __sparc__
892
893 /* 
894  * FIXME:  
895  *
896  * There is no official CONTEXT structure defined for the SPARC 
897  * architecture, so I just made one up.
898  *
899  * This structure is valid only for 32-bit SPARC architectures,
900  * not for 64-bit SPARC.
901  *
902  * Note that this structure contains only the 'top-level' registers;
903  * the rest of the register window chain is not visible.
904  *
905  * The layout follows the Solaris 'prgregset_t' structure.
906  * 
907  */ 
908
909 #define CONTEXT_SPARC            0x10000000
910
911 #define CONTEXT_CONTROL         (CONTEXT_SPARC | 0x00000001)
912 #define CONTEXT_FLOATING_POINT  (CONTEXT_SPARC | 0x00000002)
913 #define CONTEXT_INTEGER         (CONTEXT_SPARC | 0x00000004)
914
915 #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER)
916
917 typedef struct _CONTEXT
918 {
919     DWORD ContextFlags;
920
921     /* These are selected by CONTEXT_INTEGER */
922     DWORD g0;
923     DWORD g1;
924     DWORD g2;
925     DWORD g3;
926     DWORD g4;
927     DWORD g5;
928     DWORD g6;
929     DWORD g7;
930     DWORD o0;
931     DWORD o1;
932     DWORD o2;
933     DWORD o3;
934     DWORD o4;
935     DWORD o5;
936     DWORD o6;
937     DWORD o7;
938     DWORD l0;
939     DWORD l1;
940     DWORD l2;
941     DWORD l3;
942     DWORD l4;
943     DWORD l5;
944     DWORD l6;
945     DWORD l7;
946     DWORD i0;
947     DWORD i1;
948     DWORD i2;
949     DWORD i3;
950     DWORD i4;
951     DWORD i5;
952     DWORD i6;
953     DWORD i7;
954
955     /* These are selected by CONTEXT_CONTROL */
956     DWORD psr;
957     DWORD pc;
958     DWORD npc;
959     DWORD y;
960     DWORD wim;
961     DWORD tbr;
962
963     /* FIXME: floating point registers missing */
964
965 } CONTEXT;
966
967 #endif  /* __sparc__ */
968
969 #if !defined(CONTEXT_FULL) && !defined(RC_INVOKED)
970 #error You need to define a CONTEXT for your CPU
971 #endif
972
973 typedef CONTEXT *PCONTEXT;
974 typedef HANDLE *PHANDLE;
975
976 #ifdef __WINE__
977
978 /* Macros for easier access to i386 context registers */
979
980 #define AX_reg(context)      (*(WORD*)&(context)->Eax)
981 #define BX_reg(context)      (*(WORD*)&(context)->Ebx)
982 #define CX_reg(context)      (*(WORD*)&(context)->Ecx)
983 #define DX_reg(context)      (*(WORD*)&(context)->Edx)
984 #define SI_reg(context)      (*(WORD*)&(context)->Esi)
985 #define DI_reg(context)      (*(WORD*)&(context)->Edi)
986 #define BP_reg(context)      (*(WORD*)&(context)->Ebp)
987
988 #define AL_reg(context)      (*(BYTE*)&(context)->Eax)
989 #define AH_reg(context)      (*((BYTE*)&(context)->Eax + 1))
990 #define BL_reg(context)      (*(BYTE*)&(context)->Ebx)
991 #define BH_reg(context)      (*((BYTE*)&(context)->Ebx + 1))
992 #define CL_reg(context)      (*(BYTE*)&(context)->Ecx)
993 #define CH_reg(context)      (*((BYTE*)&(context)->Ecx + 1))
994 #define DL_reg(context)      (*(BYTE*)&(context)->Edx)
995 #define DH_reg(context)      (*((BYTE*)&(context)->Edx + 1))
996
997 #define SET_CFLAG(context)   ((context)->EFlags |= 0x0001)
998 #define RESET_CFLAG(context) ((context)->EFlags &= ~0x0001)
999 #define SET_ZFLAG(context)   ((context)->EFlags |= 0x0040)
1000 #define RESET_ZFLAG(context) ((context)->EFlags &= ~0x0040)
1001 #define ISV86(context)       ((context)->EFlags & 0x00020000)
1002
1003
1004 /* Macros to retrieve the current context */
1005
1006 #ifdef __i386__
1007
1008 #ifdef NEED_UNDERSCORE_PREFIX
1009 # define __ASM_NAME(name) "_" name
1010 #else
1011 # define __ASM_NAME(name) name
1012 #endif
1013
1014 #ifdef NEED_TYPE_IN_DEF
1015 # define __ASM_FUNC(name) ".def " __ASM_NAME(name) "; .scl 2; .type 32; .endef"
1016 #else
1017 # define __ASM_FUNC(name) ".type " __ASM_NAME(name) ",@function"
1018 #endif
1019
1020 #ifdef __GNUC__
1021 # define __ASM_GLOBAL_FUNC(name,code) \
1022       __asm__( ".align 4\n\t" \
1023                ".globl " __ASM_NAME(#name) "\n\t" \
1024                __ASM_FUNC(#name) "\n" \
1025                __ASM_NAME(#name) ":\n\t" \
1026                code );
1027 #else  /* __GNUC__ */
1028 # define __ASM_GLOBAL_FUNC(name,code) \
1029       void __asm_dummy_##name(void) { \
1030           asm( ".align 4\n\t" \
1031                ".globl " __ASM_NAME(#name) "\n\t" \
1032                __ASM_FUNC(#name) "\n" \
1033                __ASM_NAME(#name) ":\n\t" \
1034                code ); \
1035       }
1036 #endif  /* __GNUC__ */
1037
1038 #define _DEFINE_REGS_ENTRYPOINT( name, fn, args ) \
1039     __ASM_GLOBAL_FUNC( name, \
1040                        "call " __ASM_NAME("CALL32_Regs") "\n\t" \
1041                        ".long " __ASM_NAME(#fn) "\n\t" \
1042                        ".byte " #args ", " #args )
1043 #define DEFINE_REGS_ENTRYPOINT_0( name, fn ) \
1044   extern void WINAPI name(void); \
1045   _DEFINE_REGS_ENTRYPOINT( name, fn, 0 )
1046 #define DEFINE_REGS_ENTRYPOINT_1( name, fn, t1 ) \
1047   extern void WINAPI name( t1 a1 ); \
1048   _DEFINE_REGS_ENTRYPOINT( name, fn, 4 )
1049 #define DEFINE_REGS_ENTRYPOINT_2( name, fn, t1, t2 ) \
1050   extern void WINAPI name( t1 a1, t2 a2 ); \
1051   _DEFINE_REGS_ENTRYPOINT( name, fn, 8 )
1052 #define DEFINE_REGS_ENTRYPOINT_3( name, fn, t1, t2, t3 ) \
1053   extern void WINAPI name( t1 a1, t2 a2, t3 a3 ); \
1054   _DEFINE_REGS_ENTRYPOINT( name, fn, 12 )
1055 #define DEFINE_REGS_ENTRYPOINT_4( name, fn, t1, t2, t3, t4 ) \
1056   extern void WINAPI name( t1 a1, t2 a2, t3 a3, t4 a4 ); \
1057   _DEFINE_REGS_ENTRYPOINT( name, fn, 16 )
1058
1059 #endif  /* __i386__ */
1060
1061 #ifdef __sparc__
1062 /* FIXME: use getcontext() to retrieve full context */
1063 #define _GET_CONTEXT \
1064     CONTEXT context;   \
1065     do { memset(&context, 0, sizeof(CONTEXT));            \
1066          context.ContextFlags = CONTEXT_CONTROL;          \
1067          context.pc = (DWORD)__builtin_return_address(0); \
1068        } while (0)
1069
1070 #define DEFINE_REGS_ENTRYPOINT_0( name, fn ) \
1071   void WINAPI name ( void ) \
1072   { _GET_CONTEXT; fn( &context ); }
1073 #define DEFINE_REGS_ENTRYPOINT_1( name, fn, t1 ) \
1074   void WINAPI name ( t1 a1 ) \
1075   { _GET_CONTEXT; fn( a1, &context ); }
1076 #define DEFINE_REGS_ENTRYPOINT_2( name, fn, t1, t2 ) \
1077   void WINAPI name ( t1 a1, t2 a2 ) \
1078   { _GET_CONTEXT; fn( a1, a2, &context ); }
1079 #define DEFINE_REGS_ENTRYPOINT_3( name, fn, t1, t2, t3 ) \
1080   void WINAPI name ( t1 a1, t2 a2, t3 a3 ) \
1081   { _GET_CONTEXT; fn( a1, a2, a3, &context ); }
1082 #define DEFINE_REGS_ENTRYPOINT_4( name, fn, t1, t2, t3, t4 ) \
1083   void WINAPI name ( t1 a1, t2 a2, t3 a3, t4 a4 ) \
1084   { _GET_CONTEXT; fn( a1, a2, a3, a4, &context ); }
1085
1086 #endif /* __sparc__ */
1087
1088 #ifndef DEFINE_REGS_ENTRYPOINT_0
1089 #error You need to define DEFINE_REGS_ENTRYPOINT macros for your CPU
1090 #endif
1091
1092 /* Constructor functions */
1093
1094 #ifdef __GNUC__
1095 # define DECL_GLOBAL_CONSTRUCTOR(func) \
1096     static void func(void) __attribute__((constructor)); \
1097     static void func(void)
1098 #else  /* __GNUC__ */
1099 # ifdef __i386__
1100 #  define DECL_GLOBAL_CONSTRUCTOR(func) \
1101     static void __dummy_init_##func(void) { \
1102         asm(".section .init,\"ax\"\n\t" \
1103             "call " #func "\n\t" \
1104             ".previous"); } \
1105     static void func(void)
1106 # else  /* __i386__ */
1107 #  error You must define the DECL_GLOBAL_CONSTRUCTOR macro for your platform
1108 # endif
1109 #endif  /* __GNUC__ */
1110
1111 /* Segment register access */
1112
1113 #ifdef __i386__
1114 # ifdef __GNUC__
1115 #  define __DEFINE_GET_SEG(seg) \
1116     extern inline unsigned short __get_##seg(void) \
1117     { unsigned short res; __asm__("movw %%" #seg ",%w0" : "=r"(res)); return res; }
1118 #  define __DEFINE_SET_SEG(seg) \
1119     extern inline void __set_##seg(int val) { __asm__("movw %w0,%%" #seg : : "r" (val)); }
1120 # else  /* __GNUC__ */
1121 #  define __DEFINE_GET_SEG(seg) extern unsigned short __get_##seg(void);
1122 #  define __DEFINE_SET_SEG(seg) extern void __set_##seg(unsigned int);
1123 # endif /* __GNUC__ */
1124 #else  /* __i386__ */
1125 # define __DEFINE_GET_SEG(seg) inline static unsigned short __get_##seg(void) { return 0; }
1126 # define __DEFINE_SET_SEG(seg) /* nothing */
1127 #endif  /* __i386__ */
1128
1129 __DEFINE_GET_SEG(cs)
1130 __DEFINE_GET_SEG(ds)
1131 __DEFINE_GET_SEG(es)
1132 __DEFINE_GET_SEG(fs)
1133 __DEFINE_GET_SEG(gs)
1134 __DEFINE_GET_SEG(ss)
1135 __DEFINE_SET_SEG(fs)
1136 __DEFINE_SET_SEG(gs)
1137 #undef __DEFINE_GET_SEG
1138 #undef __DEFINE_SET_SEG
1139
1140 #endif  /* __WINE__ */
1141
1142
1143
1144 /*
1145  * Language IDs
1146  */
1147
1148 #define MAKELCID(l, s)          (MAKELONG(l, s))
1149
1150 #define MAKELANGID(p, s)        ((((WORD)(s))<<10) | (WORD)(p))
1151 #define PRIMARYLANGID(l)        ((WORD)(l) & 0x3ff)
1152 #define SUBLANGID(l)            ((WORD)(l) >> 10)
1153
1154 #define LANGIDFROMLCID(lcid)    ((WORD)(lcid))
1155 #define SORTIDFROMLCID(lcid)    ((WORD)((((DWORD)(lcid)) >> 16) & 0x0f))
1156
1157 #define LANG_SYSTEM_DEFAULT     (MAKELANGID(LANG_NEUTRAL, SUBLANG_SYS_DEFAULT))
1158 #define LANG_USER_DEFAULT       (MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT))
1159 #define LOCALE_SYSTEM_DEFAULT   (MAKELCID(LANG_SYSTEM_DEFAULT, SORT_DEFAULT))
1160 #define LOCALE_USER_DEFAULT     (MAKELCID(LANG_USER_DEFAULT, SORT_DEFAULT)) 
1161 #define LOCALE_NEUTRAL          (MAKELCID(MAKELANGID(LANG_NEUTRAL,SUBLANG_NEUTRAL),SORT_DEFAULT))
1162
1163 /* FIXME: are the symbolic names correct for LIDs:  0x17, 0x20, 0x28,
1164  *        0x2a, 0x2b, 0x2c, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35,
1165  *        0x37, 0x39, 0x3a, 0x3b, 0x3c, 0x3e, 0x3f, 0x41, 0x43, 0x44,
1166  *        0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e,
1167  *        0x4f, 0x57
1168  */
1169 #define LANG_NEUTRAL                     0x00
1170 #define LANG_AFRIKAANS                   0x36
1171 #define LANG_ALBANIAN                    0x1c
1172 #define LANG_ARABIC                      0x01
1173 #define LANG_ARMENIAN                    0x2b
1174 #define LANG_ASSAMESE                    0x4d
1175 #define LANG_AZERI                       0x2c
1176 #define LANG_BASQUE                      0x2d
1177 #define LANG_BENGALI                     0x45
1178 #define LANG_BULGARIAN                   0x02
1179 #define LANG_BYELORUSSIAN                0x23
1180 #define LANG_CATALAN                     0x03
1181 #define LANG_CHINESE                     0x04
1182 #define LANG_SERBO_CROATIAN              0x1a
1183 #define LANG_CROATIAN     LANG_SERBO_CROATIAN
1184 #define LANG_SERBIAN      LANG_SERBO_CROATIAN
1185 #define LANG_CZECH                       0x05
1186 #define LANG_DANISH                      0x06
1187 #define LANG_DUTCH                       0x13
1188 #define LANG_ENGLISH                     0x09
1189 #define LANG_ESTONIAN                    0x25
1190 #define LANG_FAEROESE                    0x38
1191 #define LANG_FARSI                       0x29
1192 #define LANG_FINNISH                     0x0b
1193 #define LANG_FRENCH                      0x0c
1194 #define LANG_GAELIC                      0x3c
1195 #define LANG_GEORGIAN                    0x37
1196 #define LANG_GERMAN                      0x07
1197 #define LANG_GREEK                       0x08
1198 #define LANG_GUJARATI                    0x47
1199 #define LANG_HEBREW                      0x0D
1200 #define LANG_HINDI                       0x39
1201 #define LANG_HUNGARIAN                   0x0e
1202 #define LANG_ICELANDIC                   0x0f
1203 #define LANG_INDONESIAN                  0x21
1204 #define LANG_ITALIAN                     0x10
1205 #define LANG_JAPANESE                    0x11
1206 #define LANG_KANNADA                     0x4b
1207 #define LANG_KAZAKH                      0x3f
1208 #define LANG_KONKANI                     0x57
1209 #define LANG_KOREAN                      0x12
1210 #define LANG_LATVIAN                     0x26
1211 #define LANG_LITHUANIAN                  0x27
1212 #define LANG_MACEDONIAN                  0x2f
1213 #define LANG_MALAY                       0x3e
1214 #define LANG_MALAYALAM                   0x4c
1215 #define LANG_MALTESE                     0x3a
1216 #define LANG_MAORI                       0x28
1217 #define LANG_MARATHI                     0x4e
1218 #define LANG_NORWEGIAN                   0x14
1219 #define LANG_ORIYA                       0x48
1220 #define LANG_POLISH                      0x15
1221 #define LANG_PORTUGUESE                  0x16
1222 #define LANG_PUNJABI                     0x46
1223 #define LANG_RHAETO_ROMANCE              0x17
1224 #define LANG_ROMANIAN                    0x18
1225 #define LANG_RUSSIAN                     0x19
1226 #define LANG_SAAMI                       0x3b
1227 #define LANG_SANSKRIT                    0x4f
1228 #define LANG_SLOVAK                      0x1b
1229 #define LANG_SLOVENIAN                   0x24
1230 #define LANG_SORBIAN                     0x2e
1231 #define LANG_SPANISH                     0x0a
1232 #define LANG_SUTU                        0x30
1233 #define LANG_SWAHILI                     0x41
1234 #define LANG_SWEDISH                     0x1d
1235 #define LANG_TAMIL                       0x49
1236 #define LANG_TATAR                       0x44
1237 #define LANG_TELUGU                      0x4a
1238 #define LANG_THAI                        0x1e
1239 #define LANG_TSONGA                      0x31
1240 #define LANG_TSWANA                      0x32
1241 #define LANG_TURKISH                     0x1f
1242 #define LANG_UKRAINIAN                   0x22
1243 #define LANG_URDU                        0x20
1244 #define LANG_UZBEK                       0x43
1245 #define LANG_VENDA                       0x33
1246 #define LANG_VIETNAMESE                  0x2a
1247 #define LANG_XHOSA                       0x34
1248 #define LANG_ZULU                        0x35
1249 /* non standard; keep the number high enough (but < 0xff) */
1250 #define LANG_ESPERANTO                   0x8f
1251 #define LANG_WALON                       0x90
1252 #define LANG_CORNISH                     0x91
1253 #define LANG_WELSH                       0x92
1254 #define LANG_BRETON                      0x93
1255
1256 /* Sublanguage definitions */
1257 #define SUBLANG_NEUTRAL                  0x00    /* language neutral */
1258 #define SUBLANG_DEFAULT                  0x01    /* user default */
1259 #define SUBLANG_SYS_DEFAULT              0x02    /* system default */
1260
1261 #define SUBLANG_ARABIC                   0x01
1262 #define SUBLANG_ARABIC_SAUDI_ARABIA      0x01
1263 #define SUBLANG_ARABIC_IRAQ              0x02
1264 #define SUBLANG_ARABIC_EGYPT             0x03
1265 #define SUBLANG_ARABIC_LIBYA             0x04
1266 #define SUBLANG_ARABIC_ALGERIA           0x05
1267 #define SUBLANG_ARABIC_MOROCCO           0x06
1268 #define SUBLANG_ARABIC_TUNISIA           0x07
1269 #define SUBLANG_ARABIC_OMAN              0x08
1270 #define SUBLANG_ARABIC_YEMEN             0x09
1271 #define SUBLANG_ARABIC_SYRIA             0x0a
1272 #define SUBLANG_ARABIC_JORDAN            0x0b
1273 #define SUBLANG_ARABIC_LEBANON           0x0c
1274 #define SUBLANG_ARABIC_KUWAIT            0x0d
1275 #define SUBLANG_ARABIC_UAE               0x0e
1276 #define SUBLANG_ARABIC_BAHRAIN           0x0f
1277 #define SUBLANG_ARABIC_QATAR             0x10
1278 #define SUBLANG_CHINESE_TRADITIONAL      0x01
1279 #define SUBLANG_CHINESE_SIMPLIFIED       0x02
1280 #define SUBLANG_CHINESE_HONGKONG         0x03
1281 #define SUBLANG_CHINESE_SINGAPORE        0x04
1282 #define SUBLANG_CHINESE_MACAU            0x05
1283 #define SUBLANG_DUTCH                    0x01
1284 #define SUBLANG_DUTCH_BELGIAN            0x02
1285 #define SUBLANG_DUTCH_SURINAM            0x03
1286 #define SUBLANG_ENGLISH_US               0x01
1287 #define SUBLANG_ENGLISH_UK               0x02
1288 #define SUBLANG_ENGLISH_AUS              0x03
1289 #define SUBLANG_ENGLISH_CAN              0x04
1290 #define SUBLANG_ENGLISH_NZ               0x05
1291 #define SUBLANG_ENGLISH_EIRE             0x06
1292 #define SUBLANG_ENGLISH_SAFRICA          0x07
1293 #define SUBLANG_ENGLISH_JAMAICA          0x08
1294 #define SUBLANG_ENGLISH_CARRIBEAN        0x09
1295 #define SUBLANG_ENGLISH_BELIZE           0x0a
1296 #define SUBLANG_ENGLISH_TRINIDAD         0x0b
1297 #define SUBLANG_ENGLISH_ZIMBABWE         0x0c
1298 #define SUBLANG_ENGLISH_PHILIPPINES      0x0d
1299 #define SUBLANG_FRENCH                   0x01
1300 #define SUBLANG_FRENCH_BELGIAN           0x02
1301 #define SUBLANG_FRENCH_CANADIAN          0x03
1302 #define SUBLANG_FRENCH_SWISS             0x04
1303 #define SUBLANG_FRENCH_LUXEMBOURG        0x05
1304 #define SUBLANG_FRENCH_MONACO            0x06
1305 #define SUBLANG_GERMAN                   0x01
1306 #define SUBLANG_GERMAN_SWISS             0x02
1307 #define SUBLANG_GERMAN_AUSTRIAN          0x03
1308 #define SUBLANG_GERMAN_LUXEMBOURG        0x04
1309 #define SUBLANG_GERMAN_LIECHTENSTEIN     0x05
1310 #define SUBLANG_ITALIAN                  0x01
1311 #define SUBLANG_ITALIAN_SWISS            0x02
1312 #define SUBLANG_KOREAN                   0x01
1313 #define SUBLANG_KOREAN_JOHAB             0x02
1314 #define SUBLANG_NORWEGIAN_BOKMAL         0x01
1315 #define SUBLANG_NORWEGIAN_NYNORSK        0x02
1316 #define SUBLANG_PORTUGUESE               0x02
1317 #define SUBLANG_PORTUGUESE_BRAZILIAN     0x01
1318 #define SUBLANG_SPANISH                  0x01
1319 #define SUBLANG_SPANISH_MEXICAN          0x02
1320 #define SUBLANG_SPANISH_MODERN           0x03
1321 #define SUBLANG_SPANISH_GUATEMALA        0x04
1322 #define SUBLANG_SPANISH_COSTARICA        0x05
1323 #define SUBLANG_SPANISH_PANAMA           0x06
1324 #define SUBLANG_SPANISH_DOMINICAN        0x07
1325 #define SUBLANG_SPANISH_VENEZUELA        0x08
1326 #define SUBLANG_SPANISH_COLOMBIA         0x09
1327 #define SUBLANG_SPANISH_PERU             0x0a
1328 #define SUBLANG_SPANISH_ARGENTINA        0x0b
1329 #define SUBLANG_SPANISH_ECUADOR          0x0c
1330 #define SUBLANG_SPANISH_CHILE            0x0d
1331 #define SUBLANG_SPANISH_URUGUAY          0x0e
1332 #define SUBLANG_SPANISH_PARAGUAY         0x0f
1333 #define SUBLANG_SPANISH_BOLIVIA          0x10
1334 #define SUBLANG_SPANISH_EL_SALVADOR      0x11
1335 #define SUBLANG_SPANISH_HONDURAS         0x12
1336 #define SUBLANG_SPANISH_NICARAGUA        0x13
1337 #define SUBLANG_SPANISH_PUERTO_RICO      0x14
1338 /* FIXME: I don't know the symbolic names for those */
1339 #define SUBLANG_ROMANIAN                 0x01
1340 #define SUBLANG_ROMANIAN_MOLDAVIA        0x02
1341 #define SUBLANG_RUSSIAN                  0x01
1342 #define SUBLANG_RUSSIAN_MOLDAVIA         0x02
1343 #define SUBLANG_CROATIAN                 0x01
1344 #define SUBLANG_SERBIAN                  0x02
1345 #define SUBLANG_SERBIAN_LATIN            0x03
1346 #define SUBLANG_SWEDISH                  0x01
1347 #define SUBLANG_SWEDISH_FINLAND          0x02
1348 #define SUBLANG_LITHUANIAN               0x01
1349 #define SUBLANG_LITHUANIAN_CLASSIC       0x02
1350 #define SUBLANG_AZERI                    0x01
1351 #define SUBLANG_AZERI_CYRILLIC           0x02
1352 #define SUBLANG_GAELIC                   0x01
1353 #define SUBLANG_GAELIC_SCOTTISH          0x02
1354 #define SUBLANG_GAELIC_MANX              0x03
1355 #define SUBLANG_MALAY                    0x01
1356 #define SUBLANG_MALAY_BRUNEI_DARUSSALAM  0x02
1357 #define SUBLANG_UZBEK                    0x01
1358 #define SUBLANG_UZBEK_CYRILLIC           0x02
1359 #define SUBLANG_URDU_PAKISTAN            0x01
1360
1361
1362
1363 /*
1364  * Sort definitions
1365  */
1366
1367 #define SORT_DEFAULT                     0x0
1368 #define SORT_JAPANESE_XJIS               0x0
1369 #define SORT_JAPANESE_UNICODE            0x1
1370 #define SORT_CHINESE_BIG5                0x0
1371 #define SORT_CHINESE_UNICODE             0x1
1372 #define SORT_KOREAN_KSC                  0x0
1373 #define SORT_KOREAN_UNICODE              0x1
1374
1375
1376
1377 /*
1378  * Definitions for IsTextUnicode()
1379  */
1380
1381 #define IS_TEXT_UNICODE_ASCII16            0x0001
1382 #define IS_TEXT_UNICODE_STATISTICS         0x0002
1383 #define IS_TEXT_UNICODE_CONTROLS           0x0004
1384 #define IS_TEXT_UNICODE_SIGNATURE          0x0008
1385 #define IS_TEXT_UNICODE_UNICODE_MASK       0x000F
1386 #define IS_TEXT_UNICODE_REVERSE_ASCII16    0x0010
1387 #define IS_TEXT_UNICODE_REVERSE_STATISTICS 0x0020
1388 #define IS_TEXT_UNICODE_REVERSE_CONTROLS   0x0040
1389 #define IS_TEXT_UNICODE_REVERSE_SIGNATURE  0x0080
1390 #define IS_TEXT_UNICODE_REVERSE_MASK       0x00F0
1391 #define IS_TEXT_UNICODE_ILLEGAL_CHARS      0x0100
1392 #define IS_TEXT_UNICODE_ODD_LENGTH         0x0200
1393 #define IS_TEXT_UNICODE_DBCS_LEADBYTE      0x0400
1394 #define IS_TEXT_UNICODE_NOT_UNICODE_MASK   0x0F00
1395 #define IS_TEXT_UNICODE_NULL_BYTES         0x1000
1396 #define IS_TEXT_UNICODE_NOT_ASCII_MASK     0xF000
1397
1398
1399
1400 /*
1401  * Exception codes
1402  */
1403
1404 #define STATUS_SUCCESS                   0x00000000
1405 #define STATUS_WAIT_0                    0x00000000
1406 #define STATUS_ABANDONED_WAIT_0          0x00000080
1407 #define STATUS_USER_APC                  0x000000C0
1408 #define STATUS_TIMEOUT                   0x00000102
1409 #define STATUS_PENDING                   0x00000103
1410
1411 #define STATUS_GUARD_PAGE_VIOLATION      0x80000001    
1412 #define STATUS_DATATYPE_MISALIGNMENT     0x80000002
1413 #define STATUS_BREAKPOINT                0x80000003
1414 #define STATUS_SINGLE_STEP               0x80000004
1415 #define STATUS_BUFFER_OVERFLOW           0x80000005
1416 #define STATUS_NO_MORE_FILES             0x80000006
1417 #define STATUS_WAKE_SYSTEM_DEBUGGER      0x80000007
1418
1419 #define STATUS_HANDLES_CLOSED            0x8000000A
1420 #define STATUS_NO_INHERITANCE            0x8000000B
1421 #define STATUS_GUID_SUBSTITUTION_MADE    0x8000000C
1422 #define STATUS_PARTIAL_COPY              0x8000000D
1423 #define STATUS_DEVICE_PAPER_EMPTY        0x8000000E
1424 #define STATUS_DEVICE_POWERED_OFF        0x8000000F
1425 #define STATUS_DEVICE_OFF_LINE           0x80000010
1426 #define STATUS_DEVICE_BUSY               0x80000011
1427 #define STATUS_NO_MORE_EAS               0x80000012
1428 #define STATUS_INVALID_EA_NAME           0x80000013
1429 #define STATUS_EA_LIST_INCONSISTENT      0x80000014
1430 #define STATUS_INVALID_EA_FLAG           0x80000015
1431 #define STATUS_VERIFY_REQUIRED           0x80000016
1432 #define STATUS_EXTRANEOUS_INFORMATION    0x80000017
1433 #define STATUS_RXACT_COMMIT_NECESSARY    0x80000018
1434 #define STATUS_NO_MORE_ENTRIES           0x8000001A
1435 #define STATUS_FILEMARK_DETECTED         0x8000001B
1436 #define STATUS_MEDIA_CHANGED             0x8000001C
1437 #define STATUS_BUS_RESET                 0x8000001D
1438 #define STATUS_END_OF_MEDIA              0x8000001E
1439 #define STATUS_BEGINNING_OF_MEDIA        0x8000001F
1440 #define STATUS_MEDIA_CHECK               0x80000020
1441 #define STATUS_SETMARK_DETECTED          0x80000021
1442 #define STATUS_NO_DATA_DETECTED          0x80000022
1443 #define STATUS_REDIRECTOR_HAS_OPEN_HANDLES 0x80000023
1444 #define STATUS_SERVER_HAS_OPEN_HANDLES   0x80000024
1445 #define STATUS_ALREADY_DISCONNECTED      0x80000025
1446 #define STATUS_LONGJUMP                  0x80000026
1447
1448 #define STATUS_UNSUCCESSFUL              0xC0000001
1449 #define STATUS_NOT_IMPLEMENTED           0xC0000002
1450 #define STATUS_INVALID_INFO_CLASS        0xC0000003
1451 #define STATUS_INFO_LENGTH_MISMATCH      0xC0000004
1452 #define STATUS_ACCESS_VIOLATION          0xC0000005
1453 #define STATUS_IN_PAGE_ERROR             0xC0000006
1454 #define STATUS_PAGEFILE_QUOTA            0xC0000007
1455 #define STATUS_INVALID_HANDLE            0xC0000008
1456 #define STATUS_BAD_INITIAL_STACK         0xC0000009
1457 #define STATUS_BAD_INITIAL_PC            0xC000000A
1458 #define STATUS_INVALID_CID               0xC000000B
1459 #define STATUS_TIMER_NOT_CANCELED        0xC000000C
1460 #define STATUS_INVALID_PARAMETER         0xC000000D
1461 #define STATUS_NO_SUCH_DEVICE            0xC000000E
1462 #define STATUS_NO_SUCH_FILE              0xC000000F
1463 #define STATUS_INVALID_DEVICE_REQUEST    0xC0000010
1464 #define STATUS_END_OF_FILE               0xC0000011
1465 #define STATUS_WRONG_VOLUME              0xC0000012
1466 #define STATUS_NO_MEDIA_IN_DEVICE        0xC0000013
1467 #define STATUS_UNRECOGNIZED_MEDIA        0xC0000014
1468 #define STATUS_NONEXISTENT_SECTOR        0xC0000015
1469 #define STATUS_MORE_PROCESSING_REQUIRED  0xC0000016
1470 #define STATUS_NO_MEMORY                 0xC0000017
1471 #define STATUS_CONFLICTING_ADDRESSES     0xC0000018
1472 #define STATUS_NOT_MAPPED_VIEW           0xC0000019
1473 #define STATUS_UNABLE_TO_FREE_VM         0xC000001A
1474 #define STATUS_UNABLE_TO_DELETE_SECTION  0xC000001B
1475 #define STATUS_INVALID_SYSTEM_SERVICE    0xC000001C
1476 #define STATUS_ILLEGAL_INSTRUCTION       0xC000001D
1477 #define STATUS_INVALID_LOCK_SEQUENCE     0xC000001E
1478 #define STATUS_INVALID_VIEW_SIZE         0xC000001F
1479 #define STATUS_INVALID_FILE_FOR_SECTION  0xC0000020
1480 #define STATUS_ALREADY_COMMITTED         0xC0000021
1481 #define STATUS_ACCESS_DENIED             0xC0000022
1482 #define STATUS_BUFFER_TOO_SMALL          0xC0000023
1483 #define STATUS_OBJECT_TYPE_MISMATCH      0xC0000024
1484 #define STATUS_NONCONTINUABLE_EXCEPTION  0xC0000025
1485 #define STATUS_INVALID_DISPOSITION       0xC0000026
1486 #define STATUS_UNWIND                    0xC0000027
1487 #define STATUS_BAD_STACK                 0xC0000028
1488 #define STATUS_INVALID_UNWIND_TARGET     0xC0000029
1489 #define STATUS_NOT_LOCKED                0xC000002A
1490 #define STATUS_PARITY_ERROR              0xC000002B
1491 #define STATUS_UNABLE_TO_DECOMMIT_VM     0xC000002C
1492 #define STATUS_NOT_COMMITTED             0xC000002D
1493 #define STATUS_INVALID_PORT_ATTRIBUTES   0xC000002E
1494 #define STATUS_PORT_MESSAGE_TOO_LONG     0xC000002F
1495 #define STATUS_INVALID_PARAMETER_MIX     0xC0000030
1496 #define STATUS_INVALID_QUOTA_LOWER       0xC0000031
1497 #define STATUS_DISK_CORRUPT_ERROR        0xC0000032
1498 #define STATUS_OBJECT_NAME_INVALID       0xC0000033
1499 #define STATUS_OBJECT_NAME_NOT_FOUND     0xC0000034
1500 #define STATUS_OBJECT_NAME_COLLISION     0xC0000035
1501 #define STATUS_PORT_DISCONNECTED         0xC0000037
1502 #define STATUS_DEVICE_ALREADY_ATTACHED   0xC0000038
1503 #define STATUS_OBJECT_PATH_INVALID       0xC0000039
1504 #define STATUS_OBJECT_PATH_NOT_FOUND     0xC000003A
1505 #define STATUS_PATH_SYNTAX_BAD           0xC000003B
1506 #define STATUS_DATA_OVERRUN              0xC000003C
1507 #define STATUS_DATA_LATE_ERROR           0xC000003D
1508 #define STATUS_DATA_ERROR                0xC000003E
1509 #define STATUS_CRC_ERROR                 0xC000003F
1510 #define STATUS_SECTION_TOO_BIG           0xC0000040
1511 #define STATUS_PORT_CONNECTION_REFUSED   0xC0000041
1512 #define STATUS_INVALID_PORT_HANDLE       0xC0000042
1513 #define STATUS_SHARING_VIOLATION         0xC0000043
1514 #define STATUS_QUOTA_EXCEEDED            0xC0000044
1515 #define STATUS_INVALID_PAGE_PROTECTION   0xC0000045
1516 #define STATUS_MUTANT_NOT_OWNED          0xC0000046
1517 #define STATUS_SEMAPHORE_LIMIT_EXCEEDED  0xC0000047
1518 #define STATUS_PORT_ALREADY_SET          0xC0000048
1519 #define STATUS_SUSPEND_COUNT_EXCEEDED    0xC000004A
1520 #define STATUS_LOCK_NOT_GRANTED          0xC0000054  /* FIXME: not sure */
1521 #define STATUS_FILE_LOCK_CONFLICT        0xC0000055  /* FIXME: not sure */
1522 #define STATUS_UNKNOWN_REVISION          0xC0000058
1523 #define STATUS_INVALID_SECURITY_DESCR    0xC0000079
1524 #define STATUS_DISK_FULL                 0xC000007F 
1525 #define STATUS_SECTION_NOT_EXTENDED      0xC0000087
1526 #define STATUS_ARRAY_BOUNDS_EXCEEDED     0xC000008C
1527 #define STATUS_FLOAT_DENORMAL_OPERAND    0xC000008D
1528 #define STATUS_FLOAT_DIVIDE_BY_ZERO      0xC000008E
1529 #define STATUS_FLOAT_INEXACT_RESULT      0xC000008F
1530 #define STATUS_FLOAT_INVALID_OPERATION   0xC0000090
1531 #define STATUS_FLOAT_OVERFLOW            0xC0000091
1532 #define STATUS_FLOAT_STACK_CHECK         0xC0000092
1533 #define STATUS_FLOAT_UNDERFLOW           0xC0000093
1534 #define STATUS_INTEGER_DIVIDE_BY_ZERO    0xC0000094
1535 #define STATUS_INTEGER_OVERFLOW          0xC0000095
1536 #define STATUS_PRIVILEGED_INSTRUCTION    0xC0000096
1537 #define STATUS_MEDIA_WRITE_PROTECTED     0XC00000A2
1538 #define STATUS_INVALID_PARAMETER_2       0xC00000F0
1539 #define STATUS_STACK_OVERFLOW            0xC00000FD
1540 #define STATUS_DIRECTORY_NOT_EMPTY       0xC0000101
1541 #define STATUS_TOO_MANY_OPENED_FILES     0xC000011F
1542 #define STATUS_CONTROL_C_EXIT            0xC000013A
1543 #define STATUS_PIPE_BROKEN               0xC000014B
1544 #define STATUS_NOT_REGISTRY_FILE         0xC000015C
1545 #define STATUS_PARTITION_FAILURE         0xC0000172
1546 #define STATUS_INVALID_BLOCK_LENGTH      0xC0000173
1547 #define STATUS_DEVICE_NOT_PARTITIONED    0xC0000174
1548 #define STATUS_UNABLE_TO_LOCK_MEDIA      0xC0000175
1549 #define STATUS_UNABLE_TO_UNLOAD_MEDIA    0xC0000176
1550 #define STATUS_EOM_OVERFLOW              0xC0000177
1551 #define STATUS_NO_MEDIA                  0xC0000178
1552 #define STATUS_NO_SUCH_MEMBER            0xC000017A
1553 #define STATUS_INVALID_MEMBER            0xC000017B
1554 #define STATUS_KEY_DELETED               0xC000017C
1555 #define STATUS_NO_LOG_SPACE              0xC000017D
1556 #define STATUS_TOO_MANY_SIDS             0xC000017E
1557 #define STATUS_LM_CROSS_ENCRYPTION_REQUIRED 0xC000017F
1558 #define STATUS_KEY_HAS_CHILDREN          0xC0000180
1559 #define STATUS_CHILD_MUST_BE_VOLATILE    0xC0000181
1560 #define STATUS_DEVICE_CONFIGURATION_ERROR0xC0000182
1561 #define STATUS_DRIVER_INTERNAL_ERROR     0xC0000183
1562 #define STATUS_INVALID_DEVICE_STATE      0xC0000184
1563 #define STATUS_IO_DEVICE_ERROR           0xC0000185
1564 #define STATUS_DEVICE_PROTOCOL_ERROR     0xC0000186
1565 #define STATUS_BACKUP_CONTROLLER         0xC0000187
1566 #define STATUS_LOG_FILE_FULL             0xC0000188
1567 #define STATUS_TOO_LATE                  0xC0000189
1568 #define STATUS_NO_TRUST_LSA_SECRET       0xC000018A
1569 #define STATUS_NO_TRUST_SAM_ACCOUNT      0xC000018B
1570 #define STATUS_TRUSTED_DOMAIN_FAILURE    0xC000018C
1571 #define STATUS_TRUSTED_RELATIONSHIP_FAILURE 0xC000018D
1572 #define STATUS_EVENTLOG_FILE_CORRUPT     0xC000018E
1573 #define STATUS_EVENTLOG_CANT_START       0xC000018F
1574 #define STATUS_TRUST_FAILURE             0xC0000190
1575 #define STATUS_MUTANT_LIMIT_EXCEEDED     0xC0000191
1576 #define STATUS_NETLOGON_NOT_STARTED      0xC0000192
1577 #define STATUS_ACCOUNT_EXPIRED           0xC0000193
1578 #define STATUS_POSSIBLE_DEADLOCK         0xC0000194
1579 #define STATUS_NETWORK_CREDENTIAL_CONFLICT 0xC0000195
1580 #define STATUS_REMOTE_SESSION_LIMIT      0xC0000196
1581 #define STATUS_EVENTLOG_FILE_CHANGED     0xC0000197
1582 #define STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT 0xC0000198
1583 #define STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT 0xC0000199
1584 #define STATUS_NOLOGON_SERVER_TRUST_ACCOUNT 0xC000019A
1585 #define STATUS_DOMAIN_TRUST_INCONSISTENT 0xC000019B
1586 #define STATUS_FS_DRIVER_REQUIRED        0xC000019C
1587
1588 #define STATUS_RESOURCE_LANG_NOT_FOUND   0xC0000204
1589
1590 #define MAXIMUM_WAIT_OBJECTS 64
1591 #define MAXIMUM_SUSPEND_COUNT 127
1592
1593
1594 /*
1595  * Return values from the actual exception handlers
1596  */
1597
1598 #define ExceptionContinueExecution 0
1599 #define ExceptionContinueSearch    1
1600 #define ExceptionNestedException   2
1601 #define ExceptionCollidedUnwind    3
1602  
1603 /*
1604  * Return values from filters in except() and from UnhandledExceptionFilter
1605  */
1606  
1607 #define EXCEPTION_EXECUTE_HANDLER        1
1608 #define EXCEPTION_CONTINUE_SEARCH        0
1609 #define EXCEPTION_CONTINUE_EXECUTION    -1
1610
1611 /*
1612  * From OS/2 2.0 exception handling
1613  * Win32 seems to use the same flags as ExceptionFlags in an EXCEPTION_RECORD
1614  */
1615
1616 #define EH_NONCONTINUABLE   0x01
1617 #define EH_UNWINDING        0x02
1618 #define EH_EXIT_UNWIND      0x04
1619 #define EH_STACK_INVALID    0x08
1620 #define EH_NESTED_CALL      0x10
1621
1622 #define EXCEPTION_CONTINUABLE        0
1623 #define EXCEPTION_NONCONTINUABLE     EH_NONCONTINUABLE
1624  
1625 /*
1626  * The exception record used by Win32 to give additional information 
1627  * about exception to exception handlers.
1628  */
1629
1630 #define EXCEPTION_MAXIMUM_PARAMETERS 15
1631
1632 typedef struct __EXCEPTION_RECORD
1633 {
1634     DWORD    ExceptionCode;
1635     DWORD    ExceptionFlags;
1636     struct __EXCEPTION_RECORD *ExceptionRecord;
1637
1638     LPVOID   ExceptionAddress;
1639     DWORD    NumberParameters;
1640     DWORD    ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
1641 } EXCEPTION_RECORD, *PEXCEPTION_RECORD;
1642
1643 /*
1644  * The exception pointers structure passed to exception filters
1645  * in except() and the UnhandledExceptionFilter().
1646  */
1647  
1648 typedef struct _EXCEPTION_POINTERS 
1649 {
1650   PEXCEPTION_RECORD  ExceptionRecord;
1651   PCONTEXT           ContextRecord;
1652 } EXCEPTION_POINTERS, *PEXCEPTION_POINTERS;
1653
1654
1655 /*
1656  * The exception frame, used for registering exception handlers 
1657  * Win32 cares only about this, but compilers generally emit 
1658  * larger exception frames for their own use.
1659  */
1660
1661 struct __EXCEPTION_FRAME;
1662
1663 typedef DWORD (*PEXCEPTION_HANDLER)(PEXCEPTION_RECORD,struct __EXCEPTION_FRAME*,
1664                                     PCONTEXT,struct __EXCEPTION_FRAME **);
1665
1666 typedef struct __EXCEPTION_FRAME
1667 {
1668   struct __EXCEPTION_FRAME *Prev;
1669   PEXCEPTION_HANDLER       Handler;
1670 } EXCEPTION_FRAME, *PEXCEPTION_FRAME;
1671
1672 #include "poppack.h"
1673
1674 /*
1675  * function pointer to a exception filter
1676  */
1677
1678 typedef LONG CALLBACK (*PTOP_LEVEL_EXCEPTION_FILTER)(PEXCEPTION_POINTERS ExceptionInfo);
1679 typedef PTOP_LEVEL_EXCEPTION_FILTER LPTOP_LEVEL_EXCEPTION_FILTER;
1680
1681 DWORD WINAPI UnhandledExceptionFilter( PEXCEPTION_POINTERS epointers );
1682 LPTOP_LEVEL_EXCEPTION_FILTER
1683 WINAPI SetUnhandledExceptionFilter( LPTOP_LEVEL_EXCEPTION_FILTER filter );
1684
1685 /* status values for ContinueDebugEvent */
1686 #define DBG_CONTINUE                0x00010002
1687 #define DBG_TERMINATE_THREAD        0x40010003
1688 #define DBG_TERMINATE_PROCESS       0x40010004
1689 #define DBG_CONTROL_C               0x40010005
1690 #define DBG_CONTROL_BREAK           0x40010008
1691 #define DBG_EXCEPTION_NOT_HANDLED   0x80010001
1692
1693 typedef struct _NT_TIB 
1694 {
1695         struct _EXCEPTION_REGISTRATION_RECORD *ExceptionList;
1696         PVOID StackBase;
1697         PVOID StackLimit;
1698         PVOID SubSystemTib;
1699         union {
1700           PVOID FiberData;
1701           DWORD Version;
1702         } DUMMYUNIONNAME;
1703         PVOID ArbitraryUserPointer;
1704         struct _NT_TIB *Self;
1705 } NT_TIB, *PNT_TIB;
1706
1707 struct _TEB;
1708
1709 #if defined(__i386__) && defined(__GNUC__)
1710 extern inline struct _TEB WINAPI *NtCurrentTeb(void);
1711 extern inline struct _TEB WINAPI *NtCurrentTeb(void)
1712 {
1713     struct _TEB *teb;
1714     __asm__(".byte 0x64\n\tmovl (0x18),%0" : "=r" (teb));
1715     return teb;
1716 }
1717 #else
1718 extern struct _TEB WINAPI *NtCurrentTeb(void);
1719 #endif
1720
1721
1722 /*
1723  * File formats definitions
1724  */
1725
1726 typedef struct _IMAGE_DOS_HEADER {
1727     WORD  e_magic;      /* 00: MZ Header signature */
1728     WORD  e_cblp;       /* 02: Bytes on last page of file */
1729     WORD  e_cp;         /* 04: Pages in file */
1730     WORD  e_crlc;       /* 06: Relocations */
1731     WORD  e_cparhdr;    /* 08: Size of header in paragraphs */
1732     WORD  e_minalloc;   /* 0a: Minimum extra paragraphs needed */
1733     WORD  e_maxalloc;   /* 0c: Maximum extra paragraphs needed */
1734     WORD  e_ss;         /* 0e: Initial (relative) SS value */
1735     WORD  e_sp;         /* 10: Initial SP value */
1736     WORD  e_csum;       /* 12: Checksum */
1737     WORD  e_ip;         /* 14: Initial IP value */
1738     WORD  e_cs;         /* 16: Initial (relative) CS value */
1739     WORD  e_lfarlc;     /* 18: File address of relocation table */
1740     WORD  e_ovno;       /* 1a: Overlay number */
1741     WORD  e_res[4];     /* 1c: Reserved words */
1742     WORD  e_oemid;      /* 24: OEM identifier (for e_oeminfo) */
1743     WORD  e_oeminfo;    /* 26: OEM information; e_oemid specific */
1744     WORD  e_res2[10];   /* 28: Reserved words */
1745     DWORD e_lfanew;     /* 3c: Offset to extended header */
1746 } IMAGE_DOS_HEADER, *PIMAGE_DOS_HEADER;
1747
1748 #define IMAGE_DOS_SIGNATURE    0x5A4D     /* MZ   */
1749 #define IMAGE_OS2_SIGNATURE    0x454E     /* NE   */
1750 #define IMAGE_OS2_SIGNATURE_LE 0x454C     /* LE   */
1751 #define IMAGE_OS2_SIGNATURE_LX 0x584C     /* LX */
1752 #define IMAGE_VXD_SIGNATURE    0x454C     /* LE   */
1753 #define IMAGE_NT_SIGNATURE     0x00004550 /* PE00 */
1754
1755 /*
1756  * This is the Windows executable (NE) header.
1757  * the name IMAGE_OS2_HEADER is misleading, but in the SDK this way.
1758  */
1759 typedef struct 
1760 {
1761     WORD  ne_magic;             /* 00 NE signature 'NE' */
1762     BYTE  ne_ver;               /* 02 Linker version number */
1763     BYTE  ne_rev;               /* 03 Linker revision number */
1764     WORD  ne_enttab;            /* 04 Offset to entry table relative to NE */
1765     WORD  ne_cbenttab;          /* 06 Length of entry table in bytes */
1766     LONG  ne_crc;               /* 08 Checksum */
1767     WORD  ne_flags;             /* 0c Flags about segments in this file */
1768     WORD  ne_autodata;          /* 0e Automatic data segment number */
1769     WORD  ne_heap;              /* 10 Initial size of local heap */
1770     WORD  ne_stack;             /* 12 Initial size of stack */
1771     DWORD ne_csip;              /* 14 Initial CS:IP */
1772     DWORD ne_sssp;              /* 18 Initial SS:SP */
1773     WORD  ne_cseg;              /* 1c # of entries in segment table */
1774     WORD  ne_cmod;              /* 1e # of entries in module reference tab. */
1775     WORD  ne_cbnrestab;         /* 20 Length of nonresident-name table     */
1776     WORD  ne_segtab;            /* 22 Offset to segment table */
1777     WORD  ne_rsrctab;           /* 24 Offset to resource table */
1778     WORD  ne_restab;            /* 26 Offset to resident-name table */
1779     WORD  ne_modtab;            /* 28 Offset to module reference table */
1780     WORD  ne_imptab;            /* 2a Offset to imported name table */
1781     DWORD ne_nrestab;           /* 2c Offset to nonresident-name table */
1782     WORD  ne_cmovent;           /* 30 # of movable entry points */
1783     WORD  ne_align;             /* 32 Logical sector alignment shift count */
1784     WORD  ne_cres;              /* 34 # of resource segments */
1785     BYTE  ne_exetyp;            /* 36 Flags indicating target OS */
1786     BYTE  ne_flagsothers;       /* 37 Additional information flags */
1787     WORD  fastload_offset;      /* 38 Offset to fast load area (should be ne_pretthunks)*/
1788     WORD  fastload_length;      /* 3a Length of fast load area (should be ne_psegrefbytes) */
1789     WORD  ne_swaparea;          /* 3c Reserved by Microsoft */
1790     WORD  ne_expver;            /* 3e Expected Windows version number */
1791 } IMAGE_OS2_HEADER,*PIMAGE_OS2_HEADER;
1792
1793 typedef struct _IMAGE_VXD_HEADER {
1794   WORD  e32_magic;
1795   BYTE  e32_border;
1796   BYTE  e32_worder;
1797   DWORD e32_level;
1798   WORD  e32_cpu;
1799   WORD  e32_os;
1800   DWORD e32_ver;
1801   DWORD e32_mflags;
1802   DWORD e32_mpages;
1803   DWORD e32_startobj;
1804   DWORD e32_eip;
1805   DWORD e32_stackobj;
1806   DWORD e32_esp;
1807   DWORD e32_pagesize;
1808   DWORD e32_lastpagesize;
1809   DWORD e32_fixupsize;
1810   DWORD e32_fixupsum;
1811   DWORD e32_ldrsize;
1812   DWORD e32_ldrsum;
1813   DWORD e32_objtab;
1814   DWORD e32_objcnt;
1815   DWORD e32_objmap;
1816   DWORD e32_itermap;
1817   DWORD e32_rsrctab;
1818   DWORD e32_rsrccnt;
1819   DWORD e32_restab;
1820   DWORD e32_enttab;
1821   DWORD e32_dirtab;
1822   DWORD e32_dircnt;
1823   DWORD e32_fpagetab;
1824   DWORD e32_frectab;
1825   DWORD e32_impmod;
1826   DWORD e32_impmodcnt;
1827   DWORD e32_impproc;
1828   DWORD e32_pagesum;
1829   DWORD e32_datapage;
1830   DWORD e32_preload;
1831   DWORD e32_nrestab;
1832   DWORD e32_cbnrestab;
1833   DWORD e32_nressum;
1834   DWORD e32_autodata;
1835   DWORD e32_debuginfo;
1836   DWORD e32_debuglen;
1837   DWORD e32_instpreload;
1838   DWORD e32_instdemand;
1839   DWORD e32_heapsize;
1840   BYTE   e32_res3[12];
1841   DWORD e32_winresoff;
1842   DWORD e32_winreslen;
1843   WORD  e32_devid;
1844   WORD  e32_ddkver;
1845 } IMAGE_VXD_HEADER, *PIMAGE_VXD_HEADER;
1846
1847
1848 /* These defines describe the meanings of the bits in the Characteristics
1849    field */
1850
1851 #define IMAGE_FILE_RELOCS_STRIPPED      0x0001 /* No relocation info */
1852 #define IMAGE_FILE_EXECUTABLE_IMAGE     0x0002
1853 #define IMAGE_FILE_LINE_NUMS_STRIPPED   0x0004
1854 #define IMAGE_FILE_LOCAL_SYMS_STRIPPED  0x0008
1855 #define IMAGE_FILE_16BIT_MACHINE        0x0040
1856 #define IMAGE_FILE_BYTES_REVERSED_LO    0x0080
1857 #define IMAGE_FILE_32BIT_MACHINE        0x0100
1858 #define IMAGE_FILE_DEBUG_STRIPPED       0x0200
1859 #define IMAGE_FILE_SYSTEM               0x1000
1860 #define IMAGE_FILE_DLL                  0x2000
1861 #define IMAGE_FILE_BYTES_REVERSED_HI    0x8000
1862
1863 /* These are the settings of the Machine field. */
1864 #define IMAGE_FILE_MACHINE_UNKNOWN      0
1865 #define IMAGE_FILE_MACHINE_I860         0x14d
1866 #define IMAGE_FILE_MACHINE_I386         0x14c
1867 #define IMAGE_FILE_MACHINE_R3000        0x162
1868 #define IMAGE_FILE_MACHINE_R4000        0x166
1869 #define IMAGE_FILE_MACHINE_R10000       0x168
1870 #define IMAGE_FILE_MACHINE_ALPHA        0x184
1871 #define IMAGE_FILE_MACHINE_POWERPC      0x1F0  
1872
1873 #define IMAGE_SIZEOF_FILE_HEADER        20
1874
1875 /* Possible Magic values */
1876 #define IMAGE_NT_OPTIONAL_HDR_MAGIC        0x10b
1877 #define IMAGE_ROM_OPTIONAL_HDR_MAGIC       0x107
1878
1879 /* These are indexes into the DataDirectory array */
1880 #define IMAGE_FILE_EXPORT_DIRECTORY             0
1881 #define IMAGE_FILE_IMPORT_DIRECTORY             1
1882 #define IMAGE_FILE_RESOURCE_DIRECTORY           2
1883 #define IMAGE_FILE_EXCEPTION_DIRECTORY          3
1884 #define IMAGE_FILE_SECURITY_DIRECTORY           4
1885 #define IMAGE_FILE_BASE_RELOCATION_TABLE        5
1886 #define IMAGE_FILE_DEBUG_DIRECTORY              6
1887 #define IMAGE_FILE_DESCRIPTION_STRING           7
1888 #define IMAGE_FILE_MACHINE_VALUE                8  /* Mips */
1889 #define IMAGE_FILE_THREAD_LOCAL_STORAGE         9
1890 #define IMAGE_FILE_CALLBACK_DIRECTORY           10
1891
1892 /* Directory Entries, indices into the DataDirectory array */
1893
1894 #define IMAGE_DIRECTORY_ENTRY_EXPORT            0
1895 #define IMAGE_DIRECTORY_ENTRY_IMPORT            1
1896 #define IMAGE_DIRECTORY_ENTRY_RESOURCE          2
1897 #define IMAGE_DIRECTORY_ENTRY_EXCEPTION         3
1898 #define IMAGE_DIRECTORY_ENTRY_SECURITY          4
1899 #define IMAGE_DIRECTORY_ENTRY_BASERELOC         5
1900 #define IMAGE_DIRECTORY_ENTRY_DEBUG             6
1901 #define IMAGE_DIRECTORY_ENTRY_COPYRIGHT         7
1902 #define IMAGE_DIRECTORY_ENTRY_GLOBALPTR         8   /* (MIPS GP) */
1903 #define IMAGE_DIRECTORY_ENTRY_TLS               9
1904 #define IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG       10
1905 #define IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT      11
1906 #define IMAGE_DIRECTORY_ENTRY_IAT               12  /* Import Address Table */
1907 #define IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT      13
1908 #define IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR    14
1909
1910 /* Subsystem Values */
1911
1912 #define IMAGE_SUBSYSTEM_UNKNOWN         0
1913 #define IMAGE_SUBSYSTEM_NATIVE          1
1914 #define IMAGE_SUBSYSTEM_WINDOWS_GUI     2       /* Windows GUI subsystem */
1915 #define IMAGE_SUBSYSTEM_WINDOWS_CUI     3       /* Windows character subsystem*/
1916 #define IMAGE_SUBSYSTEM_OS2_CUI         5
1917 #define IMAGE_SUBSYSTEM_POSIX_CUI       7
1918
1919 typedef struct _IMAGE_FILE_HEADER {
1920   WORD  Machine;
1921   WORD  NumberOfSections;
1922   DWORD TimeDateStamp;
1923   DWORD PointerToSymbolTable;
1924   DWORD NumberOfSymbols;
1925   WORD  SizeOfOptionalHeader;
1926   WORD  Characteristics;
1927 } IMAGE_FILE_HEADER, *PIMAGE_FILE_HEADER;
1928
1929 typedef struct _IMAGE_DATA_DIRECTORY {
1930   DWORD VirtualAddress;
1931   DWORD Size;
1932 } IMAGE_DATA_DIRECTORY, *PIMAGE_DATA_DIRECTORY;
1933
1934 #define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 16
1935
1936 typedef struct _IMAGE_OPTIONAL_HEADER {
1937
1938   /* Standard fields */
1939
1940   WORD  Magic;
1941   BYTE  MajorLinkerVersion;
1942   BYTE  MinorLinkerVersion;
1943   DWORD SizeOfCode;
1944   DWORD SizeOfInitializedData;
1945   DWORD SizeOfUninitializedData;
1946   DWORD AddressOfEntryPoint;
1947   DWORD BaseOfCode;
1948   DWORD BaseOfData;
1949
1950   /* NT additional fields */
1951
1952   DWORD ImageBase;
1953   DWORD SectionAlignment;
1954   DWORD FileAlignment;
1955   WORD  MajorOperatingSystemVersion;
1956   WORD  MinorOperatingSystemVersion;
1957   WORD  MajorImageVersion;
1958   WORD  MinorImageVersion;
1959   WORD  MajorSubsystemVersion;
1960   WORD  MinorSubsystemVersion;
1961   DWORD Win32VersionValue;
1962   DWORD SizeOfImage;
1963   DWORD SizeOfHeaders;
1964   DWORD CheckSum;
1965   WORD  Subsystem;
1966   WORD  DllCharacteristics;
1967   DWORD SizeOfStackReserve;
1968   DWORD SizeOfStackCommit;
1969   DWORD SizeOfHeapReserve;
1970   DWORD SizeOfHeapCommit;
1971   DWORD LoaderFlags;
1972   DWORD NumberOfRvaAndSizes;
1973   IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
1974 } IMAGE_OPTIONAL_HEADER, *PIMAGE_OPTIONAL_HEADER;
1975
1976 typedef struct _IMAGE_NT_HEADERS {
1977   DWORD Signature;
1978   IMAGE_FILE_HEADER FileHeader;
1979   IMAGE_OPTIONAL_HEADER OptionalHeader;
1980 } IMAGE_NT_HEADERS, *PIMAGE_NT_HEADERS;
1981
1982 #define IMAGE_SIZEOF_SHORT_NAME 8
1983
1984 typedef struct _IMAGE_SECTION_HEADER {
1985   BYTE  Name[IMAGE_SIZEOF_SHORT_NAME];
1986   union {
1987     DWORD PhysicalAddress;
1988     DWORD VirtualSize;
1989   } Misc;
1990   DWORD VirtualAddress;
1991   DWORD SizeOfRawData;
1992   DWORD PointerToRawData;
1993   DWORD PointerToRelocations;
1994   DWORD PointerToLinenumbers;
1995   WORD  NumberOfRelocations;
1996   WORD  NumberOfLinenumbers;
1997   DWORD Characteristics;
1998 } IMAGE_SECTION_HEADER, *PIMAGE_SECTION_HEADER;
1999
2000 #define IMAGE_SIZEOF_SECTION_HEADER 40
2001
2002 #define IMAGE_FIRST_SECTION(ntheader) \
2003   ((PIMAGE_SECTION_HEADER)((LPBYTE)&((PIMAGE_NT_HEADERS)(ntheader))->OptionalHeader + \
2004                            ((PIMAGE_NT_HEADERS)(ntheader))->FileHeader.SizeOfOptionalHeader))
2005
2006 /* These defines are for the Characteristics bitfield. */
2007 /* #define IMAGE_SCN_TYPE_REG                   0x00000000 - Reserved */
2008 /* #define IMAGE_SCN_TYPE_DSECT                 0x00000001 - Reserved */
2009 /* #define IMAGE_SCN_TYPE_NOLOAD                0x00000002 - Reserved */
2010 /* #define IMAGE_SCN_TYPE_GROUP                 0x00000004 - Reserved */
2011 /* #define IMAGE_SCN_TYPE_NO_PAD                0x00000008 - Reserved */
2012 /* #define IMAGE_SCN_TYPE_COPY                  0x00000010 - Reserved */
2013
2014 #define IMAGE_SCN_CNT_CODE                      0x00000020
2015 #define IMAGE_SCN_CNT_INITIALIZED_DATA          0x00000040
2016 #define IMAGE_SCN_CNT_UNINITIALIZED_DATA        0x00000080
2017
2018 #define IMAGE_SCN_LNK_OTHER                     0x00000100 
2019 #define IMAGE_SCN_LNK_INFO                      0x00000200  
2020 /* #define      IMAGE_SCN_TYPE_OVER             0x00000400 - Reserved */
2021 #define IMAGE_SCN_LNK_REMOVE                    0x00000800
2022 #define IMAGE_SCN_LNK_COMDAT                    0x00001000
2023
2024 /*                                              0x00002000 - Reserved */
2025 /* #define IMAGE_SCN_MEM_PROTECTED              0x00004000 - Obsolete */
2026 #define IMAGE_SCN_MEM_FARDATA                   0x00008000
2027
2028 /* #define IMAGE_SCN_MEM_SYSHEAP                0x00010000 - Obsolete */
2029 #define IMAGE_SCN_MEM_PURGEABLE                 0x00020000
2030 #define IMAGE_SCN_MEM_16BIT                     0x00020000
2031 #define IMAGE_SCN_MEM_LOCKED                    0x00040000
2032 #define IMAGE_SCN_MEM_PRELOAD                   0x00080000
2033
2034 #define IMAGE_SCN_ALIGN_1BYTES                  0x00100000
2035 #define IMAGE_SCN_ALIGN_2BYTES                  0x00200000
2036 #define IMAGE_SCN_ALIGN_4BYTES                  0x00300000
2037 #define IMAGE_SCN_ALIGN_8BYTES                  0x00400000
2038 #define IMAGE_SCN_ALIGN_16BYTES                 0x00500000  /* Default */
2039 #define IMAGE_SCN_ALIGN_32BYTES                 0x00600000
2040 #define IMAGE_SCN_ALIGN_64BYTES                 0x00700000
2041 /*                                              0x00800000 - Unused */
2042
2043 #define IMAGE_SCN_LNK_NRELOC_OVFL               0x01000000
2044
2045
2046 #define IMAGE_SCN_MEM_DISCARDABLE               0x02000000
2047 #define IMAGE_SCN_MEM_NOT_CACHED                0x04000000
2048 #define IMAGE_SCN_MEM_NOT_PAGED                 0x08000000
2049 #define IMAGE_SCN_MEM_SHARED                    0x10000000
2050 #define IMAGE_SCN_MEM_EXECUTE                   0x20000000
2051 #define IMAGE_SCN_MEM_READ                      0x40000000
2052 #define IMAGE_SCN_MEM_WRITE                     0x80000000
2053
2054 #include "pshpack2.h"
2055
2056 typedef struct _IMAGE_SYMBOL {
2057     union {
2058         BYTE    ShortName[8];
2059         struct {
2060             DWORD   Short;
2061             DWORD   Long;
2062         } Name;
2063         DWORD   LongName[2];
2064     } N;
2065     DWORD   Value;
2066     SHORT   SectionNumber;
2067     WORD    Type;
2068     BYTE    StorageClass;
2069     BYTE    NumberOfAuxSymbols;
2070 } IMAGE_SYMBOL;
2071 typedef IMAGE_SYMBOL *PIMAGE_SYMBOL;
2072
2073 #define IMAGE_SIZEOF_SYMBOL 18
2074
2075 typedef struct _IMAGE_LINENUMBER {
2076     union {
2077         DWORD   SymbolTableIndex;
2078         DWORD   VirtualAddress;
2079     } Type;
2080     WORD    Linenumber;
2081 } IMAGE_LINENUMBER;
2082 typedef IMAGE_LINENUMBER *PIMAGE_LINENUMBER;
2083
2084 #define IMAGE_SIZEOF_LINENUMBER  6
2085
2086 typedef union _IMAGE_AUX_SYMBOL {
2087     struct {
2088         DWORD    TagIndex;
2089         union {
2090             struct {
2091                 WORD    Linenumber;
2092                 WORD    Size;
2093             } LnSz;
2094            DWORD    TotalSize;
2095         } Misc;
2096         union {
2097             struct {
2098                 DWORD    PointerToLinenumber;
2099                 DWORD    PointerToNextFunction;
2100             } Function;
2101             struct {
2102                 WORD     Dimension[4];
2103             } Array;
2104         } FcnAry;
2105         WORD    TvIndex;
2106     } Sym;
2107     struct {
2108         BYTE    Name[IMAGE_SIZEOF_SYMBOL];
2109     } File;
2110     struct {
2111         DWORD   Length;
2112         WORD    NumberOfRelocations;
2113         WORD    NumberOfLinenumbers;
2114         DWORD   CheckSum;
2115         SHORT   Number;
2116         BYTE    Selection;
2117     } Section;
2118 } IMAGE_AUX_SYMBOL;
2119 typedef IMAGE_AUX_SYMBOL *PIMAGE_AUX_SYMBOL;
2120
2121 #define IMAGE_SIZEOF_AUX_SYMBOL 18
2122
2123 #include "poppack.h"
2124
2125 #define IMAGE_SYM_UNDEFINED           (SHORT)0
2126 #define IMAGE_SYM_ABSOLUTE            (SHORT)-1
2127 #define IMAGE_SYM_DEBUG               (SHORT)-2
2128
2129 #define IMAGE_SYM_TYPE_NULL                 0x0000
2130 #define IMAGE_SYM_TYPE_VOID                 0x0001
2131 #define IMAGE_SYM_TYPE_CHAR                 0x0002
2132 #define IMAGE_SYM_TYPE_SHORT                0x0003
2133 #define IMAGE_SYM_TYPE_INT                  0x0004
2134 #define IMAGE_SYM_TYPE_LONG                 0x0005
2135 #define IMAGE_SYM_TYPE_FLOAT                0x0006
2136 #define IMAGE_SYM_TYPE_DOUBLE               0x0007
2137 #define IMAGE_SYM_TYPE_STRUCT               0x0008
2138 #define IMAGE_SYM_TYPE_UNION                0x0009
2139 #define IMAGE_SYM_TYPE_ENUM                 0x000A
2140 #define IMAGE_SYM_TYPE_MOE                  0x000B
2141 #define IMAGE_SYM_TYPE_BYTE                 0x000C
2142 #define IMAGE_SYM_TYPE_WORD                 0x000D
2143 #define IMAGE_SYM_TYPE_UINT                 0x000E
2144 #define IMAGE_SYM_TYPE_DWORD                0x000F
2145 #define IMAGE_SYM_TYPE_PCODE                0x8000
2146
2147 #define IMAGE_SYM_DTYPE_NULL                0
2148 #define IMAGE_SYM_DTYPE_POINTER             1
2149 #define IMAGE_SYM_DTYPE_FUNCTION            2
2150 #define IMAGE_SYM_DTYPE_ARRAY               3
2151
2152 #define IMAGE_SYM_CLASS_END_OF_FUNCTION     (BYTE )-1
2153 #define IMAGE_SYM_CLASS_NULL                0x0000
2154 #define IMAGE_SYM_CLASS_AUTOMATIC           0x0001
2155 #define IMAGE_SYM_CLASS_EXTERNAL            0x0002
2156 #define IMAGE_SYM_CLASS_STATIC              0x0003
2157 #define IMAGE_SYM_CLASS_REGISTER            0x0004
2158 #define IMAGE_SYM_CLASS_EXTERNAL_DEF        0x0005
2159 #define IMAGE_SYM_CLASS_LABEL               0x0006
2160 #define IMAGE_SYM_CLASS_UNDEFINED_LABEL     0x0007
2161 #define IMAGE_SYM_CLASS_MEMBER_OF_STRUCT    0x0008
2162 #define IMAGE_SYM_CLASS_ARGUMENT            0x0009
2163 #define IMAGE_SYM_CLASS_STRUCT_TAG          0x000A
2164 #define IMAGE_SYM_CLASS_MEMBER_OF_UNION     0x000B
2165 #define IMAGE_SYM_CLASS_UNION_TAG           0x000C
2166 #define IMAGE_SYM_CLASS_TYPE_DEFINITION     0x000D
2167 #define IMAGE_SYM_CLASS_UNDEFINED_STATIC    0x000E
2168 #define IMAGE_SYM_CLASS_ENUM_TAG            0x000F
2169 #define IMAGE_SYM_CLASS_MEMBER_OF_ENUM      0x0010
2170 #define IMAGE_SYM_CLASS_REGISTER_PARAM      0x0011
2171 #define IMAGE_SYM_CLASS_BIT_FIELD           0x0012
2172
2173 #define IMAGE_SYM_CLASS_FAR_EXTERNAL        0x0044
2174 #define IMAGE_SYM_CLASS_BLOCK               0x0064
2175 #define IMAGE_SYM_CLASS_FUNCTION            0x0065
2176 #define IMAGE_SYM_CLASS_END_OF_STRUCT       0x0066
2177 #define IMAGE_SYM_CLASS_FILE                0x0067
2178 #define IMAGE_SYM_CLASS_SECTION             0x0068
2179 #define IMAGE_SYM_CLASS_WEAK_EXTERNAL       0x0069
2180
2181 #define N_BTMASK                            0x000F
2182 #define N_TMASK                             0x0030
2183 #define N_TMASK1                            0x00C0
2184 #define N_TMASK2                            0x00F0
2185 #define N_BTSHFT                            4
2186 #define N_TSHIFT                            2
2187
2188 #define BTYPE(x) ((x) & N_BTMASK)
2189
2190 #ifndef ISPTR
2191 #define ISPTR(x) (((x) & N_TMASK) == (IMAGE_SYM_DTYPE_POINTER << N_BTSHFT))
2192 #endif
2193
2194 #ifndef ISFCN
2195 #define ISFCN(x) (((x) & N_TMASK) == (IMAGE_SYM_DTYPE_FUNCTION << N_BTSHFT))
2196 #endif
2197
2198 #ifndef ISARY
2199 #define ISARY(x) (((x) & N_TMASK) == (IMAGE_SYM_DTYPE_ARRAY << N_BTSHFT))
2200 #endif
2201
2202 #ifndef ISTAG
2203 #define ISTAG(x) ((x)==IMAGE_SYM_CLASS_STRUCT_TAG || (x)==IMAGE_SYM_CLASS_UNION_TAG || (x)==IMAGE_SYM_CLASS_ENUM_TAG)
2204 #endif
2205
2206 #ifndef INCREF
2207 #define INCREF(x) ((((x)&~N_BTMASK)<<N_TSHIFT)|(IMAGE_SYM_DTYPE_POINTER<<N_BTSHFT)|((x)&N_BTMASK))
2208 #endif
2209 #ifndef DECREF
2210 #define DECREF(x) ((((x)>>N_TSHIFT)&~N_BTMASK)|((x)&N_BTMASK))
2211 #endif
2212
2213 #define IMAGE_COMDAT_SELECT_NODUPLICATES    1
2214 #define IMAGE_COMDAT_SELECT_ANY             2
2215 #define IMAGE_COMDAT_SELECT_SAME_SIZE       3
2216 #define IMAGE_COMDAT_SELECT_EXACT_MATCH     4
2217 #define IMAGE_COMDAT_SELECT_ASSOCIATIVE     5
2218 #define IMAGE_COMDAT_SELECT_LARGEST         6
2219 #define IMAGE_COMDAT_SELECT_NEWEST          7
2220
2221 #define IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY  1
2222 #define IMAGE_WEAK_EXTERN_SEARCH_LIBRARY    2
2223 #define IMAGE_WEAK_EXTERN_SEARCH_ALIAS      3
2224
2225 /* Export module directory */
2226
2227 typedef struct _IMAGE_EXPORT_DIRECTORY {
2228         DWORD   Characteristics;
2229         DWORD   TimeDateStamp;
2230         WORD    MajorVersion;
2231         WORD    MinorVersion;
2232         DWORD   Name;
2233         DWORD   Base;
2234         DWORD   NumberOfFunctions;
2235         DWORD   NumberOfNames;
2236         DWORD   AddressOfFunctions;
2237         DWORD   AddressOfNames;
2238         DWORD   AddressOfNameOrdinals;
2239 } IMAGE_EXPORT_DIRECTORY,*PIMAGE_EXPORT_DIRECTORY;
2240
2241 /* Import name entry */
2242 typedef struct _IMAGE_IMPORT_BY_NAME {
2243         WORD    Hint;
2244         BYTE    Name[1];
2245 } IMAGE_IMPORT_BY_NAME,*PIMAGE_IMPORT_BY_NAME;
2246
2247 /* Import thunk */
2248 typedef struct _IMAGE_THUNK_DATA {
2249         union {
2250                 LPBYTE    ForwarderString;
2251                 PDWORD    Function;
2252                 DWORD     Ordinal;
2253                 PIMAGE_IMPORT_BY_NAME   AddressOfData;
2254         } u1;
2255 } IMAGE_THUNK_DATA,*PIMAGE_THUNK_DATA;
2256
2257 /* Import module directory */
2258
2259 typedef struct _IMAGE_IMPORT_DESCRIPTOR {
2260         union {
2261                 DWORD   Characteristics; /* 0 for terminating null import descriptor  */
2262                 PIMAGE_THUNK_DATA OriginalFirstThunk;   /* RVA to original unbound IAT */
2263         } u;
2264         DWORD   TimeDateStamp;  /* 0 if not bound,
2265                                  * -1 if bound, and real date\time stamp
2266                                  *    in IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT
2267                                  * (new BIND)
2268                                  * otherwise date/time stamp of DLL bound to
2269                                  * (Old BIND)
2270                                  */
2271         DWORD   ForwarderChain; /* -1 if no forwarders */
2272         DWORD   Name;
2273         /* RVA to IAT (if bound this IAT has actual addresses) */
2274         PIMAGE_THUNK_DATA FirstThunk;   
2275 } IMAGE_IMPORT_DESCRIPTOR,*PIMAGE_IMPORT_DESCRIPTOR;
2276
2277 #define IMAGE_ORDINAL_FLAG              0x80000000
2278 #define IMAGE_SNAP_BY_ORDINAL(Ordinal)  ((Ordinal & IMAGE_ORDINAL_FLAG) != 0)
2279 #define IMAGE_ORDINAL(Ordinal)          (Ordinal & 0xffff)
2280
2281 typedef struct _IMAGE_BOUND_IMPORT_DESCRIPTOR
2282 {
2283     DWORD   TimeDateStamp;
2284     WORD    OffsetModuleName;
2285     WORD    NumberOfModuleForwarderRefs;
2286 /* Array of zero or more IMAGE_BOUND_FORWARDER_REF follows */
2287 } IMAGE_BOUND_IMPORT_DESCRIPTOR,  *PIMAGE_BOUND_IMPORT_DESCRIPTOR;
2288
2289 typedef struct _IMAGE_BOUND_FORWARDER_REF
2290 {
2291     DWORD   TimeDateStamp;
2292     WORD    OffsetModuleName;
2293     WORD    Reserved;
2294 } IMAGE_BOUND_FORWARDER_REF, *PIMAGE_BOUND_FORWARDER_REF;
2295
2296 typedef struct _IMAGE_BASE_RELOCATION
2297 {
2298         DWORD   VirtualAddress;
2299         DWORD   SizeOfBlock;
2300         WORD    TypeOffset[1];
2301 } IMAGE_BASE_RELOCATION,*PIMAGE_BASE_RELOCATION;
2302
2303 typedef struct _IMAGE_RELOCATION
2304 {
2305     union {
2306         DWORD   VirtualAddress;
2307         DWORD   RelocCount;
2308     } u;
2309     DWORD   SymbolTableIndex;
2310     WORD    Type;
2311 } IMAGE_RELOCATION;
2312 typedef IMAGE_RELOCATION *PIMAGE_RELOCATION;
2313
2314 #define IMAGE_SIZEOF_RELOCATION 10
2315
2316 /* generic relocation types */
2317 #define IMAGE_REL_BASED_ABSOLUTE                0
2318 #define IMAGE_REL_BASED_HIGH                    1
2319 #define IMAGE_REL_BASED_LOW                     2
2320 #define IMAGE_REL_BASED_HIGHLOW                 3
2321 #define IMAGE_REL_BASED_HIGHADJ                 4
2322 #define IMAGE_REL_BASED_MIPS_JMPADDR            5
2323 #define IMAGE_REL_BASED_SECTION                 6
2324 #define IMAGE_REL_BASED_REL                     7
2325 #define IMAGE_REL_BASED_MIPS_JMPADDR16          9
2326 #define IMAGE_REL_BASED_IA64_IMM64              9 /* yes, 9 too */
2327 #define IMAGE_REL_BASED_DIR64                   10
2328 #define IMAGE_REL_BASED_HIGH3ADJ                11
2329
2330 /* I386 relocation types */
2331 #define IMAGE_REL_I386_ABSOLUTE                 0
2332 #define IMAGE_REL_I386_DIR16                    1
2333 #define IMAGE_REL_I386_REL16                    2
2334 #define IMAGE_REL_I386_DIR32                    6
2335 #define IMAGE_REL_I386_DIR32NB                  7
2336 #define IMAGE_REL_I386_SEG12                    9
2337 #define IMAGE_REL_I386_SECTION                  10
2338 #define IMAGE_REL_I386_SECREL                   11
2339 #define IMAGE_REL_I386_REL32                    20
2340
2341 /* MIPS relocation types */
2342 #define IMAGE_REL_MIPS_ABSOLUTE         0x0000
2343 #define IMAGE_REL_MIPS_REFHALF          0x0001
2344 #define IMAGE_REL_MIPS_REFWORD          0x0002
2345 #define IMAGE_REL_MIPS_JMPADDR          0x0003
2346 #define IMAGE_REL_MIPS_REFHI            0x0004
2347 #define IMAGE_REL_MIPS_REFLO            0x0005
2348 #define IMAGE_REL_MIPS_GPREL            0x0006
2349 #define IMAGE_REL_MIPS_LITERAL          0x0007
2350 #define IMAGE_REL_MIPS_SECTION          0x000A
2351 #define IMAGE_REL_MIPS_SECREL           0x000B
2352 #define IMAGE_REL_MIPS_SECRELLO         0x000C
2353 #define IMAGE_REL_MIPS_SECRELHI         0x000D
2354 #define IMAGE_REL_MIPS_JMPADDR16        0x0010
2355 #define IMAGE_REL_MIPS_REFWORDNB        0x0022
2356 #define IMAGE_REL_MIPS_PAIR             0x0025
2357
2358 /* ALPHA relocation types */
2359 #define IMAGE_REL_ALPHA_ABSOLUTE        0x0000
2360 #define IMAGE_REL_ALPHA_REFLONG         0x0001
2361 #define IMAGE_REL_ALPHA_REFQUAD         0x0002
2362 #define IMAGE_REL_ALPHA_GPREL           0x0003
2363 #define IMAGE_REL_ALPHA_LITERAL         0x0004
2364 #define IMAGE_REL_ALPHA_LITUSE          0x0005
2365 #define IMAGE_REL_ALPHA_GPDISP          0x0006
2366 #define IMAGE_REL_ALPHA_BRADDR          0x0007
2367 #define IMAGE_REL_ALPHA_HINT            0x0008
2368 #define IMAGE_REL_ALPHA_INLINE_REFLONG  0x0009
2369 #define IMAGE_REL_ALPHA_REFHI           0x000A
2370 #define IMAGE_REL_ALPHA_REFLO           0x000B
2371 #define IMAGE_REL_ALPHA_PAIR            0x000C
2372 #define IMAGE_REL_ALPHA_MATCH           0x000D
2373 #define IMAGE_REL_ALPHA_SECTION         0x000E
2374 #define IMAGE_REL_ALPHA_SECREL          0x000F
2375 #define IMAGE_REL_ALPHA_REFLONGNB       0x0010
2376 #define IMAGE_REL_ALPHA_SECRELLO        0x0011
2377 #define IMAGE_REL_ALPHA_SECRELHI        0x0012
2378 #define IMAGE_REL_ALPHA_REFQ3           0x0013
2379 #define IMAGE_REL_ALPHA_REFQ2           0x0014
2380 #define IMAGE_REL_ALPHA_REFQ1           0x0015
2381 #define IMAGE_REL_ALPHA_GPRELLO         0x0016
2382 #define IMAGE_REL_ALPHA_GPRELHI         0x0017
2383
2384 /* PowerPC relocation types */
2385 #define IMAGE_REL_PPC_ABSOLUTE          0x0000
2386 #define IMAGE_REL_PPC_ADDR64            0x0001
2387 #define IMAGE_REL_PPC_ADDR            0x0002
2388 #define IMAGE_REL_PPC_ADDR24            0x0003
2389 #define IMAGE_REL_PPC_ADDR16            0x0004
2390 #define IMAGE_REL_PPC_ADDR14            0x0005
2391 #define IMAGE_REL_PPC_REL24             0x0006
2392 #define IMAGE_REL_PPC_REL14             0x0007
2393 #define IMAGE_REL_PPC_TOCREL16          0x0008
2394 #define IMAGE_REL_PPC_TOCREL14          0x0009
2395 #define IMAGE_REL_PPC_ADDR32NB          0x000A
2396 #define IMAGE_REL_PPC_SECREL            0x000B
2397 #define IMAGE_REL_PPC_SECTION           0x000C
2398 #define IMAGE_REL_PPC_IFGLUE            0x000D
2399 #define IMAGE_REL_PPC_IMGLUE            0x000E
2400 #define IMAGE_REL_PPC_SECREL16          0x000F
2401 #define IMAGE_REL_PPC_REFHI             0x0010
2402 #define IMAGE_REL_PPC_REFLO             0x0011
2403 #define IMAGE_REL_PPC_PAIR              0x0012
2404 #define IMAGE_REL_PPC_SECRELLO          0x0013
2405 #define IMAGE_REL_PPC_SECRELHI          0x0014
2406 #define IMAGE_REL_PPC_GPREL             0x0015
2407 #define IMAGE_REL_PPC_TYPEMASK          0x00FF
2408 /* modifier bits */
2409 #define IMAGE_REL_PPC_NEG               0x0100
2410 #define IMAGE_REL_PPC_BRTAKEN           0x0200
2411 #define IMAGE_REL_PPC_BRNTAKEN          0x0400
2412 #define IMAGE_REL_PPC_TOCDEFN           0x0800
2413
2414 /* SH3 ? relocation type */
2415 #define IMAGE_REL_SH3_ABSOLUTE          0x0000
2416 #define IMAGE_REL_SH3_DIRECT16          0x0001
2417 #define IMAGE_REL_SH3_DIRECT          0x0002
2418 #define IMAGE_REL_SH3_DIRECT8           0x0003
2419 #define IMAGE_REL_SH3_DIRECT8_WORD      0x0004
2420 #define IMAGE_REL_SH3_DIRECT8_LONG      0x0005
2421 #define IMAGE_REL_SH3_DIRECT4           0x0006
2422 #define IMAGE_REL_SH3_DIRECT4_WORD      0x0007
2423 #define IMAGE_REL_SH3_DIRECT4_LONG      0x0008
2424 #define IMAGE_REL_SH3_PCREL8_WORD       0x0009
2425 #define IMAGE_REL_SH3_PCREL8_LONG       0x000A
2426 #define IMAGE_REL_SH3_PCREL12_WORD      0x000B
2427 #define IMAGE_REL_SH3_STARTOF_SECTION   0x000C
2428 #define IMAGE_REL_SH3_SIZEOF_SECTION    0x000D
2429 #define IMAGE_REL_SH3_SECTION           0x000E
2430 #define IMAGE_REL_SH3_SECREL            0x000F
2431 #define IMAGE_REL_SH3_DIRECT32_NB       0x0010
2432
2433 /* ARM (Archimedes?) relocation types */
2434 #define IMAGE_REL_ARM_ABSOLUTE          0x0000
2435 #define IMAGE_REL_ARM_ADDR              0x0001
2436 #define IMAGE_REL_ARM_ADDR32NB          0x0002
2437 #define IMAGE_REL_ARM_BRANCH24          0x0003
2438 #define IMAGE_REL_ARM_BRANCH11          0x0004
2439 #define IMAGE_REL_ARM_SECTION           0x000E
2440 #define IMAGE_REL_ARM_SECREL            0x000F
2441
2442 /* IA64 relocation types */
2443 #define IMAGE_REL_IA64_ABSOLUTE         0x0000
2444 #define IMAGE_REL_IA64_IMM14            0x0001
2445 #define IMAGE_REL_IA64_IMM22            0x0002
2446 #define IMAGE_REL_IA64_IMM64            0x0003
2447 #define IMAGE_REL_IA64_DIR              0x0004
2448 #define IMAGE_REL_IA64_DIR64            0x0005
2449 #define IMAGE_REL_IA64_PCREL21B         0x0006
2450 #define IMAGE_REL_IA64_PCREL21M         0x0007
2451 #define IMAGE_REL_IA64_PCREL21F         0x0008
2452 #define IMAGE_REL_IA64_GPREL22          0x0009
2453 #define IMAGE_REL_IA64_LTOFF22          0x000A
2454 #define IMAGE_REL_IA64_SECTION          0x000B
2455 #define IMAGE_REL_IA64_SECREL22         0x000C
2456 #define IMAGE_REL_IA64_SECREL64I        0x000D
2457 #define IMAGE_REL_IA64_SECREL           0x000E
2458 #define IMAGE_REL_IA64_LTOFF64          0x000F
2459 #define IMAGE_REL_IA64_DIR32NB          0x0010
2460 #define IMAGE_REL_IA64_RESERVED_11      0x0011
2461 #define IMAGE_REL_IA64_RESERVED_12      0x0012
2462 #define IMAGE_REL_IA64_RESERVED_13      0x0013
2463 #define IMAGE_REL_IA64_RESERVED_14      0x0014
2464 #define IMAGE_REL_IA64_RESERVED_15      0x0015
2465 #define IMAGE_REL_IA64_RESERVED_16      0x0016
2466 #define IMAGE_REL_IA64_ADDEND           0x001F
2467
2468 /* archive format */
2469
2470 #define IMAGE_ARCHIVE_START_SIZE             8
2471 #define IMAGE_ARCHIVE_START                  "!<arch>\n"
2472 #define IMAGE_ARCHIVE_END                    "`\n"
2473 #define IMAGE_ARCHIVE_PAD                    "\n"
2474 #define IMAGE_ARCHIVE_LINKER_MEMBER          "/               "
2475 #define IMAGE_ARCHIVE_LONGNAMES_MEMBER       "//              "
2476
2477 typedef struct _IMAGE_ARCHIVE_MEMBER_HEADER
2478 {
2479     BYTE     Name[16];
2480     BYTE     Date[12];
2481     BYTE     UserID[6];
2482     BYTE     GroupID[6];
2483     BYTE     Mode[8];
2484     BYTE     Size[10];
2485     BYTE     EndHeader[2];
2486 } IMAGE_ARCHIVE_MEMBER_HEADER, *PIMAGE_ARCHIVE_MEMBER_HEADER;
2487
2488 #define IMAGE_SIZEOF_ARCHIVE_MEMBER_HDR 60
2489
2490 /*
2491  * Resource directory stuff
2492  */
2493 typedef struct _IMAGE_RESOURCE_DIRECTORY {
2494         DWORD   Characteristics;
2495         DWORD   TimeDateStamp;
2496         WORD    MajorVersion;
2497         WORD    MinorVersion;
2498         WORD    NumberOfNamedEntries;
2499         WORD    NumberOfIdEntries;
2500         /*  IMAGE_RESOURCE_DIRECTORY_ENTRY DirectoryEntries[]; */
2501 } IMAGE_RESOURCE_DIRECTORY,*PIMAGE_RESOURCE_DIRECTORY;
2502
2503 #define IMAGE_RESOURCE_NAME_IS_STRING           0x80000000
2504 #define IMAGE_RESOURCE_DATA_IS_DIRECTORY        0x80000000
2505
2506 typedef struct _IMAGE_RESOURCE_DIRECTORY_ENTRY {
2507         union {
2508                 struct {
2509 #ifdef BITFIELDS_BIGENDIAN
2510                         unsigned NameIsString:1;
2511                         unsigned NameOffset:31;
2512 #else
2513                         unsigned NameOffset:31;
2514                         unsigned NameIsString:1;
2515 #endif
2516                 } DUMMYSTRUCTNAME1;
2517                 DWORD   Name;
2518                 struct {
2519 #ifdef WORDS_BIGENDIAN
2520                         WORD    __pad;
2521                         WORD    Id;
2522 #else
2523                         WORD    Id;
2524                         WORD    __pad;
2525 #endif
2526                 } DUMMYSTRUCTNAME2;
2527         } DUMMYUNIONNAME1;
2528         union {
2529                 DWORD   OffsetToData;
2530                 struct {
2531 #ifdef BITFIELDS_BIGENDIAN
2532                         unsigned DataIsDirectory:1;
2533                         unsigned OffsetToDirectory:31;
2534 #else
2535                         unsigned OffsetToDirectory:31;
2536                         unsigned DataIsDirectory:1;
2537 #endif
2538                 } DUMMYSTRUCTNAME3;
2539         } DUMMYUNIONNAME2;
2540 } IMAGE_RESOURCE_DIRECTORY_ENTRY,*PIMAGE_RESOURCE_DIRECTORY_ENTRY;
2541
2542
2543 typedef struct _IMAGE_RESOURCE_DIRECTORY_STRING {
2544         WORD    Length;
2545         CHAR    NameString[ 1 ];
2546 } IMAGE_RESOURCE_DIRECTORY_STRING,*PIMAGE_RESOURCE_DIRECTORY_STRING;
2547
2548 typedef struct _IMAGE_RESOURCE_DIR_STRING_U {
2549         WORD    Length;
2550         WCHAR   NameString[ 1 ];
2551 } IMAGE_RESOURCE_DIR_STRING_U,*PIMAGE_RESOURCE_DIR_STRING_U;
2552
2553 typedef struct _IMAGE_RESOURCE_DATA_ENTRY {
2554         DWORD   OffsetToData;
2555         DWORD   Size;
2556         DWORD   CodePage;
2557         DWORD   ResourceHandle;
2558 } IMAGE_RESOURCE_DATA_ENTRY,*PIMAGE_RESOURCE_DATA_ENTRY;
2559
2560
2561 typedef VOID CALLBACK (*PIMAGE_TLS_CALLBACK)(
2562         LPVOID DllHandle,DWORD Reason,LPVOID Reserved
2563 );
2564
2565 typedef struct _IMAGE_TLS_DIRECTORY {
2566         DWORD   StartAddressOfRawData;
2567         DWORD   EndAddressOfRawData;
2568         LPDWORD AddressOfIndex;
2569         PIMAGE_TLS_CALLBACK *AddressOfCallBacks;
2570         DWORD   SizeOfZeroFill;
2571         DWORD   Characteristics;
2572 } IMAGE_TLS_DIRECTORY,*PIMAGE_TLS_DIRECTORY;
2573
2574 typedef struct _IMAGE_DEBUG_DIRECTORY {
2575   DWORD Characteristics;
2576   DWORD TimeDateStamp;
2577   WORD  MajorVersion;
2578   WORD  MinorVersion;
2579   DWORD Type;
2580   DWORD SizeOfData;
2581   DWORD AddressOfRawData;
2582   DWORD PointerToRawData;
2583 } IMAGE_DEBUG_DIRECTORY, *PIMAGE_DEBUG_DIRECTORY;
2584
2585 #define IMAGE_DEBUG_TYPE_UNKNOWN        0
2586 #define IMAGE_DEBUG_TYPE_COFF           1
2587 #define IMAGE_DEBUG_TYPE_CODEVIEW       2
2588 #define IMAGE_DEBUG_TYPE_FPO            3
2589 #define IMAGE_DEBUG_TYPE_MISC           4
2590 #define IMAGE_DEBUG_TYPE_EXCEPTION      5
2591 #define IMAGE_DEBUG_TYPE_FIXUP          6
2592 #define IMAGE_DEBUG_TYPE_OMAP_TO_SRC    7
2593 #define IMAGE_DEBUG_TYPE_OMAP_FROM_SRC  8
2594 #define IMAGE_DEBUG_TYPE_BORLAND        9
2595 #define IMAGE_DEBUG_TYPE_RESERVED10    10
2596
2597 typedef struct _IMAGE_COFF_SYMBOLS_HEADER {
2598   DWORD NumberOfSymbols;
2599   DWORD LvaToFirstSymbol;
2600   DWORD NumberOfLinenumbers;
2601   DWORD LvaToFirstLinenumber;
2602   DWORD RvaToFirstByteOfCode;
2603   DWORD RvaToLastByteOfCode;
2604   DWORD RvaToFirstByteOfData;
2605   DWORD RvaToLastByteOfData;
2606 } IMAGE_COFF_SYMBOLS_HEADER, *PIMAGE_COFF_SYMBOLS_HEADER;
2607
2608 #define FRAME_FPO       0
2609 #define FRAME_TRAP      1
2610 #define FRAME_TSS       2
2611 #define FRAME_NONFPO    3
2612
2613 typedef struct _FPO_DATA {
2614   DWORD ulOffStart;
2615   DWORD cbProcSize;
2616   DWORD cdwLocals;
2617   WORD  cdwParams;
2618   unsigned cbProlog : 8;
2619   unsigned cbRegs   : 3;
2620   unsigned fHasSEH  : 1;
2621   unsigned fUseBP   : 1;
2622   unsigned reserved : 1;
2623   unsigned cbFrame  : 2;
2624 } FPO_DATA, *PFPO_DATA;
2625
2626 typedef struct _IMAGE_LOAD_CONFIG_DIRECTORY {
2627   DWORD Characteristics;
2628   DWORD TimeDateStamp;
2629   WORD  MajorVersion;
2630   WORD  MinorVersion;
2631   DWORD GlobalFlagsClear;
2632   DWORD GlobalFlagsSet;
2633   DWORD CriticalSectionDefaultTimeout;
2634   DWORD DeCommitFreeBlockThreshold;
2635   DWORD DeCommitTotalFreeThreshold;
2636   PVOID LockPrefixTable;
2637   DWORD MaximumAllocationSize;
2638   DWORD VirtualMemoryThreshold;
2639   DWORD ProcessHeapFlags;
2640   DWORD ProcessAffinityMask;
2641   WORD  CSDVersion;
2642   WORD  Reserved1;
2643   PVOID EditList;
2644   DWORD Reserved[1];
2645 } IMAGE_LOAD_CONFIG_DIRECTORY, *PIMAGE_LOAD_CONFIG_DIRECTORY;
2646
2647 typedef struct _IMAGE_FUNCTION_ENTRY {
2648   DWORD StartingAddress;
2649   DWORD EndingAddress;
2650   DWORD EndOfPrologue;
2651 } IMAGE_FUNCTION_ENTRY, *PIMAGE_FUNCTION_ENTRY;
2652
2653 #define IMAGE_DEBUG_MISC_EXENAME    1
2654  
2655 typedef struct _IMAGE_DEBUG_MISC {
2656     DWORD       DataType;
2657     DWORD       Length;
2658     BYTE        Unicode;
2659     BYTE        Reserved[ 3 ];
2660     BYTE        Data[ 1 ];
2661 } IMAGE_DEBUG_MISC, *PIMAGE_DEBUG_MISC;
2662
2663 /* This is the structure that appears at the very start of a .DBG file. */
2664
2665 typedef struct _IMAGE_SEPARATE_DEBUG_HEADER {
2666         WORD    Signature;
2667         WORD    Flags;
2668         WORD    Machine;
2669         WORD    Characteristics;
2670         DWORD   TimeDateStamp;
2671         DWORD   CheckSum;
2672         DWORD   ImageBase;
2673         DWORD   SizeOfImage;
2674         DWORD   NumberOfSections;
2675         DWORD   ExportedNamesSize;
2676         DWORD   DebugDirectorySize;
2677         DWORD   SectionAlignment;
2678         DWORD   Reserved[ 2 ];
2679 } IMAGE_SEPARATE_DEBUG_HEADER,*PIMAGE_SEPARATE_DEBUG_HEADER;
2680
2681 #define IMAGE_SEPARATE_DEBUG_SIGNATURE 0x4944
2682
2683
2684 typedef struct tagMESSAGE_RESOURCE_ENTRY {
2685         WORD    Length;
2686         WORD    Flags;
2687         BYTE    Text[1];
2688 } MESSAGE_RESOURCE_ENTRY,*PMESSAGE_RESOURCE_ENTRY;
2689 #define MESSAGE_RESOURCE_UNICODE        0x0001
2690
2691 typedef struct tagMESSAGE_RESOURCE_BLOCK {
2692         DWORD   LowId;
2693         DWORD   HighId;
2694         DWORD   OffsetToEntries;
2695 } MESSAGE_RESOURCE_BLOCK,*PMESSAGE_RESOURCE_BLOCK;
2696
2697 typedef struct tagMESSAGE_RESOURCE_DATA {
2698         DWORD                   NumberOfBlocks;
2699         MESSAGE_RESOURCE_BLOCK  Blocks[ 1 ];
2700 } MESSAGE_RESOURCE_DATA,*PMESSAGE_RESOURCE_DATA;
2701
2702 /*
2703  * Here follows typedefs for security and tokens.
2704  */ 
2705
2706 /*
2707  * First a constant for the following typdefs.
2708  */
2709
2710 #define ANYSIZE_ARRAY   1
2711
2712 /* FIXME:  Orphan.  What does it point to? */
2713 typedef PVOID PACCESS_TOKEN;
2714
2715 /*
2716  * TOKEN_INFORMATION_CLASS
2717  */
2718
2719 typedef enum _TOKEN_INFORMATION_CLASS {
2720   TokenUser = 1, 
2721   TokenGroups, 
2722   TokenPrivileges, 
2723   TokenOwner, 
2724   TokenPrimaryGroup, 
2725   TokenDefaultDacl, 
2726   TokenSource, 
2727   TokenType, 
2728   TokenImpersonationLevel, 
2729   TokenStatistics 
2730 } TOKEN_INFORMATION_CLASS; 
2731
2732 #ifndef _SECURITY_DEFINED
2733 #define _SECURITY_DEFINED
2734
2735 #include "pshpack1.h"
2736
2737 typedef DWORD ACCESS_MASK, *PACCESS_MASK;
2738
2739 typedef struct _GENERIC_MAPPING {
2740     ACCESS_MASK GenericRead;
2741     ACCESS_MASK GenericWrite;
2742     ACCESS_MASK GenericExecute;
2743     ACCESS_MASK GenericAll;
2744 } GENERIC_MAPPING, *PGENERIC_MAPPING;
2745
2746 #ifndef SID_IDENTIFIER_AUTHORITY_DEFINED
2747 #define SID_IDENTIFIER_AUTHORITY_DEFINED
2748 typedef struct {
2749     BYTE Value[6];
2750 } SID_IDENTIFIER_AUTHORITY,*PSID_IDENTIFIER_AUTHORITY,*LPSID_IDENTIFIER_AUTHORITY;
2751 #endif /* !defined(SID_IDENTIFIER_AUTHORITY_DEFINED) */
2752
2753 #ifndef SID_DEFINED
2754 #define SID_DEFINED
2755 typedef struct _SID {
2756     BYTE Revision;
2757     BYTE SubAuthorityCount;
2758     SID_IDENTIFIER_AUTHORITY IdentifierAuthority;
2759     DWORD SubAuthority[1];
2760 } SID,*PSID;
2761 #endif /* !defined(SID_DEFINED) */
2762
2763 #define SID_REVISION                    (1)     /* Current revision */
2764 #define SID_MAX_SUB_AUTHORITIES         (15)    /* current max subauths */
2765 #define SID_RECOMMENDED_SUB_AUTHORITIES (1)     /* recommended subauths */
2766
2767
2768 /* 
2769  * ACL 
2770  */
2771
2772 #define ACL_REVISION1 1
2773 #define ACL_REVISION2 2
2774 #define ACL_REVISION3 3
2775 #define ACL_REVISION4 4
2776
2777 #define MIN_ACL_REVISION ACL_REVISION2
2778 #define MAX_ACL_REVISION ACL_REVISION4
2779
2780 typedef struct _ACL {
2781     BYTE AclRevision;
2782     BYTE Sbz1;
2783     WORD AclSize;
2784     WORD AceCount;
2785     WORD Sbz2;
2786 } ACL, *PACL;
2787
2788 /* SECURITY_DESCRIPTOR */
2789 #define SECURITY_DESCRIPTOR_REVISION    1
2790 #define SECURITY_DESCRIPTOR_REVISION1   1
2791
2792
2793 #define SE_OWNER_DEFAULTED      0x0001
2794 #define SE_GROUP_DEFAULTED      0x0002
2795 #define SE_DACL_PRESENT         0x0004
2796 #define SE_DACL_DEFAULTED       0x0008
2797 #define SE_SACL_PRESENT         0x0010
2798 #define SE_SACL_DEFAULTED       0x0020
2799 #define SE_SELF_RELATIVE        0x8000
2800
2801 typedef DWORD SECURITY_INFORMATION, *PSECURITY_INFORMATION;
2802 typedef WORD SECURITY_DESCRIPTOR_CONTROL, *PSECURITY_DESCRIPTOR_CONTROL;
2803
2804 /* The security descriptor structure */
2805 typedef struct {
2806     BYTE Revision;
2807     BYTE Sbz1;
2808     SECURITY_DESCRIPTOR_CONTROL Control;
2809     DWORD Owner;
2810     DWORD Group;
2811     DWORD Sacl;
2812     DWORD Dacl;
2813 } SECURITY_DESCRIPTOR_RELATIVE, *PISECURITY_DESCRIPTOR_RELATIVE;
2814
2815 typedef struct {
2816     BYTE Revision;
2817     BYTE Sbz1;
2818     SECURITY_DESCRIPTOR_CONTROL Control;
2819     PSID Owner;
2820     PSID Group;
2821     PACL Sacl;
2822     PACL Dacl;
2823 } SECURITY_DESCRIPTOR, *PSECURITY_DESCRIPTOR;
2824
2825 #define SECURITY_DESCRIPTOR_MIN_LENGTH   (sizeof(SECURITY_DESCRIPTOR)) 
2826
2827 #include "poppack.h"
2828
2829 #endif /* _SECURITY_DEFINED */
2830
2831 #include "pshpack1.h"
2832
2833 /* 
2834  * SID_AND_ATTRIBUTES
2835  */
2836
2837 typedef struct _SID_AND_ATTRIBUTES {
2838   PSID  Sid; 
2839   DWORD Attributes; 
2840 } SID_AND_ATTRIBUTES ; 
2841  
2842 /* security entities */
2843 #define SECURITY_NULL_RID                       (0x00000000L)
2844 #define SECURITY_WORLD_RID                      (0x00000000L)
2845 #define SECURITY_LOCAL_RID                      (0X00000000L)
2846
2847 #define SECURITY_NULL_SID_AUTHORITY             {0,0,0,0,0,0}
2848
2849 /* S-1-1 */
2850 #define SECURITY_WORLD_SID_AUTHORITY            {0,0,0,0,0,1}
2851
2852 /* S-1-2 */
2853 #define SECURITY_LOCAL_SID_AUTHORITY            {0,0,0,0,0,2}
2854
2855 /* S-1-3 */
2856 #define SECURITY_CREATOR_SID_AUTHORITY          {0,0,0,0,0,3}
2857 #define SECURITY_CREATOR_OWNER_RID              (0x00000000L) 
2858 #define SECURITY_CREATOR_GROUP_RID              (0x00000001L)
2859 #define SECURITY_CREATOR_OWNER_SERVER_RID       (0x00000002L)
2860 #define SECURITY_CREATOR_GROUP_SERVER_RID       (0x00000003L)
2861
2862 /* S-1-4 */
2863 #define SECURITY_NON_UNIQUE_AUTHORITY           {0,0,0,0,0,4}
2864
2865 /* S-1-5 */
2866 #define SECURITY_NT_AUTHORITY                   {0,0,0,0,0,5} 
2867 #define SECURITY_DIALUP_RID                     0x00000001L
2868 #define SECURITY_NETWORK_RID                    0x00000002L
2869 #define SECURITY_BATCH_RID                      0x00000003L
2870 #define SECURITY_INTERACTIVE_RID                0x00000004L
2871 #define SECURITY_LOGON_IDS_RID                  0x00000005L
2872 #define SECURITY_SERVICE_RID                    0x00000006L
2873 #define SECURITY_ANONYMOUS_LOGON_RID            0x00000007L
2874 #define SECURITY_PROXY_RID                      0x00000008L
2875 #define SECURITY_ENTERPRISE_CONTROLLERS_RID     0x00000009L
2876 #define SECURITY_PRINCIPAL_SELF_RID             0x0000000AL
2877 #define SECURITY_AUTHENTICATED_USER_RID         0x0000000BL
2878 #define SECURITY_RESTRICTED_CODE_RID            0x0000000CL
2879 #define SECURITY_TERMINAL_SERVER_RID            0x0000000DL
2880 #define SECURITY_LOCAL_SYSTEM_RID               0x00000012L
2881 #define SECURITY_NT_NON_UNIQUE                  0x00000015L
2882 #define SECURITY_BUILTIN_DOMAIN_RID             0x00000020L
2883
2884 #define DOMAIN_GROUP_RID_ADMINS                 0x00000200L
2885 #define DOMAIN_GROUP_RID_USERS                  0x00000201L
2886 #define DOMAIN_GROUP_RID_GUESTS                 0x00000202L
2887
2888 #define DOMAIN_ALIAS_RID_ADMINS                 0x00000220L
2889 #define DOMAIN_ALIAS_RID_USERS                  0x00000221L
2890 #define DOMAIN_ALIAS_RID_GUESTS                 0x00000222L
2891
2892 #define SECURITY_SERVER_LOGON_RID               SECURITY_ENTERPRISE_CONTROLLERS_RID
2893
2894 #define SECURITY_LOGON_IDS_RID_COUNT            (3L)
2895
2896 /*
2897  * TOKEN_USER
2898  */
2899
2900 typedef struct _TOKEN_USER {
2901   SID_AND_ATTRIBUTES User; 
2902 } TOKEN_USER; 
2903
2904 /*
2905  * TOKEN_GROUPS
2906  */
2907
2908 typedef struct _TOKEN_GROUPS  {
2909   DWORD GroupCount; 
2910   SID_AND_ATTRIBUTES Groups[ANYSIZE_ARRAY]; 
2911 } TOKEN_GROUPS; 
2912
2913 /*
2914  * LUID_AND_ATTRIBUTES
2915  */
2916
2917 typedef union _LARGE_INTEGER {
2918     struct {
2919         DWORD    LowPart;
2920         LONG     HighPart;
2921     } DUMMYSTRUCTNAME;
2922     LONGLONG QuadPart;
2923 } LARGE_INTEGER, *LPLARGE_INTEGER, *PLARGE_INTEGER;
2924
2925 typedef union _ULARGE_INTEGER {
2926     struct {
2927         DWORD    LowPart;
2928         DWORD    HighPart;
2929     } DUMMYSTRUCTNAME;
2930     ULONGLONG QuadPart;
2931 } ULARGE_INTEGER, *LPULARGE_INTEGER, *PULARGE_INTEGER;
2932
2933 /*
2934  * Locally Unique Identifier
2935  */
2936
2937 typedef LARGE_INTEGER LUID,*PLUID;
2938
2939 typedef struct _LUID_AND_ATTRIBUTES {
2940   LUID   Luid; 
2941   DWORD  Attributes; 
2942 } LUID_AND_ATTRIBUTES; 
2943
2944 /*
2945  * PRIVILEGE_SET
2946  */
2947
2948 typedef struct _PRIVILEGE_SET {
2949     DWORD PrivilegeCount;
2950     DWORD Control;
2951     LUID_AND_ATTRIBUTES Privilege[ANYSIZE_ARRAY];
2952 } PRIVILEGE_SET, *PPRIVILEGE_SET;
2953
2954 /*
2955  * TOKEN_PRIVILEGES
2956  */
2957
2958 typedef struct _TOKEN_PRIVILEGES {
2959   DWORD PrivilegeCount; 
2960   LUID_AND_ATTRIBUTES Privileges[ANYSIZE_ARRAY]; 
2961 } TOKEN_PRIVILEGES, *PTOKEN_PRIVILEGES; 
2962
2963 /*
2964  * TOKEN_OWNER
2965  */
2966
2967 typedef struct _TOKEN_OWNER {
2968   PSID Owner; 
2969 } TOKEN_OWNER; 
2970
2971 /*
2972  * TOKEN_PRIMARY_GROUP
2973  */
2974
2975 typedef struct _TOKEN_PRIMARY_GROUP {
2976   PSID PrimaryGroup; 
2977 } TOKEN_PRIMARY_GROUP; 
2978
2979
2980 /*
2981  * TOKEN_DEFAULT_DACL
2982  */
2983
2984 typedef struct _TOKEN_DEFAULT_DACL { 
2985   PACL DefaultDacl; 
2986 } TOKEN_DEFAULT_DACL; 
2987
2988 /*
2989  * TOKEN_SOURCEL
2990  */
2991
2992 typedef struct _TOKEN_SOURCE {
2993   char Sourcename[8]; 
2994   LUID SourceIdentifier; 
2995 } TOKEN_SOURCE; 
2996
2997 /*
2998  * TOKEN_TYPE
2999  */
3000
3001 typedef enum tagTOKEN_TYPE {
3002   TokenPrimary = 1, 
3003   TokenImpersonation 
3004 } TOKEN_TYPE; 
3005
3006 /*
3007  * SECURITY_IMPERSONATION_LEVEL
3008  */
3009
3010 typedef enum _SECURITY_IMPERSONATION_LEVEL {
3011   SecurityAnonymous, 
3012   SecurityIdentification, 
3013   SecurityImpersonation, 
3014   SecurityDelegation 
3015 } SECURITY_IMPERSONATION_LEVEL, *PSECURITY_IMPERSONATION_LEVEL; 
3016
3017
3018 typedef BOOLEAN SECURITY_CONTEXT_TRACKING_MODE,
3019         * PSECURITY_CONTEXT_TRACKING_MODE;
3020 /*
3021  *      Quality of Service
3022  */
3023
3024 typedef struct _SECURITY_QUALITY_OF_SERVICE {
3025   DWORD                         Length;
3026   SECURITY_IMPERSONATION_LEVEL  ImpersonationLevel;
3027   SECURITY_CONTEXT_TRACKING_MODE ContextTrackingMode;
3028   BOOL                          EffectiveOnly;
3029 } SECURITY_QUALITY_OF_SERVICE, *PSECURITY_QUALITY_OF_SERVICE;
3030
3031 /*
3032  * TOKEN_STATISTICS
3033  */
3034
3035 typedef struct _TOKEN_STATISTICS {
3036   LUID  TokenId; 
3037   LUID  AuthenticationId; 
3038   LARGE_INTEGER ExpirationTime; 
3039   TOKEN_TYPE    TokenType; 
3040   SECURITY_IMPERSONATION_LEVEL ImpersonationLevel; 
3041   DWORD DynamicCharged; 
3042   DWORD DynamicAvailable; 
3043   DWORD GroupCount; 
3044   DWORD PrivilegeCount; 
3045   LUID  ModifiedId; 
3046 } TOKEN_STATISTICS; 
3047
3048 /* 
3049  *      ACLs of NT 
3050  */
3051
3052 #define ACL_REVISION    2
3053
3054 #define ACL_REVISION1   1
3055 #define ACL_REVISION2   2
3056
3057 /* ACEs, directly starting after an ACL */
3058 typedef struct _ACE_HEADER {
3059         BYTE    AceType;
3060         BYTE    AceFlags;
3061         WORD    AceSize;
3062 } ACE_HEADER,*PACE_HEADER;
3063
3064 /* AceType */
3065 #define ACCESS_ALLOWED_ACE_TYPE         0
3066 #define ACCESS_DENIED_ACE_TYPE          1
3067 #define SYSTEM_AUDIT_ACE_TYPE           2
3068 #define SYSTEM_ALARM_ACE_TYPE           3
3069
3070 /* inherit AceFlags */
3071 #define OBJECT_INHERIT_ACE              0x01
3072 #define CONTAINER_INHERIT_ACE           0x02
3073 #define NO_PROPAGATE_INHERIT_ACE        0x04
3074 #define INHERIT_ONLY_ACE                0x08
3075 #define VALID_INHERIT_FLAGS             0x0F
3076
3077 /* AceFlags mask for what events we (should) audit */
3078 #define SUCCESSFUL_ACCESS_ACE_FLAG      0x40
3079 #define FAILED_ACCESS_ACE_FLAG          0x80
3080
3081 /* different ACEs depending on AceType 
3082  * SidStart marks the begin of a SID
3083  * so the thing finally looks like this:
3084  * 0: ACE_HEADER
3085  * 4: ACCESS_MASK
3086  * 8... : SID
3087  */
3088 typedef struct _ACCESS_ALLOWED_ACE {
3089         ACE_HEADER      Header;
3090         DWORD           Mask;
3091         DWORD           SidStart;
3092 } ACCESS_ALLOWED_ACE,*PACCESS_ALLOWED_ACE;
3093
3094 typedef struct _ACCESS_DENIED_ACE {
3095         ACE_HEADER      Header;
3096         DWORD           Mask;
3097         DWORD           SidStart;
3098 } ACCESS_DENIED_ACE,*PACCESS_DENIED_ACE;
3099
3100 typedef struct _SYSTEM_AUDIT_ACE {
3101         ACE_HEADER      Header;
3102         DWORD           Mask;
3103         DWORD           SidStart;
3104 } SYSTEM_AUDIT_ACE,*PSYSTEM_AUDIT_ACE;
3105
3106 typedef struct _SYSTEM_ALARM_ACE {
3107         ACE_HEADER      Header;
3108         DWORD           Mask;
3109         DWORD           SidStart;
3110 } SYSTEM_ALARM_ACE,*PSYSTEM_ALARM_ACE;
3111
3112 typedef enum tagSID_NAME_USE {
3113         SidTypeUser = 1,
3114         SidTypeGroup,
3115         SidTypeDomain,
3116         SidTypeAlias,
3117         SidTypeWellKnownGroup,
3118         SidTypeDeletedAccount,
3119         SidTypeInvalid,
3120         SidTypeUnknown
3121 } SID_NAME_USE,*PSID_NAME_USE;
3122
3123 /* Access rights */
3124
3125 /* DELETE may be already defined via /usr/include/arpa/nameser_compat.h */
3126 #undef  DELETE
3127 #define DELETE                     0x00010000
3128 #define READ_CONTROL               0x00020000
3129 #define WRITE_DAC                  0x00040000
3130 #define WRITE_OWNER                0x00080000
3131 #define SYNCHRONIZE                0x00100000
3132 #define STANDARD_RIGHTS_REQUIRED   0x000f0000
3133
3134 #define STANDARD_RIGHTS_READ       READ_CONTROL
3135 #define STANDARD_RIGHTS_WRITE      READ_CONTROL
3136 #define STANDARD_RIGHTS_EXECUTE    READ_CONTROL
3137
3138 #define STANDARD_RIGHTS_ALL        0x001f0000
3139
3140 #define SPECIFIC_RIGHTS_ALL        0x0000ffff
3141
3142 #define GENERIC_READ               0x80000000
3143 #define GENERIC_WRITE              0x40000000
3144 #define GENERIC_EXECUTE            0x20000000
3145 #define GENERIC_ALL                0x10000000
3146
3147 #define MAXIMUM_ALLOWED            0x02000000
3148 #define ACCESS_SYSTEM_SECURITY     0x01000000
3149
3150 #define EVENT_MODIFY_STATE         0x0002
3151 #define EVENT_ALL_ACCESS           (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3)
3152
3153 #define SEMAPHORE_MODIFY_STATE     0x0002
3154 #define SEMAPHORE_ALL_ACCESS       (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3)
3155
3156 #define MUTEX_MODIFY_STATE         0x0001
3157 #define MUTEX_ALL_ACCESS           (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x1)
3158
3159 #define TIMER_QUERY_STATE          0x0001
3160 #define TIMER_MODIFY_STATE         0x0002
3161 #define TIMER_ALL_ACCESS           (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3)
3162
3163 #define PROCESS_TERMINATE          0x0001
3164 #define PROCESS_CREATE_THREAD      0x0002
3165 #define PROCESS_VM_OPERATION       0x0008
3166 #define PROCESS_VM_READ            0x0010
3167 #define PROCESS_VM_WRITE           0x0020
3168 #define PROCESS_DUP_HANDLE         0x0040
3169 #define PROCESS_CREATE_PROCESS     0x0080
3170 #define PROCESS_SET_QUOTA          0x0100
3171 #define PROCESS_SET_INFORMATION    0x0200
3172 #define PROCESS_QUERY_INFORMATION  0x0400
3173 #define PROCESS_ALL_ACCESS         (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0xfff)
3174
3175 #define THREAD_TERMINATE           0x0001
3176 #define THREAD_SUSPEND_RESUME      0x0002
3177 #define THREAD_GET_CONTEXT         0x0008
3178 #define THREAD_SET_CONTEXT         0x0010
3179 #define THREAD_SET_INFORMATION     0x0020
3180 #define THREAD_QUERY_INFORMATION   0x0040
3181 #define THREAD_SET_THREAD_TOKEN    0x0080
3182 #define THREAD_IMPERSONATE         0x0100
3183 #define THREAD_DIRECT_IMPERSONATION 0x0200
3184 #define THREAD_ALL_ACCESS          (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3ff)
3185
3186 #define THREAD_BASE_PRIORITY_LOWRT  15 
3187 #define THREAD_BASE_PRIORITY_MAX    2 
3188 #define THREAD_BASE_PRIORITY_MIN   -2
3189 #define THREAD_BASE_PRIORITY_IDLE  -15
3190
3191 #define FILE_READ_DATA            0x0001    /* file & pipe */
3192 #define FILE_LIST_DIRECTORY       0x0001    /* directory */
3193 #define FILE_WRITE_DATA           0x0002    /* file & pipe */
3194 #define FILE_ADD_FILE             0x0002    /* directory */
3195 #define FILE_APPEND_DATA          0x0004    /* file */
3196 #define FILE_ADD_SUBDIRECTORY     0x0004    /* directory */
3197 #define FILE_CREATE_PIPE_INSTANCE 0x0004    /* named pipe */
3198 #define FILE_READ_EA              0x0008    /* file & directory */
3199 #define FILE_READ_PROPERTIES      FILE_READ_EA
3200 #define FILE_WRITE_EA             0x0010    /* file & directory */
3201 #define FILE_WRITE_PROPERTIES     FILE_WRITE_EA
3202 #define FILE_EXECUTE              0x0020    /* file */
3203 #define FILE_TRAVERSE             0x0020    /* directory */
3204 #define FILE_DELETE_CHILD         0x0040    /* directory */
3205 #define FILE_READ_ATTRIBUTES      0x0080    /* all */
3206 #define FILE_WRITE_ATTRIBUTES     0x0100    /* all */
3207 #define FILE_ALL_ACCESS           (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x1ff)
3208
3209 #define FILE_GENERIC_READ         (STANDARD_RIGHTS_READ | FILE_READ_DATA | \
3210                                    FILE_READ_ATTRIBUTES | FILE_READ_EA | \
3211                                    SYNCHRONIZE)
3212 #define FILE_GENERIC_WRITE        (STANDARD_RIGHTS_WRITE | FILE_WRITE_DATA | \
3213                                    FILE_WRITE_ATTRIBUTES | FILE_WRITE_EA | \
3214                                    FILE_APPEND_DATA | SYNCHRONIZE)
3215 #define FILE_GENERIC_EXECUTE      (STANDARD_RIGHTS_EXECUTE | FILE_EXECUTE | \
3216                                    FILE_READ_ATTRIBUTES | SYNCHRONIZE)
3217
3218
3219 /* File attribute flags */
3220 #define FILE_SHARE_READ                 0x00000001L
3221 #define FILE_SHARE_WRITE                0x00000002L
3222 #define FILE_SHARE_DELETE               0x00000004L
3223 #define FILE_ATTRIBUTE_READONLY         0x00000001L
3224 #define FILE_ATTRIBUTE_HIDDEN           0x00000002L
3225 #define FILE_ATTRIBUTE_SYSTEM           0x00000004L
3226 #define FILE_ATTRIBUTE_LABEL            0x00000008L  /* Not in Windows API */
3227 #define FILE_ATTRIBUTE_DIRECTORY        0x00000010L
3228 #define FILE_ATTRIBUTE_ARCHIVE          0x00000020L
3229 #define FILE_ATTRIBUTE_NORMAL           0x00000080L
3230 #define FILE_ATTRIBUTE_TEMPORARY        0x00000100L
3231 #define FILE_ATTRIBUTE_ATOMIC_WRITE     0x00000200L
3232 #define FILE_ATTRIBUTE_XACTION_WRITE    0x00000400L
3233 #define FILE_ATTRIBUTE_COMPRESSED       0x00000800L
3234 #define FILE_ATTRIBUTE_OFFLINE          0x00001000L
3235 #define FILE_ATTRIBUTE_SYMLINK          0x80000000L  /* Not in Windows API */
3236
3237 /* File notification flags */
3238 #define FILE_NOTIFY_CHANGE_FILE_NAME    0x00000001
3239 #define FILE_NOTIFY_CHANGE_DIR_NAME     0x00000002
3240 #define FILE_NOTIFY_CHANGE_ATTRIBUTES   0x00000004
3241 #define FILE_NOTIFY_CHANGE_SIZE         0x00000008
3242 #define FILE_NOTIFY_CHANGE_LAST_WRITE   0x00000010
3243 #define FILE_NOTIFY_CHANGE_LAST_ACCESS  0x00000020
3244 #define FILE_NOTIFY_CHANGE_CREATION     0x00000040
3245 #define FILE_NOTIFY_CHANGE_SECURITY     0x00000100
3246
3247 #define FILE_ACTION_ADDED               0x00000001
3248 #define FILE_ACTION_REMOVED             0x00000002
3249 #define FILE_ACTION_MODIFIED            0x00000003
3250 #define FILE_ACTION_RENAMED_OLD_NAME    0x00000004
3251 #define FILE_ACTION_RENAMED_NEW_NAME    0x00000005
3252
3253
3254 #define FILE_CASE_SENSITIVE_SEARCH      0x00000001
3255 #define FILE_CASE_PRESERVED_NAMES       0x00000002
3256 #define FILE_UNICODE_ON_DISK            0x00000004
3257 #define FILE_PERSISTENT_ACLS            0x00000008
3258 #define FILE_FILE_COMPRESSION           0x00000010
3259 #define FILE_VOLUME_IS_COMPRESSED       0x00008000
3260
3261 /* File alignments (NT) */
3262 #define FILE_BYTE_ALIGNMENT             0x00000000
3263 #define FILE_WORD_ALIGNMENT             0x00000001
3264 #define FILE_LONG_ALIGNMENT             0x00000003
3265 #define FILE_QUAD_ALIGNMENT             0x00000007
3266 #define FILE_OCTA_ALIGNMENT             0x0000000f
3267 #define FILE_32_BYTE_ALIGNMENT          0x0000001f
3268 #define FILE_64_BYTE_ALIGNMENT          0x0000003f
3269 #define FILE_128_BYTE_ALIGNMENT         0x0000007f
3270 #define FILE_256_BYTE_ALIGNMENT         0x000000ff
3271 #define FILE_512_BYTE_ALIGNMENT         0x000001ff
3272
3273 #define REG_NONE                0       /* no type */
3274 #define REG_SZ                  1       /* string type (ASCII) */
3275 #define REG_EXPAND_SZ           2       /* string, includes %ENVVAR% (expanded by caller) (ASCII) */
3276 #define REG_BINARY              3       /* binary format, callerspecific */
3277 /* YES, REG_DWORD == REG_DWORD_LITTLE_ENDIAN */
3278 #define REG_DWORD               4       /* DWORD in little endian format */
3279 #define REG_DWORD_LITTLE_ENDIAN 4       /* DWORD in little endian format */
3280 #define REG_DWORD_BIG_ENDIAN    5       /* DWORD in big endian format  */
3281 #define REG_LINK                6       /* symbolic link (UNICODE) */
3282 #define REG_MULTI_SZ            7       /* multiple strings, delimited by \0, terminated by \0\0 (ASCII) */
3283 #define REG_RESOURCE_LIST       8       /* resource list? huh? */
3284 #define REG_FULL_RESOURCE_DESCRIPTOR    9       /* full resource descriptor? huh? */
3285 #define REG_RESOURCE_REQUIREMENTS_LIST  10
3286
3287 /* ----------------------------- begin registry ----------------------------- */
3288
3289 /* Registry security values */
3290 #define OWNER_SECURITY_INFORMATION      0x00000001
3291 #define GROUP_SECURITY_INFORMATION      0x00000002
3292 #define DACL_SECURITY_INFORMATION       0x00000004
3293 #define SACL_SECURITY_INFORMATION       0x00000008
3294
3295 #define REG_OPTION_RESERVED             0x00000000
3296 #define REG_OPTION_NON_VOLATILE         0x00000000
3297 #define REG_OPTION_VOLATILE             0x00000001
3298 #define REG_OPTION_CREATE_LINK          0x00000002
3299 #define REG_OPTION_BACKUP_RESTORE       0x00000004 /* FIXME */
3300 #define REG_OPTION_OPEN_LINK            0x00000008
3301 #define REG_LEGAL_OPTION               (REG_OPTION_RESERVED|  \
3302                                         REG_OPTION_NON_VOLATILE|  \
3303                                         REG_OPTION_VOLATILE|  \
3304                                         REG_OPTION_CREATE_LINK|  \
3305                                         REG_OPTION_BACKUP_RESTORE|  \
3306                                         REG_OPTION_OPEN_LINK)
3307
3308
3309 #define REG_CREATED_NEW_KEY     0x00000001
3310 #define REG_OPENED_EXISTING_KEY 0x00000002
3311
3312 /* For RegNotifyChangeKeyValue */
3313 #define REG_NOTIFY_CHANGE_NAME  0x1
3314
3315 #define KEY_QUERY_VALUE         0x00000001
3316 #define KEY_SET_VALUE           0x00000002
3317 #define KEY_CREATE_SUB_KEY      0x00000004
3318 #define KEY_ENUMERATE_SUB_KEYS  0x00000008
3319 #define KEY_NOTIFY              0x00000010
3320 #define KEY_CREATE_LINK         0x00000020
3321
3322 #define KEY_READ              ((STANDARD_RIGHTS_READ|  \
3323                                 KEY_QUERY_VALUE|  \
3324                                 KEY_ENUMERATE_SUB_KEYS|  \
3325                                 KEY_NOTIFY)  \
3326                                 & (~SYNCHRONIZE)  \
3327                               )
3328 #define KEY_WRITE             ((STANDARD_RIGHTS_WRITE|  \
3329                                 KEY_SET_VALUE|  \
3330                                 KEY_CREATE_SUB_KEY)  \
3331                                 & (~SYNCHRONIZE)  \
3332                               )
3333 #define KEY_EXECUTE           ((KEY_READ)  \
3334                                 & (~SYNCHRONIZE))  \
3335                               )
3336 #define KEY_ALL_ACCESS        ((STANDARD_RIGHTS_ALL|  \
3337                                 KEY_QUERY_VALUE|  \
3338                                 KEY_SET_VALUE|  \
3339                                 KEY_CREATE_SUB_KEY|  \
3340                                 KEY_ENUMERATE_SUB_KEYS|  \
3341                                 KEY_NOTIFY|  \
3342                                 KEY_CREATE_LINK)  \
3343                                 & (~SYNCHRONIZE)  \
3344                               )
3345 /* ------------------------------ end registry ------------------------------ */
3346
3347
3348 typedef struct _RTL_CRITICAL_SECTION_DEBUG 
3349 {
3350   WORD   Type;
3351   WORD   CreatorBackTraceIndex;
3352   struct _RTL_CRITICAL_SECTION *CriticalSection;
3353   LIST_ENTRY ProcessLocksList;
3354   DWORD EntryCount;
3355   DWORD ContentionCount;
3356   DWORD Spare[ 2 ];
3357 } RTL_CRITICAL_SECTION_DEBUG, *PRTL_CRITICAL_SECTION_DEBUG, RTL_RESOURCE_DEBUG, *PRTL_RESOURCE_DEBUG;
3358
3359 typedef struct _RTL_CRITICAL_SECTION {
3360     PRTL_CRITICAL_SECTION_DEBUG DebugInfo;
3361     LONG LockCount;
3362     LONG RecursionCount;
3363     HANDLE OwningThread;
3364     HANDLE LockSemaphore;
3365     ULONG_PTR SpinCount;
3366 } RTL_CRITICAL_SECTION, *PRTL_CRITICAL_SECTION;
3367
3368
3369 #define EVENTLOG_SUCCESS                0x0000
3370 #define EVENTLOG_ERROR_TYPE             0x0001
3371 #define EVENTLOG_WARNING_TYPE           0x0002
3372 #define EVENTLOG_INFORMATION_TYPE       0x0004
3373 #define EVENTLOG_AUDIT_SUCCESS          0x0008
3374 #define EVENTLOG_AUDIT_FAILURE          0x0010
3375
3376 #define SERVICE_BOOT_START   0x00000000
3377 #define SERVICE_SYSTEM_START 0x00000001
3378 #define SERVICE_AUTO_START   0x00000002
3379 #define SERVICE_DEMAND_START 0x00000003
3380 #define SERVICE_DISABLED     0x00000004
3381
3382 #define SERVICE_ERROR_IGNORE   0x00000000
3383 #define SERVICE_ERROR_NORMAL   0x00000001
3384 #define SERVICE_ERROR_SEVERE   0x00000002
3385 #define SERVICE_ERROR_CRITICAL 0x00000003
3386
3387 /* Service types */
3388 #define SERVICE_KERNEL_DRIVER      0x00000001
3389 #define SERVICE_FILE_SYSTEM_DRIVER 0x00000002
3390 #define SERVICE_ADAPTER            0x00000004
3391 #define SERVICE_RECOGNIZER_DRIVER  0x00000008
3392
3393 #define SERVICE_DRIVER ( SERVICE_KERNEL_DRIVER | SERVICE_FILE_SYSTEM_DRIVER | \
3394                          SERVICE_RECOGNIZER_DRIVER )
3395
3396 #define SERVICE_WIN32_OWN_PROCESS   0x00000010
3397 #define SERVICE_WIN32_SHARE_PROCESS 0x00000020
3398 #define SERVICE_WIN32  (SERVICE_WIN32_OWN_PROCESS | SERVICE_WIN32_SHARE_PROCESS)
3399
3400 #define SERVICE_INTERACTIVE_PROCESS 0x00000100
3401
3402 #define SERVICE_TYPE_ALL ( SERVICE_WIN32 | SERVICE_ADAPTER | \
3403                            SERVICE_DRIVER | SERVICE_INTERACTIVE_PROCESS )
3404
3405
3406 typedef enum _CM_SERVICE_NODE_TYPE 
3407 {
3408   DriverType               = SERVICE_KERNEL_DRIVER,
3409   FileSystemType           = SERVICE_FILE_SYSTEM_DRIVER,
3410   Win32ServiceOwnProcess   = SERVICE_WIN32_OWN_PROCESS,
3411   Win32ServiceShareProcess = SERVICE_WIN32_SHARE_PROCESS,
3412   AdapterType              = SERVICE_ADAPTER,
3413   RecognizerType           = SERVICE_RECOGNIZER_DRIVER
3414 } SERVICE_NODE_TYPE;
3415
3416 typedef enum _CM_SERVICE_LOAD_TYPE 
3417 {
3418   BootLoad    = SERVICE_BOOT_START,
3419   SystemLoad  = SERVICE_SYSTEM_START,
3420   AutoLoad    = SERVICE_AUTO_START,
3421   DemandLoad  = SERVICE_DEMAND_START,
3422   DisableLoad = SERVICE_DISABLED
3423 } SERVICE_LOAD_TYPE;
3424
3425 typedef enum _CM_ERROR_CONTROL_TYPE 
3426 {
3427   IgnoreError   = SERVICE_ERROR_IGNORE,
3428   NormalError   = SERVICE_ERROR_NORMAL,
3429   SevereError   = SERVICE_ERROR_SEVERE,
3430   CriticalError = SERVICE_ERROR_CRITICAL
3431 } SERVICE_ERROR_TYPE;
3432
3433
3434
3435 #define RtlEqualMemory(Destination, Source, Length) (!memcmp((Destination),(Source),(Length)))
3436 #define RtlMoveMemory(Destination, Source, Length) memmove((Destination),(Source),(Length))
3437 #define RtlCopyMemory(Destination, Source, Length) memcpy((Destination),(Source),(Length))
3438 #define RtlFillMemory(Destination, Length, Fill) memset((Destination),(Fill),(Length))
3439 #define RtlZeroMemory(Destination, Length) memset((Destination),0,(Length))
3440
3441 #include "guiddef.h"
3442
3443 #include "poppack.h"
3444
3445 #endif  /* __WINE_WINNT_H */