VirtualBox

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

Last change on this file since 68862 was 68572, checked in by vboxsync, 7 years ago

merging vbglioc r117744: iprt: Introducing RT_FAR and friends to deal with the world of 16-bit compilers. Made iprt/types.h somewhat 16-bit safe (explicit far pointers, int type fixes).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 159.2 KB
Line 
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# if RT_GNUC_PREREQ(3, 3)
1066# define RT_NO_THROW_PROTO __attribute__((__nothrow__))
1067# else
1068# define RT_NO_THROW_PROTO
1069# endif
1070# else
1071# define RT_NO_THROW_PROTO throw()
1072# endif
1073#else
1074# define RT_NO_THROW_PROTO
1075#endif
1076
1077/** @def RT_NO_THROW_DEF
1078 * The counter part to RT_NO_THROW_PROTO that is added to the function
1079 * definition.
1080 */
1081#if defined(RT_EXCEPTIONS_ENABLED) && !defined(__GNUC__)
1082# define RT_NO_THROW_DEF RT_NO_THROW_PROTO
1083#else
1084# define RT_NO_THROW_DEF
1085#endif
1086
1087/** @def RT_THROW
1088 * How to express that a method or function throws a type of exceptions. Some
1089 * compilers does not want this kind of information and will warning about it.
1090 *
1091 * @param type The type exception.
1092 *
1093 * @remarks If the actual throwing is done from the header, enclose it by
1094 * \#ifdef RT_EXCEPTIONS_ENABLED ... \#else ... \#endif so the header
1095 * compiles cleanly without exceptions enabled.
1096 *
1097 * Do NOT use this for the actual throwing of exceptions!
1098 */
1099#ifdef RT_EXCEPTIONS_ENABLED
1100# if RT_MSC_PREREQ_EX(RT_MSC_VER_VC71, 0)
1101# define RT_THROW(type)
1102# elif RT_GNUC_PREREQ(7, 0)
1103# define RT_THROW(type)
1104# else
1105# define RT_THROW(type) throw(type)
1106# endif
1107#else
1108# define RT_THROW(type)
1109#endif
1110
1111/** @def RT_IPRT_FORMAT_ATTR
1112 * Identifies a function taking an IPRT format string.
1113 * @param a_iFmt The index (1-based) of the format string argument.
1114 * @param a_iArgs The index (1-based) of the first format argument, use 0 for
1115 * va_list.
1116 */
1117#if defined(__GNUC__) && defined(WITH_IPRT_FORMAT_ATTRIBUTE)
1118# define RT_IPRT_FORMAT_ATTR(a_iFmt, a_iArgs) __attribute__((__iprt_format__(a_iFmt, a_iArgs)))
1119#else
1120# define RT_IPRT_FORMAT_ATTR(a_iFmt, a_iArgs)
1121#endif
1122
1123/** @def RT_IPRT_FORMAT_ATTR_MAYBE_NULL
1124 * Identifies a function taking an IPRT format string, NULL is allowed.
1125 * @param a_iFmt The index (1-based) of the format string argument.
1126 * @param a_iArgs The index (1-based) of the first format argument, use 0 for
1127 * va_list.
1128 */
1129#if defined(__GNUC__) && defined(WITH_IPRT_FORMAT_ATTRIBUTE)
1130# define RT_IPRT_FORMAT_ATTR_MAYBE_NULL(a_iFmt, a_iArgs) __attribute__((__iprt_format_maybe_null__(a_iFmt, a_iArgs)))
1131#else
1132# define RT_IPRT_FORMAT_ATTR_MAYBE_NULL(a_iFmt, a_iArgs)
1133#endif
1134
1135
1136/** @def RT_GCC_SUPPORTS_VISIBILITY_HIDDEN
1137 * Indicates that the "hidden" visibility attribute can be used (GCC) */
1138#if defined(__GNUC__)
1139# if __GNUC__ >= 4 && !defined(RT_OS_OS2) && !defined(RT_OS_WINDOWS)
1140# define RT_GCC_SUPPORTS_VISIBILITY_HIDDEN
1141# endif
1142#endif
1143
1144/** @def RT_COMPILER_SUPPORTS_VA_ARGS
1145 * If the defined, the compiler supports the variadic macro feature (..., __VA_ARGS__). */
1146#if defined(_MSC_VER)
1147# if _MSC_VER >= 1600 /* Visual C++ v10.0 / 2010 */
1148# define RT_COMPILER_SUPPORTS_VA_ARGS
1149# endif
1150#elif defined(__GNUC__)
1151# if __GNUC__ >= 3 /* not entirely sure when this was added */
1152# define RT_COMPILER_SUPPORTS_VA_ARGS
1153# endif
1154#endif
1155
1156
1157
1158/** @def RTCALL
1159 * The standard calling convention for the Runtime interfaces.
1160 *
1161 * @remarks The regparm(0) in the X86/GNUC variant deals with -mregparm=x use in
1162 * the linux kernel and potentially elsewhere (3rd party).
1163 */
1164#if defined(_MSC_VER) || defined(__WATCOMC__)
1165# define RTCALL __cdecl
1166#elif defined(RT_OS_OS2)
1167# define RTCALL __cdecl
1168#elif defined(__GNUC__) && defined(RT_ARCH_X86)
1169# define RTCALL __attribute__((__cdecl__,__regparm__(0)))
1170#else
1171# define RTCALL
1172#endif
1173
1174/** @def DECLEXPORT
1175 * How to declare an exported function.
1176 * @param type The return type of the function declaration.
1177 */
1178#if defined(_MSC_VER) || defined(RT_OS_OS2)
1179# define DECLEXPORT(type) __declspec(dllexport) type
1180#elif defined(RT_USE_VISIBILITY_DEFAULT)
1181# define DECLEXPORT(type) __attribute__((visibility("default"))) type
1182#else
1183# define DECLEXPORT(type) type
1184#endif
1185
1186/** @def DECLIMPORT
1187 * How to declare an imported function.
1188 * @param type The return type of the function declaration.
1189 */
1190#if defined(_MSC_VER) || (defined(RT_OS_OS2) && !defined(__IBMC__) && !defined(__IBMCPP__))
1191# define DECLIMPORT(type) __declspec(dllimport) type
1192#else
1193# define DECLIMPORT(type) type
1194#endif
1195
1196/** @def DECLHIDDEN
1197 * How to declare a non-exported function or variable.
1198 * @param type The return type of the function or the data type of the variable.
1199 */
1200#if !defined(RT_GCC_SUPPORTS_VISIBILITY_HIDDEN) || defined(RT_NO_VISIBILITY_HIDDEN)
1201# define DECLHIDDEN(type) type
1202#else
1203# define DECLHIDDEN(type) __attribute__((visibility("hidden"))) type
1204#endif
1205
1206/** @def DECL_HIDDEN_CONST
1207 * Workaround for g++ warnings when applying the hidden attribute to a const
1208 * definition. Use DECLHIDDEN for the declaration.
1209 * @param a_Type The return type of the function or the data type of
1210 * the variable.
1211 */
1212#if defined(__cplusplus) && defined(__GNUC__)
1213# define DECL_HIDDEN_CONST(a_Type) a_Type
1214#else
1215# define DECL_HIDDEN_CONST(a_Type) DECLHIDDEN(a_Type)
1216#endif
1217
1218/** @def DECL_INVALID
1219 * How to declare a function not available for linking in the current context.
1220 * The purpose is to create compile or like time errors when used. This isn't
1221 * possible on all platforms.
1222 * @param type The return type of the function.
1223 */
1224#if defined(_MSC_VER)
1225# define DECL_INVALID(type) __declspec(dllimport) type __stdcall
1226#elif defined(__GNUC__) && defined(__cplusplus)
1227# define DECL_INVALID(type) extern "C++" type
1228#else
1229# define DECL_INVALID(type) type
1230#endif
1231
1232/** @def DECLASM
1233 * How to declare an internal assembly function.
1234 * @param type The return type of the function declaration.
1235 */
1236#ifdef __cplusplus
1237# define DECLASM(type) extern "C" type RTCALL
1238#else
1239# define DECLASM(type) type RTCALL
1240#endif
1241
1242/** @def DECLASMTYPE
1243 * How to declare an internal assembly function type.
1244 * @param type The return type of the function.
1245 */
1246#define DECLASMTYPE(type) type RTCALL
1247
1248/** @def DECL_NO_RETURN
1249 * How to declare a function which does not return.
1250 * @note This macro can be combined with other macros, for example
1251 * @code
1252 * EMR3DECL(DECL_NO_RETURN(void)) foo(void);
1253 * @endcode
1254 */
1255#ifdef _MSC_VER
1256# define DECL_NO_RETURN(type) __declspec(noreturn) type
1257#elif defined(__GNUC__)
1258# define DECL_NO_RETURN(type) __attribute__((noreturn)) type
1259#else
1260# define DECL_NO_RETURN(type) type
1261#endif
1262/** @deprecated Use DECL_NO_RETURN instead. */
1263#define DECLNORETURN(type) DECL_NO_RETURN(type)
1264
1265/** @def DECL_RETURNS_TWICE
1266 * How to declare a function which may return more than once.
1267 * @note This macro can be combined with other macros, for example
1268 * @code
1269 * EMR3DECL(DECL_RETURNS_TWICE(void)) MySetJmp(void);
1270 * @endcode
1271 */
1272#if RT_GNUC_PREREQ(4, 1)
1273# define DECL_RETURNS_TWICE(type) __attribute__((returns_twice)) type
1274# else
1275# define DECL_RETURNS_TWICE(type) type
1276#endif
1277
1278/** @def DECLWEAK
1279 * How to declare a variable which is not necessarily resolved at
1280 * runtime.
1281 * @note This macro can be combined with other macros, for example
1282 * @code
1283 * EMR3DECL(DECLWEAK(int)) foo;
1284 * @endcode
1285 */
1286#if defined(__GNUC__)
1287# define DECLWEAK(type) type __attribute__((weak))
1288#else
1289# define DECLWEAK(type) type
1290#endif
1291
1292/** @def DECLCALLBACK
1293 * How to declare an call back function type.
1294 * @param type The return type of the function declaration.
1295 */
1296#define DECLCALLBACK(type) type RT_FAR_CODE RTCALL
1297
1298/** @def DECLCALLBACKPTR
1299 * How to declare an call back function pointer.
1300 * @param type The return type of the function declaration.
1301 * @param name The name of the variable member.
1302 */
1303#if defined(__IBMC__) || defined(__IBMCPP__)
1304# define DECLCALLBACKPTR(type, name) type (* RTCALL name)
1305#else
1306# define DECLCALLBACKPTR(type, name) type (RT_FAR_CODE RTCALL * name)
1307#endif
1308
1309/** @def DECLCALLBACKMEMBER
1310 * How to declare an call back function pointer member.
1311 * @param type The return type of the function declaration.
1312 * @param name The name of the struct/union/class member.
1313 */
1314#if defined(__IBMC__) || defined(__IBMCPP__)
1315# define DECLCALLBACKMEMBER(type, name) type (* RTCALL name)
1316#else
1317# define DECLCALLBACKMEMBER(type, name) type (RT_FAR_CODE RTCALL * name)
1318#endif
1319
1320/** @def DECLR3CALLBACKMEMBER
1321 * How to declare an call back function pointer member - R3 Ptr.
1322 * @param type The return type of the function declaration.
1323 * @param name The name of the struct/union/class member.
1324 * @param args The argument list enclosed in parentheses.
1325 */
1326#ifdef IN_RING3
1327# define DECLR3CALLBACKMEMBER(type, name, args) DECLCALLBACKMEMBER(type, name) args
1328#else
1329# define DECLR3CALLBACKMEMBER(type, name, args) RTR3PTR name
1330#endif
1331
1332/** @def DECLRCCALLBACKMEMBER
1333 * How to declare an call back function pointer member - RC Ptr.
1334 * @param type The return type of the function declaration.
1335 * @param name The name of the struct/union/class member.
1336 * @param args The argument list enclosed in parentheses.
1337 */
1338#ifdef IN_RC
1339# define DECLRCCALLBACKMEMBER(type, name, args) DECLCALLBACKMEMBER(type, name) args
1340#else
1341# define DECLRCCALLBACKMEMBER(type, name, args) RTRCPTR name
1342#endif
1343
1344/** @def DECLR0CALLBACKMEMBER
1345 * How to declare an call back function pointer member - R0 Ptr.
1346 * @param type The return type of the function declaration.
1347 * @param name The name of the struct/union/class member.
1348 * @param args The argument list enclosed in parentheses.
1349 */
1350#ifdef IN_RING0
1351# define DECLR0CALLBACKMEMBER(type, name, args) DECLCALLBACKMEMBER(type, name) args
1352#else
1353# define DECLR0CALLBACKMEMBER(type, name, args) RTR0PTR name
1354#endif
1355
1356/** @def DECLINLINE
1357 * How to declare a function as inline.
1358 * @param type The return type of the function declaration.
1359 * @remarks Don't use this macro on C++ methods.
1360 */
1361#ifdef __GNUC__
1362# define DECLINLINE(type) static __inline__ type
1363#elif defined(__cplusplus)
1364# define DECLINLINE(type) static inline type
1365#elif defined(_MSC_VER)
1366# define DECLINLINE(type) static _inline type
1367#elif defined(__IBMC__)
1368# define DECLINLINE(type) _Inline type
1369#else
1370# define DECLINLINE(type) inline type
1371#endif
1372
1373
1374/** @def DECL_FORCE_INLINE
1375 * How to declare a function as inline and try convince the compiler to always
1376 * inline it regardless of optimization switches.
1377 * @param type The return type of the function declaration.
1378 * @remarks Use sparsely and with care. Don't use this macro on C++ methods.
1379 */
1380#ifdef __GNUC__
1381# define DECL_FORCE_INLINE(type) __attribute__((__always_inline__)) DECLINLINE(type)
1382#elif defined(_MSC_VER)
1383# define DECL_FORCE_INLINE(type) __forceinline type
1384#else
1385# define DECL_FORCE_INLINE(type) DECLINLINE(type)
1386#endif
1387
1388
1389/** @def DECL_NO_INLINE
1390 * How to declare a function telling the compiler not to inline it.
1391 * @param scope The function scope, static or RT_NOTHING.
1392 * @param type The return type of the function declaration.
1393 * @remarks Don't use this macro on C++ methods.
1394 */
1395#ifdef __GNUC__
1396# define DECL_NO_INLINE(scope,type) __attribute__((__noinline__)) scope type
1397#elif defined(_MSC_VER)
1398# define DECL_NO_INLINE(scope,type) __declspec(noinline) scope type
1399#else
1400# define DECL_NO_INLINE(scope,type) scope type
1401#endif
1402
1403
1404/** @def IN_RT_STATIC
1405 * Used to indicate whether we're linking against a static IPRT
1406 * or not.
1407 *
1408 * The IPRT symbols will be declared as hidden (if supported). Note that this
1409 * define has no effect without also setting one of the IN_RT_R0, IN_RT_R3 or
1410 * IN_RT_RC indicators.
1411 */
1412
1413/** @def IN_RT_R0
1414 * Used to indicate whether we're inside the same link module as the host
1415 * context ring-0 Runtime Library.
1416 */
1417/** @def RTR0DECL(type)
1418 * Runtime Library host context ring-0 export or import declaration.
1419 * @param type The return type of the function declaration.
1420 * @remarks This is only used inside IPRT. Other APIs need to define their own
1421 * XXXX_DECL macros for dealing with import/export/static visibility.
1422 */
1423#ifdef IN_RT_R0
1424# ifdef IN_RT_STATIC
1425# define RTR0DECL(type) DECLHIDDEN(type) RTCALL
1426# else
1427# define RTR0DECL(type) DECLEXPORT(type) RTCALL
1428# endif
1429#else
1430# define RTR0DECL(type) DECLIMPORT(type) RTCALL
1431#endif
1432
1433/** @def IN_RT_R3
1434 * Used to indicate whether we're inside the same link module as the host
1435 * context ring-3 Runtime Library.
1436 */
1437/** @def RTR3DECL(type)
1438 * Runtime Library host context ring-3 export or import declaration.
1439 * @param type The return type of the function declaration.
1440 * @remarks This is only used inside IPRT. Other APIs need to define their own
1441 * XXXX_DECL macros for dealing with import/export/static visibility.
1442 */
1443#ifdef IN_RT_R3
1444# ifdef IN_RT_STATIC
1445# define RTR3DECL(type) DECLHIDDEN(type) RTCALL
1446# else
1447# define RTR3DECL(type) DECLEXPORT(type) RTCALL
1448# endif
1449#else
1450# define RTR3DECL(type) DECLIMPORT(type) RTCALL
1451#endif
1452
1453/** @def IN_RT_RC
1454 * Used to indicate whether we're inside the same link module as the raw-mode
1455 * context (RC) runtime library.
1456 */
1457/** @def RTRCDECL(type)
1458 * Runtime Library raw-mode context export or import declaration.
1459 * @param type The return type of the function declaration.
1460 * @remarks This is only used inside IPRT. Other APIs need to define their own
1461 * XXXX_DECL macros for dealing with import/export/static visibility.
1462 */
1463#ifdef IN_RT_RC
1464# ifdef IN_RT_STATIC
1465# define RTRCDECL(type) DECLHIDDEN(type) RTCALL
1466# else
1467# define RTRCDECL(type) DECLEXPORT(type) RTCALL
1468# endif
1469#else
1470# define RTRCDECL(type) DECLIMPORT(type) RTCALL
1471#endif
1472
1473/** @def RTDECL(type)
1474 * Runtime Library export or import declaration.
1475 * Functions declared using this macro exists in all contexts.
1476 * @param type The return type of the function declaration.
1477 * @remarks This is only used inside IPRT. Other APIs need to define their own
1478 * XXXX_DECL macros for dealing with import/export/static visibility.
1479 */
1480#if defined(IN_RT_R3) || defined(IN_RT_RC) || defined(IN_RT_R0)
1481# ifdef IN_RT_STATIC
1482# define RTDECL(type) DECLHIDDEN(type) RTCALL
1483# else
1484# define RTDECL(type) DECLEXPORT(type) RTCALL
1485# endif
1486#else
1487# define RTDECL(type) DECLIMPORT(type) RTCALL
1488#endif
1489
1490/** @def RTDATADECL(type)
1491 * Runtime Library export or import declaration.
1492 * Data declared using this macro exists in all contexts.
1493 * @param type The data type.
1494 * @remarks This is only used inside IPRT. Other APIs need to define their own
1495 * XXXX_DECL macros for dealing with import/export/static visibility.
1496 */
1497/** @def RT_DECL_DATA_CONST(type)
1498 * Definition of a const variable. See DECL_HIDDEN_CONST.
1499 * @param type The const data type.
1500 * @remarks This is only used inside IPRT. Other APIs need to define their own
1501 * XXXX_DECL macros for dealing with import/export/static visibility.
1502 */
1503#if defined(IN_RT_R3) || defined(IN_RT_RC) || defined(IN_RT_R0)
1504# ifdef IN_RT_STATIC
1505# define RTDATADECL(type) DECLHIDDEN(type)
1506# define RT_DECL_DATA_CONST(type) DECL_HIDDEN_CONST(type)
1507# else
1508# define RTDATADECL(type) DECLEXPORT(type)
1509# if defined(__cplusplus) && defined(__GNUC__)
1510# define RT_DECL_DATA_CONST(type) type
1511# else
1512# define RT_DECL_DATA_CONST(type) DECLEXPORT(type)
1513# endif
1514# endif
1515#else
1516# define RTDATADECL(type) DECLIMPORT(type)
1517# define RT_DECL_DATA_CONST(type) DECLIMPORT(type)
1518#endif
1519
1520/** @def RT_DECL_CLASS
1521 * Declares an class living in the runtime.
1522 * @remarks This is only used inside IPRT. Other APIs need to define their own
1523 * XXXX_DECL macros for dealing with import/export/static visibility.
1524 */
1525#if defined(IN_RT_R3) || defined(IN_RT_RC) || defined(IN_RT_R0)
1526# ifdef IN_RT_STATIC
1527# define RT_DECL_CLASS
1528# else
1529# define RT_DECL_CLASS DECLEXPORT_CLASS
1530# endif
1531#else
1532# define RT_DECL_CLASS DECLIMPORT_CLASS
1533#endif
1534
1535
1536/** @def RT_NOCRT
1537 * Symbol name wrapper for the No-CRT bits.
1538 *
1539 * In order to coexist in the same process as other CRTs, we need to
1540 * decorate the symbols such that they don't conflict the ones in the
1541 * other CRTs. The result of such conflicts / duplicate symbols can
1542 * confuse the dynamic loader on Unix like systems.
1543 *
1544 * Define RT_WITHOUT_NOCRT_WRAPPERS to drop the wrapping.
1545 * Define RT_WITHOUT_NOCRT_WRAPPER_ALIASES to drop the aliases to the
1546 * wrapped names.
1547 */
1548/** @def RT_NOCRT_STR
1549 * Same as RT_NOCRT only it'll return a double quoted string of the result.
1550 */
1551#ifndef RT_WITHOUT_NOCRT_WRAPPERS
1552# define RT_NOCRT(name) nocrt_ ## name
1553# define RT_NOCRT_STR(name) "nocrt_" # name
1554#else
1555# define RT_NOCRT(name) name
1556# define RT_NOCRT_STR(name) #name
1557#endif
1558
1559
1560
1561/** @def RT_LIKELY
1562 * Give the compiler a hint that an expression is very likely to hold true.
1563 *
1564 * Some compilers support explicit branch prediction so that the CPU backend
1565 * can hint the processor and also so that code blocks can be reordered such
1566 * that the predicted path sees a more linear flow, thus improving cache
1567 * behaviour, etc.
1568 *
1569 * IPRT provides the macros RT_LIKELY() and RT_UNLIKELY() as a way to utilize
1570 * this compiler feature when present.
1571 *
1572 * A few notes about the usage:
1573 *
1574 * - Generally, order your code use RT_LIKELY() instead of RT_UNLIKELY().
1575 *
1576 * - Generally, use RT_UNLIKELY() with error condition checks (unless you
1577 * have some _strong_ reason to do otherwise, in which case document it),
1578 * and/or RT_LIKELY() with success condition checks, assuming you want
1579 * to optimize for the success path.
1580 *
1581 * - Other than that, if you don't know the likelihood of a test succeeding
1582 * from empirical or other 'hard' evidence, don't make predictions unless
1583 * you happen to be a Dirk Gently character.
1584 *
1585 * - These macros are meant to be used in places that get executed a lot. It
1586 * is wasteful to make predictions in code that is executed rarely (e.g.
1587 * at subsystem initialization time) as the basic block reordering that this
1588 * affects can often generate larger code.
1589 *
1590 * - Note that RT_SUCCESS() and RT_FAILURE() already makes use of RT_LIKELY()
1591 * and RT_UNLIKELY(). Should you wish for prediction free status checks,
1592 * use the RT_SUCCESS_NP() and RT_FAILURE_NP() macros instead.
1593 *
1594 *
1595 * @returns the boolean result of the expression.
1596 * @param expr The expression that's very likely to be true.
1597 * @see RT_UNLIKELY
1598 */
1599/** @def RT_UNLIKELY
1600 * Give the compiler a hint that an expression is highly unlikely to hold true.
1601 *
1602 * See the usage instructions give in the RT_LIKELY() docs.
1603 *
1604 * @returns the boolean result of the expression.
1605 * @param expr The expression that's very unlikely to be true.
1606 * @see RT_LIKELY
1607 *
1608 * @deprecated Please use RT_LIKELY() instead wherever possible! That gives us
1609 * a better chance of the windows compilers to generate favorable code
1610 * too. The belief is that the compiler will by default assume the
1611 * if-case is more likely than the else-case.
1612 */
1613#if defined(__GNUC__)
1614# if __GNUC__ >= 3 && !defined(FORTIFY_RUNNING)
1615# define RT_LIKELY(expr) __builtin_expect(!!(expr), 1)
1616# define RT_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
1617# else
1618# define RT_LIKELY(expr) (expr)
1619# define RT_UNLIKELY(expr) (expr)
1620# endif
1621#else
1622# define RT_LIKELY(expr) (expr)
1623# define RT_UNLIKELY(expr) (expr)
1624#endif
1625
1626/** @def RT_EXPAND_2
1627 * Helper for RT_EXPAND. */
1628#define RT_EXPAND_2(a_Expr) a_Expr
1629/** @def RT_EXPAND
1630 * Returns the expanded expression.
1631 * @param a_Expr The expression to expand. */
1632#define RT_EXPAND(a_Expr) RT_EXPAND_2(a_Expr)
1633
1634/** @def RT_STR
1635 * Returns the argument as a string constant.
1636 * @param str Argument to stringify. */
1637#define RT_STR(str) #str
1638/** @def RT_XSTR
1639 * Returns the expanded argument as a string.
1640 * @param str Argument to expand and stringify. */
1641#define RT_XSTR(str) RT_STR(str)
1642
1643/** @def RT_LSTR_2
1644 * Helper for RT_WSTR that gets the expanded @a str.
1645 * @param str String litteral to prefix with 'L'. */
1646#define RT_LSTR_2(str) L##str
1647/** @def RT_LSTR
1648 * Returns the expanded argument with a L string prefix.
1649 *
1650 * Intended for converting ASCII string \#defines into wide char string
1651 * litterals on Windows.
1652 *
1653 * @param str String litteral to . */
1654#define RT_LSTR(str) RT_LSTR_2(str)
1655
1656/** @def RT_UNPACK_CALL
1657 * Unpacks the an argument list inside an extra set of parenthesis and turns it
1658 * into a call to @a a_Fn.
1659 *
1660 * @param a_Fn Function/macro to call.
1661 * @param a_Args Parameter list in parenthesis.
1662 */
1663#define RT_UNPACK_CALL(a_Fn, a_Args) a_Fn a_Args
1664
1665#if defined(RT_COMPILER_SUPPORTS_VA_ARGS) || defined(DOXYGEN_RUNNING)
1666
1667/** @def RT_UNPACK_ARGS
1668 * Returns the arguments without parenthesis.
1669 *
1670 * @param ... Parameter list in parenthesis.
1671 * @remarks Requires RT_COMPILER_SUPPORTS_VA_ARGS.
1672 */
1673# define RT_UNPACK_ARGS(...) __VA_ARGS__
1674
1675/** @def RT_COUNT_VA_ARGS_HLP
1676 * Helper for RT_COUNT_VA_ARGS that picks out the argument count from
1677 * RT_COUNT_VA_ARGS_REV_SEQ. */
1678# define RT_COUNT_VA_ARGS_HLP( \
1679 c69, c68, c67, c66, c65, c64, c63, c62, c61, c60, \
1680 c59, c58, c57, c56, c55, c54, c53, c52, c51, c50, \
1681 c49, c48, c47, c46, c45, c44, c43, c42, c41, c40, \
1682 c39, c38, c37, c36, c35, c34, c33, c32, c31, c30, \
1683 c29, c28, c27, c26, c25, c24, c23, c22, c21, c20, \
1684 c19, c18, c17, c16, c15, c14, c13, c12, c11, c10, \
1685 c9, c8, c7, c6, c5, c4, c3, c2, c1, cArgs, ...) cArgs
1686/** Argument count sequence. */
1687# define RT_COUNT_VA_ARGS_REV_SEQ \
1688 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, \
1689 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, \
1690 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, \
1691 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, \
1692 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, \
1693 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, \
1694 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
1695/** This is for zero arguments. At least Visual C++ requires it. */
1696# define RT_COUNT_VA_ARGS_PREFIX_RT_NOTHING RT_COUNT_VA_ARGS_REV_SEQ
1697/**
1698 * Counts the number of arguments given to the variadic macro.
1699 *
1700 * Max is 69.
1701 *
1702 * @returns Number of arguments in the ellipsis
1703 * @param ... Arguments to count.
1704 * @remarks Requires RT_COMPILER_SUPPORTS_VA_ARGS.
1705 */
1706# define RT_COUNT_VA_ARGS(...) \
1707 RT_UNPACK_CALL(RT_COUNT_VA_ARGS_HLP, (RT_COUNT_VA_ARGS_PREFIX_ ## __VA_ARGS__ ## RT_NOTHING, \
1708 RT_COUNT_VA_ARGS_REV_SEQ))
1709
1710#endif /* RT_COMPILER_SUPPORTS_VA_ARGS */
1711
1712
1713/** @def RT_CONCAT
1714 * Concatenate the expanded arguments without any extra spaces in between.
1715 *
1716 * @param a The first part.
1717 * @param b The second part.
1718 */
1719#define RT_CONCAT(a,b) RT_CONCAT_HLP(a,b)
1720/** RT_CONCAT helper, don't use. */
1721#define RT_CONCAT_HLP(a,b) a##b
1722
1723/** @def RT_CONCAT3
1724 * Concatenate the expanded arguments without any extra spaces in between.
1725 *
1726 * @param a The 1st part.
1727 * @param b The 2nd part.
1728 * @param c The 3rd part.
1729 */
1730#define RT_CONCAT3(a,b,c) RT_CONCAT3_HLP(a,b,c)
1731/** RT_CONCAT3 helper, don't use. */
1732#define RT_CONCAT3_HLP(a,b,c) a##b##c
1733
1734/** @def RT_CONCAT4
1735 * Concatenate the expanded arguments without any extra spaces in between.
1736 *
1737 * @param a The 1st part.
1738 * @param b The 2nd part.
1739 * @param c The 3rd part.
1740 * @param d The 4th part.
1741 */
1742#define RT_CONCAT4(a,b,c,d) RT_CONCAT4_HLP(a,b,c,d)
1743/** RT_CONCAT4 helper, don't use. */
1744#define RT_CONCAT4_HLP(a,b,c,d) a##b##c##d
1745
1746/** @def RT_CONCAT5
1747 * Concatenate the expanded arguments without any extra spaces in between.
1748 *
1749 * @param a The 1st part.
1750 * @param b The 2nd part.
1751 * @param c The 3rd part.
1752 * @param d The 4th part.
1753 * @param e The 5th part.
1754 */
1755#define RT_CONCAT5(a,b,c,d,e) RT_CONCAT5_HLP(a,b,c,d,e)
1756/** RT_CONCAT5 helper, don't use. */
1757#define RT_CONCAT5_HLP(a,b,c,d,e) a##b##c##d##e
1758
1759/** @def RT_CONCAT6
1760 * Concatenate the expanded arguments without any extra spaces in between.
1761 *
1762 * @param a The 1st part.
1763 * @param b The 2nd part.
1764 * @param c The 3rd part.
1765 * @param d The 4th part.
1766 * @param e The 5th part.
1767 * @param f The 6th part.
1768 */
1769#define RT_CONCAT6(a,b,c,d,e,f) RT_CONCAT6_HLP(a,b,c,d,e,f)
1770/** RT_CONCAT6 helper, don't use. */
1771#define RT_CONCAT6_HLP(a,b,c,d,e,f) a##b##c##d##e##f
1772
1773/** @def RT_CONCAT7
1774 * Concatenate the expanded arguments without any extra spaces in between.
1775 *
1776 * @param a The 1st part.
1777 * @param b The 2nd part.
1778 * @param c The 3rd part.
1779 * @param d The 4th part.
1780 * @param e The 5th part.
1781 * @param f The 6th part.
1782 * @param g The 7th part.
1783 */
1784#define RT_CONCAT7(a,b,c,d,e,f,g) RT_CONCAT7_HLP(a,b,c,d,e,f,g)
1785/** RT_CONCAT7 helper, don't use. */
1786#define RT_CONCAT7_HLP(a,b,c,d,e,f,g) a##b##c##d##e##f##g
1787
1788/** @def RT_CONCAT8
1789 * Concatenate the expanded arguments without any extra spaces in between.
1790 *
1791 * @param a The 1st part.
1792 * @param b The 2nd part.
1793 * @param c The 3rd part.
1794 * @param d The 4th part.
1795 * @param e The 5th part.
1796 * @param f The 6th part.
1797 * @param g The 7th part.
1798 * @param h The 8th part.
1799 */
1800#define RT_CONCAT8(a,b,c,d,e,f,g,h) RT_CONCAT8_HLP(a,b,c,d,e,f,g,h)
1801/** RT_CONCAT8 helper, don't use. */
1802#define RT_CONCAT8_HLP(a,b,c,d,e,f,g,h) a##b##c##d##e##f##g##h
1803
1804/** @def RT_CONCAT9
1805 * Concatenate the expanded arguments without any extra spaces in between.
1806 *
1807 * @param a The 1st part.
1808 * @param b The 2nd part.
1809 * @param c The 3rd part.
1810 * @param d The 4th part.
1811 * @param e The 5th part.
1812 * @param f The 6th part.
1813 * @param g The 7th part.
1814 * @param h The 8th part.
1815 * @param i The 9th part.
1816 */
1817#define RT_CONCAT9(a,b,c,d,e,f,g,h,i) RT_CONCAT9_HLP(a,b,c,d,e,f,g,h,i)
1818/** RT_CONCAT9 helper, don't use. */
1819#define RT_CONCAT9_HLP(a,b,c,d,e,f,g,h,i) a##b##c##d##e##f##g##h##i
1820
1821/**
1822 * String constant tuple - string constant, strlen(string constant).
1823 *
1824 * @param a_szConst String constant.
1825 * @sa RTSTRTUPLE
1826 */
1827#define RT_STR_TUPLE(a_szConst) a_szConst, (sizeof(a_szConst) - 1)
1828
1829
1830/**
1831 * Macro for using in switch statements that turns constants into strings.
1832 *
1833 * @param a_Const The constant (not string).
1834 */
1835#define RT_CASE_RET_STR(a_Const) case a_Const: return #a_Const
1836
1837
1838/** @def RT_BIT
1839 * Convert a bit number into an integer bitmask (unsigned).
1840 * @param bit The bit number.
1841 */
1842#define RT_BIT(bit) ( 1U << (bit) )
1843
1844/** @def RT_BIT_32
1845 * Convert a bit number into a 32-bit bitmask (unsigned).
1846 * @param bit The bit number.
1847 */
1848#define RT_BIT_32(bit) ( UINT32_C(1) << (bit) )
1849
1850/** @def RT_BIT_64
1851 * Convert a bit number into a 64-bit bitmask (unsigned).
1852 * @param bit The bit number.
1853 */
1854#define RT_BIT_64(bit) ( UINT64_C(1) << (bit) )
1855
1856
1857/** @def RT_BF_GET
1858 * Gets the value of a bit field in an integer value.
1859 *
1860 * This requires a couple of macros to be defined for the field:
1861 * - \<a_FieldNm\>_SHIFT: The shift count to get to the field.
1862 * - \<a_FieldNm\>_MASK: The field mask.
1863 *
1864 * @returns The bit field value.
1865 * @param a_uValue The integer value containing the field.
1866 * @param a_FieldNm The field name prefix for getting at the _SHIFT and
1867 * _MASK macros.
1868 * @sa #RT_BF_CLEAR, #RT_BF_SET, #RT_BF_MAKE, #RT_BF_ZMASK
1869 */
1870#define RT_BF_GET(a_uValue, a_FieldNm) ( ((a_uValue) >> RT_CONCAT(a_FieldNm,_SHIFT)) & RT_BF_ZMASK(a_FieldNm) )
1871
1872/** @def RT_BF_SET
1873 * Sets the given bit field in the integer value.
1874 *
1875 * This requires a couple of macros to be defined for the field:
1876 * - \<a_FieldNm\>_SHIFT: The shift count to get to the field.
1877 * - \<a_FieldNm\>_MASK: The field mask. Must have the same type as the
1878 * integer value!!
1879 *
1880 * @returns Integer value with bit field set to @a a_uFieldValue.
1881 * @param a_uValue The integer value containing the field.
1882 * @param a_FieldNm The field name prefix for getting at the _SHIFT and
1883 * _MASK macros.
1884 * @param a_uFieldValue The new field value.
1885 * @sa #RT_BF_GET, #RT_BF_CLEAR, #RT_BF_MAKE, #RT_BF_ZMASK
1886 */
1887#define RT_BF_SET(a_uValue, a_FieldNm, a_uFieldValue) ( RT_BF_CLEAR(a_uValue, a_FieldNm) | RT_BF_MAKE(a_FieldNm, a_uFieldValue) )
1888
1889/** @def RT_BF_CLEAR
1890 * Clears the given bit field in the integer value.
1891 *
1892 * This requires a couple of macros to be defined for the field:
1893 * - \<a_FieldNm\>_SHIFT: The shift count to get to the field.
1894 * - \<a_FieldNm\>_MASK: The field mask. Must have the same type as the
1895 * integer value!!
1896 *
1897 * @returns Integer value with bit field set to zero.
1898 * @param a_uValue The integer value containing the field.
1899 * @param a_FieldNm The field name prefix for getting at the _SHIFT and
1900 * _MASK macros.
1901 * @sa #RT_BF_GET, #RT_BF_SET, #RT_BF_MAKE, #RT_BF_ZMASK
1902 */
1903#define RT_BF_CLEAR(a_uValue, a_FieldNm) ( (a_uValue) & ~RT_CONCAT(a_FieldNm,_MASK) )
1904
1905/** @def RT_BF_MAKE
1906 * Shifts and masks a bit field value into position in the integer value.
1907 *
1908 * This requires a couple of macros to be defined for the field:
1909 * - \<a_FieldNm\>_SHIFT: The shift count to get to the field.
1910 * - \<a_FieldNm\>_MASK: The field mask.
1911 *
1912 * @param a_FieldNm The field name prefix for getting at the _SHIFT and
1913 * _MASK macros.
1914 * @param a_uFieldValue The field value that should be masked and shifted
1915 * into position.
1916 * @sa #RT_BF_GET, #RT_BF_SET, #RT_BF_CLEAR, #RT_BF_ZMASK
1917 */
1918#define RT_BF_MAKE(a_FieldNm, a_uFieldValue) ( ((a_uFieldValue) & RT_BF_ZMASK(a_FieldNm) ) << RT_CONCAT(a_FieldNm,_SHIFT) )
1919
1920/** @def RT_BF_ZMASK
1921 * Helper for getting the field mask shifted to bit position zero.
1922 *
1923 * @param a_FieldNm The field name prefix for getting at the _SHIFT and
1924 * _MASK macros.
1925 * @sa #RT_BF_GET, #RT_BF_SET, #RT_BF_CLEAR, #RT_BF_MAKE
1926 */
1927#define RT_BF_ZMASK(a_FieldNm) ( RT_CONCAT(a_FieldNm,_MASK) >> RT_CONCAT(a_FieldNm,_SHIFT) )
1928
1929/** Bit field compile time check helper
1930 * @internal */
1931#define RT_BF_CHECK_DO_XOR_MASK(a_uLeft, a_RightPrefix, a_FieldNm) ((a_uLeft) ^ RT_CONCAT3(a_RightPrefix, a_FieldNm, _MASK))
1932/** Bit field compile time check helper
1933 * @internal */
1934#define RT_BF_CHECK_DO_OR_MASK(a_uLeft, a_RightPrefix, a_FieldNm) ((a_uLeft) | RT_CONCAT3(a_RightPrefix, a_FieldNm, _MASK))
1935/** Bit field compile time check helper
1936 * @internal */
1937#define RT_BF_CHECK_DO_1ST_MASK_BIT(a_uLeft, a_RightPrefix, a_FieldNm) \
1938 ((a_uLeft) && ( (RT_CONCAT3(a_RightPrefix, a_FieldNm, _MASK) >> RT_CONCAT3(a_RightPrefix, a_FieldNm, _SHIFT)) & 1U ) )
1939/** Used to check that a bit field mask does not start too early.
1940 * @internal */
1941#define RT_BF_CHECK_DO_MASK_START(a_uLeft, a_RightPrefix, a_FieldNm) \
1942 ( (a_uLeft) \
1943 && ( RT_CONCAT3(a_RightPrefix, a_FieldNm, _SHIFT) == 0 \
1944 || ( ( ( ((RT_CONCAT3(a_RightPrefix, a_FieldNm, _MASK) >> RT_CONCAT3(a_RightPrefix, a_FieldNm, _SHIFT)) & 1U) \
1945 << RT_CONCAT3(a_RightPrefix, a_FieldNm, _SHIFT)) /* => single bit mask, correct type */ \
1946 - 1U) /* => mask of all bits below the field */ \
1947 & RT_CONCAT3(a_RightPrefix, a_FieldNm, _MASK)) == 0 ) )
1948/** @name Bit field compile time check recursion workers.
1949 * @internal
1950 * @{ */
1951#define RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix, f1) \
1952 a_DoThis(a_uLeft, a_RightPrefix, f1)
1953#define RT_BF_CHECK_DO_2(a_DoThis, a_uLeft, a_RightPrefix, f1, f2) \
1954 RT_BF_CHECK_DO_1(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2)
1955#define RT_BF_CHECK_DO_3(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3) \
1956 RT_BF_CHECK_DO_2(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3)
1957#define RT_BF_CHECK_DO_4(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4) \
1958 RT_BF_CHECK_DO_3(a_DoThis, RT_BF_CHECK_DO_1(a_DoThis, a_uLeft, a_RightPrefix,f1), a_RightPrefix, f2, f3, f4)
1959#define RT_BF_CHECK_DO_5(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5) \
1960 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)
1961#define RT_BF_CHECK_DO_6(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6) \
1962 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)
1963#define RT_BF_CHECK_DO_7(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7) \
1964 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)
1965#define RT_BF_CHECK_DO_8(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8) \
1966 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)
1967#define RT_BF_CHECK_DO_9(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9) \
1968 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)
1969#define RT_BF_CHECK_DO_10(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10) \
1970 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)
1971#define RT_BF_CHECK_DO_11(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11) \
1972 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)
1973#define RT_BF_CHECK_DO_12(a_DoThis, a_uLeft, a_RightPrefix, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12) \
1974 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)
1975#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) \
1976 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)
1977#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) \
1978 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)
1979#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) \
1980 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)
1981#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) \
1982 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)
1983#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) \
1984 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)
1985#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) \
1986 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)
1987#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) \
1988 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)
1989#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) \
1990 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)
1991#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) \
1992 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)
1993#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) \
1994 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)
1995#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) \
1996 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)
1997#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) \
1998 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)
1999#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) \
2000 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)
2001#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) \
2002 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)
2003#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) \
2004 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)
2005#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) \
2006 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)
2007#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) \
2008 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)
2009#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) \
2010 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)
2011#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) \
2012 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)
2013#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) \
2014 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)
2015#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) \
2016 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)
2017#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) \
2018 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)
2019#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) \
2020 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)
2021#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) \
2022 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)
2023#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) \
2024 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)
2025#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) \
2026 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)
2027#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) \
2028 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)
2029#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) \
2030 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)
2031#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) \
2032 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)
2033#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) \
2034 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)
2035#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) \
2036 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)
2037#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) \
2038 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)
2039#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) \
2040 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)
2041#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) \
2042 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)
2043#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) \
2044 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)
2045#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) \
2046 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)
2047#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) \
2048 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)
2049#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) \
2050 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)
2051#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) \
2052 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)
2053#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) \
2054 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)
2055#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) \
2056 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)
2057#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) \
2058 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)
2059#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) \
2060 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)
2061#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) \
2062 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)
2063#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) \
2064 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)
2065#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) \
2066 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)
2067#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) \
2068 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)
2069#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) \
2070 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)
2071#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) \
2072 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)
2073#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) \
2074 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)
2075#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) \
2076 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)
2077#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) \
2078 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)
2079/** @} */
2080
2081/** @def RT_BF_ASSERT_COMPILE_CHECKS
2082 * Emits a series of AssertCompile statements checking that the bit-field
2083 * declarations doesn't overlap, has holes, and generally makes some sense.
2084 *
2085 * This requires variadic macros because its too much to type otherwise.
2086 */
2087#if defined(RT_COMPILER_SUPPORTS_VA_ARGS) || defined(DOXYGEN_RUNNING)
2088# define RT_BF_ASSERT_COMPILE_CHECKS(a_Prefix, a_uZero, a_uCovered, a_Fields) \
2089 AssertCompile(RT_BF_CHECK_DO_N(RT_BF_CHECK_DO_OR_MASK, a_uZero, a_Prefix, RT_UNPACK_ARGS a_Fields ) == a_uCovered); \
2090 AssertCompile(RT_BF_CHECK_DO_N(RT_BF_CHECK_DO_XOR_MASK, a_uCovered, a_Prefix, RT_UNPACK_ARGS a_Fields ) == 0); \
2091 AssertCompile(RT_BF_CHECK_DO_N(RT_BF_CHECK_DO_1ST_MASK_BIT, true, a_Prefix, RT_UNPACK_ARGS a_Fields ) == true); \
2092 AssertCompile(RT_BF_CHECK_DO_N(RT_BF_CHECK_DO_MASK_START, true, a_Prefix, RT_UNPACK_ARGS a_Fields ) == true)
2093/** Bit field compile time check helper
2094 * @internal */
2095# define RT_BF_CHECK_DO_N(a_DoThis, a_uLeft, a_RightPrefix, ...) \
2096 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__))
2097#else
2098# define RT_BF_ASSERT_COMPILE_CHECKS(a_Prefix, a_uZero, a_uCovered, a_Fields) AssertCompile(true)
2099#endif
2100
2101
2102/** @def RT_ALIGN
2103 * Align macro.
2104 * @param u Value to align.
2105 * @param uAlignment The alignment. Power of two!
2106 *
2107 * @remark Be extremely careful when using this macro with type which sizeof != sizeof int.
2108 * When possible use any of the other RT_ALIGN_* macros. And when that's not
2109 * possible, make 101% sure that uAlignment is specified with a right sized type.
2110 *
2111 * Specifying an unsigned 32-bit alignment constant with a 64-bit value will give
2112 * you a 32-bit return value!
2113 *
2114 * In short: Don't use this macro. Use RT_ALIGN_T() instead.
2115 */
2116#define RT_ALIGN(u, uAlignment) ( ((u) + ((uAlignment) - 1)) & ~((uAlignment) - 1) )
2117
2118/** @def RT_ALIGN_T
2119 * Align macro.
2120 * @param u Value to align.
2121 * @param uAlignment The alignment. Power of two!
2122 * @param type Integer type to use while aligning.
2123 * @remark This macro is the preferred alignment macro, it doesn't have any of the pitfalls RT_ALIGN has.
2124 */
2125#define RT_ALIGN_T(u, uAlignment, type) ( ((type)(u) + ((uAlignment) - 1)) & ~(type)((uAlignment) - 1) )
2126
2127/** @def RT_ALIGN_32
2128 * Align macro for a 32-bit value.
2129 * @param u32 Value to align.
2130 * @param uAlignment The alignment. Power of two!
2131 */
2132#define RT_ALIGN_32(u32, uAlignment) RT_ALIGN_T(u32, uAlignment, uint32_t)
2133
2134/** @def RT_ALIGN_64
2135 * Align macro for a 64-bit value.
2136 * @param u64 Value to align.
2137 * @param uAlignment The alignment. Power of two!
2138 */
2139#define RT_ALIGN_64(u64, uAlignment) RT_ALIGN_T(u64, uAlignment, uint64_t)
2140
2141/** @def RT_ALIGN_Z
2142 * Align macro for size_t.
2143 * @param cb Value to align.
2144 * @param uAlignment The alignment. Power of two!
2145 */
2146#define RT_ALIGN_Z(cb, uAlignment) RT_ALIGN_T(cb, uAlignment, size_t)
2147
2148/** @def RT_ALIGN_P
2149 * Align macro for pointers.
2150 * @param pv Value to align.
2151 * @param uAlignment The alignment. Power of two!
2152 */
2153#define RT_ALIGN_P(pv, uAlignment) RT_ALIGN_PT(pv, uAlignment, void *)
2154
2155/** @def RT_ALIGN_PT
2156 * Align macro for pointers with type cast.
2157 * @param u Value to align.
2158 * @param uAlignment The alignment. Power of two!
2159 * @param CastType The type to cast the result to.
2160 */
2161#define RT_ALIGN_PT(u, uAlignment, CastType) ( (CastType)RT_ALIGN_T(u, uAlignment, uintptr_t) )
2162
2163/** @def RT_ALIGN_R3PT
2164 * Align macro for ring-3 pointers with type cast.
2165 * @param u Value to align.
2166 * @param uAlignment The alignment. Power of two!
2167 * @param CastType The type to cast the result to.
2168 */
2169#define RT_ALIGN_R3PT(u, uAlignment, CastType) ( (CastType)RT_ALIGN_T(u, uAlignment, RTR3UINTPTR) )
2170
2171/** @def RT_ALIGN_R0PT
2172 * Align macro for ring-0 pointers with type cast.
2173 * @param u Value to align.
2174 * @param uAlignment The alignment. Power of two!
2175 * @param CastType The type to cast the result to.
2176 */
2177#define RT_ALIGN_R0PT(u, uAlignment, CastType) ( (CastType)RT_ALIGN_T(u, uAlignment, RTR0UINTPTR) )
2178
2179/** @def RT_ALIGN_GCPT
2180 * Align macro for GC pointers with type cast.
2181 * @param u Value to align.
2182 * @param uAlignment The alignment. Power of two!
2183 * @param CastType The type to cast the result to.
2184 */
2185#define RT_ALIGN_GCPT(u, uAlignment, CastType) ( (CastType)RT_ALIGN_T(u, uAlignment, RTGCUINTPTR) )
2186
2187
2188/** @def RT_OFFSETOF
2189 * Our own special offsetof() variant, returns a signed result.
2190 *
2191 * This differs from the usual offsetof() in that it's not relying on builtin
2192 * compiler stuff and thus can use variables in arrays the structure may
2193 * contain. This is useful to determine the sizes of structures ending
2194 * with a variable length field. For gcc >= 4.4 see @bugref{7775}.
2195 *
2196 * @returns offset into the structure of the specified member. signed.
2197 * @param type Structure type.
2198 * @param member Member.
2199 */
2200#if defined(__cplusplus) && RT_GNUC_PREREQ(4, 4)
2201# define RT_OFFSETOF(type, member) ( (int)(uintptr_t)&( ((type *)(void *)0x1000)->member) - 0x1000 )
2202#else
2203# define RT_OFFSETOF(type, member) ( (int)(uintptr_t)&( ((type *)(void *)0)->member) )
2204#endif
2205
2206/** @def RT_UOFFSETOF
2207 * Our own special offsetof() variant, returns an unsigned result.
2208 *
2209 * This differs from the usual offsetof() in that it's not relying on builtin
2210 * compiler stuff and thus can use variables in arrays the structure may
2211 * contain. This is useful to determine the sizes of structures ending
2212 * with a variable length field. For gcc >= 4.4 see @bugref{7775}.
2213 *
2214 * @returns offset into the structure of the specified member. unsigned.
2215 * @param type Structure type.
2216 * @param member Member.
2217 */
2218#if defined(__cplusplus) && RT_GNUC_PREREQ(4, 4)
2219# define RT_UOFFSETOF(type, member) ( (uintptr_t)&( ((type *)(void *)0x1000)->member) - 0x1000 )
2220#else
2221# define RT_UOFFSETOF(type, member) ( (uintptr_t)&( ((type *)(void *)0)->member) )
2222#endif
2223
2224/** @def RT_OFFSETOF_ADD
2225 * RT_OFFSETOF with an addend.
2226 *
2227 * @returns offset into the structure of the specified member. signed.
2228 * @param type Structure type.
2229 * @param member Member.
2230 * @param addend The addend to add to the offset.
2231 */
2232#define RT_OFFSETOF_ADD(type, member, addend) ( (int)RT_UOFFSETOF_ADD(type, member, addend) )
2233
2234/** @def RT_UOFFSETOF_ADD
2235 * RT_UOFFSETOF with an addend.
2236 *
2237 * @returns offset into the structure of the specified member. signed.
2238 * @param type Structure type.
2239 * @param member Member.
2240 * @param addend The addend to add to the offset.
2241 */
2242#define RT_UOFFSETOF_ADD(type, member, addend) ( (uintptr_t)&( ((type *)(void *)(uintptr_t)(addend))->member) )
2243
2244/** @def RT_SIZEOFMEMB
2245 * Get the size of a structure member.
2246 *
2247 * @returns size of the structure member.
2248 * @param type Structure type.
2249 * @param member Member.
2250 */
2251#define RT_SIZEOFMEMB(type, member) ( sizeof(((type *)(void *)0)->member) )
2252
2253/** @def RT_UOFFSET_AFTER
2254 * Returns the offset of the first byte following a structure/union member.
2255 *
2256 * @return byte offset into the struct.
2257 * @param a_Type Structure type.
2258 * @param a_Member The member name.
2259 */
2260#define RT_UOFFSET_AFTER(a_Type, a_Member) ( RT_UOFFSETOF(a_Type, a_Member) + RT_SIZEOFMEMB(a_Type, a_Member) )
2261
2262/** @def RT_FROM_MEMBER
2263 * Convert a pointer to a structure member into a pointer to the structure.
2264 *
2265 * @returns pointer to the structure.
2266 * @param pMem Pointer to the member.
2267 * @param Type Structure type.
2268 * @param Member Member name.
2269 */
2270#define RT_FROM_MEMBER(pMem, Type, Member) ( (Type *) ((uint8_t *)(void *)(pMem) - RT_UOFFSETOF(Type, Member)) )
2271
2272/** @def RT_FROM_CPP_MEMBER
2273 * Same as RT_FROM_MEMBER except it avoids the annoying g++ warnings about
2274 * invalid access to non-static data member of NULL object.
2275 *
2276 * @returns pointer to the structure.
2277 * @param pMem Pointer to the member.
2278 * @param Type Structure type.
2279 * @param Member Member name.
2280 *
2281 * @remarks Using the __builtin_offsetof does not shut up the compiler.
2282 */
2283#if defined(__GNUC__) && defined(__cplusplus)
2284# define RT_FROM_CPP_MEMBER(pMem, Type, Member) \
2285 ( (Type *) ((uintptr_t)(pMem) - (uintptr_t)&((Type *)0x1000)->Member + 0x1000U) )
2286#else
2287# define RT_FROM_CPP_MEMBER(pMem, Type, Member) RT_FROM_MEMBER(pMem, Type, Member)
2288#endif
2289
2290/** @def RT_ELEMENTS
2291 * Calculates the number of elements in a statically sized array.
2292 * @returns Element count.
2293 * @param aArray Array in question.
2294 */
2295#define RT_ELEMENTS(aArray) ( sizeof(aArray) / sizeof((aArray)[0]) )
2296
2297/** @def RT_FLEXIBLE_ARRAY
2298 * What to up inside the square brackets when declaring a structure member
2299 * with a flexible size.
2300 *
2301 * @note Use RT_UOFFSETOF() to calculate the structure size.
2302 *
2303 * @note Never to a sizeof() on the structure or member!
2304 *
2305 * @note The member must be the last one.
2306 *
2307 * @note GCC does not permit using this in a union. So, for unions you must
2308 * use RT_FLEXIBLE_ARRAY_IN_UNION instead.
2309 *
2310 * @note GCC does not permit using this in nested structures, where as MSC
2311 * does. So, use RT_FLEXIBLE_ARRAY_NESTED for that.
2312 *
2313 * @sa RT_FLEXIBLE_ARRAY_NESTED, RT_FLEXIBLE_ARRAY_IN_UNION
2314 */
2315#if RT_MSC_PREREQ(RT_MSC_VER_VS2005) /** @todo Probably much much earlier. */ \
2316 || (defined(__cplusplus) && RT_GNUC_PREREQ(6, 1) && !RT_GNUC_PREREQ(7, 0)) /* gcc-7 warns again */\
2317 || defined(__WATCOMC__) /* openwatcom 1.9 supports it, we don't care about older atm. */ \
2318 || RT_CLANG_PREREQ_EX(3, 4, 0) /* Only tested clang v3.4, support is probably older. */
2319# define RT_FLEXIBLE_ARRAY
2320# if defined(__cplusplus) && defined(_MSC_VER)
2321# pragma warning(disable:4200) /* -wd4200 does not work with VS2010 */
2322# endif
2323#elif defined(__STDC_VERSION__)
2324# if __STDC_VERSION__ >= 1999901L
2325# define RT_FLEXIBLE_ARRAY
2326# else
2327# define RT_FLEXIBLE_ARRAY 1
2328# endif
2329#else
2330# define RT_FLEXIBLE_ARRAY 1
2331#endif
2332
2333/** @def RT_FLEXIBLE_ARRAY_NESTED
2334 * Variant of RT_FLEXIBLE_ARRAY for use in structures that are nested.
2335 *
2336 * GCC only allow the use of flexible array member in the top structure, whereas
2337 * MSC is less strict and let you do struct { struct { char szName[]; } s; };
2338 *
2339 * @note See notes for RT_FLEXIBLE_ARRAY.
2340 *
2341 * @note GCC does not permit using this in a union. So, for unions you must
2342 * use RT_FLEXIBLE_ARRAY_IN_NESTED_UNION instead.
2343 *
2344 * @sa RT_FLEXIBLE_ARRAY, RT_FLEXIBLE_ARRAY_IN_NESTED_UNION
2345 */
2346#ifdef _MSC_VER
2347# define RT_FLEXIBLE_ARRAY_NESTED RT_FLEXIBLE_ARRAY
2348#else
2349# define RT_FLEXIBLE_ARRAY_NESTED 1
2350#endif
2351
2352/** @def RT_FLEXIBLE_ARRAY_IN_UNION
2353 * The union version of RT_FLEXIBLE_ARRAY.
2354 *
2355 * @remarks GCC does not support flexible array members in unions, 6.1.x
2356 * actively checks for this. Visual C++ 2010 seems happy with it.
2357 *
2358 * @note See notes for RT_FLEXIBLE_ARRAY.
2359 *
2360 * @sa RT_FLEXIBLE_ARRAY, RT_FLEXIBLE_ARRAY_IN_NESTED_UNION
2361 */
2362#ifdef _MSC_VER
2363# define RT_FLEXIBLE_ARRAY_IN_UNION RT_FLEXIBLE_ARRAY
2364#else
2365# define RT_FLEXIBLE_ARRAY_IN_UNION 1
2366#endif
2367
2368/** @def RT_FLEXIBLE_ARRAY_IN_NESTED_UNION
2369 * The union version of RT_FLEXIBLE_ARRAY_NESTED.
2370 *
2371 * @note See notes for RT_FLEXIBLE_ARRAY.
2372 *
2373 * @sa RT_FLEXIBLE_ARRAY, RT_FLEXIBLE_ARRAY_IN_NESTED_UNION
2374 */
2375#ifdef _MSC_VER
2376# define RT_FLEXIBLE_ARRAY_IN_NESTED_UNION RT_FLEXIBLE_ARRAY_NESTED
2377#else
2378# define RT_FLEXIBLE_ARRAY_IN_NESTED_UNION 1
2379#endif
2380
2381/**
2382 * Checks if the value is a power of two.
2383 *
2384 * @returns true if power of two, false if not.
2385 * @param uVal The value to test.
2386 * @remarks 0 is a power of two.
2387 * @see VERR_NOT_POWER_OF_TWO
2388 */
2389#define RT_IS_POWER_OF_TWO(uVal) ( ((uVal) & ((uVal) - 1)) == 0)
2390
2391#ifdef RT_OS_OS2
2392/* Undefine RT_MAX since there is an unfortunate clash with the max
2393 resource type define in os2.h. */
2394# undef RT_MAX
2395#endif
2396
2397/** @def RT_MAX
2398 * Finds the maximum value.
2399 * @returns The higher of the two.
2400 * @param Value1 Value 1
2401 * @param Value2 Value 2
2402 */
2403#define RT_MAX(Value1, Value2) ( (Value1) >= (Value2) ? (Value1) : (Value2) )
2404
2405/** @def RT_MIN
2406 * Finds the minimum value.
2407 * @returns The lower of the two.
2408 * @param Value1 Value 1
2409 * @param Value2 Value 2
2410 */
2411#define RT_MIN(Value1, Value2) ( (Value1) <= (Value2) ? (Value1) : (Value2) )
2412
2413/** @def RT_CLAMP
2414 * Clamps the value to minimum and maximum values.
2415 * @returns The clamped value.
2416 * @param Value The value to check.
2417 * @param Min Minimum value.
2418 * @param Max Maximum value.
2419 */
2420#define RT_CLAMP(Value, Min, Max) ( (Value) > (Max) ? (Max) : (Value) < (Min) ? (Min) : (Value) )
2421
2422/** @def RT_ABS
2423 * Get the absolute (non-negative) value.
2424 * @returns The absolute value of Value.
2425 * @param Value The value.
2426 */
2427#define RT_ABS(Value) ( (Value) >= 0 ? (Value) : -(Value) )
2428
2429/** @def RT_BOOL
2430 * Turn non-zero/zero into true/false
2431 * @returns The resulting boolean value.
2432 * @param Value The value.
2433 */
2434#define RT_BOOL(Value) ( !!(Value) )
2435
2436/** @def RT_LO_U8
2437 * Gets the low uint8_t of a uint16_t or something equivalent. */
2438#ifdef __GNUC__
2439# define RT_LO_U8(a) __extension__ ({ AssertCompile(sizeof((a)) == sizeof(uint16_t)); (uint8_t)(a); })
2440#elif defined(_MSC_VER) /* shut up cast truncates constant value warnings */
2441# define RT_LO_U8(a) ( (uint8_t)(UINT8_MAX & (a)) )
2442#else
2443# define RT_LO_U8(a) ( (uint8_t)(a) )
2444#endif
2445/** @def RT_HI_U8
2446 * Gets the high uint8_t of a uint16_t or something equivalent. */
2447#ifdef __GNUC__
2448# define RT_HI_U8(a) __extension__ ({ AssertCompile(sizeof((a)) == sizeof(uint16_t)); (uint8_t)((a) >> 8); })
2449#else
2450# define RT_HI_U8(a) ( (uint8_t)((a) >> 8) )
2451#endif
2452
2453/** @def RT_LO_U16
2454 * Gets the low uint16_t of a uint32_t or something equivalent. */
2455#ifdef __GNUC__
2456# define RT_LO_U16(a) __extension__ ({ AssertCompile(sizeof((a)) == sizeof(uint32_t)); (uint16_t)(a); })
2457#elif defined(_MSC_VER) /* shut up cast truncates constant value warnings */
2458# define RT_LO_U16(a) ( (uint16_t)(UINT16_MAX & (a)) )
2459#else
2460# define RT_LO_U16(a) ( (uint16_t)(a) )
2461#endif
2462/** @def RT_HI_U16
2463 * Gets the high uint16_t of a uint32_t or something equivalent. */
2464#ifdef __GNUC__
2465# define RT_HI_U16(a) __extension__ ({ AssertCompile(sizeof((a)) == sizeof(uint32_t)); (uint16_t)((a) >> 16); })
2466#else
2467# define RT_HI_U16(a) ( (uint16_t)((a) >> 16) )
2468#endif
2469
2470/** @def RT_LO_U32
2471 * Gets the low uint32_t of a uint64_t or something equivalent. */
2472#ifdef __GNUC__
2473# define RT_LO_U32(a) __extension__ ({ AssertCompile(sizeof((a)) == sizeof(uint64_t)); (uint32_t)(a); })
2474#elif defined(_MSC_VER) /* shut up cast truncates constant value warnings */
2475# define RT_LO_U32(a) ( (uint32_t)(UINT32_MAX & (a)) )
2476#else
2477# define RT_LO_U32(a) ( (uint32_t)(a) )
2478#endif
2479/** @def RT_HI_U32
2480 * Gets the high uint32_t of a uint64_t or something equivalent. */
2481#ifdef __GNUC__
2482# define RT_HI_U32(a) __extension__ ({ AssertCompile(sizeof((a)) == sizeof(uint64_t)); (uint32_t)((a) >> 32); })
2483#else
2484# define RT_HI_U32(a) ( (uint32_t)((a) >> 32) )
2485#endif
2486
2487/** @def RT_BYTE1
2488 * Gets the first byte of something. */
2489#define RT_BYTE1(a) ( (a) & 0xff )
2490/** @def RT_BYTE2
2491 * Gets the second byte of something. */
2492#define RT_BYTE2(a) ( ((a) >> 8) & 0xff )
2493/** @def RT_BYTE3
2494 * Gets the second byte of something. */
2495#define RT_BYTE3(a) ( ((a) >> 16) & 0xff )
2496/** @def RT_BYTE4
2497 * Gets the fourth byte of something. */
2498#define RT_BYTE4(a) ( ((a) >> 24) & 0xff )
2499/** @def RT_BYTE5
2500 * Gets the fifth byte of something. */
2501#define RT_BYTE5(a) ( ((a) >> 32) & 0xff )
2502/** @def RT_BYTE6
2503 * Gets the sixth byte of something. */
2504#define RT_BYTE6(a) ( ((a) >> 40) & 0xff )
2505/** @def RT_BYTE7
2506 * Gets the seventh byte of something. */
2507#define RT_BYTE7(a) ( ((a) >> 48) & 0xff )
2508/** @def RT_BYTE8
2509 * Gets the eight byte of something. */
2510#define RT_BYTE8(a) ( ((a) >> 56) & 0xff )
2511
2512
2513/** @def RT_LODWORD
2514 * Gets the low dword (=uint32_t) of something.
2515 * @deprecated Use RT_LO_U32. */
2516#define RT_LODWORD(a) ( (uint32_t)(a) )
2517/** @def RT_HIDWORD
2518 * Gets the high dword (=uint32_t) of a 64-bit of something.
2519 * @deprecated Use RT_HI_U32. */
2520#define RT_HIDWORD(a) ( (uint32_t)((a) >> 32) )
2521
2522/** @def RT_LOWORD
2523 * Gets the low word (=uint16_t) of something.
2524 * @deprecated Use RT_LO_U16. */
2525#define RT_LOWORD(a) ( (a) & 0xffff )
2526/** @def RT_HIWORD
2527 * Gets the high word (=uint16_t) of a 32-bit something.
2528 * @deprecated Use RT_HI_U16. */
2529#define RT_HIWORD(a) ( (a) >> 16 )
2530
2531/** @def RT_LOBYTE
2532 * Gets the low byte of something.
2533 * @deprecated Use RT_LO_U8. */
2534#define RT_LOBYTE(a) ( (a) & 0xff )
2535/** @def RT_HIBYTE
2536 * Gets the high byte of a 16-bit something.
2537 * @deprecated Use RT_HI_U8. */
2538#define RT_HIBYTE(a) ( (a) >> 8 )
2539
2540
2541/** @def RT_MAKE_U64
2542 * Constructs a uint64_t value from two uint32_t values.
2543 */
2544#define RT_MAKE_U64(Lo, Hi) ( (uint64_t)((uint32_t)(Hi)) << 32 | (uint32_t)(Lo) )
2545
2546/** @def RT_MAKE_U64_FROM_U16
2547 * Constructs a uint64_t value from four uint16_t values.
2548 */
2549#define RT_MAKE_U64_FROM_U16(w0, w1, w2, w3) \
2550 ((uint64_t)( (uint64_t)((uint16_t)(w3)) << 48 \
2551 | (uint64_t)((uint16_t)(w2)) << 32 \
2552 | (uint32_t)((uint16_t)(w1)) << 16 \
2553 | (uint16_t)(w0) ))
2554
2555/** @def RT_MAKE_U64_FROM_U8
2556 * Constructs a uint64_t value from eight uint8_t values.
2557 */
2558#define RT_MAKE_U64_FROM_U8(b0, b1, b2, b3, b4, b5, b6, b7) \
2559 ((uint64_t)( (uint64_t)((uint8_t)(b7)) << 56 \
2560 | (uint64_t)((uint8_t)(b6)) << 48 \
2561 | (uint64_t)((uint8_t)(b5)) << 40 \
2562 | (uint64_t)((uint8_t)(b4)) << 32 \
2563 | (uint32_t)((uint8_t)(b3)) << 24 \
2564 | (uint32_t)((uint8_t)(b2)) << 16 \
2565 | (uint16_t)((uint8_t)(b1)) << 8 \
2566 | (uint8_t)(b0) ))
2567
2568/** @def RT_MAKE_U32
2569 * Constructs a uint32_t value from two uint16_t values.
2570 */
2571#define RT_MAKE_U32(Lo, Hi) \
2572 ((uint32_t)( (uint32_t)((uint16_t)(Hi)) << 16 \
2573 | (uint16_t)(Lo) ))
2574
2575/** @def RT_MAKE_U32_FROM_U8
2576 * Constructs a uint32_t value from four uint8_t values.
2577 */
2578#define RT_MAKE_U32_FROM_U8(b0, b1, b2, b3) \
2579 ((uint32_t)( (uint32_t)((uint8_t)(b3)) << 24 \
2580 | (uint32_t)((uint8_t)(b2)) << 16 \
2581 | (uint16_t)((uint8_t)(b1)) << 8 \
2582 | (uint8_t)(b0) ))
2583
2584/** @def RT_MAKE_U16
2585 * Constructs a uint16_t value from two uint8_t values.
2586 */
2587#define RT_MAKE_U16(Lo, Hi) \
2588 ((uint16_t)( (uint16_t)((uint8_t)(Hi)) << 8 \
2589 | (uint8_t)(Lo) ))
2590
2591
2592/** @def RT_BSWAP_U64
2593 * Reverses the byte order of an uint64_t value. */
2594#if 0
2595# define RT_BSWAP_U64(u64) RT_BSWAP_U64_C(u64)
2596#elif defined(__GNUC__)
2597# define RT_BSWAP_U64(u64) (__builtin_constant_p((u64)) \
2598 ? RT_BSWAP_U64_C(u64) : ASMByteSwapU64(u64))
2599#else
2600# define RT_BSWAP_U64(u64) ASMByteSwapU64(u64)
2601#endif
2602
2603/** @def RT_BSWAP_U32
2604 * Reverses the byte order of an uint32_t value. */
2605#if 0
2606# define RT_BSWAP_U32(u32) RT_BSWAP_U32_C(u32)
2607#elif defined(__GNUC__)
2608# define RT_BSWAP_U32(u32) (__builtin_constant_p((u32)) \
2609 ? RT_BSWAP_U32_C(u32) : ASMByteSwapU32(u32))
2610#else
2611# define RT_BSWAP_U32(u32) ASMByteSwapU32(u32)
2612#endif
2613
2614/** @def RT_BSWAP_U16
2615 * Reverses the byte order of an uint16_t value. */
2616#if 0
2617# define RT_BSWAP_U16(u16) RT_BSWAP_U16_C(u16)
2618#elif defined(__GNUC__)
2619# define RT_BSWAP_U16(u16) (__builtin_constant_p((u16)) \
2620 ? RT_BSWAP_U16_C(u16) : ASMByteSwapU16(u16))
2621#else
2622# define RT_BSWAP_U16(u16) ASMByteSwapU16(u16)
2623#endif
2624
2625
2626/** @def RT_BSWAP_U64_C
2627 * Reverses the byte order of an uint64_t constant. */
2628#define RT_BSWAP_U64_C(u64) RT_MAKE_U64(RT_BSWAP_U32_C((u64) >> 32), RT_BSWAP_U32_C((u64) & 0xffffffff))
2629
2630/** @def RT_BSWAP_U32_C
2631 * Reverses the byte order of an uint32_t constant. */
2632#define RT_BSWAP_U32_C(u32) RT_MAKE_U32_FROM_U8(RT_BYTE4(u32), RT_BYTE3(u32), RT_BYTE2(u32), RT_BYTE1(u32))
2633
2634/** @def RT_BSWAP_U16_C
2635 * Reverses the byte order of an uint16_t constant. */
2636#define RT_BSWAP_U16_C(u16) RT_MAKE_U16(RT_HIBYTE(u16), RT_LOBYTE(u16))
2637
2638
2639/** @def RT_H2LE_U64
2640 * Converts an uint64_t value from host to little endian byte order. */
2641#ifdef RT_BIG_ENDIAN
2642# define RT_H2LE_U64(u64) RT_BSWAP_U64(u64)
2643#else
2644# define RT_H2LE_U64(u64) (u64)
2645#endif
2646
2647/** @def RT_H2LE_U64_C
2648 * Converts an uint64_t constant from host to little endian byte order. */
2649#ifdef RT_BIG_ENDIAN
2650# define RT_H2LE_U64_C(u64) RT_BSWAP_U64_C(u64)
2651#else
2652# define RT_H2LE_U64_C(u64) (u64)
2653#endif
2654
2655/** @def RT_H2LE_U32
2656 * Converts an uint32_t value from host to little endian byte order. */
2657#ifdef RT_BIG_ENDIAN
2658# define RT_H2LE_U32(u32) RT_BSWAP_U32(u32)
2659#else
2660# define RT_H2LE_U32(u32) (u32)
2661#endif
2662
2663/** @def RT_H2LE_U32_C
2664 * Converts an uint32_t constant from host to little endian byte order. */
2665#ifdef RT_BIG_ENDIAN
2666# define RT_H2LE_U32_C(u32) RT_BSWAP_U32_C(u32)
2667#else
2668# define RT_H2LE_U32_C(u32) (u32)
2669#endif
2670
2671/** @def RT_H2LE_U16
2672 * Converts an uint16_t value from host to little endian byte order. */
2673#ifdef RT_BIG_ENDIAN
2674# define RT_H2LE_U16(u16) RT_BSWAP_U16(u16)
2675#else
2676# define RT_H2LE_U16(u16) (u16)
2677#endif
2678
2679/** @def RT_H2LE_U16_C
2680 * Converts an uint16_t constant from host to little endian byte order. */
2681#ifdef RT_BIG_ENDIAN
2682# define RT_H2LE_U16_C(u16) RT_BSWAP_U16_C(u16)
2683#else
2684# define RT_H2LE_U16_C(u16) (u16)
2685#endif
2686
2687
2688/** @def RT_LE2H_U64
2689 * Converts an uint64_t value from little endian to host byte order. */
2690#ifdef RT_BIG_ENDIAN
2691# define RT_LE2H_U64(u64) RT_BSWAP_U64(u64)
2692#else
2693# define RT_LE2H_U64(u64) (u64)
2694#endif
2695
2696/** @def RT_LE2H_U64_C
2697 * Converts an uint64_t constant from little endian to host byte order. */
2698#ifdef RT_BIG_ENDIAN
2699# define RT_LE2H_U64_C(u64) RT_BSWAP_U64_C(u64)
2700#else
2701# define RT_LE2H_U64_C(u64) (u64)
2702#endif
2703
2704/** @def RT_LE2H_U32
2705 * Converts an uint32_t value from little endian to host byte order. */
2706#ifdef RT_BIG_ENDIAN
2707# define RT_LE2H_U32(u32) RT_BSWAP_U32(u32)
2708#else
2709# define RT_LE2H_U32(u32) (u32)
2710#endif
2711
2712/** @def RT_LE2H_U32_C
2713 * Converts an uint32_t constant from little endian to host byte order. */
2714#ifdef RT_BIG_ENDIAN
2715# define RT_LE2H_U32_C(u32) RT_BSWAP_U32_C(u32)
2716#else
2717# define RT_LE2H_U32_C(u32) (u32)
2718#endif
2719
2720/** @def RT_LE2H_U16
2721 * Converts an uint16_t value from little endian to host byte order. */
2722#ifdef RT_BIG_ENDIAN
2723# define RT_LE2H_U16(u16) RT_BSWAP_U16(u16)
2724#else
2725# define RT_LE2H_U16(u16) (u16)
2726#endif
2727
2728/** @def RT_LE2H_U16_C
2729 * Converts an uint16_t constant from little endian to host byte order. */
2730#ifdef RT_BIG_ENDIAN
2731# define RT_LE2H_U16_C(u16) RT_BSWAP_U16_C(u16)
2732#else
2733# define RT_LE2H_U16_C(u16) (u16)
2734#endif
2735
2736
2737/** @def RT_H2BE_U64
2738 * Converts an uint64_t value from host to big endian byte order. */
2739#ifdef RT_BIG_ENDIAN
2740# define RT_H2BE_U64(u64) (u64)
2741#else
2742# define RT_H2BE_U64(u64) RT_BSWAP_U64(u64)
2743#endif
2744
2745/** @def RT_H2BE_U64_C
2746 * Converts an uint64_t constant from host to big endian byte order. */
2747#ifdef RT_BIG_ENDIAN
2748# define RT_H2BE_U64_C(u64) (u64)
2749#else
2750# define RT_H2BE_U64_C(u64) RT_BSWAP_U64_C(u64)
2751#endif
2752
2753/** @def RT_H2BE_U32
2754 * Converts an uint32_t value from host to big endian byte order. */
2755#ifdef RT_BIG_ENDIAN
2756# define RT_H2BE_U32(u32) (u32)
2757#else
2758# define RT_H2BE_U32(u32) RT_BSWAP_U32(u32)
2759#endif
2760
2761/** @def RT_H2BE_U32_C
2762 * Converts an uint32_t constant from host to big endian byte order. */
2763#ifdef RT_BIG_ENDIAN
2764# define RT_H2BE_U32_C(u32) (u32)
2765#else
2766# define RT_H2BE_U32_C(u32) RT_BSWAP_U32_C(u32)
2767#endif
2768
2769/** @def RT_H2BE_U16
2770 * Converts an uint16_t value from host to big endian byte order. */
2771#ifdef RT_BIG_ENDIAN
2772# define RT_H2BE_U16(u16) (u16)
2773#else
2774# define RT_H2BE_U16(u16) RT_BSWAP_U16(u16)
2775#endif
2776
2777/** @def RT_H2BE_U16_C
2778 * Converts an uint16_t constant from host to big endian byte order. */
2779#ifdef RT_BIG_ENDIAN
2780# define RT_H2BE_U16_C(u16) (u16)
2781#else
2782# define RT_H2BE_U16_C(u16) RT_BSWAP_U16_C(u16)
2783#endif
2784
2785/** @def RT_BE2H_U64
2786 * Converts an uint64_t value from big endian to host byte order. */
2787#ifdef RT_BIG_ENDIAN
2788# define RT_BE2H_U64(u64) (u64)
2789#else
2790# define RT_BE2H_U64(u64) RT_BSWAP_U64(u64)
2791#endif
2792
2793/** @def RT_BE2H_U64
2794 * Converts an uint64_t constant from big endian to host byte order. */
2795#ifdef RT_BIG_ENDIAN
2796# define RT_BE2H_U64_C(u64) (u64)
2797#else
2798# define RT_BE2H_U64_C(u64) RT_BSWAP_U64_C(u64)
2799#endif
2800
2801/** @def RT_BE2H_U32
2802 * Converts an uint32_t value from big endian to host byte order. */
2803#ifdef RT_BIG_ENDIAN
2804# define RT_BE2H_U32(u32) (u32)
2805#else
2806# define RT_BE2H_U32(u32) RT_BSWAP_U32(u32)
2807#endif
2808
2809/** @def RT_BE2H_U32_C
2810 * Converts an uint32_t value from big endian to host byte order. */
2811#ifdef RT_BIG_ENDIAN
2812# define RT_BE2H_U32_C(u32) (u32)
2813#else
2814# define RT_BE2H_U32_C(u32) RT_BSWAP_U32_C(u32)
2815#endif
2816
2817/** @def RT_BE2H_U16
2818 * Converts an uint16_t value from big endian to host byte order. */
2819#ifdef RT_BIG_ENDIAN
2820# define RT_BE2H_U16(u16) (u16)
2821#else
2822# define RT_BE2H_U16(u16) RT_BSWAP_U16(u16)
2823#endif
2824
2825/** @def RT_BE2H_U16_C
2826 * Converts an uint16_t constant from big endian to host byte order. */
2827#ifdef RT_BIG_ENDIAN
2828# define RT_BE2H_U16_C(u16) (u16)
2829#else
2830# define RT_BE2H_U16_C(u16) RT_BSWAP_U16_C(u16)
2831#endif
2832
2833
2834/** @def RT_H2N_U64
2835 * Converts an uint64_t value from host to network byte order. */
2836#define RT_H2N_U64(u64) RT_H2BE_U64(u64)
2837
2838/** @def RT_H2N_U64_C
2839 * Converts an uint64_t constant from host to network byte order. */
2840#define RT_H2N_U64_C(u64) RT_H2BE_U64_C(u64)
2841
2842/** @def RT_H2N_U32
2843 * Converts an uint32_t value from host to network byte order. */
2844#define RT_H2N_U32(u32) RT_H2BE_U32(u32)
2845
2846/** @def RT_H2N_U32_C
2847 * Converts an uint32_t constant from host to network byte order. */
2848#define RT_H2N_U32_C(u32) RT_H2BE_U32_C(u32)
2849
2850/** @def RT_H2N_U16
2851 * Converts an uint16_t value from host to network byte order. */
2852#define RT_H2N_U16(u16) RT_H2BE_U16(u16)
2853
2854/** @def RT_H2N_U16_C
2855 * Converts an uint16_t constant from host to network byte order. */
2856#define RT_H2N_U16_C(u16) RT_H2BE_U16_C(u16)
2857
2858/** @def RT_N2H_U64
2859 * Converts an uint64_t value from network to host byte order. */
2860#define RT_N2H_U64(u64) RT_BE2H_U64(u64)
2861
2862/** @def RT_N2H_U64_C
2863 * Converts an uint64_t constant from network to host byte order. */
2864#define RT_N2H_U64_C(u64) RT_BE2H_U64_C(u64)
2865
2866/** @def RT_N2H_U32
2867 * Converts an uint32_t value from network to host byte order. */
2868#define RT_N2H_U32(u32) RT_BE2H_U32(u32)
2869
2870/** @def RT_N2H_U32_C
2871 * Converts an uint32_t constant from network to host byte order. */
2872#define RT_N2H_U32_C(u32) RT_BE2H_U32_C(u32)
2873
2874/** @def RT_N2H_U16
2875 * Converts an uint16_t value from network to host byte order. */
2876#define RT_N2H_U16(u16) RT_BE2H_U16(u16)
2877
2878/** @def RT_N2H_U16_C
2879 * Converts an uint16_t value from network to host byte order. */
2880#define RT_N2H_U16_C(u16) RT_BE2H_U16_C(u16)
2881
2882
2883/*
2884 * The BSD sys/param.h + machine/param.h file is a major source of
2885 * namespace pollution. Kill off some of the worse ones unless we're
2886 * compiling kernel code.
2887 */
2888#if defined(RT_OS_DARWIN) \
2889 && !defined(KERNEL) \
2890 && !defined(RT_NO_BSD_PARAM_H_UNDEFING) \
2891 && ( defined(_SYS_PARAM_H_) || defined(_I386_PARAM_H_) )
2892/* sys/param.h: */
2893# undef PSWP
2894# undef PVM
2895# undef PINOD
2896# undef PRIBO
2897# undef PVFS
2898# undef PZERO
2899# undef PSOCK
2900# undef PWAIT
2901# undef PLOCK
2902# undef PPAUSE
2903# undef PUSER
2904# undef PRIMASK
2905# undef MINBUCKET
2906# undef MAXALLOCSAVE
2907# undef FSHIFT
2908# undef FSCALE
2909
2910/* i386/machine.h: */
2911# undef ALIGN
2912# undef ALIGNBYTES
2913# undef DELAY
2914# undef STATUS_WORD
2915# undef USERMODE
2916# undef BASEPRI
2917# undef MSIZE
2918# undef CLSIZE
2919# undef CLSIZELOG2
2920#endif
2921
2922/** @def NIL_OFFSET
2923 * NIL offset.
2924 * Whenever we use offsets instead of pointers to save space and relocation effort
2925 * NIL_OFFSET shall be used as the equivalent to NULL.
2926 */
2927#define NIL_OFFSET (~0U)
2928
2929
2930/** @def NOREF
2931 * Keeps the compiler from bitching about an unused parameter, local variable,
2932 * or other stuff, will never use _Pragma are is thus more flexible.
2933 */
2934#define NOREF(var) (void)(var)
2935
2936/** @def RT_NOREF_PV
2937 * Keeps the compiler from bitching about an unused parameter or local variable.
2938 * This one cannot be used with structure members and such, like for instance
2939 * AssertRC may end up doing due to its generic nature.
2940 */
2941#if defined(__cplusplus) && RT_CLANG_PREREQ(6, 0)
2942# define RT_NOREF_PV(var) _Pragma(RT_STR(unused(var)))
2943#else
2944# define RT_NOREF_PV(var) (void)(var)
2945#endif
2946
2947/** @def RT_NOREF1
2948 * RT_NOREF_PV shorthand taking on parameter. */
2949#define RT_NOREF1(var1) RT_NOREF_PV(var1)
2950/** @def RT_NOREF2
2951 * RT_NOREF_PV shorthand taking two parameters. */
2952#define RT_NOREF2(var1, var2) RT_NOREF_PV(var1); RT_NOREF1(var2)
2953/** @def RT_NOREF3
2954 * RT_NOREF_PV shorthand taking three parameters. */
2955#define RT_NOREF3(var1, var2, var3) RT_NOREF_PV(var1); RT_NOREF2(var2, var3)
2956/** @def RT_NOREF4
2957 * RT_NOREF_PV shorthand taking four parameters. */
2958#define RT_NOREF4(var1, var2, var3, var4) RT_NOREF_PV(var1); RT_NOREF3(var2, var3, var4)
2959/** @def RT_NOREF5
2960 * RT_NOREF_PV shorthand taking five parameters. */
2961#define RT_NOREF5(var1, var2, var3, var4, var5) RT_NOREF_PV(var1); RT_NOREF4(var2, var3, var4, var5)
2962/** @def RT_NOREF6
2963 * RT_NOREF_PV shorthand taking six parameters. */
2964#define RT_NOREF6(var1, var2, var3, var4, var5, var6) RT_NOREF_PV(var1); RT_NOREF5(var2, var3, var4, var5, var6)
2965/** @def RT_NOREF7
2966 * RT_NOREF_PV shorthand taking seven parameters. */
2967#define RT_NOREF7(var1, var2, var3, var4, var5, var6, var7) \
2968 RT_NOREF_PV(var1); RT_NOREF6(var2, var3, var4, var5, var6, var7)
2969/** @def RT_NOREF8
2970 * RT_NOREF_PV shorthand taking eight parameters. */
2971#define RT_NOREF8(var1, var2, var3, var4, var5, var6, var7, var8) \
2972 RT_NOREF_PV(var1); RT_NOREF7(var2, var3, var4, var5, var6, var7, var8)
2973/** @def RT_NOREF9
2974 * RT_NOREF_PV shorthand taking nine parameters. */
2975#define RT_NOREF9(var1, var2, var3, var4, var5, var6, var7, var8, var9) \
2976 RT_NOREF_PV(var1); RT_NOREF8(var2, var3, var4, var5, var6, var7, var8, var9)
2977/** @def RT_NOREF10
2978 * RT_NOREF_PV shorthand taking ten parameters. */
2979#define RT_NOREF10(var1, var2, var3, var4, var5, var6, var7, var8, var9, var10) \
2980 RT_NOREF_PV(var1); RT_NOREF_PV(var2); RT_NOREF_PV(var3); RT_NOREF_PV(var4); RT_NOREF_PV(var5); RT_NOREF_PV(var6); \
2981 RT_NOREF_PV(var7); RT_NOREF_PV(var8); RT_NOREF_PV(var9); RT_NOREF_PV(var10)
2982/** @def RT_NOREF11
2983 * RT_NOREF_PV shorthand taking eleven parameters. */
2984#define RT_NOREF11(var1, var2, var3, var4, var5, var6, var7, var8, var9, var10, var11) \
2985 RT_NOREF_PV(var1); RT_NOREF10(var2, var3, var4, var5, var6, var7, var8, var9, var10)
2986/** @def RT_NOREF12
2987 * RT_NOREF_PV shorthand taking twelve parameters. */
2988#define RT_NOREF12(var1, var2, var3, var4, var5, var6, var7, var8, var9, var10, var11, var12) \
2989 RT_NOREF_PV(var1); RT_NOREF11(var2, var3, var4, var5, var6, var7, var8, var9, var10, var11, var12)
2990/** @def RT_NOREF13
2991 * RT_NOREF_PV shorthand taking thirteen parameters. */
2992#define RT_NOREF13(var1, var2, var3, var4, var5, var6, var7, var8, var9, var10, var11, var12, var13) \
2993 RT_NOREF_PV(var1); RT_NOREF12(var2, var3, var4, var5, var6, var7, var8, var9, var10, var11, var12, var13)
2994/** @def RT_NOREF14
2995 * RT_NOREF_PV shorthand taking fourteen parameters. */
2996#define RT_NOREF14(var1, var2, var3, var4, var5, var6, var7, var8, var9, var10, var11, var12, var13, var14) \
2997 RT_NOREF_PV(var1); RT_NOREF13(var2, var3, var4, var5, var6, var7, var8, var9, var10, var11, var12, var13, var14)
2998/** @def RT_NOREF15
2999 * RT_NOREF_PV shorthand taking fifteen parameters. */
3000#define RT_NOREF15(var1, var2, var3, var4, var5, var6, var7, var8, var9, var10, var11, var12, var13, var14, var15) \
3001 RT_NOREF_PV(var1); RT_NOREF14(var2, var3, var4, var5, var6, var7, var8, var9, var10, var11, var12, var13, var14, var15)
3002/** @def RT_NOREF16
3003 * RT_NOREF_PV shorthand taking fifteen parameters. */
3004#define RT_NOREF16(var1, var2, var3, var4, var5, var6, var7, var8, var9, var10, var11, var12, var13, var14, var15, var16) \
3005 RT_NOREF_PV(var1); RT_NOREF15(var2, var3, var4, var5, var6, var7, var8, var9, var10, var11, var12, var13, var14, var15, var16)
3006/** @def RT_NOREF17
3007 * RT_NOREF_PV shorthand taking seventeen parameters. */
3008#define RT_NOREF17(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17) \
3009 RT_NOREF_PV(v1); RT_NOREF16(v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17)
3010/** @def RT_NOREF18
3011 * RT_NOREF_PV shorthand taking eighteen parameters. */
3012#define RT_NOREF18(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18) \
3013 RT_NOREF_PV(v1); RT_NOREF17(v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18)
3014/** @def RT_NOREF19
3015 * RT_NOREF_PV shorthand taking nineteen parameters. */
3016#define RT_NOREF19(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19) \
3017 RT_NOREF_PV(v1); RT_NOREF18(v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19)
3018/** @def RT_NOREF20
3019 * RT_NOREF_PV shorthand taking twenty parameters. */
3020#define RT_NOREF20(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20) \
3021 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)
3022/** @def RT_NOREF21
3023 * RT_NOREF_PV shorthand taking twentyone parameters. */
3024#define RT_NOREF21(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21) \
3025 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)
3026/** @def RT_NOREF22
3027 * RT_NOREF_PV shorthand taking twentytwo parameters. */
3028#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) \
3029 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)
3030
3031/** @def RT_NOREF
3032 * RT_NOREF_PV variant using the variadic macro feature of C99.
3033 * @remarks Only use this in sources */
3034#ifdef RT_COMPILER_SUPPORTS_VA_ARGS
3035# define RT_NOREF(...) \
3036 RT_UNPACK_CALL(RT_CONCAT(RT_NOREF, RT_EXPAND(RT_COUNT_VA_ARGS(__VA_ARGS__))),(__VA_ARGS__))
3037#endif
3038
3039
3040/** @def RT_BREAKPOINT
3041 * Emit a debug breakpoint instruction.
3042 *
3043 * @remarks In the x86/amd64 gnu world we add a nop instruction after the int3
3044 * to force gdb to remain at the int3 source line.
3045 * @remarks The L4 kernel will try make sense of the breakpoint, thus the jmp on
3046 * x86/amd64.
3047 */
3048#ifdef __GNUC__
3049# if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
3050# if !defined(__L4ENV__)
3051# define RT_BREAKPOINT() __asm__ __volatile__("int $3\n\tnop\n\t")
3052# else
3053# define RT_BREAKPOINT() __asm__ __volatile__("int3; jmp 1f; 1:\n\t")
3054# endif
3055# elif defined(RT_ARCH_SPARC64)
3056# define RT_BREAKPOINT() __asm__ __volatile__("illtrap 0\n\t") /** @todo Sparc64: this is just a wild guess. */
3057# elif defined(RT_ARCH_SPARC)
3058# define RT_BREAKPOINT() __asm__ __volatile__("unimp 0\n\t") /** @todo Sparc: this is just a wild guess (same as Sparc64, just different name). */
3059# endif
3060#endif
3061#ifdef _MSC_VER
3062# define RT_BREAKPOINT() __debugbreak()
3063#endif
3064#if defined(__IBMC__) || defined(__IBMCPP__)
3065# define RT_BREAKPOINT() __interrupt(3)
3066#endif
3067#if defined(__WATCOMC__)
3068# define RT_BREAKPOINT() _asm { int 3 }
3069#endif
3070#ifndef RT_BREAKPOINT
3071# error "This compiler/arch is not supported!"
3072#endif
3073
3074
3075/** @defgroup grp_rt_cdefs_size Size Constants
3076 * (Of course, these are binary computer terms, not SI.)
3077 * @{
3078 */
3079/** 1 K (Kilo) (1 024). */
3080#define _1K 0x00000400
3081/** 2 K (Kilo) (2 048). */
3082#define _2K 0x00000800
3083/** 4 K (Kilo) (4 096). */
3084#define _4K 0x00001000
3085/** 8 K (Kilo) (8 192). */
3086#define _8K 0x00002000
3087/** 16 K (Kilo) (16 384). */
3088#define _16K 0x00004000
3089/** 32 K (Kilo) (32 768). */
3090#define _32K 0x00008000
3091/** 64 K (Kilo) (65 536). */
3092#if ARCH_BITS != 16
3093# define _64K 0x00010000
3094#else
3095# define _64K UINT32_C(0x00010000)
3096#endif
3097/** 128 K (Kilo) (131 072). */
3098#if ARCH_BITS != 16
3099# define _128K 0x00020000
3100#else
3101# define _128K UINT32_C(0x00020000)
3102#endif
3103/** 256 K (Kilo) (262 144). */
3104#if ARCH_BITS != 16
3105# define _256K 0x00040000
3106#else
3107# define _256K UINT32_C(0x00040000)
3108#endif
3109/** 512 K (Kilo) (524 288). */
3110#if ARCH_BITS != 16
3111# define _512K 0x00080000
3112#else
3113# define _512K UINT32_C(0x00080000)
3114#endif
3115/** 1 M (Mega) (1 048 576). */
3116#if ARCH_BITS != 16
3117# define _1M 0x00100000
3118#else
3119# define _1M UINT32_C(0x00100000)
3120#endif
3121/** 2 M (Mega) (2 097 152). */
3122#if ARCH_BITS != 16
3123# define _2M 0x00200000
3124#else
3125# define _2M UINT32_C(0x00200000)
3126#endif
3127/** 4 M (Mega) (4 194 304). */
3128#if ARCH_BITS != 16
3129# define _4M 0x00400000
3130#else
3131# define _4M UINT32_C(0x00400000)
3132#endif
3133/** 8 M (Mega) (8 388 608). */
3134#define _8M UINT32_C(0x00800000)
3135/** 16 M (Mega) (16 777 216). */
3136#define _16M UINT32_C(0x01000000)
3137/** 32 M (Mega) (33 554 432). */
3138#define _32M UINT32_C(0x02000000)
3139/** 64 M (Mega) (67 108 864). */
3140#define _64M UINT32_C(0x04000000)
3141/** 128 M (Mega) (134 217 728). */
3142#define _128M UINT32_C(0x08000000)
3143/** 256 M (Mega) (268 435 456). */
3144#define _256M UINT32_C(0x10000000)
3145/** 512 M (Mega) (536 870 912). */
3146#define _512M UINT32_C(0x20000000)
3147/** 1 G (Giga) (1 073 741 824). (32-bit) */
3148#if ARCH_BITS != 16
3149# define _1G 0x40000000
3150#else
3151# define _1G UINT32_C(0x40000000)
3152#endif
3153/** 1 G (Giga) (1 073 741 824). (64-bit) */
3154#if ARCH_BITS != 16
3155# define _1G64 0x40000000LL
3156#else
3157# define _1G64 UINT64_C(0x40000000)
3158#endif
3159/** 2 G (Giga) (2 147 483 648). (32-bit) */
3160#define _2G32 UINT32_C(0x80000000)
3161/** 2 G (Giga) (2 147 483 648). (64-bit) */
3162#if ARCH_BITS != 16
3163# define _2G 0x0000000080000000LL
3164#else
3165# define _2G UINT64_C(0x0000000080000000)
3166#endif
3167/** 4 G (Giga) (4 294 967 296). */
3168#if ARCH_BITS != 16
3169# define _4G 0x0000000100000000LL
3170#else
3171# define _4G UINT64_C(0x0000000100000000)
3172#endif
3173/** 1 T (Tera) (1 099 511 627 776). */
3174#if ARCH_BITS != 16
3175# define _1T 0x0000010000000000LL
3176#else
3177# define _1T UINT64_C(0x0000010000000000)
3178#endif
3179/** 1 P (Peta) (1 125 899 906 842 624). */
3180#if ARCH_BITS != 16
3181# define _1P 0x0004000000000000LL
3182#else
3183# define _1P UINT64_C(0x0004000000000000)
3184#endif
3185/** 1 E (Exa) (1 152 921 504 606 846 976). */
3186#if ARCH_BITS != 16
3187# define _1E 0x1000000000000000LL
3188#else
3189# define _1E UINT64_C(0x1000000000000000)
3190#endif
3191/** 2 E (Exa) (2 305 843 009 213 693 952). */
3192#if ARCH_BITS != 16
3193# define _2E 0x2000000000000000ULL
3194#else
3195# define _2E UINT64_C(0x2000000000000000)
3196#endif
3197/** @} */
3198
3199/** @defgroup grp_rt_cdefs_decimal_grouping Decimal Constant Grouping Macros
3200 * @{ */
3201#define RT_D1(g1) g1
3202#define RT_D2(g1, g2) g1#g2
3203#define RT_D3(g1, g2, g3) g1#g2#g3
3204#define RT_D4(g1, g2, g3, g4) g1#g2#g3#g4
3205#define RT_D5(g1, g2, g3, g4, g5) g1#g2#g3#g4#g5
3206#define RT_D6(g1, g2, g3, g4, g5, g6) g1#g2#g3#g4#g5#g6
3207#define RT_D7(g1, g2, g3, g4, g5, g6, g7) g1#g2#g3#g4#g5#g6#g7
3208
3209#define RT_D1_U(g1) UINT32_C(g1)
3210#define RT_D2_U(g1, g2) UINT32_C(g1#g2)
3211#define RT_D3_U(g1, g2, g3) UINT32_C(g1#g2#g3)
3212#define RT_D4_U(g1, g2, g3, g4) UINT64_C(g1#g2#g3#g4)
3213#define RT_D5_U(g1, g2, g3, g4, g5) UINT64_C(g1#g2#g3#g4#g5)
3214#define RT_D6_U(g1, g2, g3, g4, g5, g6) UINT64_C(g1#g2#g3#g4#g5#g6)
3215#define RT_D7_U(g1, g2, g3, g4, g5, g6, g7) UINT64_C(g1#g2#g3#g4#g5#g6#g7)
3216
3217#define RT_D1_S(g1) INT32_C(g1)
3218#define RT_D2_S(g1, g2) INT32_C(g1#g2)
3219#define RT_D3_S(g1, g2, g3) INT32_C(g1#g2#g3)
3220#define RT_D4_S(g1, g2, g3, g4) INT64_C(g1#g2#g3#g4)
3221#define RT_D5_S(g1, g2, g3, g4, g5) INT64_C(g1#g2#g3#g4#g5)
3222#define RT_D6_S(g1, g2, g3, g4, g5, g6) INT64_C(g1#g2#g3#g4#g5#g6)
3223#define RT_D7_S(g1, g2, g3, g4, g5, g6, g7) INT64_C(g1#g2#g3#g4#g5#g6#g7)
3224
3225#define RT_D1_U32(g1) UINT32_C(g1)
3226#define RT_D2_U32(g1, g2) UINT32_C(g1#g2)
3227#define RT_D3_U32(g1, g2, g3) UINT32_C(g1#g2#g3)
3228#define RT_D4_U32(g1, g2, g3, g4) UINT32_C(g1#g2#g3#g4)
3229
3230#define RT_D1_S32(g1) INT32_C(g1)
3231#define RT_D2_S32(g1, g2) INT32_C(g1#g2)
3232#define RT_D3_S32(g1, g2, g3) INT32_C(g1#g2#g3)
3233#define RT_D4_S32(g1, g2, g3, g4) INT32_C(g1#g2#g3#g4)
3234
3235#define RT_D1_U64(g1) UINT64_C(g1)
3236#define RT_D2_U64(g1, g2) UINT64_C(g1#g2)
3237#define RT_D3_U64(g1, g2, g3) UINT64_C(g1#g2#g3)
3238#define RT_D4_U64(g1, g2, g3, g4) UINT64_C(g1#g2#g3#g4)
3239#define RT_D5_U64(g1, g2, g3, g4, g5) UINT64_C(g1#g2#g3#g4#g5)
3240#define RT_D6_U64(g1, g2, g3, g4, g5, g6) UINT64_C(g1#g2#g3#g4#g5#g6)
3241#define RT_D7_U64(g1, g2, g3, g4, g5, g6, g7) UINT64_C(g1#g2#g3#g4#g5#g6#g7)
3242
3243#define RT_D1_S64(g1) INT64_C(g1)
3244#define RT_D2_S64(g1, g2) INT64_C(g1#g2)
3245#define RT_D3_S64(g1, g2, g3) INT64_C(g1#g2#g3)
3246#define RT_D4_S64(g1, g2, g3, g4) INT64_C(g1#g2#g3#g4)
3247#define RT_D5_S64(g1, g2, g3, g4, g5) INT64_C(g1#g2#g3#g4#g5)
3248#define RT_D6_S64(g1, g2, g3, g4, g5, g6) INT64_C(g1#g2#g3#g4#g5#g6)
3249#define RT_D7_S64(g1, g2, g3, g4, g5, g6, g7) INT64_C(g1#g2#g3#g4#g5#g6#g7)
3250/** @} */
3251
3252
3253/** @defgroup grp_rt_cdefs_time Time Constants
3254 * @{
3255 */
3256/** 1 hour expressed in nanoseconds (64-bit). */
3257#define RT_NS_1HOUR UINT64_C(3600000000000)
3258/** 1 minute expressed in nanoseconds (64-bit). */
3259#define RT_NS_1MIN UINT64_C(60000000000)
3260/** 45 second expressed in nanoseconds. */
3261#define RT_NS_45SEC UINT64_C(45000000000)
3262/** 30 second expressed in nanoseconds. */
3263#define RT_NS_30SEC UINT64_C(30000000000)
3264/** 20 second expressed in nanoseconds. */
3265#define RT_NS_20SEC UINT64_C(20000000000)
3266/** 15 second expressed in nanoseconds. */
3267#define RT_NS_15SEC UINT64_C(15000000000)
3268/** 10 second expressed in nanoseconds. */
3269#define RT_NS_10SEC UINT64_C(10000000000)
3270/** 1 second expressed in nanoseconds. */
3271#define RT_NS_1SEC UINT32_C(1000000000)
3272/** 100 millsecond expressed in nanoseconds. */
3273#define RT_NS_100MS UINT32_C(100000000)
3274/** 10 millsecond expressed in nanoseconds. */
3275#define RT_NS_10MS UINT32_C(10000000)
3276/** 1 millsecond expressed in nanoseconds. */
3277#define RT_NS_1MS UINT32_C(1000000)
3278/** 100 microseconds expressed in nanoseconds. */
3279#define RT_NS_100US UINT32_C(100000)
3280/** 10 microseconds expressed in nanoseconds. */
3281#define RT_NS_10US UINT32_C(10000)
3282/** 1 microsecond expressed in nanoseconds. */
3283#define RT_NS_1US UINT32_C(1000)
3284
3285/** 1 second expressed in nanoseconds - 64-bit type. */
3286#define RT_NS_1SEC_64 UINT64_C(1000000000)
3287/** 100 millsecond expressed in nanoseconds - 64-bit type. */
3288#define RT_NS_100MS_64 UINT64_C(100000000)
3289/** 10 millsecond expressed in nanoseconds - 64-bit type. */
3290#define RT_NS_10MS_64 UINT64_C(10000000)
3291/** 1 millsecond expressed in nanoseconds - 64-bit type. */
3292#define RT_NS_1MS_64 UINT64_C(1000000)
3293/** 100 microseconds expressed in nanoseconds - 64-bit type. */
3294#define RT_NS_100US_64 UINT64_C(100000)
3295/** 10 microseconds expressed in nanoseconds - 64-bit type. */
3296#define RT_NS_10US_64 UINT64_C(10000)
3297/** 1 microsecond expressed in nanoseconds - 64-bit type. */
3298#define RT_NS_1US_64 UINT64_C(1000)
3299
3300/** 1 hour expressed in microseconds. */
3301#define RT_US_1HOUR UINT32_C(3600000000)
3302/** 1 minute expressed in microseconds. */
3303#define RT_US_1MIN UINT32_C(60000000)
3304/** 1 second expressed in microseconds. */
3305#define RT_US_1SEC UINT32_C(1000000)
3306/** 100 millsecond expressed in microseconds. */
3307#define RT_US_100MS UINT32_C(100000)
3308/** 10 millsecond expressed in microseconds. */
3309#define RT_US_10MS UINT32_C(10000)
3310/** 1 millsecond expressed in microseconds. */
3311#define RT_US_1MS UINT32_C(1000)
3312
3313/** 1 hour expressed in microseconds - 64-bit type. */
3314#define RT_US_1HOUR_64 UINT64_C(3600000000)
3315/** 1 minute expressed in microseconds - 64-bit type. */
3316#define RT_US_1MIN_64 UINT64_C(60000000)
3317/** 1 second expressed in microseconds - 64-bit type. */
3318#define RT_US_1SEC_64 UINT64_C(1000000)
3319/** 100 millsecond expressed in microseconds - 64-bit type. */
3320#define RT_US_100MS_64 UINT64_C(100000)
3321/** 10 millsecond expressed in microseconds - 64-bit type. */
3322#define RT_US_10MS_64 UINT64_C(10000)
3323/** 1 millsecond expressed in microseconds - 64-bit type. */
3324#define RT_US_1MS_64 UINT64_C(1000)
3325
3326/** 1 hour expressed in milliseconds. */
3327#define RT_MS_1HOUR UINT32_C(3600000)
3328/** 1 minute expressed in milliseconds. */
3329#define RT_MS_1MIN UINT32_C(60000)
3330/** 1 second expressed in milliseconds. */
3331#define RT_MS_1SEC UINT32_C(1000)
3332
3333/** 1 hour expressed in milliseconds - 64-bit type. */
3334#define RT_MS_1HOUR_64 UINT64_C(3600000)
3335/** 1 minute expressed in milliseconds - 64-bit type. */
3336#define RT_MS_1MIN_64 UINT64_C(60000)
3337/** 1 second expressed in milliseconds - 64-bit type. */
3338#define RT_MS_1SEC_64 UINT64_C(1000)
3339
3340/** The number of seconds per week. */
3341#define RT_SEC_1WEEK UINT32_C(604800)
3342/** The number of seconds per day. */
3343#define RT_SEC_1DAY UINT32_C(86400)
3344/** The number of seconds per hour. */
3345#define RT_SEC_1HOUR UINT32_C(3600)
3346
3347/** The number of seconds per week - 64-bit type. */
3348#define RT_SEC_1WEEK_64 UINT64_C(604800)
3349/** The number of seconds per day - 64-bit type. */
3350#define RT_SEC_1DAY_64 UINT64_C(86400)
3351/** The number of seconds per hour - 64-bit type. */
3352#define RT_SEC_1HOUR_64 UINT64_C(3600)
3353/** @} */
3354
3355
3356/** @defgroup grp_rt_cdefs_dbgtype Debug Info Types
3357 * @{ */
3358/** Other format. */
3359#define RT_DBGTYPE_OTHER RT_BIT_32(0)
3360/** Stabs. */
3361#define RT_DBGTYPE_STABS RT_BIT_32(1)
3362/** Debug With Arbitrary Record Format (DWARF). */
3363#define RT_DBGTYPE_DWARF RT_BIT_32(2)
3364/** Microsoft Codeview debug info. */
3365#define RT_DBGTYPE_CODEVIEW RT_BIT_32(3)
3366/** Watcom debug info. */
3367#define RT_DBGTYPE_WATCOM RT_BIT_32(4)
3368/** IBM High Level Language debug info. */
3369#define RT_DBGTYPE_HLL RT_BIT_32(5)
3370/** Old OS/2 and Windows symbol file. */
3371#define RT_DBGTYPE_SYM RT_BIT_32(6)
3372/** Map file. */
3373#define RT_DBGTYPE_MAP RT_BIT_32(7)
3374/** @} */
3375
3376
3377/** @defgroup grp_rt_cdefs_exetype Executable Image Types
3378 * @{ */
3379/** Some other format. */
3380#define RT_EXETYPE_OTHER RT_BIT_32(0)
3381/** Portable Executable. */
3382#define RT_EXETYPE_PE RT_BIT_32(1)
3383/** Linear eXecutable. */
3384#define RT_EXETYPE_LX RT_BIT_32(2)
3385/** Linear Executable. */
3386#define RT_EXETYPE_LE RT_BIT_32(3)
3387/** New Executable. */
3388#define RT_EXETYPE_NE RT_BIT_32(4)
3389/** DOS Executable (Mark Zbikowski). */
3390#define RT_EXETYPE_MZ RT_BIT_32(5)
3391/** COM Executable. */
3392#define RT_EXETYPE_COM RT_BIT_32(6)
3393/** a.out Executable. */
3394#define RT_EXETYPE_AOUT RT_BIT_32(7)
3395/** Executable and Linkable Format. */
3396#define RT_EXETYPE_ELF RT_BIT_32(8)
3397/** Mach-O Executable (including FAT ones). */
3398#define RT_EXETYPE_MACHO RT_BIT_32(9)
3399/** TE from UEFI. */
3400#define RT_EXETYPE_TE RT_BIT_32(9)
3401/** @} */
3402
3403
3404/** @def VALID_PTR
3405 * Pointer validation macro.
3406 * @param ptr The pointer.
3407 */
3408#if defined(RT_ARCH_AMD64)
3409# ifdef IN_RING3
3410# if defined(RT_OS_DARWIN) /* first 4GB is reserved for legacy kernel. */
3411# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) >= _4G \
3412 && !((uintptr_t)(ptr) & 0xffff800000000000ULL) )
3413# elif defined(RT_OS_SOLARIS) /* The kernel only used the top 2TB, but keep it simple. */
3414# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
3415 && ( ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0xffff800000000000ULL \
3416 || ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0) )
3417# else
3418# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
3419 && !((uintptr_t)(ptr) & 0xffff800000000000ULL) )
3420# endif
3421# else /* !IN_RING3 */
3422# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
3423 && ( ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0xffff800000000000ULL \
3424 || ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0) )
3425# endif /* !IN_RING3 */
3426
3427#elif defined(RT_ARCH_X86)
3428# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U )
3429
3430#elif defined(RT_ARCH_SPARC64)
3431# ifdef IN_RING3
3432# if defined(RT_OS_SOLARIS)
3433/** Sparc64 user mode: According to Figure 9.4 in solaris internals */
3434/** @todo # define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x80004000U >= 0x80004000U + 0x100000000ULL ) - figure this. */
3435# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x80000000U >= 0x80000000U + 0x100000000ULL )
3436# else
3437# error "Port me"
3438# endif
3439# else /* !IN_RING3 */
3440# if defined(RT_OS_SOLARIS)
3441/** @todo Sparc64 kernel mode: This is according to Figure 11.1 in solaris
3442 * internals. Verify in sources. */
3443# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) >= 0x01000000U )
3444# else
3445# error "Port me"
3446# endif
3447# endif /* !IN_RING3 */
3448
3449#elif defined(RT_ARCH_SPARC)
3450# ifdef IN_RING3
3451# ifdef RT_OS_SOLARIS
3452/** Sparc user mode: According to
3453 * http://cvs.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/uts/sun4/os/startup.c#510 */
3454# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x400000U >= 0x400000U + 0x2000U )
3455
3456# else
3457# error "Port me"
3458# endif
3459# else /* !IN_RING3 */
3460# ifdef RT_OS_SOLARIS
3461/** @todo Sparc kernel mode: Check the sources! */
3462# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U )
3463# else
3464# error "Port me"
3465# endif
3466# endif /* !IN_RING3 */
3467
3468#elif defined(RT_ARCH_ARM)
3469/* ASSUMES that at least the last and first 4K are out of bounds. */
3470# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U )
3471
3472#else
3473# error "Architecture identifier missing / not implemented."
3474#endif
3475
3476/** Old name for RT_VALID_PTR. */
3477#define VALID_PTR(ptr) RT_VALID_PTR(ptr)
3478
3479/** @def RT_VALID_ALIGNED_PTR
3480 * Pointer validation macro that also checks the alignment.
3481 * @param ptr The pointer.
3482 * @param align The alignment, must be a power of two.
3483 */
3484#define RT_VALID_ALIGNED_PTR(ptr, align) \
3485 ( !((uintptr_t)(ptr) & (uintptr_t)((align) - 1)) \
3486 && VALID_PTR(ptr) )
3487
3488
3489/** @def VALID_PHYS32
3490 * 32 bits physical address validation macro.
3491 * @param Phys The RTGCPHYS address.
3492 */
3493#define VALID_PHYS32(Phys) ( (uint64_t)(Phys) < (uint64_t)_4G )
3494
3495/** @def N_
3496 * The \#define N_ is used to mark a string for translation. This is usable in
3497 * any part of the code, as it is only used by the tools that create message
3498 * catalogs. This macro is a no-op as far as the compiler and code generation
3499 * is concerned.
3500 *
3501 * If you want to both mark a string for translation and translate it, use _().
3502 */
3503#define N_(s) (s)
3504
3505/** @def _
3506 * The \#define _ is used to mark a string for translation and to translate it
3507 * in one step.
3508 *
3509 * If you want to only mark a string for translation, use N_().
3510 */
3511#define _(s) gettext(s)
3512
3513
3514/** @def __PRETTY_FUNCTION__
3515 * With GNU C we'd like to use the builtin __PRETTY_FUNCTION__, so define that
3516 * for the other compilers.
3517 */
3518#if !defined(__GNUC__) && !defined(__PRETTY_FUNCTION__)
3519# ifdef _MSC_VER
3520# define __PRETTY_FUNCTION__ __FUNCSIG__
3521# else
3522# define __PRETTY_FUNCTION__ __FUNCTION__
3523# endif
3524#endif
3525
3526
3527/** @def RT_STRICT
3528 * The \#define RT_STRICT controls whether or not assertions and other runtime
3529 * checks should be compiled in or not. This is defined when DEBUG is defined.
3530 * If RT_NO_STRICT is defined, it will unconditionally be undefined.
3531 *
3532 * If you want assertions which are not subject to compile time options use
3533 * the AssertRelease*() flavors.
3534 */
3535#if !defined(RT_STRICT) && defined(DEBUG)
3536# define RT_STRICT
3537#endif
3538#ifdef RT_NO_STRICT
3539# undef RT_STRICT
3540#endif
3541
3542/** @todo remove this: */
3543#if !defined(RT_LOCK_STRICT) && !defined(DEBUG_bird)
3544# define RT_LOCK_NO_STRICT
3545#endif
3546#if !defined(RT_LOCK_STRICT_ORDER) && !defined(DEBUG_bird)
3547# define RT_LOCK_NO_STRICT_ORDER
3548#endif
3549
3550/** @def RT_LOCK_STRICT
3551 * The \#define RT_LOCK_STRICT controls whether deadlock detection and related
3552 * checks are done in the lock and semaphore code. It is by default enabled in
3553 * RT_STRICT builds, but this behavior can be overridden by defining
3554 * RT_LOCK_NO_STRICT. */
3555#if !defined(RT_LOCK_STRICT) && !defined(RT_LOCK_NO_STRICT) && defined(RT_STRICT)
3556# define RT_LOCK_STRICT
3557#endif
3558/** @def RT_LOCK_NO_STRICT
3559 * The \#define RT_LOCK_NO_STRICT disables RT_LOCK_STRICT. */
3560#if defined(RT_LOCK_NO_STRICT) && defined(RT_LOCK_STRICT)
3561# undef RT_LOCK_STRICT
3562#endif
3563
3564/** @def RT_LOCK_STRICT_ORDER
3565 * The \#define RT_LOCK_STRICT_ORDER controls whether locking order is checked
3566 * by the lock and semaphore code. It is by default enabled in RT_STRICT
3567 * builds, but this behavior can be overridden by defining
3568 * RT_LOCK_NO_STRICT_ORDER. */
3569#if !defined(RT_LOCK_STRICT_ORDER) && !defined(RT_LOCK_NO_STRICT_ORDER) && defined(RT_STRICT)
3570# define RT_LOCK_STRICT_ORDER
3571#endif
3572/** @def RT_LOCK_NO_STRICT_ORDER
3573 * The \#define RT_LOCK_NO_STRICT_ORDER disables RT_LOCK_STRICT_ORDER. */
3574#if defined(RT_LOCK_NO_STRICT_ORDER) && defined(RT_LOCK_STRICT_ORDER)
3575# undef RT_LOCK_STRICT_ORDER
3576#endif
3577
3578
3579/** Source position. */
3580#define RT_SRC_POS __FILE__, __LINE__, RT_GCC_EXTENSION __PRETTY_FUNCTION__
3581
3582/** Source position declaration. */
3583#define RT_SRC_POS_DECL const char *pszFile, unsigned iLine, const char *pszFunction
3584
3585/** Source position arguments. */
3586#define RT_SRC_POS_ARGS pszFile, iLine, pszFunction
3587
3588/** Applies NOREF() to the source position arguments. */
3589#define RT_SRC_POS_NOREF() do { NOREF(pszFile); NOREF(iLine); NOREF(pszFunction); } while (0)
3590
3591
3592/** @def RT_INLINE_ASM_EXTERNAL
3593 * Defined as 1 if the compiler does not support inline assembly.
3594 * The ASM* functions will then be implemented in external .asm files.
3595 */
3596#if (defined(_MSC_VER) && defined(RT_ARCH_AMD64)) \
3597 || (!defined(RT_ARCH_AMD64) && !defined(RT_ARCH_X86)) \
3598 || defined(__WATCOMC__)
3599# define RT_INLINE_ASM_EXTERNAL 1
3600#else
3601# define RT_INLINE_ASM_EXTERNAL 0
3602#endif
3603
3604/** @def RT_INLINE_ASM_GNU_STYLE
3605 * Defined as 1 if the compiler understands GNU style inline assembly.
3606 */
3607#if defined(_MSC_VER) || defined(__WATCOMC__)
3608# define RT_INLINE_ASM_GNU_STYLE 0
3609#else
3610# define RT_INLINE_ASM_GNU_STYLE 1
3611#endif
3612
3613/** @def RT_INLINE_ASM_USES_INTRIN
3614 * Defined as the major MSC version if the compiler have and uses intrin.h.
3615 * Otherwise it is 0. */
3616#ifdef _MSC_VER
3617# if _MSC_VER >= 1700 /* Visual C++ v11.0 / 2012 */
3618# define RT_INLINE_ASM_USES_INTRIN 17
3619# elif _MSC_VER >= 1600 /* Visual C++ v10.0 / 2010 */
3620# define RT_INLINE_ASM_USES_INTRIN 16
3621# elif _MSC_VER >= 1500 /* Visual C++ v9.0 / 2008 */
3622# define RT_INLINE_ASM_USES_INTRIN 15
3623# elif _MSC_VER >= 1400 /* Visual C++ v8.0 / 2005 */
3624# define RT_INLINE_ASM_USES_INTRIN 14
3625# endif
3626#endif
3627#ifndef RT_INLINE_ASM_USES_INTRIN
3628# define RT_INLINE_ASM_USES_INTRIN 0
3629#endif
3630
3631/** @def RT_COMPILER_SUPPORTS_LAMBDA
3632 * If the defined, the compiler supports lambda expressions. These expressions
3633 * are useful for embedding assertions and type checks into macros. */
3634#if defined(_MSC_VER) && defined(__cplusplus)
3635# if _MSC_VER >= 1600 /* Visual C++ v10.0 / 2010 */
3636# define RT_COMPILER_SUPPORTS_LAMBDA
3637# endif
3638#elif defined(__GNUC__) && defined(__cplusplus)
3639/* 4.5 or later, I think, if in ++11 mode... */
3640#endif
3641
3642/** @def RT_DATA_IS_FAR
3643 * Set to 1 if we're in 16-bit mode and use far pointers.
3644 */
3645#if ARCH_BITS == 16 && defined(__WATCOMC__) \
3646 && (defined(__COMPACT__) || defined(__LARGE__))
3647# define RT_DATA_IS_FAR 1
3648#else
3649# define RT_DATA_IS_FAR 0
3650#endif
3651
3652/** @def RT_FAR
3653 * For indicating far pointers in 16-bit code.
3654 * Does nothing in 32-bit and 64-bit code. */
3655/** @def RT_NEAR
3656 * For indicating near pointers in 16-bit code.
3657 * Does nothing in 32-bit and 64-bit code. */
3658/** @def RT_FAR_CODE
3659 * For indicating far 16-bit functions.
3660 * Does nothing in 32-bit and 64-bit code. */
3661/** @def RT_NEAR_CODE
3662 * For indicating near 16-bit functions.
3663 * Does nothing in 32-bit and 64-bit code. */
3664/** @def RT_FAR_DATA
3665 * For indicating far 16-bit external data, i.e. in a segment other than DATA16.
3666 * Does nothing in 32-bit and 64-bit code. */
3667#if ARCH_BITS == 16
3668# define RT_FAR __far
3669# define RT_NEAR __near
3670# define RT_FAR_CODE __far
3671# define RT_NEAR_CODE __near
3672# define RT_FAR_DATA __far
3673#else
3674# define RT_FAR
3675# define RT_NEAR
3676# define RT_FAR_CODE
3677# define RT_NEAR_CODE
3678# define RT_FAR_DATA
3679#endif
3680
3681
3682/** @} */
3683
3684
3685/** @defgroup grp_rt_cdefs_cpp Special Macros for C++
3686 * @ingroup grp_rt_cdefs
3687 * @{
3688 */
3689
3690#ifdef __cplusplus
3691
3692/** @def DECLEXPORT_CLASS
3693 * How to declare an exported class. Place this macro after the 'class'
3694 * keyword in the declaration of every class you want to export.
3695 *
3696 * @note It is necessary to use this macro even for inner classes declared
3697 * inside the already exported classes. This is a GCC specific requirement,
3698 * but it seems not to harm other compilers.
3699 */
3700#if defined(_MSC_VER) || defined(RT_OS_OS2)
3701# define DECLEXPORT_CLASS __declspec(dllexport)
3702#elif defined(RT_USE_VISIBILITY_DEFAULT)
3703# define DECLEXPORT_CLASS __attribute__((visibility("default")))
3704#else
3705# define DECLEXPORT_CLASS
3706#endif
3707
3708/** @def DECLIMPORT_CLASS
3709 * How to declare an imported class Place this macro after the 'class'
3710 * keyword in the declaration of every class you want to export.
3711 *
3712 * @note It is necessary to use this macro even for inner classes declared
3713 * inside the already exported classes. This is a GCC specific requirement,
3714 * but it seems not to harm other compilers.
3715 */
3716#if defined(_MSC_VER) || (defined(RT_OS_OS2) && !defined(__IBMC__) && !defined(__IBMCPP__))
3717# define DECLIMPORT_CLASS __declspec(dllimport)
3718#elif defined(RT_USE_VISIBILITY_DEFAULT)
3719# define DECLIMPORT_CLASS __attribute__((visibility("default")))
3720#else
3721# define DECLIMPORT_CLASS
3722#endif
3723
3724/** @def WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP
3725 * Macro to work around error C2593 of the not-so-smart MSVC 7.x ambiguity
3726 * resolver. The following snippet clearly demonstrates the code causing this
3727 * error:
3728 * @code
3729 * class A
3730 * {
3731 * public:
3732 * operator bool() const { return false; }
3733 * operator int*() const { return NULL; }
3734 * };
3735 * int main()
3736 * {
3737 * A a;
3738 * if (!a);
3739 * if (a && 0);
3740 * return 0;
3741 * }
3742 * @endcode
3743 * The code itself seems pretty valid to me and GCC thinks the same.
3744 *
3745 * This macro fixes the compiler error by explicitly overloading implicit
3746 * global operators !, && and || that take the given class instance as one of
3747 * their arguments.
3748 *
3749 * The best is to use this macro right after the class declaration.
3750 *
3751 * @note The macro expands to nothing for compilers other than MSVC.
3752 *
3753 * @param Cls Class to apply the workaround to
3754 */
3755#if defined(_MSC_VER)
3756# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP(Cls) \
3757 inline bool operator! (const Cls &that) { return !bool (that); } \
3758 inline bool operator&& (const Cls &that, bool b) { return bool (that) && b; } \
3759 inline bool operator|| (const Cls &that, bool b) { return bool (that) || b; } \
3760 inline bool operator&& (bool b, const Cls &that) { return b && bool (that); } \
3761 inline bool operator|| (bool b, const Cls &that) { return b || bool (that); }
3762#else
3763# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP(Cls)
3764#endif
3765
3766/** @def WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL
3767 * Version of WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP for template classes.
3768 *
3769 * @param Tpl Name of the template class to apply the workaround to
3770 * @param ArgsDecl arguments of the template, as declared in |<>| after the
3771 * |template| keyword, including |<>|
3772 * @param Args arguments of the template, as specified in |<>| after the
3773 * template class name when using the, including |<>|
3774 *
3775 * Example:
3776 * @code
3777 * // template class declaration
3778 * template <class C>
3779 * class Foo { ... };
3780 * // applied workaround
3781 * WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL (Foo, <class C>, <C>)
3782 * @endcode
3783 */
3784#if defined(_MSC_VER)
3785# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL(Tpl, ArgsDecl, Args) \
3786 template ArgsDecl \
3787 inline bool operator! (const Tpl Args &that) { return !bool (that); } \
3788 template ArgsDecl \
3789 inline bool operator&& (const Tpl Args &that, bool b) { return bool (that) && b; } \
3790 template ArgsDecl \
3791 inline bool operator|| (const Tpl Args &that, bool b) { return bool (that) || b; } \
3792 template ArgsDecl \
3793 inline bool operator&& (bool b, const Tpl Args &that) { return b && bool (that); } \
3794 template ArgsDecl \
3795 inline bool operator|| (bool b, const Tpl Args &that) { return b || bool (that); }
3796#else
3797# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL(Tpl, ArgsDecl, Args)
3798#endif
3799
3800
3801/** @def DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP
3802 * Declares the copy constructor and the assignment operation as inlined no-ops
3803 * (non-existent functions) for the given class. Use this macro inside the
3804 * private section if you want to effectively disable these operations for your
3805 * class.
3806 *
3807 * @param Cls class name to declare for
3808 */
3809#define DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(Cls) \
3810 inline Cls(const Cls &); \
3811 inline Cls &operator= (const Cls &)
3812
3813
3814/** @def DECLARE_CLS_NEW_DELETE_NOOP
3815 * Declares the new and delete operations as no-ops (non-existent functions)
3816 * for the given class. Use this macro inside the private section if you want
3817 * to effectively limit creating class instances on the stack only.
3818 *
3819 * @note The destructor of the given class must not be virtual, otherwise a
3820 * compile time error will occur. Note that this is not a drawback: having
3821 * the virtual destructor for a stack-based class is absolutely useless
3822 * (the real class of the stack-based instance is always known to the compiler
3823 * at compile time, so it will always call the correct destructor).
3824 *
3825 * @param Cls class name to declare for
3826 */
3827#define DECLARE_CLS_NEW_DELETE_NOOP(Cls) \
3828 inline static void *operator new (size_t); \
3829 inline static void operator delete (void *)
3830
3831#endif /* __cplusplus */
3832
3833/** @} */
3834
3835#endif
3836
Note: See TracBrowser for help on using the repository browser.

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