5 #ifndef __UTILS_MONO_COMPILER_H__
6 #define __UTILS_MONO_COMPILER_H__
9 * This file includes macros used in the runtime to encapsulate different
10 * compiler behaviours.
13 #if defined(HAVE_UNISTD_H)
18 #define MONO_ATTR_USED __attribute__ ((__used__))
20 #define MONO_ATTR_USED
24 #define MONO_ATTR_FORMAT_PRINTF(fmt_pos,arg_pos) __attribute__ ((__format__(__printf__,fmt_pos,arg_pos)))
26 #define MONO_ATTR_FORMAT_PRINTF(fmt_pos,arg_pos)
29 /* Deal with Microsoft C compiler differences */
34 #if _MSC_VER < 1800 /* VS 2013 */
35 #define strtoull _strtoui64
39 #define trunc(x) (((x) < 0) ? ceil((x)) : floor((x)))
40 #if _MSC_VER < 1800 /* VS 2013 */
41 #define isnan(x) _isnan(x)
42 #define isinf(x) (_isnan(x) ? 0 : (_fpclass(x) == _FPCLASS_NINF) ? -1 : (_fpclass(x) == _FPCLASS_PINF) ? 1 : 0)
43 #define isnormal(x) _finite(x)
47 #define pclose _pclose
50 #define mkdir(x) _mkdir(x)
52 #define __func__ __FUNCTION__
55 typedef SSIZE_T ssize_t;
58 * SSIZE_MAX is not defined in MSVC, so define it here.
60 * These values come from MinGW64, and are public domain.
65 #define SSIZE_MAX _I64_MAX
67 #define SSIZE_MAX INT_MAX
74 // Quiet Visual Studio linker warning, LNK4221, in cases when this source file intentional ends up empty.
75 #define MONO_EMPTY_SOURCE_FILE(x) void __mono_win32_ ## x ## _quiet_lnk4221 (void) {}
77 #define MONO_EMPTY_SOURCE_FILE(x)
80 #if !defined(_MSC_VER) && !defined(HOST_SOLARIS) && !defined(_WIN32) && !defined(__CYGWIN__) && !defined(MONOTOUCH) && HAVE_VISIBILITY_HIDDEN
82 #define MONO_LLVM_INTERNAL MONO_API
84 #define MONO_LLVM_INTERNAL
87 #define MONO_LLVM_INTERNAL
90 /* Used to mark internal functions used by the profiler modules */
91 #define MONO_PROFILER_API MONO_API
94 #define MONO_ALWAYS_INLINE __attribute__ ((__always_inline__))
95 #elif defined(_MSC_VER)
96 #define MONO_ALWAYS_INLINE __forceinline
98 #define MONO_ALWAYS_INLINE
102 #define MONO_NEVER_INLINE __attribute__ ((__noinline__))
103 #elif defined(_MSC_VER)
104 #define MONO_NEVER_INLINE __declspec(noinline)
106 #define MONO_NEVER_INLINE
110 #define MONO_COLD __attribute__ ((__cold__))
115 #if defined (__GNUC__) && defined (__GNUC_MINOR__) && defined (__GNUC_PATCHLEVEL__)
116 #define MONO_GNUC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
119 #if defined(__has_feature)
120 #if __has_feature(thread_sanitizer)
121 #define MONO_HAS_CLANG_THREAD_SANITIZER 1
123 #define MONO_HAS_CLANG_THREAD_SANITIZER 0
126 #define MONO_HAS_CLANG_THREAD_SANITIZER 0
129 /* Used to tell Clang's ThreadSanitizer to not report data races that occur within a certain function */
130 #if MONO_HAS_CLANG_THREAD_SANITIZER
131 #define MONO_NO_SANITIZE_THREAD __attribute__ ((no_sanitize("thread")))
133 #define MONO_NO_SANITIZE_THREAD
136 /* Used when building with Android NDK's unified headers */
137 #if defined(HOST_ANDROID) && defined (ANDROID_UNIFIED_HEADERS)
138 #if __ANDROID_API__ < 21
140 typedef int32_t __mono_off32_t;
142 #ifdef HAVE_SYS_MMAN_H
143 #include <sys/mman.h>
147 /* Unified headers before API 21 do not declare mmap when LARGE_FILES are used (via -D_FILE_OFFSET_BITS=64)
148 * which is always the case when Mono build targets Android. The problem here is that the unified headers
149 * map `mmap` to `mmap64` if large files are enabled but this api exists only in API21 onwards. Therefore
150 * we must carefully declare the 32-bit mmap here without changing the ABI along the way. Carefully because
151 * in this instance off_t is redeclared to be 64-bit and that's not what we want.
153 void* mmap (void*, size_t, int, int, int, __mono_off32_t);
156 #ifdef HAVE_SYS_SENDFILE_H
157 #include <sys/sendfile.h>
160 #if !defined(sendfile)
161 /* The same thing as with mmap happens with sendfile */
162 ssize_t sendfile (int out_fd, int in_fd, __mono_off32_t* offset, size_t count);
163 #endif /* !sendfile */
165 #endif /* __ANDROID_API__ < 21 */
166 #endif /* HOST_ANDROID && ANDROID_UNIFIED_HEADERS */
168 #endif /* __UTILS_MONO_COMPILER_H__*/