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