10 #include <sdkddkver.h>
12 // FIXME: Should we include these here?
16 /* Helper macro to enable gcc's extension. */
17 #ifndef __GNU_EXTENSION
19 #define __GNU_EXTENSION __extension__
21 #define __GNU_EXTENSION
25 typedef unsigned long POINTER_64
; // FIXME! HACK!!!
30 // Pseudo Modifiers for Input Parameters
58 // Defines the "size" of an any-size array
61 #define ANYSIZE_ARRAY 1
85 #define NULL ((void *)0)
86 #define NULL64 ((void * POINTER_64)0)
93 // We should use the -fms-extensions compiler flag for gcc,
94 // and clean up the mess.
96 #ifndef __ANONYMOUS_DEFINED
97 #define __ANONYMOUS_DEFINED
99 #ifndef NONAMELESSUNION
101 #define _ANONYMOUS_UNION __GNU_EXTENSION
102 #define _ANONYMOUS_STRUCT __GNU_EXTENSION
103 #elif defined(__WATCOMC__) || defined(_MSC_VER)
104 #define _ANONYMOUS_UNION
105 #define _ANONYMOUS_STRUCT
106 #endif /* __GNUC__/__WATCOMC__ */
107 #endif /* NONAMELESSUNION */
109 #ifndef _ANONYMOUS_UNION
110 #define _ANONYMOUS_UNION
111 #define _UNION_NAME(x) x
112 #define DUMMYUNIONNAME u
113 #define DUMMYUNIONNAME2 u2
114 #define DUMMYUNIONNAME3 u3
115 #define DUMMYUNIONNAME4 u4
116 #define DUMMYUNIONNAME5 u5
117 #define DUMMYUNIONNAME6 u6
118 #define DUMMYUNIONNAME7 u7
119 #define DUMMYUNIONNAME8 u8
121 #define _UNION_NAME(x)
122 #define DUMMYUNIONNAME
123 #define DUMMYUNIONNAME2
124 #define DUMMYUNIONNAME3
125 #define DUMMYUNIONNAME4
126 #define DUMMYUNIONNAME5
127 #define DUMMYUNIONNAME6
128 #define DUMMYUNIONNAME7
129 #define DUMMYUNIONNAME8
132 #ifndef _ANONYMOUS_STRUCT
133 #define _ANONYMOUS_STRUCT
134 #define _STRUCT_NAME(x) x
135 #define DUMMYSTRUCTNAME s
136 #define DUMMYSTRUCTNAME2 s2
137 #define DUMMYSTRUCTNAME3 s3
138 #define DUMMYSTRUCTNAME4 s4
139 #define DUMMYSTRUCTNAME5 s5
141 #define _STRUCT_NAME(x)
142 #define DUMMYSTRUCTNAME
143 #define DUMMYSTRUCTNAME2
144 #define DUMMYSTRUCTNAME3
145 #define DUMMYSTRUCTNAME4
146 #define DUMMYSTRUCTNAME5
149 #endif /* __ANONYMOUS_DEFINED */
154 #define RESTRICTED_POINTER
157 // Returns the base address of a structure from a structure member
159 #ifndef CONTAINING_RECORD
160 #define CONTAINING_RECORD(address, type, field) \
161 ((type *)(((ULONG_PTR)address) - (ULONG_PTR)(&(((type *)0)->field))))
165 // Returns the byte offset of the specified structure's member
168 #define FIELD_OFFSET(Type, Field) ((LONG)(LONG_PTR)&(((Type*) 0)->Field))
170 #define FIELD_OFFSET(Type, Field) __builtin_offsetof(Type, Field)
174 // Returns the type's alignment
176 #if defined(_MSC_VER) && (_MSC_VER >= 1300)
177 #define TYPE_ALIGNMENT(t) __alignof(t)
179 #define TYPE_ALIGNMENT(t) FIELD_OFFSET( struct { char x; t test; }, test )
183 // Calling Conventions
186 #define FASTCALL __fastcall
191 #define NTAPI __stdcall
194 // Used by the DDK exclusively , don't put in drivers
196 #define DDKAPI __stdcall // Use NTAPI instead
197 #define DDKCDECLAPI __cdecl // Just use __cdecl
200 // Import and Export Specifiers
203 // Done the same way as in windef.h for now
204 #define DECLSPEC_IMPORT __declspec(dllimport)
205 #define DECLSPEC_NORETURN __declspec(noreturn)
208 #ifndef DECLSPEC_ADDRSAFE
209 #if (_MSC_VER >= 1200) && (defined(_M_ALPHA) || defined(_M_AXP64))
210 #define DECLSPEC_ADDRSAFE __declspec(address_safe)
212 #define DECLSPEC_ADDRSAFE
216 #if !defined(_NTSYSTEM_)
217 #define NTSYSAPI DECLSPEC_IMPORT
218 #define NTSYSCALLAPI DECLSPEC_IMPORT
221 #if defined(_NTDLLBUILD_)
224 #define NTSYSCALLAPI DECLSPEC_ADDRSAFE
232 #if (_MSC_VER >= 1200)
233 #define FORCEINLINE __forceinline
235 #define FORCEINLINE __inline
237 #define FORCEINLINE static __inline__ __attribute__((always_inline))
241 #ifndef DECLSPEC_NOINLINE
242 #if (_MSC_VER >= 1300)
243 #define DECLSPEC_NOINLINE __declspec(noinline)
244 #elif defined(__GNUC__)
245 #define DECLSPEC_NOINLINE __attribute__((noinline))
247 #define DECLSPEC_NOINLINE
251 #if !defined(_M_CEE_PURE)
252 #define NTAPI_INLINE NTAPI
258 // Use to specify structure alignment
260 #ifndef DECLSPEC_ALIGN
261 #if defined(_MSC_VER) && (_MSC_VER >= 1300) && !defined(MIDL_PASS)
262 #define DECLSPEC_ALIGN(x) __declspec(align(x))
263 #elif defined(__GNUC__)
264 #define DECLSPEC_ALIGN(x) __attribute__((aligned(x)))
266 #define DECLSPEC_ALIGN(x)
273 // Use to silence unused variable warnings when it is intentional
275 #define UNREFERENCED_PARAMETER(P) {(P)=(P);}
276 #define UNREFERENCED_LOCAL_VARIABLE(L) {(L)=(L);}
277 #define DBG_UNREFERENCED_PARAMETER(P)
278 #define DBG_UNREFERENCED_LOCAL_VARIABLE(L)
283 // min/max helper macros
288 #define min(a,b) (((a) < (b)) ? (a) : (b))
292 #define max(a,b) (((a) > (b)) ? (a) : (b))
300 // Tell windef.h that we have defined some basic types
308 //typedef void * POINTER_64 PVOID64;
309 typedef PVOID PVOID64
; // FIXME!
315 typedef void *HANDLE
;
316 #define DECLARE_HANDLE(n) typedef struct n##__{int i;}*n
318 typedef PVOID HANDLE
;
319 #define DECLARE_HANDLE(n) typedef HANDLE n
321 typedef HANDLE
*PHANDLE
;
324 // Upper-Case Versions of Some Standard C Types
331 #if !defined(MIDL_PASS)
335 typedef double DOUBLE
;
338 // Used to store a non-float 8 byte aligned structure
342 _ANONYMOUS_UNION
union
344 __GNU_EXTENSION __int64 UseThisFieldToCopy
;
345 double DoNotUseThisField
;
347 } QUAD
, *PQUAD
, UQUAD
, *PUQUAD
;
353 typedef unsigned char UCHAR
, *PUCHAR
;
354 typedef unsigned short USHORT
, *PUSHORT
;
355 typedef unsigned long ULONG
, *PULONG
;
356 typedef CONST UCHAR
*PCUCHAR
;
357 typedef CONST USHORT
*PCUSHORT
;
358 typedef CONST ULONG
*PCULONG
;
361 typedef USHORT FSHORT
;
363 typedef UCHAR BOOLEAN
;
364 typedef BOOLEAN
*PBOOLEAN
;
369 typedef SHORT
*PSHORT
;
372 typedef LONG NTSTATUS
;
373 typedef NTSTATUS
*PNTSTATUS
;
375 typedef signed char SCHAR
;
376 typedef SCHAR
*PSCHAR
;
378 #ifndef _HRESULT_DEFINED
379 #define _HRESULT_DEFINED
380 typedef LONG HRESULT
;
386 __GNU_EXTENSION
typedef __int64 LONGLONG
, *PLONGLONG
;
387 __GNU_EXTENSION
typedef unsigned __int64 ULONGLONG
, *PULONGLONG
;
388 typedef ULONGLONG DWORDLONG
, *PDWORDLONG
;
391 // Update Sequence Number
393 typedef LONGLONG USN
;
397 // ANSI (Multi-byte Character) types
399 typedef CHAR
*PCHAR
, *LPCH
, *PCH
;
400 typedef CONST CHAR
*LPCCH
, *PCCH
;
401 typedef CHAR
*NPSTR
, *LPSTR
, *PSTR
;
402 typedef PSTR
*PZPSTR
;
403 typedef CONST PSTR
*PCZPSTR
;
404 typedef CONST CHAR
*LPCSTR
, *PCSTR
;
405 typedef PCSTR
*PZPCSTR
;
408 // Pointer to an Asciiz string
411 typedef CONST
char *PCSZ
;
414 // UNICODE (Wide Character) types
416 typedef wchar_t WCHAR
;
417 typedef WCHAR
*PWCHAR
, *LPWCH
, *PWCH
;
418 typedef CONST WCHAR
*LPCWCH
, *PCWCH
;
419 typedef WCHAR
*NWPSTR
, *LPWSTR
, *PWSTR
;
420 typedef PWSTR
*PZPWSTR
;
421 typedef CONST PWSTR
*PCZPWSTR
;
422 typedef WCHAR UNALIGNED
*LPUWSTR
, *PUWSTR
;
423 typedef CONST WCHAR
*LPCWSTR
, *PCWSTR
;
424 typedef PCWSTR
*PZPCWSTR
;
425 typedef CONST WCHAR UNALIGNED
*LPCUWSTR
, *PCUWSTR
;
428 // Cardinal Data Types
430 typedef char CCHAR
, *PCCHAR
;
431 typedef short CSHORT
, *PCSHORT
;
432 typedef ULONG CLONG
, *PCLONG
;
435 // NLS basics (Locale and Language Ids)
438 typedef PULONG PLCID
;
439 typedef USHORT LANGID
;
444 // Large Integer Unions
446 #if defined(MIDL_PASS)
447 typedef struct _LARGE_INTEGER
{
449 typedef union _LARGE_INTEGER
{
450 _ANONYMOUS_STRUCT
struct
462 } LARGE_INTEGER
, *PLARGE_INTEGER
;
464 #if defined(MIDL_PASS)
465 typedef struct _ULARGE_INTEGER
{
467 typedef union _ULARGE_INTEGER
{
468 _ANONYMOUS_STRUCT
struct
480 } ULARGE_INTEGER
, *PULARGE_INTEGER
;
483 // Physical Addresses are always treated as 64-bit wide
485 typedef LARGE_INTEGER PHYSICAL_ADDRESS
, *PPHYSICAL_ADDRESS
;
490 // Locally Unique Identifier
492 typedef struct _LUID
{
500 // Native API Return Value Macros
502 #define NT_SUCCESS(Status) (((NTSTATUS)(Status)) >= 0)
503 #define NT_INFORMATION(Status) ((((ULONG)(Status)) >> 30) == 1)
504 #define NT_WARNING(Status) ((((ULONG)(Status)) >> 30) == 2)
505 #define NT_ERROR(Status) ((((ULONG)(Status)) >> 30) == 3)
512 typedef struct _UNICODE_STRING
{
514 USHORT MaximumLength
;
516 } UNICODE_STRING
, *PUNICODE_STRING
;
517 typedef const UNICODE_STRING
* PCUNICODE_STRING
;
518 #define UNICODE_NULL ((WCHAR)0)
520 typedef struct _CSTRING
{
522 USHORT MaximumLength
;
524 } CSTRING
, *PCSTRING
;
525 #define ANSI_NULL ((CHAR)0)
527 typedef struct _STRING
{
529 USHORT MaximumLength
;
533 typedef STRING ANSI_STRING
;
534 typedef PSTRING PANSI_STRING
;
535 typedef STRING OEM_STRING
;
536 typedef PSTRING POEM_STRING
;
537 typedef CONST STRING
* PCOEM_STRING
;
538 typedef STRING CANSI_STRING
;
539 typedef PSTRING PCANSI_STRING
;
541 typedef struct _STRING32
{
543 USHORT MaximumLength
;
545 } STRING32
, *PSTRING32
,
546 UNICODE_STRING32
, *PUNICODE_STRING32
,
547 ANSI_STRING32
, *PANSI_STRING32
;
549 typedef struct _STRING64
{
551 USHORT MaximumLength
;
553 } STRING64
, *PSTRING64
,
554 UNICODE_STRING64
, *PUNICODE_STRING64
,
555 ANSI_STRING64
, *PANSI_STRING64
;
560 #define MAKELANGID(p, s) ((((USHORT)(s)) << 10) | (USHORT)(p))
561 #define PRIMARYLANGID(lgid) ((USHORT)(lgid) & 0x3ff)
562 #define SUBLANGID(lgid) ((USHORT)(lgid) >> 10)
564 #define NLS_VALID_LOCALE_MASK 0x000fffff
566 #define MAKELCID(lgid, srtid) ((ULONG)((((ULONG)((USHORT)(srtid))) << 16) | \
567 ((ULONG)((USHORT)(lgid)))))
568 #define MAKESORTLCID(lgid, srtid, ver) \
569 ((ULONG)((MAKELCID(lgid, srtid)) | \
570 (((ULONG)((USHORT)(ver))) << 20)))
571 #define LANGIDFROMLCID(lcid) ((USHORT)(lcid))
572 #define SORTIDFROMLCID(lcid) ((USHORT)((((ULONG)(lcid)) >> 16) & 0xf))
573 #define SORTVERSIONFROMLCID(lcid) ((USHORT)((((ULONG)(lcid)) >> 20) & 0xf))
580 typedef struct _OBJECT_ATTRIBUTES
{
582 HANDLE RootDirectory
;
583 PUNICODE_STRING ObjectName
;
585 PVOID SecurityDescriptor
;
586 PVOID SecurityQualityOfService
;
587 } OBJECT_ATTRIBUTES
, *POBJECT_ATTRIBUTES
;
588 typedef CONST OBJECT_ATTRIBUTES
*PCOBJECT_ATTRIBUTES
;
591 // Values for the Attributes member
593 #define OBJ_INHERIT 0x00000002
594 #define OBJ_PERMANENT 0x00000010
595 #define OBJ_EXCLUSIVE 0x00000020
596 #define OBJ_CASE_INSENSITIVE 0x00000040
597 #define OBJ_OPENIF 0x00000080
598 #define OBJ_OPENLINK 0x00000100
599 #define OBJ_KERNEL_HANDLE 0x00000200
600 #define OBJ_FORCE_ACCESS_CHECK 0x00000400
601 #define OBJ_VALID_ATTRIBUTES 0x000007F2
606 #define InitializeObjectAttributes(p,n,a,r,s) { \
607 (p)->Length = sizeof(OBJECT_ATTRIBUTES); \
608 (p)->RootDirectory = (r); \
609 (p)->Attributes = (a); \
610 (p)->ObjectName = (n); \
611 (p)->SecurityDescriptor = (s); \
612 (p)->SecurityQualityOfService = NULL; \
620 typedef enum _NT_PRODUCT_TYPE
{
624 } NT_PRODUCT_TYPE
, *PNT_PRODUCT_TYPE
;
629 // Doubly Linked Lists
631 typedef struct _LIST_ENTRY
{
632 struct _LIST_ENTRY
*Flink
;
633 struct _LIST_ENTRY
*Blink
;
634 } LIST_ENTRY
, *PLIST_ENTRY
, *RESTRICTED_POINTER PRLIST_ENTRY
;
636 typedef struct LIST_ENTRY32
640 } LIST_ENTRY32
, *PLIST_ENTRY32
;
642 typedef struct LIST_ENTRY64
646 } LIST_ENTRY64
, *PLIST_ENTRY64
;
649 // Singly Linked Lists
651 typedef struct _SINGLE_LIST_ENTRY
{
652 struct _SINGLE_LIST_ENTRY
*Next
;
653 } SINGLE_LIST_ENTRY
, *PSINGLE_LIST_ENTRY
;
660 #define RTL_CONSTANT_STRING(s) { sizeof(s)-sizeof((s)[0]), sizeof(s), s }
662 #define RTL_FIELD_SIZE(type, field) (sizeof(((type *)0)->field))
664 #define RTL_NUMBER_OF_V1(A) (sizeof(A)/sizeof((A)[0]))
665 #define RTL_NUMBER_OF_V2(A) RTL_NUMBER_OF_V1(A)
666 #ifdef ENABLE_RTL_NUMBER_OF_V2
667 #define RTL_NUMBER_OF(A) RTL_NUMBER_OF_V2(A)
669 #define RTL_NUMBER_OF(A) RTL_NUMBER_OF_V1(A)
671 #define ARRAYSIZE(A) RTL_NUMBER_OF_V2(A)
680 #define MINSHORT 0x8000
681 #define MAXSHORT 0x7fff
682 #define MINLONG 0x80000000
683 #define MAXLONG 0x7fffffff
684 #define MAXUCHAR 0xff
685 #define MAXUSHORT 0xffff
686 #define MAXULONG 0xffffffff
687 #define MAXLONGLONG (0x7fffffffffffffffLL)
692 // Multiplication and Shift Operations
694 #define Int32x32To64(a,b) ((LONGLONG)(a)*(LONGLONG)(b))
695 #define UInt32x32To64(a,b) ((DWORDLONG)(a)*(DWORDLONG)(b))
696 #define Int64ShllMod32(a,b) ((DWORDLONG)(a)<<(b))
697 #define Int64ShraMod32(a,b) ((LONGLONG)(a)>>(b))
698 #define Int64ShrlMod32(a,b) ((DWORDLONG)(a)>>(b))
703 // C_ASSERT Definition
705 #define C_ASSERT(expr) extern char (*c_assert(void)) [(expr) ? 1 : -1]
710 // Primary language IDs.
712 #define LANG_NEUTRAL 0x00
713 #define LANG_INVARIANT 0x7f
715 #define LANG_AFRIKAANS 0x36
716 #define LANG_ALBANIAN 0x1c
717 #define LANG_ALSATIAN 0x84
718 #define LANG_AMHARIC 0x5e
719 #define LANG_ARABIC 0x01
720 #define LANG_ARMENIAN 0x2b
721 #define LANG_ASSAMESE 0x4d
722 #define LANG_AZERI 0x2c
723 #define LANG_BASHKIR 0x6d
724 #define LANG_BASQUE 0x2d
725 #define LANG_BELARUSIAN 0x23
726 #define LANG_BENGALI 0x45
727 #define LANG_BRETON 0x7e
728 #define LANG_BOSNIAN 0x1a
729 #define LANG_BOSNIAN_NEUTRAL 0x781a
730 #define LANG_BULGARIAN 0x02
731 #define LANG_CATALAN 0x03
732 #define LANG_CHINESE 0x04
733 #define LANG_CHINESE_SIMPLIFIED 0x04
734 #define LANG_CHINESE_TRADITIONAL 0x7c04
735 #define LANG_CORSICAN 0x83
736 #define LANG_CROATIAN 0x1a
737 #define LANG_CZECH 0x05
738 #define LANG_DANISH 0x06
739 #define LANG_DARI 0x8c
740 #define LANG_DIVEHI 0x65
741 #define LANG_DUTCH 0x13
742 #define LANG_ENGLISH 0x09
743 #define LANG_ESTONIAN 0x25
744 #define LANG_FAEROESE 0x38
745 #define LANG_FARSI 0x29
746 #define LANG_FILIPINO 0x64
747 #define LANG_FINNISH 0x0b
748 #define LANG_FRENCH 0x0c
749 #define LANG_FRISIAN 0x62
750 #define LANG_GALICIAN 0x56
751 #define LANG_GEORGIAN 0x37
752 #define LANG_GERMAN 0x07
753 #define LANG_GREEK 0x08
754 #define LANG_GREENLANDIC 0x6f
755 #define LANG_GUJARATI 0x47
756 #define LANG_HAUSA 0x68
757 #define LANG_HEBREW 0x0d
758 #define LANG_HINDI 0x39
759 #define LANG_HUNGARIAN 0x0e
760 #define LANG_ICELANDIC 0x0f
761 #define LANG_IGBO 0x70
762 #define LANG_INDONESIAN 0x21
763 #define LANG_INUKTITUT 0x5d
764 #define LANG_IRISH 0x3c
765 #define LANG_ITALIAN 0x10
766 #define LANG_JAPANESE 0x11
767 #define LANG_KANNADA 0x4b
768 #define LANG_KASHMIRI 0x60
769 #define LANG_KAZAK 0x3f
770 #define LANG_KHMER 0x53
771 #define LANG_KICHE 0x86
772 #define LANG_KINYARWANDA 0x87
773 #define LANG_KONKANI 0x57
774 #define LANG_KOREAN 0x12
775 #define LANG_KYRGYZ 0x40
776 #define LANG_LAO 0x54
777 #define LANG_LATVIAN 0x26
778 #define LANG_LITHUANIAN 0x27
779 #define LANG_LOWER_SORBIAN 0x2e
780 #define LANG_LUXEMBOURGISH 0x6e
781 #define LANG_MACEDONIAN 0x2f
782 #define LANG_MALAY 0x3e
783 #define LANG_MALAYALAM 0x4c
784 #define LANG_MALTESE 0x3a
785 #define LANG_MANIPURI 0x58
786 #define LANG_MAORI 0x81
787 #define LANG_MAPUDUNGUN 0x7a
788 #define LANG_MARATHI 0x4e
789 #define LANG_MOHAWK 0x7c
790 #define LANG_MONGOLIAN 0x50
791 #define LANG_NEPALI 0x61
792 #define LANG_NORWEGIAN 0x14
793 #define LANG_OCCITAN 0x82
794 #define LANG_ORIYA 0x48
795 #define LANG_PASHTO 0x63
796 #define LANG_PERSIAN 0x29
797 #define LANG_POLISH 0x15
798 #define LANG_PORTUGUESE 0x16
799 #define LANG_PUNJABI 0x46
800 #define LANG_QUECHUA 0x6b
801 #define LANG_ROMANIAN 0x18
802 #define LANG_ROMANSH 0x17
803 #define LANG_RUSSIAN 0x19
804 #define LANG_SAMI 0x3b
805 #define LANG_SANSKRIT 0x4f
806 #define LANG_SERBIAN 0x1a
807 #define LANG_SERBIAN_NEUTRAL 0x7c1a
808 #define LANG_SINDHI 0x59
809 #define LANG_SINHALESE 0x5b
810 #define LANG_SLOVAK 0x1b
811 #define LANG_SLOVENIAN 0x24
812 #define LANG_SOTHO 0x6c
813 #define LANG_SPANISH 0x0a
814 #define LANG_SWAHILI 0x41
815 #define LANG_SWEDISH 0x1d
816 #define LANG_SYRIAC 0x5a
817 #define LANG_TAJIK 0x28
818 #define LANG_TAMAZIGHT 0x5f
819 #define LANG_TAMIL 0x49
820 #define LANG_TATAR 0x44
821 #define LANG_TELUGU 0x4a
822 #define LANG_THAI 0x1e
823 #define LANG_TIBETAN 0x51
824 #define LANG_TIGRIGNA 0x73
825 #define LANG_TSWANA 0x32
826 #define LANG_TURKISH 0x1f
827 #define LANG_TURKMEN 0x42
828 #define LANG_UIGHUR 0x80
829 #define LANG_UKRAINIAN 0x22
830 #define LANG_UPPER_SORBIAN 0x2e
831 #define LANG_URDU 0x20
832 #define LANG_UZBEK 0x43
833 #define LANG_VIETNAMESE 0x2a
834 #define LANG_WELSH 0x52
835 #define LANG_WOLOF 0x88
836 #define LANG_XHOSA 0x34
837 #define LANG_YAKUT 0x85
839 #define LANG_YORUBA 0x6a
840 #define LANG_ZULU 0x35
844 #endif /* _NTDEF_H */