Git conversion: Make reactos the root directory, move rosapps, rostests, wallpapers...
[reactos.git] / sdk / include / xdk / ntdef.template.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 $if(0)
28 //#include <winapifamily.h>
29 $endif()
30 #include <basetsd.h>
31 #include <guiddef.h>
32 #include <excpt.h>
33 #include <sdkddkver.h>
34 #include <specstrings.h>
35 #include <kernelspecs.h>
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41 /* Default to strict */
42 #ifndef NO_STRICT
43 #ifndef STRICT
44 #define STRICT 1
45 #endif
46 #endif
47
48 /* Pseudo Modifiers for Input Parameters */
49
50 #ifndef IN
51 #define IN
52 #endif
53
54 #ifndef OUT
55 #define OUT
56 #endif
57
58 #ifndef OPTIONAL
59 #define OPTIONAL
60 #endif
61
62 #ifndef NOTHING
63 #define NOTHING
64 #endif
65
66 #ifndef CRITICAL
67 #define CRITICAL
68 #endif
69
70 /* Constant modifier */
71 #ifndef CONST
72 #define CONST const
73 #endif
74
75 /* TRUE/FALSE */
76 #define FALSE 0
77 #define TRUE 1
78
79 /* NULL/NULL64 */
80 #ifndef NULL
81 #ifdef __cplusplus
82 #define NULL 0
83 #define NULL64 0
84 #else
85 #define NULL ((void *)0)
86 #define NULL64 ((void * POINTER_64)0)
87 #endif
88 #endif /* NULL */
89
90 #define ARGUMENT_PRESENT(ArgumentPointer) \
91 ((CHAR*)((ULONG_PTR)(ArgumentPointer)) != (CHAR*)NULL)
92
93 #if defined(_MANAGED)
94 #define FASTCALL __stdcall
95 #elif defined(_M_IX86)
96 #define FASTCALL __fastcall
97 #else
98 #define FASTCALL
99 #endif /* _MANAGED */
100
101 /* min/max helper macros */
102 #ifndef NOMINMAX
103 # ifndef min
104 # define min(a,b) (((a) < (b)) ? (a) : (b))
105 # endif
106 # ifndef max
107 # define max(a,b) (((a) > (b)) ? (a) : (b))
108 # endif
109 #endif /* NOMINMAX */
110
111 /* Tell windef.h that we have defined some basic types */
112 #define BASETYPES
113
114 $define(_NTDEF_)
115 $define(ULONG=ULONG)
116 $define(USHORT=USHORT)
117 $define(UCHAR=UCHAR)
118 $include(ntbasedef.h)
119
120 typedef _Return_type_success_(return >= 0) LONG NTSTATUS;
121 typedef NTSTATUS *PNTSTATUS;
122
123 #ifndef __SECSTATUS_DEFINED__
124 typedef long SECURITY_STATUS;
125 #define __SECSTATUS_DEFINED__
126 #endif
127
128 /* Physical Addresses are always treated as 64-bit wide */
129 typedef LARGE_INTEGER PHYSICAL_ADDRESS, *PPHYSICAL_ADDRESS;
130
131 #define TIME LARGE_INTEGER
132 #define _TIME _LARGE_INTEGER
133 #define PTIME PLARGE_INTEGER
134 #define LowTime LowPart
135 #define HighTime HighPart
136
137 /* Used to store a non-float 8 byte aligned structure */
138 typedef struct _QUAD
139 {
140 _ANONYMOUS_UNION union
141 {
142 __GNU_EXTENSION __int64 UseThisFieldToCopy;
143 double DoNotUseThisField;
144 } DUMMYUNIONNAME;
145 } QUAD, *PQUAD, UQUAD, *PUQUAD;
146
147 #if (_WIN32_WINNT >= 0x0600) || (defined(__cplusplus) && defined(WINDOWS_ENABLE_CPLUSPLUS))
148 typedef CONST UCHAR *PCUCHAR;
149 typedef CONST USHORT *PCUSHORT;
150 typedef CONST ULONG *PCULONG;
151 typedef CONST UQUAD *PCUQUAD;
152 typedef CONST SCHAR *PCSCHAR;
153 #endif /* (/_WIN32_WINNT >= 0x0600) */
154 #if (_WIN32_WINNT >= 0x0600)
155 typedef CONST NTSTATUS *PCNTSTATUS;
156 #endif /* (/_WIN32_WINNT >= 0x0600) */
157
158 /* String Types */
159 typedef struct _STRING {
160 USHORT Length;
161 USHORT MaximumLength;
162 #ifdef MIDL_PASS
163 [size_is(MaximumLength), length_is(Length) ]
164 #endif
165 _Field_size_bytes_part_opt_(MaximumLength, Length) PCHAR Buffer;
166 } STRING, *PSTRING,
167 ANSI_STRING, *PANSI_STRING,
168 OEM_STRING, *POEM_STRING;
169
170 typedef CONST STRING* PCOEM_STRING;
171 typedef STRING CANSI_STRING;
172 typedef PSTRING PCANSI_STRING;
173
174 typedef struct _STRING32 {
175 USHORT Length;
176 USHORT MaximumLength;
177 $ULONG Buffer;
178 } STRING32, *PSTRING32,
179 UNICODE_STRING32, *PUNICODE_STRING32,
180 ANSI_STRING32, *PANSI_STRING32;
181
182 typedef struct _STRING64 {
183 USHORT Length;
184 USHORT MaximumLength;
185 ULONGLONG Buffer;
186 } STRING64, *PSTRING64,
187 UNICODE_STRING64, *PUNICODE_STRING64,
188 ANSI_STRING64, *PANSI_STRING64;
189
190 typedef struct _CSTRING {
191 USHORT Length;
192 USHORT MaximumLength;
193 CONST CHAR *Buffer;
194 } CSTRING, *PCSTRING;
195
196 typedef struct _UNICODE_STRING {
197 USHORT Length;
198 USHORT MaximumLength;
199 #ifdef MIDL_PASS
200 [size_is(MaximumLength / 2), length_is((Length) / 2)] PUSHORT Buffer;
201 #else
202 _Field_size_bytes_part_(MaximumLength, Length) PWCH Buffer;
203 #endif
204 } UNICODE_STRING, *PUNICODE_STRING;
205 typedef const UNICODE_STRING* PCUNICODE_STRING;
206
207 typedef USHORT RTL_STRING_LENGTH_TYPE;
208
209 #ifdef __cplusplus
210 extern "C++" template<typename _Type> struct _RTL_remove_const_template;
211 extern "C++" template<typename _Type> struct _RTL_remove_const_template<const _Type&> { typedef _Type type; };
212 #define _RTL_CONSTANT_STRING_remove_const_macro(s) \
213 (const_cast<_RTL_remove_const_template<decltype((s)[0])>::type*>(s))
214 extern "C++" template<class _Ty> struct _RTL_CONSTANT_STRING_type_check_template;
215 extern "C++" template<class _Ty, int _Count> struct _RTL_CONSTANT_STRING_type_check_template<const _Ty (&)[_Count]> { typedef char type; };
216 #define _RTL_CONSTANT_STRING_type_check(s) _RTL_CONSTANT_STRING_type_check_template<decltype(s)>::type
217 #else
218 # define _RTL_CONSTANT_STRING_remove_const_macro(s) (s)
219 char _RTL_CONSTANT_STRING_type_check(const void *s);
220 #endif
221 #define RTL_CONSTANT_STRING(s) { \
222 sizeof(s)-sizeof((s)[0]), \
223 sizeof(s) / sizeof(_RTL_CONSTANT_STRING_type_check(s)), \
224 _RTL_CONSTANT_STRING_remove_const_macro(s) }
225
226 #ifdef _MSC_VER
227 #define DECLARE_UNICODE_STRING_SIZE(_var, _size) \
228 WCHAR _var ## _buffer[_size]; \
229 __pragma(warning(push)) __pragma(warning(disable:4221)) __pragma(warning(disable:4204)) \
230 UNICODE_STRING _var = { 0, (_size) * sizeof(WCHAR) , _var ## _buffer } \
231 __pragma(warning(pop))
232
233 #define DECLARE_CONST_UNICODE_STRING(_var, _string) \
234 const WCHAR _var##_buffer[] = _string; \
235 __pragma(warning(push)) __pragma(warning(disable:4221)) __pragma(warning(disable:4204)) \
236 const UNICODE_STRING _var = { sizeof(_string) - sizeof(WCHAR), sizeof(_string), (PWCH)_var##_buffer } \
237 __pragma(warning(pop))
238 #else
239 #define DECLARE_UNICODE_STRING_SIZE(_var, _size) \
240 WCHAR _var ## _buffer[_size]; \
241 UNICODE_STRING _var = { 0, (_size) * sizeof(WCHAR) , _var ## _buffer }
242
243 #define DECLARE_CONST_UNICODE_STRING(_var, _string) \
244 const WCHAR _var##_buffer[] = _string; \
245 const UNICODE_STRING _var = { sizeof(_string) - sizeof(WCHAR), sizeof(_string), (PWCH)_var##_buffer }
246 #endif
247
248 #define DECLARE_GLOBAL_CONST_UNICODE_STRING(_var, _str) \
249 extern const __declspec(selectany) UNICODE_STRING _var = RTL_CONSTANT_STRING(_str)
250
251 /* Object Attributes */
252 typedef struct _OBJECT_ATTRIBUTES {
253 ULONG Length;
254 HANDLE RootDirectory;
255 PUNICODE_STRING ObjectName;
256 ULONG Attributes;
257 PVOID SecurityDescriptor;
258 PVOID SecurityQualityOfService;
259 } OBJECT_ATTRIBUTES, *POBJECT_ATTRIBUTES;
260 typedef CONST OBJECT_ATTRIBUTES *PCOBJECT_ATTRIBUTES;
261
262 typedef struct _OBJECT_ATTRIBUTES32 {
263 ULONG Length;
264 ULONG RootDirectory;
265 ULONG ObjectName;
266 ULONG Attributes;
267 ULONG SecurityDescriptor;
268 ULONG SecurityQualityOfService;
269 } OBJECT_ATTRIBUTES32, *POBJECT_ATTRIBUTES32;
270 typedef CONST OBJECT_ATTRIBUTES32 *PCOBJECT_ATTRIBUTES32;
271
272 typedef struct _OBJECT_ATTRIBUTES64 {
273 ULONG Length;
274 ULONG64 RootDirectory;
275 ULONG64 ObjectName;
276 ULONG Attributes;
277 ULONG64 SecurityDescriptor;
278 ULONG64 SecurityQualityOfService;
279 } OBJECT_ATTRIBUTES64, *POBJECT_ATTRIBUTES64;
280 typedef CONST OBJECT_ATTRIBUTES64 *PCOBJECT_ATTRIBUTES64;
281
282 #define OBJ_HANDLE_TAGBITS 0x00000003L
283
284 /* Values for the Attributes member */
285 #define OBJ_INHERIT 0x00000002L
286 #define OBJ_PERMANENT 0x00000010L
287 #define OBJ_EXCLUSIVE 0x00000020L
288 #define OBJ_CASE_INSENSITIVE 0x00000040L
289 #define OBJ_OPENIF 0x00000080L
290 #define OBJ_OPENLINK 0x00000100L
291 #define OBJ_KERNEL_HANDLE 0x00000200L
292 #define OBJ_FORCE_ACCESS_CHECK 0x00000400L
293 #define OBJ_VALID_ATTRIBUTES 0x000007F2L
294
295 /* Helper Macro */
296 #define InitializeObjectAttributes(p,n,a,r,s) { \
297 (p)->Length = sizeof(OBJECT_ATTRIBUTES); \
298 (p)->RootDirectory = (r); \
299 (p)->ObjectName = (n); \
300 (p)->Attributes = (a); \
301 (p)->SecurityDescriptor = (s); \
302 (p)->SecurityQualityOfService = NULL; \
303 }
304
305 #define RTL_CONSTANT_OBJECT_ATTRIBUTES(n,a) { \
306 sizeof(OBJECT_ATTRIBUTES), \
307 NULL, \
308 RTL_CONST_CAST(PUNICODE_STRING)(n), \
309 a, \
310 NULL, \
311 NULL \
312 }
313
314 #define RTL_INIT_OBJECT_ATTRIBUTES(n, a) \
315 RTL_CONSTANT_OBJECT_ATTRIBUTES(n, a)
316
317 #ifdef _MSC_VER
318 #pragma warning(push)
319 #pragma warning(disable:4214) /* Bit fields of other types than int */
320 #endif /* _MSC_VER */
321 typedef struct _RTL_BALANCED_NODE
322 {
323 _ANONYMOUS_UNION union
324 {
325 struct _RTL_BALANCED_NODE *Children[2];
326 _ANONYMOUS_STRUCT struct
327 {
328 struct _RTL_BALANCED_NODE *Left;
329 struct _RTL_BALANCED_NODE *Right;
330 } DUMMYSTRUCTNAME;
331 } DUMMYUNIONNAME;
332 _ANONYMOUS_UNION union
333 {
334 UCHAR Red : 1;
335 UCHAR Balance : 2;
336 ULONG_PTR ParentValue;
337 } DUMMYUNIONNAME2;
338 } RTL_BALANCED_NODE, *PRTL_BALANCED_NODE;
339 #ifdef _MSC_VER
340 #pragma warning(pop)
341 #endif /* _MSC_VER */
342
343 #define RTL_BALANCED_NODE_RESERVED_PARENT_MASK 3
344 #define RTL_BALANCED_NODE_GET_PARENT_POINTER(Node) \
345 ((PRTL_BALANCED_NODE)((Node)->ParentValue & \
346 ~RTL_BALANCED_NODE_RESERVED_PARENT_MASK))
347
348 /* Product Types */
349 typedef enum _NT_PRODUCT_TYPE {
350 NtProductWinNt = 1,
351 NtProductLanManNt,
352 NtProductServer
353 } NT_PRODUCT_TYPE, *PNT_PRODUCT_TYPE;
354
355 typedef enum _EVENT_TYPE {
356 NotificationEvent,
357 SynchronizationEvent
358 } EVENT_TYPE;
359
360 typedef enum _TIMER_TYPE {
361 NotificationTimer,
362 SynchronizationTimer
363 } TIMER_TYPE;
364
365 typedef enum _WAIT_TYPE {
366 WaitAll,
367 WaitAny
368 } WAIT_TYPE;
369
370 #ifndef MIDL_PASS
371 FORCEINLINE
372 VOID
373 ListEntry32To64(
374 _In_ PLIST_ENTRY32 ListEntry32,
375 _Out_ PLIST_ENTRY64 ListEntry64)
376 {
377 ListEntry64->Flink = ListEntry32->Flink;
378 ListEntry64->Blink = ListEntry32->Blink;
379 }
380
381 FORCEINLINE
382 VOID
383 ListEntry64To32(
384 _In_ PLIST_ENTRY64 ListEntry64,
385 _Out_ PLIST_ENTRY32 ListEntry32)
386 {
387 /* ASSERT without ASSERT or intrinsics ... */
388 if (((ListEntry64->Flink >> 32) != 0) ||
389 ((ListEntry64->Blink >> 32) != 0))
390 {
391 (VOID)*(volatile LONG*)(LONG_PTR)-1;
392 }
393 ListEntry32->Flink = ListEntry64->Flink & 0xFFFFFFFF;
394 ListEntry32->Blink = ListEntry64->Blink & 0xFFFFFFFF;
395 }
396 #endif /* !MIDL_PASS */
397
398 #ifdef __cplusplus
399 } // extern "C"
400 #endif
401
402 #endif /* _NTDEF_ */