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