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 NONAMELESSUNION
98 #define _ANONYMOUS_UNION __GNU_EXTENSION
99 #define _ANONYMOUS_STRUCT __GNU_EXTENSION
100 #elif defined(__WATCOMC__) || defined(_MSC_VER)
101 #define _ANONYMOUS_UNION
102 #define _ANONYMOUS_STRUCT
103 #endif /* __GNUC__/__WATCOMC__ */
104 #endif /* NONAMELESSUNION */
106 #ifndef _ANONYMOUS_UNION
107 #define _ANONYMOUS_UNION
108 #define _UNION_NAME(x) x
109 #define DUMMYUNIONNAME u
110 #define DUMMYUNIONNAME2 u2
111 #define DUMMYUNIONNAME3 u3
112 #define DUMMYUNIONNAME4 u4
113 #define DUMMYUNIONNAME5 u5
114 #define DUMMYUNIONNAME6 u6
115 #define DUMMYUNIONNAME7 u7
116 #define DUMMYUNIONNAME8 u8
118 #define _UNION_NAME(x)
119 #define DUMMYUNIONNAME
120 #define DUMMYUNIONNAME2
121 #define DUMMYUNIONNAME3
122 #define DUMMYUNIONNAME4
123 #define DUMMYUNIONNAME5
124 #define DUMMYUNIONNAME6
125 #define DUMMYUNIONNAME7
126 #define DUMMYUNIONNAME8
129 #ifndef _ANONYMOUS_STRUCT
130 #define _ANONYMOUS_STRUCT
131 #define _STRUCT_NAME(x) x
132 #define DUMMYSTRUCTNAME s
133 #define DUMMYSTRUCTNAME2 s2
134 #define DUMMYSTRUCTNAME3 s3
136 #define _STRUCT_NAME(x)
137 #define DUMMYSTRUCTNAME
138 #define DUMMYSTRUCTNAME2
139 #define DUMMYSTRUCTNAME3
147 #define RESTRICTED_POINTER
150 // Returns the base address of a structure from a structure member
152 #ifndef CONTAINING_RECORD
153 #define CONTAINING_RECORD(address, type, field) \
154 ((type *)(((ULONG_PTR)address) - (ULONG_PTR)(&(((type *)0)->field))))
158 // Returns the byte offset of the specified structure's member
161 #define FIELD_OFFSET(Type, Field) ((LONG)(LONG_PTR)&(((Type*) 0)->Field))
163 #define FIELD_OFFSET(Type, Field) __builtin_offsetof(Type, Field)
167 // Returns the type's alignment
169 #if defined(_MSC_VER) && (_MSC_VER >= 1300)
170 #define TYPE_ALIGNMENT(t) __alignof(t)
172 #define TYPE_ALIGNMENT(t) FIELD_OFFSET( struct { char x; t test; }, test )
176 // Calling Conventions
179 #define FASTCALL __fastcall
184 #define NTAPI __stdcall
187 // Used by the DDK exclusively , don't put in drivers
189 #define DDKAPI __stdcall // Use NTAPI instead
190 #define DDKCDECLAPI __cdecl // Just use __cdecl
193 // Import and Export Specifiers
196 // Done the same way as in windef.h for now
197 #define DECLSPEC_IMPORT __declspec(dllimport)
198 #define DECLSPEC_NORETURN __declspec(noreturn)
201 #ifndef DECLSPEC_ADDRSAFE
202 #if (_MSC_VER >= 1200) && (defined(_M_ALPHA) || defined(_M_AXP64))
203 #define DECLSPEC_ADDRSAFE __declspec(address_safe)
205 #define DECLSPEC_ADDRSAFE
209 #if !defined(_NTSYSTEM_)
210 #define NTSYSAPI DECLSPEC_IMPORT
211 #define NTSYSCALLAPI DECLSPEC_IMPORT
214 #if defined(_NTDLLBUILD_)
217 #define NTSYSCALLAPI DECLSPEC_ADDRSAFE
225 #if (_MSC_VER >= 1200)
226 #define FORCEINLINE __forceinline
228 #define FORCEINLINE __inline
230 #define FORCEINLINE static __inline__ __attribute__((always_inline))
234 #ifndef DECLSPEC_NOINLINE
235 #if (_MSC_VER >= 1300)
236 #define DECLSPEC_NOINLINE __declspec(noinline)
237 #elif defined(__GNUC__)
238 #define DECLSPEC_NOINLINE __attribute__((noinline))
240 #define DECLSPEC_NOINLINE
244 #if !defined(_M_CEE_PURE)
245 #define NTAPI_INLINE NTAPI
251 // Use to specify structure alignment
253 #ifndef DECLSPEC_ALIGN
254 #if defined(_MSC_VER) && (_MSC_VER >= 1300) && !defined(MIDL_PASS)
255 #define DECLSPEC_ALIGN(x) __declspec(align(x))
256 #elif defined(__GNUC__)
257 #define DECLSPEC_ALIGN(x) __attribute__((aligned(x)))
259 #define DECLSPEC_ALIGN(x)
266 // Use to silence unused variable warnings when it is intentional
268 #define UNREFERENCED_PARAMETER(P) {(P)=(P);}
269 #define UNREFERENCED_LOCAL_VARIABLE(L) {(L)=(L);}
270 #define DBG_UNREFERENCED_PARAMETER(P)
271 #define DBG_UNREFERENCED_LOCAL_VARIABLE(L)
276 // min/max helper macros
281 #define min(a,b) (((a) < (b)) ? (a) : (b))
285 #define max(a,b) (((a) > (b)) ? (a) : (b))
293 // Tell windef.h that we have defined some basic types
301 //typedef void * POINTER_64 PVOID64;
302 typedef PVOID PVOID64
; // FIXME!
308 typedef void *HANDLE
;
309 #define DECLARE_HANDLE(n) typedef struct n##__{int i;}*n
311 typedef PVOID HANDLE
;
312 #define DECLARE_HANDLE(n) typedef HANDLE n
314 typedef HANDLE
*PHANDLE
;
317 // Upper-Case Versions of Some Standard C Types
324 #if !defined(MIDL_PASS)
328 typedef double DOUBLE
;
331 // Used to store a non-float 8 byte aligned structure
335 _ANONYMOUS_UNION
union
337 __GNU_EXTENSION __int64 UseThisFieldToCopy
;
338 double DoNotUseThisField
;
340 } QUAD
, *PQUAD
, UQUAD
, *PUQUAD
;
346 typedef unsigned char UCHAR
, *PUCHAR
;
347 typedef unsigned short USHORT
, *PUSHORT
;
348 typedef unsigned long ULONG
, *PULONG
;
349 typedef CONST UCHAR
*PCUCHAR
;
350 typedef CONST USHORT
*PCUSHORT
;
351 typedef CONST ULONG
*PCULONG
;
354 typedef USHORT FSHORT
;
356 typedef UCHAR BOOLEAN
;
357 typedef BOOLEAN
*PBOOLEAN
;
362 typedef SHORT
*PSHORT
;
365 typedef LONG NTSTATUS
;
366 typedef NTSTATUS
*PNTSTATUS
;
368 typedef signed char SCHAR
;
369 typedef SCHAR
*PSCHAR
;
371 #ifndef _HRESULT_DEFINED
372 #define _HRESULT_DEFINED
373 typedef LONG HRESULT
;
379 __GNU_EXTENSION
typedef __int64 LONGLONG
, *PLONGLONG
;
380 __GNU_EXTENSION
typedef unsigned __int64 ULONGLONG
, *PULONGLONG
;
381 typedef ULONGLONG DWORDLONG
, *PDWORDLONG
;
384 // Update Sequence Number
386 typedef LONGLONG USN
;
390 // ANSI (Multi-byte Character) types
392 typedef CHAR
*PCHAR
, *LPCH
, *PCH
;
393 typedef CONST CHAR
*LPCCH
, *PCCH
;
394 typedef CHAR
*NPSTR
, *LPSTR
, *PSTR
;
395 typedef PSTR
*PZPSTR
;
396 typedef CONST PSTR
*PCZPSTR
;
397 typedef CONST CHAR
*LPCSTR
, *PCSTR
;
398 typedef PCSTR
*PZPCSTR
;
401 // Pointer to an Asciiz string
404 typedef CONST
char *PCSZ
;
407 // UNICODE (Wide Character) types
409 typedef wchar_t WCHAR
;
410 typedef WCHAR
*PWCHAR
, *LPWCH
, *PWCH
;
411 typedef CONST WCHAR
*LPCWCH
, *PCWCH
;
412 typedef WCHAR
*NWPSTR
, *LPWSTR
, *PWSTR
;
413 typedef PWSTR
*PZPWSTR
;
414 typedef CONST PWSTR
*PCZPWSTR
;
415 typedef WCHAR UNALIGNED
*LPUWSTR
, *PUWSTR
;
416 typedef CONST WCHAR
*LPCWSTR
, *PCWSTR
;
417 typedef PCWSTR
*PZPCWSTR
;
418 typedef CONST WCHAR UNALIGNED
*LPCUWSTR
, *PCUWSTR
;
421 // Cardinal Data Types
423 typedef char CCHAR
, *PCCHAR
;
424 typedef short CSHORT
, *PCSHORT
;
425 typedef ULONG CLONG
, *PCLONG
;
428 // NLS basics (Locale and Language Ids)
431 typedef PULONG PLCID
;
432 typedef USHORT LANGID
;
437 // Large Integer Unions
439 #if defined(MIDL_PASS)
440 typedef struct _LARGE_INTEGER
{
442 typedef union _LARGE_INTEGER
{
443 _ANONYMOUS_STRUCT
struct
455 } LARGE_INTEGER
, *PLARGE_INTEGER
;
457 #if defined(MIDL_PASS)
458 typedef struct _ULARGE_INTEGER
{
460 typedef union _ULARGE_INTEGER
{
461 _ANONYMOUS_STRUCT
struct
473 } ULARGE_INTEGER
, *PULARGE_INTEGER
;
476 // Physical Addresses are always treated as 64-bit wide
478 typedef LARGE_INTEGER PHYSICAL_ADDRESS
, *PPHYSICAL_ADDRESS
;
483 // Locally Unique Identifier
485 typedef struct _LUID
{
493 // Native API Return Value Macros
495 #define NT_SUCCESS(Status) (((NTSTATUS)(Status)) >= 0)
496 #define NT_INFORMATION(Status) ((((ULONG)(Status)) >> 30) == 1)
497 #define NT_WARNING(Status) ((((ULONG)(Status)) >> 30) == 2)
498 #define NT_ERROR(Status) ((((ULONG)(Status)) >> 30) == 3)
505 typedef struct _UNICODE_STRING
{
507 USHORT MaximumLength
;
509 } UNICODE_STRING
, *PUNICODE_STRING
;
510 typedef const UNICODE_STRING
* PCUNICODE_STRING
;
511 #define UNICODE_NULL ((WCHAR)0)
513 typedef struct _CSTRING
{
515 USHORT MaximumLength
;
517 } CSTRING
, *PCSTRING
;
518 #define ANSI_NULL ((CHAR)0)
520 typedef struct _STRING
{
522 USHORT MaximumLength
;
526 typedef STRING ANSI_STRING
;
527 typedef PSTRING PANSI_STRING
;
528 typedef STRING OEM_STRING
;
529 typedef PSTRING POEM_STRING
;
530 typedef CONST STRING
* PCOEM_STRING
;
531 typedef STRING CANSI_STRING
;
532 typedef PSTRING PCANSI_STRING
;
534 typedef struct _STRING32
{
536 USHORT MaximumLength
;
538 } STRING32
, *PSTRING32
,
539 UNICODE_STRING32
, *PUNICODE_STRING32
,
540 ANSI_STRING32
, *PANSI_STRING32
;
542 typedef struct _STRING64
{
544 USHORT MaximumLength
;
546 } STRING64
, *PSTRING64
,
547 UNICODE_STRING64
, *PUNICODE_STRING64
,
548 ANSI_STRING64
, *PANSI_STRING64
;
553 #define MAKELANGID(p, s) ((((USHORT)(s)) << 10) | (USHORT)(p))
554 #define PRIMARYLANGID(lgid) ((USHORT)(lgid) & 0x3ff)
555 #define SUBLANGID(lgid) ((USHORT)(lgid) >> 10)
557 #define NLS_VALID_LOCALE_MASK 0x000fffff
559 #define MAKELCID(lgid, srtid) ((ULONG)((((ULONG)((USHORT)(srtid))) << 16) | \
560 ((ULONG)((USHORT)(lgid)))))
561 #define MAKESORTLCID(lgid, srtid, ver) \
562 ((ULONG)((MAKELCID(lgid, srtid)) | \
563 (((ULONG)((USHORT)(ver))) << 20)))
564 #define LANGIDFROMLCID(lcid) ((USHORT)(lcid))
565 #define SORTIDFROMLCID(lcid) ((USHORT)((((ULONG)(lcid)) >> 16) & 0xf))
566 #define SORTVERSIONFROMLCID(lcid) ((USHORT)((((ULONG)(lcid)) >> 20) & 0xf))
573 typedef struct _OBJECT_ATTRIBUTES
{
575 HANDLE RootDirectory
;
576 PUNICODE_STRING ObjectName
;
578 PVOID SecurityDescriptor
;
579 PVOID SecurityQualityOfService
;
580 } OBJECT_ATTRIBUTES
, *POBJECT_ATTRIBUTES
;
581 typedef CONST OBJECT_ATTRIBUTES
*PCOBJECT_ATTRIBUTES
;
584 // Values for the Attributes member
586 #define OBJ_INHERIT 0x00000002
587 #define OBJ_PERMANENT 0x00000010
588 #define OBJ_EXCLUSIVE 0x00000020
589 #define OBJ_CASE_INSENSITIVE 0x00000040
590 #define OBJ_OPENIF 0x00000080
591 #define OBJ_OPENLINK 0x00000100
592 #define OBJ_KERNEL_HANDLE 0x00000200
593 #define OBJ_FORCE_ACCESS_CHECK 0x00000400
594 #define OBJ_VALID_ATTRIBUTES 0x000007F2
599 #define InitializeObjectAttributes(p,n,a,r,s) { \
600 (p)->Length = sizeof(OBJECT_ATTRIBUTES); \
601 (p)->RootDirectory = (r); \
602 (p)->Attributes = (a); \
603 (p)->ObjectName = (n); \
604 (p)->SecurityDescriptor = (s); \
605 (p)->SecurityQualityOfService = NULL; \
613 typedef enum _NT_PRODUCT_TYPE
{
617 } NT_PRODUCT_TYPE
, *PNT_PRODUCT_TYPE
;
622 // Doubly Linked Lists
624 typedef struct _LIST_ENTRY
{
625 struct _LIST_ENTRY
*Flink
;
626 struct _LIST_ENTRY
*Blink
;
627 } LIST_ENTRY
, *PLIST_ENTRY
, *RESTRICTED_POINTER PRLIST_ENTRY
;
629 typedef struct LIST_ENTRY32
633 } LIST_ENTRY32
, *PLIST_ENTRY32
;
635 typedef struct LIST_ENTRY64
639 } LIST_ENTRY64
, *PLIST_ENTRY64
;
642 // Singly Linked Lists
644 typedef struct _SINGLE_LIST_ENTRY
{
645 struct _SINGLE_LIST_ENTRY
*Next
;
646 } SINGLE_LIST_ENTRY
, *PSINGLE_LIST_ENTRY
;
653 #define RTL_CONSTANT_STRING(s) { sizeof(s)-sizeof((s)[0]), sizeof(s), s }
655 #define RTL_FIELD_SIZE(type, field) (sizeof(((type *)0)->field))
657 #define RTL_NUMBER_OF_V1(A) (sizeof(A)/sizeof((A)[0]))
658 #define RTL_NUMBER_OF_V2(A) RTL_NUMBER_OF_V1(A)
659 #ifdef ENABLE_RTL_NUMBER_OF_V2
660 #define RTL_NUMBER_OF(A) RTL_NUMBER_OF_V2(A)
662 #define RTL_NUMBER_OF(A) RTL_NUMBER_OF_V1(A)
664 #define ARRAYSIZE(A) RTL_NUMBER_OF_V2(A)
673 #define MINSHORT 0x8000
674 #define MAXSHORT 0x7fff
675 #define MINLONG 0x80000000
676 #define MAXLONG 0x7fffffff
677 #define MAXUCHAR 0xff
678 #define MAXUSHORT 0xffff
679 #define MAXULONG 0xffffffff
680 #define MAXLONGLONG (0x7fffffffffffffffLL)
685 // Multiplication and Shift Operations
687 #define Int32x32To64(a,b) ((LONGLONG)(a)*(LONGLONG)(b))
688 #define UInt32x32To64(a,b) ((DWORDLONG)(a)*(DWORDLONG)(b))
689 #define Int64ShllMod32(a,b) ((DWORDLONG)(a)<<(b))
690 #define Int64ShraMod32(a,b) ((LONGLONG)(a)>>(b))
691 #define Int64ShrlMod32(a,b) ((DWORDLONG)(a)>>(b))
696 // C_ASSERT Definition
698 #define C_ASSERT(expr) extern char (*c_assert(void)) [(expr) ? 1 : -1]
703 // Primary language IDs.
705 #define LANG_NEUTRAL 0x00
706 #define LANG_INVARIANT 0x7f
708 #define LANG_AFRIKAANS 0x36
709 #define LANG_ALBANIAN 0x1c
710 #define LANG_ALSATIAN 0x84
711 #define LANG_AMHARIC 0x5e
712 #define LANG_ARABIC 0x01
713 #define LANG_ARMENIAN 0x2b
714 #define LANG_ASSAMESE 0x4d
715 #define LANG_AZERI 0x2c
716 #define LANG_BASHKIR 0x6d
717 #define LANG_BASQUE 0x2d
718 #define LANG_BELARUSIAN 0x23
719 #define LANG_BENGALI 0x45
720 #define LANG_BRETON 0x7e
721 #define LANG_BOSNIAN 0x1a
722 #define LANG_BOSNIAN_NEUTRAL 0x781a
723 #define LANG_BULGARIAN 0x02
724 #define LANG_CATALAN 0x03
725 #define LANG_CHINESE 0x04
726 #define LANG_CHINESE_SIMPLIFIED 0x04
727 #define LANG_CHINESE_TRADITIONAL 0x7c04
728 #define LANG_CORSICAN 0x83
729 #define LANG_CROATIAN 0x1a
730 #define LANG_CZECH 0x05
731 #define LANG_DANISH 0x06
732 #define LANG_DARI 0x8c
733 #define LANG_DIVEHI 0x65
734 #define LANG_DUTCH 0x13
735 #define LANG_ENGLISH 0x09
736 #define LANG_ESTONIAN 0x25
737 #define LANG_FAEROESE 0x38
738 #define LANG_FARSI 0x29
739 #define LANG_FILIPINO 0x64
740 #define LANG_FINNISH 0x0b
741 #define LANG_FRENCH 0x0c
742 #define LANG_FRISIAN 0x62
743 #define LANG_GALICIAN 0x56
744 #define LANG_GEORGIAN 0x37
745 #define LANG_GERMAN 0x07
746 #define LANG_GREEK 0x08
747 #define LANG_GREENLANDIC 0x6f
748 #define LANG_GUJARATI 0x47
749 #define LANG_HAUSA 0x68
750 #define LANG_HEBREW 0x0d
751 #define LANG_HINDI 0x39
752 #define LANG_HUNGARIAN 0x0e
753 #define LANG_ICELANDIC 0x0f
754 #define LANG_IGBO 0x70
755 #define LANG_INDONESIAN 0x21
756 #define LANG_INUKTITUT 0x5d
757 #define LANG_IRISH 0x3c
758 #define LANG_ITALIAN 0x10
759 #define LANG_JAPANESE 0x11
760 #define LANG_KANNADA 0x4b
761 #define LANG_KASHMIRI 0x60
762 #define LANG_KAZAK 0x3f
763 #define LANG_KHMER 0x53
764 #define LANG_KICHE 0x86
765 #define LANG_KINYARWANDA 0x87
766 #define LANG_KONKANI 0x57
767 #define LANG_KOREAN 0x12
768 #define LANG_KYRGYZ 0x40
769 #define LANG_LAO 0x54
770 #define LANG_LATVIAN 0x26
771 #define LANG_LITHUANIAN 0x27
772 #define LANG_LOWER_SORBIAN 0x2e
773 #define LANG_LUXEMBOURGISH 0x6e
774 #define LANG_MACEDONIAN 0x2f
775 #define LANG_MALAY 0x3e
776 #define LANG_MALAYALAM 0x4c
777 #define LANG_MALTESE 0x3a
778 #define LANG_MANIPURI 0x58
779 #define LANG_MAORI 0x81
780 #define LANG_MAPUDUNGUN 0x7a
781 #define LANG_MARATHI 0x4e
782 #define LANG_MOHAWK 0x7c
783 #define LANG_MONGOLIAN 0x50
784 #define LANG_NEPALI 0x61
785 #define LANG_NORWEGIAN 0x14
786 #define LANG_OCCITAN 0x82
787 #define LANG_ORIYA 0x48
788 #define LANG_PASHTO 0x63
789 #define LANG_PERSIAN 0x29
790 #define LANG_POLISH 0x15
791 #define LANG_PORTUGUESE 0x16
792 #define LANG_PUNJABI 0x46
793 #define LANG_QUECHUA 0x6b
794 #define LANG_ROMANIAN 0x18
795 #define LANG_ROMANSH 0x17
796 #define LANG_RUSSIAN 0x19
797 #define LANG_SAMI 0x3b
798 #define LANG_SANSKRIT 0x4f
799 #define LANG_SERBIAN 0x1a
800 #define LANG_SERBIAN_NEUTRAL 0x7c1a
801 #define LANG_SINDHI 0x59
802 #define LANG_SINHALESE 0x5b
803 #define LANG_SLOVAK 0x1b
804 #define LANG_SLOVENIAN 0x24
805 #define LANG_SOTHO 0x6c
806 #define LANG_SPANISH 0x0a
807 #define LANG_SWAHILI 0x41
808 #define LANG_SWEDISH 0x1d
809 #define LANG_SYRIAC 0x5a
810 #define LANG_TAJIK 0x28
811 #define LANG_TAMAZIGHT 0x5f
812 #define LANG_TAMIL 0x49
813 #define LANG_TATAR 0x44
814 #define LANG_TELUGU 0x4a
815 #define LANG_THAI 0x1e
816 #define LANG_TIBETAN 0x51
817 #define LANG_TIGRIGNA 0x73
818 #define LANG_TSWANA 0x32
819 #define LANG_TURKISH 0x1f
820 #define LANG_TURKMEN 0x42
821 #define LANG_UIGHUR 0x80
822 #define LANG_UKRAINIAN 0x22
823 #define LANG_UPPER_SORBIAN 0x2e
824 #define LANG_URDU 0x20
825 #define LANG_UZBEK 0x43
826 #define LANG_VIETNAMESE 0x2a
827 #define LANG_WELSH 0x52
828 #define LANG_WOLOF 0x88
829 #define LANG_XHOSA 0x34
830 #define LANG_YAKUT 0x85
832 #define LANG_YORUBA 0x6a
833 #define LANG_ZULU 0x35
837 #endif /* _NTDEF_H */