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