~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/include/winnt.h

Version: ~ [ wine-1.1.33 ] ~ [ wine-1.1.32 ] ~ [ wine-1.1.31 ] ~ [ wine-1.1.30 ] ~ [ wine-1.1.29 ] ~ [ wine-1.1.28 ] ~ [ wine-1.1.27 ] ~ [ wine-1.1.26 ] ~ [ wine-1.1.25 ] ~ [ wine-1.1.24 ] ~ [ wine-1.1.23 ] ~ [ wine-1.1.22 ] ~ [ wine-1.1.21 ] ~ [ wine-1.1.20 ] ~ [ wine-1.1.19 ] ~ [ wine-1.1.18 ] ~ [ wine-1.1.17 ] ~ [ wine-1.1.16 ] ~ [ wine-1.1.15 ] ~ [ wine-1.1.14 ] ~ [ wine-1.1.13 ] ~ [ wine-1.1.12 ] ~ [ wine-1.1.11 ] ~ [ wine-1.1.10 ] ~ [ wine-1.1.9 ] ~ [ wine-1.1.8 ] ~ [ wine-1.1.7 ] ~ [ wine-1.0.1 ] ~ [ wine-1.1.6 ] ~ [ wine-1.1.5 ] ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~

  1 /*
  2  * Win32 definitions for Windows NT
  3  *
  4  * Copyright 1996 Alexandre Julliard
  5  *
  6  * This library is free software; you can redistribute it and/or
  7  * modify it under the terms of the GNU Lesser General Public
  8  * License as published by the Free Software Foundation; either
  9  * version 2.1 of the License, or (at your option) any later version.
 10  *
 11  * This library is distributed in the hope that it will be useful,
 12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 14  * Lesser General Public License for more details.
 15  *
 16  * You should have received a copy of the GNU Lesser General Public
 17  * License along with this library; if not, write to the Free Software
 18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 19  */
 20 
 21 #ifndef _WINNT_
 22 #define _WINNT_
 23 
 24 #include <basetsd.h>
 25 #include <guiddef.h>
 26 
 27 #ifndef RC_INVOKED
 28 #include <ctype.h>
 29 #include <stddef.h>
 30 #include <string.h>
 31 #endif
 32 
 33 
 34 #ifdef __cplusplus
 35 extern "C" {
 36 #endif
 37 
 38 #ifdef _NTSYSTEM_
 39 #define NTSYSAPI
 40 #else
 41 #define NTSYSAPI DECLSPEC_IMPORT
 42 #endif
 43 
 44 #define NTAPI __stdcall
 45 
 46 #ifndef MIDL_PASS
 47 # if defined(_MSC_VER)
 48 #  define DECLSPEC_IMPORT __declspec(dllimport)
 49 # elif defined(__MINGW32__) || defined(__CYGWIN__)
 50 #  define DECLSPEC_IMPORT __attribute__((dllimport))
 51 # else
 52 #  define DECLSPEC_IMPORT DECLSPEC_HIDDEN
 53 # endif
 54 #else
 55 # define DECLSPEC_IMPORT
 56 #endif
 57 
 58 #ifndef DECLSPEC_NORETURN
 59 # if defined(_MSC_VER) && (_MSC_VER >= 1200) && !defined(MIDL_PASS)
 60 #  define DECLSPEC_NORETURN __declspec(noreturn)
 61 # elif defined(__GNUC__)
 62 #  define DECLSPEC_NORETURN __attribute__((noreturn))
 63 # else
 64 #  define DECLSPEC_NORETURN
 65 # endif
 66 #endif
 67 
 68 #ifndef DECLSPEC_ALIGN
 69 # if defined(_MSC_VER) && (_MSC_VER >= 1300) && !defined(MIDL_PASS)
 70 #  define DECLSPEC_ALIGN(x) __declspec(align(x))
 71 # elif defined(__GNUC__)
 72 #  define DECLSPEC_ALIGN(x) __attribute__((aligned(x)))
 73 # else
 74 #  define DECLSPEC_ALIGN(x)
 75 # endif
 76 #endif
 77 
 78 #ifndef DECLSPEC_CACHEALIGN
 79 # define DECLSPEC_CACHEALIGN DECLSPEC_ALIGN(128)
 80 #endif
 81 
 82 #ifndef DECLSPEC_UUID
 83 # if defined(_MSC_VER) && (_MSC_VER >= 1100) && defined (__cplusplus)
 84 #  define DECLSPEC_UUID(x) __declspec(uuid(x))
 85 # else
 86 #  define DECLSPEC_UUID(x)
 87 # endif
 88 #endif
 89 
 90 #ifndef DECLSPEC_NOVTABLE
 91 # if defined(_MSC_VER) && (_MSC_VER >= 1100) && defined(__cplusplus)
 92 #  define DECLSPEC_NOVTABLE __declspec(novtable)
 93 # else
 94 #  define DECLSPEC_NOVTABLE
 95 # endif
 96 #endif
 97 
 98 #ifndef DECLSPEC_SELECTANY
 99 #if defined(_MSC_VER) && (_MSC_VER >= 1100)
100 #define DECLSPEC_SELECTANY __declspec(selectany)
101 #else
102 #define DECLSPEC_SELECTANY
103 #endif
104 #endif
105 
106 #ifndef NOP_FUNCTION
107 # if defined(_MSC_VER) && (_MSC_VER >= 1210)
108 #  define NOP_FUNCTION __noop
109 # else
110 #  define NOP_FUNCTION (void)0
111 # endif
112 #endif
113 
114 #ifndef DECLSPEC_ADDRSAFE
115 # if defined(_MSC_VER) && (_MSC_VER >= 1200) && (defined(_M_ALPHA) || defined(_M_AXP64))
116 #  define DECLSPEC_ADDRSAFE __declspec(address_safe)
117 # else
118 #  define DECLSPEC_ADDRSAFE
119 # endif
120 #endif
121 
122 #ifndef FORCEINLINE
123 # if defined(_MSC_VER) && (_MSC_VER >= 1200)
124 #  define FORCEINLINE __forceinline
125 # elif defined(__GNUC__) && ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 2)))
126 #  define FORCEINLINE __attribute__((always_inline))
127 # else
128 #  define FORCEINLINE inline
129 # endif
130 #endif
131 
132 #ifndef DECLSPEC_DEPRECATED
133 # if defined(_MSC_VER) && (_MSC_VER >= 1300) && !defined(MIDL_PASS)
134 #  define DECLSPEC_DEPRECATED __declspec(deprecated)
135 #  define DEPRECATE_SUPPORTED
136 # elif defined(__GNUC__) && ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 2)))
137 #  define DECLSPEC_DEPRECATED __attribute__((deprecated))
138 #  define DEPRECATE_SUPPORTED
139 # else
140 #  define DECLSPEC_DEPRECATED
141 #  undef  DEPRECATE_SUPPORTED
142 # endif
143 #endif
144 
145 /* a couple of useful Wine extensions */
146 
147 #ifdef _MSC_VER
148 # define DECLSPEC_EXPORT __declspec(dllexport)
149 #elif defined(__MINGW32__)
150 # define DECLSPEC_EXPORT __attribute__((dllexport))
151 #elif defined(__GNUC__) && ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)))
152 # define DECLSPEC_EXPORT __attribute__((visibility ("default")))
153 #else
154 # define DECLSPEC_EXPORT
155 #endif
156 
157 #if defined(__MSC_VER) || defined(__MINGW32__) || defined(__CYGWIN__)
158 # define DECLSPEC_HIDDEN
159 #elif defined(__GNUC__) && ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)))
160 # define DECLSPEC_HIDDEN __attribute__((visibility ("hidden")))
161 #else
162 # define DECLSPEC_HIDDEN
163 #endif
164 
165 #if defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 3)))
166 #define __WINE_ALLOC_SIZE(x) __attribute__((__alloc_size__(x)))
167 #else
168 #define __WINE_ALLOC_SIZE(x)
169 #endif
170 
171 /* Anonymous union/struct handling */
172 
173 #ifndef NONAMELESSSTRUCT
174 # ifdef __GNUC__
175    /* Anonymous struct support starts with gcc 2.96 or gcc/g++ 3.x */
176 #  if (__GNUC__ < 2) || ((__GNUC__ == 2) && (defined(__cplusplus) || (__GNUC_MINOR__ < 96)))
177 #   define NONAMELESSSTRUCT
178 #  endif
179 # elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
180 #  define NONAMELESSSTRUCT
181 # endif
182 #endif  /* NONAMELESSSTRUCT */
183 
184 #ifndef NONAMELESSUNION
185 # ifdef __GNUC__
186    /* Anonymous unions support starts with gcc 2.96/g++ 2.95 */
187 #  if (__GNUC__ < 2) || ((__GNUC__ == 2) && ((__GNUC_MINOR__ < 95) || ((__GNUC_MINOR__ == 95) && !defined(__cplusplus))))
188 #   define NONAMELESSUNION
189 #  endif
190 # elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
191 #  define NONAMELESSUNION
192 # endif
193 #endif  /* NONAMELESSUNION */
194 
195 #ifndef NONAMELESSSTRUCT
196 #define DUMMYSTRUCTNAME
197 #define DUMMYSTRUCTNAME1
198 #define DUMMYSTRUCTNAME2
199 #define DUMMYSTRUCTNAME3
200 #define DUMMYSTRUCTNAME4
201 #define DUMMYSTRUCTNAME5
202 #else /* !defined(NONAMELESSSTRUCT) */
203 #define DUMMYSTRUCTNAME   s
204 #define DUMMYSTRUCTNAME1  s1
205 #define DUMMYSTRUCTNAME2  s2
206 #define DUMMYSTRUCTNAME3  s3
207 #define DUMMYSTRUCTNAME4  s4
208 #define DUMMYSTRUCTNAME5  s5
209 #endif /* !defined(NONAMELESSSTRUCT) */
210 
211 #ifndef NONAMELESSUNION
212 #define DUMMYUNIONNAME
213 #define DUMMYUNIONNAME1
214 #define DUMMYUNIONNAME2
215 #define DUMMYUNIONNAME3
216 #define DUMMYUNIONNAME4
217 #define DUMMYUNIONNAME5
218 #define DUMMYUNIONNAME6
219 #define DUMMYUNIONNAME7
220 #define DUMMYUNIONNAME8
221 #else /* !defined(NONAMELESSUNION) */
222 #define DUMMYUNIONNAME   u
223 #define DUMMYUNIONNAME1  u1
224 #define DUMMYUNIONNAME2  u2
225 #define DUMMYUNIONNAME3  u3
226 #define DUMMYUNIONNAME4  u4
227 #define DUMMYUNIONNAME5  u5
228 #define DUMMYUNIONNAME6  u6
229 #define DUMMYUNIONNAME7  u7
230 #define DUMMYUNIONNAME8  u8
231 #endif /* !defined(NONAMELESSUNION) */
232 
233 /* C99 restrict support */
234 
235 #if defined(ENABLE_RESTRICTED) && !defined(MIDL_PASS) && !defined(RC_INVOKED)
236 # if defined(_MSC_VER) && defined(_M_MRX000)
237 #  define RESTRICTED_POINTER __restrict
238 # elif defined(__GNUC__) && ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 95)))
239 #  define RESTRICTED_POINTER __restrict
240 # else
241 #  define RESTRICTED_POINTER
242 # endif
243 #else
244 # define RESTRICTED_POINTER
245 #endif
246 
247 /* C99 unaligned support */
248 
249 #if defined(_MSC_VER) && (defined(_M_MRX000) || defined(_M_ALPHA) || defined(_M_PPC) || defined(_M_IA64) || defined(_M_AMD64))
250 # define UNALIGNED __unaligned
251 # ifdef _WIN64
252 #  define UNALIGNED64 __unaligned
253 # else
254 #  define UNALIGNED64
255 # endif
256 #else
257 # define UNALIGNED
258 # define UNALIGNED64
259 #endif
260 
261 /* Alignment macros */
262 
263 #if defined(_WIN64) || (defined(_MSC_VER) && defined(_M_ALPHA)) || defined(__alpha__)
264 #define MAX_NATURAL_ALIGNMENT sizeof(ULONGLONG)
265 #define MEMORY_ALLOCATION_ALIGNMENT 16
266 #else
267 #define MAX_NATURAL_ALIGNMENT sizeof(DWORD)
268 #define MEMORY_ALLOCATION_ALIGNMENT 8
269 #endif
270 
271 #if defined(_MSC_VER) && (_MSC_VER >= 1300) && defined(__cplusplus)
272 # define TYPE_ALIGNMENT(t) __alignof(t)
273 #elif defined(__GNUC__)
274 # define TYPE_ALIGNMENT(t) __alignof__(t)
275 #else
276 # define TYPE_ALIGNMENT(t) FIELD_OFFSET(struct { char x; t test; }, test)
277 #endif
278 
279 #ifdef _WIN64
280 # define PROBE_ALIGNMENT(_s) \
281     (TYPE_ALIGNMENT(_s) > TYPE_ALIGNMENT(DWORD) ? \
282     TYPE_ALIGNMENT(_s) : TYPE_ALIGNMENT(DWORD))
283 # define PROBE_ALIGNMENT32(_s) TYPE_ALIGNMENT(DWORD)
284 #else
285 # define PROBE_ALIGNMENT(_s) TYPE_ALIGNMENT(DWORD)
286 #endif
287 
288 /* Compile time assertion */
289 
290 #if defined(_MSC_VER)
291 # define C_ASSERT(e) typedef char __C_ASSERT__[(e)?1:-1]
292 #elif defined(__GNUC__) 
293 # define C_ASSERT(e) extern char __C_ASSERT__[(e)?1:-1] __attribute__((unused))
294 #else
295 # define C_ASSERT(e)
296 #endif
297 
298 /* Eliminate Microsoft C/C++ compiler warning 4715 */
299 #if (_MSC_VER > 1200)
300 # define DEFAULT_UNREACHABLE default: __assume(0)
301 #else
302 # define DEFAULT_UNREACHABLE
303 #endif
304 
305 /* Error Masks */
306 #define APPLICATION_ERROR_MASK       0x20000000
307 #define ERROR_SEVERITY_SUCCESS       0x00000000
308 #define ERROR_SEVERITY_INFORMATIONAL 0x40000000
309 #define ERROR_SEVERITY_WARNING       0x80000000
310 #define ERROR_SEVERITY_ERROR         0xC0000000
311 
312 /* Microsoft's macros for declaring functions */
313 
314 #ifdef __cplusplus
315 # define EXTERN_C    extern "C"
316 #else
317 # define EXTERN_C    extern
318 #endif
319 
320 #define STDMETHODCALLTYPE       __stdcall
321 #define STDMETHODVCALLTYPE      __cdecl
322 #define STDAPICALLTYPE          __stdcall
323 #define STDAPIVCALLTYPE         __cdecl
324 
325 #define STDAPI                  EXTERN_C HRESULT STDAPICALLTYPE
326 #define STDAPI_(type)           EXTERN_C type STDAPICALLTYPE
327 #define STDMETHODIMP            HRESULT STDMETHODCALLTYPE
328 #define STDMETHODIMP_(type)     type STDMETHODCALLTYPE
329 #define STDAPIV                 EXTERN_C HRESULT STDAPIVCALLTYPE
330 #define STDAPIV_(type)          EXTERN_C type STDAPIVCALLTYPE
331 #define STDMETHODIMPV           HRESULT STDMETHODVCALLTYPE
332 #define STDMETHODIMPV_(type)    type STDMETHODVCALLTYPE
333 
334 /* Define the basic types */
335 #ifndef VOID
336 #define VOID void
337 #endif
338 typedef VOID           *PVOID;
339 typedef VOID           *PVOID64;
340 typedef BYTE            BOOLEAN,    *PBOOLEAN;
341 typedef char            CHAR,       *PCHAR;
342 typedef short           SHORT,      *PSHORT;
343 #ifdef _MSC_VER
344 typedef long            LONG,       *PLONG;
345 #else
346 typedef int             LONG,       *PLONG;
347 #endif
348 
349 /* Some systems might have wchar_t, but we really need 16 bit characters */
350 #ifdef WINE_UNICODE_NATIVE
351 typedef wchar_t         WCHAR,      *PWCHAR;
352 #else
353 typedef unsigned short  WCHAR,      *PWCHAR;
354 #endif
355 
356 /* 'Extended/Wide' numerical types */
357 #ifndef _ULONGLONG_
358 # define _ULONGLONG_
359 # ifdef _MSC_VER
360 typedef signed __int64   LONGLONG,  *PLONGLONG;
361 typedef unsigned __int64 ULONGLONG, *PULONGLONG;
362 # else
363 typedef signed __int64   DECLSPEC_ALIGN(8) LONGLONG,   *PLONGLONG;
364 typedef unsigned __int64 DECLSPEC_ALIGN(8) ULONGLONG,  *PULONGLONG;
365 # endif
366 #endif
367 
368 #ifndef _DWORDLONG_
369 # define _DWORDLONG_
370 # ifdef _MSC_VER
371 typedef ULONGLONG DWORDLONG, *PDWORDLONG;
372 # else
373 typedef ULONGLONG   DECLSPEC_ALIGN(8) DWORDLONG,   *PDWORDLONG;
374 # endif
375 #endif
376 
377 /* ANSI string types */
378 typedef CHAR           *PCH,        *LPCH;
379 typedef const CHAR     *PCCH,       *LPCCH;
380 typedef CHAR           *PSTR,       *LPSTR,     *NPSTR;
381 typedef const CHAR     *PCSTR,      *LPCSTR;
382 
383 /* Unicode string types */
384 typedef WCHAR          *PWCH,       *LPWCH;
385 typedef const WCHAR    *PCWCH,      *LPCWCH;
386 typedef WCHAR          *PWSTR,      *LPWSTR,    *NWPSTR;
387 typedef const WCHAR    *PCWSTR,     *LPCWSTR;
388 
389 /* Neutral character and string types */
390 /* These are only defined for Winelib, i.e. _not_ defined for
391  * the emulator. The reason is they depend on the UNICODE
392  * macro which only exists in the user's code.
393  */
394 #ifndef WINE_NO_UNICODE_MACROS
395 # ifdef UNICODE
396 # ifndef _TCHAR_DEFINED
397 typedef WCHAR           TCHAR,      *PTCHAR;
398 # define _TCHAR_DEFINED
399 #endif
400 typedef LPWSTR          PTSTR,       LPTSTR;
401 typedef LPCWSTR         PCTSTR,      LPCTSTR;
402 #  define __TEXT(string) L##string
403 # else  /* UNICODE */
404 # ifndef _TCHAR_DEFINED
405 typedef CHAR            TCHAR,      *PTCHAR;
406 # define _TCHAR_DEFINED
407 # endif
408 typedef LPSTR           PTSTR,       LPTSTR;
409 typedef LPCSTR          PCTSTR,      LPCTSTR;
410 #  define __TEXT(string) string
411 # endif /* UNICODE */
412 # define TEXT(quote) __TEXT(quote)
413 #endif   /* WINE_NO_UNICODE_MACROS */
414 
415 /* Misc common WIN32 types */
416 typedef char            CCHAR;
417 typedef DWORD           LCID,       *PLCID;
418 typedef WORD            LANGID;
419 typedef DWORD           EXECUTION_STATE;
420 #ifndef _HRESULT_DEFINED
421 #define _HRESULT_DEFINED
422 typedef LONG            HRESULT;
423 #endif
424 
425 /* Handle type */
426 
427 typedef void *HANDLE;
428 typedef HANDLE *PHANDLE, *LPHANDLE;
429 
430 #ifdef STRICT
431 #define DECLARE_HANDLE(a) typedef struct a##__ { int unused; } *a
432 #else /*STRICT*/
433 #define DECLARE_HANDLE(a) typedef HANDLE a
434 #endif /*STRICT*/
435 
436 typedef BYTE  FCHAR;
437 typedef WORD  FSHORT;
438 typedef DWORD FLONG;
439 
440 /* Defines */
441 
442 #ifndef WIN32_NO_STATUS
443 
444 #define STATUS_WAIT_0                    ((DWORD) 0x00000000)
445 #define STATUS_ABANDONED_WAIT_0          ((DWORD) 0x00000080)
446 #define STATUS_USER_APC                  ((DWORD) 0x000000C0)
447 #define STATUS_TIMEOUT                   ((DWORD) 0x00000102)
448 #define STATUS_PENDING                   ((DWORD) 0x00000103)
449 #define STATUS_SEGMENT_NOTIFICATION      ((DWORD) 0x40000005)
450 #define STATUS_GUARD_PAGE_VIOLATION      ((DWORD) 0x80000001)
451 #define STATUS_DATATYPE_MISALIGNMENT     ((DWORD) 0x80000002)
452 #define STATUS_BREAKPOINT                ((DWORD) 0x80000003)
453 #define STATUS_SINGLE_STEP               ((DWORD) 0x80000004)
454 #define STATUS_ACCESS_VIOLATION          ((DWORD) 0xC0000005)
455 #define STATUS_IN_PAGE_ERROR             ((DWORD) 0xC0000006)
456 #define STATUS_INVALID_HANDLE            ((DWORD) 0xC0000008)
457 #define STATUS_NO_MEMORY                 ((DWORD) 0xC0000017)
458 #define STATUS_ILLEGAL_INSTRUCTION       ((DWORD) 0xC000001D)
459 #define STATUS_NONCONTINUABLE_EXCEPTION  ((DWORD) 0xC0000025)
460 #define STATUS_INVALID_DISPOSITION       ((DWORD) 0xC0000026)
461 #define STATUS_ARRAY_BOUNDS_EXCEEDED     ((DWORD) 0xC000008C)
462 #define STATUS_FLOAT_DENORMAL_OPERAND    ((DWORD) 0xC000008D)
463 #define STATUS_FLOAT_DIVIDE_BY_ZERO      ((DWORD) 0xC000008E)
464 #define STATUS_FLOAT_INEXACT_RESULT      ((DWORD) 0xC000008F)
465 #define STATUS_FLOAT_INVALID_OPERATION   ((DWORD) 0xC0000090)
466 #define STATUS_FLOAT_OVERFLOW            ((DWORD) 0xC0000091)
467 #define STATUS_FLOAT_STACK_CHECK         ((DWORD) 0xC0000092)
468 #define STATUS_FLOAT_UNDERFLOW           ((DWORD) 0xC0000093)
469 #define STATUS_INTEGER_DIVIDE_BY_ZERO    ((DWORD) 0xC0000094)
470 #define STATUS_INTEGER_OVERFLOW          ((DWORD) 0xC0000095)
471 #define STATUS_PRIVILEGED_INSTRUCTION    ((DWORD) 0xC0000096)
472 #define STATUS_STACK_OVERFLOW            ((DWORD) 0xC00000FD)
473 #define STATUS_CONTROL_C_EXIT            ((DWORD) 0xC000013A)
474 #define STATUS_FLOAT_MULTIPLE_FAULTS     ((DWORD) 0xC00002B4)
475 #define STATUS_FLOAT_MULTIPLE_TRAPS      ((DWORD) 0xC00002B5)
476 #define STATUS_REG_NAT_CONSUMPTION       ((DWORD) 0xC00002C9)
477 #define STATUS_SXS_EARLY_DEACTIVATION    ((DWORD) 0xC015000F)
478 #define STATUS_SXS_INVALID_DEACTIVATION  ((DWORD) 0xC0150010)
479 
480 /* status values for ContinueDebugEvent */
481 #define DBG_EXCEPTION_HANDLED       ((DWORD) 0x00010001)
482 #define DBG_CONTINUE                ((DWORD) 0x00010002)
483 #define DBG_TERMINATE_THREAD        ((DWORD) 0x40010003)
484 #define DBG_TERMINATE_PROCESS       ((DWORD) 0x40010004)
485 #define DBG_CONTROL_C               ((DWORD) 0x40010005)
486 #define DBG_CONTROL_BREAK           ((DWORD) 0x40010008)
487 #define DBG_COMMAND_EXCEPTION       ((DWORD) 0x40010009)
488 #define DBG_EXCEPTION_NOT_HANDLED   ((DWORD) 0x80010001)
489 
490 #endif /* WIN32_NO_STATUS */
491 
492 /* Argument 1 passed to the DllEntryProc. */
493 #define DLL_PROCESS_DETACH      0       /* detach process (unload library) */
494 #define DLL_PROCESS_ATTACH      1       /* attach process (load library) */
495 #define DLL_THREAD_ATTACH       2       /* attach new thread */
496 #define DLL_THREAD_DETACH       3       /* detach thread */
497 #ifdef __WINESRC__
498 #define DLL_WINE_PREATTACH      8       /* called before process attach for Wine builtins */
499 #endif
500 
501 /* u.x.wProcessorArchitecture (NT) */
502 #define PROCESSOR_ARCHITECTURE_INTEL    0
503 #define PROCESSOR_ARCHITECTURE_MIPS     1
504 #define PROCESSOR_ARCHITECTURE_ALPHA    2
505 #define PROCESSOR_ARCHITECTURE_PPC      3
506 #define PROCESSOR_ARCHITECTURE_SHX      4
507 #define PROCESSOR_ARCHITECTURE_ARM      5
508 #define PROCESSOR_ARCHITECTURE_IA64     6
509 #define PROCESSOR_ARCHITECTURE_ALPHA64  7
510 #define PROCESSOR_ARCHITECTURE_MSIL     8
511 #define PROCESSOR_ARCHITECTURE_AMD64    9
512 #define PROCESSOR_ARCHITECTURE_UNKNOWN  0xFFFF
513 
514 /* dwProcessorType */
515 #define PROCESSOR_INTEL_386      386
516 #define PROCESSOR_INTEL_486      486
517 #define PROCESSOR_INTEL_PENTIUM  586
518 #define PROCESSOR_INTEL_860      860
519 #define PROCESSOR_INTEL_IA64     2200
520 #define PROCESSOR_AMD_X8664      8664
521 #define PROCESSOR_MIPS_R2000     2000
522 #define PROCESSOR_MIPS_R3000     3000
523 #define PROCESSOR_MIPS_R4000     4000
524 #define PROCESSOR_ALPHA_21064    21064
525 #define PROCESSOR_PPC_601        601
526 #define PROCESSOR_PPC_603        603
527 #define PROCESSOR_PPC_604        604
528 #define PROCESSOR_PPC_620        620
529 #define PROCESSOR_HITACHI_SH3    10003
530 #define PROCESSOR_HITACHI_SH3E   10004
531 #define PROCESSOR_HITACHI_SH4    10005
532 #define PROCESSOR_MOTOROLA_821   821
533 #define PROCESSOR_SHx_SH3        103
534 #define PROCESSOR_SHx_SH4        104
535 #define PROCESSOR_STRONGARM      2577
536 #define PROCESSOR_ARM720         1824    /* 0x720 */
537 #define PROCESSOR_ARM820         2080    /* 0x820 */
538 #define PROCESSOR_ARM920         2336    /* 0x920 */
539 #define PROCESSOR_ARM_7TDMI      70001
540 
541 #define MAXIMUM_PROCESSORS       32
542 typedef struct _MEMORY_BASIC_INFORMATION
543 {
544     LPVOID   BaseAddress;
545     LPVOID   AllocationBase;
546     DWORD    AllocationProtect;
547     SIZE_T   RegionSize;
548     DWORD    State;
549     DWORD    Protect;
550     DWORD    Type;
551 } MEMORY_BASIC_INFORMATION, *PMEMORY_BASIC_INFORMATION;
552 
553 #define PAGE_NOACCESS           0x01
554 #define PAGE_READONLY           0x02
555 #define PAGE_READWRITE          0x04
556 #define PAGE_WRITECOPY          0x08
557 #define PAGE_EXECUTE            0x10
558 #define PAGE_EXECUTE_READ       0x20
559 #define PAGE_EXECUTE_READWRITE  0x40
560 #define PAGE_EXECUTE_WRITECOPY  0x80
561 #define PAGE_GUARD              0x100
562 #define PAGE_NOCACHE            0x200
563 #define PAGE_WRITECOMBINE       0x400
564 
565 #define MEM_COMMIT              0x00001000
566 #define MEM_RESERVE             0x00002000
567 #define MEM_DECOMMIT            0x00004000
568 #define MEM_RELEASE             0x00008000
569 #define MEM_FREE                0x00010000
570 #define MEM_PRIVATE             0x00020000
571 #define MEM_MAPPED              0x00040000
572 #define MEM_RESET               0x00080000
573 #define MEM_TOP_DOWN            0x00100000
574 #define MEM_WRITE_WATCH         0x00200000
575 #define MEM_PHYSICAL            0x00400000
576 #define MEM_LARGE_PAGES         0x20000000
577 #define MEM_4MB_PAGES           0x80000000
578 #ifdef __WINESRC__
579 #define MEM_SYSTEM              0x80000000
580 #endif
581 
582 #define SEC_FILE                0x00800000
583 #define SEC_IMAGE               0x01000000
584 #define SEC_RESERVE             0x04000000
585 #define SEC_COMMIT              0x08000000
586 #define SEC_NOCACHE             0x10000000
587 #define SEC_LARGE_PAGES         0x80000000
588 #define MEM_IMAGE               SEC_IMAGE
589 
590 #define WRITE_WATCH_FLAG_RESET  0x00000001
591 
592 
593 #define MINCHAR       0x80
594 #define MAXCHAR       0x7f
595 #define MINSHORT      0x8000
596 #define MAXSHORT      0x7fff
597 #define MINLONG       0x80000000
598 #define MAXLONG       0x7fffffff
599 #define MAXBYTE       0xff
600 #define MAXWORD       0xffff
601 #define MAXDWORD      0xffffffff
602 
603 #define FIELD_OFFSET(type, field) \
604   ((LONG)(INT_PTR)&(((type *)0)->field))
605 
606 #define CONTAINING_RECORD(address, type, field) \
607   ((type *)((PCHAR)(address) - (PCHAR)(&((type *)0)->field)))
608 
609 /* Types */
610 
611 typedef struct _LIST_ENTRY {
612   struct _LIST_ENTRY *Flink;
613   struct _LIST_ENTRY *Blink;
614 } LIST_ENTRY, *PLIST_ENTRY, * RESTRICTED_POINTER PRLIST_ENTRY;
615 
616 typedef struct _SINGLE_LIST_ENTRY {
617   struct _SINGLE_LIST_ENTRY *Next;
618 } SINGLE_LIST_ENTRY, *PSINGLE_LIST_ENTRY;
619 
620 #ifdef _WIN64
621 
622 typedef struct DECLSPEC_ALIGN(16) _SLIST_ENTRY *PSLIST_ENTRY;
623 typedef struct DECLSPEC_ALIGN(16) _SLIST_ENTRY {
624     PSLIST_ENTRY Next;
625 } SLIST_ENTRY;
626 
627 typedef union DECLSPEC_ALIGN(16) _SLIST_HEADER {
628     struct {
629         ULONGLONG Alignment;
630         ULONGLONG Region;
631     } DUMMYSTRUCTNAME;
632     struct {
633         ULONGLONG Depth:16;
634         ULONGLONG Sequence:9;
635         ULONGLONG NextEntry:39;
636         ULONGLONG HeaderType:1;
637         ULONGLONG Init:1;
638         ULONGLONG Reserved:59;
639         ULONGLONG Region:3;
640     } Header8;
641     struct {
642         ULONGLONG Depth:16;
643         ULONGLONG Sequence:48;
644         ULONGLONG HeaderType:1;
645         ULONGLONG Init:1;
646         ULONGLONG Reserved:2;
647         ULONGLONG NextEntry:60;
648     } Header16;
649 } SLIST_HEADER, *PSLIST_HEADER;
650 
651 #else
652 
653 #undef SLIST_ENTRY /* for Mac OS */
654 #define SLIST_ENTRY SINGLE_LIST_ENTRY
655 #define _SLIST_ENTRY _SINGLE_LIST_ENTRY
656 #define PSLIST_ENTRY PSINGLE_LIST_ENTRY
657 
658 typedef union _SLIST_HEADER {
659     ULONGLONG Alignment;
660     struct {
661         SLIST_ENTRY Next;
662         WORD Depth;
663         WORD Sequence;
664     } DUMMYSTRUCTNAME;
665 } SLIST_HEADER, *PSLIST_HEADER;
666 
667 #endif
668 
669 NTSYSAPI PSLIST_ENTRY WINAPI RtlFirstEntrySList(const SLIST_HEADER*);
670 NTSYSAPI VOID         WINAPI RtlInitializeSListHead(PSLIST_HEADER);
671 NTSYSAPI PSLIST_ENTRY WINAPI RtlInterlockedFlushSList(PSLIST_HEADER);
672 NTSYSAPI PSLIST_ENTRY WINAPI RtlInterlockedPopEntrySList(PSLIST_HEADER);
673 NTSYSAPI PSLIST_ENTRY WINAPI RtlInterlockedPushEntrySList(PSLIST_HEADER, PSLIST_ENTRY);
674 NTSYSAPI WORD         WINAPI RtlQueryDepthSList(PSLIST_HEADER);
675 
676 
677 /* Heap flags */
678 
679 #define HEAP_NO_SERIALIZE               0x00000001
680 #define HEAP_GROWABLE                   0x00000002
681 #define HEAP_GENERATE_EXCEPTIONS        0x00000004
682 #define HEAP_ZERO_MEMORY                0x00000008
683 #define HEAP_REALLOC_IN_PLACE_ONLY      0x00000010
684 #define HEAP_TAIL_CHECKING_ENABLED      0x00000020
685 #define HEAP_FREE_CHECKING_ENABLED      0x00000040
686 #define HEAP_DISABLE_COALESCE_ON_FREE   0x00000080
687 #define HEAP_CREATE_ALIGN_16            0x00010000
688 #define HEAP_CREATE_ENABLE_TRACING      0x00020000
689 #define HEAP_CREATE_ENABLE_EXECUTE      0x00040000
690 
691 /* This flag allows it to create heaps shared by all processes under win95,
692    FIXME: correct name */
693 #define HEAP_SHARED                     0x04000000
694 
695 typedef enum _HEAP_INFORMATION_CLASS {
696     HeapCompatibilityInformation,
697 } HEAP_INFORMATION_CLASS;
698 
699 /* Processor feature flags.  */
700 #define PF_FLOATING_POINT_PRECISION_ERRATA      0
701 #define PF_FLOATING_POINT_EMULATED              1
702 #define PF_COMPARE_EXCHANGE_DOUBLE              2
703 #define PF_MMX_INSTRUCTIONS_AVAILABLE           3
704 #define PF_PPC_MOVEMEM_64BIT_OK                 4
705 #define PF_ALPHA_BYTE_INSTRUCTIONS              5
706 #define PF_XMMI_INSTRUCTIONS_AVAILABLE          6
707 #define PF_3DNOW_INSTRUCTIONS_AVAILABLE         7
708 #define PF_RDTSC_INSTRUCTION_AVAILABLE          8
709 #define PF_PAE_ENABLED                          9
710 #define PF_XMMI64_INSTRUCTIONS_AVAILABLE        10
711 #define PF_SSE_DAZ_MODE_AVAILABLE               11
712 #define PF_NX_ENABLED                           12
713 #define PF_SSE3_INSTRUCTIONS_AVAILABLE          13
714 #define PF_COMPARE_EXCHANGE128                  14
715 #define PF_COMPARE64_EXCHANGE128                15
716 #define PF_CHANNELS_ENABLED                     16
717 
718 
719 /* Execution state flags */
720 #define ES_SYSTEM_REQUIRED    0x00000001
721 #define ES_DISPLAY_REQUIRED   0x00000002
722 #define ES_USER_PRESENT       0x00000004
723 #define ES_CONTINUOUS         0x80000000
724 
725 /* The Win32 register context */
726 
727 /* CONTEXT is the CPU-dependent context; it should be used        */
728 /* wherever a platform-specific context is needed (e.g. exception */
729 /* handling, Win32 register functions). */
730 
731 /* CONTEXT86 is the i386-specific context; it should be used     */
732 /* wherever only a 386 context makes sense (e.g. DOS interrupts, */
733 /* Win16 register functions), so that this code can be compiled  */
734 /* on all platforms. */
735 
736 #define SIZE_OF_80387_REGISTERS      80
737 
738 typedef struct _FLOATING_SAVE_AREA
739 {
740     DWORD   ControlWord;
741     DWORD   StatusWord;
742     DWORD   TagWord;
743     DWORD   ErrorOffset;
744     DWORD   ErrorSelector;
745     DWORD   DataOffset;
746     DWORD   DataSelector;
747     BYTE    RegisterArea[SIZE_OF_80387_REGISTERS];
748     DWORD   Cr0NpxState;
749 } FLOATING_SAVE_AREA, *PFLOATING_SAVE_AREA;
750 
751 #define MAXIMUM_SUPPORTED_EXTENSION     512
752 
753 typedef struct _CONTEXT86
754 {
755     DWORD   ContextFlags;
756 
757     /* These are selected by CONTEXT_DEBUG_REGISTERS */
758     DWORD   Dr0;
759     DWORD   Dr1;
760     DWORD   Dr2;
761     DWORD   Dr3;
762     DWORD   Dr6;
763     DWORD   Dr7;
764 
765     /* These are selected by CONTEXT_FLOATING_POINT */
766     FLOATING_SAVE_AREA FloatSave;
767 
768     /* These are selected by CONTEXT_SEGMENTS */
769     DWORD   SegGs;
770     DWORD   SegFs;
771     DWORD   SegEs;
772     DWORD   SegDs;
773 
774     /* These are selected by CONTEXT_INTEGER */
775     DWORD   Edi;
776     DWORD   Esi;
777     DWORD   Ebx;
778     DWORD   Edx;
779     DWORD   Ecx;
780     DWORD   Eax;
781 
782     /* These are selected by CONTEXT_CONTROL */
783     DWORD   Ebp;
784     DWORD   Eip;
785     DWORD   SegCs;
786     DWORD   EFlags;
787     DWORD   Esp;
788     DWORD   SegSs;
789 
790     BYTE    ExtendedRegisters[MAXIMUM_SUPPORTED_EXTENSION];
791 } CONTEXT86;
792 
793 #define CONTEXT_X86       0x00010000
794 #define CONTEXT_i386      CONTEXT_X86
795 #define CONTEXT_i486      CONTEXT_X86
796 
797 #define CONTEXT86_CONTROL   (CONTEXT_i386 | 0x0001) /* SS:SP, CS:IP, FLAGS, BP */
798 #define CONTEXT86_INTEGER   (CONTEXT_i386 | 0x0002) /* AX, BX, CX, DX, SI, DI */
799 #define CONTEXT86_SEGMENTS  (CONTEXT_i386 | 0x0004) /* DS, ES, FS, GS */
800 #define CONTEXT86_FLOATING_POINT  (CONTEXT_i386 | 0x0008L) /* 387 state */
801 #define CONTEXT86_DEBUG_REGISTERS (CONTEXT_i386 | 0x0010L) /* DB 0-3,6,7 */
802 #define CONTEXT86_EXTENDED_REGISTERS (CONTEXT_i386 | 0x0020L)
803 #define CONTEXT86_FULL (CONTEXT86_CONTROL | CONTEXT86_INTEGER | CONTEXT86_SEGMENTS)
804 #define CONTEXT86_ALL (CONTEXT86_CONTROL | CONTEXT86_INTEGER | CONTEXT86_SEGMENTS | \
805         CONTEXT86_FLOATING_POINT | CONTEXT86_DEBUG_REGISTERS | CONTEXT86_EXTENDED_REGISTERS)
806 
807 /* i386 context definitions */
808 #ifdef __i386__
809 
810 #define CONTEXT_CONTROL         CONTEXT86_CONTROL
811 #define CONTEXT_INTEGER         CONTEXT86_INTEGER
812 #define CONTEXT_SEGMENTS        CONTEXT86_SEGMENTS
813 #define CONTEXT_FLOATING_POINT  CONTEXT86_FLOATING_POINT
814 #define CONTEXT_DEBUG_REGISTERS CONTEXT86_DEBUG_REGISTERS
815 #define CONTEXT_EXTENDED_REGISTERS CONTEXT86_EXTENDED_REGISTERS
816 #define CONTEXT_FULL            CONTEXT86_FULL
817 #define CONTEXT_ALL             CONTEXT86_ALL
818 
819 typedef CONTEXT86 CONTEXT;
820 
821 #define EXCEPTION_READ_FAULT    0
822 #define EXCEPTION_WRITE_FAULT   1
823 #define EXCEPTION_EXECUTE_FAULT 8
824 
825 #endif  /* __i386__ */
826 
827 typedef struct _LDT_ENTRY {
828     WORD        LimitLow;
829     WORD        BaseLow;
830     union {
831         struct {
832             BYTE    BaseMid;
833             BYTE    Flags1;
834             BYTE    Flags2;
835             BYTE    BaseHi;
836         } Bytes;
837         struct {
838             unsigned    BaseMid: 8;
839             unsigned    Type : 5;
840             unsigned    Dpl : 2;
841             unsigned    Pres : 1;
842             unsigned    LimitHi : 4;
843             unsigned    Sys : 1;
844             unsigned    Reserved_0 : 1;
845             unsigned    Default_Big : 1;
846             unsigned    Granularity : 1;
847             unsigned    BaseHi : 8;
848         } Bits;
849     } HighWord;
850 } LDT_ENTRY, *PLDT_ENTRY;
851 
852 /* x86-64 context definitions */
853 #if defined(__x86_64__)
854 
855 #define CONTEXT_AMD64   0x00100000
856 
857 #define CONTEXT_CONTROL   (CONTEXT_AMD64 | 0x0001)
858 #define CONTEXT_INTEGER   (CONTEXT_AMD64 | 0x0002)
859 #define CONTEXT_SEGMENTS  (CONTEXT_AMD64 | 0x0004)
860 #define CONTEXT_FLOATING_POINT  (CONTEXT_AMD64 | 0x0008L)
861 #define CONTEXT_DEBUG_REGISTERS (CONTEXT_AMD64 | 0x0010L)
862 #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT)
863 #define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS | CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS)
864 
865 #define EXCEPTION_READ_FAULT    0
866 #define EXCEPTION_WRITE_FAULT   1
867 #define EXCEPTION_EXECUTE_FAULT 8
868 
869 typedef struct DECLSPEC_ALIGN(16) _M128A {
870     ULONGLONG Low;
871     LONGLONG High;
872 } M128A, *PM128A;
873 
874 typedef struct _XMM_SAVE_AREA32 {
875     WORD ControlWord;
876     WORD StatusWord;
877     BYTE TagWord;
878     BYTE Reserved1;
879     WORD ErrorOpcode;
880     DWORD ErrorOffset;
881     WORD ErrorSelector;
882     WORD Reserved2;
883     DWORD DataOffset;
884     WORD DataSelector;
885     WORD Reserved3;
886     DWORD MxCsr;
887     DWORD MxCsr_Mask;
888     M128A FloatRegisters[8];
889     M128A XmmRegisters[16];
890     BYTE Reserved4[96];
891 } XMM_SAVE_AREA32, *PXMM_SAVE_AREA32;
892 
893 typedef struct DECLSPEC_ALIGN(16) _CONTEXT {
894     DWORD64 P1Home;
895     DWORD64 P2Home;
896     DWORD64 P3Home;
897     DWORD64 P4Home;
898     DWORD64 P5Home;
899     DWORD64 P6Home;
900 
901     /* Control flags */
902     DWORD ContextFlags;
903     DWORD MxCsr;
904 
905     /* Segment */
906     WORD SegCs;
907     WORD SegDs;
908     WORD SegEs;
909     WORD SegFs;
910     WORD SegGs;
911     WORD SegSs;
912     DWORD EFlags;
913 
914     /* Debug */
915     DWORD64 Dr0;
916     DWORD64 Dr1;
917     DWORD64 Dr2;
918     DWORD64 Dr3;
919     DWORD64 Dr6;
920     DWORD64 Dr7;
921 
922     /* Integer */
923     DWORD64 Rax;
924     DWORD64 Rcx;
925     DWORD64 Rdx;
926     DWORD64 Rbx;
927     DWORD64 Rsp;
928     DWORD64 Rbp;
929     DWORD64 Rsi;
930     DWORD64 Rdi;
931     DWORD64 R8;
932     DWORD64 R9;
933     DWORD64 R10;
934     DWORD64 R11;
935     DWORD64 R12;
936     DWORD64 R13;
937     DWORD64 R14;
938     DWORD64 R15;
939 
940     /* Counter */
941     DWORD64 Rip;
942 
943     /* Floating point */
944     union {
945         XMM_SAVE_AREA32 FltSave;
946         struct {
947             M128A Header[2];
948             M128A Legacy[8];
949             M128A Xmm0;
950             M128A Xmm1;
951             M128A Xmm2;
952             M128A Xmm3;
953             M128A Xmm4;
954             M128A Xmm5;
955             M128A Xmm6;
956             M128A Xmm7;
957             M128A Xmm8;
958             M128A Xmm9;
959             M128A Xmm10;
960             M128A Xmm11;
961             M128A Xmm12;
962             M128A Xmm13;
963             M128A Xmm14;
964             M128A Xmm15;
965         } DUMMYSTRUCTNAME;
966     } DUMMYUNIONNAME;
967 
968     /* Vector */
969     M128A VectorRegister[26];
970     DWORD64 VectorControl;
971 
972     /* Debug control */
973     DWORD64 DebugControl;
974     DWORD64 LastBranchToRip;
975     DWORD64 LastBranchFromRip;
976     DWORD64 LastExceptionToRip;
977     DWORD64 LastExceptionFromRip;
978 } CONTEXT;
979 
980 #endif /* __x86_64__ */
981 
982 /* Alpha context definitions */
983 #if defined(_ALPHA_) || defined(__ALPHA__) || defined(__alpha__)
984 
985 #define CONTEXT_ALPHA   0x00020000
986 
987 #define CONTEXT_CONTROL         (CONTEXT_ALPHA | 0x00000001L)
988 #define CONTEXT_FLOATING_POINT  (CONTEXT_ALPHA | 0x00000002L)
989 #define CONTEXT_INTEGER         (CONTEXT_ALPHA | 0x00000004L)
990 #define CONTEXT_FULL  (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER)
991 
992 #define EXCEPTION_READ_FAULT    0
993 #define EXCEPTION_WRITE_FAULT   1
994 #define EXCEPTION_EXECUTE_FAULT 8
995 
996 typedef struct _CONTEXT
997 {
998     /* selected by CONTEXT_FLOATING_POINT */
999     ULONGLONG FltF0;
1000     ULONGLONG FltF1;
1001     ULONGLONG FltF2;
1002     ULONGLONG FltF3;
1003     ULONGLONG FltF4;
1004     ULONGLONG FltF5;
1005     ULONGLONG FltF6;
1006     ULONGLONG FltF7;
1007     ULONGLONG FltF8;
1008     ULONGLONG FltF9;
1009     ULONGLONG FltF10;
1010     ULONGLONG FltF11;
1011     ULONGLONG FltF12;
1012     ULONGLONG FltF13;
1013     ULONGLONG FltF14;
1014     ULONGLONG FltF15;
1015     ULONGLONG FltF16;
1016     ULONGLONG FltF17;
1017     ULONGLONG FltF18;
1018     ULONGLONG FltF19;
1019     ULONGLONG FltF20;
1020     ULONGLONG FltF21;
1021     ULONGLONG FltF22;
1022     ULONGLONG FltF23;
1023     ULONGLONG FltF24;
1024     ULONGLONG FltF25;
1025     ULONGLONG FltF26;
1026     ULONGLONG FltF27;
1027     ULONGLONG FltF28;
1028     ULONGLONG FltF29;
1029     ULONGLONG FltF30;
1030     ULONGLONG FltF31;
1031 
1032     /* selected by CONTEXT_INTEGER */
1033     ULONGLONG IntV0;
1034     ULONGLONG IntT0;
1035     ULONGLONG IntT1;
1036     ULONGLONG IntT2;
1037     ULONGLONG IntT3;
1038     ULONGLONG IntT4;
1039     ULONGLONG IntT5;
1040     ULONGLONG IntT6;
1041     ULONGLONG IntT7;
1042     ULONGLONG IntS0;
1043     ULONGLONG IntS1;
1044     ULONGLONG IntS2;
1045     ULONGLONG IntS3;
1046     ULONGLONG IntS4;
1047     ULONGLONG IntS5;
1048     ULONGLONG IntFp;
1049     ULONGLONG IntA0;
1050     ULONGLONG IntA1;
1051     ULONGLONG IntA2;
1052     ULONGLONG IntA3;
1053     ULONGLONG IntA4;
1054     ULONGLONG IntA5;
1055     ULONGLONG IntT8;
1056     ULONGLONG IntT9;
1057     ULONGLONG IntT10;
1058     ULONGLONG IntT11;
1059     ULONGLONG IntRa;
1060     ULONGLONG IntT12;
1061     ULONGLONG IntAt;
1062     ULONGLONG IntGp;
1063     ULONGLONG IntSp;
1064     ULONGLONG IntZero;
1065 
1066     /* selected by CONTEXT_FLOATING_POINT */
1067     ULONGLONG Fpcr;
1068     ULONGLONG SoftFpcr;
1069 
1070     /* selected by CONTEXT_CONTROL */
1071     ULONGLONG Fir;
1072     DWORD Psr;
1073     DWORD ContextFlags;
1074     DWORD Fill[4];
1075 } CONTEXT;
1076 
1077 #define _QUAD_PSR_OFFSET   HighSoftFpcr
1078 #define _QUAD_FLAGS_OFFSET HighFir
1079 
1080 #endif  /* _ALPHA_ */
1081 
1082 #ifdef __arm__
1083 
1084 /* The following flags control the contents of the CONTEXT structure. */
1085 
1086 #define CONTEXT_ARM    0x0000040
1087 #define CONTEXT_CONTROL         (CONTEXT_ARM | 0x00000001L)
1088 #define CONTEXT_INTEGER         (CONTEXT_ARM | 0x00000002L)
1089 
1090 #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER)
1091 
1092 #define EXCEPTION_READ_FAULT    0
1093 #define EXCEPTION_WRITE_FAULT   1
1094 #define EXCEPTION_EXECUTE_FAULT 8
1095 
1096 typedef struct _CONTEXT {
1097         /* The flags values within this flag control the contents of
1098            a CONTEXT record.
1099 
1100            If the context record is used as an input parameter, then
1101            for each portion of the context record controlled by a flag
1102            whose value is set, it is assumed that that portion of the
1103            context record contains valid context. If the context record
1104            is being used to modify a thread's context, then only that
1105            portion of the threads context will be modified.
1106 
1107            If the context record is used as an IN OUT parameter to capture
1108            the context of a thread, then only those portions of the thread's
1109            context corresponding to set flags will be returned.
1110 
1111            The context record is never used as an OUT only parameter. */
1112 
1113         ULONG ContextFlags;
1114 
1115         /* This section is specified/returned if the ContextFlags word contains
1116            the flag CONTEXT_INTEGER. */
1117         ULONG R0;
1118         ULONG R1;
1119         ULONG R2;
1120         ULONG R3;
1121         ULONG R4;
1122         ULONG R5;
1123         ULONG R6;
1124         ULONG R7;
1125         ULONG R8;
1126         ULONG R9;
1127         ULONG R10;
1128         ULONG R11;
1129         ULONG R12;
1130 
1131         ULONG Sp;
1132         ULONG Lr;
1133         ULONG Pc;
1134         ULONG Psr;
1135 } CONTEXT;
1136 
1137 #endif /* __arm__ */
1138 
1139 
1140 /* Mips context definitions */
1141 #ifdef _MIPS_
1142 
1143 #define CONTEXT_R4000   0x00010000
1144 
1145 #define CONTEXT_CONTROL         (CONTEXT_R4000 | 0x00000001)
1146 #define CONTEXT_FLOATING_POINT  (CONTEXT_R4000 | 0x00000002)
1147 #define CONTEXT_INTEGER         (CONTEXT_R4000 | 0x00000004)
1148 
1149 #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER)
1150 
1151 #define EXCEPTION_READ_FAULT    0
1152 #define EXCEPTION_WRITE_FAULT   1
1153 #define EXCEPTION_EXECUTE_FAULT 8
1154 
1155 typedef struct _CONTEXT
1156 {
1157     DWORD Argument[4];
1158     /* These are selected by CONTEXT_FLOATING_POINT */
1159     DWORD FltF0;
1160     DWORD FltF1;
1161     DWORD FltF2;
1162     DWORD FltF3;
1163     DWORD FltF4;
1164     DWORD FltF5;
1165     DWORD FltF6;
1166     DWORD FltF7;
1167     DWORD FltF8;
1168     DWORD FltF9;
1169     DWORD FltF10;
1170     DWORD FltF11;
1171     DWORD FltF12;
1172     DWORD FltF13;
1173     DWORD FltF14;
1174     DWORD FltF15;
1175     DWORD FltF16;
1176     DWORD FltF17;
1177     DWORD FltF18;
1178     DWORD FltF19;
1179     DWORD FltF20;
1180     DWORD FltF21;
1181     DWORD FltF22;
1182     DWORD FltF23;
1183     DWORD FltF24;
1184     DWORD FltF25;
1185     DWORD FltF26;
1186     DWORD FltF27;
1187     DWORD FltF28;
1188     DWORD FltF29;
1189     DWORD FltF30;
1190     DWORD FltF31;
1191 
1192     /* These are selected by CONTEXT_INTEGER */
1193     DWORD IntZero;
1194     DWORD IntAt;
1195     DWORD IntV0;
1196     DWORD IntV1;
1197     DWORD IntA0;
1198     DWORD IntA1;
1199     DWORD IntA2;
1200     DWORD IntA3;
1201     DWORD IntT0;
1202     DWORD IntT1;
1203     DWORD IntT2;
1204     DWORD IntT3;
1205     DWORD IntT4;
1206     DWORD IntT5;
1207     DWORD IntT6;
1208     DWORD IntT7;
1209     DWORD IntS0;
1210     DWORD IntS1;
1211     DWORD IntS2;
1212     DWORD IntS3;
1213     DWORD IntS4;
1214     DWORD IntS5;
1215     DWORD IntS6;
1216     DWORD IntS7;
1217     DWORD IntT8;
1218     DWORD IntT9;
1219     DWORD IntK0;
1220     DWORD IntK1;
1221     DWORD IntGp;
1222     DWORD IntSp;
1223     DWORD IntS8;
1224     DWORD IntRa;
1225     DWORD IntLo;
1226     DWORD IntHi;
1227 
1228     /* These are selected by CONTEXT_FLOATING_POINT */
1229     DWORD Fsr;
1230 
1231     /* These are selected by CONTEXT_CONTROL */
1232     DWORD Fir;
1233     DWORD Psr;
1234 
1235     DWORD ContextFlags;
1236     DWORD Fill[2];
1237 } CONTEXT;
1238 
1239 #endif  /* _MIPS_ */
1240 
1241 /* PowerPC context definitions */
1242 #ifdef __powerpc__
1243 
1244 #define CONTEXT_CONTROL         0x0001
1245 #define CONTEXT_FLOATING_POINT  0x0002
1246 #define CONTEXT_INTEGER         0x0004
1247 #define CONTEXT_DEBUG_REGISTERS 0x0008
1248 #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER)
1249 
1250 #define EXCEPTION_READ_FAULT    0
1251 #define EXCEPTION_WRITE_FAULT   1
1252 #define EXCEPTION_EXECUTE_FAULT 8
1253 
1254 typedef struct
1255 {
1256     /* These are selected by CONTEXT_FLOATING_POINT */
1257     double Fpr0;
1258     double Fpr1;
1259     double Fpr2;
1260     double Fpr3;
1261     double Fpr4;
1262     double Fpr5;
1263     double Fpr6;
1264     double Fpr7;
1265     double Fpr8;
1266     double Fpr9;
1267     double Fpr10;
1268     double Fpr11;
1269     double Fpr12;
1270     double Fpr13;
1271     double Fpr14;
1272     double Fpr15;
1273     double Fpr16;
1274     double Fpr17;
1275     double Fpr18;
1276     double Fpr19;
1277     double Fpr20;
1278     double Fpr21;
1279     double Fpr22;
1280     double Fpr23;
1281     double Fpr24;
1282     double Fpr25;
1283     double Fpr26;
1284     double Fpr27;
1285     double Fpr28;
1286     double Fpr29;
1287     double Fpr30;
1288     double Fpr31;
1289     double Fpscr;
1290 
1291     /* These are selected by CONTEXT_INTEGER */
1292     DWORD Gpr0;
1293     DWORD Gpr1;
1294     DWORD Gpr2;
1295     DWORD Gpr3;
1296     DWORD Gpr4;
1297     DWORD Gpr5;
1298     DWORD Gpr6;
1299     DWORD Gpr7;
1300     DWORD Gpr8;
1301     DWORD Gpr9;
1302     DWORD Gpr10;
1303     DWORD Gpr11;
1304     DWORD Gpr12;
1305     DWORD Gpr13;
1306     DWORD Gpr14;
1307     DWORD Gpr15;
1308     DWORD Gpr16;
1309     DWORD Gpr17;
1310     DWORD Gpr18;
1311     DWORD Gpr19;
1312     DWORD Gpr20;
1313     DWORD Gpr21;
1314     DWORD Gpr22;
1315     DWORD Gpr23;
1316     DWORD Gpr24;
1317     DWORD Gpr25;
1318     DWORD Gpr26;
1319     DWORD Gpr27;
1320     DWORD Gpr28;
1321     DWORD Gpr29;
1322     DWORD Gpr30;
1323     DWORD Gpr31;
1324 
1325     DWORD Cr;
1326     DWORD Xer;
1327 
1328     /* These are selected by CONTEXT_CONTROL */
1329     DWORD Msr;
1330     DWORD Iar; /* Instruction Address Register , aka PC ... */
1331     DWORD Lr;
1332     DWORD Ctr;
1333 
1334     DWORD ContextFlags;
1335     
1336     DWORD Dar;   /* Fault registers for coredump */
1337     DWORD Dsisr; 
1338     DWORD Trap;  /* number of powerpc exception taken */
1339 
1340     /* These are selected by CONTEXT_DEBUG_REGISTERS */
1341     DWORD Dr0;
1342     DWORD Dr1;
1343     DWORD Dr2;
1344     DWORD Dr3;
1345     DWORD Dr4;
1346     DWORD Dr5;
1347     DWORD Dr6;
1348     DWORD Dr7;
1349 } CONTEXT;
1350 
1351 typedef struct _STACK_FRAME_HEADER
1352 {
1353     DWORD BackChain;
1354     DWORD GlueSaved1;
1355     DWORD GlueSaved2;
1356     DWORD Reserved1;
1357     DWORD Spare1;
1358     DWORD Spare2;
1359 
1360     DWORD Parameter0;
1361     DWORD Parameter1;
1362     DWORD Parameter2;
1363     DWORD Parameter3;
1364     DWORD Parameter4;
1365     DWORD Parameter5;
1366     DWORD Parameter6;
1367     DWORD Parameter7;
1368 } STACK_FRAME_HEADER,*PSTACK_FRAME_HEADER;
1369 
1370 #endif  /* __powerpc__ */
1371 
1372 #ifdef __sparc__
1373 
1374 /*
1375  * FIXME:
1376  *
1377  * There is no official CONTEXT structure defined for the SPARC
1378  * architecture, so I just made one up.
1379  *
1380  * This structure is valid only for 32-bit SPARC architectures,
1381  * not for 64-bit SPARC.
1382  *
1383  * Note that this structure contains only the 'top-level' registers;
1384  * the rest of the register window chain is not visible.
1385  *
1386  * The layout follows the Solaris 'prgregset_t' structure.
1387  *
1388  */
1389 
1390 #define CONTEXT_SPARC            0x10000000
1391 
1392 #define CONTEXT_CONTROL         (CONTEXT_SPARC | 0x00000001)
1393 #define CONTEXT_FLOATING_POINT  (CONTEXT_SPARC | 0x00000002)
1394 #define CONTEXT_INTEGER         (CONTEXT_SPARC | 0x00000004)
1395 
1396 #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER)
1397 
1398 #define EXCEPTION_READ_FAULT    0
1399 #define EXCEPTION_WRITE_FAULT   1
1400 #define EXCEPTION_EXECUTE_FAULT 8
1401 
1402 typedef struct _CONTEXT
1403 {
1404     DWORD ContextFlags;
1405 
1406     /* These are selected by CONTEXT_INTEGER */
1407     DWORD g0;
1408     DWORD g1;
1409     DWORD g2;
1410     DWORD g3;
1411     DWORD g4;
1412     DWORD g5;
1413     DWORD g6;
1414     DWORD g7;
1415     DWORD o0;
1416     DWORD o1;
1417     DWORD o2;
1418     DWORD o3;
1419     DWORD o4;
1420     DWORD o5;
1421     DWORD o6;
1422     DWORD o7;
1423     DWORD l0;
1424     DWORD l1;
1425     DWORD l2;
1426     DWORD l3;
1427     DWORD l4;
1428     DWORD l5;
1429     DWORD l6;
1430     DWORD l7;
1431     DWORD i0;
1432     DWORD i1;
1433     DWORD i2;
1434     DWORD i3;
1435     DWORD i4;
1436     DWORD i5;
1437     DWORD i6;
1438     DWORD i7;
1439 
1440     /* These are selected by CONTEXT_CONTROL */
1441     DWORD psr;
1442     DWORD pc;
1443     DWORD npc;
1444     DWORD y;
1445     DWORD wim;
1446     DWORD tbr;
1447 
1448     /* FIXME: floating point registers missing */
1449 
1450 } CONTEXT;
1451 
1452 #endif  /* __sparc__ */
1453 
1454 #if !defined(CONTEXT_FULL) && !defined(RC_INVOKED)
1455 #error You need to define a CONTEXT for your CPU
1456 #endif
1457 
1458 typedef CONTEXT *PCONTEXT;
1459 
1460 /*
1461  * Language IDs
1462  */
1463 
1464 #define MAKELCID(l, s)          (MAKELONG(l, s))
1465 
1466 #define MAKELANGID(p, s)        ((((WORD)(s))<<10) | (WORD)(p))
1467 #define PRIMARYLANGID(l)        ((WORD)(l) & 0x3ff)
1468 #define SUBLANGID(l)            ((WORD)(l) >> 10)
1469 
1470 #define LANGIDFROMLCID(lcid)    ((WORD)(lcid))
1471 #define SORTIDFROMLCID(lcid)    ((WORD)((((DWORD)(lcid)) >> 16) & 0x0f))
1472 
1473 #define LANG_SYSTEM_DEFAULT     (MAKELANGID(LANG_NEUTRAL, SUBLANG_SYS_DEFAULT))
1474 #define LANG_USER_DEFAULT       (MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT))
1475 #define LOCALE_SYSTEM_DEFAULT   (MAKELCID(LANG_SYSTEM_DEFAULT, SORT_DEFAULT))
1476 #define LOCALE_USER_DEFAULT     (MAKELCID(LANG_USER_DEFAULT, SORT_DEFAULT))
1477 #define LOCALE_NEUTRAL          (MAKELCID(MAKELANGID(LANG_NEUTRAL,SUBLANG_NEUTRAL),SORT_DEFAULT))
1478 
1479 #define UNREFERENCED_PARAMETER(u)       (void)(u)
1480 #define DBG_UNREFERENCED_PARAMETER(u)   (void)(u)
1481 #define DBG_UNREFERENCED_LOCAL_VARIABLE(u) (void)(u)
1482 
1483 #define LANG_NEUTRAL        0x00
1484 #define LANG_INVARIANT      0x7f
1485 
1486 #define LANG_AFRIKAANS      0x36
1487 #define LANG_ALBANIAN       0x1c
1488 #define LANG_ALSATIAN       0x84
1489 #define LANG_AMHARIC        0x5e
1490 #define LANG_ARABIC         0x01
1491 #define LANG_ARMENIAN       0x2b
1492 #define LANG_ASSAMESE       0x4d
1493 #define LANG_AZERI          0x2c
1494 #define LANG_BASHKIR        0x6d
1495 #define LANG_BASQUE         0x2d
1496 #define LANG_BELARUSIAN     0x23
1497 #define LANG_BENGALI        0x45
1498 #define LANG_BOSNIAN        0x1a
1499 #define LANG_BOSNIAN_NEUTRAL      0x781a
1500 #define LANG_BRETON         0x7e
1501 #define LANG_BULGARIAN      0x02
1502 #define LANG_CATALAN        0x03
1503 #define LANG_CHINESE        0x04
1504 #define LANG_CHINESE_SIMPLIFIED   0x0004
1505 #define LANG_CHINESE_TRADITIONAL  0x7c04
1506 #define LANG_CORSICAN       0x83
1507 #define LANG_CROATIAN       0x1a
1508 #define LANG_CZECH          0x05
1509 #define LANG_DANISH         0x06
1510 #define LANG_DARI           0x8c
1511 #define LANG_DIVEHI         0x65
1512 #define LANG_DUTCH          0x13
1513 #define LANG_ENGLISH        0x09
1514 #define LANG_ESTONIAN       0x25
1515 #define LANG_FAEROESE       0x38
1516 #define LANG_FARSI          LANG_PERSIAN
1517 #define LANG_FILIPINO       0x64
1518 #define LANG_FINNISH        0x0b
1519 #define LANG_FRENCH         0x0c
1520 #define LANG_FRISIAN        0x62
1521 #define LANG_GALICIAN       0x56
1522 #define LANG_GEORGIAN       0x37
1523 #define LANG_GERMAN         0x07
1524 #define LANG_GREEK          0x08
1525 #define LANG_GREENLANDIC    0x6f
1526 #define LANG_GUJARATI       0x47
1527 #define LANG_HAUSA          0x68
1528 #define LANG_HEBREW         0x0d
1529 #define LANG_HINDI          0x39
1530 #define LANG_HUNGARIAN      0x0e
1531 #define LANG_ICELANDIC      0x0f
1532 #define LANG_IGBO           0x70
1533 #define LANG_INDONESIAN     0x21
1534 #define LANG_INUKTITUT      0x5d
1535 #define LANG_IRISH          0x3c
1536 #define LANG_ITALIAN        0x10
1537 #define LANG_JAPANESE       0x11
1538 #define LANG_KANNADA        0x4b
1539 #define LANG_KASHMIRI       0x60
1540 #define LANG_KAZAK          0x3f
1541 #define LANG_KHMER          0x53
1542 #define LANG_KICHE          0x86
1543 #define LANG_KINYARWANDA    0x87
1544 #define LANG_KONKANI        0x57
1545 #define LANG_KOREAN         0x12
1546 #define LANG_KYRGYZ         0x40
1547 #define LANG_LAO            0x54
1548 #define LANG_LATVIAN        0x26
1549 #define LANG_LITHUANIAN     0x27
1550 #define LANG_LOWER_SORBIAN  0x2e
1551 #define LANG_LUXEMBOURGISH  0x6e
1552 #define LANG_MACEDONIAN     0x2f
1553 #define LANG_MALAY          0x3e
1554 #define LANG_MALAYALAM      0x4c
1555 #define LANG_MALTESE        0x3a
1556 #define LANG_MANIPURI       0x58
1557 #define LANG_MAORI          0x81
1558 #define LANG_MAPUDUNGUN     0x7a
1559 #define LANG_MARATHI        0x4e
1560 #define LANG_MOHAWK         0x7c
1561 #define LANG_MONGOLIAN      0x50
1562 #define LANG_NEPALI         0x61
1563 #define LANG_NORWEGIAN      0x14
1564 #define LANG_OCCITAN        0x82
1565 #define LANG_ORIYA          0x48
1566 #define LANG_PASHTO         0x63
1567 #define LANG_PERSIAN        0x29
1568 #define LANG_POLISH         0x15
1569 #define LANG_PORTUGUESE     0x16
1570 #define LANG_PUNJABI        0x46
1571 #define LANG_QUECHUA        0x6b
1572 #define LANG_ROMANIAN       0x18
1573 #define LANG_ROMANSH        0x17
1574 #define LANG_RUSSIAN        0x19
1575 #define LANG_SAMI           0x3b
1576 #define LANG_SANSKRIT       0x4f
1577 #define LANG_SERBIAN        0x1a
1578 #define LANG_SERBIAN_NEUTRAL      0x7c1a
1579 #define LANG_SINDHI         0x59
1580 #define LANG_SINHALESE      0x5b
1581 #define LANG_SLOVAK         0x1b
1582 #define LANG_SLOVENIAN      0x24
1583 #define LANG_SOTHO          0x6c
1584 #define LANG_SPANISH        0x0a
1585 #define LANG_SWAHILI        0x41
1586 #define LANG_SWEDISH        0x1d
1587 #define LANG_SYRIAC         0x5a
1588 #define LANG_TAJIK          0x28
1589 #define LANG_TAMAZIGHT      0x5f
1590 #define LANG_TAMIL          0x49
1591 #define LANG_TATAR          0x44
1592 #define LANG_TELUGU         0x4a
1593 #define LANG_THAI           0x1e
1594 #define LANG_TIBETAN        0x51
1595 #define LANG_TIGRIGNA       0x73
1596 #define LANG_TSWANA         0x32
1597 #define LANG_TURKISH        0x1f
1598 #define LANG_TURKMEN        0x42
1599 #define LANG_UIGHUR         0x80
1600 #define LANG_UKRAINIAN      0x22
1601 #define LANG_UPPER_SORBIAN  0x2e
1602 #define LANG_URDU           0x20
1603 #define LANG_UZBEK          0x43
1604 #define LANG_VIETNAMESE     0x2a
1605 #define LANG_WELSH          0x52
1606 #define LANG_WOLOF          0x88
1607 #define LANG_XHOSA          0x34
1608 #define LANG_YAKUT          0x85
1609 #define LANG_YI             0x78
1610 #define LANG_YORUBA         0x6a
1611 #define LANG_ZULU           0x35
1612 
1613 /* These are documented by the MSDN but are missing from the Windows header */
1614 #define LANG_MALAGASY       0x8d
1615 
1616 /* FIXME: these are not defined anywhere */
1617 #define LANG_SUTU           0x30
1618 #define LANG_TSONGA         0x31
1619 #define LANG_VENDA          0x33
1620 
1621 /* non standard; keep the number high enough (but < 0xff) */
1622 #define LANG_ESPERANTO                   0x8f
1623 #define LANG_WALON                       0x90
1624 #define LANG_CORNISH                     0x91
1625 #define LANG_GAELIC                      0x94
1626 
1627 /* Sublanguage definitions */
1628 #define SUBLANG_NEUTRAL                  0x00    /* language neutral */
1629 #define SUBLANG_DEFAULT                  0x01    /* user default */
1630 #define SUBLANG_SYS_DEFAULT              0x02    /* system default */
1631 #define SUBLANG_CUSTOM_DEFAULT           0x03
1632 #define SUBLANG_CUSTOM_UNSPECIFIED       0x04
1633 #define SUBLANG_UI_CUSTOM_DEFAULT        0x05
1634 
1635 #define SUBLANG_AFRIKAANS_SOUTH_AFRICA     0x01
1636 #define SUBLANG_ALBANIAN_ALBANIA           0x01
1637 #define SUBLANG_ALSATIAN_FRANCE            0x01
1638 #define SUBLANG_AMHARIC_ETHIOPIA           0x01
1639 #define SUBLANG_ARABIC_SAUDI_ARABIA        0x01
1640 #define SUBLANG_ARABIC_IRAQ                0x02
1641 #define SUBLANG_ARABIC_EGYPT               0x03
1642 #define SUBLANG_ARABIC_LIBYA               0x04
1643 #define SUBLANG_ARABIC_ALGERIA             0x05
1644 #define SUBLANG_ARABIC_MOROCCO             0x06
1645 #define SUBLANG_ARABIC_TUNISIA             0x07
1646 #define SUBLANG_ARABIC_OMAN                0x08
1647 #define SUBLANG_ARABIC_YEMEN               0x09
1648 #define SUBLANG_ARABIC_SYRIA               0x0a
1649 #define SUBLANG_ARABIC_JORDAN              0x0b
1650 #define SUBLANG_ARABIC_LEBANON             0x0c
1651 #define SUBLANG_ARABIC_KUWAIT              0x0d
1652 #define SUBLANG_ARABIC_UAE                 0x0e
1653 #define SUBLANG_ARABIC_BAHRAIN             0x0f
1654 #define SUBLANG_ARABIC_QATAR               0x10
1655 #define SUBLANG_ARMENIAN_ARMENIA           0x01
1656 #define SUBLANG_ASSAMESE_INDIA             0x01
1657 #define SUBLANG_AZERI_LATIN                0x01
1658 #define SUBLANG_AZERI_CYRILLIC             0x02
1659 #define SUBLANG_BASHKIR_RUSSIA             0x01
1660 #define SUBLANG_BASQUE_BASQUE              0x01
1661 #define SUBLANG_BELARUSIAN_BELARUS         0x01
1662 #define SUBLANG_BENGALI_INDIA              0x01
1663 #define SUBLANG_BENGALI_BANGLADESH         0x02
1664 #define SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_LATIN 0x05
1665 #define SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_CYRILLIC 0x08
1666 #define SUBLANG_BRETON_FRANCE              0x01
1667 #define SUBLANG_BULGARIAN_BULGARIA         0x01
1668 #define SUBLANG_CATALAN_CATALAN            0x01
1669 #define SUBLANG_CHINESE_TRADITIONAL        0x01
1670 #define SUBLANG_CHINESE_SIMPLIFIED         0x02
1671 #define SUBLANG_CHINESE_HONGKONG           0x03
1672 #define SUBLANG_CHINESE_SINGAPORE          0x04
1673 #define SUBLANG_CHINESE_MACAU              0x05
1674 #define SUBLANG_CORSICAN_FRANCE            0x01
1675 #define SUBLANG_CROATIAN_CROATIA           0x01
1676 #define SUBLANG_CROATIAN_BOSNIA_HERZEGOVINA_LATIN 0x04
1677 #define SUBLANG_CZECH_CZECH_REPUBLIC       0x01
1678 #define SUBLANG_DANISH_DENMARK             0x01
1679 #define SUBLANG_DARI_AFGHANISTAN           0x01
1680 #define SUBLANG_DIVEHI_MALDIVES            0x01
1681 #define SUBLANG_DUTCH                      0x01
1682 #define SUBLANG_DUTCH_BELGIAN              0x02
1683 #define SUBLANG_ENGLISH_US                 0x01
1684 #define SUBLANG_ENGLISH_UK                 0x02
1685 #define SUBLANG_ENGLISH_AUS                0x03
1686 #define SUBLANG_ENGLISH_CAN                0x04
1687 #define SUBLANG_ENGLISH_NZ                 0x05
1688 #define SUBLANG_ENGLISH_EIRE               0x06
1689 #define SUBLANG_ENGLISH_SOUTH_AFRICA       0x07
1690 #define SUBLANG_ENGLISH_JAMAICA            0x08
1691 #define SUBLANG_ENGLISH_CARIBBEAN          0x09
1692 #define SUBLANG_ENGLISH_BELIZE             0x0a
1693 #define SUBLANG_ENGLISH_TRINIDAD           0x0b
1694 #define SUBLANG_ENGLISH_ZIMBABWE           0x0c
1695 #define SUBLANG_ENGLISH_PHILIPPINES        0x0d
1696 #define SUBLANG_ENGLISH_INDIA              0x10
1697 #define SUBLANG_ENGLISH_MALAYSIA           0x11
1698 #define SUBLANG_ENGLISH_SINGAPORE          0x12
1699 #define SUBLANG_ESTONIAN_ESTONIA           0x01
1700 #define SUBLANG_FAEROESE_FAROE_ISLANDS     0x01
1701 #define SUBLANG_FILIPINO_PHILIPPINES       0x01
1702 #define SUBLANG_FINNISH_FINLAND            0x01
1703 #define SUBLANG_FRENCH                     0x01
1704 #define SUBLANG_FRENCH_BELGIAN             0x02
1705 #define SUBLANG_FRENCH_CANADIAN            0x03
1706 #define SUBLANG_FRENCH_SWISS               0x04
1707 #define SUBLANG_FRENCH_LUXEMBOURG          0x05
1708 #define SUBLANG_FRENCH_MONACO              0x06
1709 #define SUBLANG_FRISIAN_NETHERLANDS        0x01
1710 #define SUBLANG_GALICIAN_GALICIAN          0x01
1711 #define SUBLANG_GEORGIAN_GEORGIA           0x01
1712 #define SUBLANG_GERMAN                     0x01
1713 #define SUBLANG_GERMAN_SWISS               0x02
1714 #define SUBLANG_GERMAN_AUSTRIAN            0x03
1715 #define SUBLANG_GERMAN_LUXEMBOURG          0x04
1716 #define SUBLANG_GERMAN_LIECHTENSTEIN       0x05
1717 #define SUBLANG_GREEK_GREECE               0x01
1718 #define SUBLANG_GREENLANDIC_GREENLAND      0x01
1719 #define SUBLANG_GUJARATI_INDIA             0x01
1720 #define SUBLANG_HAUSA_NIGERIA_LATIN        0x01
1721 #define SUBLANG_HEBREW_ISRAEL              0x01
1722 #define SUBLANG_HINDI_INDIA                0x01
1723 #define SUBLANG_HUNGARIAN_HUNGARY          0x01
1724 #define SUBLANG_ICELANDIC_ICELAND          0x01
1725 #define SUBLANG_IGBO_NIGERIA               0x01
1726 #define SUBLANG_INDONESIAN_INDONESIA       0x01
1727 #define SUBLANG_INUKTITUT_CANADA           0x01
1728 #define SUBLANG_INUKTITUT_CANADA_LATIN     0x02
1729 #define SUBLANG_IRISH_IRELAND              0x02
1730 #define SUBLANG_ITALIAN                    0x01
1731 #define SUBLANG_ITALIAN_SWISS              0x02
1732 #define SUBLANG_JAPANESE_JAPAN             0x01
1733 #define SUBLANG_KANNADA_INDIA              0x01
1734 #define SUBLANG_KASHMIRI_SASIA             0x02
1735 #define SUBLANG_KASHMIRI_INDIA             0x02
1736 #define SUBLANG_KAZAK_KAZAKHSTAN           0x01
1737 #define SUBLANG_KHMER_CAMBODIA             0x01
1738 #define SUBLANG_KICHE_GUATEMALA            0x01
1739 #define SUBLANG_KINYARWANDA_RWANDA         0X01
1740 #define SUBLANG_KONKANI_INDIA              0x01
1741 #define SUBLANG_KOREAN                     0x01
1742 #define SUBLANG_KYRGYZ_KYRGYZSTAN          0x01
1743 #define SUBLANG_LAO_LAO                    0x01
1744 #define SUBLANG_LATVIAN_LATVIA             0x01
1745 #define SUBLANG_LITHUANIAN_LITHUANIA       0x01
1746 #define SUBLANG_LOWER_SORBIAN_GERMANY      0x02
1747 #define SUBLANG_LUXEMBOURGISH_LUXEMBOURG   0x01
1748 #define SUBLANG_MACEDONIAN_MACEDONIA       0x01
1749 #define SUBLANG_MALAY_MALAYSIA             0x01
1750 #define SUBLANG_MALAY_BRUNEI_DARUSSALAM    0x02
1751 #define SUBLANG_MALAYALAM_INDIA            0x01
1752 #define SUBLANG_MALTESE_MALTA              0x01
1753 #define SUBLANG_MAORI_NEW_ZEALAND          0x01
1754 #define SUBLANG_MAPUDUNGUN_CHILE           0x01
1755 #define SUBLANG_MARATHI_INDIA              0x01
1756 #define SUBLANG_MOHAWK_MOHAWK              0x01
1757 #define SUBLANG_MONGOLIAN_CYRILLIC_MONGOLIA 0x01
1758 #define SUBLANG_MONGOLIAN_PRC              0x02
1759 #define SUBLANG_NEPALI_INDIA               0x02
1760 #define SUBLANG_NEPALI_NEPAL               0x01
1761 #define SUBLANG_NORWEGIAN_BOKMAL           0x01
1762 #define SUBLANG_NORWEGIAN_NYNORSK          0x02
1763 #define SUBLANG_OCCITAN_FRANCE             0x01
1764 #define SUBLANG_ORIYA_INDIA                0x01
1765 #define SUBLANG_PASHTO_AFGHANISTAN         0x01
1766 #define SUBLANG_PERSIAN_IRAN               0x01
1767 #define SUBLANG_POLISH_POLAND              0x01
1768 #define SUBLANG_PORTUGUESE                 0x02
1769 #define SUBLANG_PORTUGUESE_BRAZILIAN       0x01
1770 #define SUBLANG_PUNJABI_INDIA              0x01
1771 #define SUBLANG_QUECHUA_BOLIVIA            0x01
1772 #define SUBLANG_QUECHUA_ECUADOR            0x02
1773 #define SUBLANG_QUECHUA_PERU               0x03
1774 #define SUBLANG_ROMANIAN_ROMANIA           0x01
1775 #define SUBLANG_ROMANSH_SWITZERLAND        0x01
1776 #define SUBLANG_RUSSIAN_RUSSIA             0x01
1777 #define SUBLANG_SAMI_NORTHERN_NORWAY       0x01
1778 #define SUBLANG_SAMI_NORTHERN_SWEDEN       0x02
1779 #define SUBLANG_SAMI_NORTHERN_FINLAND      0x03
1780 #define SUBLANG_SAMI_LULE_NORWAY           0x04
1781 #define SUBLANG_SAMI_LULE_SWEDEN           0x05
1782 #define SUBLANG_SAMI_SOUTHERN_NORWAY       0x06
1783 #define SUBLANG_SAMI_SOUTHERN_SWEDEN       0x07
1784 #define SUBLANG_SAMI_SKOLT_FINLAND         0x08
1785 #define SUBLANG_SAMI_INARI_FINLAND         0x09
1786 #define SUBLANG_SANSKRIT_INDIA             0x01
1787 #define SUBLANG_SERBIAN_BOSNIA_HERZEGOVINA_LATIN 0x06
1788 #define SUBLANG_SERBIAN_BOSNIA_HERZEGOVINA_CYRILLIC 0x07
1789 #define SUBLANG_SERBIAN_CROATIA            0x01
1790 #define SUBLANG_SERBIAN_LATIN              0x02
1791 #define SUBLANG_SERBIAN_CYRILLIC           0x03
1792 #define SUBLANG_SINDHI_AFGHANISTAN         0x02
1793 #define SUBLANG_SINHALESE_SRI_LANKA        0x01
1794 #define SUBLANG_SLOVAK_SLOVAKIA            0x01
1795 #define SUBLANG_SLOVENIAN_SLOVENIA         0x01
1796 #define SUBLANG_SOTHO_NORTHERN_SOUTH_AFRICA 0x01
1797 #define SUBLANG_SPANISH                    0x01
1798 #define SUBLANG_SPANISH_MEXICAN            0x02
1799 #define SUBLANG_SPANISH_MODERN             0x03
1800 #define SUBLANG_SPANISH_GUATEMALA          0x04
1801 #define SUBLANG_SPANISH_COSTA_RICA         0x05
1802 #define SUBLANG_SPANISH_PANAMA             0x06
1803 #define SUBLANG_SPANISH_DOMINICAN_REPUBLIC 0x07
1804 #define SUBLANG_SPANISH_VENEZUELA          0x08
1805 #define SUBLANG_SPANISH_COLOMBIA           0x09
1806 #define SUBLANG_SPANISH_PERU               0x0a
1807 #define SUBLANG_SPANISH_ARGENTINA          0x0b
1808 #define SUBLANG_SPANISH_ECUADOR            0x0c
1809 #define SUBLANG_SPANISH_CHILE              0x0d
1810 #define SUBLANG_SPANISH_URUGUAY            0x0e
1811 #define SUBLANG_SPANISH_PARAGUAY           0x0f
1812 #define SUBLANG_SPANISH_BOLIVIA            0x10
1813 #define SUBLANG_SPANISH_EL_SALVADOR        0x11
1814 #define SUBLANG_SPANISH_HONDURAS           0x12
1815 #define SUBLANG_SPANISH_NICARAGUA          0x13
1816 #define SUBLANG_SPANISH_PUERTO_RICO        0x14
1817 #define SUBLANG_SPANISH_US                 0x15
1818 #define SUBLANG_SWAHILI_KENYA              0x01
1819 #define SUBLANG_SWEDISH                    0x01
1820 #define SUBLANG_SWEDISH_FINLAND            0x02
1821 #define SUBLANG_SYRIAC_SYRIA               0x01
1822 #define SUBLANG_TAJIK_TAJIKISTAN           0x01
1823 #define SUBLANG_TAMAZIGHT_ALGERIA_LATIN    0x02
1824 #define SUBLANG_TAMIL_INDIA                0x01
1825 #define SUBLANG_TATAR_RUSSIA               0x01
1826 #define SUBLANG_TELUGU_INDIA               0x01
1827 #define SUBLANG_THAI_THAILAND              0x01
1828 #define SUBLANG_TIBETAN_PRC                0x01
1829 #define SUBLANG_TIBETAN_BHUTAN             0x02
1830 #define SUBLANG_TIGRIGNA_ERITREA           0x02
1831 #define SUBLANG_TSWANA_SOUTH_AFRICA        0x01
1832 #define SUBLANG_TURKISH_TURKEY             0x01
1833 #define SUBLANG_TURKMEN_TURKMENISTAN       0x01
1834 #define SUBLANG_UIGHUR_PRC                 0x01
1835 #define SUBLANG_UKRAINIAN_UKRAINE          0x01
1836 #define SUBLANG_UPPER_SORBIAN_GERMANY      0x01
1837 #define SUBLANG_URDU_PAKISTAN              0x01
1838 #define SUBLANG_URDU_INDIA                 0x02
1839 #define SUBLANG_UZBEK_LATIN                0x01
1840 #define SUBLANG_UZBEK_CYRILLIC             0x02
1841 #define SUBLANG_VIETNAMESE_VIETNAM         0x01
1842 #define SUBLANG_WELSH_UNITED_KINGDOM       0x01
1843 #define SUBLANG_WOLOF_SENEGAL              0x01
1844 #define SUBLANG_XHOSA_SOUTH_AFRICA         0x01
1845 #define SUBLANG_YAKUT_RUSSIA               0x01
1846 #define SUBLANG_YI_PRC                     0x01
1847 #define SUBLANG_YORUBA_NIGERIA             0x01
1848 #define SUBLANG_ZULU_SOUTH_AFRICA          0x01
1849 
1850 /* These are documented by the MSDN but are missing from the Windows header */
1851 #define SUBLANG_ENGLISH_IRELAND            SUBLANG_ENGLISH_EIRE
1852 #define SUBLANG_HAUSA_NIGERIA              SUBLANG_HAUSA_NIGERIA_LATIN
1853 #define SUBLANG_LAO_LAO_PDR                SUBLANG_LAO_LAO
1854 #define SUBLANG_LITHUANIAN                 SUBLANG_LITHUANIAN_LITHUANIA
1855 #define SUBLANG_PORTUGUESE_PORTUGAL        SUBLANG_PORTUGUESE
1856 #define SUBLANG_SWAHILI                    SUBLANG_SWAHILI_KENYA
1857 #define SUBLANG_SWEDISH_SWEDEN             SUBLANG_SWEDISH
1858 #define SUBLANG_SYRIAC                     SUBLANG_SYRIAC_SYRIA
1859 
1860 /* FIXME: these are not defined anywhere */
1861 #define SUBLANG_DUTCH_SURINAM              0x03
1862 #define SUBLANG_ROMANIAN                   SUBLANG_ROMANIAN_ROMANIA
1863 #define SUBLANG_ROMANIAN_MOLDAVIA          0x02
1864 #define SUBLANG_RUSSIAN                    SUBLANG_RUSSIAN_RUSSIA
1865 #define SUBLANG_RUSSIAN_MOLDAVIA           0x02
1866 #define SUBLANG_CROATIAN                   SUBLANG_CROATIAN_CROATIA
1867 #define SUBLANG_LITHUANIAN_CLASSIC         0x02
1868 #define SUBLANG_GAELIC                     0x01
1869 #define SUBLANG_GAELIC_SCOTTISH            0x02
1870 #define SUBLANG_GAELIC_MANX                0x03
1871 
1872 
1873 /*
1874  * Sort definitions
1875  */
1876 
1877 #define SORT_DEFAULT                     0x0
1878 #define SORT_JAPANESE_XJIS               0x0
1879 #define SORT_JAPANESE_UNICODE            0x1
1880 #define SORT_CHINESE_BIG5                0x0
1881 #define SORT_CHINESE_UNICODE             0x1
1882 #define SORT_KOREAN_KSC                  0x0
1883 #define SORT_KOREAN_UNICODE              0x1
1884 
1885 
1886 
1887 /*
1888  * Definitions for IsTextUnicode()
1889  */
1890 
1891 #define IS_TEXT_UNICODE_ASCII16            0x0001
1892 #define IS_TEXT_UNICODE_STATISTICS         0x0002
1893 #define IS_TEXT_UNICODE_CONTROLS           0x0004
1894 #define IS_TEXT_UNICODE_SIGNATURE          0x0008
1895 #define IS_TEXT_UNICODE_UNICODE_MASK       0x000F
1896 #define IS_TEXT_UNICODE_REVERSE_ASCII16    0x0010
1897 #define IS_TEXT_UNICODE_REVERSE_STATISTICS 0x0020
1898 #define IS_TEXT_UNICODE_REVERSE_CONTROLS   0x0040
1899 #define IS_TEXT_UNICODE_REVERSE_SIGNATURE  0x0080
1900 #define IS_TEXT_UNICODE_REVERSE_MASK       0x00F0
1901 #define IS_TEXT_UNICODE_ILLEGAL_CHARS      0x0100
1902 #define IS_TEXT_UNICODE_ODD_LENGTH         0x0200
1903 #define IS_TEXT_UNICODE_DBCS_LEADBYTE      0x0400
1904 #define IS_TEXT_UNICODE_NOT_UNICODE_MASK   0x0F00
1905 #define IS_TEXT_UNICODE_NULL_BYTES         0x1000
1906 #define IS_TEXT_UNICODE_NOT_ASCII_MASK     0xF000
1907 
1908 #define MAXIMUM_WAIT_OBJECTS 64
1909 #define MAXIMUM_SUSPEND_COUNT 127
1910 
1911 #define WT_EXECUTEDEFAULT              0x00
1912 #define WT_EXECUTEINIOTHREAD           0x01
1913 #define WT_EXECUTEINUITHREAD           0x02
1914 #define WT_EXECUTEINWAITTHREAD         0x04
1915 #define WT_EXECUTEONLYONCE             0x08
1916 #define WT_EXECUTELONGFUNCTION         0x10
1917 #define WT_EXECUTEINTIMERTHREAD        0x20
1918 #define WT_EXECUTEINPERSISTENTIOTHREAD 0x40
1919 #define WT_EXECUTEINPERSISTENTTHREAD   0x80
1920 #define WT_EXECUTEINLONGTHREAD         0x10
1921 #define WT_EXECUTEDELETEWAIT           0x08
1922 #define WT_TRANSFER_IMPERSONATION      0x0100
1923 
1924 
1925 #define EXCEPTION_CONTINUABLE        0
1926 #define EXCEPTION_NONCONTINUABLE     0x01
1927 
1928 /*
1929  * The exception record used by Win32 to give additional information
1930  * about exception to exception handlers.
1931  */
1932 
1933 #define EXCEPTION_MAXIMUM_PARAMETERS 15
1934 
1935 typedef struct _EXCEPTION_RECORD
1936 {
1937     DWORD    ExceptionCode;
1938     DWORD    ExceptionFlags;
1939     struct  _EXCEPTION_RECORD *ExceptionRecord;
1940 
1941     PVOID    ExceptionAddress;
1942     DWORD    NumberParameters;
1943     ULONG_PTR ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
1944 } EXCEPTION_RECORD, *PEXCEPTION_RECORD;
1945 
1946 /*
1947  * The exception pointers structure passed to exception filters
1948  * in except() and the UnhandledExceptionFilter().
1949  */
1950 
1951 typedef struct _EXCEPTION_POINTERS
1952 {
1953   PEXCEPTION_RECORD  ExceptionRecord;
1954   PCONTEXT           ContextRecord;
1955 } EXCEPTION_POINTERS, *PEXCEPTION_POINTERS;
1956 
1957 
1958 /*
1959  * The exception frame, used for registering exception handlers
1960  * Win32 cares only about this, but compilers generally emit
1961  * larger exception frames for their own use.
1962  */
1963 
1964 struct _EXCEPTION_REGISTRATION_RECORD;
1965 
1966 typedef DWORD (*PEXCEPTION_HANDLER)(PEXCEPTION_RECORD,struct _EXCEPTION_REGISTRATION_RECORD*,
1967                                     PCONTEXT,struct _EXCEPTION_REGISTRATION_RECORD **);
1968 
1969 typedef struct _EXCEPTION_REGISTRATION_RECORD
1970 {
1971   struct _EXCEPTION_REGISTRATION_RECORD *Prev;
1972   PEXCEPTION_HANDLER       Handler;
1973 } EXCEPTION_REGISTRATION_RECORD;
1974 
1975 /*
1976  * function pointer to an exception filter
1977  */
1978 
1979 typedef LONG (CALLBACK *PVECTORED_EXCEPTION_HANDLER)(PEXCEPTION_POINTERS ExceptionInfo);
1980 
1981 typedef struct _NT_TIB
1982 {
1983         struct _EXCEPTION_REGISTRATION_RECORD *ExceptionList;
1984         PVOID StackBase;
1985         PVOID StackLimit;
1986         PVOID SubSystemTib;
1987         union {
1988           PVOID FiberData;
1989           DWORD Version;
1990         } DUMMYUNIONNAME;
1991         PVOID ArbitraryUserPointer;
1992         struct _NT_TIB *Self;
1993 } NT_TIB, *PNT_TIB;
1994 
1995 struct _TEB;
1996 
1997 #if defined(__i386__) && defined(__GNUC__)
1998 extern inline struct _TEB * WINAPI NtCurrentTeb(void);
1999 extern inline struct _TEB * WINAPI NtCurrentTeb(void)
2000 {
2001     struct _TEB *teb;
2002     __asm__(".byte 0x64\n\tmovl (0x18),%0" : "=r" (teb));
2003     return teb;
2004 }
2005 #elif defined(__i386__) && defined(_MSC_VER)
2006 extern inline struct _TEB * WINAPI NtCurrentTeb(void)
2007 {
2008   struct _TEB *teb;
2009   __asm mov eax, fs:[0x18];
2010   __asm mov teb, eax;
2011   return teb;
2012 }
2013 #else
2014 extern struct _TEB * WINAPI NtCurrentTeb(void);
2015 #endif
2016 
2017 #ifdef NONAMELESSUNION
2018 #define GetCurrentFiber()  (((NT_TIB *)NtCurrentTeb())->u.FiberData)
2019 #else
2020 #define GetCurrentFiber()  (((NT_TIB *)NtCurrentTeb())->FiberData)
2021 #endif
2022 #define GetFiberData()     (*(void **)GetCurrentFiber())
2023 
2024 #define TLS_MINIMUM_AVAILABLE 64
2025 
2026 /*
2027  * File formats definitions
2028  */
2029 
2030 #include <pshpack2.h>
2031 typedef struct _IMAGE_DOS_HEADER {
2032     WORD  e_magic;      /* 00: MZ Header signature */
2033     WORD  e_cblp;       /* 02: Bytes on last page of file */
2034     WORD  e_cp;         /* 04: Pages in file */
2035     WORD  e_crlc;       /* 06: Relocations */
2036     WORD  e_cparhdr;    /* 08: Size of header in paragraphs */
2037     WORD  e_minalloc;   /* 0a: Minimum extra paragraphs needed */
2038     WORD  e_maxalloc;   /* 0c: Maximum extra paragraphs needed */
2039     WORD  e_ss;         /* 0e: Initial (relative) SS value */
2040     WORD  e_sp;         /* 10: Initial SP value */
2041     WORD  e_csum;       /* 12: Checksum */
2042     WORD  e_ip;         /* 14: Initial IP value */
2043     WORD  e_cs;         /* 16: Initial (relative) CS value */
2044     WORD  e_lfarlc;     /* 18: File address of relocation table */
2045     WORD  e_ovno;       /* 1a: Overlay number */
2046     WORD  e_res[4];     /* 1c: Reserved words */
2047     WORD  e_oemid;      /* 24: OEM identifier (for e_oeminfo) */
2048     WORD  e_oeminfo;    /* 26: OEM information; e_oemid specific */
2049     WORD  e_res2[10];   /* 28: Reserved words */
2050     DWORD e_lfanew;     /* 3c: Offset to extended header */
2051 } IMAGE_DOS_HEADER, *PIMAGE_DOS_HEADER;
2052 #include <poppack.h>
2053 
2054 #define IMAGE_DOS_SIGNATURE    0x5A4D     /* MZ   */
2055 #define IMAGE_OS2_SIGNATURE    0x454E     /* NE   */
2056 #define IMAGE_OS2_SIGNATURE_LE 0x454C     /* LE   */
2057 #define IMAGE_OS2_SIGNATURE_LX 0x584C     /* LX */
2058 #define IMAGE_VXD_SIGNATURE    0x454C     /* LE   */
2059 #define IMAGE_NT_SIGNATURE     0x00004550 /* PE00 */
2060 
2061 /*
2062  * This is the Windows executable (NE) header.
2063  * the name IMAGE_OS2_HEADER is misleading, but in the SDK this way.
2064  */
2065 #include <pshpack2.h>
2066 typedef struct
2067 {
2068     WORD  ne_magic;             /* 00 NE signature 'NE' */
2069     BYTE  ne_ver;               /* 02 Linker version number */
2070     BYTE  ne_rev;               /* 03 Linker revision number */
2071     WORD  ne_enttab;            /* 04 Offset to entry table relative to NE */
2072     WORD  ne_cbenttab;          /* 06 Length of entry table in bytes */
2073     LONG  ne_crc;               /* 08 Checksum */
2074     WORD  ne_flags;             /* 0c Flags about segments in this file */
2075     WORD  ne_autodata;          /* 0e Automatic data segment number */
2076     WORD  ne_heap;              /* 10 Initial size of local heap */
2077     WORD  ne_stack;             /* 12 Initial size of stack */
2078     DWORD ne_csip;              /* 14 Initial CS:IP */
2079     DWORD ne_sssp;              /* 18 Initial SS:SP */
2080     WORD  ne_cseg;              /* 1c # of entries in segment table */
2081     WORD  ne_cmod;              /* 1e # of entries in module reference tab. */
2082     WORD  ne_cbnrestab;         /* 20 Length of nonresident-name table     */
2083     WORD  ne_segtab;            /* 22 Offset to segment table */
2084     WORD  ne_rsrctab;           /* 24 Offset to resource table */
2085     WORD  ne_restab;            /* 26 Offset to resident-name table */
2086     WORD  ne_modtab;            /* 28 Offset to module reference table */
2087     WORD  ne_imptab;            /* 2a Offset to imported name table */
2088     DWORD ne_nrestab;           /* 2c Offset to nonresident-name table */
2089     WORD  ne_cmovent;           /* 30 # of movable entry points */
2090     WORD  ne_align;             /* 32 Logical sector alignment shift count */
2091     WORD  ne_cres;              /* 34 # of resource segments */
2092     BYTE  ne_exetyp;            /* 36 Flags indicating target OS */
2093     BYTE  ne_flagsothers;       /* 37 Additional information flags */
2094     WORD  ne_pretthunks;        /* 38 Offset to return thunks */
2095     WORD  ne_psegrefbytes;      /* 3a Offset to segment ref. bytes */
2096     WORD  ne_swaparea;          /* 3c Reserved by Microsoft */
2097     WORD  ne_expver;            /* 3e Expected Windows version number */
2098 } IMAGE_OS2_HEADER, *PIMAGE_OS2_HEADER;
2099 #include <poppack.h>
2100 
2101 #include <pshpack2.h>
2102 typedef struct _IMAGE_VXD_HEADER {
2103   WORD  e32_magic;
2104   BYTE  e32_border;
2105   BYTE  e32_worder;
2106   DWORD e32_level;
2107   WORD  e32_cpu;
2108   WORD  e32_os;
2109   DWORD e32_ver;
2110   DWORD e32_mflags;
2111   DWORD e32_mpages;
2112   DWORD e32_startobj;
2113   DWORD e32_eip;
2114   DWORD e32_stackobj;
2115   DWORD e32_esp;
2116   DWORD e32_pagesize;
2117   DWORD e32_lastpagesize;
2118   DWORD e32_fixupsize;
2119   DWORD e32_fixupsum;
2120   DWORD e32_ldrsize;
2121   DWORD e32_ldrsum;
2122   DWORD e32_objtab;
2123   DWORD e32_objcnt;
2124   DWORD e32_objmap;
2125   DWORD e32_itermap;
2126   DWORD e32_rsrctab;
2127   DWORD e32_rsrccnt;
2128   DWORD e32_restab;
2129   DWORD e32_enttab;
2130   DWORD e32_dirtab;
2131   DWORD e32_dircnt;
2132   DWORD e32_fpagetab;
2133   DWORD e32_frectab;
2134   DWORD e32_impmod;
2135   DWORD e32_impmodcnt;
2136   DWORD e32_impproc;
2137   DWORD e32_pagesum;
2138   DWORD e32_datapage;
2139   DWORD e32_preload;
2140   DWORD e32_nrestab;
2141   DWORD e32_cbnrestab;
2142   DWORD e32_nressum;
2143   DWORD e32_autodata;
2144   DWORD e32_debuginfo;
2145   DWORD e32_debuglen;
2146   DWORD e32_instpreload;
2147   DWORD e32_instdemand;
2148   DWORD e32_heapsize;
2149   BYTE  e32_res3[12];
2150   DWORD e32_winresoff;
2151   DWORD e32_winreslen;
2152   WORD  e32_devid;
2153   WORD  e32_ddkver;
2154 } IMAGE_VXD_HEADER, *PIMAGE_VXD_HEADER;
2155 #include <poppack.h>
2156 
2157 /* These defines describe the meanings of the bits in the Characteristics
2158    field */
2159 
2160 #define IMAGE_FILE_RELOCS_STRIPPED      0x0001 /* No relocation info */
2161 #define IMAGE_FILE_EXECUTABLE_IMAGE     0x0002
2162 #define IMAGE_FILE_LINE_NUMS_STRIPPED   0x0004
2163 #define IMAGE_FILE_LOCAL_SYMS_STRIPPED  0x0008
2164 #define IMAGE_FILE_AGGRESIVE_WS_TRIM    0x0010
2165 #define IMAGE_FILE_LARGE_ADDRESS_AWARE  0x0020
2166 #define IMAGE_FILE_16BIT_MACHINE        0x0040
2167 #define IMAGE_FILE_BYTES_REVERSED_LO    0x0080
2168 #define IMAGE_FILE_32BIT_MACHINE        0x0100
2169 #define IMAGE_FILE_DEBUG_STRIPPED       0x0200
2170 #define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP      0x0400
2171 #define IMAGE_FILE_NET_RUN_FROM_SWAP    0x0800
2172 #define IMAGE_FILE_SYSTEM               0x1000
2173 #define IMAGE_FILE_DLL                  0x2000
2174 #define IMAGE_FILE_UP_SYSTEM_ONLY       0x4000
2175 #define IMAGE_FILE_BYTES_REVERSED_HI    0x8000
2176 
2177 /* These are the settings of the Machine field. */
2178 #define IMAGE_FILE_MACHINE_UNKNOWN      0
2179 #define IMAGE_FILE_MACHINE_I860         0x014d
2180 #define IMAGE_FILE_MACHINE_I386         0x014c
2181 #define IMAGE_FILE_MACHINE_R3000        0x0162
2182 #define IMAGE_FILE_MACHINE_R4000        0x0166
2183 #define IMAGE_FILE_MACHINE_R10000       0x0168
2184 #define IMAGE_FILE_MACHINE_WCEMIPSV2    0x0169
2185 #define IMAGE_FILE_MACHINE_ALPHA        0x0184
2186 #define IMAGE_FILE_MACHINE_SH3          0x01a2
2187 #define IMAGE_FILE_MACHINE_SH3DSP       0x01a3
2188 #define IMAGE_FILE_MACHINE_SH3E         0x01a4
2189 #define IMAGE_FILE_MACHINE_SH4          0x01a6
2190 #define IMAGE_FILE_MACHINE_SH5          0x01a8
2191 #define IMAGE_FILE_MACHINE_ARM          0x01c0
2192 #define IMAGE_FILE_MACHINE_THUMB        0x01c2
2193 #define IMAGE_FILE_MACHINE_AM33         0x01d3
2194 #define IMAGE_FILE_MACHINE_POWERPC      0x01f0
2195 #define IMAGE_FILE_MACHINE_POWERPCFP    0x01f1
2196 #define IMAGE_FILE_MACHINE_IA64         0x0200
2197 #define IMAGE_FILE_MACHINE_MIPS16       0x0266
2198 #define IMAGE_FILE_MACHINE_ALPHA64      0x0284
2199 #define IMAGE_FILE_MACHINE_MIPSFPU      0x0366
2200 #define IMAGE_FILE_MACHINE_MIPSFPU16    0x0466
2201 #define IMAGE_FILE_MACHINE_AXP64        IMAGE_FILE_MACHINE_ALPHA64
2202 #define IMAGE_FILE_MACHINE_TRICORE      0x0520
2203 #define IMAGE_FILE_MACHINE_CEF          0x0cef
2204 #define IMAGE_FILE_MACHINE_EBC          0x0ebc
2205 #define IMAGE_FILE_MACHINE_AMD64        0x8664
2206 #define IMAGE_FILE_MACHINE_M32R         0x9041
2207 #define IMAGE_FILE_MACHINE_CEE          0xc0ee
2208 
2209 #define IMAGE_SIZEOF_FILE_HEADER                20
2210 #define IMAGE_SIZEOF_ROM_OPTIONAL_HEADER        56
2211 #define IMAGE_SIZEOF_STD_OPTIONAL_HEADER        28
2212 #define IMAGE_SIZEOF_NT_OPTIONAL32_HEADER       224
2213 #define IMAGE_SIZEOF_NT_OPTIONAL64_HEADER       240
2214 #define IMAGE_SIZEOF_SHORT_NAME                 8
2215 #define IMAGE_SIZEOF_SECTION_HEADER             40
2216 #define IMAGE_SIZEOF_SYMBOL                     18
2217 #define IMAGE_SIZEOF_AUX_SYMBOL                 18
2218 #define IMAGE_SIZEOF_RELOCATION                 10
2219 #define IMAGE_SIZEOF_BASE_RELOCATION            8
2220 #define IMAGE_SIZEOF_LINENUMBER                 6
2221 #define IMAGE_SIZEOF_ARCHIVE_MEMBER_HDR         60
2222 
2223 /* Possible Magic values */
2224 #define IMAGE_NT_OPTIONAL_HDR32_MAGIC      0x10b
2225 #define IMAGE_NT_OPTIONAL_HDR64_MAGIC      0x20b
2226 #define IMAGE_ROM_OPTIONAL_HDR_MAGIC       0x107
2227 
2228 #ifdef _WIN64
2229 #define IMAGE_SIZEOF_NT_OPTIONAL_HEADER IMAGE_SIZEOF_NT_OPTIONAL64_HEADER
2230 #define IMAGE_NT_OPTIONAL_HDR_MAGIC     IMAGE_NT_OPTIONAL_HDR64_MAGIC
2231 #else
2232 #define IMAGE_SIZEOF_NT_OPTIONAL_HEADER IMAGE_SIZEOF_NT_OPTIONAL32_HEADER
2233 #define IMAGE_NT_OPTIONAL_HDR_MAGIC     IMAGE_NT_OPTIONAL_HDR32_MAGIC
2234 #endif
2235 
2236 /* These are indexes into the DataDirectory array */
2237 #define IMAGE_FILE_EXPORT_DIRECTORY             0
2238 #define IMAGE_FILE_IMPORT_DIRECTORY             1
2239 #define IMAGE_FILE_RESOURCE_DIRECTORY           2
2240 #define IMAGE_FILE_EXCEPTION_DIRECTORY          3
2241 #define IMAGE_FILE_SECURITY_DIRECTORY           4
2242 #define IMAGE_FILE_BASE_RELOCATION_TABLE        5
2243 #define IMAGE_FILE_DEBUG_DIRECTORY              6
2244 #define IMAGE_FILE_DESCRIPTION_STRING           7
2245 #define IMAGE_FILE_MACHINE_VALUE                8  /* Mips */
2246 #define IMAGE_FILE_THREAD_LOCAL_STORAGE         9
2247 #define IMAGE_FILE_CALLBACK_DIRECTORY           10
2248 
2249 /* Directory Entries, indices into the DataDirectory array */
2250 
2251 #define IMAGE_DIRECTORY_ENTRY_EXPORT            0
2252 #define IMAGE_DIRECTORY_ENTRY_IMPORT            1
2253 #define IMAGE_DIRECTORY_ENTRY_RESOURCE          2
2254 #define IMAGE_DIRECTORY_ENTRY_EXCEPTION         3
2255 #define IMAGE_DIRECTORY_ENTRY_SECURITY          4
2256 #define IMAGE_DIRECTORY_ENTRY_BASERELOC         5
2257 #define IMAGE_DIRECTORY_ENTRY_DEBUG             6
2258 #define IMAGE_DIRECTORY_ENTRY_COPYRIGHT         7
2259 #define IMAGE_DIRECTORY_ENTRY_GLOBALPTR         8   /* (MIPS GP) */
2260 #define IMAGE_DIRECTORY_ENTRY_TLS               9
2261 #define IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG       10
2262 #define IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT      11
2263 #define IMAGE_DIRECTORY_ENTRY_IAT               12  /* Import Address Table */
2264 #define IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT      13
2265 #define IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR    14
2266 
2267 /* Subsystem Values */
2268 
2269 #define IMAGE_SUBSYSTEM_UNKNOWN                 0
2270 #define IMAGE_SUBSYSTEM_NATIVE                  1
2271 #define IMAGE_SUBSYSTEM_WINDOWS_GUI             2       /* Windows GUI subsystem */
2272 #define IMAGE_SUBSYSTEM_WINDOWS_CUI             3       /* Windows character subsystem */
2273 #define IMAGE_SUBSYSTEM_OS2_CUI                 5
2274 #define IMAGE_SUBSYSTEM_POSIX_CUI               7
2275 #define IMAGE_SUBSYSTEM_NATIVE_WINDOWS          8       /* native Win9x driver */
2276 #define IMAGE_SUBSYSTEM_WINDOWS_CE_GUI          9       /* Windows CE subsystem */
2277 #define IMAGE_SUBSYSTEM_EFI_APPLICATION         10
2278 #define IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER 11
2279 #define IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER      12
2280 #define IMAGE_SUBSYSTEM_EFI_ROM                 13
2281 #define IMAGE_SUBSYSTEM_XBOX                    14
2282 
2283 /* DLL Characteristics */
2284 #define IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE          0x0040
2285 #define IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY       0x0080
2286 #define IMAGE_DLLCHARACTERISTICS_NX_COMPAT             0x0100
2287 #define IMAGE_DLLCHARACTERISTICS_NO_ISOLATION          0x0200
2288 #define IMAGE_DLLCHARACTERISTICS_NO_SEH                0x0400
2289 #define IMAGE_DLLCHARACTERISTICS_NO_BIND               0x0800
2290 #define IMAGE_DLLCHARACTERISTICS_WDM_DRIVER            0x2000
2291 #define IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE 0x8000
2292 
2293 typedef struct _IMAGE_FILE_HEADER {
2294   WORD  Machine;
2295   WORD  NumberOfSections;
2296   DWORD TimeDateStamp;
2297   DWORD PointerToSymbolTable;
2298   DWORD NumberOfSymbols;
2299   WORD  SizeOfOptionalHeader;
2300   WORD  Characteristics;
2301 } IMAGE_FILE_HEADER, *PIMAGE_FILE_HEADER;
2302 
2303 typedef struct _IMAGE_DATA_DIRECTORY {
2304   DWORD VirtualAddress;
2305   DWORD Size;
2306 } IMAGE_DATA_DIRECTORY, *PIMAGE_DATA_DIRECTORY;
2307 
2308 #define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 16
2309 
2310 typedef struct _IMAGE_OPTIONAL_HEADER64 {
2311   WORD  Magic; /* 0x20b */
2312   BYTE MajorLinkerVersion;
2313   BYTE MinorLinkerVersion;
2314   DWORD SizeOfCode;
2315   DWORD SizeOfInitializedData;
2316   DWORD SizeOfUninitializedData;
2317   DWORD AddressOfEntryPoint;
2318   DWORD BaseOfCode;
2319   ULONGLONG ImageBase;
2320   DWORD SectionAlignment;
2321   DWORD FileAlignment;
2322   WORD MajorOperatingSystemVersion;
2323   WORD MinorOperatingSystemVersion;
2324   WORD MajorImageVersion;
2325   WORD MinorImageVersion;
2326   WORD MajorSubsystemVersion;
2327   WORD MinorSubsystemVersion;
2328   DWORD Win32VersionValue;
2329   DWORD SizeOfImage;
2330   DWORD SizeOfHeaders;
2331   DWORD CheckSum;
2332   WORD Subsystem;
2333   WORD DllCharacteristics;
2334   ULONGLONG SizeOfStackReserve;
2335   ULONGLONG SizeOfStackCommit;
2336   ULONGLONG SizeOfHeapReserve;
2337   ULONGLONG SizeOfHeapCommit;
2338   DWORD LoaderFlags;
2339   DWORD NumberOfRvaAndSizes;
2340   IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
2341 } IMAGE_OPTIONAL_HEADER64, *PIMAGE_OPTIONAL_HEADER64;
2342 
2343 typedef struct _IMAGE_NT_HEADERS64 {
2344   DWORD Signature;
2345   IMAGE_FILE_HEADER FileHeader;
2346   IMAGE_OPTIONAL_HEADER64 OptionalHeader;
2347 } IMAGE_NT_HEADERS64, *PIMAGE_NT_HEADERS64;
2348 
2349 typedef struct _IMAGE_OPTIONAL_HEADER {
2350 
2351   /* Standard fields */
2352 
2353   WORD  Magic; /* 0x10b or 0x107 */     /* 0x00 */
2354   BYTE  MajorLinkerVersion;
2355   BYTE  MinorLinkerVersion;
2356   DWORD SizeOfCode;
2357   DWORD SizeOfInitializedData;
2358   DWORD SizeOfUninitializedData;
2359   DWORD AddressOfEntryPoint;            /* 0x10 */
2360   DWORD BaseOfCode;
2361   DWORD BaseOfData;
2362 
2363   /* NT additional fields */
2364 
2365   DWORD ImageBase;
2366   DWORD SectionAlignment;               /* 0x20 */
2367   DWORD FileAlignment;
2368   WORD  MajorOperatingSystemVersion;
2369   WORD  MinorOperatingSystemVersion;
2370   WORD  MajorImageVersion;
2371   WORD  MinorImageVersion;
2372   WORD  MajorSubsystemVersion;          /* 0x30 */
2373   WORD  MinorSubsystemVersion;
2374   DWORD Win32VersionValue;
2375   DWORD SizeOfImage;
2376   DWORD SizeOfHeaders;
2377   DWORD CheckSum;                       /* 0x40 */
2378   WORD  Subsystem;
2379   WORD  DllCharacteristics;
2380   DWORD SizeOfStackReserve;
2381   DWORD SizeOfStackCommit;
2382   DWORD SizeOfHeapReserve;              /* 0x50 */
2383   DWORD SizeOfHeapCommit;
2384   DWORD LoaderFlags;
2385   DWORD NumberOfRvaAndSizes;
2386   IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; /* 0x60 */
2387   /* 0xE0 */
2388 } IMAGE_OPTIONAL_HEADER32, *PIMAGE_OPTIONAL_HEADER32;
2389 
2390 typedef struct _IMAGE_NT_HEADERS {
2391   DWORD Signature; /* "PE"\0\0 */       /* 0x00 */
2392   IMAGE_FILE_HEADER FileHeader;         /* 0x04 */
2393   IMAGE_OPTIONAL_HEADER32 OptionalHeader;       /* 0x18 */
2394 } IMAGE_NT_HEADERS32, *PIMAGE_NT_HEADERS32;
2395 
2396 #ifdef _WIN64
2397 typedef IMAGE_NT_HEADERS64  IMAGE_NT_HEADERS;
2398 typedef PIMAGE_NT_HEADERS64 PIMAGE_NT_HEADERS;
2399 typedef IMAGE_OPTIONAL_HEADER64 IMAGE_OPTIONAL_HEADER;
2400 typedef PIMAGE_OPTIONAL_HEADER64 PIMAGE_OPTIONAL_HEADER;
2401 #else
2402 typedef IMAGE_NT_HEADERS32  IMAGE_NT_HEADERS;
2403 typedef PIMAGE_NT_HEADERS32 PIMAGE_NT_HEADERS;
2404 typedef IMAGE_OPTIONAL_HEADER32 IMAGE_OPTIONAL_HEADER;
2405 typedef PIMAGE_OPTIONAL_HEADER32 PIMAGE_OPTIONAL_HEADER;
2406 #endif
2407 
2408 #define IMAGE_SIZEOF_SHORT_NAME 8
2409 
2410 typedef struct _IMAGE_SECTION_HEADER {
2411   BYTE  Name[IMAGE_SIZEOF_SHORT_NAME];
2412   union {
2413     DWORD PhysicalAddress;
2414     DWORD VirtualSize;
2415   } Misc;
2416   DWORD VirtualAddress;
2417   DWORD SizeOfRawData;
2418   DWORD PointerToRawData;
2419   DWORD PointerToRelocations;
2420   DWORD PointerToLinenumbers;
2421   WORD  NumberOfRelocations;
2422   WORD  NumberOfLinenumbers;
2423   DWORD Characteristics;
2424 } IMAGE_SECTION_HEADER, *PIMAGE_SECTION_HEADER;
2425 
2426 #define IMAGE_SIZEOF_SECTION_HEADER 40
2427 
2428 #define IMAGE_FIRST_SECTION(ntheader) \
2429   ((PIMAGE_SECTION_HEADER)(ULONG_PTR)((const BYTE *)&((const IMAGE_NT_HEADERS *)(ntheader))->OptionalHeader + \
2430                            ((const IMAGE_NT_HEADERS *)(ntheader))->FileHeader.SizeOfOptionalHeader))
2431 
2432 /* These defines are for the Characteristics bitfield. */
2433 /* #define IMAGE_SCN_TYPE_REG                   0x00000000 - Reserved */
2434 /* #define IMAGE_SCN_TYPE_DSECT                 0x00000001 - Reserved */
2435 /* #define IMAGE_SCN_TYPE_NOLOAD                0x00000002 - Reserved */
2436 /* #define IMAGE_SCN_TYPE_GROUP                 0x00000004 - Reserved */
2437 #define IMAGE_SCN_TYPE_NO_PAD                   0x00000008 /* Reserved */
2438 /* #define IMAGE_SCN_TYPE_COPY                  0x00000010 - Reserved */
2439 
2440 #define IMAGE_SCN_CNT_CODE                      0x00000020
2441 #define IMAGE_SCN_CNT_INITIALIZED_DATA          0x00000040
2442 #define IMAGE_SCN_CNT_UNINITIALIZED_DATA        0x00000080
2443 
2444 #define IMAGE_SCN_LNK_OTHER                     0x00000100
2445 #define IMAGE_SCN_LNK_INFO                      0x00000200
2446 /* #define      IMAGE_SCN_TYPE_OVER             0x00000400 - Reserved */
2447 #define IMAGE_SCN_LNK_REMOVE                    0x00000800
2448 #define IMAGE_SCN_LNK_COMDAT                    0x00001000
2449 
2450 /*                                              0x00002000 - Reserved */
2451 /* #define IMAGE_SCN_MEM_PROTECTED              0x00004000 - Obsolete */
2452 #define IMAGE_SCN_MEM_FARDATA                   0x00008000
2453 
2454 /* #define IMAGE_SCN_MEM_SYSHEAP                0x00010000 - Obsolete */
2455 #define IMAGE_SCN_MEM_PURGEABLE                 0x00020000
2456 #define IMAGE_SCN_MEM_16BIT                     0x00020000
2457 #define IMAGE_SCN_MEM_LOCKED                    0x00040000
2458 #define IMAGE_SCN_MEM_PRELOAD                   0x00080000
2459 
2460 #define IMAGE_SCN_ALIGN_1BYTES                  0x00100000
2461 #define IMAGE_SCN_ALIGN_2BYTES                  0x00200000
2462 #define IMAGE_SCN_ALIGN_4BYTES                  0x00300000
2463 #define IMAGE_SCN_ALIGN_8BYTES                  0x00400000
2464 #define IMAGE_SCN_ALIGN_16BYTES                 0x00500000  /* Default */
2465 #define IMAGE_SCN_ALIGN_32BYTES                 0x00600000
2466 #define IMAGE_SCN_ALIGN_64BYTES                 0x00700000
2467 #define IMAGE_SCN_ALIGN_128BYTES                0x00800000
2468 #define IMAGE_SCN_ALIGN_256BYTES                0x00900000
2469 #define IMAGE_SCN_ALIGN_512BYTES                0x00A00000
2470 #define IMAGE_SCN_ALIGN_1024BYTES               0x00B00000
2471 #define IMAGE_SCN_ALIGN_2048BYTES               0x00C00000
2472 #define IMAGE_SCN_ALIGN_4096BYTES               0x00D00000
2473 #define IMAGE_SCN_ALIGN_8192BYTES               0x00E00000
2474 /*                                              0x00F00000 - Unused */
2475 #define IMAGE_SCN_ALIGN_MASK                    0x00F00000
2476 
2477 #define IMAGE_SCN_LNK_NRELOC_OVFL               0x01000000
2478 
2479 
2480 #define IMAGE_SCN_MEM_DISCARDABLE               0x02000000
2481 #define IMAGE_SCN_MEM_NOT_CACHED                0x04000000
2482 #define IMAGE_SCN_MEM_NOT_PAGED                 0x08000000
2483 #define IMAGE_SCN_MEM_SHARED                    0x10000000
2484 #define IMAGE_SCN_MEM_EXECUTE                   0x20000000
2485 #define IMAGE_SCN_MEM_READ                      0x40000000
2486 #define IMAGE_SCN_MEM_WRITE                     0x80000000
2487 
2488 #include <pshpack2.h>
2489 
2490 typedef struct _IMAGE_SYMBOL {
2491     union {
2492         BYTE    ShortName[8];
2493         struct {
2494             DWORD   Short;
2495             DWORD   Long;
2496         } Name;
2497         DWORD   LongName[2];
2498     } N;
2499     DWORD   Value;
2500     SHORT   SectionNumber;
2501     WORD    Type;
2502     BYTE    StorageClass;
2503     BYTE    NumberOfAuxSymbols;
2504 } IMAGE_SYMBOL;
2505 typedef IMAGE_SYMBOL *PIMAGE_SYMBOL;
2506 
2507 #define IMAGE_SIZEOF_SYMBOL 18
2508 
2509 typedef struct _IMAGE_LINENUMBER {
2510     union {
2511         DWORD   SymbolTableIndex;
2512         DWORD   VirtualAddress;
2513     } Type;
2514     WORD    Linenumber;
2515 } IMAGE_LINENUMBER;
2516 typedef IMAGE_LINENUMBER *PIMAGE_LINENUMBER;
2517 
2518 #define IMAGE_SIZEOF_LINENUMBER  6
2519 
2520 typedef union _IMAGE_AUX_SYMBOL {
2521     struct {
2522         DWORD    TagIndex;
2523         union {
2524             struct {
2525                 WORD    Linenumber;
2526                 WORD    Size;
2527             } LnSz;
2528            DWORD    TotalSize;
2529         } Misc;
2530         union {
2531             struct {
2532                 DWORD    PointerToLinenumber;
2533                 DWORD    PointerToNextFunction;
2534             } Function;
2535             struct {
2536                 WORD     Dimension[4];
2537             } Array;
2538         } FcnAry;
2539         WORD    TvIndex;
2540     } Sym;
2541     struct {
2542         BYTE    Name[IMAGE_SIZEOF_SYMBOL];
2543     } File;
2544     struct {
2545         DWORD   Length;
2546         WORD    NumberOfRelocations;
2547         WORD    NumberOfLinenumbers;
2548         DWORD   CheckSum;
2549         SHORT   Number;
2550         BYTE    Selection;
2551     } Section;
2552 } IMAGE_AUX_SYMBOL;
2553 typedef IMAGE_AUX_SYMBOL *PIMAGE_AUX_SYMBOL;
2554 
2555 #define IMAGE_SIZEOF_AUX_SYMBOL 18
2556 
2557 #include <poppack.h>
2558 
2559 #define IMAGE_SYM_UNDEFINED           (SHORT)0
2560 #define IMAGE_SYM_ABSOLUTE            (SHORT)-1
2561 #define IMAGE_SYM_DEBUG               (SHORT)-2
2562 
2563 #define IMAGE_SYM_TYPE_NULL                 0x0000
2564 #define IMAGE_SYM_TYPE_VOID                 0x0001
2565 #define IMAGE_SYM_TYPE_CHAR                 0x0002
2566 #define IMAGE_SYM_TYPE_SHORT                0x0003
2567 #define IMAGE_SYM_TYPE_INT                  0x0004
2568 #define IMAGE_SYM_TYPE_LONG                 0x0005
2569 #define IMAGE_SYM_TYPE_FLOAT                0x0006
2570 #define IMAGE_SYM_TYPE_DOUBLE               0x0007
2571 #define IMAGE_SYM_TYPE_STRUCT               0x0008
2572 #define IMAGE_SYM_TYPE_UNION                0x0009
2573 #define IMAGE_SYM_TYPE_ENUM                 0x000A
2574 #define IMAGE_SYM_TYPE_MOE                  0x000B
2575 #define IMAGE_SYM_TYPE_BYTE                 0x000C
2576 #define IMAGE_SYM_TYPE_WORD                 0x000D
2577 #define IMAGE_SYM_TYPE_UINT                 0x000E
2578 #define IMAGE_SYM_TYPE_DWORD                0x000F
2579 #define IMAGE_SYM_TYPE_PCODE                0x8000
2580 
2581 #define IMAGE_SYM_DTYPE_NULL                0
2582 #define IMAGE_SYM_DTYPE_POINTER             1
2583 #define IMAGE_SYM_DTYPE_FUNCTION            2
2584 #define IMAGE_SYM_DTYPE_ARRAY               3
2585 
2586 #define IMAGE_SYM_CLASS_END_OF_FUNCTION     (BYTE )-1
2587 #define IMAGE_SYM_CLASS_NULL                0x0000
2588 #define IMAGE_SYM_CLASS_AUTOMATIC           0x0001
2589 #define IMAGE_SYM_CLASS_EXTERNAL            0x0002
2590 #define IMAGE_SYM_CLASS_STATIC              0x0003
2591 #define IMAGE_SYM_CLASS_REGISTER            0x0004
2592 #define IMAGE_SYM_CLASS_EXTERNAL_DEF        0x0005
2593 #define IMAGE_SYM_CLASS_LABEL               0x0006
2594 #define IMAGE_SYM_CLASS_UNDEFINED_LABEL     0x0007
2595 #define IMAGE_SYM_CLASS_MEMBER_OF_STRUCT    0x0008
2596 #define IMAGE_SYM_CLASS_ARGUMENT            0x0009
2597 #define IMAGE_SYM_CLASS_STRUCT_TAG          0x000A
2598 #define IMAGE_SYM_CLASS_MEMBER_OF_UNION     0x000B
2599 #define IMAGE_SYM_CLASS_UNION_TAG           0x000C
2600 #define IMAGE_SYM_CLASS_TYPE_DEFINITION     0x000D
2601 #define IMAGE_SYM_CLASS_UNDEFINED_STATIC    0x000E
2602 #define IMAGE_SYM_CLASS_ENUM_TAG            0x000F
2603 #define IMAGE_SYM_CLASS_MEMBER_OF_ENUM      0x0010
2604 #define IMAGE_SYM_CLASS_REGISTER_PARAM      0x0011
2605 #define IMAGE_SYM_CLASS_BIT_FIELD           0x0012
2606 
2607 #define IMAGE_SYM_CLASS_FAR_EXTERNAL        0x0044
2608 #define IMAGE_SYM_CLASS_BLOCK               0x0064
2609 #define IMAGE_SYM_CLASS_FUNCTION            0x0065
2610 #define IMAGE_SYM_CLASS_END_OF_STRUCT       0x0066
2611 #define IMAGE_SYM_CLASS_FILE                0x0067
2612 #define IMAGE_SYM_CLASS_SECTION             0x0068
2613 #define IMAGE_SYM_CLASS_WEAK_EXTERNAL       0x0069
2614 
2615 #define N_BTMASK                            0x000F
2616 #define N_TMASK                             0x0030
2617 #define N_TMASK1                            0x00C0
2618 #define N_TMASK2                            0x00F0
2619 #define N_BTSHFT                            4
2620 #define N_TSHIFT                            2
2621 
2622 #define BTYPE(x) ((x) & N_BTMASK)
2623 
2624 #ifndef ISPTR
2625 #define ISPTR(x) (((x) & N_TMASK) == (IMAGE_SYM_DTYPE_POINTER << N_BTSHFT))
2626 #endif
2627 
2628 #ifndef ISFCN
2629 #define ISFCN(x) (((x) & N_TMASK) == (IMAGE_SYM_DTYPE_FUNCTION << N_BTSHFT))
2630 #endif
2631 
2632 #ifndef ISARY
2633 #define ISARY(x) (((x) & N_TMASK) == (IMAGE_SYM_DTYPE_ARRAY << N_BTSHFT))
2634 #endif
2635 
2636 #ifndef ISTAG
2637 #define ISTAG(x) ((x)==IMAGE_SYM_CLASS_STRUCT_TAG || (x)==IMAGE_SYM_CLASS_UNION_TAG || (x)==IMAGE_SYM_CLASS_ENUM_TAG)
2638 #endif
2639 
2640 #ifndef INCREF
2641 #define INCREF(x) ((((x)&~N_BTMASK)<<N_TSHIFT)|(IMAGE_SYM_DTYPE_POINTER<<N_BTSHFT)|((x)&N_BTMASK))
2642 #endif
2643 #ifndef DECREF
2644 #define DECREF(x) ((((x)>>N_TSHIFT)&~N_BTMASK)|((x)&N_BTMASK))
2645 #endif
2646 
2647 #define IMAGE_COMDAT_SELECT_NODUPLICATES    1
2648 #define IMAGE_COMDAT_SELECT_ANY             2
2649 #define IMAGE_COMDAT_SELECT_SAME_SIZE       3
2650 #define IMAGE_COMDAT_SELECT_EXACT_MATCH     4
2651 #define IMAGE_COMDAT_SELECT_ASSOCIATIVE     5
2652 #define IMAGE_COMDAT_SELECT_LARGEST         6
2653 #define IMAGE_COMDAT_SELECT_NEWEST          7
2654 
2655 #define IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY  1
2656 #define IMAGE_WEAK_EXTERN_SEARCH_LIBRARY    2
2657 #define IMAGE_WEAK_EXTERN_SEARCH_ALIAS      3
2658 
2659 /* Export module directory */
2660 
2661 typedef struct _IMAGE_EXPORT_DIRECTORY {
2662         DWORD   Characteristics;
2663         DWORD   TimeDateStamp;
2664         WORD    MajorVersion;
2665         WORD    MinorVersion;
2666         DWORD   Name;
2667         DWORD   Base;
2668         DWORD   NumberOfFunctions;
2669         DWORD   NumberOfNames;
2670         DWORD   AddressOfFunctions;
2671         DWORD   AddressOfNames;
2672         DWORD   AddressOfNameOrdinals;
2673 } IMAGE_EXPORT_DIRECTORY,*PIMAGE_EXPORT_DIRECTORY;
2674 
2675 /* Import name entry */
2676 typedef struct _IMAGE_IMPORT_BY_NAME {
2677         WORD    Hint;
2678         BYTE    Name[1];
2679 } IMAGE_IMPORT_BY_NAME,*PIMAGE_IMPORT_BY_NAME;
2680 
2681 #include <pshpack8.h>
2682 /* Import thunk */
2683 typedef struct _IMAGE_THUNK_DATA64 {
2684         union {
2685                 ULONGLONG ForwarderString;
2686                 ULONGLONG Function;
2687                 ULONGLONG Ordinal;
2688                 ULONGLONG AddressOfData;
2689         } u1;
2690 } IMAGE_THUNK_DATA64,*PIMAGE_THUNK_DATA64;
2691 #include <poppack.h>
2692 
2693 typedef struct _IMAGE_THUNK_DATA32 {
2694         union {
2695                 DWORD ForwarderString;
2696                 DWORD Function;
2697                 DWORD Ordinal;
2698                 DWORD AddressOfData;
2699         } u1;
2700 } IMAGE_THUNK_DATA32,*PIMAGE_THUNK_DATA32;
2701 
2702 /* Import module directory */
2703 
2704 typedef struct _IMAGE_IMPORT_DESCRIPTOR {
2705         union {
2706                 DWORD   Characteristics; /* 0 for terminating null import descriptor  */
2707                 DWORD   OriginalFirstThunk;     /* RVA to original unbound IAT */
2708         } DUMMYUNIONNAME;
2709         DWORD   TimeDateStamp;  /* 0 if not bound,
2710                                  * -1 if bound, and real date\time stamp
2711                                  *    in IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT
2712                                  * (new BIND)
2713                                  * otherwise date/time stamp of DLL bound to
2714                                  * (Old BIND)
2715                                  */
2716         DWORD   ForwarderChain; /* -1 if no forwarders */
2717         DWORD   Name;
2718         /* RVA to IAT (if bound this IAT has actual addresses) */
2719         DWORD   FirstThunk;
2720 } IMAGE_IMPORT_DESCRIPTOR,*PIMAGE_IMPORT_DESCRIPTOR;
2721 
2722 #define IMAGE_ORDINAL_FLAG64             (((ULONGLONG)0x80000000 << 32) | 0x00000000)
2723 #define IMAGE_ORDINAL_FLAG32             0x80000000
2724 #define IMAGE_SNAP_BY_ORDINAL64(ordinal) (((ordinal) & IMAGE_ORDINAL_FLAG64) != 0)
2725 #define IMAGE_SNAP_BY_ORDINAL32(ordinal) (((ordinal) & IMAGE_ORDINAL_FLAG32) != 0)
2726 #define IMAGE_ORDINAL64(ordinal)         ((ordinal) & 0xffff)
2727 #define IMAGE_ORDINAL32(ordinal)         ((ordinal) & 0xffff)
2728 
2729 #ifdef _WIN64
2730 #define IMAGE_ORDINAL_FLAG              IMAGE_ORDINAL_FLAG64
2731 #define IMAGE_SNAP_BY_ORDINAL(Ordinal)  IMAGE_SNAP_BY_ORDINAL64(Ordinal)
2732 #define IMAGE_ORDINAL(Ordinal)          IMAGE_ORDINAL64(Ordinal)
2733 typedef IMAGE_THUNK_DATA64              IMAGE_THUNK_DATA;
2734 typedef PIMAGE_THUNK_DATA64             PIMAGE_THUNK_DATA;
2735 #else
2736 #define IMAGE_ORDINAL_FLAG              IMAGE_ORDINAL_FLAG32
2737 #define IMAGE_SNAP_BY_ORDINAL(Ordinal)  IMAGE_SNAP_BY_ORDINAL32(Ordinal)
2738 #define IMAGE_ORDINAL(Ordinal)          IMAGE_ORDINAL32(Ordinal)
2739 typedef IMAGE_THUNK_DATA32              IMAGE_THUNK_DATA;
2740 typedef PIMAGE_THUNK_DATA32             PIMAGE_THUNK_DATA;
2741 #endif
2742 
2743 typedef struct _IMAGE_BOUND_IMPORT_DESCRIPTOR
2744 {
2745     DWORD   TimeDateStamp;
2746     WORD    OffsetModuleName;
2747     WORD    NumberOfModuleForwarderRefs;
2748 /* Array of zero or more IMAGE_BOUND_FORWARDER_REF follows */
2749 } IMAGE_BOUND_IMPORT_DESCRIPTOR,  *PIMAGE_BOUND_IMPORT_DESCRIPTOR;
2750 
2751 typedef struct _IMAGE_BOUND_FORWARDER_REF
2752 {
2753     DWORD   TimeDateStamp;
2754     WORD    OffsetModuleName;
2755     WORD    Reserved;
2756 } IMAGE_BOUND_FORWARDER_REF, *PIMAGE_BOUND_FORWARDER_REF;
2757 
2758 typedef struct _IMAGE_BASE_RELOCATION
2759 {
2760         DWORD   VirtualAddress;
2761         DWORD   SizeOfBlock;
2762         /* WORD TypeOffset[1]; */
2763 } IMAGE_BASE_RELOCATION,*PIMAGE_BASE_RELOCATION;
2764 
2765 #include <pshpack2.h>
2766 
2767 typedef struct _IMAGE_RELOCATION
2768 {
2769     union {
2770         DWORD   VirtualAddress;
2771         DWORD   RelocCount;
2772     } DUMMYUNIONNAME;
2773     DWORD   SymbolTableIndex;
2774     WORD    Type;
2775 } IMAGE_RELOCATION, *PIMAGE_RELOCATION;
2776 
2777 #include <poppack.h>
2778 
2779 #define IMAGE_SIZEOF_RELOCATION 10
2780 
2781 /* generic relocation types */
2782 #define IMAGE_REL_BASED_ABSOLUTE                0
2783 #define IMAGE_REL_BASED_HIGH                    1
2784 #define IMAGE_REL_BASED_LOW                     2
2785 #define IMAGE_REL_BASED_HIGHLOW                 3
2786 #define IMAGE_REL_BASED_HIGHADJ                 4
2787 #define IMAGE_REL_BASED_MIPS_JMPADDR            5
2788 #define IMAGE_REL_BASED_SECTION                 6
2789 #define IMAGE_REL_BASED_REL                     7
2790 #define IMAGE_REL_BASED_MIPS_JMPADDR16          9
2791 #define IMAGE_REL_BASED_IA64_IMM64              9 /* yes, 9 too */
2792 #define IMAGE_REL_BASED_DIR64                   10
2793 #define IMAGE_REL_BASED_HIGH3ADJ                11
2794 
2795 /* I386 relocation types */
2796 #define IMAGE_REL_I386_ABSOLUTE                 0
2797 #define IMAGE_REL_I386_DIR16                    1
2798 #define IMAGE_REL_I386_REL16                    2
2799 #define IMAGE_REL_I386_DIR32                    6
2800 #define IMAGE_REL_I386_DIR32NB                  7
2801 #define IMAGE_REL_I386_SEG12                    9
2802 #define IMAGE_REL_I386_SECTION                  10
2803 #define IMAGE_REL_I386_SECREL                   11
2804 #define IMAGE_REL_I386_REL32                    20
2805 
2806 /* MIPS relocation types */
2807 #define IMAGE_REL_MIPS_ABSOLUTE         0x0000
2808 #define IMAGE_REL_MIPS_REFHALF          0x0001
2809 #define IMAGE_REL_MIPS_REFWORD          0x0002
2810 #define IMAGE_REL_MIPS_JMPADDR          0x0003
2811 #define IMAGE_REL_MIPS_REFHI            0x0004
2812 #define IMAGE_REL_MIPS_REFLO            0x0005
2813 #define IMAGE_REL_MIPS_GPREL            0x0006
2814 #define IMAGE_REL_MIPS_LITERAL          0x0007
2815 #define IMAGE_REL_MIPS_SECTION          0x000A
2816 #define IMAGE_REL_MIPS_SECREL           0x000B
2817 #define IMAGE_REL_MIPS_SECRELLO         0x000C
2818 #define IMAGE_REL_MIPS_SECRELHI         0x000D
2819 #define IMAGE_REL_MIPS_JMPADDR16        0x0010
2820 #define IMAGE_REL_MIPS_REFWORDNB        0x0022
2821 #define IMAGE_REL_MIPS_PAIR             0x0025
2822 
2823 /* ALPHA relocation types */
2824 #define IMAGE_REL_ALPHA_ABSOLUTE        0x0000
2825 #define IMAGE_REL_ALPHA_REFLONG         0x0001
2826 #define IMAGE_REL_ALPHA_REFQUAD         0x0002
2827 #define IMAGE_REL_ALPHA_GPREL           0x0003
2828 #define IMAGE_REL_ALPHA_LITERAL         0x0004
2829 #define IMAGE_REL_ALPHA_LITUSE          0x0005
2830 #define IMAGE_REL_ALPHA_GPDISP          0x0006
2831 #define IMAGE_REL_ALPHA_BRADDR          0x0007
2832 #define IMAGE_REL_ALPHA_HINT            0x0008
2833 #define IMAGE_REL_ALPHA_INLINE_REFLONG  0x0009
2834 #define IMAGE_REL_ALPHA_REFHI           0x000A
2835 #define IMAGE_REL_ALPHA_REFLO           0x000B
2836 #define IMAGE_REL_ALPHA_PAIR            0x000C
2837 #define IMAGE_REL_ALPHA_MATCH           0x000D
2838 #define IMAGE_REL_ALPHA_SECTION         0x000E
2839 #define IMAGE_REL_ALPHA_SECREL          0x000F
2840 #define IMAGE_REL_ALPHA_REFLONGNB       0x0010
2841 #define IMAGE_REL_ALPHA_SECRELLO        0x0011
2842 #define IMAGE_REL_ALPHA_SECRELHI        0x0012
2843 #define IMAGE_REL_ALPHA_REFQ3           0x0013
2844 #define IMAGE_REL_ALPHA_REFQ2           0x0014
2845 #define IMAGE_REL_ALPHA_REFQ1           0x0015
2846 #define IMAGE_REL_ALPHA_GPRELLO         0x0016
2847 #define IMAGE_REL_ALPHA_GPRELHI         0x0017
2848 
2849 /* PowerPC relocation types */
2850 #define IMAGE_REL_PPC_ABSOLUTE          0x0000
2851 #define IMAGE_REL_PPC_ADDR64            0x0001
2852 #define IMAGE_REL_PPC_ADDR            0x0002
2853 #define IMAGE_REL_PPC_ADDR24            0x0003
2854 #define IMAGE_REL_PPC_ADDR16            0x0004
2855 #define IMAGE_REL_PPC_ADDR14            0x0005
2856 #define IMAGE_REL_PPC_REL24             0x0006
2857 #define IMAGE_REL_PPC_REL14             0x0007
2858 #define IMAGE_REL_PPC_TOCREL16          0x0008
2859 #define IMAGE_REL_PPC_TOCREL14          0x0009
2860 #define IMAGE_REL_PPC_ADDR32NB          0x000A
2861 #define IMAGE_REL_PPC_SECREL            0x000B
2862 #define IMAGE_REL_PPC_SECTION           0x000C
2863 #define IMAGE_REL_PPC_IFGLUE            0x000D
2864 #define IMAGE_REL_PPC_IMGLUE            0x000E
2865 #define IMAGE_REL_PPC_SECREL16          0x000F
2866 #define IMAGE_REL_PPC_REFHI             0x0010
2867 #define IMAGE_REL_PPC_REFLO             0x0011
2868 #define IMAGE_REL_PPC_PAIR              0x0012
2869 #define IMAGE_REL_PPC_SECRELLO          0x0013
2870 #define IMAGE_REL_PPC_SECRELHI          0x0014
2871 #define IMAGE_REL_PPC_GPREL             0x0015
2872 #define IMAGE_REL_PPC_TYPEMASK          0x00FF
2873 /* modifier bits */
2874 #define IMAGE_REL_PPC_NEG               0x0100
2875 #define IMAGE_REL_PPC_BRTAKEN           0x0200
2876 #define IMAGE_REL_PPC_BRNTAKEN          0x0400
2877 #define IMAGE_REL_PPC_TOCDEFN           0x0800
2878 
2879 /* SH3 ? relocation type */
2880 #define IMAGE_REL_SH3_ABSOLUTE          0x0000
2881 #define IMAGE_REL_SH3_DIRECT16          0x0001
2882 #define IMAGE_REL_SH3_DIRECT          0x0002
2883 #define IMAGE_REL_SH3_DIRECT8           0x0003
2884 #define IMAGE_REL_SH3_DIRECT8_WORD      0x0004
2885 #define IMAGE_REL_SH3_DIRECT8_LONG      0x0005
2886 #define IMAGE_REL_SH3_DIRECT4           0x0006
2887 #define IMAGE_REL_SH3_DIRECT4_WORD      0x0007
2888 #define IMAGE_REL_SH3_DIRECT4_LONG      0x0008
2889 #define IMAGE_REL_SH3_PCREL8_WORD       0x0009
2890 #define IMAGE_REL_SH3_PCREL8_LONG       0x000A
2891 #define IMAGE_REL_SH3_PCREL12_WORD      0x000B
2892 #define IMAGE_REL_SH3_STARTOF_SECTION   0x000C
2893 #define IMAGE_REL_SH3_SIZEOF_SECTION    0x000D
2894 #define IMAGE_REL_SH3_SECTION           0x000E
2895 #define IMAGE_REL_SH3_SECREL            0x000F
2896 #define IMAGE_REL_SH3_DIRECT32_NB       0x0010
2897 
2898 /* ARM (Archimedes?) relocation types */
2899 #define IMAGE_REL_ARM_ABSOLUTE          0x0000
2900 #define IMAGE_REL_ARM_ADDR              0x0001
2901 #define IMAGE_REL_ARM_ADDR32NB          0x0002
2902 #define IMAGE_REL_ARM_BRANCH24          0x0003
2903 #define IMAGE_REL_ARM_BRANCH11          0x0004
2904 #define IMAGE_REL_ARM_SECTION           0x000E
2905 #define IMAGE_REL_ARM_SECREL            0x000F
2906 
2907 /* IA64 relocation types */
2908 #define IMAGE_REL_IA64_ABSOLUTE         0x0000
2909 #define IMAGE_REL_IA64_IMM14            0x0001
2910 #define IMAGE_REL_IA64_IMM22            0x0002
2911 #define IMAGE_REL_IA64_IMM64            0x0003
2912 #define IMAGE_REL_IA64_DIR              0x0004
2913 #define IMAGE_REL_IA64_DIR64            0x0005
2914 #define IMAGE_REL_IA64_PCREL21B         0x0006
2915 #define IMAGE_REL_IA64_PCREL21M         0x0007
2916 #define IMAGE_REL_IA64_PCREL21F         0x0008
2917 #define IMAGE_REL_IA64_GPREL22          0x0009
2918 #define IMAGE_REL_IA64_LTOFF22          0x000A
2919 #define IMAGE_REL_IA64_SECTION          0x000B
2920 #define IMAGE_REL_IA64_SECREL22         0x000C
2921 #define IMAGE_REL_IA64_SECREL64I        0x000D
2922 #define IMAGE_REL_IA64_SECREL           0x000E
2923 #define IMAGE_REL_IA64_LTOFF64          0x000F
2924 #define IMAGE_REL_IA64_DIR32NB          0x0010
2925 #define IMAGE_REL_IA64_RESERVED_11      0x0011
2926 #define IMAGE_REL_IA64_RESERVED_12      0x0012
2927 #define IMAGE_REL_IA64_RESERVED_13      0x0013
2928 #define IMAGE_REL_IA64_RESERVED_14      0x0014
2929 #define IMAGE_REL_IA64_RESERVED_15      0x0015
2930 #define IMAGE_REL_IA64_RESERVED_16      0x0016
2931 #define IMAGE_REL_IA64_ADDEND           0x001F
2932 
2933 /* AMD64 relocation types */
2934 #define IMAGE_REL_AMD64_ABSOLUTE        0x0000
2935 #define IMAGE_REL_AMD64_ADDR64          0x0001
2936 #define IMAGE_REL_AMD64_ADDR32          0x0002
2937 #define IMAGE_REL_AMD64_ADDR32NB        0x0003
2938 #define IMAGE_REL_AMD64_REL32           0x0004
2939 #define IMAGE_REL_AMD64_REL32_1         0x0005
2940 #define IMAGE_REL_AMD64_REL32_2         0x0006
2941 #define IMAGE_REL_AMD64_REL32_3         0x0007
2942 #define IMAGE_REL_AMD64_REL32_4         0x0008
2943 #define IMAGE_REL_AMD64_REL32_5         0x0009
2944 #define IMAGE_REL_AMD64_SECTION         0x000A
2945 #define IMAGE_REL_AMD64_SECREL          0x000B
2946 #define IMAGE_REL_AMD64_SECREL7         0x000C
2947 #define IMAGE_REL_AMD64_TOKEN           0x000D
2948 #define IMAGE_REL_AMD64_SREL32          0x000E
2949 #define IMAGE_REL_AMD64_PAIR            0x000F
2950 #define IMAGE_REL_AMD64_SSPAN32         0x0010
2951 
2952 /* archive format */
2953 
2954 #define IMAGE_ARCHIVE_START_SIZE             8
2955 #define IMAGE_ARCHIVE_START                  "!<arch>\n"
2956 #define IMAGE_ARCHIVE_END                    "`\n"
2957 #define IMAGE_ARCHIVE_PAD                    "\n"
2958 #define IMAGE_ARCHIVE_LINKER_MEMBER          "/               "
2959 #define IMAGE_ARCHIVE_LONGNAMES_MEMBER       "//              "
2960 
2961 typedef struct _IMAGE_ARCHIVE_MEMBER_HEADER
2962 {
2963     BYTE     Name[16];
2964     BYTE     Date[12];
2965     BYTE     UserID[6];
2966     BYTE     GroupID[6];
2967     BYTE     Mode[8];
2968     BYTE     Size[10];
2969     BYTE     EndHeader[2];
2970 } IMAGE_ARCHIVE_MEMBER_HEADER, *PIMAGE_ARCHIVE_MEMBER_HEADER;
2971 
2972 #define IMAGE_SIZEOF_ARCHIVE_MEMBER_HDR 60
2973 
2974 typedef struct _IMPORT_OBJECT_HEADER
2975 {
2976     WORD     Sig1;
2977     WORD     Sig2;
2978     WORD     Version;
2979     WORD     Machine;
2980     DWORD    TimeDateStamp;
2981     DWORD    SizeOfData;
2982     union
2983     {
2984         WORD Ordinal;
2985         WORD Hint;
2986     } DUMMYUNIONNAME;
2987     WORD     Type : 2;
2988     WORD     NameType : 3;
2989     WORD     Reserved : 11;
2990 } IMPORT_OBJECT_HEADER;
2991 
2992 #define IMPORT_OBJECT_HDR_SIG2  0xffff
2993 
2994 typedef enum IMPORT_OBJECT_TYPE
2995 {
2996     IMPORT_OBJECT_CODE = 0,
2997     IMPORT_OBJECT_DATA = 1,
2998     IMPORT_OBJECT_CONST = 2
2999 } IMPORT_OBJECT_TYPE;
3000 
3001 typedef enum IMPORT_OBJECT_NAME_TYPE
3002 {
3003     IMPORT_OBJECT_ORDINAL = 0,
3004     IMPORT_OBJECT_NAME = 1,
3005     IMPORT_OBJECT_NAME_NO_PREFIX = 2,
3006     IMPORT_OBJECT_NAME_UNDECORATE = 3
3007 } IMPORT_OBJECT_NAME_TYPE;
3008 
3009 typedef struct _ANON_OBJECT_HEADER
3010 {
3011     WORD     Sig1;
3012     WORD     Sig2;
3013     WORD     Version;
3014     WORD     Machine;
3015     DWORD    TimeDateStamp;
3016     CLSID    ClassID;
3017     DWORD    SizeOfData;
3018 } ANON_OBJECT_HEADER;
3019 
3020 /*
3021  * Resource directory stuff
3022  */
3023 typedef struct _IMAGE_RESOURCE_DIRECTORY {
3024         DWORD   Characteristics;
3025         DWORD   TimeDateStamp;
3026         WORD    MajorVersion;
3027         WORD    MinorVersion;
3028         WORD    NumberOfNamedEntries;
3029         WORD    NumberOfIdEntries;
3030         /*  IMAGE_RESOURCE_DIRECTORY_ENTRY DirectoryEntries[]; */
3031 } IMAGE_RESOURCE_DIRECTORY,*PIMAGE_RESOURCE_DIRECTORY;
3032 
3033 #define IMAGE_RESOURCE_NAME_IS_STRING           0x80000000
3034 #define IMAGE_RESOURCE_DATA_IS_DIRECTORY        0x80000000
3035 
3036 typedef struct _IMAGE_RESOURCE_DIRECTORY_ENTRY {
3037         union {
3038                 struct {
3039 #ifdef BITFIELDS_BIGENDIAN
3040                         unsigned NameIsString:1;
3041                         unsigned NameOffset:31;
3042 #else
3043                         unsigned NameOffset:31;
3044                         unsigned NameIsString:1;
3045 #endif
3046                 } DUMMYSTRUCTNAME1;
3047                 DWORD   Name;
3048                 struct {
3049 #ifdef WORDS_BIGENDIAN
3050                         WORD    __pad;
3051                         WORD    Id;
3052 #else
3053                         WORD    Id;
3054                         WORD    __pad;
3055 #endif
3056                 } DUMMYSTRUCTNAME2;
3057         } DUMMYUNIONNAME1;
3058         union {
3059                 DWORD   OffsetToData;
3060                 struct {
3061 #ifdef BITFIELDS_BIGENDIAN
3062                         unsigned DataIsDirectory:1;
3063                         unsigned OffsetToDirectory:31;
3064 #else
3065                         unsigned OffsetToDirectory:31;
3066                         unsigned DataIsDirectory:1;
3067 #endif
3068                 } DUMMYSTRUCTNAME3;
3069         } DUMMYUNIONNAME2;
3070 } IMAGE_RESOURCE_DIRECTORY_ENTRY,*PIMAGE_RESOURCE_DIRECTORY_ENTRY;
3071 
3072 
3073 typedef struct _IMAGE_RESOURCE_DIRECTORY_STRING {
3074         WORD    Length;
3075         CHAR    NameString[ 1 ];
3076 } IMAGE_RESOURCE_DIRECTORY_STRING,*PIMAGE_RESOURCE_DIRECTORY_STRING;
3077 
3078 typedef struct _IMAGE_RESOURCE_DIR_STRING_U {
3079         WORD    Length;
3080         WCHAR   NameString[ 1 ];
3081 } IMAGE_RESOURCE_DIR_STRING_U,*PIMAGE_RESOURCE_DIR_STRING_U;
3082 
3083 typedef struct _IMAGE_RESOURCE_DATA_ENTRY {
3084         DWORD   OffsetToData;
3085         DWORD   Size;
3086         DWORD   CodePage;
3087         DWORD   Reserved;
3088 } IMAGE_RESOURCE_DATA_ENTRY,*PIMAGE_RESOURCE_DATA_ENTRY;
3089 
3090 
3091 typedef VOID (CALLBACK *PIMAGE_TLS_CALLBACK)(
3092         LPVOID DllHandle,DWORD Reason,LPVOID Reserved
3093 );
3094 
3095 typedef struct _IMAGE_TLS_DIRECTORY64 {
3096     ULONGLONG   StartAddressOfRawData;
3097     ULONGLONG   EndAddressOfRawData;
3098     ULONGLONG   AddressOfIndex;
3099     ULONGLONG   AddressOfCallBacks;
3100     DWORD       SizeOfZeroFill;
3101     DWORD       Characteristics;
3102 } IMAGE_TLS_DIRECTORY64, *PIMAGE_TLS_DIRECTORY64;
3103 
3104 typedef struct _IMAGE_TLS_DIRECTORY32 {
3105     DWORD   StartAddressOfRawData;
3106     DWORD   EndAddressOfRawData;
3107     DWORD   AddressOfIndex;
3108     DWORD   AddressOfCallBacks;
3109     DWORD   SizeOfZeroFill;
3110     DWORD   Characteristics;
3111 } IMAGE_TLS_DIRECTORY32, *PIMAGE_TLS_DIRECTORY32;
3112 
3113 #ifdef _WIN64
3114 typedef IMAGE_TLS_DIRECTORY64           IMAGE_TLS_DIRECTORY;
3115 typedef PIMAGE_TLS_DIRECTORY64          PIMAGE_TLS_DIRECTORY;
3116 #else
3117 typedef IMAGE_TLS_DIRECTORY32           IMAGE_TLS_DIRECTORY;
3118 typedef PIMAGE_TLS_DIRECTORY32          PIMAGE_TLS_DIRECTORY;
3119 #endif
3120 
3121 typedef struct _IMAGE_DEBUG_DIRECTORY {
3122   DWORD Characteristics;
3123   DWORD TimeDateStamp;
3124   WORD  MajorVersion;
3125   WORD  MinorVersion;
3126   DWORD Type;
3127   DWORD SizeOfData;
3128   DWORD AddressOfRawData;
3129   DWORD PointerToRawData;
3130 } IMAGE_DEBUG_DIRECTORY, *PIMAGE_DEBUG_DIRECTORY;
3131 
3132 #define IMAGE_DEBUG_TYPE_UNKNOWN        0
3133 #define IMAGE_DEBUG_TYPE_COFF           1
3134 #define IMAGE_DEBUG_TYPE_CODEVIEW       2
3135 #define IMAGE_DEBUG_TYPE_FPO            3
3136 #define IMAGE_DEBUG_TYPE_MISC           4
3137 #define IMAGE_DEBUG_TYPE_EXCEPTION      5
3138 #define IMAGE_DEBUG_TYPE_FIXUP          6
3139 #define IMAGE_DEBUG_TYPE_OMAP_TO_SRC    7
3140 #define IMAGE_DEBUG_TYPE_OMAP_FROM_SRC  8
3141 #define IMAGE_DEBUG_TYPE_BORLAND        9
3142 #define IMAGE_DEBUG_TYPE_RESERVED10    10
3143 
3144 typedef enum ReplacesCorHdrNumericDefines
3145 {
3146     COMIMAGE_FLAGS_ILONLY           = 0x00000001,
3147     COMIMAGE_FLAGS_32BITREQUIRED    = 0x00000002,
3148     COMIMAGE_FLAGS_IL_LIBRARY       = 0x00000004,
3149     COMIMAGE_FLAGS_STRONGNAMESIGNED = 0x00000008,
3150     COMIMAGE_FLAGS_TRACKDEBUGDATA   = 0x00010000,
3151 
3152     COR_VERSION_MAJOR_V2       = 2,
3153     COR_VERSION_MAJOR          = COR_VERSION_MAJOR_V2,
3154     COR_VERSION_MINOR          = 0,
3155     COR_DELETED_NAME_LENGTH    = 8,
3156     COR_VTABLEGAP_NAME_LENGTH  = 8,
3157 
3158     NATIVE_TYPE_MAX_CB = 1,
3159     COR_ILMETHOD_SECT_SMALL_MAX_DATASIZE = 0xff,
3160 
3161     IMAGE_COR_MIH_METHODRVA  = 0x01,
3162     IMAGE_COR_MIH_EHRVA      = 0x02,
3163     IMAGE_COR_MIH_BASICBLOCK = 0x08,
3164 
3165     COR_VTABLE_32BIT             = 0x01,
3166     COR_VTABLE_64BIT             = 0x02,
3167     COR_VTABLE_FROM_UNMANAGED    = 0x04,
3168     COR_VTABLE_CALL_MOST_DERIVED = 0x10,
3169 
3170     IMAGE_COR_EATJ_THUNK_SIZE = 32,
3171 
3172     MAX_CLASS_NAME   = 1024,
3173     MAX_PACKAGE_NAME = 1024,
3174 } ReplacesCorHdrNumericDefines;
3175 
3176 typedef struct IMAGE_COR20_HEADER
3177 {
3178     DWORD cb;
3179     WORD  MajorRuntimeVersion;
3180     WORD  MinorRuntimeVersion;
3181 
3182     IMAGE_DATA_DIRECTORY MetaData;
3183     DWORD Flags;
3184     DWORD EntryPointToken;
3185 
3186     IMAGE_DATA_DIRECTORY Resources;
3187     IMAGE_DATA_DIRECTORY StrongNameSignature;
3188     IMAGE_DATA_DIRECTORY CodeManagerTable;
3189     IMAGE_DATA_DIRECTORY VTableFixups;
3190     IMAGE_DATA_DIRECTORY ExportAddressTableJumps;
3191     IMAGE_DATA_DIRECTORY ManagedNativeHeader;
3192 
3193 } IMAGE_COR20_HEADER, *PIMAGE_COR20_HEADER;
3194 
3195 typedef struct _IMAGE_COFF_SYMBOLS_HEADER {
3196   DWORD NumberOfSymbols;
3197   DWORD LvaToFirstSymbol;
3198   DWORD NumberOfLinenumbers;
3199   DWORD LvaToFirstLinenumber;
3200   DWORD RvaToFirstByteOfCode;
3201   DWORD RvaToLastByteOfCode;
3202   DWORD RvaToFirstByteOfData;
3203   DWORD RvaToLastByteOfData;
3204 } IMAGE_COFF_SYMBOLS_HEADER, *PIMAGE_COFF_SYMBOLS_HEADER;
3205 
3206 #define FRAME_FPO       0
3207 #define FRAME_TRAP      1
3208 #define FRAME_TSS       2
3209 #define FRAME_NONFPO    3
3210 
3211 typedef struct _FPO_DATA {
3212   DWORD ulOffStart;
3213   DWORD cbProcSize;
3214   DWORD cdwLocals;
3215   WORD  cdwParams;
3216   WORD  cbProlog : 8;
3217   WORD  cbRegs   : 3;
3218   WORD  fHasSEH  : 1;
3219   WORD  fUseBP   : 1;
3220   WORD  reserved : 1;
3221   WORD  cbFrame  : 2;
3222 } FPO_DATA, *PFPO_DATA;
3223 
3224 typedef struct _IMAGE_LOAD_CONFIG_DIRECTORY {
3225   DWORD Size;
3226   DWORD TimeDateStamp;
3227   WORD  MajorVersion;
3228   WORD  MinorVersion;
3229   DWORD GlobalFlagsClear;
3230   DWORD GlobalFlagsSet;
3231   DWORD CriticalSectionDefaultTimeout;
3232   DWORD DeCommitFreeBlockThreshold;
3233   DWORD DeCommitTotalFreeThreshold;
3234   PVOID LockPrefixTable;
3235   DWORD MaximumAllocationSize;
3236   DWORD VirtualMemoryThreshold;
3237   DWORD ProcessHeapFlags;
3238   DWORD ProcessAffinityMask;
3239   WORD  CSDVersion;
3240   WORD  Reserved1;
3241   PVOID EditList;
3242   DWORD SecurityCookie;
3243   DWORD SEHandlerTable;
3244   DWORD SEHandlerCount;
3245 } IMAGE_LOAD_CONFIG_DIRECTORY, *PIMAGE_LOAD_CONFIG_DIRECTORY;
3246 
3247 typedef struct _IMAGE_FUNCTION_ENTRY {
3248   DWORD StartingAddress;
3249   DWORD EndingAddress;
3250   DWORD EndOfPrologue;
3251 } IMAGE_FUNCTION_ENTRY, *PIMAGE_FUNCTION_ENTRY;
3252 
3253 #define IMAGE_DEBUG_MISC_EXENAME    1
3254 
3255 typedef struct _IMAGE_DEBUG_MISC {
3256     DWORD       DataType;
3257     DWORD       Length;
3258     BYTE        Unicode;
3259     BYTE        Reserved[ 3 ];
3260     BYTE        Data[ 1 ];
3261 } IMAGE_DEBUG_MISC, *PIMAGE_DEBUG_MISC;
3262 
3263 /* This is the structure that appears at the very start of a .DBG file. */
3264 
3265 typedef struct _IMAGE_SEPARATE_DEBUG_HEADER {
3266         WORD    Signature;
3267         WORD    Flags;
3268         WORD    Machine;
3269         WORD    Characteristics;
3270         DWORD   TimeDateStamp;
3271         DWORD   CheckSum;
3272         DWORD   ImageBase;
3273         DWORD   SizeOfImage;
3274         DWORD   NumberOfSections;
3275         DWORD   ExportedNamesSize;
3276         DWORD   DebugDirectorySize;
3277         DWORD   SectionAlignment;
3278         DWORD   Reserved[ 2 ];
3279 } IMAGE_SEPARATE_DEBUG_HEADER,*PIMAGE_SEPARATE_DEBUG_HEADER;
3280 
3281 #define IMAGE_SEPARATE_DEBUG_SIGNATURE 0x4944
3282 
3283 
3284 typedef struct tagMESSAGE_RESOURCE_ENTRY {
3285         WORD    Length;
3286         WORD    Flags;
3287         BYTE    Text[1];
3288 } MESSAGE_RESOURCE_ENTRY,*PMESSAGE_RESOURCE_ENTRY;
3289 #define MESSAGE_RESOURCE_UNICODE        0x0001
3290 
3291 typedef struct tagMESSAGE_RESOURCE_BLOCK {
3292         DWORD   LowId;
3293         DWORD   HighId;
3294         DWORD   OffsetToEntries;
3295 } MESSAGE_RESOURCE_BLOCK,*PMESSAGE_RESOURCE_BLOCK;
3296 
3297 typedef struct tagMESSAGE_RESOURCE_DATA {
3298         DWORD                   NumberOfBlocks;
3299         MESSAGE_RESOURCE_BLOCK  Blocks[ 1 ];
3300 } MESSAGE_RESOURCE_DATA,*PMESSAGE_RESOURCE_DATA;
3301 
3302 /*
3303  * Here follows typedefs for security and tokens.
3304  */
3305 
3306 /*
3307  * First a constant for the following typedefs.
3308  */
3309 
3310 #define ANYSIZE_ARRAY   1
3311 
3312 /* FIXME:  Orphan.  What does it point to? */
3313 typedef PVOID PACCESS_TOKEN;
3314 typedef PVOID PSECURITY_DESCRIPTOR;
3315 typedef PVOID PSID;
3316 
3317 /*
3318  * TOKEN_INFORMATION_CLASS
3319  */
3320 
3321 typedef enum _TOKEN_INFORMATION_CLASS {
3322   TokenUser = 1,
3323   TokenGroups,
3324   TokenPrivileges,
3325   TokenOwner,
3326   TokenPrimaryGroup,
3327   TokenDefaultDacl,
3328   TokenSource,
3329   TokenType,
3330   TokenImpersonationLevel,
3331   TokenStatistics,
3332   TokenRestrictedSids,
3333   TokenSessionId,
3334   TokenGroupsAndPrivileges,
3335   TokenSessionReference,
3336   TokenSandBoxInert
3337 } TOKEN_INFORMATION_CLASS;
3338 
3339 #define TOKEN_TOKEN_ADJUST_DEFAULT   0x0080
3340 #define TOKEN_ADJUST_GROUPS          0x0040
3341 #define TOKEN_ADJUST_PRIVILEGES      0x0020
3342 #define TOKEN_ADJUST_SESSIONID       0x0100
3343 #define TOKEN_ASSIGN_PRIMARY         0x0001
3344 #define TOKEN_DUPLICATE              0x0002
3345 #define TOKEN_EXECUTE                STANDARD_RIGHTS_EXECUTE
3346 #define TOKEN_IMPERSONATE            0x0004
3347 #define TOKEN_QUERY                  0x0008
3348 #define TOKEN_QUERY_SOURCE           0x0010
3349 #define TOKEN_ADJUST_DEFAULT         0x0080
3350 #define TOKEN_READ                   (STANDARD_RIGHTS_READ|TOKEN_QUERY)
3351 #define TOKEN_WRITE                  (STANDARD_RIGHTS_WRITE     | \
3352                                         TOKEN_ADJUST_PRIVILEGES | \
3353                                         TOKEN_ADJUST_GROUPS | \
3354                                         TOKEN_ADJUST_DEFAULT )
3355 #define TOKEN_ALL_ACCESS             (STANDARD_RIGHTS_REQUIRED | \
3356                                         TOKEN_ASSIGN_PRIMARY | \
3357                                         TOKEN_DUPLICATE | \
3358                                         TOKEN_IMPERSONATE | \
3359                                         TOKEN_QUERY | \
3360                                         TOKEN_QUERY_SOURCE | \
3361                                         TOKEN_ADJUST_PRIVILEGES | \
3362                                         TOKEN_ADJUST_GROUPS | \
3363                                         TOKEN_ADJUST_SESSIONID | \
3364                                         TOKEN_ADJUST_DEFAULT )
3365 
3366 #ifndef _SECURITY_DEFINED
3367 #define _SECURITY_DEFINED
3368 
3369 
3370 typedef DWORD ACCESS_MASK, *PACCESS_MASK;
3371 
3372 typedef struct _GENERIC_MAPPING {
3373     ACCESS_MASK GenericRead;
3374     ACCESS_MASK GenericWrite;
3375     ACCESS_MASK GenericExecute;
3376     ACCESS_MASK GenericAll;
3377 } GENERIC_MAPPING, *PGENERIC_MAPPING;
3378 
3379 #ifndef SID_IDENTIFIER_AUTHORITY_DEFINED
3380 #define SID_IDENTIFIER_AUTHORITY_DEFINED
3381 typedef struct {
3382     BYTE Value[6];
3383 } SID_IDENTIFIER_AUTHORITY, *PSID_IDENTIFIER_AUTHORITY;
3384 #endif /* !defined(SID_IDENTIFIER_AUTHORITY_DEFINED) */
3385 
3386 #ifndef SID_DEFINED
3387 #define SID_DEFINED
3388 typedef struct _SID {
3389     BYTE Revision;
3390     BYTE SubAuthorityCount;
3391     SID_IDENTIFIER_AUTHORITY IdentifierAuthority;
3392     DWORD SubAuthority[1];
3393 } SID,*PISID;
3394 #endif /* !defined(SID_DEFINED) */
3395 
3396 #define SID_REVISION                    (1)     /* Current revision */
3397 #define SID_MAX_SUB_AUTHORITIES         (15)    /* current max subauths */
3398 #define SID_RECOMMENDED_SUB_AUTHORITIES (1)     /* recommended subauths */
3399 
3400 #define SECURITY_MAX_SID_SIZE (sizeof(SID) - sizeof(DWORD) + (SID_MAX_SUB_AUTHORITIES * sizeof(DWORD)))
3401 
3402 /*
3403  * ACL
3404  */
3405 
3406 #define ACL_REVISION1 1
3407 #define ACL_REVISION2 2
3408 #define ACL_REVISION3 3
3409 #define ACL_REVISION4 4
3410 
3411 #define MIN_ACL_REVISION ACL_REVISION2
3412 #define MAX_ACL_REVISION ACL_REVISION4
3413 
3414 #define ACL_REVISION 2
3415 
3416 typedef struct _ACL {
3417     BYTE AclRevision;
3418     BYTE Sbz1;
3419     WORD AclSize;
3420     WORD AceCount;
3421     WORD Sbz2;
3422 } ACL, *PACL;
3423 
3424 typedef enum _ACL_INFORMATION_CLASS
3425 {
3426   AclRevisionInformation = 1, 
3427   AclSizeInformation
3428 } ACL_INFORMATION_CLASS;
3429 
3430 typedef struct _ACL_REVISION_INFORMATION
3431 {
3432     DWORD AclRevision;
3433 } ACL_REVISION_INFORMATION, *PACL_REVISION_INFORMATION;
3434 
3435 typedef struct _ACL_SIZE_INFORMATION
3436 {
3437     DWORD AceCount;
3438     DWORD AclBytesInUse;
3439     DWORD AclBytesFree;
3440 } ACL_SIZE_INFORMATION, *PACL_SIZE_INFORMATION;
3441 
3442 /* SECURITY_DESCRIPTOR */
3443 #define SECURITY_DESCRIPTOR_REVISION    1
3444 #define SECURITY_DESCRIPTOR_REVISION1   1
3445 
3446 
3447 /*
3448  * Privilege Names
3449  */
3450 #define SE_CREATE_TOKEN_NAME            TEXT("SeCreateTokenPrivilege")
3451 #define SE_ASSIGNPRIMARYTOKEN_NAME      TEXT("SeAssignPrimaryTokenPrivilege")
3452 #define SE_LOCK_MEMORY_NAME             TEXT("SeLockMemoryPrivilege")
3453 #define SE_INCREASE_QUOTA_NAME          TEXT("SeIncreaseQuotaPrivilege")
3454 #define SE_UNSOLICITED_INPUT_NAME       TEXT("SeUnsolicitedInputPrivilege")
3455 #define SE_MACHINE_ACCOUNT_NAME         TEXT("SeMachineAccountPrivilege")
3456 #define SE_TCB_NAME                     TEXT("SeTcbPrivilege")
3457 #define SE_SECURITY_NAME                TEXT("SeSecurityPrivilege")
3458 #define SE_TAKE_OWNERSHIP_NAME          TEXT("SeTakeOwnershipPrivilege")
3459 #define SE_LOAD_DRIVER_NAME             TEXT("SeLoadDriverPrivilege")
3460 #define SE_SYSTEM_PROFILE_NAME          TEXT("SeSystemProfilePrivilege")
3461 #define SE_SYSTEMTIME_NAME              TEXT("SeSystemtimePrivilege")
3462 #define SE_PROF_SINGLE_PROCESS_NAME     TEXT("SeProfileSingleProcessPrivilege")
3463 #define SE_INC_BASE_PRIORITY_NAME       TEXT("SeIncreaseBasePriorityPrivilege")
3464 #define SE_CREATE_PAGEFILE_NAME         TEXT("SeCreatePagefilePrivilege")
3465 #define SE_CREATE_PERMANENT_NAME        TEXT("SeCreatePermanentPrivilege")
3466 #define SE_BACKUP_NAME                  TEXT("SeBackupPrivilege")
3467 #define SE_RESTORE_NAME                 TEXT("SeRestorePrivilege")
3468 #define SE_SHUTDOWN_NAME                TEXT("SeShutdownPrivilege")
3469 #define SE_DEBUG_NAME                   TEXT("SeDebugPrivilege")
3470 #define SE_AUDIT_NAME                   TEXT("SeAuditPrivilege")
3471 #define SE_SYSTEM_ENVIRONMENT_NAME      TEXT("SeSystemEnvironmentPrivilege")
3472 #define SE_CHANGE_NOTIFY_NAME           TEXT("SeChangeNotifyPrivilege")
3473 #define SE_REMOTE_SHUTDOWN_NAME         TEXT("SeRemoteShutdownPrivilege")
3474 #define SE_UNDOCK_NAME                  TEXT("SeUndockPrivilege")
3475 #define SE_ENABLE_DELEGATION_NAME       TEXT("SeEnableDelegationPrivilege")
3476 #define SE_MANAGE_VOLUME_NAME           TEXT("SeManageVolumePrivilege")
3477 #define SE_IMPERSONATE_NAME             TEXT("SeImpersonatePrivilege")
3478 #define SE_CREATE_GLOBAL_NAME           TEXT("SeCreateGlobalPrivilege")
3479 
3480 #define SE_GROUP_MANDATORY              0x00000001
3481 #define SE_GROUP_ENABLED_BY_DEFAULT     0x00000002
3482 #define SE_GROUP_ENABLED                0x00000004
3483 #define SE_GROUP_OWNER                  0x00000008
3484 #define SE_GROUP_USE_FOR_DENY_ONLY      0x00000010
3485 #define SE_GROUP_LOGON_ID               0xC0000000
3486 #define SE_GROUP_RESOURCE               0x20000000
3487 
3488 #define SE_PRIVILEGE_ENABLED_BY_DEFAULT 0x00000001
3489 #define SE_PRIVILEGE_ENABLED            0x00000002
3490 #define SE_PRIVILEGE_REMOVE             0x00000004
3491 #define SE_PRIVILEGE_USED_FOR_ACCESS    0x80000000
3492 
3493 #define PRIVILEGE_SET_ALL_NECESSARY     1
3494 
3495 #define SE_OWNER_DEFAULTED              0x00000001
3496 #define SE_GROUP_DEFAULTED              0x00000002
3497 #define SE_DACL_PRESENT                 0x00000004
3498 #define SE_DACL_DEFAULTED               0x00000008
3499 #define SE_SACL_PRESENT                 0x00000010
3500 #define SE_SACL_DEFAULTED               0x00000020
3501 #define SE_DACL_AUTO_INHERIT_REQ        0x00000100
3502 #define SE_SACL_AUTO_INHERIT_REQ        0x00000200
3503 #define SE_DACL_AUTO_INHERITED          0x00000400
3504 #define SE_SACL_AUTO_INHERITED          0x00000800
3505 #define SE_DACL_PROTECTED               0x00001000
3506 #define SE_SACL_PROTECTED               0x00002000
3507 #define SE_RM_CONTROL_VALID             0x00004000
3508 #define SE_SELF_RELATIVE                0x00008000
3509 
3510 typedef DWORD SECURITY_INFORMATION, *PSECURITY_INFORMATION;
3511 typedef WORD SECURITY_DESCRIPTOR_CONTROL, *PSECURITY_DESCRIPTOR_CONTROL;
3512 
3513 /* The security descriptor structure */
3514 typedef struct {
3515     BYTE Revision;
3516     BYTE Sbz1;
3517     SECURITY_DESCRIPTOR_CONTROL Control;
3518     DWORD Owner;
3519     DWORD Group;
3520     DWORD Sacl;
3521     DWORD Dacl;
3522 } SECURITY_DESCRIPTOR_RELATIVE, *PISECURITY_DESCRIPTOR_RELATIVE;
3523 
3524 typedef struct {
3525     BYTE Revision;
3526     BYTE Sbz1;
3527     SECURITY_DESCRIPTOR_CONTROL Control;
3528     PSID Owner;
3529     PSID Group;
3530     PACL Sacl;
3531     PACL Dacl;
3532 } SECURITY_DESCRIPTOR, *PISECURITY_DESCRIPTOR;
3533 
3534 #define SECURITY_DESCRIPTOR_MIN_LENGTH   (sizeof(SECURITY_DESCRIPTOR))
3535 
3536 #endif /* _SECURITY_DEFINED */
3537 
3538 /*
3539  * SID_AND_ATTRIBUTES
3540  */
3541 
3542 typedef struct _SID_AND_ATTRIBUTES {
3543   PSID  Sid;
3544   DWORD Attributes;
3545 } SID_AND_ATTRIBUTES, *PSID_AND_ATTRIBUTES;
3546 
3547 /* security entities */
3548 #define SECURITY_NULL_RID                       (0x00000000L)
3549 #define SECURITY_WORLD_RID                      (0x00000000L)
3550 #define SECURITY_LOCAL_RID                      (0X00000000L)
3551 
3552 #define SECURITY_NULL_SID_AUTHORITY             {0,0,0,0,0,0}
3553 
3554 /* S-1-1 */
3555 #define SECURITY_WORLD_SID_AUTHORITY            {0,0,0,0,0,1}
3556 
3557 /* S-1-2 */
3558 #define SECURITY_LOCAL_SID_AUTHORITY            {0,0,0,0,0,2}
3559 
3560 /* S-1-3 */
3561 #define SECURITY_CREATOR_SID_AUTHORITY          {0,0,0,0,0,3}
3562 #define SECURITY_CREATOR_OWNER_RID              (0x00000000L)
3563 #define SECURITY_CREATOR_GROUP_RID              (0x00000001L)
3564 #define SECURITY_CREATOR_OWNER_SERVER_RID       (0x00000002L)
3565 #define SECURITY_CREATOR_GROUP_SERVER_RID       (0x00000003L)
3566 
3567 /* S-1-4 */
3568 #define SECURITY_NON_UNIQUE_AUTHORITY           {0,0,0,0,0,4}
3569 
3570 /* S-1-5 */
3571 #define SECURITY_NT_AUTHORITY                   {0,0,0,0,0,5}
3572 #define SECURITY_DIALUP_RID                     0x00000001L
3573 #define SECURITY_NETWORK_RID                    0x00000002L
3574 #define SECURITY_BATCH_RID                      0x00000003L
3575 #define SECURITY_INTERACTIVE_RID                0x00000004L
3576 #define SECURITY_LOGON_IDS_RID                  0x00000005L
3577 #define SECURITY_SERVICE_RID                    0x00000006L
3578 #define SECURITY_ANONYMOUS_LOGON_RID            0x00000007L
3579 #define SECURITY_PROXY_RID                      0x00000008L
3580 #define SECURITY_ENTERPRISE_CONTROLLERS_RID     0x00000009L
3581 #define SECURITY_SERVER_LOGON_RID               SECURITY_ENTERPRISE_CONTROLLERS_RID
3582 #define SECURITY_PRINCIPAL_SELF_RID             0x0000000AL
3583 #define SECURITY_AUTHENTICATED_USER_RID         0x0000000BL
3584 #define SECURITY_RESTRICTED_CODE_RID            0x0000000CL
3585 #define SECURITY_TERMINAL_SERVER_RID            0x0000000DL
3586 #define SECURITY_REMOTE_LOGON_RID               0x0000000EL
3587 #define SECURITY_THIS_ORGANIZATION_RID          0x0000000FL
3588 #define SECURITY_LOCAL_SYSTEM_RID               0x00000012L
3589 #define SECURITY_LOCAL_SERVICE_RID              0x00000013L
3590 #define SECURITY_NETWORK_SERVICE_RID            0x00000014L
3591 #define SECURITY_NT_NON_UNIQUE                  0x00000015L
3592 #define SECURITY_BUILTIN_DOMAIN_RID             0x00000020L
3593 
3594 #define SECURITY_PACKAGE_BASE_RID               0x00000040L
3595 #define SECURITY_PACKAGE_NTLM_RID               0x0000000AL
3596 #define SECURITY_PACKAGE_SCHANNEL_RID           0x0000000EL
3597 #define SECURITY_PACKAGE_DIGEST_RID             0x00000015L
3598 #define SECURITY_MAX_ALWAYS_FILTERED            0x000003E7L
3599 #define SECURITY_MIN_NEVER_FILTERED             0x000003E8L
3600 #define SECURITY_OTHER_ORGANIZATION_RID         0x000003E8L
3601 
3602 #define FOREST_USER_RID_MAX                     0x000001F3L
3603 #define DOMAIN_USER_RID_ADMIN                   0x000001F4L
3604 #define DOMAIN_USER_RID_GUEST                   0x000001F5L
3605 #define DOMAIN_USER_RID_KRBTGT                  0x000001F6L
3606 #define DOMAIN_USER_RID_MAX                     0x000003E7L
3607 
3608 #define DOMAIN_GROUP_RID_ADMINS                 0x00000200L
3609 #define DOMAIN_GROUP_RID_USERS                  0x00000201L
3610 #define DOMAIN_GROUP_RID_GUESTS                 0x00000202L
3611 #define DOMAIN_GROUP_RID_COMPUTERS              0x00000203L
3612 #define DOMAIN_GROUP_RID_CONTROLLERS            0x00000204L
3613 #define DOMAIN_GROUP_RID_CERT_ADMINS            0x00000205L
3614 #define DOMAIN_GROUP_RID_SCHEMA_ADMINS          0x00000206L
3615 #define DOMAIN_GROUP_RID_ENTERPRISE_ADMINS      0x00000207L
3616 #define DOMAIN_GROUP_RID_POLICY_ADMINS          0x00000208L
3617 
3618 #define DOMAIN_ALIAS_RID_ADMINS                 0x00000220L
3619 #define DOMAIN_ALIAS_RID_USERS                  0x00000221L
3620 #define DOMAIN_ALIAS_RID_GUESTS                 0x00000222L
3621 #define DOMAIN_ALIAS_RID_POWER_USERS            0x00000223L
3622 
3623 #define DOMAIN_ALIAS_RID_ACCOUNT_OPS            0x00000224L
3624 #define DOMAIN_ALIAS_RID_SYSTEM_OPS             0x00000225L
3625 #define DOMAIN_ALIAS_RID_PRINT_OPS              0x00000226L
3626 #define DOMAIN_ALIAS_RID_BACKUP_OPS             0x00000227L
3627 
3628 #define DOMAIN_ALIAS_RID_REPLICATOR             0x00000228L
3629 #define DOMAIN_ALIAS_RID_RAS_SERVERS            0x00000229L
3630 #define DOMAIN_ALIAS_RID_PREW2KCOMPACCESS       0x0000022AL
3631 #define DOMAIN_ALIAS_RID_REMOTE_DESKTOP_USERS   0x0000022BL
3632 #define DOMAIN_ALIAS_RID_NETWORK_CONFIGURATION_OPS 0x0000022CL
3633 #define DOMAIN_ALIAS_RID_INCOMING_FOREST_TRUST_BUILDERS 0x0000022DL
3634 
3635 #define DOMAIN_ALIAS_RID_MONITORING_USERS       0x0000022EL
3636 #define DOMAIN_ALIAS_RID_LOGGING_USERS          0x0000022FL
3637 #define DOMAIN_ALIAS_RID_AUTHORIZATIONACCESS    0x00000230L
3638 #define