diff options
Diffstat (limited to 'include/iprt/cdefs.h')
-rw-r--r-- | include/iprt/cdefs.h | 384 |
1 files changed, 355 insertions, 29 deletions
diff --git a/include/iprt/cdefs.h b/include/iprt/cdefs.h index db52defa..744fd48b 100644 --- a/include/iprt/cdefs.h +++ b/include/iprt/cdefs.h @@ -3,7 +3,7 @@ */ /* - * Copyright (C) 2006-2010 Oracle Corporation + * Copyright (C) 2006-2012 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; @@ -31,16 +31,6 @@ * @{ */ -/* - * Include sys/cdefs.h if present, if not define the stuff we need. - */ -#ifdef HAVE_SYS_CDEFS_H -# if defined(RT_ARCH_LINUX) && defined(__KERNEL__) -# error "oops" -# endif -# include <sys/cdefs.h> -#else - /** @def RT_C_DECLS_BEGIN * Used to start a block of function declarations which are shared * between C and C++ program. @@ -51,14 +41,12 @@ * between C and C++ program. */ -# if defined(__cplusplus) -# define RT_C_DECLS_BEGIN extern "C" { -# define RT_C_DECLS_END } -# else -# define RT_C_DECLS_BEGIN -# define RT_C_DECLS_END -# endif - +#if defined(__cplusplus) +# define RT_C_DECLS_BEGIN extern "C" { +# define RT_C_DECLS_END } +#else +# define RT_C_DECLS_BEGIN +# define RT_C_DECLS_END #endif @@ -283,6 +271,321 @@ #endif + +/** @name RT_OPSYS_XXX - Operative System Identifiers. + * These are the value that the RT_OPSYS \#define can take. @{ + */ +/** Unknown OS. */ +#define RT_OPSYS_UNKNOWN 0 +/** OS Agnostic. */ +#define RT_OPSYS_AGNOSTIC 1 +/** Darwin - aka Mac OS X. */ +#define RT_OPSYS_DARWIN 2 +/** DragonFly BSD. */ +#define RT_OPSYS_DRAGONFLY 3 +/** DOS. */ +#define RT_OPSYS_DOS 4 +/** FreeBSD. */ +#define RT_OPSYS_FREEBSD 5 +/** Haiku. */ +#define RT_OPSYS_HAIKU 6 +/** Linux. */ +#define RT_OPSYS_LINUX 7 +/** L4. */ +#define RT_OPSYS_L4 8 +/** Minix. */ +#define RT_OPSYS_MINIX 9 +/** NetBSD. */ +#define RT_OPSYS_NETBSD 11 +/** Netware. */ +#define RT_OPSYS_NETWARE 12 +/** NT (native). */ +#define RT_OPSYS_NT 13 +/** OpenBSD. */ +#define RT_OPSYS_OPENBSD 14 +/** OS/2. */ +#define RT_OPSYS_OS2 15 +/** Plan 9. */ +#define RT_OPSYS_PLAN9 16 +/** QNX. */ +#define RT_OPSYS_QNX 17 +/** Solaris. */ +#define RT_OPSYS_SOLARIS 18 +/** UEFI. */ +#define RT_OPSYS_UEFI 19 +/** Windows. */ +#define RT_OPSYS_WINDOWS 20 +/** The max RT_OPSYS_XXX value (exclusive). */ +#define RT_OPSYS_MAX 21 +/** @} */ + +/** @def RT_OPSYS + * Indicates which OS we're targetting. It's a \#define with is + * assigned one of the RT_OPSYS_XXX defines above. + * + * So to test if we're on FreeBSD do the following: + * @code + * #if RT_OPSYS == RT_OPSYS_FREEBSD + * some_funky_freebsd_specific_stuff(); + * #endif + * @endcode + */ + +/* + * Set RT_OPSYS_XXX according to RT_OS_XXX. + * + * Search: #define RT_OPSYS_([A-Z0-9]+) .* + * Replace: # elif defined(RT_OS_\1)\n# define RT_OPSYS RT_OPSYS_\1 + */ +#ifndef RT_OPSYS +# if defined(RT_OS_UNKNOWN) +# define RT_OPSYS RT_OPSYS_UNKNOWN +# elif defined(RT_OS_AGNOSTIC) +# define RT_OPSYS RT_OPSYS_AGNOSTIC +# elif defined(RT_OS_DARWIN) +# define RT_OPSYS RT_OPSYS_DARWIN +# elif defined(RT_OS_DRAGONFLY) +# define RT_OPSYS RT_OPSYS_DRAGONFLY +# elif defined(RT_OS_DOS) +# define RT_OPSYS RT_OPSYS_DOS +# elif defined(RT_OS_FREEBSD) +# define RT_OPSYS RT_OPSYS_FREEBSD +# elif defined(RT_OS_HAIKU) +# define RT_OPSYS RT_OPSYS_HAIKU +# elif defined(RT_OS_LINUX) +# define RT_OPSYS RT_OPSYS_LINUX +# elif defined(RT_OS_L4) +# define RT_OPSYS RT_OPSYS_L4 +# elif defined(RT_OS_MINIX) +# define RT_OPSYS RT_OPSYS_MINIX +# elif defined(RT_OS_NETBSD) +# define RT_OPSYS RT_OPSYS_NETBSD +# elif defined(RT_OS_NETWARE) +# define RT_OPSYS RT_OPSYS_NETWARE +# elif defined(RT_OS_NT) +# define RT_OPSYS RT_OPSYS_NT +# elif defined(RT_OS_OPENBSD) +# define RT_OPSYS RT_OPSYS_OPENBSD +# elif defined(RT_OS_OS2) +# define RT_OPSYS RT_OPSYS_OS2 +# elif defined(RT_OS_PLAN9) +# define RT_OPSYS RT_OPSYS_PLAN9 +# elif defined(RT_OS_QNX) +# define RT_OPSYS RT_OPSYS_QNX +# elif defined(RT_OS_SOLARIS) +# define RT_OPSYS RT_OPSYS_SOLARIS +# elif defined(RT_OS_UEFI) +# define RT_OPSYS RT_OPSYS_UEFI +# elif defined(RT_OS_WINDOWS) +# define RT_OPSYS RT_OPSYS_WINDOWS +# endif +#endif + +/* + * Guess RT_OPSYS based on compiler predefined macros. + */ +#ifndef RT_OPSYS +# if defined(__APPLE__) +# define RT_OPSYS RT_OPSYS_DARWIN +# elif defined(__DragonFly__) +# define RT_OPSYS RT_OPSYS_DRAGONFLY +# elif defined(__FreeBSD__) /*??*/ +# define RT_OPSYS RT_OPSYS_FREEBSD +# elif defined(__gnu_linux__) +# define RT_OPSYS RT_OPSYS_LINUX +# elif defined(__NetBSD__) /*??*/ +# define RT_OPSYS RT_OPSYS_NETBSD +# elif defined(__OpenBSD__) /*??*/ +# define RT_OPSYS RT_OPSYS_OPENBSD +# elif defined(__OS2__) +# define RT_OPSYS RT_OPSYS_OS2 +# elif defined(__sun__) || defined(__SunOS__) || defined(__sun) || defined(__SunOS) +# define RT_OPSYS RT_OPSYS_SOLARIS +# elif defined(_WIN32) || defined(_WIN64) +# define RT_OPSYS RT_OPSYS_WINDOWS +# else +# error "Port Me" +# endif +#endif + +#if RT_OPSYS < RT_OPSYS_UNKNOWN || RT_OPSYS >= RT_OPSYS_MAX +# error "Invalid RT_OPSYS value." +#endif + +/* + * Do some consistency checks. + * + * Search: #define RT_OPSYS_([A-Z0-9]+) .* + * Replace: #if defined(RT_OS_\1) && RT_OPSYS != RT_OPSYS_\1\n# error RT_OPSYS vs RT_OS_\1\n#endif + */ +#if defined(RT_OS_UNKNOWN) && RT_OPSYS != RT_OPSYS_UNKNOWN +# error RT_OPSYS vs RT_OS_UNKNOWN +#endif +#if defined(RT_OS_AGNOSTIC) && RT_OPSYS != RT_OPSYS_AGNOSTIC +# error RT_OPSYS vs RT_OS_AGNOSTIC +#endif +#if defined(RT_OS_DARWIN) && RT_OPSYS != RT_OPSYS_DARWIN +# error RT_OPSYS vs RT_OS_DARWIN +#endif +#if defined(RT_OS_DRAGONFLY) && RT_OPSYS != RT_OPSYS_DRAGONFLY +# error RT_OPSYS vs RT_OS_DRAGONFLY +#endif +#if defined(RT_OS_DOS) && RT_OPSYS != RT_OPSYS_DOS +# error RT_OPSYS vs RT_OS_DOS +#endif +#if defined(RT_OS_FREEBSD) && RT_OPSYS != RT_OPSYS_FREEBSD +# error RT_OPSYS vs RT_OS_FREEBSD +#endif +#if defined(RT_OS_HAIKU) && RT_OPSYS != RT_OPSYS_HAIKU +# error RT_OPSYS vs RT_OS_HAIKU +#endif +#if defined(RT_OS_LINUX) && RT_OPSYS != RT_OPSYS_LINUX +# error RT_OPSYS vs RT_OS_LINUX +#endif +#if defined(RT_OS_L4) && RT_OPSYS != RT_OPSYS_L4 +# error RT_OPSYS vs RT_OS_L4 +#endif +#if defined(RT_OS_MINIX) && RT_OPSYS != RT_OPSYS_MINIX +# error RT_OPSYS vs RT_OS_MINIX +#endif +#if defined(RT_OS_NETBSD) && RT_OPSYS != RT_OPSYS_NETBSD +# error RT_OPSYS vs RT_OS_NETBSD +#endif +#if defined(RT_OS_NETWARE) && RT_OPSYS != RT_OPSYS_NETWARE +# error RT_OPSYS vs RT_OS_NETWARE +#endif +#if defined(RT_OS_NT) && RT_OPSYS != RT_OPSYS_NT +# error RT_OPSYS vs RT_OS_NT +#endif +#if defined(RT_OS_OPENBSD) && RT_OPSYS != RT_OPSYS_OPENBSD +# error RT_OPSYS vs RT_OS_OPENBSD +#endif +#if defined(RT_OS_OS2) && RT_OPSYS != RT_OPSYS_OS2 +# error RT_OPSYS vs RT_OS_OS2 +#endif +#if defined(RT_OS_PLAN9) && RT_OPSYS != RT_OPSYS_PLAN9 +# error RT_OPSYS vs RT_OS_PLAN9 +#endif +#if defined(RT_OS_QNX) && RT_OPSYS != RT_OPSYS_QNX +# error RT_OPSYS vs RT_OS_QNX +#endif +#if defined(RT_OS_SOLARIS) && RT_OPSYS != RT_OPSYS_SOLARIS +# error RT_OPSYS vs RT_OS_SOLARIS +#endif +#if defined(RT_OS_UEFI) && RT_OPSYS != RT_OPSYS_UEFI +# error RT_OPSYS vs RT_OS_UEFI +#endif +#if defined(RT_OS_WINDOWS) && RT_OPSYS != RT_OPSYS_WINDOWS +# error RT_OPSYS vs RT_OS_WINDOWS +#endif + +/* + * Make sure the RT_OS_XXX macro is defined. + * + * Search: #define RT_OPSYS_([A-Z0-9]+) .* + * Replace: #elif RT_OPSYS == RT_OPSYS_\1\n# ifndef RT_OS_\1\n# define RT_OS_\1\n# endif + */ +#if RT_OPSYS == RT_OPSYS_UNKNOWN +# ifndef RT_OS_UNKNOWN +# define RT_OS_UNKNOWN +# endif +#elif RT_OPSYS == RT_OPSYS_AGNOSTIC +# ifndef RT_OS_AGNOSTIC +# define RT_OS_AGNOSTIC +# endif +#elif RT_OPSYS == RT_OPSYS_DARWIN +# ifndef RT_OS_DARWIN +# define RT_OS_DARWIN +# endif +#elif RT_OPSYS == RT_OPSYS_DRAGONFLY +# ifndef RT_OS_DRAGONFLY +# define RT_OS_DRAGONFLY +# endif +#elif RT_OPSYS == RT_OPSYS_DOS +# ifndef RT_OS_DOS +# define RT_OS_DOS +# endif +#elif RT_OPSYS == RT_OPSYS_FREEBSD +# ifndef RT_OS_FREEBSD +# define RT_OS_FREEBSD +# endif +#elif RT_OPSYS == RT_OPSYS_HAIKU +# ifndef RT_OS_HAIKU +# define RT_OS_HAIKU +# endif +#elif RT_OPSYS == RT_OPSYS_LINUX +# ifndef RT_OS_LINUX +# define RT_OS_LINUX +# endif +#elif RT_OPSYS == RT_OPSYS_L4 +# ifndef RT_OS_L4 +# define RT_OS_L4 +# endif +#elif RT_OPSYS == RT_OPSYS_MINIX +# ifndef RT_OS_MINIX +# define RT_OS_MINIX +# endif +#elif RT_OPSYS == RT_OPSYS_NETBSD +# ifndef RT_OS_NETBSD +# define RT_OS_NETBSD +# endif +#elif RT_OPSYS == RT_OPSYS_NETWARE +# ifndef RT_OS_NETWARE +# define RT_OS_NETWARE +# endif +#elif RT_OPSYS == RT_OPSYS_NT +# ifndef RT_OS_NT +# define RT_OS_NT +# endif +#elif RT_OPSYS == RT_OPSYS_OPENBSD +# ifndef RT_OS_OPENBSD +# define RT_OS_OPENBSD +# endif +#elif RT_OPSYS == RT_OPSYS_OS2 +# ifndef RT_OS_OS2 +# define RT_OS_OS2 +# endif +#elif RT_OPSYS == RT_OPSYS_PLAN9 +# ifndef RT_OS_PLAN9 +# define RT_OS_PLAN9 +# endif +#elif RT_OPSYS == RT_OPSYS_QNX +# ifndef RT_OS_QNX +# define RT_OS_QNX +# endif +#elif RT_OPSYS == RT_OPSYS_SOLARIS +# ifndef RT_OS_SOLARIS +# define RT_OS_SOLARIS +# endif +#elif RT_OPSYS == RT_OPSYS_UEFI +# ifndef RT_OS_UEFI +# define RT_OS_UEFI +# endif +#elif RT_OPSYS == RT_OPSYS_WINDOWS +# ifndef RT_OS_WINDOWS +# define RT_OS_WINDOWS +# endif +#else +# error "Bad RT_OPSYS value." +#endif + + +/** + * Checks whether the given OpSys uses DOS-style paths or not. + * + * By DOS-style paths we include drive lettering and UNC paths. + * + * @returns true / false + * @param a_OpSys The RT_OPSYS_XXX value to check, will be reference + * multiple times. + */ +#define RT_OPSYS_USES_DOS_PATHS(a_OpSys) \ + ( (a_OpSys) == RT_OPSYS_WINDOWS \ + || (a_OpSys) == RT_OPSYS_OS2 \ + || (a_OpSys) == RT_OPSYS_DOS ) + + + /** @def CTXTYPE * Declare a type differently in GC, R3 and R0. * @@ -762,14 +1065,22 @@ * @param type The return type of the function declaration. * @param name The name of the variable member. */ -#define DECLCALLBACKPTR(type, name) type (RTCALL * name) +#if defined(__IBMC__) || defined(__IBMCPP__) +# define DECLCALLBACKPTR(type, name) type (* RTCALL name) +#else +# define DECLCALLBACKPTR(type, name) type (RTCALL * name) +#endif /** @def DECLCALLBACKMEMBER * How to declare an call back function pointer member. * @param type The return type of the function declaration. * @param name The name of the struct/union/class member. */ -#define DECLCALLBACKMEMBER(type, name) type (RTCALL * name) +#if defined(__IBMC__) || defined(__IBMCPP__) +# define DECLCALLBACKMEMBER(type, name) type (* RTCALL name) +#else +# define DECLCALLBACKMEMBER(type, name) type (RTCALL * name) +#endif /** @def DECLR3CALLBACKMEMBER * How to declare an call back function pointer member - R3 Ptr. @@ -778,7 +1089,7 @@ * @param args The argument list enclosed in parentheses. */ #ifdef IN_RING3 -# define DECLR3CALLBACKMEMBER(type, name, args) type (RTCALL * name) args +# define DECLR3CALLBACKMEMBER(type, name, args) DECLCALLBACKMEMBER(type, name) args #else # define DECLR3CALLBACKMEMBER(type, name, args) RTR3PTR name #endif @@ -790,7 +1101,7 @@ * @param args The argument list enclosed in parentheses. */ #ifdef IN_RC -# define DECLRCCALLBACKMEMBER(type, name, args) type (RTCALL * name) args +# define DECLRCCALLBACKMEMBER(type, name, args) DECLCALLBACKMEMBER(type, name) args #else # define DECLRCCALLBACKMEMBER(type, name, args) RTRCPTR name #endif @@ -802,7 +1113,7 @@ * @param args The argument list enclosed in parentheses. */ #ifdef IN_RING0 -# define DECLR0CALLBACKMEMBER(type, name, args) type (RTCALL * name) args +# define DECLR0CALLBACKMEMBER(type, name, args) DECLCALLBACKMEMBER(type, name) args #else # define DECLR0CALLBACKMEMBER(type, name, args) RTR0PTR name #endif @@ -1093,6 +1404,14 @@ #define RT_STR_TUPLE(a_szConst) a_szConst, (sizeof(a_szConst) - 1) +/** + * Macro for using in switch statements that turns constants into strings. + * + * @param a_Const The constant (not string). + */ +#define RT_CASE_RET_STR(a_Const) case a_Const: return #a_Const + + /** @def RT_BIT * Convert a bit number into an integer bitmask (unsigned). * @param bit The bit number. @@ -1362,9 +1681,9 @@ /** @def RT_LO_U16 * Gets the low uint16_t of a uint32_t or something equivalent. */ #ifdef __GNUC__ -# define RT_LO_U16(a) __extension__ ({ AssertCompile(sizeof((a)) == sizeof(uint64_t)); (uint32_t)(a); }) +# define RT_LO_U16(a) __extension__ ({ AssertCompile(sizeof((a)) == sizeof(uint32_t)); (uint16_t)(a); }) #else -# define RT_LO_U16(a) ( (uint32_t)(a) ) +# define RT_LO_U16(a) ( (uint16_t)(a) ) #endif /** @def RT_HI_U16 * Gets the high uint16_t of a uint32_t or something equivalent). */ @@ -2332,10 +2651,17 @@ #endif /** @def RT_INLINE_ASM_USES_INTRIN - * Defined as 1 if the compiler have and uses intrin.h. Otherwise it is 0. */ + * Defined as the major MSC version if the compiler have and uses intrin.h. + * Otherwise it is 0. */ #ifdef _MSC_VER -# if _MSC_VER >= 1400 -# define RT_INLINE_ASM_USES_INTRIN 1 +# if _MSC_VER >= 1700 /* Visual C++ v11.0 / 2012 */ +# define RT_INLINE_ASM_USES_INTRIN 17 +# elif _MSC_VER >= 1600 /* Visual C++ v10.0 / 2010 */ +# define RT_INLINE_ASM_USES_INTRIN 16 +# elif _MSC_VER >= 1500 /* Visual C++ v9.0 / 2008 */ +# define RT_INLINE_ASM_USES_INTRIN 15 +# elif _MSC_VER >= 1400 /* Visual C++ v8.0 / 2005 */ +# define RT_INLINE_ASM_USES_INTRIN 14 # endif #endif #ifndef RT_INLINE_ASM_USES_INTRIN |