VirtualBox

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

Last change on this file since 25817 was 25748, checked in by vboxsync, 15 years ago

iprt/cdefs,*: Use RT_LOCK_STRICT and RT_LOCK_STRICT_ORDER for controlling deadlock detection and lock order validation. Currently both are disabled by default, but it's possible to add VBOX_WITH_STRICT_LOCKS=1 to LocalConfig.kmk to enable it all.

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