[XDK/DDK]
[reactos.git] / reactos / 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 /* Physical Addresses are always treated as 64-bit wide */
121 typedef LARGE_INTEGER PHYSICAL_ADDRESS, *PPHYSICAL_ADDRESS;
122
123 /* Used to store a non-float 8 byte aligned structure */
124 typedef struct _QUAD
125 {
126 _ANONYMOUS_UNION union
127 {
128 __GNU_EXTENSION __int64 UseThisFieldToCopy;
129 double DoNotUseThisField;
130 } DUMMYUNIONNAME;
131 } QUAD, *PQUAD, UQUAD, *PUQUAD;
132
133 /* String Types */
134 typedef struct _STRING {
135 USHORT Length;
136 USHORT MaximumLength;
137 #ifdef MIDL_PASS
138 [size_is(MaximumLength), length_is(Length) ]
139 #endif
140 _Field_size_bytes_part_opt_(MaximumLength, Length) PCHAR Buffer;
141 } STRING, *PSTRING,
142 ANSI_STRING, *PANSI_STRING,
143 OEM_STRING, *POEM_STRING;
144
145 typedef CONST STRING* PCOEM_STRING;
146 typedef STRING CANSI_STRING;
147 typedef PSTRING PCANSI_STRING;
148
149 typedef struct _STRING32 {
150 USHORT Length;
151 USHORT MaximumLength;
152 $ULONG Buffer;
153 } STRING32, *PSTRING32,
154 UNICODE_STRING32, *PUNICODE_STRING32,
155 ANSI_STRING32, *PANSI_STRING32;
156
157 typedef struct _STRING64 {
158 USHORT Length;
159 USHORT MaximumLength;
160 ULONGLONG Buffer;
161 } STRING64, *PSTRING64,
162 UNICODE_STRING64, *PUNICODE_STRING64,
163 ANSI_STRING64, *PANSI_STRING64;
164
165 typedef struct _CSTRING {
166 USHORT Length;
167 USHORT MaximumLength;
168 CONST CHAR *Buffer;
169 } CSTRING, *PCSTRING;
170
171 typedef struct _UNICODE_STRING {
172 USHORT Length;
173 USHORT MaximumLength;
174 #ifdef MIDL_PASS
175 [size_is(MaximumLength / 2), length_is((Length) / 2)] PUSHORT Buffer;
176 #else
177 _Field_size_bytes_part_(MaximumLength, Length) PWCH Buffer;
178 #endif
179 } UNICODE_STRING, *PUNICODE_STRING;
180 typedef const UNICODE_STRING* PCUNICODE_STRING;
181
182 typedef USHORT RTL_STRING_LENGTH_TYPE;
183
184 #ifdef __cplusplus
185 extern "C++" template<typename _Type> struct _RTL_remove_const_template;
186 extern "C++" template<typename _Type> struct _RTL_remove_const_template<const _Type&> { typedef _Type type; };
187 #define _RTL_CONSTANT_STRING_remove_const_macro(s) \
188 (const_cast<_RTL_remove_const_template<decltype((s)[0])>::type*>(s))
189 extern "C++" template<class _Ty> struct _RTL_CONSTANT_STRING_type_check_template;
190 extern "C++" template<class _Ty, int _Count> struct _RTL_CONSTANT_STRING_type_check_template<const _Ty (&)[_Count]> { typedef char type; };
191 #define _RTL_CONSTANT_STRING_type_check(s) _RTL_CONSTANT_STRING_type_check_template<decltype(s)>::type
192 #else
193 # define _RTL_CONSTANT_STRING_remove_const_macro(s) (s)
194 char _RTL_CONSTANT_STRING_type_check(const void *s);
195 #endif
196 #define RTL_CONSTANT_STRING(s) { \
197 sizeof(s)-sizeof((s)[0]), \
198 sizeof(s) / sizeof(_RTL_CONSTANT_STRING_type_check(s)), \
199 _RTL_CONSTANT_STRING_remove_const_macro(s) }
200
201 #define DECLARE_UNICODE_STRING_SIZE(_var, _size) \
202 WCHAR _var ## _buffer[_size]; \
203 __pragma(warning(push)) __pragma(warning(disable:4221)) __pragma(warning(disable:4204)) \
204 UNICODE_STRING _var = { 0, (_size) * sizeof(WCHAR) , _var ## _buffer } \
205 __pragma(warning(pop))
206
207 #define DECLARE_CONST_UNICODE_STRING(_var, _string) \
208 const WCHAR _var##_buffer[] = _string; \
209 __pragma(warning(push)) __pragma(warning(disable:4221)) __pragma(warning(disable:4204)) \
210 const UNICODE_STRING _var = { sizeof(_string) - sizeof(WCHAR), sizeof(_string), (PWCH)_var##_buffer } \
211 __pragma(warning(pop))
212
213 #define DECLARE_GLOBAL_CONST_UNICODE_STRING(_var, _str) \
214 extern const __declspec(selectany) UNICODE_STRING _var = RTL_CONSTANT_STRING(_str)
215
216 /* Object Attributes */
217 typedef struct _OBJECT_ATTRIBUTES {
218 ULONG Length;
219 HANDLE RootDirectory;
220 PUNICODE_STRING ObjectName;
221 ULONG Attributes;
222 PVOID SecurityDescriptor;
223 PVOID SecurityQualityOfService;
224 } OBJECT_ATTRIBUTES, *POBJECT_ATTRIBUTES;
225 typedef CONST OBJECT_ATTRIBUTES *PCOBJECT_ATTRIBUTES;
226
227 typedef struct _OBJECT_ATTRIBUTES32 {
228 ULONG Length;
229 ULONG RootDirectory;
230 ULONG ObjectName;
231 ULONG Attributes;
232 ULONG SecurityDescriptor;
233 ULONG SecurityQualityOfService;
234 } OBJECT_ATTRIBUTES32, *POBJECT_ATTRIBUTES32;
235 typedef CONST OBJECT_ATTRIBUTES32 *PCOBJECT_ATTRIBUTES32;
236
237 typedef struct _OBJECT_ATTRIBUTES64 {
238 ULONG Length;
239 ULONG64 RootDirectory;
240 ULONG64 ObjectName;
241 ULONG Attributes;
242 ULONG64 SecurityDescriptor;
243 ULONG64 SecurityQualityOfService;
244 } OBJECT_ATTRIBUTES64, *POBJECT_ATTRIBUTES64;
245 typedef CONST OBJECT_ATTRIBUTES64 *PCOBJECT_ATTRIBUTES64;
246
247 /* Values for the Attributes member */
248 #define OBJ_INHERIT 0x00000002L
249 #define OBJ_PERMANENT 0x00000010L
250 #define OBJ_EXCLUSIVE 0x00000020L
251 #define OBJ_CASE_INSENSITIVE 0x00000040L
252 #define OBJ_OPENIF 0x00000080L
253 #define OBJ_OPENLINK 0x00000100L
254 #define OBJ_KERNEL_HANDLE 0x00000200L
255 #define OBJ_FORCE_ACCESS_CHECK 0x00000400L
256 #define OBJ_VALID_ATTRIBUTES 0x000007F2L
257
258 /* Helper Macro */
259 #define InitializeObjectAttributes(p,n,a,r,s) { \
260 (p)->Length = sizeof(OBJECT_ATTRIBUTES); \
261 (p)->RootDirectory = (r); \
262 (p)->ObjectName = (n); \
263 (p)->Attributes = (a); \
264 (p)->SecurityDescriptor = (s); \
265 (p)->SecurityQualityOfService = NULL; \
266 }
267
268 #define RTL_CONSTANT_OBJECT_ATTRIBUTES(n,a) { \
269 sizeof(OBJECT_ATTRIBUTES), \
270 NULL, \
271 RTL_CONST_CAST(PUNICODE_STRING)(n), \
272 a, \
273 NULL, \
274 NULL \
275 }
276
277 #define RTL_INIT_OBJECT_ATTRIBUTES(n, a) \
278 RTL_CONSTANT_OBJECT_ATTRIBUTES(n, a)
279
280 /* Product Types */
281 typedef enum _NT_PRODUCT_TYPE {
282 NtProductWinNt = 1,
283 NtProductLanManNt,
284 NtProductServer
285 } NT_PRODUCT_TYPE, *PNT_PRODUCT_TYPE;
286
287 typedef enum _EVENT_TYPE {
288 NotificationEvent,
289 SynchronizationEvent
290 } EVENT_TYPE;
291
292 typedef enum _TIMER_TYPE {
293 NotificationTimer,
294 SynchronizationTimer
295 } TIMER_TYPE;
296
297 typedef enum _WAIT_TYPE {
298 WaitAll,
299 WaitAny
300 } WAIT_TYPE;
301
302 #ifdef __cplusplus
303 } // extern "C"
304 #endif
305
306 #endif /* _NTDEF_ */