VirtualBox

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

Last change on this file since 91991 was 90825, checked in by vboxsync, 3 years ago

iprt/cdefs.h: RT_VALID_PTR now only recognize kernel address in linux/r0.

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