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