VirtualBox

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

Last change on this file since 45968 was 45968, checked in by vboxsync, 12 years ago

Ldr,Dbg: DWARF and ELF hacking in progress.

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

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