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