ntdef.h 31 KB

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