VirtualBox

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

最後變更 在這個檔案從108290是 108290,由 vboxsync 提交於 4 週 前

iprt/cdefs.h,VMM/IEM: Added RT_NO_WARN_UNUSED_INLINE_PROTOTYPE_BEGIN/END to cdefs.h for working around warning/error in IEMInline.h with recent gcc versions (13.3 and others). jiraref:VBP-1531

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

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