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