VirtualBox

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

Last change on this file since 58955 was 58955, checked in by vboxsync, 9 years ago

iprt/cdefs.h: Added the RT_BF_SET and RT_BF_CLEAR macros.

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

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