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