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