VirtualBox

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

Last change on this file since 90062 was 89076, checked in by vboxsync, 4 years ago

IPRT/cdefs.h: Also disable warning for MSVC 2019 for RT_FLEXIBLE_ARRAY usage. Needs review!

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