VirtualBox

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

Last change on this file since 95395 was 95358, checked in by vboxsync, 3 years ago

iprt/cdefs.h: Added RT_ALIGNAS_VAR, RT_ALIGNAS_TYPE, RT_ALIGNAS_MEMB and RT_CACHELINE_SIZE for better data alignment. bugref:9898

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