VirtualBox

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

Last change on this file since 11007 was 10998, checked in by vboxsync, 16 years ago

iprt: Use the byte swapper routines from iprt/asm.h.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 47.7 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 DECLEXPORT
442 * How to declare an exported function.
443 * @param type The return type of the function declaration.
444 */
445#if defined(_MSC_VER) || defined(RT_OS_OS2)
446# define DECLEXPORT(type) __declspec(dllexport) type
447#elif defined(RT_USE_VISIBILITY_DEFAULT)
448# define DECLEXPORT(type) __attribute__((visibility("default"))) type
449#else
450# define DECLEXPORT(type) type
451#endif
452
453/** @def DECLIMPORT
454 * How to declare an imported function.
455 * @param type The return type of the function declaration.
456 */
457#if defined(_MSC_VER) || (defined(RT_OS_OS2) && !defined(__IBMC__) && !defined(__IBMCPP__))
458# define DECLIMPORT(type) __declspec(dllimport) type
459#else
460# define DECLIMPORT(type) type
461#endif
462
463/** @def DECLHIDDEN
464 * How to declare a non-exported function or variable.
465 * @param type The return type of the function or the data type of the variable.
466 */
467#if defined(RT_OS_OS2) || defined(RT_OS_WINDOWS) || !defined(RT_USE_VISIBILITY_HIDDEN)
468# define DECLHIDDEN(type) type
469#else
470# define DECLHIDDEN(type) __attribute__((visibility("hidden"))) type
471#endif
472
473/** @def DECLASM
474 * How to declare an internal assembly function.
475 * @param type The return type of the function declaration.
476 */
477#ifdef __cplusplus
478# ifdef _MSC_VER
479# define DECLASM(type) extern "C" type __cdecl
480# else
481# define DECLASM(type) extern "C" type
482# endif
483#else
484# ifdef _MSC_VER
485# define DECLASM(type) type __cdecl
486# else
487# define DECLASM(type) type
488# endif
489#endif
490
491/** @def DECLASMTYPE
492 * How to declare an internal assembly function type.
493 * @param type The return type of the function.
494 */
495#ifdef _MSC_VER
496# define DECLASMTYPE(type) type __cdecl
497#else
498# define DECLASMTYPE(type) type
499#endif
500
501/** @def DECLNORETURN
502 * How to declare a function which does not return.
503 * @note: This macro can be combined with other macros, for example
504 * @code
505 * EMR3DECL(DECLNORETURN(void)) foo(void);
506 * @endcode
507 */
508#ifdef _MSC_VER
509# define DECLNORETURN(type) __declspec(noreturn) type
510#elif defined(__GNUC__)
511# define DECLNORETURN(type) __attribute__((noreturn)) type
512#else
513# define DECLNORETURN(type) type
514#endif
515
516/** @def DECLCALLBACK
517 * How to declare an call back function type.
518 * @param type The return type of the function declaration.
519 */
520#define DECLCALLBACK(type) type RTCALL
521
522/** @def DECLCALLBACKPTR
523 * How to declare an call back function pointer.
524 * @param type The return type of the function declaration.
525 * @param name The name of the variable member.
526 */
527#define DECLCALLBACKPTR(type, name) type (RTCALL * name)
528
529/** @def DECLCALLBACKMEMBER
530 * How to declare an call back function pointer member.
531 * @param type The return type of the function declaration.
532 * @param name The name of the struct/union/class member.
533 */
534#define DECLCALLBACKMEMBER(type, name) type (RTCALL * name)
535
536/** @def DECLR3CALLBACKMEMBER
537 * How to declare an call back function pointer member - R3 Ptr.
538 * @param type The return type of the function declaration.
539 * @param name The name of the struct/union/class member.
540 * @param args The argument list enclosed in parentheses.
541 */
542#ifdef IN_RING3
543# define DECLR3CALLBACKMEMBER(type, name, args) type (RTCALL * name) args
544#else
545# define DECLR3CALLBACKMEMBER(type, name, args) RTR3PTR name
546#endif
547
548/** @def DECLGCCALLBACKMEMBER
549 * How to declare an call back function pointer member - GC Ptr.
550 * @param type The return type of the function declaration.
551 * @param name The name of the struct/union/class member.
552 * @param args The argument list enclosed in parentheses.
553 */
554#ifdef IN_GC
555# define DECLGCCALLBACKMEMBER(type, name, args) type (RTCALL * name) args
556#else
557# define DECLGCCALLBACKMEMBER(type, name, args) RTRCPTR name
558#endif
559
560/** @def DECLR0CALLBACKMEMBER
561 * How to declare an call back function pointer member - R0 Ptr.
562 * @param type The return type of the function declaration.
563 * @param name The name of the struct/union/class member.
564 * @param args The argument list enclosed in parentheses.
565 */
566#ifdef IN_RING0
567# define DECLR0CALLBACKMEMBER(type, name, args) type (RTCALL * name) args
568#else
569# define DECLR0CALLBACKMEMBER(type, name, args) RTR0PTR name
570#endif
571
572/** @def DECLINLINE
573 * How to declare a function as inline.
574 * @param type The return type of the function declaration.
575 * @remarks Don't use this macro on C++ methods.
576 */
577#ifdef __GNUC__
578# define DECLINLINE(type) static __inline__ type
579#elif defined(__cplusplus)
580# define DECLINLINE(type) inline type
581#elif defined(_MSC_VER)
582# define DECLINLINE(type) _inline type
583#elif defined(__IBMC__)
584# define DECLINLINE(type) _Inline type
585#else
586# define DECLINLINE(type) inline type
587#endif
588
589
590/** @def IN_RT_STATIC
591 * Used to inidicate whether we're linking against a static IPRT
592 * or not. The IPRT symbols will be declared as hidden (if
593 * supported). Note that this define has no effect without setting
594 * IN_RT_R0, IN_RT_R3 or IN_RT_GC indicators are set first.
595 */
596
597/** @def IN_RT_R0
598 * Used to indicate whether we're inside the same link module as
599 * the HC Ring-0 Runtime Library.
600 */
601/** @def RTR0DECL(type)
602 * Runtime Library HC Ring-0 export or import declaration.
603 * @param type The return type of the function declaration.
604 */
605#ifdef IN_RT_R0
606# ifdef IN_RT_STATIC
607# define RTR0DECL(type) DECLHIDDEN(type) RTCALL
608# else
609# define RTR0DECL(type) DECLEXPORT(type) RTCALL
610# endif
611#else
612# define RTR0DECL(type) DECLIMPORT(type) RTCALL
613#endif
614
615/** @def IN_RT_R3
616 * Used to indicate whether we're inside the same link module as
617 * the HC Ring-3 Runtime Library.
618 */
619/** @def RTR3DECL(type)
620 * Runtime Library HC Ring-3 export or import declaration.
621 * @param type The return type of the function declaration.
622 */
623#ifdef IN_RT_R3
624# ifdef IN_RT_STATIC
625# define RTR3DECL(type) DECLHIDDEN(type) RTCALL
626# else
627# define RTR3DECL(type) DECLEXPORT(type) RTCALL
628# endif
629#else
630# define RTR3DECL(type) DECLIMPORT(type) RTCALL
631#endif
632
633/** @def IN_RT_GC
634 * Used to indicate whether we're inside the same link module as
635 * the GC Runtime Library.
636 */
637/** @def RTGCDECL(type)
638 * Runtime Library HC Ring-3 export or import declaration.
639 * @param type The return type of the function declaration.
640 */
641#ifdef IN_RT_GC
642# ifdef IN_RT_STATIC
643# define RTGCDECL(type) DECLHIDDEN(type) RTCALL
644# else
645# define RTGCDECL(type) DECLEXPORT(type) RTCALL
646# endif
647#else
648# define RTGCDECL(type) DECLIMPORT(type) RTCALL
649#endif
650
651/** @def RTDECL(type)
652 * Runtime Library export or import declaration.
653 * Functions declared using this macro exists in all contexts.
654 * @param type The return type of the function declaration.
655 */
656#if defined(IN_RT_R3) || defined(IN_RT_GC) || defined(IN_RT_R0)
657# ifdef IN_RT_STATIC
658# define RTDECL(type) DECLHIDDEN(type) RTCALL
659# else
660# define RTDECL(type) DECLEXPORT(type) RTCALL
661# endif
662#else
663# define RTDECL(type) DECLIMPORT(type) RTCALL
664#endif
665
666/** @def RTDATADECL(type)
667 * Runtime Library export or import declaration.
668 * Data declared using this macro exists in all contexts.
669 * @param type The return type of the function declaration.
670 */
671#if defined(IN_RT_R3) || defined(IN_RT_GC) || defined(IN_RT_R0)
672# ifdef IN_RT_STATIC
673# define RTDATADECL(type) DECLHIDDEN(type)
674# else
675# define RTDATADECL(type) DECLEXPORT(type)
676# endif
677#else
678# define RTDATADECL(type) DECLIMPORT(type)
679#endif
680
681
682/** @def RT_NOCRT
683 * Symbol name wrapper for the No-CRT bits.
684 *
685 * In order to coexist in the same process as other CRTs, we need to
686 * decorate the symbols such that they don't conflict the ones in the
687 * other CRTs. The result of such conflicts / duplicate symbols can
688 * confuse the dynamic loader on unix like systems.
689 *
690 * Define RT_WITHOUT_NOCRT_WRAPPERS to drop the wrapping.
691 * Define RT_WITHOUT_NOCRT_WRAPPER_ALIASES to drop the aliases to the
692 * wrapped names.
693 */
694/** @def RT_NOCRT_STR
695 * Same as RT_NOCRT only it'll return a double quoted string of the result.
696 */
697#ifndef RT_WITHOUT_NOCRT_WRAPPERS
698# define RT_NOCRT(name) nocrt_ ## name
699# define RT_NOCRT_STR(name) "nocrt_" # name
700#else
701# define RT_NOCRT(name) name
702# define RT_NOCRT_STR(name) #name
703#endif
704
705
706
707/** @def RT_LIKELY
708 * Give the compiler a hint that an expression is very likely to hold true.
709 *
710 * Some compilers support explicit branch prediction so that the CPU backend
711 * can hint the processor and also so that code blocks can be reordered such
712 * that the predicted path sees a more linear flow, thus improving cache
713 * behaviour, etc.
714 *
715 * IPRT provides the macros RT_LIKELY() and RT_UNLIKELY() as a way to utilize
716 * this compiler feature when present.
717 *
718 * A few notes about the usage:
719 *
720 * - Generally, use RT_UNLIKELY() with error condition checks (unless you
721 * have some _strong_ reason to do otherwise, in which case document it),
722 * and/or RT_LIKELY() with success condition checks, assuming you want
723 * to optimize for the success path.
724 *
725 * - Other than that, if you don't know the likelihood of a test succeeding
726 * from empirical or other 'hard' evidence, don't make predictions unless
727 * you happen to be a Dirk Gently.
728 *
729 * - These macros are meant to be used in places that get executed a lot. It
730 * is wasteful to make predictions in code that is executed seldomly (e.g.
731 * at subsystem initialization time) as the basic block reording that this
732 * affecs can often generate larger code.
733 *
734 * - Note that RT_SUCCESS() and RT_FAILURE() already makes use of RT_LIKELY()
735 * and RT_UNLIKELY(). Should you wish for prediction free status checks,
736 * use the RT_SUCCESS_NP() and RT_FAILURE_NP() macros instead.
737 *
738 *
739 * @returns the boolean result of the expression.
740 * @param expr The expression that's very likely to be true.
741 * @see RT_UNLIKELY
742 */
743/** @def RT_UNLIKELY
744 * Give the compiler a hint that an expression is highly unlikely hold true.
745 *
746 * See the usage instructions give in the RT_LIKELY() docs.
747 *
748 * @returns the boolean result of the expression.
749 * @param expr The expression that's very unlikely to be true.
750 * @see RT_LIKELY
751 */
752#if defined(__GNUC__)
753# if __GNUC__ >= 3
754# define RT_LIKELY(expr) __builtin_expect(!!(expr), 1)
755# define RT_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
756# else
757# define RT_LIKELY(expr) (expr)
758# define RT_UNLIKELY(expr) (expr)
759# endif
760#else
761# define RT_LIKELY(expr) (expr)
762# define RT_UNLIKELY(expr) (expr)
763#endif
764
765
766/** @def RT_BIT
767 * Make a bitmask for one integer sized bit.
768 * @param bit Bit number.
769 */
770#define RT_BIT(bit) (1U << (bit))
771
772/** @def RT_BIT_32
773 * Make a 32-bit bitmask for one bit.
774 * @param bit Bit number.
775 */
776#define RT_BIT_32(bit) (UINT32_C(1) << (bit))
777
778/** @def RT_BIT_64
779 * Make a 64-bit bitmask for one bit.
780 * @param bit Bit number.
781 */
782#define RT_BIT_64(bit) (UINT64_C(1) << (bit))
783
784/** @def RT_ALIGN
785 * Align macro.
786 * @param u Value to align.
787 * @param uAlignment The alignment. Power of two!
788 *
789 * @remark Be extremely careful when using this macro with type which sizeof != sizeof int.
790 * When possible use any of the other RT_ALIGN_* macros. And when that's not
791 * possible, make 101% sure that uAlignment is specified with a right sized type.
792 *
793 * Specifying an unsigned 32-bit alignment constant with a 64-bit value will give
794 * you a 32-bit return value!
795 *
796 * In short: Don't use this macro. Use RT_ALIGN_T() instead.
797 */
798#define RT_ALIGN(u, uAlignment) ( ((u) + ((uAlignment) - 1)) & ~((uAlignment) - 1) )
799
800/** @def RT_ALIGN_T
801 * Align macro.
802 * @param u Value to align.
803 * @param uAlignment The alignment. Power of two!
804 * @param type Integer type to use while aligning.
805 * @remark This macro is the prefered alignment macro, it doesn't have any of the pitfalls RT_ALIGN has.
806 */
807#define RT_ALIGN_T(u, uAlignment, type) ( ((type)(u) + ((uAlignment) - 1)) & ~(type)((uAlignment) - 1) )
808
809/** @def RT_ALIGN_32
810 * Align macro for a 32-bit value.
811 * @param u32 Value to align.
812 * @param uAlignment The alignment. Power of two!
813 */
814#define RT_ALIGN_32(u32, uAlignment) RT_ALIGN_T(u32, uAlignment, uint32_t)
815
816/** @def RT_ALIGN_64
817 * Align macro for a 64-bit value.
818 * @param u64 Value to align.
819 * @param uAlignment The alignment. Power of two!
820 */
821#define RT_ALIGN_64(u64, uAlignment) RT_ALIGN_T(u64, uAlignment, uint64_t)
822
823/** @def RT_ALIGN_Z
824 * Align macro for size_t.
825 * @param cb Value to align.
826 * @param uAlignment The alignment. Power of two!
827 */
828#define RT_ALIGN_Z(cb, uAlignment) RT_ALIGN_T(cb, uAlignment, size_t)
829
830/** @def RT_ALIGN_P
831 * Align macro for pointers.
832 * @param pv Value to align.
833 * @param uAlignment The alignment. Power of two!
834 */
835#define RT_ALIGN_P(pv, uAlignment) RT_ALIGN_PT(pv, uAlignment, void *)
836
837/** @def RT_ALIGN_PT
838 * Align macro for pointers with type cast.
839 * @param u Value to align.
840 * @param uAlignment The alignment. Power of two!
841 * @param CastType The type to cast the result to.
842 */
843#define RT_ALIGN_PT(u, uAlignment, CastType) ((CastType)RT_ALIGN_T(u, uAlignment, uintptr_t))
844
845/** @def RT_ALIGN_R3PT
846 * Align macro for ring-3 pointers with type cast.
847 * @param u Value to align.
848 * @param uAlignment The alignment. Power of two!
849 * @param CastType The type to cast the result to.
850 */
851#define RT_ALIGN_R3PT(u, uAlignment, CastType) ((CastType)RT_ALIGN_T(u, uAlignment, RTR3UINTPTR))
852
853/** @def RT_ALIGN_R0PT
854 * Align macro for ring-0 pointers with type cast.
855 * @param u Value to align.
856 * @param uAlignment The alignment. Power of two!
857 * @param CastType The type to cast the result to.
858 */
859#define RT_ALIGN_R0PT(u, uAlignment, CastType) ((CastType)RT_ALIGN_T(u, uAlignment, RTR0UINTPTR))
860
861/** @def RT_ALIGN_GCPT
862 * Align macro for GC pointers with type cast.
863 * @param u Value to align.
864 * @param uAlignment The alignment. Power of two!
865 * @param CastType The type to cast the result to.
866 */
867#define RT_ALIGN_GCPT(u, uAlignment, CastType) ((CastType)RT_ALIGN_T(u, uAlignment, RTGCUINTPTR))
868
869
870/** @def RT_OFFSETOF
871 * Our own special offsetof() variant, returns a signed result.
872 *
873 * This differs from the usual offsetof() in that it's not relying on builtin
874 * compiler stuff and thus can use variables in arrays the structure may
875 * contain. If in this usful to determin the sizes of structures ending
876 * with a variable length field.
877 *
878 * @returns offset into the structure of the specified member. signed.
879 * @param type Structure type.
880 * @param member Member.
881 */
882#define RT_OFFSETOF(type, member) ( (int)(uintptr_t)&( ((type *)(void *)0)->member) )
883
884/** @def RT_UOFFSETOF
885 * Our own special offsetof() variant, returns an unsigned 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. unsigned.
893 * @param type Structure type.
894 * @param member Member.
895 */
896#define RT_UOFFSETOF(type, member) ( (uintptr_t)&( ((type *)(void *)0)->member) )
897
898/** @def RT_SIZEOFMEMB
899 * Get the size of a structure member.
900 *
901 * @returns size of the structure member.
902 * @param type Structure type.
903 * @param member Member.
904 */
905#define RT_SIZEOFMEMB(type, member) ( sizeof(((type *)(void *)0)->member) )
906
907/** @def RT_ELEMENTS
908 * Calcs the number of elements in an array.
909 * @returns Element count.
910 * @param aArray Array in question.
911 */
912#define RT_ELEMENTS(aArray) ( sizeof(aArray) / sizeof((aArray)[0]) )
913
914#ifdef RT_OS_OS2
915/* Undefine RT_MAX since there is an unfortunate clash with the max
916 resource type define in os2.h. */
917# undef RT_MAX
918#endif
919
920/** @def RT_MAX
921 * Finds the maximum value.
922 * @returns The higher of the two.
923 * @param Value1 Value 1
924 * @param Value2 Value 2
925 */
926#define RT_MAX(Value1, Value2) ((Value1) >= (Value2) ? (Value1) : (Value2))
927
928/** @def RT_MIN
929 * Finds the minimum value.
930 * @returns The lower of the two.
931 * @param Value1 Value 1
932 * @param Value2 Value 2
933 */
934#define RT_MIN(Value1, Value2) ((Value1) <= (Value2) ? (Value1) : (Value2))
935
936/** @def RT_ABS
937 * Get the absolute (non-negative) value.
938 * @returns The absolute value of Value.
939 * @param Value The value.
940 */
941#define RT_ABS(Value) ((Value) >= 0 ? (Value) : -(Value))
942
943/** @def RT_LOWORD
944 * Gets the low word (=uint16_t) of something. */
945#define RT_LOWORD(a) ((a) & 0xffff)
946
947/** @def RT_HIWORD
948 * Gets the high word (=uint16_t) of a 32 bit something. */
949#define RT_HIWORD(a) ((a) >> 16)
950
951/** @def RT_LOBYTE
952 * Gets the low byte of something. */
953#define RT_LOBYTE(a) ((a) & 0xff)
954
955/** @def RT_HIBYTE
956 * Gets the low byte of a 16 bit something. */
957#define RT_HIBYTE(a) ((a) >> 8)
958
959/** @def RT_BYTE1
960 * Gets first byte of something. */
961#define RT_BYTE1(a) ((a) & 0xff)
962
963/** @def RT_BYTE2
964 * Gets second byte of something. */
965#define RT_BYTE2(a) (((a) >> 8) & 0xff)
966
967/** @def RT_BYTE3
968 * Gets second byte of something. */
969#define RT_BYTE3(a) (((a) >> 16) & 0xff)
970
971/** @def RT_BYTE4
972 * Gets fourth byte of something. */
973#define RT_BYTE4(a) (((a) >> 24) & 0xff)
974
975
976/** @def RT_MAKE_U64
977 * Constructs a uint64_t value from two uint32_t values.
978 */
979#define RT_MAKE_U64(Lo, Hi) ( (uint64_t)((uint32_t)(Hi)) << 32 | (uint32_t)(Lo) )
980
981/** @def RT_MAKE_U64_FROM_U16
982 * Constructs a uint64_t value from four uint16_t values.
983 */
984#define RT_MAKE_U64_FROM_U16(w0, w1, w2, w3) \
985 ( (uint64_t)((uint16_t)(w3)) << 48 \
986 | (uint64_t)((uint16_t)(w2)) << 32 \
987 | (uint32_t)((uint16_t)(w1)) << 16 \
988 | (uint16_t)(w0) )
989
990/** @def RT_MAKE_U64_FROM_U8
991 * Constructs a uint64_t value from eight uint8_t values.
992 */
993#define RT_MAKE_U64_FROM_U8(b0, b1, b2, b3, b4, b5, b6, b7) \
994 ( (uint64_t)((uint8_t)(b7)) << 56 \
995 | (uint64_t)((uint8_t)(b6)) << 48 \
996 | (uint64_t)((uint8_t)(b5)) << 40 \
997 | (uint64_t)((uint8_t)(b4)) << 32 \
998 | (uint32_t)((uint8_t)(b3)) << 24 \
999 | (uint32_t)((uint8_t)(b2)) << 16 \
1000 | (uint16_t)((uint8_t)(b1)) << 8 \
1001 | (uint8_t)(b0) )
1002
1003/** @def RT_MAKE_U32
1004 * Constructs a uint32_t value from two uint16_t values.
1005 */
1006#define RT_MAKE_U32(Lo, Hi) ( (uint32_t)((uint16_t)(Hi)) << 16 | (uint16_t)(Lo) )
1007
1008/** @def RT_MAKE_U32_FROM_U8
1009 * Constructs a uint32_t value from four uint8_t values.
1010 */
1011#define RT_MAKE_U32_FROM_U8(b0, b1, b2, b3) \
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_U16
1018 * Constructs a uint32_t value from two uint16_t values.
1019 */
1020#define RT_MAKE_U16(Lo, Hi) ( (uint16_t)((uint8_t)(Hi)) << 8 | (uint8_t)(Lo) )
1021
1022
1023/** @def RT_BSWAP_U64
1024 * Reverses the byte order of an uint64_t value. */
1025#if 0
1026# define RT_BSWAP_U64(u64) RT_MAKE_U64(RT_H2BE_U32((u64) >> 32), RT_H2BE_U32((u64) & 0xffffffff))
1027#else
1028# define RT_BSWAP_U64(u64) ASMByteSwapU64(u64)
1029#endif
1030
1031/** @def RT_BSWAP_U32
1032 * Converts uint32_t value from host to big endian byte order. */
1033#if 0
1034# define RT_BSWAP_U32(u32) (RT_BYTE4(u32) | (RT_BYTE3(u32) << 8) | (RT_BYTE2(u32) << 16) | (RT_BYTE1(u32) << 24))
1035#else
1036# define RT_BSWAP_U32(u32) ASMByteSwapU32(u32)
1037#endif
1038
1039/** @def RT_BSWAP_U16
1040 * Converts uint16_t value from host to big endian byte order. */
1041#if 0
1042# define RT_BSWAP_U16(u16) (RT_HIBYTE(u16) | (RT_LOBYTE(u16) << 8))
1043#else
1044# define RT_BSWAP_U16(u16) ASMByteSwapU16(u16)
1045#endif
1046
1047
1048/** @def RT_H2LE_U64
1049 * Converts an uint64_t value from host to little endian byte order. */
1050#ifdef RT_BIG_ENDIAN
1051# define RT_H2LE_U64(u64) RT_BSWAP_U64(u64)
1052#else
1053# define RT_H2LE_U64(u64) (u64)
1054#endif
1055
1056/** @def RT_H2LE_U32
1057 * Converts an uint32_t value from host to little endian byte order. */
1058#ifdef RT_BIG_ENDIAN
1059# define RT_H2LE_U32(u32) RT_BSWAP_U32(u32)
1060#else
1061# define RT_H2LE_U32(u32) (u32)
1062#endif
1063
1064/** @def RT_H2LE_U16
1065 * Converts an uint16_t value from host to little endian byte order. */
1066#ifdef RT_BIG_ENDIAN
1067# define RT_H2LE_U16(u16) RT_BSWAP_U16(u16)
1068#else
1069# define RT_H2LE_U16(u16) (u16)
1070#endif
1071
1072/** @def RT_LE2H_U64
1073 * Converts an uint64_t value from little endian to host byte order. */
1074#ifdef RT_BIG_ENDIAN
1075# define RT_LE2H_U64(u64) RT_BSWAP_U64(u64)
1076#else
1077# define RT_LE2H_U64(u64) (u64)
1078#endif
1079
1080/** @def RT_LE2H_U32
1081 * Converts an uint32_t value from little endian to host byte order. */
1082#ifdef RT_BIG_ENDIAN
1083# define RT_LE2H_U32(u32) RT_BSWAP_U32(u32)
1084#else
1085# define RT_LE2H_U32(u32) (u32)
1086#endif
1087
1088/** @def RT_LE2H_U16
1089 * Converts an uint16_t value from little endian to host byte order. */
1090#ifdef RT_BIG_ENDIAN
1091# define RT_LE2H_U16(u16) RT_BSWAP_U16(u16)
1092#else
1093# define RT_LE2H_U16(u16) (u16)
1094#endif
1095
1096
1097/** @def RT_H2BE_U64
1098 * Converts an uint64_t value from host to big endian byte order. */
1099#ifdef RT_BIG_ENDIAN
1100# define RT_H2BE_U64(u64) (u64)
1101#else
1102# define RT_H2BE_U64(u64) RT_BSWAP_U64(u64)
1103#endif
1104
1105/** @def RT_H2BE_U32
1106 * Converts an uint32_t value from host to big endian byte order. */
1107#ifdef RT_BIG_ENDIAN
1108# define RT_H2BE_U32(u32) (u32)
1109#else
1110# define RT_H2BE_U32(u32) RT_BSWAP_U32(u32)
1111#endif
1112
1113/** @def RT_H2BE_U16
1114 * Converts an uint16_t value from host to big endian byte order. */
1115#ifdef RT_BIG_ENDIAN
1116# define RT_H2BE_U16(u16) (u16)
1117#else
1118# define RT_H2BE_U16(u16) RT_BSWAP_U16(u16)
1119#endif
1120
1121/** @def RT_BE2H_U64
1122 * Converts an uint64_t value from big endian to host byte order. */
1123#ifdef RT_BIG_ENDIAN
1124# define RT_BE2H_U64(u64) (u64)
1125#else
1126# define RT_BE2H_U64(u64) RT_BSWAP_U64(u64)
1127#endif
1128
1129/** @def RT_BE2H_U32
1130 * Converts an uint32_t value from big endian to host byte order. */
1131#ifdef RT_BIG_ENDIAN
1132# define RT_BE2H_U32(u32) (u32)
1133#else
1134# define RT_BE2H_U32(u32) RT_BSWAP_U32(u32)
1135#endif
1136
1137/** @def RT_BE2H_U16
1138 * Converts an uint16_t value from big endian to host byte order. */
1139#ifdef RT_BIG_ENDIAN
1140# define RT_BE2H_U16(u16) (u16)
1141#else
1142# define RT_BE2H_U16(u16) RT_BSWAP_U16(u16)
1143#endif
1144
1145
1146/** @def RT_H2N_U64
1147 * Converts an uint64_t value from host to network byte order. */
1148#define RT_H2N_U64(u64) RT_H2BE_U64(u64)
1149
1150/** @def RT_H2N_U32
1151 * Converts an uint32_t value from host to network byte order. */
1152#define RT_H2N_U32(u32) RT_H2BE_U32(u32)
1153
1154/** @def RT_H2N_U16
1155 * Converts an uint16_t value from host to network byte order. */
1156#define RT_H2N_U16(u16) RT_H2BE_U16(u16)
1157
1158/** @def RT_N2H_U64
1159 * Converts an uint64_t value from network to host byte order. */
1160#define RT_N2H_U64(u64) RT_BE2H_U64(u64)
1161
1162/** @def RT_N2H_U32
1163 * Converts an uint32_t value from network to host byte order. */
1164#define RT_N2H_U32(u32) RT_BE2H_U32(u32)
1165
1166/** @def RT_N2H_U16
1167 * Converts an uint16_t value from network to host byte order. */
1168#define RT_N2H_U16(u16) RT_BE2H_U16(u16)
1169
1170
1171/** @def RT_NO_DEPRECATED_MACROS
1172 * Define RT_NO_DEPRECATED_MACROS to not define deprecated macros.
1173 */
1174#ifndef RT_NO_DEPRECATED_MACROS
1175/** @copydoc RT_ELEMENTS
1176 * @deprecated use RT_ELEMENTS. */
1177# define ELEMENTS(aArray) RT_ELEMENTS(aArray)
1178#endif
1179
1180
1181/*
1182 * The BSD sys/param.h + machine/param.h file is a major source of
1183 * namespace pollution. Kill off some of the worse ones unless we're
1184 * compiling kernel code.
1185 */
1186#if defined(RT_OS_DARWIN) \
1187 && !defined(KERNEL) \
1188 && !defined(RT_NO_BSD_PARAM_H_UNDEFING) \
1189 && ( defined(_SYS_PARAM_H_) || defined(_I386_PARAM_H_) )
1190/* sys/param.h: */
1191# undef PSWP
1192# undef PVM
1193# undef PINOD
1194# undef PRIBO
1195# undef PVFS
1196# undef PZERO
1197# undef PSOCK
1198# undef PWAIT
1199# undef PLOCK
1200# undef PPAUSE
1201# undef PUSER
1202# undef PRIMASK
1203# undef MINBUCKET
1204# undef MAXALLOCSAVE
1205# undef FSHIFT
1206# undef FSCALE
1207
1208/* i386/machine.h: */
1209# undef ALIGN
1210# undef ALIGNBYTES
1211# undef DELAY
1212# undef STATUS_WORD
1213# undef USERMODE
1214# undef BASEPRI
1215# undef MSIZE
1216# undef CLSIZE
1217# undef CLSIZELOG2
1218#endif
1219
1220
1221/** @def NULL
1222 * NULL pointer.
1223 */
1224#ifndef NULL
1225# ifdef __cplusplus
1226# define NULL 0
1227# else
1228# define NULL ((void*)0)
1229# endif
1230#endif
1231
1232/** @def NIL_OFFSET
1233 * NIL offset.
1234 * Whenever we use offsets instead of pointers to save space and relocation effort
1235 * NIL_OFFSET shall be used as the equivalent to NULL.
1236 */
1237#define NIL_OFFSET (~0U)
1238
1239/** @def NOREF
1240 * Keeps the compiler from bitching about an unused parameters.
1241 */
1242#define NOREF(var) (void)(var)
1243
1244/** @def Breakpoint
1245 * Emit a debug breakpoint instruction.
1246 *
1247 * Use this for instrumenting a debugging session only!
1248 * No comitted code shall use Breakpoint().
1249 */
1250#ifdef __GNUC__
1251# define Breakpoint() __asm__ __volatile__("int $3\n\t")
1252#endif
1253#ifdef _MSC_VER
1254# define Breakpoint() __asm int 3
1255#endif
1256#if defined(__IBMC__) || defined(__IBMCPP__)
1257# define Breakpoint() __interrupt(3)
1258#endif
1259#ifndef Breakpoint
1260# error "This compiler is not supported!"
1261#endif
1262
1263
1264/** Size Constants
1265 * (Of course, these are binary computer terms, not SI.)
1266 * @{
1267 */
1268/** 1 K (Kilo) (1 024). */
1269#define _1K 0x00000400
1270/** 4 K (Kilo) (4 096). */
1271#define _4K 0x00001000
1272/** 32 K (Kilo) (32 678). */
1273#define _32K 0x00008000
1274/** 64 K (Kilo) (65 536). */
1275#define _64K 0x00010000
1276/** 128 K (Kilo) (131 072). */
1277#define _128K 0x00020000
1278/** 256 K (Kilo) (262 144). */
1279#define _256K 0x00040000
1280/** 512 K (Kilo) (524 288). */
1281#define _512K 0x00080000
1282/** 1 M (Mega) (1 048 576). */
1283#define _1M 0x00100000
1284/** 2 M (Mega) (2 097 152). */
1285#define _2M 0x00200000
1286/** 4 M (Mega) (4 194 304). */
1287#define _4M 0x00400000
1288/** 1 G (Giga) (1 073 741 824). */
1289#define _1G 0x40000000
1290/** 2 G (Giga) (2 147 483 648). (32-bit) */
1291#define _2G32 0x80000000U
1292/** 2 G (Giga) (2 147 483 648). (64-bit) */
1293#define _2G 0x0000000080000000LL
1294/** 4 G (Giga) (4 294 967 296). */
1295#define _4G 0x0000000100000000LL
1296/** 1 T (Tera) (1 099 511 627 776). */
1297#define _1T 0x0000010000000000LL
1298/** 1 P (Peta) (1 125 899 906 842 624). */
1299#define _1P 0x0004000000000000LL
1300/** 1 E (Exa) (1 152 921 504 606 846 976). */
1301#define _1E 0x1000000000000000LL
1302/** 2 E (Exa) (2 305 843 009 213 693 952). */
1303#define _2E 0x2000000000000000ULL
1304/** @} */
1305
1306/** @def VALID_PTR
1307 * Pointer validation macro.
1308 * @param ptr
1309 */
1310#if defined(RT_ARCH_AMD64)
1311# ifdef IN_RING3
1312# if defined(RT_OS_DARWIN) /* first 4GB is reserved for legacy kernel. */
1313# define VALID_PTR(ptr) ( (uintptr_t)(ptr) >= _4G \
1314 && !((uintptr_t)(ptr) & 0xffff800000000000ULL) )
1315# elif defined(RT_OS_SOLARIS) /* The kernel only used the top 2TB, but keep it simple. */
1316# define VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
1317 && ( ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0xffff800000000000ULL \
1318 || ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0) )
1319# else
1320# define VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
1321 && !((uintptr_t)(ptr) & 0xffff800000000000ULL) )
1322# endif
1323# else /* !IN_RING3 */
1324# define VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
1325 && ( ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0xffff800000000000ULL \
1326 || ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0) )
1327# endif /* !IN_RING3 */
1328#elif defined(RT_ARCH_X86)
1329# define VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U )
1330#else
1331# error "Architecture identifier missing / not implemented."
1332#endif
1333
1334
1335/** @def VALID_PHYS32
1336 * 32 bits physical address validation macro.
1337 * @param Phys The RTGCPHYS address.
1338 */
1339#define VALID_PHYS32(Phys) ( (uint64_t)(Phys) < (uint64_t)_4G )
1340
1341/** @def N_
1342 * The \#define N_ is used mark a string for translation. This is usable in
1343 * any part of the code, as it is only used by the tools that create message
1344 * catalogs. This macro is a no-op as far as the compiler and code generation
1345 * is concerned.
1346 *
1347 * If you want to both mark a string for translation and translate it, use _.
1348 */
1349#define N_(s) (s)
1350
1351/** @def _
1352 * The \#define _ is used mark a string for translation and to translate it in
1353 * one step.
1354 *
1355 * If you want to only mark a string for translation, use N_.
1356 */
1357#define _(s) gettext(s)
1358
1359
1360/** @def __PRETTY_FUNCTION__
1361 * With GNU C we'd like to use the builtin __PRETTY_FUNCTION__, so define that for the other compilers.
1362 */
1363#if !defined(__GNUC__) && !defined(__PRETTY_FUNCTION__)
1364# define __PRETTY_FUNCTION__ __FUNCTION__
1365#endif
1366
1367
1368/** @def RT_STRICT
1369 * The \#define RT_STRICT controls whether or not assertions and other runtime checks
1370 * should be compiled in or not.
1371 *
1372 * If you want assertions which are not a subject to compile time options use
1373 * the AssertRelease*() flavors.
1374 */
1375#if !defined(RT_STRICT) && defined(DEBUG)
1376# define RT_STRICT
1377#endif
1378
1379/** Source position. */
1380#define RT_SRC_POS __FILE__, __LINE__, __PRETTY_FUNCTION__
1381
1382/** Source position declaration. */
1383#define RT_SRC_POS_DECL const char *pszFile, unsigned iLine, const char *pszFunction
1384
1385/** Source position arguments. */
1386#define RT_SRC_POS_ARGS pszFile, iLine, pszFunction
1387
1388/** @} */
1389
1390
1391/** @defgroup grp_rt_cdefs_cpp Special Macros for C++
1392 * @ingroup grp_rt_cdefs
1393 * @{
1394 */
1395
1396#ifdef __cplusplus
1397
1398/** @def DECLEXPORT_CLASS
1399 * How to declare an exported class. Place this macro after the 'class'
1400 * keyword in the declaration of every class you want to export.
1401 *
1402 * @note It is necessary to use this macro even for inner classes declared
1403 * inside the already exported classes. This is a GCC specific requirement,
1404 * but it seems not to harm other compilers.
1405 */
1406#if defined(_MSC_VER) || defined(RT_OS_OS2)
1407# define DECLEXPORT_CLASS __declspec(dllexport)
1408#elif defined(RT_USE_VISIBILITY_DEFAULT)
1409# define DECLEXPORT_CLASS __attribute__((visibility("default")))
1410#else
1411# define DECLEXPORT_CLASS
1412#endif
1413
1414/** @def DECLIMPORT_CLASS
1415 * How to declare an imported class Place this macro after the 'class'
1416 * keyword in the declaration of every class you want to export.
1417 *
1418 * @note It is necessary to use this macro even for inner classes declared
1419 * inside the already exported classes. This is a GCC specific requirement,
1420 * but it seems not to harm other compilers.
1421 */
1422#if defined(_MSC_VER) || (defined(RT_OS_OS2) && !defined(__IBMC__) && !defined(__IBMCPP__))
1423# define DECLIMPORT_CLASS __declspec(dllimport)
1424#elif defined(RT_USE_VISIBILITY_DEFAULT)
1425# define DECLIMPORT_CLASS __attribute__((visibility("default")))
1426#else
1427# define DECLIMPORT_CLASS
1428#endif
1429
1430/** @def WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP
1431 * Macro to work around error C2593 of the not-so-smart MSVC 7.x ambiguity
1432 * resolver. The following snippet clearly demonstrates the code causing this
1433 * error:
1434 * @code
1435 * class A
1436 * {
1437 * public:
1438 * operator bool() const { return false; }
1439 * operator int*() const { return NULL; }
1440 * };
1441 * int main()
1442 * {
1443 * A a;
1444 * if (!a);
1445 * if (a && 0);
1446 * return 0;
1447 * }
1448 * @endcode
1449 * The code itself seems pretty valid to me and GCC thinks the same.
1450 *
1451 * This macro fixes the compiler error by explicitly overloading implicit
1452 * global operators !, && and || that take the given class instance as one of
1453 * their arguments.
1454 *
1455 * The best is to use this macro right after the class declaration.
1456 *
1457 * @note The macro expands to nothing for compilers other than MSVC.
1458 *
1459 * @param Cls Class to apply the workaround to
1460 */
1461#if defined(_MSC_VER)
1462# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP(Cls) \
1463 inline bool operator! (const Cls &that) { return !bool (that); } \
1464 inline bool operator&& (const Cls &that, bool b) { return bool (that) && b; } \
1465 inline bool operator|| (const Cls &that, bool b) { return bool (that) || b; } \
1466 inline bool operator&& (bool b, const Cls &that) { return b && bool (that); } \
1467 inline bool operator|| (bool b, const Cls &that) { return b || bool (that); }
1468#else
1469# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP(Cls)
1470#endif
1471
1472/** @def WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL
1473 * Version of WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP for template classes.
1474 *
1475 * @param Tpl Name of the template class to apply the workaround to
1476 * @param ArgsDecl arguments of the template, as declared in |<>| after the
1477 * |template| keyword, including |<>|
1478 * @param Args arguments of the template, as specified in |<>| after the
1479 * template class name when using the, including |<>|
1480 *
1481 * Example:
1482 * @code
1483 * // template class declaration
1484 * template <class C>
1485 * class Foo { ... };
1486 * // applied workaround
1487 * WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL (Foo, <class C>, <C>)
1488 * @endcode
1489 */
1490#if defined(_MSC_VER)
1491# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL(Tpl, ArgsDecl, Args) \
1492 template ArgsDecl \
1493 inline bool operator! (const Tpl Args &that) { return !bool (that); } \
1494 template ArgsDecl \
1495 inline bool operator&& (const Tpl Args &that, bool b) { return bool (that) && b; } \
1496 template ArgsDecl \
1497 inline bool operator|| (const Tpl Args &that, bool b) { return bool (that) || b; } \
1498 template ArgsDecl \
1499 inline bool operator&& (bool b, const Tpl Args &that) { return b && bool (that); } \
1500 template ArgsDecl \
1501 inline bool operator|| (bool b, const Tpl Args &that) { return b || bool (that); }
1502#else
1503# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL(Tpl, ArgsDecl, Args)
1504#endif
1505
1506
1507/** @def DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP
1508 * Declares the copy constructor and the assignment operation as inlined no-ops
1509 * (non-existent functions) for the given class. Use this macro inside the
1510 * private section if you want to effectively disable these operations for your
1511 * class.
1512 *
1513 * @param Cls class name to declare for
1514 */
1515
1516#define DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(Cls) \
1517 inline Cls (const Cls &); \
1518 inline Cls &operator= (const Cls &);
1519
1520
1521/** @def DECLARE_CLS_NEW_DELETE_NOOP
1522 * Declares the new and delete operations as no-ops (non-existent functions)
1523 * for the given class. Use this macro inside the private section if you want
1524 * to effectively limit creating class instances on the stack only.
1525 *
1526 * @note The destructor of the given class must not be virtual, otherwise a
1527 * compile time error will occur. Note that this is not a drawback: having
1528 * the virtual destructor for a stack-based class is absolutely useless
1529 * (the real class of the stack-based instance is always known to the compiler
1530 * at compile time, so it will always call the correct destructor).
1531 *
1532 * @param Cls class name to declare for
1533 */
1534#define DECLARE_CLS_NEW_DELETE_NOOP(Cls) \
1535 inline static void *operator new (size_t); \
1536 inline static void operator delete (void *);
1537
1538#endif /* defined(__cplusplus) */
1539
1540/** @} */
1541
1542#endif
1543
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