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