VirtualBox

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

Last change on this file since 11101 was 11030, checked in by vboxsync, 16 years ago

iprt/cdefs.h: Don't use throw() unless C++ exceptions are enabled.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 48.2 KB
Line 
1/** @file
2 * IPRT - Common C and C++ definitions.
3 */
4
5/*
6 * Copyright (C) 2006-2007 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 __BEGIN_DECLS
49 * Used to start a block of function declarations which are shared
50 * between C and C++ program.
51 */
52
53 /** @def __END_DECLS
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 __BEGIN_DECLS extern "C" {
60 # define __END_DECLS }
61 #else
62 # define __BEGIN_DECLS
63 # define __END_DECLS
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_GC
80#define IN_RT_GC
81#define IN_RT_R0
82#define IN_RT_R3
83#define IN_RT_STATIC
84#define RT_STRICT
85#define Breakpoint
86#define RT_NO_DEPRECATED_MACROS
87#endif /* DOXYGEN_RUNNING */
88
89/** @def RT_ARCH_X86
90 * Indicates that we're compiling for the X86 architecture.
91 */
92
93/** @def RT_ARCH_AMD64
94 * Indicates that we're compiling for the AMD64 architecture.
95 */
96#if !defined(RT_ARCH_X86) && !defined(RT_ARCH_AMD64)
97# if defined(__amd64__) || defined(__x86_64__) || defined(_M_X64) || defined(__AMD64__)
98# define RT_ARCH_AMD64
99# elif defined(__i386__) || defined(_M_IX86) || defined(__X86__)
100# define RT_ARCH_X86
101# else /* PORTME: append test for new archs. */
102# error "Check what predefined stuff your compiler uses to indicate architecture."
103# endif
104#elif defined(RT_ARCH_X86) && defined(RT_ARCH_AMD64) /* PORTME: append new archs. */
105# error "Both RT_ARCH_X86 and RT_ARCH_AMD64 cannot be defined at the same time!"
106#endif
107
108
109/** @def __X86__
110 * Indicates that we're compiling for the X86 architecture.
111 * @deprecated
112 */
113
114/** @def __AMD64__
115 * Indicates that we're compiling for the AMD64 architecture.
116 * @deprecated
117 */
118#if !defined(__X86__) && !defined(__AMD64__)
119# if defined(RT_ARCH_AMD64)
120# define __AMD64__
121# elif defined(RT_ARCH_X86)
122# define __X86__
123# else
124# error "Check what predefined stuff your compiler uses to indicate architecture."
125# endif
126#elif defined(__X86__) && defined(__AMD64__)
127# error "Both __X86__ and __AMD64__ cannot be defined at the same time!"
128#elif defined(__X86__) && !defined(RT_ARCH_X86)
129# error "Both __X86__ without RT_ARCH_X86!"
130#elif defined(__AMD64__) && !defined(RT_ARCH_AMD64)
131# error "Both __AMD64__ without RT_ARCH_AMD64!"
132#endif
133
134/** @def IN_RING0
135 * Used to indicate that we're compiling code which is running
136 * in Ring-0 Host Context.
137 */
138
139/** @def IN_RING3
140 * Used to indicate that we're compiling code which is running
141 * in Ring-3 Host Context.
142 */
143
144/** @def IN_GC
145 * Used to indicate that we're compiling code which is running
146 * in Guest Context (implies R0).
147 */
148#if !defined(IN_RING3) && !defined(IN_RING0) && !defined(IN_GC)
149# error "You must defined which context the compiled code should run in; IN_RING3, IN_RING0 or IN_GC"
150#endif
151#if (defined(IN_RING3) && (defined(IN_RING0) || defined(IN_GC)) ) \
152 || (defined(IN_RING0) && (defined(IN_RING3) || defined(IN_GC)) ) \
153 || (defined(IN_GC) && (defined(IN_RING3) || defined(IN_RING0)) )
154# error "Only one of the IN_RING3, IN_RING0, IN_GC defines should be defined."
155#endif
156
157
158/** @def ARCH_BITS
159 * Defines the bit count of the current context.
160 */
161#if !defined(ARCH_BITS) || defined(DOXYGEN_RUNNING)
162# if defined(RT_ARCH_AMD64)
163# define ARCH_BITS 64
164# else
165# define ARCH_BITS 32
166# endif
167#endif
168
169/** @def HC_ARCH_BITS
170 * Defines the host architecture bit count.
171 */
172#if !defined(HC_ARCH_BITS) || defined(DOXYGEN_RUNNING)
173# ifndef IN_GC
174# define HC_ARCH_BITS ARCH_BITS
175# else
176# define HC_ARCH_BITS 32
177# endif
178#endif
179
180/** @def GC_ARCH_BITS
181 * Defines the guest architecture bit count.
182 */
183#if !defined(GC_ARCH_BITS) && !defined(DOXYGEN_RUNNING)
184# ifdef VBOX_WITH_64_BITS_GUESTS
185# define GC_ARCH_BITS 64
186# else
187# define GC_ARCH_BITS 32
188# endif
189#endif
190
191/** @def R3_ARCH_BITS
192 * Defines the host ring-3 architecture bit count.
193 */
194#if !defined(R3_ARCH_BITS) || defined(DOXYGEN_RUNNING)
195# ifdef IN_RING3
196# define R3_ARCH_BITS ARCH_BITS
197# else
198# define R3_ARCH_BITS HC_ARCH_BITS
199# endif
200#endif
201
202/** @def R0_ARCH_BITS
203 * Defines the host ring-0 architecture bit count.
204 */
205#if !defined(R0_ARCH_BITS) || defined(DOXYGEN_RUNNING)
206# ifdef IN_RING0
207# define R0_ARCH_BITS ARCH_BITS
208# else
209# define R0_ARCH_BITS HC_ARCH_BITS
210# endif
211#endif
212
213/** @def GC_ARCH_BITS
214 * Defines the guest architecture bit count.
215 */
216#if !defined(GC_ARCH_BITS) || defined(DOXYGEN_RUNNING)
217# ifdef IN_GC
218# define GC_ARCH_BITS ARCH_BITS
219# else
220# define GC_ARCH_BITS 32
221# endif
222#endif
223
224
225/** @def CTXTYPE
226 * Declare a type differently in GC, R3 and R0.
227 *
228 * @param GCType The GC type.
229 * @param R3Type The R3 type.
230 * @param R0Type The R0 type.
231 * @remark For pointers used only in one context use RCPTRTYPE(), R3R0PTRTYPE(), R3PTRTYPE() or R0PTRTYPE().
232 */
233#ifdef IN_GC
234# define CTXTYPE(GCType, R3Type, R0Type) GCType
235#elif defined(IN_RING3)
236# define CTXTYPE(GCType, R3Type, R0Type) R3Type
237#else
238# define CTXTYPE(GCType, R3Type, R0Type) R0Type
239#endif
240
241/** @def GCTYPE
242 * Declare a type differently in GC and HC.
243 *
244 * @param GCType The GC type.
245 * @param HCType The HC type.
246 * @remark For pointers used only in one context use RCPTRTYPE(), R3R0PTRTYPE(), R3PTRTYPE() or R0PTRTYPE().
247 */
248#define GCTYPE(GCType, HCType) CTXTYPE(GCType, HCType, HCType)
249
250/** @def RCPTRTYPE
251 * Declare a pointer which is used in the raw mode context but appears in structure(s) used by
252 * both HC and RC. The main purpose is to make sure structures have the same
253 * size when built for different architectures.
254 *
255 * @param RCType The RC type.
256 */
257#define RCPTRTYPE(RCType) CTXTYPE(RCType, RTRCPTR, RTRCPTR)
258
259/** @def R3R0PTRTYPE
260 * Declare a pointer which is used in HC, is explicitely valid in ring 3 and 0,
261 * but appears in structure(s) used by both HC and GC. The main purpose is to
262 * make sure structures have the same size when built for different architectures.
263 *
264 * @param R3R0Type The R3R0 type.
265 * @remarks This used to be called HCPTRTYPE.
266 */
267#define R3R0PTRTYPE(R3R0Type) CTXTYPE(RTHCPTR, R3R0Type, R3R0Type)
268
269/** @def R3PTRTYPE
270 * Declare a pointer which is used in R3 but appears in structure(s) used by
271 * both HC and GC. The main purpose is to make sure structures have the same
272 * size when built for different architectures.
273 *
274 * @param R3Type The R3 type.
275 */
276#define R3PTRTYPE(R3Type) CTXTYPE(RTHCUINTPTR, R3Type, RTHCUINTPTR)
277
278/** @def R0PTRTYPE
279 * Declare a pointer which is used in R0 but appears in structure(s) used by
280 * both HC and GC. The main purpose is to make sure structures have the same
281 * size when built for different architectures.
282 *
283 * @param R0Type The R0 type.
284 */
285#define R0PTRTYPE(R0Type) CTXTYPE(RTHCUINTPTR, RTHCUINTPTR, R0Type)
286
287/** @def CTXSUFF
288 * Adds the suffix of the current context to the passed in
289 * identifier name. The suffix is HC or GC.
290 *
291 * This is macro should only be used in shared code to avoid a forrest of ifdefs.
292 * @param var Identifier name.
293 */
294/** @def OTHERCTXSUFF
295 * Adds the suffix of the other context to the passed in
296 * identifier name. The suffix is HC or GC.
297 *
298 * This is macro should only be used in shared code to avoid a forrest of ifdefs.
299 * @param var Identifier name.
300 */
301#ifdef IN_GC
302# define CTXSUFF(var) var##GC
303# define OTHERCTXSUFF(var) var##HC
304#else
305# define CTXSUFF(var) var##HC
306# define OTHERCTXSUFF(var) var##GC
307#endif
308
309/** @def CTXALLSUFF
310 * Adds the suffix of the current context to the passed in
311 * identifier name. The suffix is R3, R0 or GC.
312 *
313 * This is macro should only be used in shared code to avoid a forrest of ifdefs.
314 * @param var Identifier name.
315 */
316#ifdef IN_GC
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 CTXMID
325 * Adds the current context as a middle name of an identifier name
326 * The middle name is HC or GC.
327 *
328 * This is macro should only be used in shared code to avoid a forrest of ifdefs.
329 * @param first First name.
330 * @param last Surname.
331 */
332/** @def OTHERCTXMID
333 * Adds the other context as a middle name of an identifier name
334 * The middle name is HC or GC.
335 *
336 * This is macro should only be used in shared code to avoid a forrest of ifdefs.
337 * @param first First name.
338 * @param last Surname.
339 */
340#ifdef IN_GC
341# define CTXMID(first, last) first##GC##last
342# define OTHERCTXMID(first, last) first##HC##last
343#else
344# define CTXMID(first, last) first##HC##last
345# define OTHERCTXMID(first, last) first##GC##last
346#endif
347
348/** @def CTXALLMID
349 * Adds the current context as a middle name of an identifier name
350 * The middle name is R3, R0 or GC.
351 *
352 * This is macro should only be used in shared code to avoid a forrest of ifdefs.
353 * @param first First name.
354 * @param last Surname.
355 */
356#ifdef IN_GC
357# define CTXALLMID(first, last) first##GC##last
358#elif defined(IN_RING0)
359# define CTXALLMID(first, last) first##R0##last
360#else
361# define CTXALLMID(first, last) first##R3##last
362#endif
363
364
365/** @def R3STRING
366 * A macro which in GC and R0 will return a dummy string while in R3 it will return
367 * the parameter.
368 *
369 * This is typically used to wrap description strings in structures shared
370 * between R3, R0 and/or GC. The intention is to avoid the \#ifdef IN_RING3 mess.
371 *
372 * @param pR3String The R3 string. Only referenced in R3.
373 * @see R0STRING and GCSTRING
374 */
375#ifdef IN_RING3
376# define R3STRING(pR3String) (pR3String)
377#else
378# define R3STRING(pR3String) ("<R3_STRING>")
379#endif
380
381/** @def R0STRING
382 * A macro which in GC and R3 will return a dummy string while in R0 it will return
383 * the parameter.
384 *
385 * This is typically used to wrap description strings in structures shared
386 * between R3, R0 and/or GC. The intention is to avoid the \#ifdef IN_RING0 mess.
387 *
388 * @param pR0String The R0 string. Only referenced in R0.
389 * @see R3STRING and GCSTRING
390 */
391#ifdef IN_RING0
392# define R0STRING(pR0String) (pR0String)
393#else
394# define R0STRING(pR0String) ("<R0_STRING>")
395#endif
396
397/** @def GCSTRING
398 * A macro which in R3 and R0 will return a dummy string while in GC it will return
399 * the parameter.
400 *
401 * This is typically used to wrap description strings in structures shared
402 * between R3, R0 and/or GC. The intention is to avoid the \#ifdef IN_GC mess.
403 *
404 * @param pR0String The GC string. Only referenced in GC.
405 * @see R3STRING, R0STRING
406 */
407#ifdef IN_GC
408# define GCSTRING(pR0String) (pGCString)
409#else
410# define GCSTRING(pR0String) ("<GC_STRING>")
411#endif
412
413/** @def HCSTRING
414 * Macro which in GC will return a dummy string while in HC will return
415 * the parameter.
416 *
417 * This is typically used to wrap description strings in structures shared
418 * between HC and GC. The intention is to avoid the \#ifdef IN_GC kludge.
419 *
420 * @param pHCString The HC string. Only referenced in HC.
421 * @deprecated Use R3STRING or R0STRING instead.
422 */
423#ifdef IN_GC
424# define HCSTRING(pHCString) ("<HC_STRING>")
425#else
426# define HCSTRING(pHCString) (pHCString)
427#endif
428
429
430/** @def RTCALL
431 * The standard calling convention for the Runtime interfaces.
432 */
433#ifdef _MSC_VER
434# define RTCALL __cdecl
435#elif defined(__GNUC__) && defined(IN_RING0) && !(defined(RT_OS_OS2) || defined(RT_ARCH_AMD64)) /* the latter is kernel/gcc */
436# define RTCALL __attribute__((cdecl,regparm(0)))
437#else
438# define RTCALL
439#endif
440
441/** @def RT_NO_THROW
442 * How to express that a function doesn't throw C++ exceptions
443 * and the compiler can thus save itself the bother of trying
444 * to catch any of them. Put this between the closing parenthesis
445 * and the semicolon in function prototypes (and implementation if C++).
446 */
447#if defined(__cplusplus) \
448 && ( (defined(_MSC_VER) && defined(_CPPUNWIND)) \
449 || (defined(__GNUC__) && defined(__EXCEPTIONS)))
450# define RT_NO_THROW throw()
451#else
452# define RT_NO_THROW
453#endif
454
455/** @def DECLEXPORT
456 * How to declare an exported function.
457 * @param type The return type of the function declaration.
458 */
459#if defined(_MSC_VER) || defined(RT_OS_OS2)
460# define DECLEXPORT(type) __declspec(dllexport) type
461#elif defined(RT_USE_VISIBILITY_DEFAULT)
462# define DECLEXPORT(type) __attribute__((visibility("default"))) type
463#else
464# define DECLEXPORT(type) type
465#endif
466
467/** @def DECLIMPORT
468 * How to declare an imported function.
469 * @param type The return type of the function declaration.
470 */
471#if defined(_MSC_VER) || (defined(RT_OS_OS2) && !defined(__IBMC__) && !defined(__IBMCPP__))
472# define DECLIMPORT(type) __declspec(dllimport) type
473#else
474# define DECLIMPORT(type) type
475#endif
476
477/** @def DECLHIDDEN
478 * How to declare a non-exported function or variable.
479 * @param type The return type of the function or the data type of the variable.
480 */
481#if defined(RT_OS_OS2) || defined(RT_OS_WINDOWS) || !defined(RT_USE_VISIBILITY_HIDDEN)
482# define DECLHIDDEN(type) type
483#else
484# define DECLHIDDEN(type) __attribute__((visibility("hidden"))) type
485#endif
486
487/** @def DECLASM
488 * How to declare an internal assembly function.
489 * @param type The return type of the function declaration.
490 */
491#ifdef __cplusplus
492# ifdef _MSC_VER
493# define DECLASM(type) extern "C" type __cdecl
494# else
495# define DECLASM(type) extern "C" type
496# endif
497#else
498# ifdef _MSC_VER
499# define DECLASM(type) type __cdecl
500# else
501# define DECLASM(type) type
502# endif
503#endif
504
505/** @def DECLASMTYPE
506 * How to declare an internal assembly function type.
507 * @param type The return type of the function.
508 */
509#ifdef _MSC_VER
510# define DECLASMTYPE(type) type __cdecl
511#else
512# define DECLASMTYPE(type) type
513#endif
514
515/** @def DECLNORETURN
516 * How to declare a function which does not return.
517 * @note: This macro can be combined with other macros, for example
518 * @code
519 * EMR3DECL(DECLNORETURN(void)) foo(void);
520 * @endcode
521 */
522#ifdef _MSC_VER
523# define DECLNORETURN(type) __declspec(noreturn) type
524#elif defined(__GNUC__)
525# define DECLNORETURN(type) __attribute__((noreturn)) type
526#else
527# define DECLNORETURN(type) type
528#endif
529
530/** @def DECLCALLBACK
531 * How to declare an call back function type.
532 * @param type The return type of the function declaration.
533 */
534#define DECLCALLBACK(type) type RTCALL
535
536/** @def DECLCALLBACKPTR
537 * How to declare an call back function pointer.
538 * @param type The return type of the function declaration.
539 * @param name The name of the variable member.
540 */
541#define DECLCALLBACKPTR(type, name) type (RTCALL * name)
542
543/** @def DECLCALLBACKMEMBER
544 * How to declare an call back function pointer member.
545 * @param type The return type of the function declaration.
546 * @param name The name of the struct/union/class member.
547 */
548#define DECLCALLBACKMEMBER(type, name) type (RTCALL * name)
549
550/** @def DECLR3CALLBACKMEMBER
551 * How to declare an call back function pointer member - R3 Ptr.
552 * @param type The return type of the function declaration.
553 * @param name The name of the struct/union/class member.
554 * @param args The argument list enclosed in parentheses.
555 */
556#ifdef IN_RING3
557# define DECLR3CALLBACKMEMBER(type, name, args) type (RTCALL * name) args
558#else
559# define DECLR3CALLBACKMEMBER(type, name, args) RTR3PTR name
560#endif
561
562/** @def DECLGCCALLBACKMEMBER
563 * How to declare an call back function pointer member - GC Ptr.
564 * @param type The return type of the function declaration.
565 * @param name The name of the struct/union/class member.
566 * @param args The argument list enclosed in parentheses.
567 */
568#ifdef IN_GC
569# define DECLGCCALLBACKMEMBER(type, name, args) type (RTCALL * name) args
570#else
571# define DECLGCCALLBACKMEMBER(type, name, args) RTRCPTR name
572#endif
573
574/** @def DECLR0CALLBACKMEMBER
575 * How to declare an call back function pointer member - R0 Ptr.
576 * @param type The return type of the function declaration.
577 * @param name The name of the struct/union/class member.
578 * @param args The argument list enclosed in parentheses.
579 */
580#ifdef IN_RING0
581# define DECLR0CALLBACKMEMBER(type, name, args) type (RTCALL * name) args
582#else
583# define DECLR0CALLBACKMEMBER(type, name, args) RTR0PTR name
584#endif
585
586/** @def DECLINLINE
587 * How to declare a function as inline.
588 * @param type The return type of the function declaration.
589 * @remarks Don't use this macro on C++ methods.
590 */
591#ifdef __GNUC__
592# define DECLINLINE(type) static __inline__ type
593#elif defined(__cplusplus)
594# define DECLINLINE(type) inline type
595#elif defined(_MSC_VER)
596# define DECLINLINE(type) _inline type
597#elif defined(__IBMC__)
598# define DECLINLINE(type) _Inline type
599#else
600# define DECLINLINE(type) inline type
601#endif
602
603
604/** @def IN_RT_STATIC
605 * Used to inidicate whether we're linking against a static IPRT
606 * or not. The IPRT symbols will be declared as hidden (if
607 * supported). Note that this define has no effect without setting
608 * IN_RT_R0, IN_RT_R3 or IN_RT_GC indicators are set first.
609 */
610
611/** @def IN_RT_R0
612 * Used to indicate whether we're inside the same link module as
613 * the HC Ring-0 Runtime Library.
614 */
615/** @def RTR0DECL(type)
616 * Runtime Library HC Ring-0 export or import declaration.
617 * @param type The return type of the function declaration.
618 */
619#ifdef IN_RT_R0
620# ifdef IN_RT_STATIC
621# define RTR0DECL(type) DECLHIDDEN(type) RTCALL
622# else
623# define RTR0DECL(type) DECLEXPORT(type) RTCALL
624# endif
625#else
626# define RTR0DECL(type) DECLIMPORT(type) RTCALL
627#endif
628
629/** @def IN_RT_R3
630 * Used to indicate whether we're inside the same link module as
631 * the HC Ring-3 Runtime Library.
632 */
633/** @def RTR3DECL(type)
634 * Runtime Library HC Ring-3 export or import declaration.
635 * @param type The return type of the function declaration.
636 */
637#ifdef IN_RT_R3
638# ifdef IN_RT_STATIC
639# define RTR3DECL(type) DECLHIDDEN(type) RTCALL
640# else
641# define RTR3DECL(type) DECLEXPORT(type) RTCALL
642# endif
643#else
644# define RTR3DECL(type) DECLIMPORT(type) RTCALL
645#endif
646
647/** @def IN_RT_GC
648 * Used to indicate whether we're inside the same link module as
649 * the GC Runtime Library.
650 */
651/** @def RTGCDECL(type)
652 * Runtime Library HC Ring-3 export or import declaration.
653 * @param type The return type of the function declaration.
654 */
655#ifdef IN_RT_GC
656# ifdef IN_RT_STATIC
657# define RTGCDECL(type) DECLHIDDEN(type) RTCALL
658# else
659# define RTGCDECL(type) DECLEXPORT(type) RTCALL
660# endif
661#else
662# define RTGCDECL(type) DECLIMPORT(type) RTCALL
663#endif
664
665/** @def RTDECL(type)
666 * Runtime Library export or import declaration.
667 * Functions declared using this macro exists in all contexts.
668 * @param type The return type of the function declaration.
669 */
670#if defined(IN_RT_R3) || defined(IN_RT_GC) || defined(IN_RT_R0)
671# ifdef IN_RT_STATIC
672# define RTDECL(type) DECLHIDDEN(type) RTCALL
673# else
674# define RTDECL(type) DECLEXPORT(type) RTCALL
675# endif
676#else
677# define RTDECL(type) DECLIMPORT(type) RTCALL
678#endif
679
680/** @def RTDATADECL(type)
681 * Runtime Library export or import declaration.
682 * Data declared using this macro exists in all contexts.
683 * @param type The return type of the function declaration.
684 */
685#if defined(IN_RT_R3) || defined(IN_RT_GC) || defined(IN_RT_R0)
686# ifdef IN_RT_STATIC
687# define RTDATADECL(type) DECLHIDDEN(type)
688# else
689# define RTDATADECL(type) DECLEXPORT(type)
690# endif
691#else
692# define RTDATADECL(type) DECLIMPORT(type)
693#endif
694
695
696/** @def RT_NOCRT
697 * Symbol name wrapper for the No-CRT bits.
698 *
699 * In order to coexist in the same process as other CRTs, we need to
700 * decorate the symbols such that they don't conflict the ones in the
701 * other CRTs. The result of such conflicts / duplicate symbols can
702 * confuse the dynamic loader on unix like systems.
703 *
704 * Define RT_WITHOUT_NOCRT_WRAPPERS to drop the wrapping.
705 * Define RT_WITHOUT_NOCRT_WRAPPER_ALIASES to drop the aliases to the
706 * wrapped names.
707 */
708/** @def RT_NOCRT_STR
709 * Same as RT_NOCRT only it'll return a double quoted string of the result.
710 */
711#ifndef RT_WITHOUT_NOCRT_WRAPPERS
712# define RT_NOCRT(name) nocrt_ ## name
713# define RT_NOCRT_STR(name) "nocrt_" # name
714#else
715# define RT_NOCRT(name) name
716# define RT_NOCRT_STR(name) #name
717#endif
718
719
720
721/** @def RT_LIKELY
722 * Give the compiler a hint that an expression is very likely to hold true.
723 *
724 * Some compilers support explicit branch prediction so that the CPU backend
725 * can hint the processor and also so that code blocks can be reordered such
726 * that the predicted path sees a more linear flow, thus improving cache
727 * behaviour, etc.
728 *
729 * IPRT provides the macros RT_LIKELY() and RT_UNLIKELY() as a way to utilize
730 * this compiler feature when present.
731 *
732 * A few notes about the usage:
733 *
734 * - Generally, use RT_UNLIKELY() with error condition checks (unless you
735 * have some _strong_ reason to do otherwise, in which case document it),
736 * and/or RT_LIKELY() with success condition checks, assuming you want
737 * to optimize for the success path.
738 *
739 * - Other than that, if you don't know the likelihood of a test succeeding
740 * from empirical or other 'hard' evidence, don't make predictions unless
741 * you happen to be a Dirk Gently.
742 *
743 * - These macros are meant to be used in places that get executed a lot. It
744 * is wasteful to make predictions in code that is executed seldomly (e.g.
745 * at subsystem initialization time) as the basic block reording that this
746 * affecs can often generate larger code.
747 *
748 * - Note that RT_SUCCESS() and RT_FAILURE() already makes use of RT_LIKELY()
749 * and RT_UNLIKELY(). Should you wish for prediction free status checks,
750 * use the RT_SUCCESS_NP() and RT_FAILURE_NP() macros instead.
751 *
752 *
753 * @returns the boolean result of the expression.
754 * @param expr The expression that's very likely to be true.
755 * @see RT_UNLIKELY
756 */
757/** @def RT_UNLIKELY
758 * Give the compiler a hint that an expression is highly unlikely hold true.
759 *
760 * See the usage instructions give in the RT_LIKELY() docs.
761 *
762 * @returns the boolean result of the expression.
763 * @param expr The expression that's very unlikely to be true.
764 * @see RT_LIKELY
765 */
766#if defined(__GNUC__)
767# if __GNUC__ >= 3
768# define RT_LIKELY(expr) __builtin_expect(!!(expr), 1)
769# define RT_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
770# else
771# define RT_LIKELY(expr) (expr)
772# define RT_UNLIKELY(expr) (expr)
773# endif
774#else
775# define RT_LIKELY(expr) (expr)
776# define RT_UNLIKELY(expr) (expr)
777#endif
778
779
780/** @def RT_BIT
781 * Make a bitmask for one integer sized bit.
782 * @param bit Bit number.
783 */
784#define RT_BIT(bit) (1U << (bit))
785
786/** @def RT_BIT_32
787 * Make a 32-bit bitmask for one bit.
788 * @param bit Bit number.
789 */
790#define RT_BIT_32(bit) (UINT32_C(1) << (bit))
791
792/** @def RT_BIT_64
793 * Make a 64-bit bitmask for one bit.
794 * @param bit Bit number.
795 */
796#define RT_BIT_64(bit) (UINT64_C(1) << (bit))
797
798/** @def RT_ALIGN
799 * Align macro.
800 * @param u Value to align.
801 * @param uAlignment The alignment. Power of two!
802 *
803 * @remark Be extremely careful when using this macro with type which sizeof != sizeof int.
804 * When possible use any of the other RT_ALIGN_* macros. And when that's not
805 * possible, make 101% sure that uAlignment is specified with a right sized type.
806 *
807 * Specifying an unsigned 32-bit alignment constant with a 64-bit value will give
808 * you a 32-bit return value!
809 *
810 * In short: Don't use this macro. Use RT_ALIGN_T() instead.
811 */
812#define RT_ALIGN(u, uAlignment) ( ((u) + ((uAlignment) - 1)) & ~((uAlignment) - 1) )
813
814/** @def RT_ALIGN_T
815 * Align macro.
816 * @param u Value to align.
817 * @param uAlignment The alignment. Power of two!
818 * @param type Integer type to use while aligning.
819 * @remark This macro is the prefered alignment macro, it doesn't have any of the pitfalls RT_ALIGN has.
820 */
821#define RT_ALIGN_T(u, uAlignment, type) ( ((type)(u) + ((uAlignment) - 1)) & ~(type)((uAlignment) - 1) )
822
823/** @def RT_ALIGN_32
824 * Align macro for a 32-bit value.
825 * @param u32 Value to align.
826 * @param uAlignment The alignment. Power of two!
827 */
828#define RT_ALIGN_32(u32, uAlignment) RT_ALIGN_T(u32, uAlignment, uint32_t)
829
830/** @def RT_ALIGN_64
831 * Align macro for a 64-bit value.
832 * @param u64 Value to align.
833 * @param uAlignment The alignment. Power of two!
834 */
835#define RT_ALIGN_64(u64, uAlignment) RT_ALIGN_T(u64, uAlignment, uint64_t)
836
837/** @def RT_ALIGN_Z
838 * Align macro for size_t.
839 * @param cb Value to align.
840 * @param uAlignment The alignment. Power of two!
841 */
842#define RT_ALIGN_Z(cb, uAlignment) RT_ALIGN_T(cb, uAlignment, size_t)
843
844/** @def RT_ALIGN_P
845 * Align macro for pointers.
846 * @param pv Value to align.
847 * @param uAlignment The alignment. Power of two!
848 */
849#define RT_ALIGN_P(pv, uAlignment) RT_ALIGN_PT(pv, uAlignment, void *)
850
851/** @def RT_ALIGN_PT
852 * Align macro for pointers with type cast.
853 * @param u Value to align.
854 * @param uAlignment The alignment. Power of two!
855 * @param CastType The type to cast the result to.
856 */
857#define RT_ALIGN_PT(u, uAlignment, CastType) ((CastType)RT_ALIGN_T(u, uAlignment, uintptr_t))
858
859/** @def RT_ALIGN_R3PT
860 * Align macro for ring-3 pointers with type cast.
861 * @param u Value to align.
862 * @param uAlignment The alignment. Power of two!
863 * @param CastType The type to cast the result to.
864 */
865#define RT_ALIGN_R3PT(u, uAlignment, CastType) ((CastType)RT_ALIGN_T(u, uAlignment, RTR3UINTPTR))
866
867/** @def RT_ALIGN_R0PT
868 * Align macro for ring-0 pointers with type cast.
869 * @param u Value to align.
870 * @param uAlignment The alignment. Power of two!
871 * @param CastType The type to cast the result to.
872 */
873#define RT_ALIGN_R0PT(u, uAlignment, CastType) ((CastType)RT_ALIGN_T(u, uAlignment, RTR0UINTPTR))
874
875/** @def RT_ALIGN_GCPT
876 * Align macro for GC pointers with type cast.
877 * @param u Value to align.
878 * @param uAlignment The alignment. Power of two!
879 * @param CastType The type to cast the result to.
880 */
881#define RT_ALIGN_GCPT(u, uAlignment, CastType) ((CastType)RT_ALIGN_T(u, uAlignment, RTGCUINTPTR))
882
883
884/** @def RT_OFFSETOF
885 * Our own special offsetof() variant, returns a signed result.
886 *
887 * This differs from the usual offsetof() in that it's not relying on builtin
888 * compiler stuff and thus can use variables in arrays the structure may
889 * contain. If in this usful to determin the sizes of structures ending
890 * with a variable length field.
891 *
892 * @returns offset into the structure of the specified member. signed.
893 * @param type Structure type.
894 * @param member Member.
895 */
896#define RT_OFFSETOF(type, member) ( (int)(uintptr_t)&( ((type *)(void *)0)->member) )
897
898/** @def RT_UOFFSETOF
899 * Our own special offsetof() variant, returns an unsigned result.
900 *
901 * This differs from the usual offsetof() in that it's not relying on builtin
902 * compiler stuff and thus can use variables in arrays the structure may
903 * contain. If in this usful to determin the sizes of structures ending
904 * with a variable length field.
905 *
906 * @returns offset into the structure of the specified member. unsigned.
907 * @param type Structure type.
908 * @param member Member.
909 */
910#define RT_UOFFSETOF(type, member) ( (uintptr_t)&( ((type *)(void *)0)->member) )
911
912/** @def RT_SIZEOFMEMB
913 * Get the size of a structure member.
914 *
915 * @returns size of the structure member.
916 * @param type Structure type.
917 * @param member Member.
918 */
919#define RT_SIZEOFMEMB(type, member) ( sizeof(((type *)(void *)0)->member) )
920
921/** @def RT_ELEMENTS
922 * Calcs the number of elements in an array.
923 * @returns Element count.
924 * @param aArray Array in question.
925 */
926#define RT_ELEMENTS(aArray) ( sizeof(aArray) / sizeof((aArray)[0]) )
927
928#ifdef RT_OS_OS2
929/* Undefine RT_MAX since there is an unfortunate clash with the max
930 resource type define in os2.h. */
931# undef RT_MAX
932#endif
933
934/** @def RT_MAX
935 * Finds the maximum value.
936 * @returns The higher of the two.
937 * @param Value1 Value 1
938 * @param Value2 Value 2
939 */
940#define RT_MAX(Value1, Value2) ((Value1) >= (Value2) ? (Value1) : (Value2))
941
942/** @def RT_MIN
943 * Finds the minimum value.
944 * @returns The lower of the two.
945 * @param Value1 Value 1
946 * @param Value2 Value 2
947 */
948#define RT_MIN(Value1, Value2) ((Value1) <= (Value2) ? (Value1) : (Value2))
949
950/** @def RT_ABS
951 * Get the absolute (non-negative) value.
952 * @returns The absolute value of Value.
953 * @param Value The value.
954 */
955#define RT_ABS(Value) ((Value) >= 0 ? (Value) : -(Value))
956
957/** @def RT_LOWORD
958 * Gets the low word (=uint16_t) of something. */
959#define RT_LOWORD(a) ((a) & 0xffff)
960
961/** @def RT_HIWORD
962 * Gets the high word (=uint16_t) of a 32 bit something. */
963#define RT_HIWORD(a) ((a) >> 16)
964
965/** @def RT_LOBYTE
966 * Gets the low byte of something. */
967#define RT_LOBYTE(a) ((a) & 0xff)
968
969/** @def RT_HIBYTE
970 * Gets the low byte of a 16 bit something. */
971#define RT_HIBYTE(a) ((a) >> 8)
972
973/** @def RT_BYTE1
974 * Gets first byte of something. */
975#define RT_BYTE1(a) ((a) & 0xff)
976
977/** @def RT_BYTE2
978 * Gets second byte of something. */
979#define RT_BYTE2(a) (((a) >> 8) & 0xff)
980
981/** @def RT_BYTE3
982 * Gets second byte of something. */
983#define RT_BYTE3(a) (((a) >> 16) & 0xff)
984
985/** @def RT_BYTE4
986 * Gets fourth byte of something. */
987#define RT_BYTE4(a) (((a) >> 24) & 0xff)
988
989
990/** @def RT_MAKE_U64
991 * Constructs a uint64_t value from two uint32_t values.
992 */
993#define RT_MAKE_U64(Lo, Hi) ( (uint64_t)((uint32_t)(Hi)) << 32 | (uint32_t)(Lo) )
994
995/** @def RT_MAKE_U64_FROM_U16
996 * Constructs a uint64_t value from four uint16_t values.
997 */
998#define RT_MAKE_U64_FROM_U16(w0, w1, w2, w3) \
999 ( (uint64_t)((uint16_t)(w3)) << 48 \
1000 | (uint64_t)((uint16_t)(w2)) << 32 \
1001 | (uint32_t)((uint16_t)(w1)) << 16 \
1002 | (uint16_t)(w0) )
1003
1004/** @def RT_MAKE_U64_FROM_U8
1005 * Constructs a uint64_t value from eight uint8_t values.
1006 */
1007#define RT_MAKE_U64_FROM_U8(b0, b1, b2, b3, b4, b5, b6, b7) \
1008 ( (uint64_t)((uint8_t)(b7)) << 56 \
1009 | (uint64_t)((uint8_t)(b6)) << 48 \
1010 | (uint64_t)((uint8_t)(b5)) << 40 \
1011 | (uint64_t)((uint8_t)(b4)) << 32 \
1012 | (uint32_t)((uint8_t)(b3)) << 24 \
1013 | (uint32_t)((uint8_t)(b2)) << 16 \
1014 | (uint16_t)((uint8_t)(b1)) << 8 \
1015 | (uint8_t)(b0) )
1016
1017/** @def RT_MAKE_U32
1018 * Constructs a uint32_t value from two uint16_t values.
1019 */
1020#define RT_MAKE_U32(Lo, Hi) ( (uint32_t)((uint16_t)(Hi)) << 16 | (uint16_t)(Lo) )
1021
1022/** @def RT_MAKE_U32_FROM_U8
1023 * Constructs a uint32_t value from four uint8_t values.
1024 */
1025#define RT_MAKE_U32_FROM_U8(b0, b1, b2, b3) \
1026 ( (uint32_t)((uint8_t)(b3)) << 24 \
1027 | (uint32_t)((uint8_t)(b2)) << 16 \
1028 | (uint16_t)((uint8_t)(b1)) << 8 \
1029 | (uint8_t)(b0) )
1030
1031/** @def RT_MAKE_U16
1032 * Constructs a uint32_t value from two uint16_t values.
1033 */
1034#define RT_MAKE_U16(Lo, Hi) ( (uint16_t)((uint8_t)(Hi)) << 8 | (uint8_t)(Lo) )
1035
1036
1037/** @def RT_BSWAP_U64
1038 * Reverses the byte order of an uint64_t value. */
1039#if 0
1040# define RT_BSWAP_U64(u64) RT_MAKE_U64(RT_H2BE_U32((u64) >> 32), RT_H2BE_U32((u64) & 0xffffffff))
1041#else
1042# define RT_BSWAP_U64(u64) ASMByteSwapU64(u64)
1043#endif
1044
1045/** @def RT_BSWAP_U32
1046 * Converts uint32_t value from host to big endian byte order. */
1047#if 0
1048# define RT_BSWAP_U32(u32) (RT_BYTE4(u32) | (RT_BYTE3(u32) << 8) | (RT_BYTE2(u32) << 16) | (RT_BYTE1(u32) << 24))
1049#else
1050# define RT_BSWAP_U32(u32) ASMByteSwapU32(u32)
1051#endif
1052
1053/** @def RT_BSWAP_U16
1054 * Converts uint16_t value from host to big endian byte order. */
1055#if 0
1056# define RT_BSWAP_U16(u16) (RT_HIBYTE(u16) | (RT_LOBYTE(u16) << 8))
1057#else
1058# define RT_BSWAP_U16(u16) ASMByteSwapU16(u16)
1059#endif
1060
1061
1062/** @def RT_H2LE_U64
1063 * Converts an uint64_t value from host to little endian byte order. */
1064#ifdef RT_BIG_ENDIAN
1065# define RT_H2LE_U64(u64) RT_BSWAP_U64(u64)
1066#else
1067# define RT_H2LE_U64(u64) (u64)
1068#endif
1069
1070/** @def RT_H2LE_U32
1071 * Converts an uint32_t value from host to little endian byte order. */
1072#ifdef RT_BIG_ENDIAN
1073# define RT_H2LE_U32(u32) RT_BSWAP_U32(u32)
1074#else
1075# define RT_H2LE_U32(u32) (u32)
1076#endif
1077
1078/** @def RT_H2LE_U16
1079 * Converts an uint16_t value from host to little endian byte order. */
1080#ifdef RT_BIG_ENDIAN
1081# define RT_H2LE_U16(u16) RT_BSWAP_U16(u16)
1082#else
1083# define RT_H2LE_U16(u16) (u16)
1084#endif
1085
1086/** @def RT_LE2H_U64
1087 * Converts an uint64_t value from little endian to host byte order. */
1088#ifdef RT_BIG_ENDIAN
1089# define RT_LE2H_U64(u64) RT_BSWAP_U64(u64)
1090#else
1091# define RT_LE2H_U64(u64) (u64)
1092#endif
1093
1094/** @def RT_LE2H_U32
1095 * Converts an uint32_t value from little endian to host byte order. */
1096#ifdef RT_BIG_ENDIAN
1097# define RT_LE2H_U32(u32) RT_BSWAP_U32(u32)
1098#else
1099# define RT_LE2H_U32(u32) (u32)
1100#endif
1101
1102/** @def RT_LE2H_U16
1103 * Converts an uint16_t value from little endian to host byte order. */
1104#ifdef RT_BIG_ENDIAN
1105# define RT_LE2H_U16(u16) RT_BSWAP_U16(u16)
1106#else
1107# define RT_LE2H_U16(u16) (u16)
1108#endif
1109
1110
1111/** @def RT_H2BE_U64
1112 * Converts an uint64_t value from host to big endian byte order. */
1113#ifdef RT_BIG_ENDIAN
1114# define RT_H2BE_U64(u64) (u64)
1115#else
1116# define RT_H2BE_U64(u64) RT_BSWAP_U64(u64)
1117#endif
1118
1119/** @def RT_H2BE_U32
1120 * Converts an uint32_t value from host to big endian byte order. */
1121#ifdef RT_BIG_ENDIAN
1122# define RT_H2BE_U32(u32) (u32)
1123#else
1124# define RT_H2BE_U32(u32) RT_BSWAP_U32(u32)
1125#endif
1126
1127/** @def RT_H2BE_U16
1128 * Converts an uint16_t value from host to big endian byte order. */
1129#ifdef RT_BIG_ENDIAN
1130# define RT_H2BE_U16(u16) (u16)
1131#else
1132# define RT_H2BE_U16(u16) RT_BSWAP_U16(u16)
1133#endif
1134
1135/** @def RT_BE2H_U64
1136 * Converts an uint64_t value from big endian to host byte order. */
1137#ifdef RT_BIG_ENDIAN
1138# define RT_BE2H_U64(u64) (u64)
1139#else
1140# define RT_BE2H_U64(u64) RT_BSWAP_U64(u64)
1141#endif
1142
1143/** @def RT_BE2H_U32
1144 * Converts an uint32_t value from big endian to host byte order. */
1145#ifdef RT_BIG_ENDIAN
1146# define RT_BE2H_U32(u32) (u32)
1147#else
1148# define RT_BE2H_U32(u32) RT_BSWAP_U32(u32)
1149#endif
1150
1151/** @def RT_BE2H_U16
1152 * Converts an uint16_t value from big endian to host byte order. */
1153#ifdef RT_BIG_ENDIAN
1154# define RT_BE2H_U16(u16) (u16)
1155#else
1156# define RT_BE2H_U16(u16) RT_BSWAP_U16(u16)
1157#endif
1158
1159
1160/** @def RT_H2N_U64
1161 * Converts an uint64_t value from host to network byte order. */
1162#define RT_H2N_U64(u64) RT_H2BE_U64(u64)
1163
1164/** @def RT_H2N_U32
1165 * Converts an uint32_t value from host to network byte order. */
1166#define RT_H2N_U32(u32) RT_H2BE_U32(u32)
1167
1168/** @def RT_H2N_U16
1169 * Converts an uint16_t value from host to network byte order. */
1170#define RT_H2N_U16(u16) RT_H2BE_U16(u16)
1171
1172/** @def RT_N2H_U64
1173 * Converts an uint64_t value from network to host byte order. */
1174#define RT_N2H_U64(u64) RT_BE2H_U64(u64)
1175
1176/** @def RT_N2H_U32
1177 * Converts an uint32_t value from network to host byte order. */
1178#define RT_N2H_U32(u32) RT_BE2H_U32(u32)
1179
1180/** @def RT_N2H_U16
1181 * Converts an uint16_t value from network to host byte order. */
1182#define RT_N2H_U16(u16) RT_BE2H_U16(u16)
1183
1184
1185/** @def RT_NO_DEPRECATED_MACROS
1186 * Define RT_NO_DEPRECATED_MACROS to not define deprecated macros.
1187 */
1188#ifndef RT_NO_DEPRECATED_MACROS
1189/** @copydoc RT_ELEMENTS
1190 * @deprecated use RT_ELEMENTS. */
1191# define ELEMENTS(aArray) RT_ELEMENTS(aArray)
1192#endif
1193
1194
1195/*
1196 * The BSD sys/param.h + machine/param.h file is a major source of
1197 * namespace pollution. Kill off some of the worse ones unless we're
1198 * compiling kernel code.
1199 */
1200#if defined(RT_OS_DARWIN) \
1201 && !defined(KERNEL) \
1202 && !defined(RT_NO_BSD_PARAM_H_UNDEFING) \
1203 && ( defined(_SYS_PARAM_H_) || defined(_I386_PARAM_H_) )
1204/* sys/param.h: */
1205# undef PSWP
1206# undef PVM
1207# undef PINOD
1208# undef PRIBO
1209# undef PVFS
1210# undef PZERO
1211# undef PSOCK
1212# undef PWAIT
1213# undef PLOCK
1214# undef PPAUSE
1215# undef PUSER
1216# undef PRIMASK
1217# undef MINBUCKET
1218# undef MAXALLOCSAVE
1219# undef FSHIFT
1220# undef FSCALE
1221
1222/* i386/machine.h: */
1223# undef ALIGN
1224# undef ALIGNBYTES
1225# undef DELAY
1226# undef STATUS_WORD
1227# undef USERMODE
1228# undef BASEPRI
1229# undef MSIZE
1230# undef CLSIZE
1231# undef CLSIZELOG2
1232#endif
1233
1234
1235/** @def NULL
1236 * NULL pointer.
1237 */
1238#ifndef NULL
1239# ifdef __cplusplus
1240# define NULL 0
1241# else
1242# define NULL ((void*)0)
1243# endif
1244#endif
1245
1246/** @def NIL_OFFSET
1247 * NIL offset.
1248 * Whenever we use offsets instead of pointers to save space and relocation effort
1249 * NIL_OFFSET shall be used as the equivalent to NULL.
1250 */
1251#define NIL_OFFSET (~0U)
1252
1253/** @def NOREF
1254 * Keeps the compiler from bitching about an unused parameters.
1255 */
1256#define NOREF(var) (void)(var)
1257
1258/** @def Breakpoint
1259 * Emit a debug breakpoint instruction.
1260 *
1261 * Use this for instrumenting a debugging session only!
1262 * No comitted code shall use Breakpoint().
1263 */
1264#ifdef __GNUC__
1265# define Breakpoint() __asm__ __volatile__("int $3\n\t")
1266#endif
1267#ifdef _MSC_VER
1268# define Breakpoint() __asm int 3
1269#endif
1270#if defined(__IBMC__) || defined(__IBMCPP__)
1271# define Breakpoint() __interrupt(3)
1272#endif
1273#ifndef Breakpoint
1274# error "This compiler is not supported!"
1275#endif
1276
1277
1278/** Size Constants
1279 * (Of course, these are binary computer terms, not SI.)
1280 * @{
1281 */
1282/** 1 K (Kilo) (1 024). */
1283#define _1K 0x00000400
1284/** 4 K (Kilo) (4 096). */
1285#define _4K 0x00001000
1286/** 32 K (Kilo) (32 678). */
1287#define _32K 0x00008000
1288/** 64 K (Kilo) (65 536). */
1289#define _64K 0x00010000
1290/** 128 K (Kilo) (131 072). */
1291#define _128K 0x00020000
1292/** 256 K (Kilo) (262 144). */
1293#define _256K 0x00040000
1294/** 512 K (Kilo) (524 288). */
1295#define _512K 0x00080000
1296/** 1 M (Mega) (1 048 576). */
1297#define _1M 0x00100000
1298/** 2 M (Mega) (2 097 152). */
1299#define _2M 0x00200000
1300/** 4 M (Mega) (4 194 304). */
1301#define _4M 0x00400000
1302/** 1 G (Giga) (1 073 741 824). */
1303#define _1G 0x40000000
1304/** 2 G (Giga) (2 147 483 648). (32-bit) */
1305#define _2G32 0x80000000U
1306/** 2 G (Giga) (2 147 483 648). (64-bit) */
1307#define _2G 0x0000000080000000LL
1308/** 4 G (Giga) (4 294 967 296). */
1309#define _4G 0x0000000100000000LL
1310/** 1 T (Tera) (1 099 511 627 776). */
1311#define _1T 0x0000010000000000LL
1312/** 1 P (Peta) (1 125 899 906 842 624). */
1313#define _1P 0x0004000000000000LL
1314/** 1 E (Exa) (1 152 921 504 606 846 976). */
1315#define _1E 0x1000000000000000LL
1316/** 2 E (Exa) (2 305 843 009 213 693 952). */
1317#define _2E 0x2000000000000000ULL
1318/** @} */
1319
1320/** @def VALID_PTR
1321 * Pointer validation macro.
1322 * @param ptr
1323 */
1324#if defined(RT_ARCH_AMD64)
1325# ifdef IN_RING3
1326# if defined(RT_OS_DARWIN) /* first 4GB is reserved for legacy kernel. */
1327# define VALID_PTR(ptr) ( (uintptr_t)(ptr) >= _4G \
1328 && !((uintptr_t)(ptr) & 0xffff800000000000ULL) )
1329# elif defined(RT_OS_SOLARIS) /* The kernel only used the top 2TB, but keep it simple. */
1330# define VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
1331 && ( ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0xffff800000000000ULL \
1332 || ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0) )
1333# else
1334# define VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
1335 && !((uintptr_t)(ptr) & 0xffff800000000000ULL) )
1336# endif
1337# else /* !IN_RING3 */
1338# define VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
1339 && ( ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0xffff800000000000ULL \
1340 || ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0) )
1341# endif /* !IN_RING3 */
1342#elif defined(RT_ARCH_X86)
1343# define VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U )
1344#else
1345# error "Architecture identifier missing / not implemented."
1346#endif
1347
1348
1349/** @def VALID_PHYS32
1350 * 32 bits physical address validation macro.
1351 * @param Phys The RTGCPHYS address.
1352 */
1353#define VALID_PHYS32(Phys) ( (uint64_t)(Phys) < (uint64_t)_4G )
1354
1355/** @def N_
1356 * The \#define N_ is used mark a string for translation. This is usable in
1357 * any part of the code, as it is only used by the tools that create message
1358 * catalogs. This macro is a no-op as far as the compiler and code generation
1359 * is concerned.
1360 *
1361 * If you want to both mark a string for translation and translate it, use _.
1362 */
1363#define N_(s) (s)
1364
1365/** @def _
1366 * The \#define _ is used mark a string for translation and to translate it in
1367 * one step.
1368 *
1369 * If you want to only mark a string for translation, use N_.
1370 */
1371#define _(s) gettext(s)
1372
1373
1374/** @def __PRETTY_FUNCTION__
1375 * With GNU C we'd like to use the builtin __PRETTY_FUNCTION__, so define that for the other compilers.
1376 */
1377#if !defined(__GNUC__) && !defined(__PRETTY_FUNCTION__)
1378# define __PRETTY_FUNCTION__ __FUNCTION__
1379#endif
1380
1381
1382/** @def RT_STRICT
1383 * The \#define RT_STRICT controls whether or not assertions and other runtime checks
1384 * should be compiled in or not.
1385 *
1386 * If you want assertions which are not a subject to compile time options use
1387 * the AssertRelease*() flavors.
1388 */
1389#if !defined(RT_STRICT) && defined(DEBUG)
1390# define RT_STRICT
1391#endif
1392
1393/** Source position. */
1394#define RT_SRC_POS __FILE__, __LINE__, __PRETTY_FUNCTION__
1395
1396/** Source position declaration. */
1397#define RT_SRC_POS_DECL const char *pszFile, unsigned iLine, const char *pszFunction
1398
1399/** Source position arguments. */
1400#define RT_SRC_POS_ARGS pszFile, iLine, pszFunction
1401
1402/** @} */
1403
1404
1405/** @defgroup grp_rt_cdefs_cpp Special Macros for C++
1406 * @ingroup grp_rt_cdefs
1407 * @{
1408 */
1409
1410#ifdef __cplusplus
1411
1412/** @def DECLEXPORT_CLASS
1413 * How to declare an exported class. Place this macro after the 'class'
1414 * keyword in the declaration of every class you want to export.
1415 *
1416 * @note It is necessary to use this macro even for inner classes declared
1417 * inside the already exported classes. This is a GCC specific requirement,
1418 * but it seems not to harm other compilers.
1419 */
1420#if defined(_MSC_VER) || defined(RT_OS_OS2)
1421# define DECLEXPORT_CLASS __declspec(dllexport)
1422#elif defined(RT_USE_VISIBILITY_DEFAULT)
1423# define DECLEXPORT_CLASS __attribute__((visibility("default")))
1424#else
1425# define DECLEXPORT_CLASS
1426#endif
1427
1428/** @def DECLIMPORT_CLASS
1429 * How to declare an imported class Place this macro after the 'class'
1430 * keyword in the declaration of every class you want to export.
1431 *
1432 * @note It is necessary to use this macro even for inner classes declared
1433 * inside the already exported classes. This is a GCC specific requirement,
1434 * but it seems not to harm other compilers.
1435 */
1436#if defined(_MSC_VER) || (defined(RT_OS_OS2) && !defined(__IBMC__) && !defined(__IBMCPP__))
1437# define DECLIMPORT_CLASS __declspec(dllimport)
1438#elif defined(RT_USE_VISIBILITY_DEFAULT)
1439# define DECLIMPORT_CLASS __attribute__((visibility("default")))
1440#else
1441# define DECLIMPORT_CLASS
1442#endif
1443
1444/** @def WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP
1445 * Macro to work around error C2593 of the not-so-smart MSVC 7.x ambiguity
1446 * resolver. The following snippet clearly demonstrates the code causing this
1447 * error:
1448 * @code
1449 * class A
1450 * {
1451 * public:
1452 * operator bool() const { return false; }
1453 * operator int*() const { return NULL; }
1454 * };
1455 * int main()
1456 * {
1457 * A a;
1458 * if (!a);
1459 * if (a && 0);
1460 * return 0;
1461 * }
1462 * @endcode
1463 * The code itself seems pretty valid to me and GCC thinks the same.
1464 *
1465 * This macro fixes the compiler error by explicitly overloading implicit
1466 * global operators !, && and || that take the given class instance as one of
1467 * their arguments.
1468 *
1469 * The best is to use this macro right after the class declaration.
1470 *
1471 * @note The macro expands to nothing for compilers other than MSVC.
1472 *
1473 * @param Cls Class to apply the workaround to
1474 */
1475#if defined(_MSC_VER)
1476# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP(Cls) \
1477 inline bool operator! (const Cls &that) { return !bool (that); } \
1478 inline bool operator&& (const Cls &that, bool b) { return bool (that) && b; } \
1479 inline bool operator|| (const Cls &that, bool b) { return bool (that) || b; } \
1480 inline bool operator&& (bool b, const Cls &that) { return b && bool (that); } \
1481 inline bool operator|| (bool b, const Cls &that) { return b || bool (that); }
1482#else
1483# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP(Cls)
1484#endif
1485
1486/** @def WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL
1487 * Version of WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP for template classes.
1488 *
1489 * @param Tpl Name of the template class to apply the workaround to
1490 * @param ArgsDecl arguments of the template, as declared in |<>| after the
1491 * |template| keyword, including |<>|
1492 * @param Args arguments of the template, as specified in |<>| after the
1493 * template class name when using the, including |<>|
1494 *
1495 * Example:
1496 * @code
1497 * // template class declaration
1498 * template <class C>
1499 * class Foo { ... };
1500 * // applied workaround
1501 * WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL (Foo, <class C>, <C>)
1502 * @endcode
1503 */
1504#if defined(_MSC_VER)
1505# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL(Tpl, ArgsDecl, Args) \
1506 template ArgsDecl \
1507 inline bool operator! (const Tpl Args &that) { return !bool (that); } \
1508 template ArgsDecl \
1509 inline bool operator&& (const Tpl Args &that, bool b) { return bool (that) && b; } \
1510 template ArgsDecl \
1511 inline bool operator|| (const Tpl Args &that, bool b) { return bool (that) || b; } \
1512 template ArgsDecl \
1513 inline bool operator&& (bool b, const Tpl Args &that) { return b && bool (that); } \
1514 template ArgsDecl \
1515 inline bool operator|| (bool b, const Tpl Args &that) { return b || bool (that); }
1516#else
1517# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL(Tpl, ArgsDecl, Args)
1518#endif
1519
1520
1521/** @def DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP
1522 * Declares the copy constructor and the assignment operation as inlined no-ops
1523 * (non-existent functions) for the given class. Use this macro inside the
1524 * private section if you want to effectively disable these operations for your
1525 * class.
1526 *
1527 * @param Cls class name to declare for
1528 */
1529
1530#define DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(Cls) \
1531 inline Cls (const Cls &); \
1532 inline Cls &operator= (const Cls &);
1533
1534
1535/** @def DECLARE_CLS_NEW_DELETE_NOOP
1536 * Declares the new and delete operations as no-ops (non-existent functions)
1537 * for the given class. Use this macro inside the private section if you want
1538 * to effectively limit creating class instances on the stack only.
1539 *
1540 * @note The destructor of the given class must not be virtual, otherwise a
1541 * compile time error will occur. Note that this is not a drawback: having
1542 * the virtual destructor for a stack-based class is absolutely useless
1543 * (the real class of the stack-based instance is always known to the compiler
1544 * at compile time, so it will always call the correct destructor).
1545 *
1546 * @param Cls class name to declare for
1547 */
1548#define DECLARE_CLS_NEW_DELETE_NOOP(Cls) \
1549 inline static void *operator new (size_t); \
1550 inline static void operator delete (void *);
1551
1552#endif /* defined(__cplusplus) */
1553
1554/** @} */
1555
1556#endif
1557
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