VirtualBox

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

Last change on this file was 106565, checked in by vboxsync, 5 weeks ago

IPRT: Sort out export/import trouble with 'inline-assembly' functions implemented in C++ on windows by introducing a RT_DECL_ASM() macro that combines RTDECL with DECLASM. [scm] jiraref:VBP-1171

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 211.4 KB
Line 
1/** @file
2 * IPRT - Common C and C++ definitions.
3 */
4
5/*
6 * Copyright (C) 2006-2024 Oracle and/or its affiliates.
7 *
8 * This file is part of VirtualBox base platform packages, as
9 * available from https://www.virtualbox.org.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation, in version 3 of the
14 * License.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <https://www.gnu.org/licenses>.
23 *
24 * The contents of this file may alternatively be used under the terms
25 * of the Common Development and Distribution License Version 1.0
26 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
27 * in the VirtualBox distribution, in which case the provisions of the
28 * CDDL are applicable instead of those of the GPL.
29 *
30 * You may elect to license modified versions of this file under the
31 * terms and conditions of either the GPL or the CDDL or both.
32 *
33 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
34 */
35
36#ifndef IPRT_INCLUDED_cdefs_h
37#define IPRT_INCLUDED_cdefs_h
38#ifndef RT_WITHOUT_PRAGMA_ONCE
39# pragma once
40#endif
41
42
43/** @defgroup grp_rt_cdefs IPRT Common Definitions and Macros
44 * @{
45 */
46
47/** @def RT_C_DECLS_BEGIN
48 * Used to start a block of function declarations which are shared
49 * between C and C++ program.
50 */
51
52/** @def RT_C_DECLS_END
53 * Used to end a block of function declarations which are shared
54 * between C and C++ program.
55 */
56
57#if defined(__cplusplus)
58# define RT_C_DECLS_BEGIN extern "C" {
59# define RT_C_DECLS_END }
60#else
61# define RT_C_DECLS_BEGIN
62# define RT_C_DECLS_END
63#endif
64
65
66/*
67 * Shut up DOXYGEN warnings and guide it properly thru the code.
68 */
69#ifdef DOXYGEN_RUNNING
70# define __AMD64__
71# define __X86__
72# define RT_ARCH_AMD64
73# define RT_ARCH_X86
74# define RT_ARCH_SPARC
75# define RT_ARCH_SPARC64
76# define RT_ARCH_ARM32
77# define RT_ARCH_ARM64
78# define IN_RING0
79# define IN_RING3
80# define IN_RC
81# define IN_RT_RC
82# define IN_RT_R0
83# define IN_RT_R3
84# define IN_RT_STATIC
85# define RT_STRICT
86# define RT_NO_STRICT
87# define RT_LOCK_STRICT
88# define RT_LOCK_NO_STRICT
89# define RT_LOCK_STRICT_ORDER
90# define RT_LOCK_NO_STRICT_ORDER
91# define RT_BREAKPOINT
92# define RT_NO_DEPRECATED_MACROS
93# define RT_EXCEPTIONS_ENABLED
94# define RT_BIG_ENDIAN
95# define RT_LITTLE_ENDIAN
96# define RT_COMPILER_GROKS_64BIT_BITFIELDS
97# define RT_COMPILER_WITH_80BIT_LONG_DOUBLE
98# define RT_COMPILER_WITH_128BIT_LONG_DOUBLE
99# define RT_COMPILER_WITH_128BIT_INT_TYPES
100# define RT_NO_VISIBILITY_HIDDEN
101# define RT_GCC_SUPPORTS_VISIBILITY_HIDDEN
102# define RT_COMPILER_SUPPORTS_VA_ARGS
103# define RT_COMPILER_SUPPORTS_LAMBDA
104# define RT_IN_ASSEMBLER
105#endif /* DOXYGEN_RUNNING */
106
107/** @def RT_ARCH_X86
108 * Indicates that we're compiling for the X86 architecture.
109 */
110
111/** @def RT_ARCH_AMD64
112 * Indicates that we're compiling for the AMD64 architecture.
113 */
114
115/** @def RT_ARCH_SPARC
116 * Indicates that we're compiling for the SPARC V8 architecture (32-bit).
117 */
118
119/** @def RT_ARCH_SPARC64
120 * Indicates that we're compiling for the SPARC V9 architecture (64-bit).
121 */
122
123/** @def RT_ARCH_ARM32
124 * Indicates that we're compiling for the 32-bit ARM architecture, the value
125 * is the version (i.e. 6 for ARMv6).
126 */
127
128/** @def RT_ARCH_ARM64
129 * Indicates that we're compiling for the 64-bit ARM architecture.
130 */
131
132#if !defined(RT_ARCH_X86) \
133 && !defined(RT_ARCH_AMD64) \
134 && !defined(RT_ARCH_SPARC) \
135 && !defined(RT_ARCH_SPARC64) \
136 && !defined(RT_ARCH_ARM32) \
137 && !defined(RT_ARCH_ARM64)
138# if defined(__amd64__) || defined(__x86_64__) || defined(_M_X64) || defined(__AMD64__)
139# define RT_ARCH_AMD64
140# elif defined(__i386__) || defined(_M_IX86) || defined(__X86__)
141# define RT_ARCH_X86
142# elif defined(__sparcv9)
143# define RT_ARCH_SPARC64
144# elif defined(__sparc__)
145# define RT_ARCH_SPARC
146# elif defined(__arm64__) || defined(__aarch64__)
147# define RT_ARCH_ARM64 __ARM_ARCH
148# elif defined(__arm__)
149# define RT_ARCH_ARM32 __ARM_ARCH
150# elif defined(__arm32__)
151# define RT_ARCH_ARM32 __ARM_ARCH
152# else /* PORTME: append test for new archs. */
153# error "Check what predefined macros your compiler uses to indicate architecture."
154# endif
155/* PORTME: append new archs checks. */
156#elif defined(RT_ARCH_X86) && defined(RT_ARCH_AMD64)
157# error "Both RT_ARCH_X86 and RT_ARCH_AMD64 cannot be defined at the same time!"
158#elif defined(RT_ARCH_X86) && defined(RT_ARCH_SPARC)
159# error "Both RT_ARCH_X86 and RT_ARCH_SPARC cannot be defined at the same time!"
160#elif defined(RT_ARCH_X86) && defined(RT_ARCH_SPARC64)
161# error "Both RT_ARCH_X86 and RT_ARCH_SPARC64 cannot be defined at the same time!"
162#elif defined(RT_ARCH_AMD64) && defined(RT_ARCH_SPARC)
163# error "Both RT_ARCH_AMD64 and RT_ARCH_SPARC cannot be defined at the same time!"
164#elif defined(RT_ARCH_AMD64) && defined(RT_ARCH_SPARC64)
165# error "Both RT_ARCH_AMD64 and RT_ARCH_SPARC64 cannot be defined at the same time!"
166#elif defined(RT_ARCH_SPARC) && defined(RT_ARCH_SPARC64)
167# error "Both RT_ARCH_SPARC and RT_ARCH_SPARC64 cannot be defined at the same time!"
168#elif defined(RT_ARCH_ARM32) && defined(RT_ARCH_AMD64)
169# error "Both RT_ARCH_ARM32 and RT_ARCH_AMD64 cannot be defined at the same time!"
170#elif defined(RT_ARCH_ARM32) && defined(RT_ARCH_X86)
171# error "Both RT_ARCH_ARM32 and RT_ARCH_X86 cannot be defined at the same time!"
172#elif defined(RT_ARCH_ARM32) && defined(RT_ARCH_SPARC64)
173# error "Both RT_ARCH_ARM32 and RT_ARCH_SPARC64 cannot be defined at the same time!"
174#elif defined(RT_ARCH_ARM32) && defined(RT_ARCH_SPARC)
175# error "Both RT_ARCH_ARM32 and RT_ARCH_SPARC cannot be defined at the same time!"
176#elif defined(RT_ARCH_ARM64) && defined(RT_ARCH_AMD64)
177# error "Both RT_ARCH_ARM64 and RT_ARCH_AMD64 cannot be defined at the same time!"
178#elif defined(RT_ARCH_ARM64) && defined(RT_ARCH_X86)
179# error "Both RT_ARCH_ARM64 and RT_ARCH_X86 cannot be defined at the same time!"
180#elif defined(RT_ARCH_ARM64) && defined(RT_ARCH_SPARC64)
181# error "Both RT_ARCH_ARM64 and RT_ARCH_SPARC64 cannot be defined at the same time!"
182#elif defined(RT_ARCH_ARM64) && defined(RT_ARCH_SPARC)
183# error "Both RT_ARCH_ARM64 and RT_ARCH_SPARC cannot be defined at the same time!"
184#elif defined(RT_ARCH_ARM64) && defined(RT_ARCH_ARM32)
185# error "Both RT_ARCH_ARM64 and RT_ARCH_ARM32 cannot be defined at the same time!"
186#endif
187#ifdef RT_ARCH_ARM
188# error "RT_ARCH_ARM is now RT_ARCH_ARM32!"
189#endif
190
191/* Final check (PORTME). */
192#if (defined(RT_ARCH_X86) != 0) \
193 + (defined(RT_ARCH_AMD64) != 0) \
194 + (defined(RT_ARCH_SPARC) != 0) \
195 + (defined(RT_ARCH_SPARC64) != 0) \
196 + (defined(RT_ARCH_ARM32) != 0) \
197 + (defined(RT_ARCH_ARM64) != 0) \
198 != 1
199# error "Exactly one RT_ARCH_XXX macro shall be defined"
200#endif
201
202/** @name RT_ARCH_VAL_XXX - Architectures.
203 *
204 * These are values used by RT_ARCH_VAL among others as an alternative to
205 * RT_ARCH_X86, RT_ARCH_AMD64 and friends for identifying the compiler target
206 * architecture. Each value is a power of two (single bit), so they can be
207 * combined together to form an architecture mask if desirable.
208 *
209 * @{ */
210/** */
211#define RT_ARCH_VAL_X86_16 0x00000001
212#define RT_ARCH_VAL_X86 0x00000002
213#define RT_ARCH_VAL_AMD64 0x00000004
214#define RT_ARCH_VAL_ARM32 0x00000010
215#define RT_ARCH_VAL_ARM64 0x00000020
216#define RT_ARCH_VAL_SPARC32 0x00000100
217#define RT_ARCH_VAL_SPARC64 0x00000200
218/** @} */
219
220
221/** @def RT_ARCH_VAL
222 * The RT_ARCH_VAL_XXX for the compiler target architecture. */
223#if defined(RT_ARCH_AMD64)
224# define RT_ARCH_VAL RT_ARCH_VAL_AMD64
225#elif defined(RT_ARCH_ARM64)
226# define RT_ARCH_VAL RT_ARCH_VAL_ARM64
227#elif defined(RT_ARCH_X86)
228# define RT_ARCH_VAL RT_ARCH_VAL_X86
229#elif defined(RT_ARCH_ARM32)
230# define RT_ARCH_VAL RT_ARCH_VAL_ARM32
231#elif defined(RT_ARCH_SPARC)
232# define RT_ARCH_VAL RT_ARCH_VAL_SPARC32
233#elif defined(RT_ARCH_SPARC64)
234# define RT_ARCH_VAL RT_ARCH_VAL_SPARC64
235#else
236# error "RT_ARCH_VAL: port me"
237#endif
238
239/** @def RT_IN_ASSEMBLER
240 * Define when the source is being preprocessed for the assembler rather than
241 * the C, C++, Objective-C, or Objective-C++ compilers. */
242#ifdef __ASSEMBLER__
243# define RT_IN_ASSEMBLER
244#endif
245
246/** @def RT_CPLUSPLUS_PREREQ
247 * Require a minimum __cplusplus value, simplifying dealing with non-C++ code.
248 *
249 * @param a_Min The minimum version, e.g. 201100.
250 */
251#ifdef __cplusplus
252# define RT_CPLUSPLUS_PREREQ(a_Min) (__cplusplus >= (a_Min))
253#else
254# define RT_CPLUSPLUS_PREREQ(a_Min) (0)
255#endif
256
257/** @def RT_GNUC_PREREQ
258 * Shorter than fiddling with __GNUC__ and __GNUC_MINOR__.
259 *
260 * @param a_MinMajor Minimum major version
261 * @param a_MinMinor The minor version number part.
262 */
263#define RT_GNUC_PREREQ(a_MinMajor, a_MinMinor) RT_GNUC_PREREQ_EX(a_MinMajor, a_MinMinor, 0)
264/** @def RT_GNUC_PREREQ_EX
265 * Simplified way of checking __GNUC__ and __GNUC_MINOR__ regardless of actual
266 * compiler used, returns @a a_OtherRet for other compilers.
267 *
268 * @param a_MinMajor Minimum major version
269 * @param a_MinMinor The minor version number part.
270 * @param a_OtherRet What to return for non-GCC compilers.
271 */
272#if defined(__GNUC__) && defined(__GNUC_MINOR__)
273# define RT_GNUC_PREREQ_EX(a_MinMajor, a_MinMinor, a_OtherRet) \
274 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((a_MinMajor) << 16) + (a_MinMinor))
275#else
276# define RT_GNUC_PREREQ_EX(a_MinMajor, a_MinMinor, a_OtherRet) (a_OtherRet)
277#endif
278
279/** @def RT_MSC_PREREQ
280 * Convenient way of checking _MSC_VER regardless of actual compiler used
281 * (returns false if not MSC).
282 *
283 * @param a_MinVer Preferably a RT_MSC_VER_XXX value.
284 */
285#define RT_MSC_PREREQ(a_MinVer) RT_MSC_PREREQ_EX(a_MinVer, 0)
286/** @def RT_MSC_PREREQ_EX
287 * Convenient way of checking _MSC_VER regardless of actual compiler used,
288 * returns @a a_OtherRet for other compilers.
289 *
290 * @param a_MinVer Preferably a RT_MSC_VER_XXX value.
291 * @param a_OtherRet What to return for non-MSC compilers.
292 */
293#if defined(_MSC_VER)
294# define RT_MSC_PREREQ_EX(a_MinVer, a_OtherRet) ( (_MSC_VER) >= (a_MinVer) )
295#else
296# define RT_MSC_PREREQ_EX(a_MinVer, a_OtherRet) (a_OtherRet)
297#endif
298/** @name RT_MSC_VER_XXX - _MSC_VER values to use with RT_MSC_PREREQ.
299 * @remarks The VCxxx values are derived from the CRT DLLs shipping with the
300 * compilers.
301 * @{ */
302#define RT_MSC_VER_VC50 (1100) /**< Visual C++ 5.0. */
303#define RT_MSC_VER_VC60 (1200) /**< Visual C++ 6.0. */
304#define RT_MSC_VER_VC70 (1300) /**< Visual C++ 7.0. */
305#define RT_MSC_VER_VC70 (1300) /**< Visual C++ 7.0. */
306#define RT_MSC_VER_VS2003 (1310) /**< Visual Studio 2003, aka Visual C++ 7.1. */
307#define RT_MSC_VER_VC71 RT_MSC_VER_VS2003 /**< Visual C++ 7.1, aka Visual Studio 2003. */
308#define RT_MSC_VER_VS2005 (1400) /**< Visual Studio 2005. */
309#define RT_MSC_VER_VC80 RT_MSC_VER_VS2005 /**< Visual C++ 8.0, aka Visual Studio 2008. */
310#define RT_MSC_VER_VS2008 (1500) /**< Visual Studio 2008. */
311#define RT_MSC_VER_VC90 RT_MSC_VER_VS2008 /**< Visual C++ 9.0, aka Visual Studio 2008. */
312#define RT_MSC_VER_VS2010 (1600) /**< Visual Studio 2010. */
313#define RT_MSC_VER_VC100 RT_MSC_VER_VS2010 /**< Visual C++ 10.0, aka Visual Studio 2010. */
314#define RT_MSC_VER_VS2012 (1700) /**< Visual Studio 2012. */
315#define RT_MSC_VER_VC110 RT_MSC_VER_VS2012 /**< Visual C++ 11.0, aka Visual Studio 2012. */
316#define RT_MSC_VER_VS2013 (1800) /**< Visual Studio 2013. */
317#define RT_MSC_VER_VC120 RT_MSC_VER_VS2013 /**< Visual C++ 12.0, aka Visual Studio 2013. */
318#define RT_MSC_VER_VS2015 (1900) /**< Visual Studio 2015. */
319#define RT_MSC_VER_VC140 RT_MSC_VER_VS2015 /**< Visual C++ 14.0, aka Visual Studio 2015. */
320#define RT_MSC_VER_VS2017 (1910) /**< Visual Studio 2017. */
321#define RT_MSC_VER_VC141 RT_MSC_VER_VS2017 /**< Visual C++ 14.1, aka Visual Studio 2017. */
322#define RT_MSC_VER_VS2019 (1920) /**< Visual Studio 2019. */
323#define RT_MSC_VER_VC142 RT_MSC_VER_VS2019 /**< Visual C++ 14.2, aka Visual Studio 2019. */
324#define RT_MSC_VER_VS2019_U6 (1926) /**< Visual Studio 2019, update 6. */
325#define RT_MSC_VER_VC142_U6 RT_MSC_VER_VS2019_U6 /**< Visual C++ 14.2 update 6. */
326#define RT_MSC_VER_VS2019_U8 (1928) /**< Visual Studio 2019, update 8. */
327#define RT_MSC_VER_VC142_U8 RT_MSC_VER_VS2019_U8 /**< Visual C++ 14.2 update 8. */
328#define RT_MSC_VER_VS2019_U11 (1929) /**< Visual Studio 2019, update 11. */
329#define RT_MSC_VER_VC142_U11 RT_MSC_VER_VS2019_U11 /**< Visual C++ 14.2 update 11. */
330#define RT_MSC_VER_VS2022 (1930) /**< Visual Studio 2022. */
331#define RT_MSC_VER_VC143 RT_MSC_VER_VS2022 /**< Visual C++ 14.3, aka Visual Studio 2022. */
332/** @} */
333
334/** @def RT_CLANG_PREREQ
335 * Shorter than fiddling with __clang_major__ and __clang_minor__.
336 *
337 * @param a_MinMajor Minimum major version
338 * @param a_MinMinor The minor version number part.
339 */
340#define RT_CLANG_PREREQ(a_MinMajor, a_MinMinor) RT_CLANG_PREREQ_EX(a_MinMajor, a_MinMinor, 0)
341/** @def RT_CLANG_PREREQ_EX
342 * Simplified way of checking __clang_major__ and __clang_minor__ regardless of
343 * actual compiler used, returns @a a_OtherRet for other compilers.
344 *
345 * @param a_MinMajor Minimum major version
346 * @param a_MinMinor The minor version number part.
347 * @param a_OtherRet What to return for non-GCC compilers.
348 */
349#if defined(__clang_major__) && defined(__clang_minor__)
350# define RT_CLANG_PREREQ_EX(a_MinMajor, a_MinMinor, a_OtherRet) \
351 ((__clang_major__ << 16) + __clang_minor__ >= ((a_MinMajor) << 16) + (a_MinMinor))
352#else
353# define RT_CLANG_PREREQ_EX(a_MinMajor, a_MinMinor, a_OtherRet) (a_OtherRet)
354#endif
355/** @def RT_CLANG_HAS_FEATURE
356 * Wrapper around clang's __has_feature().
357 *
358 * @param a_Feature The feature to check for.
359 */
360#if defined(__clang_major__) && defined(__clang_minor__) && defined(__has_feature)
361# define RT_CLANG_HAS_FEATURE(a_Feature) (__has_feature(a_Feature))
362#else
363# define RT_CLANG_HAS_FEATURE(a_Feature) (0)
364#endif
365
366
367#if !defined(__X86__) && !defined(__AMD64__) && (defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86))
368# if defined(RT_ARCH_AMD64)
369/** Indicates that we're compiling for the AMD64 architecture.
370 * @deprecated
371 */
372# define __AMD64__
373# elif defined(RT_ARCH_X86)
374/** Indicates that we're compiling for the X86 architecture.
375 * @deprecated
376 */
377# define __X86__
378# else
379# error "Check what predefined macros your compiler uses to indicate architecture."
380# endif
381#elif defined(__X86__) && defined(__AMD64__)
382# error "Both __X86__ and __AMD64__ cannot be defined at the same time!"
383#elif defined(__X86__) && !defined(RT_ARCH_X86)
384# error "__X86__ without RT_ARCH_X86!"
385#elif defined(__AMD64__) && !defined(RT_ARCH_AMD64)
386# error "__AMD64__ without RT_ARCH_AMD64!"
387#endif
388
389/** @def RT_BIG_ENDIAN
390 * Defined if the architecture is big endian. */
391/** @def RT_LITTLE_ENDIAN
392 * Defined if the architecture is little endian. */
393#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86) || defined(RT_ARCH_ARM32) || defined(RT_ARCH_ARM64)
394# define RT_LITTLE_ENDIAN
395#elif defined(RT_ARCH_SPARC) || defined(RT_ARCH_SPARC64)
396# define RT_BIG_ENDIAN
397#else
398# error "PORTME: architecture endianess"
399#endif
400#if defined(RT_BIG_ENDIAN) && defined(RT_LITTLE_ENDIAN)
401# error "Both RT_BIG_ENDIAN and RT_LITTLE_ENDIAN are defined"
402#endif
403
404
405/** @def IN_RING0
406 * Used to indicate that we're compiling code which is running
407 * in Ring-0 Host Context.
408 */
409
410/** @def IN_RING3
411 * Used to indicate that we're compiling code which is running
412 * in Ring-3 Host Context.
413 */
414
415/** @def IN_RC
416 * Used to indicate that we're compiling code which is running
417 * in the Raw-mode Context (implies R0).
418 */
419#if !defined(IN_RING3) && !defined(IN_RING0) && !defined(IN_RC)
420# error "You must define which context the compiled code should run in; IN_RING3, IN_RING0 or IN_RC"
421#endif
422#if (defined(IN_RING3) && (defined(IN_RING0) || defined(IN_RC)) ) \
423 || (defined(IN_RING0) && (defined(IN_RING3) || defined(IN_RC)) ) \
424 || (defined(IN_RC) && (defined(IN_RING3) || defined(IN_RING0)) )
425# error "Only one of the IN_RING3, IN_RING0, IN_RC defines should be defined."
426#endif
427
428
429/** @def ARCH_BITS
430 * Defines the bit count of the current context.
431 */
432#if !defined(ARCH_BITS) || defined(DOXYGEN_RUNNING)
433# if defined(RT_ARCH_AMD64) || defined(RT_ARCH_SPARC64) || defined(RT_ARCH_ARM64) || defined(DOXYGEN_RUNNING)
434# define ARCH_BITS 64
435# elif !defined(__I86__) || !defined(__WATCOMC__)
436# define ARCH_BITS 32
437# else
438# define ARCH_BITS 16
439# endif
440#endif
441
442/* ARCH_BITS validation (PORTME). */
443#if ARCH_BITS == 64
444 #if defined(RT_ARCH_X86) || defined(RT_ARCH_SPARC) || defined(RT_ARCH_ARM32)
445 # error "ARCH_BITS=64 but non-64-bit RT_ARCH_XXX defined."
446 #endif
447 #if !defined(RT_ARCH_AMD64) && !defined(RT_ARCH_SPARC64) && !defined(RT_ARCH_ARM64)
448 # error "ARCH_BITS=64 but no 64-bit RT_ARCH_XXX defined."
449 #endif
450
451#elif ARCH_BITS == 32
452 #if defined(RT_ARCH_AMD64) || defined(RT_ARCH_SPARC64) || defined(RT_ARCH_ARM64)
453 # error "ARCH_BITS=32 but non-32-bit RT_ARCH_XXX defined."
454 #endif
455 #if !defined(RT_ARCH_X86) && !defined(RT_ARCH_SPARC) && !defined(RT_ARCH_ARM32)
456 # error "ARCH_BITS=32 but no 32-bit RT_ARCH_XXX defined."
457 #endif
458
459#elif ARCH_BITS == 16
460 #if defined(RT_ARCH_AMD64) || defined(RT_ARCH_SPARC) || defined(RT_ARCH_SPARC64) || defined(RT_ARCH_ARM32) || defined(RT_ARCH_ARM64)
461 # error "ARCH_BITS=16 but non-16-bit RT_ARCH_XX defined."
462 #endif
463 #if !defined(RT_ARCH_X86)
464 # error "ARCH_BITS=16 but RT_ARCH_X86 isn't defined."
465 #endif
466
467#else
468# error "Unsupported ARCH_BITS value!"
469#endif
470
471/** @def HC_ARCH_BITS
472 * Defines the host architecture bit count.
473 */
474#if !defined(HC_ARCH_BITS) || defined(DOXYGEN_RUNNING)
475# if !defined(IN_RC) || defined(DOXYGEN_RUNNING)
476# define HC_ARCH_BITS ARCH_BITS
477# else
478# define HC_ARCH_BITS 32
479# endif
480#endif
481
482/** @def GC_ARCH_BITS
483 * Defines the guest architecture bit count.
484 */
485#if !defined(GC_ARCH_BITS) || defined(DOXYGEN_RUNNING)
486# if defined(VBOX_WITH_64_BITS_GUESTS) || defined(DOXYGEN_RUNNING)
487# define GC_ARCH_BITS 64
488# else
489# define GC_ARCH_BITS 32
490# endif
491#endif
492
493/** @def R3_ARCH_BITS
494 * Defines the host ring-3 architecture bit count.
495 */
496#if !defined(R3_ARCH_BITS) || defined(DOXYGEN_RUNNING)
497# ifdef IN_RING3
498# define R3_ARCH_BITS ARCH_BITS
499# else
500# define R3_ARCH_BITS HC_ARCH_BITS
501# endif
502#endif
503
504/** @def R0_ARCH_BITS
505 * Defines the host ring-0 architecture bit count.
506 */
507#if !defined(R0_ARCH_BITS) || defined(DOXYGEN_RUNNING)
508# ifdef IN_RING0
509# define R0_ARCH_BITS ARCH_BITS
510# else
511# define R0_ARCH_BITS HC_ARCH_BITS
512# endif
513#endif
514
515
516
517/** @name RT_OPSYS_XXX - Operative System Identifiers.
518 * These are the value that the RT_OPSYS \#define can take. @{
519 */
520/** Unknown OS. */
521#define RT_OPSYS_UNKNOWN 0
522/** OS Agnostic. */
523#define RT_OPSYS_AGNOSTIC 1
524/** Darwin - aka Mac OS X. */
525#define RT_OPSYS_DARWIN 2
526/** DragonFly BSD. */
527#define RT_OPSYS_DRAGONFLY 3
528/** DOS. */
529#define RT_OPSYS_DOS 4
530/** FreeBSD. */
531#define RT_OPSYS_FREEBSD 5
532/** Haiku. */
533#define RT_OPSYS_HAIKU 6
534/** Linux. */
535#define RT_OPSYS_LINUX 7
536/** L4. */
537#define RT_OPSYS_L4 8
538/** Minix. */
539#define RT_OPSYS_MINIX 9
540/** NetBSD. */
541#define RT_OPSYS_NETBSD 11
542/** Netware. */
543#define RT_OPSYS_NETWARE 12
544/** NT (native). */
545#define RT_OPSYS_NT 13
546/** OpenBSD. */
547#define RT_OPSYS_OPENBSD 14
548/** OS/2. */
549#define RT_OPSYS_OS2 15
550/** Plan 9. */
551#define RT_OPSYS_PLAN9 16
552/** QNX. */
553#define RT_OPSYS_QNX 17
554/** Solaris. */
555#define RT_OPSYS_SOLARIS 18
556/** UEFI. */
557#define RT_OPSYS_UEFI 19
558/** Windows. */
559#define RT_OPSYS_WINDOWS 20
560/** The max RT_OPSYS_XXX value (exclusive). */
561#define RT_OPSYS_MAX 21
562/** @} */
563
564/** @def RT_OPSYS
565 * Indicates which OS we're targeting. It's a \#define with is
566 * assigned one of the RT_OPSYS_XXX defines above.
567 *
568 * So to test if we're on FreeBSD do the following:
569 * @code
570 * #if RT_OPSYS == RT_OPSYS_FREEBSD
571 * some_funky_freebsd_specific_stuff();
572 * #endif
573 * @endcode
574 */
575
576/*
577 * Set RT_OPSYS_XXX according to RT_OS_XXX.
578 *
579 * Search: #define RT_OPSYS_([A-Z0-9]+) .*
580 * Replace: # elif defined(RT_OS_\1)\n# define RT_OPSYS RT_OPSYS_\1
581 */
582#ifndef RT_OPSYS
583# if defined(RT_OS_UNKNOWN) || defined(DOXYGEN_RUNNING)
584# define RT_OPSYS RT_OPSYS_UNKNOWN
585# elif defined(RT_OS_AGNOSTIC)
586# define RT_OPSYS RT_OPSYS_AGNOSTIC
587# elif defined(RT_OS_DARWIN)
588# define RT_OPSYS RT_OPSYS_DARWIN
589# elif defined(RT_OS_DRAGONFLY)
590# define RT_OPSYS RT_OPSYS_DRAGONFLY
591# elif defined(RT_OS_DOS)
592# define RT_OPSYS RT_OPSYS_DOS
593# elif defined(RT_OS_FREEBSD)
594# define RT_OPSYS RT_OPSYS_FREEBSD
595# elif defined(RT_OS_HAIKU)
596# define RT_OPSYS RT_OPSYS_HAIKU
597# elif defined(RT_OS_LINUX)
598# define RT_OPSYS RT_OPSYS_LINUX
599# elif defined(RT_OS_L4)
600# define RT_OPSYS RT_OPSYS_L4
601# elif defined(RT_OS_MINIX)
602# define RT_OPSYS RT_OPSYS_MINIX
603# elif defined(RT_OS_NETBSD)
604# define RT_OPSYS RT_OPSYS_NETBSD
605# elif defined(RT_OS_NETWARE)
606# define RT_OPSYS RT_OPSYS_NETWARE
607# elif defined(RT_OS_NT)
608# define RT_OPSYS RT_OPSYS_NT
609# elif defined(RT_OS_OPENBSD)
610# define RT_OPSYS RT_OPSYS_OPENBSD
611# elif defined(RT_OS_OS2)
612# define RT_OPSYS RT_OPSYS_OS2
613# elif defined(RT_OS_PLAN9)
614# define RT_OPSYS RT_OPSYS_PLAN9
615# elif defined(RT_OS_QNX)
616# define RT_OPSYS RT_OPSYS_QNX
617# elif defined(RT_OS_SOLARIS)
618# define RT_OPSYS RT_OPSYS_SOLARIS
619# elif defined(RT_OS_UEFI)
620# define RT_OPSYS RT_OPSYS_UEFI
621# elif defined(RT_OS_WINDOWS)
622# define RT_OPSYS RT_OPSYS_WINDOWS
623# endif
624#endif
625
626/*
627 * Guess RT_OPSYS based on compiler predefined macros.
628 */
629#ifndef RT_OPSYS
630# if defined(__APPLE__)
631# define RT_OPSYS RT_OPSYS_DARWIN
632# elif defined(__DragonFly__)
633# define RT_OPSYS RT_OPSYS_DRAGONFLY
634# elif defined(__FreeBSD__) /*??*/
635# define RT_OPSYS RT_OPSYS_FREEBSD
636# elif defined(__gnu_linux__)
637# define RT_OPSYS RT_OPSYS_LINUX
638# elif defined(__NetBSD__) /*??*/
639# define RT_OPSYS RT_OPSYS_NETBSD
640# elif defined(__OpenBSD__) /*??*/
641# define RT_OPSYS RT_OPSYS_OPENBSD
642# elif defined(__OS2__)
643# define RT_OPSYS RT_OPSYS_OS2
644# elif defined(__sun__) || defined(__SunOS__) || defined(__sun) || defined(__SunOS)
645# define RT_OPSYS RT_OPSYS_SOLARIS
646# elif defined(_WIN32) || defined(_WIN64)
647# define RT_OPSYS RT_OPSYS_WINDOWS
648# elif defined(MSDOS) || defined(_MSDOS) || defined(DOS16RM) /* OW+MSC || MSC || DMC */
649# define RT_OPSYS RT_OPSYS_DOS
650# else
651# error "Port Me"
652# endif
653#endif
654
655#if RT_OPSYS < RT_OPSYS_UNKNOWN || RT_OPSYS >= RT_OPSYS_MAX
656# error "Invalid RT_OPSYS value."
657#endif
658
659/*
660 * Do some consistency checks.
661 *
662 * Search: #define RT_OPSYS_([A-Z0-9]+) .*
663 * Replace: #if defined(RT_OS_\1) && RT_OPSYS != RT_OPSYS_\1\n# error RT_OPSYS vs RT_OS_\1\n#endif
664 */
665#if defined(RT_OS_UNKNOWN) && RT_OPSYS != RT_OPSYS_UNKNOWN
666# error RT_OPSYS vs RT_OS_UNKNOWN
667#endif
668#if defined(RT_OS_AGNOSTIC) && RT_OPSYS != RT_OPSYS_AGNOSTIC
669# error RT_OPSYS vs RT_OS_AGNOSTIC
670#endif
671#if defined(RT_OS_DARWIN) && RT_OPSYS != RT_OPSYS_DARWIN
672# error RT_OPSYS vs RT_OS_DARWIN
673#endif
674#if defined(RT_OS_DRAGONFLY) && RT_OPSYS != RT_OPSYS_DRAGONFLY
675# error RT_OPSYS vs RT_OS_DRAGONFLY
676#endif
677#if defined(RT_OS_DOS) && RT_OPSYS != RT_OPSYS_DOS
678# error RT_OPSYS vs RT_OS_DOS
679#endif
680#if defined(RT_OS_FREEBSD) && RT_OPSYS != RT_OPSYS_FREEBSD
681# error RT_OPSYS vs RT_OS_FREEBSD
682#endif
683#if defined(RT_OS_HAIKU) && RT_OPSYS != RT_OPSYS_HAIKU
684# error RT_OPSYS vs RT_OS_HAIKU
685#endif
686#if defined(RT_OS_LINUX) && RT_OPSYS != RT_OPSYS_LINUX
687# error RT_OPSYS vs RT_OS_LINUX
688#endif
689#if defined(RT_OS_L4) && RT_OPSYS != RT_OPSYS_L4
690# error RT_OPSYS vs RT_OS_L4
691#endif
692#if defined(RT_OS_MINIX) && RT_OPSYS != RT_OPSYS_MINIX
693# error RT_OPSYS vs RT_OS_MINIX
694#endif
695#if defined(RT_OS_NETBSD) && RT_OPSYS != RT_OPSYS_NETBSD
696# error RT_OPSYS vs RT_OS_NETBSD
697#endif
698#if defined(RT_OS_NETWARE) && RT_OPSYS != RT_OPSYS_NETWARE
699# error RT_OPSYS vs RT_OS_NETWARE
700#endif
701#if defined(RT_OS_NT) && RT_OPSYS != RT_OPSYS_NT
702# error RT_OPSYS vs RT_OS_NT
703#endif
704#if defined(RT_OS_OPENBSD) && RT_OPSYS != RT_OPSYS_OPENBSD
705# error RT_OPSYS vs RT_OS_OPENBSD
706#endif
707#if defined(RT_OS_OS2) && RT_OPSYS != RT_OPSYS_OS2
708# error RT_OPSYS vs RT_OS_OS2
709#endif
710#if defined(RT_OS_PLAN9) && RT_OPSYS != RT_OPSYS_PLAN9
711# error RT_OPSYS vs RT_OS_PLAN9
712#endif
713#if defined(RT_OS_QNX) && RT_OPSYS != RT_OPSYS_QNX
714# error RT_OPSYS vs RT_OS_QNX
715#endif
716#if defined(RT_OS_SOLARIS) && RT_OPSYS != RT_OPSYS_SOLARIS
717# error RT_OPSYS vs RT_OS_SOLARIS
718#endif
719#if defined(RT_OS_UEFI) && RT_OPSYS != RT_OPSYS_UEFI
720# error RT_OPSYS vs RT_OS_UEFI
721#endif
722#if defined(RT_OS_WINDOWS) && RT_OPSYS != RT_OPSYS_WINDOWS
723# error RT_OPSYS vs RT_OS_WINDOWS
724#endif
725
726/*
727 * Make sure the RT_OS_XXX macro is defined.
728 *
729 * Search: #define RT_OPSYS_([A-Z0-9]+) .*
730 * Replace: #elif RT_OPSYS == RT_OPSYS_\1\n# ifndef RT_OS_\1\n# define RT_OS_\1\n# endif
731 */
732#if RT_OPSYS == RT_OPSYS_UNKNOWN
733# ifndef RT_OS_UNKNOWN
734# define RT_OS_UNKNOWN
735# endif
736#elif RT_OPSYS == RT_OPSYS_AGNOSTIC
737# ifndef RT_OS_AGNOSTIC
738# define RT_OS_AGNOSTIC
739# endif
740#elif RT_OPSYS == RT_OPSYS_DARWIN
741# ifndef RT_OS_DARWIN
742# define RT_OS_DARWIN
743# endif
744#elif RT_OPSYS == RT_OPSYS_DRAGONFLY
745# ifndef RT_OS_DRAGONFLY
746# define RT_OS_DRAGONFLY
747# endif
748#elif RT_OPSYS == RT_OPSYS_DOS
749# ifndef RT_OS_DOS
750# define RT_OS_DOS
751# endif
752#elif RT_OPSYS == RT_OPSYS_FREEBSD
753# ifndef RT_OS_FREEBSD
754# define RT_OS_FREEBSD
755# endif
756#elif RT_OPSYS == RT_OPSYS_HAIKU
757# ifndef RT_OS_HAIKU
758# define RT_OS_HAIKU
759# endif
760#elif RT_OPSYS == RT_OPSYS_LINUX
761# ifndef RT_OS_LINUX
762# define RT_OS_LINUX
763# endif
764#elif RT_OPSYS == RT_OPSYS_L4
765# ifndef RT_OS_L4
766# define RT_OS_L4
767# endif
768#elif RT_OPSYS == RT_OPSYS_MINIX
769# ifndef RT_OS_MINIX
770# define RT_OS_MINIX
771# endif
772#elif RT_OPSYS == RT_OPSYS_NETBSD
773# ifndef RT_OS_NETBSD
774# define RT_OS_NETBSD
775# endif
776#elif RT_OPSYS == RT_OPSYS_NETWARE
777# ifndef RT_OS_NETWARE
778# define RT_OS_NETWARE
779# endif
780#elif RT_OPSYS == RT_OPSYS_NT
781# ifndef RT_OS_NT
782# define RT_OS_NT
783# endif
784#elif RT_OPSYS == RT_OPSYS_OPENBSD
785# ifndef RT_OS_OPENBSD
786# define RT_OS_OPENBSD
787# endif
788#elif RT_OPSYS == RT_OPSYS_OS2
789# ifndef RT_OS_OS2
790# define RT_OS_OS2
791# endif
792#elif RT_OPSYS == RT_OPSYS_PLAN9
793# ifndef RT_OS_PLAN9
794# define RT_OS_PLAN9
795# endif
796#elif RT_OPSYS == RT_OPSYS_QNX
797# ifndef RT_OS_QNX
798# define RT_OS_QNX
799# endif
800#elif RT_OPSYS == RT_OPSYS_SOLARIS
801# ifndef RT_OS_SOLARIS
802# define RT_OS_SOLARIS
803# endif
804#elif RT_OPSYS == RT_OPSYS_UEFI
805# ifndef RT_OS_UEFI
806# define RT_OS_UEFI
807# endif
808#elif RT_OPSYS == RT_OPSYS_WINDOWS
809# ifndef RT_OS_WINDOWS
810# define RT_OS_WINDOWS
811# endif
812#else
813# error "Bad RT_OPSYS value."
814#endif
815
816
817/**
818 * Checks whether the given OpSys uses DOS-style paths or not.
819 *
820 * By DOS-style paths we include drive lettering and UNC paths.
821 *
822 * @returns true / false
823 * @param a_OpSys The RT_OPSYS_XXX value to check, will be reference
824 * multiple times.
825 */
826#define RT_OPSYS_USES_DOS_PATHS(a_OpSys) \
827 ( (a_OpSys) == RT_OPSYS_WINDOWS \
828 || (a_OpSys) == RT_OPSYS_OS2 \
829 || (a_OpSys) == RT_OPSYS_DOS )
830
831
832
833/** @def CTXTYPE
834 * Declare a type differently in GC, R3 and R0.
835 *
836 * @param a_GCType The GC type.
837 * @param a_R3Type The R3 type.
838 * @param a_R0Type The R0 type.
839 * @remark For pointers used only in one context use RCPTRTYPE(), R3R0PTRTYPE(), R3PTRTYPE() or R0PTRTYPE().
840 */
841#if defined(IN_RC) && !defined(DOXYGEN_RUNNING)
842# define CTXTYPE(a_GCType, a_R3Type, a_R0Type) a_GCType
843#elif defined(IN_RING3) || defined(DOXYGEN_RUNNING)
844# define CTXTYPE(a_GCType, a_R3Type, a_R0Type) a_R3Type
845#else
846# define CTXTYPE(a_GCType, a_R3Type, a_R0Type) a_R0Type
847#endif
848
849/** @def CTX_EXPR
850 * Expression selector for avoiding \#ifdef's.
851 *
852 * @param a_R3Expr The R3 expression.
853 * @param a_R0Expr The R0 expression.
854 * @param a_RCExpr The RC expression.
855 */
856#if defined(IN_RC) && !defined(DOXYGEN_RUNNING)
857# define CTX_EXPR(a_R3Expr, a_R0Expr, a_RCExpr) a_RCExpr
858#elif defined(IN_RING0) && !defined(DOXYGEN_RUNNING)
859# define CTX_EXPR(a_R3Expr, a_R0Expr, a_RCExpr) a_R0Expr
860#else
861# define CTX_EXPR(a_R3Expr, a_R0Expr, a_RCExpr) a_R3Expr
862#endif
863
864/** @def RCPTRTYPE
865 * Declare a pointer which is used in the raw mode context but appears in structure(s) used by
866 * both HC and RC. The main purpose is to make sure structures have the same
867 * size when built for different architectures.
868 *
869 * @param a_RCType The RC type.
870 */
871#define RCPTRTYPE(a_RCType) CTXTYPE(a_RCType, RTRCPTR, RTRCPTR)
872
873/** @def RGPTRTYPE
874 * This will become RCPTRTYPE once we've converted all uses of RCPTRTYPE to this.
875 *
876 * @param a_RCType The RC type.
877 */
878#define RGPTRTYPE(a_RCType) CTXTYPE(a_RCType, RTGCPTR, RTGCPTR)
879
880/** @def R3R0PTRTYPE
881 * Declare a pointer which is used in HC, is explicitly valid in ring 3 and 0,
882 * but appears in structure(s) used by both HC and GC. The main purpose is to
883 * make sure structures have the same size when built for different architectures.
884 *
885 * @param a_R3R0Type The R3R0 type.
886 * @remarks This used to be called HCPTRTYPE.
887 */
888#define R3R0PTRTYPE(a_R3R0Type) CTXTYPE(RTHCPTR, a_R3R0Type, a_R3R0Type)
889
890/** @def R3PTRTYPE
891 * Declare a pointer which is used in R3 but appears in structure(s) used by
892 * both HC and GC. The main purpose is to make sure structures have the same
893 * size when built for different architectures.
894 *
895 * @param a_R3Type The R3 type.
896 */
897#define R3PTRTYPE(a_R3Type) CTXTYPE(RTHCUINTPTR, a_R3Type, RTHCUINTPTR)
898
899/** @def R0PTRTYPE
900 * Declare a pointer which is used in R0 but appears in structure(s) used by
901 * both HC and GC. The main purpose is to make sure structures have the same
902 * size when built for different architectures.
903 *
904 * @param a_R0Type The R0 type.
905 */
906#define R0PTRTYPE(a_R0Type) CTXTYPE(RTHCUINTPTR, RTHCUINTPTR, a_R0Type)
907
908/** @def CTXSUFF
909 * Adds the suffix of the current context to the passed in
910 * identifier name. The suffix is HC or GC.
911 *
912 * This is macro should only be used in shared code to avoid a forest of ifdefs.
913 * @param a_Var Identifier name.
914 * @deprecated Use CTX_SUFF. Do NOT use this for new code.
915 */
916/** @def OTHERCTXSUFF
917 * Adds the suffix of the other context to the passed in
918 * identifier name. The suffix is HC or GC.
919 *
920 * This is macro should only be used in shared code to avoid a forest of ifdefs.
921 * @param a_Var Identifier name.
922 * @deprecated Use CTX_SUFF. Do NOT use this for new code.
923 */
924#if defined(IN_RC) && !defined(DOXYGEN_RUNNING)
925# define CTXSUFF(a_Var) a_Var##GC
926# define OTHERCTXSUFF(a_Var) a_Var##HC
927#else
928# define CTXSUFF(a_Var) a_Var##HC
929# define OTHERCTXSUFF(a_Var) a_Var##GC
930#endif
931
932/** @def CTXALLSUFF
933 * Adds the suffix of the current context to the passed in
934 * identifier name. The suffix is R3, R0 or GC.
935 *
936 * This is macro should only be used in shared code to avoid a forest of ifdefs.
937 * @param a_Var Identifier name.
938 * @deprecated Use CTX_SUFF. Do NOT use this for new code.
939 */
940#if defined(IN_RC) && !defined(DOXYGEN_RUNNING)
941# define CTXALLSUFF(a_Var) a_Var##GC
942#elif defined(IN_RING0) && !defined(DOXYGEN_RUNNING)
943# define CTXALLSUFF(a_Var) a_Var##R0
944#else
945# define CTXALLSUFF(a_Var) a_Var##R3
946#endif
947
948/** @def CTX_SUFF
949 * Adds the suffix of the current context to the passed in
950 * identifier name. The suffix is R3, R0 or RC.
951 *
952 * This is macro should only be used in shared code to avoid a forest of ifdefs.
953 * @param a_Var Identifier name.
954 *
955 * @remark This will replace CTXALLSUFF and CTXSUFF before long.
956 */
957#if defined(IN_RC) && !defined(DOXYGEN_RUNNING)
958# define CTX_SUFF(a_Var) a_Var##RC
959#elif defined(IN_RING0) && !defined(DOXYGEN_RUNNING)
960# define CTX_SUFF(a_Var) a_Var##R0
961#else
962# define CTX_SUFF(a_Var) a_Var##R3
963#endif
964
965/** @def CTX_SUFF_Z
966 * Adds the suffix of the current context to the passed in
967 * identifier name, combining RC and R0 into RZ.
968 * The suffix thus is R3 or RZ.
969 *
970 * This is macro should only be used in shared code to avoid a forest of ifdefs.
971 * @param a_Var Identifier name.
972 *
973 * @remark This will replace CTXALLSUFF and CTXSUFF before long.
974 */
975#if defined(IN_RING3) || defined(DOXYGEN_RUNNING)
976# define CTX_SUFF_Z(a_Var) a_Var##R3
977#else
978# define CTX_SUFF_Z(a_Var) a_Var##RZ
979#endif
980
981
982/** @def CTXMID
983 * Adds the current context as a middle name of an identifier name
984 * The middle name is HC or GC.
985 *
986 * This is macro should only be used in shared code to avoid a forest of ifdefs.
987 * @param a_First First name.
988 * @param a_Last Surname.
989 */
990/** @def OTHERCTXMID
991 * Adds the other context as a middle name of an identifier name
992 * The middle name is HC or GC.
993 *
994 * This is macro should only be used in shared code to avoid a forest of ifdefs.
995 * @param a_First First name.
996 * @param a_Last Surname.
997 * @deprecated use CTX_MID or CTX_MID_Z
998 */
999#if defined(IN_RC) && !defined(DOXYGEN_RUNNING)
1000# define CTXMID(a_First, a_Last) a_First##GC##a_Last
1001# define OTHERCTXMID(a_First, a_Last) a_First##HC##a_Last
1002#else
1003# define CTXMID(a_First, a_Last) a_First##HC##a_Last
1004# define OTHERCTXMID(a_First, a_Last) a_First##GC##a_Last
1005#endif
1006
1007/** @def CTXALLMID
1008 * Adds the current context as a middle name of an identifier name.
1009 * The middle name is R3, R0 or GC.
1010 *
1011 * This is macro should only be used in shared code to avoid a forest of ifdefs.
1012 * @param a_First First name.
1013 * @param a_Last Surname.
1014 * @deprecated use CTX_MID or CTX_MID_Z
1015 */
1016#if defined(IN_RC) && !defined(DOXYGEN_RUNNING)
1017# define CTXALLMID(a_First, a_Last) a_First##GC##a_Last
1018#elif defined(IN_RING0) && !defined(DOXYGEN_RUNNING)
1019# define CTXALLMID(a_First, a_Last) a_First##R0##a_Last
1020#else
1021# define CTXALLMID(a_First, a_Last) a_First##R3##a_Last
1022#endif
1023
1024/** @def CTX_MID
1025 * Adds the current context as a middle name of an identifier name.
1026 * The middle name is R3, R0 or RC.
1027 *
1028 * This is macro should only be used in shared code to avoid a forest of ifdefs.
1029 * @param a_First First name.
1030 * @param a_Last Surname.
1031 */
1032#if defined(IN_RC) && !defined(DOXYGEN_RUNNING)
1033# define CTX_MID(a_First, a_Last) a_First##RC##a_Last
1034#elif defined(IN_RING0) && !defined(DOXYGEN_RUNNING)
1035# define CTX_MID(a_First, a_Last) a_First##R0##a_Last
1036#else
1037# define CTX_MID(a_First, a_Last) a_First##R3##a_Last
1038#endif
1039
1040/** @def CTX_MID_Z
1041 * Adds the current context as a middle name of an identifier name, combining RC
1042 * and R0 into RZ.
1043 * The middle name thus is either R3 or RZ.
1044 *
1045 * This is macro should only be used in shared code to avoid a forest of ifdefs.
1046 * @param a_First First name.
1047 * @param a_Last Surname.
1048 */
1049#ifdef IN_RING3
1050# define CTX_MID_Z(a_First, a_Last) a_First##R3##a_Last
1051#else
1052# define CTX_MID_Z(a_First, a_Last) a_First##RZ##a_Last
1053#endif
1054
1055
1056/** @def R3STRING
1057 * A macro which in GC and R0 will return a dummy string while in R3 it will return
1058 * the parameter.
1059 *
1060 * This is typically used to wrap description strings in structures shared
1061 * between R3, R0 and/or GC. The intention is to avoid the \#ifdef IN_RING3 mess.
1062 *
1063 * @param a_pR3String The R3 string. Only referenced in R3.
1064 * @see R0STRING and GCSTRING
1065 */
1066#ifdef IN_RING3
1067# define R3STRING(a_pR3String) (a_pR3String)
1068#else
1069# define R3STRING(a_pR3String) ("<R3_STRING>")
1070#endif
1071
1072/** @def R0STRING
1073 * A macro which in GC and R3 will return a dummy string while in R0 it will return
1074 * the parameter.
1075 *
1076 * This is typically used to wrap description strings in structures shared
1077 * between R3, R0 and/or GC. The intention is to avoid the \#ifdef IN_RING0 mess.
1078 *
1079 * @param a_pR0String The R0 string. Only referenced in R0.
1080 * @see R3STRING and GCSTRING
1081 */
1082#ifdef IN_RING0
1083# define R0STRING(a_pR0String) (a_pR0String)
1084#else
1085# define R0STRING(a_pR0String) ("<R0_STRING>")
1086#endif
1087
1088/** @def RCSTRING
1089 * A macro which in R3 and R0 will return a dummy string while in RC it will return
1090 * the parameter.
1091 *
1092 * This is typically used to wrap description strings in structures shared
1093 * between R3, R0 and/or RC. The intention is to avoid the \#ifdef IN_RC mess.
1094 *
1095 * @param a_pRCString The RC string. Only referenced in RC.
1096 * @see R3STRING, R0STRING
1097 */
1098#ifdef IN_RC
1099# define RCSTRING(a_pRCString) (a_pRCString)
1100#else
1101# define RCSTRING(a_pRCString) ("<RC_STRING>")
1102#endif
1103
1104
1105/** @def RT_NOTHING
1106 * A macro that expands to nothing.
1107 * This is primarily intended as a dummy argument for macros to avoid the
1108 * undefined behavior passing empty arguments to an macro (ISO C90 and C++98,
1109 * gcc v4.4 warns about it).
1110 */
1111#define RT_NOTHING
1112
1113/** @def RT_GCC_EXTENSION
1114 * Macro for shutting up GCC warnings about using language extensions. */
1115#ifdef __GNUC__
1116# define RT_GCC_EXTENSION __extension__
1117#else
1118# define RT_GCC_EXTENSION
1119#endif
1120
1121/** @def RT_GCC_NO_WARN_DEPRECATED_BEGIN
1122 * Used to start a block of code where GCC and Clang should not warn about
1123 * deprecated declarations. */
1124/** @def RT_GCC_NO_WARN_DEPRECATED_END
1125 * Used to end a block of code where GCC and Clang should not warn about
1126 * deprecated declarations. */
1127#if RT_CLANG_PREREQ(4, 0)
1128# define RT_GCC_NO_WARN_DEPRECATED_BEGIN \
1129 _Pragma("clang diagnostic push") \
1130 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
1131# define RT_GCC_NO_WARN_DEPRECATED_END \
1132 _Pragma("clang diagnostic pop")
1133
1134#elif RT_GNUC_PREREQ(4, 6)
1135# define RT_GCC_NO_WARN_DEPRECATED_BEGIN \
1136 _Pragma("GCC diagnostic push") \
1137 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
1138# define RT_GCC_NO_WARN_DEPRECATED_END \
1139 _Pragma("GCC diagnostic pop")
1140#else
1141# define RT_GCC_NO_WARN_DEPRECATED_BEGIN
1142# define RT_GCC_NO_WARN_DEPRECATED_END
1143#endif
1144
1145/** @def RT_GCC_NO_WARN_CONVERSION_BEGIN
1146 * Used to start a block of code where GCC should not warn about implicit
1147 * conversions that may alter a value. */
1148#if RT_GNUC_PREREQ(4, 6)
1149# define RT_GCC_NO_WARN_CONVERSION_BEGIN \
1150 _Pragma("GCC diagnostic push") \
1151 _Pragma("GCC diagnostic ignored \"-Wconversion\"")
1152/** @def RT_GCC_NO_WARN_CONVERSION_END
1153 * Used to end a block of code where GCC should not warn about implicit
1154 * conversions that may alter a value. */
1155# define RT_GCC_NO_WARN_CONVERSION_END \
1156 _Pragma("GCC diagnostic pop")
1157#else
1158# define RT_GCC_NO_WARN_CONVERSION_BEGIN
1159# define RT_GCC_NO_WARN_CONVERSION_END
1160#endif
1161
1162/** @def RT_COMPILER_GROKS_64BIT_BITFIELDS
1163 * Macro that is defined if the compiler understands 64-bit bitfields. */
1164#if !defined(RT_OS_OS2) || (!defined(__IBMC__) && !defined(__IBMCPP__))
1165# if !defined(__WATCOMC__) /* watcom compiler doesn't grok it either. */
1166# define RT_COMPILER_GROKS_64BIT_BITFIELDS
1167# endif
1168#endif
1169
1170/** @def RT_COMPILER_LONG_DOUBLE_BITS
1171 * Number of relevant bits in the long double type: 64, 80 or 128 */
1172/** @def RT_COMPILER_WITH_64BIT_LONG_DOUBLE
1173 * Macro that is defined if the compiler implements long double as the
1174 * IEEE precision floating. */
1175/** @def RT_COMPILER_WITH_80BIT_LONG_DOUBLE
1176 * Macro that is defined if the compiler implements long double as the
1177 * IEEE extended precision floating. */
1178/** @def RT_COMPILER_WITH_128BIT_LONG_DOUBLE
1179* Macro that is defined if the compiler implements long double as the
1180* IEEE quadruple precision floating (128-bit).
1181* @note Currently not able to detect this, so must be explicitly defined. */
1182#if defined(__LDBL_MANT_DIG__) /* GCC & clang have this defined and should be more reliable. */
1183# if __LDBL_MANT_DIG__ == 53
1184# define RT_COMPILER_LONG_DOUBLE_BITS 64
1185# define RT_COMPILER_WITH_64BIT_LONG_DOUBLE
1186# undef RT_COMPILER_WITH_80BIT_LONG_DOUBLE
1187# undef RT_COMPILER_WITH_128BIT_LONG_DOUBLE
1188# elif __LDBL_MANT_DIG__ == 64
1189# define RT_COMPILER_LONG_DOUBLE_BITS 80
1190# undef RT_COMPILER_WITH_64BIT_LONG_DOUBLE
1191# define RT_COMPILER_WITH_80BIT_LONG_DOUBLE
1192# undef RT_COMPILER_WITH_128BIT_LONG_DOUBLE
1193# elif __LDBL_MANT_DIG__ == 113
1194# define RT_COMPILER_LONG_DOUBLE_BITS 128
1195# undef RT_COMPILER_WITH_64BIT_LONG_DOUBLE
1196# undef RT_COMPILER_WITH_80BIT_LONG_DOUBLE
1197# define RT_COMPILER_WITH_128BIT_LONG_DOUBLE
1198# else
1199# error "Port me!"
1200# endif
1201#elif defined(RT_OS_WINDOWS) || defined(RT_ARCH_ARM64) || defined(RT_ARCH_ARM32) /* the M1 arm64 at least */
1202# define RT_COMPILER_LONG_DOUBLE_BITS 64
1203# define RT_COMPILER_WITH_64BIT_LONG_DOUBLE
1204# undef RT_COMPILER_WITH_80BIT_LONG_DOUBLE
1205# undef RT_COMPILER_WITH_128BIT_LONG_DOUBLE
1206#elif defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
1207# define RT_COMPILER_LONG_DOUBLE_BITS 80
1208# undef RT_COMPILER_WITH_64BIT_LONG_DOUBLE
1209# define RT_COMPILER_WITH_80BIT_LONG_DOUBLE
1210# undef RT_COMPILER_WITH_128BIT_LONG_DOUBLE
1211#elif defined(RT_ARCH_SPARC) || defined(RT_ARCH_SPARC64)
1212# define RT_COMPILER_LONG_DOUBLE_BITS 128
1213# undef RT_COMPILER_WITH_64BIT_LONG_DOUBLE
1214# undef RT_COMPILER_WITH_80BIT_LONG_DOUBLE
1215# define RT_COMPILER_WITH_128BIT_LONG_DOUBLE
1216#else
1217# error "Port me!"
1218#endif
1219
1220
1221/*
1222 * The cl.exe frontend emulation of parfait is incorrect and
1223 * it still defines __SIZEOF_INT128__ despite msvc not supporting this
1224 * type and our code relying on the uint18_t type being a struct
1225 * in inline assembler code.
1226 */
1227#if defined(_MSC_VER) && defined(VBOX_WITH_PARFAIT)
1228# undef __SIZEOF_INT128__
1229#endif
1230
1231
1232/** @def RT_COMPILER_WITH_128BIT_INT_TYPES
1233 * Defined when uint128_t and int128_t are native integer types. If
1234 * undefined, they are structure with Hi & Lo members. */
1235#if defined(__SIZEOF_INT128__) || (defined(__GNUC__) && (defined(RT_ARCH_AMD64) || defined(RT_ARCH_ARM64)))
1236# define RT_COMPILER_WITH_128BIT_INT_TYPES
1237#endif
1238
1239/** @def RT_EXCEPTIONS_ENABLED
1240 * Defined when C++ exceptions are enabled.
1241 */
1242#if !defined(RT_EXCEPTIONS_ENABLED) \
1243 && defined(__cplusplus) \
1244 && ( (defined(_MSC_VER) && defined(_CPPUNWIND)) \
1245 || (defined(__GNUC__) && defined(__EXCEPTIONS)))
1246# define RT_EXCEPTIONS_ENABLED
1247#endif
1248
1249/** @def DECL_NOTHROW
1250 * How to declare a function which does not throw C++ exceptions.
1251 *
1252 * @param a_Type The return type.
1253 *
1254 * @note This macro can be combined with other macros, for example
1255 * @code
1256 * RTR3DECL(DECL_NOTHROW(void)) foo(void);
1257 * @endcode
1258 *
1259 * @note GCC is currently restricted to 4.2+ given the ominous comments on
1260 * RT_NOTHROW_PROTO.
1261 */
1262#ifdef __cplusplus
1263# if RT_MSC_PREREQ(RT_MSC_VER_VS2015) /*?*/
1264# define DECL_NOTHROW(a_Type) __declspec(nothrow) a_Type
1265# elif RT_CLANG_PREREQ(6,0) || RT_GNUC_PREREQ(4,2)
1266# define DECL_NOTHROW(a_Type) __attribute__((__nothrow__)) a_Type
1267# else
1268# define DECL_NOTHROW(a_Type) a_Type
1269# endif
1270#else
1271# define DECL_NOTHROW(a_Type) a_Type
1272#endif
1273
1274/** @def RT_NOTHROW_PROTO
1275 * Function does not throw any C++ exceptions, prototype edition.
1276 *
1277 * How to express that a function doesn't throw C++ exceptions and the compiler
1278 * can thus save itself the bother of trying to catch any of them and generate
1279 * unwind info. Put this between the closing parenthesis and the semicolon in
1280 * function prototypes (and implementation if C++).
1281 *
1282 * @note This translates to 'noexcept' when compiling in newer C++ mode.
1283 *
1284 * @remarks The use of the nothrow attribute with GCC is because old compilers
1285 * (4.1.1, 32-bit) leaking the nothrow into global space or something
1286 * when used with RTDECL or similar. Using this forces us to have two
1287 * macros, as the nothrow attribute is not for the function definition.
1288 */
1289/** @def RT_NOTHROW_DEF
1290 * Function does not throw any C++ exceptions, definition edition.
1291 *
1292 * The counter part to RT_NOTHROW_PROTO that is added to the function
1293 * definition.
1294 */
1295#ifdef RT_EXCEPTIONS_ENABLED
1296# if RT_MSC_PREREQ_EX(RT_MSC_VER_VS2015, 0) \
1297 || RT_CLANG_HAS_FEATURE(cxx_noexcept) \
1298 || (RT_GNUC_PREREQ(7, 0) && __cplusplus >= 201100)
1299# define RT_NOTHROW_PROTO noexcept
1300# define RT_NOTHROW_DEF noexcept
1301# elif defined(__GNUC__)
1302# if RT_GNUC_PREREQ(3, 3)
1303# define RT_NOTHROW_PROTO __attribute__((__nothrow__))
1304# else
1305# define RT_NOTHROW_PROTO
1306# endif
1307# define RT_NOTHROW_DEF /* Would need a DECL_NO_THROW like __declspec(nothrow), which we wont do at this point. */
1308# else
1309# define RT_NOTHROW_PROTO throw()
1310# define RT_NOTHROW_DEF throw()
1311# endif
1312#else
1313# define RT_NOTHROW_PROTO
1314# define RT_NOTHROW_DEF
1315#endif
1316/** @def RT_NOTHROW_PROTO
1317 * @deprecated Use RT_NOTHROW_PROTO. */
1318#define RT_NO_THROW_PROTO RT_NOTHROW_PROTO
1319/** @def RT_NOTHROW_DEF
1320 * @deprecated Use RT_NOTHROW_DEF. */
1321#define RT_NO_THROW_DEF RT_NOTHROW_DEF
1322
1323/** @def RT_THROW
1324 * How to express that a method or function throws a type of exceptions. Some
1325 * compilers does not want this kind of information and will warning about it.
1326 *
1327 * @param a_Type The type exception.
1328 *
1329 * @remarks If the actual throwing is done from the header, enclose it by
1330 * \#ifdef RT_EXCEPTIONS_ENABLED ... \#else ... \#endif so the header
1331 * compiles cleanly without exceptions enabled.
1332 *
1333 * Do NOT use this for the actual throwing of exceptions!
1334 */
1335#ifdef RT_EXCEPTIONS_ENABLED
1336# if (__cplusplus + 0) >= 201700
1337# define RT_THROW(a_Type) noexcept(false)
1338# elif RT_MSC_PREREQ_EX(RT_MSC_VER_VC71, 0)
1339# define RT_THROW(a_Type)
1340# elif RT_GNUC_PREREQ(7, 0)
1341# define RT_THROW(a_Type)
1342# else
1343# define RT_THROW(a_Type) throw(a_Type)
1344# endif
1345#else
1346# define RT_THROW(a_Type)
1347#endif
1348
1349
1350/** @def RT_OVERRIDE
1351 * Wrapper for the C++11 override keyword.
1352 *
1353 * @remarks Recognized by g++ starting 4.7, however causes pedantic warnings
1354 * when used without officially enabling the C++11 features.
1355 */
1356#ifdef __cplusplus
1357# if RT_MSC_PREREQ_EX(RT_MSC_VER_VS2012, 0) || RT_CLANG_HAS_FEATURE(cxx_override_control)
1358# define RT_OVERRIDE override
1359# elif RT_GNUC_PREREQ(4, 7) || RT_CLANG_PREREQ(7, 1) /** @todo possibly clang supports this earlier. found no __has_feature check. */
1360# if __cplusplus >= 201100
1361# define RT_OVERRIDE override
1362# else
1363# define RT_OVERRIDE
1364# endif
1365# else
1366# define RT_OVERRIDE
1367# endif
1368#else
1369# define RT_OVERRIDE
1370#endif
1371
1372/** @def RT_FINAL
1373 * Wrapper for the C++11 final keyword.
1374 *
1375 * @remarks Recognized by g++ starting 4.7. Assumes it triggers warnings just
1376 * like override does when C++11 isn't officially enabled.
1377 */
1378#ifdef __cplusplus
1379# if RT_MSC_PREREQ_EX(RT_MSC_VER_VS2015, 0) /** @todo not sure since when this is supported, probably 2012 like override. */
1380# define RT_FINAL final
1381# elif RT_GNUC_PREREQ(4, 7) /** @todo clang and final */
1382# if __cplusplus >= 201100
1383# define RT_FINAL final
1384# else
1385# define RT_FINAL
1386# endif
1387# else
1388# define RT_FINAL
1389# endif
1390#else
1391# define RT_FINAL
1392#endif
1393
1394/** @def RT_NOEXCEPT
1395 * Wrapper for the C++11 noexcept keyword (only true form).
1396 */
1397/** @def RT_NOEXCEPT_EX
1398 * Wrapper for the C++11 noexcept keyword with expression.
1399 * @param a_Expr The expression.
1400 */
1401#ifdef __cplusplus
1402# if (RT_MSC_PREREQ_EX(RT_MSC_VER_VS2015, 0) && defined(RT_EXCEPTIONS_ENABLED)) \
1403 || RT_CLANG_HAS_FEATURE(cxx_noexcept) \
1404 || (RT_GNUC_PREREQ(7, 0) && __cplusplus >= 201100)
1405# define RT_NOEXCEPT noexcept
1406# define RT_NOEXCEPT_EX(a_Expr) noexcept(a_Expr)
1407# else
1408# define RT_NOEXCEPT
1409# define RT_NOEXCEPT_EX(a_Expr)
1410# endif
1411#else
1412# define RT_NOEXCEPT
1413# define RT_NOEXCEPT_EX(a_Expr)
1414#endif
1415
1416/** @def RT_ALIGNAS_VAR
1417 * Wrapper for the C++ alignas keyword when used on variables.
1418 *
1419 * This must be put before the storage class and type.
1420 *
1421 * @param a_cbAlign The alignment. Must be power of two.
1422 * @note If C++11 is not enabled/detectable, alternatives will be used where
1423 * available. */
1424/** @def RT_ALIGNAS_TYPE
1425 * Wrapper for the C++ alignas keyword when used on types.
1426 *
1427 * When using struct, this must follow the struct keyword.
1428 *
1429 * @param a_cbAlign The alignment. Must be power of two.
1430 * @note If C++11 is not enabled/detectable, alternatives will be used where
1431 * available. */
1432/** @def RT_ALIGNAS_MEMB
1433 * Wrapper for the C++ alignas keyword when used on structure members.
1434 *
1435 * This must be put before the variable type.
1436 *
1437 * @param a_cbAlign The alignment. Must be power of two.
1438 * @note If C++11 is not enabled/detectable, alternatives will be used where
1439 * available. */
1440#ifdef __cplusplus
1441# if __cplusplus >= 201100 || defined(DOXYGEN_RUNNING)
1442# define RT_ALIGNAS_VAR(a_cbAlign) alignas(a_cbAlign)
1443# define RT_ALIGNAS_TYPE(a_cbAlign) alignas(a_cbAlign)
1444# define RT_ALIGNAS_MEMB(a_cbAlign) alignas(a_cbAlign)
1445# endif
1446#endif
1447#ifndef RT_ALIGNAS_VAR
1448# ifdef _MSC_VER
1449# define RT_ALIGNAS_VAR(a_cbAlign) __declspec(align(a_cbAlign))
1450# define RT_ALIGNAS_TYPE(a_cbAlign) __declspec(align(a_cbAlign))
1451# define RT_ALIGNAS_MEMB(a_cbAlign) __declspec(align(a_cbAlign))
1452# elif defined(__GNUC__)
1453# define RT_ALIGNAS_VAR(a_cbAlign) __attribute__((__aligned__(a_cbAlign)))
1454# define RT_ALIGNAS_TYPE(a_cbAlign) __attribute__((__aligned__(a_cbAlign)))
1455# define RT_ALIGNAS_MEMB(a_cbAlign) __attribute__((__aligned__(a_cbAlign)))
1456# else
1457# define RT_ALIGNAS_VAR(a_cbAlign)
1458# define RT_ALIGNAS_TYPE(a_cbAlign)
1459# define RT_ALIGNAS_MEMB(a_cbAlign)
1460# endif
1461#endif
1462
1463/** @def RT_CACHELINE_SIZE
1464 * The typical cache line size for the target architecture.
1465 * @see RT_ALIGNAS_VAR, RT_ALIGNAS_TYPE, RT_ALIGNAS_MEMB
1466 * @todo This is not correct for M1,M2,M3,M4,++, they have 128 byte cache lines.
1467 */
1468#if defined(RT_ARCH_X86) || defined(RT_ARCH_AMD64) \
1469 || defined(RT_ARCH_ARM32) || defined(RT_ARCH_ARM64) \
1470 || defined(RT_ARCH_SPARC32) || defined(RT_ARCH_SPARC64) \
1471 || defined(DOXYGEN_RUNNING)
1472# define RT_CACHELINE_SIZE 64
1473#else
1474# define RT_CACHELINE_SIZE 128 /* better overdo it */
1475#endif
1476
1477
1478/** @def RT_CONSTEXPR
1479 * Wrapper for the C++11 constexpr keyword for use as per C++11.
1480 */
1481#if RT_CPLUSPLUS_PREREQ(201100)
1482# define RT_CONSTEXPR constexpr
1483#else
1484# define RT_CONSTEXPR
1485#endif
1486
1487/** @def RT_CONSTEXPR_IF
1488 * Wrapper for the C++17 use of constexpr in combination with if statements.
1489 */
1490#if RT_CPLUSPLUS_PREREQ(201700)
1491# define RT_CONSTEXPR_IF(a_CondExpr) constexpr(a_CondExpr)
1492#else
1493# define RT_CONSTEXPR_IF(a_CondExpr) (a_CondExpr)
1494#endif
1495
1496
1497/** @def RT_FALL_THROUGH
1498 * Tell the compiler that we're falling through to the next case in a switch.
1499 * @sa RT_FALL_THRU */
1500#if RT_CLANG_PREREQ(4, 0) && RT_CPLUSPLUS_PREREQ(201100)
1501# define RT_FALL_THROUGH() [[clang::fallthrough]]
1502#elif RT_CLANG_PREREQ(12, 0) || RT_GNUC_PREREQ(7, 0)
1503# define RT_FALL_THROUGH() __attribute__((__fallthrough__))
1504#elif RT_CPLUSPLUS_PREREQ(201700)
1505# define RT_FALL_THROUGH() [[fallthrough]]
1506#else
1507# define RT_FALL_THROUGH() (void)0
1508#endif
1509/** @def RT_FALL_THRU
1510 * Tell the compiler that we're falling thru to the next case in a switch.
1511 * @sa RT_FALL_THROUGH */
1512#define RT_FALL_THRU() RT_FALL_THROUGH()
1513
1514
1515/** @def RT_IPRT_FORMAT_ATTR
1516 * Identifies a function taking an IPRT format string.
1517 * @param a_iFmt The index (1-based) of the format string argument.
1518 * @param a_iArgs The index (1-based) of the first format argument, use 0 for
1519 * va_list.
1520 */
1521#if defined(__GNUC__) && defined(WITH_IPRT_FORMAT_ATTRIBUTE)
1522# define RT_IPRT_FORMAT_ATTR(a_iFmt, a_iArgs) __attribute__((__iprt_format__(a_iFmt, a_iArgs)))
1523#else
1524# define RT_IPRT_FORMAT_ATTR(a_iFmt, a_iArgs)
1525#endif
1526
1527/** @def RT_IPRT_FORMAT_ATTR_MAYBE_NULL
1528 * Identifies a function taking an IPRT format string, NULL is allowed.
1529 * @param a_iFmt The index (1-based) of the format string argument.
1530 * @param a_iArgs The index (1-based) of the first format argument, use 0 for
1531 * va_list.
1532 */
1533#if defined(__GNUC__) && defined(WITH_IPRT_FORMAT_ATTRIBUTE)
1534# define RT_IPRT_FORMAT_ATTR_MAYBE_NULL(a_iFmt, a_iArgs) __attribute__((__iprt_format_maybe_null__(a_iFmt, a_iArgs)))
1535#else
1536# define RT_IPRT_FORMAT_ATTR_MAYBE_NULL(a_iFmt, a_iArgs)
1537#endif
1538
1539/** @def RT_IPRT_CALLREQ_ATTR
1540 * Identifies a function taking a function call request with parameter list and
1541 * everything for asynchronous execution.
1542 * @param a_iFn The index (1-based) of the function pointer argument.
1543 * @param a_iArgc The index (1-based) of the argument count.
1544 * @param a_iArgs The index (1-based) of the first argument, use 0 for
1545 * va_list.
1546 */
1547#if defined(__GNUC__) && defined(WITH_IPRT_CALLREQ_ATTRIBUTE)
1548# define RT_IPRT_CALLREQ_ATTR(a_iFn, a_iArgc, a_iArgs) __attribute__((__iprt_callreq__(a_iFn, a_iArgc, a_iArgs)))
1549#else
1550# define RT_IPRT_CALLREQ_ATTR(a_iFn, a_iArgc, a_iArgs)
1551#endif
1552
1553
1554/** @def RT_GCC_SUPPORTS_VISIBILITY_HIDDEN
1555 * Indicates that the "hidden" visibility attribute can be used (GCC) */
1556#if defined(__GNUC__)
1557# if __GNUC__ >= 4 && !defined(RT_OS_OS2) && !defined(RT_OS_WINDOWS)
1558# define RT_GCC_SUPPORTS_VISIBILITY_HIDDEN
1559# endif
1560#endif
1561
1562/** @def RT_COMPILER_SUPPORTS_VA_ARGS
1563 * If the defined, the compiler supports the variadic macro feature (..., __VA_ARGS__). */
1564#if defined(_MSC_VER)
1565# if _MSC_VER >= 1600 /* Visual C++ v10.0 / 2010 */
1566# define RT_COMPILER_SUPPORTS_VA_ARGS
1567# endif
1568#elif defined(__GNUC__)
1569# if __GNUC__ >= 3 /* not entirely sure when this was added */
1570# define RT_COMPILER_SUPPORTS_VA_ARGS
1571# endif
1572#elif defined(__WATCOMC__)
1573# define RT_COMPILER_SUPPORTS_VA_ARGS
1574#endif
1575
1576/** @def RT_CB_LOG_CAST
1577 * Helper for logging function pointers to function may throw stuff.
1578 *
1579 * Not needed for function pointer types declared using our DECLCALLBACK
1580 * macros, only external types. */
1581#if defined(_MSC_VER) && defined(RT_EXCEPTIONS_ENABLED)
1582# define RT_CB_LOG_CAST(a_pfnCallback) ((uintptr_t)(a_pfnCallback) + 1 - 1)
1583#else
1584# define RT_CB_LOG_CAST(a_pfnCallback) (a_pfnCallback)
1585#endif
1586
1587
1588
1589/** @def RTCALL
1590 * The standard calling convention for the Runtime interfaces.
1591 *
1592 * @remarks The regparm(0) in the X86/GNUC variant deals with -mregparm=x use in
1593 * the linux kernel and potentially elsewhere (3rd party).
1594 */
1595#if defined(_MSC_VER) || defined(__WATCOMC__)
1596# define RTCALL __cdecl
1597#elif defined(RT_OS_OS2)
1598# define RTCALL __cdecl
1599#elif defined(__GNUC__) && defined(RT_ARCH_X86)
1600# define RTCALL __attribute__((__cdecl__,__regparm__(0)))
1601#else
1602# define RTCALL
1603#endif
1604
1605/** @def DECLEXPORT
1606 * How to declare an exported function.
1607 * @param a_RetType The return type of the function declaration.
1608 */
1609#if defined(_MSC_VER) || defined(RT_OS_OS2)
1610# define DECLEXPORT(a_RetType) __declspec(dllexport) a_RetType
1611#elif defined(RT_USE_VISIBILITY_DEFAULT)
1612# define DECLEXPORT(a_RetType) __attribute__((visibility("default"))) a_RetType
1613#else
1614# define DECLEXPORT(a_RetType) a_RetType
1615#endif
1616
1617/** @def DECL_EXPORT_NOTHROW
1618 * How to declare an exported function that does not throw C++ exceptions.
1619 * @param a_RetType The return type of the function declaration.
1620 */
1621#define DECL_EXPORT_NOTHROW(a_RetType) DECL_NOTHROW(DECLEXPORT(a_RetType))
1622
1623/** @def DECLIMPORT
1624 * How to declare an imported function.
1625 * @param a_RetType The return type of the function declaration.
1626 */
1627#if defined(_MSC_VER) || (defined(RT_OS_OS2) && !defined(__IBMC__) && !defined(__IBMCPP__))
1628# define DECLIMPORT(a_RetType) __declspec(dllimport) a_RetType
1629#else
1630# define DECLIMPORT(a_RetType) a_RetType
1631#endif
1632
1633/** @def DECL_IMPORT_NOTHROW
1634 * How to declare an imported function that does not throw C++ exceptions.
1635 * @param a_RetType The return type of the function declaration.
1636 */
1637#define DECL_IMPORT_NOTHROW(a_RetType) DECL_NOTHROW(DECLIMPORT(a_RetType))
1638
1639/** @def DECL_HIDDEN_ONLY
1640 * How to declare a non-exported function or variable.
1641 * @param a_Type The return type of the function or the data type of the variable.
1642 * @sa DECL_HIDDEN, DECL_HIDDEN_DATA, DECL_HIDDEN_CONST
1643 * @internal Considered more or less internal.
1644 */
1645#if !defined(RT_GCC_SUPPORTS_VISIBILITY_HIDDEN) || defined(RT_NO_VISIBILITY_HIDDEN)
1646# define DECL_HIDDEN_ONLY(a_Type) a_Type
1647#else
1648# define DECL_HIDDEN_ONLY(a_Type) __attribute__((visibility("hidden"))) a_Type
1649#endif
1650
1651/** @def DECLHIDDEN
1652 * How to declare a non-exported function or variable.
1653 * @param a_Type The return type of the function or the data type of the variable.
1654 * @sa DECL_HIDDEN_THROW, DECL_HIDDEN_DATA, DECL_HIDDEN_CONST
1655 * @todo split up into data and non-data.
1656 */
1657#define DECLHIDDEN(a_Type) DECL_NOTHROW(DECL_HIDDEN_ONLY(a_Type))
1658
1659/** @def DECL_HIDDEN_NOTHROW
1660 * How to declare a non-exported function that does not throw C++ exceptions.
1661 * @param a_RetType The return type of the function.
1662 * @note Same as DECLHIDDEN but provided to go along with DECL_IMPORT_NOTHROW
1663 * and DECL_EXPORT_NOTHROW.
1664 */
1665#define DECL_HIDDEN_NOTHROW(a_RetType) DECL_NOTHROW(DECL_HIDDEN_ONLY(a_RetType))
1666
1667/** @def DECL_HIDDEN_THROW
1668 * How to declare a non-exported function that may throw C++ exceptions.
1669 * @param a_RetType The return type of the function.
1670 */
1671#define DECL_HIDDEN_THROW(a_RetType) DECL_HIDDEN_ONLY(a_RetType)
1672
1673/** @def DECL_HIDDEN_DATA
1674 * How to declare a non-exported variable.
1675 * @param a_Type The data type of the variable.
1676 * @sa DECL_HIDDEN_CONST
1677 */
1678#if !defined(RT_GCC_SUPPORTS_VISIBILITY_HIDDEN) || defined(RT_NO_VISIBILITY_HIDDEN)
1679# define DECL_HIDDEN_DATA(a_Type) a_Type
1680#else
1681# define DECL_HIDDEN_DATA(a_Type) __attribute__((visibility("hidden"))) a_Type
1682#endif
1683
1684/** @def DECL_HIDDEN_CONST
1685 * Workaround for g++ warnings when applying the hidden attribute to a const
1686 * definition. Use DECL_HIDDEN_DATA for the declaration.
1687 * @param a_Type The data type of the variable.
1688 * @sa DECL_HIDDEN_DATA
1689 */
1690#if defined(__cplusplus) && defined(__GNUC__)
1691# define DECL_HIDDEN_CONST(a_Type) a_Type
1692#else
1693# define DECL_HIDDEN_CONST(a_Type) DECL_HIDDEN_DATA(a_Type)
1694#endif
1695
1696/** @def DECL_INVALID
1697 * How to declare a function not available for linking in the current context.
1698 * The purpose is to create compile or like time errors when used. This isn't
1699 * possible on all platforms.
1700 * @param a_RetType The return type of the function.
1701 */
1702#if defined(_MSC_VER)
1703# define DECL_INVALID(a_RetType) __declspec(dllimport) a_RetType __stdcall
1704#elif defined(__GNUC__) && defined(__cplusplus)
1705# define DECL_INVALID(a_RetType) extern "C++" a_RetType
1706#else
1707# define DECL_INVALID(a_RetType) a_RetType
1708#endif
1709
1710/** @def DECL_EXTERN_C
1711 * Prepends an 'extern "C"' in C++ code.
1712 * @param a_RetTypeExpr The return type, calling convention, function
1713 * attributes, and whatnot expression of the function
1714 * declaration.
1715 */
1716#ifdef __cplusplus
1717# define DECL_EXTERN_C(a_RetTypeExpr) extern "C" a_RetTypeExpr
1718#else
1719# define DECL_EXTERN_C(a_RetTypeExpr) a_RetTypeExpr
1720#endif
1721
1722/** @def DECLASM
1723 * How to declare an internal assembly function.
1724 * @param a_RetType The return type of the function declaration.
1725 * @note DECL_NOTHROW is implied.
1726 */
1727#ifdef __cplusplus
1728# define DECLASM(a_RetType) extern "C" DECL_NOTHROW(a_RetType RTCALL)
1729#else
1730# define DECLASM(a_RetType) DECL_NOTHROW(a_RetType RTCALL)
1731#endif
1732
1733/** @def RT_ASM_DECL_PRAGMA_WATCOM
1734 * How to declare a assembly method prototype with watcom \#pragma aux definition. */
1735/** @def RT_ASM_DECL_PRAGMA_WATCOM_386
1736 * Same as RT_ASM_DECL_PRAGMA_WATCOM, but there is no 16-bit version when
1737 * 8086, 80186 or 80286 is selected as the target CPU. */
1738#if defined(__WATCOMC__) && ARCH_BITS == 16 && defined(RT_ARCH_X86)
1739# define RT_ASM_DECL_PRAGMA_WATCOM(a_RetType) a_RetType
1740# if defined(__SW_0) || defined(__SW_1) || defined(__SW_2)
1741# define RT_ASM_DECL_PRAGMA_WATCOM_386(a_RetType) DECLASM(a_RetType)
1742# else
1743# define RT_ASM_DECL_PRAGMA_WATCOM_386(a_RetType) a_RetType
1744# endif
1745#elif defined(__WATCOMC__) && ARCH_BITS == 32 && defined(RT_ARCH_X86)
1746# define RT_ASM_DECL_PRAGMA_WATCOM(a_RetType) a_RetType
1747# define RT_ASM_DECL_PRAGMA_WATCOM_386(a_RetType) a_RetType
1748#else
1749# define RT_ASM_DECL_PRAGMA_WATCOM(a_RetType) RT_DECL_ASM(a_RetType)
1750# define RT_ASM_DECL_PRAGMA_WATCOM_386(a_RetType) RT_DECL_ASM(a_RetType)
1751#endif
1752
1753/** @def DECL_NO_RETURN
1754 * How to declare a function which does not return.
1755 * @note This macro can be combined with other macros, for example
1756 * @code
1757 * RTR3DECL(DECL_NO_RETURN(void)) foo(void);
1758 * @endcode
1759 */
1760#ifdef _MSC_VER
1761# define DECL_NO_RETURN(a_RetType) __declspec(noreturn) a_RetType
1762#elif defined(__GNUC__)
1763# define DECL_NO_RETURN(a_RetType) __attribute__((noreturn)) a_RetType
1764#else
1765# define DECL_NO_RETURN(a_RetType) a_RetType
1766#endif
1767
1768/** @def DECL_RETURNS_TWICE
1769 * How to declare a function which may return more than once.
1770 * @note This macro can be combined with other macros, for example
1771 * @code
1772 * RTR3DECL(DECL_RETURNS_TWICE(void)) MySetJmp(void);
1773 * @endcode
1774 */
1775#if RT_GNUC_PREREQ(4, 1)
1776# define DECL_RETURNS_TWICE(a_RetType) __attribute__((returns_twice)) a_RetType
1777#else
1778# define DECL_RETURNS_TWICE(a_RetType) a_RetType
1779#endif
1780
1781/** @def DECL_CHECK_RETURN
1782 * Require a return value to be checked.
1783 * @note This macro can be combined with other macros, for example
1784 * @code
1785 * RTR3DECL(DECL_CHECK_RETURN(int)) MayReturnInfoStatus(void);
1786 * @endcode
1787 */
1788#if RT_GNUC_PREREQ(3, 4)
1789# define DECL_CHECK_RETURN(a_RetType) __attribute__((warn_unused_result)) a_RetType
1790#elif defined(_MSC_VER)
1791# define DECL_CHECK_RETURN(a_RetType) __declspec("SAL_checkReturn") a_RetType
1792#else
1793# define DECL_CHECK_RETURN(a_RetType) a_RetType
1794#endif
1795
1796/** @def DECL_CHECK_RETURN_NOT_R3
1797 * Variation of DECL_CHECK_RETURN that only applies the required to non-ring-3
1798 * code.
1799 */
1800#ifndef IN_RING3
1801# define DECL_CHECK_RETURN_NOT_R3(a_RetType) DECL_CHECK_RETURN(a_RetType)
1802#else
1803# define DECL_CHECK_RETURN_NOT_R3(a_RetType) a_RetType
1804#endif
1805
1806/** @def DECLWEAK
1807 * How to declare a variable which is not necessarily resolved at
1808 * runtime.
1809 * @note This macro can be combined with other macros, for example
1810 * @code
1811 * RTR3DECL(DECLWEAK(int)) foo;
1812 * @endcode
1813 */
1814#if defined(__GNUC__)
1815# define DECLWEAK(a_Type) a_Type __attribute__((weak))
1816#else
1817# define DECLWEAK(a_Type) a_Type
1818#endif
1819
1820/** @def DECLCALLBACK
1821 * How to declare an call back function.
1822 * @param a_RetType The return type of the function declaration.
1823 * @note DECL_NOTHROW is implied.
1824 * @note Use DECLCALLBACKTYPE for typedefs.
1825 */
1826#define DECLCALLBACK(a_RetType) DECL_NOTHROW(a_RetType RT_FAR_CODE RTCALL)
1827
1828/** @def DECL_HIDDEN_CALLBACK
1829 * How to declare an call back function with hidden visibility.
1830 * @param a_RetType The return type of the function declaration.
1831 * @note DECL_NOTHROW is implied.
1832 * @note Use DECLCALLBACKTYPE for typedefs.
1833 */
1834#define DECL_HIDDEN_CALLBACK(a_RetType) DECL_HIDDEN_ONLY(DECLCALLBACK(a_RetType))
1835
1836/** @def DECLCALLBACKTYPE_EX
1837 * How to declare an call back function type.
1838 * @param a_RetType The return type of the function declaration.
1839 * @param a_CallConv Calling convention.
1840 * @param a_Name The name of the typedef
1841 * @param a_Args The argument list enclosed in parentheses.
1842 * @note DECL_NOTHROW is implied, but not supported by all compilers yet.
1843 */
1844#if RT_CLANG_PREREQ(6,0) && !defined(RT_RELAXED_CALLBACKS_TYPES)
1845# define DECLCALLBACKTYPE_EX(a_RetType, a_CallConv, a_Name, a_Args) __attribute__((__nothrow__)) a_RetType a_CallConv a_Name a_Args
1846#elif RT_MSC_PREREQ(RT_MSC_VER_VS2015) /*?*/ && defined(__cplusplus) && defined(_MSC_EXTENSIONS) && !defined(RT_RELAXED_CALLBACKS_TYPES)
1847# define DECLCALLBACKTYPE_EX(a_RetType, a_CallConv, a_Name, a_Args) a_RetType a_CallConv a_Name a_Args throw()
1848#else
1849# define DECLCALLBACKTYPE_EX(a_RetType, a_CallConv, a_Name, a_Args) a_RetType a_CallConv a_Name a_Args
1850#endif
1851/** @def DECLCALLBACKTYPE
1852 * How to declare an call back function type.
1853 * @param a_RetType The return type of the function declaration.
1854 * @param a_Name The name of the typedef
1855 * @param a_Args The argument list enclosed in parentheses.
1856 * @note DECL_NOTHROW is implied, but not supported by all compilers yet.
1857 */
1858#define DECLCALLBACKTYPE(a_RetType, a_Name, a_Args) DECLCALLBACKTYPE_EX(a_RetType, RT_FAR_CODE RTCALL, a_Name, a_Args)
1859
1860/** @def DECLCALLBACKPTR_EX
1861 * How to declare an call back function pointer.
1862 * @param a_RetType The return type of the function declaration.
1863 * @param a_CallConv Calling convention.
1864 * @param a_Name The name of the variable member.
1865 * @param a_Args The argument list enclosed in parentheses.
1866 * @note DECL_NOTHROW is implied, but not supported by all compilers yet.
1867 */
1868#if defined(__IBMC__) || defined(__IBMCPP__)
1869# define DECLCALLBACKPTR_EX(a_RetType, a_CallConv, a_Name, a_Args) a_RetType (* a_CallConv a_Name) a_Args
1870#elif RT_CLANG_PREREQ(6,0) && !defined(RT_RELAXED_CALLBACKS_TYPES)
1871# define DECLCALLBACKPTR_EX(a_RetType, a_CallConv, a_Name, a_Args) __attribute__((__nothrow__)) a_RetType (a_CallConv * a_Name) a_Args
1872#elif RT_MSC_PREREQ(RT_MSC_VER_VS2015) /*?*/ && defined(__cplusplus) && defined(_MSC_EXTENSIONS) && !defined(RT_RELAXED_CALLBACKS_TYPES)
1873# define DECLCALLBACKPTR_EX(a_RetType, a_CallConv, a_Name, a_Args) a_RetType (a_CallConv * a_Name) a_Args throw()
1874#else
1875# define DECLCALLBACKPTR_EX(a_RetType, a_CallConv, a_Name, a_Args) a_RetType (a_CallConv * a_Name) a_Args
1876#endif
1877/** @def DECLCALLBACKPTR
1878 * How to declare an call back function pointer.
1879 * @param a_RetType The return type of the function declaration.
1880 * @param a_Name The name of the variable member.
1881 * @param a_Args The argument list enclosed in parentheses.
1882 * @note DECL_NOTHROW is implied, but not supported by all compilers yet.
1883 */
1884#define DECLCALLBACKPTR(a_RetType, a_Name, a_Args) DECLCALLBACKPTR_EX(a_RetType, RT_FAR_CODE RTCALL, a_Name, a_Args)
1885
1886/** @def DECLCALLBACKMEMBER_EX
1887 * How to declare an call back function pointer member.
1888 * @param a_RetType The return type of the function declaration.
1889 * @param a_CallConv Calling convention.
1890 * @param a_Name The name of the struct/union/class member.
1891 * @param a_Args The argument list enclosed in parentheses.
1892 * @note DECL_NOTHROW is implied, but not supported by all compilers yet.
1893 */
1894#if defined(__IBMC__) || defined(__IBMCPP__)
1895# define DECLCALLBACKMEMBER_EX(a_RetType, a_CallConv, a_Name, a_Args) a_RetType (* a_CallConv a_Name) a_Args
1896#elif RT_CLANG_PREREQ(6,0) && !defined(RT_RELAXED_CALLBACKS_TYPES)
1897# define DECLCALLBACKMEMBER_EX(a_RetType, a_CallConv, a_Name, a_Args) __attribute__((__nothrow__)) a_RetType (a_CallConv *a_Name) a_Args
1898#elif RT_MSC_PREREQ(RT_MSC_VER_VS2015) /*?*/ && defined(__cplusplus) && defined(_MSC_EXTENSIONS) && !defined(RT_RELAXED_CALLBACKS_TYPES)
1899# define DECLCALLBACKMEMBER_EX(a_RetType, a_CallConv, a_Name, a_Args) a_RetType (a_CallConv *a_Name) a_Args throw()
1900#else
1901# define DECLCALLBACKMEMBER_EX(a_RetType, a_CallConv, a_Name, a_Args) a_RetType (a_CallConv *a_Name) a_Args
1902#endif
1903/** @def DECLCALLBACKMEMBER
1904 * How to declare an call back function pointer member.
1905 * @param a_RetType The return type of the function declaration.
1906 * @param a_Name The name of the struct/union/class member.
1907 * @param a_Args The argument list enclosed in parentheses.
1908 * @note DECL_NOTHROW is implied, but not supported by all compilers yet.
1909 */
1910#define DECLCALLBACKMEMBER(a_RetType, a_Name, a_Args) DECLCALLBACKMEMBER_EX(a_RetType, RT_FAR_CODE RTCALL, a_Name, a_Args)
1911
1912/** @def DECLR3CALLBACKMEMBER
1913 * How to declare an call back function pointer member - R3 Ptr.
1914 * @param a_RetType The return type of the function declaration.
1915 * @param a_Name The name of the struct/union/class member.
1916 * @param a_Args The argument list enclosed in parentheses.
1917 * @note DECL_NOTHROW is implied, but not supported by all compilers yet.
1918 */
1919#if defined(IN_RING3) || defined(DOXYGEN_RUNNING)
1920# define DECLR3CALLBACKMEMBER(a_RetType, a_Name, a_Args) DECLCALLBACKMEMBER(a_RetType, a_Name, a_Args)
1921#else
1922# define DECLR3CALLBACKMEMBER(a_RetType, a_Name, a_Args) RTR3PTR a_Name
1923#endif
1924
1925/** @def DECLRCCALLBACKMEMBER
1926 * How to declare an call back function pointer member - RC Ptr.
1927 * @param a_RetType The return type of the function declaration.
1928 * @param a_Name The name of the struct/union/class member.
1929 * @param a_Args The argument list enclosed in parentheses.
1930 * @note DECL_NOTHROW is implied, but not supported by all compilers yet.
1931 */
1932#if defined(IN_RC) || defined(DOXYGEN_RUNNING)
1933# define DECLRCCALLBACKMEMBER(a_RetType, a_Name, a_Args) DECLCALLBACKMEMBER(a_RetType, a_Name, a_Args)
1934#else
1935# define DECLRCCALLBACKMEMBER(a_RetType, a_Name, a_Args) RTRCPTR a_Name
1936#endif
1937#if defined(IN_RC) || defined(DOXYGEN_RUNNING)
1938# define DECLRGCALLBACKMEMBER(a_RetType, a_Name, a_Args) DECLCALLBACKMEMBER(a_RetType, a_Name, a_Args)
1939#else
1940# define DECLRGCALLBACKMEMBER(a_RetType, a_Name, a_Args) RTRGPTR a_Name
1941#endif
1942
1943/** @def DECLR0CALLBACKMEMBER
1944 * How to declare an call back function pointer member - R0 Ptr.
1945 * @param a_RetType The return type of the function declaration.
1946 * @param a_Name The name of the struct/union/class member.
1947 * @param a_Args The argument list enclosed in parentheses.
1948 * @note DECL_NOTHROW is implied, but not supported by all compilers yet.
1949 */
1950#if defined(IN_RING0) || defined(DOXYGEN_RUNNING)
1951# define DECLR0CALLBACKMEMBER(a_RetType, a_Name, a_Args) DECLCALLBACKMEMBER(a_RetType, a_Name, a_Args)
1952#else
1953# define DECLR0CALLBACKMEMBER(a_RetType, a_Name, a_Args) RTR0PTR a_Name
1954#endif
1955
1956/** @def DECLINLINE
1957 * How to declare a function as inline that does not throw any C++ exceptions.
1958 * @param a_RetType The return type of the function declaration.
1959 * @remarks Don't use this macro on C++ methods.
1960 * @sa DECL_INLINE_THROW
1961 */
1962#if defined(__GNUC__) && !defined(DOXYGEN_RUNNING)
1963# define DECLINLINE(a_RetType) DECL_NOTHROW(static __inline__ a_RetType)
1964#elif defined(__cplusplus) || defined(DOXYGEN_RUNNING)
1965# define DECLINLINE(a_RetType) DECL_NOTHROW(static inline a_RetType)
1966#elif defined(_MSC_VER)
1967# define DECLINLINE(a_RetType) DECL_NOTHROW(static _inline a_RetType)
1968#elif defined(__IBMC__)
1969# define DECLINLINE(a_RetType) DECL_NOTHROW(_Inline a_RetType)
1970#else
1971# define DECLINLINE(a_RetType) DECL_NOTHROW(inline a_RetType)
1972#endif
1973
1974/** @def DECL_INLINE_THROW
1975 * How to declare a function as inline that throws C++ exceptions.
1976 * @param a_RetType The return type of the function declaration.
1977 * @remarks Don't use this macro on C++ methods.
1978 */
1979#if defined(__GNUC__) && !defined(DOXYGEN_RUNNING)
1980# define DECL_INLINE_THROW(a_RetType) static __inline__ a_RetType
1981#elif defined(__cplusplus) || defined(DOXYGEN_RUNNING)
1982# define DECL_INLINE_THROW(a_RetType) static inline a_RetType
1983#elif defined(_MSC_VER)
1984# define DECL_INLINE_THROW(a_RetType) static _inline a_RetType
1985#elif defined(__IBMC__)
1986# define DECL_INLINE_THROW(a_RetType) _Inline a_RetType
1987#else
1988# define DECL_INLINE_THROW(a_RetType) inline a_RetType
1989#endif
1990
1991/** @def DECL_FORCE_INLINE
1992 * How to declare a function that does not throw any C++ exceptions as inline
1993 * and try convince the compiler to always inline it regardless of optimization
1994 * switches.
1995 * @param a_RetType The return type of the function declaration.
1996 * @remarks Use sparsely and with care. Don't use this macro on C++ methods.
1997 * @sa DECL_FORCE_INLINE_THROW
1998 */
1999#ifdef __GNUC__
2000# define DECL_FORCE_INLINE(a_RetType) __attribute__((__always_inline__)) DECLINLINE(a_RetType)
2001#elif defined(_MSC_VER)
2002# define DECL_FORCE_INLINE(a_RetType) DECL_NOTHROW(__forceinline a_RetType)
2003#else
2004# define DECL_FORCE_INLINE(a_RetType) DECLINLINE(a_RetType)
2005#endif
2006
2007/** @def DECL_FORCE_INLINE_THROW
2008 * How to declare a function throwing C++ exceptions as inline and try convince
2009 * the compiler to always inline it regardless of optimization switches.
2010 * @param a_RetType The return type of the function declaration.
2011 * @remarks Use sparsely and with care. Don't use this macro on C++ methods.
2012 */
2013#ifdef __GNUC__
2014# define DECL_FORCE_INLINE_THROW(a_RetType) __attribute__((__always_inline__)) DECL_INLINE_THROW(a_RetType)
2015#elif defined(_MSC_VER)
2016# define DECL_FORCE_INLINE_THROW(a_RetType) __forceinline a_RetType
2017#else
2018# define DECL_FORCE_INLINE_THROW(a_RetType) DECL_INLINE_THROW(a_RetType)
2019#endif
2020
2021
2022/** @def DECL_NO_INLINE
2023 * How to declare a function telling the compiler not to inline it.
2024 * @param scope The function scope, static or RT_NOTHING.
2025 * @param a_RetType The return type of the function declaration.
2026 * @remarks Don't use this macro on C++ methods.
2027 */
2028#ifdef __GNUC__
2029# define DECL_NO_INLINE(scope, a_RetType) __attribute__((__noinline__)) scope a_RetType
2030#elif defined(_MSC_VER)
2031# define DECL_NO_INLINE(scope, a_RetType) __declspec(noinline) scope a_RetType
2032#else
2033# define DECL_NO_INLINE(scope,a_RetType) scope a_RetType
2034#endif
2035
2036
2037/** @def IN_RT_STATIC
2038 * Used to indicate whether we're linking against a static IPRT
2039 * or not.
2040 *
2041 * The IPRT symbols will be declared as hidden (if supported). Note that this
2042 * define has no effect without also setting one of the IN_RT_R0, IN_RT_R3 or
2043 * IN_RT_RC indicators.
2044 */
2045
2046/** @def IN_RT_R0
2047 * Used to indicate whether we're inside the same link module as the host
2048 * context ring-0 Runtime Library.
2049 */
2050/** @def RTR0DECL(a_RetType)
2051 * Runtime Library host context ring-0 export or import declaration.
2052 * @param a_RetType The return a_RetType of the function declaration.
2053 * @remarks This is only used inside IPRT. Other APIs need to define their own
2054 * XXXX_DECL macros for dealing with import/export/static visibility.
2055 * @note DECL_NOTHROW is implied.
2056 */
2057#ifdef IN_RT_R0
2058# ifdef IN_RT_STATIC
2059# define RTR0DECL(a_RetType) DECL_HIDDEN_NOTHROW(a_RetType) RTCALL
2060# else
2061# define RTR0DECL(a_RetType) DECL_EXPORT_NOTHROW(a_RetType) RTCALL
2062# endif
2063#else
2064# define RTR0DECL(a_RetType) DECL_IMPORT_NOTHROW(a_RetType) RTCALL
2065#endif
2066
2067/** @def IN_RT_R3
2068 * Used to indicate whether we're inside the same link module as the host
2069 * context ring-3 Runtime Library.
2070 */
2071/** @def RTR3DECL(a_RetType)
2072 * Runtime Library host context ring-3 export or import declaration.
2073 * @param a_RetType The return type of the function declaration.
2074 * @remarks This is only used inside IPRT. Other APIs need to define their own
2075 * XXXX_DECL macros for dealing with import/export/static visibility.
2076 * @note DECL_NOTHROW is implied.
2077 */
2078#ifdef IN_RT_R3
2079# ifdef IN_RT_STATIC
2080# define RTR3DECL(a_RetType) DECL_HIDDEN_NOTHROW(a_RetType) RTCALL
2081# else
2082# define RTR3DECL(a_RetType) DECL_EXPORT_NOTHROW(a_RetType) RTCALL
2083# endif
2084#else
2085# define RTR3DECL(a_RetType) DECL_IMPORT_NOTHROW(a_RetType) RTCALL
2086#endif
2087
2088/** @def IN_RT_RC
2089 * Used to indicate whether we're inside the same link module as the raw-mode
2090 * context (RC) runtime library.
2091 */
2092/** @def RTRCDECL(a_RetType)
2093 * Runtime Library raw-mode context export or import declaration.
2094 * @param a_RetType The return type of the function declaration.
2095 * @remarks This is only used inside IPRT. Other APIs need to define their own
2096 * XXXX_DECL macros for dealing with import/export/static visibility.
2097 * @note DECL_NOTHROW is implied.
2098 */
2099#ifdef IN_RT_RC
2100# ifdef IN_RT_STATIC
2101# define RTRCDECL(a_RetType) DECL_HIDDEN_NOTHROW(a_RetType) RTCALL
2102# else
2103# define RTRCDECL(a_RetType) DECL_EXPORT_NOTHROW(a_RetType) RTCALL
2104# endif
2105#else
2106# define RTRCDECL(a_RetType) DECL_IMPORT_NOTHROW(a_RetType) RTCALL
2107#endif
2108
2109/** @def RTDECL(a_RetType)
2110 * Runtime Library export or import declaration.
2111 * Functions declared using this macro exists in all contexts.
2112 * @param a_RetType The return type of the function declaration.
2113 * @remarks This is only used inside IPRT. Other APIs need to define their own
2114 * XXXX_DECL macros for dealing with import/export/static visibility.
2115 * @note DECL_NOTHROW is implied.
2116 */
2117#if defined(IN_RT_R3) || defined(IN_RT_RC) || defined(IN_RT_R0)
2118# ifdef IN_RT_STATIC
2119# define RTDECL(a_RetType) DECL_HIDDEN_NOTHROW(a_RetType) RTCALL
2120# else
2121# define RTDECL(a_RetType) DECL_EXPORT_NOTHROW(a_RetType) RTCALL
2122# endif
2123#else
2124# define RTDECL(a_RetType) DECL_IMPORT_NOTHROW(a_RetType) RTCALL
2125#endif
2126
2127/** @def RT_DECL_ASM(a_RetType)
2128 * Runtime Library assembly export or import declaration.
2129 * Functions declared using this macro exists in all contexts.
2130 * @param a_RetType The return type of the function declaration.
2131 * @remarks This is only used inside IPRT.
2132 * @note This is compatible with DECLASM, just add hidden/import/export
2133 * attributes to the function.
2134 */
2135#if defined(IN_RT_R3) || defined(IN_RT_RC) || defined(IN_RT_R0)
2136# ifdef IN_RT_STATIC
2137# define RT_DECL_ASM(a_RetType) DECL_EXTERN_C(DECL_HIDDEN_NOTHROW(a_RetType RTCALL))
2138# else
2139# define RT_DECL_ASM(a_RetType) DECL_EXTERN_C(DECL_EXPORT_NOTHROW(a_RetType RTCALL))
2140# endif
2141#else
2142# define RT_DECL_ASM(a_RetType) DECL_EXTERN_C(DECL_IMPORT_NOTHROW(a_RetType RTCALL))
2143#endif
2144
2145/** @def RTDATADECL(a_Type)
2146 * Runtime Library export or import declaration.
2147 * Data declared using this macro exists in all contexts.
2148 * @param a_Type The data type.
2149 * @remarks This is only used inside IPRT. Other APIs need to define their own
2150 * XXXX_DECL macros for dealing with import/export/static visibility.
2151 */
2152/** @def RT_DECL_DATA_CONST(a_Type)
2153 * Definition of a const variable. See DECL_HIDDEN_CONST.
2154 * @param a_Type The const data type.
2155 * @remarks This is only used inside IPRT. Other APIs need to define their own
2156 * XXXX_DECL macros for dealing with import/export/static visibility.
2157 */
2158#if defined(IN_RT_R3) || defined(IN_RT_RC) || defined(IN_RT_R0)
2159# ifdef IN_RT_STATIC
2160# define RTDATADECL(a_Type) DECL_HIDDEN_DATA(a_Type)
2161# define RT_DECL_DATA_CONST(a_Type) DECL_HIDDEN_CONST(a_Type)
2162# else
2163# define RTDATADECL(a_Type) DECLEXPORT(a_Type)
2164# if defined(__cplusplus) && defined(__GNUC__)
2165# define RT_DECL_DATA_CONST(a_Type) a_Type
2166# else
2167# define RT_DECL_DATA_CONST(a_Type) DECLEXPORT(a_Type)
2168# endif
2169# endif
2170#else
2171# define RTDATADECL(a_Type) DECLIMPORT(a_Type)
2172# define RT_DECL_DATA_CONST(a_Type) DECLIMPORT(a_Type)
2173#endif
2174
2175/** @def RT_DECL_CLASS
2176 * Declares an class living in the runtime.
2177 * @remarks This is only used inside IPRT. Other APIs need to define their own
2178 * XXXX_DECL macros for dealing with import/export/static visibility.
2179 */
2180#if defined(IN_RT_R3) || defined(IN_RT_RC) || defined(IN_RT_R0)
2181# ifdef IN_RT_STATIC
2182# define RT_DECL_CLASS
2183# else
2184# define RT_DECL_CLASS DECLEXPORT_CLASS
2185# endif
2186#else
2187# define RT_DECL_CLASS DECLIMPORT_CLASS
2188#endif
2189
2190
2191/** @def RT_NOCRT
2192 * Symbol name wrapper for the No-CRT bits.
2193 *
2194 * In order to coexist in the same process as other CRTs, we need to
2195 * decorate the symbols such that they don't conflict the ones in the
2196 * other CRTs. The result of such conflicts / duplicate symbols can
2197 * confuse the dynamic loader on Unix like systems.
2198 *
2199 * Define RT_WITHOUT_NOCRT_WRAPPERS to drop the wrapping.
2200 * Define RT_WITHOUT_NOCRT_WRAPPER_ALIASES to drop the aliases to the
2201 * wrapped names.
2202 */
2203/** @def RT_NOCRT_STR
2204 * Same as RT_NOCRT only it'll return a double quoted string of the result.
2205 */
2206#if !defined(RT_WITHOUT_NOCRT_WRAPPERS) || defined(RT_FORCE_NOCRT_WRAPPERS)
2207# define RT_NOCRT(name) nocrt_ ## name
2208# define RT_NOCRT_STR(name) "nocrt_" # name
2209#else
2210# define RT_NOCRT(name) name
2211# define RT_NOCRT_STR(name) #name
2212#endif
2213
2214
2215/** @name Untrusted data classifications.
2216 * @{ */
2217/** @def RT_UNTRUSTED_USER
2218 * For marking non-volatile (race free) data from user mode as untrusted.
2219 * This is just for visible documentation. */
2220#define RT_UNTRUSTED_USER
2221/** @def RT_UNTRUSTED_VOLATILE_USER
2222 * For marking volatile data shared with user mode as untrusted.
2223 * This is more than just documentation as it specifies the 'volatile' keyword,
2224 * because the guest could modify the data at any time. */
2225#define RT_UNTRUSTED_VOLATILE_USER volatile
2226
2227/** @def RT_UNTRUSTED_GUEST
2228 * For marking non-volatile (race free) data from the guest as untrusted.
2229 * This is just for visible documentation. */
2230#define RT_UNTRUSTED_GUEST
2231/** @def RT_UNTRUSTED_VOLATILE_GUEST
2232 * For marking volatile data shared with the guest as untrusted.
2233 * This is more than just documentation as it specifies the 'volatile' keyword,
2234 * because the guest could modify the data at any time. */
2235#define RT_UNTRUSTED_VOLATILE_GUEST volatile
2236
2237/** @def RT_UNTRUSTED_HOST
2238 * For marking non-volatile (race free) data from the host as untrusted.
2239 * This is just for visible documentation. */
2240#define RT_UNTRUSTED_HOST
2241/** @def RT_UNTRUSTED_VOLATILE_HOST
2242 * For marking volatile data shared with the host as untrusted.
2243 * This is more than just documentation as it specifies the 'volatile' keyword,
2244 * because the host could modify the data at any time. */
2245#define RT_UNTRUSTED_VOLATILE_HOST volatile
2246
2247/** @def RT_UNTRUSTED_HSTGST
2248 * For marking non-volatile (race free) data from the host/gust as untrusted.
2249 * This is just for visible documentation. */
2250#define RT_UNTRUSTED_HSTGST
2251/** @def RT_UNTRUSTED_VOLATILE_HSTGST
2252 * For marking volatile data shared with the host/guest as untrusted.
2253 * This is more than just documentation as it specifies the 'volatile' keyword,
2254 * because the host could modify the data at any time. */
2255#define RT_UNTRUSTED_VOLATILE_HSTGST volatile
2256/** @} */
2257
2258/** @name Fences for use when handling untrusted data.
2259 * @{ */
2260/** For use after copying untruated volatile data to a non-volatile location.
2261 * This translates to a compiler memory barrier and will help ensure that the
2262 * compiler uses the non-volatile copy of the data. */
2263#define RT_UNTRUSTED_NONVOLATILE_COPY_FENCE() ASMCompilerBarrier()
2264/** For use after finished validating guest input.
2265 * What this translates to is architecture dependent. On intel it will
2266 * translate to a CPU load+store fence as well as a compiler memory barrier. */
2267#if defined(RT_ARCH_AMD64) || (defined(RT_ARCH_X86) && !defined(RT_WITH_OLD_CPU_SUPPORT))
2268# define RT_UNTRUSTED_VALIDATED_FENCE() do { ASMCompilerBarrier(); ASMReadFence(); } while (0)
2269#elif defined(RT_ARCH_X86)
2270# define RT_UNTRUSTED_VALIDATED_FENCE() do { ASMCompilerBarrier(); ASMMemoryFence(); } while (0)
2271#else
2272# define RT_UNTRUSTED_VALIDATED_FENCE() do { ASMCompilerBarrier(); } while (0)
2273#endif
2274/** @} */
2275
2276
2277/** @def RT_LIKELY
2278 * Give the compiler a hint that an expression is very likely to hold true.
2279 *
2280 * Some compilers support explicit branch prediction so that the CPU backend
2281 * can hint the processor and also so that code blocks can be reordered such
2282 * that the predicted path sees a more linear flow, thus improving cache
2283 * behaviour, etc.
2284 *
2285 * IPRT provides the macros RT_LIKELY() and RT_UNLIKELY() as a way to utilize
2286 * this compiler feature when present.
2287 *
2288 * A few notes about the usage:
2289 *
2290 * - Generally, order your code use RT_LIKELY() instead of RT_UNLIKELY().
2291 *
2292 * - Generally, use RT_UNLIKELY() with error condition checks (unless you
2293 * have some _strong_ reason to do otherwise, in which case document it),
2294 * and/or RT_LIKELY() with success condition checks, assuming you want
2295 * to optimize for the success path.
2296 *
2297 * - Other than that, if you don't know the likelihood of a test succeeding
2298 * from empirical or other 'hard' evidence, don't make predictions unless
2299 * you happen to be a Dirk Gently character.
2300 *
2301 * - These macros are meant to be used in places that get executed a lot. It
2302 * is wasteful to make predictions in code that is executed rarely (e.g.
2303 * at subsystem initialization time) as the basic block reordering that this
2304 * affects can often generate larger code.
2305 *
2306 * - Note that RT_SUCCESS() and RT_FAILURE() already makes use of RT_LIKELY()
2307 * and RT_UNLIKELY(). Should you wish for prediction free status checks,
2308 * use the RT_SUCCESS_NP() and RT_FAILURE_NP() macros instead.
2309 *
2310 *
2311 * @returns the boolean result of the expression.
2312 * @param expr The expression that's very likely to be true.
2313 * @see RT_UNLIKELY
2314 */
2315/** @def RT_UNLIKELY
2316 * Give the compiler a hint that an expression is highly unlikely to hold true.
2317 *
2318 * See the usage instructions give in the RT_LIKELY() docs.
2319 *
2320 * @returns the boolean result of the expression.
2321 * @param expr The expression that's very unlikely to be true.
2322 * @see RT_LIKELY
2323 *
2324 * @deprecated Please use RT_LIKELY() instead wherever possible! That gives us
2325 * a better chance of the windows compilers to generate favorable code
2326 * too. The belief is that the compiler will by default assume the
2327 * if-case is more likely than the else-case.
2328 */
2329#if defined(__GNUC__)
2330# if __GNUC__ >= 3 && !defined(FORTIFY_RUNNING)
2331# define RT_LIKELY(expr) __builtin_expect(!!(expr), 1)
2332# define RT_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
2333# else
2334# define RT_LIKELY(expr) (expr)
2335# define RT_UNLIKELY(expr) (expr)
2336# endif
2337#else
2338# define RT_LIKELY(expr) (expr)
2339# define RT_UNLIKELY(expr) (expr)
2340#endif
2341
2342/** @def RT_EXPAND_2
2343 * Helper for RT_EXPAND. */
2344#define RT_EXPAND_2(a_Expr) a_Expr
2345/** @def RT_EXPAND
2346 * Returns the expanded expression.
2347 * @param a_Expr The expression to expand. */
2348#define RT_EXPAND(a_Expr) RT_EXPAND_2(a_Expr)
2349
2350/** @def RT_STR
2351 * Returns the argument as a string constant.
2352 * @param str Argument to stringify. */
2353#define RT_STR(str) #str
2354/** @def RT_XSTR
2355 * Returns the expanded argument as a string.
2356 * @param str Argument to expand and stringify. */
2357#define RT_XSTR(str) RT_STR(str)
2358
2359/** @def RT_LSTR_2
2360 * Helper for RT_WSTR that gets the expanded @a str.
2361 * @param str String litteral to prefix with 'L'. */
2362#define RT_LSTR_2(str) L##str
2363/** @def RT_LSTR
2364 * Returns the expanded argument with a L string prefix.
2365 *
2366 * Intended for converting ASCII string \#defines into wide char string
2367 * litterals on Windows.
2368 *
2369 * @param str String litteral to . */
2370#define RT_LSTR(str) RT_LSTR_2(str)
2371
2372/** @def RT_UNPACK_CALL
2373 * Unpacks the an argument list inside an extra set of parenthesis and turns it
2374 * into a call to @a a_Fn.
2375 *
2376 * @param a_Fn Function/macro to call.
2377 * @param a_Args Parameter list in parenthesis.
2378 */
2379#define RT_UNPACK_CALL(a_Fn, a_Args) a_Fn a_Args
2380
2381#if defined(RT_COMPILER_SUPPORTS_VA_ARGS) || defined(DOXYGEN_RUNNING)
2382
2383/** @def RT_UNPACK_ARGS
2384 * Returns the arguments without parenthesis.
2385 *
2386 * @param ... Parameter list in parenthesis.
2387 * @remarks Requires RT_COMPILER_SUPPORTS_VA_ARGS.
2388 */
2389# define RT_UNPACK_ARGS(...) __VA_ARGS__
2390
2391/** @def RT_COUNT_VA_ARGS_HLP
2392 * Helper for RT_COUNT_VA_ARGS that picks out the argument count from
2393 * RT_COUNT_VA_ARGS_REV_SEQ. */
2394# define RT_COUNT_VA_ARGS_HLP( \
2395 c69, c68, c67, c66, c65, c64, c63, c62, c61, c60, \
2396 c59, c58, c57, c56, c55, c54, c53, c52, c51, c50, \
2397 c49, c48, c47, c46, c45, c44, c43, c42, c41, c40, \
2398 c39, c38, c37, c36, c35, c34, c33, c32, c31, c30, \
2399 c29, c28, c27, c26, c25, c24, c23, c22, c21, c20, \
2400 c19, c18, c17, c16, c15, c14, c13, c12, c11, c10, \
2401 c9, c8, c7, c6, c5, c4, c3, c2, c1, cArgs, ...) cArgs
2402/** Argument count sequence. */
2403# define RT_COUNT_VA_ARGS_REV_SEQ \
2404 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, \
2405 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, \
2406 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, \
2407 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, \
2408 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, \
2409 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, \
2410 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
2411/** This is for zero arguments. At least Visual C++ requires it. */
2412# define RT_COUNT_VA_ARGS_PREFIX_RT_NOTHING RT_COUNT_VA_ARGS_REV_SEQ
2413/**
2414 * Counts the number of arguments given to the variadic macro.
2415 *
2416 * Max is 69.
2417 *
2418 * @returns Number of arguments in the ellipsis
2419 * @param ... Arguments to count.
2420 * @remarks Requires RT_COMPILER_SUPPORTS_VA_ARGS.
2421 */
2422# define RT_COUNT_VA_ARGS(...) \
2423 RT_UNPACK_CALL(RT_COUNT_VA_ARGS_HLP, (RT_COUNT_VA_ARGS_PREFIX_ ## __VA_ARGS__ ## RT_NOTHING, \
2424 RT_COUNT_VA_ARGS_REV_SEQ))
2425
2426#endif /* RT_COMPILER_SUPPORTS_VA_ARGS */
2427
2428
2429/** @def RT_CONCAT
2430 * Concatenate the expanded arguments without any extra spaces in between.
2431 *
2432 * @param a The first part.
2433 * @param b The second part.
2434 */
2435#define RT_CONCAT(a,b) RT_CONCAT_HLP(a,b)
2436/** RT_CONCAT helper, don't use. */
2437#define RT_CONCAT_HLP(a,b) a##b
2438
2439/** @def RT_CONCAT3
2440 * Concatenate the expanded arguments without any extra spaces in between.
2441 *
2442 * @param a The 1st part.
2443 * @param b The 2nd part.
2444 * @param c The 3rd part.
2445 */
2446#define RT_CONCAT3(a,b,c) RT_CONCAT3_HLP(a,b,c)
2447/** RT_CONCAT3 helper, don't use. */
2448#define RT_CONCAT3_HLP(a,b,c) a##b##c
2449
2450/** @def RT_CONCAT4
2451 * Concatenate the expanded arguments without any extra spaces in between.
2452 *
2453 * @param a The 1st part.
2454 * @param b The 2nd part.
2455 * @param c The 3rd part.
2456 * @param d The 4th part.
2457 */
2458#define RT_CONCAT4(a,b,c,d) RT_CONCAT4_HLP(a,b,c,d)
2459/** RT_CONCAT4 helper, don't use. */
2460#define RT_CONCAT4_HLP(a,b,c,d) a##b##c##d
2461
2462/** @def RT_CONCAT5
2463 * Concatenate the expanded arguments without any extra spaces in between.
2464 *
2465 * @param a The 1st part.
2466 * @param b The 2nd part.
2467 * @param c The 3rd part.
2468 * @param d The 4th part.
2469 * @param e The 5th part.
2470 */
2471#define RT_CONCAT5(a,b,c,d,e) RT_CONCAT5_HLP(a,b,c,d,e)
2472/** RT_CONCAT5 helper, don't use. */
2473#define RT_CONCAT5_HLP(a,b,c,d,e) a##b##c##d##e
2474
2475/** @def RT_CONCAT6
2476 * Concatenate the expanded arguments without any extra spaces in between.
2477 *
2478 * @param a The 1st part.
2479 * @param b The 2nd part.
2480 * @param c The 3rd part.
2481 * @param d The 4th part.
2482 * @param e The 5th part.
2483 * @param f The 6th part.
2484 */
2485#define RT_CONCAT6(a,b,c,d,e,f) RT_CONCAT6_HLP(a,b,c,d,e,f)
2486/** RT_CONCAT6 helper, don't use. */
2487#define RT_CONCAT6_HLP(a,b,c,d,e,f) a##b##c##d##e##f
2488
2489/** @def RT_CONCAT7
2490 * Concatenate the expanded arguments without any extra spaces in between.
2491 *
2492 * @param a The 1st part.
2493 * @param b The 2nd part.
2494 * @param c The 3rd part.
2495 * @param d The 4th part.
2496 * @param e The 5th part.
2497 * @param f The 6th part.
2498 * @param g The 7th part.
2499 */
2500#define RT_CONCAT7(a,b,c,d,e,f,g) RT_CONCAT7_HLP(a,b,c,d,e,f,g)
2501/** RT_CONCAT7 helper, don't use. */
2502#define RT_CONCAT7_HLP(a,b,c,d,e,f,g) a##b##c##d##e##f##g
2503
2504/** @def RT_CONCAT8
2505 * Concatenate the expanded arguments without any extra spaces in between.
2506 *
2507 * @param a The 1st part.
2508 * @param b The 2nd part.
2509 * @param c The 3rd part.
2510 * @param d The 4th part.
2511 * @param e The 5th part.
2512 * @param f The 6th part.
2513 * @param g The 7th part.
2514 * @param h The 8th part.
2515 */
2516#define RT_CONCAT8(a,b,c,d,e,f,g,h) RT_CONCAT8_HLP(a,b,c,d,e,f,g,h)
2517/** RT_CONCAT8 helper, don't use. */
2518#define RT_CONCAT8_HLP(a,b,c,d,e,f,g,h) a##b##c##d##e##f##g##h
2519
2520/** @def RT_CONCAT9
2521 * Concatenate the expanded arguments without any extra spaces in between.
2522 *
2523 * @param a The 1st part.
2524 * @param b The 2nd part.
2525 * @param c The 3rd part.
2526 * @param d The 4th part.
2527 * @param e The 5th part.
2528 * @param f The 6th part.
2529 * @param g The 7th part.
2530 * @param h The 8th part.
2531 * @param i The 9th part.
2532 */
2533#define RT_CONCAT9(a,b,c,d,e,f,g,h,i) RT_CONCAT9_HLP(a,b,c,d,e,f,g,h,i)
2534/** RT_CONCAT9 helper, don't use. */
2535#define RT_CONCAT9_HLP(a,b,c,d,e,f,g,h,i) a##b##c##d##e##f##g##h##i
2536
2537/**
2538 * String constant tuple - string constant, strlen(string constant).
2539 *
2540 * @param a_szConst String constant.
2541 * @sa RTSTRTUPLE
2542 */
2543#define RT_STR_TUPLE(a_szConst) a_szConst, (sizeof(a_szConst) - 1)
2544
2545
2546/**
2547 * Macro for using in switch statements that turns constants into strings.
2548 *
2549 * @param a_Const The constant (not string).
2550 */
2551#define RT_CASE_RET_STR(a_Const) case a_Const: return #a_Const
2552
2553
2554/** @def RT_BIT
2555 * Convert a bit number into an integer bitmask (unsigned).
2556 * @param bit The bit number.
2557 */
2558#define RT_BIT(bit) ( 1U << (bit) )
2559
2560/** @def RT_BIT_32
2561 * Convert a bit number into a 32-bit bitmask (unsigned).
2562 * @param bit The bit number.
2563 */
2564#define RT_BIT_32(bit) ( UINT32_C(1) << (bit) )
2565
2566/** @def RT_BIT_64
2567 * Convert a bit number into a 64-bit bitmask (unsigned).
2568 * @param bit The bit number.
2569 */
2570#define RT_BIT_64(bit) ( UINT64_C(1) << (bit) )
2571
2572/** @def RT_BIT_Z
2573 * Convert a bit number into a size_t bitmask (for avoid MSC warnings).
2574 * @param a_iBit The bit number.
2575 */
2576#define RT_BIT_Z(a_iBit) ( (size_t)(1) << (a_iBit) )
2577
2578
2579/** @def RT_BF_GET
2580 * Gets the value of a bit field in an integer value.
2581 *
2582 * This requires a couple of macros to be defined for the field:
2583 * - \<a_FieldNm\>_SHIFT: The shift count to get to the field.
2584 * - \<a_FieldNm\>_MASK: The field mask.
2585 *
2586 * @returns The bit field value.
2587 * @param a_uValue The integer value containing the field.
2588 * @param a_FieldNm The field name prefix for getting at the _SHIFT and
2589 * _MASK macros.
2590 * @sa #RT_BF_CLEAR, #RT_BF_SET, #RT_BF_MAKE, #RT_BF_ZMASK
2591 */
2592#define RT_BF_GET(a_uValue, a_FieldNm) ( ((a_uValue) >> RT_CONCAT(a_FieldNm,_SHIFT)) & RT_BF_ZMASK(a_FieldNm) )
2593
2594/** @def RT_BF_SET
2595 * Sets the given bit field in the integer value.
2596 *
2597 * This requires a couple of macros to be defined for the field:
2598 * - \<a_FieldNm\>_SHIFT: The shift count to get to the field.
2599 * - \<a_FieldNm\>_MASK: The field mask. Must have the same type as the
2600 * integer value!!
2601 *
2602 * @returns Integer value with bit field set to @a a_uFieldValue.
2603 * @param a_uValue The integer value containing the field.
2604 * @param a_FieldNm The field name prefix for getting at the _SHIFT and
2605 * _MASK macros.
2606 * @param a_uFieldValue The new field value.
2607 * @sa #RT_BF_GET, #RT_BF_CLEAR, #RT_BF_MAKE, #RT_BF_ZMASK
2608 */
2609#define RT_BF_SET(a_uValue, a_FieldNm, a_uFieldValue) ( RT_BF_CLEAR(a_uValue, a_FieldNm) | RT_BF_MAKE(a_FieldNm, a_uFieldValue) )
2610
2611/** @def RT_BF_CLEAR
2612 * Clears the given bit field in the integer value.
2613 *
2614 * This requires a couple of macros to be defined for the field:
2615 * - \<a_FieldNm\>_SHIFT: The shift count to get to the field.
2616 * - \<a_FieldNm\>_MASK: The field mask. Must have the same type as the
2617 * integer value!!
2618 *
2619 * @returns Integer value with bit field set to zero.
2620 * @param a_uValue The integer value containing the field.
2621 * @param a_FieldNm The field name prefix for getting at the _SHIFT and
2622 * _MASK macros.
2623 * @sa #RT_BF_GET, #RT_BF_SET, #RT_BF_MAKE, #RT_BF_ZMASK
2624 */
2625#define RT_BF_CLEAR(a_uValue, a_FieldNm) ( (a_uValue) & ~RT_CONCAT(a_FieldNm,_MASK) )
2626
2627/** @def RT_BF_MAKE
2628 * Shifts and masks a bit field value into position in the integer value.
2629 *
2630 * This requires a couple of macros to be defined for the field:
2631 * - \<a_FieldNm\>_SHIFT: The shift count to get to the field.
2632 * - \<a_FieldNm\>_MASK: The field mask.
2633 *
2634 * @param a_FieldNm The field name prefix for getting at the _SHIFT and
2635 * _MASK macros.
2636 * @param a_uFieldValue The field value that should be masked and shifted
2637 * into position.
2638 * @sa #RT_BF_GET, #RT_BF_SET, #RT_BF_CLEAR, #RT_BF_ZMASK
2639 */
2640#define RT_BF_MAKE(a_FieldNm, a_uFieldValue) ( ((a_uFieldValue) & RT_BF_ZMASK(a_FieldNm) ) << RT_CONCAT(a_FieldNm,_SHIFT) )
2641
2642/** @def RT_BF_ZMASK
2643 * Helper for getting the field mask shifted to bit position zero.
2644 *
2645 * @param a_FieldNm The field name prefix for getting at the _SHIFT and
2646 * _MASK macros.
2647 * @sa #RT_BF_GET, #RT_BF_SET, #RT_BF_CLEAR, #RT_BF_MAKE
2648 */
2649#define RT_BF_ZMASK(a_FieldNm) ( RT_CONCAT(a_FieldNm,_MASK) >> RT_CONCAT(a_FieldNm,_SHIFT) )
2650
2651/** Bit field compile time check helper
2652 * @internal */
2653#define RT_BF_CHECK_DO_XOR_MASK(a_uLeft, a_RightPrefix, a_FieldNm) ((a_uLeft) ^ RT_CONCAT3(a_RightPrefix, a_FieldNm, _MASK))
2654/** Bit field compile time check helper
2655 * @internal */
2656#define RT_BF_CHECK_DO_OR_MASK(a_uLeft, a_RightPrefix, a_FieldNm) ((a_uLeft) | RT_CONCAT3(a_RightPrefix, a_FieldNm, _MASK))
2657/** Bit field compile time check helper
2658 * @internal */
2659#define RT_BF_CHECK_DO_1ST_MASK_BIT(a_uLeft, a_RightPrefix, a_FieldNm) \
2660 ((a_uLeft) && ( (RT_CONCAT3(a_RightPrefix, a_FieldNm, _MASK) >> RT_CONCAT3(a_RightPrefix, a_FieldNm, _SHIFT)) & 1U ) )
2661/** Used to check that a bit field mask does not start too early.
2662 * @internal */
2663#define RT_BF_CHECK_DO_MASK_START(a_uLeft, a_RightPrefix, a_FieldNm) \
2664 ( (a_uLeft) \
2665 && ( RT_CONCAT3(a_RightPrefix, a_FieldNm, _SHIFT) == 0 \
2666 || ( ( ( ((RT_CONCAT3(a_RightPrefix, a_FieldNm, _MASK) >> RT_CONCAT3(a_RightPrefix, a_FieldNm, _SHIFT)) & 1U) \
2667 << RT_CONCAT3(a_RightPrefix, a_FieldNm, _SHIFT)) /* => single bit mask, correct type */ \
2668 - 1U) /* => mask of all bits below the field */ \
2669 & RT_CONCAT3(a_RightPrefix, a_FieldNm, _MASK)) == 0 ) )
2670/** @name Bit field compile time check recursion workers.
2671 * @internal
2672 * @{ */
2673#define RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix, f1) \
2674 a_DoThis(a_uLeft, a_RightPrefix, f1)
2675#define RT_BF_CHECK_DO_2(a_DoThis, a_uLeft, a_RightPrefix, f1, f2) \
2676 RT_BF_CHECK_DO_1(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2)
2677#define RT_BF_CHECK_DO_3(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3) \
2678 RT_BF_CHECK_DO_2(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3)
2679#define RT_BF_CHECK_DO_4(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4) \
2680 RT_BF_CHECK_DO_3(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4)
2681#define RT_BF_CHECK_DO_5(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5) \
2682 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)
2683#define RT_BF_CHECK_DO_6(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6) \
2684 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)
2685#define RT_BF_CHECK_DO_7(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7) \
2686 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)
2687#define RT_BF_CHECK_DO_8(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8) \
2688 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)
2689#define RT_BF_CHECK_DO_9(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9) \
2690 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)
2691#define RT_BF_CHECK_DO_10(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10) \
2692 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)
2693#define RT_BF_CHECK_DO_11(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11) \
2694 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)
2695#define RT_BF_CHECK_DO_12(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12) \
2696 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)
2697#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) \
2698 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)
2699#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) \
2700 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)
2701#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) \
2702 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)
2703#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) \
2704 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)
2705#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) \
2706 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)
2707#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) \
2708 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)
2709#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) \
2710 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)
2711#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) \
2712 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)
2713#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) \
2714 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)
2715#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) \
2716 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)
2717#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) \
2718 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)
2719#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) \
2720 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)
2721#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) \
2722 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)
2723#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) \
2724 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)
2725#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) \
2726 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)
2727#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) \
2728 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)
2729#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) \
2730 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)
2731#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) \
2732 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)
2733#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) \
2734 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)
2735#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) \
2736 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)
2737#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) \
2738 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)
2739#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) \
2740 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)
2741#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) \
2742 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)
2743#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) \
2744 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)
2745#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) \
2746 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)
2747#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) \
2748 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)
2749#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) \
2750 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)
2751#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) \
2752 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)
2753#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) \
2754 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)
2755#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) \
2756 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)
2757#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) \
2758 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)
2759#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) \
2760 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)
2761#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) \
2762 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)
2763#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) \
2764 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)
2765#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) \
2766 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)
2767#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) \
2768 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)
2769#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) \
2770 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)
2771#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) \
2772 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)
2773#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) \
2774 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)
2775#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) \
2776 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)
2777#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) \
2778 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)
2779#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) \
2780 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)
2781#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) \
2782 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)
2783#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) \
2784 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)
2785#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) \
2786 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)
2787#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) \
2788 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)
2789#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) \
2790 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)
2791#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) \
2792 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)
2793#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) \
2794 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)
2795#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) \
2796 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)
2797#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) \
2798 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)
2799#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) \
2800 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)
2801/** @} */
2802
2803/** @def RT_BF_ASSERT_COMPILE_CHECKS
2804 * Emits a series of AssertCompile statements checking that the bit-field
2805 * declarations doesn't overlap, has holes, and generally makes some sense.
2806 *
2807 * This requires variadic macros because its too much to type otherwise.
2808 */
2809#if defined(RT_COMPILER_SUPPORTS_VA_ARGS) || defined(DOXYGEN_RUNNING)
2810# define RT_BF_ASSERT_COMPILE_CHECKS(a_Prefix, a_uZero, a_uCovered, a_Fields) \
2811 AssertCompile(RT_BF_CHECK_DO_N(RT_BF_CHECK_DO_OR_MASK, a_uZero, a_Prefix, RT_UNPACK_ARGS a_Fields ) == a_uCovered); \
2812 AssertCompile(RT_BF_CHECK_DO_N(RT_BF_CHECK_DO_XOR_MASK, a_uCovered, a_Prefix, RT_UNPACK_ARGS a_Fields ) == 0); \
2813 AssertCompile(RT_BF_CHECK_DO_N(RT_BF_CHECK_DO_1ST_MASK_BIT, true, a_Prefix, RT_UNPACK_ARGS a_Fields ) == true); \
2814 AssertCompile(RT_BF_CHECK_DO_N(RT_BF_CHECK_DO_MASK_START, true, a_Prefix, RT_UNPACK_ARGS a_Fields ) == true)
2815/** Bit field compile time check helper
2816 * @internal */
2817# define RT_BF_CHECK_DO_N(a_DoThis, a_uLeft, a_RightPrefix, ...) \
2818 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__))
2819#else
2820# define RT_BF_ASSERT_COMPILE_CHECKS(a_Prefix, a_uZero, a_uCovered, a_Fields) AssertCompile(true)
2821#endif
2822
2823
2824/** @def RT_ALIGN
2825 * Align macro.
2826 * @param u Value to align.
2827 * @param uAlignment The alignment. Power of two!
2828 *
2829 * @remark Be extremely careful when using this macro with type which sizeof != sizeof int.
2830 * When possible use any of the other RT_ALIGN_* macros. And when that's not
2831 * possible, make 101% sure that uAlignment is specified with a right sized type.
2832 *
2833 * Specifying an unsigned 32-bit alignment constant with a 64-bit value will give
2834 * you a 32-bit return value!
2835 *
2836 * In short: Don't use this macro. Use RT_ALIGN_T() instead.
2837 */
2838#define RT_ALIGN(u, uAlignment) ( ((u) + ((uAlignment) - 1)) & ~((uAlignment) - 1) )
2839
2840/** @def RT_ALIGN_T
2841 * Align macro.
2842 * @param u Value to align.
2843 * @param uAlignment The alignment. Power of two!
2844 * @param type Integer type to use while aligning.
2845 * @remark This macro is the preferred alignment macro, it doesn't have any of the pitfalls RT_ALIGN has.
2846 */
2847#define RT_ALIGN_T(u, uAlignment, type) ( ((type)(u) + ((uAlignment) - 1)) & ~(type)((uAlignment) - 1) )
2848
2849/** @def RT_ALIGN_32
2850 * Align macro for a 32-bit value.
2851 * @param u32 Value to align.
2852 * @param uAlignment The alignment. Power of two!
2853 */
2854#define RT_ALIGN_32(u32, uAlignment) RT_ALIGN_T(u32, uAlignment, uint32_t)
2855
2856/** @def RT_ALIGN_64
2857 * Align macro for a 64-bit value.
2858 * @param u64 Value to align.
2859 * @param uAlignment The alignment. Power of two!
2860 */
2861#define RT_ALIGN_64(u64, uAlignment) RT_ALIGN_T(u64, uAlignment, uint64_t)
2862
2863/** @def RT_ALIGN_Z
2864 * Align macro for size_t.
2865 * @param cb Value to align.
2866 * @param uAlignment The alignment. Power of two!
2867 */
2868#define RT_ALIGN_Z(cb, uAlignment) RT_ALIGN_T(cb, uAlignment, size_t)
2869
2870/** @def RT_ALIGN_P
2871 * Align macro for pointers.
2872 * @param pv Value to align.
2873 * @param uAlignment The alignment. Power of two!
2874 */
2875#define RT_ALIGN_P(pv, uAlignment) RT_ALIGN_PT(pv, uAlignment, void *)
2876
2877/** @def RT_ALIGN_PT
2878 * Align macro for pointers with type cast.
2879 * @param u Value to align.
2880 * @param uAlignment The alignment. Power of two!
2881 * @param CastType The type to cast the result to.
2882 */
2883#define RT_ALIGN_PT(u, uAlignment, CastType) ( (CastType)RT_ALIGN_T(u, uAlignment, uintptr_t) )
2884
2885/** @def RT_ALIGN_R3PT
2886 * Align macro for ring-3 pointers with type cast.
2887 * @param u Value to align.
2888 * @param uAlignment The alignment. Power of two!
2889 * @param CastType The type to cast the result to.
2890 */
2891#define RT_ALIGN_R3PT(u, uAlignment, CastType) ( (CastType)RT_ALIGN_T(u, uAlignment, RTR3UINTPTR) )
2892
2893/** @def RT_ALIGN_R0PT
2894 * Align macro for ring-0 pointers with type cast.
2895 * @param u Value to align.
2896 * @param uAlignment The alignment. Power of two!
2897 * @param CastType The type to cast the result to.
2898 */
2899#define RT_ALIGN_R0PT(u, uAlignment, CastType) ( (CastType)RT_ALIGN_T(u, uAlignment, RTR0UINTPTR) )
2900
2901/** @def RT_ALIGN_GCPT
2902 * Align macro for GC pointers with type cast.
2903 * @param u Value to align.
2904 * @param uAlignment The alignment. Power of two!
2905 * @param CastType The type to cast the result to.
2906 */
2907#define RT_ALIGN_GCPT(u, uAlignment, CastType) ( (CastType)RT_ALIGN_T(u, uAlignment, RTGCUINTPTR) )
2908
2909
2910/** @def RT_OFFSETOF
2911 * Our own special offsetof() variant, returns a signed result.
2912 *
2913 * @returns offset into the structure of the specified member. signed.
2914 * @param type Structure type.
2915 * @param member Member.
2916 *
2917 * @remarks Only use this for static offset calculations. Please
2918 * use RT_UOFFSETOF_DYN for dynamic ones (i.e. involves
2919 * non-constant array indexing).
2920 *
2921 */
2922#if RT_GNUC_PREREQ(4, 0)
2923# define RT_OFFSETOF(type, member) ( (int)__builtin_offsetof(type, member) )
2924#else
2925# define RT_OFFSETOF(type, member) ( (int)(intptr_t)&( ((type *)(void *)0)->member) )
2926#endif
2927
2928/** @def RT_UOFFSETOF
2929 * Our own offsetof() variant, returns an unsigned result.
2930 *
2931 * @returns offset into the structure of the specified member. unsigned.
2932 * @param type Structure type.
2933 * @param member Member.
2934 *
2935 * @remarks Only use this for static offset calculations. Please
2936 * use RT_UOFFSETOF_DYN for dynamic ones (i.e. involves
2937 * non-constant array indexing).
2938 */
2939#if RT_GNUC_PREREQ(4, 0)
2940# define RT_UOFFSETOF(type, member) ( (uintptr_t)__builtin_offsetof(type, member) )
2941#else
2942# define RT_UOFFSETOF(type, member) ( (uintptr_t)&( ((type *)(void *)0)->member) )
2943#endif
2944
2945/** @def RT_OFFSETOF_ADD
2946 * RT_OFFSETOF with an addend.
2947 *
2948 * @returns offset into the structure of the specified member. signed.
2949 * @param type Structure type.
2950 * @param member Member.
2951 * @param addend The addend to add to the offset.
2952 *
2953 * @remarks Only use this for static offset calculations.
2954 */
2955#define RT_OFFSETOF_ADD(type, member, addend) ( (int)RT_UOFFSETOF_ADD(type, member, addend) )
2956
2957/** @def RT_UOFFSETOF_ADD
2958 * RT_UOFFSETOF with an addend.
2959 *
2960 * @returns offset into the structure of the specified member. signed.
2961 * @param type Structure type.
2962 * @param member Member.
2963 * @param addend The addend to add to the offset.
2964 *
2965 * @remarks Only use this for static offset calculations.
2966 */
2967#if RT_GNUC_PREREQ(4, 0)
2968# define RT_UOFFSETOF_ADD(type, member, addend) ( (uintptr_t)(__builtin_offsetof(type, member) + (addend)))
2969#else
2970# define RT_UOFFSETOF_ADD(type, member, addend) ( (uintptr_t)&( ((type *)(void *)(uintptr_t)(addend))->member) )
2971#endif
2972
2973/** @def RT_UOFFSETOF_DYN
2974 * Dynamic (runtime) structure offset calculations, involving
2975 * indexing of array members via variable.
2976 *
2977 * @returns offset into the structure of the specified member. signed.
2978 * @param type Structure type.
2979 * @param memberarray Member.
2980 */
2981#if defined(__cplusplus) && RT_GNUC_PREREQ(4, 4)
2982# define RT_UOFFSETOF_DYN(type, memberarray) ( (uintptr_t)&( ((type *)(void *)0x1000)->memberarray) - 0x1000 )
2983#else
2984# define RT_UOFFSETOF_DYN(type, memberarray) ( (uintptr_t)&( ((type *)(void *)0)->memberarray) )
2985#endif
2986
2987
2988/** @def RT_SIZEOFMEMB
2989 * Get the size of a structure member.
2990 *
2991 * @returns size of the structure member.
2992 * @param type Structure type.
2993 * @param member Member.
2994 */
2995#define RT_SIZEOFMEMB(type, member) ( sizeof(((type *)(void *)0)->member) )
2996
2997/** @def RT_UOFFSET_AFTER
2998 * Returns the offset of the first byte following a structure/union member.
2999 *
3000 * @return byte offset into the struct.
3001 * @param a_Type Structure type.
3002 * @param a_Member The member name.
3003 */
3004#define RT_UOFFSET_AFTER(a_Type, a_Member) ( RT_UOFFSETOF(a_Type, a_Member) + RT_SIZEOFMEMB(a_Type, a_Member) )
3005
3006/** @def RT_FROM_MEMBER
3007 * Convert a pointer to a structure member into a pointer to the structure.
3008 *
3009 * @returns pointer to the structure.
3010 * @param pMem Pointer to the member.
3011 * @param Type Structure type.
3012 * @param Member Member name.
3013 */
3014#define RT_FROM_MEMBER(pMem, Type, Member) ( (Type *) ((uint8_t *)(void *)(pMem) - RT_UOFFSETOF(Type, Member)) )
3015
3016/** @def RT_FROM_CPP_MEMBER
3017 * Same as RT_FROM_MEMBER except it avoids the annoying g++ warnings about
3018 * invalid access to non-static data member of NULL object.
3019 *
3020 * @returns pointer to the structure.
3021 * @param pMem Pointer to the member.
3022 * @param Type Structure type.
3023 * @param Member Member name.
3024 *
3025 * @remarks Using the __builtin_offsetof does not shut up the compiler.
3026 */
3027#if defined(__GNUC__) && defined(__cplusplus)
3028# define RT_FROM_CPP_MEMBER(pMem, Type, Member) \
3029 ( (Type *) ((uintptr_t)(pMem) - (uintptr_t)&((Type *)0x1000)->Member + 0x1000U) )
3030#else
3031# define RT_FROM_CPP_MEMBER(pMem, Type, Member) RT_FROM_MEMBER(pMem, Type, Member)
3032#endif
3033
3034/** @def RT_FROM_MEMBER_DYN
3035 * Convert a pointer to a structure member into a pointer to the structure.
3036 *
3037 * @returns pointer to the structure.
3038 * @param pMem Pointer to the member.
3039 * @param Type Structure type.
3040 * @param Member Member name dynamic size (some array is index by
3041 * non-constant value).
3042 */
3043#define RT_FROM_MEMBER_DYN(pMem, Type, Member) ( (Type *) ((uint8_t *)(void *)(pMem) - RT_UOFFSETOF_DYN(Type, Member)) )
3044
3045/** @def RT_ELEMENTS
3046 * Calculates the number of elements in a statically sized array.
3047 * @returns Element count.
3048 * @param aArray Array in question.
3049 */
3050#define RT_ELEMENTS(aArray) ( sizeof(aArray) / sizeof((aArray)[0]) )
3051
3052/** @def RT_SAFE_SUBSCRIPT
3053 * Safe array subscript using modulo and size_t cast.
3054 * @param a_Array The array.
3055 * @param a_idx The array index, cast to size_t to ensure unsigned.
3056 */
3057#define RT_SAFE_SUBSCRIPT(a_Array, a_idx) (a_Array)[(size_t)(a_idx) % RT_ELEMENTS(a_Array)]
3058
3059/** @def RT_SAFE_SUBSCRIPT32
3060 * Safe array subscript using modulo and uint32_t cast.
3061 * @param a_Array The array.
3062 * @param a_idx The array index, cast to size_t to ensure unsigned.
3063 * @note Only consider using this if array size is not power of two.
3064 */
3065#define RT_SAFE_SUBSCRIPT32(a_Array, a_idx) (a_Array)[(uint32_t)(a_idx) % RT_ELEMENTS(a_Array)]
3066
3067/** @def RT_SAFE_SUBSCRIPT16
3068 * Safe array subscript using modulo and uint16_t cast.
3069 * @param a_Array The array.
3070 * @param a_idx The array index, cast to size_t to ensure unsigned.
3071 * @note Only consider using this if array size is not power of two.
3072 */
3073#define RT_SAFE_SUBSCRIPT16(a_Array, a_idx) (a_Array)[(uint16_t)(a_idx) % RT_ELEMENTS(a_Array)]
3074
3075/** @def RT_SAFE_SUBSCRIPT8
3076 * Safe array subscript using modulo and uint8_t cast.
3077 * @param a_Array The array.
3078 * @param a_idx The array index, cast to size_t to ensure unsigned.
3079 * @note Only consider using this if array size is not power of two.
3080 */
3081#define RT_SAFE_SUBSCRIPT8(a_Array, a_idx) (a_Array)[(uint8_t)(a_idx) % RT_ELEMENTS(a_Array)]
3082
3083/** @def RT_SAFE_SUBSCRIPT_NC
3084 * Safe array subscript using modulo but no cast.
3085 * @param a_Array The array.
3086 * @param a_idx The array index - assumes unsigned type.
3087 * @note Only consider using this if array size is not power of two.
3088 */
3089#define RT_SAFE_SUBSCRIPT_NC(a_Array, a_idx) (a_Array)[(a_idx) % RT_ELEMENTS(a_Array)]
3090
3091/** @def RT_FLEXIBLE_ARRAY
3092 * What to up inside the square brackets when declaring a structure member
3093 * with a flexible size.
3094 *
3095 * @note RT_FLEXIBLE_ARRAY_EXTENSION must always preceed the type, unless
3096 * it's C-only code.
3097 *
3098 * @note Use RT_UOFFSETOF() to calculate the structure size.
3099 *
3100 * @note Never do a sizeof() on the structure or member!
3101 *
3102 * @note The member must be the last one.
3103 *
3104 * @note GCC does not permit using this in a union. So, for unions you must
3105 * use RT_FLEXIBLE_ARRAY_IN_UNION instead.
3106 *
3107 * @note GCC does not permit using this in nested structures, where as MSC
3108 * does. So, use RT_FLEXIBLE_ARRAY_NESTED for that.
3109 *
3110 * @sa RT_FLEXIBLE_ARRAY_NESTED, RT_FLEXIBLE_ARRAY_IN_UNION
3111 */
3112#if RT_MSC_PREREQ(RT_MSC_VER_VS2005) /** @todo Probably much much earlier. */ \
3113 || (defined(__cplusplus) && RT_GNUC_PREREQ(6, 1)) /* not tested 7.x, but hope it works with __extension__ too. */ \
3114 || defined(__WATCOMC__) /* openwatcom 1.9 supports it, we don't care about older atm. */ \
3115 || RT_CLANG_PREREQ_EX(3, 4, 0) /* Only tested clang v3.4, support is probably older. */
3116# define RT_FLEXIBLE_ARRAY
3117# if defined(__cplusplus) && defined(_MSC_VER)
3118# pragma warning(disable:4200) /* -wd4200 does not work with VS2010 */
3119# pragma warning(disable:4815) /* -wd4815 does not work with VS2019 */
3120# endif
3121#elif defined(__STDC_VERSION__)
3122# if __STDC_VERSION__ >= 199901L
3123# define RT_FLEXIBLE_ARRAY
3124# else /* __STDC_VERSION__ < 199901L */
3125# define RT_FLEXIBLE_ARRAY 1
3126# endif /* __STDC_VERSION__ < 199901L */
3127#else
3128# define RT_FLEXIBLE_ARRAY 1
3129#endif
3130
3131/** @def RT_FLEXIBLE_ARRAY_EXTENSION
3132 * A trick to make GNU C++ quietly accept flexible arrays in C++ code when
3133 * pedantic warnings are enabled. Put this on the line before the flexible
3134 * array. */
3135#if (RT_GNUC_PREREQ(7, 0) && defined(__cplusplus)) || defined(DOXGYEN_RUNNING)
3136# define RT_FLEXIBLE_ARRAY_EXTENSION RT_GCC_EXTENSION
3137#else
3138# define RT_FLEXIBLE_ARRAY_EXTENSION
3139#endif
3140
3141/** @def RT_FLEXIBLE_ARRAY_NESTED
3142 * Variant of RT_FLEXIBLE_ARRAY for use in structures that are nested.
3143 *
3144 * GCC only allow the use of flexible array member in the top structure, whereas
3145 * MSC is less strict and let you do struct { struct { char szName[]; } s; };
3146 *
3147 * @note See notes for RT_FLEXIBLE_ARRAY.
3148 *
3149 * @note GCC does not permit using this in a union. So, for unions you must
3150 * use RT_FLEXIBLE_ARRAY_IN_NESTED_UNION instead.
3151 *
3152 * @sa RT_FLEXIBLE_ARRAY, RT_FLEXIBLE_ARRAY_IN_NESTED_UNION
3153 */
3154#ifdef _MSC_VER
3155# define RT_FLEXIBLE_ARRAY_NESTED RT_FLEXIBLE_ARRAY
3156#else
3157# define RT_FLEXIBLE_ARRAY_NESTED 1
3158#endif
3159
3160/** @def RT_FLEXIBLE_ARRAY_IN_UNION
3161 * The union version of RT_FLEXIBLE_ARRAY.
3162 *
3163 * @remarks GCC does not support flexible array members in unions, 6.1.x
3164 * actively checks for this. Visual C++ 2010 seems happy with it.
3165 *
3166 * @note See notes for RT_FLEXIBLE_ARRAY.
3167 *
3168 * @sa RT_FLEXIBLE_ARRAY, RT_FLEXIBLE_ARRAY_IN_NESTED_UNION
3169 */
3170#ifdef _MSC_VER
3171# define RT_FLEXIBLE_ARRAY_IN_UNION RT_FLEXIBLE_ARRAY
3172#else
3173# define RT_FLEXIBLE_ARRAY_IN_UNION 1
3174#endif
3175
3176/** @def RT_FLEXIBLE_ARRAY_IN_NESTED_UNION
3177 * The union version of RT_FLEXIBLE_ARRAY_NESTED.
3178 *
3179 * @note See notes for RT_FLEXIBLE_ARRAY.
3180 *
3181 * @sa RT_FLEXIBLE_ARRAY, RT_FLEXIBLE_ARRAY_IN_NESTED_UNION
3182 */
3183#ifdef _MSC_VER
3184# define RT_FLEXIBLE_ARRAY_IN_NESTED_UNION RT_FLEXIBLE_ARRAY_NESTED
3185#else
3186# define RT_FLEXIBLE_ARRAY_IN_NESTED_UNION 1
3187#endif
3188
3189/** @def RT_UNION_NM
3190 * For compilers (like DTrace) that does not grok nameless unions, we have a
3191 * little hack to make them palatable.
3192 */
3193/** @def RT_STRUCT_NM
3194 * For compilers (like DTrace) that does not grok nameless structs (it is
3195 * non-standard C++), we have a little hack to make them palatable.
3196 */
3197#ifdef IPRT_WITHOUT_NAMED_UNIONS_AND_STRUCTS
3198# define RT_UNION_NM(a_Nm) a_Nm
3199# define RT_STRUCT_NM(a_Nm) a_Nm
3200#else
3201# define RT_UNION_NM(a_Nm)
3202# define RT_STRUCT_NM(a_Nm)
3203#endif
3204
3205/**
3206 * Checks if the value is a power of two.
3207 *
3208 * @returns true if power of two, false if not.
3209 * @param uVal The value to test.
3210 * @remarks 0 is a power of two.
3211 * @see VERR_NOT_POWER_OF_TWO
3212 */
3213#define RT_IS_POWER_OF_TWO(uVal) ( ((uVal) & ((uVal) - 1)) == 0)
3214
3215#ifdef RT_OS_OS2
3216/* Undefine RT_MAX since there is an unfortunate clash with the max
3217 resource type define in os2.h. */
3218# undef RT_MAX
3219#endif
3220
3221/** @def RT_MAX
3222 * Finds the maximum value.
3223 * @returns The higher of the two.
3224 * @param Value1 Value 1
3225 * @param Value2 Value 2
3226 */
3227#define RT_MAX(Value1, Value2) ( (Value1) >= (Value2) ? (Value1) : (Value2) )
3228
3229/** @def RT_MIN
3230 * Finds the minimum value.
3231 * @returns The lower of the two.
3232 * @param Value1 Value 1
3233 * @param Value2 Value 2
3234 */
3235#define RT_MIN(Value1, Value2) ( (Value1) <= (Value2) ? (Value1) : (Value2) )
3236
3237/** @def RT_CLAMP
3238 * Clamps the value to minimum and maximum values.
3239 * @returns The clamped value.
3240 * @param Value The value to check.
3241 * @param Min Minimum value.
3242 * @param Max Maximum value.
3243 */
3244#define RT_CLAMP(Value, Min, Max) ( (Value) > (Max) ? (Max) : (Value) < (Min) ? (Min) : (Value) )
3245
3246/** @def RT_ABS
3247 * Get the absolute (non-negative) value.
3248 * @returns The absolute value of Value.
3249 * @param Value The value.
3250 */
3251#define RT_ABS(Value) ( (Value) >= 0 ? (Value) : -(Value) )
3252
3253/** @def RT_BOOL
3254 * Turn non-zero/zero into true/false
3255 * @returns The resulting boolean value.
3256 * @param Value The value.
3257 */
3258#define RT_BOOL(Value) ( !!(Value) )
3259
3260/** @def RT_LO_U8
3261 * Gets the low uint8_t of a uint16_t or something equivalent. */
3262#ifdef __GNUC__
3263# define RT_LO_U8(a) __extension__ ({ AssertCompile(sizeof((a)) == sizeof(uint16_t)); (uint8_t)(a); })
3264#elif defined(_MSC_VER) /* shut up cast truncates constant value warnings */
3265# define RT_LO_U8(a) ( (uint8_t)(UINT8_MAX & (a)) )
3266#else
3267# define RT_LO_U8(a) ( (uint8_t)(a) )
3268#endif
3269/** @def RT_HI_U8
3270 * Gets the high uint8_t of a uint16_t or something equivalent. */
3271#ifdef __GNUC__
3272# define RT_HI_U8(a) __extension__ ({ AssertCompile(sizeof((a)) == sizeof(uint16_t)); (uint8_t)((a) >> 8); })
3273#else
3274# define RT_HI_U8(a) ( (uint8_t)((a) >> 8) )
3275#endif
3276
3277/** @def RT_LO_U16
3278 * Gets the low uint16_t of a uint32_t or something equivalent. */
3279#ifdef __GNUC__
3280# define RT_LO_U16(a) __extension__ ({ AssertCompile(sizeof((a)) == sizeof(uint32_t)); (uint16_t)(a); })
3281#elif defined(_MSC_VER) /* shut up cast truncates constant value warnings */
3282# define RT_LO_U16(a) ( (uint16_t)(UINT16_MAX & (a)) )
3283#else
3284# define RT_LO_U16(a) ( (uint16_t)(a) )
3285#endif
3286/** @def RT_HI_U16
3287 * Gets the high uint16_t of a uint32_t or something equivalent. */
3288#ifdef __GNUC__
3289# define RT_HI_U16(a) __extension__ ({ AssertCompile(sizeof((a)) == sizeof(uint32_t)); (uint16_t)((a) >> 16); })
3290#else
3291# define RT_HI_U16(a) ( (uint16_t)((a) >> 16) )
3292#endif
3293
3294/** @def RT_LO_U32
3295 * Gets the low uint32_t of a uint64_t or something equivalent. */
3296#ifdef __GNUC__
3297# define RT_LO_U32(a) __extension__ ({ AssertCompile(sizeof((a)) == sizeof(uint64_t)); (uint32_t)(a); })
3298#elif defined(_MSC_VER) /* shut up cast truncates constant value warnings */
3299# define RT_LO_U32(a) ( (uint32_t)(UINT32_MAX & (a)) )
3300#else
3301# define RT_LO_U32(a) ( (uint32_t)(a) )
3302#endif
3303/** @def RT_HI_U32
3304 * Gets the high uint32_t of a uint64_t or something equivalent. */
3305#ifdef __GNUC__
3306# define RT_HI_U32(a) __extension__ ({ AssertCompile(sizeof((a)) == sizeof(uint64_t)); (uint32_t)((a) >> 32); })
3307#else
3308# define RT_HI_U32(a) ( (uint32_t)((a) >> 32) )
3309#endif
3310
3311/** @def RT_BYTE1
3312 * Gets the first byte of something. */
3313#define RT_BYTE1(a) ( (uint8_t)((a) & 0xff) )
3314/** @def RT_BYTE2
3315 * Gets the second byte of something. */
3316#define RT_BYTE2(a) ( (uint8_t)(((a) >> 8) & 0xff) )
3317/** @def RT_BYTE3
3318 * Gets the second byte of something. */
3319#define RT_BYTE3(a) ( (uint8_t)(((a) >> 16) & 0xff) )
3320/** @def RT_BYTE4
3321 * Gets the fourth byte of something. */
3322#define RT_BYTE4(a) ( (uint8_t)(((a) >> 24) & 0xff) )
3323/** @def RT_BYTE5
3324 * Gets the fifth byte of something. */
3325#define RT_BYTE5(a) ( (uint8_t)(((a) >> 32) & 0xff) )
3326/** @def RT_BYTE6
3327 * Gets the sixth byte of something. */
3328#define RT_BYTE6(a) ( (uint8_t)(((a) >> 40) & 0xff) )
3329/** @def RT_BYTE7
3330 * Gets the seventh byte of something. */
3331#define RT_BYTE7(a) ( (uint8_t)(((a) >> 48) & 0xff) )
3332/** @def RT_BYTE8
3333 * Gets the eight byte of something. */
3334#define RT_BYTE8(a) ( (uint8_t)(((a) >> 56) & 0xff) )
3335
3336
3337/** @def RT_LODWORD
3338 * Gets the low dword (=uint32_t) of something.
3339 * @deprecated Use RT_LO_U32. */
3340#define RT_LODWORD(a) ( (uint32_t)(a) )
3341/** @def RT_HIDWORD
3342 * Gets the high dword (=uint32_t) of a 64-bit of something.
3343 * @deprecated Use RT_HI_U32. */
3344#define RT_HIDWORD(a) ( (uint32_t)((a) >> 32) )
3345
3346/** @def RT_LOWORD
3347 * Gets the low word (=uint16_t) of something.
3348 * @deprecated Use RT_LO_U16. */
3349#define RT_LOWORD(a) ( (a) & 0xffff )
3350/** @def RT_HIWORD
3351 * Gets the high word (=uint16_t) of a 32-bit something.
3352 * @deprecated Use RT_HI_U16. */
3353#define RT_HIWORD(a) ( (a) >> 16 )
3354
3355/** @def RT_LOBYTE
3356 * Gets the low byte of something.
3357 * @deprecated Use RT_LO_U8. */
3358#define RT_LOBYTE(a) ( (a) & 0xff )
3359/** @def RT_HIBYTE
3360 * Gets the high byte of a 16-bit something.
3361 * @deprecated Use RT_HI_U8. */
3362#define RT_HIBYTE(a) ( (a) >> 8 )
3363
3364
3365/** @def RT_MAKE_U64
3366 * Constructs a uint64_t value from two uint32_t values.
3367 */
3368#define RT_MAKE_U64(Lo, Hi) ( (uint64_t)((uint32_t)(Hi)) << 32 | (uint32_t)(Lo) )
3369
3370/** @def RT_MAKE_U64_FROM_U16
3371 * Constructs a uint64_t value from four uint16_t values, with parameters in
3372 * least significant word first order.
3373 * @see RT_MAKE_U64_FROM_MSW_U16
3374 */
3375#define RT_MAKE_U64_FROM_U16(w0, w1, w2, w3) \
3376 ((uint64_t)( (uint64_t)((uint16_t)(w3)) << 48 \
3377 | (uint64_t)((uint16_t)(w2)) << 32 \
3378 | (uint32_t)((uint16_t)(w1)) << 16 \
3379 | (uint16_t)(w0) ))
3380
3381/** @def RT_MAKE_U64_FROM_U16
3382 * Constructs a uint64_t value from four uint16_t values, with parameters in
3383 * most significant word first order.
3384 * @see RT_MAKE_U64_FROM_U16
3385 */
3386#define RT_MAKE_U64_FROM_MSW_U16(w3, w2, w1, w0) RT_MAKE_U64_FROM_U16(w0, w1, w2, w3)
3387
3388/** @def RT_MAKE_U64_FROM_U8
3389 * Constructs a uint64_t value from eight uint8_t values, with parameters in
3390 * least significant byte first order.
3391 * @see RT_MAKE_U64_FROM_MSB_U8
3392 */
3393#define RT_MAKE_U64_FROM_U8(b0, b1, b2, b3, b4, b5, b6, b7) \
3394 ((uint64_t)( (uint64_t)((uint8_t)(b7)) << 56 \
3395 | (uint64_t)((uint8_t)(b6)) << 48 \
3396 | (uint64_t)((uint8_t)(b5)) << 40 \
3397 | (uint64_t)((uint8_t)(b4)) << 32 \
3398 | (uint64_t)((uint8_t)(b3)) << 24 \
3399 | (uint64_t)((uint8_t)(b2)) << 16 \
3400 | (uint64_t)((uint8_t)(b1)) << 8 \
3401 | (uint64_t) (uint8_t)(b0) ))
3402
3403/** @def RT_MAKE_U64_FROM_MSB_U8
3404 * Constructs a uint64_t value from eight uint8_t values, with parameters in
3405 * most significant byte first order.
3406 * @see RT_MAKE_U64_FROM_U8
3407 */
3408#define RT_MAKE_U64_FROM_MSB_U8(b7, b6, b5, b4, b3, b2, b1, b0) RT_MAKE_U64_FROM_U8(b0, b1, b2, b3, b4, b5, b6, b7)
3409
3410/** @def RT_MAKE_U32
3411 * Constructs a uint32_t value from two uint16_t values.
3412 */
3413#define RT_MAKE_U32(Lo, Hi) \
3414 ((uint32_t)( (uint32_t)((uint16_t)(Hi)) << 16 \
3415 | (uint16_t)(Lo) ))
3416
3417/** @def RT_MAKE_U32_FROM_U8
3418 * Constructs a uint32_t value from four uint8_t values, with parameters in
3419 * least significant byte first order.
3420 * @see RT_MAKE_U32_FROM_MSB_U8
3421 */
3422#define RT_MAKE_U32_FROM_U8(b0, b1, b2, b3) \
3423 ((uint32_t)( (uint32_t)((uint8_t)(b3)) << 24 \
3424 | (uint32_t)((uint8_t)(b2)) << 16 \
3425 | (uint32_t)((uint8_t)(b1)) << 8 \
3426 | (uint8_t)(b0) ))
3427
3428/** @def RT_MAKE_U32_FROM_MSB_U8
3429 * Constructs a uint32_t value from four uint8_t values, with parameters in most
3430 * significant byte first order.
3431 * @see RT_MAKE_U32_FROM_8
3432 */
3433#define RT_MAKE_U32_FROM_MSB_U8(b3, b2, b1, b0) RT_MAKE_U32_FROM_U8(b0, b1, b2, b3)
3434
3435/** @def RT_MAKE_U16
3436 * Constructs a uint16_t value from two uint8_t values.
3437 */
3438#define RT_MAKE_U16(Lo, Hi) \
3439 ((uint16_t)( (uint16_t)((uint8_t)(Hi)) << 8 \
3440 | (uint8_t)(Lo) ))
3441
3442
3443/** @def RT_BSWAP_U64
3444 * Reverses the byte order of an uint64_t value. */
3445#if defined(__GNUC__)
3446# define RT_BSWAP_U64(u64) (__builtin_constant_p((u64)) ? RT_BSWAP_U64_C(u64) : ASMByteSwapU64(u64))
3447#else
3448# define RT_BSWAP_U64(u64) ASMByteSwapU64(u64)
3449#endif
3450
3451/** @def RT_BSWAP_U32
3452 * Reverses the byte order of an uint32_t value. */
3453#if defined(__GNUC__)
3454# define RT_BSWAP_U32(u32) (__builtin_constant_p((u32)) ? RT_BSWAP_U32_C(u32) : ASMByteSwapU32(u32))
3455#else
3456# define RT_BSWAP_U32(u32) ASMByteSwapU32(u32)
3457#endif
3458
3459/** @def RT_BSWAP_U16
3460 * Reverses the byte order of an uint16_t value. */
3461#if defined(__GNUC__)
3462# define RT_BSWAP_U16(u16) (__builtin_constant_p((u16)) ? RT_BSWAP_U16_C(u16) : ASMByteSwapU16(u16))
3463#else
3464# define RT_BSWAP_U16(u16) ASMByteSwapU16(u16)
3465#endif
3466
3467/** @def RT_BSWAP_S64
3468 * Reverses the byte order of an int64_t value. */
3469#define RT_BSWAP_S64(i64) ((int64_t)RT_BSWAP_U64((uint64_t)i64))
3470
3471/** @def RT_BSWAP_S32
3472 * Reverses the byte order of an int32_t value. */
3473#define RT_BSWAP_S32(i32) ((int32_t)RT_BSWAP_U32((uint32_t)i32))
3474
3475/** @def RT_BSWAP_S16
3476 * Reverses the byte order of an int16_t value. */
3477#define RT_BSWAP_S16(i16) ((int16_t)RT_BSWAP_U16((uint16_t)i16))
3478
3479
3480/** @def RT_BSWAP_U64_C
3481 * Reverses the byte order of an uint64_t constant. */
3482#define RT_BSWAP_U64_C(u64) RT_MAKE_U64(RT_BSWAP_U32_C((u64) >> 32), RT_BSWAP_U32_C((u64) & 0xffffffff))
3483
3484/** @def RT_BSWAP_U32_C
3485 * Reverses the byte order of an uint32_t constant. */
3486#define RT_BSWAP_U32_C(u32) RT_MAKE_U32_FROM_U8(RT_BYTE4(u32), RT_BYTE3(u32), RT_BYTE2(u32), RT_BYTE1(u32))
3487
3488/** @def RT_BSWAP_U16_C
3489 * Reverses the byte order of an uint16_t constant. */
3490#define RT_BSWAP_U16_C(u16) RT_MAKE_U16(RT_HIBYTE(u16), RT_LOBYTE(u16))
3491
3492/** @def RT_BSWAP_S64_C
3493 * Reverses the byte order of an int64_t constant. */
3494#define RT_BSWAP_S64_C(i64) ((int64_t)RT_MAKE_U64(RT_BSWAP_U32_C((uint64_t)(i64) >> 32), RT_BSWAP_U32_C((uint32_t)(i64))))
3495
3496/** @def RT_BSWAP_S32_C
3497 * Reverses the byte order of an int32_t constant. */
3498#define RT_BSWAP_S32_C(i32) ((int32_t)RT_MAKE_U32_FROM_U8(RT_BYTE4(i32), RT_BYTE3(i32), RT_BYTE2(i32), RT_BYTE1(i)))
3499
3500/** @def RT_BSWAP_S16_C
3501 * Reverses the byte order of an uint16_t constant. */
3502#define RT_BSWAP_S16_C(i16) ((int16_t)RT_MAKE_U16(RT_HIBYTE(i16), RT_LOBYTE(i16)))
3503
3504
3505
3506/** @name Host to/from little endian.
3507 * @note Typically requires iprt/asm.h to be included.
3508 * @{ */
3509
3510/** @def RT_H2LE_U64
3511 * Converts an uint64_t value from host to little endian byte order. */
3512#ifdef RT_BIG_ENDIAN
3513# define RT_H2LE_U64(u64) RT_BSWAP_U64(u64)
3514#else
3515# define RT_H2LE_U64(u64) (u64)
3516#endif
3517
3518/** @def RT_H2LE_U64_C
3519 * Converts an uint64_t constant from host to little endian byte order. */
3520#ifdef RT_BIG_ENDIAN
3521# define RT_H2LE_U64_C(u64) RT_BSWAP_U64_C(u64)
3522#else
3523# define RT_H2LE_U64_C(u64) (u64)
3524#endif
3525
3526/** @def RT_H2LE_U32
3527 * Converts an uint32_t value from host to little endian byte order. */
3528#ifdef RT_BIG_ENDIAN
3529# define RT_H2LE_U32(u32) RT_BSWAP_U32(u32)
3530#else
3531# define RT_H2LE_U32(u32) (u32)
3532#endif
3533
3534/** @def RT_H2LE_U32_C
3535 * Converts an uint32_t constant from host to little endian byte order. */
3536#ifdef RT_BIG_ENDIAN
3537# define RT_H2LE_U32_C(u32) RT_BSWAP_U32_C(u32)
3538#else
3539# define RT_H2LE_U32_C(u32) (u32)
3540#endif
3541
3542/** @def RT_H2LE_U16
3543 * Converts an uint16_t value from host to little endian byte order. */
3544#ifdef RT_BIG_ENDIAN
3545# define RT_H2LE_U16(u16) RT_BSWAP_U16(u16)
3546#else
3547# define RT_H2LE_U16(u16) (u16)
3548#endif
3549
3550/** @def RT_H2LE_U16_C
3551 * Converts an uint16_t constant from host to little endian byte order. */
3552#ifdef RT_BIG_ENDIAN
3553# define RT_H2LE_U16_C(u16) RT_BSWAP_U16_C(u16)
3554#else
3555# define RT_H2LE_U16_C(u16) (u16)
3556#endif
3557
3558
3559/** @def RT_LE2H_U64
3560 * Converts an uint64_t value from little endian to host byte order. */
3561#ifdef RT_BIG_ENDIAN
3562# define RT_LE2H_U64(u64) RT_BSWAP_U64(u64)
3563#else
3564# define RT_LE2H_U64(u64) (u64)
3565#endif
3566
3567/** @def RT_LE2H_U64_C
3568 * Converts an uint64_t constant from little endian to host byte order. */
3569#ifdef RT_BIG_ENDIAN
3570# define RT_LE2H_U64_C(u64) RT_BSWAP_U64_C(u64)
3571#else
3572# define RT_LE2H_U64_C(u64) (u64)
3573#endif
3574
3575/** @def RT_LE2H_U32
3576 * Converts an uint32_t value from little endian to host byte order. */
3577#ifdef RT_BIG_ENDIAN
3578# define RT_LE2H_U32(u32) RT_BSWAP_U32(u32)
3579#else
3580# define RT_LE2H_U32(u32) (u32)
3581#endif
3582
3583/** @def RT_LE2H_U32_C
3584 * Converts an uint32_t constant from little endian to host byte order. */
3585#ifdef RT_BIG_ENDIAN
3586# define RT_LE2H_U32_C(u32) RT_BSWAP_U32_C(u32)
3587#else
3588# define RT_LE2H_U32_C(u32) (u32)
3589#endif
3590
3591/** @def RT_LE2H_U16
3592 * Converts an uint16_t value from little endian to host byte order. */
3593#ifdef RT_BIG_ENDIAN
3594# define RT_LE2H_U16(u16) RT_BSWAP_U16(u16)
3595#else
3596# define RT_LE2H_U16(u16) (u16)
3597#endif
3598
3599/** @def RT_LE2H_U16_C
3600 * Converts an uint16_t constant from little endian to host byte order. */
3601#ifdef RT_BIG_ENDIAN
3602# define RT_LE2H_U16_C(u16) RT_BSWAP_U16_C(u16)
3603#else
3604# define RT_LE2H_U16_C(u16) (u16)
3605#endif
3606
3607/** @def RT_H2LE_S64
3608 * Converts an int64_t value from host to little endian byte order. */
3609#ifdef RT_BIG_ENDIAN
3610# define RT_H2LE_S64(i64) RT_BSWAP_S64(i64)
3611#else
3612# define RT_H2LE_S64(i64) (i64)
3613#endif
3614
3615/** @def RT_H2LE_S64_C
3616 * Converts an int64_t constant from host to little endian byte order. */
3617#ifdef RT_BIG_ENDIAN
3618# define RT_H2LE_S64_C(i64) RT_BSWAP_S64_C(i64)
3619#else
3620# define RT_H2LE_S64_C(i64) (i64)
3621#endif
3622
3623/** @def RT_H2LE_S32
3624 * Converts an int32_t value from host to little endian byte order. */
3625#ifdef RT_BIG_ENDIAN
3626# define RT_H2LE_S32(i32) RT_BSWAP_S32(i32)
3627#else
3628# define RT_H2LE_S32(i32) (i32)
3629#endif
3630
3631/** @def RT_H2LE_S32_C
3632 * Converts an int32_t constant from host to little endian byte order. */
3633#ifdef RT_BIG_ENDIAN
3634# define RT_H2LE_S32_C(i32) RT_BSWAP_S32_C(i32)
3635#else
3636# define RT_H2LE_S32_C(i32) (i32)
3637#endif
3638
3639/** @def RT_H2LE_S16
3640 * Converts an int16_t value from host to little endian byte order. */
3641#ifdef RT_BIG_ENDIAN
3642# define RT_H2LE_S16(i16) RT_BSWAP_S16(i16)
3643#else
3644# define RT_H2LE_S16(i16) (i16)
3645#endif
3646
3647/** @def RT_H2LE_S16_C
3648 * Converts an int16_t constant from host to little endian byte order. */
3649#ifdef RT_BIG_ENDIAN
3650# define RT_H2LE_S16_C(i16) RT_BSWAP_S16_C(i16)
3651#else
3652# define RT_H2LE_S16_C(i16) (i16)
3653#endif
3654
3655/** @def RT_LE2H_S64
3656 * Converts an int64_t value from little endian to host byte order. */
3657#ifdef RT_BIG_ENDIAN
3658# define RT_LE2H_S64(i64) RT_BSWAP_S64(i64)
3659#else
3660# define RT_LE2H_S64(i64) (i64)
3661#endif
3662
3663/** @def RT_LE2H_S64_C
3664 * Converts an int64_t constant from little endian to host byte order. */
3665#ifdef RT_BIG_ENDIAN
3666# define RT_LE2H_S64_C(i64) RT_BSWAP_S64_C(i64)
3667#else
3668# define RT_LE2H_S64_C(i64) (i64)
3669#endif
3670
3671/** @def RT_LE2H_S32
3672 * Converts an int32_t value from little endian to host byte order. */
3673#ifdef RT_BIG_ENDIAN
3674# define RT_LE2H_S32(i32) RT_BSWAP_S32(i32)
3675#else
3676# define RT_LE2H_S32(i32) (i32)
3677#endif
3678
3679/** @def RT_LE2H_S32_C
3680 * Converts an int32_t constant from little endian to host byte order. */
3681#ifdef RT_BIG_ENDIAN
3682# define RT_LE2H_S32_C(i32) RT_BSWAP_S32_C(i32)
3683#else
3684# define RT_LE2H_S32_C(i32) (i32)
3685#endif
3686
3687/** @def RT_LE2H_S16
3688 * Converts an int16_t value from little endian to host byte order. */
3689#ifdef RT_BIG_ENDIAN
3690# define RT_LE2H_S16(i16) RT_BSWAP_S16(i16)
3691#else
3692# define RT_LE2H_S16(i16) (i16)
3693#endif
3694
3695/** @def RT_LE2H_S16_C
3696 * Converts an int16_t constant from little endian to host byte order. */
3697#ifdef RT_BIG_ENDIAN
3698# define RT_LE2H_S16_C(i16) RT_BSWAP_S16_C(i16)
3699#else
3700# define RT_LE2H_S16_C(i16) (i16)
3701#endif
3702
3703/** @} */
3704
3705/** @name Host to/from big endian.
3706 * @note Typically requires iprt/asm.h to be included.
3707 * @{ */
3708
3709/** @def RT_H2BE_U64
3710 * Converts an uint64_t value from host to big endian byte order. */
3711#ifdef RT_BIG_ENDIAN
3712# define RT_H2BE_U64(u64) (u64)
3713#else
3714# define RT_H2BE_U64(u64) RT_BSWAP_U64(u64)
3715#endif
3716
3717/** @def RT_H2BE_U64_C
3718 * Converts an uint64_t constant from host to big endian byte order. */
3719#ifdef RT_BIG_ENDIAN
3720# define RT_H2BE_U64_C(u64) (u64)
3721#else
3722# define RT_H2BE_U64_C(u64) RT_BSWAP_U64_C(u64)
3723#endif
3724
3725/** @def RT_H2BE_U32
3726 * Converts an uint32_t value from host to big endian byte order. */
3727#ifdef RT_BIG_ENDIAN
3728# define RT_H2BE_U32(u32) (u32)
3729#else
3730# define RT_H2BE_U32(u32) RT_BSWAP_U32(u32)
3731#endif
3732
3733/** @def RT_H2BE_U32_C
3734 * Converts an uint32_t constant from host to big endian byte order. */
3735#ifdef RT_BIG_ENDIAN
3736# define RT_H2BE_U32_C(u32) (u32)
3737#else
3738# define RT_H2BE_U32_C(u32) RT_BSWAP_U32_C(u32)
3739#endif
3740
3741/** @def RT_H2BE_U16
3742 * Converts an uint16_t value from host to big endian byte order. */
3743#ifdef RT_BIG_ENDIAN
3744# define RT_H2BE_U16(u16) (u16)
3745#else
3746# define RT_H2BE_U16(u16) RT_BSWAP_U16(u16)
3747#endif
3748
3749/** @def RT_H2BE_U16_C
3750 * Converts an uint16_t constant from host to big endian byte order. */
3751#ifdef RT_BIG_ENDIAN
3752# define RT_H2BE_U16_C(u16) (u16)
3753#else
3754# define RT_H2BE_U16_C(u16) RT_BSWAP_U16_C(u16)
3755#endif
3756
3757/** @def RT_BE2H_U64
3758 * Converts an uint64_t value from big endian to host byte order. */
3759#ifdef RT_BIG_ENDIAN
3760# define RT_BE2H_U64(u64) (u64)
3761#else
3762# define RT_BE2H_U64(u64) RT_BSWAP_U64(u64)
3763#endif
3764
3765/** @def RT_BE2H_U64
3766 * Converts an uint64_t constant from big endian to host byte order. */
3767#ifdef RT_BIG_ENDIAN
3768# define RT_BE2H_U64_C(u64) (u64)
3769#else
3770# define RT_BE2H_U64_C(u64) RT_BSWAP_U64_C(u64)
3771#endif
3772
3773/** @def RT_BE2H_U32
3774 * Converts an uint32_t value from big endian to host byte order. */
3775#ifdef RT_BIG_ENDIAN
3776# define RT_BE2H_U32(u32) (u32)
3777#else
3778# define RT_BE2H_U32(u32) RT_BSWAP_U32(u32)
3779#endif
3780
3781/** @def RT_BE2H_U32_C
3782 * Converts an uint32_t value from big endian to host byte order. */
3783#ifdef RT_BIG_ENDIAN
3784# define RT_BE2H_U32_C(u32) (u32)
3785#else
3786# define RT_BE2H_U32_C(u32) RT_BSWAP_U32_C(u32)
3787#endif
3788
3789/** @def RT_BE2H_U16
3790 * Converts an uint16_t value from big endian to host byte order. */
3791#ifdef RT_BIG_ENDIAN
3792# define RT_BE2H_U16(u16) (u16)
3793#else
3794# define RT_BE2H_U16(u16) RT_BSWAP_U16(u16)
3795#endif
3796
3797/** @def RT_BE2H_U16_C
3798 * Converts an uint16_t constant from big endian to host byte order. */
3799#ifdef RT_BIG_ENDIAN
3800# define RT_BE2H_U16_C(u16) (u16)
3801#else
3802# define RT_BE2H_U16_C(u16) RT_BSWAP_U16_C(u16)
3803#endif
3804
3805/** @def RT_H2BE_S64
3806 * Converts an int64_t value from host to big endian byte order. */
3807#ifdef RT_BIG_ENDIAN
3808# define RT_H2BE_S64(i64) (i64)
3809#else
3810# define RT_H2BE_S64(i64) RT_BSWAP_S64(i64)
3811#endif
3812
3813/** @def RT_H2BE_S64_C
3814 * Converts an int64_t constant from host to big endian byte order. */
3815#ifdef RT_BIG_ENDIAN
3816# define RT_H2BE_S64_C(i64) (i64)
3817#else
3818# define RT_H2BE_S64_C(i64) RT_BSWAP_S64_C(i64)
3819#endif
3820
3821/** @def RT_H2BE_S32
3822 * Converts an int32_t value from host to big endian byte order. */
3823#ifdef RT_BIG_ENDIAN
3824# define RT_H2BE_S32(i32) (i32)
3825#else
3826# define RT_H2BE_S32(i32) RT_BSWAP_S32(i32)
3827#endif
3828
3829/** @def RT_H2BE_S32_C
3830 * Converts an int32_t constant from host to big endian byte order. */
3831#ifdef RT_BIG_ENDIAN
3832# define RT_H2BE_S32_C(i32) (i32)
3833#else
3834# define RT_H2BE_S32_C(i32) RT_BSWAP_S32_C(i32)
3835#endif
3836
3837/** @def RT_H2BE_S16
3838 * Converts an int16_t value from host to big endian byte order. */
3839#ifdef RT_BIG_ENDIAN
3840# define RT_H2BE_S16(i16) (i16)
3841#else
3842# define RT_H2BE_S16(i16) RT_BSWAP_S16(i16)
3843#endif
3844
3845/** @def RT_H2BE_S16_C
3846 * Converts an int16_t constant from host to big endian byte order. */
3847#ifdef RT_BIG_ENDIAN
3848# define RT_H2BE_S16_C(i16) (i16)
3849#else
3850# define RT_H2BE_S16_C(i16) RT_BSWAP_S16_C(i16)
3851#endif
3852
3853/** @def RT_BE2H_S64
3854 * Converts an int64_t value from big endian to host byte order. */
3855#ifdef RT_BIG_ENDIAN
3856# define RT_BE2H_S64(i64) (i64)
3857#else
3858# define RT_BE2H_S64(i64) RT_BSWAP_S64(i64)
3859#endif
3860
3861/** @def RT_BE2H_S64
3862 * Converts an int64_t constant from big endian to host byte order. */
3863#ifdef RT_BIG_ENDIAN
3864# define RT_BE2H_S64_C(i64) (i64)
3865#else
3866# define RT_BE2H_S64_C(i64) RT_BSWAP_S64_C(i64)
3867#endif
3868
3869/** @def RT_BE2H_S32
3870 * Converts an int32_t value from big endian to host byte order. */
3871#ifdef RT_BIG_ENDIAN
3872# define RT_BE2H_S32(i32) (i32)
3873#else
3874# define RT_BE2H_S32(i32) RT_BSWAP_S32(i32)
3875#endif
3876
3877/** @def RT_BE2H_S32_C
3878 * Converts an int32_t value from big endian to host byte order. */
3879#ifdef RT_BIG_ENDIAN
3880# define RT_BE2H_S32_C(i32) (i32)
3881#else
3882# define RT_BE2H_S32_C(i32) RT_BSWAP_S32_C(i32)
3883#endif
3884
3885/** @def RT_BE2H_S16
3886 * Converts an int16_t value from big endian to host byte order. */
3887#ifdef RT_BIG_ENDIAN
3888# define RT_BE2H_S16(i16) (i16)
3889#else
3890# define RT_BE2H_S16(i16) RT_BSWAP_S16(i16)
3891#endif
3892
3893/** @def RT_BE2H_S16_C
3894 * Converts an int16_t constant from big endian to host byte order. */
3895#ifdef RT_BIG_ENDIAN
3896# define RT_BE2H_S16_C(i16) (i16)
3897#else
3898# define RT_BE2H_S16_C(i16) RT_BSWAP_S16_C(i16)
3899#endif
3900/** @} */
3901
3902/** @name Host to/from network byte order.
3903 * @note Typically requires iprt/asm.h to be included.
3904 * @{ */
3905
3906/** @def RT_H2N_U64
3907 * Converts an uint64_t value from host to network byte order. */
3908#define RT_H2N_U64(u64) RT_H2BE_U64(u64)
3909
3910/** @def RT_H2N_U64_C
3911 * Converts an uint64_t constant from host to network byte order. */
3912#define RT_H2N_U64_C(u64) RT_H2BE_U64_C(u64)
3913
3914/** @def RT_H2N_U32
3915 * Converts an uint32_t value from host to network byte order. */
3916#define RT_H2N_U32(u32) RT_H2BE_U32(u32)
3917
3918/** @def RT_H2N_U32_C
3919 * Converts an uint32_t constant from host to network byte order. */
3920#define RT_H2N_U32_C(u32) RT_H2BE_U32_C(u32)
3921
3922/** @def RT_H2N_U16
3923 * Converts an uint16_t value from host to network byte order. */
3924#define RT_H2N_U16(u16) RT_H2BE_U16(u16)
3925
3926/** @def RT_H2N_U16_C
3927 * Converts an uint16_t constant from host to network byte order. */
3928#define RT_H2N_U16_C(u16) RT_H2BE_U16_C(u16)
3929
3930/** @def RT_N2H_U64
3931 * Converts an uint64_t value from network to host byte order. */
3932#define RT_N2H_U64(u64) RT_BE2H_U64(u64)
3933
3934/** @def RT_N2H_U64_C
3935 * Converts an uint64_t constant from network to host byte order. */
3936#define RT_N2H_U64_C(u64) RT_BE2H_U64_C(u64)
3937
3938/** @def RT_N2H_U32
3939 * Converts an uint32_t value from network to host byte order. */
3940#define RT_N2H_U32(u32) RT_BE2H_U32(u32)
3941
3942/** @def RT_N2H_U32_C
3943 * Converts an uint32_t constant from network to host byte order. */
3944#define RT_N2H_U32_C(u32) RT_BE2H_U32_C(u32)
3945
3946/** @def RT_N2H_U16
3947 * Converts an uint16_t value from network to host byte order. */
3948#define RT_N2H_U16(u16) RT_BE2H_U16(u16)
3949
3950/** @def RT_N2H_U16_C
3951 * Converts an uint16_t value from network to host byte order. */
3952#define RT_N2H_U16_C(u16) RT_BE2H_U16_C(u16)
3953
3954/** @def RT_H2N_S64
3955 * Converts an int64_t value from host to network byte order. */
3956#define RT_H2N_S64(i64) RT_H2BE_S64(i64)
3957
3958/** @def RT_H2N_S64_C
3959 * Converts an int64_t constant from host to network byte order. */
3960#define RT_H2N_S64_C(i64) RT_H2BE_S64_C(i64)
3961
3962/** @def RT_H2N_S32
3963 * Converts an int32_t value from host to network byte order. */
3964#define RT_H2N_S32(i32) RT_H2BE_S32(i32)
3965
3966/** @def RT_H2N_S32_C
3967 * Converts an int32_t constant from host to network byte order. */
3968#define RT_H2N_S32_C(i32) RT_H2BE_S32_C(i32)
3969
3970/** @def RT_H2N_S16
3971 * Converts an int16_t value from host to network byte order. */
3972#define RT_H2N_S16(i16) RT_H2BE_S16(i16)
3973
3974/** @def RT_H2N_S16_C
3975 * Converts an int16_t constant from host to network byte order. */
3976#define RT_H2N_S16_C(i16) RT_H2BE_S16_C(i16)
3977
3978/** @def RT_N2H_S64
3979 * Converts an int64_t value from network to host byte order. */
3980#define RT_N2H_S64(i64) RT_BE2H_S64(i64)
3981
3982/** @def RT_N2H_S64_C
3983 * Converts an int64_t constant from network to host byte order. */
3984#define RT_N2H_S64_C(i64) RT_BE2H_S64_C(i64)
3985
3986/** @def RT_N2H_S32
3987 * Converts an int32_t value from network to host byte order. */
3988#define RT_N2H_S32(i32) RT_BE2H_S32(i32)
3989
3990/** @def RT_N2H_S32_C
3991 * Converts an int32_t constant from network to host byte order. */
3992#define RT_N2H_S32_C(i32) RT_BE2H_S32_C(i32)
3993
3994/** @def RT_N2H_S16
3995 * Converts an int16_t value from network to host byte order. */
3996#define RT_N2H_S16(i16) RT_BE2H_S16(i16)
3997
3998/** @def RT_N2H_S16_C
3999 * Converts an int16_t value from network to host byte order. */
4000#define RT_N2H_S16_C(i16) RT_BE2H_S16_C(i16)
4001
4002/** @} */
4003
4004
4005/*
4006 * The BSD sys/param.h + machine/param.h file is a major source of
4007 * namespace pollution. Kill off some of the worse ones unless we're
4008 * compiling kernel code.
4009 */
4010#if defined(RT_OS_DARWIN) \
4011 && !defined(KERNEL) \
4012 && !defined(RT_NO_BSD_PARAM_H_UNDEFING) \
4013 && ( defined(_SYS_PARAM_H_) || defined(_I386_PARAM_H_) )
4014/* sys/param.h: */
4015# undef PSWP
4016# undef PVM
4017# undef PINOD
4018# undef PRIBO
4019# undef PVFS
4020# undef PZERO
4021# undef PSOCK
4022# undef PWAIT
4023# undef PLOCK
4024# undef PPAUSE
4025# undef PUSER
4026# undef PRIMASK
4027# undef MINBUCKET
4028# undef MAXALLOCSAVE
4029# undef FSHIFT
4030# undef FSCALE
4031
4032/* i386/machine.h: */
4033# undef ALIGN
4034# undef ALIGNBYTES
4035# undef DELAY
4036# undef STATUS_WORD
4037# undef USERMODE
4038# undef BASEPRI
4039# undef MSIZE
4040# undef CLSIZE
4041# undef CLSIZELOG2
4042#endif
4043
4044/** @def NIL_OFFSET
4045 * NIL offset.
4046 * Whenever we use offsets instead of pointers to save space and relocation effort
4047 * NIL_OFFSET shall be used as the equivalent to NULL.
4048 */
4049#define NIL_OFFSET (~0U)
4050
4051
4052/** @def NOREF
4053 * Keeps the compiler from bitching about an unused parameter, local variable,
4054 * or other stuff, will never use _Pragma are is thus more flexible.
4055 */
4056#define NOREF(var) (void)(var)
4057
4058/** @def RT_NOREF_PV
4059 * Keeps the compiler from bitching about an unused parameter or local variable.
4060 * This one cannot be used with structure members and such, like for instance
4061 * AssertRC may end up doing due to its generic nature.
4062 */
4063#if defined(__cplusplus) && RT_CLANG_PREREQ(6, 0)
4064# define RT_NOREF_PV(var) _Pragma(RT_STR(unused(var)))
4065#else
4066# define RT_NOREF_PV(var) (void)(var)
4067#endif
4068
4069/** @def RT_NOREF1
4070 * RT_NOREF_PV shorthand taking on parameter. */
4071#define RT_NOREF1(var1) RT_NOREF_PV(var1)
4072/** @def RT_NOREF2
4073 * RT_NOREF_PV shorthand taking two parameters. */
4074#define RT_NOREF2(var1, var2) RT_NOREF_PV(var1); RT_NOREF1(var2)
4075/** @def RT_NOREF3
4076 * RT_NOREF_PV shorthand taking three parameters. */
4077#define RT_NOREF3(var1, var2, var3) RT_NOREF_PV(var1); RT_NOREF2(var2, var3)
4078/** @def RT_NOREF4
4079 * RT_NOREF_PV shorthand taking four parameters. */
4080#define RT_NOREF4(var1, var2, var3, var4) RT_NOREF_PV(var1); RT_NOREF3(var2, var3, var4)
4081/** @def RT_NOREF5
4082 * RT_NOREF_PV shorthand taking five parameters. */
4083#define RT_NOREF5(var1, var2, var3, var4, var5) RT_NOREF_PV(var1); RT_NOREF4(var2, var3, var4, var5)
4084/** @def RT_NOREF6
4085 * RT_NOREF_PV shorthand taking six parameters. */
4086#define RT_NOREF6(var1, var2, var3, var4, var5, var6) RT_NOREF_PV(var1); RT_NOREF5(var2, var3, var4, var5, var6)
4087/** @def RT_NOREF7
4088 * RT_NOREF_PV shorthand taking seven parameters. */
4089#define RT_NOREF7(var1, var2, var3, var4, var5, var6, var7) \
4090 RT_NOREF_PV(var1); RT_NOREF6(var2, var3, var4, var5, var6, var7)
4091/** @def RT_NOREF8
4092 * RT_NOREF_PV shorthand taking eight parameters. */
4093#define RT_NOREF8(var1, var2, var3, var4, var5, var6, var7, var8) \
4094 RT_NOREF_PV(var1); RT_NOREF7(var2, var3, var4, var5, var6, var7, var8)
4095/** @def RT_NOREF9
4096 * RT_NOREF_PV shorthand taking nine parameters. */
4097#define RT_NOREF9(var1, var2, var3, var4, var5, var6, var7, var8, var9) \
4098 RT_NOREF_PV(var1); RT_NOREF8(var2, var3, var4, var5, var6, var7, var8, var9)
4099/** @def RT_NOREF10
4100 * RT_NOREF_PV shorthand taking ten parameters. */
4101#define RT_NOREF10(var1, var2, var3, var4, var5, var6, var7, var8, var9, var10) \
4102 RT_NOREF_PV(var1); RT_NOREF_PV(var2); RT_NOREF_PV(var3); RT_NOREF_PV(var4); RT_NOREF_PV(var5); RT_NOREF_PV(var6); \
4103 RT_NOREF_PV(var7); RT_NOREF_PV(var8); RT_NOREF_PV(var9); RT_NOREF_PV(var10)
4104/** @def RT_NOREF11
4105 * RT_NOREF_PV shorthand taking eleven parameters. */
4106#define RT_NOREF11(var1, var2, var3, var4, var5, var6, var7, var8, var9, var10, var11) \
4107 RT_NOREF_PV(var1); RT_NOREF10(var2, var3, var4, var5, var6, var7, var8, var9, var10, var11)
4108/** @def RT_NOREF12
4109 * RT_NOREF_PV shorthand taking twelve parameters. */
4110#define RT_NOREF12(var1, var2, var3, var4, var5, var6, var7, var8, var9, var10, var11, var12) \
4111 RT_NOREF_PV(var1); RT_NOREF11(var2, var3, var4, var5, var6, var7, var8, var9, var10, var11, var12)
4112/** @def RT_NOREF13
4113 * RT_NOREF_PV shorthand taking thirteen parameters. */
4114#define RT_NOREF13(var1, var2, var3, var4, var5, var6, var7, var8, var9, var10, var11, var12, var13) \
4115 RT_NOREF_PV(var1); RT_NOREF12(var2, var3, var4, var5, var6, var7, var8, var9, var10, var11, var12, var13)
4116/** @def RT_NOREF14
4117 * RT_NOREF_PV shorthand taking fourteen parameters. */
4118#define RT_NOREF14(var1, var2, var3, var4, var5, var6, var7, var8, var9, var10, var11, var12, var13, var14) \
4119 RT_NOREF_PV(var1); RT_NOREF13(var2, var3, var4, var5, var6, var7, var8, var9, var10, var11, var12, var13, var14)
4120/** @def RT_NOREF15
4121 * RT_NOREF_PV shorthand taking fifteen parameters. */
4122#define RT_NOREF15(var1, var2, var3, var4, var5, var6, var7, var8, var9, var10, var11, var12, var13, var14, var15) \
4123 RT_NOREF_PV(var1); RT_NOREF14(var2, var3, var4, var5, var6, var7, var8, var9, var10, var11, var12, var13, var14, var15)
4124/** @def RT_NOREF16
4125 * RT_NOREF_PV shorthand taking fifteen parameters. */
4126#define RT_NOREF16(var1, var2, var3, var4, var5, var6, var7, var8, var9, var10, var11, var12, var13, var14, var15, var16) \
4127 RT_NOREF_PV(var1); RT_NOREF15(var2, var3, var4, var5, var6, var7, var8, var9, var10, var11, var12, var13, var14, var15, var16)
4128/** @def RT_NOREF17
4129 * RT_NOREF_PV shorthand taking seventeen parameters. */
4130#define RT_NOREF17(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17) \
4131 RT_NOREF_PV(v1); RT_NOREF16(v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17)
4132/** @def RT_NOREF18
4133 * RT_NOREF_PV shorthand taking eighteen parameters. */
4134#define RT_NOREF18(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18) \
4135 RT_NOREF_PV(v1); RT_NOREF17(v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18)
4136/** @def RT_NOREF19
4137 * RT_NOREF_PV shorthand taking nineteen parameters. */
4138#define RT_NOREF19(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19) \
4139 RT_NOREF_PV(v1); RT_NOREF18(v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19)
4140/** @def RT_NOREF20
4141 * RT_NOREF_PV shorthand taking twenty parameters. */
4142#define RT_NOREF20(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20) \
4143 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)
4144/** @def RT_NOREF21
4145 * RT_NOREF_PV shorthand taking twentyone parameters. */
4146#define RT_NOREF21(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21) \
4147 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)
4148/** @def RT_NOREF22
4149 * RT_NOREF_PV shorthand taking twentytwo parameters. */
4150#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) \
4151 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)
4152
4153/** @def RT_NOREF
4154 * RT_NOREF_PV variant using the variadic macro feature of C99.
4155 * @remarks Only use this in sources */
4156#ifdef RT_COMPILER_SUPPORTS_VA_ARGS
4157# define RT_NOREF(...) \
4158 RT_UNPACK_CALL(RT_CONCAT(RT_NOREF, RT_EXPAND(RT_COUNT_VA_ARGS(__VA_ARGS__))),(__VA_ARGS__))
4159#endif
4160
4161
4162/** @def RT_BREAKPOINT
4163 * Emit a debug breakpoint instruction.
4164 *
4165 * @remarks In the x86/amd64 gnu world we add a nop instruction after the int3
4166 * to force gdb to remain at the int3 source line.
4167 * @remarks The L4 kernel will try make sense of the breakpoint, thus the jmp on
4168 * x86/amd64.
4169 */
4170#ifdef __GNUC__
4171# if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
4172# if !defined(__L4ENV__)
4173# define RT_BREAKPOINT() __asm__ __volatile__("int $3\n\tnop\n\t")
4174# else
4175# define RT_BREAKPOINT() __asm__ __volatile__("int3; jmp 1f; 1:\n\t")
4176# endif
4177# elif defined(RT_ARCH_SPARC64)
4178# define RT_BREAKPOINT() __asm__ __volatile__("illtrap 0\n\t") /** @todo Sparc64: this is just a wild guess. */
4179# elif defined(RT_ARCH_SPARC)
4180# define RT_BREAKPOINT() __asm__ __volatile__("unimp 0\n\t") /** @todo Sparc: this is just a wild guess (same as Sparc64, just different name). */
4181# elif defined(RT_ARCH_ARM32) || defined(RT_ARCH_ARM64)
4182# define RT_BREAKPOINT() __asm__ __volatile__("brk #0xf000\n\t")
4183# endif
4184#endif
4185#ifdef _MSC_VER
4186# define RT_BREAKPOINT() __debugbreak()
4187#endif
4188#if defined(__IBMC__) || defined(__IBMCPP__)
4189# define RT_BREAKPOINT() __interrupt(3)
4190#endif
4191#if defined(__WATCOMC__)
4192# define RT_BREAKPOINT() _asm { int 3 }
4193#endif
4194#ifndef RT_BREAKPOINT
4195# error "This compiler/arch is not supported!"
4196#endif
4197
4198
4199/** @defgroup grp_rt_cdefs_size Size Constants
4200 * (Of course, these are binary computer terms, not SI.)
4201 * @{
4202 */
4203/** 1 K (Kilo) (1 024). */
4204#define _1K 0x00000400
4205/** 2 K (Kilo) (2 048). */
4206#define _2K 0x00000800
4207/** 4 K (Kilo) (4 096). */
4208#define _4K 0x00001000
4209/** 8 K (Kilo) (8 192). */
4210#define _8K 0x00002000
4211/** 16 K (Kilo) (16 384). */
4212#define _16K 0x00004000
4213/** 32 K (Kilo) (32 768). */
4214#define _32K 0x00008000
4215/** 64 K (Kilo) (65 536). */
4216#if ARCH_BITS != 16
4217# define _64K 0x00010000
4218#else
4219# define _64K UINT32_C(0x00010000)
4220#endif
4221/** 128 K (Kilo) (131 072). */
4222#if ARCH_BITS != 16
4223# define _128K 0x00020000
4224#else
4225# define _128K UINT32_C(0x00020000)
4226#endif
4227/** 256 K (Kilo) (262 144). */
4228#if ARCH_BITS != 16
4229# define _256K 0x00040000
4230#else
4231# define _256K UINT32_C(0x00040000)
4232#endif
4233/** 512 K (Kilo) (524 288). */
4234#if ARCH_BITS != 16
4235# define _512K 0x00080000
4236#else
4237# define _512K UINT32_C(0x00080000)
4238#endif
4239/** 1 M (Mega) (1 048 576). */
4240#if ARCH_BITS != 16
4241# define _1M 0x00100000
4242#else
4243# define _1M UINT32_C(0x00100000)
4244#endif
4245/** 2 M (Mega) (2 097 152). */
4246#if ARCH_BITS != 16
4247# define _2M 0x00200000
4248#else
4249# define _2M UINT32_C(0x00200000)
4250#endif
4251/** 4 M (Mega) (4 194 304). */
4252#if ARCH_BITS != 16
4253# define _4M 0x00400000
4254#else
4255# define _4M UINT32_C(0x00400000)
4256#endif
4257/** 8 M (Mega) (8 388 608). */
4258#define _8M UINT32_C(0x00800000)
4259/** 16 M (Mega) (16 777 216). */
4260#define _16M UINT32_C(0x01000000)
4261/** 32 M (Mega) (33 554 432). */
4262#define _32M UINT32_C(0x02000000)
4263/** 64 M (Mega) (67 108 864). */
4264#define _64M UINT32_C(0x04000000)
4265/** 128 M (Mega) (134 217 728). */
4266#define _128M UINT32_C(0x08000000)
4267/** 256 M (Mega) (268 435 456). */
4268#define _256M UINT32_C(0x10000000)
4269/** 512 M (Mega) (536 870 912). */
4270#define _512M UINT32_C(0x20000000)
4271/** 1 G (Giga) (1 073 741 824). (32-bit) */
4272#if ARCH_BITS != 16
4273# define _1G 0x40000000
4274#else
4275# define _1G UINT32_C(0x40000000)
4276#endif
4277/** 1 G (Giga) (1 073 741 824). (64-bit) */
4278#if ARCH_BITS != 16
4279# define _1G64 0x40000000LL
4280#else
4281# define _1G64 UINT64_C(0x40000000)
4282#endif
4283/** 2 G (Giga) (2 147 483 648). (32-bit) */
4284#define _2G32 UINT32_C(0x80000000)
4285/** 2 G (Giga) (2 147 483 648). (64-bit) */
4286#if ARCH_BITS != 16
4287# define _2G 0x0000000080000000LL
4288#else
4289# define _2G UINT64_C(0x0000000080000000)
4290#endif
4291/** 4 G (Giga) (4 294 967 296). */
4292#if ARCH_BITS != 16
4293# define _4G 0x0000000100000000LL
4294#else
4295# define _4G UINT64_C(0x0000000100000000)
4296#endif
4297/** 1 T (Tera) (1 099 511 627 776). */
4298#if ARCH_BITS != 16
4299# define _1T 0x0000010000000000LL
4300#else
4301# define _1T UINT64_C(0x0000010000000000)
4302#endif
4303/** 1 P (Peta) (1 125 899 906 842 624). */
4304#if ARCH_BITS != 16
4305# define _1P 0x0004000000000000LL
4306#else
4307# define _1P UINT64_C(0x0004000000000000)
4308#endif
4309/** 1 E (Exa) (1 152 921 504 606 846 976). */
4310#if ARCH_BITS != 16
4311# define _1E 0x1000000000000000LL
4312#else
4313# define _1E UINT64_C(0x1000000000000000)
4314#endif
4315/** 2 E (Exa) (2 305 843 009 213 693 952). */
4316#if ARCH_BITS != 16
4317# define _2E 0x2000000000000000ULL
4318#else
4319# define _2E UINT64_C(0x2000000000000000)
4320#endif
4321/** @} */
4322
4323/** @defgroup grp_rt_cdefs_decimal_grouping Decimal Constant Grouping Macros
4324 * @{ */
4325#define RT_D1(g1) g1
4326#define RT_D2(g1, g2) g1#g2
4327#define RT_D3(g1, g2, g3) g1#g2#g3
4328#define RT_D4(g1, g2, g3, g4) g1#g2#g3#g4
4329#define RT_D5(g1, g2, g3, g4, g5) g1#g2#g3#g4#g5
4330#define RT_D6(g1, g2, g3, g4, g5, g6) g1#g2#g3#g4#g5#g6
4331#define RT_D7(g1, g2, g3, g4, g5, g6, g7) g1#g2#g3#g4#g5#g6#g7
4332
4333#define RT_D1_U(g1) UINT32_C(g1)
4334#define RT_D2_U(g1, g2) UINT32_C(g1#g2)
4335#define RT_D3_U(g1, g2, g3) UINT32_C(g1#g2#g3)
4336#define RT_D4_U(g1, g2, g3, g4) UINT64_C(g1#g2#g3#g4)
4337#define RT_D5_U(g1, g2, g3, g4, g5) UINT64_C(g1#g2#g3#g4#g5)
4338#define RT_D6_U(g1, g2, g3, g4, g5, g6) UINT64_C(g1#g2#g3#g4#g5#g6)
4339#define RT_D7_U(g1, g2, g3, g4, g5, g6, g7) UINT64_C(g1#g2#g3#g4#g5#g6#g7)
4340
4341#define RT_D1_S(g1) INT32_C(g1)
4342#define RT_D2_S(g1, g2) INT32_C(g1#g2)
4343#define RT_D3_S(g1, g2, g3) INT32_C(g1#g2#g3)
4344#define RT_D4_S(g1, g2, g3, g4) INT64_C(g1#g2#g3#g4)
4345#define RT_D5_S(g1, g2, g3, g4, g5) INT64_C(g1#g2#g3#g4#g5)
4346#define RT_D6_S(g1, g2, g3, g4, g5, g6) INT64_C(g1#g2#g3#g4#g5#g6)
4347#define RT_D7_S(g1, g2, g3, g4, g5, g6, g7) INT64_C(g1#g2#g3#g4#g5#g6#g7)
4348
4349#define RT_D1_U32(g1) UINT32_C(g1)
4350#define RT_D2_U32(g1, g2) UINT32_C(g1#g2)
4351#define RT_D3_U32(g1, g2, g3) UINT32_C(g1#g2#g3)
4352#define RT_D4_U32(g1, g2, g3, g4) UINT32_C(g1#g2#g3#g4)
4353
4354#define RT_D1_S32(g1) INT32_C(g1)
4355#define RT_D2_S32(g1, g2) INT32_C(g1#g2)
4356#define RT_D3_S32(g1, g2, g3) INT32_C(g1#g2#g3)
4357#define RT_D4_S32(g1, g2, g3, g4) INT32_C(g1#g2#g3#g4)
4358
4359#define RT_D1_U64(g1) UINT64_C(g1)
4360#define RT_D2_U64(g1, g2) UINT64_C(g1#g2)
4361#define RT_D3_U64(g1, g2, g3) UINT64_C(g1#g2#g3)
4362#define RT_D4_U64(g1, g2, g3, g4) UINT64_C(g1#g2#g3#g4)
4363#define RT_D5_U64(g1, g2, g3, g4, g5) UINT64_C(g1#g2#g3#g4#g5)
4364#define RT_D6_U64(g1, g2, g3, g4, g5, g6) UINT64_C(g1#g2#g3#g4#g5#g6)
4365#define RT_D7_U64(g1, g2, g3, g4, g5, g6, g7) UINT64_C(g1#g2#g3#g4#g5#g6#g7)
4366
4367#define RT_D1_S64(g1) INT64_C(g1)
4368#define RT_D2_S64(g1, g2) INT64_C(g1#g2)
4369#define RT_D3_S64(g1, g2, g3) INT64_C(g1#g2#g3)
4370#define RT_D4_S64(g1, g2, g3, g4) INT64_C(g1#g2#g3#g4)
4371#define RT_D5_S64(g1, g2, g3, g4, g5) INT64_C(g1#g2#g3#g4#g5)
4372#define RT_D6_S64(g1, g2, g3, g4, g5, g6) INT64_C(g1#g2#g3#g4#g5#g6)
4373#define RT_D7_S64(g1, g2, g3, g4, g5, g6, g7) INT64_C(g1#g2#g3#g4#g5#g6#g7)
4374/** @} */
4375
4376
4377/** @defgroup grp_rt_cdefs_time Time Constants
4378 * @{
4379 */
4380/** 1 week expressed in nanoseconds (64-bit). */
4381#define RT_NS_1WEEK UINT64_C(604800000000000)
4382/** 1 day expressed in nanoseconds (64-bit). */
4383#define RT_NS_1DAY UINT64_C(86400000000000)
4384/** 1 hour expressed in nanoseconds (64-bit). */
4385#define RT_NS_1HOUR UINT64_C(3600000000000)
4386/** 30 minutes expressed in nanoseconds (64-bit). */
4387#define RT_NS_30MIN UINT64_C(1800000000000)
4388/** 5 minutes expressed in nanoseconds (64-bit). */
4389#define RT_NS_5MIN UINT64_C(300000000000)
4390/** 1 minute expressed in nanoseconds (64-bit). */
4391#define RT_NS_1MIN UINT64_C(60000000000)
4392/** 45 seconds expressed in nanoseconds (64-bit). */
4393#define RT_NS_45SEC UINT64_C(45000000000)
4394/** 30 seconds expressed in nanoseconds (64-bit). */
4395#define RT_NS_30SEC UINT64_C(30000000000)
4396/** 20 seconds expressed in nanoseconds (64-bit). */
4397#define RT_NS_20SEC UINT64_C(20000000000)
4398/** 15 seconds expressed in nanoseconds (64-bit). */
4399#define RT_NS_15SEC UINT64_C(15000000000)
4400/** 10 seconds expressed in nanoseconds (64-bit). */
4401#define RT_NS_10SEC UINT64_C(10000000000)
4402/** 1 second expressed in nanoseconds. */
4403#define RT_NS_1SEC UINT32_C(1000000000)
4404/** 100 millsecond expressed in nanoseconds. */
4405#define RT_NS_100MS UINT32_C(100000000)
4406/** 10 millsecond expressed in nanoseconds. */
4407#define RT_NS_10MS UINT32_C(10000000)
4408/** 8 millsecond expressed in nanoseconds. */
4409#define RT_NS_8MS UINT32_C(8000000)
4410/** 2 millsecond expressed in nanoseconds. */
4411#define RT_NS_2MS UINT32_C(2000000)
4412/** 1 millsecond expressed in nanoseconds. */
4413#define RT_NS_1MS UINT32_C(1000000)
4414/** 100 microseconds expressed in nanoseconds. */
4415#define RT_NS_100US UINT32_C(100000)
4416/** 10 microseconds expressed in nanoseconds. */
4417#define RT_NS_10US UINT32_C(10000)
4418/** 1 microsecond expressed in nanoseconds. */
4419#define RT_NS_1US UINT32_C(1000)
4420
4421/** 1 second expressed in nanoseconds - 64-bit type. */
4422#define RT_NS_1SEC_64 UINT64_C(1000000000)
4423/** 100 millsecond expressed in nanoseconds - 64-bit type. */
4424#define RT_NS_100MS_64 UINT64_C(100000000)
4425/** 10 millsecond expressed in nanoseconds - 64-bit type. */
4426#define RT_NS_10MS_64 UINT64_C(10000000)
4427/** 1 millsecond expressed in nanoseconds - 64-bit type. */
4428#define RT_NS_1MS_64 UINT64_C(1000000)
4429/** 100 microseconds expressed in nanoseconds - 64-bit type. */
4430#define RT_NS_100US_64 UINT64_C(100000)
4431/** 10 microseconds expressed in nanoseconds - 64-bit type. */
4432#define RT_NS_10US_64 UINT64_C(10000)
4433/** 1 microsecond expressed in nanoseconds - 64-bit type. */
4434#define RT_NS_1US_64 UINT64_C(1000)
4435
4436/** 1 week expressed in microseconds (64-bit). */
4437#define RT_US_1WEEK UINT64_C(604800000000)
4438/** 1 day expressed in microseconds (64-bit). */
4439#define RT_US_1DAY UINT64_C(86400000000)
4440/** 1 hour expressed in microseconds. */
4441#define RT_US_1HOUR UINT32_C(3600000000)
4442/** 30 minutes expressed in microseconds. */
4443#define RT_US_30MIN UINT32_C(1800000000)
4444/** 5 minutes expressed in microseconds. */
4445#define RT_US_5MIN UINT32_C(300000000)
4446/** 1 minute expressed in microseconds. */
4447#define RT_US_1MIN UINT32_C(60000000)
4448/** 45 seconds expressed in microseconds. */
4449#define RT_US_45SEC UINT32_C(45000000)
4450/** 30 seconds expressed in microseconds. */
4451#define RT_US_30SEC UINT32_C(30000000)
4452/** 20 seconds expressed in microseconds. */
4453#define RT_US_20SEC UINT32_C(20000000)
4454/** 15 seconds expressed in microseconds. */
4455#define RT_US_15SEC UINT32_C(15000000)
4456/** 10 seconds expressed in microseconds. */
4457#define RT_US_10SEC UINT32_C(10000000)
4458/** 5 seconds expressed in microseconds. */
4459#define RT_US_5SEC UINT32_C(5000000)
4460/** 1 second expressed in microseconds. */
4461#define RT_US_1SEC UINT32_C(1000000)
4462/** 100 millsecond expressed in microseconds. */
4463#define RT_US_100MS UINT32_C(100000)
4464/** 10 millsecond expressed in microseconds. */
4465#define RT_US_10MS UINT32_C(10000)
4466/** 1 millsecond expressed in microseconds. */
4467#define RT_US_1MS UINT32_C(1000)
4468
4469/** 1 hour expressed in microseconds - 64-bit type. */
4470#define RT_US_1HOUR_64 UINT64_C(3600000000)
4471/** 30 minutes expressed in microseconds - 64-bit type. */
4472#define RT_US_30MIN_64 UINT64_C(1800000000)
4473/** 5 minutes expressed in microseconds - 64-bit type. */
4474#define RT_US_5MIN_64 UINT64_C(300000000)
4475/** 1 minute expressed in microseconds - 64-bit type. */
4476#define RT_US_1MIN_64 UINT64_C(60000000)
4477/** 45 seconds expressed in microseconds - 64-bit type. */
4478#define RT_US_45SEC_64 UINT64_C(45000000)
4479/** 30 seconds expressed in microseconds - 64-bit type. */
4480#define RT_US_30SEC_64 UINT64_C(30000000)
4481/** 20 seconds expressed in microseconds - 64-bit type. */
4482#define RT_US_20SEC_64 UINT64_C(20000000)
4483/** 15 seconds expressed in microseconds - 64-bit type. */
4484#define RT_US_15SEC_64 UINT64_C(15000000)
4485/** 10 seconds expressed in microseconds - 64-bit type. */
4486#define RT_US_10SEC_64 UINT64_C(10000000)
4487/** 5 seconds expressed in microseconds - 64-bit type. */
4488#define RT_US_5SEC_64 UINT64_C(5000000)
4489/** 1 second expressed in microseconds - 64-bit type. */
4490#define RT_US_1SEC_64 UINT64_C(1000000)
4491/** 100 millsecond expressed in microseconds - 64-bit type. */
4492#define RT_US_100MS_64 UINT64_C(100000)
4493/** 10 millsecond expressed in microseconds - 64-bit type. */
4494#define RT_US_10MS_64 UINT64_C(10000)
4495/** 1 millsecond expressed in microseconds - 64-bit type. */
4496#define RT_US_1MS_64 UINT64_C(1000)
4497
4498/** 1 week expressed in milliseconds. */
4499#define RT_MS_1WEEK UINT32_C(604800000)
4500/** 1 day expressed in milliseconds. */
4501#define RT_MS_1DAY UINT32_C(86400000)
4502/** 1 hour expressed in milliseconds. */
4503#define RT_MS_1HOUR UINT32_C(3600000)
4504/** 30 minutes expressed in milliseconds. */
4505#define RT_MS_30MIN UINT32_C(1800000)
4506/** 5 minutes expressed in milliseconds. */
4507#define RT_MS_5MIN UINT32_C(300000)
4508/** 1 minute expressed in milliseconds. */
4509#define RT_MS_1MIN UINT32_C(60000)
4510/** 45 seconds expressed in milliseconds. */
4511#define RT_MS_45SEC UINT32_C(45000)
4512/** 30 seconds expressed in milliseconds. */
4513#define RT_MS_30SEC UINT32_C(30000)
4514/** 20 seconds expressed in milliseconds. */
4515#define RT_MS_20SEC UINT32_C(20000)
4516/** 15 seconds expressed in milliseconds. */
4517#define RT_MS_15SEC UINT32_C(15000)
4518/** 10 seconds expressed in milliseconds. */
4519#define RT_MS_10SEC UINT32_C(10000)
4520/** 5 seconds expressed in milliseconds. */
4521#define RT_MS_5SEC UINT32_C(5000)
4522/** 1 second expressed in milliseconds. */
4523#define RT_MS_1SEC UINT32_C(1000)
4524
4525/** 1 week expressed in milliseconds - 64-bit type. */
4526#define RT_MS_1WEEK_64 UINT64_C(604800000)
4527/** 1 day expressed in milliseconds - 64-bit type. */
4528#define RT_MS_1DAY_64 UINT64_C(86400000)
4529/** 1 hour expressed in milliseconds - 64-bit type. */
4530#define RT_MS_1HOUR_64 UINT64_C(3600000)
4531/** 30 minutes expressed in milliseconds - 64-bit type. */
4532#define RT_MS_30MIN_64 UINT64_C(1800000)
4533/** 5 minutes expressed in milliseconds - 64-bit type. */
4534#define RT_MS_5MIN_64 UINT64_C(300000)
4535/** 1 minute expressed in milliseconds - 64-bit type. */
4536#define RT_MS_1MIN_64 UINT64_C(60000)
4537/** 45 seconds expressed in milliseconds - 64-bit type. */
4538#define RT_MS_45SEC_64 UINT64_C(45000)
4539/** 30 seconds expressed in milliseconds - 64-bit type. */
4540#define RT_MS_30SEC_64 UINT64_C(30000)
4541/** 20 seconds expressed in milliseconds - 64-bit type. */
4542#define RT_MS_20SEC_64 UINT64_C(20000)
4543/** 15 seconds expressed in milliseconds - 64-bit type. */
4544#define RT_MS_15SEC_64 UINT64_C(15000)
4545/** 10 seconds expressed in milliseconds - 64-bit type. */
4546#define RT_MS_10SEC_64 UINT64_C(10000)
4547/** 5 seconds expressed in milliseconds - 64-bit type. */
4548#define RT_MS_5SEC_64 UINT64_C(5000)
4549/** 1 second expressed in milliseconds - 64-bit type. */
4550#define RT_MS_1SEC_64 UINT64_C(1000)
4551
4552/** The number of seconds per week. */
4553#define RT_SEC_1WEEK UINT32_C(604800)
4554/** The number of seconds per day. */
4555#define RT_SEC_1DAY UINT32_C(86400)
4556/** The number of seconds per hour. */
4557#define RT_SEC_1HOUR UINT32_C(3600)
4558
4559/** The number of seconds per week - 64-bit type. */
4560#define RT_SEC_1WEEK_64 UINT64_C(604800)
4561/** The number of seconds per day - 64-bit type. */
4562#define RT_SEC_1DAY_64 UINT64_C(86400)
4563/** The number of seconds per hour - 64-bit type. */
4564#define RT_SEC_1HOUR_64 UINT64_C(3600)
4565/** @} */
4566
4567
4568/** @defgroup grp_rt_cdefs_dbgtype Debug Info Types
4569 * @{ */
4570/** Other format. */
4571#define RT_DBGTYPE_OTHER RT_BIT_32(0)
4572/** Stabs. */
4573#define RT_DBGTYPE_STABS RT_BIT_32(1)
4574/** Debug With Arbitrary Record Format (DWARF). */
4575#define RT_DBGTYPE_DWARF RT_BIT_32(2)
4576/** Microsoft Codeview debug info. */
4577#define RT_DBGTYPE_CODEVIEW RT_BIT_32(3)
4578/** Watcom debug info. */
4579#define RT_DBGTYPE_WATCOM RT_BIT_32(4)
4580/** IBM High Level Language debug info. */
4581#define RT_DBGTYPE_HLL RT_BIT_32(5)
4582/** Old OS/2 and Windows symbol file. */
4583#define RT_DBGTYPE_SYM RT_BIT_32(6)
4584/** Map file. */
4585#define RT_DBGTYPE_MAP RT_BIT_32(7)
4586/** @} */
4587
4588
4589/** @defgroup grp_rt_cdefs_exetype Executable Image Types
4590 * @{ */
4591/** Some other format. */
4592#define RT_EXETYPE_OTHER RT_BIT_32(0)
4593/** Portable Executable. */
4594#define RT_EXETYPE_PE RT_BIT_32(1)
4595/** Linear eXecutable. */
4596#define RT_EXETYPE_LX RT_BIT_32(2)
4597/** Linear Executable. */
4598#define RT_EXETYPE_LE RT_BIT_32(3)
4599/** New Executable. */
4600#define RT_EXETYPE_NE RT_BIT_32(4)
4601/** DOS Executable (Mark Zbikowski). */
4602#define RT_EXETYPE_MZ RT_BIT_32(5)
4603/** COM Executable. */
4604#define RT_EXETYPE_COM RT_BIT_32(6)
4605/** a.out Executable. */
4606#define RT_EXETYPE_AOUT RT_BIT_32(7)
4607/** Executable and Linkable Format. */
4608#define RT_EXETYPE_ELF RT_BIT_32(8)
4609/** Mach-O Executable (including FAT ones). */
4610#define RT_EXETYPE_MACHO RT_BIT_32(9)
4611/** TE from UEFI. */
4612#define RT_EXETYPE_TE RT_BIT_32(9)
4613/** @} */
4614
4615
4616/** @def RT_VALID_PTR
4617 * Pointer validation macro.
4618 * @param ptr The pointer.
4619 */
4620#ifdef VBOX_WITH_PARFAIT
4621/*
4622 * Parfait will report memory leaks when something returns after a memory allocation
4623 * using a check containing RT_VALID_PTR() (AssertPtrReturn and friends for example).
4624 * To avoid those false positives the macro will just check for the pointer being != NULL.
4625 */
4626# define RT_VALID_PTR(ptr) (ptr != NULL)
4627#else
4628#if defined(RT_ARCH_AMD64)
4629# ifdef IN_RING3
4630# if defined(RT_OS_DARWIN) /* first 4GB is reserved for legacy kernel. */
4631# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) >= _4G \
4632 && !((uintptr_t)(ptr) & 0xffff800000000000ULL) )
4633# elif defined(RT_OS_SOLARIS) /* The kernel only used the top 2TB, but keep it simple. */
4634# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
4635 && ( ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0xffff800000000000ULL \
4636 || ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0) )
4637# elif defined(RT_OS_LINUX) /* May use 5-level paging (see Documentation/x86/x86_64/mm.rst). */
4638# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) >= 0x1000U /* one invalid page at the bottom */ \
4639 && !((uintptr_t)(ptr) & 0xff00000000000000ULL) )
4640# else
4641# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) >= 0x1000U \
4642 && !((uintptr_t)(ptr) & 0xffff800000000000ULL) )
4643# endif
4644# else /* !IN_RING3 */
4645# if defined(RT_OS_LINUX) /* May use 5-level paging (see Documentation/x86/x86_64/mm.rst). */
4646# if 1 /* User address are no longer considered valid in kernel mode (SMAP, etc). */
4647# define RT_VALID_PTR(ptr) ((uintptr_t)(ptr) - 0xff00000000000000ULL < 0x00ffffffffe00000ULL) /* 2MB invalid space at the top */
4648# else
4649# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x200000 >= 0x201000U /* one invalid page at the bottom and 2MB at the top */ \
4650 && ( ((uintptr_t)(ptr) & 0xff00000000000000ULL) == 0xff00000000000000ULL \
4651 || ((uintptr_t)(ptr) & 0xff00000000000000ULL) == 0) )
4652# endif
4653# else
4654# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
4655 && ( ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0xffff800000000000ULL \
4656 || ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0) )
4657# endif
4658# endif /* !IN_RING3 */
4659
4660# elif defined(RT_ARCH_X86)
4661# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U )
4662
4663# elif defined(RT_ARCH_SPARC64)
4664# ifdef IN_RING3
4665# if defined(RT_OS_SOLARIS)
4666/** Sparc64 user mode: According to Figure 9.4 in solaris internals */
4667/** @todo # define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x80004000U >= 0x80004000U + 0x100000000ULL ) - figure this. */
4668# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x80000000U >= 0x80000000U + 0x100000000ULL )
4669# else
4670# error "Port me"
4671# endif
4672# else /* !IN_RING3 */
4673# if defined(RT_OS_SOLARIS)
4674/** @todo Sparc64 kernel mode: This is according to Figure 11.1 in solaris
4675 * internals. Verify in sources. */
4676# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) >= 0x01000000U )
4677# else
4678# error "Port me"
4679# endif
4680# endif /* !IN_RING3 */
4681
4682# elif defined(RT_ARCH_SPARC)
4683# ifdef IN_RING3
4684# ifdef RT_OS_SOLARIS
4685/** Sparc user mode: According to
4686 * http://cvs.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/uts/sun4/os/startup.c#510 */
4687# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x400000U >= 0x400000U + 0x2000U )
4688
4689# else
4690# error "Port me"
4691# endif
4692# else /* !IN_RING3 */
4693# ifdef RT_OS_SOLARIS
4694/** @todo Sparc kernel mode: Check the sources! */
4695# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U )
4696# else
4697# error "Port me"
4698# endif
4699# endif /* !IN_RING3 */
4700
4701# elif defined(RT_ARCH_ARM32) || defined(RT_ARCH_ARM64)
4702/* ASSUMES that at least the last and first 4K are out of bounds. */
4703# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U )
4704
4705# else
4706# error "Architecture identifier missing / not implemented."
4707# endif
4708#endif /*!VBOX_WITH_PARFAIT*/
4709
4710/** @def RT_VALID_ALIGNED_PTR
4711 * Pointer validation macro that also checks the alignment.
4712 * @param ptr The pointer.
4713 * @param align The alignment, must be a power of two.
4714 */
4715#define RT_VALID_ALIGNED_PTR(ptr, align) \
4716 ( !((uintptr_t)(ptr) & (uintptr_t)((align) - 1)) \
4717 && RT_VALID_PTR(ptr) )
4718
4719
4720/** @def VALID_PHYS32
4721 * 32 bits physical address validation macro.
4722 * @param Phys The RTGCPHYS address.
4723 */
4724#define VALID_PHYS32(Phys) ( (uint64_t)(Phys) < (uint64_t)_4G )
4725
4726/** @def N_
4727 * The \#define N_ is used to mark a string for translation. This is usable in
4728 * any part of the code, as it is only used by the tools that create message
4729 * catalogs. This macro is a no-op as far as the compiler and code generation
4730 * is concerned.
4731 *
4732 * If you want to both mark a string for translation and translate it, use _().
4733 */
4734#define N_(s) (s)
4735
4736/** @def _
4737 * The \#define _ is used to mark a string for translation and to translate it
4738 * in one step.
4739 *
4740 * If you want to only mark a string for translation, use N_().
4741 */
4742#define _(s) gettext(s)
4743
4744
4745#if (!defined(__GNUC__) && !defined(__PRETTY_FUNCTION__)) || defined(DOXYGEN_RUNNING)
4746# if defined(_MSC_VER) || defined(DOXYGEN_RUNNING)
4747/** With GNU C we'd like to use the builtin __PRETTY_FUNCTION__, so define that
4748 * for the other compilers. */
4749# define __PRETTY_FUNCTION__ __FUNCSIG__
4750# else
4751# define __PRETTY_FUNCTION__ __FUNCTION__
4752# endif
4753#endif
4754
4755
4756/** @def RT_STRICT
4757 * The \#define RT_STRICT controls whether or not assertions and other runtime
4758 * checks should be compiled in or not. This is defined when DEBUG is defined.
4759 * If RT_NO_STRICT is defined, it will unconditionally be undefined.
4760 *
4761 * If you want assertions which are not subject to compile time options use
4762 * the AssertRelease*() flavors.
4763 */
4764#if !defined(RT_STRICT) && defined(DEBUG)
4765# define RT_STRICT
4766#endif
4767#ifdef RT_NO_STRICT
4768# undef RT_STRICT
4769#endif
4770
4771/** @todo remove this: */
4772#if !defined(RT_LOCK_STRICT) && !defined(DEBUG_bird)
4773# define RT_LOCK_NO_STRICT
4774#endif
4775#if !defined(RT_LOCK_STRICT_ORDER) && !defined(DEBUG_bird)
4776# define RT_LOCK_NO_STRICT_ORDER
4777#endif
4778
4779/** @def RT_LOCK_STRICT
4780 * The \#define RT_LOCK_STRICT controls whether deadlock detection and related
4781 * checks are done in the lock and semaphore code. It is by default enabled in
4782 * RT_STRICT builds, but this behavior can be overridden by defining
4783 * RT_LOCK_NO_STRICT. */
4784#if !defined(RT_LOCK_STRICT) && !defined(RT_LOCK_NO_STRICT) && defined(RT_STRICT)
4785# define RT_LOCK_STRICT
4786#endif
4787/** @def RT_LOCK_NO_STRICT
4788 * The \#define RT_LOCK_NO_STRICT disables RT_LOCK_STRICT. */
4789#if defined(RT_LOCK_NO_STRICT) && defined(RT_LOCK_STRICT)
4790# undef RT_LOCK_STRICT
4791#endif
4792
4793/** @def RT_LOCK_STRICT_ORDER
4794 * The \#define RT_LOCK_STRICT_ORDER controls whether locking order is checked
4795 * by the lock and semaphore code. It is by default enabled in RT_STRICT
4796 * builds, but this behavior can be overridden by defining
4797 * RT_LOCK_NO_STRICT_ORDER. */
4798#if !defined(RT_LOCK_STRICT_ORDER) && !defined(RT_LOCK_NO_STRICT_ORDER) && defined(RT_STRICT)
4799# define RT_LOCK_STRICT_ORDER
4800#endif
4801/** @def RT_LOCK_NO_STRICT_ORDER
4802 * The \#define RT_LOCK_NO_STRICT_ORDER disables RT_LOCK_STRICT_ORDER. */
4803#if defined(RT_LOCK_NO_STRICT_ORDER) && defined(RT_LOCK_STRICT_ORDER)
4804# undef RT_LOCK_STRICT_ORDER
4805#endif
4806
4807
4808/** Source position. */
4809#define RT_SRC_POS __FILE__, __LINE__, RT_GCC_EXTENSION __PRETTY_FUNCTION__
4810
4811/** Source position declaration. */
4812#define RT_SRC_POS_DECL const char *pszFile, unsigned iLine, const char *pszFunction
4813
4814/** Source position arguments. */
4815#define RT_SRC_POS_ARGS pszFile, iLine, pszFunction
4816
4817/** Applies NOREF() to the source position arguments. */
4818#define RT_SRC_POS_NOREF() do { NOREF(pszFile); NOREF(iLine); NOREF(pszFunction); } while (0)
4819
4820
4821/** @def RT_INLINE_ASM_EXTERNAL
4822 * Defined as 1 if the compiler does not support inline assembly.
4823 * The ASM* functions will then be implemented in external .asm files.
4824 */
4825#if (defined(_MSC_VER) && defined(RT_ARCH_AMD64)) \
4826 || (!defined(RT_ARCH_AMD64) && !defined(RT_ARCH_X86) && !defined(RT_ARCH_ARM64) && !defined(RT_ARCH_ARM32)) \
4827 || defined(__WATCOMC__)
4828# define RT_INLINE_ASM_EXTERNAL 1
4829#else
4830# define RT_INLINE_ASM_EXTERNAL 0
4831#endif
4832
4833/** @def RT_INLINE_ASM_EXTERNAL_TMP_ARM
4834 * Temporary version of RT_INLINE_ASM_EXTERNAL that excludes ARM. */
4835#if RT_INLINE_ASM_EXTERNAL && !(defined(RT_ARCH_ARM64) || defined(RT_ARCH_ARM32))
4836# define RT_INLINE_ASM_EXTERNAL_TMP_ARM 1
4837#else
4838# define RT_INLINE_ASM_EXTERNAL_TMP_ARM 0
4839#endif
4840
4841/** @def RT_INLINE_ASM_GNU_STYLE
4842 * Defined as 1 if the compiler understands GNU style inline assembly.
4843 */
4844#if defined(_MSC_VER) || defined(__WATCOMC__)
4845# define RT_INLINE_ASM_GNU_STYLE 0
4846#else
4847# define RT_INLINE_ASM_GNU_STYLE 1
4848#endif
4849
4850/** @def RT_INLINE_ASM_USES_INTRIN
4851 * Defined as one of the RT_MSC_VER_XXX MSC version values if the compiler have
4852 * and uses intrin.h. Otherwise it is 0. */
4853#ifdef _MSC_VER
4854# if _MSC_VER >= RT_MSC_VER_VS2019 /* Visual C++ v14.2 */
4855# define RT_INLINE_ASM_USES_INTRIN RT_MSC_VER_VS2019
4856# elif _MSC_VER >= RT_MSC_VER_VS2017 /* Visual C++ v14.1 */
4857# define RT_INLINE_ASM_USES_INTRIN RT_MSC_VER_VS2017
4858# elif _MSC_VER >= RT_MSC_VER_VS2015 /* Visual C++ v14.0 */
4859# define RT_INLINE_ASM_USES_INTRIN RT_MSC_VER_VS2015
4860# elif _MSC_VER >= RT_MSC_VER_VS2013 /* Visual C++ v12.0 */
4861# define RT_INLINE_ASM_USES_INTRIN RT_MSC_VER_VS2013
4862# elif _MSC_VER >= RT_MSC_VER_VS2012 /* Visual C++ v11.0 */
4863# define RT_INLINE_ASM_USES_INTRIN RT_MSC_VER_VS2012
4864# elif _MSC_VER >= RT_MSC_VER_VS2010 /* Visual C++ v10.0 */
4865# define RT_INLINE_ASM_USES_INTRIN RT_MSC_VER_VS2010
4866# elif _MSC_VER >= RT_MSC_VER_VS2008 /* Visual C++ v9.0 */
4867# define RT_INLINE_ASM_USES_INTRIN RT_MSC_VER_VS2008
4868# elif _MSC_VER >= RT_MSC_VER_VS2005 /* Visual C++ v8.0 */
4869# define RT_INLINE_ASM_USES_INTRIN RT_MSC_VER_VS2005
4870# endif
4871#endif
4872#ifndef RT_INLINE_ASM_USES_INTRIN
4873# define RT_INLINE_ASM_USES_INTRIN 0
4874#endif
4875
4876#define RT_MSC_VER_VS2012 (1700) /**< Visual Studio 2012. */
4877#define RT_MSC_VER_VC110 RT_MSC_VER_VS2012 /**< Visual C++ 11.0, aka Visual Studio 2012. */
4878#define RT_MSC_VER_VS2013 (1800) /**< Visual Studio 2013. */
4879#define RT_MSC_VER_VC120 RT_MSC_VER_VS2013 /**< Visual C++ 12.0, aka Visual Studio 2013. */
4880#define RT_MSC_VER_VS2015 (1900) /**< Visual Studio 2015. */
4881#define RT_MSC_VER_VC140 RT_MSC_VER_VS2015 /**< Visual C++ 14.0, aka Visual Studio 2015. */
4882#define RT_MSC_VER_VS2017 (1910) /**< Visual Studio 2017. */
4883#define RT_MSC_VER_VC141 RT_MSC_VER_VS2017 /**< Visual C++ 14.1, aka Visual Studio 2017. */
4884#define RT_MSC_VER_VS2019 (1920) /**< Visual Studio 2017. */
4885#define RT_MSC_VER_VC142 RT_MSC_VER_VS2019 /**< Visual C++ 14.2, aka Visual Studio 2019. */
4886
4887/** @def RT_COMPILER_SUPPORTS_LAMBDA
4888 * If the defined, the compiler supports lambda expressions. These expressions
4889 * are useful for embedding assertions and type checks into macros. */
4890#if defined(_MSC_VER) && defined(__cplusplus)
4891# if _MSC_VER >= 1600 /* Visual C++ v10.0 / 2010 */
4892# define RT_COMPILER_SUPPORTS_LAMBDA
4893# endif
4894#elif defined(__GNUC__) && defined(__cplusplus)
4895/* 4.5 or later, I think, if in ++11 mode... */
4896#endif
4897
4898/** @def RT_DATA_IS_FAR
4899 * Set to 1 if we're in 16-bit mode and use far pointers.
4900 */
4901#if ARCH_BITS == 16 && defined(__WATCOMC__) \
4902 && (defined(__COMPACT__) || defined(__LARGE__))
4903# define RT_DATA_IS_FAR 1
4904#else
4905# define RT_DATA_IS_FAR 0
4906#endif
4907
4908/** @def RT_FAR
4909 * For indicating far pointers in 16-bit code.
4910 * Does nothing in 32-bit and 64-bit code. */
4911/** @def RT_NEAR
4912 * For indicating near pointers in 16-bit code.
4913 * Does nothing in 32-bit and 64-bit code. */
4914/** @def RT_FAR_CODE
4915 * For indicating far 16-bit functions.
4916 * Does nothing in 32-bit and 64-bit code. */
4917/** @def RT_NEAR_CODE
4918 * For indicating near 16-bit functions.
4919 * Does nothing in 32-bit and 64-bit code. */
4920/** @def RT_FAR_DATA
4921 * For indicating far 16-bit external data, i.e. in a segment other than DATA16.
4922 * Does nothing in 32-bit and 64-bit code. */
4923#if ARCH_BITS == 16
4924# define RT_FAR __far
4925# define RT_NEAR __near
4926# define RT_FAR_CODE __far
4927# define RT_NEAR_CODE __near
4928# define RT_FAR_DATA __far
4929#else
4930# define RT_FAR
4931# define RT_NEAR
4932# define RT_FAR_CODE
4933# define RT_NEAR_CODE
4934# define RT_FAR_DATA
4935#endif
4936
4937
4938/** @} */
4939
4940
4941/** @defgroup grp_rt_cdefs_cpp Special Macros for C++
4942 * @ingroup grp_rt_cdefs
4943 * @{
4944 */
4945
4946#ifdef __cplusplus
4947
4948/** @def DECLEXPORT_CLASS
4949 * How to declare an exported class. Place this macro after the 'class'
4950 * keyword in the declaration of every class you want to export.
4951 *
4952 * @note It is necessary to use this macro even for inner classes declared
4953 * inside the already exported classes. This is a GCC specific requirement,
4954 * but it seems not to harm other compilers.
4955 */
4956#if defined(_MSC_VER) || defined(RT_OS_OS2)
4957# define DECLEXPORT_CLASS __declspec(dllexport)
4958#elif defined(RT_USE_VISIBILITY_DEFAULT)
4959# define DECLEXPORT_CLASS __attribute__((visibility("default")))
4960#else
4961# define DECLEXPORT_CLASS
4962#endif
4963
4964/** @def DECLIMPORT_CLASS
4965 * How to declare an imported class Place this macro after the 'class'
4966 * keyword in the declaration of every class you want to export.
4967 *
4968 * @note It is necessary to use this macro even for inner classes declared
4969 * inside the already exported classes. This is a GCC specific requirement,
4970 * but it seems not to harm other compilers.
4971 */
4972#if defined(_MSC_VER) || (defined(RT_OS_OS2) && !defined(__IBMC__) && !defined(__IBMCPP__))
4973# define DECLIMPORT_CLASS __declspec(dllimport)
4974#elif defined(RT_USE_VISIBILITY_DEFAULT)
4975# define DECLIMPORT_CLASS __attribute__((visibility("default")))
4976#else
4977# define DECLIMPORT_CLASS
4978#endif
4979
4980/** @def WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP
4981 * Macro to work around error C2593 of the not-so-smart MSVC 7.x ambiguity
4982 * resolver. The following snippet clearly demonstrates the code causing this
4983 * error:
4984 * @code
4985 * class A
4986 * {
4987 * public:
4988 * operator bool() const { return false; }
4989 * operator int*() const { return NULL; }
4990 * };
4991 * int main()
4992 * {
4993 * A a;
4994 * if (!a);
4995 * if (a && 0);
4996 * return 0;
4997 * }
4998 * @endcode
4999 * The code itself seems pretty valid to me and GCC thinks the same.
5000 *
5001 * This macro fixes the compiler error by explicitly overloading implicit
5002 * global operators !, && and || that take the given class instance as one of
5003 * their arguments.
5004 *
5005 * The best is to use this macro right after the class declaration.
5006 *
5007 * @note The macro expands to nothing for compilers other than MSVC.
5008 *
5009 * @param Cls Class to apply the workaround to
5010 */
5011#if defined(_MSC_VER)
5012# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP(Cls) \
5013 inline bool operator! (const Cls &that) { return !bool (that); } \
5014 inline bool operator&& (const Cls &that, bool b) { return bool (that) && b; } \
5015 inline bool operator|| (const Cls &that, bool b) { return bool (that) || b; } \
5016 inline bool operator&& (bool b, const Cls &that) { return b && bool (that); } \
5017 inline bool operator|| (bool b, const Cls &that) { return b || bool (that); }
5018#else
5019# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP(Cls)
5020#endif
5021
5022/** @def WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL
5023 * Version of WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP for template classes.
5024 *
5025 * @param Tpl Name of the template class to apply the workaround to
5026 * @param ArgsDecl arguments of the template, as declared in |<>| after the
5027 * |template| keyword, including |<>|
5028 * @param Args arguments of the template, as specified in |<>| after the
5029 * template class name when using the, including |<>|
5030 *
5031 * Example:
5032 * @code
5033 * // template class declaration
5034 * template <class C>
5035 * class Foo { ... };
5036 * // applied workaround
5037 * WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL (Foo, <class C>, <C>)
5038 * @endcode
5039 */
5040#if defined(_MSC_VER)
5041# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL(Tpl, ArgsDecl, Args) \
5042 template ArgsDecl \
5043 inline bool operator! (const Tpl Args &that) { return !bool (that); } \
5044 template ArgsDecl \
5045 inline bool operator&& (const Tpl Args &that, bool b) { return bool (that) && b; } \
5046 template ArgsDecl \
5047 inline bool operator|| (const Tpl Args &that, bool b) { return bool (that) || b; } \
5048 template ArgsDecl \
5049 inline bool operator&& (bool b, const Tpl Args &that) { return b && bool (that); } \
5050 template ArgsDecl \
5051 inline bool operator|| (bool b, const Tpl Args &that) { return b || bool (that); }
5052#else
5053# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL(Tpl, ArgsDecl, Args)
5054#endif
5055
5056
5057/** @def DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP
5058 * Declares the copy constructor and the assignment operation as inlined no-ops
5059 * (non-existent functions) for the given class. Use this macro inside the
5060 * private section if you want to effectively disable these operations for your
5061 * class.
5062 *
5063 * @param Cls class name to declare for
5064 */
5065#define DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(Cls) \
5066 inline Cls(const Cls &); \
5067 inline Cls &operator= (const Cls &)
5068
5069
5070/** @def DECLARE_CLS_NEW_DELETE_NOOP
5071 * Declares the new and delete operations as no-ops (non-existent functions)
5072 * for the given class. Use this macro inside the private section if you want
5073 * to effectively limit creating class instances on the stack only.
5074 *
5075 * @note The destructor of the given class must not be virtual, otherwise a
5076 * compile time error will occur. Note that this is not a drawback: having
5077 * the virtual destructor for a stack-based class is absolutely useless
5078 * (the real class of the stack-based instance is always known to the compiler
5079 * at compile time, so it will always call the correct destructor).
5080 *
5081 * @param Cls class name to declare for
5082 */
5083#define DECLARE_CLS_NEW_DELETE_NOOP(Cls) \
5084 inline static void *operator new (size_t); \
5085 inline static void operator delete (void *)
5086
5087#endif /* __cplusplus */
5088
5089/** @} */
5090
5091#endif /* !IPRT_INCLUDED_cdefs_h */
5092
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