progman: Added Hebrew translation.
[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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #ifndef _WINNT_
22 #define _WINNT_
23
24 #include <basetsd.h>
25 #include <guiddef.h>
26
27 #ifndef RC_INVOKED
28 #include <ctype.h>
29 #include <stddef.h>
30 #include <string.h>
31 #endif
32
33
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37
38 #ifdef _NTSYSTEM_
39 #define NTSYSAPI
40 #else
41 #define NTSYSAPI DECLSPEC_IMPORT
42 #endif
43
44 #define NTAPI __stdcall
45
46 #ifndef MIDL_PASS
47 # if defined(_MSC_VER)
48 #  define DECLSPEC_IMPORT __declspec(dllimport)
49 # elif defined(__MINGW32__) || defined(__CYGWIN__)
50 #  define DECLSPEC_IMPORT __attribute__((dllimport))
51 # else
52 #  define DECLSPEC_IMPORT DECLSPEC_HIDDEN
53 # endif
54 #else
55 # define DECLSPEC_IMPORT
56 #endif
57
58 #ifndef DECLSPEC_NORETURN
59 # if defined(_MSC_VER) && (_MSC_VER >= 1200) && !defined(MIDL_PASS)
60 #  define DECLSPEC_NORETURN __declspec(noreturn)
61 # elif defined(__GNUC__)
62 #  define DECLSPEC_NORETURN __attribute__((noreturn))
63 # else
64 #  define DECLSPEC_NORETURN
65 # endif
66 #endif
67
68 #ifndef DECLSPEC_ALIGN
69 # if defined(_MSC_VER) && (_MSC_VER >= 1300) && !defined(MIDL_PASS)
70 #  define DECLSPEC_ALIGN(x) __declspec(align(x))
71 # elif defined(__GNUC__)
72 #  define DECLSPEC_ALIGN(x) __attribute__((aligned(x)))
73 # else
74 #  define DECLSPEC_ALIGN(x)
75 # endif
76 #endif
77
78 #ifndef DECLSPEC_CACHEALIGN
79 # define DECLSPEC_CACHEALIGN DECLSPEC_ALIGN(128)
80 #endif
81
82 #ifndef DECLSPEC_UUID
83 # if defined(_MSC_VER) && (_MSC_VER >= 1100) && defined (__cplusplus)
84 #  define DECLSPEC_UUID(x) __declspec(uuid(x))
85 # else
86 #  define DECLSPEC_UUID(x)
87 # endif
88 #endif
89
90 #ifndef DECLSPEC_NOVTABLE
91 # if defined(_MSC_VER) && (_MSC_VER >= 1100) && defined(__cplusplus)
92 #  define DECLSPEC_NOVTABLE __declspec(novtable)
93 # else
94 #  define DECLSPEC_NOVTABLE
95 # endif
96 #endif
97
98 #ifndef DECLSPEC_SELECTANY
99 #if defined(_MSC_VER) && (_MSC_VER >= 1100)
100 #define DECLSPEC_SELECTANY __declspec(selectany)
101 #else
102 #define DECLSPEC_SELECTANY
103 #endif
104 #endif
105
106 #ifndef NOP_FUNCTION
107 # if defined(_MSC_VER) && (_MSC_VER >= 1210)
108 #  define NOP_FUNCTION __noop
109 # else
110 #  define NOP_FUNCTION (void)0
111 # endif
112 #endif
113
114 #ifndef DECLSPEC_ADDRSAFE
115 # if defined(_MSC_VER) && (_MSC_VER >= 1200) && (defined(_M_ALPHA) || defined(_M_AXP64))
116 #  define DECLSPEC_ADDRSAFE __declspec(address_safe)
117 # else
118 #  define DECLSPEC_ADDRSAFE
119 # endif
120 #endif
121
122 #ifndef FORCEINLINE
123 # if defined(_MSC_VER) && (_MSC_VER >= 1200)
124 #  define FORCEINLINE __forceinline
125 # elif defined(__GNUC__) && ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 2)))
126 #  define FORCEINLINE inline __attribute__((always_inline))
127 # else
128 #  define FORCEINLINE inline
129 # endif
130 #endif
131
132 #ifndef DECLSPEC_DEPRECATED
133 # if defined(_MSC_VER) && (_MSC_VER >= 1300) && !defined(MIDL_PASS)
134 #  define DECLSPEC_DEPRECATED __declspec(deprecated)
135 #  define DEPRECATE_SUPPORTED
136 # elif defined(__GNUC__) && ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 2)))
137 #  define DECLSPEC_DEPRECATED __attribute__((deprecated))
138 #  define DEPRECATE_SUPPORTED
139 # else
140 #  define DECLSPEC_DEPRECATED
141 #  undef  DEPRECATE_SUPPORTED
142 # endif
143 #endif
144
145 /* a couple of useful Wine extensions */
146
147 #ifdef _MSC_VER
148 # define DECLSPEC_EXPORT __declspec(dllexport)
149 #elif defined(__MINGW32__)
150 # define DECLSPEC_EXPORT __attribute__((dllexport))
151 #elif defined(__GNUC__) && ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)))
152 # define DECLSPEC_EXPORT __attribute__((visibility ("default")))
153 #else
154 # define DECLSPEC_EXPORT
155 #endif
156
157 #if defined(__MSC_VER) || defined(__MINGW32__) || defined(__CYGWIN__)
158 # define DECLSPEC_HIDDEN
159 #elif defined(__GNUC__) && ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)))
160 # define DECLSPEC_HIDDEN __attribute__((visibility ("hidden")))
161 #else
162 # define DECLSPEC_HIDDEN
163 #endif
164
165 #if defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 3)))
166 #define __WINE_ALLOC_SIZE(x) __attribute__((__alloc_size__(x)))
167 #else
168 #define __WINE_ALLOC_SIZE(x)
169 #endif
170
171 /* Anonymous union/struct handling */
172
173 #ifndef NONAMELESSSTRUCT
174 # ifdef __GNUC__
175    /* Anonymous struct support starts with gcc 2.96 or gcc/g++ 3.x */
176 #  if (__GNUC__ < 2) || ((__GNUC__ == 2) && (defined(__cplusplus) || (__GNUC_MINOR__ < 96)))
177 #   define NONAMELESSSTRUCT
178 #  endif
179 # elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
180 #  define NONAMELESSSTRUCT
181 # endif
182 #endif  /* NONAMELESSSTRUCT */
183
184 #ifndef NONAMELESSUNION
185 # ifdef __GNUC__
186    /* Anonymous unions support starts with gcc 2.96/g++ 2.95 */
187 #  if (__GNUC__ < 2) || ((__GNUC__ == 2) && ((__GNUC_MINOR__ < 95) || ((__GNUC_MINOR__ == 95) && !defined(__cplusplus))))
188 #   define NONAMELESSUNION
189 #  endif
190 # elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
191 #  define NONAMELESSUNION
192 # endif
193 #endif  /* NONAMELESSUNION */
194
195 #ifndef NONAMELESSSTRUCT
196 #define DUMMYSTRUCTNAME
197 #define DUMMYSTRUCTNAME1
198 #define DUMMYSTRUCTNAME2
199 #define DUMMYSTRUCTNAME3
200 #define DUMMYSTRUCTNAME4
201 #define DUMMYSTRUCTNAME5
202 #else /* !defined(NONAMELESSSTRUCT) */
203 #define DUMMYSTRUCTNAME   s
204 #define DUMMYSTRUCTNAME1  s1
205 #define DUMMYSTRUCTNAME2  s2
206 #define DUMMYSTRUCTNAME3  s3
207 #define DUMMYSTRUCTNAME4  s4
208 #define DUMMYSTRUCTNAME5  s5
209 #endif /* !defined(NONAMELESSSTRUCT) */
210
211 #ifndef NONAMELESSUNION
212 #define DUMMYUNIONNAME
213 #define DUMMYUNIONNAME1
214 #define DUMMYUNIONNAME2
215 #define DUMMYUNIONNAME3
216 #define DUMMYUNIONNAME4
217 #define DUMMYUNIONNAME5
218 #define DUMMYUNIONNAME6
219 #define DUMMYUNIONNAME7
220 #define DUMMYUNIONNAME8
221 #else /* !defined(NONAMELESSUNION) */
222 #define DUMMYUNIONNAME   u
223 #define DUMMYUNIONNAME1  u1
224 #define DUMMYUNIONNAME2  u2
225 #define DUMMYUNIONNAME3  u3
226 #define DUMMYUNIONNAME4  u4
227 #define DUMMYUNIONNAME5  u5
228 #define DUMMYUNIONNAME6  u6
229 #define DUMMYUNIONNAME7  u7
230 #define DUMMYUNIONNAME8  u8
231 #endif /* !defined(NONAMELESSUNION) */
232
233 /* C99 restrict support */
234
235 #if defined(ENABLE_RESTRICTED) && !defined(MIDL_PASS) && !defined(RC_INVOKED)
236 # if defined(_MSC_VER) && defined(_M_MRX000)
237 #  define RESTRICTED_POINTER __restrict
238 # elif defined(__GNUC__) && ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 95)))
239 #  define RESTRICTED_POINTER __restrict
240 # else
241 #  define RESTRICTED_POINTER
242 # endif
243 #else
244 # define RESTRICTED_POINTER
245 #endif
246
247 /* C99 unaligned support */
248
249 #ifndef UNALIGNED
250 #if defined(_MSC_VER) && (defined(_M_MRX000) || defined(_M_ALPHA) || defined(_M_PPC) || defined(_M_IA64) || defined(_M_AMD64))
251 # define UNALIGNED __unaligned
252 # ifdef _WIN64
253 #  define UNALIGNED64 __unaligned
254 # else
255 #  define UNALIGNED64
256 # endif
257 #else
258 # define UNALIGNED
259 # define UNALIGNED64
260 #endif
261 #endif
262
263 /* Alignment macros */
264
265 #if defined(_WIN64) || (defined(_MSC_VER) && defined(_M_ALPHA)) || defined(__alpha__)
266 #define MAX_NATURAL_ALIGNMENT sizeof(ULONGLONG)
267 #define MEMORY_ALLOCATION_ALIGNMENT 16
268 #else
269 #define MAX_NATURAL_ALIGNMENT sizeof(DWORD)
270 #define MEMORY_ALLOCATION_ALIGNMENT 8
271 #endif
272
273 #if defined(_MSC_VER) && (_MSC_VER >= 1300) && defined(__cplusplus)
274 # define TYPE_ALIGNMENT(t) __alignof(t)
275 #elif defined(__GNUC__)
276 # define TYPE_ALIGNMENT(t) __alignof__(t)
277 #else
278 # define TYPE_ALIGNMENT(t) FIELD_OFFSET(struct { char x; t test; }, test)
279 #endif
280
281 #ifdef _WIN64
282 # define PROBE_ALIGNMENT(_s) \
283     (TYPE_ALIGNMENT(_s) > TYPE_ALIGNMENT(DWORD) ? \
284     TYPE_ALIGNMENT(_s) : TYPE_ALIGNMENT(DWORD))
285 # define PROBE_ALIGNMENT32(_s) TYPE_ALIGNMENT(DWORD)
286 #else
287 # define PROBE_ALIGNMENT(_s) TYPE_ALIGNMENT(DWORD)
288 #endif
289
290 /* Compile time assertion */
291
292 #if defined(_MSC_VER)
293 # define C_ASSERT(e) typedef char __C_ASSERT__[(e)?1:-1]
294 #else
295 # define C_ASSERT(e) extern void __C_ASSERT__(int [(e)?1:-1])
296 #endif
297
298 /* Eliminate Microsoft C/C++ compiler warning 4715 */
299 #if defined(_MSC_VER) && (_MSC_VER > 1200)
300 # define DEFAULT_UNREACHABLE default: __assume(0)
301 #else
302 # define DEFAULT_UNREACHABLE
303 #endif
304
305 /* Error Masks */
306 #define APPLICATION_ERROR_MASK       0x20000000
307 #define ERROR_SEVERITY_SUCCESS       0x00000000
308 #define ERROR_SEVERITY_INFORMATIONAL 0x40000000
309 #define ERROR_SEVERITY_WARNING       0x80000000
310 #define ERROR_SEVERITY_ERROR         0xC0000000
311
312 #ifdef __cplusplus
313 #define DEFINE_ENUM_FLAG_OPERATORS(ENUMTYPE) \
314 extern "C++" { \
315     inline ENUMTYPE operator | (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((int)a)|((int)b)); } \
316     inline ENUMTYPE operator |= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((int &)a) |= ((int)b)); } \
317     inline ENUMTYPE operator & (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((int)a)&((int)b)); } \
318     inline ENUMTYPE operator &= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((int &)a) &= ((int)b)); } \
319     inline ENUMTYPE operator ~ (ENUMTYPE a) { return (ENUMTYPE)(~((int)a)); } \
320     inline ENUMTYPE operator ^ (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((int)a)^((int)b)); } \
321     inline ENUMTYPE operator ^= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((int &)a) ^= ((int)b)); } \
322 }
323 #else
324 #define DEFINE_ENUM_FLAG_OPERATORS(ENUMTYPE) /* */
325 #endif
326
327 /* Microsoft's macros for declaring functions */
328
329 #ifdef __cplusplus
330 # define EXTERN_C    extern "C"
331 #else
332 # define EXTERN_C    extern
333 #endif
334
335 #define STDMETHODCALLTYPE       __stdcall
336 #define STDMETHODVCALLTYPE      __cdecl
337 #define STDAPICALLTYPE          __stdcall
338 #define STDAPIVCALLTYPE         __cdecl
339
340 #define STDAPI                  EXTERN_C HRESULT STDAPICALLTYPE
341 #define STDAPI_(type)           EXTERN_C type STDAPICALLTYPE
342 #define STDMETHODIMP            HRESULT STDMETHODCALLTYPE
343 #define STDMETHODIMP_(type)     type STDMETHODCALLTYPE
344 #define STDAPIV                 EXTERN_C HRESULT STDAPIVCALLTYPE
345 #define STDAPIV_(type)          EXTERN_C type STDAPIVCALLTYPE
346 #define STDMETHODIMPV           HRESULT STDMETHODVCALLTYPE
347 #define STDMETHODIMPV_(type)    type STDMETHODVCALLTYPE
348
349 /* Define the basic types */
350 #ifndef VOID
351 #define VOID void
352 #endif
353 typedef VOID           *PVOID;
354 typedef VOID           *PVOID64;
355 typedef BYTE            BOOLEAN,    *PBOOLEAN;
356 typedef char            CHAR,       *PCHAR;
357 typedef short           SHORT,      *PSHORT;
358 #ifdef _MSC_VER
359 typedef long            LONG,       *PLONG;
360 #else
361 typedef int             LONG,       *PLONG;
362 #endif
363
364 /* Some systems might have wchar_t, but we really need 16 bit characters */
365 #ifdef WINE_UNICODE_NATIVE
366 typedef wchar_t         WCHAR,      *PWCHAR;
367 #else
368 typedef unsigned short  WCHAR,      *PWCHAR;
369 #endif
370
371 /* 'Extended/Wide' numerical types */
372 #ifndef _ULONGLONG_
373 # define _ULONGLONG_
374 # ifdef _MSC_VER
375 typedef signed __int64   LONGLONG,  *PLONGLONG;
376 typedef unsigned __int64 ULONGLONG, *PULONGLONG;
377 # else
378 typedef signed __int64   DECLSPEC_ALIGN(8) LONGLONG,   *PLONGLONG;
379 typedef unsigned __int64 DECLSPEC_ALIGN(8) ULONGLONG,  *PULONGLONG;
380 # endif
381 #endif
382
383 #ifndef _DWORDLONG_
384 # define _DWORDLONG_
385 # ifdef _MSC_VER
386 typedef ULONGLONG DWORDLONG, *PDWORDLONG;
387 # else
388 typedef ULONGLONG   DECLSPEC_ALIGN(8) DWORDLONG,   *PDWORDLONG;
389 # endif
390 #endif
391
392 /* ANSI string types */
393 typedef CHAR           *PCH,        *LPCH;
394 typedef const CHAR     *PCCH,       *LPCCH;
395 typedef CHAR           *PSTR,       *LPSTR,     *NPSTR;
396 typedef const CHAR     *PCSTR,      *LPCSTR;
397
398 /* Unicode string types */
399 typedef WCHAR          *PWCH,       *LPWCH;
400 typedef const WCHAR    *PCWCH,      *LPCWCH;
401 typedef WCHAR          *PWSTR,      *LPWSTR,    *NWPSTR;
402 typedef const WCHAR    *PCWSTR,     *LPCWSTR;
403
404 /* Neutral character and string types */
405 /* These are only defined for Winelib, i.e. _not_ defined for
406  * the emulator. The reason is they depend on the UNICODE
407  * macro which only exists in the user's code.
408  */
409 #ifndef WINE_NO_UNICODE_MACROS
410 # ifdef UNICODE
411 # ifndef _TCHAR_DEFINED
412 typedef WCHAR           TCHAR,      *PTCHAR;
413 # define _TCHAR_DEFINED
414 #endif
415 typedef LPWSTR          PTSTR,       LPTSTR;
416 typedef LPCWSTR         PCTSTR,      LPCTSTR;
417 #  define __TEXT(string) L##string
418 # else  /* UNICODE */
419 # ifndef _TCHAR_DEFINED
420 typedef CHAR            TCHAR,      *PTCHAR;
421 # define _TCHAR_DEFINED
422 # endif
423 typedef LPSTR           PTSTR,       LPTSTR;
424 typedef LPCSTR          PCTSTR,      LPCTSTR;
425 #  define __TEXT(string) string
426 # endif /* UNICODE */
427 # define TEXT(quote) __TEXT(quote)
428 #endif   /* WINE_NO_UNICODE_MACROS */
429
430 /* Misc common WIN32 types */
431 typedef char            CCHAR;
432 typedef DWORD           LCID,       *PLCID;
433 typedef WORD            LANGID;
434 typedef DWORD           EXECUTION_STATE;
435 #ifndef _HRESULT_DEFINED
436 #define _HRESULT_DEFINED
437 typedef LONG            HRESULT;
438 #endif
439
440 /* Handle type */
441
442 typedef void *HANDLE;
443 typedef HANDLE *PHANDLE, *LPHANDLE;
444
445 #ifdef STRICT
446 #define DECLARE_HANDLE(a) typedef struct a##__ { int unused; } *a
447 #else /*STRICT*/
448 #define DECLARE_HANDLE(a) typedef HANDLE a
449 #endif /*STRICT*/
450
451 typedef BYTE  FCHAR;
452 typedef WORD  FSHORT;
453 typedef DWORD FLONG;
454
455 /* Defines */
456
457 #ifndef WIN32_NO_STATUS
458
459 #define STATUS_WAIT_0                    ((DWORD) 0x00000000)
460 #define STATUS_ABANDONED_WAIT_0          ((DWORD) 0x00000080)
461 #define STATUS_USER_APC                  ((DWORD) 0x000000C0)
462 #define STATUS_TIMEOUT                   ((DWORD) 0x00000102)
463 #define STATUS_PENDING                   ((DWORD) 0x00000103)
464 #define STATUS_SEGMENT_NOTIFICATION      ((DWORD) 0x40000005)
465 #define STATUS_GUARD_PAGE_VIOLATION      ((DWORD) 0x80000001)
466 #define STATUS_DATATYPE_MISALIGNMENT     ((DWORD) 0x80000002)
467 #define STATUS_BREAKPOINT                ((DWORD) 0x80000003)
468 #define STATUS_SINGLE_STEP               ((DWORD) 0x80000004)
469 #define STATUS_ACCESS_VIOLATION          ((DWORD) 0xC0000005)
470 #define STATUS_IN_PAGE_ERROR             ((DWORD) 0xC0000006)
471 #define STATUS_INVALID_HANDLE            ((DWORD) 0xC0000008)
472 #define STATUS_NO_MEMORY                 ((DWORD) 0xC0000017)
473 #define STATUS_ILLEGAL_INSTRUCTION       ((DWORD) 0xC000001D)
474 #define STATUS_NONCONTINUABLE_EXCEPTION  ((DWORD) 0xC0000025)
475 #define STATUS_INVALID_DISPOSITION       ((DWORD) 0xC0000026)
476 #define STATUS_ARRAY_BOUNDS_EXCEEDED     ((DWORD) 0xC000008C)
477 #define STATUS_FLOAT_DENORMAL_OPERAND    ((DWORD) 0xC000008D)
478 #define STATUS_FLOAT_DIVIDE_BY_ZERO      ((DWORD) 0xC000008E)
479 #define STATUS_FLOAT_INEXACT_RESULT      ((DWORD) 0xC000008F)
480 #define STATUS_FLOAT_INVALID_OPERATION   ((DWORD) 0xC0000090)
481 #define STATUS_FLOAT_OVERFLOW            ((DWORD) 0xC0000091)
482 #define STATUS_FLOAT_STACK_CHECK         ((DWORD) 0xC0000092)
483 #define STATUS_FLOAT_UNDERFLOW           ((DWORD) 0xC0000093)
484 #define STATUS_INTEGER_DIVIDE_BY_ZERO    ((DWORD) 0xC0000094)
485 #define STATUS_INTEGER_OVERFLOW          ((DWORD) 0xC0000095)
486 #define STATUS_PRIVILEGED_INSTRUCTION    ((DWORD) 0xC0000096)
487 #define STATUS_STACK_OVERFLOW            ((DWORD) 0xC00000FD)
488 #define STATUS_CONTROL_C_EXIT            ((DWORD) 0xC000013A)
489 #define STATUS_FLOAT_MULTIPLE_FAULTS     ((DWORD) 0xC00002B4)
490 #define STATUS_FLOAT_MULTIPLE_TRAPS      ((DWORD) 0xC00002B5)
491 #define STATUS_REG_NAT_CONSUMPTION       ((DWORD) 0xC00002C9)
492 #define STATUS_SXS_EARLY_DEACTIVATION    ((DWORD) 0xC015000F)
493 #define STATUS_SXS_INVALID_DEACTIVATION  ((DWORD) 0xC0150010)
494
495 /* status values for ContinueDebugEvent */
496 #define DBG_EXCEPTION_HANDLED       ((DWORD) 0x00010001)
497 #define DBG_CONTINUE                ((DWORD) 0x00010002)
498 #define DBG_TERMINATE_THREAD        ((DWORD) 0x40010003)
499 #define DBG_TERMINATE_PROCESS       ((DWORD) 0x40010004)
500 #define DBG_CONTROL_C               ((DWORD) 0x40010005)
501 #define DBG_CONTROL_BREAK           ((DWORD) 0x40010008)
502 #define DBG_COMMAND_EXCEPTION       ((DWORD) 0x40010009)
503 #define DBG_EXCEPTION_NOT_HANDLED   ((DWORD) 0x80010001)
504
505 #endif /* WIN32_NO_STATUS */
506
507 /* Argument 1 passed to the DllEntryProc. */
508 #define DLL_PROCESS_DETACH      0       /* detach process (unload library) */
509 #define DLL_PROCESS_ATTACH      1       /* attach process (load library) */
510 #define DLL_THREAD_ATTACH       2       /* attach new thread */
511 #define DLL_THREAD_DETACH       3       /* detach thread */
512 #ifdef __WINESRC__
513 #define DLL_WINE_PREATTACH      8       /* called before process attach for Wine builtins */
514 #endif
515
516 /* u.x.wProcessorArchitecture (NT) */
517 #define PROCESSOR_ARCHITECTURE_INTEL    0
518 #define PROCESSOR_ARCHITECTURE_MIPS     1
519 #define PROCESSOR_ARCHITECTURE_ALPHA    2
520 #define PROCESSOR_ARCHITECTURE_PPC      3
521 #define PROCESSOR_ARCHITECTURE_SHX      4
522 #define PROCESSOR_ARCHITECTURE_ARM      5
523 #define PROCESSOR_ARCHITECTURE_IA64     6
524 #define PROCESSOR_ARCHITECTURE_ALPHA64  7
525 #define PROCESSOR_ARCHITECTURE_MSIL     8
526 #define PROCESSOR_ARCHITECTURE_AMD64    9
527 #define PROCESSOR_ARCHITECTURE_IA32_ON_WIN64    10
528 #define PROCESSOR_ARCHITECTURE_UNKNOWN  0xFFFF
529
530 /* Wine extension */
531 #define PROCESSOR_ARCHITECTURE_SPARC    20
532
533 /* dwProcessorType */
534 #define PROCESSOR_INTEL_386      386
535 #define PROCESSOR_INTEL_486      486
536 #define PROCESSOR_INTEL_PENTIUM  586
537 #define PROCESSOR_INTEL_860      860
538 #define PROCESSOR_INTEL_IA64     2200
539 #define PROCESSOR_AMD_X8664      8664
540 #define PROCESSOR_MIPS_R2000     2000
541 #define PROCESSOR_MIPS_R3000     3000
542 #define PROCESSOR_MIPS_R4000     4000
543 #define PROCESSOR_ALPHA_21064    21064
544 #define PROCESSOR_PPC_601        601
545 #define PROCESSOR_PPC_603        603
546 #define PROCESSOR_PPC_604        604
547 #define PROCESSOR_PPC_620        620
548 #define PROCESSOR_HITACHI_SH3    10003
549 #define PROCESSOR_HITACHI_SH3E   10004
550 #define PROCESSOR_HITACHI_SH4    10005
551 #define PROCESSOR_MOTOROLA_821   821
552 #define PROCESSOR_SHx_SH3        103
553 #define PROCESSOR_SHx_SH4        104
554 #define PROCESSOR_STRONGARM      2577
555 #define PROCESSOR_ARM720         1824    /* 0x720 */
556 #define PROCESSOR_ARM820         2080    /* 0x820 */
557 #define PROCESSOR_ARM920         2336    /* 0x920 */
558 #define PROCESSOR_ARM_7TDMI      70001
559
560 #ifdef _WIN64
561 #define MAXIMUM_PROCESSORS       64
562 #else
563 #define MAXIMUM_PROCESSORS       32
564 #endif
565
566 typedef struct _MEMORY_BASIC_INFORMATION
567 {
568     LPVOID   BaseAddress;
569     LPVOID   AllocationBase;
570     DWORD    AllocationProtect;
571     SIZE_T   RegionSize;
572     DWORD    State;
573     DWORD    Protect;
574     DWORD    Type;
575 } MEMORY_BASIC_INFORMATION, *PMEMORY_BASIC_INFORMATION;
576
577 #define PAGE_NOACCESS           0x01
578 #define PAGE_READONLY           0x02
579 #define PAGE_READWRITE          0x04
580 #define PAGE_WRITECOPY          0x08
581 #define PAGE_EXECUTE            0x10
582 #define PAGE_EXECUTE_READ       0x20
583 #define PAGE_EXECUTE_READWRITE  0x40
584 #define PAGE_EXECUTE_WRITECOPY  0x80
585 #define PAGE_GUARD              0x100
586 #define PAGE_NOCACHE            0x200
587 #define PAGE_WRITECOMBINE       0x400
588
589 #define MEM_COMMIT              0x00001000
590 #define MEM_RESERVE             0x00002000
591 #define MEM_DECOMMIT            0x00004000
592 #define MEM_RELEASE             0x00008000
593 #define MEM_FREE                0x00010000
594 #define MEM_PRIVATE             0x00020000
595 #define MEM_MAPPED              0x00040000
596 #define MEM_RESET               0x00080000
597 #define MEM_TOP_DOWN            0x00100000
598 #define MEM_WRITE_WATCH         0x00200000
599 #define MEM_PHYSICAL            0x00400000
600 #define MEM_LARGE_PAGES         0x20000000
601 #define MEM_4MB_PAGES           0x80000000
602
603 #define SEC_FILE                0x00800000
604 #define SEC_IMAGE               0x01000000
605 #define SEC_RESERVE             0x04000000
606 #define SEC_COMMIT              0x08000000
607 #define SEC_NOCACHE             0x10000000
608 #define SEC_LARGE_PAGES         0x80000000
609 #define MEM_IMAGE               SEC_IMAGE
610
611 #define WRITE_WATCH_FLAG_RESET  0x00000001
612
613
614 #define MINCHAR       0x80
615 #define MAXCHAR       0x7f
616 #define MINSHORT      0x8000
617 #define MAXSHORT      0x7fff
618 #define MINLONG       0x80000000
619 #define MAXLONG       0x7fffffff
620 #define MAXBYTE       0xff
621 #define MAXWORD       0xffff
622 #define MAXDWORD      0xffffffff
623
624 #define UNICODE_STRING_MAX_CHARS 32767
625
626 #define FIELD_OFFSET(type, field) \
627   ((LONG)(INT_PTR)&(((type *)0)->field))
628
629 #define CONTAINING_RECORD(address, type, field) \
630   ((type *)((PCHAR)(address) - (PCHAR)(&((type *)0)->field)))
631
632 /* Types */
633
634 typedef struct _LIST_ENTRY {
635   struct _LIST_ENTRY *Flink;
636   struct _LIST_ENTRY *Blink;
637 } LIST_ENTRY, *PLIST_ENTRY, * RESTRICTED_POINTER PRLIST_ENTRY;
638
639 typedef struct _SINGLE_LIST_ENTRY {
640   struct _SINGLE_LIST_ENTRY *Next;
641 } SINGLE_LIST_ENTRY, *PSINGLE_LIST_ENTRY;
642
643 #ifdef _WIN64
644
645 typedef struct DECLSPEC_ALIGN(16) _SLIST_ENTRY *PSLIST_ENTRY;
646 typedef struct DECLSPEC_ALIGN(16) _SLIST_ENTRY {
647     PSLIST_ENTRY Next;
648 } SLIST_ENTRY;
649
650 typedef union DECLSPEC_ALIGN(16) _SLIST_HEADER {
651     struct {
652         ULONGLONG Alignment;
653         ULONGLONG Region;
654     } DUMMYSTRUCTNAME;
655     struct {
656         ULONGLONG Depth:16;
657         ULONGLONG Sequence:9;
658         ULONGLONG NextEntry:39;
659         ULONGLONG HeaderType:1;
660         ULONGLONG Init:1;
661         ULONGLONG Reserved:59;
662         ULONGLONG Region:3;
663     } Header8;
664     struct {
665         ULONGLONG Depth:16;
666         ULONGLONG Sequence:48;
667         ULONGLONG HeaderType:1;
668         ULONGLONG Init:1;
669         ULONGLONG Reserved:2;
670         ULONGLONG NextEntry:60;
671     } Header16;
672 } SLIST_HEADER, *PSLIST_HEADER;
673
674 #else
675
676 #undef SLIST_ENTRY /* for Mac OS */
677 #define SLIST_ENTRY SINGLE_LIST_ENTRY
678 #define _SLIST_ENTRY _SINGLE_LIST_ENTRY
679 #define PSLIST_ENTRY PSINGLE_LIST_ENTRY
680
681 typedef union _SLIST_HEADER {
682     ULONGLONG Alignment;
683     struct {
684         SLIST_ENTRY Next;
685         WORD Depth;
686         WORD Sequence;
687     } DUMMYSTRUCTNAME;
688 } SLIST_HEADER, *PSLIST_HEADER;
689
690 #endif
691
692 NTSYSAPI PSLIST_ENTRY WINAPI RtlFirstEntrySList(const SLIST_HEADER*);
693 NTSYSAPI VOID         WINAPI RtlInitializeSListHead(PSLIST_HEADER);
694 NTSYSAPI PSLIST_ENTRY WINAPI RtlInterlockedFlushSList(PSLIST_HEADER);
695 NTSYSAPI PSLIST_ENTRY WINAPI RtlInterlockedPopEntrySList(PSLIST_HEADER);
696 NTSYSAPI PSLIST_ENTRY WINAPI RtlInterlockedPushEntrySList(PSLIST_HEADER, PSLIST_ENTRY);
697 NTSYSAPI WORD         WINAPI RtlQueryDepthSList(PSLIST_HEADER);
698
699
700 /* Heap flags */
701
702 #define HEAP_NO_SERIALIZE               0x00000001
703 #define HEAP_GROWABLE                   0x00000002
704 #define HEAP_GENERATE_EXCEPTIONS        0x00000004
705 #define HEAP_ZERO_MEMORY                0x00000008
706 #define HEAP_REALLOC_IN_PLACE_ONLY      0x00000010
707 #define HEAP_TAIL_CHECKING_ENABLED      0x00000020
708 #define HEAP_FREE_CHECKING_ENABLED      0x00000040
709 #define HEAP_DISABLE_COALESCE_ON_FREE   0x00000080
710 #define HEAP_CREATE_ALIGN_16            0x00010000
711 #define HEAP_CREATE_ENABLE_TRACING      0x00020000
712 #define HEAP_CREATE_ENABLE_EXECUTE      0x00040000
713
714 /* This flag allows it to create heaps shared by all processes under win95,
715    FIXME: correct name */
716 #define HEAP_SHARED                     0x04000000
717
718 typedef enum _HEAP_INFORMATION_CLASS {
719     HeapCompatibilityInformation,
720 } HEAP_INFORMATION_CLASS;
721
722 /* Processor feature flags.  */
723 #define PF_FLOATING_POINT_PRECISION_ERRATA      0
724 #define PF_FLOATING_POINT_EMULATED              1
725 #define PF_COMPARE_EXCHANGE_DOUBLE              2
726 #define PF_MMX_INSTRUCTIONS_AVAILABLE           3
727 #define PF_PPC_MOVEMEM_64BIT_OK                 4
728 #define PF_ALPHA_BYTE_INSTRUCTIONS              5
729 #define PF_XMMI_INSTRUCTIONS_AVAILABLE          6
730 #define PF_3DNOW_INSTRUCTIONS_AVAILABLE         7
731 #define PF_RDTSC_INSTRUCTION_AVAILABLE          8
732 #define PF_PAE_ENABLED                          9
733 #define PF_XMMI64_INSTRUCTIONS_AVAILABLE        10
734 #define PF_SSE_DAZ_MODE_AVAILABLE               11
735 #define PF_NX_ENABLED                           12
736 #define PF_SSE3_INSTRUCTIONS_AVAILABLE          13
737 #define PF_COMPARE_EXCHANGE128                  14
738 #define PF_COMPARE64_EXCHANGE128                15
739 #define PF_CHANNELS_ENABLED                     16
740
741
742 /* Execution state flags */
743 #define ES_SYSTEM_REQUIRED    0x00000001
744 #define ES_DISPLAY_REQUIRED   0x00000002
745 #define ES_USER_PRESENT       0x00000004
746 #define ES_CONTINUOUS         0x80000000
747
748 /* The Win32 register context */
749
750 /* i386 context definitions */
751 #ifdef __i386__
752
753 #define SIZE_OF_80387_REGISTERS      80
754
755 typedef struct _FLOATING_SAVE_AREA
756 {
757     DWORD   ControlWord;
758     DWORD   StatusWord;
759     DWORD   TagWord;
760     DWORD   ErrorOffset;
761     DWORD   ErrorSelector;
762     DWORD   DataOffset;
763     DWORD   DataSelector;
764     BYTE    RegisterArea[SIZE_OF_80387_REGISTERS];
765     DWORD   Cr0NpxState;
766 } FLOATING_SAVE_AREA, *PFLOATING_SAVE_AREA;
767
768 #define MAXIMUM_SUPPORTED_EXTENSION     512
769
770 typedef struct _CONTEXT
771 {
772     DWORD   ContextFlags;
773
774     /* These are selected by CONTEXT_DEBUG_REGISTERS */
775     DWORD   Dr0;
776     DWORD   Dr1;
777     DWORD   Dr2;
778     DWORD   Dr3;
779     DWORD   Dr6;
780     DWORD   Dr7;
781
782     /* These are selected by CONTEXT_FLOATING_POINT */
783     FLOATING_SAVE_AREA FloatSave;
784
785     /* These are selected by CONTEXT_SEGMENTS */
786     DWORD   SegGs;
787     DWORD   SegFs;
788     DWORD   SegEs;
789     DWORD   SegDs;
790
791     /* These are selected by CONTEXT_INTEGER */
792     DWORD   Edi;
793     DWORD   Esi;
794     DWORD   Ebx;
795     DWORD   Edx;
796     DWORD   Ecx;
797     DWORD   Eax;
798
799     /* These are selected by CONTEXT_CONTROL */
800     DWORD   Ebp;
801     DWORD   Eip;
802     DWORD   SegCs;
803     DWORD   EFlags;
804     DWORD   Esp;
805     DWORD   SegSs;
806
807     BYTE    ExtendedRegisters[MAXIMUM_SUPPORTED_EXTENSION];
808 } CONTEXT;
809
810 #define CONTEXT_X86       0x00010000
811 #define CONTEXT_i386      CONTEXT_X86
812 #define CONTEXT_i486      CONTEXT_X86
813
814 #define CONTEXT_CONTROL   (CONTEXT_i386 | 0x0001) /* SS:SP, CS:IP, FLAGS, BP */
815 #define CONTEXT_INTEGER   (CONTEXT_i386 | 0x0002) /* AX, BX, CX, DX, SI, DI */
816 #define CONTEXT_SEGMENTS  (CONTEXT_i386 | 0x0004) /* DS, ES, FS, GS */
817 #define CONTEXT_FLOATING_POINT  (CONTEXT_i386 | 0x0008L) /* 387 state */
818 #define CONTEXT_DEBUG_REGISTERS (CONTEXT_i386 | 0x0010L) /* DB 0-3,6,7 */
819 #define CONTEXT_EXTENDED_REGISTERS (CONTEXT_i386 | 0x0020L)
820 #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS)
821 #define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS | \
822         CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS | CONTEXT_EXTENDED_REGISTERS)
823
824 #define EXCEPTION_READ_FAULT    0
825 #define EXCEPTION_WRITE_FAULT   1
826 #define EXCEPTION_EXECUTE_FAULT 8
827
828 #endif  /* __i386__ */
829
830 typedef struct _LDT_ENTRY {
831     WORD        LimitLow;
832     WORD        BaseLow;
833     union {
834         struct {
835             BYTE    BaseMid;
836             BYTE    Flags1;
837             BYTE    Flags2;
838             BYTE    BaseHi;
839         } Bytes;
840         struct {
841             unsigned    BaseMid: 8;
842             unsigned    Type : 5;
843             unsigned    Dpl : 2;
844             unsigned    Pres : 1;
845             unsigned    LimitHi : 4;
846             unsigned    Sys : 1;
847             unsigned    Reserved_0 : 1;
848             unsigned    Default_Big : 1;
849             unsigned    Granularity : 1;
850             unsigned    BaseHi : 8;
851         } Bits;
852     } HighWord;
853 } LDT_ENTRY, *PLDT_ENTRY;
854
855 /* x86-64 context definitions */
856 #if defined(__x86_64__)
857
858 #define CONTEXT_AMD64   0x00100000
859
860 #define CONTEXT_CONTROL   (CONTEXT_AMD64 | 0x0001)
861 #define CONTEXT_INTEGER   (CONTEXT_AMD64 | 0x0002)
862 #define CONTEXT_SEGMENTS  (CONTEXT_AMD64 | 0x0004)
863 #define CONTEXT_FLOATING_POINT  (CONTEXT_AMD64 | 0x0008L)
864 #define CONTEXT_DEBUG_REGISTERS (CONTEXT_AMD64 | 0x0010L)
865 #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT)
866 #define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS | CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS)
867
868 #define EXCEPTION_READ_FAULT    0
869 #define EXCEPTION_WRITE_FAULT   1
870 #define EXCEPTION_EXECUTE_FAULT 8
871
872 typedef struct DECLSPEC_ALIGN(16) _M128A {
873     ULONGLONG Low;
874     LONGLONG High;
875 } M128A, *PM128A;
876
877 typedef struct _XMM_SAVE_AREA32 {
878     WORD ControlWord;        /* 000 */
879     WORD StatusWord;         /* 002 */
880     BYTE TagWord;            /* 004 */
881     BYTE Reserved1;          /* 005 */
882     WORD ErrorOpcode;        /* 006 */
883     DWORD ErrorOffset;       /* 008 */
884     WORD ErrorSelector;      /* 00c */
885     WORD Reserved2;          /* 00e */
886     DWORD DataOffset;        /* 010 */
887     WORD DataSelector;       /* 014 */
888     WORD Reserved3;          /* 016 */
889     DWORD MxCsr;             /* 018 */
890     DWORD MxCsr_Mask;        /* 01c */
891     M128A FloatRegisters[8]; /* 020 */
892     M128A XmmRegisters[16];  /* 0a0 */
893     BYTE Reserved4[96];      /* 1a0 */
894 } XMM_SAVE_AREA32, *PXMM_SAVE_AREA32;
895
896 typedef struct DECLSPEC_ALIGN(16) _CONTEXT {
897     DWORD64 P1Home;          /* 000 */
898     DWORD64 P2Home;          /* 008 */
899     DWORD64 P3Home;          /* 010 */
900     DWORD64 P4Home;          /* 018 */
901     DWORD64 P5Home;          /* 020 */
902     DWORD64 P6Home;          /* 028 */
903
904     /* Control flags */
905     DWORD ContextFlags;      /* 030 */
906     DWORD MxCsr;             /* 034 */
907
908     /* Segment */
909     WORD SegCs;              /* 038 */
910     WORD SegDs;              /* 03a */
911     WORD SegEs;              /* 03c */
912     WORD SegFs;              /* 03e */
913     WORD SegGs;              /* 040 */
914     WORD SegSs;              /* 042 */
915     DWORD EFlags;            /* 044 */
916
917     /* Debug */
918     DWORD64 Dr0;             /* 048 */
919     DWORD64 Dr1;             /* 050 */
920     DWORD64 Dr2;             /* 058 */
921     DWORD64 Dr3;             /* 060 */
922     DWORD64 Dr6;             /* 068 */
923     DWORD64 Dr7;             /* 070 */
924
925     /* Integer */
926     DWORD64 Rax;             /* 078 */
927     DWORD64 Rcx;             /* 080 */
928     DWORD64 Rdx;             /* 088 */
929     DWORD64 Rbx;             /* 090 */
930     DWORD64 Rsp;             /* 098 */
931     DWORD64 Rbp;             /* 0a0 */
932     DWORD64 Rsi;             /* 0a8 */
933     DWORD64 Rdi;             /* 0b0 */
934     DWORD64 R8;              /* 0b8 */
935     DWORD64 R9;              /* 0c0 */
936     DWORD64 R10;             /* 0c8 */
937     DWORD64 R11;             /* 0d0 */
938     DWORD64 R12;             /* 0d8 */
939     DWORD64 R13;             /* 0e0 */
940     DWORD64 R14;             /* 0e8 */
941     DWORD64 R15;             /* 0f0 */
942
943     /* Counter */
944     DWORD64 Rip;             /* 0f8 */
945
946     /* Floating point */
947     union {
948         XMM_SAVE_AREA32 FltSave;  /* 100 */
949         struct {
950             M128A Header[2];      /* 100 */
951             M128A Legacy[8];      /* 120 */
952             M128A Xmm0;           /* 1a0 */
953             M128A Xmm1;           /* 1b0 */
954             M128A Xmm2;           /* 1c0 */
955             M128A Xmm3;           /* 1d0 */
956             M128A Xmm4;           /* 1e0 */
957             M128A Xmm5;           /* 1f0 */
958             M128A Xmm6;           /* 200 */
959             M128A Xmm7;           /* 210 */
960             M128A Xmm8;           /* 220 */
961             M128A Xmm9;           /* 230 */
962             M128A Xmm10;          /* 240 */
963             M128A Xmm11;          /* 250 */
964             M128A Xmm12;          /* 260 */
965             M128A Xmm13;          /* 270 */
966             M128A Xmm14;          /* 280 */
967             M128A Xmm15;          /* 290 */
968         } DUMMYSTRUCTNAME;
969     } DUMMYUNIONNAME;
970
971     /* Vector */
972     M128A VectorRegister[26];     /* 300 */
973     DWORD64 VectorControl;        /* 4a0 */
974
975     /* Debug control */
976     DWORD64 DebugControl;         /* 4a8 */
977     DWORD64 LastBranchToRip;      /* 4b0 */
978     DWORD64 LastBranchFromRip;    /* 4b8 */
979     DWORD64 LastExceptionToRip;   /* 4c0 */
980     DWORD64 LastExceptionFromRip; /* 4c8 */
981 } CONTEXT;
982
983 typedef struct _RUNTIME_FUNCTION
984 {
985     DWORD BeginAddress;
986     DWORD EndAddress;
987     DWORD UnwindData;
988 } RUNTIME_FUNCTION, *PRUNTIME_FUNCTION;
989
990 #define UNWIND_HISTORY_TABLE_SIZE 12
991
992 typedef struct _UNWIND_HISTORY_TABLE_ENTRY
993 {
994     ULONG64 ImageBase;
995     PRUNTIME_FUNCTION FunctionEntry;
996 } UNWIND_HISTORY_TABLE_ENTRY, *PUNWIND_HISTORY_TABLE_ENTRY;
997
998 #define UNWIND_HISTORY_TABLE_NONE 0
999 #define UNWIND_HISTORY_TABLE_GLOBAL 1
1000 #define UNWIND_HISTORY_TABLE_LOCAL 2
1001
1002 typedef struct _UNWIND_HISTORY_TABLE
1003 {
1004     ULONG Count;
1005     UCHAR Search;
1006     ULONG64 LowAddress;
1007     ULONG64 HighAddress;
1008     UNWIND_HISTORY_TABLE_ENTRY Entry[UNWIND_HISTORY_TABLE_SIZE];
1009 } UNWIND_HISTORY_TABLE, *PUNWIND_HISTORY_TABLE;
1010
1011 typedef struct _KNONVOLATILE_CONTEXT_POINTERS
1012 {
1013     union
1014     {
1015         PM128A FloatingContext[16];
1016         struct
1017         {
1018             PM128A Xmm0;
1019             PM128A Xmm1;
1020             PM128A Xmm2;
1021             PM128A Xmm3;
1022             PM128A Xmm4;
1023             PM128A Xmm5;
1024             PM128A Xmm6;
1025             PM128A Xmm7;
1026             PM128A Xmm8;
1027             PM128A Xmm9;
1028             PM128A Xmm10;
1029             PM128A Xmm11;
1030             PM128A Xmm12;
1031             PM128A Xmm13;
1032             PM128A Xmm14;
1033             PM128A Xmm15;
1034         } DUMMYSTRUCTNAME1;
1035     } DUMMYUNIONNAME1;
1036
1037     union
1038     {
1039         PULONG64 IntegerContext[16];
1040         struct
1041         {
1042             PULONG64 Rax;
1043             PULONG64 Rcx;
1044             PULONG64 Rdx;
1045             PULONG64 Rbx;
1046             PULONG64 Rsp;
1047             PULONG64 Rbp;
1048             PULONG64 Rsi;
1049             PULONG64 Rdi;
1050             PULONG64 R8;
1051             PULONG64 R9;
1052             PULONG64 R10;
1053             PULONG64 R11;
1054             PULONG64 R12;
1055             PULONG64 R13;
1056             PULONG64 R14;
1057             PULONG64 R15;
1058         } DUMMYSTRUCTNAME2;
1059     } DUMMYUNIONNAME2;
1060 } KNONVOLATILE_CONTEXT_POINTERS, *PKNONVOLATILE_CONTEXT_POINTERS;
1061
1062 BOOLEAN CDECL            RtlAddFunctionTable(RUNTIME_FUNCTION*,DWORD,DWORD64);
1063 BOOLEAN CDECL            RtlDeleteFunctionTable(RUNTIME_FUNCTION*);
1064 PRUNTIME_FUNCTION WINAPI RtlLookupFunctionEntry(DWORD64,DWORD64*,UNWIND_HISTORY_TABLE*);
1065 PVOID WINAPI             RtlVirtualUnwind(ULONG,ULONG64,ULONG64,RUNTIME_FUNCTION*,CONTEXT*,PVOID*,ULONG64*,KNONVOLATILE_CONTEXT_POINTERS*);
1066
1067 #define UNW_FLAG_NHANDLER  0
1068 #define UNW_FLAG_EHANDLER  1
1069 #define UNW_FLAG_UHANDLER  2
1070 #define UNW_FLAG_CHAININFO 4
1071
1072 #endif /* __x86_64__ */
1073
1074 /* IA64 context definitions */
1075 #ifdef __ia64__
1076
1077 #define CONTEXT_IA64                  0x00080000
1078 #define CONTEXT_CONTROL               (CONTEXT_IA64 | 0x00000001)
1079 #define CONTEXT_LOWER_FLOATING_POINT  (CONTEXT_IA64 | 0x00000002)
1080 #define CONTEXT_HIGHER_FLOATING_POINT (CONTEXT_IA64 | 0x00000004)
1081 #define CONTEXT_INTEGER               (CONTEXT_IA64 | 0x00000008)
1082 #define CONTEXT_DEBUG                 (CONTEXT_IA64 | 0x00000010)
1083 #define CONTEXT_IA32_CONTROL          (CONTEXT_IA64 | 0x00000020)
1084 #define CONTEXT_FLOATING_POINT        (CONTEXT_LOWER_FLOATING_POINT | CONTEXT_HIGHER_FLOATING_POINT)
1085 #define CONTEXT_FULL                  (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER | CONTEXT_IA32_CONTROL)
1086 #define CONTEXT_ALL                   (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER | CONTEXT_DEBUG | CONTEXT_IA32_CONTROL)
1087
1088 #define CONTEXT_EXCEPTION_ACTIVE      0x8000000
1089 #define CONTEXT_SERVICE_ACTIVE        0x10000000
1090 #define CONTEXT_EXCEPTION_REQUEST     0x40000000
1091 #define CONTEXT_EXCEPTION_REPORTING   0x80000000
1092
1093 typedef struct _CONTEXT
1094 {
1095     DWORD ContextFlags;
1096     DWORD Fill1[3];
1097     ULONGLONG DbI0;
1098     ULONGLONG DbI1;
1099     ULONGLONG DbI2;
1100     ULONGLONG DbI3;
1101     ULONGLONG DbI4;
1102     ULONGLONG DbI5;
1103     ULONGLONG DbI6;
1104     ULONGLONG DbI7;
1105     ULONGLONG DbD0;
1106     ULONGLONG DbD1;
1107     ULONGLONG DbD2;
1108     ULONGLONG DbD3;
1109     ULONGLONG DbD4;
1110     ULONGLONG DbD5;
1111     ULONGLONG DbD6;
1112     ULONGLONG DbD7;
1113     FLOAT128 FltS0;
1114     FLOAT128 FltS1;
1115     FLOAT128 FltS2;
1116     FLOAT128 FltS3;
1117     FLOAT128 FltT0;
1118     FLOAT128 FltT1;
1119     FLOAT128 FltT2;
1120     FLOAT128 FltT3;
1121     FLOAT128 FltT4;
1122     FLOAT128 FltT5;
1123     FLOAT128 FltT6;
1124     FLOAT128 FltT7;
1125     FLOAT128 FltT8;
1126     FLOAT128 FltT9;
1127     FLOAT128 FltS4;
1128     FLOAT128 FltS5;
1129     FLOAT128 FltS6;
1130     FLOAT128 FltS7;
1131     FLOAT128 FltS8;
1132     FLOAT128 FltS9;
1133     FLOAT128 FltS10;
1134     FLOAT128 FltS11;
1135     FLOAT128 FltS12;
1136     FLOAT128 FltS13;
1137     FLOAT128 FltS14;
1138     FLOAT128 FltS15;
1139     FLOAT128 FltS16;
1140     FLOAT128 FltS17;
1141     FLOAT128 FltS18;
1142     FLOAT128 FltS19;
1143     FLOAT128 FltF32;
1144     FLOAT128 FltF33;
1145     FLOAT128 FltF34;
1146     FLOAT128 FltF35;
1147     FLOAT128 FltF36;
1148     FLOAT128 FltF37;
1149     FLOAT128 FltF38;
1150     FLOAT128 FltF39;
1151     FLOAT128 FltF40;
1152     FLOAT128 FltF41;
1153     FLOAT128 FltF42;
1154     FLOAT128 FltF43;
1155     FLOAT128 FltF44;
1156     FLOAT128 FltF45;
1157     FLOAT128 FltF46;
1158     FLOAT128 FltF47;
1159     FLOAT128 FltF48;
1160     FLOAT128 FltF49;
1161     FLOAT128 FltF50;
1162     FLOAT128 FltF51;
1163     FLOAT128 FltF52;
1164     FLOAT128 FltF53;
1165     FLOAT128 FltF54;
1166     FLOAT128 FltF55;
1167     FLOAT128 FltF56;
1168     FLOAT128 FltF57;
1169     FLOAT128 FltF58;
1170     FLOAT128 FltF59;
1171     FLOAT128 FltF60;
1172     FLOAT128 FltF61;
1173     FLOAT128 FltF62;
1174     FLOAT128 FltF63;
1175     FLOAT128 FltF64;
1176     FLOAT128 FltF65;
1177     FLOAT128 FltF66;
1178     FLOAT128 FltF67;
1179     FLOAT128 FltF68;
1180     FLOAT128 FltF69;
1181     FLOAT128 FltF70;
1182     FLOAT128 FltF71;
1183     FLOAT128 FltF72;
1184     FLOAT128 FltF73;
1185     FLOAT128 FltF74;
1186     FLOAT128 FltF75;
1187     FLOAT128 FltF76;
1188     FLOAT128 FltF77;
1189     FLOAT128 FltF78;
1190     FLOAT128 FltF79;
1191     FLOAT128 FltF80;
1192     FLOAT128 FltF81;
1193     FLOAT128 FltF82;
1194     FLOAT128 FltF83;
1195     FLOAT128 FltF84;
1196     FLOAT128 FltF85;
1197     FLOAT128 FltF86;
1198     FLOAT128 FltF87;
1199     FLOAT128 FltF88;
1200     FLOAT128 FltF89;
1201     FLOAT128 FltF90;
1202     FLOAT128 FltF91;
1203     FLOAT128 FltF92;
1204     FLOAT128 FltF93;
1205     FLOAT128 FltF94;
1206     FLOAT128 FltF95;
1207     FLOAT128 FltF96;
1208     FLOAT128 FltF97;
1209     FLOAT128 FltF98;
1210     FLOAT128 FltF99;
1211     FLOAT128 FltF100;
1212     FLOAT128 FltF101;
1213     FLOAT128 FltF102;
1214     FLOAT128 FltF103;
1215     FLOAT128 FltF104;
1216     FLOAT128 FltF105;
1217     FLOAT128 FltF106;
1218     FLOAT128 FltF107;
1219     FLOAT128 FltF108;
1220     FLOAT128 FltF109;
1221     FLOAT128 FltF110;
1222     FLOAT128 FltF111;
1223     FLOAT128 FltF112;
1224     FLOAT128 FltF113;
1225     FLOAT128 FltF114;
1226     FLOAT128 FltF115;
1227     FLOAT128 FltF116;
1228     FLOAT128 FltF117;
1229     FLOAT128 FltF118;
1230     FLOAT128 FltF119;
1231     FLOAT128 FltF120;
1232     FLOAT128 FltF121;
1233     FLOAT128 FltF122;
1234     FLOAT128 FltF123;
1235     FLOAT128 FltF124;
1236     FLOAT128 FltF125;
1237     FLOAT128 FltF126;
1238     FLOAT128 FltF127;
1239     ULONGLONG StFPSR;
1240     ULONGLONG IntGp;
1241     ULONGLONG IntT0;
1242     ULONGLONG IntT1;
1243     ULONGLONG IntS0;
1244     ULONGLONG IntS1;
1245     ULONGLONG IntS2;
1246     ULONGLONG IntS3;
1247     ULONGLONG IntV0;
1248     ULONGLONG IntT2;
1249     ULONGLONG IntT3;
1250     ULONGLONG IntT4;
1251     ULONGLONG IntSp;
1252     ULONGLONG IntTeb;
1253     ULONGLONG IntT5;
1254     ULONGLONG IntT6;
1255     ULONGLONG IntT7;
1256     ULONGLONG IntT8;
1257     ULONGLONG IntT9;
1258     ULONGLONG IntT10;
1259     ULONGLONG IntT11;
1260     ULONGLONG IntT12;
1261     ULONGLONG IntT13;
1262     ULONGLONG IntT14;
1263     ULONGLONG IntT15;
1264     ULONGLONG IntT16;
1265     ULONGLONG IntT17;
1266     ULONGLONG IntT18;
1267     ULONGLONG IntT19;
1268     ULONGLONG IntT20;
1269     ULONGLONG IntT21;
1270     ULONGLONG IntT22;
1271     ULONGLONG IntNats;
1272     ULONGLONG Preds;
1273     ULONGLONG BrRp;
1274     ULONGLONG BrS0;
1275     ULONGLONG BrS1;
1276     ULONGLONG BrS2;
1277     ULONGLONG BrS3;
1278     ULONGLONG BrS4;
1279     ULONGLONG BrT0;
1280     ULONGLONG BrT1;
1281     ULONGLONG ApUNAT;
1282     ULONGLONG ApLC;
1283     ULONGLONG ApEC;
1284     ULONGLONG ApCCV;
1285     ULONGLONG ApDCR;
1286     ULONGLONG RsPFS;
1287     ULONGLONG RsBSP;
1288     ULONGLONG RsBSPSTORE;
1289     ULONGLONG RsRSC;
1290     ULONGLONG RsRNAT;
1291     ULONGLONG StIPSR;
1292     ULONGLONG StIIP;
1293     ULONGLONG StIFS;
1294     ULONGLONG StFCR;
1295     ULONGLONG Eflag;
1296     ULONGLONG SegCSD;
1297     ULONGLONG SegSSD;
1298     ULONGLONG Cflag;
1299     ULONGLONG StFSR;
1300     ULONGLONG StFIR;
1301     ULONGLONG StFDR;
1302     ULONGLONG UNUSEDPACK;
1303 } CONTEXT, *PCONTEXT;
1304
1305 typedef struct _RUNTIME_FUNCTION
1306 {
1307     ULONG BeginAddress;
1308     ULONG EndAddress;
1309     ULONG UnwindInfoAddress;
1310 } RUNTIME_FUNCTION, *PRUNTIME_FUNCTION;
1311
1312 typedef struct _FRAME_POINTERS {
1313   ULONGLONG MemoryStackFp;
1314   ULONGLONG BackingStoreFp;
1315 } FRAME_POINTERS, *PFRAME_POINTERS;
1316
1317 #define UNWIND_HISTORY_TABLE_SIZE 12
1318
1319 typedef struct _UNWIND_HISTORY_TABLE_ENTRY {
1320   ULONG64 ImageBase;
1321   ULONG64 Gp;
1322   PRUNTIME_FUNCTION FunctionEntry;
1323 } UNWIND_HISTORY_TABLE_ENTRY, *PUNWIND_HISTORY_TABLE_ENTRY;
1324
1325 typedef struct _UNWIND_HISTORY_TABLE {
1326   ULONG Count;
1327   UCHAR Search;
1328   ULONG64 LowAddress;
1329   ULONG64 HighAddress;
1330   UNWIND_HISTORY_TABLE_ENTRY Entry[UNWIND_HISTORY_TABLE_SIZE];
1331 } UNWIND_HISTORY_TABLE, *PUNWIND_HISTORY_TABLE;
1332
1333 typedef struct _KNONVOLATILE_CONTEXT_POINTERS
1334 {
1335     PFLOAT128  FltS0;
1336     PFLOAT128  FltS1;
1337     PFLOAT128  FltS2;
1338     PFLOAT128  FltS3;
1339     PFLOAT128  HighFloatingContext[10];
1340     PFLOAT128  FltS4;
1341     PFLOAT128  FltS5;
1342     PFLOAT128  FltS6;
1343     PFLOAT128  FltS7;
1344     PFLOAT128  FltS8;
1345     PFLOAT128  FltS9;
1346     PFLOAT128  FltS10;
1347     PFLOAT128  FltS11;
1348     PFLOAT128  FltS12;
1349     PFLOAT128  FltS13;
1350     PFLOAT128  FltS14;
1351     PFLOAT128  FltS15;
1352     PFLOAT128  FltS16;
1353     PFLOAT128  FltS17;
1354     PFLOAT128  FltS18;
1355     PFLOAT128  FltS19;
1356     PULONGLONG IntS0;
1357     PULONGLONG IntS1;
1358     PULONGLONG IntS2;
1359     PULONGLONG IntS3;
1360     PULONGLONG IntSp;
1361     PULONGLONG IntS0Nat;
1362     PULONGLONG IntS1Nat;
1363     PULONGLONG IntS2Nat;
1364     PULONGLONG IntS3Nat;
1365     PULONGLONG IntSpNat;
1366     PULONGLONG Preds;
1367     PULONGLONG BrRp;
1368     PULONGLONG BrS0;
1369     PULONGLONG BrS1;
1370     PULONGLONG BrS2;
1371     PULONGLONG BrS3;
1372     PULONGLONG BrS4;
1373     PULONGLONG ApUNAT;
1374     PULONGLONG ApLC;
1375     PULONGLONG ApEC;
1376     PULONGLONG RsPFS;
1377     PULONGLONG StFSR;
1378     PULONGLONG StFIR;
1379     PULONGLONG StFDR;
1380     PULONGLONG Cflag;
1381 } KNONVOLATILE_CONTEXT_POINTERS, *PKNONVOLATILE_CONTEXT_POINTERS;
1382
1383 ULONGLONG WINAPI RtlVirtualUnwind(ULONGLONG,ULONGLONG,RUNTIME_FUNCTION*,CONTEXT*,BOOLEAN*,FRAME_POINTERS*,KNONVOLATILE_CONTEXT_POINTERS*);
1384
1385 #endif /* __ia64__ */
1386
1387 /* Alpha context definitions */
1388 #if defined(_ALPHA_) || defined(__ALPHA__) || defined(__alpha__)
1389
1390 #define CONTEXT_ALPHA   0x00020000
1391
1392 #define CONTEXT_CONTROL         (CONTEXT_ALPHA | 0x00000001L)
1393 #define CONTEXT_FLOATING_POINT  (CONTEXT_ALPHA | 0x00000002L)
1394 #define CONTEXT_INTEGER         (CONTEXT_ALPHA | 0x00000004L)
1395 #define CONTEXT_FULL  (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER)
1396
1397 #define EXCEPTION_READ_FAULT    0
1398 #define EXCEPTION_WRITE_FAULT   1
1399 #define EXCEPTION_EXECUTE_FAULT 8
1400
1401 typedef struct _CONTEXT
1402 {
1403     /* selected by CONTEXT_FLOATING_POINT */
1404     ULONGLONG FltF0;
1405     ULONGLONG FltF1;
1406     ULONGLONG FltF2;
1407     ULONGLONG FltF3;
1408     ULONGLONG FltF4;
1409     ULONGLONG FltF5;
1410     ULONGLONG FltF6;
1411     ULONGLONG FltF7;
1412     ULONGLONG FltF8;
1413     ULONGLONG FltF9;
1414     ULONGLONG FltF10;
1415     ULONGLONG FltF11;
1416     ULONGLONG FltF12;
1417     ULONGLONG FltF13;
1418     ULONGLONG FltF14;
1419     ULONGLONG FltF15;
1420     ULONGLONG FltF16;
1421     ULONGLONG FltF17;
1422     ULONGLONG FltF18;
1423     ULONGLONG FltF19;
1424     ULONGLONG FltF20;
1425     ULONGLONG FltF21;
1426     ULONGLONG FltF22;
1427     ULONGLONG FltF23;
1428     ULONGLONG FltF24;
1429     ULONGLONG FltF25;
1430     ULONGLONG FltF26;
1431     ULONGLONG FltF27;
1432     ULONGLONG FltF28;
1433     ULONGLONG FltF29;
1434     ULONGLONG FltF30;
1435     ULONGLONG FltF31;
1436
1437     /* selected by CONTEXT_INTEGER */
1438     ULONGLONG IntV0;
1439     ULONGLONG IntT0;
1440     ULONGLONG IntT1;
1441     ULONGLONG IntT2;
1442     ULONGLONG IntT3;
1443     ULONGLONG IntT4;
1444     ULONGLONG IntT5;
1445     ULONGLONG IntT6;
1446     ULONGLONG IntT7;
1447     ULONGLONG IntS0;
1448     ULONGLONG IntS1;
1449     ULONGLONG IntS2;
1450     ULONGLONG IntS3;
1451     ULONGLONG IntS4;
1452     ULONGLONG IntS5;
1453     ULONGLONG IntFp;
1454     ULONGLONG IntA0;
1455     ULONGLONG IntA1;
1456     ULONGLONG IntA2;
1457     ULONGLONG IntA3;
1458     ULONGLONG IntA4;
1459     ULONGLONG IntA5;
1460     ULONGLONG IntT8;
1461     ULONGLONG IntT9;
1462     ULONGLONG IntT10;
1463     ULONGLONG IntT11;
1464     ULONGLONG IntRa;
1465     ULONGLONG IntT12;
1466     ULONGLONG IntAt;
1467     ULONGLONG IntGp;
1468     ULONGLONG IntSp;
1469     ULONGLONG IntZero;
1470
1471     /* selected by CONTEXT_FLOATING_POINT */
1472     ULONGLONG Fpcr;
1473     ULONGLONG SoftFpcr;
1474
1475     /* selected by CONTEXT_CONTROL */
1476     ULONGLONG Fir;
1477     DWORD Psr;
1478     DWORD ContextFlags;
1479     DWORD Fill[4];
1480 } CONTEXT;
1481
1482 #define _QUAD_PSR_OFFSET   HighSoftFpcr
1483 #define _QUAD_FLAGS_OFFSET HighFir
1484
1485 #endif  /* _ALPHA_ */
1486
1487 #ifdef __arm__
1488
1489 /* The following flags control the contents of the CONTEXT structure. */
1490
1491 #define CONTEXT_ARM    0x0000040
1492 #define CONTEXT_CONTROL         (CONTEXT_ARM | 0x00000001L)
1493 #define CONTEXT_INTEGER         (CONTEXT_ARM | 0x00000002L)
1494
1495 #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER)
1496
1497 #define EXCEPTION_READ_FAULT    0
1498 #define EXCEPTION_WRITE_FAULT   1
1499 #define EXCEPTION_EXECUTE_FAULT 8
1500
1501 typedef struct _CONTEXT {
1502         /* The flags values within this flag control the contents of
1503            a CONTEXT record.
1504
1505            If the context record is used as an input parameter, then
1506            for each portion of the context record controlled by a flag
1507            whose value is set, it is assumed that that portion of the
1508            context record contains valid context. If the context record
1509            is being used to modify a thread's context, then only that
1510            portion of the threads context will be modified.
1511
1512            If the context record is used as an IN OUT parameter to capture
1513            the context of a thread, then only those portions of the thread's
1514            context corresponding to set flags will be returned.
1515
1516            The context record is never used as an OUT only parameter. */
1517
1518         ULONG ContextFlags;
1519
1520         /* This section is specified/returned if the ContextFlags word contains
1521            the flag CONTEXT_INTEGER. */
1522         ULONG R0;
1523         ULONG R1;
1524         ULONG R2;
1525         ULONG R3;
1526         ULONG R4;
1527         ULONG R5;
1528         ULONG R6;
1529         ULONG R7;
1530         ULONG R8;
1531         ULONG R9;
1532         ULONG R10;
1533         ULONG Fp;
1534         ULONG Ip;
1535
1536         /* These are selected by CONTEXT_CONTROL */
1537         ULONG Sp;
1538         ULONG Lr;
1539         ULONG Pc;
1540         ULONG Cpsr;
1541 } CONTEXT;
1542
1543 #endif /* __arm__ */
1544
1545
1546 /* Mips context definitions */
1547 #if defined(_MIPS_) || defined(__MIPS__) || defined(__mips__)
1548
1549 #define CONTEXT_R4000   0x00010000
1550
1551 #define CONTEXT_CONTROL         (CONTEXT_R4000 | 0x00000001)
1552 #define CONTEXT_FLOATING_POINT  (CONTEXT_R4000 | 0x00000002)
1553 #define CONTEXT_INTEGER         (CONTEXT_R4000 | 0x00000004)
1554
1555 #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER)
1556
1557 #define EXCEPTION_READ_FAULT    0
1558 #define EXCEPTION_WRITE_FAULT   1
1559 #define EXCEPTION_EXECUTE_FAULT 8
1560
1561 typedef struct _CONTEXT
1562 {
1563     DWORD Argument[4];
1564     /* These are selected by CONTEXT_FLOATING_POINT */
1565     DWORD FltF0;
1566     DWORD FltF1;
1567     DWORD FltF2;
1568     DWORD FltF3;
1569     DWORD FltF4;
1570     DWORD FltF5;
1571     DWORD FltF6;
1572     DWORD FltF7;
1573     DWORD FltF8;
1574     DWORD FltF9;
1575     DWORD FltF10;
1576     DWORD FltF11;
1577     DWORD FltF12;
1578     DWORD FltF13;
1579     DWORD FltF14;
1580     DWORD FltF15;
1581     DWORD FltF16;
1582     DWORD FltF17;
1583     DWORD FltF18;
1584     DWORD FltF19;
1585     DWORD FltF20;
1586     DWORD FltF21;
1587     DWORD FltF22;
1588     DWORD FltF23;
1589     DWORD FltF24;
1590     DWORD FltF25;
1591     DWORD FltF26;
1592     DWORD FltF27;
1593     DWORD FltF28;
1594     DWORD FltF29;
1595     DWORD FltF30;
1596     DWORD FltF31;
1597
1598     /* These are selected by CONTEXT_INTEGER */
1599     DWORD IntZero;
1600     DWORD IntAt;
1601     DWORD IntV0;
1602     DWORD IntV1;
1603     DWORD IntA0;
1604     DWORD IntA1;
1605     DWORD IntA2;
1606     DWORD IntA3;
1607     DWORD IntT0;
1608     DWORD IntT1;
1609     DWORD IntT2;
1610     DWORD IntT3;
1611     DWORD IntT4;
1612     DWORD IntT5;
1613     DWORD IntT6;
1614     DWORD IntT7;
1615     DWORD IntS0;
1616     DWORD IntS1;
1617     DWORD IntS2;
1618     DWORD IntS3;
1619     DWORD IntS4;
1620     DWORD IntS5;
1621     DWORD IntS6;
1622     DWORD IntS7;
1623     DWORD IntT8;
1624     DWORD IntT9;
1625     DWORD IntK0;
1626     DWORD IntK1;
1627     DWORD IntGp;
1628     DWORD IntSp;
1629     DWORD IntS8;
1630     DWORD IntRa;
1631     DWORD IntLo;
1632     DWORD IntHi;
1633
1634     /* These are selected by CONTEXT_FLOATING_POINT */
1635     DWORD Fsr;
1636
1637     /* These are selected by CONTEXT_CONTROL */
1638     DWORD Fir;
1639     DWORD Psr;
1640
1641     DWORD ContextFlags;
1642     DWORD Fill[2];
1643 } CONTEXT;
1644
1645 #endif  /* _MIPS_ */
1646
1647 /* PowerPC context definitions */
1648 #ifdef __powerpc__
1649
1650 #define CONTEXT_CONTROL         0x0001
1651 #define CONTEXT_FLOATING_POINT  0x0002
1652 #define CONTEXT_INTEGER         0x0004
1653 #define CONTEXT_DEBUG_REGISTERS 0x0008
1654 #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER)
1655
1656 #define EXCEPTION_READ_FAULT    0
1657 #define EXCEPTION_WRITE_FAULT   1
1658 #define EXCEPTION_EXECUTE_FAULT 8
1659
1660 typedef struct
1661 {
1662     /* These are selected by CONTEXT_FLOATING_POINT */
1663     double Fpr0;
1664     double Fpr1;
1665     double Fpr2;
1666     double Fpr3;
1667     double Fpr4;
1668     double Fpr5;
1669     double Fpr6;
1670     double Fpr7;
1671     double Fpr8;
1672     double Fpr9;
1673     double Fpr10;
1674     double Fpr11;
1675     double Fpr12;
1676     double Fpr13;
1677     double Fpr14;
1678     double Fpr15;
1679     double Fpr16;
1680     double Fpr17;
1681     double Fpr18;
1682     double Fpr19;
1683     double Fpr20;
1684     double Fpr21;
1685     double Fpr22;
1686     double Fpr23;
1687     double Fpr24;
1688     double Fpr25;
1689     double Fpr26;
1690     double Fpr27;
1691     double Fpr28;
1692     double Fpr29;
1693     double Fpr30;
1694     double Fpr31;
1695     double Fpscr;
1696
1697     /* These are selected by CONTEXT_INTEGER */
1698     DWORD Gpr0;
1699     DWORD Gpr1;
1700     DWORD Gpr2;
1701     DWORD Gpr3;
1702     DWORD Gpr4;
1703     DWORD Gpr5;
1704     DWORD Gpr6;
1705     DWORD Gpr7;
1706     DWORD Gpr8;
1707     DWORD Gpr9;
1708     DWORD Gpr10;
1709     DWORD Gpr11;
1710     DWORD Gpr12;
1711     DWORD Gpr13;
1712     DWORD Gpr14;
1713     DWORD Gpr15;
1714     DWORD Gpr16;
1715     DWORD Gpr17;
1716     DWORD Gpr18;
1717     DWORD Gpr19;
1718     DWORD Gpr20;
1719     DWORD Gpr21;
1720     DWORD Gpr22;
1721     DWORD Gpr23;
1722     DWORD Gpr24;
1723     DWORD Gpr25;
1724     DWORD Gpr26;
1725     DWORD Gpr27;
1726     DWORD Gpr28;
1727     DWORD Gpr29;
1728     DWORD Gpr30;
1729     DWORD Gpr31;
1730
1731     DWORD Cr;
1732     DWORD Xer;
1733
1734     /* These are selected by CONTEXT_CONTROL */
1735     DWORD Msr;
1736     DWORD Iar; /* Instruction Address Register , aka PC ... */
1737     DWORD Lr;
1738     DWORD Ctr;
1739
1740     DWORD ContextFlags;
1741     
1742     DWORD Dar;   /* Fault registers for coredump */
1743     DWORD Dsisr; 
1744     DWORD Trap;  /* number of powerpc exception taken */
1745
1746     /* These are selected by CONTEXT_DEBUG_REGISTERS */
1747     DWORD Dr0;
1748     DWORD Dr1;
1749     DWORD Dr2;
1750     DWORD Dr3;
1751     DWORD Dr4;
1752     DWORD Dr5;
1753     DWORD Dr6;
1754     DWORD Dr7;
1755 } CONTEXT;
1756
1757 typedef struct _STACK_FRAME_HEADER
1758 {
1759     DWORD BackChain;
1760     DWORD GlueSaved1;
1761     DWORD GlueSaved2;
1762     DWORD Reserved1;
1763     DWORD Spare1;
1764     DWORD Spare2;
1765
1766     DWORD Parameter0;
1767     DWORD Parameter1;
1768     DWORD Parameter2;
1769     DWORD Parameter3;
1770     DWORD Parameter4;
1771     DWORD Parameter5;
1772     DWORD Parameter6;
1773     DWORD Parameter7;
1774 } STACK_FRAME_HEADER,*PSTACK_FRAME_HEADER;
1775
1776 #endif  /* __powerpc__ */
1777
1778 #ifdef __sparc__
1779
1780 /*
1781  * FIXME:
1782  *
1783  * There is no official CONTEXT structure defined for the SPARC
1784  * architecture, so I just made one up.
1785  *
1786  * This structure is valid only for 32-bit SPARC architectures,
1787  * not for 64-bit SPARC.
1788  *
1789  * Note that this structure contains only the 'top-level' registers;
1790  * the rest of the register window chain is not visible.
1791  *
1792  * The layout follows the Solaris 'prgregset_t' structure.
1793  *
1794  */
1795
1796 #define CONTEXT_SPARC            0x10000000
1797
1798 #define CONTEXT_CONTROL         (CONTEXT_SPARC | 0x00000001)
1799 #define CONTEXT_FLOATING_POINT  (CONTEXT_SPARC | 0x00000002)
1800 #define CONTEXT_INTEGER         (CONTEXT_SPARC | 0x00000004)
1801
1802 #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER)
1803
1804 #define EXCEPTION_READ_FAULT    0
1805 #define EXCEPTION_WRITE_FAULT   1
1806 #define EXCEPTION_EXECUTE_FAULT 8
1807
1808 typedef struct _CONTEXT
1809 {
1810     DWORD ContextFlags;
1811
1812     /* These are selected by CONTEXT_INTEGER */
1813     DWORD g0;
1814     DWORD g1;
1815     DWORD g2;
1816     DWORD g3;
1817     DWORD g4;
1818     DWORD g5;
1819     DWORD g6;
1820     DWORD g7;
1821     DWORD o0;
1822     DWORD o1;
1823     DWORD o2;
1824     DWORD o3;
1825     DWORD o4;
1826     DWORD o5;
1827     DWORD o6;
1828     DWORD o7;
1829     DWORD l0;
1830     DWORD l1;
1831     DWORD l2;
1832     DWORD l3;
1833     DWORD l4;
1834     DWORD l5;
1835     DWORD l6;
1836     DWORD l7;
1837     DWORD i0;
1838     DWORD i1;
1839     DWORD i2;
1840     DWORD i3;
1841     DWORD i4;
1842     DWORD i5;
1843     DWORD i6;
1844     DWORD i7;
1845
1846     /* These are selected by CONTEXT_CONTROL */
1847     DWORD psr;
1848     DWORD pc;
1849     DWORD npc;
1850     DWORD y;
1851     DWORD wim;
1852     DWORD tbr;
1853
1854     /* FIXME: floating point registers missing */
1855
1856 } CONTEXT;
1857
1858 #endif  /* __sparc__ */
1859
1860 #if !defined(CONTEXT_FULL) && !defined(RC_INVOKED)
1861 #error You need to define a CONTEXT for your CPU
1862 #endif
1863
1864 typedef CONTEXT *PCONTEXT;
1865
1866 NTSYSAPI void WINAPI RtlCaptureContext(CONTEXT*);
1867
1868 /*
1869  * Product types
1870  */
1871 #define PRODUCT_UNLICENSED                              0xABCDABCD
1872 #define PRODUCT_BUSINESS                                0x00000006
1873 #define PRODUCT_BUSINESS_N                              0x00000010
1874 #define PRODUCT_CLUSTER_SERVER                          0x00000012
1875 #define PRODUCT_DATACENTER_SERVER                       0x00000008
1876 #define PRODUCT_DATACENTER_SERVER_CORE                  0x0000000C
1877 #define PRODUCT_DATACENTER_SERVER_CORE_V                0x00000027
1878 #define PRODUCT_SERVER_V                                0x00000025
1879 #define PRODUCT_ENTERPRISE                              0x00000004
1880 #define PRODUCT_ENTERPRISE_N                            0x0000001B
1881 #define PRODUCT_ENTERPRISE_SERVER                       0x0000000A
1882 #define PRODUCT_ENTERPRISE_SERVER_CORE                  0x0000000E
1883 #define PRODUCT_ENTERPRISE_SERVER_CORE_V                0x00000029
1884 #define PRODUCT_ENTERPRISE_SERVER_IA64                  0x0000000F
1885 #define PRODUCT_ENTERPRISE_SERVER_V                     0x00000026
1886 #define PRODUCT_HOME_BASIC                              0x00000002
1887 #define PRODUCT_HOME_BASIC_N                            0x00000005
1888 #define PRODUCT_HOME_PREMIUM                            0x00000003
1889 #define PRODUCT_HOME_PREMIUM_N                          0x0000001A
1890 #define PRODUCT_HYPERV                                  0x0000002A
1891 #define PRODUCT_MEDIUMBUSINESS_SERVER_MANAGEMENT        0x0000001E
1892 #define PRODUCT_MEDIUMBUSINESS_SERVER_MESSAGING         0x00000020
1893 #define PRODUCT_MEDIUMBUSINESS_SERVER_SECURITY          0x0000001F
1894 #define PRODUCT_SERVER_FOR_SMALLBUSINESS                0x00000018
1895 #define PRODUCT_SERVER_FOR_SMALLBUSINESS_V              0x00000023
1896 #define PRODUCT_SMALLBUSINESS_SERVER                    0x00000009
1897 #define PRODUCT_STANDARD_SERVER                         0x00000007
1898 #define PRODUCT_STANDARD_SERVER_CORE                    0x0000000D
1899 #define PRODUCT_STANDARD_SERVER_CORE_V                  0x00000028
1900 #define PRODUCT_STANDARD_SERVER_V                       0x00000024
1901 #define PRODUCT_STARTER                                 0x0000000B
1902 #define PRODUCT_STORAGE_ENTERPRISE_SERVER               0x00000017
1903 #define PRODUCT_STORAGE_EXPRESS_SERVER                  0x00000014
1904 #define PRODUCT_STORAGE_STANDARD_SERVER                 0x00000015
1905 #define PRODUCT_STORAGE_WORKGROUP_SERVER                0x00000016
1906 #define PRODUCT_UNDEFINED                               0x00000000
1907 #define PRODUCT_ULTIMATE                                0x00000001
1908 #define PRODUCT_ULTIMATE_N                              0x0000001C
1909 #define PRODUCT_WEB_SERVER                              0x00000011
1910 #define PRODUCT_WEB_SERVER_CORE                         0x0000001D
1911
1912
1913 /*
1914  * Language IDs
1915  */
1916
1917 #define MAKELCID(l, s)          (MAKELONG(l, s))
1918
1919 #define MAKELANGID(p, s)        ((((WORD)(s))<<10) | (WORD)(p))
1920 #define PRIMARYLANGID(l)        ((WORD)(l) & 0x3ff)
1921 #define SUBLANGID(l)            ((WORD)(l) >> 10)
1922
1923 #define LANGIDFROMLCID(lcid)    ((WORD)(lcid))
1924 #define SORTIDFROMLCID(lcid)    ((WORD)((((DWORD)(lcid)) >> 16) & 0x0f))
1925
1926 #define LANG_SYSTEM_DEFAULT     (MAKELANGID(LANG_NEUTRAL, SUBLANG_SYS_DEFAULT))
1927 #define LANG_USER_DEFAULT       (MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT))
1928 #define LOCALE_SYSTEM_DEFAULT   (MAKELCID(LANG_SYSTEM_DEFAULT, SORT_DEFAULT))
1929 #define LOCALE_USER_DEFAULT     (MAKELCID(LANG_USER_DEFAULT, SORT_DEFAULT))
1930 #define LOCALE_NEUTRAL          (MAKELCID(MAKELANGID(LANG_NEUTRAL,SUBLANG_NEUTRAL),SORT_DEFAULT))
1931 #define LOCALE_INVARIANT        (MAKELCID(MAKELANGID(LANG_INVARIANT,SUBLANG_NEUTRAL),SORT_DEFAULT))
1932
1933 #define UNREFERENCED_PARAMETER(u)       (void)(u)
1934 #define DBG_UNREFERENCED_PARAMETER(u)   (void)(u)
1935 #define DBG_UNREFERENCED_LOCAL_VARIABLE(u) (void)(u)
1936
1937 #define LANG_NEUTRAL        0x00
1938 #define LANG_INVARIANT      0x7f
1939
1940 #define LANG_AFRIKAANS      0x36
1941 #define LANG_ALBANIAN       0x1c
1942 #define LANG_ALSATIAN       0x84
1943 #define LANG_AMHARIC        0x5e
1944 #define LANG_ARABIC         0x01
1945 #define LANG_ARMENIAN       0x2b
1946 #define LANG_ASSAMESE       0x4d
1947 #define LANG_AZERI          0x2c
1948 #define LANG_BASHKIR        0x6d
1949 #define LANG_BASQUE         0x2d
1950 #define LANG_BELARUSIAN     0x23
1951 #define LANG_BENGALI        0x45
1952 #define LANG_BOSNIAN        0x1a
1953 #define LANG_BOSNIAN_NEUTRAL      0x781a
1954 #define LANG_BRETON         0x7e
1955 #define LANG_BULGARIAN      0x02
1956 #define LANG_CATALAN        0x03
1957 #define LANG_CHINESE        0x04
1958 #define LANG_CHINESE_SIMPLIFIED   0x0004
1959 #define LANG_CHINESE_TRADITIONAL  0x7c04
1960 #define LANG_CORSICAN       0x83
1961 #define LANG_CROATIAN       0x1a
1962 #define LANG_CZECH          0x05
1963 #define LANG_DANISH         0x06
1964 #define LANG_DARI           0x8c
1965 #define LANG_DIVEHI         0x65
1966 #define LANG_DUTCH          0x13
1967 #define LANG_ENGLISH        0x09
1968 #define LANG_ESTONIAN       0x25
1969 #define LANG_FAEROESE       0x38
1970 #define LANG_FARSI          LANG_PERSIAN
1971 #define LANG_FILIPINO       0x64
1972 #define LANG_FINNISH        0x0b
1973 #define LANG_FRENCH         0x0c
1974 #define LANG_FRISIAN        0x62
1975 #define LANG_GALICIAN       0x56
1976 #define LANG_GEORGIAN       0x37
1977 #define LANG_GERMAN         0x07
1978 #define LANG_GREEK          0x08
1979 #define LANG_GREENLANDIC    0x6f
1980 #define LANG_GUJARATI       0x47
1981 #define LANG_HAUSA          0x68
1982 #define LANG_HEBREW         0x0d
1983 #define LANG_HINDI          0x39
1984 #define LANG_HUNGARIAN      0x0e
1985 #define LANG_ICELANDIC      0x0f
1986 #define LANG_IGBO           0x70
1987 #define LANG_INDONESIAN     0x21
1988 #define LANG_INUKTITUT      0x5d
1989 #define LANG_IRISH          0x3c
1990 #define LANG_ITALIAN        0x10
1991 #define LANG_JAPANESE       0x11
1992 #define LANG_KANNADA        0x4b
1993 #define LANG_KASHMIRI       0x60
1994 #define LANG_KAZAK          0x3f
1995 #define LANG_KHMER          0x53
1996 #define LANG_KICHE          0x86
1997 #define LANG_KINYARWANDA    0x87
1998 #define LANG_KONKANI        0x57
1999 #define LANG_KOREAN         0x12
2000 #define LANG_KYRGYZ         0x40
2001 #define LANG_LAO            0x54
2002 #define LANG_LATVIAN        0x26
2003 #define LANG_LITHUANIAN     0x27
2004 #define LANG_LOWER_SORBIAN  0x2e
2005 #define LANG_LUXEMBOURGISH  0x6e
2006 #define LANG_MACEDONIAN     0x2f
2007 #define LANG_MALAY          0x3e
2008 #define LANG_MALAYALAM      0x4c
2009 #define LANG_MALTESE        0x3a
2010 #define LANG_MANIPURI       0x58
2011 #define LANG_MAORI          0x81
2012 #define LANG_MAPUDUNGUN     0x7a
2013 #define LANG_MARATHI        0x4e
2014 #define LANG_MOHAWK         0x7c
2015 #define LANG_MONGOLIAN      0x50
2016 #define LANG_NEPALI         0x61
2017 #define LANG_NORWEGIAN      0x14
2018 #define LANG_OCCITAN        0x82
2019 #define LANG_ORIYA          0x48
2020 #define LANG_PASHTO         0x63
2021 #define LANG_PERSIAN        0x29
2022 #define LANG_POLISH         0x15
2023 #define LANG_PORTUGUESE     0x16
2024 #define LANG_PUNJABI        0x46
2025 #define LANG_QUECHUA        0x6b
2026 #define LANG_ROMANIAN       0x18
2027 #define LANG_ROMANSH        0x17
2028 #define LANG_RUSSIAN        0x19
2029 #define LANG_SAMI           0x3b
2030 #define LANG_SANSKRIT       0x4f
2031 #define LANG_SERBIAN        0x1a
2032 #define LANG_SERBIAN_NEUTRAL      0x7c1a
2033 #define LANG_SINDHI         0x59
2034 #define LANG_SINHALESE      0x5b
2035 #define LANG_SLOVAK         0x1b
2036 #define LANG_SLOVENIAN      0x24
2037 #define LANG_SOTHO          0x6c
2038 #define LANG_SPANISH        0x0a
2039 #define LANG_SWAHILI        0x41
2040 #define LANG_SWEDISH        0x1d
2041 #define LANG_SYRIAC         0x5a
2042 #define LANG_TAJIK          0x28
2043 #define LANG_TAMAZIGHT      0x5f
2044 #define LANG_TAMIL          0x49
2045 #define LANG_TATAR          0x44
2046 #define LANG_TELUGU         0x4a
2047 #define LANG_THAI           0x1e
2048 #define LANG_TIBETAN        0x51
2049 #define LANG_TIGRIGNA       0x73
2050 #define LANG_TSWANA         0x32
2051 #define LANG_TURKISH        0x1f
2052 #define LANG_TURKMEN        0x42
2053 #define LANG_UIGHUR         0x80
2054 #define LANG_UKRAINIAN      0x22
2055 #define LANG_UPPER_SORBIAN  0x2e
2056 #define LANG_URDU           0x20
2057 #define LANG_UZBEK          0x43
2058 #define LANG_VIETNAMESE     0x2a
2059 #define LANG_WELSH          0x52
2060 #define LANG_WOLOF          0x88
2061 #define LANG_XHOSA          0x34
2062 #define LANG_YAKUT          0x85
2063 #define LANG_YI             0x78
2064 #define LANG_YORUBA         0x6a
2065 #define LANG_ZULU           0x35
2066
2067 /* These are documented by the MSDN but are missing from the Windows header */
2068 #define LANG_MALAGASY       0x8d
2069
2070 /* FIXME: these are not defined anywhere */
2071 #define LANG_SUTU           0x30
2072 #define LANG_TSONGA         0x31
2073 #define LANG_VENDA          0x33
2074
2075 /* non standard; keep the number high enough (but < 0xff) */
2076 #define LANG_ESPERANTO                   0x8f
2077 #define LANG_WALON                       0x90
2078 #define LANG_CORNISH                     0x91
2079 #define LANG_GAELIC                      0x94
2080
2081 /* Sublanguage definitions */
2082 #define SUBLANG_NEUTRAL                  0x00    /* language neutral */
2083 #define SUBLANG_DEFAULT                  0x01    /* user default */
2084 #define SUBLANG_SYS_DEFAULT              0x02    /* system default */
2085 #define SUBLANG_CUSTOM_DEFAULT           0x03
2086 #define SUBLANG_CUSTOM_UNSPECIFIED       0x04
2087 #define SUBLANG_UI_CUSTOM_DEFAULT        0x05
2088
2089 #define SUBLANG_AFRIKAANS_SOUTH_AFRICA     0x01
2090 #define SUBLANG_ALBANIAN_ALBANIA           0x01
2091 #define SUBLANG_ALSATIAN_FRANCE            0x01
2092 #define SUBLANG_AMHARIC_ETHIOPIA           0x01
2093 #define SUBLANG_ARABIC_SAUDI_ARABIA        0x01
2094 #define SUBLANG_ARABIC_IRAQ                0x02
2095 #define SUBLANG_ARABIC_EGYPT               0x03
2096 #define SUBLANG_ARABIC_LIBYA               0x04
2097 #define SUBLANG_ARABIC_ALGERIA             0x05
2098 #define SUBLANG_ARABIC_MOROCCO             0x06
2099 #define SUBLANG_ARABIC_TUNISIA             0x07
2100 #define SUBLANG_ARABIC_OMAN                0x08
2101 #define SUBLANG_ARABIC_YEMEN               0x09
2102 #define SUBLANG_ARABIC_SYRIA               0x0a
2103 #define SUBLANG_ARABIC_JORDAN              0x0b
2104 #define SUBLANG_ARABIC_LEBANON             0x0c
2105 #define SUBLANG_ARABIC_KUWAIT              0x0d
2106 #define SUBLANG_ARABIC_UAE                 0x0e
2107 #define SUBLANG_ARABIC_BAHRAIN             0x0f
2108 #define SUBLANG_ARABIC_QATAR               0x10
2109 #define SUBLANG_ARMENIAN_ARMENIA           0x01
2110 #define SUBLANG_ASSAMESE_INDIA             0x01
2111 #define SUBLANG_AZERI_LATIN                0x01
2112 #define SUBLANG_AZERI_CYRILLIC             0x02
2113 #define SUBLANG_BASHKIR_RUSSIA             0x01
2114 #define SUBLANG_BASQUE_BASQUE              0x01
2115 #define SUBLANG_BELARUSIAN_BELARUS         0x01
2116 #define SUBLANG_BENGALI_INDIA              0x01
2117 #define SUBLANG_BENGALI_BANGLADESH         0x02
2118 #define SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_LATIN 0x05
2119 #define SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_CYRILLIC 0x08
2120 #define SUBLANG_BRETON_FRANCE              0x01
2121 #define SUBLANG_BULGARIAN_BULGARIA         0x01
2122 #define SUBLANG_CATALAN_CATALAN            0x01
2123 #define SUBLANG_CHINESE_TRADITIONAL        0x01
2124 #define SUBLANG_CHINESE_SIMPLIFIED         0x02
2125 #define SUBLANG_CHINESE_HONGKONG           0x03
2126 #define SUBLANG_CHINESE_SINGAPORE          0x04
2127 #define SUBLANG_CHINESE_MACAU              0x05
2128 #define SUBLANG_CORSICAN_FRANCE            0x01
2129 #define SUBLANG_CROATIAN_CROATIA           0x01
2130 #define SUBLANG_CROATIAN_BOSNIA_HERZEGOVINA_LATIN 0x04
2131 #define SUBLANG_CZECH_CZECH_REPUBLIC       0x01
2132 #define SUBLANG_DANISH_DENMARK             0x01
2133 #define SUBLANG_DARI_AFGHANISTAN           0x01
2134 #define SUBLANG_DIVEHI_MALDIVES            0x01
2135 #define SUBLANG_DUTCH                      0x01
2136 #define SUBLANG_DUTCH_BELGIAN              0x02
2137 #define SUBLANG_ENGLISH_US                 0x01
2138 #define SUBLANG_ENGLISH_UK                 0x02
2139 #define SUBLANG_ENGLISH_AUS                0x03
2140 #define SUBLANG_ENGLISH_CAN                0x04
2141 #define SUBLANG_ENGLISH_NZ                 0x05
2142 #define SUBLANG_ENGLISH_EIRE               0x06
2143 #define SUBLANG_ENGLISH_SOUTH_AFRICA       0x07
2144 #define SUBLANG_ENGLISH_JAMAICA            0x08
2145 #define SUBLANG_ENGLISH_CARIBBEAN          0x09
2146 #define SUBLANG_ENGLISH_BELIZE             0x0a
2147 #define SUBLANG_ENGLISH_TRINIDAD           0x0b
2148 #define SUBLANG_ENGLISH_ZIMBABWE           0x0c
2149 #define SUBLANG_ENGLISH_PHILIPPINES        0x0d
2150 #define SUBLANG_ENGLISH_INDIA              0x10
2151 #define SUBLANG_ENGLISH_MALAYSIA           0x11
2152 #define SUBLANG_ENGLISH_SINGAPORE          0x12
2153 #define SUBLANG_ESTONIAN_ESTONIA           0x01
2154 #define SUBLANG_FAEROESE_FAROE_ISLANDS     0x01
2155 #define SUBLANG_FILIPINO_PHILIPPINES       0x01
2156 #define SUBLANG_FINNISH_FINLAND            0x01
2157 #define SUBLANG_FRENCH                     0x01
2158 #define SUBLANG_FRENCH_BELGIAN             0x02
2159 #define SUBLANG_FRENCH_CANADIAN            0x03
2160 #define SUBLANG_FRENCH_SWISS               0x04
2161 #define SUBLANG_FRENCH_LUXEMBOURG          0x05
2162 #define SUBLANG_FRENCH_MONACO              0x06
2163 #define SUBLANG_FRISIAN_NETHERLANDS        0x01
2164 #define SUBLANG_GALICIAN_GALICIAN          0x01
2165 #define SUBLANG_GEORGIAN_GEORGIA           0x01
2166 #define SUBLANG_GERMAN                     0x01
2167 #define SUBLANG_GERMAN_SWISS               0x02
2168 #define SUBLANG_GERMAN_AUSTRIAN            0x03
2169 #define SUBLANG_GERMAN_LUXEMBOURG          0x04
2170 #define SUBLANG_GERMAN_LIECHTENSTEIN       0x05
2171 #define SUBLANG_GREEK_GREECE               0x01
2172 #define SUBLANG_GREENLANDIC_GREENLAND      0x01
2173 #define SUBLANG_GUJARATI_INDIA             0x01
2174 #define SUBLANG_HAUSA_NIGERIA_LATIN        0x01
2175 #define SUBLANG_HEBREW_ISRAEL              0x01
2176 #define SUBLANG_HINDI_INDIA                0x01
2177 #define SUBLANG_HUNGARIAN_HUNGARY          0x01
2178 #define SUBLANG_ICELANDIC_ICELAND          0x01
2179 #define SUBLANG_IGBO_NIGERIA               0x01
2180 #define SUBLANG_INDONESIAN_INDONESIA       0x01
2181 #define SUBLANG_INUKTITUT_CANADA           0x01
2182 #define SUBLANG_INUKTITUT_CANADA_LATIN     0x02
2183 #define SUBLANG_IRISH_IRELAND              0x02
2184 #define SUBLANG_ITALIAN                    0x01
2185 #define SUBLANG_ITALIAN_SWISS              0x02
2186 #define SUBLANG_JAPANESE_JAPAN             0x01
2187 #define SUBLANG_KANNADA_INDIA              0x01
2188 #define SUBLANG_KASHMIRI_SASIA             0x02
2189 #define SUBLANG_KASHMIRI_INDIA             0x02
2190 #define SUBLANG_KAZAK_KAZAKHSTAN           0x01
2191 #define SUBLANG_KHMER_CAMBODIA             0x01
2192 #define SUBLANG_KICHE_GUATEMALA            0x01
2193 #define SUBLANG_KINYARWANDA_RWANDA         0X01
2194 #define SUBLANG_KONKANI_INDIA              0x01
2195 #define SUBLANG_KOREAN                     0x01
2196 #define SUBLANG_KYRGYZ_KYRGYZSTAN          0x01
2197 #define SUBLANG_LAO_LAO                    0x01
2198 #define SUBLANG_LATVIAN_LATVIA             0x01
2199 #define SUBLANG_LITHUANIAN_LITHUANIA       0x01
2200 #define SUBLANG_LOWER_SORBIAN_GERMANY      0x02
2201 #define SUBLANG_LUXEMBOURGISH_LUXEMBOURG   0x01
2202 #define SUBLANG_MACEDONIAN_MACEDONIA       0x01
2203 #define SUBLANG_MALAY_MALAYSIA             0x01
2204 #define SUBLANG_MALAY_BRUNEI_DARUSSALAM    0x02
2205 #define SUBLANG_MALAYALAM_INDIA            0x01
2206 #define SUBLANG_MALTESE_MALTA              0x01
2207 #define SUBLANG_MAORI_NEW_ZEALAND          0x01
2208 #define SUBLANG_MAPUDUNGUN_CHILE           0x01
2209 #define SUBLANG_MARATHI_INDIA              0x01
2210 #define SUBLANG_MOHAWK_MOHAWK              0x01
2211 #define SUBLANG_MONGOLIAN_CYRILLIC_MONGOLIA 0x01
2212 #define SUBLANG_MONGOLIAN_PRC              0x02
2213 #define SUBLANG_NEPALI_INDIA               0x02
2214 #define SUBLANG_NEPALI_NEPAL               0x01
2215 #define SUBLANG_NORWEGIAN_BOKMAL           0x01
2216 #define SUBLANG_NORWEGIAN_NYNORSK          0x02
2217 #define SUBLANG_OCCITAN_FRANCE             0x01
2218 #define SUBLANG_ORIYA_INDIA                0x01
2219 #define SUBLANG_PASHTO_AFGHANISTAN         0x01
2220 #define SUBLANG_PERSIAN_IRAN               0x01
2221 #define SUBLANG_POLISH_POLAND              0x01
2222 #define SUBLANG_PORTUGUESE                 0x02
2223 #define SUBLANG_PORTUGUESE_BRAZILIAN       0x01
2224 #define SUBLANG_PUNJABI_INDIA              0x01
2225 #define SUBLANG_QUECHUA_BOLIVIA            0x01
2226 #define SUBLANG_QUECHUA_ECUADOR            0x02
2227 #define SUBLANG_QUECHUA_PERU               0x03
2228 #define SUBLANG_ROMANIAN_ROMANIA           0x01
2229 #define SUBLANG_ROMANSH_SWITZERLAND        0x01
2230 #define SUBLANG_RUSSIAN_RUSSIA             0x01
2231 #define SUBLANG_SAMI_NORTHERN_NORWAY       0x01
2232 #define SUBLANG_SAMI_NORTHERN_SWEDEN       0x02
2233 #define SUBLANG_SAMI_NORTHERN_FINLAND      0x03
2234 #define SUBLANG_SAMI_LULE_NORWAY           0x04
2235 #define SUBLANG_SAMI_LULE_SWEDEN           0x05
2236 #define SUBLANG_SAMI_SOUTHERN_NORWAY       0x06
2237 #define SUBLANG_SAMI_SOUTHERN_SWEDEN       0x07
2238 #define SUBLANG_SAMI_SKOLT_FINLAND         0x08
2239 #define SUBLANG_SAMI_INARI_FINLAND         0x09
2240 #define SUBLANG_SANSKRIT_INDIA             0x01
2241 #define SUBLANG_SERBIAN_BOSNIA_HERZEGOVINA_LATIN 0x06
2242 #define SUBLANG_SERBIAN_BOSNIA_HERZEGOVINA_CYRILLIC 0x07
2243 #define SUBLANG_SERBIAN_CROATIA            0x01
2244 #define SUBLANG_SERBIAN_LATIN              0x02
2245 #define SUBLANG_SERBIAN_CYRILLIC           0x03
2246 #define SUBLANG_SINDHI_AFGHANISTAN         0x02
2247 #define SUBLANG_SINHALESE_SRI_LANKA        0x01
2248 #define SUBLANG_SLOVAK_SLOVAKIA            0x01
2249 #define SUBLANG_SLOVENIAN_SLOVENIA         0x01
2250 #define SUBLANG_SOTHO_NORTHERN_SOUTH_AFRICA 0x01
2251 #define SUBLANG_SPANISH                    0x01
2252 #define SUBLANG_SPANISH_MEXICAN            0x02
2253 #define SUBLANG_SPANISH_MODERN             0x03
2254 #define SUBLANG_SPANISH_GUATEMALA          0x04
2255 #define SUBLANG_SPANISH_COSTA_RICA         0x05
2256 #define SUBLANG_SPANISH_PANAMA             0x06
2257 #define SUBLANG_SPANISH_DOMINICAN_REPUBLIC 0x07
2258 #define SUBLANG_SPANISH_VENEZUELA          0x08
2259 #define SUBLANG_SPANISH_COLOMBIA           0x09
2260 #define SUBLANG_SPANISH_PERU               0x0a
2261 #define SUBLANG_SPANISH_ARGENTINA          0x0b
2262 #define SUBLANG_SPANISH_ECUADOR            0x0c
2263 #define SUBLANG_SPANISH_CHILE              0x0d
2264 #define SUBLANG_SPANISH_URUGUAY            0x0e
2265 #define SUBLANG_SPANISH_PARAGUAY           0x0f
2266 #define SUBLANG_SPANISH_BOLIVIA            0x10
2267 #define SUBLANG_SPANISH_EL_SALVADOR        0x11
2268 #define SUBLANG_SPANISH_HONDURAS           0x12
2269 #define SUBLANG_SPANISH_NICARAGUA          0x13
2270 #define SUBLANG_SPANISH_PUERTO_RICO        0x14
2271 #define SUBLANG_SPANISH_US                 0x15
2272 #define SUBLANG_SWAHILI_KENYA              0x01
2273 #define SUBLANG_SWEDISH                    0x01
2274 #define SUBLANG_SWEDISH_FINLAND            0x02
2275 #define SUBLANG_SYRIAC_SYRIA               0x01
2276 #define SUBLANG_TAJIK_TAJIKISTAN           0x01
2277 #define SUBLANG_TAMAZIGHT_ALGERIA_LATIN    0x02
2278 #define SUBLANG_TAMIL_INDIA                0x01
2279 #define SUBLANG_TATAR_RUSSIA               0x01
2280 #define SUBLANG_TELUGU_INDIA               0x01
2281 #define SUBLANG_THAI_THAILAND              0x01
2282 #define SUBLANG_TIBETAN_PRC                0x01
2283 #define SUBLANG_TIBETAN_BHUTAN             0x02
2284 #define SUBLANG_TIGRIGNA_ERITREA           0x02
2285 #define SUBLANG_TSWANA_SOUTH_AFRICA        0x01
2286 #define SUBLANG_TURKISH_TURKEY             0x01
2287 #define SUBLANG_TURKMEN_TURKMENISTAN       0x01
2288 #define SUBLANG_UIGHUR_PRC                 0x01
2289 #define SUBLANG_UKRAINIAN_UKRAINE          0x01
2290 #define SUBLANG_UPPER_SORBIAN_GERMANY      0x01
2291 #define SUBLANG_URDU_PAKISTAN              0x01
2292 #define SUBLANG_URDU_INDIA                 0x02
2293 #define SUBLANG_UZBEK_LATIN                0x01
2294 #define SUBLANG_UZBEK_CYRILLIC             0x02
2295 #define SUBLANG_VIETNAMESE_VIETNAM         0x01
2296 #define SUBLANG_WELSH_UNITED_KINGDOM       0x01
2297 #define SUBLANG_WOLOF_SENEGAL              0x01
2298 #define SUBLANG_XHOSA_SOUTH_AFRICA         0x01
2299 #define SUBLANG_YAKUT_RUSSIA               0x01
2300 #define SUBLANG_YI_PRC                     0x01
2301 #define SUBLANG_YORUBA_NIGERIA             0x01
2302 #define SUBLANG_ZULU_SOUTH_AFRICA          0x01
2303
2304 /* These are documented by the MSDN but are missing from the Windows header */
2305 #define SUBLANG_ENGLISH_IRELAND            SUBLANG_ENGLISH_EIRE
2306 #define SUBLANG_HAUSA_NIGERIA              SUBLANG_HAUSA_NIGERIA_LATIN
2307 #define SUBLANG_LAO_LAO_PDR                SUBLANG_LAO_LAO
2308 #define SUBLANG_LITHUANIAN                 SUBLANG_LITHUANIAN_LITHUANIA
2309 #define SUBLANG_PORTUGUESE_PORTUGAL        SUBLANG_PORTUGUESE
2310 #define SUBLANG_SWAHILI                    SUBLANG_SWAHILI_KENYA
2311 #define SUBLANG_SWEDISH_SWEDEN             SUBLANG_SWEDISH
2312 #define SUBLANG_SYRIAC                     SUBLANG_SYRIAC_SYRIA
2313
2314 /* FIXME: these are not defined anywhere */
2315 #define SUBLANG_DUTCH_SURINAM              0x03
2316 #define SUBLANG_ROMANIAN                   SUBLANG_ROMANIAN_ROMANIA
2317 #define SUBLANG_ROMANIAN_MOLDAVIA          0x02
2318 #define SUBLANG_RUSSIAN                    SUBLANG_RUSSIAN_RUSSIA
2319 #define SUBLANG_RUSSIAN_MOLDAVIA           0x02
2320 #define SUBLANG_CROATIAN                   SUBLANG_CROATIAN_CROATIA
2321 #define SUBLANG_LITHUANIAN_CLASSIC         0x02
2322 #define SUBLANG_GAELIC                     0x01
2323 #define SUBLANG_GAELIC_SCOTTISH            0x02
2324 #define SUBLANG_GAELIC_MANX                0x03
2325
2326
2327 /*
2328  * Sort definitions
2329  */
2330
2331 #define SORT_DEFAULT                     0x0
2332 #define SORT_JAPANESE_XJIS               0x0
2333 #define SORT_JAPANESE_UNICODE            0x1
2334 #define SORT_CHINESE_BIG5                0x0
2335 #define SORT_CHINESE_UNICODE             0x1
2336 #define SORT_KOREAN_KSC                  0x0
2337 #define SORT_KOREAN_UNICODE              0x1
2338
2339
2340
2341 /*
2342  * Definitions for IsTextUnicode()
2343  */
2344
2345 #define IS_TEXT_UNICODE_ASCII16            0x0001
2346 #define IS_TEXT_UNICODE_STATISTICS         0x0002
2347 #define IS_TEXT_UNICODE_CONTROLS           0x0004
2348 #define IS_TEXT_UNICODE_SIGNATURE          0x0008
2349 #define IS_TEXT_UNICODE_UNICODE_MASK       0x000F
2350 #define IS_TEXT_UNICODE_REVERSE_ASCII16    0x0010
2351 #define IS_TEXT_UNICODE_REVERSE_STATISTICS 0x0020
2352 #define IS_TEXT_UNICODE_REVERSE_CONTROLS   0x0040
2353 #define IS_TEXT_UNICODE_REVERSE_SIGNATURE  0x0080
2354 #define IS_TEXT_UNICODE_REVERSE_MASK       0x00F0
2355 #define IS_TEXT_UNICODE_ILLEGAL_CHARS      0x0100
2356 #define IS_TEXT_UNICODE_ODD_LENGTH         0x0200
2357 #define IS_TEXT_UNICODE_DBCS_LEADBYTE      0x0400
2358 #define IS_TEXT_UNICODE_NOT_UNICODE_MASK   0x0F00
2359 #define IS_TEXT_UNICODE_NULL_BYTES         0x1000
2360 #define IS_TEXT_UNICODE_NOT_ASCII_MASK     0xF000
2361
2362 #define MAXIMUM_WAIT_OBJECTS 64
2363 #define MAXIMUM_SUSPEND_COUNT 127
2364
2365 #define WT_EXECUTEDEFAULT              0x00
2366 #define WT_EXECUTEINIOTHREAD           0x01
2367 #define WT_EXECUTEINUITHREAD           0x02
2368 #define WT_EXECUTEINWAITTHREAD         0x04
2369 #define WT_EXECUTEONLYONCE             0x08
2370 #define WT_EXECUTELONGFUNCTION         0x10
2371 #define WT_EXECUTEINTIMERTHREAD        0x20
2372 #define WT_EXECUTEINPERSISTENTIOTHREAD 0x40
2373 #define WT_EXECUTEINPERSISTENTTHREAD   0x80
2374 #define WT_EXECUTEINLONGTHREAD         0x10
2375 #define WT_EXECUTEDELETEWAIT           0x08
2376 #define WT_TRANSFER_IMPERSONATION      0x0100
2377
2378
2379 #define EXCEPTION_CONTINUABLE        0
2380 #define EXCEPTION_NONCONTINUABLE     0x01
2381
2382 /*
2383  * The exception record used by Win32 to give additional information
2384  * about exception to exception handlers.
2385  */
2386
2387 #define EXCEPTION_MAXIMUM_PARAMETERS 15
2388
2389 typedef struct _EXCEPTION_RECORD
2390 {
2391     DWORD    ExceptionCode;
2392     DWORD    ExceptionFlags;
2393     struct  _EXCEPTION_RECORD *ExceptionRecord;
2394
2395     PVOID    ExceptionAddress;
2396     DWORD    NumberParameters;
2397     ULONG_PTR ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
2398 } EXCEPTION_RECORD, *PEXCEPTION_RECORD;
2399
2400 /*
2401  * The exception pointers structure passed to exception filters
2402  * in except() and the UnhandledExceptionFilter().
2403  */
2404
2405 typedef struct _EXCEPTION_POINTERS
2406 {
2407   PEXCEPTION_RECORD  ExceptionRecord;
2408   PCONTEXT           ContextRecord;
2409 } EXCEPTION_POINTERS, *PEXCEPTION_POINTERS;
2410
2411
2412 /*
2413  * The exception frame, used for registering exception handlers
2414  * Win32 cares only about this, but compilers generally emit
2415  * larger exception frames for their own use.
2416  */
2417
2418 struct _EXCEPTION_REGISTRATION_RECORD;
2419
2420 typedef DWORD (*PEXCEPTION_HANDLER)(PEXCEPTION_RECORD,struct _EXCEPTION_REGISTRATION_RECORD*,
2421                                     PCONTEXT,struct _EXCEPTION_REGISTRATION_RECORD **);
2422
2423 typedef struct _EXCEPTION_REGISTRATION_RECORD
2424 {
2425   struct _EXCEPTION_REGISTRATION_RECORD *Prev;
2426   PEXCEPTION_HANDLER       Handler;
2427 } EXCEPTION_REGISTRATION_RECORD;
2428
2429 /*
2430  * function pointer to an exception filter
2431  */
2432
2433 typedef LONG (CALLBACK *PVECTORED_EXCEPTION_HANDLER)(PEXCEPTION_POINTERS ExceptionInfo);
2434
2435 typedef struct _NT_TIB
2436 {
2437         struct _EXCEPTION_REGISTRATION_RECORD *ExceptionList;
2438         PVOID StackBase;
2439         PVOID StackLimit;
2440         PVOID SubSystemTib;
2441         union {
2442           PVOID FiberData;
2443           DWORD Version;
2444         } DUMMYUNIONNAME;
2445         PVOID ArbitraryUserPointer;
2446         struct _NT_TIB *Self;
2447 } NT_TIB, *PNT_TIB;
2448
2449 struct _TEB;
2450
2451 #if defined(__i386__) && defined(__GNUC__) && ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 2)))
2452 static FORCEINLINE struct _TEB * WINAPI NtCurrentTeb(void)
2453 {
2454     struct _TEB *teb;
2455     __asm__(".byte 0x64\n\tmovl (0x18),%0" : "=r" (teb));
2456     return teb;
2457 }
2458 #elif defined(__i386__) && defined(_MSC_VER)
2459 static FORCEINLINE struct _TEB * WINAPI NtCurrentTeb(void)
2460 {
2461   struct _TEB *teb;
2462   __asm mov eax, fs:[0x18];
2463   __asm mov teb, eax;
2464   return teb;
2465 }
2466 #elif defined(__x86_64__) && defined(__GNUC__)
2467 static FORCEINLINE struct _TEB * WINAPI NtCurrentTeb(void)
2468 {
2469     struct _TEB *teb;
2470     __asm__(".byte 0x65\n\tmovq (0x30),%0" : "=r" (teb));
2471     return teb;
2472 }
2473 #elif defined(__x86_64__) && defined (_MSC_VER)
2474 static FORCEINLINE struct _TEB * WINAPI NtCurrentTeb(void)
2475 {
2476   struct _TEB *teb;
2477   __asm mov rax, gs:[0x30];
2478   __asm mov teb, rax;
2479   return teb;
2480 }
2481 #else
2482 extern struct _TEB * WINAPI NtCurrentTeb(void);
2483 #endif
2484
2485 #ifdef NONAMELESSUNION
2486 #define GetCurrentFiber()  (((NT_TIB *)NtCurrentTeb())->u.FiberData)
2487 #else
2488 #define GetCurrentFiber()  (((NT_TIB *)NtCurrentTeb())->FiberData)
2489 #endif
2490 #define GetFiberData()     (*(void **)GetCurrentFiber())
2491
2492 #define TLS_MINIMUM_AVAILABLE 64
2493
2494 /*
2495  * File formats definitions
2496  */
2497
2498 #include <pshpack2.h>
2499 typedef struct _IMAGE_DOS_HEADER {
2500     WORD  e_magic;      /* 00: MZ Header signature */
2501     WORD  e_cblp;       /* 02: Bytes on last page of file */
2502     WORD  e_cp;         /* 04: Pages in file */
2503     WORD  e_crlc;       /* 06: Relocations */
2504     WORD  e_cparhdr;    /* 08: Size of header in paragraphs */
2505     WORD  e_minalloc;   /* 0a: Minimum extra paragraphs needed */
2506     WORD  e_maxalloc;   /* 0c: Maximum extra paragraphs needed */
2507     WORD  e_ss;         /* 0e: Initial (relative) SS value */
2508     WORD  e_sp;         /* 10: Initial SP value */
2509     WORD  e_csum;       /* 12: Checksum */
2510     WORD  e_ip;         /* 14: Initial IP value */
2511     WORD  e_cs;         /* 16: Initial (relative) CS value */
2512     WORD  e_lfarlc;     /* 18: File address of relocation table */
2513     WORD  e_ovno;       /* 1a: Overlay number */
2514     WORD  e_res[4];     /* 1c: Reserved words */
2515     WORD  e_oemid;      /* 24: OEM identifier (for e_oeminfo) */
2516     WORD  e_oeminfo;    /* 26: OEM information; e_oemid specific */
2517     WORD  e_res2[10];   /* 28: Reserved words */
2518     DWORD e_lfanew;     /* 3c: Offset to extended header */
2519 } IMAGE_DOS_HEADER, *PIMAGE_DOS_HEADER;
2520 #include <poppack.h>
2521
2522 #define IMAGE_DOS_SIGNATURE    0x5A4D     /* MZ   */
2523 #define IMAGE_OS2_SIGNATURE    0x454E     /* NE   */
2524 #define IMAGE_OS2_SIGNATURE_LE 0x454C     /* LE   */
2525 #define IMAGE_OS2_SIGNATURE_LX 0x584C     /* LX */
2526 #define IMAGE_VXD_SIGNATURE    0x454C     /* LE   */
2527 #define IMAGE_NT_SIGNATURE     0x00004550 /* PE00 */
2528
2529 /*
2530  * This is the Windows executable (NE) header.
2531  * the name IMAGE_OS2_HEADER is misleading, but in the SDK this way.
2532  */
2533 #include <pshpack2.h>
2534 typedef struct
2535 {
2536     WORD  ne_magic;             /* 00 NE signature 'NE' */
2537     BYTE  ne_ver;               /* 02 Linker version number */
2538     BYTE  ne_rev;               /* 03 Linker revision number */
2539     WORD  ne_enttab;            /* 04 Offset to entry table relative to NE */
2540     WORD  ne_cbenttab;          /* 06 Length of entry table in bytes */
2541     LONG  ne_crc;               /* 08 Checksum */
2542     WORD  ne_flags;             /* 0c Flags about segments in this file */
2543     WORD  ne_autodata;          /* 0e Automatic data segment number */
2544     WORD  ne_heap;              /* 10 Initial size of local heap */
2545     WORD  ne_stack;             /* 12 Initial size of stack */
2546     DWORD ne_csip;              /* 14 Initial CS:IP */
2547     DWORD ne_sssp;              /* 18 Initial SS:SP */
2548     WORD  ne_cseg;              /* 1c # of entries in segment table */
2549     WORD  ne_cmod;              /* 1e # of entries in module reference tab. */
2550     WORD  ne_cbnrestab;         /* 20 Length of nonresident-name table     */
2551     WORD  ne_segtab;            /* 22 Offset to segment table */
2552     WORD  ne_rsrctab;           /* 24 Offset to resource table */
2553     WORD  ne_restab;            /* 26 Offset to resident-name table */
2554     WORD  ne_modtab;            /* 28 Offset to module reference table */
2555     WORD  ne_imptab;            /* 2a Offset to imported name table */
2556     DWORD ne_nrestab;           /* 2c Offset to nonresident-name table */
2557     WORD  ne_cmovent;           /* 30 # of movable entry points */
2558     WORD  ne_align;             /* 32 Logical sector alignment shift count */
2559     WORD  ne_cres;              /* 34 # of resource segments */
2560     BYTE  ne_exetyp;            /* 36 Flags indicating target OS */
2561     BYTE  ne_flagsothers;       /* 37 Additional information flags */
2562     WORD  ne_pretthunks;        /* 38 Offset to return thunks */
2563     WORD  ne_psegrefbytes;      /* 3a Offset to segment ref. bytes */
2564     WORD  ne_swaparea;          /* 3c Reserved by Microsoft */
2565     WORD  ne_expver;            /* 3e Expected Windows version number */
2566 } IMAGE_OS2_HEADER, *PIMAGE_OS2_HEADER;
2567 #include <poppack.h>
2568
2569 #include <pshpack2.h>
2570 typedef struct _IMAGE_VXD_HEADER {
2571   WORD  e32_magic;
2572   BYTE  e32_border;
2573   BYTE  e32_worder;
2574   DWORD e32_level;
2575   WORD  e32_cpu;
2576   WORD  e32_os;
2577   DWORD e32_ver;
2578   DWORD e32_mflags;
2579   DWORD e32_mpages;
2580   DWORD e32_startobj;
2581   DWORD e32_eip;
2582   DWORD e32_stackobj;
2583   DWORD e32_esp;
2584   DWORD e32_pagesize;
2585   DWORD e32_lastpagesize;
2586   DWORD e32_fixupsize;
2587   DWORD e32_fixupsum;
2588   DWORD e32_ldrsize;
2589   DWORD e32_ldrsum;
2590   DWORD e32_objtab;
2591   DWORD e32_objcnt;
2592   DWORD e32_objmap;
2593   DWORD e32_itermap;
2594   DWORD e32_rsrctab;
2595   DWORD e32_rsrccnt;
2596   DWORD e32_restab;
2597   DWORD e32_enttab;
2598   DWORD e32_dirtab;
2599   DWORD e32_dircnt;
2600   DWORD e32_fpagetab;
2601   DWORD e32_frectab;
2602   DWORD e32_impmod;
2603   DWORD e32_impmodcnt;
2604   DWORD e32_impproc;
2605   DWORD e32_pagesum;
2606   DWORD e32_datapage;
2607   DWORD e32_preload;
2608   DWORD e32_nrestab;
2609   DWORD e32_cbnrestab;
2610   DWORD e32_nressum;
2611   DWORD e32_autodata;
2612   DWORD e32_debuginfo;
2613   DWORD e32_debuglen;
2614   DWORD e32_instpreload;
2615   DWORD e32_instdemand;
2616   DWORD e32_heapsize;
2617   BYTE  e32_res3[12];
2618   DWORD e32_winresoff;
2619   DWORD e32_winreslen;
2620   WORD  e32_devid;
2621   WORD  e32_ddkver;
2622 } IMAGE_VXD_HEADER, *PIMAGE_VXD_HEADER;
2623 #include <poppack.h>
2624
2625 /* These defines describe the meanings of the bits in the Characteristics
2626    field */
2627
2628 #define IMAGE_FILE_RELOCS_STRIPPED      0x0001 /* No relocation info */
2629 #define IMAGE_FILE_EXECUTABLE_IMAGE     0x0002
2630 #define IMAGE_FILE_LINE_NUMS_STRIPPED   0x0004
2631 #define IMAGE_FILE_LOCAL_SYMS_STRIPPED  0x0008
2632 #define IMAGE_FILE_AGGRESIVE_WS_TRIM    0x0010
2633 #define IMAGE_FILE_LARGE_ADDRESS_AWARE  0x0020
2634 #define IMAGE_FILE_16BIT_MACHINE        0x0040
2635 #define IMAGE_FILE_BYTES_REVERSED_LO    0x0080
2636 #define IMAGE_FILE_32BIT_MACHINE        0x0100
2637 #define IMAGE_FILE_DEBUG_STRIPPED       0x0200
2638 #define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP      0x0400
2639 #define IMAGE_FILE_NET_RUN_FROM_SWAP    0x0800
2640 #define IMAGE_FILE_SYSTEM               0x1000
2641 #define IMAGE_FILE_DLL                  0x2000
2642 #define IMAGE_FILE_UP_SYSTEM_ONLY       0x4000
2643 #define IMAGE_FILE_BYTES_REVERSED_HI    0x8000
2644
2645 /* These are the settings of the Machine field. */
2646 #define IMAGE_FILE_MACHINE_UNKNOWN      0
2647 #define IMAGE_FILE_MACHINE_I860         0x014d
2648 #define IMAGE_FILE_MACHINE_I386         0x014c
2649 #define IMAGE_FILE_MACHINE_R3000        0x0162
2650 #define IMAGE_FILE_MACHINE_R4000        0x0166
2651 #define IMAGE_FILE_MACHINE_R10000       0x0168
2652 #define IMAGE_FILE_MACHINE_WCEMIPSV2    0x0169
2653 #define IMAGE_FILE_MACHINE_ALPHA        0x0184
2654 #define IMAGE_FILE_MACHINE_SH3          0x01a2
2655 #define IMAGE_FILE_MACHINE_SH3DSP       0x01a3
2656 #define IMAGE_FILE_MACHINE_SH3E         0x01a4
2657 #define IMAGE_FILE_MACHINE_SH4          0x01a6
2658 #define IMAGE_FILE_MACHINE_SH5          0x01a8
2659 #define IMAGE_FILE_MACHINE_ARM          0x01c0
2660 #define IMAGE_FILE_MACHINE_THUMB        0x01c2
2661 #define IMAGE_FILE_MACHINE_AM33         0x01d3
2662 #define IMAGE_FILE_MACHINE_POWERPC      0x01f0
2663 #define IMAGE_FILE_MACHINE_POWERPCFP    0x01f1
2664 #define IMAGE_FILE_MACHINE_IA64         0x0200
2665 #define IMAGE_FILE_MACHINE_MIPS16       0x0266
2666 #define IMAGE_FILE_MACHINE_ALPHA64      0x0284
2667 #define IMAGE_FILE_MACHINE_MIPSFPU      0x0366
2668 #define IMAGE_FILE_MACHINE_MIPSFPU16    0x0466
2669 #define IMAGE_FILE_MACHINE_AXP64        IMAGE_FILE_MACHINE_ALPHA64
2670 #define IMAGE_FILE_MACHINE_TRICORE      0x0520
2671 #define IMAGE_FILE_MACHINE_CEF          0x0cef
2672 #define IMAGE_FILE_MACHINE_EBC          0x0ebc
2673 #define IMAGE_FILE_MACHINE_AMD64        0x8664
2674 #define IMAGE_FILE_MACHINE_M32R         0x9041
2675 #define IMAGE_FILE_MACHINE_CEE          0xc0ee
2676
2677 /* Wine extension */
2678 #define IMAGE_FILE_MACHINE_SPARC        0x2000
2679
2680 #define IMAGE_SIZEOF_FILE_HEADER                20
2681 #define IMAGE_SIZEOF_ROM_OPTIONAL_HEADER        56
2682 #define IMAGE_SIZEOF_STD_OPTIONAL_HEADER        28
2683 #define IMAGE_SIZEOF_NT_OPTIONAL32_HEADER       224
2684 #define IMAGE_SIZEOF_NT_OPTIONAL64_HEADER       240
2685 #define IMAGE_SIZEOF_SHORT_NAME                 8
2686 #define IMAGE_SIZEOF_SECTION_HEADER             40
2687 #define IMAGE_SIZEOF_SYMBOL                     18
2688 #define IMAGE_SIZEOF_AUX_SYMBOL                 18
2689 #define IMAGE_SIZEOF_RELOCATION                 10
2690 #define IMAGE_SIZEOF_BASE_RELOCATION            8
2691 #define IMAGE_SIZEOF_LINENUMBER                 6
2692 #define IMAGE_SIZEOF_ARCHIVE_MEMBER_HDR         60
2693
2694 /* Possible Magic values */
2695 #define IMAGE_NT_OPTIONAL_HDR32_MAGIC      0x10b
2696 #define IMAGE_NT_OPTIONAL_HDR64_MAGIC      0x20b
2697 #define IMAGE_ROM_OPTIONAL_HDR_MAGIC       0x107
2698
2699 #ifdef _WIN64
2700 #define IMAGE_SIZEOF_NT_OPTIONAL_HEADER IMAGE_SIZEOF_NT_OPTIONAL64_HEADER
2701 #define IMAGE_NT_OPTIONAL_HDR_MAGIC     IMAGE_NT_OPTIONAL_HDR64_MAGIC
2702 #else
2703 #define IMAGE_SIZEOF_NT_OPTIONAL_HEADER IMAGE_SIZEOF_NT_OPTIONAL32_HEADER
2704 #define IMAGE_NT_OPTIONAL_HDR_MAGIC     IMAGE_NT_OPTIONAL_HDR32_MAGIC
2705 #endif
2706
2707 /* These are indexes into the DataDirectory array */
2708 #define IMAGE_FILE_EXPORT_DIRECTORY             0
2709 #define IMAGE_FILE_IMPORT_DIRECTORY             1
2710 #define IMAGE_FILE_RESOURCE_DIRECTORY           2
2711 #define IMAGE_FILE_EXCEPTION_DIRECTORY          3
2712 #define IMAGE_FILE_SECURITY_DIRECTORY           4
2713 #define IMAGE_FILE_BASE_RELOCATION_TABLE        5
2714 #define IMAGE_FILE_DEBUG_DIRECTORY              6
2715 #define IMAGE_FILE_DESCRIPTION_STRING           7
2716 #define IMAGE_FILE_MACHINE_VALUE                8  /* Mips */
2717 #define IMAGE_FILE_THREAD_LOCAL_STORAGE         9
2718 #define IMAGE_FILE_CALLBACK_DIRECTORY           10
2719
2720 /* Directory Entries, indices into the DataDirectory array */
2721
2722 #define IMAGE_DIRECTORY_ENTRY_EXPORT            0
2723 #define IMAGE_DIRECTORY_ENTRY_IMPORT            1
2724 #define IMAGE_DIRECTORY_ENTRY_RESOURCE          2
2725 #define IMAGE_DIRECTORY_ENTRY_EXCEPTION         3
2726 #define IMAGE_DIRECTORY_ENTRY_SECURITY          4
2727 #define IMAGE_DIRECTORY_ENTRY_BASERELOC         5
2728 #define IMAGE_DIRECTORY_ENTRY_DEBUG             6
2729 #define IMAGE_DIRECTORY_ENTRY_COPYRIGHT         7
2730 #define IMAGE_DIRECTORY_ENTRY_GLOBALPTR         8   /* (MIPS GP) */
2731 #define IMAGE_DIRECTORY_ENTRY_TLS               9
2732 #define IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG       10
2733 #define IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT      11
2734 #define IMAGE_DIRECTORY_ENTRY_IAT               12  /* Import Address Table */
2735 #define IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT      13
2736 #define IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR    14
2737
2738 /* Subsystem Values */
2739
2740 #define IMAGE_SUBSYSTEM_UNKNOWN                 0
2741 #define IMAGE_SUBSYSTEM_NATIVE                  1
2742 #define IMAGE_SUBSYSTEM_WINDOWS_GUI             2       /* Windows GUI subsystem */
2743 #define IMAGE_SUBSYSTEM_WINDOWS_CUI             3       /* Windows character subsystem */
2744 #define IMAGE_SUBSYSTEM_OS2_CUI                 5
2745 #define IMAGE_SUBSYSTEM_POSIX_CUI               7
2746 #define IMAGE_SUBSYSTEM_NATIVE_WINDOWS          8       /* native Win9x driver */
2747 #define IMAGE_SUBSYSTEM_WINDOWS_CE_GUI          9       /* Windows CE subsystem */
2748 #define IMAGE_SUBSYSTEM_EFI_APPLICATION         10
2749 #define IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER 11
2750 #define IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER      12
2751 #define IMAGE_SUBSYSTEM_EFI_ROM                 13
2752 #define IMAGE_SUBSYSTEM_XBOX                    14
2753 #define IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION        16
2754
2755 /* DLL Characteristics */
2756 #define IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE          0x0040
2757 #define IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY       0x0080
2758 #define IMAGE_DLLCHARACTERISTICS_NX_COMPAT             0x0100
2759 #define IMAGE_DLLCHARACTERISTICS_NO_ISOLATION          0x0200
2760 #define IMAGE_DLLCHARACTERISTICS_NO_SEH                0x0400
2761 #define IMAGE_DLLCHARACTERISTICS_NO_BIND               0x0800
2762 #define IMAGE_DLLCHARACTERISTICS_WDM_DRIVER            0x2000
2763 #define IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE 0x8000
2764
2765 typedef struct _IMAGE_FILE_HEADER {
2766   WORD  Machine;
2767   WORD  NumberOfSections;
2768   DWORD TimeDateStamp;
2769   DWORD PointerToSymbolTable;
2770   DWORD NumberOfSymbols;
2771   WORD  SizeOfOptionalHeader;
2772   WORD  Characteristics;
2773 } IMAGE_FILE_HEADER, *PIMAGE_FILE_HEADER;
2774
2775 typedef struct _IMAGE_DATA_DIRECTORY {
2776   DWORD VirtualAddress;
2777   DWORD Size;
2778 } IMAGE_DATA_DIRECTORY, *PIMAGE_DATA_DIRECTORY;
2779
2780 #define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 16
2781
2782 typedef struct _IMAGE_OPTIONAL_HEADER64 {
2783   WORD  Magic; /* 0x20b */
2784   BYTE MajorLinkerVersion;
2785   BYTE MinorLinkerVersion;
2786   DWORD SizeOfCode;
2787   DWORD SizeOfInitializedData;
2788   DWORD SizeOfUninitializedData;
2789   DWORD AddressOfEntryPoint;
2790   DWORD BaseOfCode;
2791   ULONGLONG ImageBase;
2792   DWORD SectionAlignment;
2793   DWORD FileAlignment;
2794   WORD MajorOperatingSystemVersion;
2795   WORD MinorOperatingSystemVersion;
2796   WORD MajorImageVersion;
2797   WORD MinorImageVersion;
2798   WORD MajorSubsystemVersion;
2799   WORD MinorSubsystemVersion;
2800   DWORD Win32VersionValue;
2801   DWORD SizeOfImage;
2802   DWORD SizeOfHeaders;
2803   DWORD CheckSum;
2804   WORD Subsystem;
2805   WORD DllCharacteristics;
2806   ULONGLONG SizeOfStackReserve;
2807   ULONGLONG SizeOfStackCommit;
2808   ULONGLONG SizeOfHeapReserve;
2809   ULONGLONG SizeOfHeapCommit;
2810   DWORD LoaderFlags;
2811   DWORD NumberOfRvaAndSizes;
2812   IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
2813 } IMAGE_OPTIONAL_HEADER64, *PIMAGE_OPTIONAL_HEADER64;
2814
2815 typedef struct _IMAGE_NT_HEADERS64 {
2816   DWORD Signature;
2817   IMAGE_FILE_HEADER FileHeader;
2818   IMAGE_OPTIONAL_HEADER64 OptionalHeader;
2819 } IMAGE_NT_HEADERS64, *PIMAGE_NT_HEADERS64;
2820
2821 typedef struct _IMAGE_OPTIONAL_HEADER {
2822
2823   /* Standard fields */
2824
2825   WORD  Magic; /* 0x10b or 0x107 */     /* 0x00 */
2826   BYTE  MajorLinkerVersion;
2827   BYTE  MinorLinkerVersion;
2828   DWORD SizeOfCode;
2829   DWORD SizeOfInitializedData;
2830   DWORD SizeOfUninitializedData;
2831   DWORD AddressOfEntryPoint;            /* 0x10 */
2832   DWORD BaseOfCode;
2833   DWORD BaseOfData;
2834
2835   /* NT additional fields */
2836
2837   DWORD ImageBase;
2838   DWORD SectionAlignment;               /* 0x20 */
2839   DWORD FileAlignment;
2840   WORD  MajorOperatingSystemVersion;
2841   WORD  MinorOperatingSystemVersion;
2842   WORD  MajorImageVersion;
2843   WORD  MinorImageVersion;
2844   WORD  MajorSubsystemVersion;          /* 0x30 */
2845   WORD  MinorSubsystemVersion;
2846   DWORD Win32VersionValue;
2847   DWORD SizeOfImage;
2848   DWORD SizeOfHeaders;
2849   DWORD CheckSum;                       /* 0x40 */
2850   WORD  Subsystem;
2851   WORD  DllCharacteristics;
2852   DWORD SizeOfStackReserve;
2853   DWORD SizeOfStackCommit;
2854   DWORD SizeOfHeapReserve;              /* 0x50 */
2855   DWORD SizeOfHeapCommit;
2856   DWORD LoaderFlags;
2857   DWORD NumberOfRvaAndSizes;
2858   IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; /* 0x60 */
2859   /* 0xE0 */
2860 } IMAGE_OPTIONAL_HEADER32, *PIMAGE_OPTIONAL_HEADER32;
2861
2862 typedef struct _IMAGE_NT_HEADERS {
2863   DWORD Signature; /* "PE"\0\0 */       /* 0x00 */
2864   IMAGE_FILE_HEADER FileHeader;         /* 0x04 */
2865   IMAGE_OPTIONAL_HEADER32 OptionalHeader;       /* 0x18 */
2866 } IMAGE_NT_HEADERS32, *PIMAGE_NT_HEADERS32;
2867
2868 #ifdef _WIN64
2869 typedef IMAGE_NT_HEADERS64  IMAGE_NT_HEADERS;
2870 typedef PIMAGE_NT_HEADERS64 PIMAGE_NT_HEADERS;
2871 typedef IMAGE_OPTIONAL_HEADER64 IMAGE_OPTIONAL_HEADER;
2872 typedef PIMAGE_OPTIONAL_HEADER64 PIMAGE_OPTIONAL_HEADER;
2873 #else
2874 typedef IMAGE_NT_HEADERS32  IMAGE_NT_HEADERS;
2875 typedef PIMAGE_NT_HEADERS32 PIMAGE_NT_HEADERS;
2876 typedef IMAGE_OPTIONAL_HEADER32 IMAGE_OPTIONAL_HEADER;
2877 typedef PIMAGE_OPTIONAL_HEADER32 PIMAGE_OPTIONAL_HEADER;
2878 #endif
2879
2880 #define IMAGE_SIZEOF_SHORT_NAME 8
2881
2882 typedef struct _IMAGE_SECTION_HEADER {
2883   BYTE  Name[IMAGE_SIZEOF_SHORT_NAME];
2884   union {
2885     DWORD PhysicalAddress;
2886     DWORD VirtualSize;
2887   } Misc;
2888   DWORD VirtualAddress;
2889   DWORD SizeOfRawData;
2890   DWORD PointerToRawData;
2891   DWORD PointerToRelocations;
2892   DWORD PointerToLinenumbers;
2893   WORD  NumberOfRelocations;
2894   WORD  NumberOfLinenumbers;
2895   DWORD Characteristics;
2896 } IMAGE_SECTION_HEADER, *PIMAGE_SECTION_HEADER;
2897
2898 #define IMAGE_SIZEOF_SECTION_HEADER 40
2899
2900 #define IMAGE_FIRST_SECTION(ntheader) \
2901   ((PIMAGE_SECTION_HEADER)(ULONG_PTR)((const BYTE *)&((const IMAGE_NT_HEADERS *)(ntheader))->OptionalHeader + \
2902                            ((const IMAGE_NT_HEADERS *)(ntheader))->FileHeader.SizeOfOptionalHeader))
2903
2904 /* These defines are for the Characteristics bitfield. */
2905 /* #define IMAGE_SCN_TYPE_REG                   0x00000000 - Reserved */
2906 /* #define IMAGE_SCN_TYPE_DSECT                 0x00000001 - Reserved */
2907 /* #define IMAGE_SCN_TYPE_NOLOAD                0x00000002 - Reserved */
2908 /* #define IMAGE_SCN_TYPE_GROUP                 0x00000004 - Reserved */
2909 #define IMAGE_SCN_TYPE_NO_PAD                   0x00000008 /* Reserved */
2910 /* #define IMAGE_SCN_TYPE_COPY                  0x00000010 - Reserved */
2911
2912 #define IMAGE_SCN_CNT_CODE                      0x00000020
2913 #define IMAGE_SCN_CNT_INITIALIZED_DATA          0x00000040
2914 #define IMAGE_SCN_CNT_UNINITIALIZED_DATA        0x00000080
2915
2916 #define IMAGE_SCN_LNK_OTHER                     0x00000100
2917 #define IMAGE_SCN_LNK_INFO                      0x00000200
2918 /* #define      IMAGE_SCN_TYPE_OVER             0x00000400 - Reserved */
2919 #define IMAGE_SCN_LNK_REMOVE                    0x00000800
2920 #define IMAGE_SCN_LNK_COMDAT                    0x00001000
2921
2922 /*                                              0x00002000 - Reserved */
2923 /* #define IMAGE_SCN_MEM_PROTECTED              0x00004000 - Obsolete */
2924 #define IMAGE_SCN_MEM_FARDATA                   0x00008000
2925
2926 /* #define IMAGE_SCN_MEM_SYSHEAP                0x00010000 - Obsolete */
2927 #define IMAGE_SCN_MEM_PURGEABLE                 0x00020000
2928 #define IMAGE_SCN_MEM_16BIT                     0x00020000
2929 #define IMAGE_SCN_MEM_LOCKED                    0x00040000
2930 #define IMAGE_SCN_MEM_PRELOAD                   0x00080000
2931
2932 #define IMAGE_SCN_ALIGN_1BYTES                  0x00100000
2933 #define IMAGE_SCN_ALIGN_2BYTES                  0x00200000
2934 #define IMAGE_SCN_ALIGN_4BYTES                  0x00300000
2935 #define IMAGE_SCN_ALIGN_8BYTES                  0x00400000
2936 #define IMAGE_SCN_ALIGN_16BYTES                 0x00500000  /* Default */
2937 #define IMAGE_SCN_ALIGN_32BYTES                 0x00600000
2938 #define IMAGE_SCN_ALIGN_64BYTES                 0x00700000
2939 #define IMAGE_SCN_ALIGN_128BYTES                0x00800000
2940 #define IMAGE_SCN_ALIGN_256BYTES                0x00900000
2941 #define IMAGE_SCN_ALIGN_512BYTES                0x00A00000
2942 #define IMAGE_SCN_ALIGN_1024BYTES               0x00B00000
2943 #define IMAGE_SCN_ALIGN_2048BYTES               0x00C00000
2944 #define IMAGE_SCN_ALIGN_4096BYTES               0x00D00000
2945 #define IMAGE_SCN_ALIGN_8192BYTES               0x00E00000
2946 /*                                              0x00F00000 - Unused */
2947 #define IMAGE_SCN_ALIGN_MASK                    0x00F00000
2948
2949 #define IMAGE_SCN_LNK_NRELOC_OVFL               0x01000000
2950
2951
2952 #define IMAGE_SCN_MEM_DISCARDABLE               0x02000000
2953 #define IMAGE_SCN_MEM_NOT_CACHED                0x04000000
2954 #define IMAGE_SCN_MEM_NOT_PAGED                 0x08000000
2955 #define IMAGE_SCN_MEM_SHARED                    0x10000000
2956 #define IMAGE_SCN_MEM_EXECUTE                   0x20000000
2957 #define IMAGE_SCN_MEM_READ                      0x40000000
2958 #define IMAGE_SCN_MEM_WRITE                     0x80000000
2959
2960 #include <pshpack2.h>
2961
2962 typedef struct _IMAGE_SYMBOL {
2963     union {
2964         BYTE    ShortName[8];
2965         struct {
2966             DWORD   Short;
2967             DWORD   Long;
2968         } Name;
2969         DWORD   LongName[2];
2970     } N;
2971     DWORD   Value;
2972     SHORT   SectionNumber;
2973     WORD    Type;
2974     BYTE    StorageClass;
2975     BYTE    NumberOfAuxSymbols;
2976 } IMAGE_SYMBOL;
2977 typedef IMAGE_SYMBOL *PIMAGE_SYMBOL;
2978
2979 #define IMAGE_SIZEOF_SYMBOL 18
2980
2981 typedef struct _IMAGE_LINENUMBER {
2982     union {
2983         DWORD   SymbolTableIndex;
2984         DWORD   VirtualAddress;
2985     } Type;
2986     WORD    Linenumber;
2987 } IMAGE_LINENUMBER;
2988 typedef IMAGE_LINENUMBER *PIMAGE_LINENUMBER;
2989
2990 #define IMAGE_SIZEOF_LINENUMBER  6
2991
2992 typedef union _IMAGE_AUX_SYMBOL {
2993     struct {
2994         DWORD    TagIndex;
2995         union {
2996             struct {
2997                 WORD    Linenumber;
2998                 WORD    Size;
2999             } LnSz;
3000            DWORD    TotalSize;
3001         } Misc;
3002         union {
3003             struct {
3004                 DWORD    PointerToLinenumber;
3005                 DWORD    PointerToNextFunction;
3006             } Function;
3007             struct {
3008                 WORD     Dimension[4];
3009             } Array;
3010         } FcnAry;
3011         WORD    TvIndex;
3012     } Sym;
3013     struct {
3014         BYTE    Name[IMAGE_SIZEOF_SYMBOL];
3015     } File;
3016     struct {
3017         DWORD   Length;
3018         WORD    NumberOfRelocations;
3019         WORD    NumberOfLinenumbers;
3020         DWORD   CheckSum;
3021         SHORT   Number;
3022         BYTE    Selection;
3023     } Section;
3024 } IMAGE_AUX_SYMBOL;
3025 typedef IMAGE_AUX_SYMBOL *PIMAGE_AUX_SYMBOL;
3026
3027 #define IMAGE_SIZEOF_AUX_SYMBOL 18
3028
3029 #include <poppack.h>
3030
3031 #define IMAGE_SYM_UNDEFINED           (SHORT)0
3032 #define IMAGE_SYM_ABSOLUTE            (SHORT)-1
3033 #define IMAGE_SYM_DEBUG               (SHORT)-2
3034
3035 #define IMAGE_SYM_TYPE_NULL                 0x0000
3036 #define IMAGE_SYM_TYPE_VOID                 0x0001
3037 #define IMAGE_SYM_TYPE_CHAR                 0x0002
3038 #define IMAGE_SYM_TYPE_SHORT                0x0003
3039 #define IMAGE_SYM_TYPE_INT                  0x0004
3040 #define IMAGE_SYM_TYPE_LONG                 0x0005
3041 #define IMAGE_SYM_TYPE_FLOAT                0x0006
3042 #define IMAGE_SYM_TYPE_DOUBLE               0x0007
3043 #define IMAGE_SYM_TYPE_STRUCT               0x0008
3044 #define IMAGE_SYM_TYPE_UNION                0x0009
3045 #define IMAGE_SYM_TYPE_ENUM                 0x000A
3046 #define IMAGE_SYM_TYPE_MOE                  0x000B
3047 #define IMAGE_SYM_TYPE_BYTE                 0x000C
3048 #define IMAGE_SYM_TYPE_WORD                 0x000D
3049 #define IMAGE_SYM_TYPE_UINT                 0x000E
3050 #define IMAGE_SYM_TYPE_DWORD                0x000F
3051 #define IMAGE_SYM_TYPE_PCODE                0x8000
3052
3053 #define IMAGE_SYM_DTYPE_NULL                0
3054 #define IMAGE_SYM_DTYPE_POINTER             1
3055 #define IMAGE_SYM_DTYPE_FUNCTION            2
3056 #define IMAGE_SYM_DTYPE_ARRAY               3
3057
3058 #define IMAGE_SYM_CLASS_END_OF_FUNCTION     (BYTE )-1
3059 #define IMAGE_SYM_CLASS_NULL                0x0000
3060 #define IMAGE_SYM_CLASS_AUTOMATIC           0x0001
3061 #define IMAGE_SYM_CLASS_EXTERNAL            0x0002
3062 #define IMAGE_SYM_CLASS_STATIC              0x0003
3063 #define IMAGE_SYM_CLASS_REGISTER            0x0004
3064 #define IMAGE_SYM_CLASS_EXTERNAL_DEF        0x0005
3065 #define IMAGE_SYM_CLASS_LABEL               0x0006
3066 #define IMAGE_SYM_CLASS_UNDEFINED_LABEL     0x0007
3067 #define IMAGE_SYM_CLASS_MEMBER_OF_STRUCT    0x0008
3068 #define IMAGE_SYM_CLASS_ARGUMENT            0x0009
3069 #define IMAGE_SYM_CLASS_STRUCT_TAG          0x000A
3070 #define IMAGE_SYM_CLASS_MEMBER_OF_UNION     0x000B
3071 #define IMAGE_SYM_CLASS_UNION_TAG           0x000C
3072 #define IMAGE_SYM_CLASS_TYPE_DEFINITION     0x000D
3073 #define IMAGE_SYM_CLASS_UNDEFINED_STATIC    0x000E
3074 #define IMAGE_SYM_CLASS_ENUM_TAG            0x000F
3075 #define IMAGE_SYM_CLASS_MEMBER_OF_ENUM      0x0010
3076 #define IMAGE_SYM_CLASS_REGISTER_PARAM      0x0011
3077 #define IMAGE_SYM_CLASS_BIT_FIELD           0x0012
3078
3079 #define IMAGE_SYM_CLASS_FAR_EXTERNAL        0x0044
3080 #define IMAGE_SYM_CLASS_BLOCK               0x0064
3081 #define IMAGE_SYM_CLASS_FUNCTION            0x0065
3082 #define IMAGE_SYM_CLASS_END_OF_STRUCT       0x0066
3083 #define IMAGE_SYM_CLASS_FILE                0x0067
3084 #define IMAGE_SYM_CLASS_SECTION             0x0068
3085 #define IMAGE_SYM_CLASS_WEAK_EXTERNAL       0x0069
3086
3087 #define N_BTMASK                            0x000F
3088 #define N_TMASK                             0x0030
3089 #define N_TMASK1                            0x00C0
3090 #define N_TMASK2                            0x00F0
3091 #define N_BTSHFT                            4
3092 #define N_TSHIFT                            2
3093
3094 #define BTYPE(x) ((x) & N_BTMASK)
3095
3096 #ifndef ISPTR
3097 #define ISPTR(x) (((x) & N_TMASK) == (IMAGE_SYM_DTYPE_POINTER << N_BTSHFT))
3098 #endif
3099
3100 #ifndef ISFCN
3101 #define ISFCN(x) (((x) & N_TMASK) == (IMAGE_SYM_DTYPE_FUNCTION << N_BTSHFT))
3102 #endif
3103
3104 #ifndef ISARY
3105 #define ISARY(x) (((x) & N_TMASK) == (IMAGE_SYM_DTYPE_ARRAY << N_BTSHFT))
3106 #endif
3107
3108 #ifndef ISTAG
3109 #define ISTAG(x) ((x)==IMAGE_SYM_CLASS_STRUCT_TAG || (x)==IMAGE_SYM_CLASS_UNION_TAG || (x)==IMAGE_SYM_CLASS_ENUM_TAG)
3110 #endif
3111
3112 #ifndef INCREF
3113 #define INCREF(x) ((((x)&~N_BTMASK)<<N_TSHIFT)|(IMAGE_SYM_DTYPE_POINTER<<N_BTSHFT)|((x)&N_BTMASK))
3114 #endif
3115 #ifndef DECREF
3116 #define DECREF(x) ((((x)>>N_TSHIFT)&~N_BTMASK)|((x)&N_BTMASK))
3117 #endif
3118
3119 #define IMAGE_COMDAT_SELECT_NODUPLICATES    1
3120 #define IMAGE_COMDAT_SELECT_ANY             2
3121 #define IMAGE_COMDAT_SELECT_SAME_SIZE       3
3122 #define IMAGE_COMDAT_SELECT_EXACT_MATCH     4
3123 #define IMAGE_COMDAT_SELECT_ASSOCIATIVE     5
3124 #define IMAGE_COMDAT_SELECT_LARGEST         6
3125 #define IMAGE_COMDAT_SELECT_NEWEST          7
3126
3127 #define IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY  1
3128 #define IMAGE_WEAK_EXTERN_SEARCH_LIBRARY    2
3129 #define IMAGE_WEAK_EXTERN_SEARCH_ALIAS      3
3130
3131 /* Export module directory */
3132
3133 typedef struct _IMAGE_EXPORT_DIRECTORY {
3134         DWORD   Characteristics;
3135         DWORD   TimeDateStamp;
3136         WORD    MajorVersion;
3137         WORD    MinorVersion;
3138         DWORD   Name;
3139         DWORD   Base;
3140         DWORD   NumberOfFunctions;
3141         DWORD   NumberOfNames;
3142         DWORD   AddressOfFunctions;
3143         DWORD   AddressOfNames;
3144         DWORD   AddressOfNameOrdinals;
3145 } IMAGE_EXPORT_DIRECTORY,*PIMAGE_EXPORT_DIRECTORY;
3146
3147 /* Import name entry */
3148 typedef struct _IMAGE_IMPORT_BY_NAME {
3149         WORD    Hint;
3150         BYTE    Name[1];
3151 } IMAGE_IMPORT_BY_NAME,*PIMAGE_IMPORT_BY_NAME;
3152
3153 #include <pshpack8.h>
3154 /* Import thunk */
3155 typedef struct _IMAGE_THUNK_DATA64 {
3156         union {
3157                 ULONGLONG ForwarderString;
3158                 ULONGLONG Function;
3159                 ULONGLONG Ordinal;
3160                 ULONGLONG AddressOfData;
3161         } u1;
3162 } IMAGE_THUNK_DATA64,*PIMAGE_THUNK_DATA64;
3163 #include <poppack.h>
3164
3165 typedef struct _IMAGE_THUNK_DATA32 {
3166         union {
3167                 DWORD ForwarderString;
3168                 DWORD Function;
3169                 DWORD Ordinal;
3170                 DWORD AddressOfData;
3171         } u1;
3172 } IMAGE_THUNK_DATA32,*PIMAGE_THUNK_DATA32;
3173
3174 /* Import module directory */
3175
3176 typedef struct _IMAGE_IMPORT_DESCRIPTOR {
3177         union {
3178                 DWORD   Characteristics; /* 0 for terminating null import descriptor  */
3179                 DWORD   OriginalFirstThunk;     /* RVA to original unbound IAT */
3180         } DUMMYUNIONNAME;
3181         DWORD   TimeDateStamp;  /* 0 if not bound,
3182                                  * -1 if bound, and real date\time stamp
3183                                  *    in IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT
3184                                  * (new BIND)
3185                                  * otherwise date/time stamp of DLL bound to
3186                                  * (Old BIND)
3187                                  */
3188         DWORD   ForwarderChain; /* -1 if no forwarders */
3189         DWORD   Name;
3190         /* RVA to IAT (if bound this IAT has actual addresses) */
3191         DWORD   FirstThunk;
3192 } IMAGE_IMPORT_DESCRIPTOR,*PIMAGE_IMPORT_DESCRIPTOR;
3193
3194 #define IMAGE_ORDINAL_FLAG64             (((ULONGLONG)0x80000000 << 32) | 0x00000000)
3195 #define IMAGE_ORDINAL_FLAG32             0x80000000
3196 #define IMAGE_SNAP_BY_ORDINAL64(ordinal) (((ordinal) & IMAGE_ORDINAL_FLAG64) != 0)
3197 #define IMAGE_SNAP_BY_ORDINAL32(ordinal) (((ordinal) & IMAGE_ORDINAL_FLAG32) != 0)
3198 #define IMAGE_ORDINAL64(ordinal)         ((ordinal) & 0xffff)
3199 #define IMAGE_ORDINAL32(ordinal)         ((ordinal) & 0xffff)
3200
3201 #ifdef _WIN64
3202 #define IMAGE_ORDINAL_FLAG              IMAGE_ORDINAL_FLAG64
3203 #define IMAGE_SNAP_BY_ORDINAL(Ordinal)  IMAGE_SNAP_BY_ORDINAL64(Ordinal)
3204 #define IMAGE_ORDINAL(Ordinal)          IMAGE_ORDINAL64(Ordinal)
3205 typedef IMAGE_THUNK_DATA64              IMAGE_THUNK_DATA;
3206 typedef PIMAGE_THUNK_DATA64             PIMAGE_THUNK_DATA;
3207 #else
3208 #define IMAGE_ORDINAL_FLAG              IMAGE_ORDINAL_FLAG32
3209 #define IMAGE_SNAP_BY_ORDINAL(Ordinal)  IMAGE_SNAP_BY_ORDINAL32(Ordinal)
3210 #define IMAGE_ORDINAL(Ordinal)          IMAGE_ORDINAL32(Ordinal)
3211 typedef IMAGE_THUNK_DATA32              IMAGE_THUNK_DATA;
3212 typedef PIMAGE_THUNK_DATA32             PIMAGE_THUNK_DATA;
3213 #endif
3214
3215 typedef struct _IMAGE_BOUND_IMPORT_DESCRIPTOR
3216 {
3217     DWORD   TimeDateStamp;
3218     WORD    OffsetModuleName;
3219     WORD    NumberOfModuleForwarderRefs;
3220 /* Array of zero or more IMAGE_BOUND_FORWARDER_REF follows */
3221 } IMAGE_BOUND_IMPORT_DESCRIPTOR,  *PIMAGE_BOUND_IMPORT_DESCRIPTOR;
3222
3223 typedef struct _IMAGE_BOUND_FORWARDER_REF
3224 {
3225     DWORD   TimeDateStamp;
3226     WORD    OffsetModuleName;
3227     WORD    Reserved;
3228 } IMAGE_BOUND_FORWARDER_REF, *PIMAGE_BOUND_FORWARDER_REF;
3229
3230 typedef struct _IMAGE_BASE_RELOCATION
3231 {
3232         DWORD   VirtualAddress;
3233         DWORD   SizeOfBlock;
3234         /* WORD TypeOffset[1]; */
3235 } IMAGE_BASE_RELOCATION,*PIMAGE_BASE_RELOCATION;
3236
3237 #include <pshpack2.h>
3238
3239 typedef struct _IMAGE_RELOCATION
3240 {
3241     union {
3242         DWORD   VirtualAddress;
3243         DWORD   RelocCount;
3244     } DUMMYUNIONNAME;
3245     DWORD   SymbolTableIndex;
3246     WORD    Type;
3247 } IMAGE_RELOCATION, *PIMAGE_RELOCATION;
3248
3249 #include <poppack.h>
3250
3251 #define IMAGE_SIZEOF_RELOCATION 10
3252
3253 /* generic relocation types */
3254 #define IMAGE_REL_BASED_ABSOLUTE                0
3255 #define IMAGE_REL_BASED_HIGH                    1
3256 #define IMAGE_REL_BASED_LOW                     2
3257 #define IMAGE_REL_BASED_HIGHLOW                 3
3258 #define IMAGE_REL_BASED_HIGHADJ                 4
3259 #define IMAGE_REL_BASED_MIPS_JMPADDR            5
3260 #define IMAGE_REL_BASED_SECTION                 6
3261 #define IMAGE_REL_BASED_REL                     7
3262 #define IMAGE_REL_BASED_MIPS_JMPADDR16          9
3263 #define IMAGE_REL_BASED_IA64_IMM64              9 /* yes, 9 too */
3264 #define IMAGE_REL_BASED_DIR64                   10
3265 #define IMAGE_REL_BASED_HIGH3ADJ                11
3266
3267 /* I386 relocation types */
3268 #define IMAGE_REL_I386_ABSOLUTE                 0
3269 #define IMAGE_REL_I386_DIR16                    1
3270 #define IMAGE_REL_I386_REL16                    2
3271 #define IMAGE_REL_I386_DIR32                    6
3272 #define IMAGE_REL_I386_DIR32NB                  7
3273 #define IMAGE_REL_I386_SEG12                    9
3274 #define IMAGE_REL_I386_SECTION                  10
3275 #define IMAGE_REL_I386_SECREL                   11
3276 #define IMAGE_REL_I386_REL32                    20
3277
3278 /* MIPS relocation types */
3279 #define IMAGE_REL_MIPS_ABSOLUTE         0x0000
3280 #define IMAGE_REL_MIPS_REFHALF          0x0001
3281 #define IMAGE_REL_MIPS_REFWORD          0x0002
3282 #define IMAGE_REL_MIPS_JMPADDR          0x0003
3283 #define IMAGE_REL_MIPS_REFHI            0x0004
3284 #define IMAGE_REL_MIPS_REFLO            0x0005
3285 #define IMAGE_REL_MIPS_GPREL            0x0006
3286 #define IMAGE_REL_MIPS_LITERAL          0x0007
3287 #define IMAGE_REL_MIPS_SECTION          0x000A
3288 #define IMAGE_REL_MIPS_SECREL           0x000B
3289 #define IMAGE_REL_MIPS_SECRELLO         0x000C
3290 #define IMAGE_REL_MIPS_SECRELHI         0x000D
3291 #define IMAGE_REL_MIPS_JMPADDR16        0x0010
3292 #define IMAGE_REL_MIPS_REFWORDNB        0x0022
3293 #define IMAGE_REL_MIPS_PAIR             0x0025
3294
3295 /* ALPHA relocation types */
3296 #define IMAGE_REL_ALPHA_ABSOLUTE        0x0000
3297 #define IMAGE_REL_ALPHA_REFLONG         0x0001
3298 #define IMAGE_REL_ALPHA_REFQUAD         0x0002
3299 #define IMAGE_REL_ALPHA_GPREL           0x0003
3300 #define IMAGE_REL_ALPHA_LITERAL         0x0004
3301 #define IMAGE_REL_ALPHA_LITUSE          0x0005
3302 #define IMAGE_REL_ALPHA_GPDISP          0x0006
3303 #define IMAGE_REL_ALPHA_BRADDR          0x0007
3304 #define IMAGE_REL_ALPHA_HINT            0x0008
3305 #define IMAGE_REL_ALPHA_INLINE_REFLONG  0x0009
3306 #define IMAGE_REL_ALPHA_REFHI           0x000A
3307 #define IMAGE_REL_ALPHA_REFLO           0x000B
3308 #define IMAGE_REL_ALPHA_PAIR            0x000C
3309 #define IMAGE_REL_ALPHA_MATCH           0x000D
3310 #define IMAGE_REL_ALPHA_SECTION         0x000E
3311 #define IMAGE_REL_ALPHA_SECREL          0x000F
3312 #define IMAGE_REL_ALPHA_REFLONGNB       0x0010
3313 #define IMAGE_REL_ALPHA_SECRELLO        0x0011
3314 #define IMAGE_REL_ALPHA_SECRELHI        0x0012
3315 #define IMAGE_REL_ALPHA_REFQ3           0x0013
3316 #define IMAGE_REL_ALPHA_REFQ2           0x0014
3317 #define IMAGE_REL_ALPHA_REFQ1           0x0015
3318 #define IMAGE_REL_ALPHA_GPRELLO         0x0016
3319 #define IMAGE_REL_ALPHA_GPRELHI         0x0017
3320
3321 /* PowerPC relocation types */
3322 #define IMAGE_REL_PPC_ABSOLUTE          0x0000
3323 #define IMAGE_REL_PPC_ADDR64            0x0001
3324 #define IMAGE_REL_PPC_ADDR            0x0002
3325 #define IMAGE_REL_PPC_ADDR24            0x0003
3326 #define IMAGE_REL_PPC_ADDR16            0x0004
3327 #define IMAGE_REL_PPC_ADDR14            0x0005
3328 #define IMAGE_REL_PPC_REL24             0x0006
3329 #define IMAGE_REL_PPC_REL14             0x0007
3330 #define IMAGE_REL_PPC_TOCREL16          0x0008
3331 #define IMAGE_REL_PPC_TOCREL14          0x0009
3332 #define IMAGE_REL_PPC_ADDR32NB          0x000A
3333 #define IMAGE_REL_PPC_SECREL            0x000B
3334 #define IMAGE_REL_PPC_SECTION           0x000C
3335 #define IMAGE_REL_PPC_IFGLUE            0x000D
3336 #define IMAGE_REL_PPC_IMGLUE            0x000E
3337 #define IMAGE_REL_PPC_SECREL16          0x000F
3338 #define IMAGE_REL_PPC_REFHI             0x0010
3339 #define IMAGE_REL_PPC_REFLO             0x0011
3340 #define IMAGE_REL_PPC_PAIR              0x0012
3341 #define IMAGE_REL_PPC_SECRELLO          0x0013
3342 #define IMAGE_REL_PPC_SECRELHI          0x0014
3343 #define IMAGE_REL_PPC_GPREL             0x0015
3344 #define IMAGE_REL_PPC_TYPEMASK          0x00FF
3345 /* modifier bits */
3346 #define IMAGE_REL_PPC_NEG               0x0100
3347 #define IMAGE_REL_PPC_BRTAKEN           0x0200
3348 #define IMAGE_REL_PPC_BRNTAKEN          0x0400
3349 #define IMAGE_REL_PPC_TOCDEFN           0x0800
3350
3351 /* SH3 ? relocation type */
3352 #define IMAGE_REL_SH3_ABSOLUTE          0x0000
3353 #define IMAGE_REL_SH3_DIRECT16          0x0001
3354 #define IMAGE_REL_SH3_DIRECT          0x0002
3355 #define IMAGE_REL_SH3_DIRECT8           0x0003
3356 #define IMAGE_REL_SH3_DIRECT8_WORD      0x0004
3357 #define IMAGE_REL_SH3_DIRECT8_LONG      0x0005
3358 #define IMAGE_REL_SH3_DIRECT4           0x0006
3359 #define IMAGE_REL_SH3_DIRECT4_WORD      0x0007
3360 #define IMAGE_REL_SH3_DIRECT4_LONG      0x0008
3361 #define IMAGE_REL_SH3_PCREL8_WORD       0x0009
3362 #define IMAGE_REL_SH3_PCREL8_LONG       0x000A
3363 #define IMAGE_REL_SH3_PCREL12_WORD      0x000B
3364 #define IMAGE_REL_SH3_STARTOF_SECTION   0x000C
3365 #define IMAGE_REL_SH3_SIZEOF_SECTION    0x000D
3366 #define IMAGE_REL_SH3_SECTION           0x000E
3367 #define IMAGE_REL_SH3_SECREL            0x000F
3368 #define IMAGE_REL_SH3_DIRECT32_NB       0x0010
3369
3370 /* ARM (Archimedes?) relocation types */
3371 #define IMAGE_REL_ARM_ABSOLUTE          0x0000
3372 #define IMAGE_REL_ARM_ADDR              0x0001
3373 #define IMAGE_REL_ARM_ADDR32NB          0x0002
3374 #define IMAGE_REL_ARM_BRANCH24          0x0003
3375 #define IMAGE_REL_ARM_BRANCH11          0x0004
3376 #define IMAGE_REL_ARM_SECTION           0x000E
3377 #define IMAGE_REL_ARM_SECREL            0x000F
3378
3379 /* IA64 relocation types */
3380 #define IMAGE_REL_IA64_ABSOLUTE         0x0000
3381 #define IMAGE_REL_IA64_IMM14            0x0001
3382 #define IMAGE_REL_IA64_IMM22            0x0002
3383 #define IMAGE_REL_IA64_IMM64            0x0003
3384 #define IMAGE_REL_IA64_DIR              0x0004
3385 #define IMAGE_REL_IA64_DIR64            0x0005
3386 #define IMAGE_REL_IA64_PCREL21B         0x0006
3387 #define IMAGE_REL_IA64_PCREL21M         0x0007
3388 #define IMAGE_REL_IA64_PCREL21F         0x0008
3389 #define IMAGE_REL_IA64_GPREL22          0x0009
3390 #define IMAGE_REL_IA64_LTOFF22          0x000A
3391 #define IMAGE_REL_IA64_SECTION          0x000B
3392 #define IMAGE_REL_IA64_SECREL22         0x000C
3393 #define IMAGE_REL_IA64_SECREL64I        0x000D
3394 #define IMAGE_REL_IA64_SECREL           0x000E
3395 #define IMAGE_REL_IA64_LTOFF64          0x000F
3396 #define IMAGE_REL_IA64_DIR32NB          0x0010
3397 #define IMAGE_REL_IA64_RESERVED_11      0x0011
3398 #define IMAGE_REL_IA64_RESERVED_12      0x0012
3399 #define IMAGE_REL_IA64_RESERVED_13      0x0013
3400 #define IMAGE_REL_IA64_RESERVED_14      0x0014
3401 #define IMAGE_REL_IA64_RESERVED_15      0x0015
3402 #define IMAGE_REL_IA64_RESERVED_16      0x0016
3403 #define IMAGE_REL_IA64_ADDEND           0x001F
3404
3405 /* AMD64 relocation types */
3406 #define IMAGE_REL_AMD64_ABSOLUTE        0x0000
3407 #define IMAGE_REL_AMD64_ADDR64          0x0001
3408 #define IMAGE_REL_AMD64_ADDR32          0x0002
3409 #define IMAGE_REL_AMD64_ADDR32NB        0x0003
3410 #define IMAGE_REL_AMD64_REL32           0x0004
3411 #define IMAGE_REL_AMD64_REL32_1         0x0005
3412 #define IMAGE_REL_AMD64_REL32_2         0x0006
3413 #define IMAGE_REL_AMD64_REL32_3         0x0007
3414 #define IMAGE_REL_AMD64_REL32_4         0x0008
3415 #define IMAGE_REL_AMD64_REL32_5         0x0009
3416 #define IMAGE_REL_AMD64_SECTION         0x000A
3417 #define IMAGE_REL_AMD64_SECREL          0x000B
3418 #define IMAGE_REL_AMD64_SECREL7         0x000C
3419 #define IMAGE_REL_AMD64_TOKEN           0x000D
3420 #define IMAGE_REL_AMD64_SREL32          0x000E
3421 #define IMAGE_REL_AMD64_PAIR            0x000F
3422 #define IMAGE_REL_AMD64_SSPAN32         0x0010
3423
3424 /* archive format */
3425
3426 #define IMAGE_ARCHIVE_START_SIZE             8
3427 #define IMAGE_ARCHIVE_START                  "!<arch>\n"
3428 #define IMAGE_ARCHIVE_END                    "`\n"
3429 #define IMAGE_ARCHIVE_PAD                    "\n"
3430 #define IMAGE_ARCHIVE_LINKER_MEMBER          "/               "
3431 #define IMAGE_ARCHIVE_LONGNAMES_MEMBER       "//              "
3432
3433 typedef struct _IMAGE_ARCHIVE_MEMBER_HEADER
3434 {
3435     BYTE     Name[16];
3436     BYTE     Date[12];
3437     BYTE     UserID[6];
3438     BYTE     GroupID[6];
3439     BYTE     Mode[8];
3440     BYTE     Size[10];
3441     BYTE     EndHeader[2];
3442 } IMAGE_ARCHIVE_MEMBER_HEADER, *PIMAGE_ARCHIVE_MEMBER_HEADER;
3443
3444 #define IMAGE_SIZEOF_ARCHIVE_MEMBER_HDR 60
3445
3446 typedef struct _IMPORT_OBJECT_HEADER
3447 {
3448     WORD     Sig1;
3449     WORD     Sig2;
3450     WORD     Version;
3451     WORD     Machine;
3452     DWORD    TimeDateStamp;
3453     DWORD    SizeOfData;
3454     union
3455     {
3456         WORD Ordinal;
3457         WORD Hint;
3458     } DUMMYUNIONNAME;
3459     WORD     Type : 2;
3460     WORD     NameType : 3;
3461     WORD     Reserved : 11;
3462 } IMPORT_OBJECT_HEADER;
3463
3464 #define IMPORT_OBJECT_HDR_SIG2  0xffff
3465
3466 typedef enum IMPORT_OBJECT_TYPE
3467 {
3468     IMPORT_OBJECT_CODE = 0,
3469     IMPORT_OBJECT_DATA = 1,
3470     IMPORT_OBJECT_CONST = 2
3471 } IMPORT_OBJECT_TYPE;
3472
3473 typedef enum IMPORT_OBJECT_NAME_TYPE
3474 {
3475     IMPORT_OBJECT_ORDINAL = 0,
3476     IMPORT_OBJECT_NAME = 1,
3477     IMPORT_OBJECT_NAME_NO_PREFIX = 2,
3478     IMPORT_OBJECT_NAME_UNDECORATE = 3
3479 } IMPORT_OBJECT_NAME_TYPE;
3480
3481 typedef struct _ANON_OBJECT_HEADER
3482 {
3483     WORD     Sig1;
3484     WORD     Sig2;
3485     WORD     Version;
3486     WORD     Machine;
3487     DWORD    TimeDateStamp;
3488     CLSID    ClassID;
3489     DWORD    SizeOfData;
3490 } ANON_OBJECT_HEADER;
3491
3492 /*
3493  * Resource directory stuff
3494  */
3495 typedef struct _IMAGE_RESOURCE_DIRECTORY {
3496         DWORD   Characteristics;
3497         DWORD   TimeDateStamp;
3498         WORD    MajorVersion;
3499         WORD    MinorVersion;
3500         WORD    NumberOfNamedEntries;
3501         WORD    NumberOfIdEntries;
3502         /*  IMAGE_RESOURCE_DIRECTORY_ENTRY DirectoryEntries[]; */
3503 } IMAGE_RESOURCE_DIRECTORY,*PIMAGE_RESOURCE_DIRECTORY;
3504
3505 #define IMAGE_RESOURCE_NAME_IS_STRING           0x80000000
3506 #define IMAGE_RESOURCE_DATA_IS_DIRECTORY        0x80000000
3507
3508 typedef struct _IMAGE_RESOURCE_DIRECTORY_ENTRY {
3509         union {
3510                 struct {
3511 #ifdef BITFIELDS_BIGENDIAN
3512                         unsigned NameIsString:1;
3513                         unsigned NameOffset:31;
3514 #else
3515                         unsigned NameOffset:31;
3516                         unsigned NameIsString:1;
3517 #endif
3518                 } DUMMYSTRUCTNAME1;
3519                 DWORD   Name;
3520                 struct {
3521 #ifdef WORDS_BIGENDIAN
3522                         WORD    __pad;
3523                         WORD    Id;
3524 #else
3525                         WORD    Id;
3526                         WORD    __pad;
3527 #endif
3528                 } DUMMYSTRUCTNAME2;
3529         } DUMMYUNIONNAME1;
3530         union {
3531                 DWORD   OffsetToData;
3532                 struct {
3533 #ifdef BITFIELDS_BIGENDIAN
3534                         unsigned DataIsDirectory:1;
3535                         unsigned OffsetToDirectory:31;
3536 #else
3537                         unsigned OffsetToDirectory:31;
3538                         unsigned DataIsDirectory:1;
3539 #endif
3540                 } DUMMYSTRUCTNAME3;
3541         } DUMMYUNIONNAME2;
3542 } IMAGE_RESOURCE_DIRECTORY_ENTRY,*PIMAGE_RESOURCE_DIRECTORY_ENTRY;
3543
3544
3545 typedef struct _IMAGE_RESOURCE_DIRECTORY_STRING {
3546         WORD    Length;
3547         CHAR    NameString[ 1 ];
3548 } IMAGE_RESOURCE_DIRECTORY_STRING,*PIMAGE_RESOURCE_DIRECTORY_STRING;
3549
3550 typedef struct _IMAGE_RESOURCE_DIR_STRING_U {
3551         WORD    Length;
3552         WCHAR   NameString[ 1 ];
3553 } IMAGE_RESOURCE_DIR_STRING_U,*PIMAGE_RESOURCE_DIR_STRING_U;
3554
3555 typedef struct _IMAGE_RESOURCE_DATA_ENTRY {
3556         DWORD   OffsetToData;
3557         DWORD   Size;
3558         DWORD   CodePage;
3559         DWORD   Reserved;
3560 } IMAGE_RESOURCE_DATA_ENTRY,*PIMAGE_RESOURCE_DATA_ENTRY;
3561
3562
3563 typedef VOID (CALLBACK *PIMAGE_TLS_CALLBACK)(
3564         LPVOID DllHandle,DWORD Reason,LPVOID Reserved
3565 );
3566
3567 typedef struct _IMAGE_TLS_DIRECTORY64 {
3568     ULONGLONG   StartAddressOfRawData;
3569     ULONGLONG   EndAddressOfRawData;
3570     ULONGLONG   AddressOfIndex;
3571     ULONGLONG   AddressOfCallBacks;
3572     DWORD       SizeOfZeroFill;
3573     DWORD       Characteristics;
3574 } IMAGE_TLS_DIRECTORY64, *PIMAGE_TLS_DIRECTORY64;
3575
3576 typedef struct _IMAGE_TLS_DIRECTORY32 {
3577     DWORD   StartAddressOfRawData;
3578     DWORD   EndAddressOfRawData;
3579     DWORD   AddressOfIndex;
3580     DWORD   AddressOfCallBacks;
3581     DWORD   SizeOfZeroFill;
3582     DWORD   Characteristics;
3583 } IMAGE_TLS_DIRECTORY32, *PIMAGE_TLS_DIRECTORY32;
3584
3585 #ifdef _WIN64
3586 typedef IMAGE_TLS_DIRECTORY64           IMAGE_TLS_DIRECTORY;
3587 typedef PIMAGE_TLS_DIRECTORY64          PIMAGE_TLS_DIRECTORY;
3588 #else
3589 typedef IMAGE_TLS_DIRECTORY32           IMAGE_TLS_DIRECTORY;
3590 typedef PIMAGE_TLS_DIRECTORY32          PIMAGE_TLS_DIRECTORY;
3591 #endif
3592
3593 typedef struct _IMAGE_DEBUG_DIRECTORY {
3594   DWORD Characteristics;
3595   DWORD TimeDateStamp;
3596   WORD  MajorVersion;
3597   WORD  MinorVersion;
3598   DWORD Type;
3599   DWORD SizeOfData;
3600   DWORD AddressOfRawData;
3601   DWORD PointerToRawData;
3602 } IMAGE_DEBUG_DIRECTORY, *PIMAGE_DEBUG_DIRECTORY;
3603
3604 #define IMAGE_DEBUG_TYPE_UNKNOWN        0
3605 #define IMAGE_DEBUG_TYPE_COFF           1
3606 #define IMAGE_DEBUG_TYPE_CODEVIEW       2
3607 #define IMAGE_DEBUG_TYPE_FPO            3
3608 #define IMAGE_DEBUG_TYPE_MISC           4
3609 #define IMAGE_DEBUG_TYPE_EXCEPTION      5
3610 #define IMAGE_DEBUG_TYPE_FIXUP          6
3611 #define IMAGE_DEBUG_TYPE_OMAP_TO_SRC    7
3612 #define IMAGE_DEBUG_TYPE_OMAP_FROM_SRC  8
3613 #define IMAGE_DEBUG_TYPE_BORLAND        9
3614 #define IMAGE_DEBUG_TYPE_RESERVED10    10
3615
3616 typedef enum ReplacesCorHdrNumericDefines
3617 {
3618     COMIMAGE_FLAGS_ILONLY           = 0x00000001,
3619     COMIMAGE_FLAGS_32BITREQUIRED    = 0x00000002,
3620     COMIMAGE_FLAGS_IL_LIBRARY       = 0x00000004,
3621     COMIMAGE_FLAGS_STRONGNAMESIGNED = 0x00000008,
3622     COMIMAGE_FLAGS_TRACKDEBUGDATA   = 0x00010000,
3623
3624     COR_VERSION_MAJOR_V2       = 2,
3625     COR_VERSION_MAJOR          = COR_VERSION_MAJOR_V2,
3626     COR_VERSION_MINOR          = 0,
3627     COR_DELETED_NAME_LENGTH    = 8,
3628     COR_VTABLEGAP_NAME_LENGTH  = 8,
3629
3630     NATIVE_TYPE_MAX_CB = 1,
3631     COR_ILMETHOD_SECT_SMALL_MAX_DATASIZE = 0xff,
3632
3633     IMAGE_COR_MIH_METHODRVA  = 0x01,
3634     IMAGE_COR_MIH_EHRVA      = 0x02,
3635     IMAGE_COR_MIH_BASICBLOCK = 0x08,
3636
3637     COR_VTABLE_32BIT             = 0x01,
3638     COR_VTABLE_64BIT             = 0x02,
3639     COR_VTABLE_FROM_UNMANAGED    = 0x04,
3640     COR_VTABLE_CALL_MOST_DERIVED = 0x10,
3641
3642     IMAGE_COR_EATJ_THUNK_SIZE = 32,
3643
3644     MAX_CLASS_NAME   = 1024,
3645     MAX_PACKAGE_NAME = 1024,
3646 } ReplacesCorHdrNumericDefines;
3647
3648 typedef struct IMAGE_COR20_HEADER
3649 {
3650     DWORD cb;
3651     WORD  MajorRuntimeVersion;
3652     WORD  MinorRuntimeVersion;
3653
3654     IMAGE_DATA_DIRECTORY MetaData;
3655     DWORD Flags;
3656     DWORD EntryPointToken;
3657
3658     IMAGE_DATA_DIRECTORY Resources;
3659     IMAGE_DATA_DIRECTORY StrongNameSignature;
3660     IMAGE_DATA_DIRECTORY CodeManagerTable;
3661     IMAGE_DATA_DIRECTORY VTableFixups;
3662     IMAGE_DATA_DIRECTORY ExportAddressTableJumps;
3663     IMAGE_DATA_DIRECTORY ManagedNativeHeader;
3664
3665 } IMAGE_COR20_HEADER, *PIMAGE_COR20_HEADER;
3666
3667 typedef struct _IMAGE_COFF_SYMBOLS_HEADER {
3668   DWORD NumberOfSymbols;
3669   DWORD LvaToFirstSymbol;
3670   DWORD NumberOfLinenumbers;
3671   DWORD LvaToFirstLinenumber;
3672   DWORD RvaToFirstByteOfCode;
3673   DWORD RvaToLastByteOfCode;
3674   DWORD RvaToFirstByteOfData;
3675   DWORD RvaToLastByteOfData;
3676 } IMAGE_COFF_SYMBOLS_HEADER, *PIMAGE_COFF_SYMBOLS_HEADER;
3677
3678 #define FRAME_FPO       0
3679 #define FRAME_TRAP      1
3680 #define FRAME_TSS       2
3681 #define FRAME_NONFPO    3
3682
3683 typedef struct _FPO_DATA {
3684   DWORD ulOffStart;
3685   DWORD cbProcSize;
3686   DWORD cdwLocals;
3687   WORD  cdwParams;
3688   WORD  cbProlog : 8;
3689   WORD  cbRegs   : 3;
3690   WORD  fHasSEH  : 1;
3691   WORD  fUseBP   : 1;
3692   WORD  reserved : 1;
3693   WORD  cbFrame  : 2;
3694 } FPO_DATA, *PFPO_DATA;
3695
3696 typedef struct _IMAGE_LOAD_CONFIG_DIRECTORY {
3697   DWORD Size;
3698   DWORD TimeDateStamp;
3699   WORD  MajorVersion;
3700   WORD  MinorVersion;
3701   DWORD GlobalFlagsClear;
3702   DWORD GlobalFlagsSet;
3703   DWORD CriticalSectionDefaultTimeout;
3704   DWORD DeCommitFreeBlockThreshold;
3705   DWORD DeCommitTotalFreeThreshold;
3706   PVOID LockPrefixTable;
3707   DWORD MaximumAllocationSize;
3708   DWORD VirtualMemoryThreshold;
3709   DWORD ProcessHeapFlags;
3710   DWORD ProcessAffinityMask;
3711   WORD  CSDVersion;
3712   WORD  Reserved1;
3713   PVOID EditList;
3714   DWORD SecurityCookie;
3715   DWORD SEHandlerTable;
3716   DWORD SEHandlerCount;
3717 } IMAGE_LOAD_CONFIG_DIRECTORY, *PIMAGE_LOAD_CONFIG_DIRECTORY;
3718
3719 typedef struct _IMAGE_FUNCTION_ENTRY {
3720   DWORD StartingAddress;
3721   DWORD EndingAddress;
3722   DWORD EndOfPrologue;
3723 } IMAGE_FUNCTION_ENTRY, *PIMAGE_FUNCTION_ENTRY;
3724
3725 #define IMAGE_DEBUG_MISC_EXENAME    1
3726
3727 typedef struct _IMAGE_DEBUG_MISC {
3728     DWORD       DataType;
3729     DWORD       Length;
3730     BYTE        Unicode;
3731     BYTE        Reserved[ 3 ];
3732     BYTE        Data[ 1 ];
3733 } IMAGE_DEBUG_MISC, *PIMAGE_DEBUG_MISC;
3734
3735 /* This is the structure that appears at the very start of a .DBG file. */
3736
3737 typedef struct _IMAGE_SEPARATE_DEBUG_HEADER {
3738         WORD    Signature;
3739         WORD    Flags;
3740         WORD    Machine;
3741         WORD    Characteristics;
3742         DWORD   TimeDateStamp;
3743         DWORD   CheckSum;
3744         DWORD   ImageBase;
3745         DWORD   SizeOfImage;
3746         DWORD   NumberOfSections;
3747         DWORD   ExportedNamesSize;
3748         DWORD   DebugDirectorySize;
3749         DWORD   SectionAlignment;
3750         DWORD   Reserved[ 2 ];
3751 } IMAGE_SEPARATE_DEBUG_HEADER,*PIMAGE_SEPARATE_DEBUG_HEADER;
3752
3753 #define IMAGE_SEPARATE_DEBUG_SIGNATURE 0x4944
3754
3755
3756 typedef struct tagMESSAGE_RESOURCE_ENTRY {
3757         WORD    Length;
3758         WORD    Flags;
3759         BYTE    Text[1];
3760 } MESSAGE_RESOURCE_ENTRY,*PMESSAGE_RESOURCE_ENTRY;
3761 #define MESSAGE_RESOURCE_UNICODE        0x0001
3762
3763 typedef struct tagMESSAGE_RESOURCE_BLOCK {
3764         DWORD   LowId;
3765         DWORD   HighId;
3766         DWORD   OffsetToEntries;
3767 } MESSAGE_RESOURCE_BLOCK,*PMESSAGE_RESOURCE_BLOCK;
3768
3769 typedef struct tagMESSAGE_RESOURCE_DATA {
3770         DWORD                   NumberOfBlocks;
3771         MESSAGE_RESOURCE_BLOCK  Blocks[ 1 ];
3772 } MESSAGE_RESOURCE_DATA,*PMESSAGE_RESOURCE_DATA;
3773
3774 /*
3775  * Here follows typedefs for security and tokens.
3776  */
3777
3778 /*
3779  * First a constant for the following typedefs.
3780  */
3781
3782 #define ANYSIZE_ARRAY   1
3783
3784 /* FIXME:  Orphan.  What does it point to? */
3785 typedef PVOID PACCESS_TOKEN;
3786 typedef PVOID PSECURITY_DESCRIPTOR;
3787 typedef PVOID PSID;
3788
3789 typedef enum _TOKEN_ELEVATION_TYPE {
3790   TokenElevationTypeDefault = 1,
3791   TokenElevationTypeFull,
3792   TokenElevationTypeLimited
3793 } TOKEN_ELEVATION_TYPE, *PTOKEN_ELEVATION_TYPE;
3794
3795 /*
3796  * TOKEN_INFORMATION_CLASS
3797  */
3798
3799 typedef enum _TOKEN_INFORMATION_CLASS {
3800   TokenUser = 1,
3801   TokenGroups,
3802   TokenPrivileges,
3803   TokenOwner,
3804   TokenPrimaryGroup,
3805   TokenDefaultDacl,
3806   TokenSource,
3807   TokenType,
3808   TokenImpersonationLevel,
3809   TokenStatistics,
3810   TokenRestrictedSids,
3811   TokenSessionId,
3812   TokenGroupsAndPrivileges,
3813   TokenSessionReference,
3814   TokenSandBoxInert,
3815   TokenAuditPolicy,
3816   TokenOrigin,
3817   TokenElevationType,
3818   TokenLinkedToken,
3819   TokenElevation,
3820   TokenHasRestrictions,
3821   TokenAccessInformation,
3822   TokenVirtualizationAllowed,
3823   TokenVirtualizationEnabled,
3824   TokenIntegrityLevel,
3825   TokenUIAccess,
3826   TokenMandatoryPolicy,
3827   TokenLogonSid,
3828   MaxTokenInfoClass
3829 } TOKEN_INFORMATION_CLASS;
3830
3831 #define TOKEN_TOKEN_ADJUST_DEFAULT   0x0080
3832 #define TOKEN_ADJUST_GROUPS          0x0040
3833 #define TOKEN_ADJUST_PRIVILEGES      0x0020
3834 #define TOKEN_ADJUST_SESSIONID       0x0100
3835 #define TOKEN_ASSIGN_PRIMARY         0x0001
3836 #define TOKEN_DUPLICATE              0x0002
3837 #define TOKEN_EXECUTE                STANDARD_RIGHTS_EXECUTE
3838 #define TOKEN_IMPERSONATE            0x0004
3839 #define TOKEN_QUERY                  0x0008
3840 #define TOKEN_QUERY_SOURCE           0x0010
3841 #define TOKEN_ADJUST_DEFAULT         0x0080
3842 #define TOKEN_READ                   (STANDARD_RIGHTS_READ|TOKEN_QUERY)
3843 #define TOKEN_WRITE                  (STANDARD_RIGHTS_WRITE     | \
3844                                         TOKEN_ADJUST_PRIVILEGES | \
3845                                         TOKEN_ADJUST_GROUPS | \
3846                                         TOKEN_ADJUST_DEFAULT )
3847 #define TOKEN_ALL_ACCESS             (STANDARD_RIGHTS_REQUIRED | \
3848                                         TOKEN_ASSIGN_PRIMARY | \
3849                                         TOKEN_DUPLICATE | \
3850                                         TOKEN_IMPERSONATE | \
3851                                         TOKEN_QUERY | \
3852                                         TOKEN_QUERY_SOURCE | \
3853                                         TOKEN_ADJUST_PRIVILEGES | \
3854                                         TOKEN_ADJUST_GROUPS | \
3855                                         TOKEN_ADJUST_SESSIONID | \
3856                                         TOKEN_ADJUST_DEFAULT )
3857
3858 #ifndef _SECURITY_DEFINED
3859 #define _SECURITY_DEFINED
3860
3861
3862 typedef DWORD ACCESS_MASK, *PACCESS_MASK;
3863
3864 typedef struct _GENERIC_MAPPING {
3865     ACCESS_MASK GenericRead;
3866     ACCESS_MASK GenericWrite;
3867     ACCESS_MASK GenericExecute;
3868     ACCESS_MASK GenericAll;
3869 } GENERIC_MAPPING, *PGENERIC_MAPPING;
3870
3871 #ifndef SID_IDENTIFIER_AUTHORITY_DEFINED
3872 #define SID_IDENTIFIER_AUTHORITY_DEFINED
3873 typedef struct {
3874     BYTE Value[6];
3875 } SID_IDENTIFIER_AUTHORITY, *PSID_IDENTIFIER_AUTHORITY;
3876 #endif /* !defined(SID_IDENTIFIER_AUTHORITY_DEFINED) */
3877
3878 #ifndef SID_DEFINED
3879 #define SID_DEFINED
3880 typedef struct _SID {
3881     BYTE Revision;
3882     BYTE SubAuthorityCount;
3883     SID_IDENTIFIER_AUTHORITY IdentifierAuthority;
3884     DWORD SubAuthority[1];
3885 } SID,*PISID;
3886 #endif /* !defined(SID_DEFINED) */
3887
3888 #define SID_REVISION                    (1)     /* Current revision */
3889 #define SID_MAX_SUB_AUTHORITIES         (15)    /* current max subauths */
3890 #define SID_RECOMMENDED_SUB_AUTHORITIES (1)     /* recommended subauths */
3891
3892 #define SECURITY_MAX_SID_SIZE (sizeof(SID) - sizeof(DWORD) + (SID_MAX_SUB_AUTHORITIES * sizeof(DWORD)))
3893
3894 /*
3895  * ACL
3896  */
3897
3898 #define ACL_REVISION1 1
3899 #define ACL_REVISION2 2
3900 #define ACL_REVISION3 3
3901 #define ACL_REVISION4 4
3902
3903 #define MIN_ACL_REVISION ACL_REVISION2
3904 #define MAX_ACL_REVISION ACL_REVISION4
3905
3906 #define ACL_REVISION 2
3907
3908 typedef struct _ACL {
3909     BYTE AclRevision;
3910     BYTE Sbz1;
3911     WORD AclSize;
3912     WORD AceCount;
3913     WORD Sbz2;
3914 } ACL, *PACL;
3915
3916 typedef enum _ACL_INFORMATION_CLASS
3917 {
3918   AclRevisionInformation = 1, 
3919   AclSizeInformation
3920 } ACL_INFORMATION_CLASS;
3921
3922 typedef struct _ACL_REVISION_INFORMATION
3923 {
3924     DWORD AclRevision;
3925 } ACL_REVISION_INFORMATION, *PACL_REVISION_INFORMATION;
3926
3927 typedef struct _ACL_SIZE_INFORMATION
3928 {
3929     DWORD AceCount;
3930     DWORD AclBytesInUse;
3931     DWORD AclBytesFree;
3932 } ACL_SIZE_INFORMATION, *PACL_SIZE_INFORMATION;
3933
3934 /* SECURITY_DESCRIPTOR */
3935 #define SECURITY_DESCRIPTOR_REVISION    1
3936 #define SECURITY_DESCRIPTOR_REVISION1   1
3937
3938
3939 /*
3940  * Privilege Names
3941  */
3942 #define SE_CREATE_TOKEN_NAME            TEXT("SeCreateTokenPrivilege")
3943 #define SE_ASSIGNPRIMARYTOKEN_NAME      TEXT("SeAssignPrimaryTokenPrivilege")
3944 #define SE_LOCK_MEMORY_NAME             TEXT("SeLockMemoryPrivilege")
3945 #define SE_INCREASE_QUOTA_NAME          TEXT("SeIncreaseQuotaPrivilege")
3946 #define SE_UNSOLICITED_INPUT_NAME       TEXT("SeUnsolicitedInputPrivilege")
3947 #define SE_MACHINE_ACCOUNT_NAME         TEXT("SeMachineAccountPrivilege")
3948 #define SE_TCB_NAME                     TEXT("SeTcbPrivilege")
3949 #define SE_SECURITY_NAME                TEXT("SeSecurityPrivilege")
3950 #define SE_TAKE_OWNERSHIP_NAME          TEXT("SeTakeOwnershipPrivilege")
3951 #define SE_LOAD_DRIVER_NAME             TEXT("SeLoadDriverPrivilege")
3952 #define SE_SYSTEM_PROFILE_NAME          TEXT("SeSystemProfilePrivilege")
3953 #define SE_SYSTEMTIME_NAME              TEXT("SeSystemtimePrivilege")
3954 #define SE_PROF_SINGLE_PROCESS_NAME     TEXT("SeProfileSingleProcessPrivilege")
3955 #define SE_INC_BASE_PRIORITY_NAME       TEXT("SeIncreaseBasePriorityPrivilege")
3956 #define SE_CREATE_PAGEFILE_NAME         TEXT("SeCreatePagefilePrivilege")
3957 #define SE_CREATE_PERMANENT_NAME        TEXT("SeCreatePermanentPrivilege")
3958 #define SE_BACKUP_NAME                  TEXT("SeBackupPrivilege")
3959 #define SE_RESTORE_NAME                 TEXT("SeRestorePrivilege")
3960 #define SE_SHUTDOWN_NAME                TEXT("SeShutdownPrivilege")
3961 #define SE_DEBUG_NAME                   TEXT("SeDebugPrivilege")
3962 #define SE_AUDIT_NAME                   TEXT("SeAuditPrivilege")
3963 #define SE_SYSTEM_ENVIRONMENT_NAME      TEXT("SeSystemEnvironmentPrivilege")
3964 #define SE_CHANGE_NOTIFY_NAME           TEXT("SeChangeNotifyPrivilege")
3965 #define SE_REMOTE_SHUTDOWN_NAME         TEXT("SeRemoteShutdownPrivilege")
3966 #define SE_UNDOCK_NAME                  TEXT("SeUndockPrivilege")
3967 #define SE_ENABLE_DELEGATION_NAME       TEXT("SeEnableDelegationPrivilege")
3968 #define SE_MANAGE_VOLUME_NAME           TEXT("SeManageVolumePrivilege")
3969 #define SE_IMPERSONATE_NAME             TEXT("SeImpersonatePrivilege")
3970 #define SE_CREATE_GLOBAL_NAME           TEXT("SeCreateGlobalPrivilege")
3971
3972 #define SE_GROUP_MANDATORY              0x00000001
3973 #define SE_GROUP_ENABLED_BY_DEFAULT     0x00000002
3974 #define SE_GROUP_ENABLED                0x00000004
3975 #define SE_GROUP_OWNER                  0x00000008
3976 #define SE_GROUP_USE_FOR_DENY_ONLY      0x00000010
3977 #define SE_GROUP_LOGON_ID               0xC0000000
3978 #define SE_GROUP_RESOURCE               0x20000000
3979
3980 #define SE_PRIVILEGE_ENABLED_BY_DEFAULT 0x00000001
3981 #define SE_PRIVILEGE_ENABLED            0x00000002
3982 #define SE_PRIVILEGE_REMOVE             0x00000004
3983 #define SE_PRIVILEGE_USED_FOR_ACCESS    0x80000000
3984
3985 #define PRIVILEGE_SET_ALL_NECESSARY     1
3986
3987 #define SE_OWNER_DEFAULTED              0x00000001
3988 #define SE_GROUP_DEFAULTED              0x00000002
3989 #define SE_DACL_PRESENT                 0x00000004
3990 #define SE_DACL_DEFAULTED               0x00000008
3991 #define SE_SACL_PRESENT                 0x00000010
3992 #define SE_SACL_DEFAULTED               0x00000020
3993 #define SE_DACL_AUTO_INHERIT_REQ        0x00000100
3994 #define SE_SACL_AUTO_INHERIT_REQ        0x00000200
3995 #define SE_DACL_AUTO_INHERITED          0x00000400
3996 #define SE_SACL_AUTO_INHERITED          0x00000800
3997 #define SE_DACL_PROTECTED               0x00001000
3998 #define SE_SACL_PROTECTED               0x00002000
3999 #define SE_RM_CONTROL_VALID             0x00004000
4000 #define SE_SELF_RELATIVE                0x00008000
4001
4002 typedef DWORD SECURITY_INFORMATION, *PSECURITY_INFORMATION;
4003 typedef WORD SECURITY_DESCRIPTOR_CONTROL, *PSECURITY_DESCRIPTOR_CONTROL;
4004
4005 /* The security descriptor structure */
4006 typedef struct {
4007     BYTE Revision;
4008     BYTE Sbz1;
4009     SECURITY_DESCRIPTOR_CONTROL Control;
4010     DWORD Owner;
4011     DWORD Group;
4012     DWORD Sacl;
4013     DWORD Dacl;
4014 } SECURITY_DESCRIPTOR_RELATIVE, *PISECURITY_DESCRIPTOR_RELATIVE;
4015
4016 typedef struct {
4017     BYTE Revision;
4018     BYTE Sbz1;
4019     SECURITY_DESCRIPTOR_CONTROL Control;
4020     PSID Owner;
4021     PSID Group;
4022     PACL Sacl;
4023     PACL Dacl;
4024 } SECURITY_DESCRIPTOR, *PISECURITY_DESCRIPTOR;
4025
4026 #define SECURITY_DESCRIPTOR_MIN_LENGTH   (sizeof(SECURITY_DESCRIPTOR))
4027
4028 #endif /* _SECURITY_DEFINED */
4029
4030 /*
4031  * SID_AND_ATTRIBUTES
4032  */
4033
4034 typedef struct _SID_AND_ATTRIBUTES {
4035   PSID  Sid;
4036   DWORD Attributes;
4037 } SID_AND_ATTRIBUTES, *PSID_AND_ATTRIBUTES;
4038
4039 /* security entities */
4040 #define SECURITY_NULL_RID                       (0x00000000L)
4041 #define SECURITY_WORLD_RID                      (0x00000000L)
4042 #define SECURITY_LOCAL_RID                      (0X00000000L)
4043
4044 #define SECURITY_NULL_SID_AUTHORITY             {0,0,0,0,0,0}
4045
4046 /* S-1-1 */
4047 #define SECURITY_WORLD_SID_AUTHORITY            {0,0,0,0,0,1}
4048
4049 /* S-1-2 */
4050 #define SECURITY_LOCAL_SID_AUTHORITY            {0,0,0,0,0,2}
4051
4052 /* S-1-3 */
4053 #define SECURITY_CREATOR_SID_AUTHORITY          {0,0,0,0,0,3}
4054 #define SECURITY_CREATOR_OWNER_RID              (0x00000000L)
4055 #define SECURITY_CREATOR_GROUP_RID              (0x00000001L)
4056 #define SECURITY_CREATOR_OWNER_SERVER_RID       (0x00000002L)
4057 #define SECURITY_CREATOR_GROUP_SERVER_RID       (0x00000003L)
4058
4059 /* S-1-4 */
4060 #define SECURITY_NON_UNIQUE_AUTHORITY           {0,0,0,0,0,4}
4061
4062 /* S-1-5 */
4063 #define SECURITY_NT_AUTHORITY                   {0,0,0,0,0,5}
4064 #define SECURITY_DIALUP_RID                     0x00000001L
4065 #define SECURITY_NETWORK_RID                    0x00000002L
4066 #define SECURITY_BATCH_RID                      0x00000003L
4067 #define SECURITY_INTERACTIVE_RID                0x00000004L
4068 #define SECURITY_LOGON_IDS_RID                  0x00000005L
4069 #define SECURITY_SERVICE_RID                    0x00000006L
4070 #define SECURITY_ANONYMOUS_LOGON_RID            0x00000007L
4071 #define SECURITY_PROXY_RID                      0x00000008L
4072 #define SECURITY_ENTERPRISE_CONTROLLERS_RID     0x00000009L
4073 #define SECURITY_SERVER_LOGON_RID               SECURITY_ENTERPRISE_CONTROLLERS_RID
4074 #define SECURITY_PRINCIPAL_SELF_RID             0x0000000AL
4075 #define SECURITY_AUTHENTICATED_USER_RID         0x0000000BL
4076 #define SECURITY_RESTRICTED_CODE_RID            0x0000000CL
4077 #define SECURITY_TERMINAL_SERVER_RID            0x0000000DL
4078 #define SECURITY_REMOTE_LOGON_RID               0x0000000EL
4079 #define SECURITY_THIS_ORGANIZATION_RID          0x0000000FL
4080 #define SECURITY_LOCAL_SYSTEM_RID               0x00000012L
4081 #define SECURITY_LOCAL_SERVICE_RID              0x00000013L
4082 #define SECURITY_NETWORK_SERVICE_RID            0x00000014L
4083 #define SECURITY_NT_NON_UNIQUE                  0x00000015L
4084 #define SECURITY_BUILTIN_DOMAIN_RID             0x00000020L
4085
4086 #define SECURITY_PACKAGE_BASE_RID               0x00000040L
4087 #define SECURITY_PACKAGE_NTLM_RID               0x0000000AL
4088 #define SECURITY_PACKAGE_SCHANNEL_RID           0x0000000EL
4089 #define SECURITY_PACKAGE_DIGEST_RID             0x00000015L
4090 #define SECURITY_MAX_ALWAYS_FILTERED            0x000003E7L
4091 #define SECURITY_MIN_NEVER_FILTERED             0x000003E8L
4092 #define SECURITY_OTHER_ORGANIZATION_RID         0x000003E8L
4093
4094 #define FOREST_USER_RID_MAX                     0x000001F3L
4095 #define DOMAIN_USER_RID_ADMIN                   0x000001F4L
4096 #define DOMAIN_USER_RID_GUEST                   0x000001F5L
4097 #define DOMAIN_USER_RID_KRBTGT                  0x000001F6L
4098 #define DOMAIN_USER_RID_MAX                     0x000003E7L
4099
4100 #define DOMAIN_GROUP_RID_ADMINS                 0x00000200L
4101 #define DOMAIN_GROUP_RID_USERS                  0x00000201L
4102 #define DOMAIN_GROUP_RID_GUESTS                 0x00000202L
4103 #define DOMAIN_GROUP_RID_COMPUTERS              0x00000203L
4104 #define DOMAIN_GROUP_RID_CONTROLLERS            0x00000204L
4105 #define DOMAIN_GROUP_RID_CERT_ADMINS            0x00000205L
4106 #define DOMAIN_GROUP_RID_SCHEMA_ADMINS          0x00000206L
4107 #define DOMAIN_GROUP_RID_ENTERPRISE_ADMINS      0x00000207L
4108 #define DOMAIN_GROUP_RID_POLICY_ADMINS          0x00000208L
4109
4110 #define SECURITY_MANDATORY_LABEL_AUTHORITY {0,0,0,0,0,16}
4111 #define SECURITY_MANDATORY_UNTRUSTED_RID        0x00000000L
4112 #define SECURITY_MANDATORY_LOW_RID              0x00001000L
4113 #define SECURITY_MANDATORY_MEDIUM_RID           0x00002000L
4114 #define SECURITY_MANDATORY_HIGH_RID             0x00003000L
4115 #define SECURITY_MANDATORY_SYSTEM_RID           0x00004000L
4116 #define SECURITY_MANDATORY_PROTECTED_PROCESS_RID 0x00005000L
4117
4118 #define DOMAIN_ALIAS_RID_ADMINS                 0x00000220L
4119 #define DOMAIN_ALIAS_RID_USERS                  0x00000221L
4120 #define DOMAIN_ALIAS_RID_GUESTS                 0x00000222L
4121 #define DOMAIN_ALIAS_RID_POWER_USERS            0x00000223L
4122
4123 #define DOMAIN_ALIAS_RID_ACCOUNT_OPS            0x00000224L
4124 #define DOMAIN_ALIAS_RID_SYSTEM_OPS             0x00000225L
4125 #define DOMAIN_ALIAS_RID_PRINT_OPS              0x00000226L
4126 #define DOMAIN_ALIAS_RID_BACKUP_OPS             0x00000227L
4127
4128 #define DOMAIN_ALIAS_RID_REPLICATOR             0x00000228L
4129 #define DOMAIN_ALIAS_RID_RAS_SERVERS            0x00000229L
4130 #define DOMAIN_ALIAS_RID_PREW2KCOMPACCESS       0x0000022AL
4131 #define DOMAIN_ALIAS_RID_REMOTE_DESKTOP_USERS   0x0000022BL
4132 #define DOMAIN_ALIAS_RID_NETWORK_CONFIGURATION_OPS 0x0000022CL
4133 #define DOMAIN_ALIAS_RID_INCOMING_FOREST_TRUST_BUILDERS 0x0000022DL
4134
4135 #define DOMAIN_ALIAS_RID_MONITORING_USERS       0x0000022EL
4136 #define DOMAIN_ALIAS_RID_LOGGING_USERS          0x0000022FL
4137 #define DOMAIN_ALIAS_RID_AUTHORIZATIONACCESS    0x00000230L
4138 #define DOMAIN_ALIAS_RID_TS_LICENSE_SERVERS     0x00000231L
4139 #define DOMAIN_ALIAS_RID_DCOM_USERS             0x00000232L
4140
4141 #define SECURITY_SERVER_LOGON_RID               SECURITY_ENTERPRISE_CONTROLLERS_RID
4142
4143 #define SECURITY_PACKAGE_RID_COUNT              2L
4144 #define SECURITY_LOGON_IDS_RID_COUNT            3L
4145
4146 typedef enum {
4147     WinNullSid                                  = 0,
4148     WinWorldSid                                 = 1,
4149     WinLocalSid                                 = 2,
4150     WinCreatorOwnerSid                          = 3,
4151     WinCreatorGroupSid                          = 4,
4152     WinCreatorOwnerServerSid                    = 5,
4153     WinCreatorGroupServerSid                    = 6,
4154     WinNtAuthoritySid                           = 7,
4155     WinDialupSid                                = 8,
4156     WinNetworkSid                               = 9,
4157     WinBatchSid                                 = 10,
4158     WinInteractiveSid                           = 11,
4159     WinServiceSid                               = 12,
4160     WinAnonymousSid                             = 13,
4161     WinProxySid                                 = 14,
4162     WinEnterpriseControllersSid                 = 15,
4163     WinSelfSid                                  = 16,
4164     WinAuthenticatedUserSid                     = 17,
4165     WinRestrictedCodeSid                        = 18,
4166     WinTerminalServerSid                        = 19,
4167     WinRemoteLogonIdSid                         = 20,
4168     WinLogonIdsSid                              = 21,
4169     WinLocalSystemSid                           = 22,
4170     WinLocalServiceSid                          = 23,
4171     WinNetworkServiceSid                        = 24,
4172     WinBuiltinDomainSid                         = 25,
4173     WinBuiltinAdministratorsSid                 = 26,
4174     WinBuiltinUsersSid                          = 27,
4175     WinBuiltinGuestsSid                         = 28,
4176     WinBuiltinPowerUsersSid                     = 29,
4177     WinBuiltinAccountOperatorsSid               = 30,
4178     WinBuiltinSystemOperatorsSid                = 31,
4179     WinBuiltinPrintOperatorsSid                 = 32,
4180     WinBuiltinBackupOperatorsSid                = 33,
4181     WinBuiltinReplicatorSid                     = 34,
4182     WinBuiltinPreWindows2000CompatibleAccessSid = 35,
4183     WinBuiltinRemoteDesktopUsersSid             = 36,
4184     WinBuiltinNetworkConfigurationOperatorsSid  = 37,
4185     WinAccountAdministratorSid                  = 38,
4186     WinAccountGuestSid                          = 39,
4187     WinAccountKrbtgtSid                         = 40,
4188     WinAccountDomainAdminsSid                   = 41,
4189     WinAccountDomainUsersSid                    = 42,
4190     WinAccountDomainGuestsSid                   = 43,
4191     WinAccountComputersSid                      = 44,
4192     WinAccountControllersSid                    = 45,
4193     WinAccountCertAdminsSid                     = 46,
4194     WinAccountSchemaAdminsSid                   = 47,
4195     WinAccountEnterpriseAdminsSid               = 48,
4196     WinAccountPolicyAdminsSid                   = 49,
4197     WinAccountRasAndIasServersSid               = 50,
4198     WinNTLMAuthenticationSid                    = 51,
4199     WinDigestAuthenticationSid                  = 52,
4200     WinSChannelAuthenticationSid                = 53,
4201     WinThisOrganizationSid                      = 54,
4202     WinOtherOrganizationSid                     = 55,
4203     WinBuiltinIncomingForestTrustBuildersSid    = 56,
4204     WinBuiltinPerfMonitoringUsersSid            = 57,
4205     WinBuiltinPerfLoggingUsersSid               = 58,
4206     WinBuiltinAuthorizationAccessSid            = 59,
4207     WinBuiltinTerminalServerLicenseServersSid   = 60,
4208     WinBuiltinDCOMUsersSid                      = 61,
4209     WinBuiltinIUsersSid                         = 62,
4210     WinIUserSid                                 = 63,
4211     WinBuiltinCryptoOperatorsSid                = 64,
4212     WinUntrustedLabelSid                        = 65,
4213     WinLowLabelSid                              = 66,
4214     WinMediumLabelSid                           = 67,
4215     WinHighLabelSid                             = 68,
4216     WinSystemLabelSid                           = 69,
4217     WinWriteRestrictedCodeSid                   = 70,
4218     WinCreatorOwnerRightsSid                    = 71,
4219     WinCacheablePrincipalsGroupSid              = 72,
4220     WinNonCacheablePrincipalsGroupSid           = 73,
4221     WinEnterpriseReadonlyControllersSid         = 74,
4222     WinAccountReadonlyControllersSid            = 75,
4223     WinBuiltinEventLogReadersGroup              = 76,
4224 } WELL_KNOWN_SID_TYPE;
4225
4226 /*
4227  * TOKEN_USER
4228  */
4229
4230 typedef struct _TOKEN_USER {
4231     SID_AND_ATTRIBUTES User;
4232 } TOKEN_USER, *PTOKEN_USER;
4233
4234 /*
4235  * TOKEN_GROUPS
4236  */
4237
4238 typedef struct _TOKEN_GROUPS {
4239     DWORD GroupCount;
4240     SID_AND_ATTRIBUTES Groups[ANYSIZE_ARRAY];
4241 } TOKEN_GROUPS, *PTOKEN_GROUPS;
4242
4243 /*
4244  * LUID_AND_ATTRIBUTES
4245  */
4246
4247 typedef union _LARGE_INTEGER {
4248     struct {
4249 #ifdef WORDS_BIGENDIAN
4250         LONG     HighPart;
4251         DWORD    LowPart;
4252 #else
4253         DWORD    LowPart;
4254         LONG     HighPart;
4255 #endif
4256     } u;
4257 #ifndef NONAMELESSSTRUCT
4258     struct {
4259 #ifdef WORDS_BIGENDIAN
4260         LONG     HighPart;
4261         DWORD    LowPart;
4262 #else
4263         DWORD    LowPart;
4264         LONG     HighPart;
4265 #endif
4266     };
4267 #endif
4268     LONGLONG QuadPart;
4269 } LARGE_INTEGER, *PLARGE_INTEGER;
4270
4271 typedef union _ULARGE_INTEGER {
4272     struct {
4273 #ifdef WORDS_BIGENDIAN
4274         DWORD    HighPart;
4275         DWORD    LowPart;
4276 #else
4277         DWORD    LowPart;
4278         DWORD    HighPart;
4279 #endif
4280     } u;
4281 #ifndef NONAMELESSSTRUCT
4282     struct {
4283 #ifdef WORDS_BIGENDIAN
4284         DWORD    HighPart;
4285         DWORD    LowPart;
4286 #else
4287         DWORD    LowPart;
4288         DWORD    HighPart;
4289 #endif
4290     };
4291 #endif
4292     ULONGLONG QuadPart;
4293 } ULARGE_INTEGER, *PULARGE_INTEGER;
4294
4295 /*
4296  * Locally Unique Identifier
4297  */
4298
4299 typedef struct _LUID {
4300     DWORD LowPart;
4301     LONG HighPart;
4302 } LUID, *PLUID;
4303
4304 #include <pshpack4.h>
4305 typedef struct _LUID_AND_ATTRIBUTES {
4306   LUID   Luid;
4307   DWORD  Attributes;
4308 } LUID_AND_ATTRIBUTES, *PLUID_AND_ATTRIBUTES;
4309 #include <poppack.h>
4310
4311 /*
4312  * PRIVILEGE_SET
4313  */
4314
4315 typedef struct _PRIVILEGE_SET {
4316     DWORD PrivilegeCount;
4317     DWORD Control;
4318     LUID_AND_ATTRIBUTES Privilege[ANYSIZE_ARRAY];
4319 } PRIVILEGE_SET, *PPRIVILEGE_SET;
4320
4321 /*
4322  * TOKEN_PRIVILEGES
4323  */
4324
4325 typedef struct _TOKEN_PRIVILEGES {
4326   DWORD PrivilegeCount;
4327   LUID_AND_ATTRIBUTES Privileges[ANYSIZE_ARRAY];
4328 } TOKEN_PRIVILEGES, *PTOKEN_PRIVILEGES;
4329
4330 /*
4331  * TOKEN_OWNER
4332  */
4333
4334 typedef struct _TOKEN_OWNER {
4335   PSID Owner;
4336 } TOKEN_OWNER, *PTOKEN_OWNER;
4337
4338 /*
4339  * TOKEN_PRIMARY_GROUP
4340  */
4341
4342 typedef struct _TOKEN_PRIMARY_GROUP {
4343   PSID PrimaryGroup;
4344 } TOKEN_PRIMARY_GROUP, *PTOKEN_PRIMARY_GROUP;
4345
4346
4347 /*
4348  * TOKEN_DEFAULT_DACL
4349  */
4350
4351 typedef struct _TOKEN_DEFAULT_DACL {
4352   PACL DefaultDacl;
4353 } TOKEN_DEFAULT_DACL, *PTOKEN_DEFAULT_DACL;
4354
4355 /*
4356  * TOKEN_SOURCE
4357  */
4358
4359 #define TOKEN_SOURCE_LENGTH 8
4360
4361 typedef struct _TOKEN_SOURCE {
4362   char SourceName[TOKEN_SOURCE_LENGTH];
4363   LUID SourceIdentifier;
4364 } TOKEN_SOURCE, *PTOKEN_SOURCE;
4365
4366 /*
4367  * TOKEN_TYPE
4368  */
4369
4370 typedef enum tagTOKEN_TYPE {
4371   TokenPrimary = 1,
4372   TokenImpersonation
4373 } TOKEN_TYPE;
4374
4375 /*
4376  * SECURITY_IMPERSONATION_LEVEL
4377  */
4378
4379 typedef enum _SECURITY_IMPERSONATION_LEVEL {
4380   SecurityAnonymous,
4381   SecurityIdentification,
4382   SecurityImpersonation,
4383   SecurityDelegation
4384 } SECURITY_IMPERSONATION_LEVEL, *PSECURITY_IMPERSONATION_LEVEL;
4385
4386 #define SECURITY_DYNAMIC_TRACKING   (TRUE)
4387 #define SECURITY_STATIC_TRACKING    (FALSE)
4388
4389 typedef BOOLEAN SECURITY_CONTEXT_TRACKING_MODE,
4390         * PSECURITY_CONTEXT_TRACKING_MODE;
4391 /*
4392  *      Quality of Service
4393  */
4394
4395 typedef struct _SECURITY_QUALITY_OF_SERVICE {
4396   DWORD                         Length;
4397   SECURITY_IMPERSONATION_LEVEL  ImpersonationLevel;
4398   SECURITY_CONTEXT_TRACKING_MODE ContextTrackingMode;
4399   BOOLEAN                       EffectiveOnly;
4400 } SECURITY_QUALITY_OF_SERVICE, *PSECURITY_QUALITY_OF_SERVICE;
4401
4402 /*
4403  * TOKEN_STATISTICS
4404  */
4405
4406 #include <pshpack4.h>
4407 typedef struct _TOKEN_STATISTICS {
4408   LUID  TokenId;
4409   LUID  AuthenticationId;
4410   LARGE_INTEGER ExpirationTime;
4411   TOKEN_TYPE    TokenType;
4412   SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
4413   DWORD DynamicCharged;
4414   DWORD DynamicAvailable;
4415   DWORD GroupCount;
4416   DWORD PrivilegeCount;
4417   LUID  ModifiedId;
4418 } TOKEN_STATISTICS;
4419 #include <poppack.h>
4420
4421 typedef struct _TOKEN_GROUPS_AND_PRIVILEGES {
4422   DWORD                 SidCount;
4423   DWORD                 SidLength;
4424   PSID_AND_ATTRIBUTES   Sids;
4425   DWORD                 RestrictedSidCount;
4426   DWORD                 RestrictedSidLength;
4427   PSID_AND_ATTRIBUTES   RestrictedSids;
4428   DWORD                 PrivilegeCount;
4429   DWORD                 PrivilegeLength;
4430   PLUID_AND_ATTRIBUTES  Privileges;
4431   LUID                  AuthenticationId;
4432 } TOKEN_GROUPS_AND_PRIVILEGES, * PTOKEN_GROUPS_AND_PRIVILEGES;
4433
4434 typedef struct _TOKEN_ORIGIN {
4435   LUID  OriginatingLogonSession;
4436 } TOKEN_ORIGIN, * PTOKEN_ORIGIN;
4437
4438 typedef struct _TOKEN_LINKED_TOKEN {
4439   HANDLE LinkedToken;
4440 } TOKEN_LINKED_TOKEN, * PTOKEN_LINKED_TOKEN;
4441
4442 typedef struct _TOKEN_ELEVATION {
4443   DWORD TokenIsElevated;
4444 } TOKEN_ELEVATION, * PTOKEN_ELEVATION;
4445
4446
4447 /*
4448  *      ACLs of NT
4449  */
4450
4451 /* ACEs, directly starting after an ACL */
4452 typedef struct _ACE_HEADER {
4453         BYTE    AceType;
4454         BYTE    AceFlags;
4455         WORD    AceSize;
4456 } ACE_HEADER,*PACE_HEADER;
4457
4458 /* AceType */
4459 #define ACCESS_ALLOWED_ACE_TYPE         0
4460 #define ACCESS_DENIED_ACE_TYPE          1
4461 #define SYSTEM_AUDIT_ACE_TYPE           2
4462 #define SYSTEM_ALARM_ACE_TYPE           3
4463
4464 /* inherit AceFlags */
4465 #define OBJECT_INHERIT_ACE              0x01
4466 #define CONTAINER_INHERIT_ACE           0x02
4467 #define NO_PROPAGATE_INHERIT_ACE        0x04
4468 #define INHERIT_ONLY_ACE                0x08
4469 #define INHERITED_ACE                   0x10
4470 #define VALID_INHERIT_FLAGS             0x1F
4471
4472 /* AceFlags mask for what events we (should) audit */
4473 #define SUCCESSFUL_ACCESS_ACE_FLAG      0x40
4474 #define FAILED_ACCESS_ACE_FLAG          0x80
4475
4476 /* different ACEs depending on AceType
4477  * SidStart marks the begin of a SID
4478  * so the thing finally looks like this:
4479  * 0: ACE_HEADER
4480  * 4: ACCESS_MASK
4481  * 8... : SID
4482  */
4483 typedef struct _ACCESS_ALLOWED_ACE {
4484         ACE_HEADER      Header;
4485         DWORD           Mask;
4486         DWORD           SidStart;
4487 } ACCESS_ALLOWED_ACE,*PACCESS_ALLOWED_ACE;
4488
4489 typedef struct _ACCESS_DENIED_ACE {
4490         ACE_HEADER      Header;
4491         DWORD           Mask;
4492         DWORD           SidStart;
4493 } ACCESS_DENIED_ACE,*PACCESS_DENIED_ACE;
4494
4495 typedef struct _SYSTEM_AUDIT_ACE {
4496         ACE_HEADER      Header;
4497         DWORD           Mask;
4498         DWORD           SidStart;
4499 } SYSTEM_AUDIT_ACE,*PSYSTEM_AUDIT_ACE;
4500
4501 typedef struct _SYSTEM_ALARM_ACE {
4502         ACE_HEADER      Header;
4503         DWORD           Mask;
4504         DWORD           SidStart;
4505 } SYSTEM_ALARM_ACE,*PSYSTEM_ALARM_ACE;
4506
4507 typedef enum tagSID_NAME_USE {
4508         SidTypeUser = 1,
4509         SidTypeGroup,
4510         SidTypeDomain,
4511         SidTypeAlias,
4512         SidTypeWellKnownGroup,
4513         SidTypeDeletedAccount,
4514         SidTypeInvalid,
4515         SidTypeUnknown
4516 } SID_NAME_USE,*PSID_NAME_USE;
4517
4518 #define ACE_OBJECT_TYPE_PRESENT 0x1
4519 #define ACE_INHERITED_OBJECT_TYPE_PRESENT   0x2
4520
4521 /* Access rights */
4522
4523 /* DELETE may be already defined via /usr/include/arpa/nameser_compat.h */
4524 #undef  DELETE
4525 #define DELETE                     0x00010000
4526 #define READ_CONTROL               0x00020000
4527 #define WRITE_DAC                  0x00040000
4528 #define WRITE_OWNER                0x00080000
4529 #define SYNCHRONIZE                0x00100000
4530 #define STANDARD_RIGHTS_REQUIRED   0x000f0000
4531
4532 #define STANDARD_RIGHTS_READ       READ_CONTROL
4533 #define STANDARD_RIGHTS_WRITE      READ_CONTROL
4534 #define STANDARD_RIGHTS_EXECUTE    READ_CONTROL
4535
4536 #define STANDARD_RIGHTS_ALL        0x001f0000
4537
4538 #define SPECIFIC_RIGHTS_ALL        0x0000ffff
4539
4540 #define GENERIC_READ               0x80000000
4541 #define GENERIC_WRITE              0x40000000
4542 #define GENERIC_EXECUTE            0x20000000
4543 #define GENERIC_ALL                0x10000000
4544
4545 #define MAXIMUM_ALLOWED            0x02000000
4546 #define ACCESS_SYSTEM_SECURITY     0x01000000
4547
4548 #define EVENT_QUERY_STATE          0x0001
4549 #define EVENT_MODIFY_STATE         0x0002
4550 #define EVENT_ALL_ACCESS           (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3)
4551
4552 #define SEMAPHORE_MODIFY_STATE     0x0002
4553 #define SEMAPHORE_ALL_ACCESS       (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3)
4554
4555 #define MUTEX_MODIFY_STATE         0x0001
4556 #define MUTEX_ALL_ACCESS           (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x1)
4557
4558 #define JOB_OBJECT_ASSIGN_PROCESS           0x0001
4559 #define JOB_OBJECT_SET_ATTRIBUTES           0x0002
4560 #define JOB_OBJECT_QUERY                    0x0004
4561 #define JOB_OBJECT_TERMINATE                0x0008
4562 #define JOB_OBJECT_SET_SECURITY_ATTRIBUTES  0x0010
4563 #define JOB_OBJECT_ALL_ACCESS               (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x1f)
4564
4565 #define TIMER_QUERY_STATE          0x0001
4566 #define TIMER_MODIFY_STATE         0x0002
4567 #define TIMER_ALL_ACCESS           (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3)
4568
4569 #define PROCESS_TERMINATE          0x0001
4570 #define PROCESS_CREATE_THREAD      0x0002
4571 #define PROCESS_VM_OPERATION       0x0008
4572 #define PROCESS_VM_READ            0x0010
4573 #define PROCESS_VM_WRITE           0x0020
4574 #define PROCESS_DUP_HANDLE         0x0040
4575 #define PROCESS_CREATE_PROCESS     0x0080
4576 #define PROCESS_SET_QUOTA          0x0100
4577 #define PROCESS_SET_INFORMATION    0x0200
4578 #define PROCESS_QUERY_INFORMATION  0x0400
4579 #define PROCESS_SUSPEND_RESUME     0x0800
4580 #define PROCESS_QUERY_LIMITED_INFORMATION 0x1000
4581 #define PROCESS_ALL_ACCESS         (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0xfff)
4582
4583 #define THREAD_TERMINATE           0x0001
4584 #define THREAD_SUSPEND_RESUME      0x0002
4585 #define THREAD_GET_CONTEXT         0x0008
4586 #define THREAD_SET_CONTEXT         0x0010
4587 #define THREAD_SET_INFORMATION     0x0020
4588 #define THREAD_QUERY_INFORMATION   0x0040
4589 #define THREAD_SET_THREAD_TOKEN    0x0080
4590 #define THREAD_IMPERSONATE         0x0100
4591 #define THREAD_DIRECT_IMPERSONATION 0x0200
4592 #define THREAD_ALL_ACCESS          (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3ff)
4593
4594 #define THREAD_BASE_PRIORITY_LOWRT  15
4595 #define THREAD_BASE_PRIORITY_MAX    2
4596 #define THREAD_BASE_PRIORITY_MIN   -2
4597 #define THREAD_BASE_PRIORITY_IDLE  -15
4598
4599 typedef struct _QUOTA_LIMITS {
4600     SIZE_T PagedPoolLimit;
4601     SIZE_T NonPagedPoolLimit;
4602     SIZE_T MinimumWorkingSetSize;
4603     SIZE_T MaximumWorkingSetSize;
4604     SIZE_T PagefileLimit;
4605     LARGE_INTEGER TimeLimit;
4606 } QUOTA_LIMITS, *PQUOTA_LIMITS;
4607
4608 #define QUOTA_LIMITS_HARDWS_MIN_ENABLE  0x00000001
4609 #define QUOTA_LIMITS_HARDWS_MIN_DISABLE 0x00000002
4610 #define QUOTA_LIMITS_HARDWS_MAX_ENABLE  0x00000004
4611 #define QUOTA_LIMITS_HARDWS_MAX_DISABLE 0x00000008
4612
4613 typedef struct _QUOTA_LIMITS_EX {
4614     SIZE_T PagedPoolLimit;
4615     SIZE_T NonPagedPoolLimit;
4616     SIZE_T MinimumWorkingSetSize;
4617     SIZE_T MaximumWorkingSetSize;
4618     SIZE_T PagefileLimit;
4619     LARGE_INTEGER TimeLimit;
4620     SIZE_T Reserved1;
4621     SIZE_T Reserved2;
4622     SIZE_T Reserved3;
4623     SIZE_T Reserved4;
4624     DWORD Flags;
4625     DWORD Reserved5;
4626 } QUOTA_LIMITS_EX, *PQUOTA_LIMITS_EX;
4627
4628 #define SECTION_QUERY              0x0001
4629 #define SECTION_MAP_WRITE          0x0002
4630 #define SECTION_MAP_READ           0x0004
4631 #define SECTION_MAP_EXECUTE        0x0008
4632 #define SECTION_EXTEND_SIZE        0x0010
4633 #define SECTION_MAP_EXECUTE_EXPLICIT 0x0020
4634 #define SECTION_ALL_ACCESS         (STANDARD_RIGHTS_REQUIRED|0x01f)
4635
4636 #define FILE_READ_DATA            0x0001    /* file & pipe */
4637 #define FILE_LIST_DIRECTORY       0x0001    /* directory */
4638 #define FILE_WRITE_DATA           0x0002    /* file & pipe */
4639 #define FILE_ADD_FILE             0x0002    /* directory */
4640 #define FILE_APPEND_DATA          0x0004    /* file */
4641 #define FILE_ADD_SUBDIRECTORY     0x0004    /* directory */
4642 #define FILE_CREATE_PIPE_INSTANCE 0x0004    /* named pipe */
4643 #define FILE_READ_EA              0x0008    /* file & directory */
4644 #define FILE_READ_PROPERTIES      FILE_READ_EA
4645 #define FILE_WRITE_EA             0x0010    /* file & directory */
4646 #define FILE_WRITE_PROPERTIES     FILE_WRITE_EA
4647 #define FILE_EXECUTE              0x0020    /* file */
4648 #define FILE_TRAVERSE             0x0020    /* directory */
4649 #define FILE_DELETE_CHILD         0x0040    /* directory */
4650 #define FILE_READ_ATTRIBUTES      0x0080    /* all */
4651 #define FILE_WRITE_ATTRIBUTES     0x0100    /* all */
4652 #define FILE_ALL_ACCESS           (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x1ff)
4653
4654 #define FILE_GENERIC_READ         (STANDARD_RIGHTS_READ | FILE_READ_DATA | \
4655                                    FILE_READ_ATTRIBUTES | FILE_READ_EA | \
4656                                    SYNCHRONIZE)
4657 #define FILE_GENERIC_WRITE        (STANDARD_RIGHTS_WRITE | FILE_WRITE_DATA | \
4658                                    FILE_WRITE_ATTRIBUTES | FILE_WRITE_EA | \
4659                                    FILE_APPEND_DATA | SYNCHRONIZE)
4660 #define FILE_GENERIC_EXECUTE      (STANDARD_RIGHTS_EXECUTE | FILE_EXECUTE | \
4661                                    FILE_READ_ATTRIBUTES | SYNCHRONIZE)
4662
4663 #define DUPLICATE_CLOSE_SOURCE     0x00000001
4664 #define DUPLICATE_SAME_ACCESS      0x00000002
4665
4666 /* File attribute flags */
4667 #define FILE_SHARE_READ                 0x00000001L
4668 #define FILE_SHARE_WRITE                0x00000002L
4669 #define FILE_SHARE_DELETE               0x00000004L
4670
4671 #define FILE_ATTRIBUTE_READONLY            0x00000001
4672 #define FILE_ATTRIBUTE_HIDDEN              0x00000002
4673 #define FILE_ATTRIBUTE_SYSTEM              0x00000004
4674 #define FILE_ATTRIBUTE_DIRECTORY           0x00000010
4675 #define FILE_ATTRIBUTE_ARCHIVE             0x00000020
4676 #define FILE_ATTRIBUTE_DEVICE              0x00000040
4677 #define FILE_ATTRIBUTE_NORMAL              0x00000080
4678 #define FILE_ATTRIBUTE_TEMPORARY           0x00000100
4679 #define FILE_ATTRIBUTE_SPARSE_FILE         0x00000200
4680 #define FILE_ATTRIBUTE_REPARSE_POINT       0x00000400
4681 #define FILE_ATTRIBUTE_COMPRESSED          0x00000800
4682 #define FILE_ATTRIBUTE_OFFLINE             0x00001000
4683 #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
4684 #define FILE_ATTRIBUTE_ENCRYPTED           0x00004000
4685
4686 /* File notification flags */
4687 #define FILE_NOTIFY_CHANGE_FILE_NAME    0x00000001
4688 #define FILE_NOTIFY_CHANGE_DIR_NAME     0x00000002
4689 #define FILE_NOTIFY_CHANGE_ATTRIBUTES   0x00000004
4690 #define FILE_NOTIFY_CHANGE_SIZE         0x00000008
4691 #define FILE_NOTIFY_CHANGE_LAST_WRITE   0x00000010
4692 #define FILE_NOTIFY_CHANGE_LAST_ACCESS  0x00000020
4693 #define FILE_NOTIFY_CHANGE_CREATION     0x00000040
4694 #define FILE_NOTIFY_CHANGE_EA           0x00000080
4695 #define FILE_NOTIFY_CHANGE_SECURITY     0x00000100
4696 #define FILE_NOTIFY_CHANGE_STREAM_NAME  0x00000200
4697 #define FILE_NOTIFY_CHANGE_STREAM_SIZE  0x00000400
4698 #define FILE_NOTIFY_CHANGE_STREAM_WRITE 0x00000800
4699
4700 #define FILE_ACTION_ADDED               0x00000001
4701 #define FILE_ACTION_REMOVED             0x00000002
4702 #define FILE_ACTION_MODIFIED            0x00000003
4703 #define FILE_ACTION_RENAMED_OLD_NAME    0x00000004
4704 #define FILE_ACTION_RENAMED_NEW_NAME    0x00000005
4705 #define FILE_ACTION_ADDED_STREAM        0x00000006
4706 #define FILE_ACTION_REMOVED_STREAM      0x00000007
4707 #define FILE_ACTION_MODIFIED_STREAM     0x00000008
4708
4709 #define FILE_CASE_SENSITIVE_SEARCH      0x00000001
4710 #define FILE_CASE_PRESERVED_NAMES       0x00000002
4711 #define FILE_UNICODE_ON_DISK            0x00000004
4712 #define FILE_PERSISTENT_ACLS            0x00000008
4713 #define FILE_FILE_COMPRESSION           0x00000010
4714 #define FILE_VOLUME_IS_COMPRESSED       0x00008000
4715 #define FILE_SUPPORTS_OBJECT_IDS        0x00010000
4716 #define FILE_SUPPORTS_ENCRYPTION        0x00020000
4717 #define FILE_NAMED_STREAMS              0x00040000
4718 #define FILE_READ_ONLY_VOLUME           0x00080000
4719
4720 /* File alignments (NT) */
4721 #define FILE_BYTE_ALIGNMENT             0x00000000
4722 #define FILE_WORD_ALIGNMENT             0x00000001
4723 #define FILE_LONG_ALIGNMENT             0x00000003
4724 #define FILE_QUAD_ALIGNMENT             0x00000007
4725 #define FILE_OCTA_ALIGNMENT             0x0000000f
4726 #define FILE_32_BYTE_ALIGNMENT          0x0000001f
4727 #define FILE_64_BYTE_ALIGNMENT          0x0000003f
4728 #define FILE_128_BYTE_ALIGNMENT         0x0000007f
4729 #define FILE_256_BYTE_ALIGNMENT         0x000000ff
4730 #define FILE_512_BYTE_ALIGNMENT         0x000001ff
4731
4732 #define MAILSLOT_NO_MESSAGE             ((DWORD)-1)
4733 #define MAILSLOT_WAIT_FOREVER           ((DWORD)-1)
4734
4735 #define REG_NONE                0       /* no type */
4736 #define REG_SZ                  1       /* string type (ASCII) */
4737 #define REG_EXPAND_SZ           2       /* string, includes %ENVVAR% (expanded by caller) (ASCII) */
4738 #define REG_BINARY              3       /* binary format, callerspecific */
4739 /* YES, REG_DWORD == REG_DWORD_LITTLE_ENDIAN */
4740 #define REG_DWORD               4       /* DWORD in little endian format */
4741 #define REG_DWORD_LITTLE_ENDIAN 4       /* DWORD in little endian format */
4742 #define REG_DWORD_BIG_ENDIAN    5       /* DWORD in big endian format  */
4743 #define REG_LINK                6       /* symbolic link (UNICODE) */
4744 #define REG_MULTI_SZ            7       /* multiple strings, delimited by \0, terminated by \0\0 (ASCII) */
4745 #define REG_RESOURCE_LIST       8       /* resource list? huh? */
4746 #define REG_FULL_RESOURCE_DESCRIPTOR    9       /* full resource descriptor? huh? */
4747 #define REG_RESOURCE_REQUIREMENTS_LIST  10
4748 #define REG_QWORD               11      /* QWORD in little endian format */
4749 #define REG_QWORD_LITTLE_ENDIAN 11      /* QWORD in little endian format */
4750
4751 /* ----------------------------- begin power management --------------------- */
4752
4753 typedef enum _LATENCY_TIME {
4754         LT_DONT_CARE,
4755         LT_LOWEST_LATENCY
4756 } LATENCY_TIME, *PLATENCY_TIME;
4757
4758 #define DISCHARGE_POLICY_CRITICAL       0
4759 #define DISCHARGE_POLICY_LOW            1
4760 #define NUM_DISCHARGE_POLICIES          4
4761
4762 #define PO_THROTTLE_NONE                0
4763 #define PO_THROTTLE_CONSTANT            1
4764 #define PO_THROTTLE_DEGRADE             2
4765 #define PO_THROTTLE_ADAPTIVE            3
4766
4767 typedef enum _POWER_ACTION {
4768         PowerActionNone = 0,
4769         PowerActionReserved,
4770         PowerActionSleep,
4771         PowerActionHibernate,
4772         PowerActionShutdown,
4773         PowerActionShutdownReset,
4774         PowerActionShutdownOff,
4775         PowerActionWarmEject
4776 } POWER_ACTION,
4777 *PPOWER_ACTION;
4778
4779 typedef enum _SYSTEM_POWER_STATE {
4780         PowerSystemUnspecified = 0,
4781         PowerSystemWorking = 1,
4782         PowerSystemSleeping1 = 2,
4783         PowerSystemSleeping2 = 3,
4784         PowerSystemSleeping3 = 4,
4785         PowerSystemHibernate = 5,
4786         PowerSystemShutdown = 6,
4787         PowerSystemMaximum = 7
4788 } SYSTEM_POWER_STATE,
4789 *PSYSTEM_POWER_STATE;
4790
4791 typedef enum _DEVICE_POWER_STATE {
4792     PowerDeviceUnspecified,
4793     PowerDeviceD0,
4794     PowerDeviceD1,
4795     PowerDeviceD2,
4796     PowerDeviceD3,
4797     PowerDeviceMaximum
4798 } DEVICE_POWER_STATE, *PDEVICE_POWER_STATE;
4799
4800 typedef enum _POWER_INFORMATION_LEVEL {
4801         SystemPowerPolicyAc,
4802         SystemPowerPolicyDc,
4803         VerifySystemPolicyAc,
4804         VerifySystemPolicyDc,
4805         SystemPowerCapabilities,
4806         SystemBatteryState,
4807         SystemPowerStateHandler,
4808         ProcessorStateHandler,
4809         SystemPowerPolicyCurrent,
4810         AdministratorPowerPolicy,
4811         SystemReserveHiberFile,
4812         ProcessorInformation,
4813         SystemPowerInformation,
4814         ProcessorStateHandler2,
4815         LastWakeTime,
4816         LastSleepTime,
4817         SystemExecutionState,
4818         SystemPowerStateNotifyHandler,
4819         ProcessorPowerPolicyAc,
4820         ProcessorPowerPolicyDc,
4821         VerifyProcessorPowerPolicyAc,
4822         VerifyProcessorPowerPolicyDc,
4823         ProcessorPowerPolicyCurrent
4824 } POWER_INFORMATION_LEVEL;
4825
4826 typedef struct _ADMINISTRATOR_POWER_POLICY {
4827         SYSTEM_POWER_STATE MinSleep;
4828         SYSTEM_POWER_STATE MaxSleep;
4829         ULONG MinVideoTimeout;
4830         ULONG MaxVideoTimeout;
4831         ULONG MinSpindownTimeout;
4832         ULONG MaxSpindownTimeout;
4833 } ADMINISTRATOR_POWER_POLICY, *PADMINISTRATOR_POWER_POLICY;
4834
4835 typedef struct {
4836         ULONG Granularity;
4837         ULONG Capacity;
4838 } BATTERY_REPORTING_SCALE,
4839 *PBATTERY_REPORTING_SCALE;
4840
4841 typedef struct {
4842         POWER_ACTION Action;
4843         ULONG Flags;
4844         ULONG EventCode;
4845 } POWER_ACTION_POLICY,
4846 *PPOWER_ACTION_POLICY;
4847
4848 typedef struct _PROCESSOR_POWER_INFORMATION {
4849         ULONG Number;
4850         ULONG MaxMhz;
4851         ULONG CurrentMhz;
4852         ULONG MhzLimit;
4853         ULONG MaxIdleState;
4854         ULONG CurrentIdleState;
4855 } PROCESSOR_POWER_INFORMATION,
4856 *PPROCESSOR_POWER_INFORMATION;
4857
4858 typedef struct _PROCESSOR_POWER_POLICY_INFO {
4859         ULONG TimeCheck;
4860         ULONG DemoteLimit;
4861         ULONG PromoteLimit;
4862         UCHAR DemotePercent;
4863         UCHAR PromotePercent;
4864         UCHAR Spare[2];
4865         ULONG AllowDemotion:1;
4866         ULONG AllowPromotion:1;
4867         ULONG Reserved:30;
4868 } PROCESSOR_POWER_POLICY_INFO,
4869 *PPROCESSOR_POWER_POLICY_INFO;
4870
4871 typedef struct _PROCESSOR_POWER_POLICY {
4872         DWORD Revision;
4873         BYTE DynamicThrottle;
4874         BYTE Spare[3];
4875         DWORD DisableCStates:1;
4876         DWORD Reserved:31;
4877         DWORD PolicyCount;
4878         PROCESSOR_POWER_POLICY_INFO Policy[3];
4879 } PROCESSOR_POWER_POLICY,
4880 *PPROCESSOR_POWER_POLICY;
4881
4882 typedef struct {
4883         BOOLEAN AcOnLine;
4884         BOOLEAN BatteryPresent;
4885         BOOLEAN Charging;
4886         BOOLEAN Discharging;
4887         BOOLEAN Spare1[4];
4888         ULONG MaxCapacity;
4889         ULONG RemainingCapacity;
4890         ULONG Rate;
4891         ULONG EstimatedTime;
4892         ULONG DefaultAlert1;
4893         ULONG DefaultAlert2;
4894 } SYSTEM_BATTERY_STATE,
4895 *PSYSTEM_BATTERY_STATE;
4896
4897 typedef struct {
4898         BOOLEAN PowerButtonPresent;
4899         BOOLEAN SleepButtonPresent;
4900         BOOLEAN LidPresent;
4901         BOOLEAN SystemS1;
4902         BOOLEAN SystemS2;
4903         BOOLEAN SystemS3;
4904         BOOLEAN SystemS4;
4905         BOOLEAN SystemS5;
4906         BOOLEAN HiberFilePresent;
4907         BOOLEAN FullWake;
4908         BOOLEAN VideoDimPresent;
4909         BOOLEAN ApmPresent;
4910         BOOLEAN UpsPresent;
4911         BOOLEAN ThermalControl;
4912         BOOLEAN ProcessorThrottle;
4913         UCHAR ProcessorMinThrottle;
4914         UCHAR ProcessorMaxThrottle;
4915         UCHAR spare2[4];
4916         BOOLEAN DiskSpinDown;
4917         UCHAR spare3[8];
4918         BOOLEAN SystemBatteriesPresent;
4919         BOOLEAN BatteriesAreShortTerm;
4920         BATTERY_REPORTING_SCALE BatteryScale[3];
4921         SYSTEM_POWER_STATE AcOnLineWake;
4922         SYSTEM_POWER_STATE SoftLidWake;
4923         SYSTEM_POWER_STATE RtcWake;
4924         SYSTEM_POWER_STATE MinDeviceWakeState;
4925         SYSTEM_POWER_STATE DefaultLowLatencyWake;
4926 } SYSTEM_POWER_CAPABILITIES,
4927 *PSYSTEM_POWER_CAPABILITIES;
4928
4929 typedef struct _SYSTEM_POWER_INFORMATION {
4930         ULONG MaxIdlenessAllowed;
4931         ULONG Idleness;
4932         ULONG TimeRemaining;
4933         UCHAR CoolingMode;
4934 } SYSTEM_POWER_INFORMATION,
4935 *PSYSTEM_POWER_INFORMATION;
4936
4937 typedef struct _SYSTEM_POWER_LEVEL {
4938         BOOLEAN Enable;
4939         UCHAR Spare[3];
4940         ULONG BatteryLevel;
4941         POWER_ACTION_POLICY PowerPolicy;
4942         SYSTEM_POWER_STATE MinSystemState;
4943 } SYSTEM_POWER_LEVEL,
4944 *PSYSTEM_POWER_LEVEL;
4945
4946 typedef struct _SYSTEM_POWER_POLICY {
4947         ULONG Revision;
4948         POWER_ACTION_POLICY PowerButton;
4949         POWER_ACTION_POLICY SleepButton;
4950         POWER_ACTION_POLICY LidClose;
4951         SYSTEM_POWER_STATE LidOpenWake;
4952         ULONG Reserved;
4953         POWER_ACTION_POLICY Idle;
4954         ULONG IdleTimeout;
4955         UCHAR IdleSensitivity;
4956         UCHAR DynamicThrottle;
4957         UCHAR Spare2[2];
4958         SYSTEM_POWER_STATE MinSleep;
4959         SYSTEM_POWER_STATE MaxSleep;
4960         SYSTEM_POWER_STATE ReducedLatencySleep;
4961         ULONG WinLogonFlags;
4962         ULONG Spare3;
4963         ULONG DozeS4Timeout;
4964         ULONG BroadcastCapacityResolution;
4965         SYSTEM_POWER_LEVEL DischargePolicy[NUM_DISCHARGE_POLICIES];
4966         ULONG VideoTimeout;
4967         BOOLEAN VideoDimDisplay;
4968         ULONG VideoReserved[3];
4969         ULONG SpindownTimeout;
4970         BOOLEAN OptimizeForPower;
4971         UCHAR FanThrottleTolerance;
4972         UCHAR ForcedThrottle;
4973         UCHAR MinThrottle;
4974         POWER_ACTION_POLICY OverThrottled;
4975 } SYSTEM_POWER_POLICY,
4976 *PSYSTEM_POWER_POLICY;
4977
4978 typedef union _FILE_SEGMENT_ELEMENT {
4979         PVOID64 Buffer;
4980         ULONGLONG Alignment;
4981 } FILE_SEGMENT_ELEMENT, *PFILE_SEGMENT_ELEMENT;
4982
4983 typedef struct _FILE_NOTIFY_INFORMATION {
4984         DWORD NextEntryOffset;
4985         DWORD Action;
4986         DWORD FileNameLength;
4987         WCHAR FileName[1];
4988 } FILE_NOTIFY_INFORMATION, *PFILE_NOTIFY_INFORMATION;
4989
4990 /* ----------------------------- begin tape storage --------------------- */
4991
4992 #define TAPE_FIXED_PARTITIONS     0
4993 #define TAPE_SELECT_PARTITIONS    1
4994 #define TAPE_INITIATOR_PARTITIONS 2
4995 #define TAPE_ERASE_SHORT 0
4996 #define TAPE_ERASE_LONG  1
4997 #define TAPE_LOAD    0
4998 #define TAPE_UNLOAD  1
4999 #define TAPE_TENSION 2
5000 #define TAPE_LOCK    3
5001 #define TAPE_UNLOCK  4
5002 #define TAPE_FORMAT  5
5003 #define TAPE_SETMARKS  0
5004 #define TAPE_FILEMARKS 1
5005 #define TAPE_SHORT_FILEMARKS 2
5006 #define TAPE_LONG_FILEMARKS  3
5007 #define TAPE_REWIND                0
5008 #define TAPE_ABSOLUTE_BLOCK        1
5009 #define TAPE_LOGICAL_BLOCK         2
5010 #define TAPE_PSEUDO_LOGICAL_BLOCK  3
5011 #define TAPE_SPACE_END_OF_DATA     4
5012 #define TAPE_SPACE_RELATIVE_BLOCKS 5
5013 #define TAPE_SPACE_FILEMARKS       6
5014 #define TAPE_SPACE_SEQUENTIAL_FMKS 7
5015 #define TAPE_SPACE_SETMARKS        8
5016 #define TAPE_SPACE_SEQUENTIAL_SMKS 9
5017
5018 typedef struct _TAPE_CREATE_PARTITION {
5019     DWORD Method;
5020     DWORD Count;
5021     DWORD Size;
5022 } TAPE_CREATE_PARTITION, *PTAPE_CREATE_PARTITION;
5023
5024 typedef struct _TAPE_ERASE {
5025     DWORD Type;
5026     BOOLEAN Immediate;
5027 } TAPE_ERASE, *PTAPE_ERASE;
5028
5029 typedef struct _TAPE_PREPARE {
5030     DWORD Operation;
5031     BOOLEAN Immediate;
5032 } TAPE_PREPARE, *PTAPE_PREPARE;
5033
5034 typedef struct _TAPE_SET_DRIVE_PARAMETERS {
5035     BOOLEAN ECC;
5036     BOOLEAN Compression;
5037     BOOLEAN DataPadding;
5038     BOOLEAN ReportSetmarks;
5039     ULONG EOTWarningZoneSize;
5040 } TAPE_SET_DRIVE_PARAMETERS, *PTAPE_SET_DRIVE_PARAMETERS;
5041
5042 typedef struct _TAPE_SET_MEDIA_PARAMETERS {
5043     ULONG BlockSize;
5044 } TAPE_SET_MEDIA_PARAMETERS, *PTAPE_SET_MEDIA_PARAMETERS;
5045
5046 typedef struct _TAPE_WRITE_MARKS {
5047     DWORD Type;
5048     DWORD Count;
5049     BOOLEAN Immediate;
5050 } TAPE_WRITE_MARKS, *PTAPE_WRITE_MARKS;
5051
5052 typedef struct _TAPE_GET_POSITION {
5053     ULONG Type;
5054     ULONG Partition;
5055     ULONG OffsetLow;
5056     ULONG OffsetHigh;
5057 } TAPE_GET_POSITION, *PTAPE_GET_POSITION;
5058
5059 typedef struct _TAPE_SET_POSITION {
5060     ULONG Method;
5061     ULONG Partition;
5062     LARGE_INTEGER Offset;
5063     BOOLEAN Immediate;
5064 } TAPE_SET_POSITION, *PTAPE_SET_POSITION;
5065
5066 typedef struct _TAPE_GET_DRIVE_PARAMETERS {
5067     BOOLEAN ECC;
5068     BOOLEAN Compression;
5069     BOOLEAN DataPadding;
5070     BOOLEAN ReportSetmarks;
5071     DWORD DefaultBlockSize;
5072     DWORD MaximumBlockSize;
5073     DWORD MinimumBlockSize;
5074     DWORD MaximumPartitionCount;
5075     DWORD FeaturesLow;
5076     DWORD FeaturesHigh;
5077     DWORD EOTWarningZoneSize;
5078 } TAPE_GET_DRIVE_PARAMETERS, *PTAPE_GET_DRIVE_PARAMETERS;
5079
5080 typedef struct _TAPE_GET_MEDIA_PARAMETERS {
5081     LARGE_INTEGER Capacity;
5082     LARGE_INTEGER Remaining;
5083     DWORD BlockSize;
5084     DWORD PartitionCount;
5085     BOOLEAN WriteProtected;
5086 } TAPE_GET_MEDIA_PARAMETERS, *PTAPE_GET_MEDIA_PARAMETERS;
5087
5088 /* ----------------------------- begin registry ----------------------------- */
5089
5090 /* Registry security values */
5091 #define OWNER_SECURITY_INFORMATION      0x00000001
5092 #define GROUP_SECURITY_INFORMATION      0x00000002
5093 #define DACL_SECURITY_INFORMATION       0x00000004
5094 #define SACL_SECURITY_INFORMATION       0x00000008
5095
5096 #define REG_OPTION_RESERVED             0x00000000
5097 #define REG_OPTION_NON_VOLATILE         0x00000000
5098 #define REG_OPTION_VOLATILE             0x00000001
5099 #define REG_OPTION_CREATE_LINK          0x00000002
5100 #define REG_OPTION_BACKUP_RESTORE       0x00000004 /* FIXME */
5101 #define REG_OPTION_OPEN_LINK            0x00000008
5102 #define REG_LEGAL_OPTION               (REG_OPTION_RESERVED|  \
5103                                         REG_OPTION_NON_VOLATILE|  \
5104                                         REG_OPTION_VOLATILE|  \
5105                                         REG_OPTION_CREATE_LINK|  \
5106                                         REG_OPTION_BACKUP_RESTORE|  \
5107                                         REG_OPTION_OPEN_LINK)
5108
5109
5110 #define REG_CREATED_NEW_KEY     0x00000001
5111 #define REG_OPENED_EXISTING_KEY 0x00000002
5112
5113 /* For RegNotifyChangeKeyValue */
5114 #define REG_NOTIFY_CHANGE_NAME       0x01
5115 #define REG_NOTIFY_CHANGE_ATTRIBUTES 0x02
5116 #define REG_NOTIFY_CHANGE_LAST_SET   0x04
5117 #define REG_NOTIFY_CHANGE_SECURITY   0x08
5118
5119 #define KEY_QUERY_VALUE         0x00000001
5120 #define KEY_SET_VALUE           0x00000002
5121 #define KEY_CREATE_SUB_KEY      0x00000004
5122 #define KEY_ENUMERATE_SUB_KEYS  0x00000008
5123 #define KEY_NOTIFY              0x00000010
5124 #define KEY_CREATE_LINK         0x00000020
5125 #define KEY_WOW64_64KEY         0x00000100
5126 #define KEY_WOW64_32KEY         0x00000200
5127 #define KEY_WOW64_RES           0x00000300
5128
5129 /* for RegKeyRestore flags */
5130 #define REG_WHOLE_HIVE_VOLATILE 0x00000001
5131 #define REG_REFRESH_HIVE        0x00000002
5132 #define REG_NO_LAZY_FLUSH       0x00000004
5133 #define REG_FORCE_RESTORE       0x00000008
5134
5135 #define KEY_READ              ((STANDARD_RIGHTS_READ|  \
5136                                 KEY_QUERY_VALUE|  \
5137                                 KEY_ENUMERATE_SUB_KEYS|  \
5138                                 KEY_NOTIFY)  \
5139                                 & (~SYNCHRONIZE)  \
5140                               )
5141 #define KEY_WRITE             ((STANDARD_RIGHTS_WRITE|  \
5142                                 KEY_SET_VALUE|  \
5143                                 KEY_CREATE_SUB_KEY)  \
5144                                 & (~SYNCHRONIZE)  \
5145                               )
5146 #define KEY_EXECUTE           ((KEY_READ) & (~SYNCHRONIZE))
5147 #define KEY_ALL_ACCESS        ((STANDARD_RIGHTS_ALL|  \
5148                                 KEY_QUERY_VALUE|  \
5149                                 KEY_SET_VALUE|  \
5150                                 KEY_CREATE_SUB_KEY|  \
5151                                 KEY_ENUMERATE_SUB_KEYS|  \
5152                                 KEY_NOTIFY|  \
5153                                 KEY_CREATE_LINK)  \
5154                                 & (~SYNCHRONIZE)  \
5155                               )
5156 /* ------------------------------ end registry ------------------------------ */
5157
5158
5159 #define EVENTLOG_SUCCESS                0x0000
5160 #define EVENTLOG_ERROR_TYPE             0x0001
5161 #define EVENTLOG_WARNING_TYPE           0x0002
5162 #define EVENTLOG_INFORMATION_TYPE       0x0004
5163 #define EVENTLOG_AUDIT_SUCCESS          0x0008
5164 #define EVENTLOG_AUDIT_FAILURE          0x0010
5165
5166 #define EVENTLOG_SEQUENTIAL_READ        0x0001
5167 #define EVENTLOG_SEEK_READ              0x0002
5168 #define EVENTLOG_FORWARDS_READ          0x0004
5169 #define EVENTLOG_BACKWARDS_READ         0x0008
5170
5171 typedef struct _EVENTLOGRECORD {
5172     DWORD  Length;
5173     DWORD  Reserved;
5174     DWORD  RecordNumber;
5175     DWORD  TimeGenerated;
5176     DWORD  TimeWritten;
5177     DWORD  EventID;
5178     WORD   EventType;
5179     WORD   NumStrings;
5180     WORD   EventCategory;
5181     WORD   ReservedFlags;
5182     DWORD  ClosingRecordNumber;
5183     DWORD  StringOffset;
5184     DWORD  UserSidLength;
5185     DWORD  UserSidOffset;
5186     DWORD  DataLength;
5187     DWORD  DataOffset;
5188 } EVENTLOGRECORD, *PEVENTLOGRECORD;
5189
5190 #define SERVICE_BOOT_START   0x00000000
5191 #define SERVICE_SYSTEM_START 0x00000001
5192 #define SERVICE_AUTO_START   0x00000002
5193 #define SERVICE_DEMAND_START 0x00000003
5194 #define SERVICE_DISABLED     0x00000004
5195
5196 #define SERVICE_ERROR_IGNORE   0x00000000
5197 #define SERVICE_ERROR_NORMAL   0x00000001
5198 #define SERVICE_ERROR_SEVERE   0x00000002
5199 #define SERVICE_ERROR_CRITICAL 0x00000003
5200
5201 /* Service types */
5202 #define SERVICE_KERNEL_DRIVER      0x00000001
5203 #define SERVICE_FILE_SYSTEM_DRIVER 0x00000002
5204 #define SERVICE_ADAPTER            0x00000004
5205 #define SERVICE_RECOGNIZER_DRIVER  0x00000008
5206
5207 #define SERVICE_DRIVER ( SERVICE_KERNEL_DRIVER | SERVICE_FILE_SYSTEM_DRIVER | \
5208                          SERVICE_RECOGNIZER_DRIVER )
5209
5210 #define SERVICE_WIN32_OWN_PROCESS   0x00000010
5211 #define SERVICE_WIN32_SHARE_PROCESS 0x00000020
5212 #define SERVICE_WIN32  (SERVICE_WIN32_OWN_PROCESS | SERVICE_WIN32_SHARE_PROCESS)
5213
5214 #define SERVICE_INTERACTIVE_PROCESS 0x00000100
5215
5216 #define SERVICE_TYPE_ALL ( SERVICE_WIN32 | SERVICE_ADAPTER | \
5217                            SERVICE_DRIVER | SERVICE_INTERACTIVE_PROCESS )
5218
5219
5220 typedef enum _CM_SERVICE_NODE_TYPE
5221 {
5222   DriverType               = SERVICE_KERNEL_DRIVER,
5223   FileSystemType           = SERVICE_FILE_SYSTEM_DRIVER,
5224   Win32ServiceOwnProcess   = SERVICE_WIN32_OWN_PROCESS,
5225   Win32ServiceShareProcess = SERVICE_WIN32_SHARE_PROCESS,
5226   AdapterType              = SERVICE_ADAPTER,
5227   RecognizerType           = SERVICE_RECOGNIZER_DRIVER
5228 } SERVICE_NODE_TYPE;
5229
5230 typedef enum _CM_SERVICE_LOAD_TYPE
5231 {
5232   BootLoad    = SERVICE_BOOT_START,
5233   SystemLoad  = SERVICE_SYSTEM_START,
5234   AutoLoad    = SERVICE_AUTO_START,
5235   DemandLoad  = SERVICE_DEMAND_START,
5236   DisableLoad = SERVICE_DISABLED
5237 } SERVICE_LOAD_TYPE;
5238
5239 typedef enum _CM_ERROR_CONTROL_TYPE
5240 {
5241   IgnoreError   = SERVICE_ERROR_IGNORE,
5242   NormalError   = SERVICE_ERROR_NORMAL,
5243   SevereError   = SERVICE_ERROR_SEVERE,
5244   CriticalError = SERVICE_ERROR_CRITICAL
5245 } SERVICE_ERROR_TYPE;
5246
5247
5248
5249 #define RtlEqualMemory(Destination, Source, Length) (!memcmp((Destination),(Source),(Length)))
5250 #define RtlMoveMemory(Destination, Source, Length) memmove((Destination),(Source),(Length))
5251 #define RtlCopyMemory(Destination, Source, Length) memcpy((Destination),(Source),(Length))
5252 #define RtlFillMemory(Destination, Length, Fill) memset((Destination),(Fill),(Length))
5253 #define RtlZeroMemory(Destination, Length) memset((Destination),0,(Length))
5254
5255 #include <guiddef.h>
5256
5257 typedef struct _OBJECT_TYPE_LIST {
5258     WORD   Level;
5259     WORD   Sbz;
5260     GUID *ObjectType;
5261 } OBJECT_TYPE_LIST, *POBJECT_TYPE_LIST;
5262
5263 typedef struct _RTL_CRITICAL_SECTION_DEBUG
5264 {
5265   WORD   Type;
5266   WORD   CreatorBackTraceIndex;
5267   struct _RTL_CRITICAL_SECTION *CriticalSection;
5268   LIST_ENTRY ProcessLocksList;
5269   DWORD EntryCount;
5270   DWORD ContentionCount;
5271 #ifdef __WINESRC__  /* in Wine we store the name here */
5272   DWORD_PTR Spare[8/sizeof(DWORD_PTR)];
5273 #else
5274   DWORD Spare[ 2 ];
5275 #endif
5276 } RTL_CRITICAL_SECTION_DEBUG, *PRTL_CRITICAL_SECTION_DEBUG, RTL_RESOURCE_DEBUG, *PRTL_RESOURCE_DEBUG;
5277
5278 typedef struct _RTL_CRITICAL_SECTION {
5279     PRTL_CRITICAL_SECTION_DEBUG DebugInfo;
5280     LONG LockCount;
5281     LONG RecursionCount;
5282     HANDLE OwningThread;
5283     HANDLE LockSemaphore;
5284     ULONG_PTR SpinCount;
5285 }  RTL_CRITICAL_SECTION, *PRTL_CRITICAL_SECTION;
5286
5287 #define RTL_CRITICAL_SECTION_FLAG_NO_DEBUG_INFO 0x1000000
5288 #define RTL_CRITICAL_SECTION_FLAG_DYNAMIC_SPIN  0x2000000
5289 #define RTL_CRITICAL_SECTION_FLAG_STATIC_INIT   0x4000000
5290 #define RTL_CRITICAL_SECTION_ALL_FLAG_BITS      0xFF000000
5291 #define RTL_CRITICAL_SECTION_FLAG_RESERVED      (RTL_CRITICAL_SECTION_ALL_FLAG_BITS & ~0x7000000)
5292
5293 typedef VOID (NTAPI * WAITORTIMERCALLBACKFUNC) (PVOID, BOOLEAN );
5294 typedef VOID (NTAPI * PFLS_CALLBACK_FUNCTION) ( PVOID );
5295
5296 #include <pshpack8.h>
5297 typedef struct _IO_COUNTERS {
5298     ULONGLONG DECLSPEC_ALIGN(8) ReadOperationCount;
5299     ULONGLONG DECLSPEC_ALIGN(8) WriteOperationCount;
5300     ULONGLONG DECLSPEC_ALIGN(8) OtherOperationCount;
5301     ULONGLONG DECLSPEC_ALIGN(8) ReadTransferCount;
5302     ULONGLONG DECLSPEC_ALIGN(8) WriteTransferCount;
5303     ULONGLONG DECLSPEC_ALIGN(8) OtherTransferCount;
5304 } IO_COUNTERS, *PIO_COUNTERS;
5305 #include <poppack.h>
5306
5307 typedef struct {
5308         DWORD dwOSVersionInfoSize;
5309         DWORD dwMajorVersion;
5310         DWORD dwMinorVersion;
5311         DWORD dwBuildNumber;
5312         DWORD dwPlatformId;
5313         CHAR szCSDVersion[128];
5314 } OSVERSIONINFOA, *POSVERSIONINFOA, *LPOSVERSIONINFOA;
5315
5316 typedef struct {
5317         DWORD dwOSVersionInfoSize;
5318         DWORD dwMajorVersion;
5319         DWORD dwMinorVersion;
5320         DWORD dwBuildNumber;
5321         DWORD dwPlatformId;
5322         WCHAR szCSDVersion[128];
5323 } OSVERSIONINFOW, *POSVERSIONINFOW, *LPOSVERSIONINFOW, RTL_OSVERSIONINFOW, *PRTL_OSVERSIONINFOW;
5324
5325 DECL_WINELIB_TYPE_AW(OSVERSIONINFO)
5326 DECL_WINELIB_TYPE_AW(POSVERSIONINFO)
5327 DECL_WINELIB_TYPE_AW(LPOSVERSIONINFO)
5328
5329 typedef struct {
5330         DWORD dwOSVersionInfoSize;
5331         DWORD dwMajorVersion;
5332         DWORD dwMinorVersion;
5333         DWORD dwBuildNumber;
5334         DWORD dwPlatformId;
5335         CHAR szCSDVersion[128];
5336         WORD wServicePackMajor;
5337         WORD wServicePackMinor;
5338         WORD wSuiteMask;
5339         BYTE wProductType;
5340         BYTE wReserved;
5341 } OSVERSIONINFOEXA, *POSVERSIONINFOEXA, *LPOSVERSIONINFOEXA;
5342
5343 typedef struct {
5344         DWORD dwOSVersionInfoSize;
5345         DWORD dwMajorVersion;
5346         DWORD dwMinorVersion;
5347         DWORD dwBuildNumber;
5348         DWORD dwPlatformId;
5349         WCHAR szCSDVersion[128];
5350         WORD wServicePackMajor;
5351         WORD wServicePackMinor;
5352         WORD wSuiteMask;
5353         BYTE wProductType;
5354         BYTE wReserved;
5355 } OSVERSIONINFOEXW, *POSVERSIONINFOEXW, *LPOSVERSIONINFOEXW, RTL_OSVERSIONINFOEXW, *PRTL_OSVERSIONINFOEXW;
5356
5357 DECL_WINELIB_TYPE_AW(OSVERSIONINFOEX)
5358 DECL_WINELIB_TYPE_AW(POSVERSIONINFOEX)
5359 DECL_WINELIB_TYPE_AW(LPOSVERSIONINFOEX)
5360
5361 NTSYSAPI ULONGLONG WINAPI VerSetConditionMask(ULONGLONG,DWORD,BYTE);
5362
5363 #define VER_SET_CONDITION(_m_,_t_,_c_) ((_m_)=VerSetConditionMask((_m_),(_t_),(_c_)))
5364
5365 #define VER_PLATFORM_WIN32s                     0
5366 #define VER_PLATFORM_WIN32_WINDOWS              1
5367 #define VER_PLATFORM_WIN32_NT                   2
5368
5369 #define VER_MINORVERSION                        0x00000001
5370 #define VER_MAJORVERSION                        0x00000002
5371 #define VER_BUILDNUMBER                         0x00000004
5372 #define VER_PLATFORMID                          0x00000008
5373 #define VER_SERVICEPACKMINOR                    0x00000010
5374 #define VER_SERVICEPACKMAJOR                    0x00000020
5375 #define VER_SUITENAME                           0x00000040
5376 #define VER_PRODUCT_TYPE                        0x00000080
5377
5378 #define VER_NT_WORKSTATION                      1
5379 #define VER_NT_DOMAIN_CONTROLLER                2
5380 #define VER_NT_SERVER                           3
5381
5382 #define VER_SUITE_SMALLBUSINESS                 0x00000001
5383 #define VER_SUITE_ENTERPRISE                    0x00000002
5384 #define VER_SUITE_BACKOFFICE                    0x00000004
5385 #define VER_SUITE_COMMUNICATIONS                0x00000008
5386 #define VER_SUITE_TERMINAL                      0x00000010
5387 #define VER_SUITE_SMALLBUSINESS_RESTRICTED      0x00000020
5388 #define VER_SUITE_EMBEDDEDNT                    0x00000040
5389 #define VER_SUITE_DATACENTER                    0x00000080
5390 #define VER_SUITE_SINGLEUSERTS                  0x00000100
5391 #define VER_SUITE_PERSONAL                      0x00000200
5392 #define VER_SUITE_BLADE                         0x00000400
5393
5394 #define VER_EQUAL                               1
5395 #define VER_GREATER                             2
5396 #define VER_GREATER_EQUAL                       3
5397 #define VER_LESS                                4
5398 #define VER_LESS_EQUAL                          5
5399 #define VER_AND                                 6
5400 #define VER_OR                                  7
5401
5402 typedef struct _ACTIVATION_CONTEXT_DETAILED_INFORMATION {
5403     DWORD dwFlags;
5404     DWORD ulFormatVersion;
5405     DWORD ulAssemblyCount;
5406     DWORD ulRootManifestPathType;
5407     DWORD ulRootManifestPathChars;
5408     DWORD ulRootConfigurationPathType;
5409     DWORD ulRootConfigurationPathChars;
5410     DWORD ulAppDirPathType;
5411     DWORD ulAppDirPathChars;
5412     PCWSTR lpRootManifestPath;
5413     PCWSTR lpRootConfigurationPath;
5414     PCWSTR lpAppDirPath;
5415 } ACTIVATION_CONTEXT_DETAILED_INFORMATION, *PACTIVATION_CONTEXT_DETAILED_INFORMATION;
5416
5417 typedef struct _ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION {
5418     DWORD ulFlags;
5419     DWORD ulEncodedAssemblyIdentityLength;
5420     DWORD ulManifestPathType;
5421     DWORD ulManifestPathLength;
5422     LARGE_INTEGER liManifestLastWriteTime;
5423     DWORD ulPolicyPathType;
5424     DWORD ulPolicyPathLength;
5425     LARGE_INTEGER liPolicyLastWriteTime;
5426     DWORD ulMetadataSatelliteRosterIndex;
5427     DWORD ulManifestVersionMajor;
5428     DWORD ulManifestVersionMinor;
5429     DWORD ulPolicyVersionMajor;
5430     DWORD ulPolicyVersionMinor;
5431     DWORD ulAssemblyDirectoryNameLength;
5432     PCWSTR lpAssemblyEncodedAssemblyIdentity;
5433     PCWSTR lpAssemblyManifestPath;
5434     PCWSTR lpAssemblyPolicyPath;
5435     PCWSTR lpAssemblyDirectoryName;
5436     DWORD  ulFileCount;
5437 } ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION, *PACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION;
5438
5439 typedef struct _ACTIVATION_CONTEXT_QUERY_INDEX {
5440     DWORD ulAssemblyIndex;
5441     DWORD ulFileIndexInAssembly;
5442 } ACTIVATION_CONTEXT_QUERY_INDEX, *PACTIVATION_CONTEXT_QUERY_INDEX;
5443
5444 typedef const struct _ACTIVATION_CONTEXT_QUERY_INDEX *PCACTIVATION_CONTEXT_QUERY_INDEX;
5445
5446 typedef struct _ASSEMBLY_FILE_DETAILED_INFORMATION {
5447     DWORD ulFlags;
5448     DWORD ulFilenameLength;
5449     DWORD ulPathLength;
5450     PCWSTR lpFileName;
5451     PCWSTR lpFilePath;
5452 } ASSEMBLY_FILE_DETAILED_INFORMATION, *PASSEMBLY_FILE_DETAILED_INFORMATION;
5453
5454 typedef const ASSEMBLY_FILE_DETAILED_INFORMATION *PCASSEMBLY_FILE_DETAILED_INFORMATION;
5455
5456 typedef enum _ACTIVATION_CONTEXT_INFO_CLASS {
5457     ActivationContextBasicInformation                       = 1,
5458     ActivationContextDetailedInformation                    = 2,
5459     AssemblyDetailedInformationInActivationContext          = 3,
5460     FileInformationInAssemblyOfAssemblyInActivationContext  = 4,
5461     MaxActivationContextInfoClass,
5462
5463     AssemblyDetailedInformationInActivationContxt          = 3,
5464     FileInformationInAssemblyOfAssemblyInActivationContxt  = 4
5465 } ACTIVATION_CONTEXT_INFO_CLASS;
5466
5467 #define ACTIVATION_CONTEXT_PATH_TYPE_NONE         1
5468 #define ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE   2
5469 #define ACTIVATION_CONTEXT_PATH_TYPE_URL          3
5470 #define ACTIVATION_CONTEXT_PATH_TYPE_ASSEMBLYREF  4
5471
5472 #define ACTIVATION_CONTEXT_SECTION_ASSEMBLY_INFORMATION          1
5473 #define ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION               2
5474 #define ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION      3
5475 #define ACTIVATION_CONTEXT_SECTION_COM_SERVER_REDIRECTION        4
5476 #define ACTIVATION_CONTEXT_SECTION_COM_INTERFACE_REDIRECTION     5
5477 #define ACTIVATION_CONTEXT_SECTION_COM_TYPE_LIBRARY_REDIRECTION  6
5478 #define ACTIVATION_CONTEXT_SECTION_COM_PROGID_REDIRECTION        7
5479 #define ACTIVATION_CONTEXT_SECTION_GLOBAL_OBJECT_RENAME_TABLE    8
5480 #define ACTIVATION_CONTEXT_SECTION_CLR_SURROGATES                9
5481
5482 typedef enum _JOBOBJECTINFOCLASS
5483 {
5484     JobObjectBasicAccountingInformation = 1,
5485     JobObjectBasicLimitInformation,
5486     JobObjectBasicProcessIdList,
5487     JobObjectBasicUIRestrictions,
5488     JobObjectSecurityLimitInformation,
5489     JobObjectEndOfJobTimeInformation,
5490     JobObjectAssociateCompletionPortInformation,
5491     JobObjectBasicAndIoAccountingInformation,
5492     JobObjectExtendedLimitInformation,
5493     JobObjectJobSetInformation,
5494     MaxJobObjectInfoClass
5495 } JOBOBJECTINFOCLASS;
5496
5497 typedef enum _LOGICAL_PROCESSOR_RELATIONSHIP
5498 {
5499     RelationProcessorCore    = 0,
5500     RelationNumaNode         = 1,
5501     RelationCache            = 2,
5502     RelationProcessorPackage = 3,
5503     RelationGroup            = 4,
5504     RelationAll              = 0xffff
5505 } LOGICAL_PROCESSOR_RELATIONSHIP;
5506
5507 typedef enum _PROCESSOR_CACHE_TYPE
5508 {
5509     CacheUnified,
5510     CacheInstruction,
5511     CacheData,
5512     CacheTrace
5513 } PROCESSOR_CACHE_TYPE;
5514
5515 typedef struct _PROCESSOR_GROUP_INFO
5516 {
5517     BYTE MaximumProcessorCount;
5518     BYTE ActiveProcessorCount;
5519     BYTE Reserved[38];
5520     KAFFINITY ActiveProcessorMask;
5521 } PROCESSOR_GROUP_INFO, *PPROCESSOR_GROUP_INFO;
5522
5523 typedef struct _CACHE_DESCRIPTOR
5524 {
5525     BYTE Level;
5526     BYTE Associativity;
5527     WORD LineSize;
5528     DWORD Size;
5529     PROCESSOR_CACHE_TYPE Type;
5530 } CACHE_DESCRIPTOR, *PCACHE_DESCRIPTOR;
5531
5532 typedef struct _GROUP_AFFINITY
5533 {
5534     KAFFINITY Mask;
5535     WORD Group;
5536     WORD Reserved[3];
5537 } GROUP_AFFINITY, *PGROUP_AFFINITY;
5538
5539 typedef struct _PROCESSOR_RELATIONSHIP
5540 {
5541     BYTE Flags;
5542     BYTE Reserved[21];
5543     WORD GroupCount;
5544     GROUP_AFFINITY GroupMask[ANYSIZE_ARRAY];
5545 } PROCESSOR_RELATIONSHIP, *PPROCESSOR_RELATIONSHIP;
5546
5547
5548 typedef struct _NUMA_NODE_RELATIONSHIP
5549 {
5550     DWORD NodeNumber;
5551     BYTE Reserved[20];
5552     GROUP_AFFINITY GroupMask;
5553 } NUMA_NODE_RELATIONSHIP, *PNUMA_NODE_RELATIONSHIP;
5554
5555 typedef struct _CACHE_RELATIONSHIP
5556 {
5557     BYTE Level;
5558     BYTE Associativity;
5559     WORD LineSize;
5560     PROCESSOR_CACHE_TYPE Type;
5561     BYTE Reserved[20];
5562     GROUP_AFFINITY GroupMask;
5563 } CACHE_RELATIONSHIP, *PCACHE_RELATIONSHIP;
5564
5565 typedef struct _GROUP_RELATIONSHIP
5566 {
5567     WORD MaximumGroupCount;
5568     WORD ActiveGroupCount;
5569     BYTE Reserved[20];
5570     PROCESSOR_GROUP_INFO GroupInfo[ANYSIZE_ARRAY];
5571 } GROUP_RELATIONSHIP, *PGROUP_RELATIONSHIP;
5572
5573 typedef struct _SYSTEM_LOGICAL_PROCESSOR_INFORMATION
5574 {
5575     ULONG_PTR ProcessorMask;
5576     LOGICAL_PROCESSOR_RELATIONSHIP Relationship;
5577     union
5578     {
5579         struct
5580         {
5581             BYTE Flags;
5582         } ProcessorCore;
5583         struct
5584         {
5585             DWORD NodeNumber;
5586         } NumaNode;
5587         CACHE_DESCRIPTOR Cache;
5588         ULONGLONG Reserved[2];
5589     } DUMMYUNIONNAME;
5590 } SYSTEM_LOGICAL_PROCESSOR_INFORMATION, *PSYSTEM_LOGICAL_PROCESSOR_INFORMATION;
5591
5592 typedef struct _SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
5593 {
5594     LOGICAL_PROCESSOR_RELATIONSHIP Relationship;
5595     DWORD Size;
5596     union
5597     {
5598         PROCESSOR_RELATIONSHIP Processor;
5599         NUMA_NODE_RELATIONSHIP NumaNode;
5600         CACHE_RELATIONSHIP Cache;
5601         GROUP_RELATIONSHIP Group;
5602     } DUMMYUNIONNAME;
5603 } SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX, *PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX;
5604
5605 NTSYSAPI BOOLEAN NTAPI RtlGetProductInfo(DWORD,DWORD,DWORD,DWORD,PDWORD);
5606
5607 #ifdef __cplusplus
5608 }
5609 #endif
5610
5611 #endif  /* _WINNT_ */