VirtualBox

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

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

PDMAsyncCompletion.cpp: Addressed out of bound indexing of StatTaskRunTimesSec and did some code cleanup reducing the file by some 110+ lines.

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