VirtualBox

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

Last change on this file since 85254 was 85229, checked in by vboxsync, 5 years ago

iprt/cdefs.h: Fixed Clang 11 warnings about RT_MAKE_U32_FROM_U8. bugref:9790

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

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