Sync with trunk r62754.
[reactos.git] / include / host / typedefs.h
1 /*
2 PROJECT: ReactOS
3 LICENSE: GPL v2 or any later version
4 FILE: include/host/typedefs.h
5 PURPOSE: Type definitions and useful macros for host tools
6 COPYRIGHT: Copyright 2007 Hervé Poussineau
7 Copyright 2007 Colin Finck <mail@colinfinck.de>
8 */
9
10 #ifndef _TYPEDEFS_HOST_H
11 #define _TYPEDEFS_HOST_H
12
13 #include <assert.h>
14 #include <stdlib.h>
15 #include <limits.h>
16
17 #ifndef _MSC_VER
18 #include <stdint.h>
19 #else
20 typedef __int8 int8_t;
21 typedef __int16 int16_t;
22 typedef __int32 int32_t;
23 typedef __int64 int64_t;
24
25 typedef unsigned __int8 uint8_t;
26 typedef unsigned __int16 uint16_t;
27 typedef unsigned __int32 uint32_t;
28 typedef unsigned __int64 uint64_t;
29 #endif
30
31 /* Function attributes for GCC */
32 #if !defined(_MSC_VER) && !defined(__fastcall)
33 #define __fastcall __attribute__((fastcall))
34 #endif
35 #if !defined(_MSC_VER) && !defined(__cdecl)
36 #define __cdecl __attribute__((cdecl))
37 #endif
38 #if !defined(_MSC_VER) && !defined(__stdcall)
39 #define __stdcall __attribute__((stdcall))
40 #endif
41
42 /* Basic definitions */
43 #define UNIMPLEMENTED { printf("%s unimplemented\n", __FUNCTION__); exit(1); }
44 #define ASSERT(x) assert(x)
45 #define ASSERTMSG(m, x) assert(x)
46 #define DPRINT if (0) printf
47 #define DPRINT1 printf
48
49 #define NTAPI
50 #define WINAPI
51
52 #define IN
53 #define OUT
54 #define OPTIONAL
55
56 #define FALSE 0
57 #define TRUE 1
58
59 #define ANYSIZE_ARRAY 1
60
61 /* Basic types
62 Emulate a LLP64 memory model using a LP64 compiler */
63 typedef void VOID, *PVOID, *LPVOID;
64 typedef char CHAR, CCHAR, *PCHAR, *PSTR, *LPSTR;
65 typedef const char *PCSTR, *LPCSTR;
66 typedef unsigned char UCHAR, *PUCHAR, BYTE, *LPBYTE, BOOLEAN, *PBOOLEAN;
67 typedef int16_t SHORT, *PSHORT;
68 typedef uint16_t USHORT, *PUSHORT, WORD, *PWORD, *LPWORD, WCHAR, *PWCHAR, *PWSTR, *LPWSTR, UINT16;
69 typedef const uint16_t *PCWSTR, *LPCWSTR;
70 typedef int32_t INT, LONG, *PLONG, *LPLONG, BOOL, WINBOOL;
71 typedef uint32_t UINT, *PUINT, *LPUINT, ULONG, *PULONG, DWORD, *PDWORD, *LPDWORD, UINT32;
72 #ifdef _LP64
73 typedef int64_t LONG_PTR, *PLONG_PTR, INT_PTR, *PINT_PTR;
74 typedef uint64_t ULONG_PTR, DWORD_PTR, *PULONG_PTR, UINT_PTR, *PUINT_PTR;
75 #else
76 typedef int32_t LONG_PTR, *PLONG_PTR, INT_PTR, *PINT_PTR;
77 typedef uint32_t ULONG_PTR, DWORD_PTR, *PULONG_PTR, UINT_PTR, *PUINT_PTR;
78 #endif
79 typedef uint64_t ULONG64, DWORD64, *PDWORD64, UINT64, ULONGLONG;
80 typedef int64_t LONGLONG, LONG64;
81 typedef float FLOAT;
82 typedef double DOUBLE;
83
84 /* Derived types */
85 typedef PVOID HANDLE;
86 #ifndef _HAVE_HKEY
87 typedef HANDLE HKEY, *PHKEY;
88 #endif
89 typedef HANDLE HMODULE, HINSTANCE;
90 typedef INT NTSTATUS, POOL_TYPE;
91 typedef LONG HRESULT;
92 typedef ULONG_PTR SIZE_T, *PSIZE_T;
93 typedef WORD LANGID;
94
95 #define MAXUSHORT USHRT_MAX
96
97 /* Widely used structures */
98 #include <pshpack4.h>
99 #ifndef _HAVE_RTL_BITMAP
100 typedef struct _RTL_BITMAP
101 {
102 ULONG SizeOfBitMap;
103 PULONG Buffer;
104 } RTL_BITMAP, *PRTL_BITMAP;
105
106 typedef struct _RTL_BITMAP_RUN
107 {
108 ULONG StartingIndex;
109 ULONG NumberOfBits;
110 } RTL_BITMAP_RUN, *PRTL_BITMAP_RUN;
111 #endif
112
113 #ifndef _HAVE_LARGE_INTEGER
114 typedef union _LARGE_INTEGER
115 {
116 struct
117 {
118 ULONG LowPart;
119 LONG HighPart;
120 };
121 struct
122 {
123 ULONG LowPart;
124 LONG HighPart;
125 } u;
126 LONGLONG QuadPart;
127 } LARGE_INTEGER, *PLARGE_INTEGER;
128 #endif
129
130 #ifndef _HAVE_LIST_ENTRY
131 typedef struct _LIST_ENTRY
132 {
133 struct _LIST_ENTRY *Flink;
134 struct _LIST_ENTRY *Blink;
135 } LIST_ENTRY,*PLIST_ENTRY;
136 #endif
137
138 #ifndef _HAVE_ANSI_STRING
139 typedef struct _ANSI_STRING
140 {
141 USHORT Length;
142 USHORT MaximumLength;
143 PSTR Buffer;
144 } ANSI_STRING, *PANSI_STRING;
145
146 typedef struct _UNICODE_STRING
147 {
148 USHORT Length;
149 USHORT MaximumLength;
150 PWSTR Buffer;
151 } UNICODE_STRING, *PUNICODE_STRING;
152 #endif
153
154 #include <poppack.h>
155
156 #ifndef _HAVE_LIST_ENTRY
157 /* List Functions */
158 static __inline
159 VOID
160 InitializeListHead(
161 IN PLIST_ENTRY ListHead
162 )
163 {
164 ListHead->Flink = ListHead->Blink = ListHead;
165 }
166
167 static __inline
168 VOID
169 InsertHeadList(
170 IN PLIST_ENTRY ListHead,
171 IN PLIST_ENTRY Entry
172 )
173 {
174 PLIST_ENTRY OldFlink;
175 OldFlink = ListHead->Flink;
176 Entry->Flink = OldFlink;
177 Entry->Blink = ListHead;
178 OldFlink->Blink = Entry;
179 ListHead->Flink = Entry;
180 }
181
182 static __inline
183 VOID
184 InsertTailList(
185 IN PLIST_ENTRY ListHead,
186 IN PLIST_ENTRY Entry
187 )
188 {
189 PLIST_ENTRY OldBlink;
190 OldBlink = ListHead->Blink;
191 Entry->Flink = ListHead;
192 Entry->Blink = OldBlink;
193 OldBlink->Flink = Entry;
194 ListHead->Blink = Entry;
195 }
196
197 static __inline
198 BOOLEAN
199 IsListEmpty(
200 IN const LIST_ENTRY * ListHead
201 )
202 {
203 return (BOOLEAN)(ListHead->Flink == ListHead);
204 }
205
206 static __inline
207 BOOLEAN
208 RemoveEntryList(
209 IN PLIST_ENTRY Entry)
210 {
211 PLIST_ENTRY OldFlink;
212 PLIST_ENTRY OldBlink;
213
214 OldFlink = Entry->Flink;
215 OldBlink = Entry->Blink;
216 OldFlink->Blink = OldBlink;
217 OldBlink->Flink = OldFlink;
218 return (BOOLEAN)(OldFlink == OldBlink);
219 }
220
221 static __inline
222 PLIST_ENTRY
223 RemoveHeadList(
224 IN PLIST_ENTRY ListHead)
225 {
226 PLIST_ENTRY Flink;
227 PLIST_ENTRY Entry;
228
229 Entry = ListHead->Flink;
230 Flink = Entry->Flink;
231 ListHead->Flink = Flink;
232 Flink->Blink = ListHead;
233 return Entry;
234 }
235
236 static __inline
237 PLIST_ENTRY
238 RemoveTailList(
239 IN PLIST_ENTRY ListHead)
240 {
241 PLIST_ENTRY Blink;
242 PLIST_ENTRY Entry;
243
244 Entry = ListHead->Blink;
245 Blink = Entry->Blink;
246 ListHead->Blink = Blink;
247 Blink->Flink = ListHead;
248 return Entry;
249 }
250 #endif
251
252 #ifndef _HAVE_ANSI_STRING
253 typedef const UNICODE_STRING *PCUNICODE_STRING;
254 #endif
255
256 /* Widely used macros */
257 #define LOBYTE(w) ((BYTE)(w))
258 #define HIBYTE(w) ((BYTE)(((WORD)(w)>>8)&0xFF))
259 #define LOWORD(l) ((WORD)((DWORD_PTR)(l)))
260 #define HIWORD(l) ((WORD)(((DWORD_PTR)(l)>>16)&0xFFFF))
261 #define MAKEWORD(a,b) ((WORD)(((BYTE)(a))|(((WORD)((BYTE)(b)))<<8)))
262 #define MAKELONG(a,b) ((LONG)(((WORD)(a))|(((DWORD)((WORD)(b)))<<16)))
263
264 #define MAXULONG 0xFFFFFFFF
265
266 #define NT_SUCCESS(x) ((x)>=0)
267 #if !defined(__GNUC__)
268 #define FIELD_OFFSET(t,f) ((LONG)(LONG_PTR)&(((t*) 0)->f))
269 #else
270 #define FIELD_OFFSET(t,f) ((LONG)__builtin_offsetof(t,f))
271 #endif
272 #define RTL_CONSTANT_STRING(s) { sizeof(s)-sizeof((s)[0]), sizeof(s), s }
273 #define CONTAINING_RECORD(address, type, field) ((type *)(((ULONG_PTR)address) - (ULONG_PTR)(&(((type *)0)->field))))
274
275 #define RtlZeroMemory(Destination, Length) memset(Destination, 0, Length)
276 #define RtlCopyMemory(Destination, Source, Length) memcpy(Destination, Source, Length)
277 #define RtlMoveMemory(Destination, Source, Length) memmove(Destination, Source, Length)
278
279 #define MAKELANGID(p,s) ((((WORD)(s))<<10)|(WORD)(p))
280 #define PRIMARYLANGID(l) ((WORD)(l)&0x3ff)
281 #define SUBLANGID(l) ((WORD)(l)>>10)
282 #define SUBLANG_NEUTRAL 0x00
283
284 /* Prevent inclusion of some other headers */
285 #define __INTERNAL_DEBUG
286 #define RTL_H
287
288 #endif
289