VirtualBox

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

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

iprt/cdefs.h: The MSC equivalent of PRETTY_FUNCTION is FUNCSIG.

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