VirtualBox

source: vbox/trunk/include/iprt/cdefs.h@ 74730

Last change on this file since 74730 was 73906, checked in by vboxsync, 6 years ago

iprt/cdefs.h: Added wrappers for the C++ noexcept keyword.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 165.1 KB
Line 
1/** @file
2 * IPRT - Common C and C++ definitions.
3 */
4
5/*
6 * Copyright (C) 2006-2017 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/** @def RT_C_DECLS_BEGIN
35 * Used to start a block of function declarations which are shared
36 * between C and C++ program.
37 */
38
39/** @def RT_C_DECLS_END
40 * Used to end a block of function declarations which are shared
41 * between C and C++ program.
42 */
43
44#if defined(__cplusplus)
45# define RT_C_DECLS_BEGIN extern "C" {
46# define RT_C_DECLS_END }
47#else
48# define RT_C_DECLS_BEGIN
49# define RT_C_DECLS_END
50#endif
51
52
53/*
54 * Shut up DOXYGEN warnings and guide it properly thru the code.
55 */
56#ifdef DOXYGEN_RUNNING
57# define __AMD64__
58# define __X86__
59# define RT_ARCH_AMD64
60# define RT_ARCH_X86
61# define RT_ARCH_SPARC
62# define RT_ARCH_SPARC64
63# define IN_RING0
64# define IN_RING3
65# define IN_RC
66# define IN_RC
67# define IN_RT_RC
68# define IN_RT_R0
69# define IN_RT_R3
70# define IN_RT_STATIC
71# define RT_STRICT
72# define RT_NO_STRICT
73# define RT_LOCK_STRICT
74# define RT_LOCK_NO_STRICT
75# define RT_LOCK_STRICT_ORDER
76# define RT_LOCK_NO_STRICT_ORDER
77# define RT_BREAKPOINT
78# define RT_NO_DEPRECATED_MACROS
79# define RT_EXCEPTIONS_ENABLED
80# define RT_BIG_ENDIAN
81# define RT_LITTLE_ENDIAN
82# define RT_COMPILER_GROKS_64BIT_BITFIELDS
83# define RT_COMPILER_WITH_80BIT_LONG_DOUBLE
84# define RT_NO_VISIBILITY_HIDDEN
85# define RT_GCC_SUPPORTS_VISIBILITY_HIDDEN
86# define RT_COMPILER_SUPPORTS_VA_ARGS
87# define RT_COMPILER_SUPPORTS_LAMBDA
88#endif /* DOXYGEN_RUNNING */
89
90/** @def RT_ARCH_X86
91 * Indicates that we're compiling for the X86 architecture.
92 */
93
94/** @def RT_ARCH_AMD64
95 * Indicates that we're compiling for the AMD64 architecture.
96 */
97
98/** @def RT_ARCH_SPARC
99 * Indicates that we're compiling for the SPARC V8 architecture (32-bit).
100 */
101
102/** @def RT_ARCH_SPARC64
103 * Indicates that we're compiling for the SPARC V9 architecture (64-bit).
104 */
105#if !defined(RT_ARCH_X86) \
106 && !defined(RT_ARCH_AMD64) \
107 && !defined(RT_ARCH_SPARC) \
108 && !defined(RT_ARCH_SPARC64) \
109 && !defined(RT_ARCH_ARM)
110# if defined(__amd64__) || defined(__x86_64__) || defined(_M_X64) || defined(__AMD64__)
111# define RT_ARCH_AMD64
112# elif defined(__i386__) || defined(_M_IX86) || defined(__X86__)
113# define RT_ARCH_X86
114# elif defined(__sparcv9)
115# define RT_ARCH_SPARC64
116# elif defined(__sparc__)
117# define RT_ARCH_SPARC
118# elif defined(__arm__) || defined(__arm32__)
119# define RT_ARCH_ARM
120# else /* PORTME: append test for new archs. */
121# error "Check what predefined macros your compiler uses to indicate architecture."
122# endif
123/* PORTME: append new archs checks. */
124#elif defined(RT_ARCH_X86) && defined(RT_ARCH_AMD64)
125# error "Both RT_ARCH_X86 and RT_ARCH_AMD64 cannot be defined at the same time!"
126#elif defined(RT_ARCH_X86) && defined(RT_ARCH_SPARC)
127# error "Both RT_ARCH_X86 and RT_ARCH_SPARC cannot be defined at the same time!"
128#elif defined(RT_ARCH_X86) && defined(RT_ARCH_SPARC64)
129# error "Both RT_ARCH_X86 and RT_ARCH_SPARC64 cannot be defined at the same time!"
130#elif defined(RT_ARCH_AMD64) && defined(RT_ARCH_SPARC)
131# error "Both RT_ARCH_AMD64 and RT_ARCH_SPARC cannot be defined at the same time!"
132#elif defined(RT_ARCH_AMD64) && defined(RT_ARCH_SPARC64)
133# error "Both RT_ARCH_AMD64 and RT_ARCH_SPARC64 cannot be defined at the same time!"
134#elif defined(RT_ARCH_SPARC) && defined(RT_ARCH_SPARC64)
135# error "Both RT_ARCH_SPARC and RT_ARCH_SPARC64 cannot be defined at the same time!"
136#elif defined(RT_ARCH_ARM) && defined(RT_ARCH_AMD64)
137# error "Both RT_ARCH_ARM and RT_ARCH_AMD64 cannot be defined at the same time!"
138#elif defined(RT_ARCH_ARM) && defined(RT_ARCH_X86)
139# error "Both RT_ARCH_ARM and RT_ARCH_X86 cannot be defined at the same time!"
140#elif defined(RT_ARCH_ARM) && defined(RT_ARCH_SPARC64)
141# error "Both RT_ARCH_ARM and RT_ARCH_SPARC64 cannot be defined at the same time!"
142#elif defined(RT_ARCH_ARM) && defined(RT_ARCH_SPARC)
143# error "Both RT_ARCH_ARM and RT_ARCH_SPARC cannot be defined at the same time!"
144#endif
145
146/* Final check (PORTME). */
147#if (defined(RT_ARCH_X86) != 0) \
148 + (defined(RT_ARCH_AMD64) != 0) \
149 + (defined(RT_ARCH_SPARC) != 0) \
150 + (defined(RT_ARCH_SPARC64) != 0) \
151 + (defined(RT_ARCH_ARM) != 0) \
152 != 1
153# error "Exactly one RT_ARCH_XXX macro shall be defined"
154#endif
155
156/** @def RT_GNUC_PREREQ
157 * Shorter than fiddling with __GNUC__ and __GNUC_MINOR__.
158 *
159 * @param a_MinMajor Minimum major version
160 * @param a_MinMinor The minor version number part.
161 */
162#define RT_GNUC_PREREQ(a_MinMajor, a_MinMinor) RT_GNUC_PREREQ_EX(a_MinMajor, a_MinMinor, 0)
163/** @def RT_GNUC_PREREQ_EX
164 * Simplified way of checking __GNUC__ and __GNUC_MINOR__ regardless of actual
165 * compiler used, returns @a a_OtherRet for other compilers.
166 *
167 * @param a_MinMajor Minimum major version
168 * @param a_MinMinor The minor version number part.
169 * @param a_OtherRet What to return for non-GCC compilers.
170 */
171#if defined(__GNUC__) && defined(__GNUC_MINOR__)
172# define RT_GNUC_PREREQ_EX(a_MinMajor, a_MinMinor, a_OtherRet) \
173 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((a_MinMajor) << 16) + (a_MinMinor))
174#else
175# define RT_GNUC_PREREQ_EX(a_MinMajor, a_MinMinor, a_OtherRet) (a_OtherRet)
176#endif
177
178/** @def RT_MSC_PREREQ
179 * Convenient way of checking _MSC_VER regardless of actual compiler used
180 * (returns false if not MSC).
181 *
182 * @param a_MinVer Preferably a RT_MSC_VER_XXX value.
183 */
184#define RT_MSC_PREREQ(a_MinVer) RT_MSC_PREREQ_EX(a_MinVer, 0)
185/** @def RT_MSC_PREREQ_EX
186 * Convenient way of checking _MSC_VER regardless of actual compiler used,
187 * returns @a a_OtherRet for other compilers.
188 *
189 * @param a_MinVer Preferably a RT_MSC_VER_XXX value.
190 * @param a_OtherRet What to return for non-MSC compilers.
191 */
192#if defined(_MSC_VER)
193# define RT_MSC_PREREQ_EX(a_MinVer, a_OtherRet) ( (_MSC_VER) >= (a_MinVer) )
194#else
195# define RT_MSC_PREREQ_EX(a_MinVer, a_OtherRet) (a_OtherRet)
196#endif
197/** @name RT_MSC_VER_XXX - _MSC_VER values to use with RT_MSC_PREREQ.
198 * @remarks The VCxxx values are derived from the CRT DLLs shipping with the
199 * compilers.
200 * @{ */
201#define RT_MSC_VER_VC50 (1100) /**< Visual C++ 5.0. */
202#define RT_MSC_VER_VC60 (1200) /**< Visual C++ 6.0. */
203#define RT_MSC_VER_VC70 (1300) /**< Visual C++ 7.0. */
204#define RT_MSC_VER_VC70 (1300) /**< Visual C++ 7.0. */
205#define RT_MSC_VER_VS2003 (1310) /**< Visual Studio 2003, aka Visual C++ 7.1. */
206#define RT_MSC_VER_VC71 RT_MSC_VER_VS2003 /**< Visual C++ 7.1, aka Visual Studio 2003. */
207#define RT_MSC_VER_VS2005 (1400) /**< Visual Studio 2005. */
208#define RT_MSC_VER_VC80 RT_MSC_VER_VS2005 /**< Visual C++ 8.0, aka Visual Studio 2008. */
209#define RT_MSC_VER_VS2008 (1500) /**< Visual Studio 2008. */
210#define RT_MSC_VER_VC90 RT_MSC_VER_VS2008 /**< Visual C++ 9.0, aka Visual Studio 2008. */
211#define RT_MSC_VER_VS2010 (1600) /**< Visual Studio 2010. */
212#define RT_MSC_VER_VC100 RT_MSC_VER_VS2010 /**< Visual C++ 10.0, aka Visual Studio 2010. */
213#define RT_MSC_VER_VS2012 (1700) /**< Visual Studio 2012. */
214#define RT_MSC_VER_VC110 RT_MSC_VER_VS2012 /**< Visual C++ 11.0, aka Visual Studio 2012. */
215#define RT_MSC_VER_VS2013 (1800) /**< Visual Studio 2013. */
216#define RT_MSC_VER_VC120 RT_MSC_VER_VS2013 /**< Visual C++ 12.0, aka Visual Studio 2013. */
217#define RT_MSC_VER_VS2015 (1900) /**< Visual Studio 2015. */
218#define RT_MSC_VER_VC140 RT_MSC_VER_VS2015 /**< Visual C++ 14.0, aka Visual Studio 2015. */
219/** @} */
220
221/** @def RT_CLANG_PREREQ
222 * Shorter than fiddling with __clang_major__ and __clang_minor__.
223 *
224 * @param a_MinMajor Minimum major version
225 * @param a_MinMinor The minor version number part.
226 */
227#define RT_CLANG_PREREQ(a_MinMajor, a_MinMinor) RT_CLANG_PREREQ_EX(a_MinMajor, a_MinMinor, 0)
228/** @def RT_CLANG_PREREQ_EX
229 * Simplified way of checking __clang_major__ and __clang_minor__ regardless of
230 * actual compiler used, returns @a a_OtherRet for other compilers.
231 *
232 * @param a_MinMajor Minimum major version
233 * @param a_MinMinor The minor version number part.
234 * @param a_OtherRet What to return for non-GCC compilers.
235 */
236#if defined(__clang_major__) && defined(__clang_minor__)
237# define RT_CLANG_PREREQ_EX(a_MinMajor, a_MinMinor, a_OtherRet) \
238 ((__clang_major__ << 16) + __clang_minor__ >= ((a_MinMajor) << 16) + (a_MinMinor))
239#else
240# define RT_CLANG_PREREQ_EX(a_MinMajor, a_MinMinor, a_OtherRet) (a_OtherRet)
241#endif
242
243
244/** @def __X86__
245 * Indicates that we're compiling for the X86 architecture.
246 * @deprecated
247 */
248
249/** @def __AMD64__
250 * Indicates that we're compiling for the AMD64 architecture.
251 * @deprecated
252 */
253#if !defined(__X86__) && !defined(__AMD64__) && (defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86))
254# if defined(RT_ARCH_AMD64)
255# define __AMD64__
256# elif defined(RT_ARCH_X86)
257# define __X86__
258# else
259# error "Check what predefined macros your compiler uses to indicate architecture."
260# endif
261#elif defined(__X86__) && defined(__AMD64__)
262# error "Both __X86__ and __AMD64__ cannot be defined at the same time!"
263#elif defined(__X86__) && !defined(RT_ARCH_X86)
264# error "__X86__ without RT_ARCH_X86!"
265#elif defined(__AMD64__) && !defined(RT_ARCH_AMD64)
266# error "__AMD64__ without RT_ARCH_AMD64!"
267#endif
268
269/** @def RT_BIG_ENDIAN
270 * Defined if the architecture is big endian. */
271/** @def RT_LITTLE_ENDIAN
272 * Defined if the architecture is little endian. */
273#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86) || defined(RT_ARCH_ARM)
274# define RT_LITTLE_ENDIAN
275#elif defined(RT_ARCH_SPARC) || defined(RT_ARCH_SPARC64)
276# define RT_BIG_ENDIAN
277#else
278# error "PORTME: architecture endianess"
279#endif
280#if defined(RT_BIG_ENDIAN) && defined(RT_LITTLE_ENDIAN)
281# error "Both RT_BIG_ENDIAN and RT_LITTLE_ENDIAN are defined"
282#endif
283
284
285/** @def IN_RING0
286 * Used to indicate that we're compiling code which is running
287 * in Ring-0 Host Context.
288 */
289
290/** @def IN_RING3
291 * Used to indicate that we're compiling code which is running
292 * in Ring-3 Host Context.
293 */
294
295/** @def IN_RC
296 * Used to indicate that we're compiling code which is running
297 * in the Raw-mode Context (implies R0).
298 */
299#if !defined(IN_RING3) && !defined(IN_RING0) && !defined(IN_RC)
300# error "You must define which context the compiled code should run in; IN_RING3, IN_RING0 or IN_RC"
301#endif
302#if (defined(IN_RING3) && (defined(IN_RING0) || defined(IN_RC)) ) \
303 || (defined(IN_RING0) && (defined(IN_RING3) || defined(IN_RC)) ) \
304 || (defined(IN_RC) && (defined(IN_RING3) || defined(IN_RING0)) )
305# error "Only one of the IN_RING3, IN_RING0, IN_RC defines should be defined."
306#endif
307
308
309/** @def ARCH_BITS
310 * Defines the bit count of the current context.
311 */
312#if !defined(ARCH_BITS) || defined(DOXYGEN_RUNNING)
313# if defined(RT_ARCH_AMD64) || defined(RT_ARCH_SPARC64)
314# define ARCH_BITS 64
315# elif !defined(__I86__) || !defined(__WATCOMC__)
316# define ARCH_BITS 32
317# else
318# define ARCH_BITS 16
319# endif
320#endif
321
322/* ARCH_BITS validation (PORTME). */
323#if ARCH_BITS == 64
324 #if defined(RT_ARCH_X86) || defined(RT_ARCH_SPARC) || defined(RT_ARCH_ARM)
325 # error "ARCH_BITS=64 but non-64-bit RT_ARCH_XXX defined."
326 #endif
327 #if !defined(RT_ARCH_AMD64) && !defined(RT_ARCH_SPARC64)
328 # error "ARCH_BITS=64 but no 64-bit RT_ARCH_XXX defined."
329 #endif
330
331#elif ARCH_BITS == 32
332 #if defined(RT_ARCH_AMD64) || defined(RT_ARCH_SPARC64)
333 # error "ARCH_BITS=32 but non-32-bit RT_ARCH_XXX defined."
334 #endif
335 #if !defined(RT_ARCH_X86) && !defined(RT_ARCH_SPARC) && !defined(RT_ARCH_ARM)
336 # error "ARCH_BITS=32 but no 32-bit RT_ARCH_XXX defined."
337 #endif
338
339#elif ARCH_BITS == 16
340 #if defined(RT_ARCH_AMD64) || defined(RT_ARCH_SPARC) || defined(RT_ARCH_SPARC64) || defined(RT_ARCH_ARM)
341 # error "ARCH_BITS=16 but non-16-bit RT_ARCH_XX defined."
342 #endif
343 #if !defined(RT_ARCH_X86)
344 # error "ARCH_BITS=16 but RT_ARCH_X86 isn't defined."
345 #endif
346
347#else
348# error "Unsupported ARCH_BITS value!"
349#endif
350
351/** @def HC_ARCH_BITS
352 * Defines the host architecture bit count.
353 */
354#if !defined(HC_ARCH_BITS) || defined(DOXYGEN_RUNNING)
355# ifndef IN_RC
356# define HC_ARCH_BITS ARCH_BITS
357# else
358# define HC_ARCH_BITS 32
359# endif
360#endif
361
362/** @def GC_ARCH_BITS
363 * Defines the guest architecture bit count.
364 */
365#if !defined(GC_ARCH_BITS) && !defined(DOXYGEN_RUNNING)
366# ifdef VBOX_WITH_64_BITS_GUESTS
367# define GC_ARCH_BITS 64
368# else
369# define GC_ARCH_BITS 32
370# endif
371#endif
372
373/** @def R3_ARCH_BITS
374 * Defines the host ring-3 architecture bit count.
375 */
376#if !defined(R3_ARCH_BITS) || defined(DOXYGEN_RUNNING)
377# ifdef IN_RING3
378# define R3_ARCH_BITS ARCH_BITS
379# else
380# define R3_ARCH_BITS HC_ARCH_BITS
381# endif
382#endif
383
384/** @def R0_ARCH_BITS
385 * Defines the host ring-0 architecture bit count.
386 */
387#if !defined(R0_ARCH_BITS) || defined(DOXYGEN_RUNNING)
388# ifdef IN_RING0
389# define R0_ARCH_BITS ARCH_BITS
390# else
391# define R0_ARCH_BITS HC_ARCH_BITS
392# endif
393#endif
394
395/** @def GC_ARCH_BITS
396 * Defines the guest architecture bit count.
397 */
398#if !defined(GC_ARCH_BITS) || defined(DOXYGEN_RUNNING)
399# ifdef IN_RC
400# define GC_ARCH_BITS ARCH_BITS
401# else
402# define GC_ARCH_BITS 32
403# endif
404#endif
405
406
407
408/** @name RT_OPSYS_XXX - Operative System Identifiers.
409 * These are the value that the RT_OPSYS \#define can take. @{
410 */
411/** Unknown OS. */
412#define RT_OPSYS_UNKNOWN 0
413/** OS Agnostic. */
414#define RT_OPSYS_AGNOSTIC 1
415/** Darwin - aka Mac OS X. */
416#define RT_OPSYS_DARWIN 2
417/** DragonFly BSD. */
418#define RT_OPSYS_DRAGONFLY 3
419/** DOS. */
420#define RT_OPSYS_DOS 4
421/** FreeBSD. */
422#define RT_OPSYS_FREEBSD 5
423/** Haiku. */
424#define RT_OPSYS_HAIKU 6
425/** Linux. */
426#define RT_OPSYS_LINUX 7
427/** L4. */
428#define RT_OPSYS_L4 8
429/** Minix. */
430#define RT_OPSYS_MINIX 9
431/** NetBSD. */
432#define RT_OPSYS_NETBSD 11
433/** Netware. */
434#define RT_OPSYS_NETWARE 12
435/** NT (native). */
436#define RT_OPSYS_NT 13
437/** OpenBSD. */
438#define RT_OPSYS_OPENBSD 14
439/** OS/2. */
440#define RT_OPSYS_OS2 15
441/** Plan 9. */
442#define RT_OPSYS_PLAN9 16
443/** QNX. */
444#define RT_OPSYS_QNX 17
445/** Solaris. */
446#define RT_OPSYS_SOLARIS 18
447/** UEFI. */
448#define RT_OPSYS_UEFI 19
449/** Windows. */
450#define RT_OPSYS_WINDOWS 20
451/** The max RT_OPSYS_XXX value (exclusive). */
452#define RT_OPSYS_MAX 21
453/** @} */
454
455/** @def RT_OPSYS
456 * Indicates which OS we're targeting. It's a \#define with is
457 * assigned one of the RT_OPSYS_XXX defines above.
458 *
459 * So to test if we're on FreeBSD do the following:
460 * @code
461 * #if RT_OPSYS == RT_OPSYS_FREEBSD
462 * some_funky_freebsd_specific_stuff();
463 * #endif
464 * @endcode
465 */
466
467/*
468 * Set RT_OPSYS_XXX according to RT_OS_XXX.
469 *
470 * Search: #define RT_OPSYS_([A-Z0-9]+) .*
471 * Replace: # elif defined(RT_OS_\1)\n# define RT_OPSYS RT_OPSYS_\1
472 */
473#ifndef RT_OPSYS
474# if defined(RT_OS_UNKNOWN) || defined(DOXYGEN_RUNNING)
475# define RT_OPSYS RT_OPSYS_UNKNOWN
476# elif defined(RT_OS_AGNOSTIC)
477# define RT_OPSYS RT_OPSYS_AGNOSTIC
478# elif defined(RT_OS_DARWIN)
479# define RT_OPSYS RT_OPSYS_DARWIN
480# elif defined(RT_OS_DRAGONFLY)
481# define RT_OPSYS RT_OPSYS_DRAGONFLY
482# elif defined(RT_OS_DOS)
483# define RT_OPSYS RT_OPSYS_DOS
484# elif defined(RT_OS_FREEBSD)
485# define RT_OPSYS RT_OPSYS_FREEBSD
486# elif defined(RT_OS_HAIKU)
487# define RT_OPSYS RT_OPSYS_HAIKU
488# elif defined(RT_OS_LINUX)
489# define RT_OPSYS RT_OPSYS_LINUX
490# elif defined(RT_OS_L4)
491# define RT_OPSYS RT_OPSYS_L4
492# elif defined(RT_OS_MINIX)
493# define RT_OPSYS RT_OPSYS_MINIX
494# elif defined(RT_OS_NETBSD)
495# define RT_OPSYS RT_OPSYS_NETBSD
496# elif defined(RT_OS_NETWARE)
497# define RT_OPSYS RT_OPSYS_NETWARE
498# elif defined(RT_OS_NT)
499# define RT_OPSYS RT_OPSYS_NT
500# elif defined(RT_OS_OPENBSD)
501# define RT_OPSYS RT_OPSYS_OPENBSD
502# elif defined(RT_OS_OS2)
503# define RT_OPSYS RT_OPSYS_OS2
504# elif defined(RT_OS_PLAN9)
505# define RT_OPSYS RT_OPSYS_PLAN9
506# elif defined(RT_OS_QNX)
507# define RT_OPSYS RT_OPSYS_QNX
508# elif defined(RT_OS_SOLARIS)
509# define RT_OPSYS RT_OPSYS_SOLARIS
510# elif defined(RT_OS_UEFI)
511# define RT_OPSYS RT_OPSYS_UEFI
512# elif defined(RT_OS_WINDOWS)
513# define RT_OPSYS RT_OPSYS_WINDOWS
514# endif
515#endif
516
517/*
518 * Guess RT_OPSYS based on compiler predefined macros.
519 */
520#ifndef RT_OPSYS
521# if defined(__APPLE__)
522# define RT_OPSYS RT_OPSYS_DARWIN
523# elif defined(__DragonFly__)
524# define RT_OPSYS RT_OPSYS_DRAGONFLY
525# elif defined(__FreeBSD__) /*??*/
526# define RT_OPSYS RT_OPSYS_FREEBSD
527# elif defined(__gnu_linux__)
528# define RT_OPSYS RT_OPSYS_LINUX
529# elif defined(__NetBSD__) /*??*/
530# define RT_OPSYS RT_OPSYS_NETBSD
531# elif defined(__OpenBSD__) /*??*/
532# define RT_OPSYS RT_OPSYS_OPENBSD
533# elif defined(__OS2__)
534# define RT_OPSYS RT_OPSYS_OS2
535# elif defined(__sun__) || defined(__SunOS__) || defined(__sun) || defined(__SunOS)
536# define RT_OPSYS RT_OPSYS_SOLARIS
537# elif defined(_WIN32) || defined(_WIN64)
538# define RT_OPSYS RT_OPSYS_WINDOWS
539# elif defined(MSDOS) || defined(_MSDOS) || defined(DOS16RM) /* OW+MSC || MSC || DMC */
540# define RT_OPSYS RT_OPSYS_DOS
541# else
542# error "Port Me"
543# endif
544#endif
545
546#if RT_OPSYS < RT_OPSYS_UNKNOWN || RT_OPSYS >= RT_OPSYS_MAX
547# error "Invalid RT_OPSYS value."
548#endif
549
550/*
551 * Do some consistency checks.
552 *
553 * Search: #define RT_OPSYS_([A-Z0-9]+) .*
554 * Replace: #if defined(RT_OS_\1) && RT_OPSYS != RT_OPSYS_\1\n# error RT_OPSYS vs RT_OS_\1\n#endif
555 */
556#if defined(RT_OS_UNKNOWN) && RT_OPSYS != RT_OPSYS_UNKNOWN
557# error RT_OPSYS vs RT_OS_UNKNOWN
558#endif
559#if defined(RT_OS_AGNOSTIC) && RT_OPSYS != RT_OPSYS_AGNOSTIC
560# error RT_OPSYS vs RT_OS_AGNOSTIC
561#endif
562#if defined(RT_OS_DARWIN) && RT_OPSYS != RT_OPSYS_DARWIN
563# error RT_OPSYS vs RT_OS_DARWIN
564#endif
565#if defined(RT_OS_DRAGONFLY) && RT_OPSYS != RT_OPSYS_DRAGONFLY
566# error RT_OPSYS vs RT_OS_DRAGONFLY
567#endif
568#if defined(RT_OS_DOS) && RT_OPSYS != RT_OPSYS_DOS
569# error RT_OPSYS vs RT_OS_DOS
570#endif
571#if defined(RT_OS_FREEBSD) && RT_OPSYS != RT_OPSYS_FREEBSD
572# error RT_OPSYS vs RT_OS_FREEBSD
573#endif
574#if defined(RT_OS_HAIKU) && RT_OPSYS != RT_OPSYS_HAIKU
575# error RT_OPSYS vs RT_OS_HAIKU
576#endif
577#if defined(RT_OS_LINUX) && RT_OPSYS != RT_OPSYS_LINUX
578# error RT_OPSYS vs RT_OS_LINUX
579#endif
580#if defined(RT_OS_L4) && RT_OPSYS != RT_OPSYS_L4
581# error RT_OPSYS vs RT_OS_L4
582#endif
583#if defined(RT_OS_MINIX) && RT_OPSYS != RT_OPSYS_MINIX
584# error RT_OPSYS vs RT_OS_MINIX
585#endif
586#if defined(RT_OS_NETBSD) && RT_OPSYS != RT_OPSYS_NETBSD
587# error RT_OPSYS vs RT_OS_NETBSD
588#endif
589#if defined(RT_OS_NETWARE) && RT_OPSYS != RT_OPSYS_NETWARE
590# error RT_OPSYS vs RT_OS_NETWARE
591#endif
592#if defined(RT_OS_NT) && RT_OPSYS != RT_OPSYS_NT
593# error RT_OPSYS vs RT_OS_NT
594#endif
595#if defined(RT_OS_OPENBSD) && RT_OPSYS != RT_OPSYS_OPENBSD
596# error RT_OPSYS vs RT_OS_OPENBSD
597#endif
598#if defined(RT_OS_OS2) && RT_OPSYS != RT_OPSYS_OS2
599# error RT_OPSYS vs RT_OS_OS2
600#endif
601#if defined(RT_OS_PLAN9) && RT_OPSYS != RT_OPSYS_PLAN9
602# error RT_OPSYS vs RT_OS_PLAN9
603#endif
604#if defined(RT_OS_QNX) && RT_OPSYS != RT_OPSYS_QNX
605# error RT_OPSYS vs RT_OS_QNX
606#endif
607#if defined(RT_OS_SOLARIS) && RT_OPSYS != RT_OPSYS_SOLARIS
608# error RT_OPSYS vs RT_OS_SOLARIS
609#endif
610#if defined(RT_OS_UEFI) && RT_OPSYS != RT_OPSYS_UEFI
611# error RT_OPSYS vs RT_OS_UEFI
612#endif
613#if defined(RT_OS_WINDOWS) && RT_OPSYS != RT_OPSYS_WINDOWS
614# error RT_OPSYS vs RT_OS_WINDOWS
615#endif
616
617/*
618 * Make sure the RT_OS_XXX macro is defined.
619 *
620 * Search: #define RT_OPSYS_([A-Z0-9]+) .*
621 * Replace: #elif RT_OPSYS == RT_OPSYS_\1\n# ifndef RT_OS_\1\n# define RT_OS_\1\n# endif
622 */
623#if RT_OPSYS == RT_OPSYS_UNKNOWN
624# ifndef RT_OS_UNKNOWN
625# define RT_OS_UNKNOWN
626# endif
627#elif RT_OPSYS == RT_OPSYS_AGNOSTIC
628# ifndef RT_OS_AGNOSTIC
629# define RT_OS_AGNOSTIC
630# endif
631#elif RT_OPSYS == RT_OPSYS_DARWIN
632# ifndef RT_OS_DARWIN
633# define RT_OS_DARWIN
634# endif
635#elif RT_OPSYS == RT_OPSYS_DRAGONFLY
636# ifndef RT_OS_DRAGONFLY
637# define RT_OS_DRAGONFLY
638# endif
639#elif RT_OPSYS == RT_OPSYS_DOS
640# ifndef RT_OS_DOS
641# define RT_OS_DOS
642# endif
643#elif RT_OPSYS == RT_OPSYS_FREEBSD
644# ifndef RT_OS_FREEBSD
645# define RT_OS_FREEBSD
646# endif
647#elif RT_OPSYS == RT_OPSYS_HAIKU
648# ifndef RT_OS_HAIKU
649# define RT_OS_HAIKU
650# endif
651#elif RT_OPSYS == RT_OPSYS_LINUX
652# ifndef RT_OS_LINUX
653# define RT_OS_LINUX
654# endif
655#elif RT_OPSYS == RT_OPSYS_L4
656# ifndef RT_OS_L4
657# define RT_OS_L4
658# endif
659#elif RT_OPSYS == RT_OPSYS_MINIX
660# ifndef RT_OS_MINIX
661# define RT_OS_MINIX
662# endif
663#elif RT_OPSYS == RT_OPSYS_NETBSD
664# ifndef RT_OS_NETBSD
665# define RT_OS_NETBSD
666# endif
667#elif RT_OPSYS == RT_OPSYS_NETWARE
668# ifndef RT_OS_NETWARE
669# define RT_OS_NETWARE
670# endif
671#elif RT_OPSYS == RT_OPSYS_NT
672# ifndef RT_OS_NT
673# define RT_OS_NT
674# endif
675#elif RT_OPSYS == RT_OPSYS_OPENBSD
676# ifndef RT_OS_OPENBSD
677# define RT_OS_OPENBSD
678# endif
679#elif RT_OPSYS == RT_OPSYS_OS2
680# ifndef RT_OS_OS2
681# define RT_OS_OS2
682# endif
683#elif RT_OPSYS == RT_OPSYS_PLAN9
684# ifndef RT_OS_PLAN9
685# define RT_OS_PLAN9
686# endif
687#elif RT_OPSYS == RT_OPSYS_QNX
688# ifndef RT_OS_QNX
689# define RT_OS_QNX
690# endif
691#elif RT_OPSYS == RT_OPSYS_SOLARIS
692# ifndef RT_OS_SOLARIS
693# define RT_OS_SOLARIS
694# endif
695#elif RT_OPSYS == RT_OPSYS_UEFI
696# ifndef RT_OS_UEFI
697# define RT_OS_UEFI
698# endif
699#elif RT_OPSYS == RT_OPSYS_WINDOWS
700# ifndef RT_OS_WINDOWS
701# define RT_OS_WINDOWS
702# endif
703#else
704# error "Bad RT_OPSYS value."
705#endif
706
707
708/**
709 * Checks whether the given OpSys uses DOS-style paths or not.
710 *
711 * By DOS-style paths we include drive lettering and UNC paths.
712 *
713 * @returns true / false
714 * @param a_OpSys The RT_OPSYS_XXX value to check, will be reference
715 * multiple times.
716 */
717#define RT_OPSYS_USES_DOS_PATHS(a_OpSys) \
718 ( (a_OpSys) == RT_OPSYS_WINDOWS \
719 || (a_OpSys) == RT_OPSYS_OS2 \
720 || (a_OpSys) == RT_OPSYS_DOS )
721
722
723
724/** @def CTXTYPE
725 * Declare a type differently in GC, R3 and R0.
726 *
727 * @param GCType The GC type.
728 * @param R3Type The R3 type.
729 * @param R0Type The R0 type.
730 * @remark For pointers used only in one context use RCPTRTYPE(), R3R0PTRTYPE(), R3PTRTYPE() or R0PTRTYPE().
731 */
732#ifdef IN_RC
733# define CTXTYPE(GCType, R3Type, R0Type) GCType
734#elif defined(IN_RING3)
735# define CTXTYPE(GCType, R3Type, R0Type) R3Type
736#else
737# define CTXTYPE(GCType, R3Type, R0Type) R0Type
738#endif
739
740/** @def RCPTRTYPE
741 * Declare a pointer which is used in the raw mode context but appears in structure(s) used by
742 * both HC and RC. The main purpose is to make sure structures have the same
743 * size when built for different architectures.
744 *
745 * @param RCType The RC type.
746 */
747#define RCPTRTYPE(RCType) CTXTYPE(RCType, RTRCPTR, RTRCPTR)
748
749/** @def R3R0PTRTYPE
750 * Declare a pointer which is used in HC, is explicitly valid in ring 3 and 0,
751 * but appears in structure(s) used by both HC and GC. The main purpose is to
752 * make sure structures have the same size when built for different architectures.
753 *
754 * @param R3R0Type The R3R0 type.
755 * @remarks This used to be called HCPTRTYPE.
756 */
757#define R3R0PTRTYPE(R3R0Type) CTXTYPE(RTHCPTR, R3R0Type, R3R0Type)
758
759/** @def R3PTRTYPE
760 * Declare a pointer which is used in R3 but appears in structure(s) used by
761 * both HC and GC. The main purpose is to make sure structures have the same
762 * size when built for different architectures.
763 *
764 * @param R3Type The R3 type.
765 */
766#define R3PTRTYPE(R3Type) CTXTYPE(RTHCUINTPTR, R3Type, RTHCUINTPTR)
767
768/** @def R0PTRTYPE
769 * Declare a pointer which is used in R0 but appears in structure(s) used by
770 * both HC and GC. The main purpose is to make sure structures have the same
771 * size when built for different architectures.
772 *
773 * @param R0Type The R0 type.
774 */
775#define R0PTRTYPE(R0Type) CTXTYPE(RTHCUINTPTR, RTHCUINTPTR, R0Type)
776
777/** @def CTXSUFF
778 * Adds the suffix of the current context to the passed in
779 * identifier name. The suffix is HC or GC.
780 *
781 * This is macro should only be used in shared code to avoid a forest of ifdefs.
782 * @param var Identifier name.
783 * @deprecated Use CTX_SUFF. Do NOT use this for new code.
784 */
785/** @def OTHERCTXSUFF
786 * Adds the suffix of the other context to the passed in
787 * identifier name. The suffix is HC or GC.
788 *
789 * This is macro should only be used in shared code to avoid a forest of ifdefs.
790 * @param var Identifier name.
791 * @deprecated Use CTX_SUFF. Do NOT use this for new code.
792 */
793#ifdef IN_RC
794# define CTXSUFF(var) var##GC
795# define OTHERCTXSUFF(var) var##HC
796#else
797# define CTXSUFF(var) var##HC
798# define OTHERCTXSUFF(var) var##GC
799#endif
800
801/** @def CTXALLSUFF
802 * Adds the suffix of the current context to the passed in
803 * identifier name. The suffix is R3, R0 or GC.
804 *
805 * This is macro should only be used in shared code to avoid a forest of ifdefs.
806 * @param var Identifier name.
807 * @deprecated Use CTX_SUFF. Do NOT use this for new code.
808 */
809#ifdef IN_RC
810# define CTXALLSUFF(var) var##GC
811#elif defined(IN_RING0)
812# define CTXALLSUFF(var) var##R0
813#else
814# define CTXALLSUFF(var) var##R3
815#endif
816
817/** @def CTX_SUFF
818 * Adds the suffix of the current context to the passed in
819 * identifier name. The suffix is R3, R0 or RC.
820 *
821 * This is macro should only be used in shared code to avoid a forest of ifdefs.
822 * @param var Identifier name.
823 *
824 * @remark This will replace CTXALLSUFF and CTXSUFF before long.
825 */
826#ifdef IN_RC
827# define CTX_SUFF(var) var##RC
828#elif defined(IN_RING0)
829# define CTX_SUFF(var) var##R0
830#else
831# define CTX_SUFF(var) var##R3
832#endif
833
834/** @def CTX_SUFF_Z
835 * Adds the suffix of the current context to the passed in
836 * identifier name, combining RC and R0 into RZ.
837 * The suffix thus is R3 or RZ.
838 *
839 * This is macro should only be used in shared code to avoid a forest of ifdefs.
840 * @param var Identifier name.
841 *
842 * @remark This will replace CTXALLSUFF and CTXSUFF before long.
843 */
844#ifdef IN_RING3
845# define CTX_SUFF_Z(var) var##R3
846#else
847# define CTX_SUFF_Z(var) var##RZ
848#endif
849
850
851/** @def CTXMID
852 * Adds the current context as a middle name of an identifier name
853 * The middle name is HC or GC.
854 *
855 * This is macro should only be used in shared code to avoid a forest of ifdefs.
856 * @param first First name.
857 * @param last Surname.
858 */
859/** @def OTHERCTXMID
860 * Adds the other context as a middle name of an identifier name
861 * The middle name is HC or GC.
862 *
863 * This is macro should only be used in shared code to avoid a forest of ifdefs.
864 * @param first First name.
865 * @param last Surname.
866 * @deprecated use CTX_MID or CTX_MID_Z
867 */
868#ifdef IN_RC
869# define CTXMID(first, last) first##GC##last
870# define OTHERCTXMID(first, last) first##HC##last
871#else
872# define CTXMID(first, last) first##HC##last
873# define OTHERCTXMID(first, last) first##GC##last
874#endif
875
876/** @def CTXALLMID
877 * Adds the current context as a middle name of an identifier name.
878 * The middle name is R3, R0 or GC.
879 *
880 * This is macro should only be used in shared code to avoid a forest of ifdefs.
881 * @param first First name.
882 * @param last Surname.
883 * @deprecated use CTX_MID or CTX_MID_Z
884 */
885#ifdef IN_RC
886# define CTXALLMID(first, last) first##GC##last
887#elif defined(IN_RING0)
888# define CTXALLMID(first, last) first##R0##last
889#else
890# define CTXALLMID(first, last) first##R3##last
891#endif
892
893/** @def CTX_MID
894 * Adds the current context as a middle name of an identifier name.
895 * The middle name is R3, R0 or RC.
896 *
897 * This is macro should only be used in shared code to avoid a forest of ifdefs.
898 * @param first First name.
899 * @param last Surname.
900 */
901#ifdef IN_RC
902# define CTX_MID(first, last) first##RC##last
903#elif defined(IN_RING0)
904# define CTX_MID(first, last) first##R0##last
905#else
906# define CTX_MID(first, last) first##R3##last
907#endif
908
909/** @def CTX_MID_Z
910 * Adds the current context as a middle name of an identifier name, combining RC
911 * and R0 into RZ.
912 * The middle name thus is either R3 or RZ.
913 *
914 * This is macro should only be used in shared code to avoid a forest of ifdefs.
915 * @param first First name.
916 * @param last Surname.
917 */
918#ifdef IN_RING3
919# define CTX_MID_Z(first, last) first##R3##last
920#else
921# define CTX_MID_Z(first, last) first##RZ##last
922#endif
923
924
925/** @def R3STRING
926 * A macro which in GC and R0 will return a dummy string while in R3 it will return
927 * the parameter.
928 *
929 * This is typically used to wrap description strings in structures shared
930 * between R3, R0 and/or GC. The intention is to avoid the \#ifdef IN_RING3 mess.
931 *
932 * @param pR3String The R3 string. Only referenced in R3.
933 * @see R0STRING and GCSTRING
934 */
935#ifdef IN_RING3
936# define R3STRING(pR3String) (pR3String)
937#else
938# define R3STRING(pR3String) ("<R3_STRING>")
939#endif
940
941/** @def R0STRING
942 * A macro which in GC and R3 will return a dummy string while in R0 it will return
943 * the parameter.
944 *
945 * This is typically used to wrap description strings in structures shared
946 * between R3, R0 and/or GC. The intention is to avoid the \#ifdef IN_RING0 mess.
947 *
948 * @param pR0String The R0 string. Only referenced in R0.
949 * @see R3STRING and GCSTRING
950 */
951#ifdef IN_RING0
952# define R0STRING(pR0String) (pR0String)
953#else
954# define R0STRING(pR0String) ("<R0_STRING>")
955#endif
956
957/** @def RCSTRING
958 * A macro which in R3 and R0 will return a dummy string while in RC it will return
959 * the parameter.
960 *
961 * This is typically used to wrap description strings in structures shared
962 * between R3, R0 and/or RC. The intention is to avoid the \#ifdef IN_RC mess.
963 *
964 * @param pRCString The RC string. Only referenced in RC.
965 * @see R3STRING, R0STRING
966 */
967#ifdef IN_RC
968# define RCSTRING(pRCString) (pRCString)
969#else
970# define RCSTRING(pRCString) ("<RC_STRING>")
971#endif
972
973
974/** @def RT_NOTHING
975 * A macro that expands to nothing.
976 * This is primarily intended as a dummy argument for macros to avoid the
977 * undefined behavior passing empty arguments to an macro (ISO C90 and C++98,
978 * gcc v4.4 warns about it).
979 */
980#define RT_NOTHING
981
982/** @def RT_GCC_EXTENSION
983 * Macro for shutting up GCC warnings about using language extensions. */
984#ifdef __GNUC__
985# define RT_GCC_EXTENSION __extension__
986#else
987# define RT_GCC_EXTENSION
988#endif
989
990/** @def RT_GCC_NO_WARN_DEPRECATED_BEGIN
991 * Used to start a block of code where GCC should not warn about deprecated
992 * declarations. */
993#if RT_GNUC_PREREQ(4, 6)
994# define RT_GCC_NO_WARN_DEPRECATED_BEGIN \
995 _Pragma("GCC diagnostic push") \
996 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
997/** @def RT_GCC_NO_WARN_DEPRECATED_END
998 * Used to end a block of code where GCC should not warn about deprecated
999 * declarations. */
1000# define RT_GCC_NO_WARN_DEPRECATED_END \
1001 _Pragma("GCC diagnostic pop")
1002#else
1003# define RT_GCC_NO_WARN_DEPRECATED_BEGIN
1004# define RT_GCC_NO_WARN_DEPRECATED_END
1005#endif
1006
1007/** @def RT_GCC_NO_WARN_CONVERSION_BEGIN
1008 * Used to start a block of code where GCC should not warn about implicit
1009 * conversions that may alter a value. */
1010#if RT_GNUC_PREREQ(4, 6)
1011# define RT_GCC_NO_WARN_CONVERSION_BEGIN \
1012 _Pragma("GCC diagnostic push") \
1013 _Pragma("GCC diagnostic ignored \"-Wconversion\"")
1014/** @def RT_GCC_NO_WARN_CONVERSION_END
1015 * Used to end a block of code where GCC should not warn about implicit
1016 * conversions that may alter a value. */
1017# define RT_GCC_NO_WARN_CONVERSION_END \
1018 _Pragma("GCC diagnostic pop")
1019#else
1020# define RT_GCC_NO_WARN_CONVERSION_BEGIN
1021# define RT_GCC_NO_WARN_CONVERSION_END
1022#endif
1023
1024/** @def RT_COMPILER_GROKS_64BIT_BITFIELDS
1025 * Macro that is defined if the compiler understands 64-bit bitfields. */
1026#if !defined(RT_OS_OS2) || (!defined(__IBMC__) && !defined(__IBMCPP__))
1027# if !defined(__WATCOMC__) /* watcom compiler doesn't grok it either. */
1028# define RT_COMPILER_GROKS_64BIT_BITFIELDS
1029# endif
1030#endif
1031
1032/** @def RT_COMPILER_WITH_80BIT_LONG_DOUBLE
1033 * Macro that is defined if the compiler implements long double as the
1034 * IEEE extended precision floating. */
1035#if (defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)) && !defined(RT_OS_WINDOWS)
1036# define RT_COMPILER_WITH_80BIT_LONG_DOUBLE
1037#endif
1038
1039
1040/** @def RT_EXCEPTIONS_ENABLED
1041 * Defined when C++ exceptions are enabled.
1042 */
1043#if !defined(RT_EXCEPTIONS_ENABLED) \
1044 && defined(__cplusplus) \
1045 && ( (defined(_MSC_VER) && defined(_CPPUNWIND)) \
1046 || (defined(__GNUC__) && defined(__EXCEPTIONS)))
1047# define RT_EXCEPTIONS_ENABLED
1048#endif
1049
1050/** @def RT_NO_THROW_PROTO
1051 * How to express that a function doesn't throw C++ exceptions
1052 * and the compiler can thus save itself the bother of trying
1053 * to catch any of them. Put this between the closing parenthesis
1054 * and the semicolon in function prototypes (and implementation if C++).
1055 *
1056 * @remarks May not work on C++ methods, mainly intented for C-style APIs.
1057 *
1058 * @remarks The use of the nothrow attribute with GCC is because old compilers
1059 * (4.1.1, 32-bit) leaking the nothrow into global space or something
1060 * when used with RTDECL or similar. Using this forces use to have two
1061 * macros, as the nothrow attribute is not for the function definition.
1062 */
1063#ifdef RT_EXCEPTIONS_ENABLED
1064# ifdef __GNUC__
1065# if RT_GNUC_PREREQ(3, 3)
1066# define RT_NO_THROW_PROTO __attribute__((__nothrow__))
1067# else
1068# define RT_NO_THROW_PROTO
1069# endif
1070# else
1071# define RT_NO_THROW_PROTO throw()
1072# endif
1073#else
1074# define RT_NO_THROW_PROTO
1075#endif
1076
1077/** @def RT_NO_THROW_DEF
1078 * The counter part to RT_NO_THROW_PROTO that is added to the function
1079 * definition.
1080 */
1081#if defined(RT_EXCEPTIONS_ENABLED) && !defined(__GNUC__)
1082# define RT_NO_THROW_DEF RT_NO_THROW_PROTO
1083#else
1084# define RT_NO_THROW_DEF
1085#endif
1086
1087/** @def RT_THROW
1088 * How to express that a method or function throws a type of exceptions. Some
1089 * compilers does not want this kind of information and will warning about it.
1090 *
1091 * @param type The type exception.
1092 *
1093 * @remarks If the actual throwing is done from the header, enclose it by
1094 * \#ifdef RT_EXCEPTIONS_ENABLED ... \#else ... \#endif so the header
1095 * compiles cleanly without exceptions enabled.
1096 *
1097 * Do NOT use this for the actual throwing of exceptions!
1098 */
1099#ifdef RT_EXCEPTIONS_ENABLED
1100# if RT_MSC_PREREQ_EX(RT_MSC_VER_VC71, 0)
1101# define RT_THROW(type)
1102# elif RT_GNUC_PREREQ(7, 0)
1103# define RT_THROW(type)
1104# else
1105# define RT_THROW(type) throw(type)
1106# endif
1107#else
1108# define RT_THROW(type)
1109#endif
1110
1111
1112/** @def RT_OVERRIDE
1113 * Wrapper for the C++11 override keyword.
1114 *
1115 * @remarks Recognized by g++ starting 4.7, however causes pedantic warnings
1116 * when used without officially enabling the C++11 features.
1117 */
1118#ifdef __cplusplus
1119# if RT_MSC_PREREQ_EX(RT_MSC_VER_VS2012, 0)
1120# define RT_OVERRIDE override
1121# elif RT_GNUC_PREREQ(4, 7)
1122# if __cplusplus >= 201100
1123# define RT_OVERRIDE override
1124# else
1125# define RT_OVERRIDE
1126# endif
1127# else
1128# define RT_OVERRIDE
1129# endif
1130#else
1131# define RT_OVERRIDE
1132#endif
1133
1134/** @def RT_NOEXCEPT
1135 * Wrapper for the C++11 noexcept keyword (only true form).
1136 */
1137/** @def RT_NOEXCEPT_EX
1138 * Wrapper for the C++11 noexcept keyword with expression.
1139 */
1140#ifdef __cplusplus
1141# if RT_MSC_PREREQ_EX(RT_MSC_VER_VS2015, 0)
1142# define RT_NOEXCEPT noexcept
1143# define RT_NOEXCEPT_EX(expr) noexcept(expr)
1144# elif RT_GNUC_PREREQ(7, 0)
1145# if __cplusplus >= 201100
1146# define RT_NOEXCEPT noexcept
1147# define RT_NOEXCEPT_EX(expr) noexcept(expr)
1148# else
1149# define RT_NOEXCEPT
1150# define RT_NOEXCEPT_EX(expr)
1151# endif
1152# else
1153# define RT_NOEXCEPT
1154# define RT_NOEXCEPT_EX(expr)
1155# endif
1156#else
1157# define RT_NOEXCEPT
1158# define RT_NOEXCEPT_EX(expr)
1159#endif
1160
1161
1162/** @def RT_FALL_THROUGH
1163 * Tell the compiler that we're falling through to the next case in a switch.
1164 * @sa RT_FALL_THRU */
1165#if RT_GNUC_PREREQ(7, 0)
1166# define RT_FALL_THROUGH() __attribute__((fallthrough))
1167#else
1168# define RT_FALL_THROUGH() (void)0
1169#endif
1170/** @def RT_FALL_THRU
1171 * Tell the compiler that we're falling thru to the next case in a switch.
1172 * @sa RT_FALL_THROUGH */
1173#define RT_FALL_THRU() RT_FALL_THROUGH()
1174
1175
1176/** @def RT_IPRT_FORMAT_ATTR
1177 * Identifies a function taking an IPRT format string.
1178 * @param a_iFmt The index (1-based) of the format string argument.
1179 * @param a_iArgs The index (1-based) of the first format argument, use 0 for
1180 * va_list.
1181 */
1182#if defined(__GNUC__) && defined(WITH_IPRT_FORMAT_ATTRIBUTE)
1183# define RT_IPRT_FORMAT_ATTR(a_iFmt, a_iArgs) __attribute__((__iprt_format__(a_iFmt, a_iArgs)))
1184#else
1185# define RT_IPRT_FORMAT_ATTR(a_iFmt, a_iArgs)
1186#endif
1187
1188/** @def RT_IPRT_FORMAT_ATTR_MAYBE_NULL
1189 * Identifies a function taking an IPRT format string, NULL is allowed.
1190 * @param a_iFmt The index (1-based) of the format string argument.
1191 * @param a_iArgs The index (1-based) of the first format argument, use 0 for
1192 * va_list.
1193 */
1194#if defined(__GNUC__) && defined(WITH_IPRT_FORMAT_ATTRIBUTE)
1195# define RT_IPRT_FORMAT_ATTR_MAYBE_NULL(a_iFmt, a_iArgs) __attribute__((__iprt_format_maybe_null__(a_iFmt, a_iArgs)))
1196#else
1197# define RT_IPRT_FORMAT_ATTR_MAYBE_NULL(a_iFmt, a_iArgs)
1198#endif
1199
1200
1201/** @def RT_GCC_SUPPORTS_VISIBILITY_HIDDEN
1202 * Indicates that the "hidden" visibility attribute can be used (GCC) */
1203#if defined(__GNUC__)
1204# if __GNUC__ >= 4 && !defined(RT_OS_OS2) && !defined(RT_OS_WINDOWS)
1205# define RT_GCC_SUPPORTS_VISIBILITY_HIDDEN
1206# endif
1207#endif
1208
1209/** @def RT_COMPILER_SUPPORTS_VA_ARGS
1210 * If the defined, the compiler supports the variadic macro feature (..., __VA_ARGS__). */
1211#if defined(_MSC_VER)
1212# if _MSC_VER >= 1600 /* Visual C++ v10.0 / 2010 */
1213# define RT_COMPILER_SUPPORTS_VA_ARGS
1214# endif
1215#elif defined(__GNUC__)
1216# if __GNUC__ >= 3 /* not entirely sure when this was added */
1217# define RT_COMPILER_SUPPORTS_VA_ARGS
1218# endif
1219#endif
1220
1221
1222
1223/** @def RTCALL
1224 * The standard calling convention for the Runtime interfaces.
1225 *
1226 * @remarks The regparm(0) in the X86/GNUC variant deals with -mregparm=x use in
1227 * the linux kernel and potentially elsewhere (3rd party).
1228 */
1229#if defined(_MSC_VER) || defined(__WATCOMC__)
1230# define RTCALL __cdecl
1231#elif defined(RT_OS_OS2)
1232# define RTCALL __cdecl
1233#elif defined(__GNUC__) && defined(RT_ARCH_X86)
1234# define RTCALL __attribute__((__cdecl__,__regparm__(0)))
1235#else
1236# define RTCALL
1237#endif
1238
1239/** @def DECLEXPORT
1240 * How to declare an exported function.
1241 * @param type The return type of the function declaration.
1242 */
1243#if defined(_MSC_VER) || defined(RT_OS_OS2)
1244# define DECLEXPORT(type) __declspec(dllexport) type
1245#elif defined(RT_USE_VISIBILITY_DEFAULT)
1246# define DECLEXPORT(type) __attribute__((visibility("default"))) type
1247#else
1248# define DECLEXPORT(type) type
1249#endif
1250
1251/** @def DECLIMPORT
1252 * How to declare an imported function.
1253 * @param type The return type of the function declaration.
1254 */
1255#if defined(_MSC_VER) || (defined(RT_OS_OS2) && !defined(__IBMC__) && !defined(__IBMCPP__))
1256# define DECLIMPORT(type) __declspec(dllimport) type
1257#else
1258# define DECLIMPORT(type) type
1259#endif
1260
1261/** @def DECLHIDDEN
1262 * How to declare a non-exported function or variable.
1263 * @param type The return type of the function or the data type of the variable.
1264 */
1265#if !defined(RT_GCC_SUPPORTS_VISIBILITY_HIDDEN) || defined(RT_NO_VISIBILITY_HIDDEN)
1266# define DECLHIDDEN(type) type
1267#else
1268# define DECLHIDDEN(type) __attribute__((visibility("hidden"))) type
1269#endif
1270
1271/** @def DECL_HIDDEN_CONST
1272 * Workaround for g++ warnings when applying the hidden attribute to a const
1273 * definition. Use DECLHIDDEN for the declaration.
1274 * @param a_Type The return type of the function or the data type of
1275 * the variable.
1276 */
1277#if defined(__cplusplus) && defined(__GNUC__)
1278# define DECL_HIDDEN_CONST(a_Type) a_Type
1279#else
1280# define DECL_HIDDEN_CONST(a_Type) DECLHIDDEN(a_Type)
1281#endif
1282
1283/** @def DECL_INVALID
1284 * How to declare a function not available for linking in the current context.
1285 * The purpose is to create compile or like time errors when used. This isn't
1286 * possible on all platforms.
1287 * @param type The return type of the function.
1288 */
1289#if defined(_MSC_VER)
1290# define DECL_INVALID(type) __declspec(dllimport) type __stdcall
1291#elif defined(__GNUC__) && defined(__cplusplus)
1292# define DECL_INVALID(type) extern "C++" type
1293#else
1294# define DECL_INVALID(type) type
1295#endif
1296
1297/** @def DECLASM
1298 * How to declare an internal assembly function.
1299 * @param type The return type of the function declaration.
1300 */
1301#ifdef __cplusplus
1302# define DECLASM(type) extern "C" type RTCALL
1303#else
1304# define DECLASM(type) type RTCALL
1305#endif
1306
1307/** @def DECLASMTYPE
1308 * How to declare an internal assembly function type.
1309 * @param type The return type of the function.
1310 */
1311#define DECLASMTYPE(type) type RTCALL
1312
1313/** @def DECL_NO_RETURN
1314 * How to declare a function which does not return.
1315 * @note This macro can be combined with other macros, for example
1316 * @code
1317 * EMR3DECL(DECL_NO_RETURN(void)) foo(void);
1318 * @endcode
1319 */
1320#ifdef _MSC_VER
1321# define DECL_NO_RETURN(type) __declspec(noreturn) type
1322#elif defined(__GNUC__)
1323# define DECL_NO_RETURN(type) __attribute__((noreturn)) type
1324#else
1325# define DECL_NO_RETURN(type) type
1326#endif
1327/** @deprecated Use DECL_NO_RETURN instead. */
1328#define DECLNORETURN(type) DECL_NO_RETURN(type)
1329
1330/** @def DECL_RETURNS_TWICE
1331 * How to declare a function which may return more than once.
1332 * @note This macro can be combined with other macros, for example
1333 * @code
1334 * EMR3DECL(DECL_RETURNS_TWICE(void)) MySetJmp(void);
1335 * @endcode
1336 */
1337#if RT_GNUC_PREREQ(4, 1)
1338# define DECL_RETURNS_TWICE(type) __attribute__((returns_twice)) type
1339# else
1340# define DECL_RETURNS_TWICE(type) type
1341#endif
1342
1343/** @def DECLWEAK
1344 * How to declare a variable which is not necessarily resolved at
1345 * runtime.
1346 * @note This macro can be combined with other macros, for example
1347 * @code
1348 * EMR3DECL(DECLWEAK(int)) foo;
1349 * @endcode
1350 */
1351#if defined(__GNUC__)
1352# define DECLWEAK(type) type __attribute__((weak))
1353#else
1354# define DECLWEAK(type) type
1355#endif
1356
1357/** @def DECLCALLBACK
1358 * How to declare an call back function type.
1359 * @param type The return type of the function declaration.
1360 */
1361#define DECLCALLBACK(type) type RT_FAR_CODE RTCALL
1362
1363/** @def DECLCALLBACKPTR
1364 * How to declare an call back function pointer.
1365 * @param type The return type of the function declaration.
1366 * @param name The name of the variable member.
1367 */
1368#if defined(__IBMC__) || defined(__IBMCPP__)
1369# define DECLCALLBACKPTR(type, name) type (* RTCALL name)
1370#else
1371# define DECLCALLBACKPTR(type, name) type (RT_FAR_CODE RTCALL * name)
1372#endif
1373
1374/** @def DECLCALLBACKMEMBER
1375 * How to declare an call back function pointer member.
1376 * @param type The return type of the function declaration.
1377 * @param name The name of the struct/union/class member.
1378 */
1379#if defined(__IBMC__) || defined(__IBMCPP__)
1380# define DECLCALLBACKMEMBER(type, name) type (* RTCALL name)
1381#else
1382# define DECLCALLBACKMEMBER(type, name) type (RT_FAR_CODE RTCALL * name)
1383#endif
1384
1385/** @def DECLR3CALLBACKMEMBER
1386 * How to declare an call back function pointer member - R3 Ptr.
1387 * @param type The return type of the function declaration.
1388 * @param name The name of the struct/union/class member.
1389 * @param args The argument list enclosed in parentheses.
1390 */
1391#ifdef IN_RING3
1392# define DECLR3CALLBACKMEMBER(type, name, args) DECLCALLBACKMEMBER(type, name) args
1393#else
1394# define DECLR3CALLBACKMEMBER(type, name, args) RTR3PTR name
1395#endif
1396
1397/** @def DECLRCCALLBACKMEMBER
1398 * How to declare an call back function pointer member - RC Ptr.
1399 * @param type The return type of the function declaration.
1400 * @param name The name of the struct/union/class member.
1401 * @param args The argument list enclosed in parentheses.
1402 */
1403#ifdef IN_RC
1404# define DECLRCCALLBACKMEMBER(type, name, args) DECLCALLBACKMEMBER(type, name) args
1405#else
1406# define DECLRCCALLBACKMEMBER(type, name, args) RTRCPTR name
1407#endif
1408
1409/** @def DECLR0CALLBACKMEMBER
1410 * How to declare an call back function pointer member - R0 Ptr.
1411 * @param type The return type of the function declaration.
1412 * @param name The name of the struct/union/class member.
1413 * @param args The argument list enclosed in parentheses.
1414 */
1415#ifdef IN_RING0
1416# define DECLR0CALLBACKMEMBER(type, name, args) DECLCALLBACKMEMBER(type, name) args
1417#else
1418# define DECLR0CALLBACKMEMBER(type, name, args) RTR0PTR name
1419#endif
1420
1421/** @def DECLINLINE
1422 * How to declare a function as inline.
1423 * @param type The return type of the function declaration.
1424 * @remarks Don't use this macro on C++ methods.
1425 */
1426#ifdef __GNUC__
1427# define DECLINLINE(type) static __inline__ type
1428#elif defined(__cplusplus)
1429# define DECLINLINE(type) static inline type
1430#elif defined(_MSC_VER)
1431# define DECLINLINE(type) static _inline type
1432#elif defined(__IBMC__)
1433# define DECLINLINE(type) _Inline type
1434#else
1435# define DECLINLINE(type) inline type
1436#endif
1437
1438
1439/** @def DECL_FORCE_INLINE
1440 * How to declare a function as inline and try convince the compiler to always
1441 * inline it regardless of optimization switches.
1442 * @param type The return type of the function declaration.
1443 * @remarks Use sparsely and with care. Don't use this macro on C++ methods.
1444 */
1445#ifdef __GNUC__
1446# define DECL_FORCE_INLINE(type) __attribute__((__always_inline__)) DECLINLINE(type)
1447#elif defined(_MSC_VER)
1448# define DECL_FORCE_INLINE(type) __forceinline type
1449#else
1450# define DECL_FORCE_INLINE(type) DECLINLINE(type)
1451#endif
1452
1453
1454/** @def DECL_NO_INLINE
1455 * How to declare a function telling the compiler not to inline it.
1456 * @param scope The function scope, static or RT_NOTHING.
1457 * @param type The return type of the function declaration.
1458 * @remarks Don't use this macro on C++ methods.
1459 */
1460#ifdef __GNUC__
1461# define DECL_NO_INLINE(scope,type) __attribute__((__noinline__)) scope type
1462#elif defined(_MSC_VER)
1463# define DECL_NO_INLINE(scope,type) __declspec(noinline) scope type
1464#else
1465# define DECL_NO_INLINE(scope,type) scope type
1466#endif
1467
1468
1469/** @def IN_RT_STATIC
1470 * Used to indicate whether we're linking against a static IPRT
1471 * or not.
1472 *
1473 * The IPRT symbols will be declared as hidden (if supported). Note that this
1474 * define has no effect without also setting one of the IN_RT_R0, IN_RT_R3 or
1475 * IN_RT_RC indicators.
1476 */
1477
1478/** @def IN_RT_R0
1479 * Used to indicate whether we're inside the same link module as the host
1480 * context ring-0 Runtime Library.
1481 */
1482/** @def RTR0DECL(type)
1483 * Runtime Library host context ring-0 export or import declaration.
1484 * @param type The return type of the function declaration.
1485 * @remarks This is only used inside IPRT. Other APIs need to define their own
1486 * XXXX_DECL macros for dealing with import/export/static visibility.
1487 */
1488#ifdef IN_RT_R0
1489# ifdef IN_RT_STATIC
1490# define RTR0DECL(type) DECLHIDDEN(type) RTCALL
1491# else
1492# define RTR0DECL(type) DECLEXPORT(type) RTCALL
1493# endif
1494#else
1495# define RTR0DECL(type) DECLIMPORT(type) RTCALL
1496#endif
1497
1498/** @def IN_RT_R3
1499 * Used to indicate whether we're inside the same link module as the host
1500 * context ring-3 Runtime Library.
1501 */
1502/** @def RTR3DECL(type)
1503 * Runtime Library host context ring-3 export or import declaration.
1504 * @param type The return type of the function declaration.
1505 * @remarks This is only used inside IPRT. Other APIs need to define their own
1506 * XXXX_DECL macros for dealing with import/export/static visibility.
1507 */
1508#ifdef IN_RT_R3
1509# ifdef IN_RT_STATIC
1510# define RTR3DECL(type) DECLHIDDEN(type) RTCALL
1511# else
1512# define RTR3DECL(type) DECLEXPORT(type) RTCALL
1513# endif
1514#else
1515# define RTR3DECL(type) DECLIMPORT(type) RTCALL
1516#endif
1517
1518/** @def IN_RT_RC
1519 * Used to indicate whether we're inside the same link module as the raw-mode
1520 * context (RC) runtime library.
1521 */
1522/** @def RTRCDECL(type)
1523 * Runtime Library raw-mode context export or import declaration.
1524 * @param type The return type of the function declaration.
1525 * @remarks This is only used inside IPRT. Other APIs need to define their own
1526 * XXXX_DECL macros for dealing with import/export/static visibility.
1527 */
1528#ifdef IN_RT_RC
1529# ifdef IN_RT_STATIC
1530# define RTRCDECL(type) DECLHIDDEN(type) RTCALL
1531# else
1532# define RTRCDECL(type) DECLEXPORT(type) RTCALL
1533# endif
1534#else
1535# define RTRCDECL(type) DECLIMPORT(type) RTCALL
1536#endif
1537
1538/** @def RTDECL(type)
1539 * Runtime Library export or import declaration.
1540 * Functions declared using this macro exists in all contexts.
1541 * @param type The return type of the function declaration.
1542 * @remarks This is only used inside IPRT. Other APIs need to define their own
1543 * XXXX_DECL macros for dealing with import/export/static visibility.
1544 */
1545#if defined(IN_RT_R3) || defined(IN_RT_RC) || defined(IN_RT_R0)
1546# ifdef IN_RT_STATIC
1547# define RTDECL(type) DECLHIDDEN(type) RTCALL
1548# else
1549# define RTDECL(type) DECLEXPORT(type) RTCALL
1550# endif
1551#else
1552# define RTDECL(type) DECLIMPORT(type) RTCALL
1553#endif
1554
1555/** @def RTDATADECL(type)
1556 * Runtime Library export or import declaration.
1557 * Data declared using this macro exists in all contexts.
1558 * @param type The data type.
1559 * @remarks This is only used inside IPRT. Other APIs need to define their own
1560 * XXXX_DECL macros for dealing with import/export/static visibility.
1561 */
1562/** @def RT_DECL_DATA_CONST(type)
1563 * Definition of a const variable. See DECL_HIDDEN_CONST.
1564 * @param type The const data type.
1565 * @remarks This is only used inside IPRT. Other APIs need to define their own
1566 * XXXX_DECL macros for dealing with import/export/static visibility.
1567 */
1568#if defined(IN_RT_R3) || defined(IN_RT_RC) || defined(IN_RT_R0)
1569# ifdef IN_RT_STATIC
1570# define RTDATADECL(type) DECLHIDDEN(type)
1571# define RT_DECL_DATA_CONST(type) DECL_HIDDEN_CONST(type)
1572# else
1573# define RTDATADECL(type) DECLEXPORT(type)
1574# if defined(__cplusplus) && defined(__GNUC__)
1575# define RT_DECL_DATA_CONST(type) type
1576# else
1577# define RT_DECL_DATA_CONST(type) DECLEXPORT(type)
1578# endif
1579# endif
1580#else
1581# define RTDATADECL(type) DECLIMPORT(type)
1582# define RT_DECL_DATA_CONST(type) DECLIMPORT(type)
1583#endif
1584
1585/** @def RT_DECL_CLASS
1586 * Declares an class living in the runtime.
1587 * @remarks This is only used inside IPRT. Other APIs need to define their own
1588 * XXXX_DECL macros for dealing with import/export/static visibility.
1589 */
1590#if defined(IN_RT_R3) || defined(IN_RT_RC) || defined(IN_RT_R0)
1591# ifdef IN_RT_STATIC
1592# define RT_DECL_CLASS
1593# else
1594# define RT_DECL_CLASS DECLEXPORT_CLASS
1595# endif
1596#else
1597# define RT_DECL_CLASS DECLIMPORT_CLASS
1598#endif
1599
1600
1601/** @def RT_NOCRT
1602 * Symbol name wrapper for the No-CRT bits.
1603 *
1604 * In order to coexist in the same process as other CRTs, we need to
1605 * decorate the symbols such that they don't conflict the ones in the
1606 * other CRTs. The result of such conflicts / duplicate symbols can
1607 * confuse the dynamic loader on Unix like systems.
1608 *
1609 * Define RT_WITHOUT_NOCRT_WRAPPERS to drop the wrapping.
1610 * Define RT_WITHOUT_NOCRT_WRAPPER_ALIASES to drop the aliases to the
1611 * wrapped names.
1612 */
1613/** @def RT_NOCRT_STR
1614 * Same as RT_NOCRT only it'll return a double quoted string of the result.
1615 */
1616#ifndef RT_WITHOUT_NOCRT_WRAPPERS
1617# define RT_NOCRT(name) nocrt_ ## name
1618# define RT_NOCRT_STR(name) "nocrt_" # name
1619#else
1620# define RT_NOCRT(name) name
1621# define RT_NOCRT_STR(name) #name
1622#endif
1623
1624
1625/** @name Untrusted data classifications.
1626 * @{ */
1627/** @def RT_UNTRUSTED_USER
1628 * For marking non-volatile (race free) data from user mode as untrusted.
1629 * This is just for visible documentation. */
1630#define RT_UNTRUSTED_USER
1631/** @def RT_UNTRUSTED_VOLATILE_USER
1632 * For marking volatile data shared with user mode as untrusted.
1633 * This is more than just documentation as it specifies the 'volatile' keyword,
1634 * because the guest could modify the data at any time. */
1635#define RT_UNTRUSTED_VOLATILE_USER volatile
1636
1637/** @def RT_UNTRUSTED_GUEST
1638 * For marking non-volatile (race free) data from the guest as untrusted.
1639 * This is just for visible documentation. */
1640#define RT_UNTRUSTED_GUEST
1641/** @def RT_UNTRUSTED_VOLATILE_GUEST
1642 * For marking volatile data shared with the guest as untrusted.
1643 * This is more than just documentation as it specifies the 'volatile' keyword,
1644 * because the guest could modify the data at any time. */
1645#define RT_UNTRUSTED_VOLATILE_GUEST volatile
1646
1647/** @def RT_UNTRUSTED_HOST
1648 * For marking non-volatile (race free) data from the host as untrusted.
1649 * This is just for visible documentation. */
1650#define RT_UNTRUSTED_HOST
1651/** @def RT_UNTRUSTED_VOLATILE_HOST
1652 * For marking volatile data shared with the host as untrusted.
1653 * This is more than just documentation as it specifies the 'volatile' keyword,
1654 * because the host could modify the data at any time. */
1655#define RT_UNTRUSTED_VOLATILE_HOST volatile
1656
1657/** @def RT_UNTRUSTED_HSTGST
1658 * For marking non-volatile (race free) data from the host/gust as untrusted.
1659 * This is just for visible documentation. */
1660#define RT_UNTRUSTED_HSTGST
1661/** @def RT_UNTRUSTED_VOLATILE_HSTGST
1662 * For marking volatile data shared with the host/guest as untrusted.
1663 * This is more than just documentation as it specifies the 'volatile' keyword,
1664 * because the host could modify the data at any time. */
1665#define RT_UNTRUSTED_VOLATILE_HSTGST volatile
1666/** @} */
1667
1668/** @name Fences for use when handling untrusted data.
1669 * @{ */
1670/** For use after copying untruated volatile data to a non-volatile location.
1671 * This translates to a compiler memory barrier and will help ensure that the
1672 * compiler uses the non-volatile copy of the data. */
1673#define RT_UNTRUSTED_NONVOLATILE_COPY_FENCE() ASMCompilerBarrier()
1674/** For use after finished validating guest input.
1675 * What this translates to is architecture dependent. On intel it will
1676 * translate to a CPU load+store fence as well as a compiler memory barrier. */
1677#if defined(RT_ARCH_AMD64) || (defined(RT_ARCH_X86) && !defined(RT_WITH_OLD_CPU_SUPPORT))
1678# define RT_UNTRUSTED_VALIDATED_FENCE() do { ASMCompilerBarrier(); ASMReadFence(); } while (0)
1679#elif defined(RT_ARCH_X86)
1680# define RT_UNTRUSTED_VALIDATED_FENCE() do { ASMCompilerBarrier(); ASMMemoryFence(); } while (0)
1681#else
1682# define RT_UNTRUSTED_VALIDATED_FENCE() do { ASMCompilerBarrier(); } while (0)
1683#endif
1684/** @} */
1685
1686
1687/** @def RT_LIKELY
1688 * Give the compiler a hint that an expression is very likely to hold true.
1689 *
1690 * Some compilers support explicit branch prediction so that the CPU backend
1691 * can hint the processor and also so that code blocks can be reordered such
1692 * that the predicted path sees a more linear flow, thus improving cache
1693 * behaviour, etc.
1694 *
1695 * IPRT provides the macros RT_LIKELY() and RT_UNLIKELY() as a way to utilize
1696 * this compiler feature when present.
1697 *
1698 * A few notes about the usage:
1699 *
1700 * - Generally, order your code use RT_LIKELY() instead of RT_UNLIKELY().
1701 *
1702 * - Generally, use RT_UNLIKELY() with error condition checks (unless you
1703 * have some _strong_ reason to do otherwise, in which case document it),
1704 * and/or RT_LIKELY() with success condition checks, assuming you want
1705 * to optimize for the success path.
1706 *
1707 * - Other than that, if you don't know the likelihood of a test succeeding
1708 * from empirical or other 'hard' evidence, don't make predictions unless
1709 * you happen to be a Dirk Gently character.
1710 *
1711 * - These macros are meant to be used in places that get executed a lot. It
1712 * is wasteful to make predictions in code that is executed rarely (e.g.
1713 * at subsystem initialization time) as the basic block reordering that this
1714 * affects can often generate larger code.
1715 *
1716 * - Note that RT_SUCCESS() and RT_FAILURE() already makes use of RT_LIKELY()
1717 * and RT_UNLIKELY(). Should you wish for prediction free status checks,
1718 * use the RT_SUCCESS_NP() and RT_FAILURE_NP() macros instead.
1719 *
1720 *
1721 * @returns the boolean result of the expression.
1722 * @param expr The expression that's very likely to be true.
1723 * @see RT_UNLIKELY
1724 */
1725/** @def RT_UNLIKELY
1726 * Give the compiler a hint that an expression is highly unlikely to hold true.
1727 *
1728 * See the usage instructions give in the RT_LIKELY() docs.
1729 *
1730 * @returns the boolean result of the expression.
1731 * @param expr The expression that's very unlikely to be true.
1732 * @see RT_LIKELY
1733 *
1734 * @deprecated Please use RT_LIKELY() instead wherever possible! That gives us
1735 * a better chance of the windows compilers to generate favorable code
1736 * too. The belief is that the compiler will by default assume the
1737 * if-case is more likely than the else-case.
1738 */
1739#if defined(__GNUC__)
1740# if __GNUC__ >= 3 && !defined(FORTIFY_RUNNING)
1741# define RT_LIKELY(expr) __builtin_expect(!!(expr), 1)
1742# define RT_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
1743# else
1744# define RT_LIKELY(expr) (expr)
1745# define RT_UNLIKELY(expr) (expr)
1746# endif
1747#else
1748# define RT_LIKELY(expr) (expr)
1749# define RT_UNLIKELY(expr) (expr)
1750#endif
1751
1752/** @def RT_EXPAND_2
1753 * Helper for RT_EXPAND. */
1754#define RT_EXPAND_2(a_Expr) a_Expr
1755/** @def RT_EXPAND
1756 * Returns the expanded expression.
1757 * @param a_Expr The expression to expand. */
1758#define RT_EXPAND(a_Expr) RT_EXPAND_2(a_Expr)
1759
1760/** @def RT_STR
1761 * Returns the argument as a string constant.
1762 * @param str Argument to stringify. */
1763#define RT_STR(str) #str
1764/** @def RT_XSTR
1765 * Returns the expanded argument as a string.
1766 * @param str Argument to expand and stringify. */
1767#define RT_XSTR(str) RT_STR(str)
1768
1769/** @def RT_LSTR_2
1770 * Helper for RT_WSTR that gets the expanded @a str.
1771 * @param str String litteral to prefix with 'L'. */
1772#define RT_LSTR_2(str) L##str
1773/** @def RT_LSTR
1774 * Returns the expanded argument with a L string prefix.
1775 *
1776 * Intended for converting ASCII string \#defines into wide char string
1777 * litterals on Windows.
1778 *
1779 * @param str String litteral to . */
1780#define RT_LSTR(str) RT_LSTR_2(str)
1781
1782/** @def RT_UNPACK_CALL
1783 * Unpacks the an argument list inside an extra set of parenthesis and turns it
1784 * into a call to @a a_Fn.
1785 *
1786 * @param a_Fn Function/macro to call.
1787 * @param a_Args Parameter list in parenthesis.
1788 */
1789#define RT_UNPACK_CALL(a_Fn, a_Args) a_Fn a_Args
1790
1791#if defined(RT_COMPILER_SUPPORTS_VA_ARGS) || defined(DOXYGEN_RUNNING)
1792
1793/** @def RT_UNPACK_ARGS
1794 * Returns the arguments without parenthesis.
1795 *
1796 * @param ... Parameter list in parenthesis.
1797 * @remarks Requires RT_COMPILER_SUPPORTS_VA_ARGS.
1798 */
1799# define RT_UNPACK_ARGS(...) __VA_ARGS__
1800
1801/** @def RT_COUNT_VA_ARGS_HLP
1802 * Helper for RT_COUNT_VA_ARGS that picks out the argument count from
1803 * RT_COUNT_VA_ARGS_REV_SEQ. */
1804# define RT_COUNT_VA_ARGS_HLP( \
1805 c69, c68, c67, c66, c65, c64, c63, c62, c61, c60, \
1806 c59, c58, c57, c56, c55, c54, c53, c52, c51, c50, \
1807 c49, c48, c47, c46, c45, c44, c43, c42, c41, c40, \
1808 c39, c38, c37, c36, c35, c34, c33, c32, c31, c30, \
1809 c29, c28, c27, c26, c25, c24, c23, c22, c21, c20, \
1810 c19, c18, c17, c16, c15, c14, c13, c12, c11, c10, \
1811 c9, c8, c7, c6, c5, c4, c3, c2, c1, cArgs, ...) cArgs
1812/** Argument count sequence. */
1813# define RT_COUNT_VA_ARGS_REV_SEQ \
1814 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, \
1815 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, \
1816 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, \
1817 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, \
1818 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, \
1819 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, \
1820 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
1821/** This is for zero arguments. At least Visual C++ requires it. */
1822# define RT_COUNT_VA_ARGS_PREFIX_RT_NOTHING RT_COUNT_VA_ARGS_REV_SEQ
1823/**
1824 * Counts the number of arguments given to the variadic macro.
1825 *
1826 * Max is 69.
1827 *
1828 * @returns Number of arguments in the ellipsis
1829 * @param ... Arguments to count.
1830 * @remarks Requires RT_COMPILER_SUPPORTS_VA_ARGS.
1831 */
1832# define RT_COUNT_VA_ARGS(...) \
1833 RT_UNPACK_CALL(RT_COUNT_VA_ARGS_HLP, (RT_COUNT_VA_ARGS_PREFIX_ ## __VA_ARGS__ ## RT_NOTHING, \
1834 RT_COUNT_VA_ARGS_REV_SEQ))
1835
1836#endif /* RT_COMPILER_SUPPORTS_VA_ARGS */
1837
1838
1839/** @def RT_CONCAT
1840 * Concatenate the expanded arguments without any extra spaces in between.
1841 *
1842 * @param a The first part.
1843 * @param b The second part.
1844 */
1845#define RT_CONCAT(a,b) RT_CONCAT_HLP(a,b)
1846/** RT_CONCAT helper, don't use. */
1847#define RT_CONCAT_HLP(a,b) a##b
1848
1849/** @def RT_CONCAT3
1850 * Concatenate the expanded arguments without any extra spaces in between.
1851 *
1852 * @param a The 1st part.
1853 * @param b The 2nd part.
1854 * @param c The 3rd part.
1855 */
1856#define RT_CONCAT3(a,b,c) RT_CONCAT3_HLP(a,b,c)
1857/** RT_CONCAT3 helper, don't use. */
1858#define RT_CONCAT3_HLP(a,b,c) a##b##c
1859
1860/** @def RT_CONCAT4
1861 * Concatenate the expanded arguments without any extra spaces in between.
1862 *
1863 * @param a The 1st part.
1864 * @param b The 2nd part.
1865 * @param c The 3rd part.
1866 * @param d The 4th part.
1867 */
1868#define RT_CONCAT4(a,b,c,d) RT_CONCAT4_HLP(a,b,c,d)
1869/** RT_CONCAT4 helper, don't use. */
1870#define RT_CONCAT4_HLP(a,b,c,d) a##b##c##d
1871
1872/** @def RT_CONCAT5
1873 * Concatenate the expanded arguments without any extra spaces in between.
1874 *
1875 * @param a The 1st part.
1876 * @param b The 2nd part.
1877 * @param c The 3rd part.
1878 * @param d The 4th part.
1879 * @param e The 5th part.
1880 */
1881#define RT_CONCAT5(a,b,c,d,e) RT_CONCAT5_HLP(a,b,c,d,e)
1882/** RT_CONCAT5 helper, don't use. */
1883#define RT_CONCAT5_HLP(a,b,c,d,e) a##b##c##d##e
1884
1885/** @def RT_CONCAT6
1886 * Concatenate the expanded arguments without any extra spaces in between.
1887 *
1888 * @param a The 1st part.
1889 * @param b The 2nd part.
1890 * @param c The 3rd part.
1891 * @param d The 4th part.
1892 * @param e The 5th part.
1893 * @param f The 6th part.
1894 */
1895#define RT_CONCAT6(a,b,c,d,e,f) RT_CONCAT6_HLP(a,b,c,d,e,f)
1896/** RT_CONCAT6 helper, don't use. */
1897#define RT_CONCAT6_HLP(a,b,c,d,e,f) a##b##c##d##e##f
1898
1899/** @def RT_CONCAT7
1900 * Concatenate the expanded arguments without any extra spaces in between.
1901 *
1902 * @param a The 1st part.
1903 * @param b The 2nd part.
1904 * @param c The 3rd part.
1905 * @param d The 4th part.
1906 * @param e The 5th part.
1907 * @param f The 6th part.
1908 * @param g The 7th part.
1909 */
1910#define RT_CONCAT7(a,b,c,d,e,f,g) RT_CONCAT7_HLP(a,b,c,d,e,f,g)
1911/** RT_CONCAT7 helper, don't use. */
1912#define RT_CONCAT7_HLP(a,b,c,d,e,f,g) a##b##c##d##e##f##g
1913
1914/** @def RT_CONCAT8
1915 * Concatenate the expanded arguments without any extra spaces in between.
1916 *
1917 * @param a The 1st part.
1918 * @param b The 2nd part.
1919 * @param c The 3rd part.
1920 * @param d The 4th part.
1921 * @param e The 5th part.
1922 * @param f The 6th part.
1923 * @param g The 7th part.
1924 * @param h The 8th part.
1925 */
1926#define RT_CONCAT8(a,b,c,d,e,f,g,h) RT_CONCAT8_HLP(a,b,c,d,e,f,g,h)
1927/** RT_CONCAT8 helper, don't use. */
1928#define RT_CONCAT8_HLP(a,b,c,d,e,f,g,h) a##b##c##d##e##f##g##h
1929
1930/** @def RT_CONCAT9
1931 * Concatenate the expanded arguments without any extra spaces in between.
1932 *
1933 * @param a The 1st part.
1934 * @param b The 2nd part.
1935 * @param c The 3rd part.
1936 * @param d The 4th part.
1937 * @param e The 5th part.
1938 * @param f The 6th part.
1939 * @param g The 7th part.
1940 * @param h The 8th part.
1941 * @param i The 9th part.
1942 */
1943#define RT_CONCAT9(a,b,c,d,e,f,g,h,i) RT_CONCAT9_HLP(a,b,c,d,e,f,g,h,i)
1944/** RT_CONCAT9 helper, don't use. */
1945#define RT_CONCAT9_HLP(a,b,c,d,e,f,g,h,i) a##b##c##d##e##f##g##h##i
1946
1947/**
1948 * String constant tuple - string constant, strlen(string constant).
1949 *
1950 * @param a_szConst String constant.
1951 * @sa RTSTRTUPLE
1952 */
1953#define RT_STR_TUPLE(a_szConst) a_szConst, (sizeof(a_szConst) - 1)
1954
1955
1956/**
1957 * Macro for using in switch statements that turns constants into strings.
1958 *
1959 * @param a_Const The constant (not string).
1960 */
1961#define RT_CASE_RET_STR(a_Const) case a_Const: return #a_Const
1962
1963
1964/** @def RT_BIT
1965 * Convert a bit number into an integer bitmask (unsigned).
1966 * @param bit The bit number.
1967 */
1968#define RT_BIT(bit) ( 1U << (bit) )
1969
1970/** @def RT_BIT_32
1971 * Convert a bit number into a 32-bit bitmask (unsigned).
1972 * @param bit The bit number.
1973 */
1974#define RT_BIT_32(bit) ( UINT32_C(1) << (bit) )
1975
1976/** @def RT_BIT_64
1977 * Convert a bit number into a 64-bit bitmask (unsigned).
1978 * @param bit The bit number.
1979 */
1980#define RT_BIT_64(bit) ( UINT64_C(1) << (bit) )
1981
1982
1983/** @def RT_BF_GET
1984 * Gets the value of a bit field in an integer value.
1985 *
1986 * This requires a couple of macros to be defined for the field:
1987 * - \<a_FieldNm\>_SHIFT: The shift count to get to the field.
1988 * - \<a_FieldNm\>_MASK: The field mask.
1989 *
1990 * @returns The bit field value.
1991 * @param a_uValue The integer value containing the field.
1992 * @param a_FieldNm The field name prefix for getting at the _SHIFT and
1993 * _MASK macros.
1994 * @sa #RT_BF_CLEAR, #RT_BF_SET, #RT_BF_MAKE, #RT_BF_ZMASK
1995 */
1996#define RT_BF_GET(a_uValue, a_FieldNm) ( ((a_uValue) >> RT_CONCAT(a_FieldNm,_SHIFT)) & RT_BF_ZMASK(a_FieldNm) )
1997
1998/** @def RT_BF_SET
1999 * Sets the given bit field in the integer value.
2000 *
2001 * This requires a couple of macros to be defined for the field:
2002 * - \<a_FieldNm\>_SHIFT: The shift count to get to the field.
2003 * - \<a_FieldNm\>_MASK: The field mask. Must have the same type as the
2004 * integer value!!
2005 *
2006 * @returns Integer value with bit field set to @a a_uFieldValue.
2007 * @param a_uValue The integer value containing the field.
2008 * @param a_FieldNm The field name prefix for getting at the _SHIFT and
2009 * _MASK macros.
2010 * @param a_uFieldValue The new field value.
2011 * @sa #RT_BF_GET, #RT_BF_CLEAR, #RT_BF_MAKE, #RT_BF_ZMASK
2012 */
2013#define RT_BF_SET(a_uValue, a_FieldNm, a_uFieldValue) ( RT_BF_CLEAR(a_uValue, a_FieldNm) | RT_BF_MAKE(a_FieldNm, a_uFieldValue) )
2014
2015/** @def RT_BF_CLEAR
2016 * Clears the given bit field in the integer value.
2017 *
2018 * This requires a couple of macros to be defined for the field:
2019 * - \<a_FieldNm\>_SHIFT: The shift count to get to the field.
2020 * - \<a_FieldNm\>_MASK: The field mask. Must have the same type as the
2021 * integer value!!
2022 *
2023 * @returns Integer value with bit field set to zero.
2024 * @param a_uValue The integer value containing the field.
2025 * @param a_FieldNm The field name prefix for getting at the _SHIFT and
2026 * _MASK macros.
2027 * @sa #RT_BF_GET, #RT_BF_SET, #RT_BF_MAKE, #RT_BF_ZMASK
2028 */
2029#define RT_BF_CLEAR(a_uValue, a_FieldNm) ( (a_uValue) & ~RT_CONCAT(a_FieldNm,_MASK) )
2030
2031/** @def RT_BF_MAKE
2032 * Shifts and masks a bit field value into position in the integer value.
2033 *
2034 * This requires a couple of macros to be defined for the field:
2035 * - \<a_FieldNm\>_SHIFT: The shift count to get to the field.
2036 * - \<a_FieldNm\>_MASK: The field mask.
2037 *
2038 * @param a_FieldNm The field name prefix for getting at the _SHIFT and
2039 * _MASK macros.
2040 * @param a_uFieldValue The field value that should be masked and shifted
2041 * into position.
2042 * @sa #RT_BF_GET, #RT_BF_SET, #RT_BF_CLEAR, #RT_BF_ZMASK
2043 */
2044#define RT_BF_MAKE(a_FieldNm, a_uFieldValue) ( ((a_uFieldValue) & RT_BF_ZMASK(a_FieldNm) ) << RT_CONCAT(a_FieldNm,_SHIFT) )
2045
2046/** @def RT_BF_ZMASK
2047 * Helper for getting the field mask shifted to bit position zero.
2048 *
2049 * @param a_FieldNm The field name prefix for getting at the _SHIFT and
2050 * _MASK macros.
2051 * @sa #RT_BF_GET, #RT_BF_SET, #RT_BF_CLEAR, #RT_BF_MAKE
2052 */
2053#define RT_BF_ZMASK(a_FieldNm) ( RT_CONCAT(a_FieldNm,_MASK) >> RT_CONCAT(a_FieldNm,_SHIFT) )
2054
2055/** Bit field compile time check helper
2056 * @internal */
2057#define RT_BF_CHECK_DO_XOR_MASK(a_uLeft, a_RightPrefix, a_FieldNm) ((a_uLeft) ^ RT_CONCAT3(a_RightPrefix, a_FieldNm, _MASK))
2058/** Bit field compile time check helper
2059 * @internal */
2060#define RT_BF_CHECK_DO_OR_MASK(a_uLeft, a_RightPrefix, a_FieldNm) ((a_uLeft) | RT_CONCAT3(a_RightPrefix, a_FieldNm, _MASK))
2061/** Bit field compile time check helper
2062 * @internal */
2063#define RT_BF_CHECK_DO_1ST_MASK_BIT(a_uLeft, a_RightPrefix, a_FieldNm) \
2064 ((a_uLeft) && ( (RT_CONCAT3(a_RightPrefix, a_FieldNm, _MASK) >> RT_CONCAT3(a_RightPrefix, a_FieldNm, _SHIFT)) & 1U ) )
2065/** Used to check that a bit field mask does not start too early.
2066 * @internal */
2067#define RT_BF_CHECK_DO_MASK_START(a_uLeft, a_RightPrefix, a_FieldNm) \
2068 ( (a_uLeft) \
2069 && ( RT_CONCAT3(a_RightPrefix, a_FieldNm, _SHIFT) == 0 \
2070 || ( ( ( ((RT_CONCAT3(a_RightPrefix, a_FieldNm, _MASK) >> RT_CONCAT3(a_RightPrefix, a_FieldNm, _SHIFT)) & 1U) \
2071 << RT_CONCAT3(a_RightPrefix, a_FieldNm, _SHIFT)) /* => single bit mask, correct type */ \
2072 - 1U) /* => mask of all bits below the field */ \
2073 & RT_CONCAT3(a_RightPrefix, a_FieldNm, _MASK)) == 0 ) )
2074/** @name Bit field compile time check recursion workers.
2075 * @internal
2076 * @{ */
2077#define RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix, f1) \
2078 a_DoThis(a_uLeft, a_RightPrefix, f1)
2079#define RT_BF_CHECK_DO_2(a_DoThis, a_uLeft, a_RightPrefix, f1, f2) \
2080 RT_BF_CHECK_DO_1(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2)
2081#define RT_BF_CHECK_DO_3(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3) \
2082 RT_BF_CHECK_DO_2(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3)
2083#define RT_BF_CHECK_DO_4(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4) \
2084 RT_BF_CHECK_DO_3(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4)
2085#define RT_BF_CHECK_DO_5(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5) \
2086 RT_BF_CHECK_DO_4(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5)
2087#define RT_BF_CHECK_DO_6(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6) \
2088 RT_BF_CHECK_DO_5(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6)
2089#define RT_BF_CHECK_DO_7(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7) \
2090 RT_BF_CHECK_DO_6(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7)
2091#define RT_BF_CHECK_DO_8(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8) \
2092 RT_BF_CHECK_DO_7(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8)
2093#define RT_BF_CHECK_DO_9(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9) \
2094 RT_BF_CHECK_DO_8(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9)
2095#define RT_BF_CHECK_DO_10(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10) \
2096 RT_BF_CHECK_DO_9(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10)
2097#define RT_BF_CHECK_DO_11(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11) \
2098 RT_BF_CHECK_DO_10(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11)
2099#define RT_BF_CHECK_DO_12(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12) \
2100 RT_BF_CHECK_DO_11(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12)
2101#define RT_BF_CHECK_DO_13(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13) \
2102 RT_BF_CHECK_DO_12(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13)
2103#define RT_BF_CHECK_DO_14(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14) \
2104 RT_BF_CHECK_DO_13(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14)
2105#define RT_BF_CHECK_DO_15(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15) \
2106 RT_BF_CHECK_DO_14(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15)
2107#define RT_BF_CHECK_DO_16(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16) \
2108 RT_BF_CHECK_DO_15(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16)
2109#define RT_BF_CHECK_DO_17(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17) \
2110 RT_BF_CHECK_DO_16(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17)
2111#define RT_BF_CHECK_DO_18(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18) \
2112 RT_BF_CHECK_DO_17(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18)
2113#define RT_BF_CHECK_DO_19(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19) \
2114 RT_BF_CHECK_DO_18(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19)
2115#define RT_BF_CHECK_DO_20(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20) \
2116 RT_BF_CHECK_DO_19(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20)
2117#define RT_BF_CHECK_DO_21(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21) \
2118 RT_BF_CHECK_DO_20(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21)
2119#define RT_BF_CHECK_DO_22(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22) \
2120 RT_BF_CHECK_DO_21(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22)
2121#define RT_BF_CHECK_DO_23(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23) \
2122 RT_BF_CHECK_DO_22(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23)
2123#define RT_BF_CHECK_DO_24(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24) \
2124 RT_BF_CHECK_DO_23(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24)
2125#define RT_BF_CHECK_DO_25(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25) \
2126 RT_BF_CHECK_DO_24(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25)
2127#define RT_BF_CHECK_DO_26(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26) \
2128 RT_BF_CHECK_DO_25(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26)
2129#define RT_BF_CHECK_DO_27(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27) \
2130 RT_BF_CHECK_DO_26(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27)
2131#define RT_BF_CHECK_DO_28(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28) \
2132 RT_BF_CHECK_DO_27(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28)
2133#define RT_BF_CHECK_DO_29(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29) \
2134 RT_BF_CHECK_DO_28(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29)
2135#define RT_BF_CHECK_DO_30(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30) \
2136 RT_BF_CHECK_DO_29(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30)
2137#define RT_BF_CHECK_DO_31(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31) \
2138 RT_BF_CHECK_DO_30(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31)
2139#define RT_BF_CHECK_DO_32(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32) \
2140 RT_BF_CHECK_DO_31(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32)
2141#define RT_BF_CHECK_DO_33(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33) \
2142 RT_BF_CHECK_DO_32(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33)
2143#define RT_BF_CHECK_DO_34(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34) \
2144 RT_BF_CHECK_DO_33(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34)
2145#define RT_BF_CHECK_DO_35(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35) \
2146 RT_BF_CHECK_DO_34(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35)
2147#define RT_BF_CHECK_DO_36(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36) \
2148 RT_BF_CHECK_DO_35(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36)
2149#define RT_BF_CHECK_DO_37(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37) \
2150 RT_BF_CHECK_DO_36(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37)
2151#define RT_BF_CHECK_DO_38(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38) \
2152 RT_BF_CHECK_DO_37(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38)
2153#define RT_BF_CHECK_DO_39(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39) \
2154 RT_BF_CHECK_DO_38(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39)
2155#define RT_BF_CHECK_DO_40(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40) \
2156 RT_BF_CHECK_DO_39(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40)
2157#define RT_BF_CHECK_DO_41(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41) \
2158 RT_BF_CHECK_DO_40(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41)
2159#define RT_BF_CHECK_DO_42(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42) \
2160 RT_BF_CHECK_DO_41(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42)
2161#define RT_BF_CHECK_DO_43(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43) \
2162 RT_BF_CHECK_DO_42(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43)
2163#define RT_BF_CHECK_DO_44(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43, f44) \
2164 RT_BF_CHECK_DO_43(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43, f44)
2165#define RT_BF_CHECK_DO_45(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43, f44, f45) \
2166 RT_BF_CHECK_DO_44(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43, f44, f45)
2167#define RT_BF_CHECK_DO_46(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43, f44, f45, f46) \
2168 RT_BF_CHECK_DO_45(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43, f44, f45, f46)
2169#define RT_BF_CHECK_DO_47(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43, f44, f45, f46, f47) \
2170 RT_BF_CHECK_DO_46(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43, f44, f45, f46, f47)
2171#define RT_BF_CHECK_DO_48(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43, f44, f45, f46, f47, f48) \
2172 RT_BF_CHECK_DO_47(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43, f44, f45, f46, f47, f48)
2173#define RT_BF_CHECK_DO_49(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43, f44, f45, f46, f47, f48, f49) \
2174 RT_BF_CHECK_DO_48(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43, f44, f45, f46, f47, f48, f49)
2175#define RT_BF_CHECK_DO_50(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43, f44, f45, f46, f47, f48, f49, f50) \
2176 RT_BF_CHECK_DO_49(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43, f44, f45, f46, f47, f48, f49, f50)
2177#define RT_BF_CHECK_DO_51(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43, f44, f45, f46, f47, f48, f49, f50, f51) \
2178 RT_BF_CHECK_DO_40(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43, f44, f45, f46, f47, f48, f49, f50, f51)
2179#define RT_BF_CHECK_DO_52(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43, f44, f45, f46, f47, f48, f49, f50, f51, f52) \
2180 RT_BF_CHECK_DO_51(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43, f44, f45, f46, f47, f48, f49, f50, f51, f52)
2181#define RT_BF_CHECK_DO_53(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43, f44, f45, f46, f47, f48, f49, f50, f51, f52, f53) \
2182 RT_BF_CHECK_DO_52(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43, f44, f45, f46, f47, f48, f49, f50, f51, f52, f53)
2183#define RT_BF_CHECK_DO_54(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43, f44, f45, f46, f47, f48, f49, f50, f51, f52, f53, f54) \
2184 RT_BF_CHECK_DO_53(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43, f44, f45, f46, f47, f48, f49, f50, f51, f52, f53, f54)
2185#define RT_BF_CHECK_DO_55(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43, f44, f45, f46, f47, f48, f49, f50, f51, f52, f53, f54, f55) \
2186 RT_BF_CHECK_DO_54(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43, f44, f45, f46, f47, f48, f49, f50, f51, f52, f53, f54, f55)
2187#define RT_BF_CHECK_DO_56(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43, f44, f45, f46, f47, f48, f49, f50, f51, f52, f53, f54, f55, f56) \
2188 RT_BF_CHECK_DO_55(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43, f44, f45, f46, f47, f48, f49, f50, f51, f52, f53, f54, f55, f56)
2189#define RT_BF_CHECK_DO_57(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43, f44, f45, f46, f47, f48, f49, f50, f51, f52, f53, f54, f55, f56, f57) \
2190 RT_BF_CHECK_DO_56(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43, f44, f45, f46, f47, f48, f49, f50, f51, f52, f53, f54, f55, f56, f57)
2191#define RT_BF_CHECK_DO_58(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43, f44, f45, f46, f47, f48, f49, f50, f51, f52, f53, f54, f55, f56, f57, f58) \
2192 RT_BF_CHECK_DO_57(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43, f44, f45, f46, f47, f48, f49, f50, f51, f52, f53, f54, f55, f56, f57, f58)
2193#define RT_BF_CHECK_DO_59(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43, f44, f45, f46, f47, f48, f49, f50, f51, f52, f53, f54, f55, f56, f57, f58, f59) \
2194 RT_BF_CHECK_DO_58(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43, f44, f45, f46, f47, f48, f49, f50, f51, f52, f53, f54, f55, f56, f57, f58, f59)
2195#define RT_BF_CHECK_DO_60(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43, f44, f45, f46, f47, f48, f49, f50, f51, f52, f53, f54, f55, f56, f57, f58, f59, f60) \
2196 RT_BF_CHECK_DO_59(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43, f44, f45, f46, f47, f48, f49, f50, f51, f52, f53, f54, f55, f56, f57, f58, f59, f60)
2197#define RT_BF_CHECK_DO_61(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43, f44, f45, f46, f47, f48, f49, f50, f51, f52, f53, f54, f55, f56, f57, f58, f59, f60, f61) \
2198 RT_BF_CHECK_DO_60(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43, f44, f45, f46, f47, f48, f49, f50, f51, f52, f53, f54, f55, f56, f57, f58, f59, f60, f61)
2199#define RT_BF_CHECK_DO_62(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43, f44, f45, f46, f47, f48, f49, f50, f51, f52, f53, f54, f55, f56, f57, f58, f59, f60, f61, f62) \
2200 RT_BF_CHECK_DO_61(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43, f44, f45, f46, f47, f48, f49, f50, f51, f52, f53, f54, f55, f56, f57, f58, f59, f60, f61, f62)
2201#define RT_BF_CHECK_DO_63(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43, f44, f45, f46, f47, f48, f49, f50, f51, f52, f53, f54, f55, f56, f57, f58, f59, f60, f61, f62, f63) \
2202 RT_BF_CHECK_DO_62(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43, f44, f45, f46, f47, f48, f49, f50, f51, f52, f53, f54, f55, f56, f57, f58, f59, f60, f61, f62, f63)
2203#define RT_BF_CHECK_DO_64(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43, f44, f45, f46, f47, f48, f49, f50, f51, f52, f53, f54, f55, f56, f57, f58, f59, f60, f61, f62, f63, f64) \
2204 RT_BF_CHECK_DO_63(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43, f44, f45, f46, f47, f48, f49, f50, f51, f52, f53, f54, f55, f56, f57, f58, f59, f60, f61, f62, f63, f64)
2205/** @} */
2206
2207/** @def RT_BF_ASSERT_COMPILE_CHECKS
2208 * Emits a series of AssertCompile statements checking that the bit-field
2209 * declarations doesn't overlap, has holes, and generally makes some sense.
2210 *
2211 * This requires variadic macros because its too much to type otherwise.
2212 */
2213#if defined(RT_COMPILER_SUPPORTS_VA_ARGS) || defined(DOXYGEN_RUNNING)
2214# define RT_BF_ASSERT_COMPILE_CHECKS(a_Prefix, a_uZero, a_uCovered, a_Fields) \
2215 AssertCompile(RT_BF_CHECK_DO_N(RT_BF_CHECK_DO_OR_MASK, a_uZero, a_Prefix, RT_UNPACK_ARGS a_Fields ) == a_uCovered); \
2216 AssertCompile(RT_BF_CHECK_DO_N(RT_BF_CHECK_DO_XOR_MASK, a_uCovered, a_Prefix, RT_UNPACK_ARGS a_Fields ) == 0); \
2217 AssertCompile(RT_BF_CHECK_DO_N(RT_BF_CHECK_DO_1ST_MASK_BIT, true, a_Prefix, RT_UNPACK_ARGS a_Fields ) == true); \
2218 AssertCompile(RT_BF_CHECK_DO_N(RT_BF_CHECK_DO_MASK_START, true, a_Prefix, RT_UNPACK_ARGS a_Fields ) == true)
2219/** Bit field compile time check helper
2220 * @internal */
2221# define RT_BF_CHECK_DO_N(a_DoThis, a_uLeft, a_RightPrefix, ...) \
2222 RT_UNPACK_CALL(RT_CONCAT(RT_BF_CHECK_DO_, RT_EXPAND(RT_COUNT_VA_ARGS(__VA_ARGS__))), (a_DoThis, a_uLeft, a_RightPrefix, __VA_ARGS__))
2223#else
2224# define RT_BF_ASSERT_COMPILE_CHECKS(a_Prefix, a_uZero, a_uCovered, a_Fields) AssertCompile(true)
2225#endif
2226
2227
2228/** @def RT_ALIGN
2229 * Align macro.
2230 * @param u Value to align.
2231 * @param uAlignment The alignment. Power of two!
2232 *
2233 * @remark Be extremely careful when using this macro with type which sizeof != sizeof int.
2234 * When possible use any of the other RT_ALIGN_* macros. And when that's not
2235 * possible, make 101% sure that uAlignment is specified with a right sized type.
2236 *
2237 * Specifying an unsigned 32-bit alignment constant with a 64-bit value will give
2238 * you a 32-bit return value!
2239 *
2240 * In short: Don't use this macro. Use RT_ALIGN_T() instead.
2241 */
2242#define RT_ALIGN(u, uAlignment) ( ((u) + ((uAlignment) - 1)) & ~((uAlignment) - 1) )
2243
2244/** @def RT_ALIGN_T
2245 * Align macro.
2246 * @param u Value to align.
2247 * @param uAlignment The alignment. Power of two!
2248 * @param type Integer type to use while aligning.
2249 * @remark This macro is the preferred alignment macro, it doesn't have any of the pitfalls RT_ALIGN has.
2250 */
2251#define RT_ALIGN_T(u, uAlignment, type) ( ((type)(u) + ((uAlignment) - 1)) & ~(type)((uAlignment) - 1) )
2252
2253/** @def RT_ALIGN_32
2254 * Align macro for a 32-bit value.
2255 * @param u32 Value to align.
2256 * @param uAlignment The alignment. Power of two!
2257 */
2258#define RT_ALIGN_32(u32, uAlignment) RT_ALIGN_T(u32, uAlignment, uint32_t)
2259
2260/** @def RT_ALIGN_64
2261 * Align macro for a 64-bit value.
2262 * @param u64 Value to align.
2263 * @param uAlignment The alignment. Power of two!
2264 */
2265#define RT_ALIGN_64(u64, uAlignment) RT_ALIGN_T(u64, uAlignment, uint64_t)
2266
2267/** @def RT_ALIGN_Z
2268 * Align macro for size_t.
2269 * @param cb Value to align.
2270 * @param uAlignment The alignment. Power of two!
2271 */
2272#define RT_ALIGN_Z(cb, uAlignment) RT_ALIGN_T(cb, uAlignment, size_t)
2273
2274/** @def RT_ALIGN_P
2275 * Align macro for pointers.
2276 * @param pv Value to align.
2277 * @param uAlignment The alignment. Power of two!
2278 */
2279#define RT_ALIGN_P(pv, uAlignment) RT_ALIGN_PT(pv, uAlignment, void *)
2280
2281/** @def RT_ALIGN_PT
2282 * Align macro for pointers with type cast.
2283 * @param u Value to align.
2284 * @param uAlignment The alignment. Power of two!
2285 * @param CastType The type to cast the result to.
2286 */
2287#define RT_ALIGN_PT(u, uAlignment, CastType) ( (CastType)RT_ALIGN_T(u, uAlignment, uintptr_t) )
2288
2289/** @def RT_ALIGN_R3PT
2290 * Align macro for ring-3 pointers with type cast.
2291 * @param u Value to align.
2292 * @param uAlignment The alignment. Power of two!
2293 * @param CastType The type to cast the result to.
2294 */
2295#define RT_ALIGN_R3PT(u, uAlignment, CastType) ( (CastType)RT_ALIGN_T(u, uAlignment, RTR3UINTPTR) )
2296
2297/** @def RT_ALIGN_R0PT
2298 * Align macro for ring-0 pointers with type cast.
2299 * @param u Value to align.
2300 * @param uAlignment The alignment. Power of two!
2301 * @param CastType The type to cast the result to.
2302 */
2303#define RT_ALIGN_R0PT(u, uAlignment, CastType) ( (CastType)RT_ALIGN_T(u, uAlignment, RTR0UINTPTR) )
2304
2305/** @def RT_ALIGN_GCPT
2306 * Align macro for GC pointers with type cast.
2307 * @param u Value to align.
2308 * @param uAlignment The alignment. Power of two!
2309 * @param CastType The type to cast the result to.
2310 */
2311#define RT_ALIGN_GCPT(u, uAlignment, CastType) ( (CastType)RT_ALIGN_T(u, uAlignment, RTGCUINTPTR) )
2312
2313
2314/** @def RT_OFFSETOF
2315 * Our own special offsetof() variant, returns a signed result.
2316 *
2317 * @returns offset into the structure of the specified member. signed.
2318 * @param type Structure type.
2319 * @param member Member.
2320 *
2321 * @remarks Only use this for static offset calculations. Please
2322 * use RT_UOFFSETOF_DYN for dynamic ones (i.e. involves
2323 * non-constant array indexing).
2324 *
2325 */
2326#if RT_GNUC_PREREQ(4, 0)
2327# define RT_OFFSETOF(type, member) ( (int)__builtin_offsetof(type, member) )
2328#else
2329# define RT_OFFSETOF(type, member) ( (int)(intptr_t)&( ((type *)(void *)0)->member) )
2330#endif
2331
2332/** @def RT_UOFFSETOF
2333 * Our own offsetof() variant, returns an unsigned result.
2334 *
2335 * @returns offset into the structure of the specified member. unsigned.
2336 * @param type Structure type.
2337 * @param member Member.
2338 *
2339 * @remarks Only use this for static offset calculations. Please
2340 * use RT_UOFFSETOF_DYN for dynamic ones (i.e. involves
2341 * non-constant array indexing).
2342 */
2343#if RT_GNUC_PREREQ(4, 0)
2344# define RT_UOFFSETOF(type, member) ( (uintptr_t)__builtin_offsetof(type, member) )
2345#else
2346# define RT_UOFFSETOF(type, member) ( (uintptr_t)&( ((type *)(void *)0)->member) )
2347#endif
2348
2349/** @def RT_OFFSETOF_ADD
2350 * RT_OFFSETOF with an addend.
2351 *
2352 * @returns offset into the structure of the specified member. signed.
2353 * @param type Structure type.
2354 * @param member Member.
2355 * @param addend The addend to add to the offset.
2356 *
2357 * @remarks Only use this for static offset calculations.
2358 */
2359#define RT_OFFSETOF_ADD(type, member, addend) ( (int)RT_UOFFSETOF_ADD(type, member, addend) )
2360
2361/** @def RT_UOFFSETOF_ADD
2362 * RT_UOFFSETOF with an addend.
2363 *
2364 * @returns offset into the structure of the specified member. signed.
2365 * @param type Structure type.
2366 * @param member Member.
2367 * @param addend The addend to add to the offset.
2368 *
2369 * @remarks Only use this for static offset calculations.
2370 */
2371#if RT_GNUC_PREREQ(4, 0)
2372# define RT_UOFFSETOF_ADD(type, member, addend) ( (uintptr_t)(__builtin_offsetof(type, member) + (addend)))
2373#else
2374# define RT_UOFFSETOF_ADD(type, member, addend) ( (uintptr_t)&( ((type *)(void *)(uintptr_t)(addend))->member) )
2375#endif
2376
2377/** @def RT_UOFFSETOF_DYN
2378 * Dynamic (runtime) structure offset calculations, involving
2379 * indexing of array members via variable.
2380 *
2381 * @returns offset into the structure of the specified member. signed.
2382 * @param type Structure type.
2383 * @param memberarray Member.
2384 */
2385#if defined(__cplusplus) && RT_GNUC_PREREQ(4, 4)
2386# define RT_UOFFSETOF_DYN(type, memberarray) ( (uintptr_t)&( ((type *)(void *)0x1000)->memberarray) - 0x1000 )
2387#else
2388# define RT_UOFFSETOF_DYN(type, memberarray) ( (uintptr_t)&( ((type *)(void *)0)->memberarray) )
2389#endif
2390
2391
2392/** @def RT_SIZEOFMEMB
2393 * Get the size of a structure member.
2394 *
2395 * @returns size of the structure member.
2396 * @param type Structure type.
2397 * @param member Member.
2398 */
2399#define RT_SIZEOFMEMB(type, member) ( sizeof(((type *)(void *)0)->member) )
2400
2401/** @def RT_UOFFSET_AFTER
2402 * Returns the offset of the first byte following a structure/union member.
2403 *
2404 * @return byte offset into the struct.
2405 * @param a_Type Structure type.
2406 * @param a_Member The member name.
2407 */
2408#define RT_UOFFSET_AFTER(a_Type, a_Member) ( RT_UOFFSETOF(a_Type, a_Member) + RT_SIZEOFMEMB(a_Type, a_Member) )
2409
2410/** @def RT_FROM_MEMBER
2411 * Convert a pointer to a structure member into a pointer to the structure.
2412 *
2413 * @returns pointer to the structure.
2414 * @param pMem Pointer to the member.
2415 * @param Type Structure type.
2416 * @param Member Member name.
2417 */
2418#define RT_FROM_MEMBER(pMem, Type, Member) ( (Type *) ((uint8_t *)(void *)(pMem) - RT_UOFFSETOF(Type, Member)) )
2419
2420/** @def RT_FROM_CPP_MEMBER
2421 * Same as RT_FROM_MEMBER except it avoids the annoying g++ warnings about
2422 * invalid access to non-static data member of NULL object.
2423 *
2424 * @returns pointer to the structure.
2425 * @param pMem Pointer to the member.
2426 * @param Type Structure type.
2427 * @param Member Member name.
2428 *
2429 * @remarks Using the __builtin_offsetof does not shut up the compiler.
2430 */
2431#if defined(__GNUC__) && defined(__cplusplus)
2432# define RT_FROM_CPP_MEMBER(pMem, Type, Member) \
2433 ( (Type *) ((uintptr_t)(pMem) - (uintptr_t)&((Type *)0x1000)->Member + 0x1000U) )
2434#else
2435# define RT_FROM_CPP_MEMBER(pMem, Type, Member) RT_FROM_MEMBER(pMem, Type, Member)
2436#endif
2437
2438/** @def RT_FROM_MEMBER_DYN
2439 * Convert a pointer to a structure member into a pointer to the structure.
2440 *
2441 * @returns pointer to the structure.
2442 * @param pMem Pointer to the member.
2443 * @param Type Structure type.
2444 * @param Member Member name dynamic size (some array is index by
2445 * non-constant value).
2446 */
2447#define RT_FROM_MEMBER_DYN(pMem, Type, Member) ( (Type *) ((uint8_t *)(void *)(pMem) - RT_UOFFSETOF_DYN(Type, Member)) )
2448
2449/** @def RT_ELEMENTS
2450 * Calculates the number of elements in a statically sized array.
2451 * @returns Element count.
2452 * @param aArray Array in question.
2453 */
2454#define RT_ELEMENTS(aArray) ( sizeof(aArray) / sizeof((aArray)[0]) )
2455
2456/** @def RT_FLEXIBLE_ARRAY
2457 * What to up inside the square brackets when declaring a structure member
2458 * with a flexible size.
2459 *
2460 * @note Use RT_UOFFSETOF() to calculate the structure size.
2461 *
2462 * @note Never to a sizeof() on the structure or member!
2463 *
2464 * @note The member must be the last one.
2465 *
2466 * @note GCC does not permit using this in a union. So, for unions you must
2467 * use RT_FLEXIBLE_ARRAY_IN_UNION instead.
2468 *
2469 * @note GCC does not permit using this in nested structures, where as MSC
2470 * does. So, use RT_FLEXIBLE_ARRAY_NESTED for that.
2471 *
2472 * @sa RT_FLEXIBLE_ARRAY_NESTED, RT_FLEXIBLE_ARRAY_IN_UNION
2473 */
2474#if RT_MSC_PREREQ(RT_MSC_VER_VS2005) /** @todo Probably much much earlier. */ \
2475 || (defined(__cplusplus) && RT_GNUC_PREREQ(6, 1) && !RT_GNUC_PREREQ(7, 0)) /* gcc-7 warns again */\
2476 || defined(__WATCOMC__) /* openwatcom 1.9 supports it, we don't care about older atm. */ \
2477 || RT_CLANG_PREREQ_EX(3, 4, 0) /* Only tested clang v3.4, support is probably older. */
2478# define RT_FLEXIBLE_ARRAY
2479# if defined(__cplusplus) && defined(_MSC_VER)
2480# pragma warning(disable:4200) /* -wd4200 does not work with VS2010 */
2481# endif
2482#elif defined(__STDC_VERSION__)
2483# if __STDC_VERSION__ >= 1999901L
2484# define RT_FLEXIBLE_ARRAY
2485# else
2486# define RT_FLEXIBLE_ARRAY 1
2487# endif
2488#else
2489# define RT_FLEXIBLE_ARRAY 1
2490#endif
2491
2492/** @def RT_FLEXIBLE_ARRAY_NESTED
2493 * Variant of RT_FLEXIBLE_ARRAY for use in structures that are nested.
2494 *
2495 * GCC only allow the use of flexible array member in the top structure, whereas
2496 * MSC is less strict and let you do struct { struct { char szName[]; } s; };
2497 *
2498 * @note See notes for RT_FLEXIBLE_ARRAY.
2499 *
2500 * @note GCC does not permit using this in a union. So, for unions you must
2501 * use RT_FLEXIBLE_ARRAY_IN_NESTED_UNION instead.
2502 *
2503 * @sa RT_FLEXIBLE_ARRAY, RT_FLEXIBLE_ARRAY_IN_NESTED_UNION
2504 */
2505#ifdef _MSC_VER
2506# define RT_FLEXIBLE_ARRAY_NESTED RT_FLEXIBLE_ARRAY
2507#else
2508# define RT_FLEXIBLE_ARRAY_NESTED 1
2509#endif
2510
2511/** @def RT_FLEXIBLE_ARRAY_IN_UNION
2512 * The union version of RT_FLEXIBLE_ARRAY.
2513 *
2514 * @remarks GCC does not support flexible array members in unions, 6.1.x
2515 * actively checks for this. Visual C++ 2010 seems happy with it.
2516 *
2517 * @note See notes for RT_FLEXIBLE_ARRAY.
2518 *
2519 * @sa RT_FLEXIBLE_ARRAY, RT_FLEXIBLE_ARRAY_IN_NESTED_UNION
2520 */
2521#ifdef _MSC_VER
2522# define RT_FLEXIBLE_ARRAY_IN_UNION RT_FLEXIBLE_ARRAY
2523#else
2524# define RT_FLEXIBLE_ARRAY_IN_UNION 1
2525#endif
2526
2527/** @def RT_FLEXIBLE_ARRAY_IN_NESTED_UNION
2528 * The union version of RT_FLEXIBLE_ARRAY_NESTED.
2529 *
2530 * @note See notes for RT_FLEXIBLE_ARRAY.
2531 *
2532 * @sa RT_FLEXIBLE_ARRAY, RT_FLEXIBLE_ARRAY_IN_NESTED_UNION
2533 */
2534#ifdef _MSC_VER
2535# define RT_FLEXIBLE_ARRAY_IN_NESTED_UNION RT_FLEXIBLE_ARRAY_NESTED
2536#else
2537# define RT_FLEXIBLE_ARRAY_IN_NESTED_UNION 1
2538#endif
2539
2540/** @def RT_UNION_NM
2541 * For compilers (like DTrace) that does not grok nameless unions, we have a
2542 * little hack to make them palatable.
2543 */
2544/** @def RT_STRUCT_NM
2545 * For compilers (like DTrace) that does not grok nameless structs (it is
2546 * non-standard C++), we have a little hack to make them palatable.
2547 */
2548#ifdef IPRT_WITHOUT_NAMED_UNIONS_AND_STRUCTS
2549# define RT_UNION_NM(a_Nm) a_Nm
2550# define RT_STRUCT_NM(a_Nm) a_Nm
2551#else
2552# define RT_UNION_NM(a_Nm)
2553# define RT_STRUCT_NM(a_Nm)
2554#endif
2555
2556/**
2557 * Checks if the value is a power of two.
2558 *
2559 * @returns true if power of two, false if not.
2560 * @param uVal The value to test.
2561 * @remarks 0 is a power of two.
2562 * @see VERR_NOT_POWER_OF_TWO
2563 */
2564#define RT_IS_POWER_OF_TWO(uVal) ( ((uVal) & ((uVal) - 1)) == 0)
2565
2566#ifdef RT_OS_OS2
2567/* Undefine RT_MAX since there is an unfortunate clash with the max
2568 resource type define in os2.h. */
2569# undef RT_MAX
2570#endif
2571
2572/** @def RT_MAX
2573 * Finds the maximum value.
2574 * @returns The higher of the two.
2575 * @param Value1 Value 1
2576 * @param Value2 Value 2
2577 */
2578#define RT_MAX(Value1, Value2) ( (Value1) >= (Value2) ? (Value1) : (Value2) )
2579
2580/** @def RT_MIN
2581 * Finds the minimum value.
2582 * @returns The lower of the two.
2583 * @param Value1 Value 1
2584 * @param Value2 Value 2
2585 */
2586#define RT_MIN(Value1, Value2) ( (Value1) <= (Value2) ? (Value1) : (Value2) )
2587
2588/** @def RT_CLAMP
2589 * Clamps the value to minimum and maximum values.
2590 * @returns The clamped value.
2591 * @param Value The value to check.
2592 * @param Min Minimum value.
2593 * @param Max Maximum value.
2594 */
2595#define RT_CLAMP(Value, Min, Max) ( (Value) > (Max) ? (Max) : (Value) < (Min) ? (Min) : (Value) )
2596
2597/** @def RT_ABS
2598 * Get the absolute (non-negative) value.
2599 * @returns The absolute value of Value.
2600 * @param Value The value.
2601 */
2602#define RT_ABS(Value) ( (Value) >= 0 ? (Value) : -(Value) )
2603
2604/** @def RT_BOOL
2605 * Turn non-zero/zero into true/false
2606 * @returns The resulting boolean value.
2607 * @param Value The value.
2608 */
2609#define RT_BOOL(Value) ( !!(Value) )
2610
2611/** @def RT_LO_U8
2612 * Gets the low uint8_t of a uint16_t or something equivalent. */
2613#ifdef __GNUC__
2614# define RT_LO_U8(a) __extension__ ({ AssertCompile(sizeof((a)) == sizeof(uint16_t)); (uint8_t)(a); })
2615#elif defined(_MSC_VER) /* shut up cast truncates constant value warnings */
2616# define RT_LO_U8(a) ( (uint8_t)(UINT8_MAX & (a)) )
2617#else
2618# define RT_LO_U8(a) ( (uint8_t)(a) )
2619#endif
2620/** @def RT_HI_U8
2621 * Gets the high uint8_t of a uint16_t or something equivalent. */
2622#ifdef __GNUC__
2623# define RT_HI_U8(a) __extension__ ({ AssertCompile(sizeof((a)) == sizeof(uint16_t)); (uint8_t)((a) >> 8); })
2624#else
2625# define RT_HI_U8(a) ( (uint8_t)((a) >> 8) )
2626#endif
2627
2628/** @def RT_LO_U16
2629 * Gets the low uint16_t of a uint32_t or something equivalent. */
2630#ifdef __GNUC__
2631# define RT_LO_U16(a) __extension__ ({ AssertCompile(sizeof((a)) == sizeof(uint32_t)); (uint16_t)(a); })
2632#elif defined(_MSC_VER) /* shut up cast truncates constant value warnings */
2633# define RT_LO_U16(a) ( (uint16_t)(UINT16_MAX & (a)) )
2634#else
2635# define RT_LO_U16(a) ( (uint16_t)(a) )
2636#endif
2637/** @def RT_HI_U16
2638 * Gets the high uint16_t of a uint32_t or something equivalent. */
2639#ifdef __GNUC__
2640# define RT_HI_U16(a) __extension__ ({ AssertCompile(sizeof((a)) == sizeof(uint32_t)); (uint16_t)((a) >> 16); })
2641#else
2642# define RT_HI_U16(a) ( (uint16_t)((a) >> 16) )
2643#endif
2644
2645/** @def RT_LO_U32
2646 * Gets the low uint32_t of a uint64_t or something equivalent. */
2647#ifdef __GNUC__
2648# define RT_LO_U32(a) __extension__ ({ AssertCompile(sizeof((a)) == sizeof(uint64_t)); (uint32_t)(a); })
2649#elif defined(_MSC_VER) /* shut up cast truncates constant value warnings */
2650# define RT_LO_U32(a) ( (uint32_t)(UINT32_MAX & (a)) )
2651#else
2652# define RT_LO_U32(a) ( (uint32_t)(a) )
2653#endif
2654/** @def RT_HI_U32
2655 * Gets the high uint32_t of a uint64_t or something equivalent. */
2656#ifdef __GNUC__
2657# define RT_HI_U32(a) __extension__ ({ AssertCompile(sizeof((a)) == sizeof(uint64_t)); (uint32_t)((a) >> 32); })
2658#else
2659# define RT_HI_U32(a) ( (uint32_t)((a) >> 32) )
2660#endif
2661
2662/** @def RT_BYTE1
2663 * Gets the first byte of something. */
2664#define RT_BYTE1(a) ( (a) & 0xff )
2665/** @def RT_BYTE2
2666 * Gets the second byte of something. */
2667#define RT_BYTE2(a) ( ((a) >> 8) & 0xff )
2668/** @def RT_BYTE3
2669 * Gets the second byte of something. */
2670#define RT_BYTE3(a) ( ((a) >> 16) & 0xff )
2671/** @def RT_BYTE4
2672 * Gets the fourth byte of something. */
2673#define RT_BYTE4(a) ( ((a) >> 24) & 0xff )
2674/** @def RT_BYTE5
2675 * Gets the fifth byte of something. */
2676#define RT_BYTE5(a) ( ((a) >> 32) & 0xff )
2677/** @def RT_BYTE6
2678 * Gets the sixth byte of something. */
2679#define RT_BYTE6(a) ( ((a) >> 40) & 0xff )
2680/** @def RT_BYTE7
2681 * Gets the seventh byte of something. */
2682#define RT_BYTE7(a) ( ((a) >> 48) & 0xff )
2683/** @def RT_BYTE8
2684 * Gets the eight byte of something. */
2685#define RT_BYTE8(a) ( ((a) >> 56) & 0xff )
2686
2687
2688/** @def RT_LODWORD
2689 * Gets the low dword (=uint32_t) of something.
2690 * @deprecated Use RT_LO_U32. */
2691#define RT_LODWORD(a) ( (uint32_t)(a) )
2692/** @def RT_HIDWORD
2693 * Gets the high dword (=uint32_t) of a 64-bit of something.
2694 * @deprecated Use RT_HI_U32. */
2695#define RT_HIDWORD(a) ( (uint32_t)((a) >> 32) )
2696
2697/** @def RT_LOWORD
2698 * Gets the low word (=uint16_t) of something.
2699 * @deprecated Use RT_LO_U16. */
2700#define RT_LOWORD(a) ( (a) & 0xffff )
2701/** @def RT_HIWORD
2702 * Gets the high word (=uint16_t) of a 32-bit something.
2703 * @deprecated Use RT_HI_U16. */
2704#define RT_HIWORD(a) ( (a) >> 16 )
2705
2706/** @def RT_LOBYTE
2707 * Gets the low byte of something.
2708 * @deprecated Use RT_LO_U8. */
2709#define RT_LOBYTE(a) ( (a) & 0xff )
2710/** @def RT_HIBYTE
2711 * Gets the high byte of a 16-bit something.
2712 * @deprecated Use RT_HI_U8. */
2713#define RT_HIBYTE(a) ( (a) >> 8 )
2714
2715
2716/** @def RT_MAKE_U64
2717 * Constructs a uint64_t value from two uint32_t values.
2718 */
2719#define RT_MAKE_U64(Lo, Hi) ( (uint64_t)((uint32_t)(Hi)) << 32 | (uint32_t)(Lo) )
2720
2721/** @def RT_MAKE_U64_FROM_U16
2722 * Constructs a uint64_t value from four uint16_t values.
2723 */
2724#define RT_MAKE_U64_FROM_U16(w0, w1, w2, w3) \
2725 ((uint64_t)( (uint64_t)((uint16_t)(w3)) << 48 \
2726 | (uint64_t)((uint16_t)(w2)) << 32 \
2727 | (uint32_t)((uint16_t)(w1)) << 16 \
2728 | (uint16_t)(w0) ))
2729
2730/** @def RT_MAKE_U64_FROM_U8
2731 * Constructs a uint64_t value from eight uint8_t values.
2732 */
2733#define RT_MAKE_U64_FROM_U8(b0, b1, b2, b3, b4, b5, b6, b7) \
2734 ((uint64_t)( (uint64_t)((uint8_t)(b7)) << 56 \
2735 | (uint64_t)((uint8_t)(b6)) << 48 \
2736 | (uint64_t)((uint8_t)(b5)) << 40 \
2737 | (uint64_t)((uint8_t)(b4)) << 32 \
2738 | (uint32_t)((uint8_t)(b3)) << 24 \
2739 | (uint32_t)((uint8_t)(b2)) << 16 \
2740 | (uint16_t)((uint8_t)(b1)) << 8 \
2741 | (uint8_t)(b0) ))
2742
2743/** @def RT_MAKE_U32
2744 * Constructs a uint32_t value from two uint16_t values.
2745 */
2746#define RT_MAKE_U32(Lo, Hi) \
2747 ((uint32_t)( (uint32_t)((uint16_t)(Hi)) << 16 \
2748 | (uint16_t)(Lo) ))
2749
2750/** @def RT_MAKE_U32_FROM_U8
2751 * Constructs a uint32_t value from four uint8_t values.
2752 */
2753#define RT_MAKE_U32_FROM_U8(b0, b1, b2, b3) \
2754 ((uint32_t)( (uint32_t)((uint8_t)(b3)) << 24 \
2755 | (uint32_t)((uint8_t)(b2)) << 16 \
2756 | (uint16_t)((uint8_t)(b1)) << 8 \
2757 | (uint8_t)(b0) ))
2758
2759/** @def RT_MAKE_U16
2760 * Constructs a uint16_t value from two uint8_t values.
2761 */
2762#define RT_MAKE_U16(Lo, Hi) \
2763 ((uint16_t)( (uint16_t)((uint8_t)(Hi)) << 8 \
2764 | (uint8_t)(Lo) ))
2765
2766
2767/** @def RT_BSWAP_U64
2768 * Reverses the byte order of an uint64_t value. */
2769#if 0
2770# define RT_BSWAP_U64(u64) RT_BSWAP_U64_C(u64)
2771#elif defined(__GNUC__)
2772# define RT_BSWAP_U64(u64) (__builtin_constant_p((u64)) \
2773 ? RT_BSWAP_U64_C(u64) : ASMByteSwapU64(u64))
2774#else
2775# define RT_BSWAP_U64(u64) ASMByteSwapU64(u64)
2776#endif
2777
2778/** @def RT_BSWAP_U32
2779 * Reverses the byte order of an uint32_t value. */
2780#if 0
2781# define RT_BSWAP_U32(u32) RT_BSWAP_U32_C(u32)
2782#elif defined(__GNUC__)
2783# define RT_BSWAP_U32(u32) (__builtin_constant_p((u32)) \
2784 ? RT_BSWAP_U32_C(u32) : ASMByteSwapU32(u32))
2785#else
2786# define RT_BSWAP_U32(u32) ASMByteSwapU32(u32)
2787#endif
2788
2789/** @def RT_BSWAP_U16
2790 * Reverses the byte order of an uint16_t value. */
2791#if 0
2792# define RT_BSWAP_U16(u16) RT_BSWAP_U16_C(u16)
2793#elif defined(__GNUC__)
2794# define RT_BSWAP_U16(u16) (__builtin_constant_p((u16)) \
2795 ? RT_BSWAP_U16_C(u16) : ASMByteSwapU16(u16))
2796#else
2797# define RT_BSWAP_U16(u16) ASMByteSwapU16(u16)
2798#endif
2799
2800
2801/** @def RT_BSWAP_U64_C
2802 * Reverses the byte order of an uint64_t constant. */
2803#define RT_BSWAP_U64_C(u64) RT_MAKE_U64(RT_BSWAP_U32_C((u64) >> 32), RT_BSWAP_U32_C((u64) & 0xffffffff))
2804
2805/** @def RT_BSWAP_U32_C
2806 * Reverses the byte order of an uint32_t constant. */
2807#define RT_BSWAP_U32_C(u32) RT_MAKE_U32_FROM_U8(RT_BYTE4(u32), RT_BYTE3(u32), RT_BYTE2(u32), RT_BYTE1(u32))
2808
2809/** @def RT_BSWAP_U16_C
2810 * Reverses the byte order of an uint16_t constant. */
2811#define RT_BSWAP_U16_C(u16) RT_MAKE_U16(RT_HIBYTE(u16), RT_LOBYTE(u16))
2812
2813
2814/** @def RT_H2LE_U64
2815 * Converts an uint64_t value from host to little endian byte order. */
2816#ifdef RT_BIG_ENDIAN
2817# define RT_H2LE_U64(u64) RT_BSWAP_U64(u64)
2818#else
2819# define RT_H2LE_U64(u64) (u64)
2820#endif
2821
2822/** @def RT_H2LE_U64_C
2823 * Converts an uint64_t constant from host to little endian byte order. */
2824#ifdef RT_BIG_ENDIAN
2825# define RT_H2LE_U64_C(u64) RT_BSWAP_U64_C(u64)
2826#else
2827# define RT_H2LE_U64_C(u64) (u64)
2828#endif
2829
2830/** @def RT_H2LE_U32
2831 * Converts an uint32_t value from host to little endian byte order. */
2832#ifdef RT_BIG_ENDIAN
2833# define RT_H2LE_U32(u32) RT_BSWAP_U32(u32)
2834#else
2835# define RT_H2LE_U32(u32) (u32)
2836#endif
2837
2838/** @def RT_H2LE_U32_C
2839 * Converts an uint32_t constant from host to little endian byte order. */
2840#ifdef RT_BIG_ENDIAN
2841# define RT_H2LE_U32_C(u32) RT_BSWAP_U32_C(u32)
2842#else
2843# define RT_H2LE_U32_C(u32) (u32)
2844#endif
2845
2846/** @def RT_H2LE_U16
2847 * Converts an uint16_t value from host to little endian byte order. */
2848#ifdef RT_BIG_ENDIAN
2849# define RT_H2LE_U16(u16) RT_BSWAP_U16(u16)
2850#else
2851# define RT_H2LE_U16(u16) (u16)
2852#endif
2853
2854/** @def RT_H2LE_U16_C
2855 * Converts an uint16_t constant from host to little endian byte order. */
2856#ifdef RT_BIG_ENDIAN
2857# define RT_H2LE_U16_C(u16) RT_BSWAP_U16_C(u16)
2858#else
2859# define RT_H2LE_U16_C(u16) (u16)
2860#endif
2861
2862
2863/** @def RT_LE2H_U64
2864 * Converts an uint64_t value from little endian to host byte order. */
2865#ifdef RT_BIG_ENDIAN
2866# define RT_LE2H_U64(u64) RT_BSWAP_U64(u64)
2867#else
2868# define RT_LE2H_U64(u64) (u64)
2869#endif
2870
2871/** @def RT_LE2H_U64_C
2872 * Converts an uint64_t constant from little endian to host byte order. */
2873#ifdef RT_BIG_ENDIAN
2874# define RT_LE2H_U64_C(u64) RT_BSWAP_U64_C(u64)
2875#else
2876# define RT_LE2H_U64_C(u64) (u64)
2877#endif
2878
2879/** @def RT_LE2H_U32
2880 * Converts an uint32_t value from little endian to host byte order. */
2881#ifdef RT_BIG_ENDIAN
2882# define RT_LE2H_U32(u32) RT_BSWAP_U32(u32)
2883#else
2884# define RT_LE2H_U32(u32) (u32)
2885#endif
2886
2887/** @def RT_LE2H_U32_C
2888 * Converts an uint32_t constant from little endian to host byte order. */
2889#ifdef RT_BIG_ENDIAN
2890# define RT_LE2H_U32_C(u32) RT_BSWAP_U32_C(u32)
2891#else
2892# define RT_LE2H_U32_C(u32) (u32)
2893#endif
2894
2895/** @def RT_LE2H_U16
2896 * Converts an uint16_t value from little endian to host byte order. */
2897#ifdef RT_BIG_ENDIAN
2898# define RT_LE2H_U16(u16) RT_BSWAP_U16(u16)
2899#else
2900# define RT_LE2H_U16(u16) (u16)
2901#endif
2902
2903/** @def RT_LE2H_U16_C
2904 * Converts an uint16_t constant from little endian to host byte order. */
2905#ifdef RT_BIG_ENDIAN
2906# define RT_LE2H_U16_C(u16) RT_BSWAP_U16_C(u16)
2907#else
2908# define RT_LE2H_U16_C(u16) (u16)
2909#endif
2910
2911
2912/** @def RT_H2BE_U64
2913 * Converts an uint64_t value from host to big endian byte order. */
2914#ifdef RT_BIG_ENDIAN
2915# define RT_H2BE_U64(u64) (u64)
2916#else
2917# define RT_H2BE_U64(u64) RT_BSWAP_U64(u64)
2918#endif
2919
2920/** @def RT_H2BE_U64_C
2921 * Converts an uint64_t constant from host to big endian byte order. */
2922#ifdef RT_BIG_ENDIAN
2923# define RT_H2BE_U64_C(u64) (u64)
2924#else
2925# define RT_H2BE_U64_C(u64) RT_BSWAP_U64_C(u64)
2926#endif
2927
2928/** @def RT_H2BE_U32
2929 * Converts an uint32_t value from host to big endian byte order. */
2930#ifdef RT_BIG_ENDIAN
2931# define RT_H2BE_U32(u32) (u32)
2932#else
2933# define RT_H2BE_U32(u32) RT_BSWAP_U32(u32)
2934#endif
2935
2936/** @def RT_H2BE_U32_C
2937 * Converts an uint32_t constant from host to big endian byte order. */
2938#ifdef RT_BIG_ENDIAN
2939# define RT_H2BE_U32_C(u32) (u32)
2940#else
2941# define RT_H2BE_U32_C(u32) RT_BSWAP_U32_C(u32)
2942#endif
2943
2944/** @def RT_H2BE_U16
2945 * Converts an uint16_t value from host to big endian byte order. */
2946#ifdef RT_BIG_ENDIAN
2947# define RT_H2BE_U16(u16) (u16)
2948#else
2949# define RT_H2BE_U16(u16) RT_BSWAP_U16(u16)
2950#endif
2951
2952/** @def RT_H2BE_U16_C
2953 * Converts an uint16_t constant from host to big endian byte order. */
2954#ifdef RT_BIG_ENDIAN
2955# define RT_H2BE_U16_C(u16) (u16)
2956#else
2957# define RT_H2BE_U16_C(u16) RT_BSWAP_U16_C(u16)
2958#endif
2959
2960/** @def RT_BE2H_U64
2961 * Converts an uint64_t value from big endian to host byte order. */
2962#ifdef RT_BIG_ENDIAN
2963# define RT_BE2H_U64(u64) (u64)
2964#else
2965# define RT_BE2H_U64(u64) RT_BSWAP_U64(u64)
2966#endif
2967
2968/** @def RT_BE2H_U64
2969 * Converts an uint64_t constant from big endian to host byte order. */
2970#ifdef RT_BIG_ENDIAN
2971# define RT_BE2H_U64_C(u64) (u64)
2972#else
2973# define RT_BE2H_U64_C(u64) RT_BSWAP_U64_C(u64)
2974#endif
2975
2976/** @def RT_BE2H_U32
2977 * Converts an uint32_t value from big endian to host byte order. */
2978#ifdef RT_BIG_ENDIAN
2979# define RT_BE2H_U32(u32) (u32)
2980#else
2981# define RT_BE2H_U32(u32) RT_BSWAP_U32(u32)
2982#endif
2983
2984/** @def RT_BE2H_U32_C
2985 * Converts an uint32_t value from big endian to host byte order. */
2986#ifdef RT_BIG_ENDIAN
2987# define RT_BE2H_U32_C(u32) (u32)
2988#else
2989# define RT_BE2H_U32_C(u32) RT_BSWAP_U32_C(u32)
2990#endif
2991
2992/** @def RT_BE2H_U16
2993 * Converts an uint16_t value from big endian to host byte order. */
2994#ifdef RT_BIG_ENDIAN
2995# define RT_BE2H_U16(u16) (u16)
2996#else
2997# define RT_BE2H_U16(u16) RT_BSWAP_U16(u16)
2998#endif
2999
3000/** @def RT_BE2H_U16_C
3001 * Converts an uint16_t constant from big endian to host byte order. */
3002#ifdef RT_BIG_ENDIAN
3003# define RT_BE2H_U16_C(u16) (u16)
3004#else
3005# define RT_BE2H_U16_C(u16) RT_BSWAP_U16_C(u16)
3006#endif
3007
3008
3009/** @def RT_H2N_U64
3010 * Converts an uint64_t value from host to network byte order. */
3011#define RT_H2N_U64(u64) RT_H2BE_U64(u64)
3012
3013/** @def RT_H2N_U64_C
3014 * Converts an uint64_t constant from host to network byte order. */
3015#define RT_H2N_U64_C(u64) RT_H2BE_U64_C(u64)
3016
3017/** @def RT_H2N_U32
3018 * Converts an uint32_t value from host to network byte order. */
3019#define RT_H2N_U32(u32) RT_H2BE_U32(u32)
3020
3021/** @def RT_H2N_U32_C
3022 * Converts an uint32_t constant from host to network byte order. */
3023#define RT_H2N_U32_C(u32) RT_H2BE_U32_C(u32)
3024
3025/** @def RT_H2N_U16
3026 * Converts an uint16_t value from host to network byte order. */
3027#define RT_H2N_U16(u16) RT_H2BE_U16(u16)
3028
3029/** @def RT_H2N_U16_C
3030 * Converts an uint16_t constant from host to network byte order. */
3031#define RT_H2N_U16_C(u16) RT_H2BE_U16_C(u16)
3032
3033/** @def RT_N2H_U64
3034 * Converts an uint64_t value from network to host byte order. */
3035#define RT_N2H_U64(u64) RT_BE2H_U64(u64)
3036
3037/** @def RT_N2H_U64_C
3038 * Converts an uint64_t constant from network to host byte order. */
3039#define RT_N2H_U64_C(u64) RT_BE2H_U64_C(u64)
3040
3041/** @def RT_N2H_U32
3042 * Converts an uint32_t value from network to host byte order. */
3043#define RT_N2H_U32(u32) RT_BE2H_U32(u32)
3044
3045/** @def RT_N2H_U32_C
3046 * Converts an uint32_t constant from network to host byte order. */
3047#define RT_N2H_U32_C(u32) RT_BE2H_U32_C(u32)
3048
3049/** @def RT_N2H_U16
3050 * Converts an uint16_t value from network to host byte order. */
3051#define RT_N2H_U16(u16) RT_BE2H_U16(u16)
3052
3053/** @def RT_N2H_U16_C
3054 * Converts an uint16_t value from network to host byte order. */
3055#define RT_N2H_U16_C(u16) RT_BE2H_U16_C(u16)
3056
3057
3058/*
3059 * The BSD sys/param.h + machine/param.h file is a major source of
3060 * namespace pollution. Kill off some of the worse ones unless we're
3061 * compiling kernel code.
3062 */
3063#if defined(RT_OS_DARWIN) \
3064 && !defined(KERNEL) \
3065 && !defined(RT_NO_BSD_PARAM_H_UNDEFING) \
3066 && ( defined(_SYS_PARAM_H_) || defined(_I386_PARAM_H_) )
3067/* sys/param.h: */
3068# undef PSWP
3069# undef PVM
3070# undef PINOD
3071# undef PRIBO
3072# undef PVFS
3073# undef PZERO
3074# undef PSOCK
3075# undef PWAIT
3076# undef PLOCK
3077# undef PPAUSE
3078# undef PUSER
3079# undef PRIMASK
3080# undef MINBUCKET
3081# undef MAXALLOCSAVE
3082# undef FSHIFT
3083# undef FSCALE
3084
3085/* i386/machine.h: */
3086# undef ALIGN
3087# undef ALIGNBYTES
3088# undef DELAY
3089# undef STATUS_WORD
3090# undef USERMODE
3091# undef BASEPRI
3092# undef MSIZE
3093# undef CLSIZE
3094# undef CLSIZELOG2
3095#endif
3096
3097/** @def NIL_OFFSET
3098 * NIL offset.
3099 * Whenever we use offsets instead of pointers to save space and relocation effort
3100 * NIL_OFFSET shall be used as the equivalent to NULL.
3101 */
3102#define NIL_OFFSET (~0U)
3103
3104
3105/** @def NOREF
3106 * Keeps the compiler from bitching about an unused parameter, local variable,
3107 * or other stuff, will never use _Pragma are is thus more flexible.
3108 */
3109#define NOREF(var) (void)(var)
3110
3111/** @def RT_NOREF_PV
3112 * Keeps the compiler from bitching about an unused parameter or local variable.
3113 * This one cannot be used with structure members and such, like for instance
3114 * AssertRC may end up doing due to its generic nature.
3115 */
3116#if defined(__cplusplus) && RT_CLANG_PREREQ(6, 0)
3117# define RT_NOREF_PV(var) _Pragma(RT_STR(unused(var)))
3118#else
3119# define RT_NOREF_PV(var) (void)(var)
3120#endif
3121
3122/** @def RT_NOREF1
3123 * RT_NOREF_PV shorthand taking on parameter. */
3124#define RT_NOREF1(var1) RT_NOREF_PV(var1)
3125/** @def RT_NOREF2
3126 * RT_NOREF_PV shorthand taking two parameters. */
3127#define RT_NOREF2(var1, var2) RT_NOREF_PV(var1); RT_NOREF1(var2)
3128/** @def RT_NOREF3
3129 * RT_NOREF_PV shorthand taking three parameters. */
3130#define RT_NOREF3(var1, var2, var3) RT_NOREF_PV(var1); RT_NOREF2(var2, var3)
3131/** @def RT_NOREF4
3132 * RT_NOREF_PV shorthand taking four parameters. */
3133#define RT_NOREF4(var1, var2, var3, var4) RT_NOREF_PV(var1); RT_NOREF3(var2, var3, var4)
3134/** @def RT_NOREF5
3135 * RT_NOREF_PV shorthand taking five parameters. */
3136#define RT_NOREF5(var1, var2, var3, var4, var5) RT_NOREF_PV(var1); RT_NOREF4(var2, var3, var4, var5)
3137/** @def RT_NOREF6
3138 * RT_NOREF_PV shorthand taking six parameters. */
3139#define RT_NOREF6(var1, var2, var3, var4, var5, var6) RT_NOREF_PV(var1); RT_NOREF5(var2, var3, var4, var5, var6)
3140/** @def RT_NOREF7
3141 * RT_NOREF_PV shorthand taking seven parameters. */
3142#define RT_NOREF7(var1, var2, var3, var4, var5, var6, var7) \
3143 RT_NOREF_PV(var1); RT_NOREF6(var2, var3, var4, var5, var6, var7)
3144/** @def RT_NOREF8
3145 * RT_NOREF_PV shorthand taking eight parameters. */
3146#define RT_NOREF8(var1, var2, var3, var4, var5, var6, var7, var8) \
3147 RT_NOREF_PV(var1); RT_NOREF7(var2, var3, var4, var5, var6, var7, var8)
3148/** @def RT_NOREF9
3149 * RT_NOREF_PV shorthand taking nine parameters. */
3150#define RT_NOREF9(var1, var2, var3, var4, var5, var6, var7, var8, var9) \
3151 RT_NOREF_PV(var1); RT_NOREF8(var2, var3, var4, var5, var6, var7, var8, var9)
3152/** @def RT_NOREF10
3153 * RT_NOREF_PV shorthand taking ten parameters. */
3154#define RT_NOREF10(var1, var2, var3, var4, var5, var6, var7, var8, var9, var10) \
3155 RT_NOREF_PV(var1); RT_NOREF_PV(var2); RT_NOREF_PV(var3); RT_NOREF_PV(var4); RT_NOREF_PV(var5); RT_NOREF_PV(var6); \
3156 RT_NOREF_PV(var7); RT_NOREF_PV(var8); RT_NOREF_PV(var9); RT_NOREF_PV(var10)
3157/** @def RT_NOREF11
3158 * RT_NOREF_PV shorthand taking eleven parameters. */
3159#define RT_NOREF11(var1, var2, var3, var4, var5, var6, var7, var8, var9, var10, var11) \
3160 RT_NOREF_PV(var1); RT_NOREF10(var2, var3, var4, var5, var6, var7, var8, var9, var10)
3161/** @def RT_NOREF12
3162 * RT_NOREF_PV shorthand taking twelve parameters. */
3163#define RT_NOREF12(var1, var2, var3, var4, var5, var6, var7, var8, var9, var10, var11, var12) \
3164 RT_NOREF_PV(var1); RT_NOREF11(var2, var3, var4, var5, var6, var7, var8, var9, var10, var11, var12)
3165/** @def RT_NOREF13
3166 * RT_NOREF_PV shorthand taking thirteen parameters. */
3167#define RT_NOREF13(var1, var2, var3, var4, var5, var6, var7, var8, var9, var10, var11, var12, var13) \
3168 RT_NOREF_PV(var1); RT_NOREF12(var2, var3, var4, var5, var6, var7, var8, var9, var10, var11, var12, var13)
3169/** @def RT_NOREF14
3170 * RT_NOREF_PV shorthand taking fourteen parameters. */
3171#define RT_NOREF14(var1, var2, var3, var4, var5, var6, var7, var8, var9, var10, var11, var12, var13, var14) \
3172 RT_NOREF_PV(var1); RT_NOREF13(var2, var3, var4, var5, var6, var7, var8, var9, var10, var11, var12, var13, var14)
3173/** @def RT_NOREF15
3174 * RT_NOREF_PV shorthand taking fifteen parameters. */
3175#define RT_NOREF15(var1, var2, var3, var4, var5, var6, var7, var8, var9, var10, var11, var12, var13, var14, var15) \
3176 RT_NOREF_PV(var1); RT_NOREF14(var2, var3, var4, var5, var6, var7, var8, var9, var10, var11, var12, var13, var14, var15)
3177/** @def RT_NOREF16
3178 * RT_NOREF_PV shorthand taking fifteen parameters. */
3179#define RT_NOREF16(var1, var2, var3, var4, var5, var6, var7, var8, var9, var10, var11, var12, var13, var14, var15, var16) \
3180 RT_NOREF_PV(var1); RT_NOREF15(var2, var3, var4, var5, var6, var7, var8, var9, var10, var11, var12, var13, var14, var15, var16)
3181/** @def RT_NOREF17
3182 * RT_NOREF_PV shorthand taking seventeen parameters. */
3183#define RT_NOREF17(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17) \
3184 RT_NOREF_PV(v1); RT_NOREF16(v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17)
3185/** @def RT_NOREF18
3186 * RT_NOREF_PV shorthand taking eighteen parameters. */
3187#define RT_NOREF18(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18) \
3188 RT_NOREF_PV(v1); RT_NOREF17(v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18)
3189/** @def RT_NOREF19
3190 * RT_NOREF_PV shorthand taking nineteen parameters. */
3191#define RT_NOREF19(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19) \
3192 RT_NOREF_PV(v1); RT_NOREF18(v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19)
3193/** @def RT_NOREF20
3194 * RT_NOREF_PV shorthand taking twenty parameters. */
3195#define RT_NOREF20(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20) \
3196 RT_NOREF_PV(v1); RT_NOREF19(v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20)
3197/** @def RT_NOREF21
3198 * RT_NOREF_PV shorthand taking twentyone parameters. */
3199#define RT_NOREF21(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21) \
3200 RT_NOREF_PV(v1); RT_NOREF20(v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21)
3201/** @def RT_NOREF22
3202 * RT_NOREF_PV shorthand taking twentytwo parameters. */
3203#define RT_NOREF22(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22) \
3204 RT_NOREF_PV(v1); RT_NOREF21(v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22)
3205
3206/** @def RT_NOREF
3207 * RT_NOREF_PV variant using the variadic macro feature of C99.
3208 * @remarks Only use this in sources */
3209#ifdef RT_COMPILER_SUPPORTS_VA_ARGS
3210# define RT_NOREF(...) \
3211 RT_UNPACK_CALL(RT_CONCAT(RT_NOREF, RT_EXPAND(RT_COUNT_VA_ARGS(__VA_ARGS__))),(__VA_ARGS__))
3212#endif
3213
3214
3215/** @def RT_BREAKPOINT
3216 * Emit a debug breakpoint instruction.
3217 *
3218 * @remarks In the x86/amd64 gnu world we add a nop instruction after the int3
3219 * to force gdb to remain at the int3 source line.
3220 * @remarks The L4 kernel will try make sense of the breakpoint, thus the jmp on
3221 * x86/amd64.
3222 */
3223#ifdef __GNUC__
3224# if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
3225# if !defined(__L4ENV__)
3226# define RT_BREAKPOINT() __asm__ __volatile__("int $3\n\tnop\n\t")
3227# else
3228# define RT_BREAKPOINT() __asm__ __volatile__("int3; jmp 1f; 1:\n\t")
3229# endif
3230# elif defined(RT_ARCH_SPARC64)
3231# define RT_BREAKPOINT() __asm__ __volatile__("illtrap 0\n\t") /** @todo Sparc64: this is just a wild guess. */
3232# elif defined(RT_ARCH_SPARC)
3233# define RT_BREAKPOINT() __asm__ __volatile__("unimp 0\n\t") /** @todo Sparc: this is just a wild guess (same as Sparc64, just different name). */
3234# endif
3235#endif
3236#ifdef _MSC_VER
3237# define RT_BREAKPOINT() __debugbreak()
3238#endif
3239#if defined(__IBMC__) || defined(__IBMCPP__)
3240# define RT_BREAKPOINT() __interrupt(3)
3241#endif
3242#if defined(__WATCOMC__)
3243# define RT_BREAKPOINT() _asm { int 3 }
3244#endif
3245#ifndef RT_BREAKPOINT
3246# error "This compiler/arch is not supported!"
3247#endif
3248
3249
3250/** @defgroup grp_rt_cdefs_size Size Constants
3251 * (Of course, these are binary computer terms, not SI.)
3252 * @{
3253 */
3254/** 1 K (Kilo) (1 024). */
3255#define _1K 0x00000400
3256/** 2 K (Kilo) (2 048). */
3257#define _2K 0x00000800
3258/** 4 K (Kilo) (4 096). */
3259#define _4K 0x00001000
3260/** 8 K (Kilo) (8 192). */
3261#define _8K 0x00002000
3262/** 16 K (Kilo) (16 384). */
3263#define _16K 0x00004000
3264/** 32 K (Kilo) (32 768). */
3265#define _32K 0x00008000
3266/** 64 K (Kilo) (65 536). */
3267#if ARCH_BITS != 16
3268# define _64K 0x00010000
3269#else
3270# define _64K UINT32_C(0x00010000)
3271#endif
3272/** 128 K (Kilo) (131 072). */
3273#if ARCH_BITS != 16
3274# define _128K 0x00020000
3275#else
3276# define _128K UINT32_C(0x00020000)
3277#endif
3278/** 256 K (Kilo) (262 144). */
3279#if ARCH_BITS != 16
3280# define _256K 0x00040000
3281#else
3282# define _256K UINT32_C(0x00040000)
3283#endif
3284/** 512 K (Kilo) (524 288). */
3285#if ARCH_BITS != 16
3286# define _512K 0x00080000
3287#else
3288# define _512K UINT32_C(0x00080000)
3289#endif
3290/** 1 M (Mega) (1 048 576). */
3291#if ARCH_BITS != 16
3292# define _1M 0x00100000
3293#else
3294# define _1M UINT32_C(0x00100000)
3295#endif
3296/** 2 M (Mega) (2 097 152). */
3297#if ARCH_BITS != 16
3298# define _2M 0x00200000
3299#else
3300# define _2M UINT32_C(0x00200000)
3301#endif
3302/** 4 M (Mega) (4 194 304). */
3303#if ARCH_BITS != 16
3304# define _4M 0x00400000
3305#else
3306# define _4M UINT32_C(0x00400000)
3307#endif
3308/** 8 M (Mega) (8 388 608). */
3309#define _8M UINT32_C(0x00800000)
3310/** 16 M (Mega) (16 777 216). */
3311#define _16M UINT32_C(0x01000000)
3312/** 32 M (Mega) (33 554 432). */
3313#define _32M UINT32_C(0x02000000)
3314/** 64 M (Mega) (67 108 864). */
3315#define _64M UINT32_C(0x04000000)
3316/** 128 M (Mega) (134 217 728). */
3317#define _128M UINT32_C(0x08000000)
3318/** 256 M (Mega) (268 435 456). */
3319#define _256M UINT32_C(0x10000000)
3320/** 512 M (Mega) (536 870 912). */
3321#define _512M UINT32_C(0x20000000)
3322/** 1 G (Giga) (1 073 741 824). (32-bit) */
3323#if ARCH_BITS != 16
3324# define _1G 0x40000000
3325#else
3326# define _1G UINT32_C(0x40000000)
3327#endif
3328/** 1 G (Giga) (1 073 741 824). (64-bit) */
3329#if ARCH_BITS != 16
3330# define _1G64 0x40000000LL
3331#else
3332# define _1G64 UINT64_C(0x40000000)
3333#endif
3334/** 2 G (Giga) (2 147 483 648). (32-bit) */
3335#define _2G32 UINT32_C(0x80000000)
3336/** 2 G (Giga) (2 147 483 648). (64-bit) */
3337#if ARCH_BITS != 16
3338# define _2G 0x0000000080000000LL
3339#else
3340# define _2G UINT64_C(0x0000000080000000)
3341#endif
3342/** 4 G (Giga) (4 294 967 296). */
3343#if ARCH_BITS != 16
3344# define _4G 0x0000000100000000LL
3345#else
3346# define _4G UINT64_C(0x0000000100000000)
3347#endif
3348/** 1 T (Tera) (1 099 511 627 776). */
3349#if ARCH_BITS != 16
3350# define _1T 0x0000010000000000LL
3351#else
3352# define _1T UINT64_C(0x0000010000000000)
3353#endif
3354/** 1 P (Peta) (1 125 899 906 842 624). */
3355#if ARCH_BITS != 16
3356# define _1P 0x0004000000000000LL
3357#else
3358# define _1P UINT64_C(0x0004000000000000)
3359#endif
3360/** 1 E (Exa) (1 152 921 504 606 846 976). */
3361#if ARCH_BITS != 16
3362# define _1E 0x1000000000000000LL
3363#else
3364# define _1E UINT64_C(0x1000000000000000)
3365#endif
3366/** 2 E (Exa) (2 305 843 009 213 693 952). */
3367#if ARCH_BITS != 16
3368# define _2E 0x2000000000000000ULL
3369#else
3370# define _2E UINT64_C(0x2000000000000000)
3371#endif
3372/** @} */
3373
3374/** @defgroup grp_rt_cdefs_decimal_grouping Decimal Constant Grouping Macros
3375 * @{ */
3376#define RT_D1(g1) g1
3377#define RT_D2(g1, g2) g1#g2
3378#define RT_D3(g1, g2, g3) g1#g2#g3
3379#define RT_D4(g1, g2, g3, g4) g1#g2#g3#g4
3380#define RT_D5(g1, g2, g3, g4, g5) g1#g2#g3#g4#g5
3381#define RT_D6(g1, g2, g3, g4, g5, g6) g1#g2#g3#g4#g5#g6
3382#define RT_D7(g1, g2, g3, g4, g5, g6, g7) g1#g2#g3#g4#g5#g6#g7
3383
3384#define RT_D1_U(g1) UINT32_C(g1)
3385#define RT_D2_U(g1, g2) UINT32_C(g1#g2)
3386#define RT_D3_U(g1, g2, g3) UINT32_C(g1#g2#g3)
3387#define RT_D4_U(g1, g2, g3, g4) UINT64_C(g1#g2#g3#g4)
3388#define RT_D5_U(g1, g2, g3, g4, g5) UINT64_C(g1#g2#g3#g4#g5)
3389#define RT_D6_U(g1, g2, g3, g4, g5, g6) UINT64_C(g1#g2#g3#g4#g5#g6)
3390#define RT_D7_U(g1, g2, g3, g4, g5, g6, g7) UINT64_C(g1#g2#g3#g4#g5#g6#g7)
3391
3392#define RT_D1_S(g1) INT32_C(g1)
3393#define RT_D2_S(g1, g2) INT32_C(g1#g2)
3394#define RT_D3_S(g1, g2, g3) INT32_C(g1#g2#g3)
3395#define RT_D4_S(g1, g2, g3, g4) INT64_C(g1#g2#g3#g4)
3396#define RT_D5_S(g1, g2, g3, g4, g5) INT64_C(g1#g2#g3#g4#g5)
3397#define RT_D6_S(g1, g2, g3, g4, g5, g6) INT64_C(g1#g2#g3#g4#g5#g6)
3398#define RT_D7_S(g1, g2, g3, g4, g5, g6, g7) INT64_C(g1#g2#g3#g4#g5#g6#g7)
3399
3400#define RT_D1_U32(g1) UINT32_C(g1)
3401#define RT_D2_U32(g1, g2) UINT32_C(g1#g2)
3402#define RT_D3_U32(g1, g2, g3) UINT32_C(g1#g2#g3)
3403#define RT_D4_U32(g1, g2, g3, g4) UINT32_C(g1#g2#g3#g4)
3404
3405#define RT_D1_S32(g1) INT32_C(g1)
3406#define RT_D2_S32(g1, g2) INT32_C(g1#g2)
3407#define RT_D3_S32(g1, g2, g3) INT32_C(g1#g2#g3)
3408#define RT_D4_S32(g1, g2, g3, g4) INT32_C(g1#g2#g3#g4)
3409
3410#define RT_D1_U64(g1) UINT64_C(g1)
3411#define RT_D2_U64(g1, g2) UINT64_C(g1#g2)
3412#define RT_D3_U64(g1, g2, g3) UINT64_C(g1#g2#g3)
3413#define RT_D4_U64(g1, g2, g3, g4) UINT64_C(g1#g2#g3#g4)
3414#define RT_D5_U64(g1, g2, g3, g4, g5) UINT64_C(g1#g2#g3#g4#g5)
3415#define RT_D6_U64(g1, g2, g3, g4, g5, g6) UINT64_C(g1#g2#g3#g4#g5#g6)
3416#define RT_D7_U64(g1, g2, g3, g4, g5, g6, g7) UINT64_C(g1#g2#g3#g4#g5#g6#g7)
3417
3418#define RT_D1_S64(g1) INT64_C(g1)
3419#define RT_D2_S64(g1, g2) INT64_C(g1#g2)
3420#define RT_D3_S64(g1, g2, g3) INT64_C(g1#g2#g3)
3421#define RT_D4_S64(g1, g2, g3, g4) INT64_C(g1#g2#g3#g4)
3422#define RT_D5_S64(g1, g2, g3, g4, g5) INT64_C(g1#g2#g3#g4#g5)
3423#define RT_D6_S64(g1, g2, g3, g4, g5, g6) INT64_C(g1#g2#g3#g4#g5#g6)
3424#define RT_D7_S64(g1, g2, g3, g4, g5, g6, g7) INT64_C(g1#g2#g3#g4#g5#g6#g7)
3425/** @} */
3426
3427
3428/** @defgroup grp_rt_cdefs_time Time Constants
3429 * @{
3430 */
3431/** 1 hour expressed in nanoseconds (64-bit). */
3432#define RT_NS_1HOUR UINT64_C(3600000000000)
3433/** 1 minute expressed in nanoseconds (64-bit). */
3434#define RT_NS_1MIN UINT64_C(60000000000)
3435/** 45 second expressed in nanoseconds. */
3436#define RT_NS_45SEC UINT64_C(45000000000)
3437/** 30 second expressed in nanoseconds. */
3438#define RT_NS_30SEC UINT64_C(30000000000)
3439/** 20 second expressed in nanoseconds. */
3440#define RT_NS_20SEC UINT64_C(20000000000)
3441/** 15 second expressed in nanoseconds. */
3442#define RT_NS_15SEC UINT64_C(15000000000)
3443/** 10 second expressed in nanoseconds. */
3444#define RT_NS_10SEC UINT64_C(10000000000)
3445/** 1 second expressed in nanoseconds. */
3446#define RT_NS_1SEC UINT32_C(1000000000)
3447/** 100 millsecond expressed in nanoseconds. */
3448#define RT_NS_100MS UINT32_C(100000000)
3449/** 10 millsecond expressed in nanoseconds. */
3450#define RT_NS_10MS UINT32_C(10000000)
3451/** 1 millsecond expressed in nanoseconds. */
3452#define RT_NS_1MS UINT32_C(1000000)
3453/** 100 microseconds expressed in nanoseconds. */
3454#define RT_NS_100US UINT32_C(100000)
3455/** 10 microseconds expressed in nanoseconds. */
3456#define RT_NS_10US UINT32_C(10000)
3457/** 1 microsecond expressed in nanoseconds. */
3458#define RT_NS_1US UINT32_C(1000)
3459
3460/** 1 second expressed in nanoseconds - 64-bit type. */
3461#define RT_NS_1SEC_64 UINT64_C(1000000000)
3462/** 100 millsecond expressed in nanoseconds - 64-bit type. */
3463#define RT_NS_100MS_64 UINT64_C(100000000)
3464/** 10 millsecond expressed in nanoseconds - 64-bit type. */
3465#define RT_NS_10MS_64 UINT64_C(10000000)
3466/** 1 millsecond expressed in nanoseconds - 64-bit type. */
3467#define RT_NS_1MS_64 UINT64_C(1000000)
3468/** 100 microseconds expressed in nanoseconds - 64-bit type. */
3469#define RT_NS_100US_64 UINT64_C(100000)
3470/** 10 microseconds expressed in nanoseconds - 64-bit type. */
3471#define RT_NS_10US_64 UINT64_C(10000)
3472/** 1 microsecond expressed in nanoseconds - 64-bit type. */
3473#define RT_NS_1US_64 UINT64_C(1000)
3474
3475/** 1 hour expressed in microseconds. */
3476#define RT_US_1HOUR UINT32_C(3600000000)
3477/** 1 minute expressed in microseconds. */
3478#define RT_US_1MIN UINT32_C(60000000)
3479/** 1 second expressed in microseconds. */
3480#define RT_US_1SEC UINT32_C(1000000)
3481/** 100 millsecond expressed in microseconds. */
3482#define RT_US_100MS UINT32_C(100000)
3483/** 10 millsecond expressed in microseconds. */
3484#define RT_US_10MS UINT32_C(10000)
3485/** 1 millsecond expressed in microseconds. */
3486#define RT_US_1MS UINT32_C(1000)
3487
3488/** 1 hour expressed in microseconds - 64-bit type. */
3489#define RT_US_1HOUR_64 UINT64_C(3600000000)
3490/** 1 minute expressed in microseconds - 64-bit type. */
3491#define RT_US_1MIN_64 UINT64_C(60000000)
3492/** 1 second expressed in microseconds - 64-bit type. */
3493#define RT_US_1SEC_64 UINT64_C(1000000)
3494/** 100 millsecond expressed in microseconds - 64-bit type. */
3495#define RT_US_100MS_64 UINT64_C(100000)
3496/** 10 millsecond expressed in microseconds - 64-bit type. */
3497#define RT_US_10MS_64 UINT64_C(10000)
3498/** 1 millsecond expressed in microseconds - 64-bit type. */
3499#define RT_US_1MS_64 UINT64_C(1000)
3500
3501/** 1 hour expressed in milliseconds. */
3502#define RT_MS_1HOUR UINT32_C(3600000)
3503/** 1 minute expressed in milliseconds. */
3504#define RT_MS_1MIN UINT32_C(60000)
3505/** 1 second expressed in milliseconds. */
3506#define RT_MS_1SEC UINT32_C(1000)
3507
3508/** 1 hour expressed in milliseconds - 64-bit type. */
3509#define RT_MS_1HOUR_64 UINT64_C(3600000)
3510/** 1 minute expressed in milliseconds - 64-bit type. */
3511#define RT_MS_1MIN_64 UINT64_C(60000)
3512/** 1 second expressed in milliseconds - 64-bit type. */
3513#define RT_MS_1SEC_64 UINT64_C(1000)
3514
3515/** The number of seconds per week. */
3516#define RT_SEC_1WEEK UINT32_C(604800)
3517/** The number of seconds per day. */
3518#define RT_SEC_1DAY UINT32_C(86400)
3519/** The number of seconds per hour. */
3520#define RT_SEC_1HOUR UINT32_C(3600)
3521
3522/** The number of seconds per week - 64-bit type. */
3523#define RT_SEC_1WEEK_64 UINT64_C(604800)
3524/** The number of seconds per day - 64-bit type. */
3525#define RT_SEC_1DAY_64 UINT64_C(86400)
3526/** The number of seconds per hour - 64-bit type. */
3527#define RT_SEC_1HOUR_64 UINT64_C(3600)
3528/** @} */
3529
3530
3531/** @defgroup grp_rt_cdefs_dbgtype Debug Info Types
3532 * @{ */
3533/** Other format. */
3534#define RT_DBGTYPE_OTHER RT_BIT_32(0)
3535/** Stabs. */
3536#define RT_DBGTYPE_STABS RT_BIT_32(1)
3537/** Debug With Arbitrary Record Format (DWARF). */
3538#define RT_DBGTYPE_DWARF RT_BIT_32(2)
3539/** Microsoft Codeview debug info. */
3540#define RT_DBGTYPE_CODEVIEW RT_BIT_32(3)
3541/** Watcom debug info. */
3542#define RT_DBGTYPE_WATCOM RT_BIT_32(4)
3543/** IBM High Level Language debug info. */
3544#define RT_DBGTYPE_HLL RT_BIT_32(5)
3545/** Old OS/2 and Windows symbol file. */
3546#define RT_DBGTYPE_SYM RT_BIT_32(6)
3547/** Map file. */
3548#define RT_DBGTYPE_MAP RT_BIT_32(7)
3549/** @} */
3550
3551
3552/** @defgroup grp_rt_cdefs_exetype Executable Image Types
3553 * @{ */
3554/** Some other format. */
3555#define RT_EXETYPE_OTHER RT_BIT_32(0)
3556/** Portable Executable. */
3557#define RT_EXETYPE_PE RT_BIT_32(1)
3558/** Linear eXecutable. */
3559#define RT_EXETYPE_LX RT_BIT_32(2)
3560/** Linear Executable. */
3561#define RT_EXETYPE_LE RT_BIT_32(3)
3562/** New Executable. */
3563#define RT_EXETYPE_NE RT_BIT_32(4)
3564/** DOS Executable (Mark Zbikowski). */
3565#define RT_EXETYPE_MZ RT_BIT_32(5)
3566/** COM Executable. */
3567#define RT_EXETYPE_COM RT_BIT_32(6)
3568/** a.out Executable. */
3569#define RT_EXETYPE_AOUT RT_BIT_32(7)
3570/** Executable and Linkable Format. */
3571#define RT_EXETYPE_ELF RT_BIT_32(8)
3572/** Mach-O Executable (including FAT ones). */
3573#define RT_EXETYPE_MACHO RT_BIT_32(9)
3574/** TE from UEFI. */
3575#define RT_EXETYPE_TE RT_BIT_32(9)
3576/** @} */
3577
3578
3579/** @def VALID_PTR
3580 * Pointer validation macro.
3581 * @param ptr The pointer.
3582 */
3583#if defined(RT_ARCH_AMD64)
3584# ifdef IN_RING3
3585# if defined(RT_OS_DARWIN) /* first 4GB is reserved for legacy kernel. */
3586# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) >= _4G \
3587 && !((uintptr_t)(ptr) & 0xffff800000000000ULL) )
3588# elif defined(RT_OS_SOLARIS) /* The kernel only used the top 2TB, but keep it simple. */
3589# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
3590 && ( ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0xffff800000000000ULL \
3591 || ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0) )
3592# else
3593# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
3594 && !((uintptr_t)(ptr) & 0xffff800000000000ULL) )
3595# endif
3596# else /* !IN_RING3 */
3597# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
3598 && ( ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0xffff800000000000ULL \
3599 || ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0) )
3600# endif /* !IN_RING3 */
3601
3602#elif defined(RT_ARCH_X86)
3603# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U )
3604
3605#elif defined(RT_ARCH_SPARC64)
3606# ifdef IN_RING3
3607# if defined(RT_OS_SOLARIS)
3608/** Sparc64 user mode: According to Figure 9.4 in solaris internals */
3609/** @todo # define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x80004000U >= 0x80004000U + 0x100000000ULL ) - figure this. */
3610# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x80000000U >= 0x80000000U + 0x100000000ULL )
3611# else
3612# error "Port me"
3613# endif
3614# else /* !IN_RING3 */
3615# if defined(RT_OS_SOLARIS)
3616/** @todo Sparc64 kernel mode: This is according to Figure 11.1 in solaris
3617 * internals. Verify in sources. */
3618# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) >= 0x01000000U )
3619# else
3620# error "Port me"
3621# endif
3622# endif /* !IN_RING3 */
3623
3624#elif defined(RT_ARCH_SPARC)
3625# ifdef IN_RING3
3626# ifdef RT_OS_SOLARIS
3627/** Sparc user mode: According to
3628 * http://cvs.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/uts/sun4/os/startup.c#510 */
3629# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x400000U >= 0x400000U + 0x2000U )
3630
3631# else
3632# error "Port me"
3633# endif
3634# else /* !IN_RING3 */
3635# ifdef RT_OS_SOLARIS
3636/** @todo Sparc kernel mode: Check the sources! */
3637# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U )
3638# else
3639# error "Port me"
3640# endif
3641# endif /* !IN_RING3 */
3642
3643#elif defined(RT_ARCH_ARM)
3644/* ASSUMES that at least the last and first 4K are out of bounds. */
3645# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U )
3646
3647#else
3648# error "Architecture identifier missing / not implemented."
3649#endif
3650
3651/** Old name for RT_VALID_PTR. */
3652#define VALID_PTR(ptr) RT_VALID_PTR(ptr)
3653
3654/** @def RT_VALID_ALIGNED_PTR
3655 * Pointer validation macro that also checks the alignment.
3656 * @param ptr The pointer.
3657 * @param align The alignment, must be a power of two.
3658 */
3659#define RT_VALID_ALIGNED_PTR(ptr, align) \
3660 ( !((uintptr_t)(ptr) & (uintptr_t)((align) - 1)) \
3661 && VALID_PTR(ptr) )
3662
3663
3664/** @def VALID_PHYS32
3665 * 32 bits physical address validation macro.
3666 * @param Phys The RTGCPHYS address.
3667 */
3668#define VALID_PHYS32(Phys) ( (uint64_t)(Phys) < (uint64_t)_4G )
3669
3670/** @def N_
3671 * The \#define N_ is used to mark a string for translation. This is usable in
3672 * any part of the code, as it is only used by the tools that create message
3673 * catalogs. This macro is a no-op as far as the compiler and code generation
3674 * is concerned.
3675 *
3676 * If you want to both mark a string for translation and translate it, use _().
3677 */
3678#define N_(s) (s)
3679
3680/** @def _
3681 * The \#define _ is used to mark a string for translation and to translate it
3682 * in one step.
3683 *
3684 * If you want to only mark a string for translation, use N_().
3685 */
3686#define _(s) gettext(s)
3687
3688
3689/** @def __PRETTY_FUNCTION__
3690 * With GNU C we'd like to use the builtin __PRETTY_FUNCTION__, so define that
3691 * for the other compilers.
3692 */
3693#if !defined(__GNUC__) && !defined(__PRETTY_FUNCTION__)
3694# ifdef _MSC_VER
3695# define __PRETTY_FUNCTION__ __FUNCSIG__
3696# else
3697# define __PRETTY_FUNCTION__ __FUNCTION__
3698# endif
3699#endif
3700
3701
3702/** @def RT_STRICT
3703 * The \#define RT_STRICT controls whether or not assertions and other runtime
3704 * checks should be compiled in or not. This is defined when DEBUG is defined.
3705 * If RT_NO_STRICT is defined, it will unconditionally be undefined.
3706 *
3707 * If you want assertions which are not subject to compile time options use
3708 * the AssertRelease*() flavors.
3709 */
3710#if !defined(RT_STRICT) && defined(DEBUG)
3711# define RT_STRICT
3712#endif
3713#ifdef RT_NO_STRICT
3714# undef RT_STRICT
3715#endif
3716
3717/** @todo remove this: */
3718#if !defined(RT_LOCK_STRICT) && !defined(DEBUG_bird)
3719# define RT_LOCK_NO_STRICT
3720#endif
3721#if !defined(RT_LOCK_STRICT_ORDER) && !defined(DEBUG_bird)
3722# define RT_LOCK_NO_STRICT_ORDER
3723#endif
3724
3725/** @def RT_LOCK_STRICT
3726 * The \#define RT_LOCK_STRICT controls whether deadlock detection and related
3727 * checks are done in the lock and semaphore code. It is by default enabled in
3728 * RT_STRICT builds, but this behavior can be overridden by defining
3729 * RT_LOCK_NO_STRICT. */
3730#if !defined(RT_LOCK_STRICT) && !defined(RT_LOCK_NO_STRICT) && defined(RT_STRICT)
3731# define RT_LOCK_STRICT
3732#endif
3733/** @def RT_LOCK_NO_STRICT
3734 * The \#define RT_LOCK_NO_STRICT disables RT_LOCK_STRICT. */
3735#if defined(RT_LOCK_NO_STRICT) && defined(RT_LOCK_STRICT)
3736# undef RT_LOCK_STRICT
3737#endif
3738
3739/** @def RT_LOCK_STRICT_ORDER
3740 * The \#define RT_LOCK_STRICT_ORDER controls whether locking order is checked
3741 * by the lock and semaphore code. It is by default enabled in RT_STRICT
3742 * builds, but this behavior can be overridden by defining
3743 * RT_LOCK_NO_STRICT_ORDER. */
3744#if !defined(RT_LOCK_STRICT_ORDER) && !defined(RT_LOCK_NO_STRICT_ORDER) && defined(RT_STRICT)
3745# define RT_LOCK_STRICT_ORDER
3746#endif
3747/** @def RT_LOCK_NO_STRICT_ORDER
3748 * The \#define RT_LOCK_NO_STRICT_ORDER disables RT_LOCK_STRICT_ORDER. */
3749#if defined(RT_LOCK_NO_STRICT_ORDER) && defined(RT_LOCK_STRICT_ORDER)
3750# undef RT_LOCK_STRICT_ORDER
3751#endif
3752
3753
3754/** Source position. */
3755#define RT_SRC_POS __FILE__, __LINE__, RT_GCC_EXTENSION __PRETTY_FUNCTION__
3756
3757/** Source position declaration. */
3758#define RT_SRC_POS_DECL const char *pszFile, unsigned iLine, const char *pszFunction
3759
3760/** Source position arguments. */
3761#define RT_SRC_POS_ARGS pszFile, iLine, pszFunction
3762
3763/** Applies NOREF() to the source position arguments. */
3764#define RT_SRC_POS_NOREF() do { NOREF(pszFile); NOREF(iLine); NOREF(pszFunction); } while (0)
3765
3766
3767/** @def RT_INLINE_ASM_EXTERNAL
3768 * Defined as 1 if the compiler does not support inline assembly.
3769 * The ASM* functions will then be implemented in external .asm files.
3770 */
3771#if (defined(_MSC_VER) && defined(RT_ARCH_AMD64)) \
3772 || (!defined(RT_ARCH_AMD64) && !defined(RT_ARCH_X86)) \
3773 || defined(__WATCOMC__)
3774# define RT_INLINE_ASM_EXTERNAL 1
3775#else
3776# define RT_INLINE_ASM_EXTERNAL 0
3777#endif
3778
3779/** @def RT_INLINE_ASM_GNU_STYLE
3780 * Defined as 1 if the compiler understands GNU style inline assembly.
3781 */
3782#if defined(_MSC_VER) || defined(__WATCOMC__)
3783# define RT_INLINE_ASM_GNU_STYLE 0
3784#else
3785# define RT_INLINE_ASM_GNU_STYLE 1
3786#endif
3787
3788/** @def RT_INLINE_ASM_USES_INTRIN
3789 * Defined as the major MSC version if the compiler have and uses intrin.h.
3790 * Otherwise it is 0. */
3791#ifdef _MSC_VER
3792# if _MSC_VER >= 1700 /* Visual C++ v11.0 / 2012 */
3793# define RT_INLINE_ASM_USES_INTRIN 17
3794# elif _MSC_VER >= 1600 /* Visual C++ v10.0 / 2010 */
3795# define RT_INLINE_ASM_USES_INTRIN 16
3796# elif _MSC_VER >= 1500 /* Visual C++ v9.0 / 2008 */
3797# define RT_INLINE_ASM_USES_INTRIN 15
3798# elif _MSC_VER >= 1400 /* Visual C++ v8.0 / 2005 */
3799# define RT_INLINE_ASM_USES_INTRIN 14
3800# endif
3801#endif
3802#ifndef RT_INLINE_ASM_USES_INTRIN
3803# define RT_INLINE_ASM_USES_INTRIN 0
3804#endif
3805
3806/** @def RT_COMPILER_SUPPORTS_LAMBDA
3807 * If the defined, the compiler supports lambda expressions. These expressions
3808 * are useful for embedding assertions and type checks into macros. */
3809#if defined(_MSC_VER) && defined(__cplusplus)
3810# if _MSC_VER >= 1600 /* Visual C++ v10.0 / 2010 */
3811# define RT_COMPILER_SUPPORTS_LAMBDA
3812# endif
3813#elif defined(__GNUC__) && defined(__cplusplus)
3814/* 4.5 or later, I think, if in ++11 mode... */
3815#endif
3816
3817/** @def RT_DATA_IS_FAR
3818 * Set to 1 if we're in 16-bit mode and use far pointers.
3819 */
3820#if ARCH_BITS == 16 && defined(__WATCOMC__) \
3821 && (defined(__COMPACT__) || defined(__LARGE__))
3822# define RT_DATA_IS_FAR 1
3823#else
3824# define RT_DATA_IS_FAR 0
3825#endif
3826
3827/** @def RT_FAR
3828 * For indicating far pointers in 16-bit code.
3829 * Does nothing in 32-bit and 64-bit code. */
3830/** @def RT_NEAR
3831 * For indicating near pointers in 16-bit code.
3832 * Does nothing in 32-bit and 64-bit code. */
3833/** @def RT_FAR_CODE
3834 * For indicating far 16-bit functions.
3835 * Does nothing in 32-bit and 64-bit code. */
3836/** @def RT_NEAR_CODE
3837 * For indicating near 16-bit functions.
3838 * Does nothing in 32-bit and 64-bit code. */
3839/** @def RT_FAR_DATA
3840 * For indicating far 16-bit external data, i.e. in a segment other than DATA16.
3841 * Does nothing in 32-bit and 64-bit code. */
3842#if ARCH_BITS == 16
3843# define RT_FAR __far
3844# define RT_NEAR __near
3845# define RT_FAR_CODE __far
3846# define RT_NEAR_CODE __near
3847# define RT_FAR_DATA __far
3848#else
3849# define RT_FAR
3850# define RT_NEAR
3851# define RT_FAR_CODE
3852# define RT_NEAR_CODE
3853# define RT_FAR_DATA
3854#endif
3855
3856
3857/** @} */
3858
3859
3860/** @defgroup grp_rt_cdefs_cpp Special Macros for C++
3861 * @ingroup grp_rt_cdefs
3862 * @{
3863 */
3864
3865#ifdef __cplusplus
3866
3867/** @def DECLEXPORT_CLASS
3868 * How to declare an exported class. Place this macro after the 'class'
3869 * keyword in the declaration of every class you want to export.
3870 *
3871 * @note It is necessary to use this macro even for inner classes declared
3872 * inside the already exported classes. This is a GCC specific requirement,
3873 * but it seems not to harm other compilers.
3874 */
3875#if defined(_MSC_VER) || defined(RT_OS_OS2)
3876# define DECLEXPORT_CLASS __declspec(dllexport)
3877#elif defined(RT_USE_VISIBILITY_DEFAULT)
3878# define DECLEXPORT_CLASS __attribute__((visibility("default")))
3879#else
3880# define DECLEXPORT_CLASS
3881#endif
3882
3883/** @def DECLIMPORT_CLASS
3884 * How to declare an imported class Place this macro after the 'class'
3885 * keyword in the declaration of every class you want to export.
3886 *
3887 * @note It is necessary to use this macro even for inner classes declared
3888 * inside the already exported classes. This is a GCC specific requirement,
3889 * but it seems not to harm other compilers.
3890 */
3891#if defined(_MSC_VER) || (defined(RT_OS_OS2) && !defined(__IBMC__) && !defined(__IBMCPP__))
3892# define DECLIMPORT_CLASS __declspec(dllimport)
3893#elif defined(RT_USE_VISIBILITY_DEFAULT)
3894# define DECLIMPORT_CLASS __attribute__((visibility("default")))
3895#else
3896# define DECLIMPORT_CLASS
3897#endif
3898
3899/** @def WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP
3900 * Macro to work around error C2593 of the not-so-smart MSVC 7.x ambiguity
3901 * resolver. The following snippet clearly demonstrates the code causing this
3902 * error:
3903 * @code
3904 * class A
3905 * {
3906 * public:
3907 * operator bool() const { return false; }
3908 * operator int*() const { return NULL; }
3909 * };
3910 * int main()
3911 * {
3912 * A a;
3913 * if (!a);
3914 * if (a && 0);
3915 * return 0;
3916 * }
3917 * @endcode
3918 * The code itself seems pretty valid to me and GCC thinks the same.
3919 *
3920 * This macro fixes the compiler error by explicitly overloading implicit
3921 * global operators !, && and || that take the given class instance as one of
3922 * their arguments.
3923 *
3924 * The best is to use this macro right after the class declaration.
3925 *
3926 * @note The macro expands to nothing for compilers other than MSVC.
3927 *
3928 * @param Cls Class to apply the workaround to
3929 */
3930#if defined(_MSC_VER)
3931# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP(Cls) \
3932 inline bool operator! (const Cls &that) { return !bool (that); } \
3933 inline bool operator&& (const Cls &that, bool b) { return bool (that) && b; } \
3934 inline bool operator|| (const Cls &that, bool b) { return bool (that) || b; } \
3935 inline bool operator&& (bool b, const Cls &that) { return b && bool (that); } \
3936 inline bool operator|| (bool b, const Cls &that) { return b || bool (that); }
3937#else
3938# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP(Cls)
3939#endif
3940
3941/** @def WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL
3942 * Version of WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP for template classes.
3943 *
3944 * @param Tpl Name of the template class to apply the workaround to
3945 * @param ArgsDecl arguments of the template, as declared in |<>| after the
3946 * |template| keyword, including |<>|
3947 * @param Args arguments of the template, as specified in |<>| after the
3948 * template class name when using the, including |<>|
3949 *
3950 * Example:
3951 * @code
3952 * // template class declaration
3953 * template <class C>
3954 * class Foo { ... };
3955 * // applied workaround
3956 * WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL (Foo, <class C>, <C>)
3957 * @endcode
3958 */
3959#if defined(_MSC_VER)
3960# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL(Tpl, ArgsDecl, Args) \
3961 template ArgsDecl \
3962 inline bool operator! (const Tpl Args &that) { return !bool (that); } \
3963 template ArgsDecl \
3964 inline bool operator&& (const Tpl Args &that, bool b) { return bool (that) && b; } \
3965 template ArgsDecl \
3966 inline bool operator|| (const Tpl Args &that, bool b) { return bool (that) || b; } \
3967 template ArgsDecl \
3968 inline bool operator&& (bool b, const Tpl Args &that) { return b && bool (that); } \
3969 template ArgsDecl \
3970 inline bool operator|| (bool b, const Tpl Args &that) { return b || bool (that); }
3971#else
3972# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL(Tpl, ArgsDecl, Args)
3973#endif
3974
3975
3976/** @def DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP
3977 * Declares the copy constructor and the assignment operation as inlined no-ops
3978 * (non-existent functions) for the given class. Use this macro inside the
3979 * private section if you want to effectively disable these operations for your
3980 * class.
3981 *
3982 * @param Cls class name to declare for
3983 */
3984#define DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(Cls) \
3985 inline Cls(const Cls &); \
3986 inline Cls &operator= (const Cls &)
3987
3988
3989/** @def DECLARE_CLS_NEW_DELETE_NOOP
3990 * Declares the new and delete operations as no-ops (non-existent functions)
3991 * for the given class. Use this macro inside the private section if you want
3992 * to effectively limit creating class instances on the stack only.
3993 *
3994 * @note The destructor of the given class must not be virtual, otherwise a
3995 * compile time error will occur. Note that this is not a drawback: having
3996 * the virtual destructor for a stack-based class is absolutely useless
3997 * (the real class of the stack-based instance is always known to the compiler
3998 * at compile time, so it will always call the correct destructor).
3999 *
4000 * @param Cls class name to declare for
4001 */
4002#define DECLARE_CLS_NEW_DELETE_NOOP(Cls) \
4003 inline static void *operator new (size_t); \
4004 inline static void operator delete (void *)
4005
4006#endif /* __cplusplus */
4007
4008/** @} */
4009
4010#endif
4011
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette