VirtualBox

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

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

cdefs: added RT_BOOL

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 71.7 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
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 * @returns pointer to the structure.
1144 * @param pMem Pointer to the member.
1145 * @param Type Structure type.
1146 * @param Member Member name.
1147 */
1148#define RT_FROM_MEMBER(pMem, Type, Member) ( (Type *) ((uint8_t *)(void *)(pMem) - RT_UOFFSETOF(Type, Member)) )
1149
1150/** @def RT_ELEMENTS
1151 * Calculates the number of elements in a statically sized array.
1152 * @returns Element count.
1153 * @param aArray Array in question.
1154 */
1155#define RT_ELEMENTS(aArray) ( sizeof(aArray) / sizeof((aArray)[0]) )
1156
1157#ifdef RT_OS_OS2
1158/* Undefine RT_MAX since there is an unfortunate clash with the max
1159 resource type define in os2.h. */
1160# undef RT_MAX
1161#endif
1162
1163/** @def RT_MAX
1164 * Finds the maximum value.
1165 * @returns The higher of the two.
1166 * @param Value1 Value 1
1167 * @param Value2 Value 2
1168 */
1169#define RT_MAX(Value1, Value2) ( (Value1) >= (Value2) ? (Value1) : (Value2) )
1170
1171/** @def RT_MIN
1172 * Finds the minimum value.
1173 * @returns The lower of the two.
1174 * @param Value1 Value 1
1175 * @param Value2 Value 2
1176 */
1177#define RT_MIN(Value1, Value2) ( (Value1) <= (Value2) ? (Value1) : (Value2) )
1178
1179/** @def RT_CLAMP
1180 * Clamps the value to minimum and maximum values.
1181 * @returns The clamped value.
1182 * @param Value The value to check.
1183 * @param Min Minimum value.
1184 * @param Max Maximum value.
1185 */
1186#define RT_CLAMP(Value, Min, Max) ( (Value) > (Max) ? (Max) : (Value) < (Min) ? (Min) : (Value) )
1187
1188/** @def RT_ABS
1189 * Get the absolute (non-negative) value.
1190 * @returns The absolute value of Value.
1191 * @param Value The value.
1192 */
1193#define RT_ABS(Value) ( (Value) >= 0 ? (Value) : -(Value) )
1194
1195/** @def RT_BOOL
1196 * Turn non-zero/zero into true/false
1197 * @returns The resulting boolean value.
1198 * @param Value The value.
1199 */
1200#define RT_BOOL(Value) ( !!(Value) )
1201
1202/** @def RT_LODWORD
1203 * Gets the low dword (=uint32_t) of something. */
1204#define RT_LODWORD(a) ( (uint32_t)(a) )
1205
1206/** @def RT_HIDWORD
1207 * Gets the high dword (=uint32_t) of a 64-bit of something. */
1208#define RT_HIDWORD(a) ( (uint32_t)((a) >> 32) )
1209
1210/** @def RT_LOWORD
1211 * Gets the low word (=uint16_t) of something. */
1212#define RT_LOWORD(a) ( (a) & 0xffff )
1213
1214/** @def RT_HIWORD
1215 * Gets the high word (=uint16_t) of a 32-bit something. */
1216#define RT_HIWORD(a) ( (a) >> 16 )
1217
1218/** @def RT_LOBYTE
1219 * Gets the low byte of something. */
1220#define RT_LOBYTE(a) ( (a) & 0xff )
1221
1222/** @def RT_HIBYTE
1223 * Gets the low byte of a 16-bit something. */
1224#define RT_HIBYTE(a) ( (a) >> 8 )
1225
1226/** @def RT_BYTE1
1227 * Gets the first byte of something. */
1228#define RT_BYTE1(a) ( (a) & 0xff )
1229
1230/** @def RT_BYTE2
1231 * Gets the second byte of something. */
1232#define RT_BYTE2(a) ( ((a) >> 8) & 0xff )
1233
1234/** @def RT_BYTE3
1235 * Gets the second byte of something. */
1236#define RT_BYTE3(a) ( ((a) >> 16) & 0xff )
1237
1238/** @def RT_BYTE4
1239 * Gets the fourth byte of something. */
1240#define RT_BYTE4(a) ( ((a) >> 24) & 0xff )
1241
1242/** @def RT_BYTE5
1243 * Gets the fifth byte of something. */
1244#define RT_BYTE5(a) (((a) >> 32) & 0xff)
1245
1246/** @def RT_BYTE6
1247 * Gets the sixth byte of something. */
1248#define RT_BYTE6(a) (((a) >> 40) & 0xff)
1249
1250/** @def RT_BYTE7
1251 * Gets the seventh byte of something. */
1252#define RT_BYTE7(a) (((a) >> 48) & 0xff)
1253
1254/** @def RT_BYTE8
1255 * Gets the eight byte of something. */
1256#define RT_BYTE8(a) (((a) >> 56) & 0xff)
1257
1258
1259/** @def RT_MAKE_U64
1260 * Constructs a uint64_t value from two uint32_t values.
1261 */
1262#define RT_MAKE_U64(Lo, Hi) ( (uint64_t)((uint32_t)(Hi)) << 32 | (uint32_t)(Lo) )
1263
1264/** @def RT_MAKE_U64_FROM_U16
1265 * Constructs a uint64_t value from four uint16_t values.
1266 */
1267#define RT_MAKE_U64_FROM_U16(w0, w1, w2, w3) \
1268 ((uint64_t)( (uint64_t)((uint16_t)(w3)) << 48 \
1269 | (uint64_t)((uint16_t)(w2)) << 32 \
1270 | (uint32_t)((uint16_t)(w1)) << 16 \
1271 | (uint16_t)(w0) ))
1272
1273/** @def RT_MAKE_U64_FROM_U8
1274 * Constructs a uint64_t value from eight uint8_t values.
1275 */
1276#define RT_MAKE_U64_FROM_U8(b0, b1, b2, b3, b4, b5, b6, b7) \
1277 ((uint64_t)( (uint64_t)((uint8_t)(b7)) << 56 \
1278 | (uint64_t)((uint8_t)(b6)) << 48 \
1279 | (uint64_t)((uint8_t)(b5)) << 40 \
1280 | (uint64_t)((uint8_t)(b4)) << 32 \
1281 | (uint32_t)((uint8_t)(b3)) << 24 \
1282 | (uint32_t)((uint8_t)(b2)) << 16 \
1283 | (uint16_t)((uint8_t)(b1)) << 8 \
1284 | (uint8_t)(b0) ))
1285
1286/** @def RT_MAKE_U32
1287 * Constructs a uint32_t value from two uint16_t values.
1288 */
1289#define RT_MAKE_U32(Lo, Hi) \
1290 ((uint32_t)( (uint32_t)((uint16_t)(Hi)) << 16 \
1291 | (uint16_t)(Lo) ))
1292
1293/** @def RT_MAKE_U32_FROM_U8
1294 * Constructs a uint32_t value from four uint8_t values.
1295 */
1296#define RT_MAKE_U32_FROM_U8(b0, b1, b2, b3) \
1297 ((uint32_t)( (uint32_t)((uint8_t)(b3)) << 24 \
1298 | (uint32_t)((uint8_t)(b2)) << 16 \
1299 | (uint16_t)((uint8_t)(b1)) << 8 \
1300 | (uint8_t)(b0) ))
1301
1302/** @def RT_MAKE_U16
1303 * Constructs a uint16_t value from two uint8_t values.
1304 */
1305#define RT_MAKE_U16(Lo, Hi) \
1306 ((uint16_t)( (uint16_t)((uint8_t)(Hi)) << 8 \
1307 | (uint8_t)(Lo) ))
1308
1309
1310/** @def RT_BSWAP_U64
1311 * Reverses the byte order of an uint64_t value. */
1312#if 0
1313# define RT_BSWAP_U64(u64) RT_BSWAP_U64_C(u64)
1314#elif defined(__GNUC__)
1315# define RT_BSWAP_U64(u64) (__builtin_constant_p((u64)) \
1316 ? RT_BSWAP_U64_C(u64) : ASMByteSwapU64(u64))
1317#else
1318# define RT_BSWAP_U64(u64) ASMByteSwapU64(u64)
1319#endif
1320
1321/** @def RT_BSWAP_U32
1322 * Reverses the byte order of an uint32_t value. */
1323#if 0
1324# define RT_BSWAP_U32(u32) RT_BSWAP_U32_C(u32)
1325#elif defined(__GNUC__)
1326# define RT_BSWAP_U32(u32) (__builtin_constant_p((u32)) \
1327 ? RT_BSWAP_U32_C(u32) : ASMByteSwapU32(u32))
1328#else
1329# define RT_BSWAP_U32(u32) ASMByteSwapU32(u32)
1330#endif
1331
1332/** @def RT_BSWAP_U16
1333 * Reverses the byte order of an uint16_t value. */
1334#if 0
1335# define RT_BSWAP_U16(u16) RT_BSWAP_U16_C(u16)
1336#elif defined(__GNUC__)
1337# define RT_BSWAP_U16(u16) (__builtin_constant_p((u16)) \
1338 ? RT_BSWAP_U16_C(u16) : ASMByteSwapU16(u16))
1339#else
1340# define RT_BSWAP_U16(u16) ASMByteSwapU16(u16)
1341#endif
1342
1343
1344/** @def RT_BSWAP_U64_C
1345 * Reverses the byte order of an uint64_t constant. */
1346#define RT_BSWAP_U64_C(u64) RT_MAKE_U64(RT_BSWAP_U32_C((u64) >> 32), RT_BSWAP_U32_C((u64) & 0xffffffff))
1347
1348/** @def RT_BSWAP_U32_C
1349 * Reverses the byte order of an uint32_t constant. */
1350#define RT_BSWAP_U32_C(u32) RT_MAKE_U32_FROM_U8(RT_BYTE4(u32), RT_BYTE3(u32), RT_BYTE2(u32), RT_BYTE1(u32))
1351
1352/** @def RT_BSWAP_U16_C
1353 * Reverses the byte order of an uint16_t constant. */
1354#define RT_BSWAP_U16_C(u16) RT_MAKE_U16(RT_HIBYTE(u16), RT_LOBYTE(u16))
1355
1356
1357/** @def RT_H2LE_U64
1358 * Converts an uint64_t value from host to little endian byte order. */
1359#ifdef RT_BIG_ENDIAN
1360# define RT_H2LE_U64(u64) RT_BSWAP_U64(u64)
1361#else
1362# define RT_H2LE_U64(u64) (u64)
1363#endif
1364
1365/** @def RT_H2LE_U64_C
1366 * Converts an uint64_t constant from host to little endian byte order. */
1367#ifdef RT_BIG_ENDIAN
1368# define RT_H2LE_U64_C(u64) RT_BSWAP_U64_C(u64)
1369#else
1370# define RT_H2LE_U64_C(u64) (u64)
1371#endif
1372
1373/** @def RT_H2LE_U32
1374 * Converts an uint32_t value from host to little endian byte order. */
1375#ifdef RT_BIG_ENDIAN
1376# define RT_H2LE_U32(u32) RT_BSWAP_U32(u32)
1377#else
1378# define RT_H2LE_U32(u32) (u32)
1379#endif
1380
1381/** @def RT_H2LE_U32_C
1382 * Converts an uint32_t constant from host to little endian byte order. */
1383#ifdef RT_BIG_ENDIAN
1384# define RT_H2LE_U32_C(u32) RT_BSWAP_U32_C(u32)
1385#else
1386# define RT_H2LE_U32_C(u32) (u32)
1387#endif
1388
1389/** @def RT_H2LE_U16
1390 * Converts an uint16_t value from host to little endian byte order. */
1391#ifdef RT_BIG_ENDIAN
1392# define RT_H2LE_U16(u16) RT_BSWAP_U16(u16)
1393#else
1394# define RT_H2LE_U16(u16) (u16)
1395#endif
1396
1397/** @def RT_H2LE_U16_C
1398 * Converts an uint16_t constant from host to little endian byte order. */
1399#ifdef RT_BIG_ENDIAN
1400# define RT_H2LE_U16_C(u16) RT_BSWAP_U16_C(u16)
1401#else
1402# define RT_H2LE_U16_C(u16) (u16)
1403#endif
1404
1405
1406/** @def RT_LE2H_U64
1407 * Converts an uint64_t value from little endian to host byte order. */
1408#ifdef RT_BIG_ENDIAN
1409# define RT_LE2H_U64(u64) RT_BSWAP_U64(u64)
1410#else
1411# define RT_LE2H_U64(u64) (u64)
1412#endif
1413
1414/** @def RT_LE2H_U64_C
1415 * Converts an uint64_t constant from little endian to host byte order. */
1416#ifdef RT_BIG_ENDIAN
1417# define RT_LE2H_U64_C(u64) RT_BSWAP_U64_C(u64)
1418#else
1419# define RT_LE2H_U64_C(u64) (u64)
1420#endif
1421
1422/** @def RT_LE2H_U32
1423 * Converts an uint32_t value from little endian to host byte order. */
1424#ifdef RT_BIG_ENDIAN
1425# define RT_LE2H_U32(u32) RT_BSWAP_U32(u32)
1426#else
1427# define RT_LE2H_U32(u32) (u32)
1428#endif
1429
1430/** @def RT_LE2H_U32_C
1431 * Converts an uint32_t constant from little endian to host byte order. */
1432#ifdef RT_BIG_ENDIAN
1433# define RT_LE2H_U32_C(u32) RT_BSWAP_U32_C(u32)
1434#else
1435# define RT_LE2H_U32_C(u32) (u32)
1436#endif
1437
1438/** @def RT_LE2H_U16
1439 * Converts an uint16_t value from little endian to host byte order. */
1440#ifdef RT_BIG_ENDIAN
1441# define RT_LE2H_U16(u16) RT_BSWAP_U16(u16)
1442#else
1443# define RT_LE2H_U16(u16) (u16)
1444#endif
1445
1446/** @def RT_LE2H_U16_C
1447 * Converts an uint16_t constant from little endian to host byte order. */
1448#ifdef RT_BIG_ENDIAN
1449# define RT_LE2H_U16_C(u16) RT_BSWAP_U16_C(u16)
1450#else
1451# define RT_LE2H_U16_C(u16) (u16)
1452#endif
1453
1454
1455/** @def RT_H2BE_U64
1456 * Converts an uint64_t value from host to big endian byte order. */
1457#ifdef RT_BIG_ENDIAN
1458# define RT_H2BE_U64(u64) (u64)
1459#else
1460# define RT_H2BE_U64(u64) RT_BSWAP_U64(u64)
1461#endif
1462
1463/** @def RT_H2BE_U64_C
1464 * Converts an uint64_t constant from host to big endian byte order. */
1465#ifdef RT_BIG_ENDIAN
1466# define RT_H2BE_U64_C(u64) (u64)
1467#else
1468# define RT_H2BE_U64_C(u64) RT_BSWAP_U64_C(u64)
1469#endif
1470
1471/** @def RT_H2BE_U32
1472 * Converts an uint32_t value from host to big endian byte order. */
1473#ifdef RT_BIG_ENDIAN
1474# define RT_H2BE_U32(u32) (u32)
1475#else
1476# define RT_H2BE_U32(u32) RT_BSWAP_U32(u32)
1477#endif
1478
1479/** @def RT_H2BE_U32_C
1480 * Converts an uint32_t constant from host to big endian byte order. */
1481#ifdef RT_BIG_ENDIAN
1482# define RT_H2BE_U32_C(u32) (u32)
1483#else
1484# define RT_H2BE_U32_C(u32) RT_BSWAP_U32_C(u32)
1485#endif
1486
1487/** @def RT_H2BE_U16
1488 * Converts an uint16_t value from host to big endian byte order. */
1489#ifdef RT_BIG_ENDIAN
1490# define RT_H2BE_U16(u16) (u16)
1491#else
1492# define RT_H2BE_U16(u16) RT_BSWAP_U16(u16)
1493#endif
1494
1495/** @def RT_H2BE_U16_C
1496 * Converts an uint16_t constant from host to big endian byte order. */
1497#ifdef RT_BIG_ENDIAN
1498# define RT_H2BE_U16_C(u16) (u16)
1499#else
1500# define RT_H2BE_U16_C(u16) RT_BSWAP_U16_C(u16)
1501#endif
1502
1503/** @def RT_BE2H_U64
1504 * Converts an uint64_t value from big endian to host byte order. */
1505#ifdef RT_BIG_ENDIAN
1506# define RT_BE2H_U64(u64) (u64)
1507#else
1508# define RT_BE2H_U64(u64) RT_BSWAP_U64(u64)
1509#endif
1510
1511/** @def RT_BE2H_U64
1512 * Converts an uint64_t constant from big endian to host byte order. */
1513#ifdef RT_BIG_ENDIAN
1514# define RT_BE2H_U64_C(u64) (u64)
1515#else
1516# define RT_BE2H_U64_C(u64) RT_BSWAP_U64_C(u64)
1517#endif
1518
1519/** @def RT_BE2H_U32
1520 * Converts an uint32_t value from big endian to host byte order. */
1521#ifdef RT_BIG_ENDIAN
1522# define RT_BE2H_U32(u32) (u32)
1523#else
1524# define RT_BE2H_U32(u32) RT_BSWAP_U32(u32)
1525#endif
1526
1527/** @def RT_BE2H_U32_C
1528 * Converts an uint32_t value from big endian to host byte order. */
1529#ifdef RT_BIG_ENDIAN
1530# define RT_BE2H_U32_C(u32) (u32)
1531#else
1532# define RT_BE2H_U32_C(u32) RT_BSWAP_U32_C(u32)
1533#endif
1534
1535/** @def RT_BE2H_U16
1536 * Converts an uint16_t value from big endian to host byte order. */
1537#ifdef RT_BIG_ENDIAN
1538# define RT_BE2H_U16(u16) (u16)
1539#else
1540# define RT_BE2H_U16(u16) RT_BSWAP_U16(u16)
1541#endif
1542
1543/** @def RT_BE2H_U16_C
1544 * Converts an uint16_t constant from big endian to host byte order. */
1545#ifdef RT_BIG_ENDIAN
1546# define RT_BE2H_U16_C(u16) (u16)
1547#else
1548# define RT_BE2H_U16_C(u16) RT_BSWAP_U16_C(u16)
1549#endif
1550
1551
1552/** @def RT_H2N_U64
1553 * Converts an uint64_t value from host to network byte order. */
1554#define RT_H2N_U64(u64) RT_H2BE_U64(u64)
1555
1556/** @def RT_H2N_U64_C
1557 * Converts an uint64_t constant from host to network byte order. */
1558#define RT_H2N_U64_C(u64) RT_H2BE_U64_C(u64)
1559
1560/** @def RT_H2N_U32
1561 * Converts an uint32_t value from host to network byte order. */
1562#define RT_H2N_U32(u32) RT_H2BE_U32(u32)
1563
1564/** @def RT_H2N_U32_C
1565 * Converts an uint32_t constant from host to network byte order. */
1566#define RT_H2N_U32_C(u32) RT_H2BE_U32_C(u32)
1567
1568/** @def RT_H2N_U16
1569 * Converts an uint16_t value from host to network byte order. */
1570#define RT_H2N_U16(u16) RT_H2BE_U16(u16)
1571
1572/** @def RT_H2N_U16_C
1573 * Converts an uint16_t constant from host to network byte order. */
1574#define RT_H2N_U16_C(u16) RT_H2BE_U16_C(u16)
1575
1576/** @def RT_N2H_U64
1577 * Converts an uint64_t value from network to host byte order. */
1578#define RT_N2H_U64(u64) RT_BE2H_U64(u64)
1579
1580/** @def RT_N2H_U64_C
1581 * Converts an uint64_t constant from network to host byte order. */
1582#define RT_N2H_U64_C(u64) RT_BE2H_U64_C(u64)
1583
1584/** @def RT_N2H_U32
1585 * Converts an uint32_t value from network to host byte order. */
1586#define RT_N2H_U32(u32) RT_BE2H_U32(u32)
1587
1588/** @def RT_N2H_U32_C
1589 * Converts an uint32_t constant from network to host byte order. */
1590#define RT_N2H_U32_C(u32) RT_BE2H_U32_C(u32)
1591
1592/** @def RT_N2H_U16
1593 * Converts an uint16_t value from network to host byte order. */
1594#define RT_N2H_U16(u16) RT_BE2H_U16(u16)
1595
1596/** @def RT_N2H_U16_C
1597 * Converts an uint16_t value from network to host byte order. */
1598#define RT_N2H_U16_C(u16) RT_BE2H_U16_C(u16)
1599
1600
1601/*
1602 * The BSD sys/param.h + machine/param.h file is a major source of
1603 * namespace pollution. Kill off some of the worse ones unless we're
1604 * compiling kernel code.
1605 */
1606#if defined(RT_OS_DARWIN) \
1607 && !defined(KERNEL) \
1608 && !defined(RT_NO_BSD_PARAM_H_UNDEFING) \
1609 && ( defined(_SYS_PARAM_H_) || defined(_I386_PARAM_H_) )
1610/* sys/param.h: */
1611# undef PSWP
1612# undef PVM
1613# undef PINOD
1614# undef PRIBO
1615# undef PVFS
1616# undef PZERO
1617# undef PSOCK
1618# undef PWAIT
1619# undef PLOCK
1620# undef PPAUSE
1621# undef PUSER
1622# undef PRIMASK
1623# undef MINBUCKET
1624# undef MAXALLOCSAVE
1625# undef FSHIFT
1626# undef FSCALE
1627
1628/* i386/machine.h: */
1629# undef ALIGN
1630# undef ALIGNBYTES
1631# undef DELAY
1632# undef STATUS_WORD
1633# undef USERMODE
1634# undef BASEPRI
1635# undef MSIZE
1636# undef CLSIZE
1637# undef CLSIZELOG2
1638#endif
1639
1640
1641/** @def NULL
1642 * NULL pointer.
1643 */
1644#ifndef NULL
1645# ifdef __cplusplus
1646# define NULL 0
1647# else
1648# define NULL ((void*)0)
1649# endif
1650#endif
1651
1652/** @def NIL_OFFSET
1653 * NIL offset.
1654 * Whenever we use offsets instead of pointers to save space and relocation effort
1655 * NIL_OFFSET shall be used as the equivalent to NULL.
1656 */
1657#define NIL_OFFSET (~0U)
1658
1659/** @def NOREF
1660 * Keeps the compiler from bitching about an unused parameter.
1661 */
1662#define NOREF(var) (void)(var)
1663
1664/** @def RT_BREAKPOINT
1665 * Emit a debug breakpoint instruction.
1666 *
1667 * @remarks In the x86/amd64 gnu world we add a nop instruction after the int3
1668 * to force gdb to remain at the int3 source line.
1669 * @remarks The L4 kernel will try make sense of the breakpoint, thus the jmp on
1670 * x86/amd64.
1671 */
1672#ifdef __GNUC__
1673# if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
1674# if !defined(__L4ENV__)
1675# define RT_BREAKPOINT() __asm__ __volatile__("int $3\n\tnop\n\t")
1676# else
1677# define RT_BREAKPOINT() __asm__ __volatile__("int3; jmp 1f; 1:\n\t")
1678# endif
1679# elif defined(RT_ARCH_SPARC64)
1680# define RT_BREAKPOINT() __asm__ __volatile__("illtrap 0\n\t") /** @todo Sparc64: this is just a wild guess. */
1681# elif defined(RT_ARCH_SPARC)
1682# define RT_BREAKPOINT() __asm__ __volatile__("unimp 0\n\t") /** @todo Sparc: this is just a wild guess (same as Sparc64, just different name). */
1683# endif
1684#endif
1685#ifdef _MSC_VER
1686# define RT_BREAKPOINT() __debugbreak()
1687#endif
1688#if defined(__IBMC__) || defined(__IBMCPP__)
1689# define RT_BREAKPOINT() __interrupt(3)
1690#endif
1691#ifndef RT_BREAKPOINT
1692# error "This compiler/arch is not supported!"
1693#endif
1694
1695
1696/** @defgroup grp_rt_cdefs_size Size Constants
1697 * (Of course, these are binary computer terms, not SI.)
1698 * @{
1699 */
1700/** 1 K (Kilo) (1 024). */
1701#define _1K 0x00000400
1702/** 4 K (Kilo) (4 096). */
1703#define _4K 0x00001000
1704/** 32 K (Kilo) (32 678). */
1705#define _32K 0x00008000
1706/** 64 K (Kilo) (65 536). */
1707#define _64K 0x00010000
1708/** 128 K (Kilo) (131 072). */
1709#define _128K 0x00020000
1710/** 256 K (Kilo) (262 144). */
1711#define _256K 0x00040000
1712/** 512 K (Kilo) (524 288). */
1713#define _512K 0x00080000
1714/** 1 M (Mega) (1 048 576). */
1715#define _1M 0x00100000
1716/** 2 M (Mega) (2 097 152). */
1717#define _2M 0x00200000
1718/** 4 M (Mega) (4 194 304). */
1719#define _4M 0x00400000
1720/** 1 G (Giga) (1 073 741 824). (32-bit) */
1721#define _1G 0x40000000
1722/** 1 G (Giga) (1 073 741 824). (64-bit) */
1723#define _1G64 0x40000000LL
1724/** 2 G (Giga) (2 147 483 648). (32-bit) */
1725#define _2G32 0x80000000U
1726/** 2 G (Giga) (2 147 483 648). (64-bit) */
1727#define _2G 0x0000000080000000LL
1728/** 4 G (Giga) (4 294 967 296). */
1729#define _4G 0x0000000100000000LL
1730/** 1 T (Tera) (1 099 511 627 776). */
1731#define _1T 0x0000010000000000LL
1732/** 1 P (Peta) (1 125 899 906 842 624). */
1733#define _1P 0x0004000000000000LL
1734/** 1 E (Exa) (1 152 921 504 606 846 976). */
1735#define _1E 0x1000000000000000LL
1736/** 2 E (Exa) (2 305 843 009 213 693 952). */
1737#define _2E 0x2000000000000000ULL
1738/** @} */
1739
1740
1741/** @defgroup grp_rt_cdefs_time Time Constants
1742 * @{
1743 */
1744/** 1 hour expressed in nanoseconds (64-bit). */
1745#define RT_NS_1HOUR UINT64_C(3600000000000)
1746/** 1 minute expressed in nanoseconds (64-bit). */
1747#define RT_NS_1MIN UINT64_C(60000000000)
1748/** 1 second expressed in nanoseconds. */
1749#define RT_NS_1SEC UINT32_C(1000000000)
1750/** 100 millsecond expressed in nanoseconds. */
1751#define RT_NS_100MS UINT32_C(100000000)
1752/** 10 millsecond expressed in nanoseconds. */
1753#define RT_NS_10MS UINT32_C(10000000)
1754/** 1 millsecond expressed in nanoseconds. */
1755#define RT_NS_1MS UINT32_C(1000000)
1756/** 100 microseconds expressed in nanoseconds. */
1757#define RT_NS_100US UINT32_C(100000)
1758/** 10 microseconds expressed in nanoseconds. */
1759#define RT_NS_10US UINT32_C(10000)
1760/** 1 microsecond expressed in nanoseconds. */
1761#define RT_NS_1US UINT32_C(1000)
1762
1763/** 1 second expressed in nanoseconds - 64-bit type. */
1764#define RT_NS_1SEC_64 UINT64_C(1000000000)
1765/** 100 millsecond expressed in nanoseconds - 64-bit type. */
1766#define RT_NS_100MS_64 UINT64_C(100000000)
1767/** 10 millsecond expressed in nanoseconds - 64-bit type. */
1768#define RT_NS_10MS_64 UINT64_C(10000000)
1769/** 1 millsecond expressed in nanoseconds - 64-bit type. */
1770#define RT_NS_1MS_64 UINT64_C(1000000)
1771/** 100 microseconds expressed in nanoseconds - 64-bit type. */
1772#define RT_NS_100US_64 UINT64_C(100000)
1773/** 10 microseconds expressed in nanoseconds - 64-bit type. */
1774#define RT_NS_10US_64 UINT64_C(10000)
1775/** 1 microsecond expressed in nanoseconds - 64-bit type. */
1776#define RT_NS_1US_64 UINT64_C(1000)
1777
1778/** 1 hour expressed in microseconds. */
1779#define RT_US_1HOUR UINT32_C(3600000000)
1780/** 1 minute expressed in microseconds. */
1781#define RT_US_1MIN UINT32_C(60000000)
1782/** 1 second expressed in microseconds. */
1783#define RT_US_1SEC UINT32_C(1000000)
1784/** 100 millsecond expressed in microseconds. */
1785#define RT_US_100MS UINT32_C(100000)
1786/** 10 millsecond expressed in microseconds. */
1787#define RT_US_10MS UINT32_C(10000)
1788/** 1 millsecond expressed in microseconds. */
1789#define RT_US_1MS UINT32_C(1000)
1790
1791/** 1 hour expressed in microseconds - 64-bit type. */
1792#define RT_US_1HOUR_64 UINT64_C(3600000000)
1793/** 1 minute expressed in microseconds - 64-bit type. */
1794#define RT_US_1MIN_64 UINT64_C(60000000)
1795/** 1 second expressed in microseconds - 64-bit type. */
1796#define RT_US_1SEC_64 UINT64_C(1000000)
1797/** 100 millsecond expressed in microseconds - 64-bit type. */
1798#define RT_US_100MS_64 UINT64_C(100000)
1799/** 10 millsecond expressed in microseconds - 64-bit type. */
1800#define RT_US_10MS_64 UINT64_C(10000)
1801/** 1 millsecond expressed in microseconds - 64-bit type. */
1802#define RT_US_1MS_64 UINT64_C(1000)
1803
1804/** 1 hour expressed in milliseconds. */
1805#define RT_MS_1HOUR UINT32_C(3600000)
1806/** 1 minute expressed in milliseconds. */
1807#define RT_MS_1MIN UINT32_C(60000)
1808/** 1 second expressed in milliseconds. */
1809#define RT_MS_1SEC UINT32_C(1000)
1810
1811/** 1 hour expressed in milliseconds - 64-bit type. */
1812#define RT_MS_1HOUR_64 UINT64_C(3600000)
1813/** 1 minute expressed in milliseconds - 64-bit type. */
1814#define RT_MS_1MIN_64 UINT64_C(60000)
1815/** 1 second expressed in milliseconds - 64-bit type. */
1816#define RT_MS_1SEC_64 UINT64_C(1000)
1817
1818/** The number of seconds per week. */
1819#define RT_SEC_1WEEK UINT32_C(604800)
1820/** The number of seconds per day. */
1821#define RT_SEC_1DAY UINT32_C(86400)
1822/** The number of seconds per hour. */
1823#define RT_SEC_1HOUR UINT32_C(3600)
1824
1825/** The number of seconds per week - 64-bit type. */
1826#define RT_SEC_1WEEK_64 UINT64_C(604800)
1827/** The number of seconds per day - 64-bit type. */
1828#define RT_SEC_1DAY_64 UINT64_C(86400)
1829/** The number of seconds per hour - 64-bit type. */
1830#define RT_SEC_1HOUR_64 UINT64_C(3600)
1831/** @} */
1832
1833
1834/** @defgroup grp_rt_cdefs_dbgtype Debug Info Types
1835 * @{ */
1836/** Other format. */
1837#define RT_DBGTYPE_OTHER RT_BIT_32(0)
1838/** Stabs. */
1839#define RT_DBGTYPE_STABS RT_BIT_32(1)
1840/** Debug With Arbitrary Record Format (DWARF). */
1841#define RT_DBGTYPE_DWARF RT_BIT_32(2)
1842/** Microsoft Codeview debug info. */
1843#define RT_DBGTYPE_CODEVIEW RT_BIT_32(3)
1844/** Watcom debug info. */
1845#define RT_DBGTYPE_WATCOM RT_BIT_32(4)
1846/** IBM High Level Language debug info. */
1847#define RT_DBGTYPE_HLL RT_BIT_32(5)
1848/** Old OS/2 and Windows symbol file. */
1849#define RT_DBGTYPE_SYM RT_BIT_32(6)
1850/** Map file. */
1851#define RT_DBGTYPE_MAP RT_BIT_32(7)
1852/** @} */
1853
1854
1855/** @defgroup grp_rt_cdefs_exetype Executable Image Types
1856 * @{ */
1857/** Some other format. */
1858#define RT_EXETYPE_OTHER RT_BIT_32(0)
1859/** Portable Executable. */
1860#define RT_EXETYPE_PE RT_BIT_32(1)
1861/** Linear eXecutable. */
1862#define RT_EXETYPE_LX RT_BIT_32(2)
1863/** Linear Executable. */
1864#define RT_EXETYPE_LE RT_BIT_32(3)
1865/** New Executable. */
1866#define RT_EXETYPE_NE RT_BIT_32(4)
1867/** DOS Executable (Mark Zbikowski). */
1868#define RT_EXETYPE_MZ RT_BIT_32(5)
1869/** COM Executable. */
1870#define RT_EXETYPE_COM RT_BIT_32(6)
1871/** a.out Executable. */
1872#define RT_EXETYPE_AOUT RT_BIT_32(7)
1873/** Executable and Linkable Format. */
1874#define RT_EXETYPE_ELF RT_BIT_32(8)
1875/** Mach-O Executable (including FAT ones). */
1876#define RT_EXETYPE_MACHO RT_BIT_32(9)
1877/** TE from UEFI. */
1878#define RT_EXETYPE_TE RT_BIT_32(9)
1879/** @} */
1880
1881
1882/** @def VALID_PTR
1883 * Pointer validation macro.
1884 * @param ptr The pointer.
1885 */
1886#if defined(RT_ARCH_AMD64)
1887# ifdef IN_RING3
1888# if defined(RT_OS_DARWIN) /* first 4GB is reserved for legacy kernel. */
1889# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) >= _4G \
1890 && !((uintptr_t)(ptr) & 0xffff800000000000ULL) )
1891# elif defined(RT_OS_SOLARIS) /* The kernel only used the top 2TB, but keep it simple. */
1892# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
1893 && ( ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0xffff800000000000ULL \
1894 || ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0) )
1895# else
1896# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
1897 && !((uintptr_t)(ptr) & 0xffff800000000000ULL) )
1898# endif
1899# else /* !IN_RING3 */
1900# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
1901 && ( ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0xffff800000000000ULL \
1902 || ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0) )
1903# endif /* !IN_RING3 */
1904
1905#elif defined(RT_ARCH_X86)
1906# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U )
1907
1908#elif defined(RT_ARCH_SPARC64)
1909# ifdef IN_RING3
1910# if defined(RT_OS_SOLARIS)
1911/** Sparc64 user mode: According to Figure 9.4 in solaris internals */
1912/** @todo # define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x80004000U >= 0x80004000U + 0x100000000ULL ) - figure this. */
1913# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x80000000U >= 0x80000000U + 0x100000000ULL )
1914# else
1915# error "Port me"
1916# endif
1917# else /* !IN_RING3 */
1918# if defined(RT_OS_SOLARIS)
1919/** @todo Sparc64 kernel mode: This is according to Figure 11.1 in solaris
1920 * internals. Verify in sources. */
1921# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) >= 0x01000000U )
1922# else
1923# error "Port me"
1924# endif
1925# endif /* !IN_RING3 */
1926
1927#elif defined(RT_ARCH_SPARC)
1928# ifdef IN_RING3
1929# ifdef RT_OS_SOLARIS
1930/** Sparc user mode: According to
1931 * http://cvs.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/uts/sun4/os/startup.c#510 */
1932# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x400000U >= 0x400000U + 0x2000U )
1933
1934# else
1935# error "Port me"
1936# endif
1937# else /* !IN_RING3 */
1938# ifdef RT_OS_SOLARIS
1939/** @todo Sparc kernel mode: Check the sources! */
1940# define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U )
1941# else
1942# error "Port me"
1943# endif
1944# endif /* !IN_RING3 */
1945
1946#else
1947# error "Architecture identifier missing / not implemented."
1948#endif
1949
1950/** Old name for RT_VALID_PTR. */
1951#define VALID_PTR(ptr) RT_VALID_PTR(ptr)
1952
1953/** @def RT_VALID_ALIGNED_PTR
1954 * Pointer validation macro that also checks the alignment.
1955 * @param ptr The pointer.
1956 * @param align The alignment, must be a power of two.
1957 */
1958#define RT_VALID_ALIGNED_PTR(ptr, align) \
1959 ( !((uintptr_t)(ptr) & (uintptr_t)((align) - 1)) \
1960 && VALID_PTR(ptr) )
1961
1962
1963/** @def VALID_PHYS32
1964 * 32 bits physical address validation macro.
1965 * @param Phys The RTGCPHYS address.
1966 */
1967#define VALID_PHYS32(Phys) ( (uint64_t)(Phys) < (uint64_t)_4G )
1968
1969/** @def N_
1970 * The \#define N_ is used to mark a string for translation. This is usable in
1971 * any part of the code, as it is only used by the tools that create message
1972 * catalogs. This macro is a no-op as far as the compiler and code generation
1973 * is concerned.
1974 *
1975 * If you want to both mark a string for translation and translate it, use _().
1976 */
1977#define N_(s) (s)
1978
1979/** @def _
1980 * The \#define _ is used to mark a string for translation and to translate it
1981 * in one step.
1982 *
1983 * If you want to only mark a string for translation, use N_().
1984 */
1985#define _(s) gettext(s)
1986
1987
1988/** @def __PRETTY_FUNCTION__
1989 * With GNU C we'd like to use the builtin __PRETTY_FUNCTION__, so define that
1990 * for the other compilers.
1991 */
1992#if !defined(__GNUC__) && !defined(__PRETTY_FUNCTION__)
1993# define __PRETTY_FUNCTION__ __FUNCTION__
1994#endif
1995
1996
1997/** @def RT_STRICT
1998 * The \#define RT_STRICT controls whether or not assertions and other runtime
1999 * checks should be compiled in or not.
2000 *
2001 * If you want assertions which are not subject to compile time options use
2002 * the AssertRelease*() flavors.
2003 */
2004#if !defined(RT_STRICT) && defined(DEBUG)
2005# define RT_STRICT
2006#endif
2007
2008/** @todo remove this: */
2009#if !defined(RT_LOCK_STRICT) && !defined(DEBUG_bird)
2010# define RT_LOCK_NO_STRICT
2011#endif
2012#if !defined(RT_LOCK_STRICT_ORDER) && !defined(DEBUG_bird)
2013# define RT_LOCK_NO_STRICT_ORDER
2014#endif
2015
2016/** @def RT_LOCK_STRICT
2017 * The \#define RT_LOCK_STRICT controls whether deadlock detection and related
2018 * checks are done in the lock and semaphore code. It is by default enabled in
2019 * RT_STRICT builds, but this behavior can be overriden by defining
2020 * RT_LOCK_NO_STRICT. */
2021#if !defined(RT_LOCK_STRICT) && !defined(RT_LOCK_NO_STRICT) && defined(RT_STRICT)
2022# define RT_LOCK_STRICT
2023#endif
2024/** @def RT_LOCK_NO_STRICT
2025 * The \#define RT_LOCK_NO_STRICT disables RT_LOCK_STRICT. */
2026#if defined(RT_LOCK_NO_STRICT) && defined(RT_LOCK_STRICT)
2027# undef RT_LOCK_STRICT
2028#endif
2029
2030/** @def RT_LOCK_STRICT_ORDER
2031 * The \#define RT_LOCK_STRICT_ORDER controls whether locking order is checked
2032 * by the lock and semaphore code. It is by default enabled in RT_STRICT
2033 * builds, but this behavior can be overriden by defining
2034 * RT_LOCK_NO_STRICT_ORDER. */
2035#if !defined(RT_LOCK_STRICT_ORDER) && !defined(RT_LOCK_NO_STRICT_ORDER) && defined(RT_STRICT)
2036# define RT_LOCK_STRICT_ORDER
2037#endif
2038/** @def RT_LOCK_NO_STRICT_ORDER
2039 * The \#define RT_LOCK_NO_STRICT_ORDER disables RT_LOCK_STRICT_ORDER. */
2040#if defined(RT_LOCK_NO_STRICT_ORDER) && defined(RT_LOCK_STRICT_ORDER)
2041# undef RT_LOCK_STRICT_ORDER
2042#endif
2043
2044
2045/** Source position. */
2046#define RT_SRC_POS __FILE__, __LINE__, __PRETTY_FUNCTION__
2047
2048/** Source position declaration. */
2049#define RT_SRC_POS_DECL const char *pszFile, unsigned iLine, const char *pszFunction
2050
2051/** Source position arguments. */
2052#define RT_SRC_POS_ARGS pszFile, iLine, pszFunction
2053
2054/** Applies NOREF() to the source position arguments. */
2055#define RT_SRC_POS_NOREF() do { NOREF(pszFile); NOREF(iLine); NOREF(pszFunction); } while (0)
2056
2057
2058/** @def RT_INLINE_ASM_EXTERNAL
2059 * Defined as 1 if the compiler does not support inline assembly.
2060 * The ASM* functions will then be implemented in external .asm files.
2061 */
2062#if (defined(_MSC_VER) && defined(RT_ARCH_AMD64)) \
2063 || (!defined(RT_ARCH_AMD64) && !defined(RT_ARCH_X86))
2064# define RT_INLINE_ASM_EXTERNAL 1
2065#else
2066# define RT_INLINE_ASM_EXTERNAL 0
2067#endif
2068
2069/** @def RT_INLINE_ASM_GNU_STYLE
2070 * Defined as 1 if the compiler understands GNU style inline assembly.
2071 */
2072#if defined(_MSC_VER)
2073# define RT_INLINE_ASM_GNU_STYLE 0
2074#else
2075# define RT_INLINE_ASM_GNU_STYLE 1
2076#endif
2077
2078/** @def RT_INLINE_ASM_USES_INTRIN
2079 * Defined as 1 if the compiler have and uses intrin.h. Otherwise it is 0. */
2080#ifdef _MSC_VER
2081# if _MSC_VER >= 1400
2082# define RT_INLINE_ASM_USES_INTRIN 1
2083# endif
2084#endif
2085#ifndef RT_INLINE_ASM_USES_INTRIN
2086# define RT_INLINE_ASM_USES_INTRIN 0
2087#endif
2088
2089/** @} */
2090
2091
2092/** @defgroup grp_rt_cdefs_cpp Special Macros for C++
2093 * @ingroup grp_rt_cdefs
2094 * @{
2095 */
2096
2097#ifdef __cplusplus
2098
2099/** @def DECLEXPORT_CLASS
2100 * How to declare an exported class. Place this macro after the 'class'
2101 * keyword in the declaration of every class you want to export.
2102 *
2103 * @note It is necessary to use this macro even for inner classes declared
2104 * inside the already exported classes. This is a GCC specific requirement,
2105 * but it seems not to harm other compilers.
2106 */
2107#if defined(_MSC_VER) || defined(RT_OS_OS2)
2108# define DECLEXPORT_CLASS __declspec(dllexport)
2109#elif defined(RT_USE_VISIBILITY_DEFAULT)
2110# define DECLEXPORT_CLASS __attribute__((visibility("default")))
2111#else
2112# define DECLEXPORT_CLASS
2113#endif
2114
2115/** @def DECLIMPORT_CLASS
2116 * How to declare an imported class Place this macro after the 'class'
2117 * keyword in the declaration of every class you want to export.
2118 *
2119 * @note It is necessary to use this macro even for inner classes declared
2120 * inside the already exported classes. This is a GCC specific requirement,
2121 * but it seems not to harm other compilers.
2122 */
2123#if defined(_MSC_VER) || (defined(RT_OS_OS2) && !defined(__IBMC__) && !defined(__IBMCPP__))
2124# define DECLIMPORT_CLASS __declspec(dllimport)
2125#elif defined(RT_USE_VISIBILITY_DEFAULT)
2126# define DECLIMPORT_CLASS __attribute__((visibility("default")))
2127#else
2128# define DECLIMPORT_CLASS
2129#endif
2130
2131/** @def WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP
2132 * Macro to work around error C2593 of the not-so-smart MSVC 7.x ambiguity
2133 * resolver. The following snippet clearly demonstrates the code causing this
2134 * error:
2135 * @code
2136 * class A
2137 * {
2138 * public:
2139 * operator bool() const { return false; }
2140 * operator int*() const { return NULL; }
2141 * };
2142 * int main()
2143 * {
2144 * A a;
2145 * if (!a);
2146 * if (a && 0);
2147 * return 0;
2148 * }
2149 * @endcode
2150 * The code itself seems pretty valid to me and GCC thinks the same.
2151 *
2152 * This macro fixes the compiler error by explicitly overloading implicit
2153 * global operators !, && and || that take the given class instance as one of
2154 * their arguments.
2155 *
2156 * The best is to use this macro right after the class declaration.
2157 *
2158 * @note The macro expands to nothing for compilers other than MSVC.
2159 *
2160 * @param Cls Class to apply the workaround to
2161 */
2162#if defined(_MSC_VER)
2163# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP(Cls) \
2164 inline bool operator! (const Cls &that) { return !bool (that); } \
2165 inline bool operator&& (const Cls &that, bool b) { return bool (that) && b; } \
2166 inline bool operator|| (const Cls &that, bool b) { return bool (that) || b; } \
2167 inline bool operator&& (bool b, const Cls &that) { return b && bool (that); } \
2168 inline bool operator|| (bool b, const Cls &that) { return b || bool (that); }
2169#else
2170# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP(Cls)
2171#endif
2172
2173/** @def WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL
2174 * Version of WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP for template classes.
2175 *
2176 * @param Tpl Name of the template class to apply the workaround to
2177 * @param ArgsDecl arguments of the template, as declared in |<>| after the
2178 * |template| keyword, including |<>|
2179 * @param Args arguments of the template, as specified in |<>| after the
2180 * template class name when using the, including |<>|
2181 *
2182 * Example:
2183 * @code
2184 * // template class declaration
2185 * template <class C>
2186 * class Foo { ... };
2187 * // applied workaround
2188 * WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL (Foo, <class C>, <C>)
2189 * @endcode
2190 */
2191#if defined(_MSC_VER)
2192# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL(Tpl, ArgsDecl, Args) \
2193 template ArgsDecl \
2194 inline bool operator! (const Tpl Args &that) { return !bool (that); } \
2195 template ArgsDecl \
2196 inline bool operator&& (const Tpl Args &that, bool b) { return bool (that) && b; } \
2197 template ArgsDecl \
2198 inline bool operator|| (const Tpl Args &that, bool b) { return bool (that) || b; } \
2199 template ArgsDecl \
2200 inline bool operator&& (bool b, const Tpl Args &that) { return b && bool (that); } \
2201 template ArgsDecl \
2202 inline bool operator|| (bool b, const Tpl Args &that) { return b || bool (that); }
2203#else
2204# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL(Tpl, ArgsDecl, Args)
2205#endif
2206
2207
2208/** @def DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP
2209 * Declares the copy constructor and the assignment operation as inlined no-ops
2210 * (non-existent functions) for the given class. Use this macro inside the
2211 * private section if you want to effectively disable these operations for your
2212 * class.
2213 *
2214 * @param Cls class name to declare for
2215 */
2216
2217#define DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(Cls) \
2218 inline Cls (const Cls &); \
2219 inline Cls &operator= (const Cls &);
2220
2221
2222/** @def DECLARE_CLS_NEW_DELETE_NOOP
2223 * Declares the new and delete operations as no-ops (non-existent functions)
2224 * for the given class. Use this macro inside the private section if you want
2225 * to effectively limit creating class instances on the stack only.
2226 *
2227 * @note The destructor of the given class must not be virtual, otherwise a
2228 * compile time error will occur. Note that this is not a drawback: having
2229 * the virtual destructor for a stack-based class is absolutely useless
2230 * (the real class of the stack-based instance is always known to the compiler
2231 * at compile time, so it will always call the correct destructor).
2232 *
2233 * @param Cls class name to declare for
2234 */
2235#define DECLARE_CLS_NEW_DELETE_NOOP(Cls) \
2236 inline static void *operator new (size_t); \
2237 inline static void operator delete (void *);
2238
2239#endif /* __cplusplus */
2240
2241/** @} */
2242
2243#endif
2244
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