Alexey Samsonov | 94b5036 | 2012-06-05 14:25:27 +0000 | [diff] [blame] | 1 | //===-- sanitizer_internal_defs.h -------------------------------*- C++ -*-===// |
Kostya Serebryany | 9aead37 | 2012-05-31 14:11:07 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file is shared between AddressSanitizer and ThreadSanitizer. |
Alexey Samsonov | 0a4c906 | 2012-06-05 13:50:57 +0000 | [diff] [blame] | 11 | // It contains macro used in run-time libraries code. |
Kostya Serebryany | 9aead37 | 2012-05-31 14:11:07 +0000 | [diff] [blame] | 12 | //===----------------------------------------------------------------------===// |
| 13 | #ifndef SANITIZER_DEFS_H |
| 14 | #define SANITIZER_DEFS_H |
| 15 | |
Evgeniy Stepanov | 24e1372 | 2013-03-19 14:33:38 +0000 | [diff] [blame] | 16 | #include "sanitizer_platform.h" |
Evgeniy Stepanov | 83cb787 | 2013-03-19 13:54:41 +0000 | [diff] [blame] | 17 | |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 18 | #ifndef SANITIZER_DEBUG |
| 19 | # define SANITIZER_DEBUG 0 |
| 20 | #endif |
| 21 | |
Timur Iskhodzhanov | 3c80c6c | 2013-08-13 11:42:45 +0000 | [diff] [blame] | 22 | // Only use SANITIZER_*ATTRIBUTE* before the function return type! |
Evgeniy Stepanov | 30e110e | 2013-03-19 14:54:17 +0000 | [diff] [blame] | 23 | #if SANITIZER_WINDOWS |
Timur Iskhodzhanov | 3c80c6c | 2013-08-13 11:42:45 +0000 | [diff] [blame] | 24 | # define SANITIZER_INTERFACE_ATTRIBUTE __declspec(dllexport) |
| 25 | // FIXME find out what we need on Windows, if anything. |
Evgeniy Stepanov | 250f221 | 2013-01-30 13:12:08 +0000 | [diff] [blame] | 26 | # define SANITIZER_WEAK_ATTRIBUTE |
| 27 | #elif defined(SANITIZER_GO) |
| 28 | # define SANITIZER_INTERFACE_ATTRIBUTE |
| 29 | # define SANITIZER_WEAK_ATTRIBUTE |
| 30 | #else |
| 31 | # define SANITIZER_INTERFACE_ATTRIBUTE __attribute__((visibility("default"))) |
| 32 | # define SANITIZER_WEAK_ATTRIBUTE __attribute__((weak)) |
| 33 | #endif |
| 34 | |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 35 | #if (SANITIZER_LINUX || SANITIZER_WINDOWS) && !defined(SANITIZER_GO) |
Evgeniy Stepanov | 250f221 | 2013-01-30 13:12:08 +0000 | [diff] [blame] | 36 | # define SANITIZER_SUPPORTS_WEAK_HOOKS 1 |
| 37 | #else |
| 38 | # define SANITIZER_SUPPORTS_WEAK_HOOKS 0 |
| 39 | #endif |
| 40 | |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 41 | // We can use .preinit_array section on Linux to call sanitizer initialization |
| 42 | // functions very early in the process startup (unless PIC macro is defined). |
| 43 | // FIXME: do we have anything like this on Mac? |
| 44 | #if SANITIZER_LINUX && !SANITIZER_ANDROID && !defined(PIC) |
| 45 | # define SANITIZER_CAN_USE_PREINIT_ARRAY 1 |
| 46 | #else |
| 47 | # define SANITIZER_CAN_USE_PREINIT_ARRAY 0 |
| 48 | #endif |
| 49 | |
Kostya Serebryany | e31eca9 | 2013-02-15 12:00:24 +0000 | [diff] [blame] | 50 | // GCC does not understand __has_feature |
Evgeniy Stepanov | 250f221 | 2013-01-30 13:12:08 +0000 | [diff] [blame] | 51 | #if !defined(__has_feature) |
| 52 | # define __has_feature(x) 0 |
| 53 | #endif |
| 54 | |
| 55 | // For portability reasons we do not include stddef.h, stdint.h or any other |
| 56 | // system header, but we do need some basic types that are not defined |
| 57 | // in a portable way by the language itself. |
| 58 | namespace __sanitizer { |
| 59 | |
| 60 | #if defined(_WIN64) |
| 61 | // 64-bit Windows uses LLP64 data model. |
| 62 | typedef unsigned long long uptr; // NOLINT |
| 63 | typedef signed long long sptr; // NOLINT |
| 64 | #else |
| 65 | typedef unsigned long uptr; // NOLINT |
| 66 | typedef signed long sptr; // NOLINT |
| 67 | #endif // defined(_WIN64) |
Bill Wendling | 7f790ca | 2013-12-16 02:36:46 +0000 | [diff] [blame] | 68 | #if defined(__x86_64__) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 69 | // Since x32 uses ILP32 data model in 64-bit hardware mode, we must use |
Bill Wendling | 7f790ca | 2013-12-16 02:36:46 +0000 | [diff] [blame] | 70 | // 64-bit pointer to unwind stack frame. |
| 71 | typedef unsigned long long uhwptr; // NOLINT |
| 72 | #else |
| 73 | typedef uptr uhwptr; // NOLINT |
| 74 | #endif |
Evgeniy Stepanov | 250f221 | 2013-01-30 13:12:08 +0000 | [diff] [blame] | 75 | typedef unsigned char u8; |
| 76 | typedef unsigned short u16; // NOLINT |
| 77 | typedef unsigned int u32; |
| 78 | typedef unsigned long long u64; // NOLINT |
| 79 | typedef signed char s8; |
| 80 | typedef signed short s16; // NOLINT |
| 81 | typedef signed int s32; |
| 82 | typedef signed long long s64; // NOLINT |
Pirama Arumuga Nainar | 259f706 | 2015-05-06 11:49:53 -0700 | [diff] [blame] | 83 | #if SANITIZER_WINDOWS |
| 84 | // On Windows, files are HANDLE, which is a synonim of void*. |
| 85 | // Use void* to avoid including <windows.h> everywhere. |
| 86 | typedef void* fd_t; |
| 87 | typedef unsigned error_t; |
| 88 | #else |
Alexey Samsonov | ee7cc44 | 2013-02-01 15:58:46 +0000 | [diff] [blame] | 89 | typedef int fd_t; |
Pirama Arumuga Nainar | 259f706 | 2015-05-06 11:49:53 -0700 | [diff] [blame] | 90 | typedef int error_t; |
| 91 | #endif |
Evgeniy Stepanov | 250f221 | 2013-01-30 13:12:08 +0000 | [diff] [blame] | 92 | |
Kostya Serebryany | 6fb47af | 2013-02-27 11:22:40 +0000 | [diff] [blame] | 93 | // WARNING: OFF_T may be different from OS type off_t, depending on the value of |
| 94 | // _FILE_OFFSET_BITS. This definition of OFF_T matches the ABI of system calls |
| 95 | // like pread and mmap, as opposed to pread64 and mmap64. |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 96 | // FreeBSD, Mac and Linux/x86-64 are special. |
| 97 | #if SANITIZER_FREEBSD || SANITIZER_MAC || \ |
| 98 | (SANITIZER_LINUX && defined(__x86_64__)) |
Kostya Serebryany | 6fb47af | 2013-02-27 11:22:40 +0000 | [diff] [blame] | 99 | typedef u64 OFF_T; |
| 100 | #else |
| 101 | typedef uptr OFF_T; |
| 102 | #endif |
| 103 | typedef u64 OFF64_T; |
Peter Collingbourne | 5317724 | 2013-10-24 06:23:39 +0000 | [diff] [blame] | 104 | |
| 105 | #if (SANITIZER_WORDSIZE == 64) || SANITIZER_MAC |
| 106 | typedef uptr operator_new_size_type; |
| 107 | #else |
| 108 | typedef u32 operator_new_size_type; |
| 109 | #endif |
Evgeniy Stepanov | 250f221 | 2013-01-30 13:12:08 +0000 | [diff] [blame] | 110 | } // namespace __sanitizer |
| 111 | |
Evgeniy Stepanov | 250f221 | 2013-01-30 13:12:08 +0000 | [diff] [blame] | 112 | |
Alexey Samsonov | 0a4c906 | 2012-06-05 13:50:57 +0000 | [diff] [blame] | 113 | using namespace __sanitizer; // NOLINT |
Kostya Serebryany | 9aead37 | 2012-05-31 14:11:07 +0000 | [diff] [blame] | 114 | // ----------- ATTENTION ------------- |
| 115 | // This header should NOT include any other headers to avoid portability issues. |
| 116 | |
Alexey Samsonov | 0a4c906 | 2012-06-05 13:50:57 +0000 | [diff] [blame] | 117 | // Common defs. |
Timur Iskhodzhanov | 40e1668 | 2013-04-12 09:37:20 +0000 | [diff] [blame] | 118 | #define INLINE inline |
Alexey Samsonov | 0a4c906 | 2012-06-05 13:50:57 +0000 | [diff] [blame] | 119 | #define INTERFACE_ATTRIBUTE SANITIZER_INTERFACE_ATTRIBUTE |
| 120 | #define WEAK SANITIZER_WEAK_ATTRIBUTE |
| 121 | |
| 122 | // Platform-specific defs. |
Dmitry Vyukov | bfa45e1 | 2012-11-06 12:47:42 +0000 | [diff] [blame] | 123 | #if defined(_MSC_VER) |
Timur Iskhodzhanov | 40e1668 | 2013-04-12 09:37:20 +0000 | [diff] [blame] | 124 | # define ALWAYS_INLINE __forceinline |
Alexey Samsonov | 0a4c906 | 2012-06-05 13:50:57 +0000 | [diff] [blame] | 125 | // FIXME(timurrrr): do we need this on Windows? |
| 126 | # define ALIAS(x) |
| 127 | # define ALIGNED(x) __declspec(align(x)) |
Alexey Samsonov | 15503b0 | 2012-06-06 13:37:02 +0000 | [diff] [blame] | 128 | # define FORMAT(f, a) |
Alexey Samsonov | 0a4c906 | 2012-06-05 13:50:57 +0000 | [diff] [blame] | 129 | # define NOINLINE __declspec(noinline) |
| 130 | # define NORETURN __declspec(noreturn) |
| 131 | # define THREADLOCAL __declspec(thread) |
Dmitry Vyukov | d51a1a1 | 2012-06-27 21:00:23 +0000 | [diff] [blame] | 132 | # define NOTHROW |
Dmitry Vyukov | e2462f7 | 2012-11-06 12:54:16 +0000 | [diff] [blame] | 133 | # define LIKELY(x) (x) |
| 134 | # define UNLIKELY(x) (x) |
Dmitry Vyukov | b1bd208 | 2013-01-11 16:40:24 +0000 | [diff] [blame] | 135 | # define PREFETCH(x) /* _mm_prefetch(x, _MM_HINT_NTA) */ |
Dmitry Vyukov | bfa45e1 | 2012-11-06 12:47:42 +0000 | [diff] [blame] | 136 | #else // _MSC_VER |
Kostya Serebryany | d475aa8 | 2013-03-29 09:44:16 +0000 | [diff] [blame] | 137 | # define ALWAYS_INLINE inline __attribute__((always_inline)) |
Alexey Samsonov | 0a4c906 | 2012-06-05 13:50:57 +0000 | [diff] [blame] | 138 | # define ALIAS(x) __attribute__((alias(x))) |
Timur Iskhodzhanov | 7c9ffde | 2013-06-04 08:25:17 +0000 | [diff] [blame] | 139 | // Please only use the ALIGNED macro before the type. |
| 140 | // Using ALIGNED after the variable declaration is not portable! |
Alexey Samsonov | 0a4c906 | 2012-06-05 13:50:57 +0000 | [diff] [blame] | 141 | # define ALIGNED(x) __attribute__((aligned(x))) |
Alexey Samsonov | 15503b0 | 2012-06-06 13:37:02 +0000 | [diff] [blame] | 142 | # define FORMAT(f, a) __attribute__((format(printf, f, a))) |
Alexey Samsonov | 0a4c906 | 2012-06-05 13:50:57 +0000 | [diff] [blame] | 143 | # define NOINLINE __attribute__((noinline)) |
| 144 | # define NORETURN __attribute__((noreturn)) |
| 145 | # define THREADLOCAL __thread |
Dmitry Vyukov | 97daee8 | 2012-11-06 12:49:22 +0000 | [diff] [blame] | 146 | # define NOTHROW throw() |
Alexey Samsonov | 0a4c906 | 2012-06-05 13:50:57 +0000 | [diff] [blame] | 147 | # define LIKELY(x) __builtin_expect(!!(x), 1) |
| 148 | # define UNLIKELY(x) __builtin_expect(!!(x), 0) |
Dmitry Vyukov | 0c7f61c | 2013-01-16 14:35:13 +0000 | [diff] [blame] | 149 | # if defined(__i386__) || defined(__x86_64__) |
| 150 | // __builtin_prefetch(x) generates prefetchnt0 on x86 |
| 151 | # define PREFETCH(x) __asm__("prefetchnta (%0)" : : "r" (x)) |
| 152 | # else |
| 153 | # define PREFETCH(x) __builtin_prefetch(x) |
| 154 | # endif |
Dmitry Vyukov | e2462f7 | 2012-11-06 12:54:16 +0000 | [diff] [blame] | 155 | #endif // _MSC_VER |
Kostya Serebryany | 9aead37 | 2012-05-31 14:11:07 +0000 | [diff] [blame] | 156 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 157 | #if !defined(_MSC_VER) || defined(__clang__) |
| 158 | # define UNUSED __attribute__((unused)) |
| 159 | # define USED __attribute__((used)) |
| 160 | #else |
| 161 | # define UNUSED |
| 162 | # define USED |
| 163 | #endif |
| 164 | |
Evgeniy Stepanov | 7202e79 | 2013-06-04 14:06:16 +0000 | [diff] [blame] | 165 | // Unaligned versions of basic types. |
| 166 | typedef ALIGNED(1) u16 uu16; |
| 167 | typedef ALIGNED(1) u32 uu32; |
| 168 | typedef ALIGNED(1) u64 uu64; |
| 169 | typedef ALIGNED(1) s16 us16; |
| 170 | typedef ALIGNED(1) s32 us32; |
| 171 | typedef ALIGNED(1) s64 us64; |
| 172 | |
Evgeniy Stepanov | 30e110e | 2013-03-19 14:54:17 +0000 | [diff] [blame] | 173 | #if SANITIZER_WINDOWS |
Dmitry Vyukov | bb19294 | 2012-11-06 12:50:13 +0000 | [diff] [blame] | 174 | typedef unsigned long DWORD; // NOLINT |
Alexey Samsonov | dd3a911 | 2012-06-15 07:29:14 +0000 | [diff] [blame] | 175 | typedef DWORD thread_return_t; |
| 176 | # define THREAD_CALLING_CONV __stdcall |
| 177 | #else // _WIN32 |
| 178 | typedef void* thread_return_t; |
| 179 | # define THREAD_CALLING_CONV |
| 180 | #endif // _WIN32 |
| 181 | typedef thread_return_t (THREAD_CALLING_CONV *thread_callback_t)(void* arg); |
| 182 | |
Alexey Samsonov | 15a7761 | 2012-06-06 15:22:20 +0000 | [diff] [blame] | 183 | // NOTE: Functions below must be defined in each run-time. |
| 184 | namespace __sanitizer { |
| 185 | void NORETURN Die(); |
Timur Iskhodzhanov | f109267 | 2013-08-13 12:03:51 +0000 | [diff] [blame] | 186 | |
| 187 | // FIXME: No, this shouldn't be in the sanitizer interface. |
| 188 | SANITIZER_INTERFACE_ATTRIBUTE |
Alexey Samsonov | 15a7761 | 2012-06-06 15:22:20 +0000 | [diff] [blame] | 189 | void NORETURN CheckFailed(const char *file, int line, const char *cond, |
| 190 | u64 v1, u64 v2); |
| 191 | } // namespace __sanitizer |
| 192 | |
| 193 | // Check macro |
Alexey Samsonov | 230c3be | 2012-06-06 09:26:25 +0000 | [diff] [blame] | 194 | #define RAW_CHECK_MSG(expr, msg) do { \ |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 195 | if (UNLIKELY(!(expr))) { \ |
Alexey Samsonov | 230c3be | 2012-06-06 09:26:25 +0000 | [diff] [blame] | 196 | RawWrite(msg); \ |
| 197 | Die(); \ |
| 198 | } \ |
| 199 | } while (0) |
| 200 | |
| 201 | #define RAW_CHECK(expr) RAW_CHECK_MSG(expr, #expr) |
| 202 | |
Alexey Samsonov | 15a7761 | 2012-06-06 15:22:20 +0000 | [diff] [blame] | 203 | #define CHECK_IMPL(c1, op, c2) \ |
| 204 | do { \ |
| 205 | __sanitizer::u64 v1 = (u64)(c1); \ |
| 206 | __sanitizer::u64 v2 = (u64)(c2); \ |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 207 | if (UNLIKELY(!(v1 op v2))) \ |
Alexey Samsonov | 15a7761 | 2012-06-06 15:22:20 +0000 | [diff] [blame] | 208 | __sanitizer::CheckFailed(__FILE__, __LINE__, \ |
| 209 | "(" #c1 ") " #op " (" #c2 ")", v1, v2); \ |
| 210 | } while (false) \ |
| 211 | /**/ |
| 212 | |
| 213 | #define CHECK(a) CHECK_IMPL((a), !=, 0) |
| 214 | #define CHECK_EQ(a, b) CHECK_IMPL((a), ==, (b)) |
| 215 | #define CHECK_NE(a, b) CHECK_IMPL((a), !=, (b)) |
| 216 | #define CHECK_LT(a, b) CHECK_IMPL((a), <, (b)) |
| 217 | #define CHECK_LE(a, b) CHECK_IMPL((a), <=, (b)) |
| 218 | #define CHECK_GT(a, b) CHECK_IMPL((a), >, (b)) |
| 219 | #define CHECK_GE(a, b) CHECK_IMPL((a), >=, (b)) |
| 220 | |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 221 | #if SANITIZER_DEBUG |
Dmitry Vyukov | fce5bd4 | 2012-06-29 16:58:33 +0000 | [diff] [blame] | 222 | #define DCHECK(a) CHECK(a) |
| 223 | #define DCHECK_EQ(a, b) CHECK_EQ(a, b) |
| 224 | #define DCHECK_NE(a, b) CHECK_NE(a, b) |
| 225 | #define DCHECK_LT(a, b) CHECK_LT(a, b) |
| 226 | #define DCHECK_LE(a, b) CHECK_LE(a, b) |
| 227 | #define DCHECK_GT(a, b) CHECK_GT(a, b) |
| 228 | #define DCHECK_GE(a, b) CHECK_GE(a, b) |
| 229 | #else |
| 230 | #define DCHECK(a) |
| 231 | #define DCHECK_EQ(a, b) |
| 232 | #define DCHECK_NE(a, b) |
| 233 | #define DCHECK_LT(a, b) |
| 234 | #define DCHECK_LE(a, b) |
| 235 | #define DCHECK_GT(a, b) |
| 236 | #define DCHECK_GE(a, b) |
| 237 | #endif |
| 238 | |
Alexey Samsonov | 45418d1 | 2012-10-09 08:42:07 +0000 | [diff] [blame] | 239 | #define UNREACHABLE(msg) do { \ |
| 240 | CHECK(0 && msg); \ |
| 241 | Die(); \ |
Kostya Serebryany | 5759d92 | 2012-10-16 04:50:32 +0000 | [diff] [blame] | 242 | } while (0) |
Alexey Samsonov | 45418d1 | 2012-10-09 08:42:07 +0000 | [diff] [blame] | 243 | |
| 244 | #define UNIMPLEMENTED() UNREACHABLE("unimplemented") |
Alexey Samsonov | 8c53e54 | 2012-06-06 15:47:40 +0000 | [diff] [blame] | 245 | |
Kostya Serebryany | c375657 | 2012-06-21 10:04:36 +0000 | [diff] [blame] | 246 | #define COMPILER_CHECK(pred) IMPL_COMPILER_ASSERT(pred, __LINE__) |
| 247 | |
Kostya Serebryany | 4c2ddda | 2012-08-28 11:54:51 +0000 | [diff] [blame] | 248 | #define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0])) |
| 249 | |
Kostya Serebryany | c375657 | 2012-06-21 10:04:36 +0000 | [diff] [blame] | 250 | #define IMPL_PASTE(a, b) a##b |
| 251 | #define IMPL_COMPILER_ASSERT(pred, line) \ |
Alexey Samsonov | d7ed1f0 | 2012-09-11 10:31:28 +0000 | [diff] [blame] | 252 | typedef char IMPL_PASTE(assertion_failed_##_, line)[2*(int)(pred)-1] |
Kostya Serebryany | c375657 | 2012-06-21 10:04:36 +0000 | [diff] [blame] | 253 | |
Alexey Samsonov | c925697 | 2012-06-15 13:09:52 +0000 | [diff] [blame] | 254 | // Limits for integral types. We have to redefine it in case we don't |
| 255 | // have stdint.h (like in Visual Studio 9). |
Alexey Samsonov | b46941a | 2012-09-24 11:43:40 +0000 | [diff] [blame] | 256 | #undef __INT64_C |
| 257 | #undef __UINT64_C |
Kostya Serebryany | 5af39e5 | 2012-11-21 12:38:58 +0000 | [diff] [blame] | 258 | #if SANITIZER_WORDSIZE == 64 |
Alexey Samsonov | c925697 | 2012-06-15 13:09:52 +0000 | [diff] [blame] | 259 | # define __INT64_C(c) c ## L |
| 260 | # define __UINT64_C(c) c ## UL |
| 261 | #else |
| 262 | # define __INT64_C(c) c ## LL |
| 263 | # define __UINT64_C(c) c ## ULL |
Kostya Serebryany | 5af39e5 | 2012-11-21 12:38:58 +0000 | [diff] [blame] | 264 | #endif // SANITIZER_WORDSIZE == 64 |
Alexey Samsonov | c925697 | 2012-06-15 13:09:52 +0000 | [diff] [blame] | 265 | #undef INT32_MIN |
| 266 | #define INT32_MIN (-2147483647-1) |
| 267 | #undef INT32_MAX |
| 268 | #define INT32_MAX (2147483647) |
| 269 | #undef UINT32_MAX |
| 270 | #define UINT32_MAX (4294967295U) |
| 271 | #undef INT64_MIN |
| 272 | #define INT64_MIN (-__INT64_C(9223372036854775807)-1) |
| 273 | #undef INT64_MAX |
| 274 | #define INT64_MAX (__INT64_C(9223372036854775807)) |
| 275 | #undef UINT64_MAX |
| 276 | #define UINT64_MAX (__UINT64_C(18446744073709551615)) |
| 277 | |
Alexey Samsonov | 70e177e | 2012-08-27 09:30:58 +0000 | [diff] [blame] | 278 | enum LinkerInitialized { LINKER_INITIALIZED = 0 }; |
| 279 | |
Alexey Samsonov | b46941a | 2012-09-24 11:43:40 +0000 | [diff] [blame] | 280 | #if !defined(_MSC_VER) || defined(__clang__) |
Kostya Serebryany | 1b5ea8f | 2012-08-28 14:11:57 +0000 | [diff] [blame] | 281 | # define GET_CALLER_PC() (uptr)__builtin_return_address(0) |
| 282 | # define GET_CURRENT_FRAME() (uptr)__builtin_frame_address(0) |
| 283 | #else |
Kostya Serebryany | 80acccf | 2012-08-28 15:25:07 +0000 | [diff] [blame] | 284 | extern "C" void* _ReturnAddress(void); |
| 285 | # pragma intrinsic(_ReturnAddress) |
Kostya Serebryany | 1b5ea8f | 2012-08-28 14:11:57 +0000 | [diff] [blame] | 286 | # define GET_CALLER_PC() (uptr)_ReturnAddress() |
| 287 | // CaptureStackBackTrace doesn't need to know BP on Windows. |
| 288 | // FIXME: This macro is still used when printing error reports though it's not |
| 289 | // clear if the BP value is needed in the ASan reports on Windows. |
| 290 | # define GET_CURRENT_FRAME() (uptr)0xDEADBEEF |
| 291 | #endif |
| 292 | |
Peter Collingbourne | 9578a3e | 2013-05-08 14:43:49 +0000 | [diff] [blame] | 293 | #define HANDLE_EINTR(res, f) \ |
| 294 | { \ |
| 295 | int rverrno; \ |
| 296 | do { \ |
| 297 | res = (f); \ |
| 298 | } while (internal_iserror(res, &rverrno) && rverrno == EINTR); \ |
Evgeniy Stepanov | 3334e12 | 2012-10-02 13:41:40 +0000 | [diff] [blame] | 299 | } |
| 300 | |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 301 | // Forces the compiler to generate a frame pointer in the function. |
| 302 | #define ENABLE_FRAME_POINTER \ |
| 303 | do { \ |
| 304 | volatile uptr enable_fp; \ |
| 305 | enable_fp = GET_CURRENT_FRAME(); \ |
| 306 | (void)enable_fp; \ |
| 307 | } while (0) |
| 308 | |
Kostya Serebryany | 9aead37 | 2012-05-31 14:11:07 +0000 | [diff] [blame] | 309 | #endif // SANITIZER_DEFS_H |