Fixed packing and layout of many system structures.
[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 <stddef.h>
15 #include <string.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 /* Architecture dependent settings. */
31 /* These are hardcoded to avoid dependencies on config.h in Winelib apps. */
32 #if defined(__i386__)
33 # undef  WORDS_BIGENDIAN
34 # undef  BITFIELDS_BIGENDIAN
35 # define ALLOW_UNALIGNED_ACCESS
36 #elif defined(__sparc__)
37 # define WORDS_BIGENDIAN
38 # define BITFIELDS_BIGENDIAN
39 # undef  ALLOW_UNALIGNED_ACCESS
40 #elif defined(__PPC__)
41 # define WORDS_BIGENDIAN
42 # define BITFIELDS_BIGENDIAN
43 # undef  ALLOW_UNALIGNED_ACCESS
44 #elif !defined(RC_INVOKED)
45 # error Unknown CPU architecture!
46 #endif
47
48
49 /* Calling conventions definitions */
50
51 #ifdef __i386__
52 # ifndef _X86_
53 #  define _X86_
54 # endif
55 # if defined(__GNUC__) && ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 7)))
56 #  define __stdcall __attribute__((__stdcall__))
57 #  define __cdecl   __attribute__((__cdecl__))
58 # else
59 #  error You need gcc >= 2.7 to build Wine on a 386
60 # endif  /* __GNUC__ */
61 #else  /* __i386__ */
62 # define __stdcall
63 # define __cdecl
64 #endif  /* __i386__ */
65
66 #ifndef __WINE__
67 #define pascal      __stdcall
68 #define _pascal     __stdcall
69 #define _stdcall    __stdcall
70 #define _fastcall   __stdcall
71 #define __fastcall  __stdcall
72 #define __export    __stdcall
73 #define cdecl       __cdecl
74 #define _cdecl      __cdecl
75
76 #define near
77 #define far
78 #define _near
79 #define _far
80 #define NEAR
81 #define FAR
82
83 #ifndef _declspec
84 #define _declspec(x)
85 #endif
86 #ifndef __declspec
87 #define __declspec(x)
88 #endif
89 #endif /* __WINE__ */
90
91 #define CALLBACK    __stdcall
92 #define WINAPI      __stdcall
93 #define APIPRIVATE  __stdcall
94 #define PASCAL      __stdcall
95 #define CDECL       __cdecl
96 #define _CDECL      __cdecl
97 #define WINAPIV     __cdecl
98 #define APIENTRY    WINAPI
99 #define CONST       const
100
101 /* Macro for structure packing and more. */
102
103 #ifdef __GNUC__
104 #define WINE_PACKED   __attribute__((packed))
105 #define WINE_UNUSED   __attribute__((unused))
106 #define WINE_NORETURN __attribute__((noreturn))
107 #else
108 #define WINE_PACKED    /* nothing */
109 #define WINE_UNUSED    /* nothing */
110 #define WINE_NORETURN  /* nothing */
111 #endif
112
113 /* Anonymous union/struct handling */
114
115 #ifdef __WINE__
116 # define NONAMELESSSTRUCT
117 # define NONAMELESSUNION
118 #else
119 /* Anonymous struct support starts with gcc/g++ 2.96 */
120 # if !defined(NONAMELESSSTRUCT) && defined(__GNUC__) && ((__GNUC__ < 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ < 96)))
121 #  define NONAMELESSSTRUCT
122 # endif
123 /* Anonymous unions support starts with gcc 2.96/g++ 2.95 */
124 # if !defined(NONAMELESSUNION) && defined(__GNUC__) && ((__GNUC__ < 2) || ((__GNUC__ == 2) && ((__GNUC_MINOR__ < 95) || ((__GNUC_MINOR__ == 95) && !defined(__cplusplus)))))
125 #  define NONAMELESSUNION
126 # endif
127 #endif
128
129 #ifndef NONAMELESSSTRUCT
130 #define DUMMYSTRUCTNAME
131 #define DUMMYSTRUCTNAME1
132 #define DUMMYSTRUCTNAME2
133 #define DUMMYSTRUCTNAME3
134 #define DUMMYSTRUCTNAME4
135 #define DUMMYSTRUCTNAME5
136 #else /* !defined(NONAMELESSSTRUCT) */
137 #define DUMMYSTRUCTNAME   s
138 #define DUMMYSTRUCTNAME1  s1
139 #define DUMMYSTRUCTNAME2  s2
140 #define DUMMYSTRUCTNAME3  s3
141 #define DUMMYSTRUCTNAME4  s4
142 #define DUMMYSTRUCTNAME5  s5
143 #endif /* !defined(NONAMELESSSTRUCT) */
144
145 #ifndef NONAMELESSUNION
146 #define DUMMYUNIONNAME
147 #define DUMMYUNIONNAME1
148 #define DUMMYUNIONNAME2
149 #define DUMMYUNIONNAME3
150 #define DUMMYUNIONNAME4
151 #define DUMMYUNIONNAME5
152 #define DUMMYUNIONNAME6
153 #define DUMMYUNIONNAME7
154 #define DUMMYUNIONNAME8
155 #else /* !defined(NONAMELESSUNION) */
156 #define DUMMYUNIONNAME   u
157 #define DUMMYUNIONNAME1  u1
158 #define DUMMYUNIONNAME2  u2
159 #define DUMMYUNIONNAME3  u3
160 #define DUMMYUNIONNAME4  u4
161 #define DUMMYUNIONNAME5  u5
162 #define DUMMYUNIONNAME6  u6
163 #define DUMMYUNIONNAME7  u7
164 #define DUMMYUNIONNAME8  u8
165 #endif /* !defined(NONAMELESSUNION) */
166
167
168 /**** Parts of windef.h that are needed here *****/
169
170 /* Misc. constants. */
171
172 #undef NULL
173 #ifdef __cplusplus
174 #define NULL  0
175 #else
176 #define NULL  ((void*)0)
177 #endif
178
179 #ifdef FALSE
180 #undef FALSE
181 #endif
182 #define FALSE 0
183
184 #ifdef TRUE
185 #undef TRUE
186 #endif
187 #define TRUE  1
188
189 #ifndef IN
190 #define IN
191 #endif
192
193 #ifndef OUT
194 #define OUT
195 #endif
196
197 #ifndef OPTIONAL
198 #define OPTIONAL
199 #endif
200
201 /* Standard data types */
202 typedef const void                  *PCVOID,   *LPCVOID;
203 typedef int             BOOL,       *PBOOL,    *LPBOOL;
204 typedef unsigned char   BYTE,       *PBYTE,    *LPBYTE;
205 typedef unsigned char   UCHAR,      *PUCHAR;
206 typedef unsigned short  USHORT,     *PUSHORT,  *LPUSHORT;
207 typedef unsigned short  WORD,       *PWORD,    *LPWORD;
208 typedef int             INT,        *PINT,     *LPINT;
209 typedef unsigned int    UINT,       *PUINT,    *LPUINT;
210 typedef unsigned long   DWORD,      *PDWORD,   *LPDWORD;
211 typedef unsigned long   ULONG,      *PULONG,   *LPULONG;
212 typedef float           FLOAT,      *PFLOAT,   *LPFLOAT;
213 typedef double          DOUBLE,     *PDOUBLE,  *LPDOUBLE;
214 typedef double          DATE;
215
216
217 /**** winnt.h proper *****/
218
219 /* Microsoft's macros for declaring functions */
220
221 #ifdef __cplusplus
222 # define EXTERN_C    extern "C"
223 #else
224 # define EXTERN_C    extern
225 #endif
226
227 #ifndef __WINE__
228 #define STDMETHODCALLTYPE       __stdcall
229 #define STDMETHODVCALLTYPE      __cdecl
230 #define STDAPICALLTYPE          __stdcall
231 #define STDAPIVCALLTYPE         __cdecl
232
233 #define STDAPI                  EXTERN_C HRESULT STDAPICALLTYPE
234 #define STDAPI_(type)           EXTERN_C type STDAPICALLTYPE
235 #define STDMETHODIMP            HRESULT STDMETHODCALLTYPE
236 #define STDMETHODIMP_(type)     type STDMETHODCALLTYPE
237 #define STDAPIV                 EXTERN_C HRESULT STDAPIVCALLTYPE
238 #define STDAPIV_(type)          EXTERN_C type STDAPIVCALLTYPE
239 #define STDMETHODIMPV           HRESULT STDMETHODVCALLTYPE
240 #define STDMETHODIMPV_(type)    type STDMETHODVCALLTYPE
241 #endif
242
243 /* Define the basic types */
244 #ifndef VOID
245 #define VOID void
246 #endif
247 typedef VOID           *PVOID,      *LPVOID;
248 typedef BYTE            BOOLEAN,    *PBOOLEAN;
249 typedef char            CHAR,       *PCHAR;
250 typedef short           SHORT,      *PSHORT;
251 typedef long            LONG,       *PLONG,    *LPLONG;
252
253 /* Some systems might have wchar_t, but we really need 16 bit characters */
254 #ifndef WINE_WCHAR_DEFINED
255 #ifdef WINE_UNICODE_NATIVE
256 typedef wchar_t         WCHAR,      *PWCHAR;
257 #else
258 typedef unsigned short  WCHAR,      *PWCHAR;
259 #endif
260 #define WINE_WCHAR_DEFINED
261 #endif
262
263 /* 'Extended/Wide' numerical types */
264 #ifndef _ULONGLONG_
265 #define _ULONGLONG_
266 typedef __int64         LONGLONG,   *PLONGLONG;
267 typedef __uint64        ULONGLONG,  *PULONGLONG;
268 #endif
269
270 #ifndef _DWORDLONG_
271 #define _DWORDLONG_
272 typedef ULONGLONG       DWORDLONG,  *PDWORDLONG;
273 #endif
274
275 /* ANSI string types */
276 typedef CHAR           *PCH,        *LPCH;
277 typedef const CHAR     *PCCH,       *LPCCH;
278 typedef CHAR           *PSTR,       *LPSTR;
279 typedef const CHAR     *PCSTR,      *LPCSTR;
280
281 /* Unicode string types */
282 typedef WCHAR          *PWCH,       *LPWCH;
283 typedef const WCHAR    *PCWCH,      *LPCWCH;
284 typedef WCHAR          *PWSTR,      *LPWSTR;
285 typedef const WCHAR    *PCWSTR,     *LPCWSTR;
286
287 /* Neutral character and string types */
288 /* These are only defined for Winelib, i.e. _not_ defined for 
289  * the emulator. The reason is they depend on the UNICODE 
290  * macro which only exists in the user's code.
291  */
292 #ifndef __WINE__
293 # ifdef WINE_UNICODE_REWRITE
294
295 /* Use this if your compiler does not provide a 16bit wchar_t type. 
296  * Note that you will need to specify -fwritable-strings or an option
297  * to this effect.
298  * In C++ both WINE_UNICODE_TEXT('c') and WINE_UNICODE_TEXT("str") are 
299  * supported, but only the string form can be supported in C.
300  */
301 EXTERN_C unsigned short* wine_rewrite_s4tos2(const wchar_t* str4);
302 #  ifdef __cplusplus
303 inline WCHAR* wine_unicode_text(const wchar_t* str4)
304 {
305   return (WCHAR*)wine_rewrite_s4tos2(str4);
306 }
307 inline WCHAR wine_unicode_text(wchar_t chr4)
308 {
309   return (WCHAR)chr4;
310 }
311 #   define WINE_UNICODE_TEXT(x)       wine_unicode_text(L##x)
312 #  else  /* __cplusplus */
313 #   define WINE_UNICODE_TEXT(x)       ((WCHAR*)wine_rewrite_s4tos2(L##x))
314 #  endif  /* __cplusplus */
315
316 # else  /* WINE_UNICODE_REWRITE */
317
318 /* Define WINE_UNICODE_NATIVE if:
319  * - your compiler provides a 16bit wchar_t type, e.g. gcc >= 2.96 with 
320  *   -fshort-wchar option
321  * - or if you decide to use the native 32bit Unix wchar_t type. Be aware 
322  *   though that the Wine APIs only support 16bit WCHAR characters for 
323  *   binary compatibility reasons.
324  * - or define nothing at all if you don't use Unicode, and blissfully 
325  *   ignore the issue :-)
326  */
327 #  define WINE_UNICODE_TEXT(string)   L##string
328
329 # endif  /* WINE_UNICODE_REWRITE */
330
331 # ifdef UNICODE
332 typedef WCHAR           TCHAR,      *PTCHAR;
333 typedef LPWSTR          PTSTR,       LPTSTR;
334 typedef LPCWSTR         PCTSTR,      LPCTSTR;
335 #  define __TEXT(string) WINE_UNICODE_TEXT(string)
336 # else  /* UNICODE */
337 typedef CHAR            TCHAR,      *PTCHAR;
338 typedef LPSTR           PTSTR,       LPTSTR;
339 typedef LPCSTR          PCTSTR,      LPCTSTR;
340 #  define __TEXT(string) string
341 # endif /* UNICODE */
342 # define TEXT(quote) __TEXT(quote)
343 #endif   /* __WINE__ */
344
345 /* Misc common WIN32 types */
346 typedef LONG            HRESULT;
347 typedef DWORD           LCID,       *PLCID;
348 typedef WORD            LANGID;
349 typedef DWORD           EXECUTION_STATE;
350
351 /* Handle type */
352
353 /* FIXME: Wine does not compile with strict on, therefore strict
354  * handles are presently only usable on machines where sizeof(UINT) ==
355  * sizeof(void*).  HANDLEs are supposed to be void* but a large amount
356  * of WINE code operates on HANDLES as if they are UINTs. So to WINE
357  * they exist as UINTs but to the Winelib user who turns on strict,
358  * they exist as void*. If there is a size difference between UINT and
359  * void* then things get ugly.
360  *
361  * Here is the plan to convert Wine to STRICT:
362  *
363  * Types will be converted one at a time by volunteers who will compile
364  * Wine with STRICT turned on. Handles that have not been converted yet 
365  * will be declared with DECLARE_OLD_HANDLE. Converted handles are 
366  * declared with DECLARE_HANDLE.
367  * See the bug report 90 for more details:
368  *    http://wine.codeweavers.com/bugzilla/show_bug.cgi?id=90
369  */
370 /*
371  * when compiling Wine we always treat HANDLE as an UINT. Then when 
372  * we're ready we'll remove the '!defined(__WINE__)' (the equivalent 
373  * of converting it from DECLARE_OLD_HANDLE to DECLARE_HANDLE).
374  */
375 #if defined(STRICT) && !defined(__WINE__)
376 typedef VOID*           HANDLE;
377 #define DECLARE_OLD_HANDLE(a) \
378     typedef struct a##__ { int unused; } *a; \
379     typedef a          *P##a,       *LP##a
380
381 #else
382 typedef UINT            HANDLE;
383 #define DECLARE_OLD_HANDLE(a) \
384     typedef HANDLE      a; \
385     typedef a          *P##a,       *LP##a
386 #endif
387 typedef HANDLE         *PHANDLE,    *LPHANDLE;
388
389 #ifdef STRICT
390 #define DECLARE_HANDLE(a) \
391     typedef struct a##__ { int unused; } *a; \
392     typedef a          *P##a,       *LP##a
393 #else /*STRICT*/
394 #define DECLARE_HANDLE(a) \
395     typedef HANDLE      a; \
396     typedef a          *P##a,       *LP##a
397 #endif /*STRICT*/
398
399 /* Defines */
400
401 /* Argument 1 passed to the DllEntryProc. */
402 #define DLL_PROCESS_DETACH      0       /* detach process (unload library) */
403 #define DLL_PROCESS_ATTACH      1       /* attach process (load library) */
404 #define DLL_THREAD_ATTACH       2       /* attach new thread */
405 #define DLL_THREAD_DETACH       3       /* detach thread */
406
407
408 /* u.x.wProcessorArchitecture (NT) */
409 #define PROCESSOR_ARCHITECTURE_INTEL    0
410 #define PROCESSOR_ARCHITECTURE_MIPS     1
411 #define PROCESSOR_ARCHITECTURE_ALPHA    2
412 #define PROCESSOR_ARCHITECTURE_PPC      3
413 #define PROCESSOR_ARCHITECTURE_SHX      4
414 #define PROCESSOR_ARCHITECTURE_ARM      5
415 #define PROCESSOR_ARCHITECTURE_UNKNOWN  0xFFFF
416
417 /* dwProcessorType */
418 #define PROCESSOR_INTEL_386      386
419 #define PROCESSOR_INTEL_486      486
420 #define PROCESSOR_INTEL_PENTIUM  586
421 #define PROCESSOR_INTEL_860      860
422 #define PROCESSOR_MIPS_R2000     2000
423 #define PROCESSOR_MIPS_R3000     3000
424 #define PROCESSOR_MIPS_R4000     4000
425 #define PROCESSOR_ALPHA_21064    21064
426 #define PROCESSOR_PPC_601        601
427 #define PROCESSOR_PPC_603        603
428 #define PROCESSOR_PPC_604        604
429 #define PROCESSOR_PPC_620        620
430 #define PROCESSOR_HITACHI_SH3    10003
431 #define PROCESSOR_HITACHI_SH3E   10004
432 #define PROCESSOR_HITACHI_SH4    10005
433 #define PROCESSOR_MOTOROLA_821   821
434 #define PROCESSOR_SHx_SH3        103
435 #define PROCESSOR_SHx_SH4        104
436 #define PROCESSOR_STRONGARM      2577
437 #define PROCESSOR_ARM720         1824    /* 0x720 */
438 #define PROCESSOR_ARM820         2080    /* 0x820 */
439 #define PROCESSOR_ARM920         2336    /* 0x920 */
440 #define PROCESSOR_ARM_7TDMI      70001
441
442 typedef struct _MEMORY_BASIC_INFORMATION
443 {
444     LPVOID   BaseAddress;
445     LPVOID   AllocationBase;
446     DWORD    AllocationProtect;
447     DWORD    RegionSize;
448     DWORD    State;
449     DWORD    Protect;
450     DWORD    Type;
451 } MEMORY_BASIC_INFORMATION,*LPMEMORY_BASIC_INFORMATION,*PMEMORY_BASIC_INFORMATION;
452
453 #define PAGE_NOACCESS           0x01
454 #define PAGE_READONLY           0x02
455 #define PAGE_READWRITE          0x04
456 #define PAGE_WRITECOPY          0x08
457 #define PAGE_EXECUTE            0x10
458 #define PAGE_EXECUTE_READ       0x20
459 #define PAGE_EXECUTE_READWRITE  0x40
460 #define PAGE_EXECUTE_WRITECOPY  0x80
461 #define PAGE_GUARD              0x100
462 #define PAGE_NOCACHE            0x200
463
464 #define MEM_COMMIT              0x00001000
465 #define MEM_RESERVE             0x00002000
466 #define MEM_DECOMMIT            0x00004000
467 #define MEM_RELEASE             0x00008000
468 #define MEM_FREE                0x00010000
469 #define MEM_PRIVATE             0x00020000
470 #define MEM_MAPPED              0x00040000
471 #define MEM_RESET               0x00080000
472 #define MEM_TOP_DOWN            0x00100000
473 #ifdef __WINE__
474 #define MEM_SYSTEM              0x80000000
475 #endif
476
477 #define SEC_FILE                0x00800000
478 #define SEC_IMAGE               0x01000000
479 #define SEC_RESERVE             0x04000000
480 #define SEC_COMMIT              0x08000000
481 #define SEC_NOCACHE             0x10000000
482 #define MEM_IMAGE               SEC_IMAGE
483
484
485 #define MINCHAR       0x80
486 #define MAXCHAR       0x7f
487 #define MINSHORT      0x8000
488 #define MAXSHORT      0x7fff
489 #define MINLONG       0x80000000
490 #define MAXLONG       0x7fffffff
491 #define MAXBYTE       0xff
492 #define MAXWORD       0xffff
493 #define MAXDWORD      0xffffffff
494
495 #define FIELD_OFFSET(type, field) \
496   ((LONG)(INT)&(((type *)0)->field))
497
498 #define CONTAINING_RECORD(address, type, field) \
499   ((type *)((PCHAR)(address) - (PCHAR)(&((type *)0)->field)))
500
501 /* Types */
502
503 typedef struct _LIST_ENTRY {
504   struct _LIST_ENTRY *Flink;
505   struct _LIST_ENTRY *Blink;
506 } LIST_ENTRY, *PLIST_ENTRY;
507
508 typedef struct _SINGLE_LIST_ENTRY {
509   struct _SINGLE_LIST_ENTRY *Next;
510 } SINGLE_LIST_ENTRY, *PSINGLE_LIST_ENTRY;
511
512 /* Heap flags */
513
514 #define HEAP_NO_SERIALIZE               0x00000001
515 #define HEAP_GROWABLE                   0x00000002
516 #define HEAP_GENERATE_EXCEPTIONS        0x00000004
517 #define HEAP_ZERO_MEMORY                0x00000008
518 #define HEAP_REALLOC_IN_PLACE_ONLY      0x00000010
519 #define HEAP_TAIL_CHECKING_ENABLED      0x00000020
520 #define HEAP_FREE_CHECKING_ENABLED      0x00000040
521 #define HEAP_DISABLE_COALESCE_ON_FREE   0x00000080
522 #define HEAP_CREATE_ALIGN_16            0x00010000
523 #define HEAP_CREATE_ENABLE_TRACING      0x00020000
524
525 /* This flag allows it to create heaps shared by all processes under win95,
526    FIXME: correct name */
527 #define HEAP_SHARED                     0x04000000  
528
529 #define HEAP_WINE_SEGPTR                0x10000000  /* Not a Win32 flag */
530 #define HEAP_WINE_CODESEG               0x20000000  /* Not a Win32 flag */
531 #define HEAP_WINE_CODE16SEG             0x40000000  /* Not a Win32 flag */
532
533 /* Processor feature flags.  */
534 #define PF_FLOATING_POINT_PRECISION_ERRATA      0
535 #define PF_FLOATING_POINT_EMULATED              1
536 #define PF_COMPARE_EXCHANGE_DOUBLE              2
537 #define PF_MMX_INSTRUCTIONS_AVAILABLE           3
538 #define PF_PPC_MOVEMEM_64BIT_OK                 4
539 #define PF_ALPHA_BYTE_INSTRUCTIONS              5
540 #define PF_XMMI_INSTRUCTIONS_AVAILABLE          6
541 #define PF_AMD3D_INSTRUCTIONS_AVAILABLE         7
542 #define PF_RDTSC_INSTRUCTION_AVAILABLE          8
543
544
545 /* Execution state flags */
546 #define ES_SYSTEM_REQUIRED    0x00000001
547 #define ES_DISPLAY_REQUIRED   0x00000002
548 #define ES_USER_PRESENT       0x00000004
549 #define ES_CONTINUOUS         0x80000000
550
551 /* The Win32 register context */
552
553 /* CONTEXT is the CPU-dependent context; it should be used        */
554 /* wherever a platform-specific context is needed (e.g. exception */
555 /* handling, Win32 register functions). */
556
557 /* CONTEXT86 is the i386-specific context; it should be used     */
558 /* wherever only a 386 context makes sense (e.g. DOS interrupts, */
559 /* Win16 register functions), so that this code can be compiled  */
560 /* on all platforms. */
561
562 #define SIZE_OF_80387_REGISTERS      80
563
564 typedef struct _FLOATING_SAVE_AREA
565 {
566     DWORD   ControlWord;
567     DWORD   StatusWord;
568     DWORD   TagWord;    
569     DWORD   ErrorOffset;
570     DWORD   ErrorSelector;
571     DWORD   DataOffset;
572     DWORD   DataSelector;    
573     BYTE    RegisterArea[SIZE_OF_80387_REGISTERS];
574     DWORD   Cr0NpxState;
575 } FLOATING_SAVE_AREA, *PFLOATING_SAVE_AREA;
576
577 #define MAXIMUM_SUPPORTED_EXTENSION     512
578
579 typedef struct _CONTEXT86
580 {
581     DWORD   ContextFlags;
582
583     /* These are selected by CONTEXT_DEBUG_REGISTERS */
584     DWORD   Dr0;
585     DWORD   Dr1;
586     DWORD   Dr2;
587     DWORD   Dr3;
588     DWORD   Dr6;
589     DWORD   Dr7;
590
591     /* These are selected by CONTEXT_FLOATING_POINT */
592     FLOATING_SAVE_AREA FloatSave;
593
594     /* These are selected by CONTEXT_SEGMENTS */
595     DWORD   SegGs;
596     DWORD   SegFs;
597     DWORD   SegEs;
598     DWORD   SegDs;    
599
600     /* These are selected by CONTEXT_INTEGER */
601     DWORD   Edi;
602     DWORD   Esi;
603     DWORD   Ebx;
604     DWORD   Edx;    
605     DWORD   Ecx;
606     DWORD   Eax;
607
608     /* These are selected by CONTEXT_CONTROL */
609     DWORD   Ebp;    
610     DWORD   Eip;
611     DWORD   SegCs;
612     DWORD   EFlags;
613     DWORD   Esp;
614     DWORD   SegSs;
615
616     BYTE    ExtendedRegisters[MAXIMUM_SUPPORTED_EXTENSION];
617 } CONTEXT86;
618
619 #define CONTEXT_X86       0x00010000
620 #define CONTEXT_i386      CONTEXT_X86
621 #define CONTEXT_i486      CONTEXT_X86
622
623 #define CONTEXT86_CONTROL   (CONTEXT_i386 | 0x0001) /* SS:SP, CS:IP, FLAGS, BP */
624 #define CONTEXT86_INTEGER   (CONTEXT_i386 | 0x0002) /* AX, BX, CX, DX, SI, DI */
625 #define CONTEXT86_SEGMENTS  (CONTEXT_i386 | 0x0004) /* DS, ES, FS, GS */
626 #define CONTEXT86_FLOATING_POINT  (CONTEXT_i386 | 0x0008L) /* 387 state */
627 #define CONTEXT86_DEBUG_REGISTERS (CONTEXT_i386 | 0x0010L) /* DB 0-3,6,7 */
628 #define CONTEXT86_FULL (CONTEXT86_CONTROL | CONTEXT86_INTEGER | CONTEXT86_SEGMENTS)
629
630 /* i386 context definitions */
631 #ifdef __i386__
632
633 #define CONTEXT_CONTROL         CONTEXT86_CONTROL
634 #define CONTEXT_INTEGER         CONTEXT86_INTEGER
635 #define CONTEXT_SEGMENTS        CONTEXT86_SEGMENTS
636 #define CONTEXT_FLOATING_POINT  CONTEXT86_FLOATING_POINT
637 #define CONTEXT_DEBUG_REGISTERS CONTEXT86_DEBUG_REGISTERS
638 #define CONTEXT_FULL            CONTEXT86_FULL
639
640 typedef CONTEXT86 CONTEXT;
641
642 #endif  /* __i386__ */
643
644 /* Alpha context definitions */
645 #ifdef _ALPHA_
646
647 #define CONTEXT_ALPHA   0x00020000
648  
649 #define CONTEXT_CONTROL         (CONTEXT_ALPHA | 0x00000001L)
650 #define CONTEXT_FLOATING_POINT  (CONTEXT_ALPHA | 0x00000002L)
651 #define CONTEXT_INTEGER         (CONTEXT_ALPHA | 0x00000004L)
652 #define CONTEXT_FULL  (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER)
653
654 typedef struct _CONTEXT
655 {
656     /* selected by CONTEXT_FLOATING_POINT */
657     ULONGLONG FltF0;
658     ULONGLONG FltF1;
659     ULONGLONG FltF2;
660     ULONGLONG FltF3;
661     ULONGLONG FltF4;
662     ULONGLONG FltF5;
663     ULONGLONG FltF6;
664     ULONGLONG FltF7;
665     ULONGLONG FltF8;
666     ULONGLONG FltF9;
667     ULONGLONG FltF10;
668     ULONGLONG FltF11;
669     ULONGLONG FltF12;
670     ULONGLONG FltF13;
671     ULONGLONG FltF14;
672     ULONGLONG FltF15;
673     ULONGLONG FltF16;
674     ULONGLONG FltF17;
675     ULONGLONG FltF18;
676     ULONGLONG FltF19;
677     ULONGLONG FltF20;
678     ULONGLONG FltF21;
679     ULONGLONG FltF22;
680     ULONGLONG FltF23;
681     ULONGLONG FltF24;
682     ULONGLONG FltF25;
683     ULONGLONG FltF26;
684     ULONGLONG FltF27;
685     ULONGLONG FltF28;
686     ULONGLONG FltF29;
687     ULONGLONG FltF30;
688     ULONGLONG FltF31;
689
690     /* selected by CONTEXT_INTEGER */
691     ULONGLONG IntV0;
692     ULONGLONG IntT0;
693     ULONGLONG IntT1;
694     ULONGLONG IntT2;
695     ULONGLONG IntT3;
696     ULONGLONG IntT4;
697     ULONGLONG IntT5;
698     ULONGLONG IntT6;
699     ULONGLONG IntT7;
700     ULONGLONG IntS0;
701     ULONGLONG IntS1;
702     ULONGLONG IntS2;
703     ULONGLONG IntS3;
704     ULONGLONG IntS4;
705     ULONGLONG IntS5;
706     ULONGLONG IntFp;
707     ULONGLONG IntA0;
708     ULONGLONG IntA1;
709     ULONGLONG IntA2;
710     ULONGLONG IntA3;
711     ULONGLONG IntA4;
712     ULONGLONG IntA5;
713     ULONGLONG IntT8;
714     ULONGLONG IntT9;
715     ULONGLONG IntT10;
716     ULONGLONG IntT11;
717     ULONGLONG IntRa;
718     ULONGLONG IntT12;
719     ULONGLONG IntAt;
720     ULONGLONG IntGp;
721     ULONGLONG IntSp;
722     ULONGLONG IntZero;
723
724     /* selected by CONTEXT_FLOATING_POINT */
725     ULONGLONG Fpcr;
726     ULONGLONG SoftFpcr;
727
728     /* selected by CONTEXT_CONTROL */
729     ULONGLONG Fir;
730     DWORD Psr;
731     DWORD ContextFlags;
732     DWORD Fill[4];
733 } CONTEXT;
734
735 #define _QUAD_PSR_OFFSET   HighSoftFpcr
736 #define _QUAD_FLAGS_OFFSET HighFir
737
738 #endif  /* _ALPHA_ */
739
740 /* Mips context definitions */
741 #ifdef _MIPS_
742
743 #define CONTEXT_R4000   0x00010000
744
745 #define CONTEXT_CONTROL         (CONTEXT_R4000 | 0x00000001)
746 #define CONTEXT_FLOATING_POINT  (CONTEXT_R4000 | 0x00000002)
747 #define CONTEXT_INTEGER         (CONTEXT_R4000 | 0x00000004)
748
749 #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER)
750
751 typedef struct _CONTEXT
752 {
753     DWORD Argument[4];
754     /* These are selected by CONTEXT_FLOATING_POINT */
755     DWORD FltF0;
756     DWORD FltF1;
757     DWORD FltF2;
758     DWORD FltF3;
759     DWORD FltF4;
760     DWORD FltF5;
761     DWORD FltF6;
762     DWORD FltF7;
763     DWORD FltF8;
764     DWORD FltF9;
765     DWORD FltF10;
766     DWORD FltF11;
767     DWORD FltF12;
768     DWORD FltF13;
769     DWORD FltF14;
770     DWORD FltF15;
771     DWORD FltF16;
772     DWORD FltF17;
773     DWORD FltF18;
774     DWORD FltF19;
775     DWORD FltF20;
776     DWORD FltF21;
777     DWORD FltF22;
778     DWORD FltF23;
779     DWORD FltF24;
780     DWORD FltF25;
781     DWORD FltF26;
782     DWORD FltF27;
783     DWORD FltF28;
784     DWORD FltF29;
785     DWORD FltF30;
786     DWORD FltF31;
787
788     /* These are selected by CONTEXT_INTEGER */
789     DWORD IntZero;
790     DWORD IntAt;
791     DWORD IntV0;
792     DWORD IntV1;
793     DWORD IntA0;
794     DWORD IntA1;
795     DWORD IntA2;
796     DWORD IntA3;
797     DWORD IntT0;
798     DWORD IntT1;
799     DWORD IntT2;
800     DWORD IntT3;
801     DWORD IntT4;
802     DWORD IntT5;
803     DWORD IntT6;
804     DWORD IntT7;
805     DWORD IntS0;
806     DWORD IntS1;
807     DWORD IntS2;
808     DWORD IntS3;
809     DWORD IntS4;
810     DWORD IntS5;
811     DWORD IntS6;
812     DWORD IntS7;
813     DWORD IntT8;
814     DWORD IntT9;
815     DWORD IntK0;
816     DWORD IntK1;
817     DWORD IntGp;
818     DWORD IntSp;
819     DWORD IntS8;
820     DWORD IntRa;
821     DWORD IntLo;
822     DWORD IntHi;
823
824     /* These are selected by CONTEXT_FLOATING_POINT */
825     DWORD Fsr;
826
827     /* These are selected by CONTEXT_CONTROL */
828     DWORD Fir;
829     DWORD Psr;
830
831     DWORD ContextFlags;
832     DWORD Fill[2];
833 } CONTEXT;
834
835 #endif  /* _MIPS_ */
836
837 /* PowerPC context definitions */
838 #ifdef __PPC__
839
840 #define CONTEXT_CONTROL         0x0001
841 #define CONTEXT_FLOATING_POINT  0x0002
842 #define CONTEXT_INTEGER         0x0004
843 #define CONTEXT_DEBUG_REGISTERS 0x0008
844 #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER)
845
846 typedef struct
847 {
848     /* These are selected by CONTEXT_FLOATING_POINT */
849     double Fpr0;
850     double Fpr1;
851     double Fpr2;
852     double Fpr3;
853     double Fpr4;
854     double Fpr5;
855     double Fpr6;
856     double Fpr7;
857     double Fpr8;
858     double Fpr9;
859     double Fpr10;
860     double Fpr11;
861     double Fpr12;
862     double Fpr13;
863     double Fpr14;
864     double Fpr15;
865     double Fpr16;
866     double Fpr17;
867     double Fpr18;
868     double Fpr19;
869     double Fpr20;
870     double Fpr21;
871     double Fpr22;
872     double Fpr23;
873     double Fpr24;
874     double Fpr25;
875     double Fpr26;
876     double Fpr27;
877     double Fpr28;
878     double Fpr29;
879     double Fpr30;
880     double Fpr31;
881     double Fpscr;
882
883     /* These are selected by CONTEXT_INTEGER */
884     DWORD Gpr0;
885     DWORD Gpr1;
886     DWORD Gpr2;
887     DWORD Gpr3;
888     DWORD Gpr4;
889     DWORD Gpr5;
890     DWORD Gpr6;
891     DWORD Gpr7;
892     DWORD Gpr8;
893     DWORD Gpr9;
894     DWORD Gpr10;
895     DWORD Gpr11;
896     DWORD Gpr12;
897     DWORD Gpr13;
898     DWORD Gpr14;
899     DWORD Gpr15;
900     DWORD Gpr16;
901     DWORD Gpr17;
902     DWORD Gpr18;
903     DWORD Gpr19;
904     DWORD Gpr20;
905     DWORD Gpr21;
906     DWORD Gpr22;
907     DWORD Gpr23;
908     DWORD Gpr24;
909     DWORD Gpr25;
910     DWORD Gpr26;
911     DWORD Gpr27;
912     DWORD Gpr28;
913     DWORD Gpr29;
914     DWORD Gpr30;
915     DWORD Gpr31;
916
917     DWORD Cr;
918     DWORD Xer;
919
920     /* These are selected by CONTEXT_CONTROL */
921     DWORD Msr;
922     DWORD Iar;
923     DWORD Lr;
924     DWORD Ctr;
925
926     DWORD ContextFlags;
927     DWORD Fill[3];
928
929     /* These are selected by CONTEXT_DEBUG_REGISTERS */
930     DWORD Dr0;
931     DWORD Dr1;
932     DWORD Dr2;
933     DWORD Dr3;
934     DWORD Dr4;
935     DWORD Dr5;
936     DWORD Dr6;
937     DWORD Dr7;
938 } CONTEXT;
939
940 typedef struct _STACK_FRAME_HEADER
941 {
942     DWORD BackChain;
943     DWORD GlueSaved1;
944     DWORD GlueSaved2;
945     DWORD Reserved1;
946     DWORD Spare1;
947     DWORD Spare2;
948
949     DWORD Parameter0;
950     DWORD Parameter1;
951     DWORD Parameter2;
952     DWORD Parameter3;
953     DWORD Parameter4;
954     DWORD Parameter5;
955     DWORD Parameter6;
956     DWORD Parameter7;
957 } STACK_FRAME_HEADER,*PSTACK_FRAME_HEADER;
958
959 #endif  /* __PPC__ */
960
961 #ifdef __sparc__
962
963 /* 
964  * FIXME:  
965  *
966  * There is no official CONTEXT structure defined for the SPARC 
967  * architecture, so I just made one up.
968  *
969  * This structure is valid only for 32-bit SPARC architectures,
970  * not for 64-bit SPARC.
971  *
972  * Note that this structure contains only the 'top-level' registers;
973  * the rest of the register window chain is not visible.
974  *
975  * The layout follows the Solaris 'prgregset_t' structure.
976  * 
977  */ 
978
979 #define CONTEXT_SPARC            0x10000000
980
981 #define CONTEXT_CONTROL         (CONTEXT_SPARC | 0x00000001)
982 #define CONTEXT_FLOATING_POINT  (CONTEXT_SPARC | 0x00000002)
983 #define CONTEXT_INTEGER         (CONTEXT_SPARC | 0x00000004)
984
985 #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER)
986
987 typedef struct _CONTEXT
988 {
989     DWORD ContextFlags;
990
991     /* These are selected by CONTEXT_INTEGER */
992     DWORD g0;
993     DWORD g1;
994     DWORD g2;
995     DWORD g3;
996     DWORD g4;
997     DWORD g5;
998     DWORD g6;
999     DWORD g7;
1000     DWORD o0;
1001     DWORD o1;
1002     DWORD o2;
1003     DWORD o3;
1004     DWORD o4;
1005     DWORD o5;
1006     DWORD o6;
1007     DWORD o7;
1008     DWORD l0;
1009     DWORD l1;
1010     DWORD l2;
1011     DWORD l3;
1012     DWORD l4;
1013     DWORD l5;
1014     DWORD l6;
1015     DWORD l7;
1016     DWORD i0;
1017     DWORD i1;
1018     DWORD i2;
1019     DWORD i3;
1020     DWORD i4;
1021     DWORD i5;
1022     DWORD i6;
1023     DWORD i7;
1024
1025     /* These are selected by CONTEXT_CONTROL */
1026     DWORD psr;
1027     DWORD pc;
1028     DWORD npc;
1029     DWORD y;
1030     DWORD wim;
1031     DWORD tbr;
1032
1033     /* FIXME: floating point registers missing */
1034
1035 } CONTEXT;
1036
1037 #endif  /* __sparc__ */
1038
1039 #if !defined(CONTEXT_FULL) && !defined(RC_INVOKED)
1040 #error You need to define a CONTEXT for your CPU
1041 #endif
1042
1043 typedef CONTEXT *PCONTEXT;
1044
1045 #ifdef __WINE__
1046
1047 /* Macros for easier access to i386 context registers */
1048
1049 #define AX_reg(context)      (*(WORD*)&(context)->Eax)
1050 #define BX_reg(context)      (*(WORD*)&(context)->Ebx)
1051 #define CX_reg(context)      (*(WORD*)&(context)->Ecx)
1052 #define DX_reg(context)      (*(WORD*)&(context)->Edx)
1053 #define SI_reg(context)      (*(WORD*)&(context)->Esi)
1054 #define DI_reg(context)      (*(WORD*)&(context)->Edi)
1055 #define BP_reg(context)      (*(WORD*)&(context)->Ebp)
1056
1057 #define AL_reg(context)      (*(BYTE*)&(context)->Eax)
1058 #define AH_reg(context)      (*((BYTE*)&(context)->Eax + 1))
1059 #define BL_reg(context)      (*(BYTE*)&(context)->Ebx)
1060 #define BH_reg(context)      (*((BYTE*)&(context)->Ebx + 1))
1061 #define CL_reg(context)      (*(BYTE*)&(context)->Ecx)
1062 #define CH_reg(context)      (*((BYTE*)&(context)->Ecx + 1))
1063 #define DL_reg(context)      (*(BYTE*)&(context)->Edx)
1064 #define DH_reg(context)      (*((BYTE*)&(context)->Edx + 1))
1065
1066 #define SET_CFLAG(context)   ((context)->EFlags |= 0x0001)
1067 #define RESET_CFLAG(context) ((context)->EFlags &= ~0x0001)
1068 #define SET_ZFLAG(context)   ((context)->EFlags |= 0x0040)
1069 #define RESET_ZFLAG(context) ((context)->EFlags &= ~0x0040)
1070 #define ISV86(context)       ((context)->EFlags & 0x00020000)
1071
1072
1073 /* Macros to retrieve the current context */
1074
1075 #ifdef NEED_UNDERSCORE_PREFIX
1076 # define __ASM_NAME(name) "_" name
1077 #else
1078 # define __ASM_NAME(name) name
1079 #endif
1080
1081 #ifdef NEED_TYPE_IN_DEF
1082 # define __ASM_FUNC(name) ".def " __ASM_NAME(name) "; .scl 2; .type 32; .endef"
1083 #else
1084 # define __ASM_FUNC(name) ".type " __ASM_NAME(name) ",@function"
1085 #endif
1086
1087 #ifdef __GNUC__
1088 # define __ASM_GLOBAL_FUNC(name,code) \
1089       __asm__( ".align 4\n\t" \
1090                ".globl " __ASM_NAME(#name) "\n\t" \
1091                __ASM_FUNC(#name) "\n" \
1092                __ASM_NAME(#name) ":\n\t" \
1093                code );
1094 #else  /* __GNUC__ */
1095 # define __ASM_GLOBAL_FUNC(name,code) \
1096       void __asm_dummy_##name(void) { \
1097           asm( ".align 4\n\t" \
1098                ".globl " __ASM_NAME(#name) "\n\t" \
1099                __ASM_FUNC(#name) "\n" \
1100                __ASM_NAME(#name) ":\n\t" \
1101                code ); \
1102       }
1103 #endif  /* __GNUC__ */
1104
1105 #ifdef __i386__
1106
1107 #define _DEFINE_REGS_ENTRYPOINT( name, fn, args ) \
1108     __ASM_GLOBAL_FUNC( name, \
1109                        "call " __ASM_NAME("CALL32_Regs") "\n\t" \
1110                        ".long " __ASM_NAME(#fn) "\n\t" \
1111                        ".byte " #args ", " #args )
1112 #define DEFINE_REGS_ENTRYPOINT_0( name, fn ) \
1113   extern void WINAPI name(void); \
1114   _DEFINE_REGS_ENTRYPOINT( name, fn, 0 )
1115 #define DEFINE_REGS_ENTRYPOINT_1( name, fn, t1 ) \
1116   extern void WINAPI name( t1 a1 ); \
1117   _DEFINE_REGS_ENTRYPOINT( name, fn, 4 )
1118 #define DEFINE_REGS_ENTRYPOINT_2( name, fn, t1, t2 ) \
1119   extern void WINAPI name( t1 a1, t2 a2 ); \
1120   _DEFINE_REGS_ENTRYPOINT( name, fn, 8 )
1121 #define DEFINE_REGS_ENTRYPOINT_3( name, fn, t1, t2, t3 ) \
1122   extern void WINAPI name( t1 a1, t2 a2, t3 a3 ); \
1123   _DEFINE_REGS_ENTRYPOINT( name, fn, 12 )
1124 #define DEFINE_REGS_ENTRYPOINT_4( name, fn, t1, t2, t3, t4 ) \
1125   extern void WINAPI name( t1 a1, t2 a2, t3 a3, t4 a4 ); \
1126   _DEFINE_REGS_ENTRYPOINT( name, fn, 16 )
1127
1128 #endif  /* __i386__ */
1129
1130 #ifdef __sparc__
1131 /* FIXME: use getcontext() to retrieve full context */
1132 #define _GET_CONTEXT \
1133     CONTEXT context;   \
1134     do { memset(&context, 0, sizeof(CONTEXT));            \
1135          context.ContextFlags = CONTEXT_CONTROL;          \
1136          context.pc = (DWORD)__builtin_return_address(0); \
1137        } while (0)
1138
1139 #define DEFINE_REGS_ENTRYPOINT_0( name, fn ) \
1140   void WINAPI name ( void ) \
1141   { _GET_CONTEXT; fn( &context ); }
1142 #define DEFINE_REGS_ENTRYPOINT_1( name, fn, t1 ) \
1143   void WINAPI name ( t1 a1 ) \
1144   { _GET_CONTEXT; fn( a1, &context ); }
1145 #define DEFINE_REGS_ENTRYPOINT_2( name, fn, t1, t2 ) \
1146   void WINAPI name ( t1 a1, t2 a2 ) \
1147   { _GET_CONTEXT; fn( a1, a2, &context ); }
1148 #define DEFINE_REGS_ENTRYPOINT_3( name, fn, t1, t2, t3 ) \
1149   void WINAPI name ( t1 a1, t2 a2, t3 a3 ) \
1150   { _GET_CONTEXT; fn( a1, a2, a3, &context ); }
1151 #define DEFINE_REGS_ENTRYPOINT_4( name, fn, t1, t2, t3, t4 ) \
1152   void WINAPI name ( t1 a1, t2 a2, t3 a3, t4 a4 ) \
1153   { _GET_CONTEXT; fn( a1, a2, a3, a4, &context ); }
1154
1155 #endif /* __sparc__ */
1156
1157 #ifdef __PPC__
1158
1159 /* FIXME: use getcontext() to retrieve full context */
1160 #define _GET_CONTEXT \
1161     CONTEXT context;   \
1162     do { memset(&context, 0, sizeof(CONTEXT));            \
1163          context.ContextFlags = CONTEXT_CONTROL;          \
1164        } while (0)
1165
1166 #define DEFINE_REGS_ENTRYPOINT_0( name, fn ) \
1167   void WINAPI name ( void ) \
1168   { _GET_CONTEXT; fn( &context ); }
1169 #define DEFINE_REGS_ENTRYPOINT_1( name, fn, t1 ) \
1170   void WINAPI name ( t1 a1 ) \
1171   { _GET_CONTEXT; fn( a1, &context ); }
1172 #define DEFINE_REGS_ENTRYPOINT_2( name, fn, t1, t2 ) \
1173   void WINAPI name ( t1 a1, t2 a2 ) \
1174   { _GET_CONTEXT; fn( a1, a2, &context ); }
1175 #define DEFINE_REGS_ENTRYPOINT_3( name, fn, t1, t2, t3 ) \
1176   void WINAPI name ( t1 a1, t2 a2, t3 a3 ) \
1177   { _GET_CONTEXT; fn( a1, a2, a3, &context ); }
1178 #define DEFINE_REGS_ENTRYPOINT_4( name, fn, t1, t2, t3, t4 ) \
1179   void WINAPI name ( t1 a1, t2 a2, t3 a3, t4 a4 ) \
1180   { _GET_CONTEXT; fn( a1, a2, a3, a4, &context ); }
1181
1182 #endif /* __PPC__ */
1183
1184
1185 #ifndef DEFINE_REGS_ENTRYPOINT_0
1186 #error You need to define DEFINE_REGS_ENTRYPOINT macros for your CPU
1187 #endif
1188
1189 /* Constructor functions */
1190
1191 #ifdef __GNUC__
1192 # define DECL_GLOBAL_CONSTRUCTOR(func) \
1193     static void func(void) __attribute__((constructor)); \
1194     static void func(void)
1195 #else  /* __GNUC__ */
1196 # ifdef __i386__
1197 #  define DECL_GLOBAL_CONSTRUCTOR(func) \
1198     static void __dummy_init_##func(void) { \
1199         asm(".section .init,\"ax\"\n\t" \
1200             "call " #func "\n\t" \
1201             ".previous"); } \
1202     static void func(void)
1203 # else  /* __i386__ */
1204 #  error You must define the DECL_GLOBAL_CONSTRUCTOR macro for your platform
1205 # endif
1206 #endif  /* __GNUC__ */
1207
1208 /* Segment register access */
1209
1210 #ifdef __i386__
1211 # ifdef __GNUC__
1212 #  define __DEFINE_GET_SEG(seg) \
1213     extern inline unsigned short __get_##seg(void) \
1214     { unsigned short res; __asm__("movw %%" #seg ",%w0" : "=r"(res)); return res; }
1215 #  define __DEFINE_SET_SEG(seg) \
1216     extern inline void __set_##seg(int val) { __asm__("movw %w0,%%" #seg : : "r" (val)); }
1217 # else  /* __GNUC__ */
1218 #  define __DEFINE_GET_SEG(seg) extern unsigned short __get_##seg(void);
1219 #  define __DEFINE_SET_SEG(seg) extern void __set_##seg(unsigned int);
1220 # endif /* __GNUC__ */
1221 #else  /* __i386__ */
1222 # define __DEFINE_GET_SEG(seg) inline static unsigned short __get_##seg(void) { return 0; }
1223 # define __DEFINE_SET_SEG(seg) /* nothing */
1224 #endif  /* __i386__ */
1225
1226 __DEFINE_GET_SEG(cs)
1227 __DEFINE_GET_SEG(ds)
1228 __DEFINE_GET_SEG(es)
1229 __DEFINE_GET_SEG(fs)
1230 __DEFINE_GET_SEG(gs)
1231 __DEFINE_GET_SEG(ss)
1232 __DEFINE_SET_SEG(fs)
1233 __DEFINE_SET_SEG(gs)
1234 #undef __DEFINE_GET_SEG
1235 #undef __DEFINE_SET_SEG
1236
1237 #endif  /* __WINE__ */
1238
1239
1240
1241 /*
1242  * Language IDs
1243  */
1244
1245 #define MAKELCID(l, s)          (MAKELONG(l, s))
1246
1247 #define MAKELANGID(p, s)        ((((WORD)(s))<<10) | (WORD)(p))
1248 #define PRIMARYLANGID(l)        ((WORD)(l) & 0x3ff)
1249 #define SUBLANGID(l)            ((WORD)(l) >> 10)
1250
1251 #define LANGIDFROMLCID(lcid)    ((WORD)(lcid))
1252 #define SORTIDFROMLCID(lcid)    ((WORD)((((DWORD)(lcid)) >> 16) & 0x0f))
1253
1254 #define LANG_SYSTEM_DEFAULT     (MAKELANGID(LANG_NEUTRAL, SUBLANG_SYS_DEFAULT))
1255 #define LANG_USER_DEFAULT       (MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT))
1256 #define LOCALE_SYSTEM_DEFAULT   (MAKELCID(LANG_SYSTEM_DEFAULT, SORT_DEFAULT))
1257 #define LOCALE_USER_DEFAULT     (MAKELCID(LANG_USER_DEFAULT, SORT_DEFAULT)) 
1258 #define LOCALE_NEUTRAL          (MAKELCID(MAKELANGID(LANG_NEUTRAL,SUBLANG_NEUTRAL),SORT_DEFAULT))
1259
1260 /* FIXME: are the symbolic names correct for LIDs:  0x17, 0x20, 0x28,
1261  *        0x2a, 0x2b, 0x2c, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35,
1262  *        0x37, 0x39, 0x3a, 0x3b, 0x3c, 0x3e, 0x3f, 0x41, 0x43, 0x44,
1263  *        0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e,
1264  *        0x4f, 0x57
1265  */
1266 #define LANG_NEUTRAL                     0x00
1267 #define LANG_AFRIKAANS                   0x36
1268 #define LANG_ALBANIAN                    0x1c
1269 #define LANG_ARABIC                      0x01
1270 #define LANG_ARMENIAN                    0x2b
1271 #define LANG_ASSAMESE                    0x4d
1272 #define LANG_AZERI                       0x2c
1273 #define LANG_BASQUE                      0x2d
1274 #define LANG_BENGALI                     0x45
1275 #define LANG_BULGARIAN                   0x02
1276 #define LANG_BYELORUSSIAN                0x23
1277 #define LANG_CATALAN                     0x03
1278 #define LANG_CHINESE                     0x04
1279 #define LANG_SERBO_CROATIAN              0x1a
1280 #define LANG_CROATIAN     LANG_SERBO_CROATIAN
1281 #define LANG_SERBIAN      LANG_SERBO_CROATIAN
1282 #define LANG_CZECH                       0x05
1283 #define LANG_DANISH                      0x06
1284 #define LANG_DUTCH                       0x13
1285 #define LANG_ENGLISH                     0x09
1286 #define LANG_ESTONIAN                    0x25
1287 #define LANG_FAEROESE                    0x38
1288 #define LANG_FARSI                       0x29
1289 #define LANG_FINNISH                     0x0b
1290 #define LANG_FRENCH                      0x0c
1291 #define LANG_GAELIC                      0x3c
1292 #define LANG_GEORGIAN                    0x37
1293 #define LANG_GERMAN                      0x07
1294 #define LANG_GREEK                       0x08
1295 #define LANG_GUJARATI                    0x47
1296 #define LANG_HEBREW                      0x0D
1297 #define LANG_HINDI                       0x39
1298 #define LANG_HUNGARIAN                   0x0e
1299 #define LANG_ICELANDIC                   0x0f
1300 #define LANG_INDONESIAN                  0x21
1301 #define LANG_ITALIAN                     0x10
1302 #define LANG_JAPANESE                    0x11
1303 #define LANG_KANNADA                     0x4b
1304 #define LANG_KAZAKH                      0x3f
1305 #define LANG_KONKANI                     0x57
1306 #define LANG_KOREAN                      0x12
1307 #define LANG_LATVIAN                     0x26
1308 #define LANG_LITHUANIAN                  0x27
1309 #define LANG_MACEDONIAN                  0x2f
1310 #define LANG_MALAY                       0x3e
1311 #define LANG_MALAYALAM                   0x4c
1312 #define LANG_MALTESE                     0x3a
1313 #define LANG_MAORI                       0x28
1314 #define LANG_MARATHI                     0x4e
1315 #define LANG_NORWEGIAN                   0x14
1316 #define LANG_ORIYA                       0x48
1317 #define LANG_POLISH                      0x15
1318 #define LANG_PORTUGUESE                  0x16
1319 #define LANG_PUNJABI                     0x46
1320 #define LANG_RHAETO_ROMANCE              0x17
1321 #define LANG_ROMANIAN                    0x18
1322 #define LANG_RUSSIAN                     0x19
1323 #define LANG_SAAMI                       0x3b
1324 #define LANG_SANSKRIT                    0x4f
1325 #define LANG_SLOVAK                      0x1b
1326 #define LANG_SLOVENIAN                   0x24
1327 #define LANG_SORBIAN                     0x2e
1328 #define LANG_SPANISH                     0x0a
1329 #define LANG_SUTU                        0x30
1330 #define LANG_SWAHILI                     0x41
1331 #define LANG_SWEDISH                     0x1d
1332 #define LANG_TAMIL                       0x49
1333 #define LANG_TATAR                       0x44
1334 #define LANG_TELUGU                      0x4a
1335 #define LANG_THAI                        0x1e
1336 #define LANG_TSONGA                      0x31
1337 #define LANG_TSWANA                      0x32
1338 #define LANG_TURKISH                     0x1f
1339 #define LANG_UKRAINIAN                   0x22
1340 #define LANG_URDU                        0x20
1341 #define LANG_UZBEK                       0x43
1342 #define LANG_VENDA                       0x33
1343 #define LANG_VIETNAMESE                  0x2a
1344 #define LANG_XHOSA                       0x34
1345 #define LANG_ZULU                        0x35
1346 /* non standard; keep the number high enough (but < 0xff) */
1347 #define LANG_ESPERANTO                   0x8f
1348 #define LANG_WALON                       0x90
1349 #define LANG_CORNISH                     0x91
1350 #define LANG_WELSH                       0x92
1351 #define LANG_BRETON                      0x93
1352
1353 /* Sublanguage definitions */
1354 #define SUBLANG_NEUTRAL                  0x00    /* language neutral */
1355 #define SUBLANG_DEFAULT                  0x01    /* user default */
1356 #define SUBLANG_SYS_DEFAULT              0x02    /* system default */
1357
1358 #define SUBLANG_ARABIC                   0x01
1359 #define SUBLANG_ARABIC_SAUDI_ARABIA      0x01
1360 #define SUBLANG_ARABIC_IRAQ              0x02
1361 #define SUBLANG_ARABIC_EGYPT             0x03
1362 #define SUBLANG_ARABIC_LIBYA             0x04
1363 #define SUBLANG_ARABIC_ALGERIA           0x05
1364 #define SUBLANG_ARABIC_MOROCCO           0x06
1365 #define SUBLANG_ARABIC_TUNISIA           0x07
1366 #define SUBLANG_ARABIC_OMAN              0x08
1367 #define SUBLANG_ARABIC_YEMEN             0x09
1368 #define SUBLANG_ARABIC_SYRIA             0x0a
1369 #define SUBLANG_ARABIC_JORDAN            0x0b
1370 #define SUBLANG_ARABIC_LEBANON           0x0c
1371 #define SUBLANG_ARABIC_KUWAIT            0x0d
1372 #define SUBLANG_ARABIC_UAE               0x0e
1373 #define SUBLANG_ARABIC_BAHRAIN           0x0f
1374 #define SUBLANG_ARABIC_QATAR             0x10
1375 #define SUBLANG_CHINESE_TRADITIONAL      0x01
1376 #define SUBLANG_CHINESE_SIMPLIFIED       0x02
1377 #define SUBLANG_CHINESE_HONGKONG         0x03
1378 #define SUBLANG_CHINESE_SINGAPORE        0x04
1379 #define SUBLANG_CHINESE_MACAU            0x05
1380 #define SUBLANG_DUTCH                    0x01
1381 #define SUBLANG_DUTCH_BELGIAN            0x02
1382 #define SUBLANG_DUTCH_SURINAM            0x03
1383 #define SUBLANG_ENGLISH_US               0x01
1384 #define SUBLANG_ENGLISH_UK               0x02
1385 #define SUBLANG_ENGLISH_AUS              0x03
1386 #define SUBLANG_ENGLISH_CAN              0x04
1387 #define SUBLANG_ENGLISH_NZ               0x05
1388 #define SUBLANG_ENGLISH_EIRE             0x06
1389 #define SUBLANG_ENGLISH_SAFRICA          0x07
1390 #define SUBLANG_ENGLISH_JAMAICA          0x08
1391 #define SUBLANG_ENGLISH_CARRIBEAN        0x09
1392 #define SUBLANG_ENGLISH_BELIZE           0x0a
1393 #define SUBLANG_ENGLISH_TRINIDAD         0x0b
1394 #define SUBLANG_ENGLISH_ZIMBABWE         0x0c
1395 #define SUBLANG_ENGLISH_PHILIPPINES      0x0d
1396 #define SUBLANG_FRENCH                   0x01
1397 #define SUBLANG_FRENCH_BELGIAN           0x02
1398 #define SUBLANG_FRENCH_CANADIAN          0x03
1399 #define SUBLANG_FRENCH_SWISS             0x04
1400 #define SUBLANG_FRENCH_LUXEMBOURG        0x05
1401 #define SUBLANG_FRENCH_MONACO            0x06
1402 #define SUBLANG_GERMAN                   0x01
1403 #define SUBLANG_GERMAN_SWISS             0x02
1404 #define SUBLANG_GERMAN_AUSTRIAN          0x03
1405 #define SUBLANG_GERMAN_LUXEMBOURG        0x04
1406 #define SUBLANG_GERMAN_LIECHTENSTEIN     0x05
1407 #define SUBLANG_ITALIAN                  0x01
1408 #define SUBLANG_ITALIAN_SWISS            0x02
1409 #define SUBLANG_KOREAN                   0x01
1410 #define SUBLANG_KOREAN_JOHAB             0x02
1411 #define SUBLANG_NORWEGIAN_BOKMAL         0x01
1412 #define SUBLANG_NORWEGIAN_NYNORSK        0x02
1413 #define SUBLANG_PORTUGUESE               0x02
1414 #define SUBLANG_PORTUGUESE_BRAZILIAN     0x01
1415 #define SUBLANG_SPANISH                  0x01
1416 #define SUBLANG_SPANISH_MEXICAN          0x02
1417 #define SUBLANG_SPANISH_MODERN           0x03
1418 #define SUBLANG_SPANISH_GUATEMALA        0x04
1419 #define SUBLANG_SPANISH_COSTARICA        0x05
1420 #define SUBLANG_SPANISH_PANAMA           0x06
1421 #define SUBLANG_SPANISH_DOMINICAN        0x07
1422 #define SUBLANG_SPANISH_VENEZUELA        0x08
1423 #define SUBLANG_SPANISH_COLOMBIA         0x09
1424 #define SUBLANG_SPANISH_PERU             0x0a
1425 #define SUBLANG_SPANISH_ARGENTINA        0x0b
1426 #define SUBLANG_SPANISH_ECUADOR          0x0c
1427 #define SUBLANG_SPANISH_CHILE            0x0d
1428 #define SUBLANG_SPANISH_URUGUAY          0x0e
1429 #define SUBLANG_SPANISH_PARAGUAY         0x0f
1430 #define SUBLANG_SPANISH_BOLIVIA          0x10
1431 #define SUBLANG_SPANISH_EL_SALVADOR      0x11
1432 #define SUBLANG_SPANISH_HONDURAS         0x12
1433 #define SUBLANG_SPANISH_NICARAGUA        0x13
1434 #define SUBLANG_SPANISH_PUERTO_RICO      0x14
1435 /* FIXME: I don't know the symbolic names for those */
1436 #define SUBLANG_ROMANIAN                 0x01
1437 #define SUBLANG_ROMANIAN_MOLDAVIA        0x02
1438 #define SUBLANG_RUSSIAN                  0x01
1439 #define SUBLANG_RUSSIAN_MOLDAVIA         0x02
1440 #define SUBLANG_CROATIAN                 0x01
1441 #define SUBLANG_SERBIAN                  0x02
1442 #define SUBLANG_SERBIAN_LATIN            0x03
1443 #define SUBLANG_SWEDISH                  0x01
1444 #define SUBLANG_SWEDISH_FINLAND          0x02
1445 #define SUBLANG_LITHUANIAN               0x01
1446 #define SUBLANG_LITHUANIAN_CLASSIC       0x02
1447 #define SUBLANG_AZERI                    0x01
1448 #define SUBLANG_AZERI_CYRILLIC           0x02
1449 #define SUBLANG_GAELIC                   0x01
1450 #define SUBLANG_GAELIC_SCOTTISH          0x02
1451 #define SUBLANG_GAELIC_MANX              0x03
1452 #define SUBLANG_MALAY                    0x01
1453 #define SUBLANG_MALAY_BRUNEI_DARUSSALAM  0x02
1454 #define SUBLANG_UZBEK                    0x01
1455 #define SUBLANG_UZBEK_CYRILLIC           0x02
1456 #define SUBLANG_URDU_PAKISTAN            0x01
1457
1458
1459
1460 /*
1461  * Sort definitions
1462  */
1463
1464 #define SORT_DEFAULT                     0x0
1465 #define SORT_JAPANESE_XJIS               0x0
1466 #define SORT_JAPANESE_UNICODE            0x1
1467 #define SORT_CHINESE_BIG5                0x0
1468 #define SORT_CHINESE_UNICODE             0x1
1469 #define SORT_KOREAN_KSC                  0x0
1470 #define SORT_KOREAN_UNICODE              0x1
1471
1472
1473
1474 /*
1475  * Definitions for IsTextUnicode()
1476  */
1477
1478 #define IS_TEXT_UNICODE_ASCII16            0x0001
1479 #define IS_TEXT_UNICODE_STATISTICS         0x0002
1480 #define IS_TEXT_UNICODE_CONTROLS           0x0004
1481 #define IS_TEXT_UNICODE_SIGNATURE          0x0008
1482 #define IS_TEXT_UNICODE_UNICODE_MASK       0x000F
1483 #define IS_TEXT_UNICODE_REVERSE_ASCII16    0x0010
1484 #define IS_TEXT_UNICODE_REVERSE_STATISTICS 0x0020
1485 #define IS_TEXT_UNICODE_REVERSE_CONTROLS   0x0040
1486 #define IS_TEXT_UNICODE_REVERSE_SIGNATURE  0x0080
1487 #define IS_TEXT_UNICODE_REVERSE_MASK       0x00F0
1488 #define IS_TEXT_UNICODE_ILLEGAL_CHARS      0x0100
1489 #define IS_TEXT_UNICODE_ODD_LENGTH         0x0200
1490 #define IS_TEXT_UNICODE_DBCS_LEADBYTE      0x0400
1491 #define IS_TEXT_UNICODE_NOT_UNICODE_MASK   0x0F00
1492 #define IS_TEXT_UNICODE_NULL_BYTES         0x1000
1493 #define IS_TEXT_UNICODE_NOT_ASCII_MASK     0xF000
1494
1495
1496
1497 /*
1498  * Exception codes
1499  */
1500
1501 #define STATUS_SUCCESS                   0x00000000
1502 #define STATUS_WAIT_0                    0x00000000
1503 #define STATUS_ABANDONED_WAIT_0          0x00000080
1504 #define STATUS_ABANDONED_WAIT_63         0x000000BF
1505 #define STATUS_USER_APC                  0x000000C0
1506 #define STATUS_ALERTED                   0x00000101
1507 #define STATUS_TIMEOUT                   0x00000102
1508 #define STATUS_PENDING                   0x00000103
1509 #define STATUS_REPARSE                   0x00000104
1510 #define STATUS_MORE_ENTRIES              0x00000105
1511 #define STATUS_NOT_ALL_ASSIGNED          0x00000106
1512 #define STATUS_SOME_NOT_MAPPED           0x00000107
1513 #define STATUS_OPLOCK_BREAK_IN_PROGRESS  0x00000108
1514 #define STATUS_VOLUME_MOUNTED            0x00000109
1515 #define STATUS_RXACT_COMMITTED           0x0000010A
1516 #define STATUS_NOTIFY_CLEANUP            0x0000010B
1517 #define STATUS_NOTIFY_ENUM_DIR           0x0000010C
1518 #define STATUS_NO_QUOTAS_FOR_ACCOUNT     0x0000010D
1519 #define STATUS_PRIMARY_TRANSPORT_CONNECT_FAILED 0x0000010E
1520 #define STATUS_PAGE_FAULT_TRANSITION     0x00000110
1521 #define STATUS_PAGE_FAULT_DEMAND_ZERO    0x00000111
1522 #define STATUS_PAGE_FAULT_COPY_ON_WRITE  0x00000112
1523 #define STATUS_PAGE_FAULT_GUARD_PAGE     0x00000113
1524 #define STATUS_PAGE_FAULT_PAGING_FILE    0x00000114
1525 #define STATUS_CACHE_PAGE_LOCKED         0x00000115
1526 #define STATUS_CRASH_DUMP                0x00000116
1527 #define STATUS_BUFFER_ALL_ZEROS          0x00000117
1528 #define STATUS_REPARSE_OBJECT            0x00000118
1529
1530 #define STATUS_THREAD_WAS_SUSPENDED      0x40000001
1531 #define STATUS_WORKING_SET_LIMIT_RANGE   0x40000002
1532 #define STATUS_IMAGE_NOT_AT_BASE         0x40000003
1533 #define STATUS_RXACT_STATE_CREATED       0x40000004
1534 #define STATUS_SEGMENT_NOTIFICATION      0x40000005
1535 #define STATUS_LOCAL_USER_SESSION_KEY    0x40000006
1536 #define STATUS_BAD_CURRENT_DIRECTORY     0x40000007
1537 #define STATUS_SERIAL_MORE_WRITES        0x40000008
1538 #define STATUS_REGISTRY_RECOVERED        0x40000009
1539 #define STATUS_FT_READ_RECOVERY_FROM_BACKUP 0x4000000A
1540 #define STATUS_FT_WRITE_RECOVERY         0x4000000B
1541 #define STATUS_SERIAL_COUNTER_TIMEOUT    0x4000000C
1542 #define STATUS_NULL_LM_PASSWORD          0x4000000D
1543 #define STATUS_IMAGE_MACHINE_TYPE_MISMATCH 0x4000000E
1544 #define STATUS_RECEIVE_PARTIAL           0x4000000F
1545 #define STATUS_RECEIVE_EXPEDITED         0x40000010
1546 #define STATUS_RECEIVE_PARTIAL_EXPEDITED 0x40000011
1547 #define STATUS_EVENT_DONE                0x40000012
1548 #define STATUS_EVENT_PENDING             0x40000013
1549 #define STATUS_CHECKING_FILE_SYSTEM      0x40000014
1550 #define STATUS_FATAL_APP_EXIT            0x40000015
1551 #define STATUS_PREDEFINED_HANDLE         0x40000016
1552 #define STATUS_WAS_UNLOCKED              0x40000017
1553 #define STATUS_SERVICE_NOTIFICATION      0x40000018
1554 #define STATUS_WAS_LOCKED                0x40000019
1555 #define STATUS_LOG_HARD_ERROR            0x4000001A
1556 #define STATUS_ALREADY_WIN32             0x4000001B
1557 #define STATUS_WX86_UNSIMULATE           0x4000001C
1558 #define STATUS_WX86_CONTINUE             0x4000001D
1559 #define STATUS_WX86_SINGLE_STEP          0x4000001E
1560 #define STATUS_WX86_BREAKPOINT           0x4000001F
1561 #define STATUS_WX86_EXCEPTION_CONTINUE   0x40000020
1562 #define STATUS_WX86_EXCEPTION_LASTCHANCE 0x40000021
1563 #define STATUS_WX86_EXCEPTION_CHAIN      0x40000022
1564 #define STATUS_IMAGE_MACHINE_TYPE_MISMATCH_EXE 0x40000023
1565 #define STATUS_NO_YIELD_PERFORMED        0x40000024
1566 #define STATUS_TIMER_RESUME_IGNORED      0x40000025
1567         
1568 #define STATUS_GUARD_PAGE_VIOLATION      0x80000001    
1569 #define STATUS_DATATYPE_MISALIGNMENT     0x80000002
1570 #define STATUS_BREAKPOINT                0x80000003
1571 #define STATUS_SINGLE_STEP               0x80000004
1572 #define STATUS_BUFFER_OVERFLOW           0x80000005
1573 #define STATUS_NO_MORE_FILES             0x80000006
1574 #define STATUS_WAKE_SYSTEM_DEBUGGER      0x80000007
1575
1576 #define STATUS_HANDLES_CLOSED            0x8000000A
1577 #define STATUS_NO_INHERITANCE            0x8000000B
1578 #define STATUS_GUID_SUBSTITUTION_MADE    0x8000000C
1579 #define STATUS_PARTIAL_COPY              0x8000000D
1580 #define STATUS_DEVICE_PAPER_EMPTY        0x8000000E
1581 #define STATUS_DEVICE_POWERED_OFF        0x8000000F
1582 #define STATUS_DEVICE_OFF_LINE           0x80000010
1583 #define STATUS_DEVICE_BUSY               0x80000011
1584 #define STATUS_NO_MORE_EAS               0x80000012
1585 #define STATUS_INVALID_EA_NAME           0x80000013
1586 #define STATUS_EA_LIST_INCONSISTENT      0x80000014
1587 #define STATUS_INVALID_EA_FLAG           0x80000015
1588 #define STATUS_VERIFY_REQUIRED           0x80000016
1589 #define STATUS_EXTRANEOUS_INFORMATION    0x80000017
1590 #define STATUS_RXACT_COMMIT_NECESSARY    0x80000018
1591 #define STATUS_NO_MORE_ENTRIES           0x8000001A
1592 #define STATUS_FILEMARK_DETECTED         0x8000001B
1593 #define STATUS_MEDIA_CHANGED             0x8000001C
1594 #define STATUS_BUS_RESET                 0x8000001D
1595 #define STATUS_END_OF_MEDIA              0x8000001E
1596 #define STATUS_BEGINNING_OF_MEDIA        0x8000001F
1597 #define STATUS_MEDIA_CHECK               0x80000020
1598 #define STATUS_SETMARK_DETECTED          0x80000021
1599 #define STATUS_NO_DATA_DETECTED          0x80000022
1600 #define STATUS_REDIRECTOR_HAS_OPEN_HANDLES 0x80000023
1601 #define STATUS_SERVER_HAS_OPEN_HANDLES   0x80000024
1602 #define STATUS_ALREADY_DISCONNECTED      0x80000025
1603 #define STATUS_LONGJUMP                  0x80000026
1604
1605 #define STATUS_UNSUCCESSFUL              0xC0000001
1606 #define STATUS_NOT_IMPLEMENTED           0xC0000002
1607 #define STATUS_INVALID_INFO_CLASS        0xC0000003
1608 #define STATUS_INFO_LENGTH_MISMATCH      0xC0000004
1609 #define STATUS_ACCESS_VIOLATION          0xC0000005
1610 #define STATUS_IN_PAGE_ERROR             0xC0000006
1611 #define STATUS_PAGEFILE_QUOTA            0xC0000007
1612 #define STATUS_INVALID_HANDLE            0xC0000008
1613 #define STATUS_BAD_INITIAL_STACK         0xC0000009
1614 #define STATUS_BAD_INITIAL_PC            0xC000000A
1615 #define STATUS_INVALID_CID               0xC000000B
1616 #define STATUS_TIMER_NOT_CANCELED        0xC000000C
1617 #define STATUS_INVALID_PARAMETER         0xC000000D
1618 #define STATUS_NO_SUCH_DEVICE            0xC000000E
1619 #define STATUS_NO_SUCH_FILE              0xC000000F
1620 #define STATUS_INVALID_DEVICE_REQUEST    0xC0000010
1621 #define STATUS_END_OF_FILE               0xC0000011
1622 #define STATUS_WRONG_VOLUME              0xC0000012
1623 #define STATUS_NO_MEDIA_IN_DEVICE        0xC0000013
1624 #define STATUS_UNRECOGNIZED_MEDIA        0xC0000014
1625 #define STATUS_NONEXISTENT_SECTOR        0xC0000015
1626 #define STATUS_MORE_PROCESSING_REQUIRED  0xC0000016
1627 #define STATUS_NO_MEMORY                 0xC0000017
1628 #define STATUS_CONFLICTING_ADDRESSES     0xC0000018
1629 #define STATUS_NOT_MAPPED_VIEW           0xC0000019
1630 #define STATUS_UNABLE_TO_FREE_VM         0xC000001A
1631 #define STATUS_UNABLE_TO_DELETE_SECTION  0xC000001B
1632 #define STATUS_INVALID_SYSTEM_SERVICE    0xC000001C
1633 #define STATUS_ILLEGAL_INSTRUCTION       0xC000001D
1634 #define STATUS_INVALID_LOCK_SEQUENCE     0xC000001E
1635 #define STATUS_INVALID_VIEW_SIZE         0xC000001F
1636 #define STATUS_INVALID_FILE_FOR_SECTION  0xC0000020
1637 #define STATUS_ALREADY_COMMITTED         0xC0000021
1638 #define STATUS_ACCESS_DENIED             0xC0000022
1639 #define STATUS_BUFFER_TOO_SMALL          0xC0000023
1640 #define STATUS_OBJECT_TYPE_MISMATCH      0xC0000024
1641 #define STATUS_NONCONTINUABLE_EXCEPTION  0xC0000025
1642 #define STATUS_INVALID_DISPOSITION       0xC0000026
1643 #define STATUS_UNWIND                    0xC0000027
1644 #define STATUS_BAD_STACK                 0xC0000028
1645 #define STATUS_INVALID_UNWIND_TARGET     0xC0000029
1646 #define STATUS_NOT_LOCKED                0xC000002A
1647 #define STATUS_PARITY_ERROR              0xC000002B
1648 #define STATUS_UNABLE_TO_DECOMMIT_VM     0xC000002C
1649 #define STATUS_NOT_COMMITTED             0xC000002D
1650 #define STATUS_INVALID_PORT_ATTRIBUTES   0xC000002E
1651 #define STATUS_PORT_MESSAGE_TOO_LONG     0xC000002F
1652 #define STATUS_INVALID_PARAMETER_MIX     0xC0000030
1653 #define STATUS_INVALID_QUOTA_LOWER       0xC0000031
1654 #define STATUS_DISK_CORRUPT_ERROR        0xC0000032
1655 #define STATUS_OBJECT_NAME_INVALID       0xC0000033
1656 #define STATUS_OBJECT_NAME_NOT_FOUND     0xC0000034
1657 #define STATUS_OBJECT_NAME_COLLISION     0xC0000035
1658 #define STATUS_PORT_DISCONNECTED         0xC0000037
1659 #define STATUS_DEVICE_ALREADY_ATTACHED   0xC0000038
1660 #define STATUS_OBJECT_PATH_INVALID       0xC0000039
1661 #define STATUS_OBJECT_PATH_NOT_FOUND     0xC000003A
1662 #define STATUS_PATH_SYNTAX_BAD           0xC000003B
1663 #define STATUS_DATA_OVERRUN              0xC000003C
1664 #define STATUS_DATA_LATE_ERROR           0xC000003D
1665 #define STATUS_DATA_ERROR                0xC000003E
1666 #define STATUS_CRC_ERROR                 0xC000003F
1667 #define STATUS_SECTION_TOO_BIG           0xC0000040
1668 #define STATUS_PORT_CONNECTION_REFUSED   0xC0000041
1669 #define STATUS_INVALID_PORT_HANDLE       0xC0000042
1670 #define STATUS_SHARING_VIOLATION         0xC0000043
1671 #define STATUS_QUOTA_EXCEEDED            0xC0000044
1672 #define STATUS_INVALID_PAGE_PROTECTION   0xC0000045
1673 #define STATUS_MUTANT_NOT_OWNED          0xC0000046
1674 #define STATUS_SEMAPHORE_LIMIT_EXCEEDED  0xC0000047
1675 #define STATUS_PORT_ALREADY_SET          0xC0000048
1676 #define STATUS_SECTION_NOT_IMAGE         0xC0000049
1677 #define STATUS_SUSPEND_COUNT_EXCEEDED    0xC000004A
1678 #define STATUS_THREAD_IS_TERMINATING     0xC000004B
1679 #define STATUS_BAD_WORKING_SET_LIMIT     0xC000004C
1680 #define STATUS_INCOMPATIBLE_FILE_MAP     0xC000004D
1681 #define STATUS_SECTION_PROTECTION        0xC000004E
1682 #define STATUS_EAS_NOT_SUPPORTED         0xC000004F
1683 #define STATUS_EA_TOO_LARGE              0xC0000050
1684 #define STATUS_NONEXISTENT_EA_ENTRY      0xC0000051
1685 #define STATUS_NO_EAS_ON_FILE            0xC0000052
1686 #define STATUS_EA_CORRUPT_ERROR          0xC0000053
1687 #define STATUS_LOCK_NOT_GRANTED          0xC0000054  /* FIXME: not sure */
1688 #define STATUS_FILE_LOCK_CONFLICT        0xC0000055  /* FIXME: not sure */
1689 #define STATUS_DELETE_PENDING            0xC0000056
1690 #define STATUS_CTL_FILE_NOT_SUPPORTED    0xC0000057
1691 #define STATUS_UNKNOWN_REVISION          0xC0000058
1692 #define STATUS_REVISION_MISMATCH         0xC0000059
1693 #define STATUS_INVALID_OWNER             0xC000005A
1694 #define STATUS_INVALID_PRIMARY_GROUP     0xC000005B
1695 #define STATUS_NO_IMPERSONATION_TOKEN    0xC000005C
1696 #define STATUS_CANT_DISABLE_MANDATORY    0xC000005D
1697 #define STATUS_NO_LOGON_SERVERS          0xC000005E
1698 #define STATUS_NO_SUCH_LOGON_SESSION     0xC000005F
1699 #define STATUS_NO_SUCH_PRIVILEGE         0xC0000060
1700 #define STATUS_PRIVILEGE_NOT_HELD        0xC0000061
1701 #define STATUS_INVALID_ACCOUNT_NAME      0xC0000062
1702 #define STATUS_USER_EXISTS               0xC0000063
1703 #define STATUS_NO_SUCH_USER              0xC0000064
1704 #define STATUS_GROUP_EXISTS              0xC0000065
1705 #define STATUS_NO_SUCH_GROUP             0xC0000066
1706 #define STATUS_MEMBER_IN_GROUP           0xC0000067
1707 #define STATUS_MEMBER_NOT_IN_GROUP       0xC0000068
1708 #define STATUS_LAST_ADMIN                0xC0000069
1709 #define STATUS_WRONG_PASSWORD            0xC000006A
1710 #define STATUS_ILL_FORMED_PASSWORD       0xC000006B
1711 #define STATUS_PASSWORD_RESTRICTION      0xC000006C
1712 #define STATUS_LOGON_FAILURE             0xC000006D
1713 #define STATUS_ACCOUNT_RESTRICTION       0xC000006E
1714 #define STATUS_INVALID_LOGON_HOURS       0xC000006F
1715 #define STATUS_INVALID_WORKSTATION       0xC0000070
1716 #define STATUS_PASSWORD_EXPIRED          0xC0000071
1717 #define STATUS_ACCOUNT_DISABLED          0xC0000072
1718 #define STATUS_NONE_MAPPED               0xC0000073
1719 #define STATUS_TOO_MANY_LUIDS_REQUESTED  0xC0000074
1720 #define STATUS_LUIDS_EXHAUSTED           0xC0000075
1721 #define STATUS_INVALID_SUB_AUTHORITY     0xC0000076
1722 #define STATUS_INVALID_ACL               0xC0000077
1723 #define STATUS_INVALID_SID               0xC0000078
1724 #define STATUS_INVALID_SECURITY_DESCR    0xC0000079
1725 #define STATUS_PROCEDURE_NOT_FOUND       0xC000007A
1726 #define STATUS_INVALID_IMAGE_FORMAT      0xC000007B
1727 #define STATUS_NO_TOKEN                  0xC000007C
1728 #define STATUS_BAD_INHERITANCE_ACL       0xC000007D
1729 #define STATUS_RANGE_NOT_LOCKED          0xC000007E
1730 #define STATUS_DISK_FULL                 0xC000007F 
1731 #define STATUS_SERVER_DISABLED           0xC0000080
1732 #define STATUS_SERVER_NOT_DISABLED       0xC0000081
1733 #define STATUS_TOO_MANY_GUIDS_REQUESTED  0xC0000082
1734 #define STATUS_GUIDS_EXHAUSTED           0xC0000083
1735 #define STATUS_INVALID_ID_AUTHORITY      0xC0000084
1736 #define STATUS_AGENTS_EXHAUSTED          0xC0000085
1737 #define STATUS_INVALID_VOLUME_LABEL      0xC0000086
1738 #define STATUS_SECTION_NOT_EXTENDED      0xC0000087
1739 #define STATUS_NOT_MAPPED_DATA           0xC0000088
1740 #define STATUS_RESOURCE_DATA_NOT_FOUND   0xC0000089
1741 #define STATUS_RESOURCE_TYPE_NOT_FOUND   0xC000008A
1742 #define STATUS_RESOURCE_NAME_NOT_FOUND   0xC000008B
1743 #define STATUS_ARRAY_BOUNDS_EXCEEDED     0xC000008C
1744 #define STATUS_FLOAT_DENORMAL_OPERAND    0xC000008D
1745 #define STATUS_FLOAT_DIVIDE_BY_ZERO      0xC000008E
1746 #define STATUS_FLOAT_INEXACT_RESULT      0xC000008F
1747 #define STATUS_FLOAT_INVALID_OPERATION   0xC0000090
1748 #define STATUS_FLOAT_OVERFLOW            0xC0000091
1749 #define STATUS_FLOAT_STACK_CHECK         0xC0000092
1750 #define STATUS_FLOAT_UNDERFLOW           0xC0000093
1751 #define STATUS_INTEGER_DIVIDE_BY_ZERO    0xC0000094
1752 #define STATUS_INTEGER_OVERFLOW          0xC0000095
1753 #define STATUS_PRIVILEGED_INSTRUCTION    0xC0000096
1754 #define STATUS_TOO_MANY_PAGING_FILES     0xC0000097
1755 #define STATUS_FILE_INVALID              0xC0000098
1756 #define STATUS_ALLOTTED_SPACE_EXCEEDED   0xC0000099
1757 #define STATUS_INSUFFICIENT_RESOURCES    0xC000009A
1758 #define STATUS_DFS_EXIT_PATH_FOUND       0xC000009B
1759 #define STATUS_DEVICE_DATA_ERROR         0xC000009C
1760 #define STATUS_DEVICE_NOT_CONNECTED      0xC000009D
1761 #define STATUS_DEVICE_POWER_FAILURE      0xC000009E
1762 #define STATUS_FREE_VM_NOT_AT_BASE       0xC000009F
1763 #define STATUS_MEMORY_NOT_ALLOCATED      0xC00000A0
1764 #define STATUS_WORKING_SET_QUOTA         0xC00000A1
1765 #define STATUS_MEDIA_WRITE_PROTECTED     0xC00000A2
1766 #define STATUS_DEVICE_NOT_READY          0xC00000A3
1767 #define STATUS_INVALID_GROUP_ATTRIBUTES  0xC00000A4
1768 #define STATUS_BAD_IMPERSONATION_LEVEL   0xC00000A5
1769 #define STATUS_CANT_OPEN_ANONYMOUS       0xC00000A6
1770 #define STATUS_BAD_VALIDATION_CLASS      0xC00000A7
1771 #define STATUS_BAD_TOKEN_TYPE            0xC00000A8
1772 #define STATUS_BAD_MASTER_BOOT_RECORD    0xC00000A9
1773 #define STATUS_INSTRUCTION_MISALIGNMENT  0xC00000AA
1774 #define STATUS_INSTANCE_NOT_AVAILABLE    0xC00000AB
1775 #define STATUS_PIPE_NOT_AVAILABLE        0xC00000AC
1776 #define STATUS_INVALID_PIPE_STATE        0xC00000AD
1777 #define STATUS_PIPE_BUSY                 0xC00000AE
1778 #define STATUS_ILLEGAL_FUNCTION          0xC00000AF
1779 #define STATUS_PIPE_DISCONNECTED         0xC00000B0
1780 #define STATUS_PIPE_CLOSING              0xC00000B1
1781 #define STATUS_PIPE_CONNECTED            0xC00000B2
1782 #define STATUS_PIPE_LISTENING            0xC00000B3
1783 #define STATUS_INVALID_READ_MODE         0xC00000B4
1784 #define STATUS_IO_TIMEOUT                0xC00000B5
1785 #define STATUS_FILE_FORCED_CLOSED        0xC00000B6
1786 #define STATUS_PROFILING_NOT_STARTED     0xC00000B7
1787 #define STATUS_PROFILING_NOT_STOPPED     0xC00000B8
1788 #define STATUS_COULD_NOT_INTERPRET       0xC00000B9
1789 #define STATUS_FILE_IS_A_DIRECTORY       0xC00000BA
1790 #define STATUS_NOT_SUPPORTED             0xC00000BB
1791 #define STATUS_REMOTE_NOT_LISTENING      0xC00000BC
1792 #define STATUS_DUPLICATE_NAME            0xC00000BD
1793 #define STATUS_BAD_NETWORK_PATH          0xC00000BE
1794 #define STATUS_NETWORK_BUSY              0xC00000BF
1795 #define STATUS_DEVICE_DOES_NOT_EXIST     0xC00000C0
1796 #define STATUS_TOO_MANY_COMMANDS         0xC00000C1
1797 #define STATUS_ADAPTER_HARDWARE_ERROR    0xC00000C2
1798 #define STATUS_INVALID_NETWORK_RESPONSE  0xC00000C3
1799 #define STATUS_UNEXPECTED_NETWORK_ERROR  0xC00000C4
1800 #define STATUS_BAD_REMOTE_ADAPTER        0xC00000C5
1801 #define STATUS_PRINT_QUEUE_FULL          0xC00000C6
1802 #define STATUS_NO_SPOOL_SPACE            0xC00000C7
1803 #define STATUS_PRINT_CANCELLED           0xC00000C8
1804 #define STATUS_NETWORK_NAME_DELETED      0xC00000C9
1805 #define STATUS_NETWORK_ACCESS_DENIED     0xC00000CA
1806 #define STATUS_BAD_DEVICE_TYPE           0xC00000CB
1807 #define STATUS_BAD_NETWORK_NAME          0xC00000CC
1808 #define STATUS_TOO_MANY_NAMES            0xC00000CD
1809 #define STATUS_TOO_MANY_SESSIONS         0xC00000CE
1810 #define STATUS_SHARING_PAUSED            0xC00000CF
1811 #define STATUS_REQUEST_NOT_ACCEPTED      0xC00000D0
1812 #define STATUS_REDIRECTOR_PAUSED         0xC00000D1
1813 #define STATUS_NET_WRITE_FAULT           0xC00000D2
1814 #define STATUS_PROFILING_AT_LIMIT        0xC00000D3
1815 #define STATUS_NOT_SAME_DEVICE           0xC00000D4
1816 #define STATUS_FILE_RENAMED              0xC00000D5
1817 #define STATUS_VIRTUAL_CIRCUIT_CLOSED    0xC00000D6
1818 #define STATUS_NO_SECURITY_ON_OBJECT     0xC00000D7
1819 #define STATUS_CANT_WAIT                 0xC00000D8
1820 #define STATUS_PIPE_EMPTY                0xC00000D9
1821 #define STATUS_CANT_ACCESS_DOMAIN_INFO   0xC00000DA
1822 #define STATUS_CANT_TERMINATE_SELF       0xC00000DB
1823 #define STATUS_INVALID_SERVER_STATE      0xC00000DC
1824 #define STATUS_INVALID_DOMAIN_STATE      0xC00000DD
1825 #define STATUS_INVALID_DOMAIN_ROLE       0xC00000DE
1826 #define STATUS_NO_SUCH_DOMAIN            0xC00000DF
1827 #define STATUS_DOMAIN_EXISTS             0xC00000E0
1828 #define STATUS_DOMAIN_LIMIT_EXCEEDED     0xC00000E1
1829 #define STATUS_OPLOCK_NOT_GRANTED        0xC00000E2
1830 #define STATUS_INVALID_OPLOCK_PROTOCOL   0xC00000E3
1831 #define STATUS_INTERNAL_DB_CORRUPTION    0xC00000E4
1832 #define STATUS_INTERNAL_ERROR            0xC00000E5
1833 #define STATUS_GENERIC_NOT_MAPPED        0xC00000E6
1834 #define STATUS_BAD_DESCRIPTOR_FORMAT     0xC00000E7
1835 #define STATUS_INVALID_USER_BUFFER       0xC00000E8
1836 #define STATUS_UNEXPECTED_IO_ERROR       0xC00000E9
1837 #define STATUS_UNEXPECTED_MM_CREATE_ERR  0xC00000EA
1838 #define STATUS_UNEXPECTED_MM_MAP_ERROR   0xC00000EB
1839 #define STATUS_UNEXPECTED_MM_EXTEND_ERR  0xC00000EC
1840 #define STATUS_NOT_LOGON_PROCESS         0xC00000ED
1841 #define STATUS_LOGON_SESSION_EXISTS      0xC00000EE
1842 #define STATUS_INVALID_PARAMETER_1       0xC00000EF
1843 #define STATUS_INVALID_PARAMETER_2       0xC00000F0
1844 #define STATUS_INVALID_PARAMETER_3       0xC00000F1
1845 #define STATUS_INVALID_PARAMETER_4       0xC00000F2
1846 #define STATUS_INVALID_PARAMETER_5       0xC00000F3
1847 #define STATUS_INVALID_PARAMETER_6       0xC00000F4
1848 #define STATUS_INVALID_PARAMETER_7       0xC00000F5
1849 #define STATUS_INVALID_PARAMETER_8       0xC00000F6
1850 #define STATUS_INVALID_PARAMETER_9       0xC00000F7
1851 #define STATUS_INVALID_PARAMETER_10      0xC00000F8
1852 #define STATUS_INVALID_PARAMETER_11      0xC00000F9
1853 #define STATUS_INVALID_PARAMETER_12      0xC00000FA
1854 #define STATUS_REDIRECTOR_NOT_STARTED    0xC00000FB
1855 #define STATUS_REDIRECTOR_STARTED        0xC00000FC
1856 #define STATUS_STACK_OVERFLOW            0xC00000FD
1857 #define STATUS_BAD_FUNCTION_TABLE        0xC00000FF
1858 #define STATUS_VARIABLE_NOT_FOUND        0xC0000100
1859 #define STATUS_DIRECTORY_NOT_EMPTY       0xC0000101
1860 #define STATUS_FILE_CORRUPT_ERROR        0xC0000102
1861 #define STATUS_NOT_A_DIRECTORY           0xC0000103
1862 #define STATUS_BAD_LOGON_SESSION_STATE   0xC0000104
1863 #define STATUS_LOGON_SESSION_COLLISION   0xC0000105
1864 #define STATUS_NAME_TOO_LONG             0xC0000106
1865 #define STATUS_FILES_OPEN                0xC0000107
1866 #define STATUS_CONNECTION_IN_USE         0xC0000108
1867 #define STATUS_MESSAGE_NOT_FOUND         0xC0000109
1868 #define STATUS_PROCESS_IS_TERMINATING    0xC000010A
1869 #define STATUS_INVALID_LOGON_TYPE        0xC000010B
1870 #define STATUS_NO_GUID_TRANSLATION       0xC000010C
1871 #define STATUS_CANNOT_IMPERSONATE        0xC000010D
1872 #define STATUS_IMAGE_ALREADY_LOADED      0xC000010E
1873 #define STATUS_ABIOS_NOT_PRESENT         0xC000010F
1874 #define STATUS_ABIOS_LID_NOT_EXIST       0xC0000110
1875 #define STATUS_ABIOS_LID_ALREADY_OWNED   0xC0000111
1876 #define STATUS_ABIOS_NOT_LID_OWNER       0xC0000112
1877 #define STATUS_ABIOS_INVALID_COMMAND     0xC0000113
1878 #define STATUS_ABIOS_INVALID_LID         0xC0000114
1879 #define STATUS_ABIOS_SELECTOR_NOT_AVAILABLE 0xC0000115
1880 #define STATUS_ABIOS_INVALID_SELECTOR    0xC0000116
1881 #define STATUS_NO_LDT                    0xC0000117
1882 #define STATUS_INVALID_LDT_SIZE          0xC0000118
1883 #define STATUS_INVALID_LDT_OFFSET        0xC0000119
1884 #define STATUS_INVALID_LDT_DESCRIPTOR    0xC000011A
1885 #define STATUS_INVALID_IMAGE_NE_FORMAT   0xC000011B
1886 #define STATUS_RXACT_INVALID_STATE       0xC000011C
1887 #define STATUS_RXACT_COMMIT_FAILURE      0xC000011D
1888 #define STATUS_MAPPED_FILE_SIZE_ZERO     0xC000011E
1889 #define STATUS_TOO_MANY_OPENED_FILES     0xC000011F
1890 #define STATUS_CANCELLED                 0xC0000120
1891 #define STATUS_CANNOT_DELETE             0xC0000121
1892 #define STATUS_INVALID_COMPUTER_NAME     0xC0000122
1893 #define STATUS_FILE_DELETED              0xC0000123
1894 #define STATUS_SPECIAL_ACCOUNT           0xC0000124
1895 #define STATUS_SPECIAL_GROUP             0xC0000125
1896 #define STATUS_SPECIAL_USER              0xC0000126
1897 #define STATUS_MEMBERS_PRIMARY_GROUP     0xC0000127
1898 #define STATUS_FILE_CLOSED               0xC0000128
1899 #define STATUS_TOO_MANY_THREADS          0xC0000129
1900 #define STATUS_THREAD_NOT_IN_PROCESS     0xC000012A
1901 #define STATUS_TOKEN_ALREADY_IN_USE      0xC000012B
1902 #define STATUS_PAGEFILE_QUOTA_EXCEEDED   0xC000012C
1903 #define STATUS_COMMITMENT_LIMIT          0xC000012D
1904 #define STATUS_INVALID_IMAGE_LE_FORMAT   0xC000012E
1905 #define STATUS_INVALID_IMAGE_NOT_MZ      0xC000012F
1906 #define STATUS_INVALID_IMAGE_PROTECT     0xC0000130
1907 #define STATUS_INVALID_IMAGE_WIN_16      0xC0000131
1908 #define STATUS_LOGON_SERVER_CONFLICT     0xC0000132
1909 #define STATUS_TIME_DIFFERENCE_AT_DC     0xC0000133
1910 #define STATUS_SYNCHRONIZATION_REQUIRED  0xC0000134
1911 #define STATUS_DLL_NOT_FOUND             0xC0000135
1912 #define STATUS_OPEN_FAILED               0xC0000136
1913 #define STATUS_IO_PRIVILEGE_FAILED       0xC0000137
1914 #define STATUS_ORDINAL_NOT_FOUND         0xC0000138
1915 #define STATUS_ENTRYPOINT_NOT_FOUND      0xC0000139
1916 #define STATUS_CONTROL_C_EXIT            0xC000013A
1917 #define STATUS_LOCAL_DISCONNECT          0xC000013B
1918 #define STATUS_REMOTE_DISCONNECT         0xC000013C
1919 #define STATUS_REMOTE_RESOURCES          0xC000013D
1920 #define STATUS_LINK_FAILED               0xC000013E
1921 #define STATUS_LINK_TIMEOUT              0xC000013F
1922 #define STATUS_INVALID_CONNECTION        0xC0000140
1923 #define STATUS_INVALID_ADDRESS           0xC0000141
1924 #define STATUS_DLL_INIT_FAILED           0xC0000142
1925 #define STATUS_MISSING_SYSTEMFILE        0xC0000143
1926 #define STATUS_UNHANDLED_EXCEPTION       0xC0000144
1927 #define STATUS_APP_INIT_FAILURE          0xC0000145
1928 #define STATUS_PAGEFILE_CREATE_FAILED    0xC0000146
1929 #define STATUS_NO_PAGEFILE               0xC0000147
1930 #define STATUS_INVALID_LEVEL             0xC0000148
1931 #define STATUS_WRONG_PASSWORD_CORE       0xC0000149
1932 #define STATUS_ILLEGAL_FLOAT_CONTEXT     0xC000014A
1933 #define STATUS_PIPE_BROKEN               0xC000014B
1934 #define STATUS_REGISTRY_CORRUPT          0xC000014C
1935 #define STATUS_REGISTRY_IO_FAILED        0xC000014D
1936 #define STATUS_NO_EVENT_PAIR             0xC000014E
1937 #define STATUS_UNRECOGNIZED_VOLUME       0xC000014F
1938 #define STATUS_SERIAL_NO_DEVICE_INITED   0xC0000150
1939 #define STATUS_NO_SUCH_ALIAS             0xC0000151
1940 #define STATUS_MEMBER_NOT_IN_ALIAS       0xC0000152
1941 #define STATUS_MEMBER_IN_ALIAS           0xC0000153
1942 #define STATUS_ALIAS_EXISTS              0xC0000154
1943 #define STATUS_LOGON_NOT_GRANTED         0xC0000155
1944 #define STATUS_TOO_MANY_SECRETS          0xC0000156
1945 #define STATUS_SECRET_TOO_LONG           0xC0000157
1946 #define STATUS_INTERNAL_DB_ERROR         0xC0000158
1947 #define STATUS_FULLSCREEN_MODE           0xC0000159
1948 #define STATUS_TOO_MANY_CONTEXT_IDS      0xC000015A
1949 #define STATUS_LOGON_TYPE_NOT_GRANTED    0xC000015B
1950 #define STATUS_NOT_REGISTRY_FILE         0xC000015C
1951 #define STATUS_NT_CROSS_ENCRYPTION_REQUIRED 0xC000015D
1952 #define STATUS_DOMAIN_CTRLR_CONFIG_ERROR 0xC000015E
1953 #define STATUS_FT_MISSING_MEMBER         0xC000015F
1954 #define STATUS_ILL_FORMED_SERVICE_ENTRY  0xC0000160
1955 #define STATUS_ILLEGAL_CHARACTER         0xC0000161
1956 #define STATUS_UNMAPPABLE_CHARACTER      0xC0000162
1957 #define STATUS_UNDEFINED_CHARACTER       0xC0000163
1958 #define STATUS_FLOPPY_VOLUME             0xC0000164
1959 #define STATUS_FLOPPY_ID_MARK_NOT_FOUND  0xC0000165
1960 #define STATUS_FLOPPY_WRONG_CYLINDER     0xC0000166
1961 #define STATUS_FLOPPY_UNKNOWN_ERROR      0xC0000167
1962 #define STATUS_FLOPPY_BAD_REGISTERS      0xC0000168
1963 #define STATUS_DISK_RECALIBRATE_FAILED   0xC0000169
1964 #define STATUS_DISK_OPERATION_FAILED     0xC000016A
1965 #define STATUS_DISK_RESET_FAILED         0xC000016B
1966 #define STATUS_SHARED_IRQ_BUSY           0xC000016C
1967 #define STATUS_FT_ORPHANING              0xC000016D
1968 #define STATUS_BIOS_FAILED_TO_CONNECT_INTERRUPT 0xC000016E
1969
1970 #define STATUS_PARTITION_FAILURE         0xC0000172
1971 #define STATUS_INVALID_BLOCK_LENGTH      0xC0000173
1972 #define STATUS_DEVICE_NOT_PARTITIONED    0xC0000174
1973 #define STATUS_UNABLE_TO_LOCK_MEDIA      0xC0000175
1974 #define STATUS_UNABLE_TO_UNLOAD_MEDIA    0xC0000176
1975 #define STATUS_EOM_OVERFLOW              0xC0000177
1976 #define STATUS_NO_MEDIA                  0xC0000178
1977 #define STATUS_NO_SUCH_MEMBER            0xC000017A
1978 #define STATUS_INVALID_MEMBER            0xC000017B
1979 #define STATUS_KEY_DELETED               0xC000017C
1980 #define STATUS_NO_LOG_SPACE              0xC000017D
1981 #define STATUS_TOO_MANY_SIDS             0xC000017E
1982 #define STATUS_LM_CROSS_ENCRYPTION_REQUIRED 0xC000017F
1983 #define STATUS_KEY_HAS_CHILDREN          0xC0000180
1984 #define STATUS_CHILD_MUST_BE_VOLATILE    0xC0000181
1985 #define STATUS_DEVICE_CONFIGURATION_ERROR 0xC0000182
1986 #define STATUS_DRIVER_INTERNAL_ERROR     0xC0000183
1987 #define STATUS_INVALID_DEVICE_STATE      0xC0000184
1988 #define STATUS_IO_DEVICE_ERROR           0xC0000185
1989 #define STATUS_DEVICE_PROTOCOL_ERROR     0xC0000186
1990 #define STATUS_BACKUP_CONTROLLER         0xC0000187
1991 #define STATUS_LOG_FILE_FULL             0xC0000188
1992 #define STATUS_TOO_LATE                  0xC0000189
1993 #define STATUS_NO_TRUST_LSA_SECRET       0xC000018A
1994 #define STATUS_NO_TRUST_SAM_ACCOUNT      0xC000018B
1995 #define STATUS_TRUSTED_DOMAIN_FAILURE    0xC000018C
1996 #define STATUS_TRUSTED_RELATIONSHIP_FAILURE 0xC000018D
1997 #define STATUS_EVENTLOG_FILE_CORRUPT     0xC000018E
1998 #define STATUS_EVENTLOG_CANT_START       0xC000018F
1999 #define STATUS_TRUST_FAILURE             0xC0000190
2000 #define STATUS_MUTANT_LIMIT_EXCEEDED     0xC0000191
2001 #define STATUS_NETLOGON_NOT_STARTED      0xC0000192
2002 #define STATUS_ACCOUNT_EXPIRED           0xC0000193
2003 #define STATUS_POSSIBLE_DEADLOCK         0xC0000194
2004 #define STATUS_NETWORK_CREDENTIAL_CONFLICT 0xC0000195
2005 #define STATUS_REMOTE_SESSION_LIMIT      0xC0000196
2006 #define STATUS_EVENTLOG_FILE_CHANGED     0xC0000197
2007 #define STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT 0xC0000198
2008 #define STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT 0xC0000199
2009 #define STATUS_NOLOGON_SERVER_TRUST_ACCOUNT 0xC000019A
2010 #define STATUS_DOMAIN_TRUST_INCONSISTENT 0xC000019B
2011 #define STATUS_FS_DRIVER_REQUIRED        0xC000019C
2012
2013 #define STATUS_NO_USER_SESSION_KEY       0xC0000202
2014 #define STATUS_USER_SESSION_DELETED      0xC0000203
2015 #define STATUS_RESOURCE_LANG_NOT_FOUND   0xC0000204
2016 #define STATUS_INSUFF_SERVER_RESOURCES   0xC0000205
2017 #define STATUS_INVALID_BUFFER_SIZE       0xC0000206
2018 #define STATUS_INVALID_ADDRESS_COMPONENT 0xC0000207
2019 #define STATUS_INVALID_ADDRESS_WILDCARD  0xC0000208
2020 #define STATUS_TOO_MANY_ADDRESSES        0xC0000209
2021 #define STATUS_ADDRESS_ALREADY_EXISTS    0xC000020A
2022 #define STATUS_ADDRESS_CLOSED            0xC000020B
2023 #define STATUS_CONNECTION_DISCONNECTED   0xC000020C
2024 #define STATUS_CONNECTION_RESET          0xC000020D
2025 #define STATUS_TOO_MANY_NODES            0xC000020E
2026 #define STATUS_TRANSACTION_ABORTED       0xC000020F
2027 #define STATUS_TRANSACTION_TIMED_OUT     0xC0000210
2028 #define STATUS_TRANSACTION_NO_RELEASE    0xC0000211
2029 #define STATUS_TRANSACTION_NO_MATCH      0xC0000212
2030 #define STATUS_TRANSACTION_RESPONDED     0xC0000213
2031 #define STATUS_TRANSACTION_INVALID_ID    0xC0000214
2032 #define STATUS_TRANSACTION_INVALID_TYPE  0xC0000215
2033 #define STATUS_NOT_SERVER_SESSION        0xC0000216
2034 #define STATUS_NOT_CLIENT_SESSION        0xC0000217
2035 #define STATUS_CANNOT_LOAD_REGISTRY_FILE 0xC0000218
2036 #define STATUS_DEBUG_ATTACH_FAILED       0xC0000219
2037 #define STATUS_SYSTEM_PROCESS_TERMINATED 0xC000021A
2038 #define STATUS_DATA_NOT_ACCEPTED         0xC000021B
2039 #define STATUS_NO_BROWSER_SERVERS_FOUND  0xC000021C
2040 #define STATUS_VDM_HARD_ERROR            0xC000021D
2041 #define STATUS_DRIVER_CANCEL_TIMEOUT     0xC000021E
2042 #define STATUS_REPLY_MESSAGE_MISMATCH    0xC000021F
2043 #define STATUS_MAPPED_ALIGNMENT          0xC0000220
2044 #define STATUS_IMAGE_CHECKSUM_MISMATCH   0xC0000221
2045 #define STATUS_LOST_WRITEBEHIND_DATA     0xC0000222
2046 #define STATUS_CLIENT_SERVER_PARAMETERS_INVALID 0xC0000223
2047 #define STATUS_PASSWORD_MUST_CHANGE      0xC0000224
2048 #define STATUS_NOT_FOUND                 0xC0000225
2049 #define STATUS_NOT_TINY_STREAM           0xC0000226
2050 #define STATUS_RECOVERY_FAILURE          0xC0000227
2051 #define STATUS_STACK_OVERFLOW_READ       0xC0000228
2052 #define STATUS_FAIL_CHECK                0xC0000229
2053 #define STATUS_DUPLICATE_OBJECTID        0xC000022A
2054 #define STATUS_OBJECTID_EXISTS           0xC000022B
2055 #define STATUS_CONVERT_TO_LARGE          0xC000022C
2056 #define STATUS_RETRY                     0xC000022D
2057 #define STATUS_FOUND_OUT_OF_SCOPE        0xC000022E
2058 #define STATUS_ALLOCATE_BUCKET           0xC000022F
2059 #define STATUS_PROPSET_NOT_FOUND         0xC0000230
2060 #define STATUS_MARSHALL_OVERFLOW         0xC0000231
2061 #define STATUS_INVALID_VARIANT           0xC0000232
2062 #define STATUS_DOMAIN_CONTROLLER_NOT_FOUND 0xC0000233
2063 #define STATUS_ACCOUNT_LOCKED_OUT        0xC0000234
2064 #define STATUS_HANDLE_NOT_CLOSABLE       0xC0000235
2065 #define STATUS_CONNECTION_REFUSED        0xC0000236
2066 #define STATUS_GRACEFUL_DISCONNECT       0xC0000237
2067 #define STATUS_ADDRESS_ALREADY_ASSOCIATED 0xC0000238
2068 #define STATUS_ADDRESS_NOT_ASSOCIATED    0xC0000239
2069 #define STATUS_CONNECTION_INVALID        0xC000023A
2070 #define STATUS_CONNECTION_ACTIVE         0xC000023B
2071 #define STATUS_NETWORK_UNREACHABLE       0xC000023C
2072 #define STATUS_HOST_UNREACHABLE          0xC000023D
2073 #define STATUS_PROTOCOL_UNREACHABLE      0xC000023E
2074 #define STATUS_PORT_UNREACHABLE          0xC000023F
2075 #define STATUS_REQUEST_ABORTED           0xC0000240
2076 #define STATUS_CONNECTION_ABORTED        0xC0000241
2077 #define STATUS_BAD_COMPRESSION_BUFFER    0xC0000242
2078 #define STATUS_USER_MAPPED_FILE          0xC0000243
2079 #define STATUS_AUDIT_FAILED              0xC0000244
2080 #define STATUS_TIMER_RESOLUTION_NOT_SET  0xC0000245
2081 #define STATUS_CONNECTION_COUNT_LIMIT    0xC0000246
2082 #define STATUS_LOGIN_TIME_RESTRICTION    0xC0000247
2083 #define STATUS_LOGIN_WKSTA_RESTRICTION   0xC0000248
2084 #define STATUS_IMAGE_MP_UP_MISMATCH      0xC0000249
2085 #define STATUS_INSUFFICIENT_LOGON_INFO   0xC0000250
2086 #define STATUS_BAD_DLL_ENTRYPOINT        0xC0000251
2087 #define STATUS_BAD_SERVICE_ENTRYPOINT    0xC0000252
2088 #define STATUS_LPC_REPLY_LOST            0xC0000253
2089 #define STATUS_IP_ADDRESS_CONFLICT1      0xC0000254
2090 #define STATUS_IP_ADDRESS_CONFLICT2      0xC0000255
2091 #define STATUS_REGISTRY_QUOTA_LIMIT      0xC0000256
2092 #define STATUS_PATH_NOT_COVERED          0xC0000257
2093 #define STATUS_NO_CALLBACK_ACTIVE        0xC0000258
2094 #define STATUS_LICENSE_QUOTA_EXCEEDED    0xC0000259
2095 #define STATUS_PWD_TOO_SHORT             0xC000025A
2096 #define STATUS_PWD_TOO_RECENT            0xC000025B
2097 #define STATUS_PWD_HISTORY_CONFLICT      0xC000025C
2098 #define STATUS_PLUGPLAY_NO_DEVICE        0xC000025E
2099 #define STATUS_UNSUPPORTED_COMPRESSION   0xC000025F
2100 #define STATUS_INVALID_HW_PROFILE        0xC0000260
2101 #define STATUS_INVALID_PLUGPLAY_DEVICE_PATH 0xC0000261
2102 #define STATUS_DRIVER_ORDINAL_NOT_FOUND  0xC0000262
2103 #define STATUS_DRIVER_ENTRYPOINT_NOT_FOUND 0xC0000263
2104 #define STATUS_RESOURCE_NOT_OWNED        0xC0000264
2105 #define STATUS_TOO_MANY_LINKS            0xC0000265
2106 #define STATUS_QUOTA_LIST_INCONSISTENT   0xC0000266
2107 #define STATUS_FILE_IS_OFFLINE           0xC0000267
2108 #define STATUS_EVALUATION_EXPIRATION     0xC0000268
2109 #define STATUS_ILLEGAL_DLL_RELOCATION    0xC0000269
2110 #define STATUS_LICENSE_VIOLATION         0xC000026A
2111 #define STATUS_DLL_INIT_FAILED_LOGOFF    0xC000026B
2112 #define STATUS_DRIVER_UNABLE_TO_LOAD     0xC000026C
2113 #define STATUS_DFS_UNAVAILABLE           0xC000026D
2114 #define STATUS_VOLUME_DISMOUNTED         0xC000026E
2115 #define STATUS_WX86_INTERNAL_ERROR       0xC000026F
2116 #define STATUS_WX86_FLOAT_STACK_CHECK    0xC0000270
2117 #define STATUS_WOW_ASSERTION             0xC0009898
2118 #define RPC_NT_INVALID_STRING_BINDING    0xC0020001
2119 #define RPC_NT_WRONG_KIND_OF_BINDING     0xC0020002
2120 #define RPC_NT_INVALID_BINDING           0xC0020003
2121 #define RPC_NT_PROTSEQ_NOT_SUPPORTED     0xC0020004
2122 #define RPC_NT_INVALID_RPC_PROTSEQ       0xC0020005
2123 #define RPC_NT_INVALID_STRING_UUID       0xC0020006
2124 #define RPC_NT_INVALID_ENDPOINT_FORMAT   0xC0020007
2125 #define RPC_NT_INVALID_NET_ADDR          0xC0020008
2126 #define RPC_NT_NO_ENDPOINT_FOUND         0xC0020009
2127 #define RPC_NT_INVALID_TIMEOUT           0xC002000A
2128 #define RPC_NT_OBJECT_NOT_FOUND          0xC002000B
2129 #define RPC_NT_ALREADY_REGISTERED        0xC002000C
2130 #define RPC_NT_TYPE_ALREADY_REGISTERED   0xC002000D
2131 #define RPC_NT_ALREADY_LISTENING         0xC002000E
2132 #define RPC_NT_NO_PROTSEQS_REGISTERED    0xC002000F
2133 #define RPC_NT_NOT_LISTENING             0xC0020010
2134 #define RPC_NT_UNKNOWN_MGR_TYPE          0xC0020011
2135 #define RPC_NT_UNKNOWN_IF                0xC0020012
2136 #define RPC_NT_NO_BINDINGS               0xC0020013
2137 #define RPC_NT_NO_PROTSEQS               0xC0020014
2138 #define RPC_NT_CANT_CREATE_ENDPOINT      0xC0020015
2139 #define RPC_NT_OUT_OF_RESOURCES          0xC0020016
2140 #define RPC_NT_SERVER_UNAVAILABLE        0xC0020017
2141 #define RPC_NT_SERVER_TOO_BUSY           0xC0020018
2142 #define RPC_NT_INVALID_NETWORK_OPTIONS   0xC0020019
2143 #define RPC_NT_NO_CALL_ACTIVE            0xC002001A
2144 #define RPC_NT_CALL_FAILED               0xC002001B
2145 #define RPC_NT_CALL_FAILED_DNE           0xC002001C
2146 #define RPC_NT_PROTOCOL_ERROR            0xC002001D
2147 #define RPC_NT_UNSUPPORTED_TRANS_SYN     0xC002001F
2148 #define RPC_NT_UNSUPPORTED_TYPE          0xC0020021
2149 #define RPC_NT_INVALID_TAG               0xC0020022
2150 #define RPC_NT_INVALID_BOUND             0xC0020023
2151 #define RPC_NT_NO_ENTRY_NAME             0xC0020024
2152 #define RPC_NT_INVALID_NAME_SYNTAX       0xC0020025
2153 #define RPC_NT_UNSUPPORTED_NAME_SYNTAX   0xC0020026
2154 #define RPC_NT_UUID_NO_ADDRESS           0xC0020028
2155 #define RPC_NT_DUPLICATE_ENDPOINT        0xC0020029
2156 #define RPC_NT_UNKNOWN_AUTHN_TYPE        0xC002002A
2157 #define RPC_NT_MAX_CALLS_TOO_SMALL       0xC002002B
2158 #define RPC_NT_STRING_TOO_LONG           0xC002002C
2159 #define RPC_NT_PROTSEQ_NOT_FOUND         0xC002002D
2160 #define RPC_NT_PROCNUM_OUT_OF_RANGE      0xC002002E
2161 #define RPC_NT_BINDING_HAS_NO_AUTH       0xC002002F
2162 #define RPC_NT_UNKNOWN_AUTHN_SERVICE     0xC0020030
2163 #define RPC_NT_UNKNOWN_AUTHN_LEVEL       0xC0020031
2164 #define RPC_NT_INVALID_AUTH_IDENTITY     0xC0020032
2165 #define RPC_NT_UNKNOWN_AUTHZ_SERVICE     0xC0020033
2166 #define EPT_NT_INVALID_ENTRY             0xC0020034
2167 #define EPT_NT_CANT_PERFORM_OP           0xC0020035
2168 #define EPT_NT_NOT_REGISTERED            0xC0020036
2169 #define RPC_NT_NOTHING_TO_EXPORT         0xC0020037
2170 #define RPC_NT_INCOMPLETE_NAME           0xC0020038
2171 #define RPC_NT_INVALID_VERS_OPTION       0xC0020039
2172 #define RPC_NT_NO_MORE_MEMBERS           0xC002003A
2173 #define RPC_NT_NOT_ALL_OBJS_UNEXPORTED   0xC002003B
2174 #define RPC_NT_INTERFACE_NOT_FOUND       0xC002003C
2175 #define RPC_NT_ENTRY_ALREADY_EXISTS      0xC002003D
2176 #define RPC_NT_ENTRY_NOT_FOUND           0xC002003E
2177 #define RPC_NT_NAME_SERVICE_UNAVAILABLE  0xC002003F
2178 #define RPC_NT_INVALID_NAF_ID            0xC0020040
2179 #define RPC_NT_CANNOT_SUPPORT            0xC0020041
2180 #define RPC_NT_NO_CONTEXT_AVAILABLE      0xC0020042
2181 #define RPC_NT_INTERNAL_ERROR            0xC0020043
2182 #define RPC_NT_ZERO_DIVIDE               0xC0020044
2183 #define RPC_NT_ADDRESS_ERROR             0xC0020045
2184 #define RPC_NT_FP_DIV_ZERO               0xC0020046
2185 #define RPC_NT_FP_UNDERFLOW              0xC0020047
2186 #define RPC_NT_FP_OVERFLOW               0xC0020048
2187 #define RPC_NT_NO_MORE_ENTRIES           0xC0030001
2188 #define RPC_NT_SS_CHAR_TRANS_OPEN_FAIL   0xC0030002
2189 #define RPC_NT_SS_CHAR_TRANS_SHORT_FILE  0xC0030003
2190 #define RPC_NT_SS_IN_NULL_CONTEXT        0xC0030004
2191 #define RPC_NT_SS_CONTEXT_MISMATCH       0xC0030005
2192 #define RPC_NT_SS_CONTEXT_DAMAGED        0xC0030006
2193 #define RPC_NT_SS_HANDLES_MISMATCH       0xC0030007
2194 #define RPC_NT_SS_CANNOT_GET_CALL_HANDLE 0xC0030008
2195 #define RPC_NT_NULL_REF_POINTER          0xC0030009
2196 #define RPC_NT_ENUM_VALUE_OUT_OF_RANGE   0xC003000A
2197 #define RPC_NT_BYTE_COUNT_TOO_SMALL      0xC003000B
2198 #define RPC_NT_BAD_STUB_DATA             0xC003000C
2199 #define RPC_NT_CALL_IN_PROGRESS          0xC0020049
2200 #define RPC_NT_NO_MORE_BINDINGS          0xC002004A
2201 #define RPC_NT_GROUP_MEMBER_NOT_FOUND    0xC002004B
2202 #define EPT_NT_CANT_CREATE               0xC002004C
2203 #define RPC_NT_INVALID_OBJECT            0xC002004D
2204 #define RPC_NT_NO_INTERFACES             0xC002004F
2205 #define RPC_NT_CALL_CANCELLED            0xC0020050
2206 #define RPC_NT_BINDING_INCOMPLETE        0xC0020051
2207 #define RPC_NT_COMM_FAILURE              0xC0020052
2208 #define RPC_NT_UNSUPPORTED_AUTHN_LEVEL   0xC0020053
2209 #define RPC_NT_NO_PRINC_NAME             0xC0020054
2210 #define RPC_NT_NOT_RPC_ERROR             0xC0020055
2211 #define RPC_NT_UUID_LOCAL_ONLY           0x40020056
2212 #define RPC_NT_SEC_PKG_ERROR             0xC0020057
2213 #define RPC_NT_NOT_CANCELLED             0xC0020058
2214 #define RPC_NT_INVALID_ES_ACTION         0xC0030059
2215 #define RPC_NT_WRONG_ES_VERSION          0xC003005A
2216 #define RPC_NT_WRONG_STUB_VERSION        0xC003005B
2217 #define RPC_NT_INVALID_PIPE_OBJECT       0xC003005C
2218 #define RPC_NT_INVALID_PIPE_OPERATION    0xC003005D
2219 #define RPC_NT_WRONG_PIPE_VERSION        0xC003005E
2220 #define RPC_NT_SEND_INCOMPLETE           0x400200AF
2221
2222 #define MAXIMUM_WAIT_OBJECTS 64
2223 #define MAXIMUM_SUSPEND_COUNT 127
2224
2225
2226 /*
2227  * Return values from the actual exception handlers
2228  */
2229
2230 #define ExceptionContinueExecution 0
2231 #define ExceptionContinueSearch    1
2232 #define ExceptionNestedException   2
2233 #define ExceptionCollidedUnwind    3
2234  
2235 /*
2236  * Return values from filters in except() and from UnhandledExceptionFilter
2237  */
2238  
2239 #define EXCEPTION_EXECUTE_HANDLER        1
2240 #define EXCEPTION_CONTINUE_SEARCH        0
2241 #define EXCEPTION_CONTINUE_EXECUTION    -1
2242
2243 /*
2244  * From OS/2 2.0 exception handling
2245  * Win32 seems to use the same flags as ExceptionFlags in an EXCEPTION_RECORD
2246  */
2247
2248 #define EH_NONCONTINUABLE   0x01
2249 #define EH_UNWINDING        0x02
2250 #define EH_EXIT_UNWIND      0x04
2251 #define EH_STACK_INVALID    0x08
2252 #define EH_NESTED_CALL      0x10
2253
2254 #define EXCEPTION_CONTINUABLE        0
2255 #define EXCEPTION_NONCONTINUABLE     EH_NONCONTINUABLE
2256  
2257 /*
2258  * The exception record used by Win32 to give additional information 
2259  * about exception to exception handlers.
2260  */
2261
2262 #define EXCEPTION_MAXIMUM_PARAMETERS 15
2263
2264 typedef struct __EXCEPTION_RECORD
2265 {
2266     DWORD    ExceptionCode;
2267     DWORD    ExceptionFlags;
2268     struct __EXCEPTION_RECORD *ExceptionRecord;
2269
2270     LPVOID   ExceptionAddress;
2271     DWORD    NumberParameters;
2272     DWORD    ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
2273 } EXCEPTION_RECORD, *PEXCEPTION_RECORD;
2274
2275 /*
2276  * The exception pointers structure passed to exception filters
2277  * in except() and the UnhandledExceptionFilter().
2278  */
2279  
2280 typedef struct _EXCEPTION_POINTERS 
2281 {
2282   PEXCEPTION_RECORD  ExceptionRecord;
2283   PCONTEXT           ContextRecord;
2284 } EXCEPTION_POINTERS, *PEXCEPTION_POINTERS;
2285
2286
2287 /*
2288  * The exception frame, used for registering exception handlers 
2289  * Win32 cares only about this, but compilers generally emit 
2290  * larger exception frames for their own use.
2291  */
2292
2293 struct __EXCEPTION_FRAME;
2294
2295 typedef DWORD (*PEXCEPTION_HANDLER)(PEXCEPTION_RECORD,struct __EXCEPTION_FRAME*,
2296                                     PCONTEXT,struct __EXCEPTION_FRAME **);
2297
2298 typedef struct __EXCEPTION_FRAME
2299 {
2300   struct __EXCEPTION_FRAME *Prev;
2301   PEXCEPTION_HANDLER       Handler;
2302 } EXCEPTION_FRAME, *PEXCEPTION_FRAME;
2303
2304 /*
2305  * function pointer to a exception filter
2306  */
2307
2308 typedef LONG CALLBACK (*PTOP_LEVEL_EXCEPTION_FILTER)(PEXCEPTION_POINTERS ExceptionInfo);
2309 typedef PTOP_LEVEL_EXCEPTION_FILTER LPTOP_LEVEL_EXCEPTION_FILTER;
2310
2311 DWORD WINAPI UnhandledExceptionFilter( PEXCEPTION_POINTERS epointers );
2312 LPTOP_LEVEL_EXCEPTION_FILTER
2313 WINAPI SetUnhandledExceptionFilter( LPTOP_LEVEL_EXCEPTION_FILTER filter );
2314
2315 /* status values for ContinueDebugEvent */
2316 #define DBG_CONTINUE                0x00010002
2317 #define DBG_TERMINATE_THREAD        0x40010003
2318 #define DBG_TERMINATE_PROCESS       0x40010004
2319 #define DBG_CONTROL_C               0x40010005
2320 #define DBG_CONTROL_BREAK           0x40010008
2321 #define DBG_EXCEPTION_NOT_HANDLED   0x80010001
2322
2323 typedef struct _NT_TIB 
2324 {
2325         struct _EXCEPTION_REGISTRATION_RECORD *ExceptionList;
2326         PVOID StackBase;
2327         PVOID StackLimit;
2328         PVOID SubSystemTib;
2329         union {
2330           PVOID FiberData;
2331           DWORD Version;
2332         } DUMMYUNIONNAME;
2333         PVOID ArbitraryUserPointer;
2334         struct _NT_TIB *Self;
2335 } NT_TIB, *PNT_TIB;
2336
2337 struct _TEB;
2338
2339 #if defined(__i386__) && defined(__GNUC__)
2340 extern inline struct _TEB WINAPI *NtCurrentTeb(void);
2341 extern inline struct _TEB WINAPI *NtCurrentTeb(void)
2342 {
2343     struct _TEB *teb;
2344     __asm__(".byte 0x64\n\tmovl (0x18),%0" : "=r" (teb));
2345     return teb;
2346 }
2347 #else
2348 extern struct _TEB WINAPI *NtCurrentTeb(void);
2349 #endif
2350
2351
2352 /*
2353  * File formats definitions
2354  */
2355
2356 typedef struct _IMAGE_DOS_HEADER {
2357     WORD  e_magic;      /* 00: MZ Header signature */
2358     WORD  e_cblp;       /* 02: Bytes on last page of file */
2359     WORD  e_cp;         /* 04: Pages in file */
2360     WORD  e_crlc;       /* 06: Relocations */
2361     WORD  e_cparhdr;    /* 08: Size of header in paragraphs */
2362     WORD  e_minalloc;   /* 0a: Minimum extra paragraphs needed */
2363     WORD  e_maxalloc;   /* 0c: Maximum extra paragraphs needed */
2364     WORD  e_ss;         /* 0e: Initial (relative) SS value */
2365     WORD  e_sp;         /* 10: Initial SP value */
2366     WORD  e_csum;       /* 12: Checksum */
2367     WORD  e_ip;         /* 14: Initial IP value */
2368     WORD  e_cs;         /* 16: Initial (relative) CS value */
2369     WORD  e_lfarlc;     /* 18: File address of relocation table */
2370     WORD  e_ovno;       /* 1a: Overlay number */
2371     WORD  e_res[4];     /* 1c: Reserved words */
2372     WORD  e_oemid;      /* 24: OEM identifier (for e_oeminfo) */
2373     WORD  e_oeminfo;    /* 26: OEM information; e_oemid specific */
2374     WORD  e_res2[10];   /* 28: Reserved words */
2375     DWORD e_lfanew;     /* 3c: Offset to extended header */
2376 } IMAGE_DOS_HEADER, *PIMAGE_DOS_HEADER;
2377
2378 #define IMAGE_DOS_SIGNATURE    0x5A4D     /* MZ   */
2379 #define IMAGE_OS2_SIGNATURE    0x454E     /* NE   */
2380 #define IMAGE_OS2_SIGNATURE_LE 0x454C     /* LE   */
2381 #define IMAGE_OS2_SIGNATURE_LX 0x584C     /* LX */
2382 #define IMAGE_VXD_SIGNATURE    0x454C     /* LE   */
2383 #define IMAGE_NT_SIGNATURE     0x00004550 /* PE00 */
2384
2385 /*
2386  * This is the Windows executable (NE) header.
2387  * the name IMAGE_OS2_HEADER is misleading, but in the SDK this way.
2388  */
2389 typedef struct 
2390 {
2391     WORD  ne_magic;             /* 00 NE signature 'NE' */
2392     BYTE  ne_ver;               /* 02 Linker version number */
2393     BYTE  ne_rev;               /* 03 Linker revision number */
2394     WORD  ne_enttab;            /* 04 Offset to entry table relative to NE */
2395     WORD  ne_cbenttab;          /* 06 Length of entry table in bytes */
2396     LONG  ne_crc;               /* 08 Checksum */
2397     WORD  ne_flags;             /* 0c Flags about segments in this file */
2398     WORD  ne_autodata;          /* 0e Automatic data segment number */
2399     WORD  ne_heap;              /* 10 Initial size of local heap */
2400     WORD  ne_stack;             /* 12 Initial size of stack */
2401     DWORD ne_csip;              /* 14 Initial CS:IP */
2402     DWORD ne_sssp;              /* 18 Initial SS:SP */
2403     WORD  ne_cseg;              /* 1c # of entries in segment table */
2404     WORD  ne_cmod;              /* 1e # of entries in module reference tab. */
2405     WORD  ne_cbnrestab;         /* 20 Length of nonresident-name table     */
2406     WORD  ne_segtab;            /* 22 Offset to segment table */
2407     WORD  ne_rsrctab;           /* 24 Offset to resource table */
2408     WORD  ne_restab;            /* 26 Offset to resident-name table */
2409     WORD  ne_modtab;            /* 28 Offset to module reference table */
2410     WORD  ne_imptab;            /* 2a Offset to imported name table */
2411     DWORD ne_nrestab;           /* 2c Offset to nonresident-name table */
2412     WORD  ne_cmovent;           /* 30 # of movable entry points */
2413     WORD  ne_align;             /* 32 Logical sector alignment shift count */
2414     WORD  ne_cres;              /* 34 # of resource segments */
2415     BYTE  ne_exetyp;            /* 36 Flags indicating target OS */
2416     BYTE  ne_flagsothers;       /* 37 Additional information flags */
2417     WORD  fastload_offset;      /* 38 Offset to fast load area (should be ne_pretthunks)*/
2418     WORD  fastload_length;      /* 3a Length of fast load area (should be ne_psegrefbytes) */
2419     WORD  ne_swaparea;          /* 3c Reserved by Microsoft */
2420     WORD  ne_expver;            /* 3e Expected Windows version number */
2421 } IMAGE_OS2_HEADER,*PIMAGE_OS2_HEADER;
2422
2423 typedef struct _IMAGE_VXD_HEADER {
2424   WORD  e32_magic;
2425   BYTE  e32_border;
2426   BYTE  e32_worder;
2427   DWORD e32_level;
2428   WORD  e32_cpu;
2429   WORD  e32_os;
2430   DWORD e32_ver;
2431   DWORD e32_mflags;
2432   DWORD e32_mpages;
2433   DWORD e32_startobj;
2434   DWORD e32_eip;
2435   DWORD e32_stackobj;
2436   DWORD e32_esp;
2437   DWORD e32_pagesize;
2438   DWORD e32_lastpagesize;
2439   DWORD e32_fixupsize;
2440   DWORD e32_fixupsum;
2441   DWORD e32_ldrsize;
2442   DWORD e32_ldrsum;
2443   DWORD e32_objtab;
2444   DWORD e32_objcnt;
2445   DWORD e32_objmap;
2446   DWORD e32_itermap;
2447   DWORD e32_rsrctab;
2448   DWORD e32_rsrccnt;
2449   DWORD e32_restab;
2450   DWORD e32_enttab;
2451   DWORD e32_dirtab;
2452   DWORD e32_dircnt;
2453   DWORD e32_fpagetab;
2454   DWORD e32_frectab;
2455   DWORD e32_impmod;
2456   DWORD e32_impmodcnt;
2457   DWORD e32_impproc;
2458   DWORD e32_pagesum;
2459   DWORD e32_datapage;
2460   DWORD e32_preload;
2461   DWORD e32_nrestab;
2462   DWORD e32_cbnrestab;
2463   DWORD e32_nressum;
2464   DWORD e32_autodata;
2465   DWORD e32_debuginfo;
2466   DWORD e32_debuglen;
2467   DWORD e32_instpreload;
2468   DWORD e32_instdemand;
2469   DWORD e32_heapsize;
2470   BYTE   e32_res3[12];
2471   DWORD e32_winresoff;
2472   DWORD e32_winreslen;
2473   WORD  e32_devid;
2474   WORD  e32_ddkver;
2475 } IMAGE_VXD_HEADER, *PIMAGE_VXD_HEADER;
2476
2477
2478 /* These defines describe the meanings of the bits in the Characteristics
2479    field */
2480
2481 #define IMAGE_FILE_RELOCS_STRIPPED      0x0001 /* No relocation info */
2482 #define IMAGE_FILE_EXECUTABLE_IMAGE     0x0002
2483 #define IMAGE_FILE_LINE_NUMS_STRIPPED   0x0004
2484 #define IMAGE_FILE_LOCAL_SYMS_STRIPPED  0x0008
2485 #define IMAGE_FILE_16BIT_MACHINE        0x0040
2486 #define IMAGE_FILE_BYTES_REVERSED_LO    0x0080
2487 #define IMAGE_FILE_32BIT_MACHINE        0x0100
2488 #define IMAGE_FILE_DEBUG_STRIPPED       0x0200
2489 #define IMAGE_FILE_SYSTEM               0x1000
2490 #define IMAGE_FILE_DLL                  0x2000
2491 #define IMAGE_FILE_BYTES_REVERSED_HI    0x8000
2492
2493 /* These are the settings of the Machine field. */
2494 #define IMAGE_FILE_MACHINE_UNKNOWN      0
2495 #define IMAGE_FILE_MACHINE_I860         0x14d
2496 #define IMAGE_FILE_MACHINE_I386         0x14c
2497 #define IMAGE_FILE_MACHINE_R3000        0x162
2498 #define IMAGE_FILE_MACHINE_R4000        0x166
2499 #define IMAGE_FILE_MACHINE_R10000       0x168
2500 #define IMAGE_FILE_MACHINE_ALPHA        0x184
2501 #define IMAGE_FILE_MACHINE_POWERPC      0x1F0  
2502
2503 #define IMAGE_SIZEOF_FILE_HEADER        20
2504
2505 /* Possible Magic values */
2506 #define IMAGE_NT_OPTIONAL_HDR_MAGIC        0x10b
2507 #define IMAGE_ROM_OPTIONAL_HDR_MAGIC       0x107
2508
2509 /* These are indexes into the DataDirectory array */
2510 #define IMAGE_FILE_EXPORT_DIRECTORY             0
2511 #define IMAGE_FILE_IMPORT_DIRECTORY             1
2512 #define IMAGE_FILE_RESOURCE_DIRECTORY           2
2513 #define IMAGE_FILE_EXCEPTION_DIRECTORY          3
2514 #define IMAGE_FILE_SECURITY_DIRECTORY           4
2515 #define IMAGE_FILE_BASE_RELOCATION_TABLE        5
2516 #define IMAGE_FILE_DEBUG_DIRECTORY              6
2517 #define IMAGE_FILE_DESCRIPTION_STRING           7
2518 #define IMAGE_FILE_MACHINE_VALUE                8  /* Mips */
2519 #define IMAGE_FILE_THREAD_LOCAL_STORAGE         9
2520 #define IMAGE_FILE_CALLBACK_DIRECTORY           10
2521
2522 /* Directory Entries, indices into the DataDirectory array */
2523
2524 #define IMAGE_DIRECTORY_ENTRY_EXPORT            0
2525 #define IMAGE_DIRECTORY_ENTRY_IMPORT            1
2526 #define IMAGE_DIRECTORY_ENTRY_RESOURCE          2
2527 #define IMAGE_DIRECTORY_ENTRY_EXCEPTION         3
2528 #define IMAGE_DIRECTORY_ENTRY_SECURITY          4
2529 #define IMAGE_DIRECTORY_ENTRY_BASERELOC         5
2530 #define IMAGE_DIRECTORY_ENTRY_DEBUG             6
2531 #define IMAGE_DIRECTORY_ENTRY_COPYRIGHT         7
2532 #define IMAGE_DIRECTORY_ENTRY_GLOBALPTR         8   /* (MIPS GP) */
2533 #define IMAGE_DIRECTORY_ENTRY_TLS               9
2534 #define IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG       10
2535 #define IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT      11
2536 #define IMAGE_DIRECTORY_ENTRY_IAT               12  /* Import Address Table */
2537 #define IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT      13
2538 #define IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR    14
2539
2540 /* Subsystem Values */
2541
2542 #define IMAGE_SUBSYSTEM_UNKNOWN         0
2543 #define IMAGE_SUBSYSTEM_NATIVE          1
2544 #define IMAGE_SUBSYSTEM_WINDOWS_GUI     2       /* Windows GUI subsystem */
2545 #define IMAGE_SUBSYSTEM_WINDOWS_CUI     3       /* Windows character subsystem*/
2546 #define IMAGE_SUBSYSTEM_OS2_CUI         5
2547 #define IMAGE_SUBSYSTEM_POSIX_CUI       7
2548
2549 typedef struct _IMAGE_FILE_HEADER {
2550   WORD  Machine;
2551   WORD  NumberOfSections;
2552   DWORD TimeDateStamp;
2553   DWORD PointerToSymbolTable;
2554   DWORD NumberOfSymbols;
2555   WORD  SizeOfOptionalHeader;
2556   WORD  Characteristics;
2557 } IMAGE_FILE_HEADER, *PIMAGE_FILE_HEADER;
2558
2559 typedef struct _IMAGE_DATA_DIRECTORY {
2560   DWORD VirtualAddress;
2561   DWORD Size;
2562 } IMAGE_DATA_DIRECTORY, *PIMAGE_DATA_DIRECTORY;
2563
2564 #define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 16
2565
2566 typedef struct _IMAGE_OPTIONAL_HEADER {
2567
2568   /* Standard fields */
2569
2570   WORD  Magic; /* 0x10b or 0x107 */     /* 0x00 */
2571   BYTE  MajorLinkerVersion;
2572   BYTE  MinorLinkerVersion;
2573   DWORD SizeOfCode;
2574   DWORD SizeOfInitializedData;
2575   DWORD SizeOfUninitializedData;
2576   DWORD AddressOfEntryPoint;            /* 0x10 */
2577   DWORD BaseOfCode;
2578   DWORD BaseOfData;
2579
2580   /* NT additional fields */
2581
2582   DWORD ImageBase;
2583   DWORD SectionAlignment;               /* 0x20 */
2584   DWORD FileAlignment;
2585   WORD  MajorOperatingSystemVersion;
2586   WORD  MinorOperatingSystemVersion;
2587   WORD  MajorImageVersion;
2588   WORD  MinorImageVersion;
2589   WORD  MajorSubsystemVersion;          /* 0x30 */
2590   WORD  MinorSubsystemVersion;
2591   DWORD Win32VersionValue;
2592   DWORD SizeOfImage;
2593   DWORD SizeOfHeaders;
2594   DWORD CheckSum;                       /* 0x40 */
2595   WORD  Subsystem;
2596   WORD  DllCharacteristics;
2597   DWORD SizeOfStackReserve;
2598   DWORD SizeOfStackCommit;
2599   DWORD SizeOfHeapReserve;              /* 0x50 */
2600   DWORD SizeOfHeapCommit;
2601   DWORD LoaderFlags;
2602   DWORD NumberOfRvaAndSizes;
2603   IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; /* 0x60 */
2604 } IMAGE_OPTIONAL_HEADER, *PIMAGE_OPTIONAL_HEADER;
2605
2606 typedef struct _IMAGE_NT_HEADERS {
2607   DWORD Signature; /* "PE"\0\0 */
2608   IMAGE_FILE_HEADER FileHeader;
2609   IMAGE_OPTIONAL_HEADER OptionalHeader;
2610 } IMAGE_NT_HEADERS, *PIMAGE_NT_HEADERS;
2611
2612 #define IMAGE_SIZEOF_SHORT_NAME 8
2613
2614 typedef struct _IMAGE_SECTION_HEADER {
2615   BYTE  Name[IMAGE_SIZEOF_SHORT_NAME];
2616   union {
2617     DWORD PhysicalAddress;
2618     DWORD VirtualSize;
2619   } Misc;
2620   DWORD VirtualAddress;
2621   DWORD SizeOfRawData;
2622   DWORD PointerToRawData;
2623   DWORD PointerToRelocations;
2624   DWORD PointerToLinenumbers;
2625   WORD  NumberOfRelocations;
2626   WORD  NumberOfLinenumbers;
2627   DWORD Characteristics;
2628 } IMAGE_SECTION_HEADER, *PIMAGE_SECTION_HEADER;
2629
2630 #define IMAGE_SIZEOF_SECTION_HEADER 40
2631
2632 #define IMAGE_FIRST_SECTION(ntheader) \
2633   ((PIMAGE_SECTION_HEADER)((LPBYTE)&((PIMAGE_NT_HEADERS)(ntheader))->OptionalHeader + \
2634                            ((PIMAGE_NT_HEADERS)(ntheader))->FileHeader.SizeOfOptionalHeader))
2635
2636 /* These defines are for the Characteristics bitfield. */
2637 /* #define IMAGE_SCN_TYPE_REG                   0x00000000 - Reserved */
2638 /* #define IMAGE_SCN_TYPE_DSECT                 0x00000001 - Reserved */
2639 /* #define IMAGE_SCN_TYPE_NOLOAD                0x00000002 - Reserved */
2640 /* #define IMAGE_SCN_TYPE_GROUP                 0x00000004 - Reserved */
2641 /* #define IMAGE_SCN_TYPE_NO_PAD                0x00000008 - Reserved */
2642 /* #define IMAGE_SCN_TYPE_COPY                  0x00000010 - Reserved */
2643
2644 #define IMAGE_SCN_CNT_CODE                      0x00000020
2645 #define IMAGE_SCN_CNT_INITIALIZED_DATA          0x00000040
2646 #define IMAGE_SCN_CNT_UNINITIALIZED_DATA        0x00000080
2647
2648 #define IMAGE_SCN_LNK_OTHER                     0x00000100 
2649 #define IMAGE_SCN_LNK_INFO                      0x00000200  
2650 /* #define      IMAGE_SCN_TYPE_OVER             0x00000400 - Reserved */
2651 #define IMAGE_SCN_LNK_REMOVE                    0x00000800
2652 #define IMAGE_SCN_LNK_COMDAT                    0x00001000
2653
2654 /*                                              0x00002000 - Reserved */
2655 /* #define IMAGE_SCN_MEM_PROTECTED              0x00004000 - Obsolete */
2656 #define IMAGE_SCN_MEM_FARDATA                   0x00008000
2657
2658 /* #define IMAGE_SCN_MEM_SYSHEAP                0x00010000 - Obsolete */
2659 #define IMAGE_SCN_MEM_PURGEABLE                 0x00020000
2660 #define IMAGE_SCN_MEM_16BIT                     0x00020000
2661 #define IMAGE_SCN_MEM_LOCKED                    0x00040000
2662 #define IMAGE_SCN_MEM_PRELOAD                   0x00080000
2663
2664 #define IMAGE_SCN_ALIGN_1BYTES                  0x00100000
2665 #define IMAGE_SCN_ALIGN_2BYTES                  0x00200000
2666 #define IMAGE_SCN_ALIGN_4BYTES                  0x00300000
2667 #define IMAGE_SCN_ALIGN_8BYTES                  0x00400000
2668 #define IMAGE_SCN_ALIGN_16BYTES                 0x00500000  /* Default */
2669 #define IMAGE_SCN_ALIGN_32BYTES                 0x00600000
2670 #define IMAGE_SCN_ALIGN_64BYTES                 0x00700000
2671 /*                                              0x00800000 - Unused */
2672
2673 #define IMAGE_SCN_LNK_NRELOC_OVFL               0x01000000
2674
2675
2676 #define IMAGE_SCN_MEM_DISCARDABLE               0x02000000
2677 #define IMAGE_SCN_MEM_NOT_CACHED                0x04000000
2678 #define IMAGE_SCN_MEM_NOT_PAGED                 0x08000000
2679 #define IMAGE_SCN_MEM_SHARED                    0x10000000
2680 #define IMAGE_SCN_MEM_EXECUTE                   0x20000000
2681 #define IMAGE_SCN_MEM_READ                      0x40000000
2682 #define IMAGE_SCN_MEM_WRITE                     0x80000000
2683
2684 #include "pshpack2.h"
2685
2686 typedef struct _IMAGE_SYMBOL {
2687     union {
2688         BYTE    ShortName[8];
2689         struct {
2690             DWORD   Short;
2691             DWORD   Long;
2692         } Name;
2693         DWORD   LongName[2];
2694     } N;
2695     DWORD   Value;
2696     SHORT   SectionNumber;
2697     WORD    Type;
2698     BYTE    StorageClass;
2699     BYTE    NumberOfAuxSymbols;
2700 } IMAGE_SYMBOL;
2701 typedef IMAGE_SYMBOL *PIMAGE_SYMBOL;
2702
2703 #define IMAGE_SIZEOF_SYMBOL 18
2704
2705 typedef struct _IMAGE_LINENUMBER {
2706     union {
2707         DWORD   SymbolTableIndex;
2708         DWORD   VirtualAddress;
2709     } Type;
2710     WORD    Linenumber;
2711 } IMAGE_LINENUMBER;
2712 typedef IMAGE_LINENUMBER *PIMAGE_LINENUMBER;
2713
2714 #define IMAGE_SIZEOF_LINENUMBER  6
2715
2716 typedef union _IMAGE_AUX_SYMBOL {
2717     struct {
2718         DWORD    TagIndex;
2719         union {
2720             struct {
2721                 WORD    Linenumber;
2722                 WORD    Size;
2723             } LnSz;
2724            DWORD    TotalSize;
2725         } Misc;
2726         union {
2727             struct {
2728                 DWORD    PointerToLinenumber;
2729                 DWORD    PointerToNextFunction;
2730             } Function;
2731             struct {
2732                 WORD     Dimension[4];
2733             } Array;
2734         } FcnAry;
2735         WORD    TvIndex;
2736     } Sym;
2737     struct {
2738         BYTE    Name[IMAGE_SIZEOF_SYMBOL];
2739     } File;
2740     struct {
2741         DWORD   Length;
2742         WORD    NumberOfRelocations;
2743         WORD    NumberOfLinenumbers;
2744         DWORD   CheckSum;
2745         SHORT   Number;
2746         BYTE    Selection;
2747     } Section;
2748 } IMAGE_AUX_SYMBOL;
2749 typedef IMAGE_AUX_SYMBOL *PIMAGE_AUX_SYMBOL;
2750
2751 #define IMAGE_SIZEOF_AUX_SYMBOL 18
2752
2753 #include "poppack.h"
2754
2755 #define IMAGE_SYM_UNDEFINED           (SHORT)0
2756 #define IMAGE_SYM_ABSOLUTE            (SHORT)-1
2757 #define IMAGE_SYM_DEBUG               (SHORT)-2
2758
2759 #define IMAGE_SYM_TYPE_NULL                 0x0000
2760 #define IMAGE_SYM_TYPE_VOID                 0x0001
2761 #define IMAGE_SYM_TYPE_CHAR                 0x0002
2762 #define IMAGE_SYM_TYPE_SHORT                0x0003
2763 #define IMAGE_SYM_TYPE_INT                  0x0004
2764 #define IMAGE_SYM_TYPE_LONG                 0x0005
2765 #define IMAGE_SYM_TYPE_FLOAT                0x0006
2766 #define IMAGE_SYM_TYPE_DOUBLE               0x0007
2767 #define IMAGE_SYM_TYPE_STRUCT               0x0008
2768 #define IMAGE_SYM_TYPE_UNION                0x0009
2769 #define IMAGE_SYM_TYPE_ENUM                 0x000A
2770 #define IMAGE_SYM_TYPE_MOE                  0x000B
2771 #define IMAGE_SYM_TYPE_BYTE                 0x000C
2772 #define IMAGE_SYM_TYPE_WORD                 0x000D
2773 #define IMAGE_SYM_TYPE_UINT                 0x000E
2774 #define IMAGE_SYM_TYPE_DWORD                0x000F
2775 #define IMAGE_SYM_TYPE_PCODE                0x8000
2776
2777 #define IMAGE_SYM_DTYPE_NULL                0
2778 #define IMAGE_SYM_DTYPE_POINTER             1
2779 #define IMAGE_SYM_DTYPE_FUNCTION            2
2780 #define IMAGE_SYM_DTYPE_ARRAY               3
2781
2782 #define IMAGE_SYM_CLASS_END_OF_FUNCTION     (BYTE )-1
2783 #define IMAGE_SYM_CLASS_NULL                0x0000
2784 #define IMAGE_SYM_CLASS_AUTOMATIC           0x0001
2785 #define IMAGE_SYM_CLASS_EXTERNAL            0x0002
2786 #define IMAGE_SYM_CLASS_STATIC              0x0003
2787 #define IMAGE_SYM_CLASS_REGISTER            0x0004
2788 #define IMAGE_SYM_CLASS_EXTERNAL_DEF        0x0005
2789 #define IMAGE_SYM_CLASS_LABEL               0x0006
2790 #define IMAGE_SYM_CLASS_UNDEFINED_LABEL     0x0007
2791 #define IMAGE_SYM_CLASS_MEMBER_OF_STRUCT    0x0008
2792 #define IMAGE_SYM_CLASS_ARGUMENT            0x0009
2793 #define IMAGE_SYM_CLASS_STRUCT_TAG          0x000A
2794 #define IMAGE_SYM_CLASS_MEMBER_OF_UNION     0x000B
2795 #define IMAGE_SYM_CLASS_UNION_TAG           0x000C
2796 #define IMAGE_SYM_CLASS_TYPE_DEFINITION     0x000D
2797 #define IMAGE_SYM_CLASS_UNDEFINED_STATIC    0x000E
2798 #define IMAGE_SYM_CLASS_ENUM_TAG            0x000F
2799 #define IMAGE_SYM_CLASS_MEMBER_OF_ENUM      0x0010
2800 #define IMAGE_SYM_CLASS_REGISTER_PARAM      0x0011
2801 #define IMAGE_SYM_CLASS_BIT_FIELD           0x0012
2802
2803 #define IMAGE_SYM_CLASS_FAR_EXTERNAL        0x0044
2804 #define IMAGE_SYM_CLASS_BLOCK               0x0064
2805 #define IMAGE_SYM_CLASS_FUNCTION            0x0065
2806 #define IMAGE_SYM_CLASS_END_OF_STRUCT       0x0066
2807 #define IMAGE_SYM_CLASS_FILE                0x0067
2808 #define IMAGE_SYM_CLASS_SECTION             0x0068
2809 #define IMAGE_SYM_CLASS_WEAK_EXTERNAL       0x0069
2810
2811 #define N_BTMASK                            0x000F
2812 #define N_TMASK                             0x0030
2813 #define N_TMASK1                            0x00C0
2814 #define N_TMASK2                            0x00F0
2815 #define N_BTSHFT                            4
2816 #define N_TSHIFT                            2
2817
2818 #define BTYPE(x) ((x) & N_BTMASK)
2819
2820 #ifndef ISPTR
2821 #define ISPTR(x) (((x) & N_TMASK) == (IMAGE_SYM_DTYPE_POINTER << N_BTSHFT))
2822 #endif
2823
2824 #ifndef ISFCN
2825 #define ISFCN(x) (((x) & N_TMASK) == (IMAGE_SYM_DTYPE_FUNCTION << N_BTSHFT))
2826 #endif
2827
2828 #ifndef ISARY
2829 #define ISARY(x) (((x) & N_TMASK) == (IMAGE_SYM_DTYPE_ARRAY << N_BTSHFT))
2830 #endif
2831
2832 #ifndef ISTAG
2833 #define ISTAG(x) ((x)==IMAGE_SYM_CLASS_STRUCT_TAG || (x)==IMAGE_SYM_CLASS_UNION_TAG || (x)==IMAGE_SYM_CLASS_ENUM_TAG)
2834 #endif
2835
2836 #ifndef INCREF
2837 #define INCREF(x) ((((x)&~N_BTMASK)<<N_TSHIFT)|(IMAGE_SYM_DTYPE_POINTER<<N_BTSHFT)|((x)&N_BTMASK))
2838 #endif
2839 #ifndef DECREF
2840 #define DECREF(x) ((((x)>>N_TSHIFT)&~N_BTMASK)|((x)&N_BTMASK))
2841 #endif
2842
2843 #define IMAGE_COMDAT_SELECT_NODUPLICATES    1
2844 #define IMAGE_COMDAT_SELECT_ANY             2
2845 #define IMAGE_COMDAT_SELECT_SAME_SIZE       3
2846 #define IMAGE_COMDAT_SELECT_EXACT_MATCH     4
2847 #define IMAGE_COMDAT_SELECT_ASSOCIATIVE     5
2848 #define IMAGE_COMDAT_SELECT_LARGEST         6
2849 #define IMAGE_COMDAT_SELECT_NEWEST          7
2850
2851 #define IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY  1
2852 #define IMAGE_WEAK_EXTERN_SEARCH_LIBRARY    2
2853 #define IMAGE_WEAK_EXTERN_SEARCH_ALIAS      3
2854
2855 /* Export module directory */
2856
2857 typedef struct _IMAGE_EXPORT_DIRECTORY {
2858         DWORD   Characteristics;
2859         DWORD   TimeDateStamp;
2860         WORD    MajorVersion;
2861         WORD    MinorVersion;
2862         DWORD   Name;
2863         DWORD   Base;
2864         DWORD   NumberOfFunctions;
2865         DWORD   NumberOfNames;
2866         DWORD   AddressOfFunctions;
2867         DWORD   AddressOfNames;
2868         DWORD   AddressOfNameOrdinals;
2869 } IMAGE_EXPORT_DIRECTORY,*PIMAGE_EXPORT_DIRECTORY;
2870
2871 /* Import name entry */
2872 typedef struct _IMAGE_IMPORT_BY_NAME {
2873         WORD    Hint;
2874         BYTE    Name[1];
2875 } IMAGE_IMPORT_BY_NAME,*PIMAGE_IMPORT_BY_NAME;
2876
2877 /* Import thunk */
2878 typedef struct _IMAGE_THUNK_DATA {
2879         union {
2880                 LPBYTE    ForwarderString;
2881                 PDWORD    Function;
2882                 DWORD     Ordinal;
2883                 PIMAGE_IMPORT_BY_NAME   AddressOfData;
2884         } u1;
2885 } IMAGE_THUNK_DATA,*PIMAGE_THUNK_DATA;
2886
2887 /* Import module directory */
2888
2889 typedef struct _IMAGE_IMPORT_DESCRIPTOR {
2890         union {
2891                 DWORD   Characteristics; /* 0 for terminating null import descriptor  */
2892                 PIMAGE_THUNK_DATA OriginalFirstThunk;   /* RVA to original unbound IAT */
2893         } u;
2894         DWORD   TimeDateStamp;  /* 0 if not bound,
2895                                  * -1 if bound, and real date\time stamp
2896                                  *    in IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT
2897                                  * (new BIND)
2898                                  * otherwise date/time stamp of DLL bound to
2899                                  * (Old BIND)
2900                                  */
2901         DWORD   ForwarderChain; /* -1 if no forwarders */
2902         DWORD   Name;
2903         /* RVA to IAT (if bound this IAT has actual addresses) */
2904         PIMAGE_THUNK_DATA FirstThunk;   
2905 } IMAGE_IMPORT_DESCRIPTOR,*PIMAGE_IMPORT_DESCRIPTOR;
2906
2907 #define IMAGE_ORDINAL_FLAG              0x80000000
2908 #define IMAGE_SNAP_BY_ORDINAL(Ordinal)  ((Ordinal & IMAGE_ORDINAL_FLAG) != 0)
2909 #define IMAGE_ORDINAL(Ordinal)          (Ordinal & 0xffff)
2910
2911 typedef struct _IMAGE_BOUND_IMPORT_DESCRIPTOR
2912 {
2913     DWORD   TimeDateStamp;
2914     WORD    OffsetModuleName;
2915     WORD    NumberOfModuleForwarderRefs;
2916 /* Array of zero or more IMAGE_BOUND_FORWARDER_REF follows */
2917 } IMAGE_BOUND_IMPORT_DESCRIPTOR,  *PIMAGE_BOUND_IMPORT_DESCRIPTOR;
2918
2919 typedef struct _IMAGE_BOUND_FORWARDER_REF
2920 {
2921     DWORD   TimeDateStamp;
2922     WORD    OffsetModuleName;
2923     WORD    Reserved;
2924 } IMAGE_BOUND_FORWARDER_REF, *PIMAGE_BOUND_FORWARDER_REF;
2925
2926 #include "pshpack2.h"
2927
2928 typedef struct _IMAGE_BASE_RELOCATION
2929 {
2930         DWORD   VirtualAddress;
2931         DWORD   SizeOfBlock;
2932         /* WORD TypeOffset[1]; */
2933 } IMAGE_BASE_RELOCATION,*PIMAGE_BASE_RELOCATION;
2934
2935 typedef struct _IMAGE_RELOCATION
2936 {
2937     union {
2938         DWORD   VirtualAddress;
2939         DWORD   RelocCount;
2940     } u;
2941     DWORD   SymbolTableIndex;
2942     WORD    Type;
2943 } IMAGE_RELOCATION;
2944 typedef IMAGE_RELOCATION *PIMAGE_RELOCATION;
2945
2946 #include "poppack.h"
2947
2948 #define IMAGE_SIZEOF_RELOCATION 10
2949
2950 /* generic relocation types */
2951 #define IMAGE_REL_BASED_ABSOLUTE                0
2952 #define IMAGE_REL_BASED_HIGH                    1
2953 #define IMAGE_REL_BASED_LOW                     2
2954 #define IMAGE_REL_BASED_HIGHLOW                 3
2955 #define IMAGE_REL_BASED_HIGHADJ                 4
2956 #define IMAGE_REL_BASED_MIPS_JMPADDR            5
2957 #define IMAGE_REL_BASED_SECTION                 6
2958 #define IMAGE_REL_BASED_REL                     7
2959 #define IMAGE_REL_BASED_MIPS_JMPADDR16          9
2960 #define IMAGE_REL_BASED_IA64_IMM64              9 /* yes, 9 too */
2961 #define IMAGE_REL_BASED_DIR64                   10
2962 #define IMAGE_REL_BASED_HIGH3ADJ                11
2963
2964 /* I386 relocation types */
2965 #define IMAGE_REL_I386_ABSOLUTE                 0
2966 #define IMAGE_REL_I386_DIR16                    1
2967 #define IMAGE_REL_I386_REL16                    2
2968 #define IMAGE_REL_I386_DIR32                    6
2969 #define IMAGE_REL_I386_DIR32NB                  7
2970 #define IMAGE_REL_I386_SEG12                    9
2971 #define IMAGE_REL_I386_SECTION                  10
2972 #define IMAGE_REL_I386_SECREL                   11
2973 #define IMAGE_REL_I386_REL32                    20
2974
2975 /* MIPS relocation types */
2976 #define IMAGE_REL_MIPS_ABSOLUTE         0x0000
2977 #define IMAGE_REL_MIPS_REFHALF          0x0001
2978 #define IMAGE_REL_MIPS_REFWORD          0x0002
2979 #define IMAGE_REL_MIPS_JMPADDR          0x0003
2980 #define IMAGE_REL_MIPS_REFHI            0x0004
2981 #define IMAGE_REL_MIPS_REFLO            0x0005
2982 #define IMAGE_REL_MIPS_GPREL            0x0006
2983 #define IMAGE_REL_MIPS_LITERAL          0x0007
2984 #define IMAGE_REL_MIPS_SECTION          0x000A
2985 #define IMAGE_REL_MIPS_SECREL           0x000B
2986 #define IMAGE_REL_MIPS_SECRELLO         0x000C
2987 #define IMAGE_REL_MIPS_SECRELHI         0x000D
2988 #define IMAGE_REL_MIPS_JMPADDR16        0x0010
2989 #define IMAGE_REL_MIPS_REFWORDNB        0x0022
2990 #define IMAGE_REL_MIPS_PAIR             0x0025
2991
2992 /* ALPHA relocation types */
2993 #define IMAGE_REL_ALPHA_ABSOLUTE        0x0000
2994 #define IMAGE_REL_ALPHA_REFLONG         0x0001
2995 #define IMAGE_REL_ALPHA_REFQUAD         0x0002
2996 #define IMAGE_REL_ALPHA_GPREL           0x0003
2997 #define IMAGE_REL_ALPHA_LITERAL         0x0004
2998 #define IMAGE_REL_ALPHA_LITUSE          0x0005
2999 #define IMAGE_REL_ALPHA_GPDISP          0x0006
3000 #define IMAGE_REL_ALPHA_BRADDR          0x0007
3001 #define IMAGE_REL_ALPHA_HINT            0x0008
3002 #define IMAGE_REL_ALPHA_INLINE_REFLONG  0x0009
3003 #define IMAGE_REL_ALPHA_REFHI           0x000A
3004 #define IMAGE_REL_ALPHA_REFLO           0x000B
3005 #define IMAGE_REL_ALPHA_PAIR            0x000C
3006 #define IMAGE_REL_ALPHA_MATCH           0x000D
3007 #define IMAGE_REL_ALPHA_SECTION         0x000E
3008 #define IMAGE_REL_ALPHA_SECREL          0x000F
3009 #define IMAGE_REL_ALPHA_REFLONGNB       0x0010
3010 #define IMAGE_REL_ALPHA_SECRELLO        0x0011
3011 #define IMAGE_REL_ALPHA_SECRELHI        0x0012
3012 #define IMAGE_REL_ALPHA_REFQ3           0x0013
3013 #define IMAGE_REL_ALPHA_REFQ2           0x0014
3014 #define IMAGE_REL_ALPHA_REFQ1           0x0015
3015 #define IMAGE_REL_ALPHA_GPRELLO         0x0016
3016 #define IMAGE_REL_ALPHA_GPRELHI         0x0017
3017
3018 /* PowerPC relocation types */
3019 #define IMAGE_REL_PPC_ABSOLUTE          0x0000
3020 #define IMAGE_REL_PPC_ADDR64            0x0001
3021 #define IMAGE_REL_PPC_ADDR            0x0002
3022 #define IMAGE_REL_PPC_ADDR24            0x0003
3023 #define IMAGE_REL_PPC_ADDR16            0x0004
3024 #define IMAGE_REL_PPC_ADDR14            0x0005
3025 #define IMAGE_REL_PPC_REL24             0x0006
3026 #define IMAGE_REL_PPC_REL14             0x0007
3027 #define IMAGE_REL_PPC_TOCREL16          0x0008
3028 #define IMAGE_REL_PPC_TOCREL14          0x0009
3029 #define IMAGE_REL_PPC_ADDR32NB          0x000A
3030 #define IMAGE_REL_PPC_SECREL            0x000B
3031 #define IMAGE_REL_PPC_SECTION           0x000C
3032 #define IMAGE_REL_PPC_IFGLUE            0x000D
3033 #define IMAGE_REL_PPC_IMGLUE            0x000E
3034 #define IMAGE_REL_PPC_SECREL16          0x000F
3035 #define IMAGE_REL_PPC_REFHI             0x0010
3036 #define IMAGE_REL_PPC_REFLO             0x0011
3037 #define IMAGE_REL_PPC_PAIR              0x0012
3038 #define IMAGE_REL_PPC_SECRELLO          0x0013
3039 #define IMAGE_REL_PPC_SECRELHI          0x0014
3040 #define IMAGE_REL_PPC_GPREL             0x0015
3041 #define IMAGE_REL_PPC_TYPEMASK          0x00FF
3042 /* modifier bits */
3043 #define IMAGE_REL_PPC_NEG               0x0100
3044 #define IMAGE_REL_PPC_BRTAKEN           0x0200
3045 #define IMAGE_REL_PPC_BRNTAKEN          0x0400
3046 #define IMAGE_REL_PPC_TOCDEFN           0x0800
3047
3048 /* SH3 ? relocation type */
3049 #define IMAGE_REL_SH3_ABSOLUTE          0x0000
3050 #define IMAGE_REL_SH3_DIRECT16          0x0001
3051 #define IMAGE_REL_SH3_DIRECT          0x0002
3052 #define IMAGE_REL_SH3_DIRECT8           0x0003
3053 #define IMAGE_REL_SH3_DIRECT8_WORD      0x0004
3054 #define IMAGE_REL_SH3_DIRECT8_LONG      0x0005
3055 #define IMAGE_REL_SH3_DIRECT4           0x0006
3056 #define IMAGE_REL_SH3_DIRECT4_WORD      0x0007
3057 #define IMAGE_REL_SH3_DIRECT4_LONG      0x0008
3058 #define IMAGE_REL_SH3_PCREL8_WORD       0x0009
3059 #define IMAGE_REL_SH3_PCREL8_LONG       0x000A
3060 #define IMAGE_REL_SH3_PCREL12_WORD      0x000B
3061 #define IMAGE_REL_SH3_STARTOF_SECTION   0x000C
3062 #define IMAGE_REL_SH3_SIZEOF_SECTION    0x000D
3063 #define IMAGE_REL_SH3_SECTION           0x000E
3064 #define IMAGE_REL_SH3_SECREL            0x000F
3065 #define IMAGE_REL_SH3_DIRECT32_NB       0x0010
3066
3067 /* ARM (Archimedes?) relocation types */
3068 #define IMAGE_REL_ARM_ABSOLUTE          0x0000
3069 #define IMAGE_REL_ARM_ADDR              0x0001
3070 #define IMAGE_REL_ARM_ADDR32NB          0x0002
3071 #define IMAGE_REL_ARM_BRANCH24          0x0003
3072 #define IMAGE_REL_ARM_BRANCH11          0x0004
3073 #define IMAGE_REL_ARM_SECTION           0x000E
3074 #define IMAGE_REL_ARM_SECREL            0x000F
3075
3076 /* IA64 relocation types */
3077 #define IMAGE_REL_IA64_ABSOLUTE         0x0000
3078 #define IMAGE_REL_IA64_IMM14            0x0001
3079 #define IMAGE_REL_IA64_IMM22            0x0002
3080 #define IMAGE_REL_IA64_IMM64            0x0003
3081 #define IMAGE_REL_IA64_DIR              0x0004
3082 #define IMAGE_REL_IA64_DIR64            0x0005
3083 #define IMAGE_REL_IA64_PCREL21B         0x0006
3084 #define IMAGE_REL_IA64_PCREL21M         0x0007
3085 #define IMAGE_REL_IA64_PCREL21F         0x0008
3086 #define IMAGE_REL_IA64_GPREL22          0x0009
3087 #define IMAGE_REL_IA64_LTOFF22          0x000A
3088 #define IMAGE_REL_IA64_SECTION          0x000B
3089 #define IMAGE_REL_IA64_SECREL22         0x000C
3090 #define IMAGE_REL_IA64_SECREL64I        0x000D
3091 #define IMAGE_REL_IA64_SECREL           0x000E
3092 #define IMAGE_REL_IA64_LTOFF64          0x000F
3093 #define IMAGE_REL_IA64_DIR32NB          0x0010
3094 #define IMAGE_REL_IA64_RESERVED_11      0x0011
3095 #define IMAGE_REL_IA64_RESERVED_12      0x0012
3096 #define IMAGE_REL_IA64_RESERVED_13      0x0013
3097 #define IMAGE_REL_IA64_RESERVED_14      0x0014
3098 #define IMAGE_REL_IA64_RESERVED_15      0x0015
3099 #define IMAGE_REL_IA64_RESERVED_16      0x0016
3100 #define IMAGE_REL_IA64_ADDEND           0x001F
3101
3102 /* archive format */
3103
3104 #define IMAGE_ARCHIVE_START_SIZE             8
3105 #define IMAGE_ARCHIVE_START                  "!<arch>\n"
3106 #define IMAGE_ARCHIVE_END                    "`\n"
3107 #define IMAGE_ARCHIVE_PAD                    "\n"
3108 #define IMAGE_ARCHIVE_LINKER_MEMBER          "/               "
3109 #define IMAGE_ARCHIVE_LONGNAMES_MEMBER       "//              "
3110
3111 typedef struct _IMAGE_ARCHIVE_MEMBER_HEADER
3112 {
3113     BYTE     Name[16];
3114     BYTE     Date[12];
3115     BYTE     UserID[6];
3116     BYTE     GroupID[6];
3117     BYTE     Mode[8];
3118     BYTE     Size[10];
3119     BYTE     EndHeader[2];
3120 } IMAGE_ARCHIVE_MEMBER_HEADER, *PIMAGE_ARCHIVE_MEMBER_HEADER;
3121
3122 #define IMAGE_SIZEOF_ARCHIVE_MEMBER_HDR 60
3123
3124 /*
3125  * Resource directory stuff
3126  */
3127 typedef struct _IMAGE_RESOURCE_DIRECTORY {
3128         DWORD   Characteristics;
3129         DWORD   TimeDateStamp;
3130         WORD    MajorVersion;
3131         WORD    MinorVersion;
3132         WORD    NumberOfNamedEntries;
3133         WORD    NumberOfIdEntries;
3134         /*  IMAGE_RESOURCE_DIRECTORY_ENTRY DirectoryEntries[]; */
3135 } IMAGE_RESOURCE_DIRECTORY,*PIMAGE_RESOURCE_DIRECTORY;
3136
3137 #define IMAGE_RESOURCE_NAME_IS_STRING           0x80000000
3138 #define IMAGE_RESOURCE_DATA_IS_DIRECTORY        0x80000000
3139
3140 typedef struct _IMAGE_RESOURCE_DIRECTORY_ENTRY {
3141         union {
3142                 struct {
3143 #ifdef BITFIELDS_BIGENDIAN
3144                         unsigned NameIsString:1;
3145                         unsigned NameOffset:31;
3146 #else
3147                         unsigned NameOffset:31;
3148                         unsigned NameIsString:1;
3149 #endif
3150                 } DUMMYSTRUCTNAME1;
3151                 DWORD   Name;
3152                 struct {
3153 #ifdef WORDS_BIGENDIAN
3154                         WORD    __pad;
3155                         WORD    Id;
3156 #else
3157                         WORD    Id;
3158                         WORD    __pad;
3159 #endif
3160                 } DUMMYSTRUCTNAME2;
3161         } DUMMYUNIONNAME1;
3162         union {
3163                 DWORD   OffsetToData;
3164                 struct {
3165 #ifdef BITFIELDS_BIGENDIAN
3166                         unsigned DataIsDirectory:1;
3167                         unsigned OffsetToDirectory:31;
3168 #else
3169                         unsigned OffsetToDirectory:31;
3170                         unsigned DataIsDirectory:1;
3171 #endif
3172                 } DUMMYSTRUCTNAME3;
3173         } DUMMYUNIONNAME2;
3174 } IMAGE_RESOURCE_DIRECTORY_ENTRY,*PIMAGE_RESOURCE_DIRECTORY_ENTRY;
3175
3176
3177 typedef struct _IMAGE_RESOURCE_DIRECTORY_STRING {
3178         WORD    Length;
3179         CHAR    NameString[ 1 ];
3180 } IMAGE_RESOURCE_DIRECTORY_STRING,*PIMAGE_RESOURCE_DIRECTORY_STRING;
3181
3182 typedef struct _IMAGE_RESOURCE_DIR_STRING_U {
3183         WORD    Length;
3184         WCHAR   NameString[ 1 ];
3185 } IMAGE_RESOURCE_DIR_STRING_U,*PIMAGE_RESOURCE_DIR_STRING_U;
3186
3187 typedef struct _IMAGE_RESOURCE_DATA_ENTRY {
3188         DWORD   OffsetToData;
3189         DWORD   Size;
3190         DWORD   CodePage;
3191         DWORD   ResourceHandle;
3192 } IMAGE_RESOURCE_DATA_ENTRY,*PIMAGE_RESOURCE_DATA_ENTRY;
3193
3194
3195 typedef VOID CALLBACK (*PIMAGE_TLS_CALLBACK)(
3196         LPVOID DllHandle,DWORD Reason,LPVOID Reserved
3197 );
3198
3199 typedef struct _IMAGE_TLS_DIRECTORY {
3200         DWORD   StartAddressOfRawData;
3201         DWORD   EndAddressOfRawData;
3202         LPDWORD AddressOfIndex;
3203         PIMAGE_TLS_CALLBACK *AddressOfCallBacks;
3204         DWORD   SizeOfZeroFill;
3205         DWORD   Characteristics;
3206 } IMAGE_TLS_DIRECTORY,*PIMAGE_TLS_DIRECTORY;
3207
3208 typedef struct _IMAGE_DEBUG_DIRECTORY {
3209   DWORD Characteristics;
3210   DWORD TimeDateStamp;
3211   WORD  MajorVersion;
3212   WORD  MinorVersion;
3213   DWORD Type;
3214   DWORD SizeOfData;
3215   DWORD AddressOfRawData;
3216   DWORD PointerToRawData;
3217 } IMAGE_DEBUG_DIRECTORY, *PIMAGE_DEBUG_DIRECTORY;
3218
3219 #define IMAGE_DEBUG_TYPE_UNKNOWN        0
3220 #define IMAGE_DEBUG_TYPE_COFF           1
3221 #define IMAGE_DEBUG_TYPE_CODEVIEW       2
3222 #define IMAGE_DEBUG_TYPE_FPO            3
3223 #define IMAGE_DEBUG_TYPE_MISC           4
3224 #define IMAGE_DEBUG_TYPE_EXCEPTION      5
3225 #define IMAGE_DEBUG_TYPE_FIXUP          6
3226 #define IMAGE_DEBUG_TYPE_OMAP_TO_SRC    7
3227 #define IMAGE_DEBUG_TYPE_OMAP_FROM_SRC  8
3228 #define IMAGE_DEBUG_TYPE_BORLAND        9
3229 #define IMAGE_DEBUG_TYPE_RESERVED10    10
3230
3231 typedef struct _IMAGE_COFF_SYMBOLS_HEADER {
3232   DWORD NumberOfSymbols;
3233   DWORD LvaToFirstSymbol;
3234   DWORD NumberOfLinenumbers;
3235   DWORD LvaToFirstLinenumber;
3236   DWORD RvaToFirstByteOfCode;
3237   DWORD RvaToLastByteOfCode;
3238   DWORD RvaToFirstByteOfData;
3239   DWORD RvaToLastByteOfData;
3240 } IMAGE_COFF_SYMBOLS_HEADER, *PIMAGE_COFF_SYMBOLS_HEADER;
3241
3242 #define FRAME_FPO       0
3243 #define FRAME_TRAP      1
3244 #define FRAME_TSS       2
3245 #define FRAME_NONFPO    3
3246
3247 typedef struct _FPO_DATA {
3248   DWORD ulOffStart;
3249   DWORD cbProcSize;
3250   DWORD cdwLocals;
3251   WORD  cdwParams;
3252   unsigned cbProlog : 8;
3253   unsigned cbRegs   : 3;
3254   unsigned fHasSEH  : 1;
3255   unsigned fUseBP   : 1;
3256   unsigned reserved : 1;
3257   unsigned cbFrame  : 2;
3258 } FPO_DATA, *PFPO_DATA;
3259
3260 typedef struct _IMAGE_LOAD_CONFIG_DIRECTORY {
3261   DWORD Characteristics;
3262   DWORD TimeDateStamp;
3263   WORD  MajorVersion;
3264   WORD  MinorVersion;
3265   DWORD GlobalFlagsClear;
3266   DWORD GlobalFlagsSet;
3267   DWORD CriticalSectionDefaultTimeout;
3268   DWORD DeCommitFreeBlockThreshold;
3269   DWORD DeCommitTotalFreeThreshold;
3270   PVOID LockPrefixTable;
3271   DWORD MaximumAllocationSize;
3272   DWORD VirtualMemoryThreshold;
3273   DWORD ProcessHeapFlags;
3274   DWORD ProcessAffinityMask;
3275   WORD  CSDVersion;
3276   WORD  Reserved1;
3277   PVOID EditList;
3278   DWORD Reserved[1];
3279 } IMAGE_LOAD_CONFIG_DIRECTORY, *PIMAGE_LOAD_CONFIG_DIRECTORY;
3280
3281 typedef struct _IMAGE_FUNCTION_ENTRY {
3282   DWORD StartingAddress;
3283   DWORD EndingAddress;
3284   DWORD EndOfPrologue;
3285 } IMAGE_FUNCTION_ENTRY, *PIMAGE_FUNCTION_ENTRY;
3286
3287 #define IMAGE_DEBUG_MISC_EXENAME    1
3288  
3289 typedef struct _IMAGE_DEBUG_MISC {
3290     DWORD       DataType;
3291     DWORD       Length;
3292     BYTE        Unicode;
3293     BYTE        Reserved[ 3 ];
3294     BYTE        Data[ 1 ];
3295 } IMAGE_DEBUG_MISC, *PIMAGE_DEBUG_MISC;
3296
3297 /* This is the structure that appears at the very start of a .DBG file. */
3298
3299 typedef struct _IMAGE_SEPARATE_DEBUG_HEADER {
3300         WORD    Signature;
3301         WORD    Flags;
3302         WORD    Machine;
3303         WORD    Characteristics;
3304         DWORD   TimeDateStamp;
3305         DWORD   CheckSum;
3306         DWORD   ImageBase;
3307         DWORD   SizeOfImage;
3308         DWORD   NumberOfSections;
3309         DWORD   ExportedNamesSize;
3310         DWORD   DebugDirectorySize;
3311         DWORD   SectionAlignment;
3312         DWORD   Reserved[ 2 ];
3313 } IMAGE_SEPARATE_DEBUG_HEADER,*PIMAGE_SEPARATE_DEBUG_HEADER;
3314
3315 #define IMAGE_SEPARATE_DEBUG_SIGNATURE 0x4944
3316
3317
3318 typedef struct tagMESSAGE_RESOURCE_ENTRY {
3319         WORD    Length;
3320         WORD    Flags;
3321         BYTE    Text[1];
3322 } MESSAGE_RESOURCE_ENTRY,*PMESSAGE_RESOURCE_ENTRY;
3323 #define MESSAGE_RESOURCE_UNICODE        0x0001
3324
3325 typedef struct tagMESSAGE_RESOURCE_BLOCK {
3326         DWORD   LowId;
3327         DWORD   HighId;
3328         DWORD   OffsetToEntries;
3329 } MESSAGE_RESOURCE_BLOCK,*PMESSAGE_RESOURCE_BLOCK;
3330
3331 typedef struct tagMESSAGE_RESOURCE_DATA {
3332         DWORD                   NumberOfBlocks;
3333         MESSAGE_RESOURCE_BLOCK  Blocks[ 1 ];
3334 } MESSAGE_RESOURCE_DATA,*PMESSAGE_RESOURCE_DATA;
3335
3336 /*
3337  * Here follows typedefs for security and tokens.
3338  */ 
3339
3340 /*
3341  * First a constant for the following typdefs.
3342  */
3343
3344 #define ANYSIZE_ARRAY   1
3345
3346 /* FIXME:  Orphan.  What does it point to? */
3347 typedef PVOID PACCESS_TOKEN;
3348
3349 /*
3350  * TOKEN_INFORMATION_CLASS
3351  */
3352
3353 typedef enum _TOKEN_INFORMATION_CLASS {
3354   TokenUser = 1, 
3355   TokenGroups, 
3356   TokenPrivileges, 
3357   TokenOwner, 
3358   TokenPrimaryGroup, 
3359   TokenDefaultDacl, 
3360   TokenSource, 
3361   TokenType, 
3362   TokenImpersonationLevel, 
3363   TokenStatistics 
3364 } TOKEN_INFORMATION_CLASS; 
3365
3366 #define TOKEN_TOKEN_ADJUST_DEFAULT   0x0080
3367 #define TOKEN_ADJUST_GROUPS          0x0040
3368 #define TOKEN_ADJUST_PRIVILEGES      0x0020
3369 #define TOKEN_ADJUST_SESSIONID       0x0100
3370 #define TOKEN_ASSIGN_PRIMARY         0x0001
3371 #define TOKEN_DUPLICATE              0x0002
3372 #define TOKEN_EXECUTE                STANDARD_RIGHTS_EXECUTE
3373 #define TOKEN_IMPERSONATE            0x0004
3374 #define TOKEN_QUERY                  0x0008
3375 #define TOKEN_QUERY_SOURCE           0x0010
3376 #define TOKEN_ADJUST_DEFAULT         0x0080
3377 #define TOKEN_READ                   (STANDARD_RIGHTS_READ|TOKEN_QUERY)
3378 #define TOKEN_WRITE                  (STANDARD_RIGHTS_WRITE     | \
3379                                         TOKEN_ADJUST_PRIVILEGES | \
3380                                         TOKEN_ADJUST_GROUPS | \
3381                                         TOKEN_ADJUST_DEFAULT )
3382 #define TOKEN_ALL_ACCESS             (STANDARD_RIGHTS_REQUIRED | \
3383                                         TOKEN_ASSIGN_PRIMARY | \
3384                                         TOKEN_DUPLICATE | \
3385                                         TOKEN_IMPERSONATE | \
3386                                         TOKEN_QUERY | \
3387                                         TOKEN_QUERY_SOURCE | \
3388                                         TOKEN_ADJUST_PRIVILEGES | \
3389                                         TOKEN_ADJUST_GROUPS | \
3390                                         TOKEN_ADJUST_SESSIONID | \
3391                                         TOKEN_ADJUST_DEFAULT )
3392
3393 #ifndef _SECURITY_DEFINED
3394 #define _SECURITY_DEFINED
3395
3396
3397 typedef DWORD ACCESS_MASK, *PACCESS_MASK;
3398
3399 typedef struct _GENERIC_MAPPING {
3400     ACCESS_MASK GenericRead;
3401     ACCESS_MASK GenericWrite;
3402     ACCESS_MASK GenericExecute;
3403     ACCESS_MASK GenericAll;
3404 } GENERIC_MAPPING, *PGENERIC_MAPPING;
3405
3406 #ifndef SID_IDENTIFIER_AUTHORITY_DEFINED
3407 #define SID_IDENTIFIER_AUTHORITY_DEFINED
3408 typedef struct {
3409     BYTE Value[6];
3410 } SID_IDENTIFIER_AUTHORITY,*PSID_IDENTIFIER_AUTHORITY,*LPSID_IDENTIFIER_AUTHORITY;
3411 #endif /* !defined(SID_IDENTIFIER_AUTHORITY_DEFINED) */
3412
3413 #ifndef SID_DEFINED
3414 #define SID_DEFINED
3415 typedef struct _SID {
3416     BYTE Revision;
3417     BYTE SubAuthorityCount;
3418     SID_IDENTIFIER_AUTHORITY IdentifierAuthority;
3419     DWORD SubAuthority[1];
3420 } SID,*PSID;
3421 #endif /* !defined(SID_DEFINED) */
3422
3423 #define SID_REVISION                    (1)     /* Current revision */
3424 #define SID_MAX_SUB_AUTHORITIES         (15)    /* current max subauths */
3425 #define SID_RECOMMENDED_SUB_AUTHORITIES (1)     /* recommended subauths */
3426
3427
3428 /* 
3429  * ACL 
3430  */
3431
3432 #define ACL_REVISION1 1
3433 #define ACL_REVISION2 2
3434 #define ACL_REVISION3 3
3435 #define ACL_REVISION4 4
3436
3437 #define MIN_ACL_REVISION ACL_REVISION2
3438 #define MAX_ACL_REVISION ACL_REVISION4
3439
3440 typedef struct _ACL {
3441     BYTE AclRevision;
3442     BYTE Sbz1;
3443     WORD AclSize;
3444     WORD AceCount;
3445     WORD Sbz2;
3446 } ACL, *PACL;
3447
3448 /* SECURITY_DESCRIPTOR */
3449 #define SECURITY_DESCRIPTOR_REVISION    1
3450 #define SECURITY_DESCRIPTOR_REVISION1   1
3451
3452
3453 #define SE_OWNER_DEFAULTED      0x0001
3454 #define SE_GROUP_DEFAULTED      0x0002
3455 #define SE_DACL_PRESENT         0x0004
3456 #define SE_DACL_DEFAULTED       0x0008
3457 #define SE_SACL_PRESENT         0x0010
3458 #define SE_SACL_DEFAULTED       0x0020
3459 #define SE_SELF_RELATIVE        0x8000
3460
3461 typedef DWORD SECURITY_INFORMATION, *PSECURITY_INFORMATION;
3462 typedef WORD SECURITY_DESCRIPTOR_CONTROL, *PSECURITY_DESCRIPTOR_CONTROL;
3463
3464 /* The security descriptor structure */
3465 typedef struct {
3466     BYTE Revision;
3467     BYTE Sbz1;
3468     SECURITY_DESCRIPTOR_CONTROL Control;
3469     DWORD Owner;
3470     DWORD Group;
3471     DWORD Sacl;
3472     DWORD Dacl;
3473 } SECURITY_DESCRIPTOR_RELATIVE, *PISECURITY_DESCRIPTOR_RELATIVE;
3474
3475 typedef struct {
3476     BYTE Revision;
3477     BYTE Sbz1;
3478     SECURITY_DESCRIPTOR_CONTROL Control;
3479     PSID Owner;
3480     PSID Group;
3481     PACL Sacl;
3482     PACL Dacl;
3483 } SECURITY_DESCRIPTOR, *PSECURITY_DESCRIPTOR;
3484
3485 #define SECURITY_DESCRIPTOR_MIN_LENGTH   (sizeof(SECURITY_DESCRIPTOR)) 
3486
3487 #endif /* _SECURITY_DEFINED */
3488
3489 /* 
3490  * SID_AND_ATTRIBUTES
3491  */
3492
3493 typedef struct _SID_AND_ATTRIBUTES {
3494   PSID  Sid; 
3495   DWORD Attributes; 
3496 } SID_AND_ATTRIBUTES ; 
3497  
3498 /* security entities */
3499 #define SECURITY_NULL_RID                       (0x00000000L)
3500 #define SECURITY_WORLD_RID                      (0x00000000L)
3501 #define SECURITY_LOCAL_RID                      (0X00000000L)
3502
3503 #define SECURITY_NULL_SID_AUTHORITY             {0,0,0,0,0,0}
3504
3505 /* S-1-1 */
3506 #define SECURITY_WORLD_SID_AUTHORITY            {0,0,0,0,0,1}
3507
3508 /* S-1-2 */
3509 #define SECURITY_LOCAL_SID_AUTHORITY            {0,0,0,0,0,2}
3510
3511 /* S-1-3 */
3512 #define SECURITY_CREATOR_SID_AUTHORITY          {0,0,0,0,0,3}
3513 #define SECURITY_CREATOR_OWNER_RID              (0x00000000L) 
3514 #define SECURITY_CREATOR_GROUP_RID              (0x00000001L)
3515 #define SECURITY_CREATOR_OWNER_SERVER_RID       (0x00000002L)
3516 #define SECURITY_CREATOR_GROUP_SERVER_RID       (0x00000003L)
3517
3518 /* S-1-4 */
3519 #define SECURITY_NON_UNIQUE_AUTHORITY           {0,0,0,0,0,4}
3520
3521 /* S-1-5 */
3522 #define SECURITY_NT_AUTHORITY                   {0,0,0,0,0,5} 
3523 #define SECURITY_DIALUP_RID                     0x00000001L
3524 #define SECURITY_NETWORK_RID                    0x00000002L
3525 #define SECURITY_BATCH_RID                      0x00000003L
3526 #define SECURITY_INTERACTIVE_RID                0x00000004L
3527 #define SECURITY_LOGON_IDS_RID                  0x00000005L
3528 #define SECURITY_SERVICE_RID                    0x00000006L
3529 #define SECURITY_ANONYMOUS_LOGON_RID            0x00000007L
3530 #define SECURITY_PROXY_RID                      0x00000008L
3531 #define SECURITY_ENTERPRISE_CONTROLLERS_RID     0x00000009L
3532 #define SECURITY_PRINCIPAL_SELF_RID             0x0000000AL
3533 #define SECURITY_AUTHENTICATED_USER_RID         0x0000000BL
3534 #define SECURITY_RESTRICTED_CODE_RID            0x0000000CL
3535 #define SECURITY_TERMINAL_SERVER_RID            0x0000000DL
3536 #define SECURITY_LOCAL_SYSTEM_RID               0x00000012L
3537 #define SECURITY_NT_NON_UNIQUE                  0x00000015L
3538 #define SECURITY_BUILTIN_DOMAIN_RID             0x00000020L
3539
3540 #define DOMAIN_GROUP_RID_ADMINS                 0x00000200L
3541 #define DOMAIN_GROUP_RID_USERS                  0x00000201L
3542 #define DOMAIN_GROUP_RID_GUESTS                 0x00000202L
3543
3544 #define DOMAIN_ALIAS_RID_ADMINS                 0x00000220L
3545 #define DOMAIN_ALIAS_RID_USERS                  0x00000221L
3546 #define DOMAIN_ALIAS_RID_GUESTS                 0x00000222L
3547
3548 #define SECURITY_SERVER_LOGON_RID               SECURITY_ENTERPRISE_CONTROLLERS_RID
3549
3550 #define SECURITY_LOGON_IDS_RID_COUNT            (3L)
3551
3552 /*
3553  * TOKEN_USER
3554  */
3555
3556 typedef struct _TOKEN_USER {
3557   SID_AND_ATTRIBUTES User; 
3558 } TOKEN_USER; 
3559
3560 /*
3561  * TOKEN_GROUPS
3562  */
3563
3564 typedef struct _TOKEN_GROUPS  {
3565   DWORD GroupCount; 
3566   SID_AND_ATTRIBUTES Groups[ANYSIZE_ARRAY]; 
3567 } TOKEN_GROUPS; 
3568
3569 /*
3570  * LUID_AND_ATTRIBUTES
3571  */
3572
3573 typedef union _LARGE_INTEGER {
3574     struct {
3575         DWORD    LowPart;
3576         LONG     HighPart;
3577     } DUMMYSTRUCTNAME;
3578     LONGLONG QuadPart;
3579 } LARGE_INTEGER, *LPLARGE_INTEGER, *PLARGE_INTEGER;
3580
3581 typedef union _ULARGE_INTEGER {
3582     struct {
3583         DWORD    LowPart;
3584         DWORD    HighPart;
3585     } DUMMYSTRUCTNAME;
3586     ULONGLONG QuadPart;
3587 } ULARGE_INTEGER, *LPULARGE_INTEGER, *PULARGE_INTEGER;
3588
3589 /*
3590  * Locally Unique Identifier
3591  */
3592
3593 typedef struct _LUID {
3594     DWORD LowPart;
3595     LONG HighPart;
3596 } LUID, *PLUID;
3597
3598 #include "pshpack4.h"
3599 typedef struct _LUID_AND_ATTRIBUTES {
3600   LUID   Luid;
3601   DWORD  Attributes;
3602 } LUID_AND_ATTRIBUTES;
3603 #include "poppack.h"
3604
3605 /*
3606  * PRIVILEGE_SET
3607  */
3608
3609 typedef struct _PRIVILEGE_SET {
3610     DWORD PrivilegeCount;
3611     DWORD Control;
3612     LUID_AND_ATTRIBUTES Privilege[ANYSIZE_ARRAY];
3613 } PRIVILEGE_SET, *PPRIVILEGE_SET;
3614
3615 /*
3616  * TOKEN_PRIVILEGES
3617  */
3618
3619 typedef struct _TOKEN_PRIVILEGES {
3620   DWORD PrivilegeCount; 
3621   LUID_AND_ATTRIBUTES Privileges[ANYSIZE_ARRAY]; 
3622 } TOKEN_PRIVILEGES, *PTOKEN_PRIVILEGES; 
3623
3624 /*
3625  * TOKEN_OWNER
3626  */
3627
3628 typedef struct _TOKEN_OWNER {
3629   PSID Owner; 
3630 } TOKEN_OWNER; 
3631
3632 /*
3633  * TOKEN_PRIMARY_GROUP
3634  */
3635
3636 typedef struct _TOKEN_PRIMARY_GROUP {
3637   PSID PrimaryGroup; 
3638 } TOKEN_PRIMARY_GROUP; 
3639
3640
3641 /*
3642  * TOKEN_DEFAULT_DACL
3643  */
3644
3645 typedef struct _TOKEN_DEFAULT_DACL { 
3646   PACL DefaultDacl; 
3647 } TOKEN_DEFAULT_DACL; 
3648
3649 /*
3650  * TOKEN_SOURCEL
3651  */
3652
3653 typedef struct _TOKEN_SOURCE {
3654   char Sourcename[8]; 
3655   LUID SourceIdentifier; 
3656 } TOKEN_SOURCE; 
3657
3658 /*
3659  * TOKEN_TYPE
3660  */
3661
3662 typedef enum tagTOKEN_TYPE {
3663   TokenPrimary = 1, 
3664   TokenImpersonation 
3665 } TOKEN_TYPE; 
3666
3667 /*
3668  * SECURITY_IMPERSONATION_LEVEL
3669  */
3670
3671 typedef enum _SECURITY_IMPERSONATION_LEVEL {
3672   SecurityAnonymous, 
3673   SecurityIdentification, 
3674   SecurityImpersonation, 
3675   SecurityDelegation 
3676 } SECURITY_IMPERSONATION_LEVEL, *PSECURITY_IMPERSONATION_LEVEL; 
3677
3678
3679 typedef BOOLEAN SECURITY_CONTEXT_TRACKING_MODE,
3680         * PSECURITY_CONTEXT_TRACKING_MODE;
3681 /*
3682  *      Quality of Service
3683  */
3684
3685 typedef struct _SECURITY_QUALITY_OF_SERVICE {
3686   DWORD                         Length;
3687   SECURITY_IMPERSONATION_LEVEL  ImpersonationLevel;
3688   SECURITY_CONTEXT_TRACKING_MODE ContextTrackingMode;
3689   BOOLEAN                       EffectiveOnly;
3690 } SECURITY_QUALITY_OF_SERVICE, *PSECURITY_QUALITY_OF_SERVICE;
3691
3692 /*
3693  * TOKEN_STATISTICS
3694  */
3695
3696 typedef struct _TOKEN_STATISTICS {
3697   LUID  TokenId; 
3698   LUID  AuthenticationId; 
3699   LARGE_INTEGER ExpirationTime; 
3700   TOKEN_TYPE    TokenType; 
3701   SECURITY_IMPERSONATION_LEVEL ImpersonationLevel; 
3702   DWORD DynamicCharged; 
3703   DWORD DynamicAvailable; 
3704   DWORD GroupCount; 
3705   DWORD PrivilegeCount; 
3706   LUID  ModifiedId; 
3707 } TOKEN_STATISTICS; 
3708
3709 /* 
3710  *      ACLs of NT 
3711  */
3712
3713 #define ACL_REVISION    2
3714
3715 #define ACL_REVISION1   1
3716 #define ACL_REVISION2   2
3717
3718 /* ACEs, directly starting after an ACL */
3719 typedef struct _ACE_HEADER {
3720         BYTE    AceType;
3721         BYTE    AceFlags;
3722         WORD    AceSize;
3723 } ACE_HEADER,*PACE_HEADER;
3724
3725 /* AceType */
3726 #define ACCESS_ALLOWED_ACE_TYPE         0
3727 #define ACCESS_DENIED_ACE_TYPE          1
3728 #define SYSTEM_AUDIT_ACE_TYPE           2
3729 #define SYSTEM_ALARM_ACE_TYPE           3
3730
3731 /* inherit AceFlags */
3732 #define OBJECT_INHERIT_ACE              0x01
3733 #define CONTAINER_INHERIT_ACE           0x02
3734 #define NO_PROPAGATE_INHERIT_ACE        0x04
3735 #define INHERIT_ONLY_ACE                0x08
3736 #define VALID_INHERIT_FLAGS             0x0F
3737
3738 /* AceFlags mask for what events we (should) audit */
3739 #define SUCCESSFUL_ACCESS_ACE_FLAG      0x40
3740 #define FAILED_ACCESS_ACE_FLAG          0x80
3741
3742 /* different ACEs depending on AceType 
3743  * SidStart marks the begin of a SID
3744  * so the thing finally looks like this:
3745  * 0: ACE_HEADER
3746  * 4: ACCESS_MASK
3747  * 8... : SID
3748  */
3749 typedef struct _ACCESS_ALLOWED_ACE {
3750         ACE_HEADER      Header;
3751         DWORD           Mask;
3752         DWORD           SidStart;
3753 } ACCESS_ALLOWED_ACE,*PACCESS_ALLOWED_ACE;
3754
3755 typedef struct _ACCESS_DENIED_ACE {
3756         ACE_HEADER      Header;
3757         DWORD           Mask;
3758         DWORD           SidStart;
3759 } ACCESS_DENIED_ACE,*PACCESS_DENIED_ACE;
3760
3761 typedef struct _SYSTEM_AUDIT_ACE {
3762         ACE_HEADER      Header;
3763         DWORD           Mask;
3764         DWORD           SidStart;
3765 } SYSTEM_AUDIT_ACE,*PSYSTEM_AUDIT_ACE;
3766
3767 typedef struct _SYSTEM_ALARM_ACE {
3768         ACE_HEADER      Header;
3769         DWORD           Mask;
3770         DWORD           SidStart;
3771 } SYSTEM_ALARM_ACE,*PSYSTEM_ALARM_ACE;
3772
3773 typedef enum tagSID_NAME_USE {
3774         SidTypeUser = 1,
3775         SidTypeGroup,
3776         SidTypeDomain,
3777         SidTypeAlias,
3778         SidTypeWellKnownGroup,
3779         SidTypeDeletedAccount,
3780         SidTypeInvalid,
3781         SidTypeUnknown
3782 } SID_NAME_USE,*PSID_NAME_USE;
3783
3784 /* Access rights */
3785
3786 /* DELETE may be already defined via /usr/include/arpa/nameser_compat.h */
3787 #undef  DELETE
3788 #define DELETE                     0x00010000
3789 #define READ_CONTROL               0x00020000
3790 #define WRITE_DAC                  0x00040000
3791 #define WRITE_OWNER                0x00080000
3792 #define SYNCHRONIZE                0x00100000
3793 #define STANDARD_RIGHTS_REQUIRED   0x000f0000
3794
3795 #define STANDARD_RIGHTS_READ       READ_CONTROL
3796 #define STANDARD_RIGHTS_WRITE      READ_CONTROL
3797 #define STANDARD_RIGHTS_EXECUTE    READ_CONTROL
3798
3799 #define STANDARD_RIGHTS_ALL        0x001f0000
3800
3801 #define SPECIFIC_RIGHTS_ALL        0x0000ffff
3802
3803 #define GENERIC_READ               0x80000000
3804 #define GENERIC_WRITE              0x40000000
3805 #define GENERIC_EXECUTE            0x20000000
3806 #define GENERIC_ALL                0x10000000
3807
3808 #define MAXIMUM_ALLOWED            0x02000000
3809 #define ACCESS_SYSTEM_SECURITY     0x01000000
3810
3811 #define EVENT_MODIFY_STATE         0x0002
3812 #define EVENT_ALL_ACCESS           (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3)
3813
3814 #define SEMAPHORE_MODIFY_STATE     0x0002
3815 #define SEMAPHORE_ALL_ACCESS       (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3)
3816
3817 #define MUTEX_MODIFY_STATE         0x0001
3818 #define MUTEX_ALL_ACCESS           (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x1)
3819
3820 #define TIMER_QUERY_STATE          0x0001
3821 #define TIMER_MODIFY_STATE         0x0002
3822 #define TIMER_ALL_ACCESS           (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3)
3823
3824 #define PROCESS_TERMINATE          0x0001
3825 #define PROCESS_CREATE_THREAD      0x0002
3826 #define PROCESS_VM_OPERATION       0x0008
3827 #define PROCESS_VM_READ            0x0010
3828 #define PROCESS_VM_WRITE           0x0020
3829 #define PROCESS_DUP_HANDLE         0x0040
3830 #define PROCESS_CREATE_PROCESS     0x0080
3831 #define PROCESS_SET_QUOTA          0x0100
3832 #define PROCESS_SET_INFORMATION    0x0200
3833 #define PROCESS_QUERY_INFORMATION  0x0400
3834 #define PROCESS_ALL_ACCESS         (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0xfff)
3835
3836 #define THREAD_TERMINATE           0x0001
3837 #define THREAD_SUSPEND_RESUME      0x0002
3838 #define THREAD_GET_CONTEXT         0x0008
3839 #define THREAD_SET_CONTEXT         0x0010
3840 #define THREAD_SET_INFORMATION     0x0020
3841 #define THREAD_QUERY_INFORMATION   0x0040
3842 #define THREAD_SET_THREAD_TOKEN    0x0080
3843 #define THREAD_IMPERSONATE         0x0100
3844 #define THREAD_DIRECT_IMPERSONATION 0x0200
3845 #define THREAD_ALL_ACCESS          (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3ff)
3846
3847 #define THREAD_BASE_PRIORITY_LOWRT  15 
3848 #define THREAD_BASE_PRIORITY_MAX    2 
3849 #define THREAD_BASE_PRIORITY_MIN   -2
3850 #define THREAD_BASE_PRIORITY_IDLE  -15
3851
3852 #define FILE_READ_DATA            0x0001    /* file & pipe */
3853 #define FILE_LIST_DIRECTORY       0x0001    /* directory */
3854 #define FILE_WRITE_DATA           0x0002    /* file & pipe */
3855 #define FILE_ADD_FILE             0x0002    /* directory */
3856 #define FILE_APPEND_DATA          0x0004    /* file */
3857 #define FILE_ADD_SUBDIRECTORY     0x0004    /* directory */
3858 #define FILE_CREATE_PIPE_INSTANCE 0x0004    /* named pipe */
3859 #define FILE_READ_EA              0x0008    /* file & directory */
3860 #define FILE_READ_PROPERTIES      FILE_READ_EA
3861 #define FILE_WRITE_EA             0x0010    /* file & directory */
3862 #define FILE_WRITE_PROPERTIES     FILE_WRITE_EA
3863 #define FILE_EXECUTE              0x0020    /* file */
3864 #define FILE_TRAVERSE             0x0020    /* directory */
3865 #define FILE_DELETE_CHILD         0x0040    /* directory */
3866 #define FILE_READ_ATTRIBUTES      0x0080    /* all */
3867 #define FILE_WRITE_ATTRIBUTES     0x0100    /* all */
3868 #define FILE_ALL_ACCESS           (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x1ff)
3869
3870 #define FILE_GENERIC_READ         (STANDARD_RIGHTS_READ | FILE_READ_DATA | \
3871                                    FILE_READ_ATTRIBUTES | FILE_READ_EA | \
3872                                    SYNCHRONIZE)
3873 #define FILE_GENERIC_WRITE        (STANDARD_RIGHTS_WRITE | FILE_WRITE_DATA | \
3874                                    FILE_WRITE_ATTRIBUTES | FILE_WRITE_EA | \
3875                                    FILE_APPEND_DATA | SYNCHRONIZE)
3876 #define FILE_GENERIC_EXECUTE      (STANDARD_RIGHTS_EXECUTE | FILE_EXECUTE | \
3877                                    FILE_READ_ATTRIBUTES | SYNCHRONIZE)
3878
3879
3880 /* File attribute flags */
3881 #define FILE_SHARE_READ                 0x00000001L
3882 #define FILE_SHARE_WRITE                0x00000002L
3883 #define FILE_SHARE_DELETE               0x00000004L
3884 #define FILE_ATTRIBUTE_READONLY         0x00000001L
3885 #define FILE_ATTRIBUTE_HIDDEN           0x00000002L
3886 #define FILE_ATTRIBUTE_SYSTEM           0x00000004L
3887 #define FILE_ATTRIBUTE_LABEL            0x00000008L  /* Not in Windows API */
3888 #define FILE_ATTRIBUTE_DIRECTORY        0x00000010L
3889 #define FILE_ATTRIBUTE_ARCHIVE          0x00000020L
3890 #define FILE_ATTRIBUTE_NORMAL           0x00000080L
3891 #define FILE_ATTRIBUTE_TEMPORARY        0x00000100L
3892 #define FILE_ATTRIBUTE_ATOMIC_WRITE     0x00000200L
3893 #define FILE_ATTRIBUTE_XACTION_WRITE    0x00000400L
3894 #define FILE_ATTRIBUTE_COMPRESSED       0x00000800L
3895 #define FILE_ATTRIBUTE_OFFLINE          0x00001000L
3896 #define FILE_ATTRIBUTE_SYMLINK          0x80000000L  /* Not in Windows API */
3897
3898 /* File notification flags */
3899 #define FILE_NOTIFY_CHANGE_FILE_NAME    0x00000001
3900 #define FILE_NOTIFY_CHANGE_DIR_NAME     0x00000002
3901 #define FILE_NOTIFY_CHANGE_ATTRIBUTES   0x00000004
3902 #define FILE_NOTIFY_CHANGE_SIZE         0x00000008
3903 #define FILE_NOTIFY_CHANGE_LAST_WRITE   0x00000010
3904 #define FILE_NOTIFY_CHANGE_LAST_ACCESS  0x00000020
3905 #define FILE_NOTIFY_CHANGE_CREATION     0x00000040
3906 #define FILE_NOTIFY_CHANGE_SECURITY     0x00000100
3907
3908 #define FILE_ACTION_ADDED               0x00000001
3909 #define FILE_ACTION_REMOVED             0x00000002
3910 #define FILE_ACTION_MODIFIED            0x00000003
3911 #define FILE_ACTION_RENAMED_OLD_NAME    0x00000004
3912 #define FILE_ACTION_RENAMED_NEW_NAME    0x00000005
3913
3914
3915 #define FILE_CASE_SENSITIVE_SEARCH      0x00000001
3916 #define FILE_CASE_PRESERVED_NAMES       0x00000002
3917 #define FILE_UNICODE_ON_DISK            0x00000004
3918 #define FILE_PERSISTENT_ACLS            0x00000008
3919 #define FILE_FILE_COMPRESSION           0x00000010
3920 #define FILE_VOLUME_IS_COMPRESSED       0x00008000
3921
3922 /* File alignments (NT) */
3923 #define FILE_BYTE_ALIGNMENT             0x00000000
3924 #define FILE_WORD_ALIGNMENT             0x00000001
3925 #define FILE_LONG_ALIGNMENT             0x00000003
3926 #define FILE_QUAD_ALIGNMENT             0x00000007
3927 #define FILE_OCTA_ALIGNMENT             0x0000000f
3928 #define FILE_32_BYTE_ALIGNMENT          0x0000001f
3929 #define FILE_64_BYTE_ALIGNMENT          0x0000003f
3930 #define FILE_128_BYTE_ALIGNMENT         0x0000007f
3931 #define FILE_256_BYTE_ALIGNMENT         0x000000ff
3932 #define FILE_512_BYTE_ALIGNMENT         0x000001ff
3933
3934 #define REG_NONE                0       /* no type */
3935 #define REG_SZ                  1       /* string type (ASCII) */
3936 #define REG_EXPAND_SZ           2       /* string, includes %ENVVAR% (expanded by caller) (ASCII) */
3937 #define REG_BINARY              3       /* binary format, callerspecific */
3938 /* YES, REG_DWORD == REG_DWORD_LITTLE_ENDIAN */
3939 #define REG_DWORD               4       /* DWORD in little endian format */
3940 #define REG_DWORD_LITTLE_ENDIAN 4       /* DWORD in little endian format */
3941 #define REG_DWORD_BIG_ENDIAN    5       /* DWORD in big endian format  */
3942 #define REG_LINK                6       /* symbolic link (UNICODE) */
3943 #define REG_MULTI_SZ            7       /* multiple strings, delimited by \0, terminated by \0\0 (ASCII) */
3944 #define REG_RESOURCE_LIST       8       /* resource list? huh? */
3945 #define REG_FULL_RESOURCE_DESCRIPTOR    9       /* full resource descriptor? huh? */
3946 #define REG_RESOURCE_REQUIREMENTS_LIST  10
3947
3948 /* ----------------------------- begin registry ----------------------------- */
3949
3950 /* Registry security values */
3951 #define OWNER_SECURITY_INFORMATION      0x00000001
3952 #define GROUP_SECURITY_INFORMATION      0x00000002
3953 #define DACL_SECURITY_INFORMATION       0x00000004
3954 #define SACL_SECURITY_INFORMATION       0x00000008
3955
3956 #define REG_OPTION_RESERVED             0x00000000
3957 #define REG_OPTION_NON_VOLATILE         0x00000000
3958 #define REG_OPTION_VOLATILE             0x00000001
3959 #define REG_OPTION_CREATE_LINK          0x00000002
3960 #define REG_OPTION_BACKUP_RESTORE       0x00000004 /* FIXME */
3961 #define REG_OPTION_OPEN_LINK            0x00000008
3962 #define REG_LEGAL_OPTION               (REG_OPTION_RESERVED|  \
3963                                         REG_OPTION_NON_VOLATILE|  \
3964                                         REG_OPTION_VOLATILE|  \
3965                                         REG_OPTION_CREATE_LINK|  \
3966                                         REG_OPTION_BACKUP_RESTORE|  \
3967                                         REG_OPTION_OPEN_LINK)
3968
3969
3970 #define REG_CREATED_NEW_KEY     0x00000001
3971 #define REG_OPENED_EXISTING_KEY 0x00000002
3972
3973 /* For RegNotifyChangeKeyValue */
3974 #define REG_NOTIFY_CHANGE_NAME  0x1
3975
3976 #define KEY_QUERY_VALUE         0x00000001
3977 #define KEY_SET_VALUE           0x00000002
3978 #define KEY_CREATE_SUB_KEY      0x00000004
3979 #define KEY_ENUMERATE_SUB_KEYS  0x00000008
3980 #define KEY_NOTIFY              0x00000010
3981 #define KEY_CREATE_LINK         0x00000020
3982
3983 #define KEY_READ              ((STANDARD_RIGHTS_READ|  \
3984                                 KEY_QUERY_VALUE|  \
3985                                 KEY_ENUMERATE_SUB_KEYS|  \
3986                                 KEY_NOTIFY)  \
3987                                 & (~SYNCHRONIZE)  \
3988                               )
3989 #define KEY_WRITE             ((STANDARD_RIGHTS_WRITE|  \
3990                                 KEY_SET_VALUE|  \
3991                                 KEY_CREATE_SUB_KEY)  \
3992                                 & (~SYNCHRONIZE)  \
3993                               )
3994 #define KEY_EXECUTE           ((KEY_READ)  \
3995                                 & (~SYNCHRONIZE))  \
3996                               )
3997 #define KEY_ALL_ACCESS        ((STANDARD_RIGHTS_ALL|  \
3998                                 KEY_QUERY_VALUE|  \
3999                                 KEY_SET_VALUE|  \
4000                                 KEY_CREATE_SUB_KEY|  \
4001                                 KEY_ENUMERATE_SUB_KEYS|  \
4002                                 KEY_NOTIFY|  \
4003                                 KEY_CREATE_LINK)  \
4004                                 & (~SYNCHRONIZE)  \
4005                               )
4006 /* ------------------------------ end registry ------------------------------ */
4007
4008
4009 #define EVENTLOG_SUCCESS                0x0000
4010 #define EVENTLOG_ERROR_TYPE             0x0001
4011 #define EVENTLOG_WARNING_TYPE           0x0002
4012 #define EVENTLOG_INFORMATION_TYPE       0x0004
4013 #define EVENTLOG_AUDIT_SUCCESS          0x0008
4014 #define EVENTLOG_AUDIT_FAILURE          0x0010
4015
4016 #define SERVICE_BOOT_START   0x00000000
4017 #define SERVICE_SYSTEM_START 0x00000001
4018 #define SERVICE_AUTO_START   0x00000002
4019 #define SERVICE_DEMAND_START 0x00000003
4020 #define SERVICE_DISABLED     0x00000004
4021
4022 #define SERVICE_ERROR_IGNORE   0x00000000
4023 #define SERVICE_ERROR_NORMAL   0x00000001
4024 #define SERVICE_ERROR_SEVERE   0x00000002
4025 #define SERVICE_ERROR_CRITICAL 0x00000003
4026
4027 /* Service types */
4028 #define SERVICE_KERNEL_DRIVER      0x00000001
4029 #define SERVICE_FILE_SYSTEM_DRIVER 0x00000002
4030 #define SERVICE_ADAPTER            0x00000004
4031 #define SERVICE_RECOGNIZER_DRIVER  0x00000008
4032
4033 #define SERVICE_DRIVER ( SERVICE_KERNEL_DRIVER | SERVICE_FILE_SYSTEM_DRIVER | \
4034                          SERVICE_RECOGNIZER_DRIVER )
4035
4036 #define SERVICE_WIN32_OWN_PROCESS   0x00000010
4037 #define SERVICE_WIN32_SHARE_PROCESS 0x00000020
4038 #define SERVICE_WIN32  (SERVICE_WIN32_OWN_PROCESS | SERVICE_WIN32_SHARE_PROCESS)
4039
4040 #define SERVICE_INTERACTIVE_PROCESS 0x00000100
4041
4042 #define SERVICE_TYPE_ALL ( SERVICE_WIN32 | SERVICE_ADAPTER | \
4043                            SERVICE_DRIVER | SERVICE_INTERACTIVE_PROCESS )
4044
4045
4046 typedef enum _CM_SERVICE_NODE_TYPE 
4047 {
4048   DriverType               = SERVICE_KERNEL_DRIVER,
4049   FileSystemType           = SERVICE_FILE_SYSTEM_DRIVER,
4050   Win32ServiceOwnProcess   = SERVICE_WIN32_OWN_PROCESS,
4051   Win32ServiceShareProcess = SERVICE_WIN32_SHARE_PROCESS,
4052   AdapterType              = SERVICE_ADAPTER,
4053   RecognizerType           = SERVICE_RECOGNIZER_DRIVER
4054 } SERVICE_NODE_TYPE;
4055
4056 typedef enum _CM_SERVICE_LOAD_TYPE 
4057 {
4058   BootLoad    = SERVICE_BOOT_START,
4059   SystemLoad  = SERVICE_SYSTEM_START,
4060   AutoLoad    = SERVICE_AUTO_START,
4061   DemandLoad  = SERVICE_DEMAND_START,
4062   DisableLoad = SERVICE_DISABLED
4063 } SERVICE_LOAD_TYPE;
4064
4065 typedef enum _CM_ERROR_CONTROL_TYPE 
4066 {
4067   IgnoreError   = SERVICE_ERROR_IGNORE,
4068   NormalError   = SERVICE_ERROR_NORMAL,
4069   SevereError   = SERVICE_ERROR_SEVERE,
4070   CriticalError = SERVICE_ERROR_CRITICAL
4071 } SERVICE_ERROR_TYPE;
4072
4073
4074
4075 #define RtlEqualMemory(Destination, Source, Length) (!memcmp((Destination),(Source),(Length)))
4076 #define RtlMoveMemory(Destination, Source, Length) memmove((Destination),(Source),(Length))
4077 #define RtlCopyMemory(Destination, Source, Length) memcpy((Destination),(Source),(Length))
4078 #define RtlFillMemory(Destination, Length, Fill) memset((Destination),(Fill),(Length))
4079 #define RtlZeroMemory(Destination, Length) memset((Destination),0,(Length))
4080
4081 #include "guiddef.h"
4082
4083 typedef struct _RTL_CRITICAL_SECTION_DEBUG 
4084 {
4085   WORD   Type;
4086   WORD   CreatorBackTraceIndex;
4087   struct _RTL_CRITICAL_SECTION *CriticalSection;
4088   LIST_ENTRY ProcessLocksList;
4089   DWORD EntryCount;
4090   DWORD ContentionCount;
4091   DWORD Spare[ 2 ];
4092 } RTL_CRITICAL_SECTION_DEBUG, *PRTL_CRITICAL_SECTION_DEBUG, RTL_RESOURCE_DEBUG, *PRTL_RESOURCE_DEBUG;
4093
4094 typedef struct _RTL_CRITICAL_SECTION {
4095     PRTL_CRITICAL_SECTION_DEBUG DebugInfo;
4096     LONG LockCount;
4097     LONG RecursionCount;
4098     HANDLE OwningThread;
4099     HANDLE LockSemaphore;
4100     ULONG_PTR SpinCount;
4101 }  RTL_CRITICAL_SECTION, *PRTL_CRITICAL_SECTION;
4102
4103 #endif  /* __WINE_WINNT_H */