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