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