VirtualBox

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

Last change on this file since 106443 was 106061, checked in by vboxsync, 3 months ago

Copyright year updates by scm.

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

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