VirtualBox

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

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

iprt/cdefs.h: Added RT_FROM_CPP_MEMBER for shutting up mr noisy (g++).

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