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