[PSDK]
[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
420 /* Avoid redefinition in windef.h */
421 #define BASETYPES
422
423 /* Unsigned Types */
424 typedef unsigned char UCHAR, *PUCHAR;
425 typedef unsigned short USHORT, *PUSHORT;
426 typedef unsigned long ULONG, *PULONG;
427
428 typedef CONST UCHAR *PCUCHAR;
429 typedef CONST USHORT *PCUSHORT;
430 typedef CONST ULONG *PCULONG;
431
432 typedef double DOUBLE;
433
434 /* Signed Types */
435 typedef SHORT *PSHORT;
436 typedef LONG *PLONG;
437
438 /* Flag types */
439 typedef unsigned char FCHAR;
440 typedef unsigned short FSHORT;
441 typedef unsigned long FLONG;
442
443 typedef unsigned char BOOLEAN, *PBOOLEAN;
444 typedef ULONG LOGICAL, *PLOGICAL;
445 typedef _Return_type_success_(return >= 0) LONG NTSTATUS, *PNTSTATUS;;
446 typedef signed char SCHAR, *PSCHAR;
447
448 #ifndef _HRESULT_DEFINED
449 #define _HRESULT_DEFINED
450 typedef _Return_type_success_(return >= 0) LONG HRESULT;
451 #endif
452
453 /* 64-bit types */
454 #define _ULONGLONG_
455 __GNU_EXTENSION typedef __int64 LONGLONG, *PLONGLONG;
456 __GNU_EXTENSION typedef unsigned __int64 ULONGLONG, *PULONGLONG;
457 #define _DWORDLONG_
458 typedef ULONGLONG DWORDLONG, *PDWORDLONG;
459
460 /* Update Sequence Number */
461 typedef LONGLONG USN;
462
463 /* ANSI (Multi-byte Character) types */
464 typedef CHAR *PCHAR, *LPCH, *PCH, *PNZCH;
465 typedef CONST CHAR *LPCCH, *PCCH, *PCNZCH;
466 typedef _Null_terminated_ CHAR *NPSTR, *LPSTR, *PSTR;
467 typedef _Null_terminated_ PSTR *PZPSTR;
468 typedef _Null_terminated_ CONST PSTR *PCZPSTR;
469 typedef _Null_terminated_ CONST CHAR *LPCSTR, *PCSTR;
470 typedef _Null_terminated_ PCSTR *PZPCSTR;
471
472 typedef _NullNull_terminated_ CHAR *PZZSTR;
473 typedef _NullNull_terminated_ CONST CHAR *PCZZSTR;
474
475 /* Pointer to an Asciiz string */
476 typedef _Null_terminated_ CHAR *PSZ;
477 typedef _Null_terminated_ CONST char *PCSZ;
478
479 /* UNICODE (Wide Character) types */
480 typedef wchar_t WCHAR;
481 typedef WCHAR *PWCHAR, *LPWCH, *PWCH;
482 typedef CONST WCHAR *LPCWCH, *PCWCH;
483 typedef _Null_terminated_ WCHAR *NWPSTR, *LPWSTR, *PWSTR;
484 typedef _Null_terminated_ PWSTR *PZPWSTR;
485 typedef _Null_terminated_ CONST PWSTR *PCZPWSTR;
486 typedef _Null_terminated_ WCHAR UNALIGNED *LPUWSTR, *PUWSTR;
487 typedef _Null_terminated_ CONST WCHAR *LPCWSTR, *PCWSTR;
488 typedef _Null_terminated_ PCWSTR *PZPCWSTR;
489 typedef _Null_terminated_ CONST WCHAR UNALIGNED *LPCUWSTR, *PCUWSTR;
490
491 typedef _NullNull_terminated_ WCHAR *PZZWSTR;
492 typedef _NullNull_terminated_ CONST WCHAR *PCZZWSTR;
493 typedef _NullNull_terminated_ WCHAR UNALIGNED *PUZZWSTR;
494 typedef _NullNull_terminated_ CONST WCHAR UNALIGNED *PCUZZWSTR;
495
496 typedef WCHAR *PNZWCH;
497 typedef CONST WCHAR *PCNZWCH;
498 typedef WCHAR UNALIGNED *PUNZWCH;
499 typedef CONST WCHAR UNALIGNED *PCUNZWCH;
500
501 #if (_WIN32_WINNT >= 0x0600) || (defined(__cplusplus) && defined(WINDOWS_ENABLE_CPLUSPLUS))
502 typedef CONST WCHAR *LPCWCHAR, *PCWCHAR;
503 typedef CONST WCHAR UNALIGNED *LPCUWCHAR, *PCUWCHAR;
504 typedef unsigned long UCSCHAR, *PUCSCHAR, *PUCSSTR;
505 typedef const UCSCHAR *PCUCSCHAR, *PCUCSSTR;
506 typedef UCSCHAR UNALIGNED *PUUCSCHAR, *PUUCSSTR;
507 typedef const UCSCHAR UNALIGNED *PCUUCSCHAR, *PCUUCSSTR;
508 #define UCSCHAR_INVALID_CHARACTER (0xffffffff)
509 #define MIN_UCSCHAR (0)
510 #define MAX_UCSCHAR (0x0010FFFF)
511 #endif /* _WIN32_WINNT >= 0x0600 */
512
513 #ifdef UNICODE
514
515 #ifndef _TCHAR_DEFINED
516 typedef WCHAR TCHAR, *PTCHAR;
517 typedef WCHAR TUCHAR, *PTUCHAR;
518 #define _TCHAR_DEFINED
519 #endif /* !_TCHAR_DEFINED */
520 typedef LPWCH LPTCH, PTCH;
521 typedef LPCWCH LPCTCH, PCTCH;
522 typedef LPWSTR PTSTR, LPTSTR;
523 typedef LPCWSTR PCTSTR, LPCTSTR;
524 typedef LPUWSTR PUTSTR, LPUTSTR;
525 typedef LPCUWSTR PCUTSTR, LPCUTSTR;
526 typedef LPWSTR LP;
527 typedef PZZWSTR PZZTSTR;
528 typedef PCZZWSTR PCZZTSTR;
529 typedef PUZZWSTR PUZZTSTR;
530 typedef PCUZZWSTR PCUZZTSTR;
531 typedef PZPWSTR PZPTSTR;
532 typedef PNZWCH PNZTCH;
533 typedef PCNZWCH PCNZTCH;
534 typedef PUNZWCH PUNZTCH;
535 typedef PCUNZWCH PCUNZTCH;
536 #define __TEXT(quote) L##quote
537
538 #else /* UNICODE */
539
540 #ifndef _TCHAR_DEFINED
541 typedef char TCHAR, *PTCHAR;
542 typedef unsigned char TUCHAR, *PTUCHAR;
543 #define _TCHAR_DEFINED
544 #endif /* !_TCHAR_DEFINED */
545 typedef LPCH LPTCH, PTCH;
546 typedef LPCCH LPCTCH, PCTCH;
547 typedef LPSTR PTSTR, LPTSTR, PUTSTR, LPUTSTR;
548 typedef LPCSTR PCTSTR, LPCTSTR, PCUTSTR, LPCUTSTR;
549 typedef PZZSTR PZZTSTR, PUZZTSTR;
550 typedef PCZZSTR PCZZTSTR, PCUZZTSTR;
551 typedef PZPSTR PZPTSTR;
552 typedef PNZCH PNZTCH, PUNZTCH;
553 typedef PCNZCH PCNZTCH, PCUNZTCH;
554 #define __TEXT(quote) quote // r_winnt
555
556 #endif /* UNICODE */ // r_winnt
557 #define TEXT(quote) __TEXT(quote) // r_winnt
558
559 /* Cardinal Data Types */
560 typedef char CCHAR;
561 typedef CCHAR *PCCHAR;
562 typedef short CSHORT, *PCSHORT;
563 typedef ULONG CLONG, *PCLONG;
564
565 /* NLS basics (Locale and Language Ids) */
566 typedef unsigned long LCID, *PLCID;
567 typedef unsigned short LANGID;
568
569 #ifndef __COMPARTMENT_ID_DEFINED__
570 #define __COMPARTMENT_ID_DEFINED__
571 typedef enum
572 {
573 UNSPECIFIED_COMPARTMENT_ID = 0,
574 DEFAULT_COMPARTMENT_ID
575 } COMPARTMENT_ID, *PCOMPARTMENT_ID;
576 #endif /* __COMPARTMENT_ID_DEFINED__ */
577
578 #ifdef _MSC_VER
579 #pragma warning(push)
580 #pragma warning(disable:4201)
581 #endif
582 /* Used to store a non-float 8 byte aligned structure */
583 typedef struct _QUAD
584 {
585 _ANONYMOUS_UNION union
586 {
587 __GNU_EXTENSION __int64 UseThisFieldToCopy;
588 double DoNotUseThisField;
589 } DUMMYUNIONNAME;
590 } QUAD, *PQUAD, UQUAD, *PUQUAD;
591
592 /* Large Integer Unions */
593 #if defined(MIDL_PASS)
594 typedef struct _LARGE_INTEGER {
595 #else
596 typedef union _LARGE_INTEGER {
597 _ANONYMOUS_STRUCT struct
598 {
599 ULONG LowPart;
600 LONG HighPart;
601 } DUMMYSTRUCTNAME;
602 struct
603 {
604 ULONG LowPart;
605 LONG HighPart;
606 } u;
607 #endif /* MIDL_PASS */
608 LONGLONG QuadPart;
609 } LARGE_INTEGER, *PLARGE_INTEGER;
610
611 #if defined(MIDL_PASS)
612 typedef struct _ULARGE_INTEGER {
613 #else
614 typedef union _ULARGE_INTEGER {
615 _ANONYMOUS_STRUCT struct
616 {
617 ULONG LowPart;
618 ULONG HighPart;
619 } DUMMYSTRUCTNAME;
620 struct
621 {
622 ULONG LowPart;
623 ULONG HighPart;
624 } u;
625 #endif /* MIDL_PASS */
626 ULONGLONG QuadPart;
627 } ULARGE_INTEGER, *PULARGE_INTEGER;
628
629 #ifdef _MSC_VER
630 #pragma warning(pop) /* disable:4201 */
631 #endif
632
633 /* Physical Addresses are always treated as 64-bit wide */
634 typedef LARGE_INTEGER PHYSICAL_ADDRESS, *PPHYSICAL_ADDRESS;
635
636 /* Locally Unique Identifier */
637 typedef struct _LUID {
638 ULONG LowPart;
639 LONG HighPart;
640 } LUID, *PLUID;
641
642 /* Native API Return Value Macros */
643 #define NT_SUCCESS(Status) (((NTSTATUS)(Status)) >= 0)
644 #define NT_INFORMATION(Status) ((((ULONG)(Status)) >> 30) == 1)
645 #define NT_WARNING(Status) ((((ULONG)(Status)) >> 30) == 2)
646 #define NT_ERROR(Status) ((((ULONG)(Status)) >> 30) == 3)
647
648 /* String Types */
649 typedef struct _UNICODE_STRING {
650 USHORT Length;
651 USHORT MaximumLength;
652 #ifdef MIDL_PASS
653 [size_is(MaximumLength / 2), length_is((Length) / 2)] PUSHORT Buffer;
654 #else
655 _Field_size_bytes_part_(MaximumLength, Length) PWCH Buffer;
656 #endif
657 } UNICODE_STRING, *PUNICODE_STRING;
658 typedef const UNICODE_STRING* PCUNICODE_STRING;
659
660 #define UNICODE_NULL ((WCHAR)0)
661 #define UNICODE_STRING_MAX_BYTES ((USHORT) 65534)
662 #define UNICODE_STRING_MAX_CHARS (32767)
663
664 typedef struct _CSTRING {
665 USHORT Length;
666 USHORT MaximumLength;
667 CONST CHAR *Buffer;
668 } CSTRING, *PCSTRING;
669 #define ANSI_NULL ((CHAR)0)
670
671 typedef struct _STRING {
672 USHORT Length;
673 USHORT MaximumLength;
674 #ifdef MIDL_PASS
675 [size_is(MaximumLength), length_is(Length) ]
676 #endif
677 _Field_size_bytes_part_opt_(MaximumLength, Length) PCHAR Buffer;
678 } STRING, *PSTRING;
679
680 typedef STRING ANSI_STRING;
681 typedef PSTRING PANSI_STRING;
682 typedef STRING OEM_STRING;
683 typedef PSTRING POEM_STRING;
684 typedef CONST STRING* PCOEM_STRING;
685 typedef STRING CANSI_STRING;
686 typedef PSTRING PCANSI_STRING;
687
688 typedef struct _STRING32 {
689 USHORT Length;
690 USHORT MaximumLength;
691 ULONG Buffer;
692 } STRING32, *PSTRING32,
693 UNICODE_STRING32, *PUNICODE_STRING32,
694 ANSI_STRING32, *PANSI_STRING32;
695
696 typedef struct _STRING64 {
697 USHORT Length;
698 USHORT MaximumLength;
699 ULONGLONG Buffer;
700 } STRING64, *PSTRING64,
701 UNICODE_STRING64, *PUNICODE_STRING64,
702 ANSI_STRING64, *PANSI_STRING64;
703
704 /* LangID and NLS */
705 #define MAKELANGID(p, s) ((((USHORT)(s)) << 10) | (USHORT)(p))
706 #define PRIMARYLANGID(lgid) ((USHORT)(lgid) & 0x3ff)
707 #define SUBLANGID(lgid) ((USHORT)(lgid) >> 10)
708
709 #define NLS_VALID_LOCALE_MASK 0x000fffff
710
711 #define MAKELCID(lgid, srtid) ((ULONG)((((ULONG)((USHORT)(srtid))) << 16) | \
712 ((ULONG)((USHORT)(lgid)))))
713 #define MAKESORTLCID(lgid, srtid, ver) \
714 ((ULONG)((MAKELCID(lgid, srtid)) | \
715 (((ULONG)((USHORT)(ver))) << 20)))
716 #define LANGIDFROMLCID(lcid) ((USHORT)(lcid))
717 #define SORTIDFROMLCID(lcid) ((USHORT)((((ULONG)(lcid)) >> 16) & 0xf))
718 #define SORTVERSIONFROMLCID(lcid) ((USHORT)((((ULONG)(lcid)) >> 20) & 0xf))
719
720 #define LOCALE_NAME_MAX_LENGTH 85
721
722 /* Object Attributes */
723 typedef struct _OBJECT_ATTRIBUTES {
724 ULONG Length;
725 HANDLE RootDirectory;
726 PUNICODE_STRING ObjectName;
727 ULONG Attributes;
728 PVOID SecurityDescriptor;
729 PVOID SecurityQualityOfService;
730 } OBJECT_ATTRIBUTES, *POBJECT_ATTRIBUTES;
731 typedef CONST OBJECT_ATTRIBUTES *PCOBJECT_ATTRIBUTES;
732
733 typedef struct _OBJECT_ATTRIBUTES32 {
734 ULONG Length;
735 ULONG RootDirectory;
736 ULONG ObjectName;
737 ULONG Attributes;
738 ULONG SecurityDescriptor;
739 ULONG SecurityQualityOfService;
740 } OBJECT_ATTRIBUTES32, *POBJECT_ATTRIBUTES32;
741 typedef CONST OBJECT_ATTRIBUTES32 *PCOBJECT_ATTRIBUTES32;
742
743 typedef struct _OBJECT_ATTRIBUTES64 {
744 ULONG Length;
745 ULONG64 RootDirectory;
746 ULONG64 ObjectName;
747 ULONG Attributes;
748 ULONG64 SecurityDescriptor;
749 ULONG64 SecurityQualityOfService;
750 } OBJECT_ATTRIBUTES64, *POBJECT_ATTRIBUTES64;
751 typedef CONST OBJECT_ATTRIBUTES64 *PCOBJECT_ATTRIBUTES64;
752
753 /* Values for the Attributes member */
754 #define OBJ_INHERIT 0x00000002L
755 #define OBJ_PERMANENT 0x00000010L
756 #define OBJ_EXCLUSIVE 0x00000020L
757 #define OBJ_CASE_INSENSITIVE 0x00000040L
758 #define OBJ_OPENIF 0x00000080L
759 #define OBJ_OPENLINK 0x00000100L
760 #define OBJ_KERNEL_HANDLE 0x00000200L
761 #define OBJ_FORCE_ACCESS_CHECK 0x00000400L
762 #define OBJ_VALID_ATTRIBUTES 0x000007F2L
763
764 /* Helper Macro */
765 #define InitializeObjectAttributes(p,n,a,r,s) { \
766 (p)->Length = sizeof(OBJECT_ATTRIBUTES); \
767 (p)->RootDirectory = (r); \
768 (p)->ObjectName = (n); \
769 (p)->Attributes = (a); \
770 (p)->SecurityDescriptor = (s); \
771 (p)->SecurityQualityOfService = NULL; \
772 }
773
774 #define RTL_CONSTANT_OBJECT_ATTRIBUTES(n,a) { \
775 sizeof(OBJECT_ATTRIBUTES), \
776 NULL, \
777 RTL_CONST_CAST(PUNICODE_STRING)(n), \
778 a, \
779 NULL, \
780 NULL \
781 }
782
783 #define RTL_INIT_OBJECT_ATTRIBUTES(n, a) \
784 RTL_CONSTANT_OBJECT_ATTRIBUTES(n, a)
785
786 /* Product Types */
787 typedef enum _NT_PRODUCT_TYPE {
788 NtProductWinNt = 1,
789 NtProductLanManNt,
790 NtProductServer
791 } NT_PRODUCT_TYPE, *PNT_PRODUCT_TYPE;
792
793 typedef enum _EVENT_TYPE {
794 NotificationEvent,
795 SynchronizationEvent
796 } EVENT_TYPE;
797
798 typedef enum _TIMER_TYPE {
799 NotificationTimer,
800 SynchronizationTimer
801 } TIMER_TYPE;
802
803 typedef enum _WAIT_TYPE {
804 WaitAll,
805 WaitAny
806 } WAIT_TYPE;
807
808 /* Doubly Linked Lists */
809 typedef struct _LIST_ENTRY {
810 struct _LIST_ENTRY *Flink;
811 struct _LIST_ENTRY *Blink;
812 } LIST_ENTRY, *PLIST_ENTRY, *RESTRICTED_POINTER PRLIST_ENTRY;
813
814 typedef struct LIST_ENTRY32 {
815 ULONG Flink;
816 ULONG Blink;
817 } LIST_ENTRY32, *PLIST_ENTRY32;
818
819 typedef struct LIST_ENTRY64 {
820 ULONGLONG Flink;
821 ULONGLONG Blink;
822 } LIST_ENTRY64, *PLIST_ENTRY64;
823
824 /* Singly Linked Lists */
825 typedef struct _SINGLE_LIST_ENTRY {
826 struct _SINGLE_LIST_ENTRY *Next;
827 } SINGLE_LIST_ENTRY, *PSINGLE_LIST_ENTRY;
828
829 typedef struct _SINGLE_LIST_ENTRY32 {
830 ULONG Next;
831 } SINGLE_LIST_ENTRY32, *PSINGLE_LIST_ENTRY32;
832
833 typedef struct _PROCESSOR_NUMBER {
834 USHORT Group;
835 UCHAR Number;
836 UCHAR Reserved;
837 } PROCESSOR_NUMBER, *PPROCESSOR_NUMBER;
838
839 _IRQL_requires_same_
840 _Function_class_(EXCEPTION_ROUTINE)
841 typedef
842 EXCEPTION_DISPOSITION
843 NTAPI
844 EXCEPTION_ROUTINE(
845 _Inout_ struct _EXCEPTION_RECORD *ExceptionRecord,
846 _In_ PVOID EstablisherFrame,
847 _Inout_ struct _CONTEXT *ContextRecord,
848 _In_ PVOID DispatcherContext);
849
850 typedef EXCEPTION_ROUTINE *PEXCEPTION_ROUTINE;
851
852 typedef struct _GROUP_AFFINITY {
853 KAFFINITY Mask;
854 USHORT Group;
855 USHORT Reserved[3];
856 } GROUP_AFFINITY, *PGROUP_AFFINITY;
857
858 /* Helper Macros */
859
860 #define RTL_FIELD_TYPE(type, field) (((type*)0)->field)
861 #define RTL_BITS_OF(sizeOfArg) (sizeof(sizeOfArg) * 8)
862 #define RTL_BITS_OF_FIELD(type, field) (RTL_BITS_OF(RTL_FIELD_TYPE(type, field)))
863
864 #ifdef __cplusplus
865 extern "C++" template<typename _Type> struct _RTL_remove_const_template;
866 extern "C++" template<typename _Type> struct _RTL_remove_const_template<const _Type&> { typedef _Type type; };
867 #define _RTL_CONSTANT_STRING_remove_const_macro(s) \
868 (const_cast<_RTL_remove_const_template<decltype((s)[0])>::type*>(s))
869 extern "C++" template<class _Ty> struct _RTL_CONSTANT_STRING_type_check_template;
870 extern "C++" template<class _Ty, int _Count> struct _RTL_CONSTANT_STRING_type_check_template<const _Ty (&)[_Count]> { typedef char type; };
871 #define _RTL_CONSTANT_STRING_type_check(s) _RTL_CONSTANT_STRING_type_check_template<decltype(s)>::type
872 #else
873 #define _RTL_CONSTANT_STRING_remove_const_macro(s) (s)
874 char _RTL_CONSTANT_STRING_type_check(const void *s);
875 #endif
876 #define RTL_CONSTANT_STRING(s) { \
877 sizeof(s)-sizeof((s)[0]), \
878 sizeof(s) / sizeof(_RTL_CONSTANT_STRING_type_check(s)), \
879 _RTL_CONSTANT_STRING_remove_const_macro(s) }
880
881 #define RTL_FIELD_SIZE(type, field) (sizeof(((type *)0)->field))
882
883 #define RTL_SIZEOF_THROUGH_FIELD(type, field) \
884 (FIELD_OFFSET(type, field) + RTL_FIELD_SIZE(type, field))
885
886 #define RTL_CONTAINS_FIELD(Struct, Size, Field) \
887 ( (((PCHAR)(&(Struct)->Field)) + sizeof((Struct)->Field)) <= (((PCHAR)(Struct))+(Size)) )
888
889 #define RTL_NUMBER_OF_V1(A) (sizeof(A)/sizeof((A)[0]))
890
891 #ifdef __GNUC__
892 #define RTL_NUMBER_OF_V2(A) \
893 (({ int _check_array_type[__builtin_types_compatible_p(typeof(A), typeof(&A[0])) ? -1 : 1]; (void)_check_array_type; }), \
894 RTL_NUMBER_OF_V1(A))
895 #else
896 /// \todo implement security checks for cplusplus / MSVC
897 #define RTL_NUMBER_OF_V2(A) RTL_NUMBER_OF_V1(A)
898 #endif
899
900 #ifdef ENABLE_RTL_NUMBER_OF_V2
901 #define RTL_NUMBER_OF(A) RTL_NUMBER_OF_V2(A)
902 #else
903 #define RTL_NUMBER_OF(A) RTL_NUMBER_OF_V1(A)
904 #endif
905 #define ARRAYSIZE(A) RTL_NUMBER_OF_V2(A)
906 #define _ARRAYSIZE(A) RTL_NUMBER_OF_V1(A)
907
908 /* Type Limits */
909 #define MINCHAR 0x80
910 #define MAXCHAR 0x7f
911 #define MINSHORT 0x8000
912 #define MAXSHORT 0x7fff
913 #define MINLONG 0x80000000
914 #define MAXLONG 0x7fffffff
915 #define MAXUCHAR 0xff
916 #define MAXUSHORT 0xffff
917 #define MAXULONG 0xffffffff
918 #define MAXLONGLONG (0x7fffffffffffffffLL)
919
920 /* Multiplication and Shift Operations. Note: we don't use inline
921 asm functions, the compiler can optimize this better. */
922 #define Int32x32To64(a,b) (((__int64)(long)(a))*((__int64)(long)(b)))
923 #define UInt32x32To64(a,b) ((unsigned __int64)(unsigned int)(a)*(unsigned __int64)(unsigned int)(b))
924
925 #if defined(MIDL_PASS)|| defined(RC_INVOKED) || defined(_M_CEE_PURE)
926 /* Use native math */
927 #define Int64ShllMod32(a,b) ((unsigned __int64)(a)<<(b))
928 #define Int64ShraMod32(a,b) (((__int64)(a))>>(b))
929 #define Int64ShrlMod32(a,b) (((unsigned __int64)(a))>>(b))
930 #else
931 /* Use intrinsics */
932 #define Int64ShllMod32(a,b) __ll_lshift(a,b)
933 #define Int64ShraMod32(a,b) __ll_rshift(a,b)
934 #define Int64ShrlMod32(a,b) __ull_rshift(a,b)
935 #endif
936
937 /* C_ASSERT Definition */
938 #define C_ASSERT(expr) extern char (*c_assert(void)) [(expr) ? 1 : -1]
939
940 /* Eliminate Microsoft C/C++ compiler warning 4715 */
941 #if defined(_MSC_VER)
942 # define DEFAULT_UNREACHABLE default: __assume(0)
943 #elif defined(__clang__) || (defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 5))))
944 # define DEFAULT_UNREACHABLE default: __builtin_unreachable()
945 #else
946 # define DEFAULT_UNREACHABLE default: break
947 #endif
948
949 #define VER_WORKSTATION_NT 0x40000000
950 #define VER_SERVER_NT 0x80000000
951 #define VER_SUITE_SMALLBUSINESS 0x00000001
952 #define VER_SUITE_ENTERPRISE 0x00000002
953 #define VER_SUITE_BACKOFFICE 0x00000004
954 #define VER_SUITE_COMMUNICATIONS 0x00000008
955 #define VER_SUITE_TERMINAL 0x00000010
956 #define VER_SUITE_SMALLBUSINESS_RESTRICTED 0x00000020
957 #define VER_SUITE_EMBEDDEDNT 0x00000040
958 #define VER_SUITE_DATACENTER 0x00000080
959 #define VER_SUITE_SINGLEUSERTS 0x00000100
960 #define VER_SUITE_PERSONAL 0x00000200
961 #define VER_SUITE_BLADE 0x00000400
962 #define VER_SUITE_EMBEDDED_RESTRICTED 0x00000800
963 #define VER_SUITE_SECURITY_APPLIANCE 0x00001000
964 #define VER_SUITE_STORAGE_SERVER 0x00002000
965 #define VER_SUITE_COMPUTE_SERVER 0x00004000
966 #define VER_SUITE_WH_SERVER 0x00008000
967
968 /* Primary language IDs. */
969 #define LANG_NEUTRAL 0x00
970 #define LANG_INVARIANT 0x7f
971
972 #define LANG_AFRIKAANS 0x36
973 #define LANG_ALBANIAN 0x1c
974 #define LANG_ALSATIAN 0x84
975 #define LANG_AMHARIC 0x5e
976 #define LANG_ARABIC 0x01
977 #define LANG_ARMENIAN 0x2b
978 #define LANG_ASSAMESE 0x4d
979 #define LANG_AZERI 0x2c
980 #define LANG_AZERBAIJANI 0x2c
981 #define LANG_BANGLA 0x45
982 #define LANG_BASHKIR 0x6d
983 #define LANG_BASQUE 0x2d
984 #define LANG_BELARUSIAN 0x23
985 #define LANG_BENGALI 0x45
986 #define LANG_BRETON 0x7e
987 #define LANG_BOSNIAN 0x1a
988 #define LANG_BOSNIAN_NEUTRAL 0x781a
989 #define LANG_BULGARIAN 0x02
990 #define LANG_CATALAN 0x03
991 #define LANG_CENTRAL_KURDISH 0x92
992 #define LANG_CHEROKEE 0x5c
993 #define LANG_CHINESE 0x04
994 #define LANG_CHINESE_SIMPLIFIED 0x04
995 #define LANG_CHINESE_TRADITIONAL 0x7c04
996 #define LANG_CORSICAN 0x83
997 #define LANG_CROATIAN 0x1a
998 #define LANG_CZECH 0x05
999 #define LANG_DANISH 0x06
1000 #define LANG_DARI 0x8c
1001 #define LANG_DIVEHI 0x65
1002 #define LANG_DUTCH 0x13
1003 #define LANG_ENGLISH 0x09
1004 #define LANG_ESTONIAN 0x25
1005 #define LANG_FAEROESE 0x38
1006 #define LANG_FARSI 0x29
1007 #define LANG_FILIPINO 0x64
1008 #define LANG_FINNISH 0x0b
1009 #define LANG_FRENCH 0x0c
1010 #define LANG_FRISIAN 0x62
1011 #define LANG_FULAH 0x67
1012 #define LANG_GALICIAN 0x56
1013 #define LANG_GEORGIAN 0x37
1014 #define LANG_GERMAN 0x07
1015 #define LANG_GREEK 0x08
1016 #define LANG_GREENLANDIC 0x6f
1017 #define LANG_GUJARATI 0x47
1018 #define LANG_HAUSA 0x68
1019 #define LANG_HAWAIIAN 0x75
1020 #define LANG_HEBREW 0x0d
1021 #define LANG_HINDI 0x39
1022 #define LANG_HUNGARIAN 0x0e
1023 #define LANG_ICELANDIC 0x0f
1024 #define LANG_IGBO 0x70
1025 #define LANG_INDONESIAN 0x21
1026 #define LANG_INUKTITUT 0x5d
1027 #define LANG_IRISH 0x3c
1028 #define LANG_ITALIAN 0x10
1029 #define LANG_JAPANESE 0x11
1030 #define LANG_KANNADA 0x4b
1031 #define LANG_KASHMIRI 0x60
1032 #define LANG_KAZAK 0x3f
1033 #define LANG_KHMER 0x53
1034 #define LANG_KICHE 0x86
1035 #define LANG_KINYARWANDA 0x87
1036 #define LANG_KONKANI 0x57
1037 #define LANG_KOREAN 0x12
1038 #define LANG_KYRGYZ 0x40
1039 #define LANG_LAO 0x54
1040 #define LANG_LATVIAN 0x26
1041 #define LANG_LITHUANIAN 0x27
1042 #define LANG_LOWER_SORBIAN 0x2e
1043 #define LANG_LUXEMBOURGISH 0x6e
1044 #define LANG_MACEDONIAN 0x2f
1045 #define LANG_MALAY 0x3e
1046 #define LANG_MALAYALAM 0x4c
1047 #define LANG_MALTESE 0x3a
1048 #define LANG_MANIPURI 0x58
1049 #define LANG_MAORI 0x81
1050 #define LANG_MAPUDUNGUN 0x7a
1051 #define LANG_MARATHI 0x4e
1052 #define LANG_MOHAWK 0x7c
1053 #define LANG_MONGOLIAN 0x50
1054 #define LANG_NEPALI 0x61
1055 #define LANG_NORWEGIAN 0x14
1056 #define LANG_OCCITAN 0x82
1057 #define LANG_ODIA 0x48
1058 #define LANG_ORIYA 0x48
1059 #define LANG_PASHTO 0x63
1060 #define LANG_PERSIAN 0x29
1061 #define LANG_POLISH 0x15
1062 #define LANG_PORTUGUESE 0x16
1063 #define LANG_PULAR 0x67
1064 #define LANG_PUNJABI 0x46
1065 #define LANG_QUECHUA 0x6b
1066 #define LANG_ROMANIAN 0x18
1067 #define LANG_ROMANSH 0x17
1068 #define LANG_RUSSIAN 0x19
1069 #define LANG_SAKHA 0x85
1070 #define LANG_SAMI 0x3b
1071 #define LANG_SANSKRIT 0x4f
1072 #define LANG_SCOTTISH_GAELIC 0x91
1073 #define LANG_SERBIAN 0x1a
1074 #define LANG_SERBIAN_NEUTRAL 0x7c1a
1075 #define LANG_SINDHI 0x59
1076 #define LANG_SINHALESE 0x5b
1077 #define LANG_SLOVAK 0x1b
1078 #define LANG_SLOVENIAN 0x24
1079 #define LANG_SOTHO 0x6c
1080 #define LANG_SPANISH 0x0a
1081 #define LANG_SWAHILI 0x41
1082 #define LANG_SWEDISH 0x1d
1083 #define LANG_SYRIAC 0x5a
1084 #define LANG_TAJIK 0x28
1085 #define LANG_TAMAZIGHT 0x5f
1086 #define LANG_TAMIL 0x49
1087 #define LANG_TATAR 0x44
1088 #define LANG_TELUGU 0x4a
1089 #define LANG_THAI 0x1e
1090 #define LANG_TIBETAN 0x51
1091 #define LANG_TIGRIGNA 0x73
1092 #define LANG_TIGRINYA 0x73
1093 #define LANG_TSWANA 0x32
1094 #define LANG_TURKISH 0x1f
1095 #define LANG_TURKMEN 0x42
1096 #define LANG_UIGHUR 0x80
1097 #define LANG_UKRAINIAN 0x22
1098 #define LANG_UPPER_SORBIAN 0x2e
1099 #define LANG_URDU 0x20
1100 #define LANG_UZBEK 0x43
1101 #define LANG_VALENCIAN 0x03
1102 #define LANG_VIETNAMESE 0x2a
1103 #define LANG_WELSH 0x52
1104 #define LANG_WOLOF 0x88
1105 #define LANG_XHOSA 0x34
1106 #define LANG_YAKUT 0x85
1107 #define LANG_YI 0x78
1108 #define LANG_YORUBA 0x6a
1109 #define LANG_ZULU 0x35
1110
1111 #ifdef __cplusplus
1112 } // extern "C"
1113 #endif
1114
1115 #endif /* _NTDEF_ */