Home | History | Annotate | Download | only in include
      1 /*
      2  * ntdef.h
      3  *
      4  * This file is part of the ReactOS PSDK package.
      5  *
      6  * Contributors:
      7  *   Created by Casper S. Hornstrup <chorns (at) users.sourceforge.net>
      8  *
      9  * THIS SOFTWARE IS NOT COPYRIGHTED
     10  *
     11  * This source code is offered for use in the public domain. You may
     12  * use, modify or distribute it freely.
     13  *
     14  * This code is distributed in the hope that it will be useful but
     15  * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
     16  * DISCLAIMED. This includes but is not limited to warranties of
     17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
     18  *
     19  */
     20 
     21 #ifndef _NTDEF_
     22 #define _NTDEF_
     23 
     24 #ifdef _WINNT_
     25 /* FIXME: In version two, warn about including both ntdef.h and winnt.h
     26  * #warning Including winnt.h and ntdef.h is deprecated and will be removed in a future release.  Please use winternl.h
     27  */
     28 #endif
     29 
     30 #include <_mingw.h>
     31 
     32 #if defined(__x86_64) && \
     33   !(defined(_X86_) || defined(__i386__) || defined(_IA64_))
     34 #if !defined(_AMD64_)
     35 #define _AMD64_
     36 #endif
     37 #endif /* _AMD64_ */
     38 
     39 #if defined(__ia64__) && \
     40   !(defined(_X86_) || defined(__x86_64) || defined(_AMD64_))
     41 #if !defined(_IA64_)
     42 #define _IA64_
     43 #endif
     44 #endif /* _IA64_ */
     45 
     46 /* Dependencies */
     47 #include <ctype.h>
     48 #include <basetsd.h>
     49 #include <excpt.h>
     50 #include <sdkddkver.h>
     51 
     52 /* FIXME: Shouldn't be included! */
     53 #include <stdarg.h>
     54 #include <string.h>
     55 
     56 /* Pseudo Modifiers for Input Parameters */
     57 
     58 #ifndef IN
     59 #define IN
     60 #endif
     61 
     62 #ifndef OUT
     63 #define OUT
     64 #endif
     65 
     66 #ifndef OPTIONAL
     67 #define OPTIONAL
     68 #endif
     69 
     70 #ifndef NOTHING
     71 #define NOTHING
     72 #endif
     73 
     74 #ifndef CRITICAL
     75 #define CRITICAL
     76 #endif
     77 
     78 #ifndef FAR
     79 #define FAR
     80 #endif
     81 
     82 
     83 /* Defines the "size" of an any-size array */
     84 #ifndef ANYSIZE_ARRAY
     85 #define ANYSIZE_ARRAY 1
     86 #endif
     87 
     88 /* Constant modifier */
     89 #ifndef CONST
     90 #define CONST const
     91 #endif
     92 
     93 /* TRUE/FALSE */
     94 #define FALSE   0
     95 #define TRUE    1
     96 
     97 /* NULL/NULL64 */
     98 #ifndef NULL
     99 #ifdef __cplusplus
    100 #ifndef _WIN64
    101 #define NULL    0
    102 #else
    103 #define NULL    0LL
    104 #endif  /* W64 */
    105 #else
    106 #define NULL    ((void *)0)
    107 #endif
    108 #endif /* NULL */
    109 #ifndef NULL64
    110 #ifdef __cplusplus
    111 #define NULL64  0LL
    112 #else
    113 #define NULL64  ((void * POINTER_64)0)
    114 #endif
    115 #endif /* NULL64 */
    116 
    117 
    118 #undef  UNALIGNED	/* avoid redefinition warnings vs _mingw.h */
    119 #undef  UNALIGNED64
    120 #if defined(_M_MRX000) || defined(_M_ALPHA) || defined(_M_PPC) || defined(_M_IA64) || defined(_M_AMD64) || defined (_M_ARM)
    121 #define ALIGNMENT_MACHINE
    122 #define UNALIGNED __unaligned
    123 #if defined(_WIN64)
    124 #define UNALIGNED64 __unaligned
    125 #else
    126 #define UNALIGNED64
    127 #endif
    128 #else
    129 #undef ALIGNMENT_MACHINE
    130 #define UNALIGNED
    131 #define UNALIGNED64
    132 #endif
    133 
    134 #if defined(_WIN64) || defined(_M_ALPHA)
    135 #define MAX_NATURAL_ALIGNMENT sizeof(ULONGLONG)
    136 #define MEMORY_ALLOCATION_ALIGNMENT 16
    137 #else
    138 #define MAX_NATURAL_ALIGNMENT sizeof(ULONG)
    139 #define MEMORY_ALLOCATION_ALIGNMENT 8
    140 #endif
    141 
    142 #if defined(_M_MRX000) && !(defined(MIDL_PASS) || defined(RC_INVOKED)) && defined(ENABLE_RESTRICTED)
    143 #define RESTRICTED_POINTER __restrict
    144 #else
    145 #define RESTRICTED_POINTER
    146 #endif
    147 
    148 
    149 #define ARGUMENT_PRESENT(ArgumentPointer) \
    150   ((CHAR*)((ULONG_PTR)(ArgumentPointer)) != (CHAR*)NULL)
    151 
    152 /* Returns the base address of a structure from a structure member */
    153 #ifndef CONTAINING_RECORD
    154 #define CONTAINING_RECORD(address, type, field) \
    155   ((type *)(((ULONG_PTR)address) - (ULONG_PTR)(&(((type *)0)->field))))
    156 #endif
    157 
    158 /* Returns the byte offset of the specified structure's member */
    159 #ifndef __GNUC__
    160 #define FIELD_OFFSET(Type, Field) ((LONG)(LONG_PTR)&(((Type*) 0)->Field))
    161 #else
    162 #define FIELD_OFFSET(Type, Field) __builtin_offsetof(Type, Field)
    163 #endif
    164 
    165 /* Returns the type's alignment */
    166 #if defined(_MSC_VER) && (_MSC_VER >= 1300)
    167 #define TYPE_ALIGNMENT(t) __alignof(t)
    168 #else
    169 #define TYPE_ALIGNMENT(t) FIELD_OFFSET(struct { char x; t test; }, test)
    170 #endif
    171 
    172 #if defined (_X86_) || defined (_AMD64_)
    173 #define PROBE_ALIGNMENT(v) TYPE_ALIGNMENT(ULONG)
    174 #elif defined (_IA64_) || defined (_ARM_)
    175 #define PROBE_ALIGNMENT(v) (TYPE_ALIGNMENT(v) > TYPE_ALIGNMENT(ULONG) ? TYPE_ALIGNMENT(v) : TYPE_ALIGNMENT(ULONG))
    176 #endif
    177 
    178 /* Calling Conventions */
    179 #if defined(_M_IX86)
    180 #define FASTCALL __fastcall
    181 #else
    182 #define FASTCALL
    183 #endif
    184 
    185 #if defined(_ARM_)
    186 #define NTAPI
    187 #else
    188 #define NTAPI __stdcall
    189 #endif
    190 
    191 
    192 #ifndef NOP_FUNCTION
    193 #if (_MSC_VER >= 1210)
    194 #define NOP_FUNCTION __noop
    195 #else
    196 #define NOP_FUNCTION (void)0
    197 #endif
    198 #endif
    199 
    200 /* Import and Export Specifiers */
    201 
    202 /* Done the same way as in windef.h for now */
    203 #define DECLSPEC_IMPORT __declspec(dllimport)
    204 #define DECLSPEC_NORETURN __declspec(noreturn)
    205 
    206 #ifndef DECLSPEC_ADDRSAFE
    207 #if (_MSC_VER >= 1200) && (defined(_M_ALPHA) || defined(_M_AXP64))
    208 #define DECLSPEC_ADDRSAFE  __declspec(address_safe)
    209 #else
    210 #define DECLSPEC_ADDRSAFE
    211 #endif
    212 #endif /* DECLSPEC_ADDRSAFE */
    213 
    214 #if !defined(_NTSYSTEM_)
    215 #define NTSYSAPI     DECLSPEC_IMPORT
    216 #define NTSYSCALLAPI DECLSPEC_IMPORT
    217 #else
    218 #define NTSYSAPI
    219 #if defined(_NTDLLBUILD_)
    220 #define NTSYSCALLAPI
    221 #else
    222 #define NTSYSCALLAPI DECLSPEC_ADDRSAFE
    223 #endif
    224 #endif
    225 
    226 /* Inlines */
    227 #ifndef FORCEINLINE
    228 #if !defined(_MSC_VER) || (_MSC_VER >=1200)
    229 #define FORCEINLINE __forceinline
    230 #else
    231 #define FORCEINLINE __inline
    232 #endif
    233 #endif /* FORCEINLINE */
    234 
    235 #ifndef DECLSPEC_NOINLINE
    236 #if (_MSC_VER >= 1300)
    237 #define DECLSPEC_NOINLINE  __declspec(noinline)
    238 #elif defined(__GNUC__)
    239 #define DECLSPEC_NOINLINE __attribute__((noinline))
    240 #else
    241 #define DECLSPEC_NOINLINE
    242 #endif
    243 #endif /* DECLSPEC_NOINLINE */
    244 
    245 #if !defined(_M_CEE_PURE)
    246 #define NTAPI_INLINE    NTAPI
    247 #else
    248 #define NTAPI_INLINE
    249 #endif
    250 
    251 /* Use to specify structure alignment */
    252 #ifndef DECLSPEC_ALIGN
    253 #if defined(_MSC_VER) && (_MSC_VER >= 1300) && !defined(MIDL_PASS)
    254 #define DECLSPEC_ALIGN(x) __declspec(align(x))
    255 #elif defined(__GNUC__)
    256 #define DECLSPEC_ALIGN(x) __attribute__ ((__aligned__ (x)))
    257 #else
    258 #define DECLSPEC_ALIGN(x)
    259 #endif
    260 #endif /* DECLSPEC_ALIGN */
    261 
    262 #ifndef SYSTEM_CACHE_ALIGNMENT_SIZE
    263 #if defined(_AMD64_) || defined(_X86_)
    264 #define SYSTEM_CACHE_ALIGNMENT_SIZE 64
    265 #else
    266 #define SYSTEM_CACHE_ALIGNMENT_SIZE 128
    267 #endif
    268 #endif
    269 
    270 #ifndef DECLSPEC_CACHEALIGN
    271 #define DECLSPEC_CACHEALIGN DECLSPEC_ALIGN(SYSTEM_CACHE_ALIGNMENT_SIZE)
    272 #endif
    273 
    274 #ifndef DECLSPEC_SELECTANY
    275 #if (_MSC_VER >= 1100) || defined(__GNUC__)
    276 #define DECLSPEC_SELECTANY __declspec(selectany)
    277 #else
    278 #define DECLSPEC_SELECTANY
    279 #endif
    280 #endif
    281 
    282 /* Use to silence unused variable warnings when it is intentional */
    283 #define UNREFERENCED_PARAMETER(P) {(P) = (P);}
    284 #define UNREFERENCED_LOCAL_VARIABLE(L) {(L) = (L);}
    285 #define DBG_UNREFERENCED_PARAMETER(P) (P)
    286 #define DBG_UNREFERENCED_LOCAL_VARIABLE(L) (L)
    287 
    288 /* min/max helper macros */
    289 #ifndef NOMINMAX
    290 
    291 #ifndef min
    292 #define min(a,b) (((a) < (b)) ? (a) : (b))
    293 #endif
    294 
    295 #ifndef max
    296 #define max(a,b) (((a) > (b)) ? (a) : (b))
    297 #endif
    298 
    299 #endif /* NOMINMAX */
    300 
    301 /* Tell windef.h that we have defined some basic types */
    302 #define BASETYPES
    303 
    304 /* Void Pointers */
    305 typedef void *PVOID;
    306 typedef void * POINTER_64 PVOID64;
    307 
    308 /* Handle Type */
    309 #ifdef STRICT
    310 typedef void *HANDLE;
    311 #define DECLARE_HANDLE(n) typedef struct n##__{int i;}*n
    312 #else
    313 typedef PVOID HANDLE;
    314 #define DECLARE_HANDLE(n) typedef HANDLE n
    315 #endif
    316 typedef HANDLE *PHANDLE;
    317 
    318 /* Upper-Case Versions of Some Standard C Types */
    319 #ifndef VOID
    320 #define VOID void
    321 typedef char CHAR;
    322 typedef short SHORT;
    323 typedef __LONG32 LONG;
    324 #if !defined(MIDL_PASS) && !defined (__WIDL__)
    325 typedef int INT;
    326 #endif
    327 #endif
    328 typedef double DOUBLE;
    329 
    330 /* Unsigned Types */
    331 typedef unsigned char UCHAR, *PUCHAR;
    332 typedef unsigned short USHORT, *PUSHORT;
    333 typedef unsigned __LONG32 ULONG, *PULONG;
    334 typedef CONST UCHAR *PCUCHAR;
    335 typedef CONST USHORT *PCUSHORT;
    336 typedef CONST ULONG *PCULONG;
    337 typedef UCHAR FCHAR;
    338 typedef USHORT FSHORT;
    339 typedef ULONG FLONG;
    340 typedef UCHAR BOOLEAN, *PBOOLEAN;
    341 typedef ULONG LOGICAL;
    342 typedef ULONG *PLOGICAL;
    343 
    344 /* Signed Types */
    345 typedef SHORT *PSHORT;
    346 typedef LONG *PLONG;
    347 typedef LONG NTSTATUS;
    348 typedef NTSTATUS *PNTSTATUS;
    349 typedef signed char SCHAR;
    350 typedef SCHAR *PSCHAR;
    351 
    352 #ifndef _DEF_WINBOOL_
    353 #define _DEF_WINBOOL_
    354 typedef int WINBOOL;
    355 #pragma push_macro("BOOL")
    356 #undef BOOL
    357 #if !defined(__OBJC__) && !defined(__OBJC_BOOL) && !defined(__objc_INCLUDE_GNU)
    358 typedef int BOOL;
    359 #endif
    360 #define BOOL WINBOOL
    361 typedef BOOL *PBOOL;
    362 typedef BOOL *LPBOOL;
    363 #pragma pop_macro("BOOL")
    364 #endif /* _DEF_WINBOOL_ */
    365 
    366 #ifndef _HRESULT_DEFINED
    367 #define _HRESULT_DEFINED
    368 typedef LONG HRESULT;
    369 #endif
    370 
    371 /* 64-bit types */
    372 #define _ULONGLONG_
    373 __MINGW_EXTENSION typedef __int64 LONGLONG, *PLONGLONG;
    374 __MINGW_EXTENSION typedef unsigned __int64 ULONGLONG, *PULONGLONG;
    375 #define _DWORDLONG_
    376 typedef ULONGLONG DWORDLONG, *PDWORDLONG;
    377 
    378 /* Update Sequence Number */
    379 typedef LONGLONG USN;
    380 
    381 /* ANSI (Multi-byte Character) types */
    382 typedef CHAR *PCHAR, *LPCH, *PCH;
    383 typedef CONST CHAR *LPCCH, *PCCH;
    384 typedef CHAR *NPSTR, *LPSTR, *PSTR;
    385 typedef PSTR *PZPSTR;
    386 typedef CONST PSTR *PCZPSTR;
    387 typedef CONST CHAR *LPCSTR, *PCSTR;
    388 typedef PCSTR *PZPCSTR;
    389 
    390 /* Pointer to an Asciiz string */
    391 typedef CHAR *PSZ;
    392 typedef CONST char *PCSZ;
    393 
    394 /* UNICODE (Wide Character) types */
    395 #ifndef __WCHAR_DEFINED
    396 #define __WCHAR_DEFINED
    397 typedef wchar_t WCHAR;
    398 #endif
    399 typedef WCHAR *PWCHAR, *LPWCH, *PWCH;
    400 typedef CONST WCHAR *LPCWCH, *PCWCH;
    401 typedef WCHAR *NWPSTR, *LPWSTR, *PWSTR;
    402 typedef PWSTR *PZPWSTR;
    403 typedef CONST PWSTR *PCZPWSTR;
    404 typedef WCHAR UNALIGNED *LPUWSTR, *PUWSTR;
    405 typedef CONST WCHAR *LPCWSTR, *PCWSTR;
    406 typedef PCWSTR *PZPCWSTR;
    407 typedef CONST WCHAR UNALIGNED *LPCUWSTR, *PCUWSTR;
    408 
    409 /* Cardinal Data Types */
    410 typedef char CCHAR, *PCCHAR;
    411 typedef short CSHORT, *PCSHORT;
    412 typedef ULONG CLONG, *PCLONG;
    413 
    414 /* NLS basics (Locale and Language Ids) */
    415 typedef ULONG LCID;
    416 typedef PULONG PLCID;
    417 typedef USHORT LANGID;
    418 
    419 /* Used to store a non-float 8 byte aligned structure */
    420 typedef struct _QUAD {
    421   __C89_NAMELESS union {
    422     __MINGW_EXTENSION __int64 UseThisFieldToCopy;
    423     double DoNotUseThisField;
    424   } DUMMYUNIONNAME;
    425 } QUAD, *PQUAD, UQUAD, *PUQUAD;
    426 
    427 #ifndef _LARGE_INTEGER_DEFINED
    428 #define _LARGE_INTEGER_DEFINED
    429 /* Large Integer Unions */
    430 #if defined(MIDL_PASS) || defined (__WIDL__)
    431 typedef struct _LARGE_INTEGER {
    432 #else
    433 typedef union _LARGE_INTEGER {
    434   __C89_NAMELESS struct {
    435     ULONG LowPart;
    436     LONG HighPart;
    437   } DUMMYSTRUCTNAME;
    438   struct {
    439     ULONG LowPart;
    440     LONG HighPart;
    441   } u;
    442 #endif /* MIDL_PASS */
    443   LONGLONG QuadPart;
    444 } LARGE_INTEGER, *PLARGE_INTEGER;
    445 
    446 #if defined(MIDL_PASS) || defined (__WIDL__)
    447 typedef struct _ULARGE_INTEGER {
    448 #else
    449 typedef union _ULARGE_INTEGER {
    450   __C89_NAMELESS struct {
    451     ULONG LowPart;
    452     ULONG HighPart;
    453   } DUMMYSTRUCTNAME;
    454   struct {
    455     ULONG LowPart;
    456     ULONG HighPart;
    457   } u;
    458 #endif /* MIDL_PASS */
    459   ULONGLONG QuadPart;
    460 } ULARGE_INTEGER, *PULARGE_INTEGER;
    461 
    462 /* Locally Unique Identifier */
    463 typedef struct _LUID {
    464   ULONG LowPart;
    465   LONG HighPart;
    466 } LUID, *PLUID;
    467 
    468 #endif /* _LARGE_INTEGER_DEFINED */
    469 
    470 /* Physical Addresses are always treated as 64-bit wide */
    471 typedef LARGE_INTEGER PHYSICAL_ADDRESS, *PPHYSICAL_ADDRESS;
    472 
    473 /* Native API Return Value Macros */
    474 #define NT_SUCCESS(Status)              (((NTSTATUS)(Status)) >= 0)
    475 #define NT_INFORMATION(Status)          ((((ULONG)(Status)) >> 30) == 1)
    476 #define NT_WARNING(Status)              ((((ULONG)(Status)) >> 30) == 2)
    477 #define NT_ERROR(Status)                ((((ULONG)(Status)) >> 30) == 3)
    478 
    479 /* String Types */
    480 #ifndef __UNICODE_STRING_DEFINED
    481 #define __UNICODE_STRING_DEFINED
    482 typedef struct _UNICODE_STRING {
    483   USHORT Length;
    484   USHORT MaximumLength;
    485   PWSTR  Buffer;
    486 } UNICODE_STRING, *PUNICODE_STRING;
    487 #endif
    488 typedef const UNICODE_STRING* PCUNICODE_STRING;
    489 
    490 #define UNICODE_NULL ((WCHAR)0)
    491 
    492 typedef struct _CSTRING {
    493   USHORT Length;
    494   USHORT MaximumLength;
    495   CONST CHAR *Buffer;
    496 } CSTRING, *PCSTRING;
    497 #define ANSI_NULL ((CHAR)0)
    498 
    499 #ifndef __STRING_DEFINED
    500 #define __STRING_DEFINED
    501 typedef struct _STRING {
    502   USHORT Length;
    503   USHORT MaximumLength;
    504   PCHAR  Buffer;
    505 } STRING, *PSTRING;
    506 #endif
    507 
    508 typedef STRING ANSI_STRING;
    509 typedef PSTRING PANSI_STRING;
    510 typedef STRING OEM_STRING;
    511 typedef PSTRING POEM_STRING;
    512 typedef CONST STRING* PCOEM_STRING;
    513 typedef STRING CANSI_STRING;
    514 typedef PSTRING PCANSI_STRING;
    515 
    516 typedef struct _STRING32 {
    517   USHORT Length;
    518   USHORT MaximumLength;
    519   ULONG  Buffer;
    520 } STRING32, *PSTRING32,
    521   UNICODE_STRING32, *PUNICODE_STRING32,
    522   ANSI_STRING32, *PANSI_STRING32;
    523 
    524 typedef struct _STRING64 {
    525   USHORT Length;
    526   USHORT MaximumLength;
    527   ULONGLONG Buffer;
    528 } STRING64, *PSTRING64,
    529   UNICODE_STRING64, *PUNICODE_STRING64,
    530   ANSI_STRING64, *PANSI_STRING64;
    531 
    532 /* LangID and NLS */
    533 #define MAKELANGID(p, s)       ((((USHORT)(s)) << 10) | (USHORT)(p))
    534 #define PRIMARYLANGID(lgid)    ((USHORT)(lgid) & 0x3ff)
    535 #define SUBLANGID(lgid)        ((USHORT)(lgid) >> 10)
    536 
    537 #define NLS_VALID_LOCALE_MASK  0x000fffff
    538 
    539 #define MAKELCID(lgid, srtid)  ((ULONG)((((ULONG)((USHORT)(srtid))) << 16) |  \
    540                                          ((ULONG)((USHORT)(lgid)))))
    541 #define MAKESORTLCID(lgid, srtid, ver)                                        \
    542                                ((ULONG)((MAKELCID(lgid, srtid)) |             \
    543                                     (((ULONG)((USHORT)(ver))) << 20)))
    544 #define LANGIDFROMLCID(lcid)   ((USHORT)(lcid))
    545 #define SORTIDFROMLCID(lcid)   ((USHORT)((((ULONG)(lcid)) >> 16) & 0xf))
    546 #define SORTVERSIONFROMLCID(lcid)  ((USHORT)((((ULONG)(lcid)) >> 20) & 0xf))
    547 
    548 
    549 /* Object Attributes */
    550 #ifndef __OBJECT_ATTRIBUTES_DEFINED
    551 #define __OBJECT_ATTRIBUTES_DEFINED
    552 typedef struct _OBJECT_ATTRIBUTES {
    553   ULONG Length;
    554   HANDLE RootDirectory;
    555   PUNICODE_STRING ObjectName;
    556   ULONG Attributes;
    557   PVOID SecurityDescriptor;
    558   PVOID SecurityQualityOfService;
    559 } OBJECT_ATTRIBUTES, *POBJECT_ATTRIBUTES;
    560 #endif
    561 typedef CONST OBJECT_ATTRIBUTES *PCOBJECT_ATTRIBUTES;
    562 
    563 /* Values for the Attributes member */
    564 #define OBJ_INHERIT             0x00000002
    565 #define OBJ_PERMANENT           0x00000010
    566 #define OBJ_EXCLUSIVE           0x00000020
    567 #define OBJ_CASE_INSENSITIVE    0x00000040
    568 #define OBJ_OPENIF              0x00000080
    569 #define OBJ_OPENLINK            0x00000100
    570 #define OBJ_KERNEL_HANDLE       0x00000200
    571 #define OBJ_FORCE_ACCESS_CHECK  0x00000400
    572 #define OBJ_VALID_ATTRIBUTES    0x000007F2
    573 
    574 /* Helper Macro */
    575 #define InitializeObjectAttributes(p,n,a,r,s) { \
    576   (p)->Length = sizeof(OBJECT_ATTRIBUTES); \
    577   (p)->RootDirectory = (r); \
    578   (p)->Attributes = (a); \
    579   (p)->ObjectName = (n); \
    580   (p)->SecurityDescriptor = (s); \
    581   (p)->SecurityQualityOfService = NULL; \
    582 }
    583 
    584 /* Product Types */
    585 typedef enum _NT_PRODUCT_TYPE {
    586   NtProductWinNt = 1,
    587   NtProductLanManNt,
    588   NtProductServer
    589 } NT_PRODUCT_TYPE, *PNT_PRODUCT_TYPE;
    590 
    591 typedef enum _EVENT_TYPE {
    592   NotificationEvent,
    593   SynchronizationEvent
    594 } EVENT_TYPE;
    595 
    596 typedef enum _TIMER_TYPE {
    597   NotificationTimer,
    598   SynchronizationTimer
    599 } TIMER_TYPE;
    600 
    601 typedef enum _WAIT_TYPE {
    602   WaitAll,
    603   WaitAny
    604 } WAIT_TYPE;
    605 
    606 #ifndef _LIST_ENTRY_DEFINED
    607 #define _LIST_ENTRY_DEFINED
    608 
    609 /* Doubly Linked Lists */
    610 typedef struct _LIST_ENTRY {
    611   struct _LIST_ENTRY *Flink;
    612   struct _LIST_ENTRY *Blink;
    613 } LIST_ENTRY, *PLIST_ENTRY, *RESTRICTED_POINTER PRLIST_ENTRY;
    614 
    615 typedef struct LIST_ENTRY32 {
    616   ULONG Flink;
    617   ULONG Blink;
    618 } LIST_ENTRY32, *PLIST_ENTRY32;
    619 
    620 typedef struct LIST_ENTRY64 {
    621   ULONGLONG Flink;
    622   ULONGLONG Blink;
    623 } LIST_ENTRY64, *PLIST_ENTRY64;
    624 
    625 /* Singly Linked Lists */
    626 typedef struct _SINGLE_LIST_ENTRY {
    627   struct _SINGLE_LIST_ENTRY *Next;
    628 } SINGLE_LIST_ENTRY, *PSINGLE_LIST_ENTRY;
    629 
    630 #endif /* _LIST_ENTRY_DEFINED */
    631 
    632 #ifndef ___PROCESSOR_NUMBER_DEFINED
    633 #define ___PROCESSOR_NUMBER_DEFINED
    634 typedef struct _PROCESSOR_NUMBER {
    635   USHORT Group;
    636   UCHAR Number;
    637   UCHAR Reserved;
    638 } PROCESSOR_NUMBER, *PPROCESSOR_NUMBER;
    639 #endif /* !___PROCESSOR_NUMBER_DEFINED */
    640 
    641 struct _CONTEXT;
    642 struct _EXCEPTION_RECORD;
    643 
    644 #ifndef __PEXCEPTION_ROUTINE_DEFINED
    645 #define __PEXCEPTION_ROUTINE_DEFINED
    646 typedef EXCEPTION_DISPOSITION
    647 (NTAPI *PEXCEPTION_ROUTINE)(
    648   struct _EXCEPTION_RECORD *ExceptionRecord,
    649   PVOID EstablisherFrame,
    650   struct _CONTEXT *ContextRecord,
    651   PVOID DispatcherContext);
    652 #endif /* __PEXCEPTION_ROUTINE_DEFINED */
    653 
    654 #ifndef ___GROUP_AFFINITY_DEFINED
    655 #define ___GROUP_AFFINITY_DEFINED
    656 typedef struct _GROUP_AFFINITY {
    657   KAFFINITY Mask;
    658   USHORT Group;
    659   USHORT Reserved[3];
    660 } GROUP_AFFINITY, *PGROUP_AFFINITY;
    661 #endif /* !___GROUP_AFFINITY_DEFINED */
    662 
    663 /* Helper Macros */
    664 #define RTL_FIELD_TYPE(type, field)    (((type*)0)->field)
    665 #define RTL_BITS_OF(sizeOfArg)         (sizeof(sizeOfArg) * 8)
    666 #define RTL_BITS_OF_FIELD(type, field) (RTL_BITS_OF(RTL_FIELD_TYPE(type, field)))
    667 
    668 #define RTL_CONSTANT_STRING(s) { sizeof(s)-sizeof((s)[0]), sizeof(s), s }
    669 
    670 #define RTL_FIELD_SIZE(type, field) (sizeof(((type *)0)->field))
    671 
    672 #define RTL_SIZEOF_THROUGH_FIELD(type, field) \
    673     (FIELD_OFFSET(type, field) + RTL_FIELD_SIZE(type, field))
    674 
    675 #define RTL_CONTAINS_FIELD(Struct, Size, Field) \
    676     ( (((PCHAR)(&(Struct)->Field)) + sizeof((Struct)->Field)) <= (((PCHAR)(Struct))+(Size)) )
    677 
    678 #define RTL_NUMBER_OF_V1(A) (sizeof(A)/sizeof((A)[0]))
    679 #define RTL_NUMBER_OF_V2(A) RTL_NUMBER_OF_V1(A)
    680 #ifdef ENABLE_RTL_NUMBER_OF_V2
    681 #define RTL_NUMBER_OF(A) RTL_NUMBER_OF_V2(A)
    682 #else
    683 #define RTL_NUMBER_OF(A) RTL_NUMBER_OF_V1(A)
    684 #endif
    685 #define ARRAYSIZE(A)    RTL_NUMBER_OF_V2(A)
    686 
    687 /* Type Limits */
    688 #define MINCHAR   0x80
    689 #define MAXCHAR   0x7f
    690 #define MINSHORT  0x8000
    691 #define MAXSHORT  0x7fff
    692 #define MINLONG   0x80000000
    693 #define MAXLONG   0x7fffffff
    694 #define MAXUCHAR  0xff
    695 #define MAXUSHORT 0xffff
    696 #define MAXULONG  0xffffffff
    697 #define MAXLONGLONG (0x7fffffffffffffffLL)
    698 
    699 /* Multiplication and Shift Operations */
    700 #define Int32x32To64(a,b) ((LONGLONG)(a)*(LONGLONG)(b))
    701 #define UInt32x32To64(a,b) ((ULONGLONG)(a)*(ULONGLONG)(b))
    702 #define Int64ShllMod32(a,b) ((ULONGLONG)(a)<<(b))
    703 #define Int64ShraMod32(a,b) ((LONGLONG)(a)>>(b))
    704 #define Int64ShrlMod32(a,b) ((ULONGLONG)(a)>>(b))
    705 
    706 /* C_ASSERT Definition */
    707 #define C_ASSERT(expr) extern char (*c_assert(void)) [(expr) ? 1 : -1]
    708 
    709 #define VER_WORKSTATION_NT                  0x40000000
    710 #define VER_SERVER_NT                       0x80000000
    711 #define VER_SUITE_SMALLBUSINESS             0x00000001
    712 #define VER_SUITE_ENTERPRISE                0x00000002
    713 #define VER_SUITE_BACKOFFICE                0x00000004
    714 #define VER_SUITE_COMMUNICATIONS            0x00000008
    715 #define VER_SUITE_TERMINAL                  0x00000010
    716 #define VER_SUITE_SMALLBUSINESS_RESTRICTED  0x00000020
    717 #define VER_SUITE_EMBEDDEDNT                0x00000040
    718 #define VER_SUITE_DATACENTER                0x00000080
    719 #define VER_SUITE_SINGLEUSERTS              0x00000100
    720 #define VER_SUITE_PERSONAL                  0x00000200
    721 #define VER_SUITE_BLADE                     0x00000400
    722 #define VER_SUITE_EMBEDDED_RESTRICTED       0x00000800
    723 #define VER_SUITE_SECURITY_APPLIANCE        0x00001000
    724 #define VER_SUITE_STORAGE_SERVER            0x00002000
    725 #define VER_SUITE_COMPUTE_SERVER            0x00004000
    726 #define VER_SUITE_WH_SERVER                 0x00008000
    727 
    728 /*  Primary language IDs. */
    729 #define LANG_NEUTRAL                              0x00
    730 #define LANG_INVARIANT                            0x7f
    731 
    732 #define LANG_AFRIKAANS                            0x36
    733 #define LANG_ALBANIAN                             0x1c
    734 #define LANG_ALSATIAN                             0x84
    735 #define LANG_AMHARIC                              0x5e
    736 #define LANG_ARABIC                               0x01
    737 #define LANG_ARMENIAN                             0x2b
    738 #define LANG_ASSAMESE                             0x4d
    739 #define LANG_AZERI                                0x2c
    740 #define LANG_BASHKIR                              0x6d
    741 #define LANG_BASQUE                               0x2d
    742 #define LANG_BELARUSIAN                           0x23
    743 #define LANG_BENGALI                              0x45
    744 #define LANG_BRETON                               0x7e
    745 #define LANG_BOSNIAN                              0x1a
    746 #define LANG_BOSNIAN_NEUTRAL                    0x781a
    747 #define LANG_BULGARIAN                            0x02
    748 #define LANG_CATALAN                              0x03
    749 #define LANG_CHINESE                              0x04
    750 #define LANG_CHINESE_SIMPLIFIED                   0x04
    751 #define LANG_CHINESE_TRADITIONAL                0x7c04
    752 #define LANG_CORSICAN                             0x83
    753 #define LANG_CROATIAN                             0x1a
    754 #define LANG_CZECH                                0x05
    755 #define LANG_DANISH                               0x06
    756 #define LANG_DARI                                 0x8c
    757 #define LANG_DIVEHI                               0x65
    758 #define LANG_DUTCH                                0x13
    759 #define LANG_ENGLISH                              0x09
    760 #define LANG_ESTONIAN                             0x25
    761 #define LANG_FAEROESE                             0x38
    762 #define LANG_FARSI                                0x29
    763 #define LANG_FILIPINO                             0x64
    764 #define LANG_FINNISH                              0x0b
    765 #define LANG_FRENCH                               0x0c
    766 #define LANG_FRISIAN                              0x62
    767 #define LANG_GALICIAN                             0x56
    768 #define LANG_GEORGIAN                             0x37
    769 #define LANG_GERMAN                               0x07
    770 #define LANG_GREEK                                0x08
    771 #define LANG_GREENLANDIC                          0x6f
    772 #define LANG_GUJARATI                             0x47
    773 #define LANG_HAUSA                                0x68
    774 #define LANG_HEBREW                               0x0d
    775 #define LANG_HINDI                                0x39
    776 #define LANG_HUNGARIAN                            0x0e
    777 #define LANG_ICELANDIC                            0x0f
    778 #define LANG_IGBO                                 0x70
    779 #define LANG_INDONESIAN                           0x21
    780 #define LANG_INUKTITUT                            0x5d
    781 #define LANG_IRISH                                0x3c
    782 #define LANG_ITALIAN                              0x10
    783 #define LANG_JAPANESE                             0x11
    784 #define LANG_KANNADA                              0x4b
    785 #define LANG_KASHMIRI                             0x60
    786 #define LANG_KAZAK                                0x3f
    787 #define LANG_KHMER                                0x53
    788 #define LANG_KICHE                                0x86
    789 #define LANG_KINYARWANDA                          0x87
    790 #define LANG_KONKANI                              0x57
    791 #define LANG_KOREAN                               0x12
    792 #define LANG_KYRGYZ                               0x40
    793 #define LANG_LAO                                  0x54
    794 #define LANG_LATVIAN                              0x26
    795 #define LANG_LITHUANIAN                           0x27
    796 #define LANG_LOWER_SORBIAN                        0x2e
    797 #define LANG_LUXEMBOURGISH                        0x6e
    798 #define LANG_MACEDONIAN                           0x2f
    799 #define LANG_MALAY                                0x3e
    800 #define LANG_MALAYALAM                            0x4c
    801 #define LANG_MALTESE                              0x3a
    802 #define LANG_MANIPURI                             0x58
    803 #define LANG_MAORI                                0x81
    804 #define LANG_MAPUDUNGUN                           0x7a
    805 #define LANG_MARATHI                              0x4e
    806 #define LANG_MOHAWK                               0x7c
    807 #define LANG_MONGOLIAN                            0x50
    808 #define LANG_NEPALI                               0x61
    809 #define LANG_NORWEGIAN                            0x14
    810 #define LANG_OCCITAN                              0x82
    811 #define LANG_ORIYA                                0x48
    812 #define LANG_PASHTO                               0x63
    813 #define LANG_PERSIAN                              0x29
    814 #define LANG_POLISH                               0x15
    815 #define LANG_PORTUGUESE                           0x16
    816 #define LANG_PUNJABI                              0x46
    817 #define LANG_QUECHUA                              0x6b
    818 #define LANG_ROMANIAN                             0x18
    819 #define LANG_ROMANSH                              0x17
    820 #define LANG_RUSSIAN                              0x19
    821 #define LANG_SAMI                                 0x3b
    822 #define LANG_SANSKRIT                             0x4f
    823 #define LANG_SERBIAN                              0x1a
    824 #define LANG_SERBIAN_NEUTRAL                    0x7c1a
    825 #define LANG_SINDHI                               0x59
    826 #define LANG_SINHALESE                            0x5b
    827 #define LANG_SLOVAK                               0x1b
    828 #define LANG_SLOVENIAN                            0x24
    829 #define LANG_SOTHO                                0x6c
    830 #define LANG_SPANISH                              0x0a
    831 #define LANG_SWAHILI                              0x41
    832 #define LANG_SWEDISH                              0x1d
    833 #define LANG_SYRIAC                               0x5a
    834 #define LANG_TAJIK                                0x28
    835 #define LANG_TAMAZIGHT                            0x5f
    836 #define LANG_TAMIL                                0x49
    837 #define LANG_TATAR                                0x44
    838 #define LANG_TELUGU                               0x4a
    839 #define LANG_THAI                                 0x1e
    840 #define LANG_TIBETAN                              0x51
    841 #define LANG_TIGRIGNA                             0x73
    842 #define LANG_TSWANA                               0x32
    843 #define LANG_TURKISH                              0x1f
    844 #define LANG_TURKMEN                              0x42
    845 #define LANG_UIGHUR                               0x80
    846 #define LANG_UKRAINIAN                            0x22
    847 #define LANG_UPPER_SORBIAN                        0x2e
    848 #define LANG_URDU                                 0x20
    849 #define LANG_UZBEK                                0x43
    850 #define LANG_VIETNAMESE                           0x2a
    851 #define LANG_WELSH                                0x52
    852 #define LANG_WOLOF                                0x88
    853 #define LANG_XHOSA                                0x34
    854 #define LANG_YAKUT                                0x85
    855 #define LANG_YI                                   0x78
    856 #define LANG_YORUBA                               0x6a
    857 #define LANG_ZULU                                 0x35
    858 
    859 #ifndef NT_INCLUDED
    860 
    861 #define FILE_ATTRIBUTE_VALID_FLAGS 0x00007fb7
    862 #define FILE_SHARE_VALID_FLAGS (FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE)
    863 
    864 #define FILE_SUPERSEDE                    0x00000000
    865 #define FILE_OPEN                         0x00000001
    866 #define FILE_CREATE                       0x00000002
    867 #define FILE_OPEN_IF                      0x00000003
    868 #define FILE_OVERWRITE                    0x00000004
    869 #define FILE_OVERWRITE_IF                 0x00000005
    870 #define FILE_MAXIMUM_DISPOSITION          0x00000005
    871 
    872 #define FILE_DIRECTORY_FILE               0x00000001
    873 #define FILE_WRITE_THROUGH                0x00000002
    874 #define FILE_SEQUENTIAL_ONLY              0x00000004
    875 #define FILE_NO_INTERMEDIATE_BUFFERING    0x00000008
    876 #define FILE_SYNCHRONOUS_IO_ALERT         0x00000010
    877 #define FILE_SYNCHRONOUS_IO_NONALERT      0x00000020
    878 #define FILE_NON_DIRECTORY_FILE           0x00000040
    879 #define FILE_CREATE_TREE_CONNECTION       0x00000080
    880 #define FILE_COMPLETE_IF_OPLOCKED         0x00000100
    881 #define FILE_NO_EA_KNOWLEDGE              0x00000200
    882 #define FILE_OPEN_REMOTE_INSTANCE         0x00000400
    883 #define FILE_RANDOM_ACCESS                0x00000800
    884 #define FILE_DELETE_ON_CLOSE              0x00001000
    885 #define FILE_OPEN_BY_FILE_ID              0x00002000
    886 #define FILE_OPEN_FOR_BACKUP_INTENT       0x00004000
    887 #define FILE_NO_COMPRESSION               0x00008000
    888 #if (NTDDI_VERSION >= NTDDI_WIN7)
    889 #define FILE_OPEN_REQUIRING_OPLOCK        0x00010000
    890 #define FILE_DISALLOW_EXCLUSIVE           0x00020000
    891 #endif /* (NTDDI_VERSION >= NTDDI_WIN7) */
    892 #define FILE_RESERVE_OPFILTER             0x00100000
    893 #define FILE_OPEN_REPARSE_POINT           0x00200000
    894 #define FILE_OPEN_NO_RECALL               0x00400000
    895 #define FILE_OPEN_FOR_FREE_SPACE_QUERY    0x00800000
    896 
    897 typedef struct _REPARSE_DATA_BUFFER
    898 {
    899   ULONG  ReparseTag;
    900   USHORT ReparseDataLength;
    901   USHORT Reserved;
    902   union
    903   {
    904     struct
    905     {
    906       USHORT SubstituteNameOffset;
    907       USHORT SubstituteNameLength;
    908       USHORT PrintNameOffset;
    909       USHORT PrintNameLength;
    910       ULONG  Flags;
    911       WCHAR  PathBuffer[1];
    912     } SymbolicLinkReparseBuffer;
    913     struct
    914     {
    915       USHORT SubstituteNameOffset;
    916       USHORT SubstituteNameLength;
    917       USHORT PrintNameOffset;
    918       USHORT PrintNameLength;
    919       WCHAR  PathBuffer[1];
    920     } MountPointReparseBuffer;
    921     struct
    922     {
    923       UCHAR  DataBuffer[1];
    924     } GenericReparseBuffer;
    925   };
    926 } REPARSE_DATA_BUFFER, *PREPARSE_DATA_BUFFER;
    927 
    928 #define REPARSE_DATA_BUFFER_HEADER_SIZE      FIELD_OFFSET(REPARSE_DATA_BUFFER, GenericReparseBuffer)
    929 
    930 #endif /* !NT_DEFINED */
    931 
    932 #endif /* _NTDEF_ */
    933 
    934