VirtualBox

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

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

iprt/cdefs.h: RTCALL should be cdecl for WATCOMC. (external asm linking)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 97.3 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/** @def RT_ALIGN
1508 * Align macro.
1509 * @param u Value to align.
1510 * @param uAlignment The alignment. Power of two!
1511 *
1512 * @remark Be extremely careful when using this macro with type which sizeof != sizeof int.
1513 * When possible use any of the other RT_ALIGN_* macros. And when that's not
1514 * possible, make 101% sure that uAlignment is specified with a right sized type.
1515 *
1516 * Specifying an unsigned 32-bit alignment constant with a 64-bit value will give
1517 * you a 32-bit return value!
1518 *
1519 * In short: Don't use this macro. Use RT_ALIGN_T() instead.
1520 */
1521#define RT_ALIGN(u, uAlignment) ( ((u) + ((uAlignment) - 1)) & ~((uAlignment) - 1) )
1522
1523/** @def RT_ALIGN_T
1524 * Align macro.
1525 * @param u Value to align.
1526 * @param uAlignment The alignment. Power of two!
1527 * @param type Integer type to use while aligning.
1528 * @remark This macro is the preferred alignment macro, it doesn't have any of the pitfalls RT_ALIGN has.
1529 */
1530#define RT_ALIGN_T(u, uAlignment, type) ( ((type)(u) + ((uAlignment) - 1)) & ~(type)((uAlignment) - 1) )
1531
1532/** @def RT_ALIGN_32
1533 * Align macro for a 32-bit value.
1534 * @param u32 Value to align.
1535 * @param uAlignment The alignment. Power of two!
1536 */
1537#define RT_ALIGN_32(u32, uAlignment) RT_ALIGN_T(u32, uAlignment, uint32_t)
1538
1539/** @def RT_ALIGN_64
1540 * Align macro for a 64-bit value.
1541 * @param u64 Value to align.
1542 * @param uAlignment The alignment. Power of two!
1543 */
1544#define RT_ALIGN_64(u64, uAlignment) RT_ALIGN_T(u64, uAlignment, uint64_t)
1545
1546/** @def RT_ALIGN_Z
1547 * Align macro for size_t.
1548 * @param cb Value to align.
1549 * @param uAlignment The alignment. Power of two!
1550 */
1551#define RT_ALIGN_Z(cb, uAlignment) RT_ALIGN_T(cb, uAlignment, size_t)
1552
1553/** @def RT_ALIGN_P
1554 * Align macro for pointers.
1555 * @param pv Value to align.
1556 * @param uAlignment The alignment. Power of two!
1557 */
1558#define RT_ALIGN_P(pv, uAlignment) RT_ALIGN_PT(pv, uAlignment, void *)
1559
1560/** @def RT_ALIGN_PT
1561 * Align macro for pointers with type cast.
1562 * @param u Value to align.
1563 * @param uAlignment The alignment. Power of two!
1564 * @param CastType The type to cast the result to.
1565 */
1566#define RT_ALIGN_PT(u, uAlignment, CastType) ( (CastType)RT_ALIGN_T(u, uAlignment, uintptr_t) )
1567
1568/** @def RT_ALIGN_R3PT
1569 * Align macro for ring-3 pointers with type cast.
1570 * @param u Value to align.
1571 * @param uAlignment The alignment. Power of two!
1572 * @param CastType The type to cast the result to.
1573 */
1574#define RT_ALIGN_R3PT(u, uAlignment, CastType) ( (CastType)RT_ALIGN_T(u, uAlignment, RTR3UINTPTR) )
1575
1576/** @def RT_ALIGN_R0PT
1577 * Align macro for ring-0 pointers with type cast.
1578 * @param u Value to align.
1579 * @param uAlignment The alignment. Power of two!
1580 * @param CastType The type to cast the result to.
1581 */
1582#define RT_ALIGN_R0PT(u, uAlignment, CastType) ( (CastType)RT_ALIGN_T(u, uAlignment, RTR0UINTPTR) )
1583
1584/** @def RT_ALIGN_GCPT
1585 * Align macro for GC pointers with type cast.
1586 * @param u Value to align.
1587 * @param uAlignment The alignment. Power of two!
1588 * @param CastType The type to cast the result to.
1589 */
1590#define RT_ALIGN_GCPT(u, uAlignment, CastType) ( (CastType)RT_ALIGN_T(u, uAlignment, RTGCUINTPTR) )
1591
1592
1593/** @def RT_OFFSETOF
1594 * Our own special offsetof() variant, returns a signed result.
1595 *
1596 * This differs from the usual offsetof() in that it's not relying on builtin
1597 * compiler stuff and thus can use variables in arrays the structure may
1598 * contain. This is useful to determine the sizes of structures ending
1599 * with a variable length field. For gcc >= 4.4 see @bugref{7775}.
1600 *
1601 * @returns offset into the structure of the specified member. signed.
1602 * @param type Structure type.
1603 * @param member Member.
1604 */
1605#if defined(__GNUC__) && defined(__cplusplus) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
1606# define RT_OFFSETOF(type, member) ( (int)(uintptr_t)&( ((type *)(void *)0x1000)->member) - 0x1000 )
1607#else
1608# define RT_OFFSETOF(type, member) ( (int)(uintptr_t)&( ((type *)(void *)0)->member) )
1609#endif
1610
1611/** @def RT_UOFFSETOF
1612 * Our own special offsetof() variant, returns an unsigned result.
1613 *
1614 * This differs from the usual offsetof() in that it's not relying on builtin
1615 * compiler stuff and thus can use variables in arrays the structure may
1616 * contain. This is useful to determine the sizes of structures ending
1617 * with a variable length field. For gcc >= 4.4 see @bugref{7775}.
1618 *
1619 * @returns offset into the structure of the specified member. unsigned.
1620 * @param type Structure type.
1621 * @param member Member.
1622 */
1623#if defined(__GNUC__) && defined(__cplusplus) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
1624# define RT_UOFFSETOF(type, member) ( (uintptr_t)&( ((type *)(void *)0x1000)->member) - 0x1000 )
1625#else
1626# define RT_UOFFSETOF(type, member) ( (uintptr_t)&( ((type *)(void *)0)->member) )
1627#endif
1628
1629/** @def RT_OFFSETOF_ADD
1630 * RT_OFFSETOF with an addend.
1631 *
1632 * @returns offset into the structure of the specified member. signed.
1633 * @param type Structure type.
1634 * @param member Member.
1635 * @param addend The addend to add to the offset.
1636 */
1637#define RT_OFFSETOF_ADD(type, member, addend) ( (int)RT_UOFFSETOF_ADD(type, member, addend) )
1638
1639/** @def RT_UOFFSETOF_ADD
1640 * RT_UOFFSETOF with an addend.
1641 *
1642 * @returns offset into the structure of the specified member. signed.
1643 * @param type Structure type.
1644 * @param member Member.
1645 * @param addend The addend to add to the offset.
1646 */
1647#define RT_UOFFSETOF_ADD(type, member, addend) ( (uintptr_t)&( ((type *)(void *)(uintptr_t)(addend))->member) )
1648
1649/** @def RT_SIZEOFMEMB
1650 * Get the size of a structure member.
1651 *
1652 * @returns size of the structure member.
1653 * @param type Structure type.
1654 * @param member Member.
1655 */
1656#define RT_SIZEOFMEMB(type, member) ( sizeof(((type *)(void *)0)->member) )
1657
1658/** @def RT_FROM_MEMBER
1659 * Convert a pointer to a structure member into a pointer to the structure.
1660 *
1661 * @returns pointer to the structure.
1662 * @param pMem Pointer to the member.
1663 * @param Type Structure type.
1664 * @param Member Member name.
1665 */
1666#define RT_FROM_MEMBER(pMem, Type, Member) ( (Type *) ((uint8_t *)(void *)(pMem) - RT_UOFFSETOF(Type, Member)) )
1667
1668/** @def RT_FROM_CPP_MEMBER
1669 * Same as RT_FROM_MEMBER except it avoids the annoying g++ warnings about
1670 * invalid access to non-static data member of NULL object.
1671 *
1672 * @returns pointer to the structure.
1673 * @param pMem Pointer to the member.
1674 * @param Type Structure type.
1675 * @param Member Member name.
1676 *
1677 * @remarks Using the __builtin_offsetof does not shut up the compiler.
1678 */
1679#if defined(__GNUC__) && defined(__cplusplus)
1680# define RT_FROM_CPP_MEMBER(pMem, Type, Member) \
1681 ( (Type *) ((uintptr_t)(pMem) - (uintptr_t)&((Type *)0x1000)->Member + 0x1000U) )
1682#else
1683# define RT_FROM_CPP_MEMBER(pMem, Type, Member) RT_FROM_MEMBER(pMem, Type, Member)
1684#endif
1685
1686/** @def RT_ELEMENTS
1687 * Calculates the number of elements in a statically sized array.
1688 * @returns Element count.
1689 * @param aArray Array in question.
1690 */
1691#define RT_ELEMENTS(aArray) ( sizeof(aArray) / sizeof((aArray)[0]) )
1692
1693/**
1694 * Checks if the value is a power of two.
1695 *
1696 * @returns true if power of two, false if not.
1697 * @param uVal The value to test.
1698 * @remarks 0 is a power of two.
1699 * @see VERR_NOT_POWER_OF_TWO
1700 */
1701#define RT_IS_POWER_OF_TWO(uVal) ( ((uVal) & ((uVal) - 1)) == 0)
1702
1703#ifdef RT_OS_OS2
1704/* Undefine RT_MAX since there is an unfortunate clash with the max
1705 resource type define in os2.h. */
1706# undef RT_MAX
1707#endif
1708
1709/** @def RT_MAX
1710 * Finds the maximum value.
1711 * @returns The higher of the two.
1712 * @param Value1 Value 1
1713 * @param Value2 Value 2
1714 */
1715#define RT_MAX(Value1, Value2) ( (Value1) >= (Value2) ? (Value1) : (Value2) )
1716
1717/** @def RT_MIN
1718 * Finds the minimum value.
1719 * @returns The lower of the two.
1720 * @param Value1 Value 1
1721 * @param Value2 Value 2
1722 */
1723#define RT_MIN(Value1, Value2) ( (Value1) <= (Value2) ? (Value1) : (Value2) )
1724
1725/** @def RT_CLAMP
1726 * Clamps the value to minimum and maximum values.
1727 * @returns The clamped value.
1728 * @param Value The value to check.
1729 * @param Min Minimum value.
1730 * @param Max Maximum value.
1731 */
1732#define RT_CLAMP(Value, Min, Max) ( (Value) > (Max) ? (Max) : (Value) < (Min) ? (Min) : (Value) )
1733
1734/** @def RT_ABS
1735 * Get the absolute (non-negative) value.
1736 * @returns The absolute value of Value.
1737 * @param Value The value.
1738 */
1739#define RT_ABS(Value) ( (Value) >= 0 ? (Value) : -(Value) )
1740
1741/** @def RT_BOOL
1742 * Turn non-zero/zero into true/false
1743 * @returns The resulting boolean value.
1744 * @param Value The value.
1745 */
1746#define RT_BOOL(Value) ( !!(Value) )
1747
1748/** @def RT_LO_U8
1749 * Gets the low uint8_t of a uint16_t or something equivalent. */
1750#ifdef __GNUC__
1751# define RT_LO_U8(a) __extension__ ({ AssertCompile(sizeof((a)) == sizeof(uint16_t)); (uint8_t)(a); })
1752#else
1753# define RT_LO_U8(a) ( (uint8_t)(a) )
1754#endif
1755/** @def RT_HI_U8
1756 * Gets the high uint8_t of a uint16_t or something equivalent. */
1757#ifdef __GNUC__
1758# define RT_HI_U8(a) __extension__ ({ AssertCompile(sizeof((a)) == sizeof(uint16_t)); (uint8_t)((a) >> 8); })
1759#else
1760# define RT_HI_U8(a) ( (uint8_t)((a) >> 8) )
1761#endif
1762
1763/** @def RT_LO_U16
1764 * Gets the low uint16_t of a uint32_t or something equivalent. */
1765#ifdef __GNUC__
1766# define RT_LO_U16(a) __extension__ ({ AssertCompile(sizeof((a)) == sizeof(uint32_t)); (uint16_t)(a); })
1767#else
1768# define RT_LO_U16(a) ( (uint16_t)(a) )
1769#endif
1770/** @def RT_HI_U16
1771 * Gets the high uint16_t of a uint32_t or something equivalent. */
1772#ifdef __GNUC__
1773# define RT_HI_U16(a) __extension__ ({ AssertCompile(sizeof((a)) == sizeof(uint32_t)); (uint16_t)((a) >> 16); })
1774#else
1775# define RT_HI_U16(a) ( (uint16_t)((a) >> 16) )
1776#endif
1777
1778/** @def RT_LO_U32
1779 * Gets the low uint32_t of a uint64_t or something equivalent. */
1780#ifdef __GNUC__
1781# define RT_LO_U32(a) __extension__ ({ AssertCompile(sizeof((a)) == sizeof(uint64_t)); (uint32_t)(a); })
1782#else
1783# define RT_LO_U32(a) ( (uint32_t)(a) )
1784#endif
1785/** @def RT_HI_U32
1786 * Gets the high uint32_t of a uint64_t or something equivalent. */
1787#ifdef __GNUC__
1788# define RT_HI_U32(a) __extension__ ({ AssertCompile(sizeof((a)) == sizeof(uint64_t)); (uint32_t)((a) >> 32); })
1789#else
1790# define RT_HI_U32(a) ( (uint32_t)((a) >> 32) )
1791#endif
1792
1793/** @def RT_BYTE1
1794 * Gets the first byte of something. */
1795#define RT_BYTE1(a) ( (a) & 0xff )
1796/** @def RT_BYTE2
1797 * Gets the second byte of something. */
1798#define RT_BYTE2(a) ( ((a) >> 8) & 0xff )
1799/** @def RT_BYTE3
1800 * Gets the second byte of something. */
1801#define RT_BYTE3(a) ( ((a) >> 16) & 0xff )
1802/** @def RT_BYTE4
1803 * Gets the fourth byte of something. */
1804#define RT_BYTE4(a) ( ((a) >> 24) & 0xff )
1805/** @def RT_BYTE5
1806 * Gets the fifth byte of something. */
1807#define RT_BYTE5(a) ( ((a) >> 32) & 0xff )
1808/** @def RT_BYTE6
1809 * Gets the sixth byte of something. */
1810#define RT_BYTE6(a) ( ((a) >> 40) & 0xff )
1811/** @def RT_BYTE7
1812 * Gets the seventh byte of something. */
1813#define RT_BYTE7(a) ( ((a) >> 48) & 0xff )
1814/** @def RT_BYTE8
1815 * Gets the eight byte of something. */
1816#define RT_BYTE8(a) ( ((a) >> 56) & 0xff )
1817
1818
1819/** @def RT_LODWORD
1820 * Gets the low dword (=uint32_t) of something.
1821 * @deprecated Use RT_LO_U32. */
1822#define RT_LODWORD(a) ( (uint32_t)(a) )
1823/** @def RT_HIDWORD
1824 * Gets the high dword (=uint32_t) of a 64-bit of something.
1825 * @deprecated Use RT_HI_U32. */
1826#define RT_HIDWORD(a) ( (uint32_t)((a) >> 32) )
1827
1828/** @def RT_LOWORD
1829 * Gets the low word (=uint16_t) of something.
1830 * @deprecated Use RT_LO_U16. */
1831#define RT_LOWORD(a) ( (a) & 0xffff )
1832/** @def RT_HIWORD
1833 * Gets the high word (=uint16_t) of a 32-bit something.
1834 * @deprecated Use RT_HI_U16. */
1835#define RT_HIWORD(a) ( (a) >> 16 )
1836
1837/** @def RT_LOBYTE
1838 * Gets the low byte of something.
1839 * @deprecated Use RT_LO_U8. */
1840#define RT_LOBYTE(a) ( (a) & 0xff )
1841/** @def RT_HIBYTE
1842 * Gets the high byte of a 16-bit something.
1843 * @deprecated Use RT_HI_U8. */
1844#define RT_HIBYTE(a) ( (a) >> 8 )
1845
1846
1847/** @def RT_MAKE_U64
1848 * Constructs a uint64_t value from two uint32_t values.
1849 */
1850#define RT_MAKE_U64(Lo, Hi) ( (uint64_t)((uint32_t)(Hi)) << 32 | (uint32_t)(Lo) )
1851
1852/** @def RT_MAKE_U64_FROM_U16
1853 * Constructs a uint64_t value from four uint16_t values.
1854 */
1855#define RT_MAKE_U64_FROM_U16(w0, w1, w2, w3) \
1856 ((uint64_t)( (uint64_t)((uint16_t)(w3)) << 48 \
1857 | (uint64_t)((uint16_t)(w2)) << 32 \
1858 | (uint32_t)((uint16_t)(w1)) << 16 \
1859 | (uint16_t)(w0) ))
1860
1861/** @def RT_MAKE_U64_FROM_U8
1862 * Constructs a uint64_t value from eight uint8_t values.
1863 */
1864#define RT_MAKE_U64_FROM_U8(b0, b1, b2, b3, b4, b5, b6, b7) \
1865 ((uint64_t)( (uint64_t)((uint8_t)(b7)) << 56 \
1866 | (uint64_t)((uint8_t)(b6)) << 48 \
1867 | (uint64_t)((uint8_t)(b5)) << 40 \
1868 | (uint64_t)((uint8_t)(b4)) << 32 \
1869 | (uint32_t)((uint8_t)(b3)) << 24 \
1870 | (uint32_t)((uint8_t)(b2)) << 16 \
1871 | (uint16_t)((uint8_t)(b1)) << 8 \
1872 | (uint8_t)(b0) ))
1873
1874/** @def RT_MAKE_U32
1875 * Constructs a uint32_t value from two uint16_t values.
1876 */
1877#define RT_MAKE_U32(Lo, Hi) \
1878 ((uint32_t)( (uint32_t)((uint16_t)(Hi)) << 16 \
1879 | (uint16_t)(Lo) ))
1880
1881/** @def RT_MAKE_U32_FROM_U8
1882 * Constructs a uint32_t value from four uint8_t values.
1883 */
1884#define RT_MAKE_U32_FROM_U8(b0, b1, b2, b3) \
1885 ((uint32_t)( (uint32_t)((uint8_t)(b3)) << 24 \
1886 | (uint32_t)((uint8_t)(b2)) << 16 \
1887 | (uint16_t)((uint8_t)(b1)) << 8 \
1888 | (uint8_t)(b0) ))
1889
1890/** @def RT_MAKE_U16
1891 * Constructs a uint16_t value from two uint8_t values.
1892 */
1893#define RT_MAKE_U16(Lo, Hi) \
1894 ((uint16_t)( (uint16_t)((uint8_t)(Hi)) << 8 \
1895 | (uint8_t)(Lo) ))
1896
1897
1898/** @def RT_BSWAP_U64
1899 * Reverses the byte order of an uint64_t value. */
1900#if 0
1901# define RT_BSWAP_U64(u64) RT_BSWAP_U64_C(u64)
1902#elif defined(__GNUC__)
1903# define RT_BSWAP_U64(u64) (__builtin_constant_p((u64)) \
1904 ? RT_BSWAP_U64_C(u64) : ASMByteSwapU64(u64))
1905#else
1906# define RT_BSWAP_U64(u64) ASMByteSwapU64(u64)
1907#endif
1908
1909/** @def RT_BSWAP_U32
1910 * Reverses the byte order of an uint32_t value. */
1911#if 0
1912# define RT_BSWAP_U32(u32) RT_BSWAP_U32_C(u32)
1913#elif defined(__GNUC__)
1914# define RT_BSWAP_U32(u32) (__builtin_constant_p((u32)) \
1915 ? RT_BSWAP_U32_C(u32) : ASMByteSwapU32(u32))
1916#else
1917# define RT_BSWAP_U32(u32) ASMByteSwapU32(u32)
1918#endif
1919
1920/** @def RT_BSWAP_U16
1921 * Reverses the byte order of an uint16_t value. */
1922#if 0
1923# define RT_BSWAP_U16(u16) RT_BSWAP_U16_C(u16)
1924#elif defined(__GNUC__)
1925# define RT_BSWAP_U16(u16) (__builtin_constant_p((u16)) \
1926 ? RT_BSWAP_U16_C(u16) : ASMByteSwapU16(u16))
1927#else
1928# define RT_BSWAP_U16(u16) ASMByteSwapU16(u16)
1929#endif
1930
1931
1932/** @def RT_BSWAP_U64_C
1933 * Reverses the byte order of an uint64_t constant. */
1934#define RT_BSWAP_U64_C(u64) RT_MAKE_U64(RT_BSWAP_U32_C((u64) >> 32), RT_BSWAP_U32_C((u64) & 0xffffffff))
1935
1936/** @def RT_BSWAP_U32_C
1937 * Reverses the byte order of an uint32_t constant. */
1938#define RT_BSWAP_U32_C(u32) RT_MAKE_U32_FROM_U8(RT_BYTE4(u32), RT_BYTE3(u32), RT_BYTE2(u32), RT_BYTE1(u32))
1939
1940/** @def RT_BSWAP_U16_C
1941 * Reverses the byte order of an uint16_t constant. */
1942#define RT_BSWAP_U16_C(u16) RT_MAKE_U16(RT_HIBYTE(u16), RT_LOBYTE(u16))
1943
1944
1945/** @def RT_H2LE_U64
1946 * Converts an uint64_t value from host to little endian byte order. */
1947#ifdef RT_BIG_ENDIAN
1948# define RT_H2LE_U64(u64) RT_BSWAP_U64(u64)
1949#else
1950# define RT_H2LE_U64(u64) (u64)
1951#endif
1952
1953/** @def RT_H2LE_U64_C
1954 * Converts an uint64_t constant from host to little endian byte order. */
1955#ifdef RT_BIG_ENDIAN
1956# define RT_H2LE_U64_C(u64) RT_BSWAP_U64_C(u64)
1957#else
1958# define RT_H2LE_U64_C(u64) (u64)
1959#endif
1960
1961/** @def RT_H2LE_U32
1962 * Converts an uint32_t value from host to little endian byte order. */
1963#ifdef RT_BIG_ENDIAN
1964# define RT_H2LE_U32(u32) RT_BSWAP_U32(u32)
1965#else
1966# define RT_H2LE_U32(u32) (u32)
1967#endif
1968
1969/** @def RT_H2LE_U32_C
1970 * Converts an uint32_t constant from host to little endian byte order. */
1971#ifdef RT_BIG_ENDIAN
1972# define RT_H2LE_U32_C(u32) RT_BSWAP_U32_C(u32)
1973#else
1974# define RT_H2LE_U32_C(u32) (u32)
1975#endif
1976
1977/** @def RT_H2LE_U16
1978 * Converts an uint16_t value from host to little endian byte order. */
1979#ifdef RT_BIG_ENDIAN
1980# define RT_H2LE_U16(u16) RT_BSWAP_U16(u16)
1981#else
1982# define RT_H2LE_U16(u16) (u16)
1983#endif
1984
1985/** @def RT_H2LE_U16_C
1986 * Converts an uint16_t constant from host to little endian byte order. */
1987#ifdef RT_BIG_ENDIAN
1988# define RT_H2LE_U16_C(u16) RT_BSWAP_U16_C(u16)
1989#else
1990# define RT_H2LE_U16_C(u16) (u16)
1991#endif
1992
1993
1994/** @def RT_LE2H_U64
1995 * Converts an uint64_t value from little endian to host byte order. */
1996#ifdef RT_BIG_ENDIAN
1997# define RT_LE2H_U64(u64) RT_BSWAP_U64(u64)
1998#else
1999# define RT_LE2H_U64(u64) (u64)
2000#endif
2001
2002/** @def RT_LE2H_U64_C
2003 * Converts an uint64_t constant from little endian to host byte order. */
2004#ifdef RT_BIG_ENDIAN
2005# define RT_LE2H_U64_C(u64) RT_BSWAP_U64_C(u64)
2006#else
2007# define RT_LE2H_U64_C(u64) (u64)
2008#endif
2009
2010/** @def RT_LE2H_U32
2011 * Converts an uint32_t value from little endian to host byte order. */
2012#ifdef RT_BIG_ENDIAN
2013# define RT_LE2H_U32(u32) RT_BSWAP_U32(u32)
2014#else
2015# define RT_LE2H_U32(u32) (u32)
2016#endif
2017
2018/** @def RT_LE2H_U32_C
2019 * Converts an uint32_t constant from little endian to host byte order. */
2020#ifdef RT_BIG_ENDIAN
2021# define RT_LE2H_U32_C(u32) RT_BSWAP_U32_C(u32)
2022#else
2023# define RT_LE2H_U32_C(u32) (u32)
2024#endif
2025
2026/** @def RT_LE2H_U16
2027 * Converts an uint16_t value from little endian to host byte order. */
2028#ifdef RT_BIG_ENDIAN
2029# define RT_LE2H_U16(u16) RT_BSWAP_U16(u16)
2030#else
2031# define RT_LE2H_U16(u16) (u16)
2032#endif
2033
2034/** @def RT_LE2H_U16_C
2035 * Converts an uint16_t constant from little endian to host byte order. */
2036#ifdef RT_BIG_ENDIAN
2037# define RT_LE2H_U16_C(u16) RT_BSWAP_U16_C(u16)
2038#else
2039# define RT_LE2H_U16_C(u16) (u16)
2040#endif
2041
2042
2043/** @def RT_H2BE_U64
2044 * Converts an uint64_t value from host to big endian byte order. */
2045#ifdef RT_BIG_ENDIAN
2046# define RT_H2BE_U64(u64) (u64)
2047#else
2048# define RT_H2BE_U64(u64) RT_BSWAP_U64(u64)
2049#endif
2050
2051/** @def RT_H2BE_U64_C
2052 * Converts an uint64_t constant from host to big endian byte order. */
2053#ifdef RT_BIG_ENDIAN
2054# define RT_H2BE_U64_C(u64) (u64)
2055#else
2056# define RT_H2BE_U64_C(u64) RT_BSWAP_U64_C(u64)
2057#endif
2058
2059/** @def RT_H2BE_U32
2060 * Converts an uint32_t value from host to big endian byte order. */
2061#ifdef RT_BIG_ENDIAN
2062# define RT_H2BE_U32(u32) (u32)
2063#else
2064# define RT_H2BE_U32(u32) RT_BSWAP_U32(u32)
2065#endif
2066
2067/** @def RT_H2BE_U32_C
2068 * Converts an uint32_t constant from host to big endian byte order. */
2069#ifdef RT_BIG_ENDIAN
2070# define RT_H2BE_U32_C(u32) (u32)
2071#else
2072# define RT_H2BE_U32_C(u32) RT_BSWAP_U32_C(u32)
2073#endif
2074
2075/** @def RT_H2BE_U16
2076 * Converts an uint16_t value from host to big endian byte order. */
2077#ifdef RT_BIG_ENDIAN
2078# define RT_H2BE_U16(u16) (u16)
2079#else
2080# define RT_H2BE_U16(u16) RT_BSWAP_U16(u16)
2081#endif
2082
2083/** @def RT_H2BE_U16_C
2084 * Converts an uint16_t constant from host to big endian byte order. */
2085#ifdef RT_BIG_ENDIAN
2086# define RT_H2BE_U16_C(u16) (u16)
2087#else
2088# define RT_H2BE_U16_C(u16) RT_BSWAP_U16_C(u16)
2089#endif
2090
2091/** @def RT_BE2H_U64
2092 * Converts an uint64_t value from big endian to host byte order. */
2093#ifdef RT_BIG_ENDIAN
2094# define RT_BE2H_U64(u64) (u64)
2095#else
2096# define RT_BE2H_U64(u64) RT_BSWAP_U64(u64)
2097#endif
2098
2099/** @def RT_BE2H_U64
2100 * Converts an uint64_t constant from big endian to host byte order. */
2101#ifdef RT_BIG_ENDIAN
2102# define RT_BE2H_U64_C(u64) (u64)
2103#else
2104# define RT_BE2H_U64_C(u64) RT_BSWAP_U64_C(u64)
2105#endif
2106
2107/** @def RT_BE2H_U32
2108 * Converts an uint32_t value from big endian to host byte order. */
2109#ifdef RT_BIG_ENDIAN
2110# define RT_BE2H_U32(u32) (u32)
2111#else
2112# define RT_BE2H_U32(u32) RT_BSWAP_U32(u32)
2113#endif
2114
2115/** @def RT_BE2H_U32_C
2116 * Converts an uint32_t value from big endian to host byte order. */
2117#ifdef RT_BIG_ENDIAN
2118# define RT_BE2H_U32_C(u32) (u32)
2119#else
2120# define RT_BE2H_U32_C(u32) RT_BSWAP_U32_C(u32)
2121#endif
2122
2123/** @def RT_BE2H_U16
2124 * Converts an uint16_t value from big endian to host byte order. */
2125#ifdef RT_BIG_ENDIAN
2126# define RT_BE2H_U16(u16) (u16)
2127#else
2128# define RT_BE2H_U16(u16) RT_BSWAP_U16(u16)
2129#endif
2130
2131/** @def RT_BE2H_U16_C
2132 * Converts an uint16_t constant from big endian to host byte order. */
2133#ifdef RT_BIG_ENDIAN
2134# define RT_BE2H_U16_C(u16) (u16)
2135#else
2136# define RT_BE2H_U16_C(u16) RT_BSWAP_U16_C(u16)
2137#endif
2138
2139
2140/** @def RT_H2N_U64
2141 * Converts an uint64_t value from host to network byte order. */
2142#define RT_H2N_U64(u64) RT_H2BE_U64(u64)
2143
2144/** @def RT_H2N_U64_C
2145 * Converts an uint64_t constant from host to network byte order. */
2146#define RT_H2N_U64_C(u64) RT_H2BE_U64_C(u64)
2147
2148/** @def RT_H2N_U32
2149 * Converts an uint32_t value from host to network byte order. */
2150#define RT_H2N_U32(u32) RT_H2BE_U32(u32)
2151
2152/** @def RT_H2N_U32_C
2153 * Converts an uint32_t constant from host to network byte order. */
2154#define RT_H2N_U32_C(u32) RT_H2BE_U32_C(u32)
2155
2156/** @def RT_H2N_U16
2157 * Converts an uint16_t value from host to network byte order. */
2158#define RT_H2N_U16(u16) RT_H2BE_U16(u16)
2159
2160/** @def RT_H2N_U16_C
2161 * Converts an uint16_t constant from host to network byte order. */
2162#define RT_H2N_U16_C(u16) RT_H2BE_U16_C(u16)
2163
2164/** @def RT_N2H_U64
2165 * Converts an uint64_t value from network to host byte order. */
2166#define RT_N2H_U64(u64) RT_BE2H_U64(u64)
2167
2168/** @def RT_N2H_U64_C
2169 * Converts an uint64_t constant from network to host byte order. */
2170#define RT_N2H_U64_C(u64) RT_BE2H_U64_C(u64)
2171
2172/** @def RT_N2H_U32
2173 * Converts an uint32_t value from network to host byte order. */
2174#define RT_N2H_U32(u32) RT_BE2H_U32(u32)
2175
2176/** @def RT_N2H_U32_C
2177 * Converts an uint32_t constant from network to host byte order. */
2178#define RT_N2H_U32_C(u32) RT_BE2H_U32_C(u32)
2179
2180/** @def RT_N2H_U16
2181 * Converts an uint16_t value from network to host byte order. */
2182#define RT_N2H_U16(u16) RT_BE2H_U16(u16)
2183
2184/** @def RT_N2H_U16_C
2185 * Converts an uint16_t value from network to host byte order. */
2186#define RT_N2H_U16_C(u16) RT_BE2H_U16_C(u16)
2187
2188
2189/*
2190 * The BSD sys/param.h + machine/param.h file is a major source of
2191 * namespace pollution. Kill off some of the worse ones unless we're
2192 * compiling kernel code.
2193 */
2194#if defined(RT_OS_DARWIN) \
2195 && !defined(KERNEL) \
2196 && !defined(RT_NO_BSD_PARAM_H_UNDEFING) \
2197 && ( defined(_SYS_PARAM_H_) || defined(_I386_PARAM_H_) )
2198/* sys/param.h: */
2199# undef PSWP
2200# undef PVM
2201# undef PINOD
2202# undef PRIBO
2203# undef PVFS
2204# undef PZERO
2205# undef PSOCK
2206# undef PWAIT
2207# undef PLOCK
2208# undef PPAUSE
2209# undef PUSER
2210# undef PRIMASK
2211# undef MINBUCKET
2212# undef MAXALLOCSAVE
2213# undef FSHIFT
2214# undef FSCALE
2215
2216/* i386/machine.h: */
2217# undef ALIGN
2218# undef ALIGNBYTES
2219# undef DELAY
2220# undef STATUS_WORD
2221# undef USERMODE
2222# undef BASEPRI
2223# undef MSIZE
2224# undef CLSIZE
2225# undef CLSIZELOG2
2226#endif
2227
2228/** @def NIL_OFFSET
2229 * NIL offset.
2230 * Whenever we use offsets instead of pointers to save space and relocation effort
2231 * NIL_OFFSET shall be used as the equivalent to NULL.
2232 */
2233#define NIL_OFFSET (~0U)
2234
2235/** @def NOREF
2236 * Keeps the compiler from bitching about an unused parameter.
2237 */
2238#define NOREF(var) (void)(var)
2239
2240/** @def RT_BREAKPOINT
2241 * Emit a debug breakpoint instruction.
2242 *
2243 * @remarks In the x86/amd64 gnu world we add a nop instruction after the int3
2244 * to force gdb to remain at the int3 source line.
2245 * @remarks The L4 kernel will try make sense of the breakpoint, thus the jmp on
2246 * x86/amd64.
2247 */
2248#ifdef __GNUC__
2249# if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
2250# if !defined(__L4ENV__)
2251# define RT_BREAKPOINT() __asm__ __volatile__("int $3\n\tnop\n\t")
2252# else
2253# define RT_BREAKPOINT() __asm__ __volatile__("int3; jmp 1f; 1:\n\t")
2254# endif
2255# elif defined(RT_ARCH_SPARC64)
2256# define RT_BREAKPOINT() __asm__ __volatile__("illtrap 0\n\t") /** @todo Sparc64: this is just a wild guess. */
2257# elif defined(RT_ARCH_SPARC)
2258# define RT_BREAKPOINT() __asm__ __volatile__("unimp 0\n\t") /** @todo Sparc: this is just a wild guess (same as Sparc64, just different name). */
2259# endif
2260#endif
2261#ifdef _MSC_VER
2262# define RT_BREAKPOINT() __debugbreak()
2263#endif
2264#if defined(__IBMC__) || defined(__IBMCPP__)
2265# define RT_BREAKPOINT() __interrupt(3)
2266#endif
2267#if defined(__WATCOMC__)
2268# define RT_BREAKPOINT() _asm { int 3 }
2269#endif
2270#ifndef RT_BREAKPOINT
2271# error "This compiler/arch is not supported!"
2272#endif
2273
2274
2275/** @defgroup grp_rt_cdefs_size Size Constants
2276 * (Of course, these are binary computer terms, not SI.)
2277 * @{
2278 */
2279/** 1 K (Kilo) (1 024). */
2280#define _1K 0x00000400
2281/** 2 K (Kilo) (2 048). */
2282#define _2K 0x00000800
2283/** 4 K (Kilo) (4 096). */
2284#define _4K 0x00001000
2285/** 8 K (Kilo) (8 192). */
2286#define _8K 0x00002000
2287/** 16 K (Kilo) (16 384). */
2288#define _16K 0x00004000
2289/** 32 K (Kilo) (32 678). */
2290#define _32K 0x00008000
2291/** 64 K (Kilo) (65 536). */
2292#if ARCH_BITS != 16
2293# define _64K 0x00010000
2294#else
2295# define _64K UINT32_C(0x00010000)
2296#endif
2297/** 128 K (Kilo) (131 072). */
2298#if ARCH_BITS != 16
2299# define _128K 0x00020000
2300#else
2301# define _128K UINT32_C(0x00020000)
2302#endif
2303/** 256 K (Kilo) (262 144). */
2304#if ARCH_BITS != 16
2305# define _256K 0x00040000
2306#else
2307# define _256K UINT32_C(0x00040000)
2308#endif
2309/** 512 K (Kilo) (524 288). */
2310#if ARCH_BITS != 16
2311# define _512K 0x00080000
2312#else
2313# define _512K UINT32_C(0x00080000)
2314#endif
2315/** 1 M (Mega) (1 048 576). */
2316#if ARCH_BITS != 16
2317# define _1M 0x00100000
2318#else
2319# define _1M UINT32_C(0x00100000)
2320#endif
2321/** 2 M (Mega) (2 097 152). */
2322#if ARCH_BITS != 16
2323# define _2M 0x00200000
2324#else
2325# define _2M UINT32_C(0x00200000)
2326#endif
2327/** 4 M (Mega) (4 194 304). */
2328#if ARCH_BITS != 16
2329# define _4M 0x00400000
2330#else
2331# define _4M UINT32_C(0x00400000)
2332#endif
2333/** 8 M (Mega) (8 388 608). */
2334#define _8M UINT32_C(0x00800000)
2335/** 16 M (Mega) (16 777 216). */
2336#define _16M UINT32_C(0x01000000)
2337/** 32 M (Mega) (33 554 432). */
2338#define _32M UINT32_C(0x02000000)
2339/** 64 M (Mega) (67 108 864). */
2340#define _64M UINT32_C(0x04000000)
2341/** 128 M (Mega) (134 217 728). */
2342#define _128M UINT32_C(0x08000000)
2343/** 256 M (Mega) (268 435 456). */
2344#define _256M UINT32_C(0x10000000)
2345/** 512 M (Mega) (536 870 912). */
2346#define _512M UINT32_C(0x20000000)
2347/** 1 G (Giga) (1 073 741 824). (32-bit) */
2348#if ARCH_BITS != 16
2349# define _1G 0x40000000
2350#else
2351# define _1G UINT32_C(0x40000000)
2352#endif
2353/** 1 G (Giga) (1 073 741 824). (64-bit) */
2354#if ARCH_BITS != 16
2355# define _1G64 0x40000000LL
2356#else
2357# define _1G64 UINT64_C(0x40000000)
2358#endif
2359/** 2 G (Giga) (2 147 483 648). (32-bit) */
2360#define _2G32 UINT32_C(0x80000000)
2361/** 2 G (Giga) (2 147 483 648). (64-bit) */
2362#if ARCH_BITS != 16
2363# define _2G 0x0000000080000000LL
2364#else
2365# define _2G UINT64_C(0x0000000080000000)
2366#endif
2367/** 4 G (Giga) (4 294 967 296). */
2368#if ARCH_BITS != 16
2369# define _4G 0x0000000100000000LL
2370#else
2371# define _4G UINT64_C(0x0000000100000000)
2372#endif
2373/** 1 T (Tera) (1 099 511 627 776). */
2374#if ARCH_BITS != 16
2375# define _1T 0x0000010000000000LL
2376#else
2377# define _1T UINT64_C(0x0000010000000000)
2378#endif
2379/** 1 P (Peta) (1 125 899 906 842 624). */
2380#if ARCH_BITS != 16
2381# define _1P 0x0004000000000000LL
2382#else
2383# define _1P UINT64_C(0x0004000000000000)
2384#endif
2385/** 1 E (Exa) (1 152 921 504 606 846 976). */
2386#if ARCH_BITS != 16
2387# define _1E 0x1000000000000000LL
2388#else
2389# define _1E UINT64_C(0x1000000000000000)
2390#endif
2391/** 2 E (Exa) (2 305 843 009 213 693 952). */
2392#if ARCH_BITS != 16
2393# define _2E 0x2000000000000000ULL
2394#else
2395# define _2E UINT64_C(0x2000000000000000)
2396#endif
2397/** @} */
2398
2399/** @defgroup grp_rt_cdefs_decimal_grouping Decimal Constant Grouping Macros
2400 * @{ */
2401#define RT_D1(g1) g1
2402#define RT_D2(g1, g2) g1#g2
2403#define RT_D3(g1, g2, g3) g1#g2#g3
2404#define RT_D4(g1, g2, g3, g4) g1#g2#g3#g4
2405#define RT_D5(g1, g2, g3, g4, g5) g1#g2#g3#g4#g5
2406#define RT_D6(g1, g2, g3, g4, g5, g6) g1#g2#g3#g4#g5#g6
2407#define RT_D7(g1, g2, g3, g4, g5, g6, g7) g1#g2#g3#g4#g5#g6#g7
2408
2409#define RT_D1_U(g1) UINT32_C(g1)
2410#define RT_D2_U(g1, g2) UINT32_C(g1#g2)
2411#define RT_D3_U(g1, g2, g3) UINT32_C(g1#g2#g3)
2412#define RT_D4_U(g1, g2, g3, g4) UINT64_C(g1#g2#g3#g4)
2413#define RT_D5_U(g1, g2, g3, g4, g5) UINT64_C(g1#g2#g3#g4#g5)
2414#define RT_D6_U(g1, g2, g3, g4, g5, g6) UINT64_C(g1#g2#g3#g4#g5#g6)
2415#define RT_D7_U(g1, g2, g3, g4, g5, g6, g7) UINT64_C(g1#g2#g3#g4#g5#g6#g7)
2416
2417#define RT_D1_S(g1) INT32_C(g1)
2418#define RT_D2_S(g1, g2) INT32_C(g1#g2)
2419#define RT_D3_S(g1, g2, g3) INT32_C(g1#g2#g3)
2420#define RT_D4_S(g1, g2, g3, g4) INT64_C(g1#g2#g3#g4)
2421#define RT_D5_S(g1, g2, g3, g4, g5) INT64_C(g1#g2#g3#g4#g5)
2422#define RT_D6_S(g1, g2, g3, g4, g5, g6) INT64_C(g1#g2#g3#g4#g5#g6)
2423#define RT_D7_S(g1, g2, g3, g4, g5, g6, g7) INT64_C(g1#g2#g3#g4#g5#g6#g7)
2424
2425#define RT_D1_U32(g1) UINT32_C(g1)
2426#define RT_D2_U32(g1, g2) UINT32_C(g1#g2)
2427#define RT_D3_U32(g1, g2, g3) UINT32_C(g1#g2#g3)
2428#define RT_D4_U32(g1, g2, g3, g4) UINT32_C(g1#g2#g3#g4)
2429
2430#define RT_D1_S32(g1) INT32_C(g1)
2431#define RT_D2_S32(g1, g2) INT32_C(g1#g2)
2432#define RT_D3_S32(g1, g2, g3) INT32_C(g1#g2#g3)
2433#define RT_D4_S32(g1, g2, g3, g4) INT32_C(g1#g2#g3#g4)
2434
2435#define RT_D1_U64(g1) UINT64_C(g1)
2436#define RT_D2_U64(g1, g2) UINT64_C(g1#g2)
2437#define RT_D3_U64(g1, g2, g3) UINT64_C(g1#g2#g3)
2438#define RT_D4_U64(g1, g2, g3, g4) UINT64_C(g1#g2#g3#g4)
2439#define RT_D5_U64(g1, g2, g3, g4, g5) UINT64_C(g1#g2#g3#g4#g5)
2440#define RT_D6_U64(g1, g2, g3, g4, g5, g6) UINT64_C(g1#g2#g3#g4#g5#g6)
2441#define RT_D7_U64(g1, g2, g3, g4, g5, g6, g7) UINT64_C(g1#g2#g3#g4#g5#g6#g7)
2442
2443#define RT_D1_S64(g1) INT64_C(g1)
2444#define RT_D2_S64(g1, g2) INT64_C(g1#g2)
2445#define RT_D3_S64(g1, g2, g3) INT64_C(g1#g2#g3)
2446#define RT_D4_S64(g1, g2, g3, g4) INT64_C(g1#g2#g3#g4)
2447#define RT_D5_S64(g1, g2, g3, g4, g5) INT64_C(g1#g2#g3#g4#g5)
2448#define RT_D6_S64(g1, g2, g3, g4, g5, g6) INT64_C(g1#g2#g3#g4#g5#g6)
2449#define RT_D7_S64(g1, g2, g3, g4, g5, g6, g7) INT64_C(g1#g2#g3#g4#g5#g6#g7)
2450/** @} */
2451
2452
2453/** @defgroup grp_rt_cdefs_time Time Constants
2454 * @{
2455 */
2456/** 1 hour expressed in nanoseconds (64-bit). */
2457#define RT_NS_1HOUR UINT64_C(3600000000000)
2458/** 1 minute expressed in nanoseconds (64-bit). */
2459#define RT_NS_1MIN UINT64_C(60000000000)
2460/** 45 second expressed in nanoseconds. */
2461#define RT_NS_45SEC UINT64_C(45000000000)
2462/** 30 second expressed in nanoseconds. */
2463#define RT_NS_30SEC UINT64_C(30000000000)
2464/** 20 second expressed in nanoseconds. */
2465#define RT_NS_20SEC UINT64_C(20000000000)
2466/** 15 second expressed in nanoseconds. */
2467#define RT_NS_15SEC UINT64_C(15000000000)
2468/** 10 second expressed in nanoseconds. */
2469#define RT_NS_10SEC UINT64_C(10000000000)
2470/** 1 second expressed in nanoseconds. */
2471#define RT_NS_1SEC UINT32_C(1000000000)
2472/** 100 millsecond expressed in nanoseconds. */
2473#define RT_NS_100MS UINT32_C(100000000)
2474/** 10 millsecond expressed in nanoseconds. */
2475#define RT_NS_10MS UINT32_C(10000000)
2476/** 1 millsecond expressed in nanoseconds. */
2477#define RT_NS_1MS UINT32_C(1000000)
2478/** 100 microseconds expressed in nanoseconds. */
2479#define RT_NS_100US UINT32_C(100000)
2480/** 10 microseconds expressed in nanoseconds. */
2481#define RT_NS_10US UINT32_C(10000)
2482/** 1 microsecond expressed in nanoseconds. */
2483#define RT_NS_1US UINT32_C(1000)
2484
2485/** 1 second expressed in nanoseconds - 64-bit type. */
2486#define RT_NS_1SEC_64 UINT64_C(1000000000)
2487/** 100 millsecond expressed in nanoseconds - 64-bit type. */
2488#define RT_NS_100MS_64 UINT64_C(100000000)
2489/** 10 millsecond expressed in nanoseconds - 64-bit type. */
2490#define RT_NS_10MS_64 UINT64_C(10000000)
2491/** 1 millsecond expressed in nanoseconds - 64-bit type. */
2492#define RT_NS_1MS_64 UINT64_C(1000000)
2493/** 100 microseconds expressed in nanoseconds - 64-bit type. */
2494#define RT_NS_100US_64 UINT64_C(100000)
2495/** 10 microseconds expressed in nanoseconds - 64-bit type. */
2496#define RT_NS_10US_64 UINT64_C(10000)
2497/** 1 microsecond expressed in nanoseconds - 64-bit type. */
2498#define RT_NS_1US_64 UINT64_C(1000)
2499
2500/** 1 hour expressed in microseconds. */
2501#define RT_US_1HOUR UINT32_C(3600000000)
2502/** 1 minute expressed in microseconds. */
2503#define RT_US_1MIN UINT32_C(60000000)
2504/** 1 second expressed in microseconds. */
2505#define RT_US_1SEC UINT32_C(1000000)
2506/** 100 millsecond expressed in microseconds. */
2507#define RT_US_100MS UINT32_C(100000)
2508/** 10 millsecond expressed in microseconds. */
2509#define RT_US_10MS UINT32_C(10000)
2510/** 1 millsecond expressed in microseconds. */
2511#define RT_US_1MS UINT32_C(1000)
2512
2513/** 1 hour expressed in microseconds - 64-bit type. */
2514#define RT_US_1HOUR_64 UINT64_C(3600000000)
2515/** 1 minute expressed in microseconds - 64-bit type. */
2516#define RT_US_1MIN_64 UINT64_C(60000000)
2517/** 1 second expressed in microseconds - 64-bit type. */
2518#define RT_US_1SEC_64 UINT64_C(1000000)
2519/** 100 millsecond expressed in microseconds - 64-bit type. */
2520#define RT_US_100MS_64 UINT64_C(100000)
2521/** 10 millsecond expressed in microseconds - 64-bit type. */
2522#define RT_US_10MS_64 UINT64_C(10000)
2523/** 1 millsecond expressed in microseconds - 64-bit type. */
2524#define RT_US_1MS_64 UINT64_C(1000)
2525
2526/** 1 hour expressed in milliseconds. */
2527#define RT_MS_1HOUR UINT32_C(3600000)
2528/** 1 minute expressed in milliseconds. */
2529#define RT_MS_1MIN UINT32_C(60000)
2530/** 1 second expressed in milliseconds. */
2531#define RT_MS_1SEC UINT32_C(1000)
2532
2533/** 1 hour expressed in milliseconds - 64-bit type. */
2534#define RT_MS_1HOUR_64 UINT64_C(3600000)
2535/** 1 minute expressed in milliseconds - 64-bit type. */
2536#define RT_MS_1MIN_64 UINT64_C(60000)
2537/** 1 second expressed in milliseconds - 64-bit type. */
2538#define RT_MS_1SEC_64 UINT64_C(1000)
2539
2540/** The number of seconds per week. */
2541#define RT_SEC_1WEEK UINT32_C(604800)
2542/** The number of seconds per day. */
2543#define RT_SEC_1DAY UINT32_C(86400)
2544/** The number of seconds per hour. */
2545#define RT_SEC_1HOUR UINT32_C(3600)
2546
2547/** The number of seconds per week - 64-bit type. */
2548#define RT_SEC_1WEEK_64 UINT64_C(604800)
2549/** The number of seconds per day - 64-bit type. */
2550#define RT_SEC_1DAY_64 UINT64_C(86400)
2551/** The number of seconds per hour - 64-bit type. */
2552#define RT_SEC_1HOUR_64 UINT64_C(3600)
2553/** @} */
2554
2555
2556/** @defgroup grp_rt_cdefs_dbgtype Debug Info Types
2557 * @{ */
2558/** Other format. */
2559#define RT_DBGTYPE_OTHER RT_BIT_32(0)
2560/** Stabs. */
2561#define RT_DBGTYPE_STABS RT_BIT_32(1)
2562/** Debug With Arbitrary Record Format (DWARF). */
2563#define RT_DBGTYPE_DWARF RT_BIT_32(2)
2564/** Microsoft Codeview debug info. */
2565#define RT_DBGTYPE_CODEVIEW RT_BIT_32(3)
2566/** Watcom debug info. */
2567#define RT_DBGTYPE_WATCOM RT_BIT_32(4)
2568/** IBM High Level Language debug info. */
2569#define RT_DBGTYPE_HLL RT_BIT_32(5)
2570/** Old OS/2 and Windows symbol file. */
2571#define RT_DBGTYPE_SYM RT_BIT_32(6)
2572/** Map file. */
2573#define RT_DBGTYPE_MAP RT_BIT_32(7)
2574/** @} */
2575
2576
2577/** @defgroup grp_rt_cdefs_exetype Executable Image Types
2578 * @{ */
2579/** Some other format. */
2580#define RT_EXETYPE_OTHER RT_BIT_32(0)
2581/** Portable Executable. */
2582#define RT_EXETYPE_PE RT_BIT_32(1)
2583/** Linear eXecutable. */
2584#define RT_EXETYPE_LX RT_BIT_32(2)
2585/** Linear Executable. */
2586#define RT_EXETYPE_LE RT_BIT_32(3)
2587/** New Executable. */
2588#define RT_EXETYPE_NE RT_BIT_32(4)
2589/** DOS Executable (Mark Zbikowski). */
2590#define RT_EXETYPE_MZ RT_BIT_32(5)
2591/** COM Executable. */
2592#define RT_EXETYPE_COM RT_BIT_32(6)
2593/** a.out Executable. */
2594#define RT_EXETYPE_AOUT RT_BIT_32(7)
2595/** Executable and Linkable Format. */
2596#define RT_EXETYPE_ELF RT_BIT_32(8)
2597/** Mach-O Executable (including FAT ones). */
2598#define RT_EXETYPE_MACHO RT_BIT_32(9)
2599/** TE from UEFI. */
2600#define RT_EXETYPE_TE RT_BIT_32(9)
2601/** @} */
2602
2603
2604/** @def VALID_PTR
2605 * Pointer validation macro.
2606 * @param ptr The pointer.
2607 */
2608#if defined(RT_ARCH_AMD64)
2609# ifdef IN_RING3
2610# if defined(RT_OS_DARWIN) /* first 4GB is reserved for legacy kernel. */
2611# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) >= _4G \
2612 && !((uintptr_t)(ptr) & 0xffff800000000000ULL) )
2613# elif defined(RT_OS_SOLARIS) /* The kernel only used the top 2TB, but keep it simple. */
2614# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
2615 && ( ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0xffff800000000000ULL \
2616 || ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0) )
2617# else
2618# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
2619 && !((uintptr_t)(ptr) & 0xffff800000000000ULL) )
2620# endif
2621# else /* !IN_RING3 */
2622# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
2623 && ( ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0xffff800000000000ULL \
2624 || ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0) )
2625# endif /* !IN_RING3 */
2626
2627#elif defined(RT_ARCH_X86)
2628# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U )
2629
2630#elif defined(RT_ARCH_SPARC64)
2631# ifdef IN_RING3
2632# if defined(RT_OS_SOLARIS)
2633/** Sparc64 user mode: According to Figure 9.4 in solaris internals */
2634/** @todo # define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x80004000U >= 0x80004000U + 0x100000000ULL ) - figure this. */
2635# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x80000000U >= 0x80000000U + 0x100000000ULL )
2636# else
2637# error "Port me"
2638# endif
2639# else /* !IN_RING3 */
2640# if defined(RT_OS_SOLARIS)
2641/** @todo Sparc64 kernel mode: This is according to Figure 11.1 in solaris
2642 * internals. Verify in sources. */
2643# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) >= 0x01000000U )
2644# else
2645# error "Port me"
2646# endif
2647# endif /* !IN_RING3 */
2648
2649#elif defined(RT_ARCH_SPARC)
2650# ifdef IN_RING3
2651# ifdef RT_OS_SOLARIS
2652/** Sparc user mode: According to
2653 * http://cvs.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/uts/sun4/os/startup.c#510 */
2654# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x400000U >= 0x400000U + 0x2000U )
2655
2656# else
2657# error "Port me"
2658# endif
2659# else /* !IN_RING3 */
2660# ifdef RT_OS_SOLARIS
2661/** @todo Sparc kernel mode: Check the sources! */
2662# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U )
2663# else
2664# error "Port me"
2665# endif
2666# endif /* !IN_RING3 */
2667
2668#elif defined(RT_ARCH_ARM)
2669/* ASSUMES that at least the last and first 4K are out of bounds. */
2670# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U )
2671
2672#else
2673# error "Architecture identifier missing / not implemented."
2674#endif
2675
2676/** Old name for RT_VALID_PTR. */
2677#define VALID_PTR(ptr) RT_VALID_PTR(ptr)
2678
2679/** @def RT_VALID_ALIGNED_PTR
2680 * Pointer validation macro that also checks the alignment.
2681 * @param ptr The pointer.
2682 * @param align The alignment, must be a power of two.
2683 */
2684#define RT_VALID_ALIGNED_PTR(ptr, align) \
2685 ( !((uintptr_t)(ptr) & (uintptr_t)((align) - 1)) \
2686 && VALID_PTR(ptr) )
2687
2688
2689/** @def VALID_PHYS32
2690 * 32 bits physical address validation macro.
2691 * @param Phys The RTGCPHYS address.
2692 */
2693#define VALID_PHYS32(Phys) ( (uint64_t)(Phys) < (uint64_t)_4G )
2694
2695/** @def N_
2696 * The \#define N_ is used to mark a string for translation. This is usable in
2697 * any part of the code, as it is only used by the tools that create message
2698 * catalogs. This macro is a no-op as far as the compiler and code generation
2699 * is concerned.
2700 *
2701 * If you want to both mark a string for translation and translate it, use _().
2702 */
2703#define N_(s) (s)
2704
2705/** @def _
2706 * The \#define _ is used to mark a string for translation and to translate it
2707 * in one step.
2708 *
2709 * If you want to only mark a string for translation, use N_().
2710 */
2711#define _(s) gettext(s)
2712
2713
2714/** @def __PRETTY_FUNCTION__
2715 * With GNU C we'd like to use the builtin __PRETTY_FUNCTION__, so define that
2716 * for the other compilers.
2717 */
2718#if !defined(__GNUC__) && !defined(__PRETTY_FUNCTION__)
2719# ifdef _MSC_VER
2720# define __PRETTY_FUNCTION__ __FUNCSIG__
2721# else
2722# define __PRETTY_FUNCTION__ __FUNCTION__
2723# endif
2724#endif
2725
2726
2727/** @def RT_STRICT
2728 * The \#define RT_STRICT controls whether or not assertions and other runtime
2729 * checks should be compiled in or not. This is defined when DEBUG is defined.
2730 * If RT_NO_STRICT is defined, it will unconditionally be undefined.
2731 *
2732 * If you want assertions which are not subject to compile time options use
2733 * the AssertRelease*() flavors.
2734 */
2735#if !defined(RT_STRICT) && defined(DEBUG)
2736# define RT_STRICT
2737#endif
2738#ifdef RT_NO_STRICT
2739# undef RT_STRICT
2740#endif
2741
2742/** @todo remove this: */
2743#if !defined(RT_LOCK_STRICT) && !defined(DEBUG_bird)
2744# define RT_LOCK_NO_STRICT
2745#endif
2746#if !defined(RT_LOCK_STRICT_ORDER) && !defined(DEBUG_bird)
2747# define RT_LOCK_NO_STRICT_ORDER
2748#endif
2749
2750/** @def RT_LOCK_STRICT
2751 * The \#define RT_LOCK_STRICT controls whether deadlock detection and related
2752 * checks are done in the lock and semaphore code. It is by default enabled in
2753 * RT_STRICT builds, but this behavior can be overridden by defining
2754 * RT_LOCK_NO_STRICT. */
2755#if !defined(RT_LOCK_STRICT) && !defined(RT_LOCK_NO_STRICT) && defined(RT_STRICT)
2756# define RT_LOCK_STRICT
2757#endif
2758/** @def RT_LOCK_NO_STRICT
2759 * The \#define RT_LOCK_NO_STRICT disables RT_LOCK_STRICT. */
2760#if defined(RT_LOCK_NO_STRICT) && defined(RT_LOCK_STRICT)
2761# undef RT_LOCK_STRICT
2762#endif
2763
2764/** @def RT_LOCK_STRICT_ORDER
2765 * The \#define RT_LOCK_STRICT_ORDER controls whether locking order is checked
2766 * by the lock and semaphore code. It is by default enabled in RT_STRICT
2767 * builds, but this behavior can be overridden by defining
2768 * RT_LOCK_NO_STRICT_ORDER. */
2769#if !defined(RT_LOCK_STRICT_ORDER) && !defined(RT_LOCK_NO_STRICT_ORDER) && defined(RT_STRICT)
2770# define RT_LOCK_STRICT_ORDER
2771#endif
2772/** @def RT_LOCK_NO_STRICT_ORDER
2773 * The \#define RT_LOCK_NO_STRICT_ORDER disables RT_LOCK_STRICT_ORDER. */
2774#if defined(RT_LOCK_NO_STRICT_ORDER) && defined(RT_LOCK_STRICT_ORDER)
2775# undef RT_LOCK_STRICT_ORDER
2776#endif
2777
2778
2779/** Source position. */
2780#define RT_SRC_POS __FILE__, __LINE__, RT_GCC_EXTENSION __PRETTY_FUNCTION__
2781
2782/** Source position declaration. */
2783#define RT_SRC_POS_DECL const char *pszFile, unsigned iLine, const char *pszFunction
2784
2785/** Source position arguments. */
2786#define RT_SRC_POS_ARGS pszFile, iLine, pszFunction
2787
2788/** Applies NOREF() to the source position arguments. */
2789#define RT_SRC_POS_NOREF() do { NOREF(pszFile); NOREF(iLine); NOREF(pszFunction); } while (0)
2790
2791
2792/** @def RT_INLINE_ASM_EXTERNAL
2793 * Defined as 1 if the compiler does not support inline assembly.
2794 * The ASM* functions will then be implemented in external .asm files.
2795 */
2796#if (defined(_MSC_VER) && defined(RT_ARCH_AMD64)) \
2797 || (!defined(RT_ARCH_AMD64) && !defined(RT_ARCH_X86)) \
2798 || defined(__WATCOMC__)
2799# define RT_INLINE_ASM_EXTERNAL 1
2800#else
2801# define RT_INLINE_ASM_EXTERNAL 0
2802#endif
2803
2804/** @def RT_INLINE_ASM_GNU_STYLE
2805 * Defined as 1 if the compiler understands GNU style inline assembly.
2806 */
2807#if defined(_MSC_VER) || defined(__WATCOMC__)
2808# define RT_INLINE_ASM_GNU_STYLE 0
2809#else
2810# define RT_INLINE_ASM_GNU_STYLE 1
2811#endif
2812
2813/** @def RT_INLINE_ASM_USES_INTRIN
2814 * Defined as the major MSC version if the compiler have and uses intrin.h.
2815 * Otherwise it is 0. */
2816#ifdef _MSC_VER
2817# if _MSC_VER >= 1700 /* Visual C++ v11.0 / 2012 */
2818# define RT_INLINE_ASM_USES_INTRIN 17
2819# elif _MSC_VER >= 1600 /* Visual C++ v10.0 / 2010 */
2820# define RT_INLINE_ASM_USES_INTRIN 16
2821# elif _MSC_VER >= 1500 /* Visual C++ v9.0 / 2008 */
2822# define RT_INLINE_ASM_USES_INTRIN 15
2823# elif _MSC_VER >= 1400 /* Visual C++ v8.0 / 2005 */
2824# define RT_INLINE_ASM_USES_INTRIN 14
2825# endif
2826#endif
2827#ifndef RT_INLINE_ASM_USES_INTRIN
2828# define RT_INLINE_ASM_USES_INTRIN 0
2829#endif
2830
2831/** @def RT_COMPILER_SUPPORTS_LAMBDA
2832 * If the defined, the compiler supports lambda expressions. These expressions
2833 * are useful for embedding assertions and type checks into macros. */
2834#if defined(_MSC_VER) && defined(__cplusplus)
2835# if _MSC_VER >= 1600 /* Visual C++ v10.0 / 2010 */
2836# define RT_COMPILER_SUPPORTS_LAMBDA
2837# endif
2838#elif defined(__GNUC__) && defined(__cplusplus)
2839/* 4.5 or later, I think, if in ++11 mode... */
2840#endif
2841
2842/** @def RT_FAR_DATA
2843 * Set to 1 if we're in 16-bit mode and use far pointers.
2844 */
2845#if ARCH_BITS == 16 && defined(__WATCOMC__) \
2846 && (defined(__COMPACT__) || defined(__LARGE__))
2847# define RT_FAR_DATA 1
2848#else
2849# define RT_FAR_DATA 0
2850#endif
2851
2852/** @} */
2853
2854
2855/** @defgroup grp_rt_cdefs_cpp Special Macros for C++
2856 * @ingroup grp_rt_cdefs
2857 * @{
2858 */
2859
2860#ifdef __cplusplus
2861
2862/** @def DECLEXPORT_CLASS
2863 * How to declare an exported class. Place this macro after the 'class'
2864 * keyword in the declaration of every class you want to export.
2865 *
2866 * @note It is necessary to use this macro even for inner classes declared
2867 * inside the already exported classes. This is a GCC specific requirement,
2868 * but it seems not to harm other compilers.
2869 */
2870#if defined(_MSC_VER) || defined(RT_OS_OS2)
2871# define DECLEXPORT_CLASS __declspec(dllexport)
2872#elif defined(RT_USE_VISIBILITY_DEFAULT)
2873# define DECLEXPORT_CLASS __attribute__((visibility("default")))
2874#else
2875# define DECLEXPORT_CLASS
2876#endif
2877
2878/** @def DECLIMPORT_CLASS
2879 * How to declare an imported class Place this macro after the 'class'
2880 * keyword in the declaration of every class you want to export.
2881 *
2882 * @note It is necessary to use this macro even for inner classes declared
2883 * inside the already exported classes. This is a GCC specific requirement,
2884 * but it seems not to harm other compilers.
2885 */
2886#if defined(_MSC_VER) || (defined(RT_OS_OS2) && !defined(__IBMC__) && !defined(__IBMCPP__))
2887# define DECLIMPORT_CLASS __declspec(dllimport)
2888#elif defined(RT_USE_VISIBILITY_DEFAULT)
2889# define DECLIMPORT_CLASS __attribute__((visibility("default")))
2890#else
2891# define DECLIMPORT_CLASS
2892#endif
2893
2894/** @def WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP
2895 * Macro to work around error C2593 of the not-so-smart MSVC 7.x ambiguity
2896 * resolver. The following snippet clearly demonstrates the code causing this
2897 * error:
2898 * @code
2899 * class A
2900 * {
2901 * public:
2902 * operator bool() const { return false; }
2903 * operator int*() const { return NULL; }
2904 * };
2905 * int main()
2906 * {
2907 * A a;
2908 * if (!a);
2909 * if (a && 0);
2910 * return 0;
2911 * }
2912 * @endcode
2913 * The code itself seems pretty valid to me and GCC thinks the same.
2914 *
2915 * This macro fixes the compiler error by explicitly overloading implicit
2916 * global operators !, && and || that take the given class instance as one of
2917 * their arguments.
2918 *
2919 * The best is to use this macro right after the class declaration.
2920 *
2921 * @note The macro expands to nothing for compilers other than MSVC.
2922 *
2923 * @param Cls Class to apply the workaround to
2924 */
2925#if defined(_MSC_VER)
2926# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP(Cls) \
2927 inline bool operator! (const Cls &that) { return !bool (that); } \
2928 inline bool operator&& (const Cls &that, bool b) { return bool (that) && b; } \
2929 inline bool operator|| (const Cls &that, bool b) { return bool (that) || b; } \
2930 inline bool operator&& (bool b, const Cls &that) { return b && bool (that); } \
2931 inline bool operator|| (bool b, const Cls &that) { return b || bool (that); }
2932#else
2933# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP(Cls)
2934#endif
2935
2936/** @def WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL
2937 * Version of WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP for template classes.
2938 *
2939 * @param Tpl Name of the template class to apply the workaround to
2940 * @param ArgsDecl arguments of the template, as declared in |<>| after the
2941 * |template| keyword, including |<>|
2942 * @param Args arguments of the template, as specified in |<>| after the
2943 * template class name when using the, including |<>|
2944 *
2945 * Example:
2946 * @code
2947 * // template class declaration
2948 * template <class C>
2949 * class Foo { ... };
2950 * // applied workaround
2951 * WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL (Foo, <class C>, <C>)
2952 * @endcode
2953 */
2954#if defined(_MSC_VER)
2955# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL(Tpl, ArgsDecl, Args) \
2956 template ArgsDecl \
2957 inline bool operator! (const Tpl Args &that) { return !bool (that); } \
2958 template ArgsDecl \
2959 inline bool operator&& (const Tpl Args &that, bool b) { return bool (that) && b; } \
2960 template ArgsDecl \
2961 inline bool operator|| (const Tpl Args &that, bool b) { return bool (that) || b; } \
2962 template ArgsDecl \
2963 inline bool operator&& (bool b, const Tpl Args &that) { return b && bool (that); } \
2964 template ArgsDecl \
2965 inline bool operator|| (bool b, const Tpl Args &that) { return b || bool (that); }
2966#else
2967# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL(Tpl, ArgsDecl, Args)
2968#endif
2969
2970
2971/** @def DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP
2972 * Declares the copy constructor and the assignment operation as inlined no-ops
2973 * (non-existent functions) for the given class. Use this macro inside the
2974 * private section if you want to effectively disable these operations for your
2975 * class.
2976 *
2977 * @param Cls class name to declare for
2978 */
2979
2980#define DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(Cls) \
2981 inline Cls (const Cls &); \
2982 inline Cls &operator= (const Cls &);
2983
2984
2985/** @def DECLARE_CLS_NEW_DELETE_NOOP
2986 * Declares the new and delete operations as no-ops (non-existent functions)
2987 * for the given class. Use this macro inside the private section if you want
2988 * to effectively limit creating class instances on the stack only.
2989 *
2990 * @note The destructor of the given class must not be virtual, otherwise a
2991 * compile time error will occur. Note that this is not a drawback: having
2992 * the virtual destructor for a stack-based class is absolutely useless
2993 * (the real class of the stack-based instance is always known to the compiler
2994 * at compile time, so it will always call the correct destructor).
2995 *
2996 * @param Cls class name to declare for
2997 */
2998#define DECLARE_CLS_NEW_DELETE_NOOP(Cls) \
2999 inline static void *operator new (size_t); \
3000 inline static void operator delete (void *);
3001
3002#endif /* __cplusplus */
3003
3004/** @} */
3005
3006#endif
3007
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