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