VirtualBox

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

最後變更 在這個檔案從57922是 57572,由 vboxsync 提交於 10 年 前

IPRT: Started on accessing system certificate stores to get SSL roots for cURL.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 94.4 KB
 
1/** @file
2 * IPRT - Common C and C++ definitions.
3 */
4
5/*
6 * Copyright (C) 2006-2015 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.alldomusa.eu.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 targeting. 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_PROTO
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 * @remarks May not work on C++ methods, mainly intented for C-style APIs.
886 *
887 * @remarks The use of the nothrow attribute with GCC is because old compilers
888 * (4.1.1, 32-bit) leaking the nothrow into global space or something
889 * when used with RTDECL or similar. Using this forces use to have two
890 * macros, as the nothrow attribute is not for the function definition.
891 */
892#ifdef RT_EXCEPTIONS_ENABLED
893# ifdef __GNUC__
894# define RT_NO_THROW_PROTO __attribute__((__nothrow__))
895# else
896# define RT_NO_THROW_PROTO throw()
897# endif
898#else
899# define RT_NO_THROW_PROTO
900#endif
901
902/** @def RT_NO_THROW_DEF
903 * The counter part to RT_NO_THROW_PROTO that is added to the function
904 * definition.
905 */
906#if defined(RT_EXCEPTIONS_ENABLED) && !defined(__GNUC__)
907# define RT_NO_THROW_DEF RT_NO_THROW_PROTO
908#else
909# define RT_NO_THROW_DEF
910#endif
911
912/** @def RT_THROW
913 * How to express that a method or function throws a type of exceptions. Some
914 * compilers does not want this kind of information and will warning about it.
915 *
916 * @param type The type exception.
917 *
918 * @remarks If the actual throwing is done from the header, enclose it by
919 * \#ifdef RT_EXCEPTIONS_ENABLED ... \#else ... \#endif so the header
920 * compiles cleanly without exceptions enabled.
921 *
922 * Do NOT use this for the actual throwing of exceptions!
923 */
924#ifdef RT_EXCEPTIONS_ENABLED
925# ifdef _MSC_VER
926# if _MSC_VER >= 1310
927# define RT_THROW(type)
928# else
929# define RT_THROW(type) throw(type)
930# endif
931# else
932# define RT_THROW(type) throw(type)
933# endif
934#else
935# define RT_THROW(type)
936#endif
937
938/** @def RT_IPRT_FORMAT_ATTR
939 * Identifies a function taking an IPRT format string.
940 * @param a_iFmt The index (1-based) of the format string argument.
941 * @param a_iArgs The index (1-based) of the first format argument, use 0 for
942 * va_list.
943 */
944#if defined(__GNUC__) && defined(WITH_IPRT_FORMAT_ATTRIBUTE)
945# define RT_IPRT_FORMAT_ATTR(a_iFmt, a_iArgs) __attribute__((__iprt_format__(a_iFmt, a_iArgs)))
946#else
947# define RT_IPRT_FORMAT_ATTR(a_iFmt, a_iArgs)
948#endif
949
950/** @def RT_IPRT_FORMAT_ATTR_MAYBE_NULL
951 * Identifies a function taking an IPRT format string, NULL is allowed.
952 * @param a_iFmt The index (1-based) of the format string argument.
953 * @param a_iArgs The index (1-based) of the first format argument, use 0 for
954 * va_list.
955 */
956#if defined(__GNUC__) && defined(WITH_IPRT_FORMAT_ATTRIBUTE)
957# define RT_IPRT_FORMAT_ATTR_MAYBE_NULL(a_iFmt, a_iArgs) __attribute__((__iprt_format_maybe_null__(a_iFmt, a_iArgs)))
958#else
959# define RT_IPRT_FORMAT_ATTR_MAYBE_NULL(a_iFmt, a_iArgs)
960#endif
961
962
963/** @def RT_GCC_SUPPORTS_VISIBILITY_HIDDEN
964 * Indicates that the "hidden" visibility attribute can be used (GCC) */
965#if defined(__GNUC__)
966# if __GNUC__ >= 4 && !defined(RT_OS_OS2) && !defined(RT_OS_WINDOWS)
967# define RT_GCC_SUPPORTS_VISIBILITY_HIDDEN
968# endif
969#endif
970
971/** @def RTCALL
972 * The standard calling convention for the Runtime interfaces.
973 *
974 * @remarks The regparm(0) in the X86/GNUC variant deals with -mregparm=x use in
975 * the linux kernel and potentially elsewhere (3rd party).
976 */
977#ifdef _MSC_VER
978# define RTCALL __cdecl
979#elif defined(RT_OS_OS2)
980# define RTCALL __cdecl
981#elif defined(__GNUC__) && defined(RT_ARCH_X86)
982# define RTCALL __attribute__((cdecl,regparm(0)))
983#else
984# define RTCALL
985#endif
986
987/** @def DECLEXPORT
988 * How to declare an exported function.
989 * @param type The return type of the function declaration.
990 */
991#if defined(_MSC_VER) || defined(RT_OS_OS2)
992# define DECLEXPORT(type) __declspec(dllexport) type
993#elif defined(RT_USE_VISIBILITY_DEFAULT)
994# define DECLEXPORT(type) __attribute__((visibility("default"))) type
995#else
996# define DECLEXPORT(type) type
997#endif
998
999/** @def DECLIMPORT
1000 * How to declare an imported function.
1001 * @param type The return type of the function declaration.
1002 */
1003#if defined(_MSC_VER) || (defined(RT_OS_OS2) && !defined(__IBMC__) && !defined(__IBMCPP__))
1004# define DECLIMPORT(type) __declspec(dllimport) type
1005#else
1006# define DECLIMPORT(type) type
1007#endif
1008
1009/** @def DECLHIDDEN
1010 * How to declare a non-exported function or variable.
1011 * @param type The return type of the function or the data type of the variable.
1012 */
1013#if !defined(RT_GCC_SUPPORTS_VISIBILITY_HIDDEN) || defined(RT_NO_VISIBILITY_HIDDEN)
1014# define DECLHIDDEN(type) type
1015#else
1016# define DECLHIDDEN(type) __attribute__((visibility("hidden"))) type
1017#endif
1018
1019/** @def DECL_HIDDEN_CONST
1020 * Workaround for g++ warnings when applying the hidden attribute to a const
1021 * definition. Use DECLHIDDEN for the declaration.
1022 * @param a_Type The return type of the function or the data type of
1023 * the variable.
1024 */
1025#if defined(__cplusplus) && defined(__GNUC__)
1026# define DECL_HIDDEN_CONST(a_Type) a_Type
1027#else
1028# define DECL_HIDDEN_CONST(a_Type) DECLHIDDEN(a_Type)
1029#endif
1030
1031/** @def DECL_INVALID
1032 * How to declare a function not available for linking in the current context.
1033 * The purpose is to create compile or like time errors when used. This isn't
1034 * possible on all platforms.
1035 * @param type The return type of the function.
1036 */
1037#if defined(_MSC_VER)
1038# define DECL_INVALID(type) __declspec(dllimport) type __stdcall
1039#elif defined(__GNUC__) && defined(__cplusplus)
1040# define DECL_INVALID(type) extern "C++" type
1041#else
1042# define DECL_INVALID(type) type
1043#endif
1044
1045/** @def DECLASM
1046 * How to declare an internal assembly function.
1047 * @param type The return type of the function declaration.
1048 */
1049#ifdef __cplusplus
1050# define DECLASM(type) extern "C" type RTCALL
1051#else
1052# define DECLASM(type) type RTCALL
1053#endif
1054
1055/** @def DECLASMTYPE
1056 * How to declare an internal assembly function type.
1057 * @param type The return type of the function.
1058 */
1059#define DECLASMTYPE(type) type RTCALL
1060
1061/** @def DECLNORETURN
1062 * How to declare a function which does not return.
1063 * @note: This macro can be combined with other macros, for example
1064 * @code
1065 * EMR3DECL(DECLNORETURN(void)) foo(void);
1066 * @endcode
1067 */
1068#ifdef _MSC_VER
1069# define DECLNORETURN(type) __declspec(noreturn) type
1070#elif defined(__GNUC__)
1071# define DECLNORETURN(type) __attribute__((noreturn)) type
1072#else
1073# define DECLNORETURN(type) type
1074#endif
1075
1076/** @def DECLWEAK
1077 * How to declare a variable which is not necessarily resolved at
1078 * runtime.
1079 * @note: This macro can be combined with other macros, for example
1080 * @code
1081 * EMR3DECL(DECLWEAK(int)) foo;
1082 * @endcode
1083 */
1084#if defined(__GNUC__)
1085# define DECLWEAK(type) type __attribute__((weak))
1086#else
1087# define DECLWEAK(type) type
1088#endif
1089
1090/** @def DECLCALLBACK
1091 * How to declare an call back function type.
1092 * @param type The return type of the function declaration.
1093 */
1094#define DECLCALLBACK(type) type RTCALL
1095
1096/** @def DECLCALLBACKPTR
1097 * How to declare an call back function pointer.
1098 * @param type The return type of the function declaration.
1099 * @param name The name of the variable member.
1100 */
1101#if defined(__IBMC__) || defined(__IBMCPP__)
1102# define DECLCALLBACKPTR(type, name) type (* RTCALL name)
1103#else
1104# define DECLCALLBACKPTR(type, name) type (RTCALL * name)
1105#endif
1106
1107/** @def DECLCALLBACKMEMBER
1108 * How to declare an call back function pointer member.
1109 * @param type The return type of the function declaration.
1110 * @param name The name of the struct/union/class member.
1111 */
1112#if defined(__IBMC__) || defined(__IBMCPP__)
1113# define DECLCALLBACKMEMBER(type, name) type (* RTCALL name)
1114#else
1115# define DECLCALLBACKMEMBER(type, name) type (RTCALL * name)
1116#endif
1117
1118/** @def DECLR3CALLBACKMEMBER
1119 * How to declare an call back function pointer member - R3 Ptr.
1120 * @param type The return type of the function declaration.
1121 * @param name The name of the struct/union/class member.
1122 * @param args The argument list enclosed in parentheses.
1123 */
1124#ifdef IN_RING3
1125# define DECLR3CALLBACKMEMBER(type, name, args) DECLCALLBACKMEMBER(type, name) args
1126#else
1127# define DECLR3CALLBACKMEMBER(type, name, args) RTR3PTR name
1128#endif
1129
1130/** @def DECLRCCALLBACKMEMBER
1131 * How to declare an call back function pointer member - RC Ptr.
1132 * @param type The return type of the function declaration.
1133 * @param name The name of the struct/union/class member.
1134 * @param args The argument list enclosed in parentheses.
1135 */
1136#ifdef IN_RC
1137# define DECLRCCALLBACKMEMBER(type, name, args) DECLCALLBACKMEMBER(type, name) args
1138#else
1139# define DECLRCCALLBACKMEMBER(type, name, args) RTRCPTR name
1140#endif
1141
1142/** @def DECLR0CALLBACKMEMBER
1143 * How to declare an call back function pointer member - R0 Ptr.
1144 * @param type The return type of the function declaration.
1145 * @param name The name of the struct/union/class member.
1146 * @param args The argument list enclosed in parentheses.
1147 */
1148#ifdef IN_RING0
1149# define DECLR0CALLBACKMEMBER(type, name, args) DECLCALLBACKMEMBER(type, name) args
1150#else
1151# define DECLR0CALLBACKMEMBER(type, name, args) RTR0PTR name
1152#endif
1153
1154/** @def DECLINLINE
1155 * How to declare a function as inline.
1156 * @param type The return type of the function declaration.
1157 * @remarks Don't use this macro on C++ methods.
1158 */
1159#ifdef __GNUC__
1160# define DECLINLINE(type) static __inline__ type
1161#elif defined(__cplusplus)
1162# define DECLINLINE(type) inline type
1163#elif defined(_MSC_VER)
1164# define DECLINLINE(type) _inline type
1165#elif defined(__IBMC__)
1166# define DECLINLINE(type) _Inline type
1167#else
1168# define DECLINLINE(type) inline type
1169#endif
1170
1171
1172/** @def DECL_FORCE_INLINE
1173 * How to declare a function as inline and try convince the compiler to always
1174 * inline it regardless of optimization switches.
1175 * @param type The return type of the function declaration.
1176 * @remarks Use sparsely and with care. Don't use this macro on C++ methods.
1177 */
1178#ifdef __GNUC__
1179# define DECL_FORCE_INLINE(type) __attribute__((__always_inline__)) DECLINLINE(type)
1180#elif defined(_MSC_VER)
1181# define DECL_FORCE_INLINE(type) __forceinline type
1182#else
1183# define DECL_FORCE_INLINE(type) DECLINLINE(type)
1184#endif
1185
1186
1187/** @def DECL_NO_INLINE
1188 * How to declare a function telling the compiler not to inline it.
1189 * @param scope The function scope, static or RT_NOTHING.
1190 * @param type The return type of the function declaration.
1191 * @remarks Don't use this macro on C++ methods.
1192 */
1193#ifdef __GNUC__
1194# define DECL_NO_INLINE(scope,type) __attribute__((__noinline__)) scope type
1195#elif defined(_MSC_VER)
1196# define DECL_NO_INLINE(scope,type) __declspec(noinline) scope type
1197#else
1198# define DECL_NO_INLINE(scope,type) scope type
1199#endif
1200
1201
1202/** @def IN_RT_STATIC
1203 * Used to indicate whether we're linking against a static IPRT
1204 * or not. The IPRT symbols will be declared as hidden (if
1205 * supported). Note that this define has no effect without setting
1206 * IN_RT_R0, IN_RT_R3 or IN_RT_RC indicators are set first.
1207 */
1208
1209/** @def IN_RT_R0
1210 * Used to indicate whether we're inside the same link module as
1211 * the HC Ring-0 Runtime Library.
1212 */
1213/** @def RTR0DECL(type)
1214 * Runtime Library HC Ring-0 export or import declaration.
1215 * @param type The return type of the function declaration.
1216 */
1217#ifdef IN_RT_R0
1218# ifdef IN_RT_STATIC
1219# define RTR0DECL(type) DECLHIDDEN(type) RTCALL
1220# else
1221# define RTR0DECL(type) DECLEXPORT(type) RTCALL
1222# endif
1223#else
1224# define RTR0DECL(type) DECLIMPORT(type) RTCALL
1225#endif
1226
1227/** @def IN_RT_R3
1228 * Used to indicate whether we're inside the same link module as
1229 * the HC Ring-3 Runtime Library.
1230 */
1231/** @def RTR3DECL(type)
1232 * Runtime Library HC Ring-3 export or import declaration.
1233 * @param type The return type of the function declaration.
1234 */
1235#ifdef IN_RT_R3
1236# ifdef IN_RT_STATIC
1237# define RTR3DECL(type) DECLHIDDEN(type) RTCALL
1238# else
1239# define RTR3DECL(type) DECLEXPORT(type) RTCALL
1240# endif
1241#else
1242# define RTR3DECL(type) DECLIMPORT(type) RTCALL
1243#endif
1244
1245/** @def IN_RT_RC
1246 * Used to indicate whether we're inside the same link module as the raw-mode
1247 * context (RC) runtime library.
1248 */
1249/** @def RTRCDECL(type)
1250 * Runtime Library raw-mode context export or import declaration.
1251 * @param type The return type of the function declaration.
1252 */
1253#ifdef IN_RT_RC
1254# ifdef IN_RT_STATIC
1255# define RTRCDECL(type) DECLHIDDEN(type) RTCALL
1256# else
1257# define RTRCDECL(type) DECLEXPORT(type) RTCALL
1258# endif
1259#else
1260# define RTRCDECL(type) DECLIMPORT(type) RTCALL
1261#endif
1262
1263/** @def RTDECL(type)
1264 * Runtime Library export or import declaration.
1265 * Functions declared using this macro exists in all contexts.
1266 * @param type The return type of the function declaration.
1267 */
1268#if defined(IN_RT_R3) || defined(IN_RT_RC) || defined(IN_RT_R0)
1269# ifdef IN_RT_STATIC
1270# define RTDECL(type) DECLHIDDEN(type) RTCALL
1271# else
1272# define RTDECL(type) DECLEXPORT(type) RTCALL
1273# endif
1274#else
1275# define RTDECL(type) DECLIMPORT(type) RTCALL
1276#endif
1277
1278/** @def RTDATADECL(type)
1279 * Runtime Library export or import declaration.
1280 * Data declared using this macro exists in all contexts.
1281 * @param type The data type.
1282 */
1283/** @def RT_DECL_DATA_CONST(type)
1284 * Definition of a const variable. See DECL_HIDDEN_CONST.
1285 * @param type The const data type.
1286 */
1287#if defined(IN_RT_R3) || defined(IN_RT_RC) || defined(IN_RT_R0)
1288# ifdef IN_RT_STATIC
1289# define RTDATADECL(type) DECLHIDDEN(type)
1290# define RT_DECL_DATA_CONST(type) DECL_HIDDEN_CONST(type)
1291# else
1292# define RTDATADECL(type) DECLEXPORT(type)
1293# if defined(__cplusplus) && defined(__GNUC__)
1294# define RT_DECL_DATA_CONST(type) type
1295# else
1296# define RT_DECL_DATA_CONST(type) DECLEXPORT(type)
1297# endif
1298# endif
1299#else
1300# define RTDATADECL(type) DECLIMPORT(type)
1301# define RT_DECL_DATA_CONST(type) DECLIMPORT(type)
1302#endif
1303
1304/** @def RT_DECL_CLASS
1305 * Declares an class living in the runtime.
1306 */
1307#if defined(IN_RT_R3) || defined(IN_RT_RC) || defined(IN_RT_R0)
1308# ifdef IN_RT_STATIC
1309# define RT_DECL_CLASS
1310# else
1311# define RT_DECL_CLASS DECLEXPORT_CLASS
1312# endif
1313#else
1314# define RT_DECL_CLASS DECLIMPORT_CLASS
1315#endif
1316
1317
1318/** @def RT_NOCRT
1319 * Symbol name wrapper for the No-CRT bits.
1320 *
1321 * In order to coexist in the same process as other CRTs, we need to
1322 * decorate the symbols such that they don't conflict the ones in the
1323 * other CRTs. The result of such conflicts / duplicate symbols can
1324 * confuse the dynamic loader on Unix like systems.
1325 *
1326 * Define RT_WITHOUT_NOCRT_WRAPPERS to drop the wrapping.
1327 * Define RT_WITHOUT_NOCRT_WRAPPER_ALIASES to drop the aliases to the
1328 * wrapped names.
1329 */
1330/** @def RT_NOCRT_STR
1331 * Same as RT_NOCRT only it'll return a double quoted string of the result.
1332 */
1333#ifndef RT_WITHOUT_NOCRT_WRAPPERS
1334# define RT_NOCRT(name) nocrt_ ## name
1335# define RT_NOCRT_STR(name) "nocrt_" # name
1336#else
1337# define RT_NOCRT(name) name
1338# define RT_NOCRT_STR(name) #name
1339#endif
1340
1341
1342
1343/** @def RT_LIKELY
1344 * Give the compiler a hint that an expression is very likely to hold true.
1345 *
1346 * Some compilers support explicit branch prediction so that the CPU backend
1347 * can hint the processor and also so that code blocks can be reordered such
1348 * that the predicted path sees a more linear flow, thus improving cache
1349 * behaviour, etc.
1350 *
1351 * IPRT provides the macros RT_LIKELY() and RT_UNLIKELY() as a way to utilize
1352 * this compiler feature when present.
1353 *
1354 * A few notes about the usage:
1355 *
1356 * - Generally, order your code use RT_LIKELY() instead of RT_UNLIKELY().
1357 *
1358 * - Generally, use RT_UNLIKELY() with error condition checks (unless you
1359 * have some _strong_ reason to do otherwise, in which case document it),
1360 * and/or RT_LIKELY() with success condition checks, assuming you want
1361 * to optimize for the success path.
1362 *
1363 * - Other than that, if you don't know the likelihood of a test succeeding
1364 * from empirical or other 'hard' evidence, don't make predictions unless
1365 * you happen to be a Dirk Gently character.
1366 *
1367 * - These macros are meant to be used in places that get executed a lot. It
1368 * is wasteful to make predictions in code that is executed rarely (e.g.
1369 * at subsystem initialization time) as the basic block reordering that this
1370 * affects can often generate larger code.
1371 *
1372 * - Note that RT_SUCCESS() and RT_FAILURE() already makes use of RT_LIKELY()
1373 * and RT_UNLIKELY(). Should you wish for prediction free status checks,
1374 * use the RT_SUCCESS_NP() and RT_FAILURE_NP() macros instead.
1375 *
1376 *
1377 * @returns the boolean result of the expression.
1378 * @param expr The expression that's very likely to be true.
1379 * @see RT_UNLIKELY
1380 */
1381/** @def RT_UNLIKELY
1382 * Give the compiler a hint that an expression is highly unlikely to hold true.
1383 *
1384 * See the usage instructions give in the RT_LIKELY() docs.
1385 *
1386 * @returns the boolean result of the expression.
1387 * @param expr The expression that's very unlikely to be true.
1388 * @see RT_LIKELY
1389 *
1390 * @deprecated Please use RT_LIKELY() instead wherever possible! That gives us
1391 * a better chance of the windows compilers to generate favorable code
1392 * too. The belief is that the compiler will by default assume the
1393 * if-case is more likely than the else-case.
1394 */
1395#if defined(__GNUC__)
1396# if __GNUC__ >= 3 && !defined(FORTIFY_RUNNING)
1397# define RT_LIKELY(expr) __builtin_expect(!!(expr), 1)
1398# define RT_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
1399# else
1400# define RT_LIKELY(expr) (expr)
1401# define RT_UNLIKELY(expr) (expr)
1402# endif
1403#else
1404# define RT_LIKELY(expr) (expr)
1405# define RT_UNLIKELY(expr) (expr)
1406#endif
1407
1408
1409/** @def RT_STR
1410 * Returns the argument as a string constant.
1411 * @param str Argument to stringify. */
1412#define RT_STR(str) #str
1413/** @def RT_XSTR
1414 * Returns the expanded argument as a string.
1415 * @param str Argument to expand and stringy. */
1416#define RT_XSTR(str) RT_STR(str)
1417
1418/** @def RT_CONCAT
1419 * Concatenate the expanded arguments without any extra spaces in between.
1420 *
1421 * @param a The first part.
1422 * @param b The second part.
1423 */
1424#define RT_CONCAT(a,b) RT_CONCAT_HLP(a,b)
1425/** RT_CONCAT helper, don't use. */
1426#define RT_CONCAT_HLP(a,b) a##b
1427
1428/** @def RT_CONCAT
1429 * Concatenate the expanded arguments without any extra spaces in between.
1430 *
1431 * @param a The 1st part.
1432 * @param b The 2nd part.
1433 * @param c The 3rd part.
1434 */
1435#define RT_CONCAT3(a,b,c) RT_CONCAT3_HLP(a,b,c)
1436/** RT_CONCAT3 helper, don't use. */
1437#define RT_CONCAT3_HLP(a,b,c) a##b##c
1438
1439/** @def RT_CONCAT
1440 * Concatenate the expanded arguments without any extra spaces in between.
1441 *
1442 * @param a The 1st part.
1443 * @param b The 2nd part.
1444 * @param c The 3rd part.
1445 */
1446#define RT_CONCAT4(a,b,c,d) RT_CONCAT4_HLP(a,b,c,d)
1447/** RT_CONCAT4 helper, don't use. */
1448#define RT_CONCAT4_HLP(a,b,c,d) a##b##c##d
1449
1450/**
1451 * String constant tuple - string constant, strlen(string constant).
1452 *
1453 * @param a_szConst String constant.
1454 * @sa RTSTRTUPLE
1455 */
1456#define RT_STR_TUPLE(a_szConst) a_szConst, (sizeof(a_szConst) - 1)
1457
1458
1459/**
1460 * Macro for using in switch statements that turns constants into strings.
1461 *
1462 * @param a_Const The constant (not string).
1463 */
1464#define RT_CASE_RET_STR(a_Const) case a_Const: return #a_Const
1465
1466
1467/** @def RT_BIT
1468 * Convert a bit number into an integer bitmask (unsigned).
1469 * @param bit The bit number.
1470 */
1471#define RT_BIT(bit) ( 1U << (bit) )
1472
1473/** @def RT_BIT_32
1474 * Convert a bit number into a 32-bit bitmask (unsigned).
1475 * @param bit The bit number.
1476 */
1477#define RT_BIT_32(bit) ( UINT32_C(1) << (bit) )
1478
1479/** @def RT_BIT_64
1480 * Convert a bit number into a 64-bit bitmask (unsigned).
1481 * @param bit The bit number.
1482 */
1483#define RT_BIT_64(bit) ( UINT64_C(1) << (bit) )
1484
1485/** @def RT_ALIGN
1486 * Align macro.
1487 * @param u Value to align.
1488 * @param uAlignment The alignment. Power of two!
1489 *
1490 * @remark Be extremely careful when using this macro with type which sizeof != sizeof int.
1491 * When possible use any of the other RT_ALIGN_* macros. And when that's not
1492 * possible, make 101% sure that uAlignment is specified with a right sized type.
1493 *
1494 * Specifying an unsigned 32-bit alignment constant with a 64-bit value will give
1495 * you a 32-bit return value!
1496 *
1497 * In short: Don't use this macro. Use RT_ALIGN_T() instead.
1498 */
1499#define RT_ALIGN(u, uAlignment) ( ((u) + ((uAlignment) - 1)) & ~((uAlignment) - 1) )
1500
1501/** @def RT_ALIGN_T
1502 * Align macro.
1503 * @param u Value to align.
1504 * @param uAlignment The alignment. Power of two!
1505 * @param type Integer type to use while aligning.
1506 * @remark This macro is the preferred alignment macro, it doesn't have any of the pitfalls RT_ALIGN has.
1507 */
1508#define RT_ALIGN_T(u, uAlignment, type) ( ((type)(u) + ((uAlignment) - 1)) & ~(type)((uAlignment) - 1) )
1509
1510/** @def RT_ALIGN_32
1511 * Align macro for a 32-bit value.
1512 * @param u32 Value to align.
1513 * @param uAlignment The alignment. Power of two!
1514 */
1515#define RT_ALIGN_32(u32, uAlignment) RT_ALIGN_T(u32, uAlignment, uint32_t)
1516
1517/** @def RT_ALIGN_64
1518 * Align macro for a 64-bit value.
1519 * @param u64 Value to align.
1520 * @param uAlignment The alignment. Power of two!
1521 */
1522#define RT_ALIGN_64(u64, uAlignment) RT_ALIGN_T(u64, uAlignment, uint64_t)
1523
1524/** @def RT_ALIGN_Z
1525 * Align macro for size_t.
1526 * @param cb Value to align.
1527 * @param uAlignment The alignment. Power of two!
1528 */
1529#define RT_ALIGN_Z(cb, uAlignment) RT_ALIGN_T(cb, uAlignment, size_t)
1530
1531/** @def RT_ALIGN_P
1532 * Align macro for pointers.
1533 * @param pv Value to align.
1534 * @param uAlignment The alignment. Power of two!
1535 */
1536#define RT_ALIGN_P(pv, uAlignment) RT_ALIGN_PT(pv, uAlignment, void *)
1537
1538/** @def RT_ALIGN_PT
1539 * Align macro for pointers with type cast.
1540 * @param u Value to align.
1541 * @param uAlignment The alignment. Power of two!
1542 * @param CastType The type to cast the result to.
1543 */
1544#define RT_ALIGN_PT(u, uAlignment, CastType) ( (CastType)RT_ALIGN_T(u, uAlignment, uintptr_t) )
1545
1546/** @def RT_ALIGN_R3PT
1547 * Align macro for ring-3 pointers with type cast.
1548 * @param u Value to align.
1549 * @param uAlignment The alignment. Power of two!
1550 * @param CastType The type to cast the result to.
1551 */
1552#define RT_ALIGN_R3PT(u, uAlignment, CastType) ( (CastType)RT_ALIGN_T(u, uAlignment, RTR3UINTPTR) )
1553
1554/** @def RT_ALIGN_R0PT
1555 * Align macro for ring-0 pointers with type cast.
1556 * @param u Value to align.
1557 * @param uAlignment The alignment. Power of two!
1558 * @param CastType The type to cast the result to.
1559 */
1560#define RT_ALIGN_R0PT(u, uAlignment, CastType) ( (CastType)RT_ALIGN_T(u, uAlignment, RTR0UINTPTR) )
1561
1562/** @def RT_ALIGN_GCPT
1563 * Align macro for GC pointers with type cast.
1564 * @param u Value to align.
1565 * @param uAlignment The alignment. Power of two!
1566 * @param CastType The type to cast the result to.
1567 */
1568#define RT_ALIGN_GCPT(u, uAlignment, CastType) ( (CastType)RT_ALIGN_T(u, uAlignment, RTGCUINTPTR) )
1569
1570
1571/** @def RT_OFFSETOF
1572 * Our own special offsetof() variant, returns a signed result.
1573 *
1574 * This differs from the usual offsetof() in that it's not relying on builtin
1575 * compiler stuff and thus can use variables in arrays the structure may
1576 * contain. This is useful to determine the sizes of structures ending
1577 * with a variable length field. For gcc >= 4.4 see @bugref{7775}.
1578 *
1579 * @returns offset into the structure of the specified member. signed.
1580 * @param type Structure type.
1581 * @param member Member.
1582 */
1583#if defined(__GNUC__) && defined(__cplusplus) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
1584# define RT_OFFSETOF(type, member) ( (int)(uintptr_t)&( ((type *)(void *)0x1000)->member) - 0x1000 )
1585#else
1586# define RT_OFFSETOF(type, member) ( (int)(uintptr_t)&( ((type *)(void *)0)->member) )
1587#endif
1588
1589/** @def RT_UOFFSETOF
1590 * Our own special offsetof() variant, returns an unsigned result.
1591 *
1592 * This differs from the usual offsetof() in that it's not relying on builtin
1593 * compiler stuff and thus can use variables in arrays the structure may
1594 * contain. This is useful to determine the sizes of structures ending
1595 * with a variable length field. For gcc >= 4.4 see @bugref{7775}.
1596 *
1597 * @returns offset into the structure of the specified member. unsigned.
1598 * @param type Structure type.
1599 * @param member Member.
1600 */
1601#if defined(__GNUC__) && defined(__cplusplus) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
1602# define RT_UOFFSETOF(type, member) ( (uintptr_t)&( ((type *)(void *)0x1000)->member) - 0x1000 )
1603#else
1604# define RT_UOFFSETOF(type, member) ( (uintptr_t)&( ((type *)(void *)0)->member) )
1605#endif
1606
1607/** @def RT_OFFSETOF_ADD
1608 * RT_OFFSETOF with an addend.
1609 *
1610 * @returns offset into the structure of the specified member. signed.
1611 * @param type Structure type.
1612 * @param member Member.
1613 * @param addend The addend to add to the offset.
1614 */
1615#define RT_OFFSETOF_ADD(type, member, addend) ( (int)RT_UOFFSETOF_ADD(type, member, addend) )
1616
1617/** @def RT_UOFFSETOF_ADD
1618 * RT_UOFFSETOF with an addend.
1619 *
1620 * @returns offset into the structure of the specified member. signed.
1621 * @param type Structure type.
1622 * @param member Member.
1623 * @param addend The addend to add to the offset.
1624 */
1625#define RT_UOFFSETOF_ADD(type, member, addend) ( (uintptr_t)&( ((type *)(void *)(uintptr_t)(addend))->member) )
1626
1627/** @def RT_SIZEOFMEMB
1628 * Get the size of a structure member.
1629 *
1630 * @returns size of the structure member.
1631 * @param type Structure type.
1632 * @param member Member.
1633 */
1634#define RT_SIZEOFMEMB(type, member) ( sizeof(((type *)(void *)0)->member) )
1635
1636/** @def RT_FROM_MEMBER
1637 * Convert a pointer to a structure member into a pointer to the structure.
1638 *
1639 * @returns pointer to the structure.
1640 * @param pMem Pointer to the member.
1641 * @param Type Structure type.
1642 * @param Member Member name.
1643 */
1644#define RT_FROM_MEMBER(pMem, Type, Member) ( (Type *) ((uint8_t *)(void *)(pMem) - RT_UOFFSETOF(Type, Member)) )
1645
1646/** @def RT_FROM_CPP_MEMBER
1647 * Same as RT_FROM_MEMBER except it avoids the annoying g++ warnings about
1648 * invalid access to non-static data member of NULL object.
1649 *
1650 * @returns pointer to the structure.
1651 * @param pMem Pointer to the member.
1652 * @param Type Structure type.
1653 * @param Member Member name.
1654 *
1655 * @remarks Using the __builtin_offsetof does not shut up the compiler.
1656 */
1657#if defined(__GNUC__) && defined(__cplusplus)
1658# define RT_FROM_CPP_MEMBER(pMem, Type, Member) \
1659 ( (Type *) ((uintptr_t)(pMem) - (uintptr_t)&((Type *)0x1000)->Member + 0x1000U) )
1660#else
1661# define RT_FROM_CPP_MEMBER(pMem, Type, Member) RT_FROM_MEMBER(pMem, Type, Member)
1662#endif
1663
1664/** @def RT_ELEMENTS
1665 * Calculates the number of elements in a statically sized array.
1666 * @returns Element count.
1667 * @param aArray Array in question.
1668 */
1669#define RT_ELEMENTS(aArray) ( sizeof(aArray) / sizeof((aArray)[0]) )
1670
1671/**
1672 * Checks if the value is a power of two.
1673 *
1674 * @returns true if power of two, false if not.
1675 * @param uVal The value to test.
1676 * @remarks 0 is a power of two.
1677 * @see VERR_NOT_POWER_OF_TWO
1678 */
1679#define RT_IS_POWER_OF_TWO(uVal) ( ((uVal) & ((uVal) - 1)) == 0)
1680
1681#ifdef RT_OS_OS2
1682/* Undefine RT_MAX since there is an unfortunate clash with the max
1683 resource type define in os2.h. */
1684# undef RT_MAX
1685#endif
1686
1687/** @def RT_MAX
1688 * Finds the maximum value.
1689 * @returns The higher of the two.
1690 * @param Value1 Value 1
1691 * @param Value2 Value 2
1692 */
1693#define RT_MAX(Value1, Value2) ( (Value1) >= (Value2) ? (Value1) : (Value2) )
1694
1695/** @def RT_MIN
1696 * Finds the minimum value.
1697 * @returns The lower of the two.
1698 * @param Value1 Value 1
1699 * @param Value2 Value 2
1700 */
1701#define RT_MIN(Value1, Value2) ( (Value1) <= (Value2) ? (Value1) : (Value2) )
1702
1703/** @def RT_CLAMP
1704 * Clamps the value to minimum and maximum values.
1705 * @returns The clamped value.
1706 * @param Value The value to check.
1707 * @param Min Minimum value.
1708 * @param Max Maximum value.
1709 */
1710#define RT_CLAMP(Value, Min, Max) ( (Value) > (Max) ? (Max) : (Value) < (Min) ? (Min) : (Value) )
1711
1712/** @def RT_ABS
1713 * Get the absolute (non-negative) value.
1714 * @returns The absolute value of Value.
1715 * @param Value The value.
1716 */
1717#define RT_ABS(Value) ( (Value) >= 0 ? (Value) : -(Value) )
1718
1719/** @def RT_BOOL
1720 * Turn non-zero/zero into true/false
1721 * @returns The resulting boolean value.
1722 * @param Value The value.
1723 */
1724#define RT_BOOL(Value) ( !!(Value) )
1725
1726/** @def RT_LO_U8
1727 * Gets the low uint8_t of a uint16_t or something equivalent. */
1728#ifdef __GNUC__
1729# define RT_LO_U8(a) __extension__ ({ AssertCompile(sizeof((a)) == sizeof(uint16_t)); (uint8_t)(a); })
1730#else
1731# define RT_LO_U8(a) ( (uint8_t)(a) )
1732#endif
1733/** @def RT_HI_U8
1734 * Gets the high uint8_t of a uint16_t or something equivalent. */
1735#ifdef __GNUC__
1736# define RT_HI_U8(a) __extension__ ({ AssertCompile(sizeof((a)) == sizeof(uint16_t)); (uint8_t)((a) >> 8); })
1737#else
1738# define RT_HI_U8(a) ( (uint8_t)((a) >> 8) )
1739#endif
1740
1741/** @def RT_LO_U16
1742 * Gets the low uint16_t of a uint32_t or something equivalent. */
1743#ifdef __GNUC__
1744# define RT_LO_U16(a) __extension__ ({ AssertCompile(sizeof((a)) == sizeof(uint32_t)); (uint16_t)(a); })
1745#else
1746# define RT_LO_U16(a) ( (uint16_t)(a) )
1747#endif
1748/** @def RT_HI_U16
1749 * Gets the high uint16_t of a uint32_t or something equivalent. */
1750#ifdef __GNUC__
1751# define RT_HI_U16(a) __extension__ ({ AssertCompile(sizeof((a)) == sizeof(uint32_t)); (uint16_t)((a) >> 16); })
1752#else
1753# define RT_HI_U16(a) ( (uint16_t)((a) >> 16) )
1754#endif
1755
1756/** @def RT_LO_U32
1757 * Gets the low uint32_t of a uint64_t or something equivalent. */
1758#ifdef __GNUC__
1759# define RT_LO_U32(a) __extension__ ({ AssertCompile(sizeof((a)) == sizeof(uint64_t)); (uint32_t)(a); })
1760#else
1761# define RT_LO_U32(a) ( (uint32_t)(a) )
1762#endif
1763/** @def RT_HI_U32
1764 * Gets the high uint32_t of a uint64_t or something equivalent. */
1765#ifdef __GNUC__
1766# define RT_HI_U32(a) __extension__ ({ AssertCompile(sizeof((a)) == sizeof(uint64_t)); (uint32_t)((a) >> 32); })
1767#else
1768# define RT_HI_U32(a) ( (uint32_t)((a) >> 32) )
1769#endif
1770
1771/** @def RT_BYTE1
1772 * Gets the first byte of something. */
1773#define RT_BYTE1(a) ( (a) & 0xff )
1774/** @def RT_BYTE2
1775 * Gets the second byte of something. */
1776#define RT_BYTE2(a) ( ((a) >> 8) & 0xff )
1777/** @def RT_BYTE3
1778 * Gets the second byte of something. */
1779#define RT_BYTE3(a) ( ((a) >> 16) & 0xff )
1780/** @def RT_BYTE4
1781 * Gets the fourth byte of something. */
1782#define RT_BYTE4(a) ( ((a) >> 24) & 0xff )
1783/** @def RT_BYTE5
1784 * Gets the fifth byte of something. */
1785#define RT_BYTE5(a) ( ((a) >> 32) & 0xff )
1786/** @def RT_BYTE6
1787 * Gets the sixth byte of something. */
1788#define RT_BYTE6(a) ( ((a) >> 40) & 0xff )
1789/** @def RT_BYTE7
1790 * Gets the seventh byte of something. */
1791#define RT_BYTE7(a) ( ((a) >> 48) & 0xff )
1792/** @def RT_BYTE8
1793 * Gets the eight byte of something. */
1794#define RT_BYTE8(a) ( ((a) >> 56) & 0xff )
1795
1796
1797/** @def RT_LODWORD
1798 * Gets the low dword (=uint32_t) of something.
1799 * @deprecated Use RT_LO_U32. */
1800#define RT_LODWORD(a) ( (uint32_t)(a) )
1801/** @def RT_HIDWORD
1802 * Gets the high dword (=uint32_t) of a 64-bit of something.
1803 * @deprecated Use RT_HI_U32. */
1804#define RT_HIDWORD(a) ( (uint32_t)((a) >> 32) )
1805
1806/** @def RT_LOWORD
1807 * Gets the low word (=uint16_t) of something.
1808 * @deprecated Use RT_LO_U16. */
1809#define RT_LOWORD(a) ( (a) & 0xffff )
1810/** @def RT_HIWORD
1811 * Gets the high word (=uint16_t) of a 32-bit something.
1812 * @deprecated Use RT_HI_U16. */
1813#define RT_HIWORD(a) ( (a) >> 16 )
1814
1815/** @def RT_LOBYTE
1816 * Gets the low byte of something.
1817 * @deprecated Use RT_LO_U8. */
1818#define RT_LOBYTE(a) ( (a) & 0xff )
1819/** @def RT_HIBYTE
1820 * Gets the high byte of a 16-bit something.
1821 * @deprecated Use RT_HI_U8. */
1822#define RT_HIBYTE(a) ( (a) >> 8 )
1823
1824
1825/** @def RT_MAKE_U64
1826 * Constructs a uint64_t value from two uint32_t values.
1827 */
1828#define RT_MAKE_U64(Lo, Hi) ( (uint64_t)((uint32_t)(Hi)) << 32 | (uint32_t)(Lo) )
1829
1830/** @def RT_MAKE_U64_FROM_U16
1831 * Constructs a uint64_t value from four uint16_t values.
1832 */
1833#define RT_MAKE_U64_FROM_U16(w0, w1, w2, w3) \
1834 ((uint64_t)( (uint64_t)((uint16_t)(w3)) << 48 \
1835 | (uint64_t)((uint16_t)(w2)) << 32 \
1836 | (uint32_t)((uint16_t)(w1)) << 16 \
1837 | (uint16_t)(w0) ))
1838
1839/** @def RT_MAKE_U64_FROM_U8
1840 * Constructs a uint64_t value from eight uint8_t values.
1841 */
1842#define RT_MAKE_U64_FROM_U8(b0, b1, b2, b3, b4, b5, b6, b7) \
1843 ((uint64_t)( (uint64_t)((uint8_t)(b7)) << 56 \
1844 | (uint64_t)((uint8_t)(b6)) << 48 \
1845 | (uint64_t)((uint8_t)(b5)) << 40 \
1846 | (uint64_t)((uint8_t)(b4)) << 32 \
1847 | (uint32_t)((uint8_t)(b3)) << 24 \
1848 | (uint32_t)((uint8_t)(b2)) << 16 \
1849 | (uint16_t)((uint8_t)(b1)) << 8 \
1850 | (uint8_t)(b0) ))
1851
1852/** @def RT_MAKE_U32
1853 * Constructs a uint32_t value from two uint16_t values.
1854 */
1855#define RT_MAKE_U32(Lo, Hi) \
1856 ((uint32_t)( (uint32_t)((uint16_t)(Hi)) << 16 \
1857 | (uint16_t)(Lo) ))
1858
1859/** @def RT_MAKE_U32_FROM_U8
1860 * Constructs a uint32_t value from four uint8_t values.
1861 */
1862#define RT_MAKE_U32_FROM_U8(b0, b1, b2, b3) \
1863 ((uint32_t)( (uint32_t)((uint8_t)(b3)) << 24 \
1864 | (uint32_t)((uint8_t)(b2)) << 16 \
1865 | (uint16_t)((uint8_t)(b1)) << 8 \
1866 | (uint8_t)(b0) ))
1867
1868/** @def RT_MAKE_U16
1869 * Constructs a uint16_t value from two uint8_t values.
1870 */
1871#define RT_MAKE_U16(Lo, Hi) \
1872 ((uint16_t)( (uint16_t)((uint8_t)(Hi)) << 8 \
1873 | (uint8_t)(Lo) ))
1874
1875
1876/** @def RT_BSWAP_U64
1877 * Reverses the byte order of an uint64_t value. */
1878#if 0
1879# define RT_BSWAP_U64(u64) RT_BSWAP_U64_C(u64)
1880#elif defined(__GNUC__)
1881# define RT_BSWAP_U64(u64) (__builtin_constant_p((u64)) \
1882 ? RT_BSWAP_U64_C(u64) : ASMByteSwapU64(u64))
1883#else
1884# define RT_BSWAP_U64(u64) ASMByteSwapU64(u64)
1885#endif
1886
1887/** @def RT_BSWAP_U32
1888 * Reverses the byte order of an uint32_t value. */
1889#if 0
1890# define RT_BSWAP_U32(u32) RT_BSWAP_U32_C(u32)
1891#elif defined(__GNUC__)
1892# define RT_BSWAP_U32(u32) (__builtin_constant_p((u32)) \
1893 ? RT_BSWAP_U32_C(u32) : ASMByteSwapU32(u32))
1894#else
1895# define RT_BSWAP_U32(u32) ASMByteSwapU32(u32)
1896#endif
1897
1898/** @def RT_BSWAP_U16
1899 * Reverses the byte order of an uint16_t value. */
1900#if 0
1901# define RT_BSWAP_U16(u16) RT_BSWAP_U16_C(u16)
1902#elif defined(__GNUC__)
1903# define RT_BSWAP_U16(u16) (__builtin_constant_p((u16)) \
1904 ? RT_BSWAP_U16_C(u16) : ASMByteSwapU16(u16))
1905#else
1906# define RT_BSWAP_U16(u16) ASMByteSwapU16(u16)
1907#endif
1908
1909
1910/** @def RT_BSWAP_U64_C
1911 * Reverses the byte order of an uint64_t constant. */
1912#define RT_BSWAP_U64_C(u64) RT_MAKE_U64(RT_BSWAP_U32_C((u64) >> 32), RT_BSWAP_U32_C((u64) & 0xffffffff))
1913
1914/** @def RT_BSWAP_U32_C
1915 * Reverses the byte order of an uint32_t constant. */
1916#define RT_BSWAP_U32_C(u32) RT_MAKE_U32_FROM_U8(RT_BYTE4(u32), RT_BYTE3(u32), RT_BYTE2(u32), RT_BYTE1(u32))
1917
1918/** @def RT_BSWAP_U16_C
1919 * Reverses the byte order of an uint16_t constant. */
1920#define RT_BSWAP_U16_C(u16) RT_MAKE_U16(RT_HIBYTE(u16), RT_LOBYTE(u16))
1921
1922
1923/** @def RT_H2LE_U64
1924 * Converts an uint64_t value from host to little endian byte order. */
1925#ifdef RT_BIG_ENDIAN
1926# define RT_H2LE_U64(u64) RT_BSWAP_U64(u64)
1927#else
1928# define RT_H2LE_U64(u64) (u64)
1929#endif
1930
1931/** @def RT_H2LE_U64_C
1932 * Converts an uint64_t constant from host to little endian byte order. */
1933#ifdef RT_BIG_ENDIAN
1934# define RT_H2LE_U64_C(u64) RT_BSWAP_U64_C(u64)
1935#else
1936# define RT_H2LE_U64_C(u64) (u64)
1937#endif
1938
1939/** @def RT_H2LE_U32
1940 * Converts an uint32_t value from host to little endian byte order. */
1941#ifdef RT_BIG_ENDIAN
1942# define RT_H2LE_U32(u32) RT_BSWAP_U32(u32)
1943#else
1944# define RT_H2LE_U32(u32) (u32)
1945#endif
1946
1947/** @def RT_H2LE_U32_C
1948 * Converts an uint32_t constant from host to little endian byte order. */
1949#ifdef RT_BIG_ENDIAN
1950# define RT_H2LE_U32_C(u32) RT_BSWAP_U32_C(u32)
1951#else
1952# define RT_H2LE_U32_C(u32) (u32)
1953#endif
1954
1955/** @def RT_H2LE_U16
1956 * Converts an uint16_t value from host to little endian byte order. */
1957#ifdef RT_BIG_ENDIAN
1958# define RT_H2LE_U16(u16) RT_BSWAP_U16(u16)
1959#else
1960# define RT_H2LE_U16(u16) (u16)
1961#endif
1962
1963/** @def RT_H2LE_U16_C
1964 * Converts an uint16_t constant from host to little endian byte order. */
1965#ifdef RT_BIG_ENDIAN
1966# define RT_H2LE_U16_C(u16) RT_BSWAP_U16_C(u16)
1967#else
1968# define RT_H2LE_U16_C(u16) (u16)
1969#endif
1970
1971
1972/** @def RT_LE2H_U64
1973 * Converts an uint64_t value from little endian to host byte order. */
1974#ifdef RT_BIG_ENDIAN
1975# define RT_LE2H_U64(u64) RT_BSWAP_U64(u64)
1976#else
1977# define RT_LE2H_U64(u64) (u64)
1978#endif
1979
1980/** @def RT_LE2H_U64_C
1981 * Converts an uint64_t constant from little endian to host byte order. */
1982#ifdef RT_BIG_ENDIAN
1983# define RT_LE2H_U64_C(u64) RT_BSWAP_U64_C(u64)
1984#else
1985# define RT_LE2H_U64_C(u64) (u64)
1986#endif
1987
1988/** @def RT_LE2H_U32
1989 * Converts an uint32_t value from little endian to host byte order. */
1990#ifdef RT_BIG_ENDIAN
1991# define RT_LE2H_U32(u32) RT_BSWAP_U32(u32)
1992#else
1993# define RT_LE2H_U32(u32) (u32)
1994#endif
1995
1996/** @def RT_LE2H_U32_C
1997 * Converts an uint32_t constant from little endian to host byte order. */
1998#ifdef RT_BIG_ENDIAN
1999# define RT_LE2H_U32_C(u32) RT_BSWAP_U32_C(u32)
2000#else
2001# define RT_LE2H_U32_C(u32) (u32)
2002#endif
2003
2004/** @def RT_LE2H_U16
2005 * Converts an uint16_t value from little endian to host byte order. */
2006#ifdef RT_BIG_ENDIAN
2007# define RT_LE2H_U16(u16) RT_BSWAP_U16(u16)
2008#else
2009# define RT_LE2H_U16(u16) (u16)
2010#endif
2011
2012/** @def RT_LE2H_U16_C
2013 * Converts an uint16_t constant from little endian to host byte order. */
2014#ifdef RT_BIG_ENDIAN
2015# define RT_LE2H_U16_C(u16) RT_BSWAP_U16_C(u16)
2016#else
2017# define RT_LE2H_U16_C(u16) (u16)
2018#endif
2019
2020
2021/** @def RT_H2BE_U64
2022 * Converts an uint64_t value from host to big endian byte order. */
2023#ifdef RT_BIG_ENDIAN
2024# define RT_H2BE_U64(u64) (u64)
2025#else
2026# define RT_H2BE_U64(u64) RT_BSWAP_U64(u64)
2027#endif
2028
2029/** @def RT_H2BE_U64_C
2030 * Converts an uint64_t constant from host to big endian byte order. */
2031#ifdef RT_BIG_ENDIAN
2032# define RT_H2BE_U64_C(u64) (u64)
2033#else
2034# define RT_H2BE_U64_C(u64) RT_BSWAP_U64_C(u64)
2035#endif
2036
2037/** @def RT_H2BE_U32
2038 * Converts an uint32_t value from host to big endian byte order. */
2039#ifdef RT_BIG_ENDIAN
2040# define RT_H2BE_U32(u32) (u32)
2041#else
2042# define RT_H2BE_U32(u32) RT_BSWAP_U32(u32)
2043#endif
2044
2045/** @def RT_H2BE_U32_C
2046 * Converts an uint32_t constant from host to big endian byte order. */
2047#ifdef RT_BIG_ENDIAN
2048# define RT_H2BE_U32_C(u32) (u32)
2049#else
2050# define RT_H2BE_U32_C(u32) RT_BSWAP_U32_C(u32)
2051#endif
2052
2053/** @def RT_H2BE_U16
2054 * Converts an uint16_t value from host to big endian byte order. */
2055#ifdef RT_BIG_ENDIAN
2056# define RT_H2BE_U16(u16) (u16)
2057#else
2058# define RT_H2BE_U16(u16) RT_BSWAP_U16(u16)
2059#endif
2060
2061/** @def RT_H2BE_U16_C
2062 * Converts an uint16_t constant from host to big endian byte order. */
2063#ifdef RT_BIG_ENDIAN
2064# define RT_H2BE_U16_C(u16) (u16)
2065#else
2066# define RT_H2BE_U16_C(u16) RT_BSWAP_U16_C(u16)
2067#endif
2068
2069/** @def RT_BE2H_U64
2070 * Converts an uint64_t value from big endian to host byte order. */
2071#ifdef RT_BIG_ENDIAN
2072# define RT_BE2H_U64(u64) (u64)
2073#else
2074# define RT_BE2H_U64(u64) RT_BSWAP_U64(u64)
2075#endif
2076
2077/** @def RT_BE2H_U64
2078 * Converts an uint64_t constant from big endian to host byte order. */
2079#ifdef RT_BIG_ENDIAN
2080# define RT_BE2H_U64_C(u64) (u64)
2081#else
2082# define RT_BE2H_U64_C(u64) RT_BSWAP_U64_C(u64)
2083#endif
2084
2085/** @def RT_BE2H_U32
2086 * Converts an uint32_t value from big endian to host byte order. */
2087#ifdef RT_BIG_ENDIAN
2088# define RT_BE2H_U32(u32) (u32)
2089#else
2090# define RT_BE2H_U32(u32) RT_BSWAP_U32(u32)
2091#endif
2092
2093/** @def RT_BE2H_U32_C
2094 * Converts an uint32_t value from big endian to host byte order. */
2095#ifdef RT_BIG_ENDIAN
2096# define RT_BE2H_U32_C(u32) (u32)
2097#else
2098# define RT_BE2H_U32_C(u32) RT_BSWAP_U32_C(u32)
2099#endif
2100
2101/** @def RT_BE2H_U16
2102 * Converts an uint16_t value from big endian to host byte order. */
2103#ifdef RT_BIG_ENDIAN
2104# define RT_BE2H_U16(u16) (u16)
2105#else
2106# define RT_BE2H_U16(u16) RT_BSWAP_U16(u16)
2107#endif
2108
2109/** @def RT_BE2H_U16_C
2110 * Converts an uint16_t constant from big endian to host byte order. */
2111#ifdef RT_BIG_ENDIAN
2112# define RT_BE2H_U16_C(u16) (u16)
2113#else
2114# define RT_BE2H_U16_C(u16) RT_BSWAP_U16_C(u16)
2115#endif
2116
2117
2118/** @def RT_H2N_U64
2119 * Converts an uint64_t value from host to network byte order. */
2120#define RT_H2N_U64(u64) RT_H2BE_U64(u64)
2121
2122/** @def RT_H2N_U64_C
2123 * Converts an uint64_t constant from host to network byte order. */
2124#define RT_H2N_U64_C(u64) RT_H2BE_U64_C(u64)
2125
2126/** @def RT_H2N_U32
2127 * Converts an uint32_t value from host to network byte order. */
2128#define RT_H2N_U32(u32) RT_H2BE_U32(u32)
2129
2130/** @def RT_H2N_U32_C
2131 * Converts an uint32_t constant from host to network byte order. */
2132#define RT_H2N_U32_C(u32) RT_H2BE_U32_C(u32)
2133
2134/** @def RT_H2N_U16
2135 * Converts an uint16_t value from host to network byte order. */
2136#define RT_H2N_U16(u16) RT_H2BE_U16(u16)
2137
2138/** @def RT_H2N_U16_C
2139 * Converts an uint16_t constant from host to network byte order. */
2140#define RT_H2N_U16_C(u16) RT_H2BE_U16_C(u16)
2141
2142/** @def RT_N2H_U64
2143 * Converts an uint64_t value from network to host byte order. */
2144#define RT_N2H_U64(u64) RT_BE2H_U64(u64)
2145
2146/** @def RT_N2H_U64_C
2147 * Converts an uint64_t constant from network to host byte order. */
2148#define RT_N2H_U64_C(u64) RT_BE2H_U64_C(u64)
2149
2150/** @def RT_N2H_U32
2151 * Converts an uint32_t value from network to host byte order. */
2152#define RT_N2H_U32(u32) RT_BE2H_U32(u32)
2153
2154/** @def RT_N2H_U32_C
2155 * Converts an uint32_t constant from network to host byte order. */
2156#define RT_N2H_U32_C(u32) RT_BE2H_U32_C(u32)
2157
2158/** @def RT_N2H_U16
2159 * Converts an uint16_t value from network to host byte order. */
2160#define RT_N2H_U16(u16) RT_BE2H_U16(u16)
2161
2162/** @def RT_N2H_U16_C
2163 * Converts an uint16_t value from network to host byte order. */
2164#define RT_N2H_U16_C(u16) RT_BE2H_U16_C(u16)
2165
2166
2167/*
2168 * The BSD sys/param.h + machine/param.h file is a major source of
2169 * namespace pollution. Kill off some of the worse ones unless we're
2170 * compiling kernel code.
2171 */
2172#if defined(RT_OS_DARWIN) \
2173 && !defined(KERNEL) \
2174 && !defined(RT_NO_BSD_PARAM_H_UNDEFING) \
2175 && ( defined(_SYS_PARAM_H_) || defined(_I386_PARAM_H_) )
2176/* sys/param.h: */
2177# undef PSWP
2178# undef PVM
2179# undef PINOD
2180# undef PRIBO
2181# undef PVFS
2182# undef PZERO
2183# undef PSOCK
2184# undef PWAIT
2185# undef PLOCK
2186# undef PPAUSE
2187# undef PUSER
2188# undef PRIMASK
2189# undef MINBUCKET
2190# undef MAXALLOCSAVE
2191# undef FSHIFT
2192# undef FSCALE
2193
2194/* i386/machine.h: */
2195# undef ALIGN
2196# undef ALIGNBYTES
2197# undef DELAY
2198# undef STATUS_WORD
2199# undef USERMODE
2200# undef BASEPRI
2201# undef MSIZE
2202# undef CLSIZE
2203# undef CLSIZELOG2
2204#endif
2205
2206/** @def NIL_OFFSET
2207 * NIL offset.
2208 * Whenever we use offsets instead of pointers to save space and relocation effort
2209 * NIL_OFFSET shall be used as the equivalent to NULL.
2210 */
2211#define NIL_OFFSET (~0U)
2212
2213/** @def NOREF
2214 * Keeps the compiler from bitching about an unused parameter.
2215 */
2216#define NOREF(var) (void)(var)
2217
2218/** @def RT_BREAKPOINT
2219 * Emit a debug breakpoint instruction.
2220 *
2221 * @remarks In the x86/amd64 gnu world we add a nop instruction after the int3
2222 * to force gdb to remain at the int3 source line.
2223 * @remarks The L4 kernel will try make sense of the breakpoint, thus the jmp on
2224 * x86/amd64.
2225 */
2226#ifdef __GNUC__
2227# if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
2228# if !defined(__L4ENV__)
2229# define RT_BREAKPOINT() __asm__ __volatile__("int $3\n\tnop\n\t")
2230# else
2231# define RT_BREAKPOINT() __asm__ __volatile__("int3; jmp 1f; 1:\n\t")
2232# endif
2233# elif defined(RT_ARCH_SPARC64)
2234# define RT_BREAKPOINT() __asm__ __volatile__("illtrap 0\n\t") /** @todo Sparc64: this is just a wild guess. */
2235# elif defined(RT_ARCH_SPARC)
2236# define RT_BREAKPOINT() __asm__ __volatile__("unimp 0\n\t") /** @todo Sparc: this is just a wild guess (same as Sparc64, just different name). */
2237# endif
2238#endif
2239#ifdef _MSC_VER
2240# define RT_BREAKPOINT() __debugbreak()
2241#endif
2242#if defined(__IBMC__) || defined(__IBMCPP__)
2243# define RT_BREAKPOINT() __interrupt(3)
2244#endif
2245#ifndef RT_BREAKPOINT
2246# error "This compiler/arch is not supported!"
2247#endif
2248
2249
2250/** @defgroup grp_rt_cdefs_size Size Constants
2251 * (Of course, these are binary computer terms, not SI.)
2252 * @{
2253 */
2254/** 1 K (Kilo) (1 024). */
2255#define _1K 0x00000400
2256/** 2 K (Kilo) (2 048). */
2257#define _2K 0x00000800
2258/** 4 K (Kilo) (4 096). */
2259#define _4K 0x00001000
2260/** 8 K (Kilo) (8 192). */
2261#define _8K 0x00002000
2262/** 16 K (Kilo) (16 384). */
2263#define _16K 0x00004000
2264/** 32 K (Kilo) (32 678). */
2265#define _32K 0x00008000
2266/** 64 K (Kilo) (65 536). */
2267#define _64K 0x00010000
2268/** 128 K (Kilo) (131 072). */
2269#define _128K 0x00020000
2270/** 256 K (Kilo) (262 144). */
2271#define _256K 0x00040000
2272/** 512 K (Kilo) (524 288). */
2273#define _512K 0x00080000
2274/** 1 M (Mega) (1 048 576). */
2275#define _1M 0x00100000
2276/** 2 M (Mega) (2 097 152). */
2277#define _2M 0x00200000
2278/** 4 M (Mega) (4 194 304). */
2279#define _4M 0x00400000
2280/** 1 G (Giga) (1 073 741 824). (32-bit) */
2281#define _1G 0x40000000
2282/** 1 G (Giga) (1 073 741 824). (64-bit) */
2283#define _1G64 0x40000000LL
2284/** 2 G (Giga) (2 147 483 648). (32-bit) */
2285#define _2G32 0x80000000U
2286/** 2 G (Giga) (2 147 483 648). (64-bit) */
2287#define _2G 0x0000000080000000LL
2288/** 4 G (Giga) (4 294 967 296). */
2289#define _4G 0x0000000100000000LL
2290/** 1 T (Tera) (1 099 511 627 776). */
2291#define _1T 0x0000010000000000LL
2292/** 1 P (Peta) (1 125 899 906 842 624). */
2293#define _1P 0x0004000000000000LL
2294/** 1 E (Exa) (1 152 921 504 606 846 976). */
2295#define _1E 0x1000000000000000LL
2296/** 2 E (Exa) (2 305 843 009 213 693 952). */
2297#define _2E 0x2000000000000000ULL
2298/** @} */
2299
2300/** @defgroup grp_rt_cdefs_decimal_grouping Decimal Constant Grouping Macros
2301 * @{ */
2302#define RT_D1(g1) g1
2303#define RT_D2(g1, g2) g1#g2
2304#define RT_D3(g1, g2, g3) g1#g2#g3
2305#define RT_D4(g1, g2, g3, g4) g1#g2#g3#g4
2306#define RT_D5(g1, g2, g3, g4, g5) g1#g2#g3#g4#g5
2307#define RT_D6(g1, g2, g3, g4, g5, g6) g1#g2#g3#g4#g5#g6
2308#define RT_D7(g1, g2, g3, g4, g5, g6, g7) g1#g2#g3#g4#g5#g6#g7
2309
2310#define RT_D1_U(g1) UINT32_C(g1)
2311#define RT_D2_U(g1, g2) UINT32_C(g1#g2)
2312#define RT_D3_U(g1, g2, g3) UINT32_C(g1#g2#g3)
2313#define RT_D4_U(g1, g2, g3, g4) UINT64_C(g1#g2#g3#g4)
2314#define RT_D5_U(g1, g2, g3, g4, g5) UINT64_C(g1#g2#g3#g4#g5)
2315#define RT_D6_U(g1, g2, g3, g4, g5, g6) UINT64_C(g1#g2#g3#g4#g5#g6)
2316#define RT_D7_U(g1, g2, g3, g4, g5, g6, g7) UINT64_C(g1#g2#g3#g4#g5#g6#g7)
2317
2318#define RT_D1_S(g1) INT32_C(g1)
2319#define RT_D2_S(g1, g2) INT32_C(g1#g2)
2320#define RT_D3_S(g1, g2, g3) INT32_C(g1#g2#g3)
2321#define RT_D4_S(g1, g2, g3, g4) INT64_C(g1#g2#g3#g4)
2322#define RT_D5_S(g1, g2, g3, g4, g5) INT64_C(g1#g2#g3#g4#g5)
2323#define RT_D6_S(g1, g2, g3, g4, g5, g6) INT64_C(g1#g2#g3#g4#g5#g6)
2324#define RT_D7_S(g1, g2, g3, g4, g5, g6, g7) INT64_C(g1#g2#g3#g4#g5#g6#g7)
2325
2326#define RT_D1_U32(g1) UINT32_C(g1)
2327#define RT_D2_U32(g1, g2) UINT32_C(g1#g2)
2328#define RT_D3_U32(g1, g2, g3) UINT32_C(g1#g2#g3)
2329#define RT_D4_U32(g1, g2, g3, g4) UINT32_C(g1#g2#g3#g4)
2330
2331#define RT_D1_S32(g1) INT32_C(g1)
2332#define RT_D2_S32(g1, g2) INT32_C(g1#g2)
2333#define RT_D3_S32(g1, g2, g3) INT32_C(g1#g2#g3)
2334#define RT_D4_S32(g1, g2, g3, g4) INT32_C(g1#g2#g3#g4)
2335
2336#define RT_D1_U64(g1) UINT64_C(g1)
2337#define RT_D2_U64(g1, g2) UINT64_C(g1#g2)
2338#define RT_D3_U64(g1, g2, g3) UINT64_C(g1#g2#g3)
2339#define RT_D4_U64(g1, g2, g3, g4) UINT64_C(g1#g2#g3#g4)
2340#define RT_D5_U64(g1, g2, g3, g4, g5) UINT64_C(g1#g2#g3#g4#g5)
2341#define RT_D6_U64(g1, g2, g3, g4, g5, g6) UINT64_C(g1#g2#g3#g4#g5#g6)
2342#define RT_D7_U64(g1, g2, g3, g4, g5, g6, g7) UINT64_C(g1#g2#g3#g4#g5#g6#g7)
2343
2344#define RT_D1_S64(g1) INT64_C(g1)
2345#define RT_D2_S64(g1, g2) INT64_C(g1#g2)
2346#define RT_D3_S64(g1, g2, g3) INT64_C(g1#g2#g3)
2347#define RT_D4_S64(g1, g2, g3, g4) INT64_C(g1#g2#g3#g4)
2348#define RT_D5_S64(g1, g2, g3, g4, g5) INT64_C(g1#g2#g3#g4#g5)
2349#define RT_D6_S64(g1, g2, g3, g4, g5, g6) INT64_C(g1#g2#g3#g4#g5#g6)
2350#define RT_D7_S64(g1, g2, g3, g4, g5, g6, g7) INT64_C(g1#g2#g3#g4#g5#g6#g7)
2351/** @} */
2352
2353
2354/** @defgroup grp_rt_cdefs_time Time Constants
2355 * @{
2356 */
2357/** 1 hour expressed in nanoseconds (64-bit). */
2358#define RT_NS_1HOUR UINT64_C(3600000000000)
2359/** 1 minute expressed in nanoseconds (64-bit). */
2360#define RT_NS_1MIN UINT64_C(60000000000)
2361/** 45 second expressed in nanoseconds. */
2362#define RT_NS_45SEC UINT64_C(45000000000)
2363/** 30 second expressed in nanoseconds. */
2364#define RT_NS_30SEC UINT64_C(30000000000)
2365/** 20 second expressed in nanoseconds. */
2366#define RT_NS_20SEC UINT64_C(20000000000)
2367/** 15 second expressed in nanoseconds. */
2368#define RT_NS_15SEC UINT64_C(15000000000)
2369/** 10 second expressed in nanoseconds. */
2370#define RT_NS_10SEC UINT64_C(10000000000)
2371/** 1 second expressed in nanoseconds. */
2372#define RT_NS_1SEC UINT32_C(1000000000)
2373/** 100 millsecond expressed in nanoseconds. */
2374#define RT_NS_100MS UINT32_C(100000000)
2375/** 10 millsecond expressed in nanoseconds. */
2376#define RT_NS_10MS UINT32_C(10000000)
2377/** 1 millsecond expressed in nanoseconds. */
2378#define RT_NS_1MS UINT32_C(1000000)
2379/** 100 microseconds expressed in nanoseconds. */
2380#define RT_NS_100US UINT32_C(100000)
2381/** 10 microseconds expressed in nanoseconds. */
2382#define RT_NS_10US UINT32_C(10000)
2383/** 1 microsecond expressed in nanoseconds. */
2384#define RT_NS_1US UINT32_C(1000)
2385
2386/** 1 second expressed in nanoseconds - 64-bit type. */
2387#define RT_NS_1SEC_64 UINT64_C(1000000000)
2388/** 100 millsecond expressed in nanoseconds - 64-bit type. */
2389#define RT_NS_100MS_64 UINT64_C(100000000)
2390/** 10 millsecond expressed in nanoseconds - 64-bit type. */
2391#define RT_NS_10MS_64 UINT64_C(10000000)
2392/** 1 millsecond expressed in nanoseconds - 64-bit type. */
2393#define RT_NS_1MS_64 UINT64_C(1000000)
2394/** 100 microseconds expressed in nanoseconds - 64-bit type. */
2395#define RT_NS_100US_64 UINT64_C(100000)
2396/** 10 microseconds expressed in nanoseconds - 64-bit type. */
2397#define RT_NS_10US_64 UINT64_C(10000)
2398/** 1 microsecond expressed in nanoseconds - 64-bit type. */
2399#define RT_NS_1US_64 UINT64_C(1000)
2400
2401/** 1 hour expressed in microseconds. */
2402#define RT_US_1HOUR UINT32_C(3600000000)
2403/** 1 minute expressed in microseconds. */
2404#define RT_US_1MIN UINT32_C(60000000)
2405/** 1 second expressed in microseconds. */
2406#define RT_US_1SEC UINT32_C(1000000)
2407/** 100 millsecond expressed in microseconds. */
2408#define RT_US_100MS UINT32_C(100000)
2409/** 10 millsecond expressed in microseconds. */
2410#define RT_US_10MS UINT32_C(10000)
2411/** 1 millsecond expressed in microseconds. */
2412#define RT_US_1MS UINT32_C(1000)
2413
2414/** 1 hour expressed in microseconds - 64-bit type. */
2415#define RT_US_1HOUR_64 UINT64_C(3600000000)
2416/** 1 minute expressed in microseconds - 64-bit type. */
2417#define RT_US_1MIN_64 UINT64_C(60000000)
2418/** 1 second expressed in microseconds - 64-bit type. */
2419#define RT_US_1SEC_64 UINT64_C(1000000)
2420/** 100 millsecond expressed in microseconds - 64-bit type. */
2421#define RT_US_100MS_64 UINT64_C(100000)
2422/** 10 millsecond expressed in microseconds - 64-bit type. */
2423#define RT_US_10MS_64 UINT64_C(10000)
2424/** 1 millsecond expressed in microseconds - 64-bit type. */
2425#define RT_US_1MS_64 UINT64_C(1000)
2426
2427/** 1 hour expressed in milliseconds. */
2428#define RT_MS_1HOUR UINT32_C(3600000)
2429/** 1 minute expressed in milliseconds. */
2430#define RT_MS_1MIN UINT32_C(60000)
2431/** 1 second expressed in milliseconds. */
2432#define RT_MS_1SEC UINT32_C(1000)
2433
2434/** 1 hour expressed in milliseconds - 64-bit type. */
2435#define RT_MS_1HOUR_64 UINT64_C(3600000)
2436/** 1 minute expressed in milliseconds - 64-bit type. */
2437#define RT_MS_1MIN_64 UINT64_C(60000)
2438/** 1 second expressed in milliseconds - 64-bit type. */
2439#define RT_MS_1SEC_64 UINT64_C(1000)
2440
2441/** The number of seconds per week. */
2442#define RT_SEC_1WEEK UINT32_C(604800)
2443/** The number of seconds per day. */
2444#define RT_SEC_1DAY UINT32_C(86400)
2445/** The number of seconds per hour. */
2446#define RT_SEC_1HOUR UINT32_C(3600)
2447
2448/** The number of seconds per week - 64-bit type. */
2449#define RT_SEC_1WEEK_64 UINT64_C(604800)
2450/** The number of seconds per day - 64-bit type. */
2451#define RT_SEC_1DAY_64 UINT64_C(86400)
2452/** The number of seconds per hour - 64-bit type. */
2453#define RT_SEC_1HOUR_64 UINT64_C(3600)
2454/** @} */
2455
2456
2457/** @defgroup grp_rt_cdefs_dbgtype Debug Info Types
2458 * @{ */
2459/** Other format. */
2460#define RT_DBGTYPE_OTHER RT_BIT_32(0)
2461/** Stabs. */
2462#define RT_DBGTYPE_STABS RT_BIT_32(1)
2463/** Debug With Arbitrary Record Format (DWARF). */
2464#define RT_DBGTYPE_DWARF RT_BIT_32(2)
2465/** Microsoft Codeview debug info. */
2466#define RT_DBGTYPE_CODEVIEW RT_BIT_32(3)
2467/** Watcom debug info. */
2468#define RT_DBGTYPE_WATCOM RT_BIT_32(4)
2469/** IBM High Level Language debug info. */
2470#define RT_DBGTYPE_HLL RT_BIT_32(5)
2471/** Old OS/2 and Windows symbol file. */
2472#define RT_DBGTYPE_SYM RT_BIT_32(6)
2473/** Map file. */
2474#define RT_DBGTYPE_MAP RT_BIT_32(7)
2475/** @} */
2476
2477
2478/** @defgroup grp_rt_cdefs_exetype Executable Image Types
2479 * @{ */
2480/** Some other format. */
2481#define RT_EXETYPE_OTHER RT_BIT_32(0)
2482/** Portable Executable. */
2483#define RT_EXETYPE_PE RT_BIT_32(1)
2484/** Linear eXecutable. */
2485#define RT_EXETYPE_LX RT_BIT_32(2)
2486/** Linear Executable. */
2487#define RT_EXETYPE_LE RT_BIT_32(3)
2488/** New Executable. */
2489#define RT_EXETYPE_NE RT_BIT_32(4)
2490/** DOS Executable (Mark Zbikowski). */
2491#define RT_EXETYPE_MZ RT_BIT_32(5)
2492/** COM Executable. */
2493#define RT_EXETYPE_COM RT_BIT_32(6)
2494/** a.out Executable. */
2495#define RT_EXETYPE_AOUT RT_BIT_32(7)
2496/** Executable and Linkable Format. */
2497#define RT_EXETYPE_ELF RT_BIT_32(8)
2498/** Mach-O Executable (including FAT ones). */
2499#define RT_EXETYPE_MACHO RT_BIT_32(9)
2500/** TE from UEFI. */
2501#define RT_EXETYPE_TE RT_BIT_32(9)
2502/** @} */
2503
2504
2505/** @def VALID_PTR
2506 * Pointer validation macro.
2507 * @param ptr The pointer.
2508 */
2509#if defined(RT_ARCH_AMD64)
2510# ifdef IN_RING3
2511# if defined(RT_OS_DARWIN) /* first 4GB is reserved for legacy kernel. */
2512# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) >= _4G \
2513 && !((uintptr_t)(ptr) & 0xffff800000000000ULL) )
2514# elif defined(RT_OS_SOLARIS) /* The kernel only used the top 2TB, but keep it simple. */
2515# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
2516 && ( ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0xffff800000000000ULL \
2517 || ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0) )
2518# else
2519# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
2520 && !((uintptr_t)(ptr) & 0xffff800000000000ULL) )
2521# endif
2522# else /* !IN_RING3 */
2523# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
2524 && ( ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0xffff800000000000ULL \
2525 || ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0) )
2526# endif /* !IN_RING3 */
2527
2528#elif defined(RT_ARCH_X86)
2529# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U )
2530
2531#elif defined(RT_ARCH_SPARC64)
2532# ifdef IN_RING3
2533# if defined(RT_OS_SOLARIS)
2534/** Sparc64 user mode: According to Figure 9.4 in solaris internals */
2535/** @todo # define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x80004000U >= 0x80004000U + 0x100000000ULL ) - figure this. */
2536# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x80000000U >= 0x80000000U + 0x100000000ULL )
2537# else
2538# error "Port me"
2539# endif
2540# else /* !IN_RING3 */
2541# if defined(RT_OS_SOLARIS)
2542/** @todo Sparc64 kernel mode: This is according to Figure 11.1 in solaris
2543 * internals. Verify in sources. */
2544# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) >= 0x01000000U )
2545# else
2546# error "Port me"
2547# endif
2548# endif /* !IN_RING3 */
2549
2550#elif defined(RT_ARCH_SPARC)
2551# ifdef IN_RING3
2552# ifdef RT_OS_SOLARIS
2553/** Sparc user mode: According to
2554 * http://cvs.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/uts/sun4/os/startup.c#510 */
2555# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x400000U >= 0x400000U + 0x2000U )
2556
2557# else
2558# error "Port me"
2559# endif
2560# else /* !IN_RING3 */
2561# ifdef RT_OS_SOLARIS
2562/** @todo Sparc kernel mode: Check the sources! */
2563# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U )
2564# else
2565# error "Port me"
2566# endif
2567# endif /* !IN_RING3 */
2568
2569#elif defined(RT_ARCH_ARM)
2570/* ASSUMES that at least the last and first 4K are out of bounds. */
2571# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U )
2572
2573#else
2574# error "Architecture identifier missing / not implemented."
2575#endif
2576
2577/** Old name for RT_VALID_PTR. */
2578#define VALID_PTR(ptr) RT_VALID_PTR(ptr)
2579
2580/** @def RT_VALID_ALIGNED_PTR
2581 * Pointer validation macro that also checks the alignment.
2582 * @param ptr The pointer.
2583 * @param align The alignment, must be a power of two.
2584 */
2585#define RT_VALID_ALIGNED_PTR(ptr, align) \
2586 ( !((uintptr_t)(ptr) & (uintptr_t)((align) - 1)) \
2587 && VALID_PTR(ptr) )
2588
2589
2590/** @def VALID_PHYS32
2591 * 32 bits physical address validation macro.
2592 * @param Phys The RTGCPHYS address.
2593 */
2594#define VALID_PHYS32(Phys) ( (uint64_t)(Phys) < (uint64_t)_4G )
2595
2596/** @def N_
2597 * The \#define N_ is used to mark a string for translation. This is usable in
2598 * any part of the code, as it is only used by the tools that create message
2599 * catalogs. This macro is a no-op as far as the compiler and code generation
2600 * is concerned.
2601 *
2602 * If you want to both mark a string for translation and translate it, use _().
2603 */
2604#define N_(s) (s)
2605
2606/** @def _
2607 * The \#define _ is used to mark a string for translation and to translate it
2608 * in one step.
2609 *
2610 * If you want to only mark a string for translation, use N_().
2611 */
2612#define _(s) gettext(s)
2613
2614
2615/** @def __PRETTY_FUNCTION__
2616 * With GNU C we'd like to use the builtin __PRETTY_FUNCTION__, so define that
2617 * for the other compilers.
2618 */
2619#if !defined(__GNUC__) && !defined(__PRETTY_FUNCTION__)
2620# ifdef _MSC_VER
2621# define __PRETTY_FUNCTION__ __FUNCSIG__
2622# else
2623# define __PRETTY_FUNCTION__ __FUNCTION__
2624# endif
2625#endif
2626
2627
2628/** @def RT_STRICT
2629 * The \#define RT_STRICT controls whether or not assertions and other runtime
2630 * checks should be compiled in or not. This is defined when DEBUG is defined.
2631 * If RT_NO_STRICT is defined, it will unconditionally be undefined.
2632 *
2633 * If you want assertions which are not subject to compile time options use
2634 * the AssertRelease*() flavors.
2635 */
2636#if !defined(RT_STRICT) && defined(DEBUG)
2637# define RT_STRICT
2638#endif
2639#ifdef RT_NO_STRICT
2640# undef RT_STRICT
2641#endif
2642
2643/** @todo remove this: */
2644#if !defined(RT_LOCK_STRICT) && !defined(DEBUG_bird)
2645# define RT_LOCK_NO_STRICT
2646#endif
2647#if !defined(RT_LOCK_STRICT_ORDER) && !defined(DEBUG_bird)
2648# define RT_LOCK_NO_STRICT_ORDER
2649#endif
2650
2651/** @def RT_LOCK_STRICT
2652 * The \#define RT_LOCK_STRICT controls whether deadlock detection and related
2653 * checks are done in the lock and semaphore code. It is by default enabled in
2654 * RT_STRICT builds, but this behavior can be overridden by defining
2655 * RT_LOCK_NO_STRICT. */
2656#if !defined(RT_LOCK_STRICT) && !defined(RT_LOCK_NO_STRICT) && defined(RT_STRICT)
2657# define RT_LOCK_STRICT
2658#endif
2659/** @def RT_LOCK_NO_STRICT
2660 * The \#define RT_LOCK_NO_STRICT disables RT_LOCK_STRICT. */
2661#if defined(RT_LOCK_NO_STRICT) && defined(RT_LOCK_STRICT)
2662# undef RT_LOCK_STRICT
2663#endif
2664
2665/** @def RT_LOCK_STRICT_ORDER
2666 * The \#define RT_LOCK_STRICT_ORDER controls whether locking order is checked
2667 * by the lock and semaphore code. It is by default enabled in RT_STRICT
2668 * builds, but this behavior can be overridden by defining
2669 * RT_LOCK_NO_STRICT_ORDER. */
2670#if !defined(RT_LOCK_STRICT_ORDER) && !defined(RT_LOCK_NO_STRICT_ORDER) && defined(RT_STRICT)
2671# define RT_LOCK_STRICT_ORDER
2672#endif
2673/** @def RT_LOCK_NO_STRICT_ORDER
2674 * The \#define RT_LOCK_NO_STRICT_ORDER disables RT_LOCK_STRICT_ORDER. */
2675#if defined(RT_LOCK_NO_STRICT_ORDER) && defined(RT_LOCK_STRICT_ORDER)
2676# undef RT_LOCK_STRICT_ORDER
2677#endif
2678
2679
2680/** Source position. */
2681#define RT_SRC_POS __FILE__, __LINE__, RT_GCC_EXTENSION __PRETTY_FUNCTION__
2682
2683/** Source position declaration. */
2684#define RT_SRC_POS_DECL const char *pszFile, unsigned iLine, const char *pszFunction
2685
2686/** Source position arguments. */
2687#define RT_SRC_POS_ARGS pszFile, iLine, pszFunction
2688
2689/** Applies NOREF() to the source position arguments. */
2690#define RT_SRC_POS_NOREF() do { NOREF(pszFile); NOREF(iLine); NOREF(pszFunction); } while (0)
2691
2692
2693/** @def RT_INLINE_ASM_EXTERNAL
2694 * Defined as 1 if the compiler does not support inline assembly.
2695 * The ASM* functions will then be implemented in external .asm files.
2696 */
2697#if (defined(_MSC_VER) && defined(RT_ARCH_AMD64)) \
2698 || (!defined(RT_ARCH_AMD64) && !defined(RT_ARCH_X86))
2699# define RT_INLINE_ASM_EXTERNAL 1
2700#else
2701# define RT_INLINE_ASM_EXTERNAL 0
2702#endif
2703
2704/** @def RT_INLINE_ASM_GNU_STYLE
2705 * Defined as 1 if the compiler understands GNU style inline assembly.
2706 */
2707#if defined(_MSC_VER)
2708# define RT_INLINE_ASM_GNU_STYLE 0
2709#else
2710# define RT_INLINE_ASM_GNU_STYLE 1
2711#endif
2712
2713/** @def RT_INLINE_ASM_USES_INTRIN
2714 * Defined as the major MSC version if the compiler have and uses intrin.h.
2715 * Otherwise it is 0. */
2716#ifdef _MSC_VER
2717# if _MSC_VER >= 1700 /* Visual C++ v11.0 / 2012 */
2718# define RT_INLINE_ASM_USES_INTRIN 17
2719# elif _MSC_VER >= 1600 /* Visual C++ v10.0 / 2010 */
2720# define RT_INLINE_ASM_USES_INTRIN 16
2721# elif _MSC_VER >= 1500 /* Visual C++ v9.0 / 2008 */
2722# define RT_INLINE_ASM_USES_INTRIN 15
2723# elif _MSC_VER >= 1400 /* Visual C++ v8.0 / 2005 */
2724# define RT_INLINE_ASM_USES_INTRIN 14
2725# endif
2726#endif
2727#ifndef RT_INLINE_ASM_USES_INTRIN
2728# define RT_INLINE_ASM_USES_INTRIN 0
2729#endif
2730
2731/** @def RT_COMPILER_SUPPORTS_LAMBDA
2732 * If the defined, the compiler supports lambda expressions. These expressions
2733 * are useful for embedding assertions and type checks into macros. */
2734#if defined(_MSC_VER) && defined(__cplusplus)
2735# if _MSC_VER >= 1600 /* Visual C++ v10.0 / 2010 */
2736# define RT_COMPILER_SUPPORTS_LAMBDA
2737# endif
2738#elif defined(__GNUC__) && defined(__cplusplus)
2739/* 4.5 or later, I think, if in ++11 mode... */
2740#endif
2741
2742/** @} */
2743
2744
2745/** @defgroup grp_rt_cdefs_cpp Special Macros for C++
2746 * @ingroup grp_rt_cdefs
2747 * @{
2748 */
2749
2750#ifdef __cplusplus
2751
2752/** @def DECLEXPORT_CLASS
2753 * How to declare an exported class. Place this macro after the 'class'
2754 * keyword in the declaration of every class you want to export.
2755 *
2756 * @note It is necessary to use this macro even for inner classes declared
2757 * inside the already exported classes. This is a GCC specific requirement,
2758 * but it seems not to harm other compilers.
2759 */
2760#if defined(_MSC_VER) || defined(RT_OS_OS2)
2761# define DECLEXPORT_CLASS __declspec(dllexport)
2762#elif defined(RT_USE_VISIBILITY_DEFAULT)
2763# define DECLEXPORT_CLASS __attribute__((visibility("default")))
2764#else
2765# define DECLEXPORT_CLASS
2766#endif
2767
2768/** @def DECLIMPORT_CLASS
2769 * How to declare an imported class Place this macro after the 'class'
2770 * keyword in the declaration of every class you want to export.
2771 *
2772 * @note It is necessary to use this macro even for inner classes declared
2773 * inside the already exported classes. This is a GCC specific requirement,
2774 * but it seems not to harm other compilers.
2775 */
2776#if defined(_MSC_VER) || (defined(RT_OS_OS2) && !defined(__IBMC__) && !defined(__IBMCPP__))
2777# define DECLIMPORT_CLASS __declspec(dllimport)
2778#elif defined(RT_USE_VISIBILITY_DEFAULT)
2779# define DECLIMPORT_CLASS __attribute__((visibility("default")))
2780#else
2781# define DECLIMPORT_CLASS
2782#endif
2783
2784/** @def WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP
2785 * Macro to work around error C2593 of the not-so-smart MSVC 7.x ambiguity
2786 * resolver. The following snippet clearly demonstrates the code causing this
2787 * error:
2788 * @code
2789 * class A
2790 * {
2791 * public:
2792 * operator bool() const { return false; }
2793 * operator int*() const { return NULL; }
2794 * };
2795 * int main()
2796 * {
2797 * A a;
2798 * if (!a);
2799 * if (a && 0);
2800 * return 0;
2801 * }
2802 * @endcode
2803 * The code itself seems pretty valid to me and GCC thinks the same.
2804 *
2805 * This macro fixes the compiler error by explicitly overloading implicit
2806 * global operators !, && and || that take the given class instance as one of
2807 * their arguments.
2808 *
2809 * The best is to use this macro right after the class declaration.
2810 *
2811 * @note The macro expands to nothing for compilers other than MSVC.
2812 *
2813 * @param Cls Class to apply the workaround to
2814 */
2815#if defined(_MSC_VER)
2816# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP(Cls) \
2817 inline bool operator! (const Cls &that) { return !bool (that); } \
2818 inline bool operator&& (const Cls &that, bool b) { return bool (that) && b; } \
2819 inline bool operator|| (const Cls &that, bool b) { return bool (that) || b; } \
2820 inline bool operator&& (bool b, const Cls &that) { return b && bool (that); } \
2821 inline bool operator|| (bool b, const Cls &that) { return b || bool (that); }
2822#else
2823# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP(Cls)
2824#endif
2825
2826/** @def WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL
2827 * Version of WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP for template classes.
2828 *
2829 * @param Tpl Name of the template class to apply the workaround to
2830 * @param ArgsDecl arguments of the template, as declared in |<>| after the
2831 * |template| keyword, including |<>|
2832 * @param Args arguments of the template, as specified in |<>| after the
2833 * template class name when using the, including |<>|
2834 *
2835 * Example:
2836 * @code
2837 * // template class declaration
2838 * template <class C>
2839 * class Foo { ... };
2840 * // applied workaround
2841 * WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL (Foo, <class C>, <C>)
2842 * @endcode
2843 */
2844#if defined(_MSC_VER)
2845# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL(Tpl, ArgsDecl, Args) \
2846 template ArgsDecl \
2847 inline bool operator! (const Tpl Args &that) { return !bool (that); } \
2848 template ArgsDecl \
2849 inline bool operator&& (const Tpl Args &that, bool b) { return bool (that) && b; } \
2850 template ArgsDecl \
2851 inline bool operator|| (const Tpl Args &that, bool b) { return bool (that) || b; } \
2852 template ArgsDecl \
2853 inline bool operator&& (bool b, const Tpl Args &that) { return b && bool (that); } \
2854 template ArgsDecl \
2855 inline bool operator|| (bool b, const Tpl Args &that) { return b || bool (that); }
2856#else
2857# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL(Tpl, ArgsDecl, Args)
2858#endif
2859
2860
2861/** @def DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP
2862 * Declares the copy constructor and the assignment operation as inlined no-ops
2863 * (non-existent functions) for the given class. Use this macro inside the
2864 * private section if you want to effectively disable these operations for your
2865 * class.
2866 *
2867 * @param Cls class name to declare for
2868 */
2869
2870#define DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(Cls) \
2871 inline Cls (const Cls &); \
2872 inline Cls &operator= (const Cls &);
2873
2874
2875/** @def DECLARE_CLS_NEW_DELETE_NOOP
2876 * Declares the new and delete operations as no-ops (non-existent functions)
2877 * for the given class. Use this macro inside the private section if you want
2878 * to effectively limit creating class instances on the stack only.
2879 *
2880 * @note The destructor of the given class must not be virtual, otherwise a
2881 * compile time error will occur. Note that this is not a drawback: having
2882 * the virtual destructor for a stack-based class is absolutely useless
2883 * (the real class of the stack-based instance is always known to the compiler
2884 * at compile time, so it will always call the correct destructor).
2885 *
2886 * @param Cls class name to declare for
2887 */
2888#define DECLARE_CLS_NEW_DELETE_NOOP(Cls) \
2889 inline static void *operator new (size_t); \
2890 inline static void operator delete (void *);
2891
2892#endif /* __cplusplus */
2893
2894/** @} */
2895
2896#endif
2897
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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