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