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