1 | /** @file
|
---|
2 | * IPRT - Common C and C++ definitions.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2009 Oracle Corporation
|
---|
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 (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | *
|
---|
16 | * The contents of this file may alternatively be used under the terms
|
---|
17 | * of the Common Development and Distribution License Version 1.0
|
---|
18 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
19 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
20 | * CDDL are applicable instead of those of the GPL.
|
---|
21 | *
|
---|
22 | * You may elect to license modified versions of this file under the
|
---|
23 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
24 | */
|
---|
25 |
|
---|
26 | #ifndef ___iprt_cdefs_h
|
---|
27 | #define ___iprt_cdefs_h
|
---|
28 |
|
---|
29 |
|
---|
30 | /** @defgroup grp_rt_cdefs IPRT Common Definitions and Macros
|
---|
31 | * @{
|
---|
32 | */
|
---|
33 |
|
---|
34 | /*
|
---|
35 | * Include sys/cdefs.h if present, if not define the stuff we need.
|
---|
36 | */
|
---|
37 | #ifdef HAVE_SYS_CDEFS_H
|
---|
38 | # if defined(RT_ARCH_LINUX) && defined(__KERNEL__)
|
---|
39 | # error "oops"
|
---|
40 | # endif
|
---|
41 | # include <sys/cdefs.h>
|
---|
42 | #else
|
---|
43 |
|
---|
44 | /** @def RT_C_DECLS_BEGIN
|
---|
45 | * Used to start a block of function declarations which are shared
|
---|
46 | * between C and C++ program.
|
---|
47 | */
|
---|
48 |
|
---|
49 | /** @def RT_C_DECLS_END
|
---|
50 | * Used to end a block of function declarations which are shared
|
---|
51 | * between C and C++ program.
|
---|
52 | */
|
---|
53 |
|
---|
54 | # if defined(__cplusplus)
|
---|
55 | # define RT_C_DECLS_BEGIN extern "C" {
|
---|
56 | # define RT_C_DECLS_END }
|
---|
57 | # else
|
---|
58 | # define RT_C_DECLS_BEGIN
|
---|
59 | # define RT_C_DECLS_END
|
---|
60 | # endif
|
---|
61 |
|
---|
62 | #endif
|
---|
63 |
|
---|
64 |
|
---|
65 | /*
|
---|
66 | * Shut up DOXYGEN warnings and guide it properly thru the code.
|
---|
67 | */
|
---|
68 | #ifdef DOXYGEN_RUNNING
|
---|
69 | #define __AMD64__
|
---|
70 | #define __X86__
|
---|
71 | #define RT_ARCH_AMD64
|
---|
72 | #define RT_ARCH_X86
|
---|
73 | #define IN_RING0
|
---|
74 | #define IN_RING3
|
---|
75 | #define IN_RC
|
---|
76 | #define IN_RC
|
---|
77 | #define IN_RT_RC
|
---|
78 | #define IN_RT_R0
|
---|
79 | #define IN_RT_R3
|
---|
80 | #define IN_RT_STATIC
|
---|
81 | #define RT_STRICT
|
---|
82 | #define RT_LOCK_STRICT
|
---|
83 | #define RT_LOCK_NO_STRICT
|
---|
84 | #define RT_LOCK_STRICT_ORDER
|
---|
85 | #define RT_LOCK_NO_STRICT_ORDER
|
---|
86 | #define Breakpoint
|
---|
87 | #define RT_NO_DEPRECATED_MACROS
|
---|
88 | #define RT_EXCEPTIONS_ENABLED
|
---|
89 | #define RT_BIG_ENDIAN
|
---|
90 | #define RT_LITTLE_ENDIAN
|
---|
91 | #endif /* DOXYGEN_RUNNING */
|
---|
92 |
|
---|
93 | /** @def RT_ARCH_X86
|
---|
94 | * Indicates that we're compiling for the X86 architecture.
|
---|
95 | */
|
---|
96 |
|
---|
97 | /** @def RT_ARCH_AMD64
|
---|
98 | * Indicates that we're compiling for the AMD64 architecture.
|
---|
99 | */
|
---|
100 |
|
---|
101 | /** @def RT_ARCH_SPARC
|
---|
102 | * Indicates that we're compiling for the SPARC V8 architecture (32-bit).
|
---|
103 | */
|
---|
104 |
|
---|
105 | /** @def RT_ARCH_SPARC64
|
---|
106 | * Indicates that we're compiling for the SPARC V9 architecture (64-bit).
|
---|
107 | */
|
---|
108 | #if !defined(RT_ARCH_X86) && !defined(RT_ARCH_AMD64) && !defined(RT_ARCH_SPARC) && !defined(RT_ARCH_SPARC64)
|
---|
109 | # if defined(__amd64__) || defined(__x86_64__) || defined(_M_X64) || defined(__AMD64__)
|
---|
110 | # define RT_ARCH_AMD64
|
---|
111 | # elif defined(__i386__) || defined(_M_IX86) || defined(__X86__)
|
---|
112 | # define RT_ARCH_X86
|
---|
113 | # elif defined(__sparc64__)
|
---|
114 | # define RT_ARCH_SPARC64
|
---|
115 | # elif defined(__sparc__)
|
---|
116 | # define RT_ARCH_SPARC
|
---|
117 | # else /* PORTME: append test for new archs. */
|
---|
118 | # error "Check what predefined macros your compiler uses to indicate architecture."
|
---|
119 | # endif
|
---|
120 | /* PORTME: append new archs checks. */
|
---|
121 | #elif defined(RT_ARCH_X86) && defined(RT_ARCH_AMD64)
|
---|
122 | # error "Both RT_ARCH_X86 and RT_ARCH_AMD64 cannot be defined at the same time!"
|
---|
123 | #elif defined(RT_ARCH_X86) && defined(RT_ARCH_SPARC)
|
---|
124 | # error "Both RT_ARCH_X86 and RT_ARCH_SPARC cannot be defined at the same time!"
|
---|
125 | #elif defined(RT_ARCH_X86) && defined(RT_ARCH_SPARC64)
|
---|
126 | # error "Both RT_ARCH_X86 and RT_ARCH_SPARC64 cannot be defined at the same time!"
|
---|
127 | #elif defined(RT_ARCH_AMD64) && defined(RT_ARCH_SPARC)
|
---|
128 | # error "Both RT_ARCH_AMD64 and RT_ARCH_SPARC cannot be defined at the same time!"
|
---|
129 | #elif defined(RT_ARCH_AMD64) && defined(RT_ARCH_SPARC64)
|
---|
130 | # error "Both RT_ARCH_AMD64 and RT_ARCH_SPARC64 cannot be defined at the same time!"
|
---|
131 | #elif defined(RT_ARCH_SPARC) && defined(RT_ARCH_SPARC64)
|
---|
132 | # error "Both RT_ARCH_SPARC and RT_ARCH_SPARC64 cannot be defined at the same time!"
|
---|
133 | #endif
|
---|
134 |
|
---|
135 |
|
---|
136 | /** @def __X86__
|
---|
137 | * Indicates that we're compiling for the X86 architecture.
|
---|
138 | * @deprecated
|
---|
139 | */
|
---|
140 |
|
---|
141 | /** @def __AMD64__
|
---|
142 | * Indicates that we're compiling for the AMD64 architecture.
|
---|
143 | * @deprecated
|
---|
144 | */
|
---|
145 | #if !defined(__X86__) && !defined(__AMD64__) && !defined(RT_ARCH_SPARC) && !defined(RT_ARCH_SPARC64)
|
---|
146 | # if defined(RT_ARCH_AMD64)
|
---|
147 | # define __AMD64__
|
---|
148 | # elif defined(RT_ARCH_X86)
|
---|
149 | # define __X86__
|
---|
150 | # else
|
---|
151 | # error "Check what predefined macros your compiler uses to indicate architecture."
|
---|
152 | # endif
|
---|
153 | #elif defined(__X86__) && defined(__AMD64__)
|
---|
154 | # error "Both __X86__ and __AMD64__ cannot be defined at the same time!"
|
---|
155 | #elif defined(__X86__) && !defined(RT_ARCH_X86)
|
---|
156 | # error "Both __X86__ without RT_ARCH_X86!"
|
---|
157 | #elif defined(__AMD64__) && !defined(RT_ARCH_AMD64)
|
---|
158 | # error "Both __AMD64__ without RT_ARCH_AMD64!"
|
---|
159 | #endif
|
---|
160 |
|
---|
161 | /** @def RT_BIG_ENDIAN
|
---|
162 | * Defined if the architecture is big endian. */
|
---|
163 | /** @def RT_LITTLE_ENDIAN
|
---|
164 | * Defined if the architecture is little endian. */
|
---|
165 | #if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
|
---|
166 | # define RT_LITTLE_ENDIAN
|
---|
167 | #elif defined(RT_ARCH_SPARC) || defined(RT_ARCH_SPARC64)
|
---|
168 | # define RT_BIG_ENDIAN
|
---|
169 | #else
|
---|
170 | # error "PORTME: architecture endianess"
|
---|
171 | #endif
|
---|
172 | #if defined(RT_BIG_ENDIAN) && defined(RT_LITTLE_ENDIAN)
|
---|
173 | # error "Both RT_BIG_ENDIAN and RT_LITTLE_ENDIAN are defined"
|
---|
174 | #endif
|
---|
175 |
|
---|
176 |
|
---|
177 | /** @def IN_RING0
|
---|
178 | * Used to indicate that we're compiling code which is running
|
---|
179 | * in Ring-0 Host Context.
|
---|
180 | */
|
---|
181 |
|
---|
182 | /** @def IN_RING3
|
---|
183 | * Used to indicate that we're compiling code which is running
|
---|
184 | * in Ring-3 Host Context.
|
---|
185 | */
|
---|
186 |
|
---|
187 | /** @def IN_RC
|
---|
188 | * Used to indicate that we're compiling code which is running
|
---|
189 | * in the Raw-mode Context (implies R0).
|
---|
190 | */
|
---|
191 | #if !defined(IN_RING3) && !defined(IN_RING0) && !defined(IN_RC) && !defined(IN_RC)
|
---|
192 | # error "You must define which context the compiled code should run in; IN_RING3, IN_RING0 or IN_RC"
|
---|
193 | #endif
|
---|
194 | #if (defined(IN_RING3) && (defined(IN_RING0) || defined(IN_RC)) ) \
|
---|
195 | || (defined(IN_RING0) && (defined(IN_RING3) || defined(IN_RC)) ) \
|
---|
196 | || (defined(IN_RC) && (defined(IN_RING3) || defined(IN_RING0)) )
|
---|
197 | # error "Only one of the IN_RING3, IN_RING0, IN_RC defines should be defined."
|
---|
198 | #endif
|
---|
199 |
|
---|
200 |
|
---|
201 | /** @def ARCH_BITS
|
---|
202 | * Defines the bit count of the current context.
|
---|
203 | */
|
---|
204 | #if !defined(ARCH_BITS) || defined(DOXYGEN_RUNNING)
|
---|
205 | # if defined(RT_ARCH_AMD64) || defined(RT_ARCH_SPARC64)
|
---|
206 | # define ARCH_BITS 64
|
---|
207 | # else
|
---|
208 | # define ARCH_BITS 32
|
---|
209 | # endif
|
---|
210 | #endif
|
---|
211 |
|
---|
212 | /** @def HC_ARCH_BITS
|
---|
213 | * Defines the host architecture bit count.
|
---|
214 | */
|
---|
215 | #if !defined(HC_ARCH_BITS) || defined(DOXYGEN_RUNNING)
|
---|
216 | # ifndef IN_RC
|
---|
217 | # define HC_ARCH_BITS ARCH_BITS
|
---|
218 | # else
|
---|
219 | # define HC_ARCH_BITS 32
|
---|
220 | # endif
|
---|
221 | #endif
|
---|
222 |
|
---|
223 | /** @def GC_ARCH_BITS
|
---|
224 | * Defines the guest architecture bit count.
|
---|
225 | */
|
---|
226 | #if !defined(GC_ARCH_BITS) && !defined(DOXYGEN_RUNNING)
|
---|
227 | # ifdef VBOX_WITH_64_BITS_GUESTS
|
---|
228 | # define GC_ARCH_BITS 64
|
---|
229 | # else
|
---|
230 | # define GC_ARCH_BITS 32
|
---|
231 | # endif
|
---|
232 | #endif
|
---|
233 |
|
---|
234 | /** @def R3_ARCH_BITS
|
---|
235 | * Defines the host ring-3 architecture bit count.
|
---|
236 | */
|
---|
237 | #if !defined(R3_ARCH_BITS) || defined(DOXYGEN_RUNNING)
|
---|
238 | # ifdef IN_RING3
|
---|
239 | # define R3_ARCH_BITS ARCH_BITS
|
---|
240 | # else
|
---|
241 | # define R3_ARCH_BITS HC_ARCH_BITS
|
---|
242 | # endif
|
---|
243 | #endif
|
---|
244 |
|
---|
245 | /** @def R0_ARCH_BITS
|
---|
246 | * Defines the host ring-0 architecture bit count.
|
---|
247 | */
|
---|
248 | #if !defined(R0_ARCH_BITS) || defined(DOXYGEN_RUNNING)
|
---|
249 | # ifdef IN_RING0
|
---|
250 | # define R0_ARCH_BITS ARCH_BITS
|
---|
251 | # else
|
---|
252 | # define R0_ARCH_BITS HC_ARCH_BITS
|
---|
253 | # endif
|
---|
254 | #endif
|
---|
255 |
|
---|
256 | /** @def GC_ARCH_BITS
|
---|
257 | * Defines the guest architecture bit count.
|
---|
258 | */
|
---|
259 | #if !defined(GC_ARCH_BITS) || defined(DOXYGEN_RUNNING)
|
---|
260 | # ifdef IN_RC
|
---|
261 | # define GC_ARCH_BITS ARCH_BITS
|
---|
262 | # else
|
---|
263 | # define GC_ARCH_BITS 32
|
---|
264 | # endif
|
---|
265 | #endif
|
---|
266 |
|
---|
267 |
|
---|
268 | /** @def CTXTYPE
|
---|
269 | * Declare a type differently in GC, R3 and R0.
|
---|
270 | *
|
---|
271 | * @param GCType The GC type.
|
---|
272 | * @param R3Type The R3 type.
|
---|
273 | * @param R0Type The R0 type.
|
---|
274 | * @remark For pointers used only in one context use RCPTRTYPE(), R3R0PTRTYPE(), R3PTRTYPE() or R0PTRTYPE().
|
---|
275 | */
|
---|
276 | #ifdef IN_RC
|
---|
277 | # define CTXTYPE(GCType, R3Type, R0Type) GCType
|
---|
278 | #elif defined(IN_RING3)
|
---|
279 | # define CTXTYPE(GCType, R3Type, R0Type) R3Type
|
---|
280 | #else
|
---|
281 | # define CTXTYPE(GCType, R3Type, R0Type) R0Type
|
---|
282 | #endif
|
---|
283 |
|
---|
284 | /** @def RCPTRTYPE
|
---|
285 | * Declare a pointer which is used in the raw mode context but appears in structure(s) used by
|
---|
286 | * both HC and RC. The main purpose is to make sure structures have the same
|
---|
287 | * size when built for different architectures.
|
---|
288 | *
|
---|
289 | * @param RCType The RC type.
|
---|
290 | */
|
---|
291 | #define RCPTRTYPE(RCType) CTXTYPE(RCType, RTRCPTR, RTRCPTR)
|
---|
292 |
|
---|
293 | /** @def R3R0PTRTYPE
|
---|
294 | * Declare a pointer which is used in HC, is explicitly valid in ring 3 and 0,
|
---|
295 | * but appears in structure(s) used by both HC and GC. The main purpose is to
|
---|
296 | * make sure structures have the same size when built for different architectures.
|
---|
297 | *
|
---|
298 | * @param R3R0Type The R3R0 type.
|
---|
299 | * @remarks This used to be called HCPTRTYPE.
|
---|
300 | */
|
---|
301 | #define R3R0PTRTYPE(R3R0Type) CTXTYPE(RTHCPTR, R3R0Type, R3R0Type)
|
---|
302 |
|
---|
303 | /** @def R3PTRTYPE
|
---|
304 | * Declare a pointer which is used in R3 but appears in structure(s) used by
|
---|
305 | * both HC and GC. The main purpose is to make sure structures have the same
|
---|
306 | * size when built for different architectures.
|
---|
307 | *
|
---|
308 | * @param R3Type The R3 type.
|
---|
309 | */
|
---|
310 | #define R3PTRTYPE(R3Type) CTXTYPE(RTHCUINTPTR, R3Type, RTHCUINTPTR)
|
---|
311 |
|
---|
312 | /** @def R0PTRTYPE
|
---|
313 | * Declare a pointer which is used in R0 but appears in structure(s) used by
|
---|
314 | * both HC and GC. The main purpose is to make sure structures have the same
|
---|
315 | * size when built for different architectures.
|
---|
316 | *
|
---|
317 | * @param R0Type The R0 type.
|
---|
318 | */
|
---|
319 | #define R0PTRTYPE(R0Type) CTXTYPE(RTHCUINTPTR, RTHCUINTPTR, R0Type)
|
---|
320 |
|
---|
321 | /** @def CTXSUFF
|
---|
322 | * Adds the suffix of the current context to the passed in
|
---|
323 | * identifier name. The suffix is HC or GC.
|
---|
324 | *
|
---|
325 | * This is macro should only be used in shared code to avoid a forest of ifdefs.
|
---|
326 | * @param var Identifier name.
|
---|
327 | * @deprecated Use CTX_SUFF. Do NOT use this for new code.
|
---|
328 | */
|
---|
329 | /** @def OTHERCTXSUFF
|
---|
330 | * Adds the suffix of the other context to the passed in
|
---|
331 | * identifier name. The suffix is HC or GC.
|
---|
332 | *
|
---|
333 | * This is macro should only be used in shared code to avoid a forest of ifdefs.
|
---|
334 | * @param var Identifier name.
|
---|
335 | * @deprecated Use CTX_SUFF. Do NOT use this for new code.
|
---|
336 | */
|
---|
337 | #ifdef IN_RC
|
---|
338 | # define CTXSUFF(var) var##GC
|
---|
339 | # define OTHERCTXSUFF(var) var##HC
|
---|
340 | #else
|
---|
341 | # define CTXSUFF(var) var##HC
|
---|
342 | # define OTHERCTXSUFF(var) var##GC
|
---|
343 | #endif
|
---|
344 |
|
---|
345 | /** @def CTXALLSUFF
|
---|
346 | * Adds the suffix of the current context to the passed in
|
---|
347 | * identifier name. The suffix is R3, R0 or GC.
|
---|
348 | *
|
---|
349 | * This is macro should only be used in shared code to avoid a forest of ifdefs.
|
---|
350 | * @param var Identifier name.
|
---|
351 | * @deprecated Use CTX_SUFF. Do NOT use this for new code.
|
---|
352 | */
|
---|
353 | #ifdef IN_RC
|
---|
354 | # define CTXALLSUFF(var) var##GC
|
---|
355 | #elif defined(IN_RING0)
|
---|
356 | # define CTXALLSUFF(var) var##R0
|
---|
357 | #else
|
---|
358 | # define CTXALLSUFF(var) var##R3
|
---|
359 | #endif
|
---|
360 |
|
---|
361 | /** @def CTX_SUFF
|
---|
362 | * Adds the suffix of the current context to the passed in
|
---|
363 | * identifier name. The suffix is R3, R0 or RC.
|
---|
364 | *
|
---|
365 | * This is macro should only be used in shared code to avoid a forest of ifdefs.
|
---|
366 | * @param var Identifier name.
|
---|
367 | *
|
---|
368 | * @remark This will replace CTXALLSUFF and CTXSUFF before long.
|
---|
369 | */
|
---|
370 | #ifdef IN_RC
|
---|
371 | # define CTX_SUFF(var) var##RC
|
---|
372 | #elif defined(IN_RING0)
|
---|
373 | # define CTX_SUFF(var) var##R0
|
---|
374 | #else
|
---|
375 | # define CTX_SUFF(var) var##R3
|
---|
376 | #endif
|
---|
377 |
|
---|
378 | /** @def CTX_SUFF_Z
|
---|
379 | * Adds the suffix of the current context to the passed in
|
---|
380 | * identifier name, combining RC and R0 into RZ.
|
---|
381 | * The suffix thus is R3 or RZ.
|
---|
382 | *
|
---|
383 | * This is macro should only be used in shared code to avoid a forest of ifdefs.
|
---|
384 | * @param var Identifier name.
|
---|
385 | *
|
---|
386 | * @remark This will replace CTXALLSUFF and CTXSUFF before long.
|
---|
387 | */
|
---|
388 | #ifdef IN_RING3
|
---|
389 | # define CTX_SUFF_Z(var) var##R3
|
---|
390 | #else
|
---|
391 | # define CTX_SUFF_Z(var) var##RZ
|
---|
392 | #endif
|
---|
393 |
|
---|
394 |
|
---|
395 | /** @def CTXMID
|
---|
396 | * Adds the current context as a middle name of an identifier name
|
---|
397 | * The middle name is HC or GC.
|
---|
398 | *
|
---|
399 | * This is macro should only be used in shared code to avoid a forest of ifdefs.
|
---|
400 | * @param first First name.
|
---|
401 | * @param last Surname.
|
---|
402 | */
|
---|
403 | /** @def OTHERCTXMID
|
---|
404 | * Adds the other context as a middle name of an identifier name
|
---|
405 | * The middle name is HC or GC.
|
---|
406 | *
|
---|
407 | * This is macro should only be used in shared code to avoid a forest of ifdefs.
|
---|
408 | * @param first First name.
|
---|
409 | * @param last Surname.
|
---|
410 | * @deprecated use CTX_MID or CTX_MID_Z
|
---|
411 | */
|
---|
412 | #ifdef IN_RC
|
---|
413 | # define CTXMID(first, last) first##GC##last
|
---|
414 | # define OTHERCTXMID(first, last) first##HC##last
|
---|
415 | #else
|
---|
416 | # define CTXMID(first, last) first##HC##last
|
---|
417 | # define OTHERCTXMID(first, last) first##GC##last
|
---|
418 | #endif
|
---|
419 |
|
---|
420 | /** @def CTXALLMID
|
---|
421 | * Adds the current context as a middle name of an identifier name.
|
---|
422 | * The middle name is R3, R0 or GC.
|
---|
423 | *
|
---|
424 | * This is macro should only be used in shared code to avoid a forest of ifdefs.
|
---|
425 | * @param first First name.
|
---|
426 | * @param last Surname.
|
---|
427 | * @deprecated use CTX_MID or CTX_MID_Z
|
---|
428 | */
|
---|
429 | #ifdef IN_RC
|
---|
430 | # define CTXALLMID(first, last) first##GC##last
|
---|
431 | #elif defined(IN_RING0)
|
---|
432 | # define CTXALLMID(first, last) first##R0##last
|
---|
433 | #else
|
---|
434 | # define CTXALLMID(first, last) first##R3##last
|
---|
435 | #endif
|
---|
436 |
|
---|
437 | /** @def CTX_MID
|
---|
438 | * Adds the current context as a middle name of an identifier name.
|
---|
439 | * The middle name is R3, R0 or RC.
|
---|
440 | *
|
---|
441 | * This is macro should only be used in shared code to avoid a forest of ifdefs.
|
---|
442 | * @param first First name.
|
---|
443 | * @param last Surname.
|
---|
444 | */
|
---|
445 | #ifdef IN_RC
|
---|
446 | # define CTX_MID(first, last) first##RC##last
|
---|
447 | #elif defined(IN_RING0)
|
---|
448 | # define CTX_MID(first, last) first##R0##last
|
---|
449 | #else
|
---|
450 | # define CTX_MID(first, last) first##R3##last
|
---|
451 | #endif
|
---|
452 |
|
---|
453 | /** @def CTX_MID_Z
|
---|
454 | * Adds the current context as a middle name of an identifier name, combining RC
|
---|
455 | * and R0 into RZ.
|
---|
456 | * The middle name thus is either R3 or RZ.
|
---|
457 | *
|
---|
458 | * This is macro should only be used in shared code to avoid a forest of ifdefs.
|
---|
459 | * @param first First name.
|
---|
460 | * @param last Surname.
|
---|
461 | */
|
---|
462 | #ifdef IN_RING3
|
---|
463 | # define CTX_MID_Z(first, last) first##R3##last
|
---|
464 | #else
|
---|
465 | # define CTX_MID_Z(first, last) first##RZ##last
|
---|
466 | #endif
|
---|
467 |
|
---|
468 |
|
---|
469 | /** @def R3STRING
|
---|
470 | * A macro which in GC and R0 will return a dummy string while in R3 it will return
|
---|
471 | * the parameter.
|
---|
472 | *
|
---|
473 | * This is typically used to wrap description strings in structures shared
|
---|
474 | * between R3, R0 and/or GC. The intention is to avoid the \#ifdef IN_RING3 mess.
|
---|
475 | *
|
---|
476 | * @param pR3String The R3 string. Only referenced in R3.
|
---|
477 | * @see R0STRING and GCSTRING
|
---|
478 | */
|
---|
479 | #ifdef IN_RING3
|
---|
480 | # define R3STRING(pR3String) (pR3String)
|
---|
481 | #else
|
---|
482 | # define R3STRING(pR3String) ("<R3_STRING>")
|
---|
483 | #endif
|
---|
484 |
|
---|
485 | /** @def R0STRING
|
---|
486 | * A macro which in GC and R3 will return a dummy string while in R0 it will return
|
---|
487 | * the parameter.
|
---|
488 | *
|
---|
489 | * This is typically used to wrap description strings in structures shared
|
---|
490 | * between R3, R0 and/or GC. The intention is to avoid the \#ifdef IN_RING0 mess.
|
---|
491 | *
|
---|
492 | * @param pR0String The R0 string. Only referenced in R0.
|
---|
493 | * @see R3STRING and GCSTRING
|
---|
494 | */
|
---|
495 | #ifdef IN_RING0
|
---|
496 | # define R0STRING(pR0String) (pR0String)
|
---|
497 | #else
|
---|
498 | # define R0STRING(pR0String) ("<R0_STRING>")
|
---|
499 | #endif
|
---|
500 |
|
---|
501 | /** @def RCSTRING
|
---|
502 | * A macro which in R3 and R0 will return a dummy string while in RC it will return
|
---|
503 | * the parameter.
|
---|
504 | *
|
---|
505 | * This is typically used to wrap description strings in structures shared
|
---|
506 | * between R3, R0 and/or RC. The intention is to avoid the \#ifdef IN_RC mess.
|
---|
507 | *
|
---|
508 | * @param pRCString The RC string. Only referenced in RC.
|
---|
509 | * @see R3STRING, R0STRING
|
---|
510 | */
|
---|
511 | #ifdef IN_RC
|
---|
512 | # define RCSTRING(pRCString) (pRCString)
|
---|
513 | #else
|
---|
514 | # define RCSTRING(pRCString) ("<RC_STRING>")
|
---|
515 | #endif
|
---|
516 |
|
---|
517 |
|
---|
518 | /** @def RT_NOTHING
|
---|
519 | * A macro that expands to nothing.
|
---|
520 | * This is primarily intended as a dummy argument for macros to avoid the
|
---|
521 | * undefined behavior passing empty arguments to an macro (ISO C90 and C++98,
|
---|
522 | * gcc v4.4 warns about it).
|
---|
523 | */
|
---|
524 | #define RT_NOTHING
|
---|
525 |
|
---|
526 | /** @def RT_EXCEPTIONS_ENABLED
|
---|
527 | * Defined when C++ exceptions are enabled.
|
---|
528 | */
|
---|
529 | #if !defined(RT_EXCEPTIONS_ENABLED) \
|
---|
530 | && defined(__cplusplus) \
|
---|
531 | && ( (defined(_MSC_VER) && defined(_CPPUNWIND)) \
|
---|
532 | || (defined(__GNUC__) && defined(__EXCEPTIONS)))
|
---|
533 | # define RT_EXCEPTIONS_ENABLED
|
---|
534 | #endif
|
---|
535 |
|
---|
536 | /** @def RT_NO_THROW
|
---|
537 | * How to express that a function doesn't throw C++ exceptions
|
---|
538 | * and the compiler can thus save itself the bother of trying
|
---|
539 | * to catch any of them. Put this between the closing parenthesis
|
---|
540 | * and the semicolon in function prototypes (and implementation if C++).
|
---|
541 | */
|
---|
542 | #ifdef RT_EXCEPTIONS_ENABLED
|
---|
543 | # define RT_NO_THROW throw()
|
---|
544 | #else
|
---|
545 | # define RT_NO_THROW
|
---|
546 | #endif
|
---|
547 |
|
---|
548 | /** @def RT_THROW
|
---|
549 | * How to express that a method or function throws a type of exceptions. Some
|
---|
550 | * compilers does not want this kind of information and will warning about it.
|
---|
551 | *
|
---|
552 | * @param type The type exception.
|
---|
553 | *
|
---|
554 | * @remarks If the actual throwing is done from the header, enclose it by
|
---|
555 | * \#ifdef RT_EXCEPTIONS_ENABLED ... \#else ... \#endif so the header
|
---|
556 | * compiles cleanly without exceptions enabled.
|
---|
557 | *
|
---|
558 | * Do NOT use this for the actual throwing of exceptions!
|
---|
559 | */
|
---|
560 | #ifdef RT_EXCEPTIONS_ENABLED
|
---|
561 | # ifdef _MSC_VER
|
---|
562 | # if _MSC_VER >= 1400
|
---|
563 | # define RT_THROW(type)
|
---|
564 | # else
|
---|
565 | # define RT_THROW(type) throw(type)
|
---|
566 | # endif
|
---|
567 | # else
|
---|
568 | # define RT_THROW(type) throw(type)
|
---|
569 | # endif
|
---|
570 | #else
|
---|
571 | # define RT_THROW(type)
|
---|
572 | #endif
|
---|
573 |
|
---|
574 | /** @def RTCALL
|
---|
575 | * The standard calling convention for the Runtime interfaces.
|
---|
576 | */
|
---|
577 | #ifdef _MSC_VER
|
---|
578 | # define RTCALL __cdecl
|
---|
579 | #elif defined(RT_OS_OS2)
|
---|
580 | # define RTCALL __cdecl
|
---|
581 | #elif defined(__GNUC__) && defined(IN_RING0) \
|
---|
582 | && !(defined(RT_ARCH_AMD64) || defined(RT_ARCH_SPARC) || defined(RT_ARCH_SPARC64)) /* the latter is kernel/gcc */
|
---|
583 | # define RTCALL __attribute__((cdecl,regparm(0)))
|
---|
584 | #else
|
---|
585 | # define RTCALL
|
---|
586 | #endif
|
---|
587 |
|
---|
588 | /** @def DECLEXPORT
|
---|
589 | * How to declare an exported function.
|
---|
590 | * @param type The return type of the function declaration.
|
---|
591 | */
|
---|
592 | #if defined(_MSC_VER) || defined(RT_OS_OS2)
|
---|
593 | # define DECLEXPORT(type) __declspec(dllexport) type
|
---|
594 | #elif defined(RT_USE_VISIBILITY_DEFAULT)
|
---|
595 | # define DECLEXPORT(type) __attribute__((visibility("default"))) type
|
---|
596 | #else
|
---|
597 | # define DECLEXPORT(type) type
|
---|
598 | #endif
|
---|
599 |
|
---|
600 | /** @def DECLIMPORT
|
---|
601 | * How to declare an imported function.
|
---|
602 | * @param type The return type of the function declaration.
|
---|
603 | */
|
---|
604 | #if defined(_MSC_VER) || (defined(RT_OS_OS2) && !defined(__IBMC__) && !defined(__IBMCPP__))
|
---|
605 | # define DECLIMPORT(type) __declspec(dllimport) type
|
---|
606 | #else
|
---|
607 | # define DECLIMPORT(type) type
|
---|
608 | #endif
|
---|
609 |
|
---|
610 | /** @def DECLHIDDEN
|
---|
611 | * How to declare a non-exported function or variable.
|
---|
612 | * @param type The return type of the function or the data type of the variable.
|
---|
613 | */
|
---|
614 | #if defined(RT_OS_OS2) || defined(RT_OS_WINDOWS) || !defined(RT_USE_VISIBILITY_HIDDEN) || defined(DOXYGEN_RUNNING)
|
---|
615 | # define DECLHIDDEN(type) type
|
---|
616 | #else
|
---|
617 | # define DECLHIDDEN(type) __attribute__((visibility("hidden"))) type
|
---|
618 | #endif
|
---|
619 |
|
---|
620 | /** @def DECL_INVALID
|
---|
621 | * How to declare a function not available for linking in the current context.
|
---|
622 | * The purpose is to create compile or like time errors when used. This isn't
|
---|
623 | * possible on all platforms.
|
---|
624 | * @param type The return type of the function.
|
---|
625 | */
|
---|
626 | #if defined(_MSC_VER)
|
---|
627 | # define DECL_INVALID(type) __declspec(dllimport) type __stdcall
|
---|
628 | #elif defined(__GNUC__) && defined(__cplusplus)
|
---|
629 | # define DECL_INVALID(type) extern "C++" type
|
---|
630 | #else
|
---|
631 | # define DECL_INVALID(type) type
|
---|
632 | #endif
|
---|
633 |
|
---|
634 | /** @def DECLASM
|
---|
635 | * How to declare an internal assembly function.
|
---|
636 | * @param type The return type of the function declaration.
|
---|
637 | */
|
---|
638 | #ifdef __cplusplus
|
---|
639 | # ifdef _MSC_VER
|
---|
640 | # define DECLASM(type) extern "C" type __cdecl
|
---|
641 | # else
|
---|
642 | # define DECLASM(type) extern "C" type
|
---|
643 | # endif
|
---|
644 | #else
|
---|
645 | # ifdef _MSC_VER
|
---|
646 | # define DECLASM(type) type __cdecl
|
---|
647 | # else
|
---|
648 | # define DECLASM(type) type
|
---|
649 | # endif
|
---|
650 | #endif
|
---|
651 |
|
---|
652 | /** @def DECLASMTYPE
|
---|
653 | * How to declare an internal assembly function type.
|
---|
654 | * @param type The return type of the function.
|
---|
655 | */
|
---|
656 | #ifdef _MSC_VER
|
---|
657 | # define DECLASMTYPE(type) type __cdecl
|
---|
658 | #else
|
---|
659 | # define DECLASMTYPE(type) type
|
---|
660 | #endif
|
---|
661 |
|
---|
662 | /** @def DECLNORETURN
|
---|
663 | * How to declare a function which does not return.
|
---|
664 | * @note: This macro can be combined with other macros, for example
|
---|
665 | * @code
|
---|
666 | * EMR3DECL(DECLNORETURN(void)) foo(void);
|
---|
667 | * @endcode
|
---|
668 | */
|
---|
669 | #ifdef _MSC_VER
|
---|
670 | # define DECLNORETURN(type) __declspec(noreturn) type
|
---|
671 | #elif defined(__GNUC__)
|
---|
672 | # define DECLNORETURN(type) __attribute__((noreturn)) type
|
---|
673 | #else
|
---|
674 | # define DECLNORETURN(type) type
|
---|
675 | #endif
|
---|
676 |
|
---|
677 | /** @def DECLCALLBACK
|
---|
678 | * How to declare an call back function type.
|
---|
679 | * @param type The return type of the function declaration.
|
---|
680 | */
|
---|
681 | #define DECLCALLBACK(type) type RTCALL
|
---|
682 |
|
---|
683 | /** @def DECLCALLBACKPTR
|
---|
684 | * How to declare an call back function pointer.
|
---|
685 | * @param type The return type of the function declaration.
|
---|
686 | * @param name The name of the variable member.
|
---|
687 | */
|
---|
688 | #define DECLCALLBACKPTR(type, name) type (RTCALL * name)
|
---|
689 |
|
---|
690 | /** @def DECLCALLBACKMEMBER
|
---|
691 | * How to declare an call back function pointer member.
|
---|
692 | * @param type The return type of the function declaration.
|
---|
693 | * @param name The name of the struct/union/class member.
|
---|
694 | */
|
---|
695 | #define DECLCALLBACKMEMBER(type, name) type (RTCALL * name)
|
---|
696 |
|
---|
697 | /** @def DECLR3CALLBACKMEMBER
|
---|
698 | * How to declare an call back function pointer member - R3 Ptr.
|
---|
699 | * @param type The return type of the function declaration.
|
---|
700 | * @param name The name of the struct/union/class member.
|
---|
701 | * @param args The argument list enclosed in parentheses.
|
---|
702 | */
|
---|
703 | #ifdef IN_RING3
|
---|
704 | # define DECLR3CALLBACKMEMBER(type, name, args) type (RTCALL * name) args
|
---|
705 | #else
|
---|
706 | # define DECLR3CALLBACKMEMBER(type, name, args) RTR3PTR name
|
---|
707 | #endif
|
---|
708 |
|
---|
709 | /** @def DECLRCCALLBACKMEMBER
|
---|
710 | * How to declare an call back function pointer member - RC Ptr.
|
---|
711 | * @param type The return type of the function declaration.
|
---|
712 | * @param name The name of the struct/union/class member.
|
---|
713 | * @param args The argument list enclosed in parentheses.
|
---|
714 | */
|
---|
715 | #ifdef IN_RC
|
---|
716 | # define DECLRCCALLBACKMEMBER(type, name, args) type (RTCALL * name) args
|
---|
717 | #else
|
---|
718 | # define DECLRCCALLBACKMEMBER(type, name, args) RTRCPTR name
|
---|
719 | #endif
|
---|
720 |
|
---|
721 | /** @def DECLR0CALLBACKMEMBER
|
---|
722 | * How to declare an call back function pointer member - R0 Ptr.
|
---|
723 | * @param type The return type of the function declaration.
|
---|
724 | * @param name The name of the struct/union/class member.
|
---|
725 | * @param args The argument list enclosed in parentheses.
|
---|
726 | */
|
---|
727 | #ifdef IN_RING0
|
---|
728 | # define DECLR0CALLBACKMEMBER(type, name, args) type (RTCALL * name) args
|
---|
729 | #else
|
---|
730 | # define DECLR0CALLBACKMEMBER(type, name, args) RTR0PTR name
|
---|
731 | #endif
|
---|
732 |
|
---|
733 | /** @def DECLINLINE
|
---|
734 | * How to declare a function as inline.
|
---|
735 | * @param type The return type of the function declaration.
|
---|
736 | * @remarks Don't use this macro on C++ methods.
|
---|
737 | */
|
---|
738 | #ifdef __GNUC__
|
---|
739 | # define DECLINLINE(type) static __inline__ type
|
---|
740 | #elif defined(__cplusplus)
|
---|
741 | # define DECLINLINE(type) inline type
|
---|
742 | #elif defined(_MSC_VER)
|
---|
743 | # define DECLINLINE(type) _inline type
|
---|
744 | #elif defined(__IBMC__)
|
---|
745 | # define DECLINLINE(type) _Inline type
|
---|
746 | #else
|
---|
747 | # define DECLINLINE(type) inline type
|
---|
748 | #endif
|
---|
749 |
|
---|
750 |
|
---|
751 | /** @def DECL_FORCE_INLINE
|
---|
752 | * How to declare a function as inline and try convince the compiler to always
|
---|
753 | * inline it regardless of optimization switches.
|
---|
754 | * @param type The return type of the function declaration.
|
---|
755 | * @remarks Use sparsely and with care. Don't use this macro on C++ methods.
|
---|
756 | */
|
---|
757 | #ifdef __GNUC__
|
---|
758 | # define DECL_FORCE_INLINE(type) __attribute__((always_inline)) DECLINLINE(type)
|
---|
759 | #elif defined(_MSC_VER)
|
---|
760 | # define DECL_FORCE_INLINE(type) __forceinline type
|
---|
761 | #else
|
---|
762 | # define DECL_FORCE_INLINE(type) DECLINLINE(type)
|
---|
763 | #endif
|
---|
764 |
|
---|
765 |
|
---|
766 | /** @def DECL_NO_INLINE
|
---|
767 | * How to declare a function telling the compiler not to inline it.
|
---|
768 | * @param scope The function scope, static or RT_NOTHING.
|
---|
769 | * @param type The return type of the function declaration.
|
---|
770 | * @remarks Don't use this macro on C++ methods.
|
---|
771 | */
|
---|
772 | #ifdef __GNUC__
|
---|
773 | # define DECL_NO_INLINE(scope,type) __attribute__((noinline)) scope type
|
---|
774 | #elif defined(_MSC_VER)
|
---|
775 | # define DECL_NO_INLINE(scope,type) __declspec(noline) scope type
|
---|
776 | #else
|
---|
777 | # define DECL_NO_INLINE(scope,type) scope type
|
---|
778 | #endif
|
---|
779 |
|
---|
780 |
|
---|
781 | /** @def IN_RT_STATIC
|
---|
782 | * Used to indicate whether we're linking against a static IPRT
|
---|
783 | * or not. The IPRT symbols will be declared as hidden (if
|
---|
784 | * supported). Note that this define has no effect without setting
|
---|
785 | * IN_RT_R0, IN_RT_R3 or IN_RT_RC indicators are set first.
|
---|
786 | */
|
---|
787 |
|
---|
788 | /** @def IN_RT_R0
|
---|
789 | * Used to indicate whether we're inside the same link module as
|
---|
790 | * the HC Ring-0 Runtime Library.
|
---|
791 | */
|
---|
792 | /** @def RTR0DECL(type)
|
---|
793 | * Runtime Library HC Ring-0 export or import declaration.
|
---|
794 | * @param type The return type of the function declaration.
|
---|
795 | */
|
---|
796 | #ifdef IN_RT_R0
|
---|
797 | # ifdef IN_RT_STATIC
|
---|
798 | # define RTR0DECL(type) DECLHIDDEN(type) RTCALL
|
---|
799 | # else
|
---|
800 | # define RTR0DECL(type) DECLEXPORT(type) RTCALL
|
---|
801 | # endif
|
---|
802 | #else
|
---|
803 | # define RTR0DECL(type) DECLIMPORT(type) RTCALL
|
---|
804 | #endif
|
---|
805 |
|
---|
806 | /** @def IN_RT_R3
|
---|
807 | * Used to indicate whether we're inside the same link module as
|
---|
808 | * the HC Ring-3 Runtime Library.
|
---|
809 | */
|
---|
810 | /** @def RTR3DECL(type)
|
---|
811 | * Runtime Library HC Ring-3 export or import declaration.
|
---|
812 | * @param type The return type of the function declaration.
|
---|
813 | */
|
---|
814 | #ifdef IN_RT_R3
|
---|
815 | # ifdef IN_RT_STATIC
|
---|
816 | # define RTR3DECL(type) DECLHIDDEN(type) RTCALL
|
---|
817 | # else
|
---|
818 | # define RTR3DECL(type) DECLEXPORT(type) RTCALL
|
---|
819 | # endif
|
---|
820 | #else
|
---|
821 | # define RTR3DECL(type) DECLIMPORT(type) RTCALL
|
---|
822 | #endif
|
---|
823 |
|
---|
824 | /** @def IN_RT_RC
|
---|
825 | * Used to indicate whether we're inside the same link module as the raw-mode
|
---|
826 | * context (RC) runtime library.
|
---|
827 | */
|
---|
828 | /** @def RTRCDECL(type)
|
---|
829 | * Runtime Library raw-mode context export or import declaration.
|
---|
830 | * @param type The return type of the function declaration.
|
---|
831 | */
|
---|
832 | #ifdef IN_RT_RC
|
---|
833 | # ifdef IN_RT_STATIC
|
---|
834 | # define RTRCDECL(type) DECLHIDDEN(type) RTCALL
|
---|
835 | # else
|
---|
836 | # define RTRCDECL(type) DECLEXPORT(type) RTCALL
|
---|
837 | # endif
|
---|
838 | #else
|
---|
839 | # define RTRCDECL(type) DECLIMPORT(type) RTCALL
|
---|
840 | #endif
|
---|
841 |
|
---|
842 | /** @def RTDECL(type)
|
---|
843 | * Runtime Library export or import declaration.
|
---|
844 | * Functions declared using this macro exists in all contexts.
|
---|
845 | * @param type The return type of the function declaration.
|
---|
846 | */
|
---|
847 | #if defined(IN_RT_R3) || defined(IN_RT_RC) || defined(IN_RT_R0)
|
---|
848 | # ifdef IN_RT_STATIC
|
---|
849 | # define RTDECL(type) DECLHIDDEN(type) RTCALL
|
---|
850 | # else
|
---|
851 | # define RTDECL(type) DECLEXPORT(type) RTCALL
|
---|
852 | # endif
|
---|
853 | #else
|
---|
854 | # define RTDECL(type) DECLIMPORT(type) RTCALL
|
---|
855 | #endif
|
---|
856 |
|
---|
857 | /** @def RTDATADECL(type)
|
---|
858 | * Runtime Library export or import declaration.
|
---|
859 | * Data declared using this macro exists in all contexts.
|
---|
860 | * @param type The return type of the function declaration.
|
---|
861 | */
|
---|
862 | #if defined(IN_RT_R3) || defined(IN_RT_RC) || defined(IN_RT_R0)
|
---|
863 | # ifdef IN_RT_STATIC
|
---|
864 | # define RTDATADECL(type) DECLHIDDEN(type)
|
---|
865 | # else
|
---|
866 | # define RTDATADECL(type) DECLEXPORT(type)
|
---|
867 | # endif
|
---|
868 | #else
|
---|
869 | # define RTDATADECL(type) DECLIMPORT(type)
|
---|
870 | #endif
|
---|
871 |
|
---|
872 | /** @def RT_DECL_CLASS
|
---|
873 | * Declares an class living in the runtime.
|
---|
874 | */
|
---|
875 | #if defined(IN_RT_R3) || defined(IN_RT_RC) || defined(IN_RT_R0)
|
---|
876 | # ifdef IN_RT_STATIC
|
---|
877 | # define RT_DECL_CLASS
|
---|
878 | # else
|
---|
879 | # define RT_DECL_CLASS DECLEXPORT_CLASS
|
---|
880 | # endif
|
---|
881 | #else
|
---|
882 | # define RT_DECL_CLASS DECLIMPORT_CLASS
|
---|
883 | #endif
|
---|
884 |
|
---|
885 |
|
---|
886 | /** @def RT_NOCRT
|
---|
887 | * Symbol name wrapper for the No-CRT bits.
|
---|
888 | *
|
---|
889 | * In order to coexist in the same process as other CRTs, we need to
|
---|
890 | * decorate the symbols such that they don't conflict the ones in the
|
---|
891 | * other CRTs. The result of such conflicts / duplicate symbols can
|
---|
892 | * confuse the dynamic loader on Unix like systems.
|
---|
893 | *
|
---|
894 | * Define RT_WITHOUT_NOCRT_WRAPPERS to drop the wrapping.
|
---|
895 | * Define RT_WITHOUT_NOCRT_WRAPPER_ALIASES to drop the aliases to the
|
---|
896 | * wrapped names.
|
---|
897 | */
|
---|
898 | /** @def RT_NOCRT_STR
|
---|
899 | * Same as RT_NOCRT only it'll return a double quoted string of the result.
|
---|
900 | */
|
---|
901 | #ifndef RT_WITHOUT_NOCRT_WRAPPERS
|
---|
902 | # define RT_NOCRT(name) nocrt_ ## name
|
---|
903 | # define RT_NOCRT_STR(name) "nocrt_" # name
|
---|
904 | #else
|
---|
905 | # define RT_NOCRT(name) name
|
---|
906 | # define RT_NOCRT_STR(name) #name
|
---|
907 | #endif
|
---|
908 |
|
---|
909 |
|
---|
910 |
|
---|
911 | /** @def RT_LIKELY
|
---|
912 | * Give the compiler a hint that an expression is very likely to hold true.
|
---|
913 | *
|
---|
914 | * Some compilers support explicit branch prediction so that the CPU backend
|
---|
915 | * can hint the processor and also so that code blocks can be reordered such
|
---|
916 | * that the predicted path sees a more linear flow, thus improving cache
|
---|
917 | * behaviour, etc.
|
---|
918 | *
|
---|
919 | * IPRT provides the macros RT_LIKELY() and RT_UNLIKELY() as a way to utilize
|
---|
920 | * this compiler feature when present.
|
---|
921 | *
|
---|
922 | * A few notes about the usage:
|
---|
923 | *
|
---|
924 | * - Generally, use RT_UNLIKELY() with error condition checks (unless you
|
---|
925 | * have some _strong_ reason to do otherwise, in which case document it),
|
---|
926 | * and/or RT_LIKELY() with success condition checks, assuming you want
|
---|
927 | * to optimize for the success path.
|
---|
928 | *
|
---|
929 | * - Other than that, if you don't know the likelihood of a test succeeding
|
---|
930 | * from empirical or other 'hard' evidence, don't make predictions unless
|
---|
931 | * you happen to be a Dirk Gently.
|
---|
932 | *
|
---|
933 | * - These macros are meant to be used in places that get executed a lot. It
|
---|
934 | * is wasteful to make predictions in code that is executed rarely (e.g.
|
---|
935 | * at subsystem initialization time) as the basic block reordering that this
|
---|
936 | * affects can often generate larger code.
|
---|
937 | *
|
---|
938 | * - Note that RT_SUCCESS() and RT_FAILURE() already makes use of RT_LIKELY()
|
---|
939 | * and RT_UNLIKELY(). Should you wish for prediction free status checks,
|
---|
940 | * use the RT_SUCCESS_NP() and RT_FAILURE_NP() macros instead.
|
---|
941 | *
|
---|
942 | *
|
---|
943 | * @returns the boolean result of the expression.
|
---|
944 | * @param expr The expression that's very likely to be true.
|
---|
945 | * @see RT_UNLIKELY
|
---|
946 | */
|
---|
947 | /** @def RT_UNLIKELY
|
---|
948 | * Give the compiler a hint that an expression is highly unlikely to hold true.
|
---|
949 | *
|
---|
950 | * See the usage instructions give in the RT_LIKELY() docs.
|
---|
951 | *
|
---|
952 | * @returns the boolean result of the expression.
|
---|
953 | * @param expr The expression that's very unlikely to be true.
|
---|
954 | * @see RT_LIKELY
|
---|
955 | */
|
---|
956 | #if defined(__GNUC__)
|
---|
957 | # if __GNUC__ >= 3
|
---|
958 | # define RT_LIKELY(expr) __builtin_expect(!!(expr), 1)
|
---|
959 | # define RT_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
|
---|
960 | # else
|
---|
961 | # define RT_LIKELY(expr) (expr)
|
---|
962 | # define RT_UNLIKELY(expr) (expr)
|
---|
963 | # endif
|
---|
964 | #else
|
---|
965 | # define RT_LIKELY(expr) (expr)
|
---|
966 | # define RT_UNLIKELY(expr) (expr)
|
---|
967 | #endif
|
---|
968 |
|
---|
969 |
|
---|
970 | /** @def RT_STR
|
---|
971 | * Returns the argument as a string constant.
|
---|
972 | * @param str Argument to stringify. */
|
---|
973 | #define RT_STR(str) #str
|
---|
974 | /** @def RT_XSTR
|
---|
975 | * Returns the expanded argument as a string.
|
---|
976 | * @param str Argument to expand and stringy. */
|
---|
977 | #define RT_XSTR(str) RT_STR(str)
|
---|
978 |
|
---|
979 |
|
---|
980 | /** @def RT_BIT
|
---|
981 | * Convert a bit number into an integer bitmask (unsigned).
|
---|
982 | * @param bit The bit number.
|
---|
983 | */
|
---|
984 | #define RT_BIT(bit) ( 1U << (bit) )
|
---|
985 |
|
---|
986 | /** @def RT_BIT_32
|
---|
987 | * Convert a bit number into a 32-bit bitmask (unsigned).
|
---|
988 | * @param bit The bit number.
|
---|
989 | */
|
---|
990 | #define RT_BIT_32(bit) ( UINT32_C(1) << (bit) )
|
---|
991 |
|
---|
992 | /** @def RT_BIT_64
|
---|
993 | * Convert a bit number into a 64-bit bitmask (unsigned).
|
---|
994 | * @param bit The bit number.
|
---|
995 | */
|
---|
996 | #define RT_BIT_64(bit) ( UINT64_C(1) << (bit) )
|
---|
997 |
|
---|
998 | /** @def RT_ALIGN
|
---|
999 | * Align macro.
|
---|
1000 | * @param u Value to align.
|
---|
1001 | * @param uAlignment The alignment. Power of two!
|
---|
1002 | *
|
---|
1003 | * @remark Be extremely careful when using this macro with type which sizeof != sizeof int.
|
---|
1004 | * When possible use any of the other RT_ALIGN_* macros. And when that's not
|
---|
1005 | * possible, make 101% sure that uAlignment is specified with a right sized type.
|
---|
1006 | *
|
---|
1007 | * Specifying an unsigned 32-bit alignment constant with a 64-bit value will give
|
---|
1008 | * you a 32-bit return value!
|
---|
1009 | *
|
---|
1010 | * In short: Don't use this macro. Use RT_ALIGN_T() instead.
|
---|
1011 | */
|
---|
1012 | #define RT_ALIGN(u, uAlignment) ( ((u) + ((uAlignment) - 1)) & ~((uAlignment) - 1) )
|
---|
1013 |
|
---|
1014 | /** @def RT_ALIGN_T
|
---|
1015 | * Align macro.
|
---|
1016 | * @param u Value to align.
|
---|
1017 | * @param uAlignment The alignment. Power of two!
|
---|
1018 | * @param type Integer type to use while aligning.
|
---|
1019 | * @remark This macro is the preferred alignment macro, it doesn't have any of the pitfalls RT_ALIGN has.
|
---|
1020 | */
|
---|
1021 | #define RT_ALIGN_T(u, uAlignment, type) ( ((type)(u) + ((uAlignment) - 1)) & ~(type)((uAlignment) - 1) )
|
---|
1022 |
|
---|
1023 | /** @def RT_ALIGN_32
|
---|
1024 | * Align macro for a 32-bit value.
|
---|
1025 | * @param u32 Value to align.
|
---|
1026 | * @param uAlignment The alignment. Power of two!
|
---|
1027 | */
|
---|
1028 | #define RT_ALIGN_32(u32, uAlignment) RT_ALIGN_T(u32, uAlignment, uint32_t)
|
---|
1029 |
|
---|
1030 | /** @def RT_ALIGN_64
|
---|
1031 | * Align macro for a 64-bit value.
|
---|
1032 | * @param u64 Value to align.
|
---|
1033 | * @param uAlignment The alignment. Power of two!
|
---|
1034 | */
|
---|
1035 | #define RT_ALIGN_64(u64, uAlignment) RT_ALIGN_T(u64, uAlignment, uint64_t)
|
---|
1036 |
|
---|
1037 | /** @def RT_ALIGN_Z
|
---|
1038 | * Align macro for size_t.
|
---|
1039 | * @param cb Value to align.
|
---|
1040 | * @param uAlignment The alignment. Power of two!
|
---|
1041 | */
|
---|
1042 | #define RT_ALIGN_Z(cb, uAlignment) RT_ALIGN_T(cb, uAlignment, size_t)
|
---|
1043 |
|
---|
1044 | /** @def RT_ALIGN_P
|
---|
1045 | * Align macro for pointers.
|
---|
1046 | * @param pv Value to align.
|
---|
1047 | * @param uAlignment The alignment. Power of two!
|
---|
1048 | */
|
---|
1049 | #define RT_ALIGN_P(pv, uAlignment) RT_ALIGN_PT(pv, uAlignment, void *)
|
---|
1050 |
|
---|
1051 | /** @def RT_ALIGN_PT
|
---|
1052 | * Align macro for pointers with type cast.
|
---|
1053 | * @param u Value to align.
|
---|
1054 | * @param uAlignment The alignment. Power of two!
|
---|
1055 | * @param CastType The type to cast the result to.
|
---|
1056 | */
|
---|
1057 | #define RT_ALIGN_PT(u, uAlignment, CastType) ( (CastType)RT_ALIGN_T(u, uAlignment, uintptr_t) )
|
---|
1058 |
|
---|
1059 | /** @def RT_ALIGN_R3PT
|
---|
1060 | * Align macro for ring-3 pointers with type cast.
|
---|
1061 | * @param u Value to align.
|
---|
1062 | * @param uAlignment The alignment. Power of two!
|
---|
1063 | * @param CastType The type to cast the result to.
|
---|
1064 | */
|
---|
1065 | #define RT_ALIGN_R3PT(u, uAlignment, CastType) ( (CastType)RT_ALIGN_T(u, uAlignment, RTR3UINTPTR) )
|
---|
1066 |
|
---|
1067 | /** @def RT_ALIGN_R0PT
|
---|
1068 | * Align macro for ring-0 pointers with type cast.
|
---|
1069 | * @param u Value to align.
|
---|
1070 | * @param uAlignment The alignment. Power of two!
|
---|
1071 | * @param CastType The type to cast the result to.
|
---|
1072 | */
|
---|
1073 | #define RT_ALIGN_R0PT(u, uAlignment, CastType) ( (CastType)RT_ALIGN_T(u, uAlignment, RTR0UINTPTR) )
|
---|
1074 |
|
---|
1075 | /** @def RT_ALIGN_GCPT
|
---|
1076 | * Align macro for GC pointers with type cast.
|
---|
1077 | * @param u Value to align.
|
---|
1078 | * @param uAlignment The alignment. Power of two!
|
---|
1079 | * @param CastType The type to cast the result to.
|
---|
1080 | */
|
---|
1081 | #define RT_ALIGN_GCPT(u, uAlignment, CastType) ( (CastType)RT_ALIGN_T(u, uAlignment, RTGCUINTPTR) )
|
---|
1082 |
|
---|
1083 |
|
---|
1084 | /** @def RT_OFFSETOF
|
---|
1085 | * Our own special offsetof() variant, returns a signed result.
|
---|
1086 | *
|
---|
1087 | * This differs from the usual offsetof() in that it's not relying on builtin
|
---|
1088 | * compiler stuff and thus can use variables in arrays the structure may
|
---|
1089 | * contain. This is useful to determine the sizes of structures ending
|
---|
1090 | * with a variable length field.
|
---|
1091 | *
|
---|
1092 | * @returns offset into the structure of the specified member. signed.
|
---|
1093 | * @param type Structure type.
|
---|
1094 | * @param member Member.
|
---|
1095 | */
|
---|
1096 | #define RT_OFFSETOF(type, member) ( (int)(uintptr_t)&( ((type *)(void *)0)->member) )
|
---|
1097 |
|
---|
1098 | /** @def RT_UOFFSETOF
|
---|
1099 | * Our own special offsetof() variant, returns an unsigned result.
|
---|
1100 | *
|
---|
1101 | * This differs from the usual offsetof() in that it's not relying on builtin
|
---|
1102 | * compiler stuff and thus can use variables in arrays the structure may
|
---|
1103 | * contain. This is useful to determine the sizes of structures ending
|
---|
1104 | * with a variable length field.
|
---|
1105 | *
|
---|
1106 | * @returns offset into the structure of the specified member. unsigned.
|
---|
1107 | * @param type Structure type.
|
---|
1108 | * @param member Member.
|
---|
1109 | */
|
---|
1110 | #define RT_UOFFSETOF(type, member) ( (uintptr_t)&( ((type *)(void *)0)->member) )
|
---|
1111 |
|
---|
1112 | /** @def RT_OFFSETOF_ADD
|
---|
1113 | * RT_OFFSETOF with an addend.
|
---|
1114 | *
|
---|
1115 | * @returns offset into the structure of the specified member. signed.
|
---|
1116 | * @param type Structure type.
|
---|
1117 | * @param member Member.
|
---|
1118 | * @param addend The addend to add to the offset.
|
---|
1119 | */
|
---|
1120 | #define RT_OFFSETOF_ADD(type, member, addend) ( (int)RT_UOFFSETOF_ADD(type, member, addend) )
|
---|
1121 |
|
---|
1122 | /** @def RT_UOFFSETOF_ADD
|
---|
1123 | * RT_UOFFSETOF with an addend.
|
---|
1124 | *
|
---|
1125 | * @returns offset into the structure of the specified member. signed.
|
---|
1126 | * @param type Structure type.
|
---|
1127 | * @param member Member.
|
---|
1128 | * @param addend The addend to add to the offset.
|
---|
1129 | */
|
---|
1130 | #define RT_UOFFSETOF_ADD(type, member, addend) ( (uintptr_t)&( ((type *)(void *)(uintptr_t)(addend))->member) )
|
---|
1131 |
|
---|
1132 | /** @def RT_SIZEOFMEMB
|
---|
1133 | * Get the size of a structure member.
|
---|
1134 | *
|
---|
1135 | * @returns size of the structure member.
|
---|
1136 | * @param type Structure type.
|
---|
1137 | * @param member Member.
|
---|
1138 | */
|
---|
1139 | #define RT_SIZEOFMEMB(type, member) ( sizeof(((type *)(void *)0)->member) )
|
---|
1140 |
|
---|
1141 | /** @def RT_FROM_MEMBER
|
---|
1142 | * Convert a pointer to a structure member into a pointer to the structure.
|
---|
1143 | * @returns pointer to the structure.
|
---|
1144 | * @param pMem Pointer to the member.
|
---|
1145 | * @param Type Structure type.
|
---|
1146 | * @param Member Member name.
|
---|
1147 | */
|
---|
1148 | #define RT_FROM_MEMBER(pMem, Type, Member) ( (Type *) ((uint8_t *)(void *)(pMem) - RT_UOFFSETOF(Type, Member)) )
|
---|
1149 |
|
---|
1150 | /** @def RT_ELEMENTS
|
---|
1151 | * Calculates the number of elements in a statically sized array.
|
---|
1152 | * @returns Element count.
|
---|
1153 | * @param aArray Array in question.
|
---|
1154 | */
|
---|
1155 | #define RT_ELEMENTS(aArray) ( sizeof(aArray) / sizeof((aArray)[0]) )
|
---|
1156 |
|
---|
1157 | #ifdef RT_OS_OS2
|
---|
1158 | /* Undefine RT_MAX since there is an unfortunate clash with the max
|
---|
1159 | resource type define in os2.h. */
|
---|
1160 | # undef RT_MAX
|
---|
1161 | #endif
|
---|
1162 |
|
---|
1163 | /** @def RT_MAX
|
---|
1164 | * Finds the maximum value.
|
---|
1165 | * @returns The higher of the two.
|
---|
1166 | * @param Value1 Value 1
|
---|
1167 | * @param Value2 Value 2
|
---|
1168 | */
|
---|
1169 | #define RT_MAX(Value1, Value2) ( (Value1) >= (Value2) ? (Value1) : (Value2) )
|
---|
1170 |
|
---|
1171 | /** @def RT_MIN
|
---|
1172 | * Finds the minimum value.
|
---|
1173 | * @returns The lower of the two.
|
---|
1174 | * @param Value1 Value 1
|
---|
1175 | * @param Value2 Value 2
|
---|
1176 | */
|
---|
1177 | #define RT_MIN(Value1, Value2) ( (Value1) <= (Value2) ? (Value1) : (Value2) )
|
---|
1178 |
|
---|
1179 | /** @def RT_CLAMP
|
---|
1180 | * Clamps the value to minimum and maximum values.
|
---|
1181 | * @returns The clamped value.
|
---|
1182 | * @param Value The value to check.
|
---|
1183 | * @param Min Minimum value.
|
---|
1184 | * @param Max Maximum value.
|
---|
1185 | */
|
---|
1186 | #define RT_CLAMP(Value, Min, Max) ( (Value) > (Max) ? (Max) : (Value) < (Min) ? (Min) : (Value) )
|
---|
1187 |
|
---|
1188 | /** @def RT_ABS
|
---|
1189 | * Get the absolute (non-negative) value.
|
---|
1190 | * @returns The absolute value of Value.
|
---|
1191 | * @param Value The value.
|
---|
1192 | */
|
---|
1193 | #define RT_ABS(Value) ( (Value) >= 0 ? (Value) : -(Value) )
|
---|
1194 |
|
---|
1195 | /** @def RT_LODWORD
|
---|
1196 | * Gets the low dword (=uint32_t) of something. */
|
---|
1197 | #define RT_LODWORD(a) ( (uint32_t)(a) )
|
---|
1198 |
|
---|
1199 | /** @def RT_HIDWORD
|
---|
1200 | * Gets the high dword (=uint32_t) of a 64-bit of something. */
|
---|
1201 | #define RT_HIDWORD(a) ( (uint32_t)((a) >> 32) )
|
---|
1202 |
|
---|
1203 | /** @def RT_LOWORD
|
---|
1204 | * Gets the low word (=uint16_t) of something. */
|
---|
1205 | #define RT_LOWORD(a) ( (a) & 0xffff )
|
---|
1206 |
|
---|
1207 | /** @def RT_HIWORD
|
---|
1208 | * Gets the high word (=uint16_t) of a 32-bit something. */
|
---|
1209 | #define RT_HIWORD(a) ( (a) >> 16 )
|
---|
1210 |
|
---|
1211 | /** @def RT_LOBYTE
|
---|
1212 | * Gets the low byte of something. */
|
---|
1213 | #define RT_LOBYTE(a) ( (a) & 0xff )
|
---|
1214 |
|
---|
1215 | /** @def RT_HIBYTE
|
---|
1216 | * Gets the low byte of a 16-bit something. */
|
---|
1217 | #define RT_HIBYTE(a) ( (a) >> 8 )
|
---|
1218 |
|
---|
1219 | /** @def RT_BYTE1
|
---|
1220 | * Gets the first byte of something. */
|
---|
1221 | #define RT_BYTE1(a) ( (a) & 0xff )
|
---|
1222 |
|
---|
1223 | /** @def RT_BYTE2
|
---|
1224 | * Gets the second byte of something. */
|
---|
1225 | #define RT_BYTE2(a) ( ((a) >> 8) & 0xff )
|
---|
1226 |
|
---|
1227 | /** @def RT_BYTE3
|
---|
1228 | * Gets the second byte of something. */
|
---|
1229 | #define RT_BYTE3(a) ( ((a) >> 16) & 0xff )
|
---|
1230 |
|
---|
1231 | /** @def RT_BYTE4
|
---|
1232 | * Gets the fourth byte of something. */
|
---|
1233 | #define RT_BYTE4(a) ( ((a) >> 24) & 0xff )
|
---|
1234 |
|
---|
1235 | /** @def RT_BYTE5
|
---|
1236 | * Gets the fifth byte of something. */
|
---|
1237 | #define RT_BYTE5(a) (((a) >> 32) & 0xff)
|
---|
1238 |
|
---|
1239 | /** @def RT_BYTE6
|
---|
1240 | * Gets the sixth byte of something. */
|
---|
1241 | #define RT_BYTE6(a) (((a) >> 40) & 0xff)
|
---|
1242 |
|
---|
1243 | /** @def RT_BYTE7
|
---|
1244 | * Gets the seventh byte of something. */
|
---|
1245 | #define RT_BYTE7(a) (((a) >> 48) & 0xff)
|
---|
1246 |
|
---|
1247 | /** @def RT_BYTE8
|
---|
1248 | * Gets the eight byte of something. */
|
---|
1249 | #define RT_BYTE8(a) (((a) >> 56) & 0xff)
|
---|
1250 |
|
---|
1251 |
|
---|
1252 | /** @def RT_MAKE_U64
|
---|
1253 | * Constructs a uint64_t value from two uint32_t values.
|
---|
1254 | */
|
---|
1255 | #define RT_MAKE_U64(Lo, Hi) ( (uint64_t)((uint32_t)(Hi)) << 32 | (uint32_t)(Lo) )
|
---|
1256 |
|
---|
1257 | /** @def RT_MAKE_U64_FROM_U16
|
---|
1258 | * Constructs a uint64_t value from four uint16_t values.
|
---|
1259 | */
|
---|
1260 | #define RT_MAKE_U64_FROM_U16(w0, w1, w2, w3) \
|
---|
1261 | ((uint64_t)( (uint64_t)((uint16_t)(w3)) << 48 \
|
---|
1262 | | (uint64_t)((uint16_t)(w2)) << 32 \
|
---|
1263 | | (uint32_t)((uint16_t)(w1)) << 16 \
|
---|
1264 | | (uint16_t)(w0) ))
|
---|
1265 |
|
---|
1266 | /** @def RT_MAKE_U64_FROM_U8
|
---|
1267 | * Constructs a uint64_t value from eight uint8_t values.
|
---|
1268 | */
|
---|
1269 | #define RT_MAKE_U64_FROM_U8(b0, b1, b2, b3, b4, b5, b6, b7) \
|
---|
1270 | ((uint64_t)( (uint64_t)((uint8_t)(b7)) << 56 \
|
---|
1271 | | (uint64_t)((uint8_t)(b6)) << 48 \
|
---|
1272 | | (uint64_t)((uint8_t)(b5)) << 40 \
|
---|
1273 | | (uint64_t)((uint8_t)(b4)) << 32 \
|
---|
1274 | | (uint32_t)((uint8_t)(b3)) << 24 \
|
---|
1275 | | (uint32_t)((uint8_t)(b2)) << 16 \
|
---|
1276 | | (uint16_t)((uint8_t)(b1)) << 8 \
|
---|
1277 | | (uint8_t)(b0) ))
|
---|
1278 |
|
---|
1279 | /** @def RT_MAKE_U32
|
---|
1280 | * Constructs a uint32_t value from two uint16_t values.
|
---|
1281 | */
|
---|
1282 | #define RT_MAKE_U32(Lo, Hi) \
|
---|
1283 | ((uint32_t)( (uint32_t)((uint16_t)(Hi)) << 16 \
|
---|
1284 | | (uint16_t)(Lo) ))
|
---|
1285 |
|
---|
1286 | /** @def RT_MAKE_U32_FROM_U8
|
---|
1287 | * Constructs a uint32_t value from four uint8_t values.
|
---|
1288 | */
|
---|
1289 | #define RT_MAKE_U32_FROM_U8(b0, b1, b2, b3) \
|
---|
1290 | ((uint32_t)( (uint32_t)((uint8_t)(b3)) << 24 \
|
---|
1291 | | (uint32_t)((uint8_t)(b2)) << 16 \
|
---|
1292 | | (uint16_t)((uint8_t)(b1)) << 8 \
|
---|
1293 | | (uint8_t)(b0) ))
|
---|
1294 |
|
---|
1295 | /** @def RT_MAKE_U16
|
---|
1296 | * Constructs a uint32_t value from two uint16_t values.
|
---|
1297 | */
|
---|
1298 | #define RT_MAKE_U16(Lo, Hi) \
|
---|
1299 | ((uint16_t)( (uint16_t)((uint8_t)(Hi)) << 8 \
|
---|
1300 | | (uint8_t)(Lo) ))
|
---|
1301 |
|
---|
1302 |
|
---|
1303 | /** @def RT_BSWAP_U64
|
---|
1304 | * Reverses the byte order of an uint64_t value. */
|
---|
1305 | #if 0
|
---|
1306 | # define RT_BSWAP_U64(u64) RT_BSWAP_U64_C(u64)
|
---|
1307 | #elif defined(__GNUC__)
|
---|
1308 | # define RT_BSWAP_U64(u64) (__builtin_constant_p((u64)) \
|
---|
1309 | ? RT_BSWAP_U64_C(u64) : ASMByteSwapU64(u64))
|
---|
1310 | #else
|
---|
1311 | # define RT_BSWAP_U64(u64) ASMByteSwapU64(u64)
|
---|
1312 | #endif
|
---|
1313 |
|
---|
1314 | /** @def RT_BSWAP_U32
|
---|
1315 | * Reverses the byte order of an uint32_t value. */
|
---|
1316 | #if 0
|
---|
1317 | # define RT_BSWAP_U32(u32) RT_BSWAP_U32_C(u32)
|
---|
1318 | #elif defined(__GNUC__)
|
---|
1319 | # define RT_BSWAP_U32(u32) (__builtin_constant_p((u32)) \
|
---|
1320 | ? RT_BSWAP_U32_C(u32) : ASMByteSwapU32(u32))
|
---|
1321 | #else
|
---|
1322 | # define RT_BSWAP_U32(u32) ASMByteSwapU32(u32)
|
---|
1323 | #endif
|
---|
1324 |
|
---|
1325 | /** @def RT_BSWAP_U16
|
---|
1326 | * Reverses the byte order of an uint16_t value. */
|
---|
1327 | #if 0
|
---|
1328 | # define RT_BSWAP_U16(u16) RT_BSWAP_U16_C(u16)
|
---|
1329 | #elif defined(__GNUC__)
|
---|
1330 | # define RT_BSWAP_U16(u16) (__builtin_constant_p((u16)) \
|
---|
1331 | ? RT_BSWAP_U16_C(u16) : ASMByteSwapU16(u16))
|
---|
1332 | #else
|
---|
1333 | # define RT_BSWAP_U16(u16) ASMByteSwapU16(u16)
|
---|
1334 | #endif
|
---|
1335 |
|
---|
1336 |
|
---|
1337 | /** @def RT_BSWAP_U64_C
|
---|
1338 | * Reverses the byte order of an uint64_t constant. */
|
---|
1339 | #define RT_BSWAP_U64_C(u64) RT_MAKE_U64(RT_BSWAP_U32_C((u64) >> 32), RT_BSWAP_U32_C((u64) & 0xffffffff))
|
---|
1340 |
|
---|
1341 | /** @def RT_BSWAP_U32_C
|
---|
1342 | * Reverses the byte order of an uint32_t constant. */
|
---|
1343 | #define RT_BSWAP_U32_C(u32) RT_MAKE_U32_FROM_U8(RT_BYTE4(u32), RT_BYTE3(u32), RT_BYTE2(u32), RT_BYTE1(u32))
|
---|
1344 |
|
---|
1345 | /** @def RT_BSWAP_U16_C
|
---|
1346 | * Reverses the byte order of an uint16_t constant. */
|
---|
1347 | #define RT_BSWAP_U16_C(u16) RT_MAKE_U16(RT_HIBYTE(u16), RT_LOBYTE(u16))
|
---|
1348 |
|
---|
1349 |
|
---|
1350 | /** @def RT_H2LE_U64
|
---|
1351 | * Converts an uint64_t value from host to little endian byte order. */
|
---|
1352 | #ifdef RT_BIG_ENDIAN
|
---|
1353 | # define RT_H2LE_U64(u64) RT_BSWAP_U64(u64)
|
---|
1354 | #else
|
---|
1355 | # define RT_H2LE_U64(u64) (u64)
|
---|
1356 | #endif
|
---|
1357 |
|
---|
1358 | /** @def RT_H2LE_U64_C
|
---|
1359 | * Converts an uint64_t constant from host to little endian byte order. */
|
---|
1360 | #ifdef RT_BIG_ENDIAN
|
---|
1361 | # define RT_H2LE_U64_C(u64) RT_BSWAP_U64_C(u64)
|
---|
1362 | #else
|
---|
1363 | # define RT_H2LE_U64_C(u64) (u64)
|
---|
1364 | #endif
|
---|
1365 |
|
---|
1366 | /** @def RT_H2LE_U32
|
---|
1367 | * Converts an uint32_t value from host to little endian byte order. */
|
---|
1368 | #ifdef RT_BIG_ENDIAN
|
---|
1369 | # define RT_H2LE_U32(u32) RT_BSWAP_U32(u32)
|
---|
1370 | #else
|
---|
1371 | # define RT_H2LE_U32(u32) (u32)
|
---|
1372 | #endif
|
---|
1373 |
|
---|
1374 | /** @def RT_H2LE_U32_C
|
---|
1375 | * Converts an uint32_t constant from host to little endian byte order. */
|
---|
1376 | #ifdef RT_BIG_ENDIAN
|
---|
1377 | # define RT_H2LE_U32_C(u32) RT_BSWAP_U32_C(u32)
|
---|
1378 | #else
|
---|
1379 | # define RT_H2LE_U32_C(u32) (u32)
|
---|
1380 | #endif
|
---|
1381 |
|
---|
1382 | /** @def RT_H2LE_U16
|
---|
1383 | * Converts an uint16_t value from host to little endian byte order. */
|
---|
1384 | #ifdef RT_BIG_ENDIAN
|
---|
1385 | # define RT_H2LE_U16(u16) RT_BSWAP_U16(u16)
|
---|
1386 | #else
|
---|
1387 | # define RT_H2LE_U16(u16) (u16)
|
---|
1388 | #endif
|
---|
1389 |
|
---|
1390 | /** @def RT_H2LE_U16_C
|
---|
1391 | * Converts an uint16_t constant from host to little endian byte order. */
|
---|
1392 | #ifdef RT_BIG_ENDIAN
|
---|
1393 | # define RT_H2LE_U16_C(u16) RT_BSWAP_U16_C(u16)
|
---|
1394 | #else
|
---|
1395 | # define RT_H2LE_U16_C(u16) (u16)
|
---|
1396 | #endif
|
---|
1397 |
|
---|
1398 |
|
---|
1399 | /** @def RT_LE2H_U64
|
---|
1400 | * Converts an uint64_t value from little endian to host byte order. */
|
---|
1401 | #ifdef RT_BIG_ENDIAN
|
---|
1402 | # define RT_LE2H_U64(u64) RT_BSWAP_U64(u64)
|
---|
1403 | #else
|
---|
1404 | # define RT_LE2H_U64(u64) (u64)
|
---|
1405 | #endif
|
---|
1406 |
|
---|
1407 | /** @def RT_LE2H_U64_C
|
---|
1408 | * Converts an uint64_t constant from little endian to host byte order. */
|
---|
1409 | #ifdef RT_BIG_ENDIAN
|
---|
1410 | # define RT_LE2H_U64_C(u64) RT_BSWAP_U64_C(u64)
|
---|
1411 | #else
|
---|
1412 | # define RT_LE2H_U64_C(u64) (u64)
|
---|
1413 | #endif
|
---|
1414 |
|
---|
1415 | /** @def RT_LE2H_U32
|
---|
1416 | * Converts an uint32_t value from little endian to host byte order. */
|
---|
1417 | #ifdef RT_BIG_ENDIAN
|
---|
1418 | # define RT_LE2H_U32(u32) RT_BSWAP_U32(u32)
|
---|
1419 | #else
|
---|
1420 | # define RT_LE2H_U32(u32) (u32)
|
---|
1421 | #endif
|
---|
1422 |
|
---|
1423 | /** @def RT_LE2H_U32_C
|
---|
1424 | * Converts an uint32_t constant from little endian to host byte order. */
|
---|
1425 | #ifdef RT_BIG_ENDIAN
|
---|
1426 | # define RT_LE2H_U32_C(u32) RT_BSWAP_U32_C(u32)
|
---|
1427 | #else
|
---|
1428 | # define RT_LE2H_U32_C(u32) (u32)
|
---|
1429 | #endif
|
---|
1430 |
|
---|
1431 | /** @def RT_LE2H_U16
|
---|
1432 | * Converts an uint16_t value from little endian to host byte order. */
|
---|
1433 | #ifdef RT_BIG_ENDIAN
|
---|
1434 | # define RT_LE2H_U16(u16) RT_BSWAP_U16(u16)
|
---|
1435 | #else
|
---|
1436 | # define RT_LE2H_U16(u16) (u16)
|
---|
1437 | #endif
|
---|
1438 |
|
---|
1439 | /** @def RT_LE2H_U16_C
|
---|
1440 | * Converts an uint16_t constant from little endian to host byte order. */
|
---|
1441 | #ifdef RT_BIG_ENDIAN
|
---|
1442 | # define RT_LE2H_U16_C(u16) RT_BSWAP_U16_C(u16)
|
---|
1443 | #else
|
---|
1444 | # define RT_LE2H_U16_C(u16) (u16)
|
---|
1445 | #endif
|
---|
1446 |
|
---|
1447 |
|
---|
1448 | /** @def RT_H2BE_U64
|
---|
1449 | * Converts an uint64_t value from host to big endian byte order. */
|
---|
1450 | #ifdef RT_BIG_ENDIAN
|
---|
1451 | # define RT_H2BE_U64(u64) (u64)
|
---|
1452 | #else
|
---|
1453 | # define RT_H2BE_U64(u64) RT_BSWAP_U64(u64)
|
---|
1454 | #endif
|
---|
1455 |
|
---|
1456 | /** @def RT_H2BE_U64_C
|
---|
1457 | * Converts an uint64_t constant from host to big endian byte order. */
|
---|
1458 | #ifdef RT_BIG_ENDIAN
|
---|
1459 | # define RT_H2BE_U64_C(u64) (u64)
|
---|
1460 | #else
|
---|
1461 | # define RT_H2BE_U64_C(u64) RT_BSWAP_U64_C(u64)
|
---|
1462 | #endif
|
---|
1463 |
|
---|
1464 | /** @def RT_H2BE_U32
|
---|
1465 | * Converts an uint32_t value from host to big endian byte order. */
|
---|
1466 | #ifdef RT_BIG_ENDIAN
|
---|
1467 | # define RT_H2BE_U32(u32) (u32)
|
---|
1468 | #else
|
---|
1469 | # define RT_H2BE_U32(u32) RT_BSWAP_U32(u32)
|
---|
1470 | #endif
|
---|
1471 |
|
---|
1472 | /** @def RT_H2BE_U32_C
|
---|
1473 | * Converts an uint32_t constant from host to big endian byte order. */
|
---|
1474 | #ifdef RT_BIG_ENDIAN
|
---|
1475 | # define RT_H2BE_U32_C(u32) (u32)
|
---|
1476 | #else
|
---|
1477 | # define RT_H2BE_U32_C(u32) RT_BSWAP_U32_C(u32)
|
---|
1478 | #endif
|
---|
1479 |
|
---|
1480 | /** @def RT_H2BE_U16
|
---|
1481 | * Converts an uint16_t value from host to big endian byte order. */
|
---|
1482 | #ifdef RT_BIG_ENDIAN
|
---|
1483 | # define RT_H2BE_U16(u16) (u16)
|
---|
1484 | #else
|
---|
1485 | # define RT_H2BE_U16(u16) RT_BSWAP_U16(u16)
|
---|
1486 | #endif
|
---|
1487 |
|
---|
1488 | /** @def RT_H2BE_U16_C
|
---|
1489 | * Converts an uint16_t constant from host to big endian byte order. */
|
---|
1490 | #ifdef RT_BIG_ENDIAN
|
---|
1491 | # define RT_H2BE_U16_C(u16) (u16)
|
---|
1492 | #else
|
---|
1493 | # define RT_H2BE_U16_C(u16) RT_BSWAP_U16_C(u16)
|
---|
1494 | #endif
|
---|
1495 |
|
---|
1496 | /** @def RT_BE2H_U64
|
---|
1497 | * Converts an uint64_t value from big endian to host byte order. */
|
---|
1498 | #ifdef RT_BIG_ENDIAN
|
---|
1499 | # define RT_BE2H_U64(u64) (u64)
|
---|
1500 | #else
|
---|
1501 | # define RT_BE2H_U64(u64) RT_BSWAP_U64(u64)
|
---|
1502 | #endif
|
---|
1503 |
|
---|
1504 | /** @def RT_BE2H_U64
|
---|
1505 | * Converts an uint64_t constant from big endian to host byte order. */
|
---|
1506 | #ifdef RT_BIG_ENDIAN
|
---|
1507 | # define RT_BE2H_U64_C(u64) (u64)
|
---|
1508 | #else
|
---|
1509 | # define RT_BE2H_U64_C(u64) RT_BSWAP_U64_C(u64)
|
---|
1510 | #endif
|
---|
1511 |
|
---|
1512 | /** @def RT_BE2H_U32
|
---|
1513 | * Converts an uint32_t value from big endian to host byte order. */
|
---|
1514 | #ifdef RT_BIG_ENDIAN
|
---|
1515 | # define RT_BE2H_U32(u32) (u32)
|
---|
1516 | #else
|
---|
1517 | # define RT_BE2H_U32(u32) RT_BSWAP_U32(u32)
|
---|
1518 | #endif
|
---|
1519 |
|
---|
1520 | /** @def RT_BE2H_U32_C
|
---|
1521 | * Converts an uint32_t value from big endian to host byte order. */
|
---|
1522 | #ifdef RT_BIG_ENDIAN
|
---|
1523 | # define RT_BE2H_U32_C(u32) (u32)
|
---|
1524 | #else
|
---|
1525 | # define RT_BE2H_U32_C(u32) RT_BSWAP_U32_C(u32)
|
---|
1526 | #endif
|
---|
1527 |
|
---|
1528 | /** @def RT_BE2H_U16
|
---|
1529 | * Converts an uint16_t value from big endian to host byte order. */
|
---|
1530 | #ifdef RT_BIG_ENDIAN
|
---|
1531 | # define RT_BE2H_U16(u16) (u16)
|
---|
1532 | #else
|
---|
1533 | # define RT_BE2H_U16(u16) RT_BSWAP_U16(u16)
|
---|
1534 | #endif
|
---|
1535 |
|
---|
1536 | /** @def RT_BE2H_U16_C
|
---|
1537 | * Converts an uint16_t constant from big endian to host byte order. */
|
---|
1538 | #ifdef RT_BIG_ENDIAN
|
---|
1539 | # define RT_BE2H_U16_C(u16) (u16)
|
---|
1540 | #else
|
---|
1541 | # define RT_BE2H_U16_C(u16) RT_BSWAP_U16_C(u16)
|
---|
1542 | #endif
|
---|
1543 |
|
---|
1544 |
|
---|
1545 | /** @def RT_H2N_U64
|
---|
1546 | * Converts an uint64_t value from host to network byte order. */
|
---|
1547 | #define RT_H2N_U64(u64) RT_H2BE_U64(u64)
|
---|
1548 |
|
---|
1549 | /** @def RT_H2N_U64_C
|
---|
1550 | * Converts an uint64_t constant from host to network byte order. */
|
---|
1551 | #define RT_H2N_U64_C(u64) RT_H2BE_U64_C(u64)
|
---|
1552 |
|
---|
1553 | /** @def RT_H2N_U32
|
---|
1554 | * Converts an uint32_t value from host to network byte order. */
|
---|
1555 | #define RT_H2N_U32(u32) RT_H2BE_U32(u32)
|
---|
1556 |
|
---|
1557 | /** @def RT_H2N_U32_C
|
---|
1558 | * Converts an uint32_t constant from host to network byte order. */
|
---|
1559 | #define RT_H2N_U32_C(u32) RT_H2BE_U32_C(u32)
|
---|
1560 |
|
---|
1561 | /** @def RT_H2N_U16
|
---|
1562 | * Converts an uint16_t value from host to network byte order. */
|
---|
1563 | #define RT_H2N_U16(u16) RT_H2BE_U16(u16)
|
---|
1564 |
|
---|
1565 | /** @def RT_H2N_U16_C
|
---|
1566 | * Converts an uint16_t constant from host to network byte order. */
|
---|
1567 | #define RT_H2N_U16_C(u16) RT_H2BE_U16_C(u16)
|
---|
1568 |
|
---|
1569 | /** @def RT_N2H_U64
|
---|
1570 | * Converts an uint64_t value from network to host byte order. */
|
---|
1571 | #define RT_N2H_U64(u64) RT_BE2H_U64(u64)
|
---|
1572 |
|
---|
1573 | /** @def RT_N2H_U64_C
|
---|
1574 | * Converts an uint64_t constant from network to host byte order. */
|
---|
1575 | #define RT_N2H_U64_C(u64) RT_BE2H_U64_C(u64)
|
---|
1576 |
|
---|
1577 | /** @def RT_N2H_U32
|
---|
1578 | * Converts an uint32_t value from network to host byte order. */
|
---|
1579 | #define RT_N2H_U32(u32) RT_BE2H_U32(u32)
|
---|
1580 |
|
---|
1581 | /** @def RT_N2H_U32_C
|
---|
1582 | * Converts an uint32_t constant from network to host byte order. */
|
---|
1583 | #define RT_N2H_U32_C(u32) RT_BE2H_U32_C(u32)
|
---|
1584 |
|
---|
1585 | /** @def RT_N2H_U16
|
---|
1586 | * Converts an uint16_t value from network to host byte order. */
|
---|
1587 | #define RT_N2H_U16(u16) RT_BE2H_U16(u16)
|
---|
1588 |
|
---|
1589 | /** @def RT_N2H_U16_C
|
---|
1590 | * Converts an uint16_t value from network to host byte order. */
|
---|
1591 | #define RT_N2H_U16_C(u16) RT_BE2H_U16_C(u16)
|
---|
1592 |
|
---|
1593 |
|
---|
1594 | /*
|
---|
1595 | * The BSD sys/param.h + machine/param.h file is a major source of
|
---|
1596 | * namespace pollution. Kill off some of the worse ones unless we're
|
---|
1597 | * compiling kernel code.
|
---|
1598 | */
|
---|
1599 | #if defined(RT_OS_DARWIN) \
|
---|
1600 | && !defined(KERNEL) \
|
---|
1601 | && !defined(RT_NO_BSD_PARAM_H_UNDEFING) \
|
---|
1602 | && ( defined(_SYS_PARAM_H_) || defined(_I386_PARAM_H_) )
|
---|
1603 | /* sys/param.h: */
|
---|
1604 | # undef PSWP
|
---|
1605 | # undef PVM
|
---|
1606 | # undef PINOD
|
---|
1607 | # undef PRIBO
|
---|
1608 | # undef PVFS
|
---|
1609 | # undef PZERO
|
---|
1610 | # undef PSOCK
|
---|
1611 | # undef PWAIT
|
---|
1612 | # undef PLOCK
|
---|
1613 | # undef PPAUSE
|
---|
1614 | # undef PUSER
|
---|
1615 | # undef PRIMASK
|
---|
1616 | # undef MINBUCKET
|
---|
1617 | # undef MAXALLOCSAVE
|
---|
1618 | # undef FSHIFT
|
---|
1619 | # undef FSCALE
|
---|
1620 |
|
---|
1621 | /* i386/machine.h: */
|
---|
1622 | # undef ALIGN
|
---|
1623 | # undef ALIGNBYTES
|
---|
1624 | # undef DELAY
|
---|
1625 | # undef STATUS_WORD
|
---|
1626 | # undef USERMODE
|
---|
1627 | # undef BASEPRI
|
---|
1628 | # undef MSIZE
|
---|
1629 | # undef CLSIZE
|
---|
1630 | # undef CLSIZELOG2
|
---|
1631 | #endif
|
---|
1632 |
|
---|
1633 |
|
---|
1634 | /** @def NULL
|
---|
1635 | * NULL pointer.
|
---|
1636 | */
|
---|
1637 | #ifndef NULL
|
---|
1638 | # ifdef __cplusplus
|
---|
1639 | # define NULL 0
|
---|
1640 | # else
|
---|
1641 | # define NULL ((void*)0)
|
---|
1642 | # endif
|
---|
1643 | #endif
|
---|
1644 |
|
---|
1645 | /** @def NIL_OFFSET
|
---|
1646 | * NIL offset.
|
---|
1647 | * Whenever we use offsets instead of pointers to save space and relocation effort
|
---|
1648 | * NIL_OFFSET shall be used as the equivalent to NULL.
|
---|
1649 | */
|
---|
1650 | #define NIL_OFFSET (~0U)
|
---|
1651 |
|
---|
1652 | /** @def NOREF
|
---|
1653 | * Keeps the compiler from bitching about an unused parameter.
|
---|
1654 | */
|
---|
1655 | #define NOREF(var) (void)(var)
|
---|
1656 |
|
---|
1657 | /** @def RT_BREAKPOINT
|
---|
1658 | * Emit a debug breakpoint instruction.
|
---|
1659 | *
|
---|
1660 | * @remarks In the x86/amd64 gnu world we add a nop instruction after the int3
|
---|
1661 | * to force gdb to remain at the int3 source line.
|
---|
1662 | * @remarks The L4 kernel will try make sense of the breakpoint, thus the jmp on
|
---|
1663 | * x86/amd64.
|
---|
1664 | */
|
---|
1665 | #ifdef __GNUC__
|
---|
1666 | # if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
|
---|
1667 | # if !defined(__L4ENV__)
|
---|
1668 | # define RT_BREAKPOINT() __asm__ __volatile__("int $3\n\tnop\n\t")
|
---|
1669 | # else
|
---|
1670 | # define RT_BREAKPOINT() __asm__ __volatile__("int3; jmp 1f; 1:\n\t")
|
---|
1671 | # endif
|
---|
1672 | # elif defined(RT_ARCH_SPARC64)
|
---|
1673 | # define RT_BREAKPOINT() __asm__ __volatile__("illtrap $0\n\t") /** @todo Sparc64: this is just a wild guess. */
|
---|
1674 | # elif defined(RT_ARCH_SPARC)
|
---|
1675 | # define RT_BREAKPOINT() __asm__ __volatile__("unimp 0\n\t") /** @todo Sparc: this is just a wild guess (same as Sparc64, just different name). */
|
---|
1676 | # endif
|
---|
1677 | #endif
|
---|
1678 | #ifdef _MSC_VER
|
---|
1679 | # define RT_BREAKPOINT() __debugbreak()
|
---|
1680 | #endif
|
---|
1681 | #if defined(__IBMC__) || defined(__IBMCPP__)
|
---|
1682 | # define RT_BREAKPOINT() __interrupt(3)
|
---|
1683 | #endif
|
---|
1684 | #ifndef RT_BREAKPOINT
|
---|
1685 | # error "This compiler/arch is not supported!"
|
---|
1686 | #endif
|
---|
1687 |
|
---|
1688 |
|
---|
1689 | /** @defgroup grp_rt_cdefs_size Size Constants
|
---|
1690 | * (Of course, these are binary computer terms, not SI.)
|
---|
1691 | * @{
|
---|
1692 | */
|
---|
1693 | /** 1 K (Kilo) (1 024). */
|
---|
1694 | #define _1K 0x00000400
|
---|
1695 | /** 4 K (Kilo) (4 096). */
|
---|
1696 | #define _4K 0x00001000
|
---|
1697 | /** 32 K (Kilo) (32 678). */
|
---|
1698 | #define _32K 0x00008000
|
---|
1699 | /** 64 K (Kilo) (65 536). */
|
---|
1700 | #define _64K 0x00010000
|
---|
1701 | /** 128 K (Kilo) (131 072). */
|
---|
1702 | #define _128K 0x00020000
|
---|
1703 | /** 256 K (Kilo) (262 144). */
|
---|
1704 | #define _256K 0x00040000
|
---|
1705 | /** 512 K (Kilo) (524 288). */
|
---|
1706 | #define _512K 0x00080000
|
---|
1707 | /** 1 M (Mega) (1 048 576). */
|
---|
1708 | #define _1M 0x00100000
|
---|
1709 | /** 2 M (Mega) (2 097 152). */
|
---|
1710 | #define _2M 0x00200000
|
---|
1711 | /** 4 M (Mega) (4 194 304). */
|
---|
1712 | #define _4M 0x00400000
|
---|
1713 | /** 1 G (Giga) (1 073 741 824). */
|
---|
1714 | #define _1G 0x40000000
|
---|
1715 | /** 2 G (Giga) (2 147 483 648). (32-bit) */
|
---|
1716 | #define _2G32 0x80000000U
|
---|
1717 | /** 2 G (Giga) (2 147 483 648). (64-bit) */
|
---|
1718 | #define _2G 0x0000000080000000LL
|
---|
1719 | /** 4 G (Giga) (4 294 967 296). */
|
---|
1720 | #define _4G 0x0000000100000000LL
|
---|
1721 | /** 1 T (Tera) (1 099 511 627 776). */
|
---|
1722 | #define _1T 0x0000010000000000LL
|
---|
1723 | /** 1 P (Peta) (1 125 899 906 842 624). */
|
---|
1724 | #define _1P 0x0004000000000000LL
|
---|
1725 | /** 1 E (Exa) (1 152 921 504 606 846 976). */
|
---|
1726 | #define _1E 0x1000000000000000LL
|
---|
1727 | /** 2 E (Exa) (2 305 843 009 213 693 952). */
|
---|
1728 | #define _2E 0x2000000000000000ULL
|
---|
1729 | /** @} */
|
---|
1730 |
|
---|
1731 |
|
---|
1732 | /** @defgroup grp_rt_cdefs_dbgtype Debug Info Types
|
---|
1733 | * @{ */
|
---|
1734 | /** Other format. */
|
---|
1735 | #define RT_DBGTYPE_OTHER RT_BIT_32(0)
|
---|
1736 | /** Stabs. */
|
---|
1737 | #define RT_DBGTYPE_STABS RT_BIT_32(1)
|
---|
1738 | /** Debug With Arbitrary Record Format (DWARF). */
|
---|
1739 | #define RT_DBGTYPE_DWARF RT_BIT_32(2)
|
---|
1740 | /** Microsoft Codeview debug info. */
|
---|
1741 | #define RT_DBGTYPE_CODEVIEW RT_BIT_32(3)
|
---|
1742 | /** Watcom debug info. */
|
---|
1743 | #define RT_DBGTYPE_WATCOM RT_BIT_32(4)
|
---|
1744 | /** IBM High Level Language debug info. */
|
---|
1745 | #define RT_DBGTYPE_HLL RT_BIT_32(5)
|
---|
1746 | /** Old OS/2 and Windows symbol file. */
|
---|
1747 | #define RT_DBGTYPE_SYM RT_BIT_32(6)
|
---|
1748 | /** Map file. */
|
---|
1749 | #define RT_DBGTYPE_MAP RT_BIT_32(7)
|
---|
1750 | /** @} */
|
---|
1751 |
|
---|
1752 |
|
---|
1753 | /** @defgroup grp_rt_cdefs_exetype Executable Image Types
|
---|
1754 | * @{ */
|
---|
1755 | /** Some other format. */
|
---|
1756 | #define RT_EXETYPE_OTHER RT_BIT_32(0)
|
---|
1757 | /** Portable Executable. */
|
---|
1758 | #define RT_EXETYPE_PE RT_BIT_32(1)
|
---|
1759 | /** Linear eXecutable. */
|
---|
1760 | #define RT_EXETYPE_LX RT_BIT_32(2)
|
---|
1761 | /** Linear Executable. */
|
---|
1762 | #define RT_EXETYPE_LE RT_BIT_32(3)
|
---|
1763 | /** New Executable. */
|
---|
1764 | #define RT_EXETYPE_NE RT_BIT_32(4)
|
---|
1765 | /** DOS Executable (Mark Zbikowski). */
|
---|
1766 | #define RT_EXETYPE_MZ RT_BIT_32(5)
|
---|
1767 | /** COM Executable. */
|
---|
1768 | #define RT_EXETYPE_COM RT_BIT_32(6)
|
---|
1769 | /** a.out Executable. */
|
---|
1770 | #define RT_EXETYPE_AOUT RT_BIT_32(7)
|
---|
1771 | /** Executable and Linkable Format. */
|
---|
1772 | #define RT_EXETYPE_ELF RT_BIT_32(8)
|
---|
1773 | /** Mach-O Executable (including FAT ones). */
|
---|
1774 | #define RT_EXETYPE_MACHO RT_BIT_32(9)
|
---|
1775 | /** TE from UEFI. */
|
---|
1776 | #define RT_EXETYPE_TE RT_BIT_32(9)
|
---|
1777 | /** @} */
|
---|
1778 |
|
---|
1779 |
|
---|
1780 | /** @def VALID_PTR
|
---|
1781 | * Pointer validation macro.
|
---|
1782 | * @param ptr The pointer.
|
---|
1783 | */
|
---|
1784 | #if defined(RT_ARCH_AMD64)
|
---|
1785 | # ifdef IN_RING3
|
---|
1786 | # if defined(RT_OS_DARWIN) /* first 4GB is reserved for legacy kernel. */
|
---|
1787 | # define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) >= _4G \
|
---|
1788 | && !((uintptr_t)(ptr) & 0xffff800000000000ULL) )
|
---|
1789 | # elif defined(RT_OS_SOLARIS) /* The kernel only used the top 2TB, but keep it simple. */
|
---|
1790 | # define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
|
---|
1791 | && ( ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0xffff800000000000ULL \
|
---|
1792 | || ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0) )
|
---|
1793 | # else
|
---|
1794 | # define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
|
---|
1795 | && !((uintptr_t)(ptr) & 0xffff800000000000ULL) )
|
---|
1796 | # endif
|
---|
1797 | # else /* !IN_RING3 */
|
---|
1798 | # define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
|
---|
1799 | && ( ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0xffff800000000000ULL \
|
---|
1800 | || ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0) )
|
---|
1801 | # endif /* !IN_RING3 */
|
---|
1802 |
|
---|
1803 | #elif defined(RT_ARCH_X86)
|
---|
1804 | # define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U )
|
---|
1805 |
|
---|
1806 | #elif defined(RT_ARCH_SPARC64)
|
---|
1807 | # ifdef IN_RING3
|
---|
1808 | # if defined(RT_OS_SOLARIS)
|
---|
1809 | /** Sparc64 user mode: According to Figure 9.4 in solaris internals */
|
---|
1810 | # define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x80004000U >= 0x80004000U + 0x100000000ULL )
|
---|
1811 | # else
|
---|
1812 | # error "Port me"
|
---|
1813 | # endif
|
---|
1814 | # else /* !IN_RING3 */
|
---|
1815 | # if defined(RT_OS_SOLARIS)
|
---|
1816 | /** @todo Sparc64 kernel mode: This is according to Figure 11.1 in solaris
|
---|
1817 | * internals. Verify in sources. */
|
---|
1818 | # define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) >= 0x01000000U )
|
---|
1819 | # else
|
---|
1820 | # error "Port me"
|
---|
1821 | # endif
|
---|
1822 | # endif /* !IN_RING3 */
|
---|
1823 |
|
---|
1824 | #elif defined(RT_ARCH_SPARC)
|
---|
1825 | # ifdef IN_RING3
|
---|
1826 | # ifdef RT_OS_SOLARIS
|
---|
1827 | /** Sparc user mode: According to Figure 9.4 (sun4u) in solaris internals. */
|
---|
1828 | # define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x414000U >= 0x414000U + 0x10000U )
|
---|
1829 | # else
|
---|
1830 | # error "Port me"
|
---|
1831 | # endif
|
---|
1832 | # else /* !IN_RING3 */
|
---|
1833 | # ifdef RT_OS_SOLARIS
|
---|
1834 | /** @todo Sparc kernel mode: Check the sources! */
|
---|
1835 | # define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U )
|
---|
1836 | # else
|
---|
1837 | # error "Port me"
|
---|
1838 | # endif
|
---|
1839 | # endif /* !IN_RING3 */
|
---|
1840 |
|
---|
1841 | #else
|
---|
1842 | # error "Architecture identifier missing / not implemented."
|
---|
1843 | #endif
|
---|
1844 |
|
---|
1845 | /** Old name for RT_VALID_PTR. */
|
---|
1846 | #define VALID_PTR(ptr) RT_VALID_PTR(ptr)
|
---|
1847 |
|
---|
1848 | /** @def RT_VALID_ALIGNED_PTR
|
---|
1849 | * Pointer validation macro that also checks the alignment.
|
---|
1850 | * @param ptr The pointer.
|
---|
1851 | * @param align The alignment, must be a power of two.
|
---|
1852 | */
|
---|
1853 | #define RT_VALID_ALIGNED_PTR(ptr, align) \
|
---|
1854 | ( !((uintptr_t)(ptr) & (uintptr_t)((align) - 1)) \
|
---|
1855 | && VALID_PTR(ptr) )
|
---|
1856 |
|
---|
1857 |
|
---|
1858 | /** @def VALID_PHYS32
|
---|
1859 | * 32 bits physical address validation macro.
|
---|
1860 | * @param Phys The RTGCPHYS address.
|
---|
1861 | */
|
---|
1862 | #define VALID_PHYS32(Phys) ( (uint64_t)(Phys) < (uint64_t)_4G )
|
---|
1863 |
|
---|
1864 | /** @def N_
|
---|
1865 | * The \#define N_ is used to mark a string for translation. This is usable in
|
---|
1866 | * any part of the code, as it is only used by the tools that create message
|
---|
1867 | * catalogs. This macro is a no-op as far as the compiler and code generation
|
---|
1868 | * is concerned.
|
---|
1869 | *
|
---|
1870 | * If you want to both mark a string for translation and translate it, use _().
|
---|
1871 | */
|
---|
1872 | #define N_(s) (s)
|
---|
1873 |
|
---|
1874 | /** @def _
|
---|
1875 | * The \#define _ is used to mark a string for translation and to translate it
|
---|
1876 | * in one step.
|
---|
1877 | *
|
---|
1878 | * If you want to only mark a string for translation, use N_().
|
---|
1879 | */
|
---|
1880 | #define _(s) gettext(s)
|
---|
1881 |
|
---|
1882 |
|
---|
1883 | /** @def __PRETTY_FUNCTION__
|
---|
1884 | * With GNU C we'd like to use the builtin __PRETTY_FUNCTION__, so define that
|
---|
1885 | * for the other compilers.
|
---|
1886 | */
|
---|
1887 | #if !defined(__GNUC__) && !defined(__PRETTY_FUNCTION__)
|
---|
1888 | # define __PRETTY_FUNCTION__ __FUNCTION__
|
---|
1889 | #endif
|
---|
1890 |
|
---|
1891 |
|
---|
1892 | /** @def RT_STRICT
|
---|
1893 | * The \#define RT_STRICT controls whether or not assertions and other runtime
|
---|
1894 | * checks should be compiled in or not.
|
---|
1895 | *
|
---|
1896 | * If you want assertions which are not subject to compile time options use
|
---|
1897 | * the AssertRelease*() flavors.
|
---|
1898 | */
|
---|
1899 | #if !defined(RT_STRICT) && defined(DEBUG)
|
---|
1900 | # define RT_STRICT
|
---|
1901 | #endif
|
---|
1902 |
|
---|
1903 | /** @todo remove this: */
|
---|
1904 | #if !defined(RT_LOCK_STRICT) && !defined(DEBUG_bird)
|
---|
1905 | # define RT_LOCK_NO_STRICT
|
---|
1906 | #endif
|
---|
1907 | #if !defined(RT_LOCK_STRICT_ORDER) && !defined(DEBUG_bird)
|
---|
1908 | # define RT_LOCK_NO_STRICT_ORDER
|
---|
1909 | #endif
|
---|
1910 |
|
---|
1911 | /** @def RT_LOCK_STRICT
|
---|
1912 | * The \#define RT_LOCK_STRICT controls whether deadlock detection and related
|
---|
1913 | * checks are done in the lock and semaphore code. It is by default enabled in
|
---|
1914 | * RT_STRICT builds, but this behavior can be overriden by defining
|
---|
1915 | * RT_LOCK_NO_STRICT. */
|
---|
1916 | #if !defined(RT_LOCK_STRICT) && !defined(RT_LOCK_NO_STRICT) && defined(RT_STRICT)
|
---|
1917 | # define RT_LOCK_STRICT
|
---|
1918 | #endif
|
---|
1919 | /** @def RT_LOCK_NO_STRICT
|
---|
1920 | * The \#define RT_LOCK_NO_STRICT disables RT_LOCK_STRICT. */
|
---|
1921 | #if defined(RT_LOCK_NO_STRICT) && defined(RT_LOCK_STRICT)
|
---|
1922 | # undef RT_LOCK_STRICT
|
---|
1923 | #endif
|
---|
1924 |
|
---|
1925 | /** @def RT_LOCK_STRICT_ORDER
|
---|
1926 | * The \#define RT_LOCK_STRICT_ORDER controls whether locking order is checked
|
---|
1927 | * by the lock and semaphore code. It is by default enabled in RT_STRICT
|
---|
1928 | * builds, but this behavior can be overriden by defining
|
---|
1929 | * RT_LOCK_NO_STRICT_ORDER. */
|
---|
1930 | #if !defined(RT_LOCK_STRICT_ORDER) && !defined(RT_LOCK_NO_STRICT_ORDER) && defined(RT_STRICT)
|
---|
1931 | # define RT_LOCK_STRICT_ORDER
|
---|
1932 | #endif
|
---|
1933 | /** @def RT_LOCK_NO_STRICT_ORDER
|
---|
1934 | * The \#define RT_LOCK_NO_STRICT_ORDER disables RT_LOCK_STRICT_ORDER. */
|
---|
1935 | #if defined(RT_LOCK_NO_STRICT_ORDER) && defined(RT_LOCK_STRICT_ORDER)
|
---|
1936 | # undef RT_LOCK_STRICT_ORDER
|
---|
1937 | #endif
|
---|
1938 |
|
---|
1939 |
|
---|
1940 | /** Source position. */
|
---|
1941 | #define RT_SRC_POS __FILE__, __LINE__, __PRETTY_FUNCTION__
|
---|
1942 |
|
---|
1943 | /** Source position declaration. */
|
---|
1944 | #define RT_SRC_POS_DECL const char *pszFile, unsigned iLine, const char *pszFunction
|
---|
1945 |
|
---|
1946 | /** Source position arguments. */
|
---|
1947 | #define RT_SRC_POS_ARGS pszFile, iLine, pszFunction
|
---|
1948 |
|
---|
1949 | /** Applies NOREF() to the source position arguments. */
|
---|
1950 | #define RT_SRC_POS_NOREF() do { NOREF(pszFile); NOREF(iLine); NOREF(pszFunction); } while (0)
|
---|
1951 |
|
---|
1952 | /** @} */
|
---|
1953 |
|
---|
1954 |
|
---|
1955 | /** @defgroup grp_rt_cdefs_cpp Special Macros for C++
|
---|
1956 | * @ingroup grp_rt_cdefs
|
---|
1957 | * @{
|
---|
1958 | */
|
---|
1959 |
|
---|
1960 | #ifdef __cplusplus
|
---|
1961 |
|
---|
1962 | /** @def DECLEXPORT_CLASS
|
---|
1963 | * How to declare an exported class. Place this macro after the 'class'
|
---|
1964 | * keyword in the declaration of every class you want to export.
|
---|
1965 | *
|
---|
1966 | * @note It is necessary to use this macro even for inner classes declared
|
---|
1967 | * inside the already exported classes. This is a GCC specific requirement,
|
---|
1968 | * but it seems not to harm other compilers.
|
---|
1969 | */
|
---|
1970 | #if defined(_MSC_VER) || defined(RT_OS_OS2)
|
---|
1971 | # define DECLEXPORT_CLASS __declspec(dllexport)
|
---|
1972 | #elif defined(RT_USE_VISIBILITY_DEFAULT)
|
---|
1973 | # define DECLEXPORT_CLASS __attribute__((visibility("default")))
|
---|
1974 | #else
|
---|
1975 | # define DECLEXPORT_CLASS
|
---|
1976 | #endif
|
---|
1977 |
|
---|
1978 | /** @def DECLIMPORT_CLASS
|
---|
1979 | * How to declare an imported class Place this macro after the 'class'
|
---|
1980 | * keyword in the declaration of every class you want to export.
|
---|
1981 | *
|
---|
1982 | * @note It is necessary to use this macro even for inner classes declared
|
---|
1983 | * inside the already exported classes. This is a GCC specific requirement,
|
---|
1984 | * but it seems not to harm other compilers.
|
---|
1985 | */
|
---|
1986 | #if defined(_MSC_VER) || (defined(RT_OS_OS2) && !defined(__IBMC__) && !defined(__IBMCPP__))
|
---|
1987 | # define DECLIMPORT_CLASS __declspec(dllimport)
|
---|
1988 | #elif defined(RT_USE_VISIBILITY_DEFAULT)
|
---|
1989 | # define DECLIMPORT_CLASS __attribute__((visibility("default")))
|
---|
1990 | #else
|
---|
1991 | # define DECLIMPORT_CLASS
|
---|
1992 | #endif
|
---|
1993 |
|
---|
1994 | /** @def WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP
|
---|
1995 | * Macro to work around error C2593 of the not-so-smart MSVC 7.x ambiguity
|
---|
1996 | * resolver. The following snippet clearly demonstrates the code causing this
|
---|
1997 | * error:
|
---|
1998 | * @code
|
---|
1999 | * class A
|
---|
2000 | * {
|
---|
2001 | * public:
|
---|
2002 | * operator bool() const { return false; }
|
---|
2003 | * operator int*() const { return NULL; }
|
---|
2004 | * };
|
---|
2005 | * int main()
|
---|
2006 | * {
|
---|
2007 | * A a;
|
---|
2008 | * if (!a);
|
---|
2009 | * if (a && 0);
|
---|
2010 | * return 0;
|
---|
2011 | * }
|
---|
2012 | * @endcode
|
---|
2013 | * The code itself seems pretty valid to me and GCC thinks the same.
|
---|
2014 | *
|
---|
2015 | * This macro fixes the compiler error by explicitly overloading implicit
|
---|
2016 | * global operators !, && and || that take the given class instance as one of
|
---|
2017 | * their arguments.
|
---|
2018 | *
|
---|
2019 | * The best is to use this macro right after the class declaration.
|
---|
2020 | *
|
---|
2021 | * @note The macro expands to nothing for compilers other than MSVC.
|
---|
2022 | *
|
---|
2023 | * @param Cls Class to apply the workaround to
|
---|
2024 | */
|
---|
2025 | #if defined(_MSC_VER)
|
---|
2026 | # define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP(Cls) \
|
---|
2027 | inline bool operator! (const Cls &that) { return !bool (that); } \
|
---|
2028 | inline bool operator&& (const Cls &that, bool b) { return bool (that) && b; } \
|
---|
2029 | inline bool operator|| (const Cls &that, bool b) { return bool (that) || b; } \
|
---|
2030 | inline bool operator&& (bool b, const Cls &that) { return b && bool (that); } \
|
---|
2031 | inline bool operator|| (bool b, const Cls &that) { return b || bool (that); }
|
---|
2032 | #else
|
---|
2033 | # define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP(Cls)
|
---|
2034 | #endif
|
---|
2035 |
|
---|
2036 | /** @def WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL
|
---|
2037 | * Version of WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP for template classes.
|
---|
2038 | *
|
---|
2039 | * @param Tpl Name of the template class to apply the workaround to
|
---|
2040 | * @param ArgsDecl arguments of the template, as declared in |<>| after the
|
---|
2041 | * |template| keyword, including |<>|
|
---|
2042 | * @param Args arguments of the template, as specified in |<>| after the
|
---|
2043 | * template class name when using the, including |<>|
|
---|
2044 | *
|
---|
2045 | * Example:
|
---|
2046 | * @code
|
---|
2047 | * // template class declaration
|
---|
2048 | * template <class C>
|
---|
2049 | * class Foo { ... };
|
---|
2050 | * // applied workaround
|
---|
2051 | * WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL (Foo, <class C>, <C>)
|
---|
2052 | * @endcode
|
---|
2053 | */
|
---|
2054 | #if defined(_MSC_VER)
|
---|
2055 | # define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL(Tpl, ArgsDecl, Args) \
|
---|
2056 | template ArgsDecl \
|
---|
2057 | inline bool operator! (const Tpl Args &that) { return !bool (that); } \
|
---|
2058 | template ArgsDecl \
|
---|
2059 | inline bool operator&& (const Tpl Args &that, bool b) { return bool (that) && b; } \
|
---|
2060 | template ArgsDecl \
|
---|
2061 | inline bool operator|| (const Tpl Args &that, bool b) { return bool (that) || b; } \
|
---|
2062 | template ArgsDecl \
|
---|
2063 | inline bool operator&& (bool b, const Tpl Args &that) { return b && bool (that); } \
|
---|
2064 | template ArgsDecl \
|
---|
2065 | inline bool operator|| (bool b, const Tpl Args &that) { return b || bool (that); }
|
---|
2066 | #else
|
---|
2067 | # define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL(Tpl, ArgsDecl, Args)
|
---|
2068 | #endif
|
---|
2069 |
|
---|
2070 |
|
---|
2071 | /** @def DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP
|
---|
2072 | * Declares the copy constructor and the assignment operation as inlined no-ops
|
---|
2073 | * (non-existent functions) for the given class. Use this macro inside the
|
---|
2074 | * private section if you want to effectively disable these operations for your
|
---|
2075 | * class.
|
---|
2076 | *
|
---|
2077 | * @param Cls class name to declare for
|
---|
2078 | */
|
---|
2079 |
|
---|
2080 | #define DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(Cls) \
|
---|
2081 | inline Cls (const Cls &); \
|
---|
2082 | inline Cls &operator= (const Cls &);
|
---|
2083 |
|
---|
2084 |
|
---|
2085 | /** @def DECLARE_CLS_NEW_DELETE_NOOP
|
---|
2086 | * Declares the new and delete operations as no-ops (non-existent functions)
|
---|
2087 | * for the given class. Use this macro inside the private section if you want
|
---|
2088 | * to effectively limit creating class instances on the stack only.
|
---|
2089 | *
|
---|
2090 | * @note The destructor of the given class must not be virtual, otherwise a
|
---|
2091 | * compile time error will occur. Note that this is not a drawback: having
|
---|
2092 | * the virtual destructor for a stack-based class is absolutely useless
|
---|
2093 | * (the real class of the stack-based instance is always known to the compiler
|
---|
2094 | * at compile time, so it will always call the correct destructor).
|
---|
2095 | *
|
---|
2096 | * @param Cls class name to declare for
|
---|
2097 | */
|
---|
2098 | #define DECLARE_CLS_NEW_DELETE_NOOP(Cls) \
|
---|
2099 | inline static void *operator new (size_t); \
|
---|
2100 | inline static void operator delete (void *);
|
---|
2101 |
|
---|
2102 | #endif /* defined(__cplusplus) */
|
---|
2103 |
|
---|
2104 | /** @} */
|
---|
2105 |
|
---|
2106 | #endif
|
---|
2107 |
|
---|