VirtualBox

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

Last change on this file since 13469 was 13211, checked in by vboxsync, 16 years ago

iprt/cdefs.h: typo (LODWORD -> HIDWORD)

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