VirtualBox

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

Last change on this file since 40894 was 40874, checked in by vboxsync, 13 years ago

Apply cdecl/regparm for RTCALL only on x86, like below for DECLASM.

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