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