Sync with trunk revision r58045 to bring the corrections on configure.cmd and on...
[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 /* Function attributes for GCC */
18 #if !defined(_MSC_VER) && !defined(__fastcall)
19 #define __fastcall __attribute__((fastcall))
20 #endif
21 #if !defined(_MSC_VER) && !defined(__cdecl)
22 #define __cdecl __attribute__((cdecl))
23 #endif
24 #if !defined(_MSC_VER) && !defined(__stdcall)
25 #define __stdcall __attribute__((stdcall))
26 #endif
27
28 /* Basic definitions */
29 #define UNIMPLEMENTED { printf("%s unimplemented\n", __FUNCTION__); exit(1); }
30 #define ASSERT(x) assert(x)
31 #define ASSERTMSG(x, m) assert(x)
32 #define DPRINT if (0) printf
33 #define DPRINT1 printf
34
35 #define NTAPI
36 #define WINAPI
37
38 #define IN
39 #define OUT
40 #define OPTIONAL
41
42 #define FALSE 0
43 #define TRUE 1
44
45 #define ANYSIZE_ARRAY 1
46
47 /* Basic types
48 Emulate a LLP64 memory model using a LP64 compiler */
49 typedef void VOID, *PVOID;
50 typedef char CHAR, CCHAR, *PCHAR, *PSTR;
51 typedef const char *PCSTR, *LPCSTR;
52 typedef unsigned char UCHAR, *PUCHAR, BYTE, *LPBYTE, BOOLEAN, *PBOOLEAN;
53 typedef short SHORT, *PSHORT;
54 typedef unsigned short USHORT, *PUSHORT, WORD, *PWORD, *LPWORD, WCHAR, *PWCHAR, *PWSTR, *LPWSTR;
55 typedef const unsigned short *PCWSTR, *LPCWSTR;
56 typedef int INT, LONG, *PLONG, *LPLONG, BOOL;
57 typedef unsigned int UINT, *PUINT, *LPUINT, ULONG, *PULONG, DWORD, *LPDWORD;
58 typedef long LONG_PTR, *PLONG_PTR, INT_PTR, *PINT_PTR;
59 typedef unsigned long ULONG_PTR, DWORD_PTR, *PULONG_PTR, UINT_PTR, *PUINT_PTR;
60 typedef long long LONGLONG;
61 typedef unsigned long long ULONGLONG;
62
63 /* Derived types */
64 typedef PVOID HANDLE, HKEY, *PHKEY;
65 typedef INT NTSTATUS, POOL_TYPE;
66 typedef LONG HRESULT;
67 typedef ULONG_PTR SIZE_T, *PSIZE_T;
68 typedef WORD LANGID;
69
70 #define MAXUSHORT USHRT_MAX
71
72 /* Widely used structures */
73 #include <pshpack4.h>
74 typedef struct _RTL_BITMAP
75 {
76 ULONG SizeOfBitMap;
77 PULONG Buffer;
78 } RTL_BITMAP, *PRTL_BITMAP;
79
80 typedef struct _RTL_BITMAP_RUN
81 {
82 ULONG StartingIndex;
83 ULONG NumberOfBits;
84 } RTL_BITMAP_RUN, *PRTL_BITMAP_RUN;
85
86 typedef union _LARGE_INTEGER
87 {
88 struct
89 {
90 DWORD LowPart;
91 LONG HighPart;
92 };
93 LONGLONG QuadPart;
94 } LARGE_INTEGER, *PLARGE_INTEGER;
95
96 typedef struct _LIST_ENTRY
97 {
98 struct _LIST_ENTRY *Flink;
99 struct _LIST_ENTRY *Blink;
100 } LIST_ENTRY,*PLIST_ENTRY;
101
102 typedef struct _ANSI_STRING
103 {
104 USHORT Length;
105 USHORT MaximumLength;
106 PSTR Buffer;
107 } ANSI_STRING, *PANSI_STRING;
108
109 typedef struct _UNICODE_STRING
110 {
111 USHORT Length;
112 USHORT MaximumLength;
113 PWSTR Buffer;
114 } UNICODE_STRING, *PUNICODE_STRING;
115 #include <poppack.h>
116
117 /* List Functions */
118 static __inline
119 VOID
120 InitializeListHead(
121 IN PLIST_ENTRY ListHead
122 )
123 {
124 ListHead->Flink = ListHead->Blink = ListHead;
125 }
126
127 static __inline
128 VOID
129 InsertHeadList(
130 IN PLIST_ENTRY ListHead,
131 IN PLIST_ENTRY Entry
132 )
133 {
134 PLIST_ENTRY OldFlink;
135 OldFlink = ListHead->Flink;
136 Entry->Flink = OldFlink;
137 Entry->Blink = ListHead;
138 OldFlink->Blink = Entry;
139 ListHead->Flink = Entry;
140 }
141
142 static __inline
143 VOID
144 InsertTailList(
145 IN PLIST_ENTRY ListHead,
146 IN PLIST_ENTRY Entry
147 )
148 {
149 PLIST_ENTRY OldBlink;
150 OldBlink = ListHead->Blink;
151 Entry->Flink = ListHead;
152 Entry->Blink = OldBlink;
153 OldBlink->Flink = Entry;
154 ListHead->Blink = Entry;
155 }
156
157 static __inline
158 BOOLEAN
159 IsListEmpty(
160 IN const LIST_ENTRY * ListHead
161 )
162 {
163 return (BOOLEAN)(ListHead->Flink == ListHead);
164 }
165
166 static __inline
167 BOOLEAN
168 RemoveEntryList(
169 IN PLIST_ENTRY Entry)
170 {
171 PLIST_ENTRY OldFlink;
172 PLIST_ENTRY OldBlink;
173
174 OldFlink = Entry->Flink;
175 OldBlink = Entry->Blink;
176 OldFlink->Blink = OldBlink;
177 OldBlink->Flink = OldFlink;
178 return (BOOLEAN)(OldFlink == OldBlink);
179 }
180
181 static __inline
182 PLIST_ENTRY
183 RemoveHeadList(
184 IN PLIST_ENTRY ListHead)
185 {
186 PLIST_ENTRY Flink;
187 PLIST_ENTRY Entry;
188
189 Entry = ListHead->Flink;
190 Flink = Entry->Flink;
191 ListHead->Flink = Flink;
192 Flink->Blink = ListHead;
193 return Entry;
194 }
195
196 static __inline
197 PLIST_ENTRY
198 RemoveTailList(
199 IN PLIST_ENTRY ListHead)
200 {
201 PLIST_ENTRY Blink;
202 PLIST_ENTRY Entry;
203
204 Entry = ListHead->Blink;
205 Blink = Entry->Blink;
206 ListHead->Blink = Blink;
207 Blink->Flink = ListHead;
208 return Entry;
209 }
210
211 typedef const UNICODE_STRING *PCUNICODE_STRING;
212
213 /* Widely used macros */
214 #define LOBYTE(w) ((BYTE)(w))
215 #define HIBYTE(w) ((BYTE)(((WORD)(w)>>8)&0xFF))
216 #define LOWORD(l) ((WORD)((DWORD_PTR)(l)))
217 #define HIWORD(l) ((WORD)(((DWORD_PTR)(l)>>16)&0xFFFF))
218 #define MAKEWORD(a,b) ((WORD)(((BYTE)(a))|(((WORD)((BYTE)(b)))<<8)))
219 #define MAKELONG(a,b) ((LONG)(((WORD)(a))|(((DWORD)((WORD)(b)))<<16)))
220
221 #define MAXULONG 0xFFFFFFFF
222
223 #define NT_SUCCESS(x) ((x)>=0)
224 #if !defined(__GNUC__)
225 #define FIELD_OFFSET(t,f) ((LONG)(LONG_PTR)&(((t*) 0)->f))
226 #else
227 #define FIELD_OFFSET(t,f) ((LONG)__builtin_offsetof(t,f))
228 #endif
229 #define RTL_CONSTANT_STRING(s) { sizeof(s)-sizeof((s)[0]), sizeof(s), s }
230 #define CONTAINING_RECORD(address, type, field) ((type *)(((ULONG_PTR)address) - (ULONG_PTR)(&(((type *)0)->field))))
231
232 #define RtlZeroMemory(Destination, Length) memset(Destination, 0, Length)
233 #define RtlCopyMemory(Destination, Source, Length) memcpy(Destination, Source, Length)
234 #define RtlMoveMemory(Destination, Source, Length) memmove(Destination, Source, Length)
235
236 #define MAKELANGID(p,s) ((((WORD)(s))<<10)|(WORD)(p))
237 #define PRIMARYLANGID(l) ((WORD)(l)&0x3ff)
238 #define SUBLANGID(l) ((WORD)(l)>>10)
239 #define SUBLANG_NEUTRAL 0x00
240
241 /* Prevent inclusion of some other headers */
242 #define __INTERNAL_DEBUG
243 #define RTL_H
244
245 #endif