Create the AHCI branch for Aman's work
[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 #define DECLARE_UNICODE_STRING_SIZE(_var, _size) \
227 WCHAR _var ## _buffer[_size]; \
228 __pragma(warning(push)) __pragma(warning(disable:4221)) __pragma(warning(disable:4204)) \
229 UNICODE_STRING _var = { 0, (_size) * sizeof(WCHAR) , _var ## _buffer } \
230 __pragma(warning(pop))
231
232 #define DECLARE_CONST_UNICODE_STRING(_var, _string) \
233 const WCHAR _var##_buffer[] = _string; \
234 __pragma(warning(push)) __pragma(warning(disable:4221)) __pragma(warning(disable:4204)) \
235 const UNICODE_STRING _var = { sizeof(_string) - sizeof(WCHAR), sizeof(_string), (PWCH)_var##_buffer } \
236 __pragma(warning(pop))
237
238 #define DECLARE_GLOBAL_CONST_UNICODE_STRING(_var, _str) \
239 extern const __declspec(selectany) UNICODE_STRING _var = RTL_CONSTANT_STRING(_str)
240
241 /* Object Attributes */
242 typedef struct _OBJECT_ATTRIBUTES {
243 ULONG Length;
244 HANDLE RootDirectory;
245 PUNICODE_STRING ObjectName;
246 ULONG Attributes;
247 PVOID SecurityDescriptor;
248 PVOID SecurityQualityOfService;
249 } OBJECT_ATTRIBUTES, *POBJECT_ATTRIBUTES;
250 typedef CONST OBJECT_ATTRIBUTES *PCOBJECT_ATTRIBUTES;
251
252 typedef struct _OBJECT_ATTRIBUTES32 {
253 ULONG Length;
254 ULONG RootDirectory;
255 ULONG ObjectName;
256 ULONG Attributes;
257 ULONG SecurityDescriptor;
258 ULONG SecurityQualityOfService;
259 } OBJECT_ATTRIBUTES32, *POBJECT_ATTRIBUTES32;
260 typedef CONST OBJECT_ATTRIBUTES32 *PCOBJECT_ATTRIBUTES32;
261
262 typedef struct _OBJECT_ATTRIBUTES64 {
263 ULONG Length;
264 ULONG64 RootDirectory;
265 ULONG64 ObjectName;
266 ULONG Attributes;
267 ULONG64 SecurityDescriptor;
268 ULONG64 SecurityQualityOfService;
269 } OBJECT_ATTRIBUTES64, *POBJECT_ATTRIBUTES64;
270 typedef CONST OBJECT_ATTRIBUTES64 *PCOBJECT_ATTRIBUTES64;
271
272 #define OBJ_HANDLE_TAGBITS 0x00000003L
273
274 /* Values for the Attributes member */
275 #define OBJ_INHERIT 0x00000002L
276 #define OBJ_PERMANENT 0x00000010L
277 #define OBJ_EXCLUSIVE 0x00000020L
278 #define OBJ_CASE_INSENSITIVE 0x00000040L
279 #define OBJ_OPENIF 0x00000080L
280 #define OBJ_OPENLINK 0x00000100L
281 #define OBJ_KERNEL_HANDLE 0x00000200L
282 #define OBJ_FORCE_ACCESS_CHECK 0x00000400L
283 #define OBJ_VALID_ATTRIBUTES 0x000007F2L
284
285 /* Helper Macro */
286 #define InitializeObjectAttributes(p,n,a,r,s) { \
287 (p)->Length = sizeof(OBJECT_ATTRIBUTES); \
288 (p)->RootDirectory = (r); \
289 (p)->ObjectName = (n); \
290 (p)->Attributes = (a); \
291 (p)->SecurityDescriptor = (s); \
292 (p)->SecurityQualityOfService = NULL; \
293 }
294
295 #define RTL_CONSTANT_OBJECT_ATTRIBUTES(n,a) { \
296 sizeof(OBJECT_ATTRIBUTES), \
297 NULL, \
298 RTL_CONST_CAST(PUNICODE_STRING)(n), \
299 a, \
300 NULL, \
301 NULL \
302 }
303
304 #define RTL_INIT_OBJECT_ATTRIBUTES(n, a) \
305 RTL_CONSTANT_OBJECT_ATTRIBUTES(n, a)
306
307 #ifdef _MSC_VER
308 #pragma warning(push)
309 #pragma warning(disable:4214) /* Bit fields of other types than int */
310 #endif /* _MSC_VER */
311 typedef struct _RTL_BALANCED_NODE
312 {
313 _ANONYMOUS_UNION union
314 {
315 struct _RTL_BALANCED_NODE *Children[2];
316 _ANONYMOUS_STRUCT struct
317 {
318 struct _RTL_BALANCED_NODE *Left;
319 struct _RTL_BALANCED_NODE *Right;
320 } DUMMYSTRUCTNAME;
321 } DUMMYUNIONNAME;
322 _ANONYMOUS_UNION union
323 {
324 UCHAR Red : 1;
325 UCHAR Balance : 2;
326 ULONG_PTR ParentValue;
327 } DUMMYUNIONNAME2;
328 } RTL_BALANCED_NODE, *PRTL_BALANCED_NODE;
329 #ifdef _MSC_VER
330 #pragma warning(pop)
331 #endif /* _MSC_VER */
332
333 #define RTL_BALANCED_NODE_RESERVED_PARENT_MASK 3
334 #define RTL_BALANCED_NODE_GET_PARENT_POINTER(Node) \
335 ((PRTL_BALANCED_NODE)((Node)->ParentValue & \
336 ~RTL_BALANCED_NODE_RESERVED_PARENT_MASK))
337
338 /* Product Types */
339 typedef enum _NT_PRODUCT_TYPE {
340 NtProductWinNt = 1,
341 NtProductLanManNt,
342 NtProductServer
343 } NT_PRODUCT_TYPE, *PNT_PRODUCT_TYPE;
344
345 typedef enum _EVENT_TYPE {
346 NotificationEvent,
347 SynchronizationEvent
348 } EVENT_TYPE;
349
350 typedef enum _TIMER_TYPE {
351 NotificationTimer,
352 SynchronizationTimer
353 } TIMER_TYPE;
354
355 typedef enum _WAIT_TYPE {
356 WaitAll,
357 WaitAny
358 } WAIT_TYPE;
359
360 #ifndef MIDL_PASS
361 FORCEINLINE
362 VOID
363 ListEntry32To64(
364 _In_ PLIST_ENTRY32 ListEntry32,
365 _Out_ PLIST_ENTRY64 ListEntry64)
366 {
367 ListEntry64->Flink = ListEntry32->Flink;
368 ListEntry64->Blink = ListEntry32->Blink;
369 }
370
371 FORCEINLINE
372 VOID
373 ListEntry64To32(
374 _In_ PLIST_ENTRY64 ListEntry64,
375 _Out_ PLIST_ENTRY32 ListEntry32)
376 {
377 /* ASSERT without ASSERT or intrinsics ... */
378 if (((ListEntry64->Flink >> 32) != 0) ||
379 ((ListEntry64->Blink >> 32) != 0))
380 {
381 (VOID)*(volatile LONG*)(LONG_PTR)-1;
382 }
383 ListEntry32->Flink = ListEntry64->Flink & 0xFFFFFFFF;
384 ListEntry32->Blink = ListEntry64->Blink & 0xFFFFFFFF;
385 }
386 #endif /* !MIDL_PASS */
387
388 #ifdef __cplusplus
389 } // extern "C"
390 #endif
391
392 #endif /* _NTDEF_ */