VirtualBox

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

Last change on this file since 36169 was 36169, checked in by vboxsync, 14 years ago

iprt/cdefs.h: DECL_FORCE_INLINE: always_inline -> always_inline to avoid trouble when code redefines the undecorated version.

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