VirtualBox

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

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

iprt/cdefs.h: Added RT_STR_TUPLE.

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