VirtualBox

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

Last change on this file since 94801 was 94537, checked in by vboxsync, 3 years ago

iprt/types.h,cdefs.h: Added RTFLOAT128U and associated macros. bugref:9898

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

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