VirtualBox

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

Last change on this file was 104365, checked in by vboxsync, 4 weeks ago

iprt/cdefs.h: Added RT_IN_ASSEMBLER for when we're preprocessing for the assembler. bugref:9898 bugref:10653 bugref:10370

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

© 2023 Oracle
ContactPrivacy policyTerms of Use