VirtualBox

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

Last change on this file since 93483 was 93443, checked in by vboxsync, 3 years ago

iprt/cdefs.h: Added checks for RT_RELAXED_CALLBACKS_TYPES before using non-standard noexcept/nothrow function pointers. bugref:10074

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

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