VirtualBox

root/trunk/include/iprt/cdefs.h

Revision 14013, 53.5 kB (checked in by vboxsync, 1 week ago)

RT_LODWORD/RT_HIDWORD must cast the result to uint32_t.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
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_RC
80 #define IN_RC
81 #define IN_RT_GC
82 #define IN_RT_R0
83 #define IN_RT_R3
84 #define IN_RT_STATIC
85 #define RT_STRICT
86 #define Breakpoint
87 #define RT_NO_DEPRECATED_MACROS
88 #endif /* DOXYGEN_RUNNING */
89
90 /** @def RT_ARCH_X86
91  * Indicates that we're compiling for the X86 architecture.
92  */
93
94 /** @def RT_ARCH_AMD64
95  * Indicates that we're compiling for the AMD64 architecture.
96  */
97 #if !defined(RT_ARCH_X86) && !defined(RT_ARCH_AMD64)
98 # if defined(__amd64__) || defined(__x86_64__) || defined(_M_X64) || defined(__AMD64__)
99 define RT_ARCH_AMD64
100 # elif defined(__i386__) || defined(_M_IX86) || defined(__X86__)
101 define RT_ARCH_X86
102 # else /* PORTME: append test for new archs. */
103 error "Check what predefined stuff your compiler uses to indicate architecture."
104 # endif
105 #elif defined(RT_ARCH_X86) && defined(RT_ARCH_AMD64) /* PORTME: append new archs. */
106 # error "Both RT_ARCH_X86 and RT_ARCH_AMD64 cannot be defined at the same time!"
107 #endif
108
109
110 /** @def __X86__
111  * Indicates that we're compiling for the X86 architecture.
112  * @deprecated
113  */
114
115 /** @def __AMD64__
116  * Indicates that we're compiling for the AMD64 architecture.
117  * @deprecated
118  */
119 #if !defined(__X86__) && !defined(__AMD64__)
120 # if defined(RT_ARCH_AMD64)
121 define __AMD64__
122 # elif defined(RT_ARCH_X86)
123 define __X86__
124 # else
125 error "Check what predefined stuff your compiler uses to indicate architecture."
126 # endif
127 #elif defined(__X86__) && defined(__AMD64__)
128 # error "Both __X86__ and __AMD64__ cannot be defined at the same time!"
129 #elif defined(__X86__) && !defined(RT_ARCH_X86)
130 # error "Both __X86__ without RT_ARCH_X86!"
131 #elif defined(__AMD64__) && !defined(RT_ARCH_AMD64)
132 # error "Both __AMD64__ without RT_ARCH_AMD64!"
133 #endif
134
135 /** @def IN_RING0
136  * Used to indicate that we're compiling code which is running
137  * in Ring-0 Host Context.
138  */
139
140 /** @def IN_RING3
141  * Used to indicate that we're compiling code which is running
142  * in Ring-3 Host Context.
143  */
144
145 /** @def IN_RC
146  * Used to indicate that we're compiling code which is running
147  * in the Raw-mode Context (implies R0).
148  */
149 #if !defined(IN_RING3) && !defined(IN_RING0) && !defined(IN_RC) && !defined(IN_RC)
150 # error "You must defined which context the compiled code should run in; IN_RING3, IN_RING0 or IN_RC"
151 #endif
152 #if (defined(IN_RING3) && (defined(IN_RING0) || defined(IN_RC)) ) \
153  || (defined(IN_RING0) && (defined(IN_RING3) || defined(IN_RC)) ) \
154  || (defined(IN_RC)    && (defined(IN_RING3) || defined(IN_RING0)) )
155 # error "Only one of the IN_RING3, IN_RING0, IN_RC defines should be defined."
156 #endif
157
158
159 /** @def ARCH_BITS
160  * Defines the bit count of the current context.
161  */
162 #if !defined(ARCH_BITS) || defined(DOXYGEN_RUNNING)
163 # if defined(RT_ARCH_AMD64)
164 define ARCH_BITS 64
165 # else
166 define ARCH_BITS 32
167 # endif
168 #endif
169
170 /** @def HC_ARCH_BITS
171  * Defines the host architecture bit count.
172  */
173 #if !defined(HC_ARCH_BITS) || defined(DOXYGEN_RUNNING)
174 # ifndef IN_RC
175 define HC_ARCH_BITS ARCH_BITS
176 # else
177 define HC_ARCH_BITS 32
178 # endif
179 #endif
180
181 /** @def GC_ARCH_BITS
182  * Defines the guest architecture bit count.
183  */
184 #if !defined(GC_ARCH_BITS) && !defined(DOXYGEN_RUNNING)
185 # ifdef VBOX_WITH_64_BITS_GUESTS
186 define GC_ARCH_BITS  64
187 # else
188 define GC_ARCH_BITS  32
189 # endif
190 #endif
191
192 /** @def R3_ARCH_BITS
193  * Defines the host ring-3 architecture bit count.
194  */
195 #if !defined(R3_ARCH_BITS) || defined(DOXYGEN_RUNNING)
196 # ifdef IN_RING3
197 define R3_ARCH_BITS ARCH_BITS
198 # else
199 define R3_ARCH_BITS HC_ARCH_BITS
200 # endif
201 #endif
202
203 /** @def R0_ARCH_BITS
204  * Defines the host ring-0 architecture bit count.
205  */
206 #if !defined(R0_ARCH_BITS) || defined(DOXYGEN_RUNNING)
207 # ifdef IN_RING0
208 define R0_ARCH_BITS ARCH_BITS
209 # else
210 define R0_ARCH_BITS HC_ARCH_BITS
211 # endif
212 #endif
213
214 /** @def GC_ARCH_BITS
215  * Defines the guest architecture bit count.
216  */
217 #if !defined(GC_ARCH_BITS) || defined(DOXYGEN_RUNNING)
218 # ifdef IN_RC
219 define GC_ARCH_BITS ARCH_BITS
220 # else
221 define GC_ARCH_BITS 32
222 # endif
223 #endif
224
225
226 /** @def CTXTYPE
227  * Declare a type differently in GC, R3 and R0.
228  *
229  * @param   GCType  The GC type.
230  * @param   R3Type  The R3 type.
231  * @param   R0Type  The R0 type.
232  * @remark  For pointers used only in one context use RCPTRTYPE(), R3R0PTRTYPE(), R3PTRTYPE() or R0PTRTYPE().
233  */
234 #ifdef IN_RC
235 # define CTXTYPE(GCType, R3Type, R0Type)  GCType
236 #elif defined(IN_RING3)
237 # define CTXTYPE(GCType, R3Type, R0Type)  R3Type
238 #else
239 # define CTXTYPE(GCType, R3Type, R0Type)  R0Type
240 #endif
241
242 /** @def RCPTRTYPE
243  * Declare a pointer which is used in the raw mode context but appears in structure(s) used by
244  * both HC and RC. The main purpose is to make sure structures have the same
245  * size when built for different architectures.
246  *
247  * @param   RCType  The RC type.
248  */
249 #define RCPTRTYPE(RCType)       CTXTYPE(RCType, RTRCPTR, RTRCPTR)
250
251 /** @def R3R0PTRTYPE
252  * Declare a pointer which is used in HC, is explicitely valid in ring 3 and 0,
253  * but appears in structure(s) used by both HC and GC. The main purpose is to
254  * make sure structures have the same size when built for different architectures.
255  *
256  * @param   R3R0Type  The R3R0 type.
257  * @remarks This used to be called HCPTRTYPE.
258  */
259 #define R3R0PTRTYPE(R3R0Type)   CTXTYPE(RTHCPTR, R3R0Type, R3R0Type)
260
261 /** @def R3PTRTYPE
262  * Declare a pointer which is used in R3 but appears in structure(s) used by
263  * both HC and GC. The main purpose is to make sure structures have the same
264  * size when built for different architectures.
265  *
266  * @param   R3Type  The R3 type.
267  */
268 #define R3PTRTYPE(R3Type)       CTXTYPE(RTHCUINTPTR, R3Type, RTHCUINTPTR)
269
270 /** @def R0PTRTYPE
271  * Declare a pointer which is used in R0 but appears in structure(s) used by
272  * both HC and GC. The main purpose is to make sure structures have the same
273  * size when built for different architectures.
274  *
275  * @param   R0Type  The R0 type.
276  */
277 #define R0PTRTYPE(R0Type)       CTXTYPE(RTHCUINTPTR, RTHCUINTPTR, R0Type)
278
279 /** @def CTXSUFF
280  * Adds the suffix of the current context to the passed in
281  * identifier name. The suffix is HC or GC.
282  *
283  * This is macro should only be used in shared code to avoid a forrest of ifdefs.
284  * @param   var     Identifier name.
285  * @deprecated Use CTX_SUFF. Do NOT use this for new code.
286  */
287 /** @def OTHERCTXSUFF
288  * Adds the suffix of the other 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  * @deprecated Use CTX_SUFF. Do NOT use this for new code.
294  */
295 #ifdef IN_RC
296 # define CTXSUFF(var)       var##GC
297 # define OTHERCTXSUFF(var)  var##HC
298 #else
299 # define CTXSUFF(var)       var##HC
300 # define OTHERCTXSUFF(var)  var##GC
301 #endif
302
303 /** @def CTXALLSUFF
304  * Adds the suffix of the current context to the passed in
305  * identifier name. The suffix is R3, R0 or GC.
306  *
307  * This is macro should only be used in shared code to avoid a forrest of ifdefs.
308  * @param   var     Identifier name.
309  * @deprecated Use CTX_SUFF. Do NOT use this for new code.
310  */
311 #ifdef IN_RC
312 # define CTXALLSUFF(var)    var##GC
313 #elif defined(IN_RING0)
314 # define CTXALLSUFF(var)    var##R0
315 #else
316 # define CTXALLSUFF(var)    var##R3
317 #endif
318
319 /** @def CTX_SUFF
320  * Adds the suffix of the current context to the passed in
321  * identifier name. The suffix is R3, R0 or RC.
322  *
323  * This is macro should only be used in shared code to avoid a forrest of ifdefs.
324  * @param   var     Identifier name.
325  *
326  * @remark  This will replace CTXALLSUFF and CTXSUFF before long.
327  */
328 #ifdef IN_RC
329 # define CTX_SUFF(var)      var##RC
330 #elif defined(IN_RING0)
331 # define CTX_SUFF(var)      var##R0
332 #else
333 # define CTX_SUFF(var)      var##R3
334 #endif
335
336 /** @def CTX_SUFF_Z
337  * Adds the suffix of the current context to the passed in
338  * identifier name, combining RC and R0 into RZ.
339  * The suffix thus is R3 or RZ.
340  *
341  * This is macro should only be used in shared code to avoid a forrest of ifdefs.
342  * @param   var     Identifier name.
343  *
344  * @remark  This will replace CTXALLSUFF and CTXSUFF before long.
345  */
346 #ifdef IN_RING3
347 # define CTX_SUFF_Z(var)    var##R3
348 #else
349 # define CTX_SUFF_Z(var)    var##RZ
350 #endif
351
352
353 /** @def CTXMID
354  * Adds the current context as a middle name of an identifier name
355  * The middle name is HC or GC.
356  *
357  * This is macro should only be used in shared code to avoid a forrest of ifdefs.
358  * @param   first   First name.
359  * @param   last    Surname.
360  */
361 /** @def OTHERCTXMID
362  * Adds the other context as a middle name of an identifier name
363  * The middle name is HC or GC.
364  *
365  * This is macro should only be used in shared code to avoid a forrest of ifdefs.
366  * @param   first   First name.
367  * @param   last    Surname.
368  * @deprecated use CTX_MID or CTX_MID_Z
369  */
370 #ifdef IN_RC
371 # define CTXMID(first, last)        first##GC##last
372 # define OTHERCTXMID(first, last)   first##HC##last
373 #else
374 # define CTXMID(first, last)        first##HC##last
375 # define OTHERCTXMID(first, last)   first##GC##last
376 #endif
377
378 /** @def CTXALLMID
379  * Adds the current context as a middle name of an identifier name.
380  * The middle name is R3, R0 or GC.
381  *
382  * This is macro should only be used in shared code to avoid a forrest of ifdefs.
383  * @param   first   First name.
384  * @param   last    Surname.
385  * @deprecated use CTX_MID or CTX_MID_Z
386  */
387 #ifdef IN_RC
388 # define CTXALLMID(first, last)     first##GC##last
389 #elif defined(IN_RING0)
390 # define CTXALLMID(first, last)     first##R0##last
391 #else
392 # define CTXALLMID(first, last)     first##R3##last
393 #endif
394
395 /** @def CTX_MID
396  * Adds the current context as a middle name of an identifier name.
397  * The middle name is R3, R0 or RC.
398  *
399  * This is macro should only be used in shared code to avoid a forrest of ifdefs.
400  * @param   first   First name.
401  * @param   last    Surname.
402  */
403 #ifdef IN_RC
404 # define CTX_MID(first, last)       first##RC##last
405 #elif defined(IN_RING0)
406 # define CTX_MID(first, last)       first##R0##last
407 #else
408 # define CTX_MID(first, last)       first##R3##last
409 #endif
410
411 /** @def CTX_MID_Z
412  * Adds the current context as a middle name of an identifier name, combining RC
413  * and R0 into RZ.
414  * The middle name thus is either R3 or RZ.
415  *
416  * This is macro should only be used in shared code to avoid a forrest of ifdefs.
417  * @param   first   First name.
418  * @param   last    Surname.
419  */
420 #ifdef IN_RING3
421 # define CTX_MID_Z(first, last)     first##R3##last
422 #else
423 # define CTX_MID_Z(first, last)     first##RZ##last
424 #endif
425
426
427 /** @def R3STRING
428  * A macro which in GC and R0 will return a dummy string while in R3 it will return
429  * the parameter.
430  *
431  * This is typically used to wrap description strings in structures shared
432  * between R3, R0 and/or GC. The intention is to avoid the \#ifdef IN_RING3 mess.
433  *
434  * @param   pR3String   The R3 string. Only referenced in R3.
435  * @see R0STRING and GCSTRING
436  */
437 #ifdef IN_RING3
438 # define R3STRING(pR3String)    (pR3String)
439 #else
440 # define R3STRING(pR3String)    ("<R3_STRING>")
441 #endif
442
443 /** @def R0STRING
444  * A macro which in GC and R3 will return a dummy string while in R0 it will return
445  * the parameter.
446  *
447  * This is typically used to wrap description strings in structures shared
448  * between R3, R0 and/or GC. The intention is to avoid the \#ifdef IN_RING0 mess.
449  *
450  * @param   pR0String   The R0 string. Only referenced in R0.
451  * @see R3STRING and GCSTRING
452  */
453 #ifdef IN_RING0
454 # define R0STRING(pR0String)    (pR0String)
455 #else
456 # define R0STRING(pR0String)    ("<R0_STRING>")
457 #endif
458
459 /** @def RCSTRING
460  * A macro which in R3 and R0 will return a dummy string while in RC it will return
461  * the parameter.
462  *
463  * This is typically used to wrap description strings in structures shared
464  * between R3, R0 and/or RC. The intention is to avoid the \#ifdef IN_RC mess.
465  *
466  * @param   pR0String   The RC string. Only referenced in RC.
467  * @see R3STRING, R0STRING
468  */
469 #ifdef IN_RC
470 # define RCSTRING(pRCString)    (pRCString)
471 #else
472 # define RCSTRING(pRCString)    ("<RC_STRING>")
473 #endif
474
475
476 /** @def RTCALL
477  * The standard calling convention for the Runtime interfaces.
478  */
479 #ifdef _MSC_VER
480 # define RTCALL     __cdecl
481 #elif defined(__GNUC__) && defined(IN_RING0) && !(defined(RT_OS_OS2) || defined(RT_ARCH_AMD64)) /* the latter is kernel/gcc */
482 # define RTCALL     __attribute__((cdecl,regparm(0)))
483 #else
484 # define RTCALL
485 #endif
486
487 /** @def RT_NO_THROW
488  * How to express that a function doesn't throw C++ exceptions
489  * and the compiler can thus save itself the bother of trying
490  * to catch any of them. Put this between the closing parenthesis
491  * and the semicolon in function prototypes (and implementation if C++).
492  */
493 #if defined(__cplusplus) \
494  && (   (defined(_MSC_VER) && defined(_CPPUNWIND)) \
495      || (defined(__GNUC__) && defined(__EXCEPTIONS)))
496 # define RT_NO_THROW    throw()
497 #else
498 # define RT_NO_THROW
499 #endif
500
501 /** @def DECLEXPORT
502  * How to declare an exported function.
503  * @param   type    The return type of the function declaration.
504  */
505 #if defined(_MSC_VER) || defined(RT_OS_OS2)
506 # define DECLEXPORT(type)       __declspec(dllexport) type
507 #elif defined(RT_USE_VISIBILITY_DEFAULT)
508 # define DECLEXPORT(type)      __attribute__((visibility("default"))) type
509 #else
510 # define DECLEXPORT(type)      type
511 #endif
512
513 /** @def DECLIMPORT
514  * How to declare an imported function.
515  * @param   type    The return type of the function declaration.
516  */
517 #if defined(_MSC_VER) || (defined(RT_OS_OS2) && !defined(__IBMC__) && !defined(__IBMCPP__))
518 # define DECLIMPORT(type)       __declspec(dllimport) type
519 #else
520 # define DECLIMPORT(type)       type
521 #endif
522
523 /** @def DECLHIDDEN
524  * How to declare a non-exported function or variable.
525  * @param   type    The return type of the function or the data type of the variable.
526  */
527 #if defined(RT_OS_OS2) || defined(RT_OS_WINDOWS) || !defined(RT_USE_VISIBILITY_HIDDEN)
528 # define DECLHIDDEN(type)       type
529 #else
530 # define DECLHIDDEN(type)       __attribute__((visibility("hidden"))) type
531 #endif
532
533 /** @def DECLASM
534  * How to declare an internal assembly function.
535  * @param   type    The return type of the function declaration.
536  */
537 #ifdef __cplusplus
538 # ifdef _MSC_VER
539 define DECLASM(type)          extern "C" type __cdecl
540 # else
541 define DECLASM(type)          extern "C" type
542 # endif
543 #else
544 # ifdef _MSC_VER
545 define DECLASM(type)          type __cdecl
546 # else
547 define DECLASM(type)          type
548 # endif
549 #endif
550
551 /** @def DECLASMTYPE
552  * How to declare an internal assembly function type.
553  * @param   type    The return type of the function.
554  */
555 #ifdef _MSC_VER
556 # define DECLASMTYPE(type)      type __cdecl
557 #else
558 # define DECLASMTYPE(type)      type
559 #endif
560
561 /** @def DECLNORETURN
562  * How to declare a function which does not return.
563  * @note: This macro can be combined with other macros, for example
564  * @code
565  *   EMR3DECL(DECLNORETURN(void)) foo(void);
566  * @endcode
567  */
568 #ifdef _MSC_VER
569 # define DECLNORETURN(type)     __declspec(noreturn) type
570 #elif defined(__GNUC__)
571 # define DECLNORETURN(type)     __attribute__((noreturn)) type
572 #else
573 # define DECLNORETURN(type)     type
574 #endif
575
576 /** @def DECLCALLBACK
577  * How to declare an call back function type.
578  * @param   type    The return type of the function declaration.
579  */
580 #define DECLCALLBACK(type)      type RTCALL
581
582 /** @def DECLCALLBACKPTR
583  * How to declare an call back function pointer.
584  * @param   type    The return type of the function declaration.
585  * @param   name    The name of the variable member.
586  */
587 #define DECLCALLBACKPTR(type, name)  type (RTCALL * name)
588
589 /** @def DECLCALLBACKMEMBER
590  * How to declare an call back function pointer member.
591  * @param   type    The return type of the function declaration.
592  * @param   name    The name of the struct/union/class member.
593  */
594 #define DECLCALLBACKMEMBER(type, name)  type (RTCALL * name)
595
596 /** @def DECLR3CALLBACKMEMBER
597  * How to declare an call back function pointer member - R3 Ptr.
598  * @param   type    The return type of the function declaration.
599  * @param   name    The name of the struct/union/class member.
600  * @param   args    The argument list enclosed in parentheses.
601  */
602 #ifdef IN_RING3
603 # define DECLR3CALLBACKMEMBER(type, name, args)  type (RTCALL * name) args
604 #else
605 # define DECLR3CALLBACKMEMBER(type, name, args)  RTR3PTR name
606 #endif
607
608 /** @def DECLRCCALLBACKMEMBER
609  * How to declare an call back function pointer member - RC Ptr.
610  * @param   type    The return type of the function declaration.
611  * @param   name    The name of the struct/union/class member.
612  * @param   args    The argument list enclosed in parentheses.
613  */
614 #ifdef IN_RC
615 # define DECLRCCALLBACKMEMBER(type, name, args)  type (RTCALL * name) args
616 #else
617 # define DECLRCCALLBACKMEMBER(type, name, args)  RTRCPTR name
618 #endif
619
620 /** @def DECLR0CALLBACKMEMBER
621  * How to declare an call back function pointer member - R0 Ptr.
622  * @param   type    The return type of the function declaration.
623  * @param   name    The name of the struct/union/class member.
624  * @param   args    The argument list enclosed in parentheses.
625  */
626 #ifdef IN_RING0
627 # define DECLR0CALLBACKMEMBER(type, name, args)  type (RTCALL * name) args
628 #else
629 # define DECLR0CALLBACKMEMBER(type, name, args)  RTR0PTR name
630 #endif
631
632 /** @def DECLINLINE
633  * How to declare a function as inline.
634  * @param   type    The return type of the function declaration.
635  * @remarks Don't use this macro on C++ methods.
636  */
637 #ifdef __GNUC__
638 # define DECLINLINE(type) static __inline__ type
639 #elif defined(__cplusplus)
640 # define DECLINLINE(type) inline type
641 #elif defined(_MSC_VER)
642 # define DECLINLINE(type) _inline type
643 #elif defined(__IBMC__)
644 # define DECLINLINE(type) _Inline type
645 #else
646 # define DECLINLINE(type) inline type
647 #endif
648
649
650 /** @def IN_RT_STATIC
651  * Used to inidicate whether we're linking against a static IPRT
652  * or not. The IPRT symbols will be declared as hidden (if
653  * supported). Note that this define has no effect without setting
654  * IN_RT_R0, IN_RT_R3 or IN_RT_GC indicators are set first.
655  */
656
657 /** @def IN_RT_R0
658  * Used to indicate whether we're inside the same link module as
659  * the HC Ring-0 Runtime Library.
660  */
661 /** @def RTR0DECL(type)
662  * Runtime Library HC Ring-0 export or import declaration.
663  * @param   type    The return type of the function declaration.
664  */
665 #ifdef IN_RT_R0
666 # ifdef IN_RT_STATIC
667 define RTR0DECL(type)    DECLHIDDEN(type) RTCALL
668 # else
669 define RTR0DECL(type)    DECLEXPORT(type) RTCALL
670 # endif
671 #else
672 # define RTR0DECL(type)     DECLIMPORT(type) RTCALL
673 #endif
674
675 /** @def IN_RT_R3
676  * Used to indicate whether we're inside the same link module as
677  * the HC Ring-3 Runtime Library.
678  */
679 /** @def RTR3DECL(type)
680  * Runtime Library HC Ring-3 export or import declaration.
681  * @param   type    The return type of the function declaration.
682  */
683 #ifdef IN_RT_R3
684 # ifdef IN_RT_STATIC
685 define RTR3DECL(type)    DECLHIDDEN(type) RTCALL
686 # else
687 define RTR3DECL(type)    DECLEXPORT(type) RTCALL
688 # endif
689 #else
690 # define RTR3DECL(type)     DECLIMPORT(type) RTCALL
691 #endif
692
693 /** @def IN_RT_GC
694  * Used to indicate whether we're inside the same link module as
695  * the GC Runtime Library.
696  */
697 /** @def RTGCDECL(type)
698  * Runtime Library HC Ring-3 export or import declaration.
699  * @param   type    The return type of the function declaration.
700  */
701 #ifdef IN_RT_GC
702 # ifdef IN_RT_STATIC
703 define RTGCDECL(type)    DECLHIDDEN(type) RTCALL
704 # else
705 define RTGCDECL(type)    DECLEXPORT(type) RTCALL
706 # endif
707 #else
708 # define RTGCDECL(type)     DECLIMPORT(type) RTCALL
709 #endif
710
711 /** @def RTDECL(type)
712  * Runtime Library export or import declaration.
713  * Functions declared using this macro exists in all contexts.
714  * @param   type    The return type of the function declaration.
715  */
716 #if defined(IN_RT_R3) || defined(IN_RT_GC) || defined(IN_RT_R0)
717 # ifdef IN_RT_STATIC
718 define RTDECL(type)      DECLHIDDEN(type) RTCALL
719 # else
720 define RTDECL(type)      DECLEXPORT(type) RTCALL
721 # endif
722 #else
723 # define RTDECL(type)       DECLIMPORT(type) RTCALL
724 #endif
725
726 /** @def RTDATADECL(type)
727  * Runtime Library export or import declaration.
728  * Data declared using this macro exists in all contexts.
729  * @param   type    The return type of the function declaration.
730  */
731 #if defined(IN_RT_R3) || defined(IN_RT_GC) || defined(IN_RT_R0)
732 # ifdef IN_RT_STATIC
733 define RTDATADECL(type)  DECLHIDDEN(type)
734 # else
735 define RTDATADECL(type)  DECLEXPORT(type)
736 # endif
737 #else
738 # define RTDATADECL(type)   DECLIMPORT(type)
739 #endif
740
741
742 /** @def RT_NOCRT
743  * Symbol name wrapper for the No-CRT bits.
744  *
745  * In order to coexist in the same process as other CRTs, we need to
746  * decorate the symbols such that they don't conflict the ones in the
747  * other CRTs. The result of such conflicts / duplicate symbols can
748  * confuse the dynamic loader on unix like systems.
749  *
750  * Define RT_WITHOUT_NOCRT_WRAPPERS to drop the wrapping.
751  * Define RT_WITHOUT_NOCRT_WRAPPER_ALIASES to drop the aliases to the
752  * wrapped names.
753  */
754 /** @def RT_NOCRT_STR
755  * Same as RT_NOCRT only it'll return a double quoted string of the result.
756  */
757 #ifndef RT_WITHOUT_NOCRT_WRAPPERS
758 # define RT_NOCRT(name) nocrt_ ## name
759 # define RT_NOCRT_STR(name) "nocrt_" # name
760 #else
761 # define RT_NOCRT(name) name
762 # define RT_NOCRT_STR(name) #name
763 #endif
764
765
766
767 /** @def RT_LIKELY
768  * Give the compiler a hint that an expression is very likely to hold true.
769  *
770  * Some compilers support explicit branch prediction so that the CPU backend
771  * can hint the processor and also so that code blocks can be reordered such
772  * that the predicted path sees a more linear flow, thus improving cache
773  * behaviour, etc.
774  *
775  * IPRT provides the macros RT_LIKELY() and RT_UNLIKELY() as a way to utilize
776  * this compiler feature when present.
777  *
778  * A few notes about the usage:
779  *
780  *      - Generally, use RT_UNLIKELY() with error condition checks (unless you
781  *        have some _strong_ reason to do otherwise, in which case document it),
782  *        and/or RT_LIKELY() with success condition checks, assuming you want
783  *        to optimize for the success path.
784  *
785  *      - Other than that, if you don't know the likelihood of a test succeeding
786  *        from empirical or other 'hard' evidence, don't make predictions unless
787  *        you happen to be a Dirk Gently.
788  *
789  *      - These macros are meant to be used in places that get executed a lot. It
790  *        is wasteful to make predictions in code that is executed seldomly (e.g.
791  *        at subsystem initialization time) as the basic block reording that this
792  *        affecs can often generate larger code.
793  *
794  *      - Note that RT_SUCCESS() and RT_FAILURE() already makes use of RT_LIKELY()
795  *        and RT_UNLIKELY(). Should you wish for prediction free status checks,
796  *        use the RT_SUCCESS_NP() and RT_FAILURE_NP() macros instead.
797  *
798  *
799  * @returns the boolean result of the expression.
800  * @param   expr        The expression that's very likely to be true.
801  * @see RT_UNLIKELY
802  */
803 /** @def RT_UNLIKELY
804  * Give the compiler a hint that an expression is highly unlikely hold true.
805  *
806  * See the usage instructions give in the RT_LIKELY() docs.
807  *
808  * @returns the boolean result of the expression.
809  * @param   expr        The expression that's very unlikely to be true.
810  * @see RT_LIKELY
811  */
812 #if defined(__GNUC__)
813 # if __GNUC__ >= 3
814 define RT_LIKELY(expr)       __builtin_expect(!!(expr), 1)
815 define RT_UNLIKELY(expr)     __builtin_expect(!!(expr), 0)
816 # else
817 define RT_LIKELY(expr)       (expr)
818 define RT_UNLIKELY(expr)     (expr)
819 # endif
820 #else
821 # define RT_LIKELY(expr)        (expr)
822 # define RT_UNLIKELY(expr)      (expr)
823 #endif
824
825
826 /** @def RT_BIT
827  * Make a bitmask for one integer sized bit.
828  * @param   bit     Bit number.
829  */
830 #define RT_BIT(bit)                     (1U << (bit))
831
832 /** @def RT_BIT_32
833  * Make a 32-bit bitmask for one bit.
834  * @param   bit     Bit number.
835  */
836 #define RT_BIT_32(bit)                  (UINT32_C(1) << (bit))
837
838 /** @def RT_BIT_64
839  * Make a 64-bit bitmask for one bit.
840  * @param   bit     Bit number.
841