1 | /** @file
|
---|
2 | * innotek Portable Runtime - Common C and C++ definitions.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License as published by the Free Software Foundation,
|
---|
12 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
13 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
14 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | *
|
---|
16 | * If you received this file as part of a commercial VirtualBox
|
---|
17 | * distribution, then only the terms of your commercial VirtualBox
|
---|
18 | * license agreement apply instead of the previous paragraph.
|
---|
19 | */
|
---|
20 |
|
---|
21 | #ifndef __iprt_cdefs_h__
|
---|
22 | #define __iprt_cdefs_h__
|
---|
23 |
|
---|
24 |
|
---|
25 | /** @defgroup grp_rt_cdefs innotek Portable Runtime Common Definitions and Macros
|
---|
26 | * @{
|
---|
27 | */
|
---|
28 |
|
---|
29 | /*
|
---|
30 | * Include sys/cdefs.h if present, if not define the stuff we need.
|
---|
31 | */
|
---|
32 | #ifdef HAVE_SYS_CDEFS_H
|
---|
33 | # if defined(__LINUX__) && defined(__KERNEL__)
|
---|
34 | # error "oops"
|
---|
35 | # endif
|
---|
36 | # include <sys/cdefs.h>
|
---|
37 | #else
|
---|
38 |
|
---|
39 | /** @def __BEGIN_DECLS
|
---|
40 | * Used to start a block of function declarations which are shared
|
---|
41 | * between C and C++ program.
|
---|
42 | */
|
---|
43 |
|
---|
44 | /** @def __END_DECLS
|
---|
45 | * Used to end a block of function declarations which are shared
|
---|
46 | * between C and C++ program.
|
---|
47 | */
|
---|
48 |
|
---|
49 | #if defined(__cplusplus)
|
---|
50 | # define __BEGIN_DECLS extern "C" {
|
---|
51 | # define __END_DECLS }
|
---|
52 | #else
|
---|
53 | # define __BEGIN_DECLS
|
---|
54 | # define __END_DECLS
|
---|
55 | #endif
|
---|
56 |
|
---|
57 | #endif
|
---|
58 |
|
---|
59 |
|
---|
60 | /*
|
---|
61 | * Shut up DOXYGEN warnings and guide it properly thru the code.
|
---|
62 | */
|
---|
63 | #ifdef __DOXYGEN__
|
---|
64 | #define __AMD64__
|
---|
65 | #define __X86__
|
---|
66 | #define IN_RING0
|
---|
67 | #define IN_RING3
|
---|
68 | #define IN_GC
|
---|
69 | #define IN_RT_GC
|
---|
70 | #define IN_RT_R0
|
---|
71 | #define IN_RT_R3
|
---|
72 | #define RT_STRICT
|
---|
73 | #define Breakpoint
|
---|
74 | #define RT_NO_DEPRECATED_MACROS
|
---|
75 | #define ARCH_BITS
|
---|
76 | #define HC_ARCH_BITS
|
---|
77 | #define R3_ARCH_BITS
|
---|
78 | #define R0_ARCH_BITS
|
---|
79 | #define GC_ARCH_BITS
|
---|
80 | #endif /* __DOXYGEN__ */
|
---|
81 |
|
---|
82 | /** @def __X86__
|
---|
83 | * Indicates that we're compiling for the X86 architecture.
|
---|
84 | */
|
---|
85 |
|
---|
86 | /** @def __AMD64__
|
---|
87 | * Indicates that we're compiling for the AMD64 architecture.
|
---|
88 | */
|
---|
89 | #if !defined(__X86__) && !defined(__AMD64__)
|
---|
90 | # if defined(__amd64__) || defined(__x86_64__) || defined(_M_X64)
|
---|
91 | # define __AMD64__
|
---|
92 | # elif defined(__i386__) || defined(_M_IX86)
|
---|
93 | # define __X86__
|
---|
94 | # else
|
---|
95 | # error "Check what predefined stuff your compiler uses to indicate architecture."
|
---|
96 | # endif
|
---|
97 | #elif defined(__X86__) && defined(__AMD64__)
|
---|
98 | # error "Both __X86__ and __AMD64__ cannot be defined at the same time!"
|
---|
99 | #endif
|
---|
100 |
|
---|
101 | /** @def IN_RING0
|
---|
102 | * Used to indicate that we're compiling code which is running
|
---|
103 | * in Ring-0 Host Context.
|
---|
104 | */
|
---|
105 |
|
---|
106 | /** @def IN_RING3
|
---|
107 | * Used to indicate that we're compiling code which is running
|
---|
108 | * in Ring-3 Host Context.
|
---|
109 | */
|
---|
110 |
|
---|
111 | /** @def IN_GC
|
---|
112 | * Used to indicate that we're compiling code which is running
|
---|
113 | * in Guest Context (implies R0).
|
---|
114 | */
|
---|
115 | #if !defined(IN_RING3) && !defined(IN_RING0) && !defined(IN_GC)
|
---|
116 | # error "You must defined which context the compiled code should run in; IN_RING3, IN_RING0 or IN_GC"
|
---|
117 | #endif
|
---|
118 | #if (defined(IN_RING3) && (defined(IN_RING0) || defined(IN_GC)) ) \
|
---|
119 | || (defined(IN_RING0) && (defined(IN_RING3) || defined(IN_GC)) ) \
|
---|
120 | || (defined(IN_GC) && (defined(IN_RING3) || defined(IN_RING0)) )
|
---|
121 | # error "Only one of the IN_RING3, IN_RING0, IN_GC defines should be defined."
|
---|
122 | #endif
|
---|
123 |
|
---|
124 |
|
---|
125 | /** @def ARCH_BITS
|
---|
126 | * Defines the bit count of the current context.
|
---|
127 | */
|
---|
128 | #ifndef ARCH_BITS
|
---|
129 | # if defined(__AMD64__)
|
---|
130 | # define ARCH_BITS 64
|
---|
131 | # else
|
---|
132 | # define ARCH_BITS 32
|
---|
133 | # endif
|
---|
134 | #endif
|
---|
135 |
|
---|
136 | /** @def HC_ARCH_BITS
|
---|
137 | * Defines the host architechture bit count.
|
---|
138 | */
|
---|
139 | #ifndef HC_ARCH_BITS
|
---|
140 | # ifndef IN_GC
|
---|
141 | # define HC_ARCH_BITS ARCH_BITS
|
---|
142 | # else
|
---|
143 | # define HC_ARCH_BITS 32
|
---|
144 | # endif
|
---|
145 | #endif
|
---|
146 |
|
---|
147 | /** @def R3_ARCH_BITS
|
---|
148 | * Defines the host ring-3 architechture bit count.
|
---|
149 | */
|
---|
150 | #ifndef R3_ARCH_BITS
|
---|
151 | # ifdef IN_RING3
|
---|
152 | # define R3_ARCH_BITS ARCH_BITS
|
---|
153 | # else
|
---|
154 | # define R3_ARCH_BITS HC_ARCH_BITS
|
---|
155 | # endif
|
---|
156 | #endif
|
---|
157 |
|
---|
158 | /** @def R0_ARCH_BITS
|
---|
159 | * Defines the host ring-0 architechture bit count.
|
---|
160 | */
|
---|
161 | #ifndef R0_ARCH_BITS
|
---|
162 | # ifdef IN_RING0
|
---|
163 | # define R0_ARCH_BITS ARCH_BITS
|
---|
164 | # else
|
---|
165 | # define R0_ARCH_BITS HC_ARCH_BITS
|
---|
166 | # endif
|
---|
167 | #endif
|
---|
168 |
|
---|
169 | /** @def GC_ARCH_BITS
|
---|
170 | * Defines the guest architechture bit count.
|
---|
171 | */
|
---|
172 | #ifndef GC_ARCH_BITS
|
---|
173 | # ifdef IN_GC
|
---|
174 | # define GC_ARCH_BITS ARCH_BITS
|
---|
175 | # else
|
---|
176 | # define GC_ARCH_BITS 32
|
---|
177 | # endif
|
---|
178 | #endif
|
---|
179 |
|
---|
180 |
|
---|
181 | /** @def CTXTYPE
|
---|
182 | * Declare a type differently in GC, R3 and R0.
|
---|
183 | *
|
---|
184 | * @param GCType The GC type.
|
---|
185 | * @param R3Type The R3 type.
|
---|
186 | * @param R0Type The R0 type.
|
---|
187 | * @remark For pointers used only in one context use GCPTRTYPE(), HCPTRTYPE(), R3PTRTYPE() or R0PTRTYPE().
|
---|
188 | */
|
---|
189 | #ifdef IN_GC
|
---|
190 | # define CTXTYPE(GCType, R3Type, R0Type) GCType
|
---|
191 | #elif defined(IN_RING3)
|
---|
192 | # define CTXTYPE(GCType, R3Type, R0Type) R3Type
|
---|
193 | #else
|
---|
194 | # define CTXTYPE(GCType, R3Type, R0Type) R0Type
|
---|
195 | #endif
|
---|
196 |
|
---|
197 | /** @def GCTYPE
|
---|
198 | * Declare a type differently in GC and HC.
|
---|
199 | *
|
---|
200 | * @param GCType The GC type.
|
---|
201 | * @param HCType The HC type.
|
---|
202 | * @remark For pointers used only in one context use GCPTRTYPE(), HCPTRTYPE(), R3PTRTYPE() or R0PTRTYPE().
|
---|
203 | */
|
---|
204 | #define GCTYPE(GCType, HCType) CTXTYPE(GCType, HCType, HCType)
|
---|
205 |
|
---|
206 | /** @def GCPTRTYPE
|
---|
207 | * Declare a pointer which is used in GC but appears in structure(s) used by
|
---|
208 | * both HC and GC. The main purpose is to make sure structures have the same
|
---|
209 | * size when built for different architectures.
|
---|
210 | *
|
---|
211 | * @param GCType The GC type.
|
---|
212 | */
|
---|
213 | #define GCPTRTYPE(GCType) CTXTYPE(GCType, RTGCPTR, RTGCPTR)
|
---|
214 |
|
---|
215 | /** @def HCPTRTYPE
|
---|
216 | * Declare a pointer which is used in HC but appears in structure(s) used by
|
---|
217 | * both HC and GC. The main purpose is to make sure structures have the same
|
---|
218 | * size when built for different architectures.
|
---|
219 | *
|
---|
220 | * @param HCType The HC type.
|
---|
221 | */
|
---|
222 | #define HCPTRTYPE(HCType) CTXTYPE(RTHCPTR, HCType, HCType)
|
---|
223 |
|
---|
224 | /** @def R3PTRTYPE
|
---|
225 | * Declare a pointer which is used in R3 but appears in structure(s) used by
|
---|
226 | * both HC and GC. The main purpose is to make sure structures have the same
|
---|
227 | * size when built for different architectures.
|
---|
228 | *
|
---|
229 | * @param R3Type The R3 type.
|
---|
230 | */
|
---|
231 | #define R3PTRTYPE(R3Type) CTXTYPE(RTHCUINTPTR, R3Type, RTHCUINTPTR)
|
---|
232 |
|
---|
233 | /** @def R0PTRTYPE
|
---|
234 | * Declare a pointer which is used in R0 but appears in structure(s) used by
|
---|
235 | * both HC and GC. The main purpose is to make sure structures have the same
|
---|
236 | * size when built for different architectures.
|
---|
237 | *
|
---|
238 | * @param R0Type The R0 type.
|
---|
239 | */
|
---|
240 | #define R0PTRTYPE(R0Type) CTXTYPE(RTHCUINTPTR, RTHCUINTPTR, R0Type)
|
---|
241 |
|
---|
242 | /** @def CTXSUFF
|
---|
243 | * Adds the suffix of the current context to the passed in
|
---|
244 | * identifier name. The suffix is HC or GC.
|
---|
245 | *
|
---|
246 | * This is macro should only be used in shared code to avoid a forrest of ifdefs.
|
---|
247 | * @param var Identifier name.
|
---|
248 | */
|
---|
249 | /** @def OTHERCTXSUFF
|
---|
250 | * Adds the suffix of the other context to the passed in
|
---|
251 | * identifier name. The suffix is HC or GC.
|
---|
252 | *
|
---|
253 | * This is macro should only be used in shared code to avoid a forrest of ifdefs.
|
---|
254 | * @param var Identifier name.
|
---|
255 | */
|
---|
256 | #ifdef IN_GC
|
---|
257 | # define CTXSUFF(var) var##GC
|
---|
258 | # define OTHERCTXSUFF(var) var##HC
|
---|
259 | #else
|
---|
260 | # define CTXSUFF(var) var##HC
|
---|
261 | # define OTHERCTXSUFF(var) var##GC
|
---|
262 | #endif
|
---|
263 |
|
---|
264 | /** @def CTXALLSUFF
|
---|
265 | * Adds the suffix of the current context to the passed in
|
---|
266 | * identifier name. The suffix is R3, R0 or GC.
|
---|
267 | *
|
---|
268 | * This is macro should only be used in shared code to avoid a forrest of ifdefs.
|
---|
269 | * @param var Identifier name.
|
---|
270 | */
|
---|
271 | #ifdef IN_GC
|
---|
272 | # define CTXALLSUFF(var) var##GC
|
---|
273 | #elif defined(IN_RING0)
|
---|
274 | # define CTXALLSUFF(var) var##R0
|
---|
275 | #else
|
---|
276 | # define CTXALLSUFF(var) var##R3
|
---|
277 | #endif
|
---|
278 |
|
---|
279 | /** @def CTXMID
|
---|
280 | * Adds the current context as a middle name of an identifier name
|
---|
281 | * The middle name is HC or GC.
|
---|
282 | *
|
---|
283 | * This is macro should only be used in shared code to avoid a forrest of ifdefs.
|
---|
284 | * @param first First name.
|
---|
285 | * @param last Surname.
|
---|
286 | */
|
---|
287 | /** @def OTHERCTXMID
|
---|
288 | * Adds the other context as a middle name of an identifier name
|
---|
289 | * The middle name is HC or GC.
|
---|
290 | *
|
---|
291 | * This is macro should only be used in shared code to avoid a forrest of ifdefs.
|
---|
292 | * @param first First name.
|
---|
293 | * @param last Surname.
|
---|
294 | */
|
---|
295 | #ifdef IN_GC
|
---|
296 | # define CTXMID(first, last) first##GC##last
|
---|
297 | # define OTHERCTXMID(first, last) first##HC##last
|
---|
298 | #else
|
---|
299 | # define CTXMID(first, last) first##HC##last
|
---|
300 | # define OTHERCTXMID(first, last) first##GC##last
|
---|
301 | #endif
|
---|
302 |
|
---|
303 | /** @def CTXALLMID
|
---|
304 | * Adds the current context as a middle name of an identifier name
|
---|
305 | * The middle name is R3, R0 or GC.
|
---|
306 | *
|
---|
307 | * This is macro should only be used in shared code to avoid a forrest of ifdefs.
|
---|
308 | * @param first First name.
|
---|
309 | * @param last Surname.
|
---|
310 | */
|
---|
311 | #ifdef IN_GC
|
---|
312 | # define CTXALLMID(first, last) first##GC##last
|
---|
313 | #elif defined(IN_RING0)
|
---|
314 | # define CTXALLMID(first, last) first##R0##last
|
---|
315 | #else
|
---|
316 | # define CTXALLMID(first, last) first##R3##last
|
---|
317 | #endif
|
---|
318 |
|
---|
319 |
|
---|
320 | /** @def R3STRING
|
---|
321 | * A macro which in GC and R0 will return a dummy string while in R3 it will return
|
---|
322 | * the parameter.
|
---|
323 | *
|
---|
324 | * This is typically used to wrap description strings in structures shared
|
---|
325 | * between R3, R0 and/or GC. The intention is to avoid the \#ifdef IN_RING3 mess.
|
---|
326 | *
|
---|
327 | * @param pR3String The R3 string. Only referenced in R3.
|
---|
328 | * @see R0STRING and GCSTRING
|
---|
329 | */
|
---|
330 | #ifdef IN_RING3
|
---|
331 | # define R3STRING(pR3String) (pR3String)
|
---|
332 | #else
|
---|
333 | # define R3STRING(pR3String) ("<R3_STRING>")
|
---|
334 | #endif
|
---|
335 |
|
---|
336 | /** @def R0STRING
|
---|
337 | * A macro which in GC and R3 will return a dummy string while in R0 it will return
|
---|
338 | * the parameter.
|
---|
339 | *
|
---|
340 | * This is typically used to wrap description strings in structures shared
|
---|
341 | * between R3, R0 and/or GC. The intention is to avoid the \#ifdef IN_RING0 mess.
|
---|
342 | *
|
---|
343 | * @param pR0String The R0 string. Only referenced in R0.
|
---|
344 | * @see R3STRING and GCSTRING
|
---|
345 | */
|
---|
346 | #ifdef IN_RING0
|
---|
347 | # define R0STRING(pR0String) (pR0String)
|
---|
348 | #else
|
---|
349 | # define R0STRING(pR0String) ("<R0_STRING>")
|
---|
350 | #endif
|
---|
351 |
|
---|
352 | /** @def GCSTRING
|
---|
353 | * A macro which in R3 and R0 will return a dummy string while in GC it will return
|
---|
354 | * the parameter.
|
---|
355 | *
|
---|
356 | * This is typically used to wrap description strings in structures shared
|
---|
357 | * between R3, R0 and/or GC. The intention is to avoid the \#ifdef IN_GC mess.
|
---|
358 | *
|
---|
359 | * @param pR0String The GC string. Only referenced in GC.
|
---|
360 | * @see R3STRING, R0STRING
|
---|
361 | */
|
---|
362 | #ifdef IN_GC
|
---|
363 | # define GCSTRING(pR0String) (pGCString)
|
---|
364 | #else
|
---|
365 | # define GCSTRING(pR0String) ("<GC_STRING>")
|
---|
366 | #endif
|
---|
367 |
|
---|
368 | /** @def HCSTRING
|
---|
369 | * Macro which in GC will return a dummy string while in HC will return
|
---|
370 | * the parameter.
|
---|
371 | *
|
---|
372 | * This is typically used to wrap description strings in structures shared
|
---|
373 | * between HC and GC. The intention is to avoid the \#ifdef IN_GC kludge.
|
---|
374 | *
|
---|
375 | * @param pHCString The HC string. Only referenced in HC.
|
---|
376 | * @deprecated Use R3STRING or R0STRING instead.
|
---|
377 | */
|
---|
378 | #ifdef IN_GC
|
---|
379 | # define HCSTRING(pHCString) ("<HC_STRING>")
|
---|
380 | #else
|
---|
381 | # define HCSTRING(pHCString) (pHCString)
|
---|
382 | #endif
|
---|
383 |
|
---|
384 |
|
---|
385 | /** @def RTCALL
|
---|
386 | * The standard calling convention for the Runtime interfaces.
|
---|
387 | */
|
---|
388 | #ifdef _MSC_VER
|
---|
389 | # define RTCALL __cdecl
|
---|
390 | #elif defined(__GNUC__) && defined(IN_RING0) && !(defined(__OS2__) || defined(__AMD64__)) /* the latter is kernel/gcc */
|
---|
391 | # define RTCALL __attribute__((cdecl,regparm(0)))
|
---|
392 | #else
|
---|
393 | # define RTCALL
|
---|
394 | #endif
|
---|
395 |
|
---|
396 | /** @def DECLEXPORT
|
---|
397 | * How to declare an exported function.
|
---|
398 | * @param type The return type of the function declaration.
|
---|
399 | */
|
---|
400 | #if defined(_MSC_VER) || defined(__OS2__)
|
---|
401 | # define DECLEXPORT(type) __declspec(dllexport) type
|
---|
402 | #else
|
---|
403 | # ifdef VBOX_HAVE_VISIBILITY_HIDDEN
|
---|
404 | # define DECLEXPORT(type) __attribute__((visibility("default"))) type
|
---|
405 | # else
|
---|
406 | # define DECLEXPORT(type) type
|
---|
407 | # endif
|
---|
408 | #endif
|
---|
409 |
|
---|
410 | /** @def DECLIMPORT
|
---|
411 | * How to declare an imported function.
|
---|
412 | * @param type The return type of the function declaration.
|
---|
413 | */
|
---|
414 | #if defined(_MSC_VER) || (defined(__OS2__) && !defined(__IBMC__) && !defined(__IBMCPP__))
|
---|
415 | # define DECLIMPORT(type) __declspec(dllimport) type
|
---|
416 | #else
|
---|
417 | # define DECLIMPORT(type) type
|
---|
418 | #endif
|
---|
419 |
|
---|
420 | /** @def DECLASM
|
---|
421 | * How to declare an internal assembly function.
|
---|
422 | * @param type The return type of the function declaration.
|
---|
423 | */
|
---|
424 | #ifdef __cplusplus
|
---|
425 | # ifdef _MSC_VER
|
---|
426 | # define DECLASM(type) extern "C" type __cdecl
|
---|
427 | # else
|
---|
428 | # define DECLASM(type) extern "C" type
|
---|
429 | # endif
|
---|
430 | #else
|
---|
431 | # ifdef _MSC_VER
|
---|
432 | # define DECLASM(type) type __cdecl
|
---|
433 | # else
|
---|
434 | # define DECLASM(type) type
|
---|
435 | # endif
|
---|
436 | #endif
|
---|
437 |
|
---|
438 | /** @def DECLASMTYPE
|
---|
439 | * How to declare an internal assembly function type.
|
---|
440 | * @param type The return type of the function.
|
---|
441 | */
|
---|
442 | #ifdef _MSC_VER
|
---|
443 | # define DECLASMTYPE(type) type __cdecl
|
---|
444 | #else
|
---|
445 | # define DECLASMTYPE(type) type
|
---|
446 | #endif
|
---|
447 |
|
---|
448 | /** @def DECLCALLBACK
|
---|
449 | * How to declare an call back function type.
|
---|
450 | * @param type The return type of the function declaration.
|
---|
451 | */
|
---|
452 | #define DECLCALLBACK(type) type RTCALL
|
---|
453 |
|
---|
454 | /** @def DECLCALLBACKPTR
|
---|
455 | * How to declare an call back function pointer.
|
---|
456 | * @param type The return type of the function declaration.
|
---|
457 | * @param name The name of the variable member.
|
---|
458 | */
|
---|
459 | #define DECLCALLBACKPTR(type, name) type (RTCALL * name)
|
---|
460 |
|
---|
461 | /** @def DECLCALLBACKMEMBER
|
---|
462 | * How to declare an call back function pointer member.
|
---|
463 | * @param type The return type of the function declaration.
|
---|
464 | * @param name The name of the struct/union/class member.
|
---|
465 | */
|
---|
466 | #define DECLCALLBACKMEMBER(type, name) type (RTCALL * name)
|
---|
467 |
|
---|
468 | /** @def DECLR3CALLBACKMEMBER
|
---|
469 | * How to declare an call back function pointer member - R3 Ptr.
|
---|
470 | * @param type The return type of the function declaration.
|
---|
471 | * @param name The name of the struct/union/class member.
|
---|
472 | * @param args The argument list enclosed in parentheses.
|
---|
473 | */
|
---|
474 | #ifdef IN_RING3
|
---|
475 | # define DECLR3CALLBACKMEMBER(type, name, args) type (RTCALL * name) args
|
---|
476 | #else
|
---|
477 | # define DECLR3CALLBACKMEMBER(type, name, args) RTR3PTR name
|
---|
478 | #endif
|
---|
479 |
|
---|
480 | /** @def DECLGCCALLBACKMEMBER
|
---|
481 | * How to declare an call back function pointer member - GC Ptr.
|
---|
482 | * @param type The return type of the function declaration.
|
---|
483 | * @param name The name of the struct/union/class member.
|
---|
484 | * @param args The argument list enclosed in parentheses.
|
---|
485 | */
|
---|
486 | #ifdef IN_GC
|
---|
487 | # define DECLGCCALLBACKMEMBER(type, name, args) type (RTCALL * name) args
|
---|
488 | #else
|
---|
489 | # define DECLGCCALLBACKMEMBER(type, name, args) RTGCPTR name
|
---|
490 | #endif
|
---|
491 |
|
---|
492 | /** @def DECLR0CALLBACKMEMBER
|
---|
493 | * How to declare an call back function pointer member - R0 Ptr.
|
---|
494 | * @param type The return type of the function declaration.
|
---|
495 | * @param name The name of the struct/union/class member.
|
---|
496 | * @param args The argument list enclosed in parentheses.
|
---|
497 | */
|
---|
498 | #ifdef IN_RING0
|
---|
499 | # define DECLR0CALLBACKMEMBER(type, name, args) type (RTCALL * name) args
|
---|
500 | #else
|
---|
501 | # define DECLR0CALLBACKMEMBER(type, name, args) RTR0PTR name
|
---|
502 | #endif
|
---|
503 |
|
---|
504 | /** @def DECLINLINE
|
---|
505 | * How to declare a function as inline.
|
---|
506 | * @param type The return type of the function declaration.
|
---|
507 | */
|
---|
508 | #ifdef __GNUC__
|
---|
509 | # define DECLINLINE(type) static inline type
|
---|
510 | #elif defined(__cplusplus)
|
---|
511 | # define DECLINLINE(type) inline type
|
---|
512 | #elif defined(_MSC_VER)
|
---|
513 | # define DECLINLINE(type) _inline type
|
---|
514 | #elif defined(__IBMC__)
|
---|
515 | # define DECLINLINE(type) _Inline type
|
---|
516 | #else
|
---|
517 | # define DECLINLINE(type) inline type
|
---|
518 | #endif
|
---|
519 |
|
---|
520 |
|
---|
521 | /** @def IN_RT_R0
|
---|
522 | * Used to indicate whether we're inside the same link module as
|
---|
523 | * the HC Ring-0 Runtime Library.
|
---|
524 | */
|
---|
525 | /** @def RTR0DECL(type)
|
---|
526 | * Runtime Library HC Ring-0 export or import declaration.
|
---|
527 | * @param type The return type of the function declaration.
|
---|
528 | */
|
---|
529 | #ifdef IN_RT_R0
|
---|
530 | # define RTR0DECL(type) DECLEXPORT(type) RTCALL
|
---|
531 | #else
|
---|
532 | # define RTR0DECL(type) DECLIMPORT(type) RTCALL
|
---|
533 | #endif
|
---|
534 |
|
---|
535 | /** @def IN_RT_R3
|
---|
536 | * Used to indicate whether we're inside the same link module as
|
---|
537 | * the HC Ring-3 Runtime Library.
|
---|
538 | */
|
---|
539 | /** @def RTR3DECL(type)
|
---|
540 | * Runtime Library HC Ring-3 export or import declaration.
|
---|
541 | * @param type The return type of the function declaration.
|
---|
542 | */
|
---|
543 | #ifdef IN_RT_R3
|
---|
544 | # define RTR3DECL(type) DECLEXPORT(type) RTCALL
|
---|
545 | #else
|
---|
546 | # define RTR3DECL(type) DECLIMPORT(type) RTCALL
|
---|
547 | #endif
|
---|
548 |
|
---|
549 | /** @def IN_RT_GC
|
---|
550 | * Used to indicate whether we're inside the same link module as
|
---|
551 | * the GC Runtime Library.
|
---|
552 | */
|
---|
553 | /** @def RTGCDECL(type)
|
---|
554 | * Runtime Library HC Ring-3 export or import declaration.
|
---|
555 | * @param type The return type of the function declaration.
|
---|
556 | */
|
---|
557 | #ifdef IN_RT_GC
|
---|
558 | # define RTGCDECL(type) DECLEXPORT(type) RTCALL
|
---|
559 | #else
|
---|
560 | # define RTGCDECL(type) DECLIMPORT(type) RTCALL
|
---|
561 | #endif
|
---|
562 |
|
---|
563 | /** @def RTDECL(type)
|
---|
564 | * Runtime Library export or import declaration.
|
---|
565 | * Functions declared using this macro exists in all contexts.
|
---|
566 | * @param type The return type of the function declaration.
|
---|
567 | */
|
---|
568 | #if defined(IN_RT_R3) || defined(IN_RT_GC) || defined(IN_RT_R0)
|
---|
569 | # define RTDECL(type) DECLEXPORT(type) RTCALL
|
---|
570 | #else
|
---|
571 | # define RTDECL(type) DECLIMPORT(type) RTCALL
|
---|
572 | #endif
|
---|
573 |
|
---|
574 | /** @def RTDATADECL(type)
|
---|
575 | * Runtime Library export or import declaration.
|
---|
576 | * Data declared using this macro exists in all contexts.
|
---|
577 | * @param type The return type of the function declaration.
|
---|
578 | */
|
---|
579 | #if defined(IN_RT_R3) || defined(IN_RT_GC) || defined(IN_RT_R0)
|
---|
580 | # define RTDATADECL(type) DECLEXPORT(type)
|
---|
581 | #else
|
---|
582 | # define RTDATADECL(type) DECLIMPORT(type)
|
---|
583 | #endif
|
---|
584 |
|
---|
585 |
|
---|
586 | /** @def RT_NOCRT
|
---|
587 | * Symbol name wrapper for the No-CRT bits.
|
---|
588 | *
|
---|
589 | * In order to coexist in the same process as other CRTs, we need to
|
---|
590 | * decorate the symbols such that they don't conflict the ones in the
|
---|
591 | * other CRTs. The result of such conflicts / duplicate symbols can
|
---|
592 | * confuse the dynamic loader on unix like systems.
|
---|
593 | *
|
---|
594 | * Define RT_WITHOUT_NOCRT_WRAPPERS to drop the wrapping.
|
---|
595 | */
|
---|
596 | /** @def RT_NOCRT_STR
|
---|
597 | * Same as RT_NOCRT only it'll return a double quoted string of the result.
|
---|
598 | */
|
---|
599 | #ifndef RT_WITHOUT_NOCRT_WRAPPERS
|
---|
600 | # define RT_NOCRT(name) nocrt_ ## name
|
---|
601 | # define RT_NOCRT_STR(name) "nocrt_" # name
|
---|
602 | #else
|
---|
603 | # define RT_NOCRT(name) name
|
---|
604 | # define RT_NOCRT_STR(name) #name
|
---|
605 | #endif
|
---|
606 |
|
---|
607 |
|
---|
608 |
|
---|
609 | /** @def RT_LIKELY
|
---|
610 | * Give the compiler a hint that an expression is very likely to hold true.
|
---|
611 | *
|
---|
612 | * Some compilers support explicit branch prediction so that the CPU backend
|
---|
613 | * can hint the processor and also so that code blocks can be reordered such
|
---|
614 | * that the predicted path sees a more linear flow, thus improving cache
|
---|
615 | * behaviour, etc.
|
---|
616 | *
|
---|
617 | * IPRT provides the macros RT_LIKELY() and RT_UNLIKELY() as a way to utilize
|
---|
618 | * this compiler feature when present.
|
---|
619 | *
|
---|
620 | * A few notes about the usage:
|
---|
621 | *
|
---|
622 | * - Generally, use RT_UNLIKELY() with error condition checks (unless you
|
---|
623 | * have some _strong_ reason to do otherwise, in which case document it),
|
---|
624 | * and/or RT_LIKELY() with success condition checks, assuming you want
|
---|
625 | * to optimize for the success path.
|
---|
626 | *
|
---|
627 | * - Other than that, if you don't know the likelihood of a test succeeding
|
---|
628 | * from empirical or other 'hard' evidence, don't make predictions unless
|
---|
629 | * you happen to be a Dirk Gently.
|
---|
630 | *
|
---|
631 | * - These macros are meant to be used in places that get executed a lot. It
|
---|
632 | * is wasteful to make predictions in code that is executed seldomly (e.g.
|
---|
633 | * at subsystem initialization time) as the basic block reording that this
|
---|
634 | * affecs can often generate larger code.
|
---|
635 | *
|
---|
636 | * - Note that RT_SUCCESS() and RT_FAILURE() already makes use of RT_LIKELY()
|
---|
637 | * and RT_UNLIKELY(). Should you wish for prediction free status checks,
|
---|
638 | * use the RT_SUCCESS_NP() and RT_FAILURE_NP() macros instead.
|
---|
639 | *
|
---|
640 | *
|
---|
641 | * @returns the boolean result of the expression.
|
---|
642 | * @param expr The expression that's very likely to be true.
|
---|
643 | * @see RT_UNLIKELY
|
---|
644 | */
|
---|
645 | /** @def RT_UNLIKELY
|
---|
646 | * Give the compiler a hint that an expression is highly unlikely hold true.
|
---|
647 | *
|
---|
648 | * See the usage instructions give in the RT_LIKELY() docs.
|
---|
649 | *
|
---|
650 | * @returns the boolean result of the expression.
|
---|
651 | * @param expr The expression that's very unlikely to be true.
|
---|
652 | * @see RT_LIKELY
|
---|
653 | */
|
---|
654 | #if defined(__GNUC__)
|
---|
655 | # if __GNUC__ >= 3
|
---|
656 | # define RT_LIKELY(expr) __builtin_expect(!!(expr), 1)
|
---|
657 | # define RT_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
|
---|
658 | # else
|
---|
659 | # define RT_LIKELY(expr) (expr)
|
---|
660 | # define RT_UNLIKELY(expr) (expr)
|
---|
661 | # endif
|
---|
662 | #else
|
---|
663 | # define RT_LIKELY(expr) (expr)
|
---|
664 | # define RT_UNLIKELY(expr) (expr)
|
---|
665 | #endif
|
---|
666 |
|
---|
667 |
|
---|
668 | /** @def RT_BIT
|
---|
669 | * Make a bitmask for one integer sized bit.
|
---|
670 | * @param bit Bit number.
|
---|
671 | */
|
---|
672 | #define RT_BIT(bit) (1U << (bit))
|
---|
673 |
|
---|
674 | /** @def RT_BIT_32
|
---|
675 | * Make a 32-bit bitmask for one bit.
|
---|
676 | * @param bit Bit number.
|
---|
677 | */
|
---|
678 | #define RT_BIT_32(bit) (UINT32_C(1) << (bit))
|
---|
679 |
|
---|
680 | /** @def RT_BIT_64
|
---|
681 | * Make a 64-bit bitmask for one bit.
|
---|
682 | * @param bit Bit number.
|
---|
683 | */
|
---|
684 | #define RT_BIT_64(bit) (UINT64_C(1) << (bit))
|
---|
685 |
|
---|
686 | /** @def RT_ALIGN
|
---|
687 | * Align macro.
|
---|
688 | * @param u Value to align.
|
---|
689 | * @param uAlignment The alignment. Power of two!
|
---|
690 | *
|
---|
691 | * @remark Be extremely careful when using this macro with type which sizeof != sizeof int.
|
---|
692 | * When possible use any of the other RT_ALIGN_* macros. And when that's not
|
---|
693 | * possible, make 101% sure that uAlignment is specified with a right sized type.
|
---|
694 | *
|
---|
695 | * Specifying an unsigned 32-bit alignment constant with a 64-bit value will give
|
---|
696 | * you a 32-bit return value!
|
---|
697 | *
|
---|
698 | * In short: Don't use this macro. Use RT_ALIGN_T() instead.
|
---|
699 | */
|
---|
700 | #define RT_ALIGN(u, uAlignment) ( ((u) + ((uAlignment) - 1)) & ~((uAlignment) - 1) )
|
---|
701 |
|
---|
702 | /** @def RT_ALIGN_T
|
---|
703 | * Align macro.
|
---|
704 | * @param u Value to align.
|
---|
705 | * @param uAlignment The alignment. Power of two!
|
---|
706 | * @param type Integer type to use while aligning.
|
---|
707 | * @remark This macro is the prefered alignment macro, it doesn't have any of the pitfalls RT_ALIGN has.
|
---|
708 | */
|
---|
709 | #define RT_ALIGN_T(u, uAlignment, type) ( ((type)(u) + ((uAlignment) - 1)) & ~(type)((uAlignment) - 1) )
|
---|
710 |
|
---|
711 | /** @def RT_ALIGN_32
|
---|
712 | * Align macro for a 32-bit value.
|
---|
713 | * @param u32 Value to align.
|
---|
714 | * @param uAlignment The alignment. Power of two!
|
---|
715 | */
|
---|
716 | #define RT_ALIGN_32(u32, uAlignment) RT_ALIGN_T(u32, uAlignment, uint32_t)
|
---|
717 |
|
---|
718 | /** @def RT_ALIGN_64
|
---|
719 | * Align macro for a 64-bit value.
|
---|
720 | * @param u64 Value to align.
|
---|
721 | * @param uAlignment The alignment. Power of two!
|
---|
722 | */
|
---|
723 | #define RT_ALIGN_64(u64, uAlignment) RT_ALIGN_T(u64, uAlignment, uint64_t)
|
---|
724 |
|
---|
725 | /** @def RT_ALIGN_Z
|
---|
726 | * Align macro for size_t.
|
---|
727 | * @param cb Value to align.
|
---|
728 | * @param uAlignment The alignment. Power of two!
|
---|
729 | */
|
---|
730 | #define RT_ALIGN_Z(cb, uAlignment) RT_ALIGN_T(cb, uAlignment, size_t)
|
---|
731 |
|
---|
732 | /** @def RT_ALIGN_P
|
---|
733 | * Align macro for pointers.
|
---|
734 | * @param pv Value to align.
|
---|
735 | * @param uAlignment The alignment. Power of two!
|
---|
736 | */
|
---|
737 | #define RT_ALIGN_P(pv, uAlignment) RT_ALIGN_PT(pv, uAlignment, void *)
|
---|
738 |
|
---|
739 | /** @def RT_ALIGN_PT
|
---|
740 | * Align macro for pointers with type cast.
|
---|
741 | * @param u Value to align.
|
---|
742 | * @param uAlignment The alignment. Power of two!
|
---|
743 | * @param CastType The type to cast the result to.
|
---|
744 | */
|
---|
745 | #define RT_ALIGN_PT(u, uAlignment, CastType) ((CastType)RT_ALIGN_T(u, uAlignment, uintptr_t))
|
---|
746 |
|
---|
747 | /** @def RT_ALIGN_R3PT
|
---|
748 | * Align macro for ring-3 pointers with type cast.
|
---|
749 | * @param u Value to align.
|
---|
750 | * @param uAlignment The alignment. Power of two!
|
---|
751 | * @param CastType The type to cast the result to.
|
---|
752 | */
|
---|
753 | #define RT_ALIGN_R3PT(u, uAlignment, CastType) ((CastType)RT_ALIGN_T(u, uAlignment, RTR3UINTPTR))
|
---|
754 |
|
---|
755 | /** @def RT_ALIGN_R0PT
|
---|
756 | * Align macro for ring-0 pointers with type cast.
|
---|
757 | * @param u Value to align.
|
---|
758 | * @param uAlignment The alignment. Power of two!
|
---|
759 | * @param CastType The type to cast the result to.
|
---|
760 | */
|
---|
761 | #define RT_ALIGN_R0PT(u, uAlignment, CastType) ((CastType)RT_ALIGN_T(u, uAlignment, RTR0UINTPTR))
|
---|
762 |
|
---|
763 | /** @def RT_ALIGN_GCPT
|
---|
764 | * Align macro for GC pointers with type cast.
|
---|
765 | * @param u Value to align.
|
---|
766 | * @param uAlignment The alignment. Power of two!
|
---|
767 | * @param CastType The type to cast the result to.
|
---|
768 | */
|
---|
769 | #define RT_ALIGN_GCPT(u, uAlignment, CastType) ((CastType)RT_ALIGN_T(u, uAlignment, RTGCUINTPTR))
|
---|
770 |
|
---|
771 |
|
---|
772 | /** @def RT_OFFSETOF
|
---|
773 | * Our own special offsetof() variant.
|
---|
774 | *
|
---|
775 | * This differs from the usual offsetof() in that it's not relying on builtin
|
---|
776 | * compiler stuff and thus can use variables in arrays the structure may
|
---|
777 | * contain. If in this usful to determin the sizes of structures ending
|
---|
778 | * with a variable length field.
|
---|
779 | *
|
---|
780 | * @returns offset into the structure of the specified member.
|
---|
781 | * @param type Structure type.
|
---|
782 | * @param member Member.
|
---|
783 | */
|
---|
784 | #define RT_OFFSETOF(type, member) ( (int)(uintptr_t)&( ((type *)(void *)0)->member) )
|
---|
785 |
|
---|
786 | /** @def RT_SIZEOFMEMB
|
---|
787 | * Get the size of a structure member.
|
---|
788 | *
|
---|
789 | * @returns size of the structure member.
|
---|
790 | * @param type Structure type.
|
---|
791 | * @param member Member.
|
---|
792 | */
|
---|
793 | #define RT_SIZEOFMEMB(type, member) ( sizeof(((type *)(void *)0)->member) )
|
---|
794 |
|
---|
795 | /** @def RT_ELEMENTS
|
---|
796 | * Calcs the number of elements in an array.
|
---|
797 | * @returns Element count.
|
---|
798 | * @param aArray Array in question.
|
---|
799 | */
|
---|
800 | #define RT_ELEMENTS(aArray) ( sizeof(aArray) / sizeof((aArray)[0]) )
|
---|
801 |
|
---|
802 | #ifdef __OS2__
|
---|
803 | /* Undefine RT_MAX since there is an unfortunate clash with the max
|
---|
804 | resource type define in os2.h. */
|
---|
805 | # undef RT_MAX
|
---|
806 | #endif
|
---|
807 |
|
---|
808 | /** @def RT_MAX
|
---|
809 | * Finds the maximum value.
|
---|
810 | * @returns The higher of the two.
|
---|
811 | * @param Value1 Value 1
|
---|
812 | * @param Value2 Value 2
|
---|
813 | */
|
---|
814 | #define RT_MAX(Value1, Value2) ((Value1) >= (Value2) ? (Value1) : (Value2))
|
---|
815 |
|
---|
816 | /** @def RT_MIN
|
---|
817 | * Finds the minimum value.
|
---|
818 | * @returns The lower of the two.
|
---|
819 | * @param Value1 Value 1
|
---|
820 | * @param Value2 Value 2
|
---|
821 | */
|
---|
822 | #define RT_MIN(Value1, Value2) ((Value1) <= (Value2) ? (Value1) : (Value2))
|
---|
823 |
|
---|
824 | /** @def RT_ABS
|
---|
825 | * Get the absolute (non-negative) value.
|
---|
826 | * @returns The absolute value of Value.
|
---|
827 | * @param Value The value.
|
---|
828 | */
|
---|
829 | #define RT_ABS(Value) ((Value) >= 0 ? (Value) : -(Value))
|
---|
830 |
|
---|
831 | /** @def RT_LOWORD
|
---|
832 | * Gets the low word (=uint16_t) of something. */
|
---|
833 | #define RT_LOWORD(a) ((a) & 0xffff)
|
---|
834 |
|
---|
835 | /** @def RT_HIWORD
|
---|
836 | * Gets the high word (=uint16_t) of a 32 bit something. */
|
---|
837 | #define RT_HIWORD(a) ((a) >> 16)
|
---|
838 |
|
---|
839 | /** @def RT_LOBYTE
|
---|
840 | * Gets the low byte of something. */
|
---|
841 | #define RT_LOBYTE(a) ((a) & 0xff)
|
---|
842 |
|
---|
843 | /** @def RT_HIBYTE
|
---|
844 | * Gets the low byte of a 16 bit something. */
|
---|
845 | #define RT_HIBYTE(a) ((a) >> 8)
|
---|
846 |
|
---|
847 | /** @def RT_BYTE1
|
---|
848 | * Gets first byte of something. */
|
---|
849 | #define RT_BYTE1(a) ((a) & 0xff)
|
---|
850 |
|
---|
851 | /** @def RT_BYTE2
|
---|
852 | * Gets second byte of something. */
|
---|
853 | #define RT_BYTE2(a) (((a) >> 8) & 0xff)
|
---|
854 |
|
---|
855 | /** @def RT_BYTE3
|
---|
856 | * Gets second byte of something. */
|
---|
857 | #define RT_BYTE3(a) (((a) >> 16) & 0xff)
|
---|
858 |
|
---|
859 | /** @def RT_BYTE4
|
---|
860 | * Gets fourth byte of something. */
|
---|
861 | #define RT_BYTE4(a) (((a) >> 24) & 0xff)
|
---|
862 |
|
---|
863 |
|
---|
864 | /** @def RT_MAKE_U64
|
---|
865 | * Constructs a uint64_t value from two uint32_t values.
|
---|
866 | */
|
---|
867 | #define RT_MAKE_U64(Lo, Hi) ( (uint64_t)((uint32_t)(Hi)) << 32 | (uint32_t)(Lo) )
|
---|
868 |
|
---|
869 | /** @def RT_MAKE_U64_FROM_U16
|
---|
870 | * Constructs a uint64_t value from four uint16_t values.
|
---|
871 | */
|
---|
872 | #define RT_MAKE_U64_FROM_U16(w0, w1, w2, w3) \
|
---|
873 | ( (uint64_t)((uint16_t)(w3)) << 48 \
|
---|
874 | | (uint64_t)((uint16_t)(w2)) << 32 \
|
---|
875 | | (uint32_t)((uint16_t)(w1)) << 16 \
|
---|
876 | | (uint16_t)(w0) )
|
---|
877 |
|
---|
878 | /** @def RT_MAKE_U64_FROM_U8
|
---|
879 | * Constructs a uint64_t value from eight uint8_t values.
|
---|
880 | */
|
---|
881 | #define RT_MAKE_U64_FROM_U8(b0, b1, b2, b3, b4, b5, b6, b7) \
|
---|
882 | ( (uint64_t)((uint8_t)(b7)) << 56 \
|
---|
883 | | (uint64_t)((uint8_t)(b6)) << 48 \
|
---|
884 | | (uint64_t)((uint8_t)(b5)) << 40 \
|
---|
885 | | (uint64_t)((uint8_t)(b4)) << 32 \
|
---|
886 | | (uint32_t)((uint8_t)(b3)) << 24 \
|
---|
887 | | (uint32_t)((uint8_t)(b2)) << 16 \
|
---|
888 | | (uint16_t)((uint8_t)(b1)) << 8 \
|
---|
889 | | (uint8_t)(b0) )
|
---|
890 |
|
---|
891 | /** @def RT_MAKE_U32
|
---|
892 | * Constructs a uint32_t value from two uint16_t values.
|
---|
893 | */
|
---|
894 | #define RT_MAKE_U32(Lo, Hi) ( (uint32_t)((uint16_t)(Hi)) << 16 | (uint16_t)(Lo) )
|
---|
895 |
|
---|
896 | /** @def RT_MAKE_U32_FROM_U8
|
---|
897 | * Constructs a uint32_t value from four uint8_t values.
|
---|
898 | */
|
---|
899 | #define RT_MAKE_U32_FROM_U8(b0, b1, b2, b3) \
|
---|
900 | ( (uint32_t)((uint8_t)(b3)) << 24 \
|
---|
901 | | (uint32_t)((uint8_t)(b2)) << 16 \
|
---|
902 | | (uint16_t)((uint8_t)(b1)) << 8 \
|
---|
903 | | (uint8_t)(b0) )
|
---|
904 | /** @todo remove this after uses in VUSBUrb.cpp has been corrected. */
|
---|
905 | #define MAKE_U32_FROM_U8(b0,b1,b2,b3) RT_MAKE_U32_FROM_U8(b0,b1,b2,b3)
|
---|
906 |
|
---|
907 | /** @def RT_MAKE_U16
|
---|
908 | * Constructs a uint32_t value from two uint16_t values.
|
---|
909 | */
|
---|
910 | #define RT_MAKE_U16(Lo, Hi) ( (uint16_t)((uint8_t)(Hi)) << 8 | (uint8_t)(Lo) )
|
---|
911 |
|
---|
912 |
|
---|
913 | /** @def RT_H2LE_U64
|
---|
914 | * Converts uint64_t value from host to little endian byte order. */
|
---|
915 | #define RT_H2LE_U64(u64) (u64)
|
---|
916 |
|
---|
917 | /** @def RT_H2LE_U32
|
---|
918 | * Converts uint32_t value from host to little endian byte order. */
|
---|
919 | #define RT_H2LE_U32(u32) (u32)
|
---|
920 |
|
---|
921 | /** @def RT_H2LE_U16
|
---|
922 | * Converts uint16_t value from host to little endian byte order. */
|
---|
923 | #define RT_H2LE_U16(u16) (u16)
|
---|
924 |
|
---|
925 | /** @def RT_LE2H_U64
|
---|
926 | * Converts uint64_t value from little endian to host byte order. */
|
---|
927 | #define RT_LE2H_U64(u64) (u64)
|
---|
928 |
|
---|
929 | /** @def RT_LE2H_U32
|
---|
930 | * Converts uint32_t value from little endian to host byte order. */
|
---|
931 | #define RT_LE2H_U32(u32) (u32)
|
---|
932 |
|
---|
933 | /** @def RT_LE2H_U16
|
---|
934 | * Converts uint16_t value from little endian to host byte order. */
|
---|
935 | #define RT_LE2H_U16(u16) (u16)
|
---|
936 |
|
---|
937 |
|
---|
938 | /** @def RT_H2BE_U64
|
---|
939 | * Converts uint64_t value from host to big endian byte order. */
|
---|
940 | #define RT_H2BE_U64(u64) RT_MAKE_U64_FROM_U32(RT_H2BE_U32((u64) >> 32), RT_H2BE_U32((u64) & 0xffffffff))
|
---|
941 |
|
---|
942 | /** @def RT_H2BE_U32
|
---|
943 | * Converts uint32_t value from host to big endian byte order. */
|
---|
944 | #define RT_H2BE_U32(u32) (RT_BYTE4(u32) | (RT_BYTE3(u32) << 8) | (RT_BYTE2(u32) << 16) | (RT_BYTE1(u32) << 24))
|
---|
945 |
|
---|
946 | /** @def RT_H2BE_U16
|
---|
947 | * Converts uint16_t value from host to big endian byte order. */
|
---|
948 | #define RT_H2BE_U16(u16) (RT_HIBYTE(u16) | (RT_LOBYTE(u16) << 8))
|
---|
949 |
|
---|
950 | /** @def RT_BE2H_U64
|
---|
951 | * Converts uint64_t value from big endian to host byte order. */
|
---|
952 | #define RT_BE2H_U64(u64) RT_MAKE_U64_FROM_U32(RT_H2BE_U32((u64) >> 32), RT_H2BE_U32((u64) & 0xffffffff))
|
---|
953 |
|
---|
954 | /** @def RT_BE2H_U32
|
---|
955 | * Converts uint32_t value from big endian to host byte order. */
|
---|
956 | #define RT_BE2H_U32(u32) (RT_BYTE4(u32) | (RT_BYTE3(u32) << 8) | (RT_BYTE2(u32) << 16) | (RT_BYTE1(u32) << 24))
|
---|
957 |
|
---|
958 | /** @def RT_BE2H_U16
|
---|
959 | * Converts uint16_t value from big endian to host byte order. */
|
---|
960 | #define RT_BE2H_U16(u16) (RT_HIBYTE(u16) | (RT_LOBYTE(u16) << 8))
|
---|
961 |
|
---|
962 |
|
---|
963 | /** @def RT_H2N_U32
|
---|
964 | * Converts uint32_t value from host to network byte order. */
|
---|
965 | #define RT_H2N_U32(u32) RT_H2BE_U32(u32)
|
---|
966 |
|
---|
967 | /** @def RT_H2N_U16
|
---|
968 | * Converts uint16_t value from host to network byte order. */
|
---|
969 | #define RT_H2N_U16(u16) RT_H2BE_U16(u16)
|
---|
970 |
|
---|
971 | /** @def RT_N2H_U32
|
---|
972 | * Converts uint32_t value from network to host byte order. */
|
---|
973 | #define RT_N2H_U32(u32) RT_BE2H_U32(u32)
|
---|
974 |
|
---|
975 | /** @def RT_N2H_U16
|
---|
976 | * Converts uint16_t value from network to host byte order. */
|
---|
977 | #define RT_N2H_U16(u16) RT_BE2H_U16(u16)
|
---|
978 |
|
---|
979 |
|
---|
980 | /** @def RT_NO_DEPRECATED_MACROS
|
---|
981 | * Define RT_NO_DEPRECATED_MACROS to not define deprecated macros.
|
---|
982 | */
|
---|
983 | #ifndef RT_NO_DEPRECATED_MACROS
|
---|
984 | /** @copydoc BIT
|
---|
985 | * @deprecated Use RT_BIT.
|
---|
986 | */
|
---|
987 | # define BIT(bit) RT_BIT(bit)
|
---|
988 | /** @deprecated Use RT_BIT64. */
|
---|
989 | # define BIT64(bit) (1ULL << (bit))
|
---|
990 | /** @copydoc RT_ALIGN_P
|
---|
991 | * @deprecated use RT_ALIGN_P. */
|
---|
992 | # define ALIGNP(pv, uAlignment) RT_ALIGN_P(pv, uAlignment)
|
---|
993 | /** @copydoc RT_SIZEOFMEMB
|
---|
994 | * @deprecated Use RT_SIZEOFMEMB. */
|
---|
995 | # define SIZEOFMEMB(type, member) RT_SIZEOFMEMB(type, member)
|
---|
996 | /** @copydoc RT_ELEMENTS
|
---|
997 | * @deprecated use RT_ELEMENTS. */
|
---|
998 | # define ELEMENTS(aArray) RT_ELEMENTS(aArray)
|
---|
999 | #endif
|
---|
1000 |
|
---|
1001 |
|
---|
1002 | /*
|
---|
1003 | * The BSD sys/param.h + machine/param.h file is a major source of
|
---|
1004 | * namespace pollution. Kill off some of the worse ones unless we're
|
---|
1005 | * compiling kernel code.
|
---|
1006 | */
|
---|
1007 | #if defined(__DARWIN__) \
|
---|
1008 | && !defined(KERNEL) \
|
---|
1009 | && !defined(RT_NO_BSD_PARAM_H_UNDEFING) \
|
---|
1010 | && ( defined(_SYS_PARAM_H_) || defined(_I386_PARAM_H_) )
|
---|
1011 | /* sys/param.h: */
|
---|
1012 | # undef PSWP
|
---|
1013 | # undef PVM
|
---|
1014 | # undef PINOD
|
---|
1015 | # undef PRIBO
|
---|
1016 | # undef PVFS
|
---|
1017 | # undef PZERO
|
---|
1018 | # undef PSOCK
|
---|
1019 | # undef PWAIT
|
---|
1020 | # undef PLOCK
|
---|
1021 | # undef PPAUSE
|
---|
1022 | # undef PUSER
|
---|
1023 | # undef PRIMASK
|
---|
1024 | # undef MINBUCKET
|
---|
1025 | # undef MAXALLOCSAVE
|
---|
1026 | # undef FSHIFT
|
---|
1027 | # undef FSCALE
|
---|
1028 |
|
---|
1029 | /* i386/machine.h: */
|
---|
1030 | # undef ALIGN
|
---|
1031 | # undef ALIGNBYTES
|
---|
1032 | # undef DELAY
|
---|
1033 | # undef STATUS_WORD
|
---|
1034 | # undef USERMODE
|
---|
1035 | # undef BASEPRI
|
---|
1036 | # undef MSIZE
|
---|
1037 | # undef CLSIZE
|
---|
1038 | # undef CLSIZELOG2
|
---|
1039 | #endif
|
---|
1040 |
|
---|
1041 |
|
---|
1042 | /** @def NULL
|
---|
1043 | * NULL pointer.
|
---|
1044 | */
|
---|
1045 | #ifndef NULL
|
---|
1046 | # ifdef __cplusplus
|
---|
1047 | # define NULL 0
|
---|
1048 | # else
|
---|
1049 | # define NULL ((void*)0)
|
---|
1050 | # endif
|
---|
1051 | #endif
|
---|
1052 |
|
---|
1053 | /** @def NIL_OFFSET
|
---|
1054 | * NIL offset.
|
---|
1055 | * Whenever we use offsets instead of pointers to save space and relocation effort
|
---|
1056 | * NIL_OFFSET shall be used as the equivalent to NULL.
|
---|
1057 | */
|
---|
1058 | #define NIL_OFFSET (~0U)
|
---|
1059 |
|
---|
1060 | /** @def NOREF
|
---|
1061 | * Keeps the compiler from bitching about an unused parameters.
|
---|
1062 | */
|
---|
1063 | #define NOREF(var) (void)(var)
|
---|
1064 |
|
---|
1065 | /** @def Breakpoint
|
---|
1066 | * Emit a debug breakpoint instruction.
|
---|
1067 | *
|
---|
1068 | * Use this for instrumenting a debugging session only!
|
---|
1069 | * No comitted code shall use Breakpoint().
|
---|
1070 | */
|
---|
1071 | #ifdef __GNUC__
|
---|
1072 | # define Breakpoint() __asm__ __volatile__("int $3\n\t")
|
---|
1073 | #endif
|
---|
1074 | #ifdef _MSC_VER
|
---|
1075 | # define Breakpoint() __asm int 3
|
---|
1076 | #endif
|
---|
1077 | #if defined(__IBMC__) || defined(__IBMCPP__)
|
---|
1078 | # define Breakpoint() __interrupt(3)
|
---|
1079 | #endif
|
---|
1080 | #ifndef Breakpoint
|
---|
1081 | # error "This compiler is not supported!"
|
---|
1082 | #endif
|
---|
1083 |
|
---|
1084 |
|
---|
1085 | /** Size Constants
|
---|
1086 | * (Of course, these are binary computer terms, not SI.)
|
---|
1087 | * @{
|
---|
1088 | */
|
---|
1089 | /** 1 K (Kilo) (1 024). */
|
---|
1090 | #define _1K 0x00000400
|
---|
1091 | /** 4 K (Kilo) (4 096). */
|
---|
1092 | #define _4K 0x00001000
|
---|
1093 | /** 32 K (Kilo) (32 678). */
|
---|
1094 | #define _32K 0x00008000
|
---|
1095 | /** 64 K (Kilo) (65 536). */
|
---|
1096 | #define _64K 0x00010000
|
---|
1097 | /** 128 K (Kilo) (131 072). */
|
---|
1098 | #define _128K 0x00020000
|
---|
1099 | /** 256 K (Kilo) (262 144). */
|
---|
1100 | #define _256K 0x00040000
|
---|
1101 | /** 512 K (Kilo) (524 288). */
|
---|
1102 | #define _512K 0x00080000
|
---|
1103 | /** 1 M (Mega) (1 048 576). */
|
---|
1104 | #define _1M 0x00100000
|
---|
1105 | /** 2 M (Mega) (2 097 152). */
|
---|
1106 | #define _2M 0x00200000
|
---|
1107 | /** 4 M (Mega) (4 194 304). */
|
---|
1108 | #define _4M 0x00400000
|
---|
1109 | /** 1 G (Giga) (1 073 741 824). */
|
---|
1110 | #define _1G 0x40000000
|
---|
1111 | /** 2 G (Giga) (2 147 483 648). (32-bit) */
|
---|
1112 | #define _2G32 0x80000000U
|
---|
1113 | /** 2 G (Giga) (2 147 483 648). (64-bit) */
|
---|
1114 | #define _2G 0x0000000080000000LL
|
---|
1115 | /** 4 G (Giga) (4 294 967 296). */
|
---|
1116 | #define _4G 0x0000000100000000LL
|
---|
1117 | /** 1 T (Tera) (1 099 511 627 776). */
|
---|
1118 | #define _1T 0x0000010000000000LL
|
---|
1119 | /** 1 P (Peta) (1 125 899 906 842 624). */
|
---|
1120 | #define _1P 0x0004000000000000LL
|
---|
1121 | /** 1 E (Exa) (1 152 921 504 606 846 976). */
|
---|
1122 | #define _1E 0x1000000000000000LL
|
---|
1123 | /** 2 E (Exa) (2 305 843 009 213 693 952). */
|
---|
1124 | #define _2E 0x2000000000000000ULL
|
---|
1125 | /** @} */
|
---|
1126 |
|
---|
1127 | /** @def VALID_PTR
|
---|
1128 | * Pointer validation macro.
|
---|
1129 | * @param ptr
|
---|
1130 | */
|
---|
1131 | #if defined(__AMD64__)
|
---|
1132 | # ifdef IN_RING3
|
---|
1133 | # if defined(__DARWIN__) /* first 4GB is reserved for legacy kernel. */
|
---|
1134 | # define VALID_PTR(ptr) ( (uintptr_t)(ptr) >= _4G \
|
---|
1135 | && !((uintptr_t)(ptr) & 0xffff800000000000ULL) )
|
---|
1136 | # else
|
---|
1137 | # define VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
|
---|
1138 | && !((uintptr_t)(ptr) & 0xffff800000000000ULL) )
|
---|
1139 | # endif
|
---|
1140 | # else /* !IN_RING3 */
|
---|
1141 | # define VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
|
---|
1142 | && ( ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0xffff800000000000ULL \
|
---|
1143 | || ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0) )
|
---|
1144 | # endif /* !IN_RING3 */
|
---|
1145 | #elif defined(__X86__)
|
---|
1146 | # define VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U )
|
---|
1147 | #else
|
---|
1148 | # error "Architecture identifier missing / not implemented."
|
---|
1149 | #endif
|
---|
1150 |
|
---|
1151 |
|
---|
1152 | /** @def N_
|
---|
1153 | * The \#define N_ is used mark a string for translation. This is usable in
|
---|
1154 | * any part of the code, as it is only used by the tools that create message
|
---|
1155 | * catalogs. This macro is a no-op as far as the compiler and code generation
|
---|
1156 | * is concerned.
|
---|
1157 | *
|
---|
1158 | * If you want to both mark a string for translation and translate it, use _.
|
---|
1159 | */
|
---|
1160 | #define N_(s) (s)
|
---|
1161 |
|
---|
1162 | /** @def _
|
---|
1163 | * The \#define _ is used mark a string for translation and to translate it in
|
---|
1164 | * one step.
|
---|
1165 | *
|
---|
1166 | * If you want to only mark a string for translation, use N_.
|
---|
1167 | */
|
---|
1168 | #define _(s) gettext(s)
|
---|
1169 |
|
---|
1170 |
|
---|
1171 | /** @def __PRETTY_FUNCTION__
|
---|
1172 | * With GNU C we'd like to use the builtin __PRETTY_FUNCTION__, so define that for the other compilers.
|
---|
1173 | */
|
---|
1174 | #if !defined(__GNUC__) && !defined(__PRETTY_FUNCTION__)
|
---|
1175 | # define __PRETTY_FUNCTION__ __FUNCTION__
|
---|
1176 | #endif
|
---|
1177 |
|
---|
1178 |
|
---|
1179 | /** @def RT_STRICT
|
---|
1180 | * The \#define RT_STRICT controls whether or not assertions and other runtime checks
|
---|
1181 | * should be compiled in or not.
|
---|
1182 | *
|
---|
1183 | * If you want assertions which are not a subject to compile time options use
|
---|
1184 | * the AssertRelease*() flavors.
|
---|
1185 | */
|
---|
1186 | #if !defined(RT_STRICT) && defined(DEBUG)
|
---|
1187 | # define RT_STRICT
|
---|
1188 | #endif
|
---|
1189 |
|
---|
1190 | /** Source position. */
|
---|
1191 | #define RT_SRC_POS __FILE__, __LINE__, __PRETTY_FUNCTION__
|
---|
1192 |
|
---|
1193 | /** Source position declaration. */
|
---|
1194 | #define RT_SRC_POS_DECL const char *pszFile, unsigned iLine, const char *pszFunction
|
---|
1195 |
|
---|
1196 | /** Source position arguments. */
|
---|
1197 | #define RT_SRC_POS_ARGS pszFile, iLine, pszFunction
|
---|
1198 |
|
---|
1199 | /** @} */
|
---|
1200 |
|
---|
1201 |
|
---|
1202 | /** @defgroup grp_rt_cdefs_cpp Special Macros for C++
|
---|
1203 | * @ingroup grp_rt_cdefs
|
---|
1204 | * @{
|
---|
1205 | */
|
---|
1206 |
|
---|
1207 | #ifdef __cplusplus
|
---|
1208 |
|
---|
1209 | /** @def WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP
|
---|
1210 | * Macro to work around error C2593 of the not-so-smart MSVC 7.x ambiguity
|
---|
1211 | * resolver. The following snippet clearly demonstrates the code causing this
|
---|
1212 | * error:
|
---|
1213 | * @code
|
---|
1214 | * class A
|
---|
1215 | * {
|
---|
1216 | * public:
|
---|
1217 | * operator bool() const { return false; }
|
---|
1218 | * operator int*() const { return NULL; }
|
---|
1219 | * };
|
---|
1220 | * int main()
|
---|
1221 | * {
|
---|
1222 | * A a;
|
---|
1223 | * if (!a);
|
---|
1224 | * if (a && 0);
|
---|
1225 | * return 0;
|
---|
1226 | * }
|
---|
1227 | * @endcode
|
---|
1228 | * The code itself seems pretty valid to me and GCC thinks the same.
|
---|
1229 | *
|
---|
1230 | * This macro fixes the compiler error by explicitly overloading implicit
|
---|
1231 | * global operators !, && and || that take the given class instance as one of
|
---|
1232 | * their arguments.
|
---|
1233 | *
|
---|
1234 | * The best is to use this macro right after the class declaration.
|
---|
1235 | *
|
---|
1236 | * @note The macro expands to nothing for compilers other than MSVC.
|
---|
1237 | *
|
---|
1238 | * @param Cls Class to apply the workaround to
|
---|
1239 | */
|
---|
1240 | #if defined(_MSC_VER)
|
---|
1241 | # define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP(Cls) \
|
---|
1242 | inline bool operator! (const Cls &that) { return !bool (that); } \
|
---|
1243 | inline bool operator&& (const Cls &that, bool b) { return bool (that) && b; } \
|
---|
1244 | inline bool operator|| (const Cls &that, bool b) { return bool (that) || b; } \
|
---|
1245 | inline bool operator&& (bool b, const Cls &that) { return b && bool (that); } \
|
---|
1246 | inline bool operator|| (bool b, const Cls &that) { return b || bool (that); }
|
---|
1247 | #else
|
---|
1248 | # define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP(Cls)
|
---|
1249 | #endif
|
---|
1250 |
|
---|
1251 | /** @def WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL
|
---|
1252 | * Version of WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP for template classes.
|
---|
1253 | *
|
---|
1254 | * @param Tpl Name of the template class to apply the workaround to
|
---|
1255 | * @param ArgsDecl arguments of the template, as declared in |<>| after the
|
---|
1256 | * |template| keyword, including |<>|
|
---|
1257 | * @param Args arguments of the template, as specified in |<>| after the
|
---|
1258 | * template class name when using the, including |<>|
|
---|
1259 | *
|
---|
1260 | * Example:
|
---|
1261 | * @code
|
---|
1262 | * // template class declaration
|
---|
1263 | * template <class C>
|
---|
1264 | * class Foo { ... };
|
---|
1265 | * // applied workaround
|
---|
1266 | * WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL (Foo, <class C>, <C>)
|
---|
1267 | * @endcode
|
---|
1268 | */
|
---|
1269 | #if defined(_MSC_VER)
|
---|
1270 | # define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL(Tpl, ArgsDecl, Args) \
|
---|
1271 | template ArgsDecl \
|
---|
1272 | inline bool operator! (const Tpl Args &that) { return !bool (that); } \
|
---|
1273 | template ArgsDecl \
|
---|
1274 | inline bool operator&& (const Tpl Args &that, bool b) { return bool (that) && b; } \
|
---|
1275 | template ArgsDecl \
|
---|
1276 | inline bool operator|| (const Tpl Args &that, bool b) { return bool (that) || b; } \
|
---|
1277 | template ArgsDecl \
|
---|
1278 | inline bool operator&& (bool b, const Tpl Args &that) { return b && bool (that); } \
|
---|
1279 | template ArgsDecl \
|
---|
1280 | inline bool operator|| (bool b, const Tpl Args &that) { return b || bool (that); }
|
---|
1281 | #else
|
---|
1282 | # define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL(Tpl, ArgsDecl, Args)
|
---|
1283 | #endif
|
---|
1284 |
|
---|
1285 |
|
---|
1286 | /** @def DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP
|
---|
1287 | * Declares the copy constructor and the assignment operation as inlined no-ops
|
---|
1288 | * (non-existent functions) for the given class. Use this macro inside the
|
---|
1289 | * private section if you want to effectively disable these operations for your
|
---|
1290 | * class.
|
---|
1291 | *
|
---|
1292 | * @param Cls class name to declare for
|
---|
1293 | */
|
---|
1294 |
|
---|
1295 | #define DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(Cls) \
|
---|
1296 | inline Cls (const Cls &); \
|
---|
1297 | inline Cls &operator= (const Cls &);
|
---|
1298 |
|
---|
1299 |
|
---|
1300 | /** @def DECLARE_CLS_NEW_DELETE_NOOP
|
---|
1301 | * Declares the new and delete operations as no-ops (non-existent functions)
|
---|
1302 | * for the given class. Use this macro inside the private section if you want
|
---|
1303 | * to effectively limit creating class instances on the stack only.
|
---|
1304 | *
|
---|
1305 | * @note The destructor of the given class must not be virtual, otherwise a
|
---|
1306 | * compile time error will occur. Note that this is not a drawback: having
|
---|
1307 | * the virtual destructor for a stack-based class is absolutely useless
|
---|
1308 | * (the real class of the stack-based instance is always known to the compiler
|
---|
1309 | * at compile time, so it will always call the correct destructor).
|
---|
1310 | *
|
---|
1311 | * @param Cls class name to declare for
|
---|
1312 | */
|
---|
1313 | #define DECLARE_CLS_NEW_DELETE_NOOP(Cls) \
|
---|
1314 | inline static void *operator new (size_t); \
|
---|
1315 | inline static void operator delete (void *);
|
---|
1316 |
|
---|
1317 | #endif /* defined(__cplusplus) */
|
---|
1318 |
|
---|
1319 | /** @} */
|
---|
1320 |
|
---|
1321 | #endif
|
---|
1322 |
|
---|