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