VirtualBox

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

Last change on this file since 22892 was 22801, checked in by vboxsync, 15 years ago

iprt/cdefs.h: Added DECL_INVALID(type).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 60.4 KB
Line 
1/** @file
2 * IPRT - Common C and C++ definitions.
3 */
4
5/*
6 * Copyright (C) 2006-2009 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
26 * Clara, CA 95054 USA or visit http://www.sun.com if you need
27 * additional information or have any questions.
28 */
29
30#ifndef ___iprt_cdefs_h
31#define ___iprt_cdefs_h
32
33
34/** @defgroup grp_rt_cdefs IPRT Common Definitions and Macros
35 * @{
36 */
37
38/*
39 * Include sys/cdefs.h if present, if not define the stuff we need.
40 */
41#ifdef HAVE_SYS_CDEFS_H
42# if defined(RT_ARCH_LINUX) && defined(__KERNEL__)
43# error "oops"
44# endif
45# include <sys/cdefs.h>
46#else
47
48/** @def RT_C_DECLS_BEGIN
49 * Used to start a block of function declarations which are shared
50 * between C and C++ program.
51 */
52
53/** @def RT_C_DECLS_END
54 * Used to end a block of function declarations which are shared
55 * between C and C++ program.
56 */
57
58# if defined(__cplusplus)
59# define RT_C_DECLS_BEGIN extern "C" {
60# define RT_C_DECLS_END }
61# else
62# define RT_C_DECLS_BEGIN
63# define RT_C_DECLS_END
64# endif
65
66#endif
67
68
69/*
70 * Shut up DOXYGEN warnings and guide it properly thru the code.
71 */
72#ifdef DOXYGEN_RUNNING
73#define __AMD64__
74#define __X86__
75#define RT_ARCH_AMD64
76#define RT_ARCH_X86
77#define IN_RING0
78#define IN_RING3
79#define IN_RC
80#define IN_RC
81#define IN_RT_GC
82#define IN_RT_R0
83#define IN_RT_R3
84#define IN_RT_STATIC
85#define RT_STRICT
86#define Breakpoint
87#define RT_NO_DEPRECATED_MACROS
88#define RT_EXCEPTIONS_ENABLED
89#endif /* DOXYGEN_RUNNING */
90
91/** @def RT_ARCH_X86
92 * Indicates that we're compiling for the X86 architecture.
93 */
94
95/** @def RT_ARCH_AMD64
96 * Indicates that we're compiling for the AMD64 architecture.
97 */
98#if !defined(RT_ARCH_X86) && !defined(RT_ARCH_AMD64)
99# if defined(__amd64__) || defined(__x86_64__) || defined(_M_X64) || defined(__AMD64__)
100# define RT_ARCH_AMD64
101# elif defined(__i386__) || defined(_M_IX86) || defined(__X86__)
102# define RT_ARCH_X86
103# else /* PORTME: append test for new archs. */
104# error "Check what predefined macros your compiler uses to indicate architecture."
105# endif
106#elif defined(RT_ARCH_X86) && defined(RT_ARCH_AMD64) /* PORTME: append new archs. */
107# error "Both RT_ARCH_X86 and RT_ARCH_AMD64 cannot be defined at the same time!"
108#endif
109
110
111/** @def __X86__
112 * Indicates that we're compiling for the X86 architecture.
113 * @deprecated
114 */
115
116/** @def __AMD64__
117 * Indicates that we're compiling for the AMD64 architecture.
118 * @deprecated
119 */
120#if !defined(__X86__) && !defined(__AMD64__)
121# if defined(RT_ARCH_AMD64)
122# define __AMD64__
123# elif defined(RT_ARCH_X86)
124# define __X86__
125# else
126# error "Check what predefined macros your compiler uses to indicate architecture."
127# endif
128#elif defined(__X86__) && defined(__AMD64__)
129# error "Both __X86__ and __AMD64__ cannot be defined at the same time!"
130#elif defined(__X86__) && !defined(RT_ARCH_X86)
131# error "Both __X86__ without RT_ARCH_X86!"
132#elif defined(__AMD64__) && !defined(RT_ARCH_AMD64)
133# error "Both __AMD64__ without RT_ARCH_AMD64!"
134#endif
135
136/** @def IN_RING0
137 * Used to indicate that we're compiling code which is running
138 * in Ring-0 Host Context.
139 */
140
141/** @def IN_RING3
142 * Used to indicate that we're compiling code which is running
143 * in Ring-3 Host Context.
144 */
145
146/** @def IN_RC
147 * Used to indicate that we're compiling code which is running
148 * in the Raw-mode Context (implies R0).
149 */
150#if !defined(IN_RING3) && !defined(IN_RING0) && !defined(IN_RC) && !defined(IN_RC)
151# error "You must define which context the compiled code should run in; IN_RING3, IN_RING0 or IN_RC"
152#endif
153#if (defined(IN_RING3) && (defined(IN_RING0) || defined(IN_RC)) ) \
154 || (defined(IN_RING0) && (defined(IN_RING3) || defined(IN_RC)) ) \
155 || (defined(IN_RC) && (defined(IN_RING3) || defined(IN_RING0)) )
156# error "Only one of the IN_RING3, IN_RING0, IN_RC defines should be defined."
157#endif
158
159
160/** @def ARCH_BITS
161 * Defines the bit count of the current context.
162 */
163#if !defined(ARCH_BITS) || defined(DOXYGEN_RUNNING)
164# if defined(RT_ARCH_AMD64)
165# define ARCH_BITS 64
166# else
167# define ARCH_BITS 32
168# endif
169#endif
170
171/** @def HC_ARCH_BITS
172 * Defines the host architecture bit count.
173 */
174#if !defined(HC_ARCH_BITS) || defined(DOXYGEN_RUNNING)
175# ifndef IN_RC
176# define HC_ARCH_BITS ARCH_BITS
177# else
178# define HC_ARCH_BITS 32
179# endif
180#endif
181
182/** @def GC_ARCH_BITS
183 * Defines the guest architecture bit count.
184 */
185#if !defined(GC_ARCH_BITS) && !defined(DOXYGEN_RUNNING)
186# ifdef VBOX_WITH_64_BITS_GUESTS
187# define GC_ARCH_BITS 64
188# else
189# define GC_ARCH_BITS 32
190# endif
191#endif
192
193/** @def R3_ARCH_BITS
194 * Defines the host ring-3 architecture bit count.
195 */
196#if !defined(R3_ARCH_BITS) || defined(DOXYGEN_RUNNING)
197# ifdef IN_RING3
198# define R3_ARCH_BITS ARCH_BITS
199# else
200# define R3_ARCH_BITS HC_ARCH_BITS
201# endif
202#endif
203
204/** @def R0_ARCH_BITS
205 * Defines the host ring-0 architecture bit count.
206 */
207#if !defined(R0_ARCH_BITS) || defined(DOXYGEN_RUNNING)
208# ifdef IN_RING0
209# define R0_ARCH_BITS ARCH_BITS
210# else
211# define R0_ARCH_BITS HC_ARCH_BITS
212# endif
213#endif
214
215/** @def GC_ARCH_BITS
216 * Defines the guest architecture bit count.
217 */
218#if !defined(GC_ARCH_BITS) || defined(DOXYGEN_RUNNING)
219# ifdef IN_RC
220# define GC_ARCH_BITS ARCH_BITS
221# else
222# define GC_ARCH_BITS 32
223# endif
224#endif
225
226
227/** @def CTXTYPE
228 * Declare a type differently in GC, R3 and R0.
229 *
230 * @param GCType The GC type.
231 * @param R3Type The R3 type.
232 * @param R0Type The R0 type.
233 * @remark For pointers used only in one context use RCPTRTYPE(), R3R0PTRTYPE(), R3PTRTYPE() or R0PTRTYPE().
234 */
235#ifdef IN_RC
236# define CTXTYPE(GCType, R3Type, R0Type) GCType
237#elif defined(IN_RING3)
238# define CTXTYPE(GCType, R3Type, R0Type) R3Type
239#else
240# define CTXTYPE(GCType, R3Type, R0Type) R0Type
241#endif
242
243/** @def RCPTRTYPE
244 * Declare a pointer which is used in the raw mode context but appears in structure(s) used by
245 * both HC and RC. The main purpose is to make sure structures have the same
246 * size when built for different architectures.
247 *
248 * @param RCType The RC type.
249 */
250#define RCPTRTYPE(RCType) CTXTYPE(RCType, RTRCPTR, RTRCPTR)
251
252/** @def R3R0PTRTYPE
253 * Declare a pointer which is used in HC, is explicitly valid in ring 3 and 0,
254 * but appears in structure(s) used by both HC and GC. The main purpose is to
255 * make sure structures have the same size when built for different architectures.
256 *
257 * @param R3R0Type The R3R0 type.
258 * @remarks This used to be called HCPTRTYPE.
259 */
260#define R3R0PTRTYPE(R3R0Type) CTXTYPE(RTHCPTR, R3R0Type, R3R0Type)
261
262/** @def R3PTRTYPE
263 * Declare a pointer which is used in R3 but appears in structure(s) used by
264 * both HC and GC. The main purpose is to make sure structures have the same
265 * size when built for different architectures.
266 *
267 * @param R3Type The R3 type.
268 */
269#define R3PTRTYPE(R3Type) CTXTYPE(RTHCUINTPTR, R3Type, RTHCUINTPTR)
270
271/** @def R0PTRTYPE
272 * Declare a pointer which is used in R0 but appears in structure(s) used by
273 * both HC and GC. The main purpose is to make sure structures have the same
274 * size when built for different architectures.
275 *
276 * @param R0Type The R0 type.
277 */
278#define R0PTRTYPE(R0Type) CTXTYPE(RTHCUINTPTR, RTHCUINTPTR, R0Type)
279
280/** @def CTXSUFF
281 * Adds the suffix of the current context to the passed in
282 * identifier name. The suffix is HC or GC.
283 *
284 * This is macro should only be used in shared code to avoid a forest of ifdefs.
285 * @param var Identifier name.
286 * @deprecated Use CTX_SUFF. Do NOT use this for new code.
287 */
288/** @def OTHERCTXSUFF
289 * Adds the suffix of the other context to the passed in
290 * identifier name. The suffix is HC or GC.
291 *
292 * This is macro should only be used in shared code to avoid a forest of ifdefs.
293 * @param var Identifier name.
294 * @deprecated Use CTX_SUFF. Do NOT use this for new code.
295 */
296#ifdef IN_RC
297# define CTXSUFF(var) var##GC
298# define OTHERCTXSUFF(var) var##HC
299#else
300# define CTXSUFF(var) var##HC
301# define OTHERCTXSUFF(var) var##GC
302#endif
303
304/** @def CTXALLSUFF
305 * Adds the suffix of the current context to the passed in
306 * identifier name. The suffix is R3, R0 or GC.
307 *
308 * This is macro should only be used in shared code to avoid a forest of ifdefs.
309 * @param var Identifier name.
310 * @deprecated Use CTX_SUFF. Do NOT use this for new code.
311 */
312#ifdef IN_RC
313# define CTXALLSUFF(var) var##GC
314#elif defined(IN_RING0)
315# define CTXALLSUFF(var) var##R0
316#else
317# define CTXALLSUFF(var) var##R3
318#endif
319
320/** @def CTX_SUFF
321 * Adds the suffix of the current context to the passed in
322 * identifier name. The suffix is R3, R0 or RC.
323 *
324 * This is macro should only be used in shared code to avoid a forest of ifdefs.
325 * @param var Identifier name.
326 *
327 * @remark This will replace CTXALLSUFF and CTXSUFF before long.
328 */
329#ifdef IN_RC
330# define CTX_SUFF(var) var##RC
331#elif defined(IN_RING0)
332# define CTX_SUFF(var) var##R0
333#else
334# define CTX_SUFF(var) var##R3
335#endif
336
337/** @def CTX_SUFF_Z
338 * Adds the suffix of the current context to the passed in
339 * identifier name, combining RC and R0 into RZ.
340 * The suffix thus is R3 or RZ.
341 *
342 * This is macro should only be used in shared code to avoid a forest of ifdefs.
343 * @param var Identifier name.
344 *
345 * @remark This will replace CTXALLSUFF and CTXSUFF before long.
346 */
347#ifdef IN_RING3
348# define CTX_SUFF_Z(var) var##R3
349#else
350# define CTX_SUFF_Z(var) var##RZ
351#endif
352
353
354/** @def CTXMID
355 * Adds the current context as a middle name of an identifier name
356 * The middle name is HC or GC.
357 *
358 * This is macro should only be used in shared code to avoid a forest of ifdefs.
359 * @param first First name.
360 * @param last Surname.
361 */
362/** @def OTHERCTXMID
363 * Adds the other context as a middle name of an identifier name
364 * The middle name is HC or GC.
365 *
366 * This is macro should only be used in shared code to avoid a forest of ifdefs.
367 * @param first First name.
368 * @param last Surname.
369 * @deprecated use CTX_MID or CTX_MID_Z
370 */
371#ifdef IN_RC
372# define CTXMID(first, last) first##GC##last
373# define OTHERCTXMID(first, last) first##HC##last
374#else
375# define CTXMID(first, last) first##HC##last
376# define OTHERCTXMID(first, last) first##GC##last
377#endif
378
379/** @def CTXALLMID
380 * Adds the current context as a middle name of an identifier name.
381 * The middle name is R3, R0 or GC.
382 *
383 * This is macro should only be used in shared code to avoid a forest of ifdefs.
384 * @param first First name.
385 * @param last Surname.
386 * @deprecated use CTX_MID or CTX_MID_Z
387 */
388#ifdef IN_RC
389# define CTXALLMID(first, last) first##GC##last
390#elif defined(IN_RING0)
391# define CTXALLMID(first, last) first##R0##last
392#else
393# define CTXALLMID(first, last) first##R3##last
394#endif
395
396/** @def CTX_MID
397 * Adds the current context as a middle name of an identifier name.
398 * The middle name is R3, R0 or RC.
399 *
400 * This is macro should only be used in shared code to avoid a forest of ifdefs.
401 * @param first First name.
402 * @param last Surname.
403 */
404#ifdef IN_RC
405# define CTX_MID(first, last) first##RC##last
406#elif defined(IN_RING0)
407# define CTX_MID(first, last) first##R0##last
408#else
409# define CTX_MID(first, last) first##R3##last
410#endif
411
412/** @def CTX_MID_Z
413 * Adds the current context as a middle name of an identifier name, combining RC
414 * and R0 into RZ.
415 * The middle name thus is either R3 or RZ.
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#ifdef IN_RING3
422# define CTX_MID_Z(first, last) first##R3##last
423#else
424# define CTX_MID_Z(first, last) first##RZ##last
425#endif
426
427
428/** @def R3STRING
429 * A macro which in GC and R0 will return a dummy string while in R3 it will return
430 * the parameter.
431 *
432 * This is typically used to wrap description strings in structures shared
433 * between R3, R0 and/or GC. The intention is to avoid the \#ifdef IN_RING3 mess.
434 *
435 * @param pR3String The R3 string. Only referenced in R3.
436 * @see R0STRING and GCSTRING
437 */
438#ifdef IN_RING3
439# define R3STRING(pR3String) (pR3String)
440#else
441# define R3STRING(pR3String) ("<R3_STRING>")
442#endif
443
444/** @def R0STRING
445 * A macro which in GC and R3 will return a dummy string while in R0 it will return
446 * the parameter.
447 *
448 * This is typically used to wrap description strings in structures shared
449 * between R3, R0 and/or GC. The intention is to avoid the \#ifdef IN_RING0 mess.
450 *
451 * @param pR0String The R0 string. Only referenced in R0.
452 * @see R3STRING and GCSTRING
453 */
454#ifdef IN_RING0
455# define R0STRING(pR0String) (pR0String)
456#else
457# define R0STRING(pR0String) ("<R0_STRING>")
458#endif
459
460/** @def RCSTRING
461 * A macro which in R3 and R0 will return a dummy string while in RC it will return
462 * the parameter.
463 *
464 * This is typically used to wrap description strings in structures shared
465 * between R3, R0 and/or RC. The intention is to avoid the \#ifdef IN_RC mess.
466 *
467 * @param pR0String The RC string. Only referenced in RC.
468 * @see R3STRING, R0STRING
469 */
470#ifdef IN_RC
471# define RCSTRING(pRCString) (pRCString)
472#else
473# define RCSTRING(pRCString) ("<RC_STRING>")
474#endif
475
476
477/** @def RT_NOTHING
478 * A macro that expands to nothing.
479 * This is primarily intended as a dummy argument for macros to avoid the
480 * undefined behavior passing empty arguments to an macro (ISO C90 and C++98,
481 * gcc v4.4 warns about it).
482 */
483#define RT_NOTHING
484
485/** @def RT_EXCEPTIONS_ENABLED
486 * Defined when C++ exceptions are enabled.
487 */
488#if !defined(RT_EXCEPTIONS_ENABLED) \
489 && defined(__cplusplus) \
490 && ( (defined(_MSC_VER) && defined(_CPPUNWIND)) \
491 || (defined(__GNUC__) && defined(__EXCEPTIONS)))
492# define RT_EXCEPTIONS_ENABLED
493#endif
494
495/** @def RT_NO_THROW
496 * How to express that a function doesn't throw C++ exceptions
497 * and the compiler can thus save itself the bother of trying
498 * to catch any of them. Put this between the closing parenthesis
499 * and the semicolon in function prototypes (and implementation if C++).
500 */
501#ifdef RT_EXCEPTIONS_ENABLED
502# define RT_NO_THROW throw()
503#else
504# define RT_NO_THROW
505#endif
506
507/** @def RT_THROW
508 * How to express that a method or function throws a type of exceptions. Some
509 * compilers does not want this kind of information and will warning about it.
510 *
511 * @param type The type exception.
512 *
513 * @remarks If the actual throwing is done from the header, enclose it by
514 * \#ifdef RT_EXCEPTIONS_ENABLED ... \#else ... \#endif so the header
515 * compiles cleanly without exceptions enabled.
516 *
517 * Do NOT use this for the actual throwing of exceptions!
518 */
519#ifdef RT_EXCEPTIONS_ENABLED
520# ifdef _MSC_VER
521# if _MSC_VER >= 1400
522# define RT_THROW(type)
523# else
524# define RT_THROW(type) throw(type)
525# endif
526# else
527# define RT_THROW(type) throw(type)
528# endif
529#else
530# define RT_THROW(type)
531#endif
532
533/** @def RTCALL
534 * The standard calling convention for the Runtime interfaces.
535 */
536#ifdef _MSC_VER
537# define RTCALL __cdecl
538#elif defined(__GNUC__) && defined(IN_RING0) && !(defined(RT_OS_OS2) || defined(RT_ARCH_AMD64)) /* the latter is kernel/gcc */
539# define RTCALL __attribute__((cdecl,regparm(0)))
540#else
541# define RTCALL
542#endif
543
544/** @def DECLEXPORT
545 * How to declare an exported function.
546 * @param type The return type of the function declaration.
547 */
548#if defined(_MSC_VER) || defined(RT_OS_OS2)
549# define DECLEXPORT(type) __declspec(dllexport) type
550#elif defined(RT_USE_VISIBILITY_DEFAULT)
551# define DECLEXPORT(type) __attribute__((visibility("default"))) type
552#else
553# define DECLEXPORT(type) type
554#endif
555
556/** @def DECLIMPORT
557 * How to declare an imported function.
558 * @param type The return type of the function declaration.
559 */
560#if defined(_MSC_VER) || (defined(RT_OS_OS2) && !defined(__IBMC__) && !defined(__IBMCPP__))
561# define DECLIMPORT(type) __declspec(dllimport) type
562#else
563# define DECLIMPORT(type) type
564#endif
565
566/** @def DECLHIDDEN
567 * How to declare a non-exported function or variable.
568 * @param type The return type of the function or the data type of the variable.
569 */
570#if defined(RT_OS_OS2) || defined(RT_OS_WINDOWS) || !defined(RT_USE_VISIBILITY_HIDDEN)
571# define DECLHIDDEN(type) type
572#else
573# define DECLHIDDEN(type) __attribute__((visibility("hidden"))) type
574#endif
575
576/** @def DECL_INVALID
577 * How to declare a function not available for linking in the current context.
578 * The purpose is to create compile or like time errors when used. This isn't
579 * possible on all platforms.
580 * @param type The return type of the function.
581 */
582#if defined(_MSC_VER)
583# define DECL_INVALID(type) __declspec(dllimport) type __stdcall
584#elif defined(__GNUC__) && defined(__cplusplus)
585# define DECL_INVALID(type) extern "C++" type
586#else
587# define DECL_INVALID(type) type
588#endif
589
590/** @def DECLASM
591 * How to declare an internal assembly function.
592 * @param type The return type of the function declaration.
593 */
594#ifdef __cplusplus
595# ifdef _MSC_VER
596# define DECLASM(type) extern "C" type __cdecl
597# else
598# define DECLASM(type) extern "C" type
599# endif
600#else
601# ifdef _MSC_VER
602# define DECLASM(type) type __cdecl
603# else
604# define DECLASM(type) type
605# endif
606#endif
607
608/** @def DECLASMTYPE
609 * How to declare an internal assembly function type.
610 * @param type The return type of the function.
611 */
612#ifdef _MSC_VER
613# define DECLASMTYPE(type) type __cdecl
614#else
615# define DECLASMTYPE(type) type
616#endif
617
618/** @def DECLNORETURN
619 * How to declare a function which does not return.
620 * @note: This macro can be combined with other macros, for example
621 * @code
622 * EMR3DECL(DECLNORETURN(void)) foo(void);
623 * @endcode
624 */
625#ifdef _MSC_VER
626# define DECLNORETURN(type) __declspec(noreturn) type
627#elif defined(__GNUC__)
628# define DECLNORETURN(type) __attribute__((noreturn)) type
629#else
630# define DECLNORETURN(type) type
631#endif
632
633/** @def DECLCALLBACK
634 * How to declare an call back function type.
635 * @param type The return type of the function declaration.
636 */
637#define DECLCALLBACK(type) type RTCALL
638
639/** @def DECLCALLBACKPTR
640 * How to declare an call back function pointer.
641 * @param type The return type of the function declaration.
642 * @param name The name of the variable member.
643 */
644#define DECLCALLBACKPTR(type, name) type (RTCALL * name)
645
646/** @def DECLCALLBACKMEMBER
647 * How to declare an call back function pointer member.
648 * @param type The return type of the function declaration.
649 * @param name The name of the struct/union/class member.
650 */
651#define DECLCALLBACKMEMBER(type, name) type (RTCALL * name)
652
653/** @def DECLR3CALLBACKMEMBER
654 * How to declare an call back function pointer member - R3 Ptr.
655 * @param type The return type of the function declaration.
656 * @param name The name of the struct/union/class member.
657 * @param args The argument list enclosed in parentheses.
658 */
659#ifdef IN_RING3
660# define DECLR3CALLBACKMEMBER(type, name, args) type (RTCALL * name) args
661#else
662# define DECLR3CALLBACKMEMBER(type, name, args) RTR3PTR name
663#endif
664
665/** @def DECLRCCALLBACKMEMBER
666 * How to declare an call back function pointer member - RC Ptr.
667 * @param type The return type of the function declaration.
668 * @param name The name of the struct/union/class member.
669 * @param args The argument list enclosed in parentheses.
670 */
671#ifdef IN_RC
672# define DECLRCCALLBACKMEMBER(type, name, args) type (RTCALL * name) args
673#else
674# define DECLRCCALLBACKMEMBER(type, name, args) RTRCPTR name
675#endif
676
677/** @def DECLR0CALLBACKMEMBER
678 * How to declare an call back function pointer member - R0 Ptr.
679 * @param type The return type of the function declaration.
680 * @param name The name of the struct/union/class member.
681 * @param args The argument list enclosed in parentheses.
682 */
683#ifdef IN_RING0
684# define DECLR0CALLBACKMEMBER(type, name, args) type (RTCALL * name) args
685#else
686# define DECLR0CALLBACKMEMBER(type, name, args) RTR0PTR name
687#endif
688
689/** @def DECLINLINE
690 * How to declare a function as inline.
691 * @param type The return type of the function declaration.
692 * @remarks Don't use this macro on C++ methods.
693 */
694#ifdef __GNUC__
695# define DECLINLINE(type) static __inline__ type
696#elif defined(__cplusplus)
697# define DECLINLINE(type) inline type
698#elif defined(_MSC_VER)
699# define DECLINLINE(type) _inline type
700#elif defined(__IBMC__)
701# define DECLINLINE(type) _Inline type
702#else
703# define DECLINLINE(type) inline type
704#endif
705
706
707/** @def DECL_FORCE_INLINE
708 * How to declare a function as inline and try convince the compiler to always
709 * inline it regardless of optimization switches.
710 * @param type The return type of the function declaration.
711 * @remarks Use sparsely and with care. Don't use this macro on C++ methods.
712 */
713#ifdef __GNUC__
714# define DECL_FORCE_INLINE(type) __attribute__((always_inline)) DECLINLINE(type)
715#elif defined(_MSC_VER)
716# define DECL_FORCE_INLINE(type) __forceinline type
717#else
718# define DECL_FORCE_INLINE(type) DECLINLINE(type)
719#endif
720
721
722/** @def DECL_NO_INLINE
723 * How to declare a function telling the compiler not to inline it.
724 * @param scope The function scope, static or RT_NOTHING.
725 * @param type The return type of the function declaration.
726 * @remarks Don't use this macro on C++ methods.
727 */
728#ifdef __GNUC__
729# define DECL_NO_INLINE(scope,type) __attribute__((noinline)) scope type
730#elif defined(_MSC_VER)
731# define DECL_NO_INLINE(scope,type) __declspec(noline) scope type
732#else
733# define DECL_NO_INLINE(scope,type) scope type
734#endif
735
736
737/** @def IN_RT_STATIC
738 * Used to indicate whether we're linking against a static IPRT
739 * or not. The IPRT symbols will be declared as hidden (if
740 * supported). Note that this define has no effect without setting
741 * IN_RT_R0, IN_RT_R3 or IN_RT_GC indicators are set first.
742 */
743
744/** @def IN_RT_R0
745 * Used to indicate whether we're inside the same link module as
746 * the HC Ring-0 Runtime Library.
747 */
748/** @def RTR0DECL(type)
749 * Runtime Library HC Ring-0 export or import declaration.
750 * @param type The return type of the function declaration.
751 */
752#ifdef IN_RT_R0
753# ifdef IN_RT_STATIC
754# define RTR0DECL(type) DECLHIDDEN(type) RTCALL
755# else
756# define RTR0DECL(type) DECLEXPORT(type) RTCALL
757# endif
758#else
759# define RTR0DECL(type) DECLIMPORT(type) RTCALL
760#endif
761
762/** @def IN_RT_R3
763 * Used to indicate whether we're inside the same link module as
764 * the HC Ring-3 Runtime Library.
765 */
766/** @def RTR3DECL(type)
767 * Runtime Library HC Ring-3 export or import declaration.
768 * @param type The return type of the function declaration.
769 */
770#ifdef IN_RT_R3
771# ifdef IN_RT_STATIC
772# define RTR3DECL(type) DECLHIDDEN(type) RTCALL
773# else
774# define RTR3DECL(type) DECLEXPORT(type) RTCALL
775# endif
776#else
777# define RTR3DECL(type) DECLIMPORT(type) RTCALL
778#endif
779
780/** @def IN_RT_GC
781 * Used to indicate whether we're inside the same link module as
782 * the GC Runtime Library.
783 */
784/** @def RTGCDECL(type)
785 * Runtime Library HC Ring-3 export or import declaration.
786 * @param type The return type of the function declaration.
787 */
788#ifdef IN_RT_GC
789# ifdef IN_RT_STATIC
790# define RTGCDECL(type) DECLHIDDEN(type) RTCALL
791# else
792# define RTGCDECL(type) DECLEXPORT(type) RTCALL
793# endif
794#else
795# define RTGCDECL(type) DECLIMPORT(type) RTCALL
796#endif
797
798/** @def RTDECL(type)
799 * Runtime Library export or import declaration.
800 * Functions declared using this macro exists in all contexts.
801 * @param type The return type of the function declaration.
802 */
803#if defined(IN_RT_R3) || defined(IN_RT_GC) || defined(IN_RT_R0)
804# ifdef IN_RT_STATIC
805# define RTDECL(type) DECLHIDDEN(type) RTCALL
806# else
807# define RTDECL(type) DECLEXPORT(type) RTCALL
808# endif
809#else
810# define RTDECL(type) DECLIMPORT(type) RTCALL
811#endif
812
813/** @def RTDATADECL(type)
814 * Runtime Library export or import declaration.
815 * Data declared using this macro exists in all contexts.
816 * @param type The return type of the function declaration.
817 */
818#if defined(IN_RT_R3) || defined(IN_RT_GC) || defined(IN_RT_R0)
819# ifdef IN_RT_STATIC
820# define RTDATADECL(type) DECLHIDDEN(type)
821# else
822# define RTDATADECL(type) DECLEXPORT(type)
823# endif
824#else
825# define RTDATADECL(type) DECLIMPORT(type)
826#endif
827
828/** @def RT_DECL_CLASS
829 * Declares an class living in the runtime.
830 */
831#if defined(IN_RT_R3) || defined(IN_RT_GC) || defined(IN_RT_R0)
832# ifdef IN_RT_STATIC
833# define RT_DECL_CLASS
834# else
835# define RT_DECL_CLASS DECLEXPORT_CLASS
836# endif
837#else
838# define RT_DECL_CLASS DECLIMPORT_CLASS
839#endif
840
841
842/** @def RT_NOCRT
843 * Symbol name wrapper for the No-CRT bits.
844 *
845 * In order to coexist in the same process as other CRTs, we need to
846 * decorate the symbols such that they don't conflict the ones in the
847 * other CRTs. The result of such conflicts / duplicate symbols can
848 * confuse the dynamic loader on Unix like systems.
849 *
850 * Define RT_WITHOUT_NOCRT_WRAPPERS to drop the wrapping.
851 * Define RT_WITHOUT_NOCRT_WRAPPER_ALIASES to drop the aliases to the
852 * wrapped names.
853 */
854/** @def RT_NOCRT_STR
855 * Same as RT_NOCRT only it'll return a double quoted string of the result.
856 */
857#ifndef RT_WITHOUT_NOCRT_WRAPPERS
858# define RT_NOCRT(name) nocrt_ ## name
859# define RT_NOCRT_STR(name) "nocrt_" # name
860#else
861# define RT_NOCRT(name) name
862# define RT_NOCRT_STR(name) #name
863#endif
864
865
866
867/** @def RT_LIKELY
868 * Give the compiler a hint that an expression is very likely to hold true.
869 *
870 * Some compilers support explicit branch prediction so that the CPU backend
871 * can hint the processor and also so that code blocks can be reordered such
872 * that the predicted path sees a more linear flow, thus improving cache
873 * behaviour, etc.
874 *
875 * IPRT provides the macros RT_LIKELY() and RT_UNLIKELY() as a way to utilize
876 * this compiler feature when present.
877 *
878 * A few notes about the usage:
879 *
880 * - Generally, use RT_UNLIKELY() with error condition checks (unless you
881 * have some _strong_ reason to do otherwise, in which case document it),
882 * and/or RT_LIKELY() with success condition checks, assuming you want
883 * to optimize for the success path.
884 *
885 * - Other than that, if you don't know the likelihood of a test succeeding
886 * from empirical or other 'hard' evidence, don't make predictions unless
887 * you happen to be a Dirk Gently.
888 *
889 * - These macros are meant to be used in places that get executed a lot. It
890 * is wasteful to make predictions in code that is executed rarely (e.g.
891 * at subsystem initialization time) as the basic block reordering that this
892 * affects can often generate larger code.
893 *
894 * - Note that RT_SUCCESS() and RT_FAILURE() already makes use of RT_LIKELY()
895 * and RT_UNLIKELY(). Should you wish for prediction free status checks,
896 * use the RT_SUCCESS_NP() and RT_FAILURE_NP() macros instead.
897 *
898 *
899 * @returns the boolean result of the expression.
900 * @param expr The expression that's very likely to be true.
901 * @see RT_UNLIKELY
902 */
903/** @def RT_UNLIKELY
904 * Give the compiler a hint that an expression is highly unlikely to hold true.
905 *
906 * See the usage instructions give in the RT_LIKELY() docs.
907 *
908 * @returns the boolean result of the expression.
909 * @param expr The expression that's very unlikely to be true.
910 * @see RT_LIKELY
911 */
912#if defined(__GNUC__)
913# if __GNUC__ >= 3
914# define RT_LIKELY(expr) __builtin_expect(!!(expr), 1)
915# define RT_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
916# else
917# define RT_LIKELY(expr) (expr)
918# define RT_UNLIKELY(expr) (expr)
919# endif
920#else
921# define RT_LIKELY(expr) (expr)
922# define RT_UNLIKELY(expr) (expr)
923#endif
924
925
926/** @def RT_STR
927 * Returns the argument as a string constant.
928 * @param str Argument to stringify. */
929#define RT_STR(str) #str
930/** @def RT_XSTR
931 * Returns the expanded argument as a string.
932 * @param str Argument to expand and stringy. */
933#define RT_XSTR(str) RT_STR(str)
934
935
936/** @def RT_BIT
937 * Convert a bit number into an integer bitmask (unsigned).
938 * @param bit The bit number.
939 */
940#define RT_BIT(bit) ( 1U << (bit) )
941
942/** @def RT_BIT_32
943 * Convert a bit number into a 32-bit bitmask (unsigned).
944 * @param bit The bit number.
945 */
946#define RT_BIT_32(bit) ( UINT32_C(1) << (bit) )
947
948/** @def RT_BIT_64
949 * Convert a bit number into a 64-bit bitmask (unsigned).
950 * @param bit The bit number.
951 */
952#define RT_BIT_64(bit) ( UINT64_C(1) << (bit) )
953
954/** @def RT_ALIGN
955 * Align macro.
956 * @param u Value to align.
957 * @param uAlignment The alignment. Power of two!
958 *
959 * @remark Be extremely careful when using this macro with type which sizeof != sizeof int.
960 * When possible use any of the other RT_ALIGN_* macros. And when that's not
961 * possible, make 101% sure that uAlignment is specified with a right sized type.
962 *
963 * Specifying an unsigned 32-bit alignment constant with a 64-bit value will give
964 * you a 32-bit return value!
965 *
966 * In short: Don't use this macro. Use RT_ALIGN_T() instead.
967 */
968#define RT_ALIGN(u, uAlignment) ( ((u) + ((uAlignment) - 1)) & ~((uAlignment) - 1) )
969
970/** @def RT_ALIGN_T
971 * Align macro.
972 * @param u Value to align.
973 * @param uAlignment The alignment. Power of two!
974 * @param type Integer type to use while aligning.
975 * @remark This macro is the preferred alignment macro, it doesn't have any of the pitfalls RT_ALIGN has.
976 */
977#define RT_ALIGN_T(u, uAlignment, type) ( ((type)(u) + ((uAlignment) - 1)) & ~(type)((uAlignment) - 1) )
978
979/** @def RT_ALIGN_32
980 * Align macro for a 32-bit value.
981 * @param u32 Value to align.
982 * @param uAlignment The alignment. Power of two!
983 */
984#define RT_ALIGN_32(u32, uAlignment) RT_ALIGN_T(u32, uAlignment, uint32_t)
985
986/** @def RT_ALIGN_64
987 * Align macro for a 64-bit value.
988 * @param u64 Value to align.
989 * @param uAlignment The alignment. Power of two!
990 */
991#define RT_ALIGN_64(u64, uAlignment) RT_ALIGN_T(u64, uAlignment, uint64_t)
992
993/** @def RT_ALIGN_Z
994 * Align macro for size_t.
995 * @param cb Value to align.
996 * @param uAlignment The alignment. Power of two!
997 */
998#define RT_ALIGN_Z(cb, uAlignment) RT_ALIGN_T(cb, uAlignment, size_t)
999
1000/** @def RT_ALIGN_P
1001 * Align macro for pointers.
1002 * @param pv Value to align.
1003 * @param uAlignment The alignment. Power of two!
1004 */
1005#define RT_ALIGN_P(pv, uAlignment) RT_ALIGN_PT(pv, uAlignment, void *)
1006
1007/** @def RT_ALIGN_PT
1008 * Align macro for pointers with type cast.
1009 * @param u Value to align.
1010 * @param uAlignment The alignment. Power of two!
1011 * @param CastType The type to cast the result to.
1012 */
1013#define RT_ALIGN_PT(u, uAlignment, CastType) ( (CastType)RT_ALIGN_T(u, uAlignment, uintptr_t) )
1014
1015/** @def RT_ALIGN_R3PT
1016 * Align macro for ring-3 pointers with type cast.
1017 * @param u Value to align.
1018 * @param uAlignment The alignment. Power of two!
1019 * @param CastType The type to cast the result to.
1020 */
1021#define RT_ALIGN_R3PT(u, uAlignment, CastType) ( (CastType)RT_ALIGN_T(u, uAlignment, RTR3UINTPTR) )
1022
1023/** @def RT_ALIGN_R0PT
1024 * Align macro for ring-0 pointers with type cast.
1025 * @param u Value to align.
1026 * @param uAlignment The alignment. Power of two!
1027 * @param CastType The type to cast the result to.
1028 */
1029#define RT_ALIGN_R0PT(u, uAlignment, CastType) ( (CastType)RT_ALIGN_T(u, uAlignment, RTR0UINTPTR) )
1030
1031/** @def RT_ALIGN_GCPT
1032 * Align macro for GC pointers with type cast.
1033 * @param u Value to align.
1034 * @param uAlignment The alignment. Power of two!
1035 * @param CastType The type to cast the result to.
1036 */
1037#define RT_ALIGN_GCPT(u, uAlignment, CastType) ( (CastType)RT_ALIGN_T(u, uAlignment, RTGCUINTPTR) )
1038
1039
1040/** @def RT_OFFSETOF
1041 * Our own special offsetof() variant, returns a signed result.
1042 *
1043 * This differs from the usual offsetof() in that it's not relying on builtin
1044 * compiler stuff and thus can use variables in arrays the structure may
1045 * contain. This is useful to determine the sizes of structures ending
1046 * with a variable length field.
1047 *
1048 * @returns offset into the structure of the specified member. signed.
1049 * @param type Structure type.
1050 * @param member Member.
1051 */
1052#define RT_OFFSETOF(type, member) ( (int)(uintptr_t)&( ((type *)(void *)0)->member) )
1053
1054/** @def RT_UOFFSETOF
1055 * Our own special offsetof() variant, returns an unsigned result.
1056 *
1057 * This differs from the usual offsetof() in that it's not relying on builtin
1058 * compiler stuff and thus can use variables in arrays the structure may
1059 * contain. This is useful to determine the sizes of structures ending
1060 * with a variable length field.
1061 *
1062 * @returns offset into the structure of the specified member. unsigned.
1063 * @param type Structure type.
1064 * @param member Member.
1065 */
1066#define RT_UOFFSETOF(type, member) ( (uintptr_t)&( ((type *)(void *)0)->member) )
1067
1068/** @def RT_OFFSETOF_ADD
1069 * RT_OFFSETOF with an addend.
1070 *
1071 * @returns offset into the structure of the specified member. signed.
1072 * @param type Structure type.
1073 * @param member Member.
1074 * @param addend The addend to add to the offset.
1075 */
1076#define RT_OFFSETOF_ADD(type, member, addend) ( (int)RT_UOFFSETOF_ADD(type, member, addend) )
1077
1078/** @def RT_UOFFSETOF_ADD
1079 * RT_UOFFSETOF with an addend.
1080 *
1081 * @returns offset into the structure of the specified member. signed.
1082 * @param type Structure type.
1083 * @param member Member.
1084 * @param addend The addend to add to the offset.
1085 */
1086#define RT_UOFFSETOF_ADD(type, member, addend) ( (uintptr_t)&( ((type *)(void *)(uintptr_t)(addend))->member) )
1087
1088/** @def RT_SIZEOFMEMB
1089 * Get the size of a structure member.
1090 *
1091 * @returns size of the structure member.
1092 * @param type Structure type.
1093 * @param member Member.
1094 */
1095#define RT_SIZEOFMEMB(type, member) ( sizeof(((type *)(void *)0)->member) )
1096
1097/** @def RT_FROM_MEMBER
1098 * Convert a pointer to a structure member into a pointer to the structure.
1099 * @returns pointer to the structure.
1100 * @param pMember Pointer to the member.
1101 * @param Type Strucutre type.
1102 * @param Member Member name.
1103 */
1104#define RT_FROM_MEMBER(pMem, Type, Member) ( (Type *) ((uint8_t *)(void *)(pMem) - RT_UOFFSETOF(Type, Member)) )
1105
1106/** @def RT_ELEMENTS
1107 * Calculates the number of elements in a statically sized array.
1108 * @returns Element count.
1109 * @param aArray Array in question.
1110 */
1111#define RT_ELEMENTS(aArray) ( sizeof(aArray) / sizeof((aArray)[0]) )
1112
1113#ifdef RT_OS_OS2
1114/* Undefine RT_MAX since there is an unfortunate clash with the max
1115 resource type define in os2.h. */
1116# undef RT_MAX
1117#endif
1118
1119/** @def RT_MAX
1120 * Finds the maximum value.
1121 * @returns The higher of the two.
1122 * @param Value1 Value 1
1123 * @param Value2 Value 2
1124 */
1125#define RT_MAX(Value1, Value2) ( (Value1) >= (Value2) ? (Value1) : (Value2) )
1126
1127/** @def RT_MIN
1128 * Finds the minimum value.
1129 * @returns The lower of the two.
1130 * @param Value1 Value 1
1131 * @param Value2 Value 2
1132 */
1133#define RT_MIN(Value1, Value2) ( (Value1) <= (Value2) ? (Value1) : (Value2) )
1134
1135/** @def RT_ABS
1136 * Get the absolute (non-negative) value.
1137 * @returns The absolute value of Value.
1138 * @param Value The value.
1139 */
1140#define RT_ABS(Value) ( (Value) >= 0 ? (Value) : -(Value) )
1141
1142/** @def RT_LODWORD
1143 * Gets the low dword (=uint32_t) of something. */
1144#define RT_LODWORD(a) ( (uint32_t)(a) )
1145
1146/** @def RT_HIDWORD
1147 * Gets the high dword (=uint32_t) of a 64-bit of something. */
1148#define RT_HIDWORD(a) ( (uint32_t)((a) >> 32) )
1149
1150/** @def RT_LOWORD
1151 * Gets the low word (=uint16_t) of something. */
1152#define RT_LOWORD(a) ( (a) & 0xffff )
1153
1154/** @def RT_HIWORD
1155 * Gets the high word (=uint16_t) of a 32-bit something. */
1156#define RT_HIWORD(a) ( (a) >> 16 )
1157
1158/** @def RT_LOBYTE
1159 * Gets the low byte of something. */
1160#define RT_LOBYTE(a) ( (a) & 0xff )
1161
1162/** @def RT_HIBYTE
1163 * Gets the low byte of a 16-bit something. */
1164#define RT_HIBYTE(a) ( (a) >> 8 )
1165
1166/** @def RT_BYTE1
1167 * Gets first byte of something. */
1168#define RT_BYTE1(a) ( (a) & 0xff )
1169
1170/** @def RT_BYTE2
1171 * Gets second byte of something. */
1172#define RT_BYTE2(a) ( ((a) >> 8) & 0xff )
1173
1174/** @def RT_BYTE3
1175 * Gets second byte of something. */
1176#define RT_BYTE3(a) ( ((a) >> 16) & 0xff )
1177
1178/** @def RT_BYTE4
1179 * Gets fourth byte of something. */
1180#define RT_BYTE4(a) ( ((a) >> 24) & 0xff )
1181
1182
1183/** @def RT_MAKE_U64
1184 * Constructs a uint64_t value from two uint32_t values.
1185 */
1186#define RT_MAKE_U64(Lo, Hi) ( (uint64_t)((uint32_t)(Hi)) << 32 | (uint32_t)(Lo) )
1187
1188/** @def RT_MAKE_U64_FROM_U16
1189 * Constructs a uint64_t value from four uint16_t values.
1190 */
1191#define RT_MAKE_U64_FROM_U16(w0, w1, w2, w3) \
1192 ( (uint64_t)((uint16_t)(w3)) << 48 \
1193 | (uint64_t)((uint16_t)(w2)) << 32 \
1194 | (uint32_t)((uint16_t)(w1)) << 16 \
1195 | (uint16_t)(w0) )
1196
1197/** @def RT_MAKE_U64_FROM_U8
1198 * Constructs a uint64_t value from eight uint8_t values.
1199 */
1200#define RT_MAKE_U64_FROM_U8(b0, b1, b2, b3, b4, b5, b6, b7) \
1201 ( (uint64_t)((uint8_t)(b7)) << 56 \
1202 | (uint64_t)((uint8_t)(b6)) << 48 \
1203 | (uint64_t)((uint8_t)(b5)) << 40 \
1204 | (uint64_t)((uint8_t)(b4)) << 32 \
1205 | (uint32_t)((uint8_t)(b3)) << 24 \
1206 | (uint32_t)((uint8_t)(b2)) << 16 \
1207 | (uint16_t)((uint8_t)(b1)) << 8 \
1208 | (uint8_t)(b0) )
1209
1210/** @def RT_MAKE_U32
1211 * Constructs a uint32_t value from two uint16_t values.
1212 */
1213#define RT_MAKE_U32(Lo, Hi) ( (uint32_t)((uint16_t)(Hi)) << 16 | (uint16_t)(Lo) )
1214
1215/** @def RT_MAKE_U32_FROM_U8
1216 * Constructs a uint32_t value from four uint8_t values.
1217 */
1218#define RT_MAKE_U32_FROM_U8(b0, b1, b2, b3) \
1219 ( (uint32_t)((uint8_t)(b3)) << 24 \
1220 | (uint32_t)((uint8_t)(b2)) << 16 \
1221 | (uint16_t)((uint8_t)(b1)) << 8 \
1222 | (uint8_t)(b0) )
1223
1224/** @def RT_MAKE_U16
1225 * Constructs a uint32_t value from two uint16_t values.
1226 */
1227#define RT_MAKE_U16(Lo, Hi) ( (uint16_t)((uint8_t)(Hi)) << 8 | (uint8_t)(Lo) )
1228
1229
1230/** @def RT_BSWAP_U64
1231 * Reverses the byte order of an uint64_t value. */
1232#if 0
1233# define RT_BSWAP_U64(u64) RT_BSWAP_U64_C(u64)
1234#elif defined(__GNUC__)
1235/** @todo use __builtin_constant_p? */
1236# define RT_BSWAP_U64(u64) ASMByteSwapU64(u64)
1237#else
1238# define RT_BSWAP_U64(u64) ASMByteSwapU64(u64)
1239#endif
1240
1241/** @def RT_BSWAP_U32
1242 * Reverses the byte order of an uint32_t value. */
1243#if 0
1244# define RT_BSWAP_U32(u32) RT_BSWAP_U32_C(u32)
1245#elif defined(__GNUC__)
1246/** @todo use __builtin_constant_p? */
1247# define RT_BSWAP_U32(u32) ASMByteSwapU32(u32)
1248#else
1249# define RT_BSWAP_U32(u32) ASMByteSwapU32(u32)
1250#endif
1251
1252/** @def RT_BSWAP_U16
1253 * Reverses the byte order of an uint16_t value. */
1254#if 0
1255# define RT_BSWAP_U16(u16) RT_BSWAP_U16_C(u16)
1256#elif defined(__GNUC__)
1257/** @todo use __builtin_constant_p? */
1258# define RT_BSWAP_U16(u16) ASMByteSwapU16(u16)
1259#else
1260# define RT_BSWAP_U16(u16) ASMByteSwapU16(u16)
1261#endif
1262
1263
1264/** @def RT_BSWAP_U64_C
1265 * Reverses the byte order of an uint64_t constant. */
1266#define RT_BSWAP_U64_C(u64) RT_MAKE_U64(RT_BSWAP_U32_C((u64) >> 32), RT_BSWAP_U32_C((u64) & 0xffffffff))
1267
1268/** @def RT_BSWAP_U32_C
1269 * Reverses the byte order of an uint32_t constant. */
1270#define RT_BSWAP_U32_C(u32) (RT_BYTE4(u32) | (RT_BYTE3(u32) << 8) | (RT_BYTE2(u32) << 16) | (RT_BYTE1(u32) << 24))
1271
1272/** @def RT_BSWAP_U16_C
1273 * Reverses the byte order of an uint16_t constant. */
1274#define RT_BSWAP_U16_C(u16) (RT_HIBYTE(u16) | (RT_LOBYTE(u16) << 8))
1275
1276
1277/** @def RT_H2LE_U64
1278 * Converts an uint64_t value from host to little endian byte order. */
1279#ifdef RT_BIG_ENDIAN
1280# define RT_H2LE_U64(u64) RT_BSWAP_U64(u64)
1281#else
1282# define RT_H2LE_U64(u64) (u64)
1283#endif
1284
1285/** @def RT_H2LE_U64_C
1286 * Converts an uint64_t constant from host to little endian byte order. */
1287#ifdef RT_BIG_ENDIAN
1288# define RT_H2LE_U64_C(u64) RT_BSWAP_U64_C(u64)
1289#else
1290# define RT_H2LE_U64_C(u64) (u64)
1291#endif
1292
1293/** @def RT_H2LE_U32
1294 * Converts an uint32_t value from host to little endian byte order. */
1295#ifdef RT_BIG_ENDIAN
1296# define RT_H2LE_U32(u32) RT_BSWAP_U32(u32)
1297#else
1298# define RT_H2LE_U32(u32) (u32)
1299#endif
1300
1301/** @def RT_H2LE_U32_C
1302 * Converts an uint32_t constant from host to little endian byte order. */
1303#ifdef RT_BIG_ENDIAN
1304# define RT_H2LE_U32_C(u32) RT_BSWAP_U32_C(u32)
1305#else
1306# define RT_H2LE_U32_C(u32) (u32)
1307#endif
1308
1309/** @def RT_H2LE_U16
1310 * Converts an uint16_t value from host to little endian byte order. */
1311#ifdef RT_BIG_ENDIAN
1312# define RT_H2LE_U16(u16) RT_BSWAP_U16(u16)
1313#else
1314# define RT_H2LE_U16(u16) (u16)
1315#endif
1316
1317/** @def RT_H2LE_U16_C
1318 * Converts an uint16_t constant from host to little endian byte order. */
1319#ifdef RT_BIG_ENDIAN
1320# define RT_H2LE_U16_C(u16) RT_BSWAP_U16_C(u16)
1321#else
1322# define RT_H2LE_U16_C(u16) (u16)
1323#endif
1324
1325
1326/** @def RT_LE2H_U64
1327 * Converts an uint64_t value from little endian to host byte order. */
1328#ifdef RT_BIG_ENDIAN
1329# define RT_LE2H_U64(u64) RT_BSWAP_U64(u64)
1330#else
1331# define RT_LE2H_U64(u64) (u64)
1332#endif
1333
1334/** @def RT_LE2H_U64_C
1335 * Converts an uint64_t constant from little endian to host byte order. */
1336#ifdef RT_BIG_ENDIAN
1337# define RT_LE2H_U64_C(u64) RT_BSWAP_U64_C(u64)
1338#else
1339# define RT_LE2H_U64_C(u64) (u64)
1340#endif
1341
1342/** @def RT_LE2H_U32
1343 * Converts an uint32_t value from little endian to host byte order. */
1344#ifdef RT_BIG_ENDIAN
1345# define RT_LE2H_U32(u32) RT_BSWAP_U32(u32)
1346#else
1347# define RT_LE2H_U32(u32) (u32)
1348#endif
1349
1350/** @def RT_LE2H_U32_C
1351 * Converts an uint32_t constant from little endian to host byte order. */
1352#ifdef RT_BIG_ENDIAN
1353# define RT_LE2H_U32_C(u32) RT_BSWAP_U32_C(u32)
1354#else
1355# define RT_LE2H_U32_C(u32) (u32)
1356#endif
1357
1358/** @def RT_LE2H_U16
1359 * Converts an uint16_t value from little endian to host byte order. */
1360#ifdef RT_BIG_ENDIAN
1361# define RT_LE2H_U16(u16) RT_BSWAP_U16(u16)
1362#else
1363# define RT_LE2H_U16(u16) (u16)
1364#endif
1365
1366/** @def RT_LE2H_U16_C
1367 * Converts an uint16_t constant from little endian to host byte order. */
1368#ifdef RT_BIG_ENDIAN
1369# define RT_LE2H_U16_C(u16) RT_BSWAP_U16_C(u16)
1370#else
1371# define RT_LE2H_U16_C(u16) (u16)
1372#endif
1373
1374
1375/** @def RT_H2BE_U64
1376 * Converts an uint64_t value from host to big endian byte order. */
1377#ifdef RT_BIG_ENDIAN
1378# define RT_H2BE_U64(u64) (u64)
1379#else
1380# define RT_H2BE_U64(u64) RT_BSWAP_U64(u64)
1381#endif
1382
1383/** @def RT_H2BE_U64_C
1384 * Converts an uint64_t constant from host to big endian byte order. */
1385#ifdef RT_BIG_ENDIAN
1386# define RT_H2BE_U64_C(u64) (u64)
1387#else
1388# define RT_H2BE_U64_C(u64) RT_BSWAP_U64_C(u64)
1389#endif
1390
1391/** @def RT_H2BE_U32
1392 * Converts an uint32_t value from host to big endian byte order. */
1393#ifdef RT_BIG_ENDIAN
1394# define RT_H2BE_U32(u32) (u32)
1395#else
1396# define RT_H2BE_U32(u32) RT_BSWAP_U32(u32)
1397#endif
1398
1399/** @def RT_H2BE_U32_C
1400 * Converts an uint32_t constant from host to big endian byte order. */
1401#ifdef RT_BIG_ENDIAN
1402# define RT_H2BE_U32_C(u32) (u32)
1403#else
1404# define RT_H2BE_U32_C(u32) RT_BSWAP_U32_C(u32)
1405#endif
1406
1407/** @def RT_H2BE_U16
1408 * Converts an uint16_t value from host to big endian byte order. */
1409#ifdef RT_BIG_ENDIAN
1410# define RT_H2BE_U16(u16) (u16)
1411#else
1412# define RT_H2BE_U16(u16) RT_BSWAP_U16(u16)
1413#endif
1414
1415/** @def RT_H2BE_U16_C
1416 * Converts an uint16_t constant from host to big endian byte order. */
1417#ifdef RT_BIG_ENDIAN
1418# define RT_H2BE_U16_C(u16) (u16)
1419#else
1420# define RT_H2BE_U16_C(u16) RT_BSWAP_U16_C(u16)
1421#endif
1422
1423/** @def RT_BE2H_U64
1424 * Converts an uint64_t value from big endian to host byte order. */
1425#ifdef RT_BIG_ENDIAN
1426# define RT_BE2H_U64(u64) (u64)
1427#else
1428# define RT_BE2H_U64(u64) RT_BSWAP_U64(u64)
1429#endif
1430
1431/** @def RT_BE2H_U64
1432 * Converts an uint64_t constant from big endian to host byte order. */
1433#ifdef RT_BIG_ENDIAN
1434# define RT_BE2H_U64_C(u64) (u64)
1435#else
1436# define RT_BE2H_U64_C(u64) RT_BSWAP_U64_C(u64)
1437#endif
1438
1439/** @def RT_BE2H_U32
1440 * Converts an uint32_t value from big endian to host byte order. */
1441#ifdef RT_BIG_ENDIAN
1442# define RT_BE2H_U32(u32) (u32)
1443#else
1444# define RT_BE2H_U32(u32) RT_BSWAP_U32(u32)
1445#endif
1446
1447/** @def RT_BE2H_U32_C
1448 * Converts an uint32_t value from big endian to host byte order. */
1449#ifdef RT_BIG_ENDIAN
1450# define RT_BE2H_U32_C(u32) (u32)
1451#else
1452# define RT_BE2H_U32_C(u32) RT_BSWAP_U32_C(u32)
1453#endif
1454
1455/** @def RT_BE2H_U16
1456 * Converts an uint16_t value from big endian to host byte order. */
1457#ifdef RT_BIG_ENDIAN
1458# define RT_BE2H_U16(u16) (u16)
1459#else
1460# define RT_BE2H_U16(u16) RT_BSWAP_U16(u16)
1461#endif
1462
1463/** @def RT_BE2H_U16_C
1464 * Converts an uint16_t constant from big endian to host byte order. */
1465#ifdef RT_BIG_ENDIAN
1466# define RT_BE2H_U16_C(u16) (u16)
1467#else
1468# define RT_BE2H_U16_C(u16) RT_BSWAP_U16_C(u16)
1469#endif
1470
1471
1472/** @def RT_H2N_U64
1473 * Converts an uint64_t value from host to network byte order. */
1474#define RT_H2N_U64(u64) RT_H2BE_U64(u64)
1475
1476/** @def RT_H2N_U64_C
1477 * Converts an uint64_t constant from host to network byte order. */
1478#define RT_H2N_U64_C(u64) RT_H2BE_U64_C(u64)
1479
1480/** @def RT_H2N_U32
1481 * Converts an uint32_t value from host to network byte order. */
1482#define RT_H2N_U32(u32) RT_H2BE_U32(u32)
1483
1484/** @def RT_H2N_U32_C
1485 * Converts an uint32_t constant from host to network byte order. */
1486#define RT_H2N_U32_C(u32) RT_H2BE_U32_C(u32)
1487
1488/** @def RT_H2N_U16
1489 * Converts an uint16_t value from host to network byte order. */
1490#define RT_H2N_U16(u16) RT_H2BE_U16(u16)
1491
1492/** @def RT_H2N_U16_C
1493 * Converts an uint16_t constant from host to network byte order. */
1494#define RT_H2N_U16_C(u16) RT_H2BE_U16_C(u16)
1495
1496/** @def RT_N2H_U64
1497 * Converts an uint64_t value from network to host byte order. */
1498#define RT_N2H_U64(u64) RT_BE2H_U64(u64)
1499
1500/** @def RT_N2H_U64_C
1501 * Converts an uint64_t constant from network to host byte order. */
1502#define RT_N2H_U64_C(u64) RT_BE2H_U64_C(u64)
1503
1504/** @def RT_N2H_U32
1505 * Converts an uint32_t value from network to host byte order. */
1506#define RT_N2H_U32(u32) RT_BE2H_U32(u32)
1507
1508/** @def RT_N2H_U32_C
1509 * Converts an uint32_t constant from network to host byte order. */
1510#define RT_N2H_U32_C(u32) RT_BE2H_U32_C(u32)
1511
1512/** @def RT_N2H_U16
1513 * Converts an uint16_t value from network to host byte order. */
1514#define RT_N2H_U16(u16) RT_BE2H_U16(u16)
1515
1516/** @def RT_N2H_U16_C
1517 * Converts an uint16_t value from network to host byte order. */
1518#define RT_N2H_U16_C(u16) RT_BE2H_U16_C(u16)
1519
1520
1521/*
1522 * The BSD sys/param.h + machine/param.h file is a major source of
1523 * namespace pollution. Kill off some of the worse ones unless we're
1524 * compiling kernel code.
1525 */
1526#if defined(RT_OS_DARWIN) \
1527 && !defined(KERNEL) \
1528 && !defined(RT_NO_BSD_PARAM_H_UNDEFING) \
1529 && ( defined(_SYS_PARAM_H_) || defined(_I386_PARAM_H_) )
1530/* sys/param.h: */
1531# undef PSWP
1532# undef PVM
1533# undef PINOD
1534# undef PRIBO
1535# undef PVFS
1536# undef PZERO
1537# undef PSOCK
1538# undef PWAIT
1539# undef PLOCK
1540# undef PPAUSE
1541# undef PUSER
1542# undef PRIMASK
1543# undef MINBUCKET
1544# undef MAXALLOCSAVE
1545# undef FSHIFT
1546# undef FSCALE
1547
1548/* i386/machine.h: */
1549# undef ALIGN
1550# undef ALIGNBYTES
1551# undef DELAY
1552# undef STATUS_WORD
1553# undef USERMODE
1554# undef BASEPRI
1555# undef MSIZE
1556# undef CLSIZE
1557# undef CLSIZELOG2
1558#endif
1559
1560
1561/** @def NULL
1562 * NULL pointer.
1563 */
1564#ifndef NULL
1565# ifdef __cplusplus
1566# define NULL 0
1567# else
1568# define NULL ((void*)0)
1569# endif
1570#endif
1571
1572/** @def NIL_OFFSET
1573 * NIL offset.
1574 * Whenever we use offsets instead of pointers to save space and relocation effort
1575 * NIL_OFFSET shall be used as the equivalent to NULL.
1576 */
1577#define NIL_OFFSET (~0U)
1578
1579/** @def NOREF
1580 * Keeps the compiler from bitching about an unused parameter.
1581 */
1582#define NOREF(var) (void)(var)
1583
1584/** @def Breakpoint
1585 * Emit a debug breakpoint instruction.
1586 *
1587 * Use this for instrumenting a debugging session only!
1588 * No committed code shall use Breakpoint().
1589 */
1590#ifdef __GNUC__
1591# define Breakpoint() __asm__ __volatile__("int $3\n\t")
1592#endif
1593#ifdef _MSC_VER
1594# define Breakpoint() __asm int 3
1595#endif
1596#if defined(__IBMC__) || defined(__IBMCPP__)
1597# define Breakpoint() __interrupt(3)
1598#endif
1599#ifndef Breakpoint
1600# error "This compiler is not supported!"
1601#endif
1602
1603
1604/** @defgroup grp_rt_cdefs_size Size Constants
1605 * (Of course, these are binary computer terms, not SI.)
1606 * @{
1607 */
1608/** 1 K (Kilo) (1 024). */
1609#define _1K 0x00000400
1610/** 4 K (Kilo) (4 096). */
1611#define _4K 0x00001000
1612/** 32 K (Kilo) (32 678). */
1613#define _32K 0x00008000
1614/** 64 K (Kilo) (65 536). */
1615#define _64K 0x00010000
1616/** 128 K (Kilo) (131 072). */
1617#define _128K 0x00020000
1618/** 256 K (Kilo) (262 144). */
1619#define _256K 0x00040000
1620/** 512 K (Kilo) (524 288). */
1621#define _512K 0x00080000
1622/** 1 M (Mega) (1 048 576). */
1623#define _1M 0x00100000
1624/** 2 M (Mega) (2 097 152). */
1625#define _2M 0x00200000
1626/** 4 M (Mega) (4 194 304). */
1627#define _4M 0x00400000
1628/** 1 G (Giga) (1 073 741 824). */
1629#define _1G 0x40000000
1630/** 2 G (Giga) (2 147 483 648). (32-bit) */
1631#define _2G32 0x80000000U
1632/** 2 G (Giga) (2 147 483 648). (64-bit) */
1633#define _2G 0x0000000080000000LL
1634/** 4 G (Giga) (4 294 967 296). */
1635#define _4G 0x0000000100000000LL
1636/** 1 T (Tera) (1 099 511 627 776). */
1637#define _1T 0x0000010000000000LL
1638/** 1 P (Peta) (1 125 899 906 842 624). */
1639#define _1P 0x0004000000000000LL
1640/** 1 E (Exa) (1 152 921 504 606 846 976). */
1641#define _1E 0x1000000000000000LL
1642/** 2 E (Exa) (2 305 843 009 213 693 952). */
1643#define _2E 0x2000000000000000ULL
1644/** @} */
1645
1646
1647/** @defgroup grp_rt_cdefs_dbgtype Debug Info Types
1648 * @{ */
1649/** Other format. */
1650#define RT_DBGTYPE_OTHER RT_BIT_32(0)
1651/** Stabs. */
1652#define RT_DBGTYPE_STABS RT_BIT_32(1)
1653/** Debug With Arbitrary Record Format (DWARF). */
1654#define RT_DBGTYPE_DWARF RT_BIT_32(2)
1655/** Microsoft Codeview debug info. */
1656#define RT_DBGTYPE_CODEVIEW RT_BIT_32(3)
1657/** Watcom debug info. */
1658#define RT_DBGTYPE_WATCOM RT_BIT_32(4)
1659/** IBM High Level Language debug info. */
1660#define RT_DBGTYPE_HLL RT_BIT_32(5)
1661/** Old OS/2 and Windows symbol file. */
1662#define RT_DBGTYPE_SYM RT_BIT_32(6)
1663/** Map file. */
1664#define RT_DBGTYPE_MAP RT_BIT_32(7)
1665/** @} */
1666
1667
1668/** @defgroup grp_rt_cdefs_exetype Executable Image Types
1669 * @{ */
1670/** Some other format. */
1671#define RT_EXETYPE_OTHER RT_BIT_32(0)
1672/** Portable Executable. */
1673#define RT_EXETYPE_PE RT_BIT_32(1)
1674/** Linear eXecutable. */
1675#define RT_EXETYPE_LX RT_BIT_32(2)
1676/** Linear Executable. */
1677#define RT_EXETYPE_LE RT_BIT_32(3)
1678/** New Executable. */
1679#define RT_EXETYPE_NE RT_BIT_32(4)
1680/** DOS Executable (Mark Zbikowski). */
1681#define RT_EXETYPE_MZ RT_BIT_32(5)
1682/** COM Executable. */
1683#define RT_EXETYPE_COM RT_BIT_32(6)
1684/** a.out Executable. */
1685#define RT_EXETYPE_AOUT RT_BIT_32(7)
1686/** Executable and Linkable Format. */
1687#define RT_EXETYPE_ELF RT_BIT_32(8)
1688/** Mach-O Executable (including FAT ones). */
1689#define RT_EXETYPE_MACHO RT_BIT_32(9)
1690/** TE from UEFI. */
1691#define RT_EXETYPE_TE RT_BIT_32(9)
1692/** @} */
1693
1694
1695/** @def VALID_PTR
1696 * Pointer validation macro.
1697 * @param ptr The pointer.
1698 */
1699#if defined(RT_ARCH_AMD64)
1700# ifdef IN_RING3
1701# if defined(RT_OS_DARWIN) /* first 4GB is reserved for legacy kernel. */
1702# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) >= _4G \
1703 && !((uintptr_t)(ptr) & 0xffff800000000000ULL) )
1704# elif defined(RT_OS_SOLARIS) /* The kernel only used the top 2TB, but keep it simple. */
1705# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
1706 && ( ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0xffff800000000000ULL \
1707 || ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0) )
1708# else
1709# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
1710 && !((uintptr_t)(ptr) & 0xffff800000000000ULL) )
1711# endif
1712# else /* !IN_RING3 */
1713# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
1714 && ( ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0xffff800000000000ULL \
1715 || ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0) )
1716# endif /* !IN_RING3 */
1717#elif defined(RT_ARCH_X86)
1718# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U )
1719#else
1720# error "Architecture identifier missing / not implemented."
1721#endif
1722
1723/** Old name for RT_VALID_PTR. */
1724#define VALID_PTR(ptr) RT_VALID_PTR(ptr)
1725
1726/** @def RT_VALID_ALIGNED_PTR
1727 * Pointer validation macro that also checks the alignment.
1728 * @param ptr The pointer.
1729 * @param align The alignment, must be a power of two.
1730 */
1731#define RT_VALID_ALIGNED_PTR(ptr, align) \
1732 ( !((uintptr_t)(ptr) & (uintptr_t)((align) - 1)) \
1733 && VALID_PTR(ptr) )
1734
1735
1736/** @def VALID_PHYS32
1737 * 32 bits physical address validation macro.
1738 * @param Phys The RTGCPHYS address.
1739 */
1740#define VALID_PHYS32(Phys) ( (uint64_t)(Phys) < (uint64_t)_4G )
1741
1742/** @def N_
1743 * The \#define N_ is used to mark a string for translation. This is usable in
1744 * any part of the code, as it is only used by the tools that create message
1745 * catalogs. This macro is a no-op as far as the compiler and code generation
1746 * is concerned.
1747 *
1748 * If you want to both mark a string for translation and translate it, use _().
1749 */
1750#define N_(s) (s)
1751
1752/** @def _
1753 * The \#define _ is used to mark a string for translation and to translate it
1754 * in one step.
1755 *
1756 * If you want to only mark a string for translation, use N_().
1757 */
1758#define _(s) gettext(s)
1759
1760
1761/** @def __PRETTY_FUNCTION__
1762 * With GNU C we'd like to use the builtin __PRETTY_FUNCTION__, so define that
1763 * for the other compilers.
1764 */
1765#if !defined(__GNUC__) && !defined(__PRETTY_FUNCTION__)
1766# define __PRETTY_FUNCTION__ __FUNCTION__
1767#endif
1768
1769
1770/** @def RT_STRICT
1771 * The \#define RT_STRICT controls whether or not assertions and other runtime
1772 * checks should be compiled in or not.
1773 *
1774 * If you want assertions which are not subject to compile time options use
1775 * the AssertRelease*() flavors.
1776 */
1777#if !defined(RT_STRICT) && defined(DEBUG)
1778# define RT_STRICT
1779#endif
1780
1781/** Source position. */
1782#define RT_SRC_POS __FILE__, __LINE__, __PRETTY_FUNCTION__
1783
1784/** Source position declaration. */
1785#define RT_SRC_POS_DECL const char *pszFile, unsigned iLine, const char *pszFunction
1786
1787/** Source position arguments. */
1788#define RT_SRC_POS_ARGS pszFile, iLine, pszFunction
1789
1790/** @} */
1791
1792
1793/** @defgroup grp_rt_cdefs_cpp Special Macros for C++
1794 * @ingroup grp_rt_cdefs
1795 * @{
1796 */
1797
1798#ifdef __cplusplus
1799
1800/** @def DECLEXPORT_CLASS
1801 * How to declare an exported class. Place this macro after the 'class'
1802 * keyword in the declaration of every class you want to export.
1803 *
1804 * @note It is necessary to use this macro even for inner classes declared
1805 * inside the already exported classes. This is a GCC specific requirement,
1806 * but it seems not to harm other compilers.
1807 */
1808#if defined(_MSC_VER) || defined(RT_OS_OS2)
1809# define DECLEXPORT_CLASS __declspec(dllexport)
1810#elif defined(RT_USE_VISIBILITY_DEFAULT)
1811# define DECLEXPORT_CLASS __attribute__((visibility("default")))
1812#else
1813# define DECLEXPORT_CLASS
1814#endif
1815
1816/** @def DECLIMPORT_CLASS
1817 * How to declare an imported class Place this macro after the 'class'
1818 * keyword in the declaration of every class you want to export.
1819 *
1820 * @note It is necessary to use this macro even for inner classes declared
1821 * inside the already exported classes. This is a GCC specific requirement,
1822 * but it seems not to harm other compilers.
1823 */
1824#if defined(_MSC_VER) || (defined(RT_OS_OS2) && !defined(__IBMC__) && !defined(__IBMCPP__))
1825# define DECLIMPORT_CLASS __declspec(dllimport)
1826#elif defined(RT_USE_VISIBILITY_DEFAULT)
1827# define DECLIMPORT_CLASS __attribute__((visibility("default")))
1828#else
1829# define DECLIMPORT_CLASS
1830#endif
1831
1832/** @def WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP
1833 * Macro to work around error C2593 of the not-so-smart MSVC 7.x ambiguity
1834 * resolver. The following snippet clearly demonstrates the code causing this
1835 * error:
1836 * @code
1837 * class A
1838 * {
1839 * public:
1840 * operator bool() const { return false; }
1841 * operator int*() const { return NULL; }
1842 * };
1843 * int main()
1844 * {
1845 * A a;
1846 * if (!a);
1847 * if (a && 0);
1848 * return 0;
1849 * }
1850 * @endcode
1851 * The code itself seems pretty valid to me and GCC thinks the same.
1852 *
1853 * This macro fixes the compiler error by explicitly overloading implicit
1854 * global operators !, && and || that take the given class instance as one of
1855 * their arguments.
1856 *
1857 * The best is to use this macro right after the class declaration.
1858 *
1859 * @note The macro expands to nothing for compilers other than MSVC.
1860 *
1861 * @param Cls Class to apply the workaround to
1862 */
1863#if defined(_MSC_VER)
1864# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP(Cls) \
1865 inline bool operator! (const Cls &that) { return !bool (that); } \
1866 inline bool operator&& (const Cls &that, bool b) { return bool (that) && b; } \
1867 inline bool operator|| (const Cls &that, bool b) { return bool (that) || b; } \
1868 inline bool operator&& (bool b, const Cls &that) { return b && bool (that); } \
1869 inline bool operator|| (bool b, const Cls &that) { return b || bool (that); }
1870#else
1871# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP(Cls)
1872#endif
1873
1874/** @def WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL
1875 * Version of WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP for template classes.
1876 *
1877 * @param Tpl Name of the template class to apply the workaround to
1878 * @param ArgsDecl arguments of the template, as declared in |<>| after the
1879 * |template| keyword, including |<>|
1880 * @param Args arguments of the template, as specified in |<>| after the
1881 * template class name when using the, including |<>|
1882 *
1883 * Example:
1884 * @code
1885 * // template class declaration
1886 * template <class C>
1887 * class Foo { ... };
1888 * // applied workaround
1889 * WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL (Foo, <class C>, <C>)
1890 * @endcode
1891 */
1892#if defined(_MSC_VER)
1893# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL(Tpl, ArgsDecl, Args) \
1894 template ArgsDecl \
1895 inline bool operator! (const Tpl Args &that) { return !bool (that); } \
1896 template ArgsDecl \
1897 inline bool operator&& (const Tpl Args &that, bool b) { return bool (that) && b; } \
1898 template ArgsDecl \
1899 inline bool operator|| (const Tpl Args &that, bool b) { return bool (that) || b; } \
1900 template ArgsDecl \
1901 inline bool operator&& (bool b, const Tpl Args &that) { return b && bool (that); } \
1902 template ArgsDecl \
1903 inline bool operator|| (bool b, const Tpl Args &that) { return b || bool (that); }
1904#else
1905# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL(Tpl, ArgsDecl, Args)
1906#endif
1907
1908
1909/** @def DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP
1910 * Declares the copy constructor and the assignment operation as inlined no-ops
1911 * (non-existent functions) for the given class. Use this macro inside the
1912 * private section if you want to effectively disable these operations for your
1913 * class.
1914 *
1915 * @param Cls class name to declare for
1916 */
1917
1918#define DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(Cls) \
1919 inline Cls (const Cls &); \
1920 inline Cls &operator= (const Cls &);
1921
1922
1923/** @def DECLARE_CLS_NEW_DELETE_NOOP
1924 * Declares the new and delete operations as no-ops (non-existent functions)
1925 * for the given class. Use this macro inside the private section if you want
1926 * to effectively limit creating class instances on the stack only.
1927 *
1928 * @note The destructor of the given class must not be virtual, otherwise a
1929 * compile time error will occur. Note that this is not a drawback: having
1930 * the virtual destructor for a stack-based class is absolutely useless
1931 * (the real class of the stack-based instance is always known to the compiler
1932 * at compile time, so it will always call the correct destructor).
1933 *
1934 * @param Cls class name to declare for
1935 */
1936#define DECLARE_CLS_NEW_DELETE_NOOP(Cls) \
1937 inline static void *operator new (size_t); \
1938 inline static void operator delete (void *);
1939
1940#endif /* defined(__cplusplus) */
1941
1942/** @} */
1943
1944#endif
1945
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