VirtualBox

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

Last change on this file since 53420 was 52565, checked in by vboxsync, 10 years ago

include/iprt/cdefs.h: try fixing the internal compiler error exposed on an OSE build on OSX host

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 92.2 KB
Line 
1/** @file
2 * IPRT - Common C and C++ definitions.
3 */
4
5/*
6 * Copyright (C) 2006-2014 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 IN_RING0
62# define IN_RING3
63# define IN_RC
64# define IN_RC
65# define IN_RT_RC
66# define IN_RT_R0
67# define IN_RT_R3
68# define IN_RT_STATIC
69# define RT_STRICT
70# define RT_NO_STRICT
71# define RT_LOCK_STRICT
72# define RT_LOCK_NO_STRICT
73# define RT_LOCK_STRICT_ORDER
74# define RT_LOCK_NO_STRICT_ORDER
75# define Breakpoint
76# define RT_NO_DEPRECATED_MACROS
77# define RT_EXCEPTIONS_ENABLED
78# define RT_BIG_ENDIAN
79# define RT_LITTLE_ENDIAN
80# define RT_COMPILER_GROKS_64BIT_BITFIELDS
81# define RT_COMPILER_WITH_80BIT_LONG_DOUBLE
82# define RT_NO_VISIBILITY_HIDDEN
83#endif /* DOXYGEN_RUNNING */
84
85/** @def RT_ARCH_X86
86 * Indicates that we're compiling for the X86 architecture.
87 */
88
89/** @def RT_ARCH_AMD64
90 * Indicates that we're compiling for the AMD64 architecture.
91 */
92
93/** @def RT_ARCH_SPARC
94 * Indicates that we're compiling for the SPARC V8 architecture (32-bit).
95 */
96
97/** @def RT_ARCH_SPARC64
98 * Indicates that we're compiling for the SPARC V9 architecture (64-bit).
99 */
100#if !defined(RT_ARCH_X86) \
101 && !defined(RT_ARCH_AMD64) \
102 && !defined(RT_ARCH_SPARC) \
103 && !defined(RT_ARCH_SPARC64) \
104 && !defined(RT_ARCH_ARM)
105# if defined(__amd64__) || defined(__x86_64__) || defined(_M_X64) || defined(__AMD64__)
106# define RT_ARCH_AMD64
107# elif defined(__i386__) || defined(_M_IX86) || defined(__X86__)
108# define RT_ARCH_X86
109# elif defined(__sparcv9)
110# define RT_ARCH_SPARC64
111# elif defined(__sparc__)
112# define RT_ARCH_SPARC
113# elif defined(__arm__) || defined(__arm32__)
114# define RT_ARCH_ARM
115# else /* PORTME: append test for new archs. */
116# error "Check what predefined macros your compiler uses to indicate architecture."
117# endif
118/* PORTME: append new archs checks. */
119#elif defined(RT_ARCH_X86) && defined(RT_ARCH_AMD64)
120# error "Both RT_ARCH_X86 and RT_ARCH_AMD64 cannot be defined at the same time!"
121#elif defined(RT_ARCH_X86) && defined(RT_ARCH_SPARC)
122# error "Both RT_ARCH_X86 and RT_ARCH_SPARC cannot be defined at the same time!"
123#elif defined(RT_ARCH_X86) && defined(RT_ARCH_SPARC64)
124# error "Both RT_ARCH_X86 and RT_ARCH_SPARC64 cannot be defined at the same time!"
125#elif defined(RT_ARCH_AMD64) && defined(RT_ARCH_SPARC)
126# error "Both RT_ARCH_AMD64 and RT_ARCH_SPARC cannot be defined at the same time!"
127#elif defined(RT_ARCH_AMD64) && defined(RT_ARCH_SPARC64)
128# error "Both RT_ARCH_AMD64 and RT_ARCH_SPARC64 cannot be defined at the same time!"
129#elif defined(RT_ARCH_SPARC) && defined(RT_ARCH_SPARC64)
130# error "Both RT_ARCH_SPARC and RT_ARCH_SPARC64 cannot be defined at the same time!"
131#elif defined(RT_ARCH_ARM) && defined(RT_ARCH_AMD64)
132# error "Both RT_ARCH_ARM and RT_ARCH_AMD64 cannot be defined at the same time!"
133#elif defined(RT_ARCH_ARM) && defined(RT_ARCH_X86)
134# error "Both RT_ARCH_ARM and RT_ARCH_X86 cannot be defined at the same time!"
135#elif defined(RT_ARCH_ARM) && defined(RT_ARCH_SPARC64)
136# error "Both RT_ARCH_ARM and RT_ARCH_SPARC64 cannot be defined at the same time!"
137#elif defined(RT_ARCH_ARM) && defined(RT_ARCH_SPARC)
138# error "Both RT_ARCH_ARM and RT_ARCH_SPARC cannot be defined at the same time!"
139#endif
140
141
142/** @def __X86__
143 * Indicates that we're compiling for the X86 architecture.
144 * @deprecated
145 */
146
147/** @def __AMD64__
148 * Indicates that we're compiling for the AMD64 architecture.
149 * @deprecated
150 */
151#if !defined(__X86__) && !defined(__AMD64__) && (defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86))
152# if defined(RT_ARCH_AMD64)
153# define __AMD64__
154# elif defined(RT_ARCH_X86)
155# define __X86__
156# else
157# error "Check what predefined macros your compiler uses to indicate architecture."
158# endif
159#elif defined(__X86__) && defined(__AMD64__)
160# error "Both __X86__ and __AMD64__ cannot be defined at the same time!"
161#elif defined(__X86__) && !defined(RT_ARCH_X86)
162# error "__X86__ without RT_ARCH_X86!"
163#elif defined(__AMD64__) && !defined(RT_ARCH_AMD64)
164# error "__AMD64__ without RT_ARCH_AMD64!"
165#endif
166
167/** @def RT_BIG_ENDIAN
168 * Defined if the architecture is big endian. */
169/** @def RT_LITTLE_ENDIAN
170 * Defined if the architecture is little endian. */
171#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86) || defined(RT_ARCH_ARM)
172# define RT_LITTLE_ENDIAN
173#elif defined(RT_ARCH_SPARC) || defined(RT_ARCH_SPARC64)
174# define RT_BIG_ENDIAN
175#else
176# error "PORTME: architecture endianess"
177#endif
178#if defined(RT_BIG_ENDIAN) && defined(RT_LITTLE_ENDIAN)
179# error "Both RT_BIG_ENDIAN and RT_LITTLE_ENDIAN are defined"
180#endif
181
182
183/** @def IN_RING0
184 * Used to indicate that we're compiling code which is running
185 * in Ring-0 Host Context.
186 */
187
188/** @def IN_RING3
189 * Used to indicate that we're compiling code which is running
190 * in Ring-3 Host Context.
191 */
192
193/** @def IN_RC
194 * Used to indicate that we're compiling code which is running
195 * in the Raw-mode Context (implies R0).
196 */
197#if !defined(IN_RING3) && !defined(IN_RING0) && !defined(IN_RC) && !defined(IN_RC)
198# error "You must define which context the compiled code should run in; IN_RING3, IN_RING0 or IN_RC"
199#endif
200#if (defined(IN_RING3) && (defined(IN_RING0) || defined(IN_RC)) ) \
201 || (defined(IN_RING0) && (defined(IN_RING3) || defined(IN_RC)) ) \
202 || (defined(IN_RC) && (defined(IN_RING3) || defined(IN_RING0)) )
203# error "Only one of the IN_RING3, IN_RING0, IN_RC defines should be defined."
204#endif
205
206
207/** @def ARCH_BITS
208 * Defines the bit count of the current context.
209 */
210#if !defined(ARCH_BITS) || defined(DOXYGEN_RUNNING)
211# if defined(RT_ARCH_AMD64) || defined(RT_ARCH_SPARC64)
212# define ARCH_BITS 64
213# else
214# define ARCH_BITS 32
215# endif
216#endif
217
218/** @def HC_ARCH_BITS
219 * Defines the host architecture bit count.
220 */
221#if !defined(HC_ARCH_BITS) || defined(DOXYGEN_RUNNING)
222# ifndef IN_RC
223# define HC_ARCH_BITS ARCH_BITS
224# else
225# define HC_ARCH_BITS 32
226# endif
227#endif
228
229/** @def GC_ARCH_BITS
230 * Defines the guest architecture bit count.
231 */
232#if !defined(GC_ARCH_BITS) && !defined(DOXYGEN_RUNNING)
233# ifdef VBOX_WITH_64_BITS_GUESTS
234# define GC_ARCH_BITS 64
235# else
236# define GC_ARCH_BITS 32
237# endif
238#endif
239
240/** @def R3_ARCH_BITS
241 * Defines the host ring-3 architecture bit count.
242 */
243#if !defined(R3_ARCH_BITS) || defined(DOXYGEN_RUNNING)
244# ifdef IN_RING3
245# define R3_ARCH_BITS ARCH_BITS
246# else
247# define R3_ARCH_BITS HC_ARCH_BITS
248# endif
249#endif
250
251/** @def R0_ARCH_BITS
252 * Defines the host ring-0 architecture bit count.
253 */
254#if !defined(R0_ARCH_BITS) || defined(DOXYGEN_RUNNING)
255# ifdef IN_RING0
256# define R0_ARCH_BITS ARCH_BITS
257# else
258# define R0_ARCH_BITS HC_ARCH_BITS
259# endif
260#endif
261
262/** @def GC_ARCH_BITS
263 * Defines the guest architecture bit count.
264 */
265#if !defined(GC_ARCH_BITS) || defined(DOXYGEN_RUNNING)
266# ifdef IN_RC
267# define GC_ARCH_BITS ARCH_BITS
268# else
269# define GC_ARCH_BITS 32
270# endif
271#endif
272
273
274
275/** @name RT_OPSYS_XXX - Operative System Identifiers.
276 * These are the value that the RT_OPSYS \#define can take. @{
277 */
278/** Unknown OS. */
279#define RT_OPSYS_UNKNOWN 0
280/** OS Agnostic. */
281#define RT_OPSYS_AGNOSTIC 1
282/** Darwin - aka Mac OS X. */
283#define RT_OPSYS_DARWIN 2
284/** DragonFly BSD. */
285#define RT_OPSYS_DRAGONFLY 3
286/** DOS. */
287#define RT_OPSYS_DOS 4
288/** FreeBSD. */
289#define RT_OPSYS_FREEBSD 5
290/** Haiku. */
291#define RT_OPSYS_HAIKU 6
292/** Linux. */
293#define RT_OPSYS_LINUX 7
294/** L4. */
295#define RT_OPSYS_L4 8
296/** Minix. */
297#define RT_OPSYS_MINIX 9
298/** NetBSD. */
299#define RT_OPSYS_NETBSD 11
300/** Netware. */
301#define RT_OPSYS_NETWARE 12
302/** NT (native). */
303#define RT_OPSYS_NT 13
304/** OpenBSD. */
305#define RT_OPSYS_OPENBSD 14
306/** OS/2. */
307#define RT_OPSYS_OS2 15
308/** Plan 9. */
309#define RT_OPSYS_PLAN9 16
310/** QNX. */
311#define RT_OPSYS_QNX 17
312/** Solaris. */
313#define RT_OPSYS_SOLARIS 18
314/** UEFI. */
315#define RT_OPSYS_UEFI 19
316/** Windows. */
317#define RT_OPSYS_WINDOWS 20
318/** The max RT_OPSYS_XXX value (exclusive). */
319#define RT_OPSYS_MAX 21
320/** @} */
321
322/** @def RT_OPSYS
323 * Indicates which OS we're targetting. It's a \#define with is
324 * assigned one of the RT_OPSYS_XXX defines above.
325 *
326 * So to test if we're on FreeBSD do the following:
327 * @code
328 * #if RT_OPSYS == RT_OPSYS_FREEBSD
329 * some_funky_freebsd_specific_stuff();
330 * #endif
331 * @endcode
332 */
333
334/*
335 * Set RT_OPSYS_XXX according to RT_OS_XXX.
336 *
337 * Search: #define RT_OPSYS_([A-Z0-9]+) .*
338 * Replace: # elif defined(RT_OS_\1)\n# define RT_OPSYS RT_OPSYS_\1
339 */
340#ifndef RT_OPSYS
341# if defined(RT_OS_UNKNOWN)
342# define RT_OPSYS RT_OPSYS_UNKNOWN
343# elif defined(RT_OS_AGNOSTIC)
344# define RT_OPSYS RT_OPSYS_AGNOSTIC
345# elif defined(RT_OS_DARWIN)
346# define RT_OPSYS RT_OPSYS_DARWIN
347# elif defined(RT_OS_DRAGONFLY)
348# define RT_OPSYS RT_OPSYS_DRAGONFLY
349# elif defined(RT_OS_DOS)
350# define RT_OPSYS RT_OPSYS_DOS
351# elif defined(RT_OS_FREEBSD)
352# define RT_OPSYS RT_OPSYS_FREEBSD
353# elif defined(RT_OS_HAIKU)
354# define RT_OPSYS RT_OPSYS_HAIKU
355# elif defined(RT_OS_LINUX)
356# define RT_OPSYS RT_OPSYS_LINUX
357# elif defined(RT_OS_L4)
358# define RT_OPSYS RT_OPSYS_L4
359# elif defined(RT_OS_MINIX)
360# define RT_OPSYS RT_OPSYS_MINIX
361# elif defined(RT_OS_NETBSD)
362# define RT_OPSYS RT_OPSYS_NETBSD
363# elif defined(RT_OS_NETWARE)
364# define RT_OPSYS RT_OPSYS_NETWARE
365# elif defined(RT_OS_NT)
366# define RT_OPSYS RT_OPSYS_NT
367# elif defined(RT_OS_OPENBSD)
368# define RT_OPSYS RT_OPSYS_OPENBSD
369# elif defined(RT_OS_OS2)
370# define RT_OPSYS RT_OPSYS_OS2
371# elif defined(RT_OS_PLAN9)
372# define RT_OPSYS RT_OPSYS_PLAN9
373# elif defined(RT_OS_QNX)
374# define RT_OPSYS RT_OPSYS_QNX
375# elif defined(RT_OS_SOLARIS)
376# define RT_OPSYS RT_OPSYS_SOLARIS
377# elif defined(RT_OS_UEFI)
378# define RT_OPSYS RT_OPSYS_UEFI
379# elif defined(RT_OS_WINDOWS)
380# define RT_OPSYS RT_OPSYS_WINDOWS
381# endif
382#endif
383
384/*
385 * Guess RT_OPSYS based on compiler predefined macros.
386 */
387#ifndef RT_OPSYS
388# if defined(__APPLE__)
389# define RT_OPSYS RT_OPSYS_DARWIN
390# elif defined(__DragonFly__)
391# define RT_OPSYS RT_OPSYS_DRAGONFLY
392# elif defined(__FreeBSD__) /*??*/
393# define RT_OPSYS RT_OPSYS_FREEBSD
394# elif defined(__gnu_linux__)
395# define RT_OPSYS RT_OPSYS_LINUX
396# elif defined(__NetBSD__) /*??*/
397# define RT_OPSYS RT_OPSYS_NETBSD
398# elif defined(__OpenBSD__) /*??*/
399# define RT_OPSYS RT_OPSYS_OPENBSD
400# elif defined(__OS2__)
401# define RT_OPSYS RT_OPSYS_OS2
402# elif defined(__sun__) || defined(__SunOS__) || defined(__sun) || defined(__SunOS)
403# define RT_OPSYS RT_OPSYS_SOLARIS
404# elif defined(_WIN32) || defined(_WIN64)
405# define RT_OPSYS RT_OPSYS_WINDOWS
406# else
407# error "Port Me"
408# endif
409#endif
410
411#if RT_OPSYS < RT_OPSYS_UNKNOWN || RT_OPSYS >= RT_OPSYS_MAX
412# error "Invalid RT_OPSYS value."
413#endif
414
415/*
416 * Do some consistency checks.
417 *
418 * Search: #define RT_OPSYS_([A-Z0-9]+) .*
419 * Replace: #if defined(RT_OS_\1) && RT_OPSYS != RT_OPSYS_\1\n# error RT_OPSYS vs RT_OS_\1\n#endif
420 */
421#if defined(RT_OS_UNKNOWN) && RT_OPSYS != RT_OPSYS_UNKNOWN
422# error RT_OPSYS vs RT_OS_UNKNOWN
423#endif
424#if defined(RT_OS_AGNOSTIC) && RT_OPSYS != RT_OPSYS_AGNOSTIC
425# error RT_OPSYS vs RT_OS_AGNOSTIC
426#endif
427#if defined(RT_OS_DARWIN) && RT_OPSYS != RT_OPSYS_DARWIN
428# error RT_OPSYS vs RT_OS_DARWIN
429#endif
430#if defined(RT_OS_DRAGONFLY) && RT_OPSYS != RT_OPSYS_DRAGONFLY
431# error RT_OPSYS vs RT_OS_DRAGONFLY
432#endif
433#if defined(RT_OS_DOS) && RT_OPSYS != RT_OPSYS_DOS
434# error RT_OPSYS vs RT_OS_DOS
435#endif
436#if defined(RT_OS_FREEBSD) && RT_OPSYS != RT_OPSYS_FREEBSD
437# error RT_OPSYS vs RT_OS_FREEBSD
438#endif
439#if defined(RT_OS_HAIKU) && RT_OPSYS != RT_OPSYS_HAIKU
440# error RT_OPSYS vs RT_OS_HAIKU
441#endif
442#if defined(RT_OS_LINUX) && RT_OPSYS != RT_OPSYS_LINUX
443# error RT_OPSYS vs RT_OS_LINUX
444#endif
445#if defined(RT_OS_L4) && RT_OPSYS != RT_OPSYS_L4
446# error RT_OPSYS vs RT_OS_L4
447#endif
448#if defined(RT_OS_MINIX) && RT_OPSYS != RT_OPSYS_MINIX
449# error RT_OPSYS vs RT_OS_MINIX
450#endif
451#if defined(RT_OS_NETBSD) && RT_OPSYS != RT_OPSYS_NETBSD
452# error RT_OPSYS vs RT_OS_NETBSD
453#endif
454#if defined(RT_OS_NETWARE) && RT_OPSYS != RT_OPSYS_NETWARE
455# error RT_OPSYS vs RT_OS_NETWARE
456#endif
457#if defined(RT_OS_NT) && RT_OPSYS != RT_OPSYS_NT
458# error RT_OPSYS vs RT_OS_NT
459#endif
460#if defined(RT_OS_OPENBSD) && RT_OPSYS != RT_OPSYS_OPENBSD
461# error RT_OPSYS vs RT_OS_OPENBSD
462#endif
463#if defined(RT_OS_OS2) && RT_OPSYS != RT_OPSYS_OS2
464# error RT_OPSYS vs RT_OS_OS2
465#endif
466#if defined(RT_OS_PLAN9) && RT_OPSYS != RT_OPSYS_PLAN9
467# error RT_OPSYS vs RT_OS_PLAN9
468#endif
469#if defined(RT_OS_QNX) && RT_OPSYS != RT_OPSYS_QNX
470# error RT_OPSYS vs RT_OS_QNX
471#endif
472#if defined(RT_OS_SOLARIS) && RT_OPSYS != RT_OPSYS_SOLARIS
473# error RT_OPSYS vs RT_OS_SOLARIS
474#endif
475#if defined(RT_OS_UEFI) && RT_OPSYS != RT_OPSYS_UEFI
476# error RT_OPSYS vs RT_OS_UEFI
477#endif
478#if defined(RT_OS_WINDOWS) && RT_OPSYS != RT_OPSYS_WINDOWS
479# error RT_OPSYS vs RT_OS_WINDOWS
480#endif
481
482/*
483 * Make sure the RT_OS_XXX macro is defined.
484 *
485 * Search: #define RT_OPSYS_([A-Z0-9]+) .*
486 * Replace: #elif RT_OPSYS == RT_OPSYS_\1\n# ifndef RT_OS_\1\n# define RT_OS_\1\n# endif
487 */
488#if RT_OPSYS == RT_OPSYS_UNKNOWN
489# ifndef RT_OS_UNKNOWN
490# define RT_OS_UNKNOWN
491# endif
492#elif RT_OPSYS == RT_OPSYS_AGNOSTIC
493# ifndef RT_OS_AGNOSTIC
494# define RT_OS_AGNOSTIC
495# endif
496#elif RT_OPSYS == RT_OPSYS_DARWIN
497# ifndef RT_OS_DARWIN
498# define RT_OS_DARWIN
499# endif
500#elif RT_OPSYS == RT_OPSYS_DRAGONFLY
501# ifndef RT_OS_DRAGONFLY
502# define RT_OS_DRAGONFLY
503# endif
504#elif RT_OPSYS == RT_OPSYS_DOS
505# ifndef RT_OS_DOS
506# define RT_OS_DOS
507# endif
508#elif RT_OPSYS == RT_OPSYS_FREEBSD
509# ifndef RT_OS_FREEBSD
510# define RT_OS_FREEBSD
511# endif
512#elif RT_OPSYS == RT_OPSYS_HAIKU
513# ifndef RT_OS_HAIKU
514# define RT_OS_HAIKU
515# endif
516#elif RT_OPSYS == RT_OPSYS_LINUX
517# ifndef RT_OS_LINUX
518# define RT_OS_LINUX
519# endif
520#elif RT_OPSYS == RT_OPSYS_L4
521# ifndef RT_OS_L4
522# define RT_OS_L4
523# endif
524#elif RT_OPSYS == RT_OPSYS_MINIX
525# ifndef RT_OS_MINIX
526# define RT_OS_MINIX
527# endif
528#elif RT_OPSYS == RT_OPSYS_NETBSD
529# ifndef RT_OS_NETBSD
530# define RT_OS_NETBSD
531# endif
532#elif RT_OPSYS == RT_OPSYS_NETWARE
533# ifndef RT_OS_NETWARE
534# define RT_OS_NETWARE
535# endif
536#elif RT_OPSYS == RT_OPSYS_NT
537# ifndef RT_OS_NT
538# define RT_OS_NT
539# endif
540#elif RT_OPSYS == RT_OPSYS_OPENBSD
541# ifndef RT_OS_OPENBSD
542# define RT_OS_OPENBSD
543# endif
544#elif RT_OPSYS == RT_OPSYS_OS2
545# ifndef RT_OS_OS2
546# define RT_OS_OS2
547# endif
548#elif RT_OPSYS == RT_OPSYS_PLAN9
549# ifndef RT_OS_PLAN9
550# define RT_OS_PLAN9
551# endif
552#elif RT_OPSYS == RT_OPSYS_QNX
553# ifndef RT_OS_QNX
554# define RT_OS_QNX
555# endif
556#elif RT_OPSYS == RT_OPSYS_SOLARIS
557# ifndef RT_OS_SOLARIS
558# define RT_OS_SOLARIS
559# endif
560#elif RT_OPSYS == RT_OPSYS_UEFI
561# ifndef RT_OS_UEFI
562# define RT_OS_UEFI
563# endif
564#elif RT_OPSYS == RT_OPSYS_WINDOWS
565# ifndef RT_OS_WINDOWS
566# define RT_OS_WINDOWS
567# endif
568#else
569# error "Bad RT_OPSYS value."
570#endif
571
572
573/**
574 * Checks whether the given OpSys uses DOS-style paths or not.
575 *
576 * By DOS-style paths we include drive lettering and UNC paths.
577 *
578 * @returns true / false
579 * @param a_OpSys The RT_OPSYS_XXX value to check, will be reference
580 * multiple times.
581 */
582#define RT_OPSYS_USES_DOS_PATHS(a_OpSys) \
583 ( (a_OpSys) == RT_OPSYS_WINDOWS \
584 || (a_OpSys) == RT_OPSYS_OS2 \
585 || (a_OpSys) == RT_OPSYS_DOS )
586
587
588
589/** @def CTXTYPE
590 * Declare a type differently in GC, R3 and R0.
591 *
592 * @param GCType The GC type.
593 * @param R3Type The R3 type.
594 * @param R0Type The R0 type.
595 * @remark For pointers used only in one context use RCPTRTYPE(), R3R0PTRTYPE(), R3PTRTYPE() or R0PTRTYPE().
596 */
597#ifdef IN_RC
598# define CTXTYPE(GCType, R3Type, R0Type) GCType
599#elif defined(IN_RING3)
600# define CTXTYPE(GCType, R3Type, R0Type) R3Type
601#else
602# define CTXTYPE(GCType, R3Type, R0Type) R0Type
603#endif
604
605/** @def RCPTRTYPE
606 * Declare a pointer which is used in the raw mode context but appears in structure(s) used by
607 * both HC and RC. The main purpose is to make sure structures have the same
608 * size when built for different architectures.
609 *
610 * @param RCType The RC type.
611 */
612#define RCPTRTYPE(RCType) CTXTYPE(RCType, RTRCPTR, RTRCPTR)
613
614/** @def R3R0PTRTYPE
615 * Declare a pointer which is used in HC, is explicitly valid in ring 3 and 0,
616 * but appears in structure(s) used by both HC and GC. The main purpose is to
617 * make sure structures have the same size when built for different architectures.
618 *
619 * @param R3R0Type The R3R0 type.
620 * @remarks This used to be called HCPTRTYPE.
621 */
622#define R3R0PTRTYPE(R3R0Type) CTXTYPE(RTHCPTR, R3R0Type, R3R0Type)
623
624/** @def R3PTRTYPE
625 * Declare a pointer which is used in R3 but appears in structure(s) used by
626 * both HC and GC. The main purpose is to make sure structures have the same
627 * size when built for different architectures.
628 *
629 * @param R3Type The R3 type.
630 */
631#define R3PTRTYPE(R3Type) CTXTYPE(RTHCUINTPTR, R3Type, RTHCUINTPTR)
632
633/** @def R0PTRTYPE
634 * Declare a pointer which is used in R0 but appears in structure(s) used by
635 * both HC and GC. The main purpose is to make sure structures have the same
636 * size when built for different architectures.
637 *
638 * @param R0Type The R0 type.
639 */
640#define R0PTRTYPE(R0Type) CTXTYPE(RTHCUINTPTR, RTHCUINTPTR, R0Type)
641
642/** @def CTXSUFF
643 * Adds the suffix of the current context to the passed in
644 * identifier name. The suffix is HC or GC.
645 *
646 * This is macro should only be used in shared code to avoid a forest of ifdefs.
647 * @param var Identifier name.
648 * @deprecated Use CTX_SUFF. Do NOT use this for new code.
649 */
650/** @def OTHERCTXSUFF
651 * Adds the suffix of the other context to the passed in
652 * identifier name. The suffix is HC or GC.
653 *
654 * This is macro should only be used in shared code to avoid a forest of ifdefs.
655 * @param var Identifier name.
656 * @deprecated Use CTX_SUFF. Do NOT use this for new code.
657 */
658#ifdef IN_RC
659# define CTXSUFF(var) var##GC
660# define OTHERCTXSUFF(var) var##HC
661#else
662# define CTXSUFF(var) var##HC
663# define OTHERCTXSUFF(var) var##GC
664#endif
665
666/** @def CTXALLSUFF
667 * Adds the suffix of the current context to the passed in
668 * identifier name. The suffix is R3, R0 or GC.
669 *
670 * This is macro should only be used in shared code to avoid a forest of ifdefs.
671 * @param var Identifier name.
672 * @deprecated Use CTX_SUFF. Do NOT use this for new code.
673 */
674#ifdef IN_RC
675# define CTXALLSUFF(var) var##GC
676#elif defined(IN_RING0)
677# define CTXALLSUFF(var) var##R0
678#else
679# define CTXALLSUFF(var) var##R3
680#endif
681
682/** @def CTX_SUFF
683 * Adds the suffix of the current context to the passed in
684 * identifier name. The suffix is R3, R0 or RC.
685 *
686 * This is macro should only be used in shared code to avoid a forest of ifdefs.
687 * @param var Identifier name.
688 *
689 * @remark This will replace CTXALLSUFF and CTXSUFF before long.
690 */
691#ifdef IN_RC
692# define CTX_SUFF(var) var##RC
693#elif defined(IN_RING0)
694# define CTX_SUFF(var) var##R0
695#else
696# define CTX_SUFF(var) var##R3
697#endif
698
699/** @def CTX_SUFF_Z
700 * Adds the suffix of the current context to the passed in
701 * identifier name, combining RC and R0 into RZ.
702 * The suffix thus is R3 or RZ.
703 *
704 * This is macro should only be used in shared code to avoid a forest of ifdefs.
705 * @param var Identifier name.
706 *
707 * @remark This will replace CTXALLSUFF and CTXSUFF before long.
708 */
709#ifdef IN_RING3
710# define CTX_SUFF_Z(var) var##R3
711#else
712# define CTX_SUFF_Z(var) var##RZ
713#endif
714
715
716/** @def CTXMID
717 * Adds the current context as a middle name of an identifier name
718 * The middle name is HC or GC.
719 *
720 * This is macro should only be used in shared code to avoid a forest of ifdefs.
721 * @param first First name.
722 * @param last Surname.
723 */
724/** @def OTHERCTXMID
725 * Adds the other context as a middle name of an identifier name
726 * The middle name is HC or GC.
727 *
728 * This is macro should only be used in shared code to avoid a forest of ifdefs.
729 * @param first First name.
730 * @param last Surname.
731 * @deprecated use CTX_MID or CTX_MID_Z
732 */
733#ifdef IN_RC
734# define CTXMID(first, last) first##GC##last
735# define OTHERCTXMID(first, last) first##HC##last
736#else
737# define CTXMID(first, last) first##HC##last
738# define OTHERCTXMID(first, last) first##GC##last
739#endif
740
741/** @def CTXALLMID
742 * Adds the current context as a middle name of an identifier name.
743 * The middle name is R3, R0 or GC.
744 *
745 * This is macro should only be used in shared code to avoid a forest of ifdefs.
746 * @param first First name.
747 * @param last Surname.
748 * @deprecated use CTX_MID or CTX_MID_Z
749 */
750#ifdef IN_RC
751# define CTXALLMID(first, last) first##GC##last
752#elif defined(IN_RING0)
753# define CTXALLMID(first, last) first##R0##last
754#else
755# define CTXALLMID(first, last) first##R3##last
756#endif
757
758/** @def CTX_MID
759 * Adds the current context as a middle name of an identifier name.
760 * The middle name is R3, R0 or RC.
761 *
762 * This is macro should only be used in shared code to avoid a forest of ifdefs.
763 * @param first First name.
764 * @param last Surname.
765 */
766#ifdef IN_RC
767# define CTX_MID(first, last) first##RC##last
768#elif defined(IN_RING0)
769# define CTX_MID(first, last) first##R0##last
770#else
771# define CTX_MID(first, last) first##R3##last
772#endif
773
774/** @def CTX_MID_Z
775 * Adds the current context as a middle name of an identifier name, combining RC
776 * and R0 into RZ.
777 * The middle name thus is either R3 or RZ.
778 *
779 * This is macro should only be used in shared code to avoid a forest of ifdefs.
780 * @param first First name.
781 * @param last Surname.
782 */
783#ifdef IN_RING3
784# define CTX_MID_Z(first, last) first##R3##last
785#else
786# define CTX_MID_Z(first, last) first##RZ##last
787#endif
788
789
790/** @def R3STRING
791 * A macro which in GC and R0 will return a dummy string while in R3 it will return
792 * the parameter.
793 *
794 * This is typically used to wrap description strings in structures shared
795 * between R3, R0 and/or GC. The intention is to avoid the \#ifdef IN_RING3 mess.
796 *
797 * @param pR3String The R3 string. Only referenced in R3.
798 * @see R0STRING and GCSTRING
799 */
800#ifdef IN_RING3
801# define R3STRING(pR3String) (pR3String)
802#else
803# define R3STRING(pR3String) ("<R3_STRING>")
804#endif
805
806/** @def R0STRING
807 * A macro which in GC and R3 will return a dummy string while in R0 it will return
808 * the parameter.
809 *
810 * This is typically used to wrap description strings in structures shared
811 * between R3, R0 and/or GC. The intention is to avoid the \#ifdef IN_RING0 mess.
812 *
813 * @param pR0String The R0 string. Only referenced in R0.
814 * @see R3STRING and GCSTRING
815 */
816#ifdef IN_RING0
817# define R0STRING(pR0String) (pR0String)
818#else
819# define R0STRING(pR0String) ("<R0_STRING>")
820#endif
821
822/** @def RCSTRING
823 * A macro which in R3 and R0 will return a dummy string while in RC it will return
824 * the parameter.
825 *
826 * This is typically used to wrap description strings in structures shared
827 * between R3, R0 and/or RC. The intention is to avoid the \#ifdef IN_RC mess.
828 *
829 * @param pRCString The RC string. Only referenced in RC.
830 * @see R3STRING, R0STRING
831 */
832#ifdef IN_RC
833# define RCSTRING(pRCString) (pRCString)
834#else
835# define RCSTRING(pRCString) ("<RC_STRING>")
836#endif
837
838
839/** @def RT_NOTHING
840 * A macro that expands to nothing.
841 * This is primarily intended as a dummy argument for macros to avoid the
842 * undefined behavior passing empty arguments to an macro (ISO C90 and C++98,
843 * gcc v4.4 warns about it).
844 */
845#define RT_NOTHING
846
847/** @def RT_GCC_EXTENSION
848 * Macro for shutting up GCC warnings about using language extensions. */
849#ifdef __GNUC__
850# define RT_GCC_EXTENSION __extension__
851#else
852# define RT_GCC_EXTENSION
853#endif
854
855/** @def RT_COMPILER_GROKS_64BIT_BITFIELDS
856 * Macro that is defined if the compiler understands 64-bit bitfields. */
857#if !defined(RT_OS_OS2) || (!defined(__IBMC__) && !defined(__IBMCPP__))
858# define RT_COMPILER_GROKS_64BIT_BITFIELDS
859#endif
860
861/** @def RT_COMPILER_WITH_80BIT_LONG_DOUBLE
862 * Macro that is defined if the compiler implements long double as the
863 * IEEE extended precision floating. */
864#if (defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)) && !defined(RT_OS_WINDOWS)
865# define RT_COMPILER_WITH_80BIT_LONG_DOUBLE
866#endif
867
868
869/** @def RT_EXCEPTIONS_ENABLED
870 * Defined when C++ exceptions are enabled.
871 */
872#if !defined(RT_EXCEPTIONS_ENABLED) \
873 && defined(__cplusplus) \
874 && ( (defined(_MSC_VER) && defined(_CPPUNWIND)) \
875 || (defined(__GNUC__) && defined(__EXCEPTIONS)))
876# define RT_EXCEPTIONS_ENABLED
877#endif
878
879/** @def RT_NO_THROW
880 * How to express that a function doesn't throw C++ exceptions
881 * and the compiler can thus save itself the bother of trying
882 * to catch any of them. Put this between the closing parenthesis
883 * and the semicolon in function prototypes (and implementation if C++).
884 */
885#ifdef RT_EXCEPTIONS_ENABLED
886# define RT_NO_THROW throw()
887#else
888# define RT_NO_THROW
889#endif
890
891/** @def RT_THROW
892 * How to express that a method or function throws a type of exceptions. Some
893 * compilers does not want this kind of information and will warning about it.
894 *
895 * @param type The type exception.
896 *
897 * @remarks If the actual throwing is done from the header, enclose it by
898 * \#ifdef RT_EXCEPTIONS_ENABLED ... \#else ... \#endif so the header
899 * compiles cleanly without exceptions enabled.
900 *
901 * Do NOT use this for the actual throwing of exceptions!
902 */
903#ifdef RT_EXCEPTIONS_ENABLED
904# ifdef _MSC_VER
905# if _MSC_VER >= 1310
906# define RT_THROW(type)
907# else
908# define RT_THROW(type) throw(type)
909# endif
910# else
911# define RT_THROW(type) throw(type)
912# endif
913#else
914# define RT_THROW(type)
915#endif
916
917/** @def RT_GCC_SUPPORTS_VISIBILITY_HIDDEN
918 * Indicates that the "hidden" visibility attribute can be used (GCC) */
919#if defined(__GNUC__)
920# if __GNUC__ >= 4 && !defined(RT_OS_OS2) && !defined(RT_OS_WINDOWS)
921# define RT_GCC_SUPPORTS_VISIBILITY_HIDDEN
922# endif
923#endif
924
925/** @def RTCALL
926 * The standard calling convention for the Runtime interfaces.
927 */
928#ifdef _MSC_VER
929# define RTCALL __cdecl
930#elif defined(RT_OS_OS2)
931# define RTCALL __cdecl
932#elif defined(__GNUC__) && defined(IN_RING0) && defined(RT_ARCH_X86) /** @todo consider dropping IN_RING0 here. */
933# define RTCALL __attribute__((cdecl,regparm(0))) /* regparm(0) deals with -mregparm=x use in the linux kernel. */
934#else
935# define RTCALL
936#endif
937
938/** @def DECLEXPORT
939 * How to declare an exported function.
940 * @param type The return type of the function declaration.
941 */
942#if defined(_MSC_VER) || defined(RT_OS_OS2)
943# define DECLEXPORT(type) __declspec(dllexport) type
944#elif defined(RT_USE_VISIBILITY_DEFAULT)
945# define DECLEXPORT(type) __attribute__((visibility("default"))) type
946#else
947# define DECLEXPORT(type) type
948#endif
949
950/** @def DECLIMPORT
951 * How to declare an imported function.
952 * @param type The return type of the function declaration.
953 */
954#if defined(_MSC_VER) || (defined(RT_OS_OS2) && !defined(__IBMC__) && !defined(__IBMCPP__))
955# define DECLIMPORT(type) __declspec(dllimport) type
956#else
957# define DECLIMPORT(type) type
958#endif
959
960/** @def DECLHIDDEN
961 * How to declare a non-exported function or variable.
962 * @param type The return type of the function or the data type of the variable.
963 */
964#if !defined(RT_GCC_SUPPORTS_VISIBILITY_HIDDEN) || defined(RT_NO_VISIBILITY_HIDDEN)
965# define DECLHIDDEN(type) type
966#else
967# define DECLHIDDEN(type) __attribute__((visibility("hidden"))) type
968#endif
969
970/** @def DECL_HIDDEN_CONST
971 * Workaround for g++ warnings when applying the hidden attribute to a const
972 * definition. Use DECLHIDDEN for the declaration.
973 * @param a_Type The return type of the function or the data type of
974 * the variable.
975 */
976#if defined(__cplusplus) && defined(__GNUC__)
977# define DECL_HIDDEN_CONST(a_Type) a_Type
978#else
979# define DECL_HIDDEN_CONST(a_Type) DECLHIDDEN(a_Type)
980#endif
981
982/** @def DECL_INVALID
983 * How to declare a function not available for linking in the current context.
984 * The purpose is to create compile or like time errors when used. This isn't
985 * possible on all platforms.
986 * @param type The return type of the function.
987 */
988#if defined(_MSC_VER)
989# define DECL_INVALID(type) __declspec(dllimport) type __stdcall
990#elif defined(__GNUC__) && defined(__cplusplus)
991# define DECL_INVALID(type) extern "C++" type
992#else
993# define DECL_INVALID(type) type
994#endif
995
996/** @def DECLASM
997 * How to declare an internal assembly function.
998 * @param type The return type of the function declaration.
999 */
1000#ifdef __cplusplus
1001# if defined(_MSC_VER) || defined(RT_OS_OS2)
1002# define DECLASM(type) extern "C" type __cdecl
1003# elif defined(__GNUC__) && defined(RT_ARCH_X86)
1004# define DECLASM(type) extern "C" type __attribute__((cdecl,regparm(0)))
1005# else
1006# define DECLASM(type) extern "C" type
1007# endif
1008#else
1009# if defined(_MSC_VER) || defined(RT_OS_OS2)
1010# define DECLASM(type) type __cdecl
1011# elif defined(__GNUC__) && defined(RT_ARCH_X86)
1012# define DECLASM(type) type __attribute__((cdecl,regparm(0)))
1013# else
1014# define DECLASM(type) type
1015# endif
1016#endif
1017
1018/** @def DECLASMTYPE
1019 * How to declare an internal assembly function type.
1020 * @param type The return type of the function.
1021 */
1022# if defined(_MSC_VER) || defined(RT_OS_OS2)
1023# define DECLASMTYPE(type) type __cdecl
1024#else
1025# define DECLASMTYPE(type) type
1026#endif
1027
1028/** @def DECLNORETURN
1029 * How to declare a function which does not return.
1030 * @note: This macro can be combined with other macros, for example
1031 * @code
1032 * EMR3DECL(DECLNORETURN(void)) foo(void);
1033 * @endcode
1034 */
1035#ifdef _MSC_VER
1036# define DECLNORETURN(type) __declspec(noreturn) type
1037#elif defined(__GNUC__)
1038# define DECLNORETURN(type) __attribute__((noreturn)) type
1039#else
1040# define DECLNORETURN(type) type
1041#endif
1042
1043/** @def DECLWEAK
1044 * How to declare a variable which is not necessarily resolved at
1045 * runtime.
1046 * @note: This macro can be combined with other macros, for example
1047 * @code
1048 * EMR3DECL(DECLWEAK(int)) foo;
1049 * @endcode
1050 */
1051#if defined(__GNUC__)
1052# define DECLWEAK(type) type __attribute__((weak))
1053#else
1054# define DECLWEAK(type) type
1055#endif
1056
1057/** @def DECLCALLBACK
1058 * How to declare an call back function type.
1059 * @param type The return type of the function declaration.
1060 */
1061#define DECLCALLBACK(type) type RTCALL
1062
1063/** @def DECLCALLBACKPTR
1064 * How to declare an call back function pointer.
1065 * @param type The return type of the function declaration.
1066 * @param name The name of the variable member.
1067 */
1068#if defined(__IBMC__) || defined(__IBMCPP__)
1069# define DECLCALLBACKPTR(type, name) type (* RTCALL name)
1070#else
1071# define DECLCALLBACKPTR(type, name) type (RTCALL * name)
1072#endif
1073
1074/** @def DECLCALLBACKMEMBER
1075 * How to declare an call back function pointer member.
1076 * @param type The return type of the function declaration.
1077 * @param name The name of the struct/union/class member.
1078 */
1079#if defined(__IBMC__) || defined(__IBMCPP__)
1080# define DECLCALLBACKMEMBER(type, name) type (* RTCALL name)
1081#else
1082# define DECLCALLBACKMEMBER(type, name) type (RTCALL * name)
1083#endif
1084
1085/** @def DECLR3CALLBACKMEMBER
1086 * How to declare an call back function pointer member - R3 Ptr.
1087 * @param type The return type of the function declaration.
1088 * @param name The name of the struct/union/class member.
1089 * @param args The argument list enclosed in parentheses.
1090 */
1091#ifdef IN_RING3
1092# define DECLR3CALLBACKMEMBER(type, name, args) DECLCALLBACKMEMBER(type, name) args
1093#else
1094# define DECLR3CALLBACKMEMBER(type, name, args) RTR3PTR name
1095#endif
1096
1097/** @def DECLRCCALLBACKMEMBER
1098 * How to declare an call back function pointer member - RC Ptr.
1099 * @param type The return type of the function declaration.
1100 * @param name The name of the struct/union/class member.
1101 * @param args The argument list enclosed in parentheses.
1102 */
1103#ifdef IN_RC
1104# define DECLRCCALLBACKMEMBER(type, name, args) DECLCALLBACKMEMBER(type, name) args
1105#else
1106# define DECLRCCALLBACKMEMBER(type, name, args) RTRCPTR name
1107#endif
1108
1109/** @def DECLR0CALLBACKMEMBER
1110 * How to declare an call back function pointer member - R0 Ptr.
1111 * @param type The return type of the function declaration.
1112 * @param name The name of the struct/union/class member.
1113 * @param args The argument list enclosed in parentheses.
1114 */
1115#ifdef IN_RING0
1116# define DECLR0CALLBACKMEMBER(type, name, args) DECLCALLBACKMEMBER(type, name) args
1117#else
1118# define DECLR0CALLBACKMEMBER(type, name, args) RTR0PTR name
1119#endif
1120
1121/** @def DECLINLINE
1122 * How to declare a function as inline.
1123 * @param type The return type of the function declaration.
1124 * @remarks Don't use this macro on C++ methods.
1125 */
1126#ifdef __GNUC__
1127# define DECLINLINE(type) static __inline__ type
1128#elif defined(__cplusplus)
1129# define DECLINLINE(type) inline type
1130#elif defined(_MSC_VER)
1131# define DECLINLINE(type) _inline type
1132#elif defined(__IBMC__)
1133# define DECLINLINE(type) _Inline type
1134#else
1135# define DECLINLINE(type) inline type
1136#endif
1137
1138
1139/** @def DECL_FORCE_INLINE
1140 * How to declare a function as inline and try convince the compiler to always
1141 * inline it regardless of optimization switches.
1142 * @param type The return type of the function declaration.
1143 * @remarks Use sparsely and with care. Don't use this macro on C++ methods.
1144 */
1145#ifdef __GNUC__
1146# define DECL_FORCE_INLINE(type) __attribute__((__always_inline__)) DECLINLINE(type)
1147#elif defined(_MSC_VER)
1148# define DECL_FORCE_INLINE(type) __forceinline type
1149#else
1150# define DECL_FORCE_INLINE(type) DECLINLINE(type)
1151#endif
1152
1153
1154/** @def DECL_NO_INLINE
1155 * How to declare a function telling the compiler not to inline it.
1156 * @param scope The function scope, static or RT_NOTHING.
1157 * @param type The return type of the function declaration.
1158 * @remarks Don't use this macro on C++ methods.
1159 */
1160#ifdef __GNUC__
1161# define DECL_NO_INLINE(scope,type) __attribute__((noinline)) scope type
1162#elif defined(_MSC_VER)
1163# define DECL_NO_INLINE(scope,type) __declspec(noinline) scope type
1164#else
1165# define DECL_NO_INLINE(scope,type) scope type
1166#endif
1167
1168
1169/** @def IN_RT_STATIC
1170 * Used to indicate whether we're linking against a static IPRT
1171 * or not. The IPRT symbols will be declared as hidden (if
1172 * supported). Note that this define has no effect without setting
1173 * IN_RT_R0, IN_RT_R3 or IN_RT_RC indicators are set first.
1174 */
1175
1176/** @def IN_RT_R0
1177 * Used to indicate whether we're inside the same link module as
1178 * the HC Ring-0 Runtime Library.
1179 */
1180/** @def RTR0DECL(type)
1181 * Runtime Library HC Ring-0 export or import declaration.
1182 * @param type The return type of the function declaration.
1183 */
1184#ifdef IN_RT_R0
1185# ifdef IN_RT_STATIC
1186# define RTR0DECL(type) DECLHIDDEN(type) RTCALL
1187# else
1188# define RTR0DECL(type) DECLEXPORT(type) RTCALL
1189# endif
1190#else
1191# define RTR0DECL(type) DECLIMPORT(type) RTCALL
1192#endif
1193
1194/** @def IN_RT_R3
1195 * Used to indicate whether we're inside the same link module as
1196 * the HC Ring-3 Runtime Library.
1197 */
1198/** @def RTR3DECL(type)
1199 * Runtime Library HC Ring-3 export or import declaration.
1200 * @param type The return type of the function declaration.
1201 */
1202#ifdef IN_RT_R3
1203# ifdef IN_RT_STATIC
1204# define RTR3DECL(type) DECLHIDDEN(type) RTCALL
1205# else
1206# define RTR3DECL(type) DECLEXPORT(type) RTCALL
1207# endif
1208#else
1209# define RTR3DECL(type) DECLIMPORT(type) RTCALL
1210#endif
1211
1212/** @def IN_RT_RC
1213 * Used to indicate whether we're inside the same link module as the raw-mode
1214 * context (RC) runtime library.
1215 */
1216/** @def RTRCDECL(type)
1217 * Runtime Library raw-mode context export or import declaration.
1218 * @param type The return type of the function declaration.
1219 */
1220#ifdef IN_RT_RC
1221# ifdef IN_RT_STATIC
1222# define RTRCDECL(type) DECLHIDDEN(type) RTCALL
1223# else
1224# define RTRCDECL(type) DECLEXPORT(type) RTCALL
1225# endif
1226#else
1227# define RTRCDECL(type) DECLIMPORT(type) RTCALL
1228#endif
1229
1230/** @def RTDECL(type)
1231 * Runtime Library export or import declaration.
1232 * Functions declared using this macro exists in all contexts.
1233 * @param type The return type of the function declaration.
1234 */
1235#if defined(IN_RT_R3) || defined(IN_RT_RC) || defined(IN_RT_R0)
1236# ifdef IN_RT_STATIC
1237# define RTDECL(type) DECLHIDDEN(type) RTCALL
1238# else
1239# define RTDECL(type) DECLEXPORT(type) RTCALL
1240# endif
1241#else
1242# define RTDECL(type) DECLIMPORT(type) RTCALL
1243#endif
1244
1245/** @def RTDATADECL(type)
1246 * Runtime Library export or import declaration.
1247 * Data declared using this macro exists in all contexts.
1248 * @param type The data type.
1249 */
1250/** @def RT_DECL_DATA_CONST(type)
1251 * Definition of a const variable. See DECL_HIDDEN_CONST.
1252 * @param type The const data type.
1253 */
1254#if defined(IN_RT_R3) || defined(IN_RT_RC) || defined(IN_RT_R0)
1255# ifdef IN_RT_STATIC
1256# define RTDATADECL(type) DECLHIDDEN(type)
1257# define RT_DECL_DATA_CONST(type) DECL_HIDDEN_CONST(type)
1258# else
1259# define RTDATADECL(type) DECLEXPORT(type)
1260# if defined(__cplusplus) && defined(__GNUC__)
1261# define RT_DECL_DATA_CONST(type) type
1262# else
1263# define RT_DECL_DATA_CONST(type) DECLEXPORT(type)
1264# endif
1265# endif
1266#else
1267# define RTDATADECL(type) DECLIMPORT(type)
1268# define RT_DECL_DATA_CONST(type) DECLIMPORT(type)
1269#endif
1270
1271/** @def RT_DECL_CLASS
1272 * Declares an class living in the runtime.
1273 */
1274#if defined(IN_RT_R3) || defined(IN_RT_RC) || defined(IN_RT_R0)
1275# ifdef IN_RT_STATIC
1276# define RT_DECL_CLASS
1277# else
1278# define RT_DECL_CLASS DECLEXPORT_CLASS
1279# endif
1280#else
1281# define RT_DECL_CLASS DECLIMPORT_CLASS
1282#endif
1283
1284
1285/** @def RT_NOCRT
1286 * Symbol name wrapper for the No-CRT bits.
1287 *
1288 * In order to coexist in the same process as other CRTs, we need to
1289 * decorate the symbols such that they don't conflict the ones in the
1290 * other CRTs. The result of such conflicts / duplicate symbols can
1291 * confuse the dynamic loader on Unix like systems.
1292 *
1293 * Define RT_WITHOUT_NOCRT_WRAPPERS to drop the wrapping.
1294 * Define RT_WITHOUT_NOCRT_WRAPPER_ALIASES to drop the aliases to the
1295 * wrapped names.
1296 */
1297/** @def RT_NOCRT_STR
1298 * Same as RT_NOCRT only it'll return a double quoted string of the result.
1299 */
1300#ifndef RT_WITHOUT_NOCRT_WRAPPERS
1301# define RT_NOCRT(name) nocrt_ ## name
1302# define RT_NOCRT_STR(name) "nocrt_" # name
1303#else
1304# define RT_NOCRT(name) name
1305# define RT_NOCRT_STR(name) #name
1306#endif
1307
1308
1309
1310/** @def RT_LIKELY
1311 * Give the compiler a hint that an expression is very likely to hold true.
1312 *
1313 * Some compilers support explicit branch prediction so that the CPU backend
1314 * can hint the processor and also so that code blocks can be reordered such
1315 * that the predicted path sees a more linear flow, thus improving cache
1316 * behaviour, etc.
1317 *
1318 * IPRT provides the macros RT_LIKELY() and RT_UNLIKELY() as a way to utilize
1319 * this compiler feature when present.
1320 *
1321 * A few notes about the usage:
1322 *
1323 * - Generally, use RT_UNLIKELY() with error condition checks (unless you
1324 * have some _strong_ reason to do otherwise, in which case document it),
1325 * and/or RT_LIKELY() with success condition checks, assuming you want
1326 * to optimize for the success path.
1327 *
1328 * - Other than that, if you don't know the likelihood of a test succeeding
1329 * from empirical or other 'hard' evidence, don't make predictions unless
1330 * you happen to be a Dirk Gently.
1331 *
1332 * - These macros are meant to be used in places that get executed a lot. It
1333 * is wasteful to make predictions in code that is executed rarely (e.g.
1334 * at subsystem initialization time) as the basic block reordering that this
1335 * affects can often generate larger code.
1336 *
1337 * - Note that RT_SUCCESS() and RT_FAILURE() already makes use of RT_LIKELY()
1338 * and RT_UNLIKELY(). Should you wish for prediction free status checks,
1339 * use the RT_SUCCESS_NP() and RT_FAILURE_NP() macros instead.
1340 *
1341 *
1342 * @returns the boolean result of the expression.
1343 * @param expr The expression that's very likely to be true.
1344 * @see RT_UNLIKELY
1345 */
1346/** @def RT_UNLIKELY
1347 * Give the compiler a hint that an expression is highly unlikely to hold true.
1348 *
1349 * See the usage instructions give in the RT_LIKELY() docs.
1350 *
1351 * @returns the boolean result of the expression.
1352 * @param expr The expression that's very unlikely to be true.
1353 * @see RT_LIKELY
1354 */
1355#if defined(__GNUC__)
1356# if __GNUC__ >= 3 && !defined(FORTIFY_RUNNING)
1357# define RT_LIKELY(expr) __builtin_expect(!!(expr), 1)
1358# define RT_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
1359# else
1360# define RT_LIKELY(expr) (expr)
1361# define RT_UNLIKELY(expr) (expr)
1362# endif
1363#else
1364# define RT_LIKELY(expr) (expr)
1365# define RT_UNLIKELY(expr) (expr)
1366#endif
1367
1368
1369/** @def RT_STR
1370 * Returns the argument as a string constant.
1371 * @param str Argument to stringify. */
1372#define RT_STR(str) #str
1373/** @def RT_XSTR
1374 * Returns the expanded argument as a string.
1375 * @param str Argument to expand and stringy. */
1376#define RT_XSTR(str) RT_STR(str)
1377
1378/** @def RT_CONCAT
1379 * Concatenate the expanded arguments without any extra spaces in between.
1380 *
1381 * @param a The first part.
1382 * @param b The second part.
1383 */
1384#define RT_CONCAT(a,b) RT_CONCAT_HLP(a,b)
1385/** RT_CONCAT helper, don't use. */
1386#define RT_CONCAT_HLP(a,b) a##b
1387
1388/** @def RT_CONCAT
1389 * Concatenate the expanded arguments without any extra spaces in between.
1390 *
1391 * @param a The 1st part.
1392 * @param b The 2nd part.
1393 * @param c The 3rd part.
1394 */
1395#define RT_CONCAT3(a,b,c) RT_CONCAT3_HLP(a,b,c)
1396/** RT_CONCAT3 helper, don't use. */
1397#define RT_CONCAT3_HLP(a,b,c) a##b##c
1398
1399/** @def RT_CONCAT
1400 * Concatenate the expanded arguments without any extra spaces in between.
1401 *
1402 * @param a The 1st part.
1403 * @param b The 2nd part.
1404 * @param c The 3rd part.
1405 */
1406#define RT_CONCAT4(a,b,c,d) RT_CONCAT4_HLP(a,b,c,d)
1407/** RT_CONCAT4 helper, don't use. */
1408#define RT_CONCAT4_HLP(a,b,c,d) a##b##c##d
1409
1410/**
1411 * String constant tuple - string constant, strlen(string constant).
1412 *
1413 * @param a_szConst String constant.
1414 */
1415#define RT_STR_TUPLE(a_szConst) a_szConst, (sizeof(a_szConst) - 1)
1416
1417
1418/**
1419 * Macro for using in switch statements that turns constants into strings.
1420 *
1421 * @param a_Const The constant (not string).
1422 */
1423#define RT_CASE_RET_STR(a_Const) case a_Const: return #a_Const
1424
1425
1426/** @def RT_BIT
1427 * Convert a bit number into an integer bitmask (unsigned).
1428 * @param bit The bit number.
1429 */
1430#define RT_BIT(bit) ( 1U << (bit) )
1431
1432/** @def RT_BIT_32
1433 * Convert a bit number into a 32-bit bitmask (unsigned).
1434 * @param bit The bit number.
1435 */
1436#define RT_BIT_32(bit) ( UINT32_C(1) << (bit) )
1437
1438/** @def RT_BIT_64
1439 * Convert a bit number into a 64-bit bitmask (unsigned).
1440 * @param bit The bit number.
1441 */
1442#define RT_BIT_64(bit) ( UINT64_C(1) << (bit) )
1443
1444/** @def RT_ALIGN
1445 * Align macro.
1446 * @param u Value to align.
1447 * @param uAlignment The alignment. Power of two!
1448 *
1449 * @remark Be extremely careful when using this macro with type which sizeof != sizeof int.
1450 * When possible use any of the other RT_ALIGN_* macros. And when that's not
1451 * possible, make 101% sure that uAlignment is specified with a right sized type.
1452 *
1453 * Specifying an unsigned 32-bit alignment constant with a 64-bit value will give
1454 * you a 32-bit return value!
1455 *
1456 * In short: Don't use this macro. Use RT_ALIGN_T() instead.
1457 */
1458#define RT_ALIGN(u, uAlignment) ( ((u) + ((uAlignment) - 1)) & ~((uAlignment) - 1) )
1459
1460/** @def RT_ALIGN_T
1461 * Align macro.
1462 * @param u Value to align.
1463 * @param uAlignment The alignment. Power of two!
1464 * @param type Integer type to use while aligning.
1465 * @remark This macro is the preferred alignment macro, it doesn't have any of the pitfalls RT_ALIGN has.
1466 */
1467#define RT_ALIGN_T(u, uAlignment, type) ( ((type)(u) + ((uAlignment) - 1)) & ~(type)((uAlignment) - 1) )
1468
1469/** @def RT_ALIGN_32
1470 * Align macro for a 32-bit value.
1471 * @param u32 Value to align.
1472 * @param uAlignment The alignment. Power of two!
1473 */
1474#define RT_ALIGN_32(u32, uAlignment) RT_ALIGN_T(u32, uAlignment, uint32_t)
1475
1476/** @def RT_ALIGN_64
1477 * Align macro for a 64-bit value.
1478 * @param u64 Value to align.
1479 * @param uAlignment The alignment. Power of two!
1480 */
1481#define RT_ALIGN_64(u64, uAlignment) RT_ALIGN_T(u64, uAlignment, uint64_t)
1482
1483/** @def RT_ALIGN_Z
1484 * Align macro for size_t.
1485 * @param cb Value to align.
1486 * @param uAlignment The alignment. Power of two!
1487 */
1488#define RT_ALIGN_Z(cb, uAlignment) RT_ALIGN_T(cb, uAlignment, size_t)
1489
1490/** @def RT_ALIGN_P
1491 * Align macro for pointers.
1492 * @param pv Value to align.
1493 * @param uAlignment The alignment. Power of two!
1494 */
1495#define RT_ALIGN_P(pv, uAlignment) RT_ALIGN_PT(pv, uAlignment, void *)
1496
1497/** @def RT_ALIGN_PT
1498 * Align macro for pointers with type cast.
1499 * @param u Value to align.
1500 * @param uAlignment The alignment. Power of two!
1501 * @param CastType The type to cast the result to.
1502 */
1503#define RT_ALIGN_PT(u, uAlignment, CastType) ( (CastType)RT_ALIGN_T(u, uAlignment, uintptr_t) )
1504
1505/** @def RT_ALIGN_R3PT
1506 * Align macro for ring-3 pointers with type cast.
1507 * @param u Value to align.
1508 * @param uAlignment The alignment. Power of two!
1509 * @param CastType The type to cast the result to.
1510 */
1511#define RT_ALIGN_R3PT(u, uAlignment, CastType) ( (CastType)RT_ALIGN_T(u, uAlignment, RTR3UINTPTR) )
1512
1513/** @def RT_ALIGN_R0PT
1514 * Align macro for ring-0 pointers with type cast.
1515 * @param u Value to align.
1516 * @param uAlignment The alignment. Power of two!
1517 * @param CastType The type to cast the result to.
1518 */
1519#define RT_ALIGN_R0PT(u, uAlignment, CastType) ( (CastType)RT_ALIGN_T(u, uAlignment, RTR0UINTPTR) )
1520
1521/** @def RT_ALIGN_GCPT
1522 * Align macro for GC pointers with type cast.
1523 * @param u Value to align.
1524 * @param uAlignment The alignment. Power of two!
1525 * @param CastType The type to cast the result to.
1526 */
1527#define RT_ALIGN_GCPT(u, uAlignment, CastType) ( (CastType)RT_ALIGN_T(u, uAlignment, RTGCUINTPTR) )
1528
1529
1530/** @def RT_OFFSETOF
1531 * Our own special offsetof() variant, returns a signed result.
1532 *
1533 * This differs from the usual offsetof() in that it's not relying on builtin
1534 * compiler stuff and thus can use variables in arrays the structure may
1535 * contain. This is useful to determine the sizes of structures ending
1536 * with a variable length field.
1537 *
1538 * @returns offset into the structure of the specified member. signed.
1539 * @param type Structure type.
1540 * @param member Member.
1541 */
1542#if defined(__GNUC__) && defined(__cplusplus) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
1543# define RT_OFFSETOF(type, member) ( (int)(uintptr_t)&( ((type *)(void *)0x1000)->member) - 0x1000 )
1544#else
1545# define RT_OFFSETOF(type, member) ( (int)(uintptr_t)&( ((type *)(void *)0)->member) )
1546#endif
1547
1548/** @def RT_UOFFSETOF
1549 * Our own special offsetof() variant, returns an unsigned result.
1550 *
1551 * This differs from the usual offsetof() in that it's not relying on builtin
1552 * compiler stuff and thus can use variables in arrays the structure may
1553 * contain. This is useful to determine the sizes of structures ending
1554 * with a variable length field.
1555 *
1556 * @returns offset into the structure of the specified member. unsigned.
1557 * @param type Structure type.
1558 * @param member Member.
1559 */
1560#if defined(__GNUC__) && defined(__cplusplus) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
1561# define RT_UOFFSETOF(type, member) ( (uintptr_t)&( ((type *)(void *)0x1000)->member) - 0x1000 )
1562#else
1563# define RT_UOFFSETOF(type, member) ( (uintptr_t)&( ((type *)(void *)0)->member) )
1564#endif
1565
1566/** @def RT_OFFSETOF_ADD
1567 * RT_OFFSETOF with an addend.
1568 *
1569 * @returns offset into the structure of the specified member. signed.
1570 * @param type Structure type.
1571 * @param member Member.
1572 * @param addend The addend to add to the offset.
1573 */
1574#define RT_OFFSETOF_ADD(type, member, addend) ( (int)RT_UOFFSETOF_ADD(type, member, addend) )
1575
1576/** @def RT_UOFFSETOF_ADD
1577 * RT_UOFFSETOF with an addend.
1578 *
1579 * @returns offset into the structure of the specified member. signed.
1580 * @param type Structure type.
1581 * @param member Member.
1582 * @param addend The addend to add to the offset.
1583 */
1584#define RT_UOFFSETOF_ADD(type, member, addend) ( (uintptr_t)&( ((type *)(void *)(uintptr_t)(addend))->member) )
1585
1586/** @def RT_SIZEOFMEMB
1587 * Get the size of a structure member.
1588 *
1589 * @returns size of the structure member.
1590 * @param type Structure type.
1591 * @param member Member.
1592 */
1593#define RT_SIZEOFMEMB(type, member) ( sizeof(((type *)(void *)0)->member) )
1594
1595/** @def RT_FROM_MEMBER
1596 * Convert a pointer to a structure member into a pointer to the structure.
1597 *
1598 * @returns pointer to the structure.
1599 * @param pMem Pointer to the member.
1600 * @param Type Structure type.
1601 * @param Member Member name.
1602 */
1603#define RT_FROM_MEMBER(pMem, Type, Member) ( (Type *) ((uint8_t *)(void *)(pMem) - RT_UOFFSETOF(Type, Member)) )
1604
1605/** @def RT_FROM_CPP_MEMBER
1606 * Same as RT_FROM_MEMBER except it avoids the annoying g++ warnings about
1607 * invalid access to non-static data member of NULL object.
1608 *
1609 * @returns pointer to the structure.
1610 * @param pMem Pointer to the member.
1611 * @param Type Structure type.
1612 * @param Member Member name.
1613 *
1614 * @remarks Using the __builtin_offsetof does not shut up the compiler.
1615 */
1616#if defined(__GNUC__) && defined(__cplusplus)
1617# define RT_FROM_CPP_MEMBER(pMem, Type, Member) \
1618 ( (Type *) ((uintptr_t)(pMem) - (uintptr_t)&((Type *)0x1000)->Member + 0x1000U) )
1619#else
1620# define RT_FROM_CPP_MEMBER(pMem, Type, Member) RT_FROM_MEMBER(pMem, Type, Member)
1621#endif
1622
1623/** @def RT_ELEMENTS
1624 * Calculates the number of elements in a statically sized array.
1625 * @returns Element count.
1626 * @param aArray Array in question.
1627 */
1628#define RT_ELEMENTS(aArray) ( sizeof(aArray) / sizeof((aArray)[0]) )
1629
1630/**
1631 * Checks if the value is a power of two.
1632 *
1633 * @returns true if power of two, false if not.
1634 * @param uVal The value to test.
1635 * @remarks 0 is a power of two.
1636 * @see VERR_NOT_POWER_OF_TWO
1637 */
1638#define RT_IS_POWER_OF_TWO(uVal) ( ((uVal) & ((uVal) - 1)) == 0)
1639
1640#ifdef RT_OS_OS2
1641/* Undefine RT_MAX since there is an unfortunate clash with the max
1642 resource type define in os2.h. */
1643# undef RT_MAX
1644#endif
1645
1646/** @def RT_MAX
1647 * Finds the maximum value.
1648 * @returns The higher of the two.
1649 * @param Value1 Value 1
1650 * @param Value2 Value 2
1651 */
1652#define RT_MAX(Value1, Value2) ( (Value1) >= (Value2) ? (Value1) : (Value2) )
1653
1654/** @def RT_MIN
1655 * Finds the minimum value.
1656 * @returns The lower of the two.
1657 * @param Value1 Value 1
1658 * @param Value2 Value 2
1659 */
1660#define RT_MIN(Value1, Value2) ( (Value1) <= (Value2) ? (Value1) : (Value2) )
1661
1662/** @def RT_CLAMP
1663 * Clamps the value to minimum and maximum values.
1664 * @returns The clamped value.
1665 * @param Value The value to check.
1666 * @param Min Minimum value.
1667 * @param Max Maximum value.
1668 */
1669#define RT_CLAMP(Value, Min, Max) ( (Value) > (Max) ? (Max) : (Value) < (Min) ? (Min) : (Value) )
1670
1671/** @def RT_ABS
1672 * Get the absolute (non-negative) value.
1673 * @returns The absolute value of Value.
1674 * @param Value The value.
1675 */
1676#define RT_ABS(Value) ( (Value) >= 0 ? (Value) : -(Value) )
1677
1678/** @def RT_BOOL
1679 * Turn non-zero/zero into true/false
1680 * @returns The resulting boolean value.
1681 * @param Value The value.
1682 */
1683#define RT_BOOL(Value) ( !!(Value) )
1684
1685/** @def RT_LO_U8
1686 * Gets the low uint8_t of a uint16_t or something equivalent. */
1687#ifdef __GNUC__
1688# define RT_LO_U8(a) __extension__ ({ AssertCompile(sizeof((a)) == sizeof(uint16_t)); (uint8_t)(a); })
1689#else
1690# define RT_LO_U8(a) ( (uint8_t)(a) )
1691#endif
1692/** @def RT_HI_U16
1693 * Gets the high uint16_t of a uint32_t or something equivalent). */
1694#ifdef __GNUC__
1695# define RT_HI_U8(a) __extension__ ({ AssertCompile(sizeof((a)) == sizeof(uint16_t)); (uint8_t)((a) >> 8); })
1696#else
1697# define RT_HI_U8(a) ( (uint8_t)((a) >> 8) )
1698#endif
1699
1700/** @def RT_LO_U16
1701 * Gets the low uint16_t of a uint32_t or something equivalent. */
1702#ifdef __GNUC__
1703# define RT_LO_U16(a) __extension__ ({ AssertCompile(sizeof((a)) == sizeof(uint32_t)); (uint16_t)(a); })
1704#else
1705# define RT_LO_U16(a) ( (uint16_t)(a) )
1706#endif
1707/** @def RT_HI_U16
1708 * Gets the high uint16_t of a uint32_t or something equivalent). */
1709#ifdef __GNUC__
1710# define RT_HI_U16(a) __extension__ ({ AssertCompile(sizeof((a)) == sizeof(uint32_t)); (uint16_t)((a) >> 16); })
1711#else
1712# define RT_HI_U16(a) ( (uint16_t)((a) >> 16) )
1713#endif
1714
1715/** @def RT_LO_U32
1716 * Gets the low uint32_t of a uint64_t or something equivalent. */
1717#ifdef __GNUC__
1718# define RT_LO_U32(a) __extension__ ({ AssertCompile(sizeof((a)) == sizeof(uint64_t)); (uint32_t)(a); })
1719#else
1720# define RT_LO_U32(a) ( (uint32_t)(a) )
1721#endif
1722/** @def RT_HI_U32
1723 * Gets the high uint32_t of a uint64_t or something equivalent). */
1724#ifdef __GNUC__
1725# define RT_HI_U32(a) __extension__ ({ AssertCompile(sizeof((a)) == sizeof(uint64_t)); (uint32_t)((a) >> 32); })
1726#else
1727# define RT_HI_U32(a) ( (uint32_t)((a) >> 32) )
1728#endif
1729
1730/** @def RT_BYTE1
1731 * Gets the first byte of something. */
1732#define RT_BYTE1(a) ( (a) & 0xff )
1733/** @def RT_BYTE2
1734 * Gets the second byte of something. */
1735#define RT_BYTE2(a) ( ((a) >> 8) & 0xff )
1736/** @def RT_BYTE3
1737 * Gets the second byte of something. */
1738#define RT_BYTE3(a) ( ((a) >> 16) & 0xff )
1739/** @def RT_BYTE4
1740 * Gets the fourth byte of something. */
1741#define RT_BYTE4(a) ( ((a) >> 24) & 0xff )
1742/** @def RT_BYTE5
1743 * Gets the fifth byte of something. */
1744#define RT_BYTE5(a) ( ((a) >> 32) & 0xff )
1745/** @def RT_BYTE6
1746 * Gets the sixth byte of something. */
1747#define RT_BYTE6(a) ( ((a) >> 40) & 0xff )
1748/** @def RT_BYTE7
1749 * Gets the seventh byte of something. */
1750#define RT_BYTE7(a) ( ((a) >> 48) & 0xff )
1751/** @def RT_BYTE8
1752 * Gets the eight byte of something. */
1753#define RT_BYTE8(a) ( ((a) >> 56) & 0xff )
1754
1755
1756/** @def RT_LODWORD
1757 * Gets the low dword (=uint32_t) of something.
1758 * @deprecated Use RT_LO_U32. */
1759#define RT_LODWORD(a) ( (uint32_t)(a) )
1760/** @def RT_HIDWORD
1761 * Gets the high dword (=uint32_t) of a 64-bit of something.
1762 * @deprecated Use RT_HI_U32. */
1763#define RT_HIDWORD(a) ( (uint32_t)((a) >> 32) )
1764
1765/** @def RT_LOWORD
1766 * Gets the low word (=uint16_t) of something.
1767 * @deprecated Use RT_LO_U16. */
1768#define RT_LOWORD(a) ( (a) & 0xffff )
1769/** @def RT_HIWORD
1770 * Gets the high word (=uint16_t) of a 32-bit something.
1771 * @deprecated Use RT_HI_U16. */
1772#define RT_HIWORD(a) ( (a) >> 16 )
1773
1774/** @def RT_LOBYTE
1775 * Gets the low byte of something.
1776 * @deprecated Use RT_LO_U8. */
1777#define RT_LOBYTE(a) ( (a) & 0xff )
1778/** @def RT_HIBYTE
1779 * Gets the low byte of a 16-bit something.
1780 * @deprecated Use RT_HI_U8. */
1781#define RT_HIBYTE(a) ( (a) >> 8 )
1782
1783
1784/** @def RT_MAKE_U64
1785 * Constructs a uint64_t value from two uint32_t values.
1786 */
1787#define RT_MAKE_U64(Lo, Hi) ( (uint64_t)((uint32_t)(Hi)) << 32 | (uint32_t)(Lo) )
1788
1789/** @def RT_MAKE_U64_FROM_U16
1790 * Constructs a uint64_t value from four uint16_t values.
1791 */
1792#define RT_MAKE_U64_FROM_U16(w0, w1, w2, w3) \
1793 ((uint64_t)( (uint64_t)((uint16_t)(w3)) << 48 \
1794 | (uint64_t)((uint16_t)(w2)) << 32 \
1795 | (uint32_t)((uint16_t)(w1)) << 16 \
1796 | (uint16_t)(w0) ))
1797
1798/** @def RT_MAKE_U64_FROM_U8
1799 * Constructs a uint64_t value from eight uint8_t values.
1800 */
1801#define RT_MAKE_U64_FROM_U8(b0, b1, b2, b3, b4, b5, b6, b7) \
1802 ((uint64_t)( (uint64_t)((uint8_t)(b7)) << 56 \
1803 | (uint64_t)((uint8_t)(b6)) << 48 \
1804 | (uint64_t)((uint8_t)(b5)) << 40 \
1805 | (uint64_t)((uint8_t)(b4)) << 32 \
1806 | (uint32_t)((uint8_t)(b3)) << 24 \
1807 | (uint32_t)((uint8_t)(b2)) << 16 \
1808 | (uint16_t)((uint8_t)(b1)) << 8 \
1809 | (uint8_t)(b0) ))
1810
1811/** @def RT_MAKE_U32
1812 * Constructs a uint32_t value from two uint16_t values.
1813 */
1814#define RT_MAKE_U32(Lo, Hi) \
1815 ((uint32_t)( (uint32_t)((uint16_t)(Hi)) << 16 \
1816 | (uint16_t)(Lo) ))
1817
1818/** @def RT_MAKE_U32_FROM_U8
1819 * Constructs a uint32_t value from four uint8_t values.
1820 */
1821#define RT_MAKE_U32_FROM_U8(b0, b1, b2, b3) \
1822 ((uint32_t)( (uint32_t)((uint8_t)(b3)) << 24 \
1823 | (uint32_t)((uint8_t)(b2)) << 16 \
1824 | (uint16_t)((uint8_t)(b1)) << 8 \
1825 | (uint8_t)(b0) ))
1826
1827/** @def RT_MAKE_U16
1828 * Constructs a uint16_t value from two uint8_t values.
1829 */
1830#define RT_MAKE_U16(Lo, Hi) \
1831 ((uint16_t)( (uint16_t)((uint8_t)(Hi)) << 8 \
1832 | (uint8_t)(Lo) ))
1833
1834
1835/** @def RT_BSWAP_U64
1836 * Reverses the byte order of an uint64_t value. */
1837#if 0
1838# define RT_BSWAP_U64(u64) RT_BSWAP_U64_C(u64)
1839#elif defined(__GNUC__)
1840# define RT_BSWAP_U64(u64) (__builtin_constant_p((u64)) \
1841 ? RT_BSWAP_U64_C(u64) : ASMByteSwapU64(u64))
1842#else
1843# define RT_BSWAP_U64(u64) ASMByteSwapU64(u64)
1844#endif
1845
1846/** @def RT_BSWAP_U32
1847 * Reverses the byte order of an uint32_t value. */
1848#if 0
1849# define RT_BSWAP_U32(u32) RT_BSWAP_U32_C(u32)
1850#elif defined(__GNUC__)
1851# define RT_BSWAP_U32(u32) (__builtin_constant_p((u32)) \
1852 ? RT_BSWAP_U32_C(u32) : ASMByteSwapU32(u32))
1853#else
1854# define RT_BSWAP_U32(u32) ASMByteSwapU32(u32)
1855#endif
1856
1857/** @def RT_BSWAP_U16
1858 * Reverses the byte order of an uint16_t value. */
1859#if 0
1860# define RT_BSWAP_U16(u16) RT_BSWAP_U16_C(u16)
1861#elif defined(__GNUC__)
1862# define RT_BSWAP_U16(u16) (__builtin_constant_p((u16)) \
1863 ? RT_BSWAP_U16_C(u16) : ASMByteSwapU16(u16))
1864#else
1865# define RT_BSWAP_U16(u16) ASMByteSwapU16(u16)
1866#endif
1867
1868
1869/** @def RT_BSWAP_U64_C
1870 * Reverses the byte order of an uint64_t constant. */
1871#define RT_BSWAP_U64_C(u64) RT_MAKE_U64(RT_BSWAP_U32_C((u64) >> 32), RT_BSWAP_U32_C((u64) & 0xffffffff))
1872
1873/** @def RT_BSWAP_U32_C
1874 * Reverses the byte order of an uint32_t constant. */
1875#define RT_BSWAP_U32_C(u32) RT_MAKE_U32_FROM_U8(RT_BYTE4(u32), RT_BYTE3(u32), RT_BYTE2(u32), RT_BYTE1(u32))
1876
1877/** @def RT_BSWAP_U16_C
1878 * Reverses the byte order of an uint16_t constant. */
1879#define RT_BSWAP_U16_C(u16) RT_MAKE_U16(RT_HIBYTE(u16), RT_LOBYTE(u16))
1880
1881
1882/** @def RT_H2LE_U64
1883 * Converts an uint64_t value from host to little endian byte order. */
1884#ifdef RT_BIG_ENDIAN
1885# define RT_H2LE_U64(u64) RT_BSWAP_U64(u64)
1886#else
1887# define RT_H2LE_U64(u64) (u64)
1888#endif
1889
1890/** @def RT_H2LE_U64_C
1891 * Converts an uint64_t constant from host to little endian byte order. */
1892#ifdef RT_BIG_ENDIAN
1893# define RT_H2LE_U64_C(u64) RT_BSWAP_U64_C(u64)
1894#else
1895# define RT_H2LE_U64_C(u64) (u64)
1896#endif
1897
1898/** @def RT_H2LE_U32
1899 * Converts an uint32_t value from host to little endian byte order. */
1900#ifdef RT_BIG_ENDIAN
1901# define RT_H2LE_U32(u32) RT_BSWAP_U32(u32)
1902#else
1903# define RT_H2LE_U32(u32) (u32)
1904#endif
1905
1906/** @def RT_H2LE_U32_C
1907 * Converts an uint32_t constant from host to little endian byte order. */
1908#ifdef RT_BIG_ENDIAN
1909# define RT_H2LE_U32_C(u32) RT_BSWAP_U32_C(u32)
1910#else
1911# define RT_H2LE_U32_C(u32) (u32)
1912#endif
1913
1914/** @def RT_H2LE_U16
1915 * Converts an uint16_t value from host to little endian byte order. */
1916#ifdef RT_BIG_ENDIAN
1917# define RT_H2LE_U16(u16) RT_BSWAP_U16(u16)
1918#else
1919# define RT_H2LE_U16(u16) (u16)
1920#endif
1921
1922/** @def RT_H2LE_U16_C
1923 * Converts an uint16_t constant from host to little endian byte order. */
1924#ifdef RT_BIG_ENDIAN
1925# define RT_H2LE_U16_C(u16) RT_BSWAP_U16_C(u16)
1926#else
1927# define RT_H2LE_U16_C(u16) (u16)
1928#endif
1929
1930
1931/** @def RT_LE2H_U64
1932 * Converts an uint64_t value from little endian to host byte order. */
1933#ifdef RT_BIG_ENDIAN
1934# define RT_LE2H_U64(u64) RT_BSWAP_U64(u64)
1935#else
1936# define RT_LE2H_U64(u64) (u64)
1937#endif
1938
1939/** @def RT_LE2H_U64_C
1940 * Converts an uint64_t constant from little endian to host byte order. */
1941#ifdef RT_BIG_ENDIAN
1942# define RT_LE2H_U64_C(u64) RT_BSWAP_U64_C(u64)
1943#else
1944# define RT_LE2H_U64_C(u64) (u64)
1945#endif
1946
1947/** @def RT_LE2H_U32
1948 * Converts an uint32_t value from little endian to host byte order. */
1949#ifdef RT_BIG_ENDIAN
1950# define RT_LE2H_U32(u32) RT_BSWAP_U32(u32)
1951#else
1952# define RT_LE2H_U32(u32) (u32)
1953#endif
1954
1955/** @def RT_LE2H_U32_C
1956 * Converts an uint32_t constant from little endian to host byte order. */
1957#ifdef RT_BIG_ENDIAN
1958# define RT_LE2H_U32_C(u32) RT_BSWAP_U32_C(u32)
1959#else
1960# define RT_LE2H_U32_C(u32) (u32)
1961#endif
1962
1963/** @def RT_LE2H_U16
1964 * Converts an uint16_t value from little endian to host byte order. */
1965#ifdef RT_BIG_ENDIAN
1966# define RT_LE2H_U16(u16) RT_BSWAP_U16(u16)
1967#else
1968# define RT_LE2H_U16(u16) (u16)
1969#endif
1970
1971/** @def RT_LE2H_U16_C
1972 * Converts an uint16_t constant from little endian to host byte order. */
1973#ifdef RT_BIG_ENDIAN
1974# define RT_LE2H_U16_C(u16) RT_BSWAP_U16_C(u16)
1975#else
1976# define RT_LE2H_U16_C(u16) (u16)
1977#endif
1978
1979
1980/** @def RT_H2BE_U64
1981 * Converts an uint64_t value from host to big endian byte order. */
1982#ifdef RT_BIG_ENDIAN
1983# define RT_H2BE_U64(u64) (u64)
1984#else
1985# define RT_H2BE_U64(u64) RT_BSWAP_U64(u64)
1986#endif
1987
1988/** @def RT_H2BE_U64_C
1989 * Converts an uint64_t constant from host to big endian byte order. */
1990#ifdef RT_BIG_ENDIAN
1991# define RT_H2BE_U64_C(u64) (u64)
1992#else
1993# define RT_H2BE_U64_C(u64) RT_BSWAP_U64_C(u64)
1994#endif
1995
1996/** @def RT_H2BE_U32
1997 * Converts an uint32_t value from host to big endian byte order. */
1998#ifdef RT_BIG_ENDIAN
1999# define RT_H2BE_U32(u32) (u32)
2000#else
2001# define RT_H2BE_U32(u32) RT_BSWAP_U32(u32)
2002#endif
2003
2004/** @def RT_H2BE_U32_C
2005 * Converts an uint32_t constant from host to big endian byte order. */
2006#ifdef RT_BIG_ENDIAN
2007# define RT_H2BE_U32_C(u32) (u32)
2008#else
2009# define RT_H2BE_U32_C(u32) RT_BSWAP_U32_C(u32)
2010#endif
2011
2012/** @def RT_H2BE_U16
2013 * Converts an uint16_t value from host to big endian byte order. */
2014#ifdef RT_BIG_ENDIAN
2015# define RT_H2BE_U16(u16) (u16)
2016#else
2017# define RT_H2BE_U16(u16) RT_BSWAP_U16(u16)
2018#endif
2019
2020/** @def RT_H2BE_U16_C
2021 * Converts an uint16_t constant from host to big endian byte order. */
2022#ifdef RT_BIG_ENDIAN
2023# define RT_H2BE_U16_C(u16) (u16)
2024#else
2025# define RT_H2BE_U16_C(u16) RT_BSWAP_U16_C(u16)
2026#endif
2027
2028/** @def RT_BE2H_U64
2029 * Converts an uint64_t value from big endian to host byte order. */
2030#ifdef RT_BIG_ENDIAN
2031# define RT_BE2H_U64(u64) (u64)
2032#else
2033# define RT_BE2H_U64(u64) RT_BSWAP_U64(u64)
2034#endif
2035
2036/** @def RT_BE2H_U64
2037 * Converts an uint64_t constant from big endian to host byte order. */
2038#ifdef RT_BIG_ENDIAN
2039# define RT_BE2H_U64_C(u64) (u64)
2040#else
2041# define RT_BE2H_U64_C(u64) RT_BSWAP_U64_C(u64)
2042#endif
2043
2044/** @def RT_BE2H_U32
2045 * Converts an uint32_t value from big endian to host byte order. */
2046#ifdef RT_BIG_ENDIAN
2047# define RT_BE2H_U32(u32) (u32)
2048#else
2049# define RT_BE2H_U32(u32) RT_BSWAP_U32(u32)
2050#endif
2051
2052/** @def RT_BE2H_U32_C
2053 * Converts an uint32_t value from big endian to host byte order. */
2054#ifdef RT_BIG_ENDIAN
2055# define RT_BE2H_U32_C(u32) (u32)
2056#else
2057# define RT_BE2H_U32_C(u32) RT_BSWAP_U32_C(u32)
2058#endif
2059
2060/** @def RT_BE2H_U16
2061 * Converts an uint16_t value from big endian to host byte order. */
2062#ifdef RT_BIG_ENDIAN
2063# define RT_BE2H_U16(u16) (u16)
2064#else
2065# define RT_BE2H_U16(u16) RT_BSWAP_U16(u16)
2066#endif
2067
2068/** @def RT_BE2H_U16_C
2069 * Converts an uint16_t constant from big endian to host byte order. */
2070#ifdef RT_BIG_ENDIAN
2071# define RT_BE2H_U16_C(u16) (u16)
2072#else
2073# define RT_BE2H_U16_C(u16) RT_BSWAP_U16_C(u16)
2074#endif
2075
2076
2077/** @def RT_H2N_U64
2078 * Converts an uint64_t value from host to network byte order. */
2079#define RT_H2N_U64(u64) RT_H2BE_U64(u64)
2080
2081/** @def RT_H2N_U64_C
2082 * Converts an uint64_t constant from host to network byte order. */
2083#define RT_H2N_U64_C(u64) RT_H2BE_U64_C(u64)
2084
2085/** @def RT_H2N_U32
2086 * Converts an uint32_t value from host to network byte order. */
2087#define RT_H2N_U32(u32) RT_H2BE_U32(u32)
2088
2089/** @def RT_H2N_U32_C
2090 * Converts an uint32_t constant from host to network byte order. */
2091#define RT_H2N_U32_C(u32) RT_H2BE_U32_C(u32)
2092
2093/** @def RT_H2N_U16
2094 * Converts an uint16_t value from host to network byte order. */
2095#define RT_H2N_U16(u16) RT_H2BE_U16(u16)
2096
2097/** @def RT_H2N_U16_C
2098 * Converts an uint16_t constant from host to network byte order. */
2099#define RT_H2N_U16_C(u16) RT_H2BE_U16_C(u16)
2100
2101/** @def RT_N2H_U64
2102 * Converts an uint64_t value from network to host byte order. */
2103#define RT_N2H_U64(u64) RT_BE2H_U64(u64)
2104
2105/** @def RT_N2H_U64_C
2106 * Converts an uint64_t constant from network to host byte order. */
2107#define RT_N2H_U64_C(u64) RT_BE2H_U64_C(u64)
2108
2109/** @def RT_N2H_U32
2110 * Converts an uint32_t value from network to host byte order. */
2111#define RT_N2H_U32(u32) RT_BE2H_U32(u32)
2112
2113/** @def RT_N2H_U32_C
2114 * Converts an uint32_t constant from network to host byte order. */
2115#define RT_N2H_U32_C(u32) RT_BE2H_U32_C(u32)
2116
2117/** @def RT_N2H_U16
2118 * Converts an uint16_t value from network to host byte order. */
2119#define RT_N2H_U16(u16) RT_BE2H_U16(u16)
2120
2121/** @def RT_N2H_U16_C
2122 * Converts an uint16_t value from network to host byte order. */
2123#define RT_N2H_U16_C(u16) RT_BE2H_U16_C(u16)
2124
2125
2126/*
2127 * The BSD sys/param.h + machine/param.h file is a major source of
2128 * namespace pollution. Kill off some of the worse ones unless we're
2129 * compiling kernel code.
2130 */
2131#if defined(RT_OS_DARWIN) \
2132 && !defined(KERNEL) \
2133 && !defined(RT_NO_BSD_PARAM_H_UNDEFING) \
2134 && ( defined(_SYS_PARAM_H_) || defined(_I386_PARAM_H_) )
2135/* sys/param.h: */
2136# undef PSWP
2137# undef PVM
2138# undef PINOD
2139# undef PRIBO
2140# undef PVFS
2141# undef PZERO
2142# undef PSOCK
2143# undef PWAIT
2144# undef PLOCK
2145# undef PPAUSE
2146# undef PUSER
2147# undef PRIMASK
2148# undef MINBUCKET
2149# undef MAXALLOCSAVE
2150# undef FSHIFT
2151# undef FSCALE
2152
2153/* i386/machine.h: */
2154# undef ALIGN
2155# undef ALIGNBYTES
2156# undef DELAY
2157# undef STATUS_WORD
2158# undef USERMODE
2159# undef BASEPRI
2160# undef MSIZE
2161# undef CLSIZE
2162# undef CLSIZELOG2
2163#endif
2164
2165/** @def NIL_OFFSET
2166 * NIL offset.
2167 * Whenever we use offsets instead of pointers to save space and relocation effort
2168 * NIL_OFFSET shall be used as the equivalent to NULL.
2169 */
2170#define NIL_OFFSET (~0U)
2171
2172/** @def NOREF
2173 * Keeps the compiler from bitching about an unused parameter.
2174 */
2175#define NOREF(var) (void)(var)
2176
2177/** @def RT_BREAKPOINT
2178 * Emit a debug breakpoint instruction.
2179 *
2180 * @remarks In the x86/amd64 gnu world we add a nop instruction after the int3
2181 * to force gdb to remain at the int3 source line.
2182 * @remarks The L4 kernel will try make sense of the breakpoint, thus the jmp on
2183 * x86/amd64.
2184 */
2185#ifdef __GNUC__
2186# if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
2187# if !defined(__L4ENV__)
2188# define RT_BREAKPOINT() __asm__ __volatile__("int $3\n\tnop\n\t")
2189# else
2190# define RT_BREAKPOINT() __asm__ __volatile__("int3; jmp 1f; 1:\n\t")
2191# endif
2192# elif defined(RT_ARCH_SPARC64)
2193# define RT_BREAKPOINT() __asm__ __volatile__("illtrap 0\n\t") /** @todo Sparc64: this is just a wild guess. */
2194# elif defined(RT_ARCH_SPARC)
2195# define RT_BREAKPOINT() __asm__ __volatile__("unimp 0\n\t") /** @todo Sparc: this is just a wild guess (same as Sparc64, just different name). */
2196# endif
2197#endif
2198#ifdef _MSC_VER
2199# define RT_BREAKPOINT() __debugbreak()
2200#endif
2201#if defined(__IBMC__) || defined(__IBMCPP__)
2202# define RT_BREAKPOINT() __interrupt(3)
2203#endif
2204#ifndef RT_BREAKPOINT
2205# error "This compiler/arch is not supported!"
2206#endif
2207
2208
2209/** @defgroup grp_rt_cdefs_size Size Constants
2210 * (Of course, these are binary computer terms, not SI.)
2211 * @{
2212 */
2213/** 1 K (Kilo) (1 024). */
2214#define _1K 0x00000400
2215/** 2 K (Kilo) (2 048). */
2216#define _2K 0x00000800
2217/** 4 K (Kilo) (4 096). */
2218#define _4K 0x00001000
2219/** 8 K (Kilo) (8 192). */
2220#define _8K 0x00002000
2221/** 16 K (Kilo) (16 384). */
2222#define _16K 0x00004000
2223/** 32 K (Kilo) (32 678). */
2224#define _32K 0x00008000
2225/** 64 K (Kilo) (65 536). */
2226#define _64K 0x00010000
2227/** 128 K (Kilo) (131 072). */
2228#define _128K 0x00020000
2229/** 256 K (Kilo) (262 144). */
2230#define _256K 0x00040000
2231/** 512 K (Kilo) (524 288). */
2232#define _512K 0x00080000
2233/** 1 M (Mega) (1 048 576). */
2234#define _1M 0x00100000
2235/** 2 M (Mega) (2 097 152). */
2236#define _2M 0x00200000
2237/** 4 M (Mega) (4 194 304). */
2238#define _4M 0x00400000
2239/** 1 G (Giga) (1 073 741 824). (32-bit) */
2240#define _1G 0x40000000
2241/** 1 G (Giga) (1 073 741 824). (64-bit) */
2242#define _1G64 0x40000000LL
2243/** 2 G (Giga) (2 147 483 648). (32-bit) */
2244#define _2G32 0x80000000U
2245/** 2 G (Giga) (2 147 483 648). (64-bit) */
2246#define _2G 0x0000000080000000LL
2247/** 4 G (Giga) (4 294 967 296). */
2248#define _4G 0x0000000100000000LL
2249/** 1 T (Tera) (1 099 511 627 776). */
2250#define _1T 0x0000010000000000LL
2251/** 1 P (Peta) (1 125 899 906 842 624). */
2252#define _1P 0x0004000000000000LL
2253/** 1 E (Exa) (1 152 921 504 606 846 976). */
2254#define _1E 0x1000000000000000LL
2255/** 2 E (Exa) (2 305 843 009 213 693 952). */
2256#define _2E 0x2000000000000000ULL
2257/** @} */
2258
2259/** @defgroup grp_rt_cdefs_decimal_grouping Decimal Constant Grouping Macros
2260 * @{ */
2261#define RT_D1(g1) g1
2262#define RT_D2(g1, g2) g1#g2
2263#define RT_D3(g1, g2, g3) g1#g2#g3
2264#define RT_D4(g1, g2, g3, g4) g1#g2#g3#g4
2265#define RT_D5(g1, g2, g3, g4, g5) g1#g2#g3#g4#g5
2266#define RT_D6(g1, g2, g3, g4, g5, g6) g1#g2#g3#g4#g5#g6
2267#define RT_D7(g1, g2, g3, g4, g5, g6, g7) g1#g2#g3#g4#g5#g6#g7
2268
2269#define RT_D1_U(g1) UINT32_C(g1)
2270#define RT_D2_U(g1, g2) UINT32_C(g1#g2)
2271#define RT_D3_U(g1, g2, g3) UINT32_C(g1#g2#g3)
2272#define RT_D4_U(g1, g2, g3, g4) UINT64_C(g1#g2#g3#g4)
2273#define RT_D5_U(g1, g2, g3, g4, g5) UINT64_C(g1#g2#g3#g4#g5)
2274#define RT_D6_U(g1, g2, g3, g4, g5, g6) UINT64_C(g1#g2#g3#g4#g5#g6)
2275#define RT_D7_U(g1, g2, g3, g4, g5, g6, g7) UINT64_C(g1#g2#g3#g4#g5#g6#g7)
2276
2277#define RT_D1_S(g1) INT32_C(g1)
2278#define RT_D2_S(g1, g2) INT32_C(g1#g2)
2279#define RT_D3_S(g1, g2, g3) INT32_C(g1#g2#g3)
2280#define RT_D4_S(g1, g2, g3, g4) INT64_C(g1#g2#g3#g4)
2281#define RT_D5_S(g1, g2, g3, g4, g5) INT64_C(g1#g2#g3#g4#g5)
2282#define RT_D6_S(g1, g2, g3, g4, g5, g6) INT64_C(g1#g2#g3#g4#g5#g6)
2283#define RT_D7_S(g1, g2, g3, g4, g5, g6, g7) INT64_C(g1#g2#g3#g4#g5#g6#g7)
2284
2285#define RT_D1_U32(g1) UINT32_C(g1)
2286#define RT_D2_U32(g1, g2) UINT32_C(g1#g2)
2287#define RT_D3_U32(g1, g2, g3) UINT32_C(g1#g2#g3)
2288#define RT_D4_U32(g1, g2, g3, g4) UINT32_C(g1#g2#g3#g4)
2289
2290#define RT_D1_S32(g1) INT32_C(g1)
2291#define RT_D2_S32(g1, g2) INT32_C(g1#g2)
2292#define RT_D3_S32(g1, g2, g3) INT32_C(g1#g2#g3)
2293#define RT_D4_S32(g1, g2, g3, g4) INT32_C(g1#g2#g3#g4)
2294
2295#define RT_D1_U64(g1) UINT64_C(g1)
2296#define RT_D2_U64(g1, g2) UINT64_C(g1#g2)
2297#define RT_D3_U64(g1, g2, g3) UINT64_C(g1#g2#g3)
2298#define RT_D4_U64(g1, g2, g3, g4) UINT64_C(g1#g2#g3#g4)
2299#define RT_D5_U64(g1, g2, g3, g4, g5) UINT64_C(g1#g2#g3#g4#g5)
2300#define RT_D6_U64(g1, g2, g3, g4, g5, g6) UINT64_C(g1#g2#g3#g4#g5#g6)
2301#define RT_D7_U64(g1, g2, g3, g4, g5, g6, g7) UINT64_C(g1#g2#g3#g4#g5#g6#g7)
2302
2303#define RT_D1_S64(g1) INT64_C(g1)
2304#define RT_D2_S64(g1, g2) INT64_C(g1#g2)
2305#define RT_D3_S64(g1, g2, g3) INT64_C(g1#g2#g3)
2306#define RT_D4_S64(g1, g2, g3, g4) INT64_C(g1#g2#g3#g4)
2307#define RT_D5_S64(g1, g2, g3, g4, g5) INT64_C(g1#g2#g3#g4#g5)
2308#define RT_D6_S64(g1, g2, g3, g4, g5, g6) INT64_C(g1#g2#g3#g4#g5#g6)
2309#define RT_D7_S64(g1, g2, g3, g4, g5, g6, g7) INT64_C(g1#g2#g3#g4#g5#g6#g7)
2310/** @} */
2311
2312
2313/** @defgroup grp_rt_cdefs_time Time Constants
2314 * @{
2315 */
2316/** 1 hour expressed in nanoseconds (64-bit). */
2317#define RT_NS_1HOUR UINT64_C(3600000000000)
2318/** 1 minute expressed in nanoseconds (64-bit). */
2319#define RT_NS_1MIN UINT64_C(60000000000)
2320/** 45 second expressed in nanoseconds. */
2321#define RT_NS_45SEC UINT64_C(45000000000)
2322/** 30 second expressed in nanoseconds. */
2323#define RT_NS_30SEC UINT64_C(30000000000)
2324/** 20 second expressed in nanoseconds. */
2325#define RT_NS_20SEC UINT64_C(20000000000)
2326/** 15 second expressed in nanoseconds. */
2327#define RT_NS_15SEC UINT64_C(15000000000)
2328/** 10 second expressed in nanoseconds. */
2329#define RT_NS_10SEC UINT64_C(10000000000)
2330/** 1 second expressed in nanoseconds. */
2331#define RT_NS_1SEC UINT32_C(1000000000)
2332/** 100 millsecond expressed in nanoseconds. */
2333#define RT_NS_100MS UINT32_C(100000000)
2334/** 10 millsecond expressed in nanoseconds. */
2335#define RT_NS_10MS UINT32_C(10000000)
2336/** 1 millsecond expressed in nanoseconds. */
2337#define RT_NS_1MS UINT32_C(1000000)
2338/** 100 microseconds expressed in nanoseconds. */
2339#define RT_NS_100US UINT32_C(100000)
2340/** 10 microseconds expressed in nanoseconds. */
2341#define RT_NS_10US UINT32_C(10000)
2342/** 1 microsecond expressed in nanoseconds. */
2343#define RT_NS_1US UINT32_C(1000)
2344
2345/** 1 second expressed in nanoseconds - 64-bit type. */
2346#define RT_NS_1SEC_64 UINT64_C(1000000000)
2347/** 100 millsecond expressed in nanoseconds - 64-bit type. */
2348#define RT_NS_100MS_64 UINT64_C(100000000)
2349/** 10 millsecond expressed in nanoseconds - 64-bit type. */
2350#define RT_NS_10MS_64 UINT64_C(10000000)
2351/** 1 millsecond expressed in nanoseconds - 64-bit type. */
2352#define RT_NS_1MS_64 UINT64_C(1000000)
2353/** 100 microseconds expressed in nanoseconds - 64-bit type. */
2354#define RT_NS_100US_64 UINT64_C(100000)
2355/** 10 microseconds expressed in nanoseconds - 64-bit type. */
2356#define RT_NS_10US_64 UINT64_C(10000)
2357/** 1 microsecond expressed in nanoseconds - 64-bit type. */
2358#define RT_NS_1US_64 UINT64_C(1000)
2359
2360/** 1 hour expressed in microseconds. */
2361#define RT_US_1HOUR UINT32_C(3600000000)
2362/** 1 minute expressed in microseconds. */
2363#define RT_US_1MIN UINT32_C(60000000)
2364/** 1 second expressed in microseconds. */
2365#define RT_US_1SEC UINT32_C(1000000)
2366/** 100 millsecond expressed in microseconds. */
2367#define RT_US_100MS UINT32_C(100000)
2368/** 10 millsecond expressed in microseconds. */
2369#define RT_US_10MS UINT32_C(10000)
2370/** 1 millsecond expressed in microseconds. */
2371#define RT_US_1MS UINT32_C(1000)
2372
2373/** 1 hour expressed in microseconds - 64-bit type. */
2374#define RT_US_1HOUR_64 UINT64_C(3600000000)
2375/** 1 minute expressed in microseconds - 64-bit type. */
2376#define RT_US_1MIN_64 UINT64_C(60000000)
2377/** 1 second expressed in microseconds - 64-bit type. */
2378#define RT_US_1SEC_64 UINT64_C(1000000)
2379/** 100 millsecond expressed in microseconds - 64-bit type. */
2380#define RT_US_100MS_64 UINT64_C(100000)
2381/** 10 millsecond expressed in microseconds - 64-bit type. */
2382#define RT_US_10MS_64 UINT64_C(10000)
2383/** 1 millsecond expressed in microseconds - 64-bit type. */
2384#define RT_US_1MS_64 UINT64_C(1000)
2385
2386/** 1 hour expressed in milliseconds. */
2387#define RT_MS_1HOUR UINT32_C(3600000)
2388/** 1 minute expressed in milliseconds. */
2389#define RT_MS_1MIN UINT32_C(60000)
2390/** 1 second expressed in milliseconds. */
2391#define RT_MS_1SEC UINT32_C(1000)
2392
2393/** 1 hour expressed in milliseconds - 64-bit type. */
2394#define RT_MS_1HOUR_64 UINT64_C(3600000)
2395/** 1 minute expressed in milliseconds - 64-bit type. */
2396#define RT_MS_1MIN_64 UINT64_C(60000)
2397/** 1 second expressed in milliseconds - 64-bit type. */
2398#define RT_MS_1SEC_64 UINT64_C(1000)
2399
2400/** The number of seconds per week. */
2401#define RT_SEC_1WEEK UINT32_C(604800)
2402/** The number of seconds per day. */
2403#define RT_SEC_1DAY UINT32_C(86400)
2404/** The number of seconds per hour. */
2405#define RT_SEC_1HOUR UINT32_C(3600)
2406
2407/** The number of seconds per week - 64-bit type. */
2408#define RT_SEC_1WEEK_64 UINT64_C(604800)
2409/** The number of seconds per day - 64-bit type. */
2410#define RT_SEC_1DAY_64 UINT64_C(86400)
2411/** The number of seconds per hour - 64-bit type. */
2412#define RT_SEC_1HOUR_64 UINT64_C(3600)
2413/** @} */
2414
2415
2416/** @defgroup grp_rt_cdefs_dbgtype Debug Info Types
2417 * @{ */
2418/** Other format. */
2419#define RT_DBGTYPE_OTHER RT_BIT_32(0)
2420/** Stabs. */
2421#define RT_DBGTYPE_STABS RT_BIT_32(1)
2422/** Debug With Arbitrary Record Format (DWARF). */
2423#define RT_DBGTYPE_DWARF RT_BIT_32(2)
2424/** Microsoft Codeview debug info. */
2425#define RT_DBGTYPE_CODEVIEW RT_BIT_32(3)
2426/** Watcom debug info. */
2427#define RT_DBGTYPE_WATCOM RT_BIT_32(4)
2428/** IBM High Level Language debug info. */
2429#define RT_DBGTYPE_HLL RT_BIT_32(5)
2430/** Old OS/2 and Windows symbol file. */
2431#define RT_DBGTYPE_SYM RT_BIT_32(6)
2432/** Map file. */
2433#define RT_DBGTYPE_MAP RT_BIT_32(7)
2434/** @} */
2435
2436
2437/** @defgroup grp_rt_cdefs_exetype Executable Image Types
2438 * @{ */
2439/** Some other format. */
2440#define RT_EXETYPE_OTHER RT_BIT_32(0)
2441/** Portable Executable. */
2442#define RT_EXETYPE_PE RT_BIT_32(1)
2443/** Linear eXecutable. */
2444#define RT_EXETYPE_LX RT_BIT_32(2)
2445/** Linear Executable. */
2446#define RT_EXETYPE_LE RT_BIT_32(3)
2447/** New Executable. */
2448#define RT_EXETYPE_NE RT_BIT_32(4)
2449/** DOS Executable (Mark Zbikowski). */
2450#define RT_EXETYPE_MZ RT_BIT_32(5)
2451/** COM Executable. */
2452#define RT_EXETYPE_COM RT_BIT_32(6)
2453/** a.out Executable. */
2454#define RT_EXETYPE_AOUT RT_BIT_32(7)
2455/** Executable and Linkable Format. */
2456#define RT_EXETYPE_ELF RT_BIT_32(8)
2457/** Mach-O Executable (including FAT ones). */
2458#define RT_EXETYPE_MACHO RT_BIT_32(9)
2459/** TE from UEFI. */
2460#define RT_EXETYPE_TE RT_BIT_32(9)
2461/** @} */
2462
2463
2464/** @def VALID_PTR
2465 * Pointer validation macro.
2466 * @param ptr The pointer.
2467 */
2468#if defined(RT_ARCH_AMD64)
2469# ifdef IN_RING3
2470# if defined(RT_OS_DARWIN) /* first 4GB is reserved for legacy kernel. */
2471# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) >= _4G \
2472 && !((uintptr_t)(ptr) & 0xffff800000000000ULL) )
2473# elif defined(RT_OS_SOLARIS) /* The kernel only used the top 2TB, but keep it simple. */
2474# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
2475 && ( ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0xffff800000000000ULL \
2476 || ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0) )
2477# else
2478# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
2479 && !((uintptr_t)(ptr) & 0xffff800000000000ULL) )
2480# endif
2481# else /* !IN_RING3 */
2482# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
2483 && ( ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0xffff800000000000ULL \
2484 || ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0) )
2485# endif /* !IN_RING3 */
2486
2487#elif defined(RT_ARCH_X86)
2488# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U )
2489
2490#elif defined(RT_ARCH_SPARC64)
2491# ifdef IN_RING3
2492# if defined(RT_OS_SOLARIS)
2493/** Sparc64 user mode: According to Figure 9.4 in solaris internals */
2494/** @todo # define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x80004000U >= 0x80004000U + 0x100000000ULL ) - figure this. */
2495# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x80000000U >= 0x80000000U + 0x100000000ULL )
2496# else
2497# error "Port me"
2498# endif
2499# else /* !IN_RING3 */
2500# if defined(RT_OS_SOLARIS)
2501/** @todo Sparc64 kernel mode: This is according to Figure 11.1 in solaris
2502 * internals. Verify in sources. */
2503# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) >= 0x01000000U )
2504# else
2505# error "Port me"
2506# endif
2507# endif /* !IN_RING3 */
2508
2509#elif defined(RT_ARCH_SPARC)
2510# ifdef IN_RING3
2511# ifdef RT_OS_SOLARIS
2512/** Sparc user mode: According to
2513 * http://cvs.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/uts/sun4/os/startup.c#510 */
2514# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x400000U >= 0x400000U + 0x2000U )
2515
2516# else
2517# error "Port me"
2518# endif
2519# else /* !IN_RING3 */
2520# ifdef RT_OS_SOLARIS
2521/** @todo Sparc kernel mode: Check the sources! */
2522# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U )
2523# else
2524# error "Port me"
2525# endif
2526# endif /* !IN_RING3 */
2527
2528#elif defined(RT_ARCH_ARM)
2529/* ASSUMES that at least the last and first 4K are out of bounds. */
2530# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U )
2531
2532#else
2533# error "Architecture identifier missing / not implemented."
2534#endif
2535
2536/** Old name for RT_VALID_PTR. */
2537#define VALID_PTR(ptr) RT_VALID_PTR(ptr)
2538
2539/** @def RT_VALID_ALIGNED_PTR
2540 * Pointer validation macro that also checks the alignment.
2541 * @param ptr The pointer.
2542 * @param align The alignment, must be a power of two.
2543 */
2544#define RT_VALID_ALIGNED_PTR(ptr, align) \
2545 ( !((uintptr_t)(ptr) & (uintptr_t)((align) - 1)) \
2546 && VALID_PTR(ptr) )
2547
2548
2549/** @def VALID_PHYS32
2550 * 32 bits physical address validation macro.
2551 * @param Phys The RTGCPHYS address.
2552 */
2553#define VALID_PHYS32(Phys) ( (uint64_t)(Phys) < (uint64_t)_4G )
2554
2555/** @def N_
2556 * The \#define N_ is used to mark a string for translation. This is usable in
2557 * any part of the code, as it is only used by the tools that create message
2558 * catalogs. This macro is a no-op as far as the compiler and code generation
2559 * is concerned.
2560 *
2561 * If you want to both mark a string for translation and translate it, use _().
2562 */
2563#define N_(s) (s)
2564
2565/** @def _
2566 * The \#define _ is used to mark a string for translation and to translate it
2567 * in one step.
2568 *
2569 * If you want to only mark a string for translation, use N_().
2570 */
2571#define _(s) gettext(s)
2572
2573
2574/** @def __PRETTY_FUNCTION__
2575 * With GNU C we'd like to use the builtin __PRETTY_FUNCTION__, so define that
2576 * for the other compilers.
2577 */
2578#if !defined(__GNUC__) && !defined(__PRETTY_FUNCTION__)
2579# ifdef _MSC_VER
2580# define __PRETTY_FUNCTION__ __FUNCSIG__
2581# else
2582# define __PRETTY_FUNCTION__ __FUNCTION__
2583# endif
2584#endif
2585
2586
2587/** @def RT_STRICT
2588 * The \#define RT_STRICT controls whether or not assertions and other runtime
2589 * checks should be compiled in or not. This is defined when DEBUG is defined.
2590 * If RT_NO_STRICT is defined, it will unconditionally be undefined.
2591 *
2592 * If you want assertions which are not subject to compile time options use
2593 * the AssertRelease*() flavors.
2594 */
2595#if !defined(RT_STRICT) && defined(DEBUG)
2596# define RT_STRICT
2597#endif
2598#ifdef RT_NO_STRICT
2599# undef RT_STRICT
2600#endif
2601
2602/** @todo remove this: */
2603#if !defined(RT_LOCK_STRICT) && !defined(DEBUG_bird)
2604# define RT_LOCK_NO_STRICT
2605#endif
2606#if !defined(RT_LOCK_STRICT_ORDER) && !defined(DEBUG_bird)
2607# define RT_LOCK_NO_STRICT_ORDER
2608#endif
2609
2610/** @def RT_LOCK_STRICT
2611 * The \#define RT_LOCK_STRICT controls whether deadlock detection and related
2612 * checks are done in the lock and semaphore code. It is by default enabled in
2613 * RT_STRICT builds, but this behavior can be overridden by defining
2614 * RT_LOCK_NO_STRICT. */
2615#if !defined(RT_LOCK_STRICT) && !defined(RT_LOCK_NO_STRICT) && defined(RT_STRICT)
2616# define RT_LOCK_STRICT
2617#endif
2618/** @def RT_LOCK_NO_STRICT
2619 * The \#define RT_LOCK_NO_STRICT disables RT_LOCK_STRICT. */
2620#if defined(RT_LOCK_NO_STRICT) && defined(RT_LOCK_STRICT)
2621# undef RT_LOCK_STRICT
2622#endif
2623
2624/** @def RT_LOCK_STRICT_ORDER
2625 * The \#define RT_LOCK_STRICT_ORDER controls whether locking order is checked
2626 * by the lock and semaphore code. It is by default enabled in RT_STRICT
2627 * builds, but this behavior can be overridden by defining
2628 * RT_LOCK_NO_STRICT_ORDER. */
2629#if !defined(RT_LOCK_STRICT_ORDER) && !defined(RT_LOCK_NO_STRICT_ORDER) && defined(RT_STRICT)
2630# define RT_LOCK_STRICT_ORDER
2631#endif
2632/** @def RT_LOCK_NO_STRICT_ORDER
2633 * The \#define RT_LOCK_NO_STRICT_ORDER disables RT_LOCK_STRICT_ORDER. */
2634#if defined(RT_LOCK_NO_STRICT_ORDER) && defined(RT_LOCK_STRICT_ORDER)
2635# undef RT_LOCK_STRICT_ORDER
2636#endif
2637
2638
2639/** Source position. */
2640#define RT_SRC_POS __FILE__, __LINE__, __PRETTY_FUNCTION__
2641
2642/** Source position declaration. */
2643#define RT_SRC_POS_DECL const char *pszFile, unsigned iLine, const char *pszFunction
2644
2645/** Source position arguments. */
2646#define RT_SRC_POS_ARGS pszFile, iLine, pszFunction
2647
2648/** Applies NOREF() to the source position arguments. */
2649#define RT_SRC_POS_NOREF() do { NOREF(pszFile); NOREF(iLine); NOREF(pszFunction); } while (0)
2650
2651
2652/** @def RT_INLINE_ASM_EXTERNAL
2653 * Defined as 1 if the compiler does not support inline assembly.
2654 * The ASM* functions will then be implemented in external .asm files.
2655 */
2656#if (defined(_MSC_VER) && defined(RT_ARCH_AMD64)) \
2657 || (!defined(RT_ARCH_AMD64) && !defined(RT_ARCH_X86))
2658# define RT_INLINE_ASM_EXTERNAL 1
2659#else
2660# define RT_INLINE_ASM_EXTERNAL 0
2661#endif
2662
2663/** @def RT_INLINE_ASM_GNU_STYLE
2664 * Defined as 1 if the compiler understands GNU style inline assembly.
2665 */
2666#if defined(_MSC_VER)
2667# define RT_INLINE_ASM_GNU_STYLE 0
2668#else
2669# define RT_INLINE_ASM_GNU_STYLE 1
2670#endif
2671
2672/** @def RT_INLINE_ASM_USES_INTRIN
2673 * Defined as the major MSC version if the compiler have and uses intrin.h.
2674 * Otherwise it is 0. */
2675#ifdef _MSC_VER
2676# if _MSC_VER >= 1700 /* Visual C++ v11.0 / 2012 */
2677# define RT_INLINE_ASM_USES_INTRIN 17
2678# elif _MSC_VER >= 1600 /* Visual C++ v10.0 / 2010 */
2679# define RT_INLINE_ASM_USES_INTRIN 16
2680# elif _MSC_VER >= 1500 /* Visual C++ v9.0 / 2008 */
2681# define RT_INLINE_ASM_USES_INTRIN 15
2682# elif _MSC_VER >= 1400 /* Visual C++ v8.0 / 2005 */
2683# define RT_INLINE_ASM_USES_INTRIN 14
2684# endif
2685#endif
2686#ifndef RT_INLINE_ASM_USES_INTRIN
2687# define RT_INLINE_ASM_USES_INTRIN 0
2688#endif
2689
2690/** @} */
2691
2692
2693/** @defgroup grp_rt_cdefs_cpp Special Macros for C++
2694 * @ingroup grp_rt_cdefs
2695 * @{
2696 */
2697
2698#ifdef __cplusplus
2699
2700/** @def DECLEXPORT_CLASS
2701 * How to declare an exported class. Place this macro after the 'class'
2702 * keyword in the declaration of every class you want to export.
2703 *
2704 * @note It is necessary to use this macro even for inner classes declared
2705 * inside the already exported classes. This is a GCC specific requirement,
2706 * but it seems not to harm other compilers.
2707 */
2708#if defined(_MSC_VER) || defined(RT_OS_OS2)
2709# define DECLEXPORT_CLASS __declspec(dllexport)
2710#elif defined(RT_USE_VISIBILITY_DEFAULT)
2711# define DECLEXPORT_CLASS __attribute__((visibility("default")))
2712#else
2713# define DECLEXPORT_CLASS
2714#endif
2715
2716/** @def DECLIMPORT_CLASS
2717 * How to declare an imported class Place this macro after the 'class'
2718 * keyword in the declaration of every class you want to export.
2719 *
2720 * @note It is necessary to use this macro even for inner classes declared
2721 * inside the already exported classes. This is a GCC specific requirement,
2722 * but it seems not to harm other compilers.
2723 */
2724#if defined(_MSC_VER) || (defined(RT_OS_OS2) && !defined(__IBMC__) && !defined(__IBMCPP__))
2725# define DECLIMPORT_CLASS __declspec(dllimport)
2726#elif defined(RT_USE_VISIBILITY_DEFAULT)
2727# define DECLIMPORT_CLASS __attribute__((visibility("default")))
2728#else
2729# define DECLIMPORT_CLASS
2730#endif
2731
2732/** @def WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP
2733 * Macro to work around error C2593 of the not-so-smart MSVC 7.x ambiguity
2734 * resolver. The following snippet clearly demonstrates the code causing this
2735 * error:
2736 * @code
2737 * class A
2738 * {
2739 * public:
2740 * operator bool() const { return false; }
2741 * operator int*() const { return NULL; }
2742 * };
2743 * int main()
2744 * {
2745 * A a;
2746 * if (!a);
2747 * if (a && 0);
2748 * return 0;
2749 * }
2750 * @endcode
2751 * The code itself seems pretty valid to me and GCC thinks the same.
2752 *
2753 * This macro fixes the compiler error by explicitly overloading implicit
2754 * global operators !, && and || that take the given class instance as one of
2755 * their arguments.
2756 *
2757 * The best is to use this macro right after the class declaration.
2758 *
2759 * @note The macro expands to nothing for compilers other than MSVC.
2760 *
2761 * @param Cls Class to apply the workaround to
2762 */
2763#if defined(_MSC_VER)
2764# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP(Cls) \
2765 inline bool operator! (const Cls &that) { return !bool (that); } \
2766 inline bool operator&& (const Cls &that, bool b) { return bool (that) && b; } \
2767 inline bool operator|| (const Cls &that, bool b) { return bool (that) || b; } \
2768 inline bool operator&& (bool b, const Cls &that) { return b && bool (that); } \
2769 inline bool operator|| (bool b, const Cls &that) { return b || bool (that); }
2770#else
2771# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP(Cls)
2772#endif
2773
2774/** @def WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL
2775 * Version of WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP for template classes.
2776 *
2777 * @param Tpl Name of the template class to apply the workaround to
2778 * @param ArgsDecl arguments of the template, as declared in |<>| after the
2779 * |template| keyword, including |<>|
2780 * @param Args arguments of the template, as specified in |<>| after the
2781 * template class name when using the, including |<>|
2782 *
2783 * Example:
2784 * @code
2785 * // template class declaration
2786 * template <class C>
2787 * class Foo { ... };
2788 * // applied workaround
2789 * WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL (Foo, <class C>, <C>)
2790 * @endcode
2791 */
2792#if defined(_MSC_VER)
2793# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL(Tpl, ArgsDecl, Args) \
2794 template ArgsDecl \
2795 inline bool operator! (const Tpl Args &that) { return !bool (that); } \
2796 template ArgsDecl \
2797 inline bool operator&& (const Tpl Args &that, bool b) { return bool (that) && b; } \
2798 template ArgsDecl \
2799 inline bool operator|| (const Tpl Args &that, bool b) { return bool (that) || b; } \
2800 template ArgsDecl \
2801 inline bool operator&& (bool b, const Tpl Args &that) { return b && bool (that); } \
2802 template ArgsDecl \
2803 inline bool operator|| (bool b, const Tpl Args &that) { return b || bool (that); }
2804#else
2805# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL(Tpl, ArgsDecl, Args)
2806#endif
2807
2808
2809/** @def DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP
2810 * Declares the copy constructor and the assignment operation as inlined no-ops
2811 * (non-existent functions) for the given class. Use this macro inside the
2812 * private section if you want to effectively disable these operations for your
2813 * class.
2814 *
2815 * @param Cls class name to declare for
2816 */
2817
2818#define DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(Cls) \
2819 inline Cls (const Cls &); \
2820 inline Cls &operator= (const Cls &);
2821
2822
2823/** @def DECLARE_CLS_NEW_DELETE_NOOP
2824 * Declares the new and delete operations as no-ops (non-existent functions)
2825 * for the given class. Use this macro inside the private section if you want
2826 * to effectively limit creating class instances on the stack only.
2827 *
2828 * @note The destructor of the given class must not be virtual, otherwise a
2829 * compile time error will occur. Note that this is not a drawback: having
2830 * the virtual destructor for a stack-based class is absolutely useless
2831 * (the real class of the stack-based instance is always known to the compiler
2832 * at compile time, so it will always call the correct destructor).
2833 *
2834 * @param Cls class name to declare for
2835 */
2836#define DECLARE_CLS_NEW_DELETE_NOOP(Cls) \
2837 inline static void *operator new (size_t); \
2838 inline static void operator delete (void *);
2839
2840#endif /* __cplusplus */
2841
2842/** @} */
2843
2844#endif
2845
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