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