Sync with trunk head (part 1 of x)
[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
69 #define MAXUSHORT USHRT_MAX
70
71 /* Widely used structures */
72 #include <host/pshpack4.h>
73 typedef struct _RTL_BITMAP
74 {
75 ULONG SizeOfBitMap;
76 PULONG Buffer;
77 } RTL_BITMAP, *PRTL_BITMAP;
78
79 typedef struct _RTL_BITMAP_RUN
80 {
81 ULONG StartingIndex;
82 ULONG NumberOfBits;
83 } RTL_BITMAP_RUN, *PRTL_BITMAP_RUN;
84
85 typedef union _LARGE_INTEGER
86 {
87 struct
88 {
89 DWORD LowPart;
90 LONG HighPart;
91 };
92 LONGLONG QuadPart;
93 } LARGE_INTEGER, *PLARGE_INTEGER;
94
95 typedef struct _LIST_ENTRY
96 {
97 struct _LIST_ENTRY *Flink;
98 struct _LIST_ENTRY *Blink;
99 } LIST_ENTRY,*PLIST_ENTRY;
100
101 typedef struct _ANSI_STRING
102 {
103 USHORT Length;
104 USHORT MaximumLength;
105 PSTR Buffer;
106 } ANSI_STRING, *PANSI_STRING;
107
108 typedef struct _UNICODE_STRING
109 {
110 USHORT Length;
111 USHORT MaximumLength;
112 PWSTR Buffer;
113 } UNICODE_STRING, *PUNICODE_STRING;
114 #include <host/poppack.h>
115
116 /* List Functions */
117 static __inline
118 VOID
119 InitializeListHead(
120 IN PLIST_ENTRY ListHead
121 )
122 {
123 ListHead->Flink = ListHead->Blink = ListHead;
124 }
125
126 static __inline
127 VOID
128 InsertHeadList(
129 IN PLIST_ENTRY ListHead,
130 IN PLIST_ENTRY Entry
131 )
132 {
133 PLIST_ENTRY OldFlink;
134 OldFlink = ListHead->Flink;
135 Entry->Flink = OldFlink;
136 Entry->Blink = ListHead;
137 OldFlink->Blink = Entry;
138 ListHead->Flink = Entry;
139 }
140
141 static __inline
142 VOID
143 InsertTailList(
144 IN PLIST_ENTRY ListHead,
145 IN PLIST_ENTRY Entry
146 )
147 {
148 PLIST_ENTRY OldBlink;
149 OldBlink = ListHead->Blink;
150 Entry->Flink = ListHead;
151 Entry->Blink = OldBlink;
152 OldBlink->Flink = Entry;
153 ListHead->Blink = Entry;
154 }
155
156 static __inline
157 BOOLEAN
158 IsListEmpty(
159 IN const LIST_ENTRY * ListHead
160 )
161 {
162 return (BOOLEAN)(ListHead->Flink == ListHead);
163 }
164
165 static __inline
166 BOOLEAN
167 RemoveEntryList(
168 IN PLIST_ENTRY Entry)
169 {
170 PLIST_ENTRY OldFlink;
171 PLIST_ENTRY OldBlink;
172
173 OldFlink = Entry->Flink;
174 OldBlink = Entry->Blink;
175 OldFlink->Blink = OldBlink;
176 OldBlink->Flink = OldFlink;
177 return (BOOLEAN)(OldFlink == OldBlink);
178 }
179
180 static __inline
181 PLIST_ENTRY
182 RemoveHeadList(
183 IN PLIST_ENTRY ListHead)
184 {
185 PLIST_ENTRY Flink;
186 PLIST_ENTRY Entry;
187
188 Entry = ListHead->Flink;
189 Flink = Entry->Flink;
190 ListHead->Flink = Flink;
191 Flink->Blink = ListHead;
192 return Entry;
193 }
194
195 static __inline
196 PLIST_ENTRY
197 RemoveTailList(
198 IN PLIST_ENTRY ListHead)
199 {
200 PLIST_ENTRY Blink;
201 PLIST_ENTRY Entry;
202
203 Entry = ListHead->Blink;
204 Blink = Entry->Blink;
205 ListHead->Blink = Blink;
206 Blink->Flink = ListHead;
207 return Entry;
208 }
209
210 typedef const UNICODE_STRING *PCUNICODE_STRING;
211
212 /* Widely used macros */
213 #define LOBYTE(w) ((BYTE)(w))
214 #define HIBYTE(w) ((BYTE)(((WORD)(w)>>8)&0xFF))
215 #define LOWORD(l) ((WORD)((DWORD_PTR)(l)))
216 #define HIWORD(l) ((WORD)(((DWORD_PTR)(l)>>16)&0xFFFF))
217 #define MAKEWORD(a,b) ((WORD)(((BYTE)(a))|(((WORD)((BYTE)(b)))<<8)))
218 #define MAKELONG(a,b) ((LONG)(((WORD)(a))|(((DWORD)((WORD)(b)))<<16)))
219
220 #define MAXULONG 0xFFFFFFFF
221
222 #define NT_SUCCESS(x) ((x)>=0)
223 #if !defined(__GNUC__)
224 #define FIELD_OFFSET(t,f) ((LONG)(LONG_PTR)&(((t*) 0)->f))
225 #else
226 #define FIELD_OFFSET(t,f) ((LONG)__builtin_offsetof(t,f))
227 #endif
228 #define RTL_CONSTANT_STRING(s) { sizeof(s)-sizeof((s)[0]), sizeof(s), s }
229 #define CONTAINING_RECORD(address, type, field) ((type *)(((ULONG_PTR)address) - (ULONG_PTR)(&(((type *)0)->field))))
230
231 #define RtlZeroMemory(Destination, Length) memset(Destination, 0, Length)
232 #define RtlCopyMemory(Destination, Source, Length) memcpy(Destination, Source, Length)
233 #define RtlMoveMemory(Destination, Source, Length) memmove(Destination, Source, Length)
234
235 /* Prevent inclusion of some other headers */
236 #define __INTERNAL_DEBUG
237 #define RTL_H
238
239 #endif