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