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