annotate libsanitizer/sanitizer_common/sanitizer_internal_defs.h @ 144:8f4e72ab4e11

fix segmentation fault caused by nothing next cur_op to end
author Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Sun, 23 Dec 2018 21:23:56 +0900
parents 84e7813d76e9
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 //===-- sanitizer_internal_defs.h -------------------------------*- C++ -*-===//
kono
parents:
diff changeset
2 //
kono
parents:
diff changeset
3 // This file is distributed under the University of Illinois Open Source
kono
parents:
diff changeset
4 // License. See LICENSE.TXT for details.
kono
parents:
diff changeset
5 //
kono
parents:
diff changeset
6 //===----------------------------------------------------------------------===//
kono
parents:
diff changeset
7 //
kono
parents:
diff changeset
8 // This file is shared between AddressSanitizer and ThreadSanitizer.
kono
parents:
diff changeset
9 // It contains macro used in run-time libraries code.
kono
parents:
diff changeset
10 //===----------------------------------------------------------------------===//
kono
parents:
diff changeset
11 #ifndef SANITIZER_DEFS_H
kono
parents:
diff changeset
12 #define SANITIZER_DEFS_H
kono
parents:
diff changeset
13
kono
parents:
diff changeset
14 #include "sanitizer_platform.h"
kono
parents:
diff changeset
15
kono
parents:
diff changeset
16 #ifndef SANITIZER_DEBUG
kono
parents:
diff changeset
17 # define SANITIZER_DEBUG 0
kono
parents:
diff changeset
18 #endif
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 // Only use SANITIZER_*ATTRIBUTE* before the function return type!
kono
parents:
diff changeset
21 #if SANITIZER_WINDOWS
kono
parents:
diff changeset
22 #if SANITIZER_IMPORT_INTERFACE
kono
parents:
diff changeset
23 # define SANITIZER_INTERFACE_ATTRIBUTE __declspec(dllimport)
kono
parents:
diff changeset
24 #else
kono
parents:
diff changeset
25 # define SANITIZER_INTERFACE_ATTRIBUTE __declspec(dllexport)
kono
parents:
diff changeset
26 #endif
kono
parents:
diff changeset
27 # define SANITIZER_WEAK_ATTRIBUTE
kono
parents:
diff changeset
28 #elif SANITIZER_GO
kono
parents:
diff changeset
29 # define SANITIZER_INTERFACE_ATTRIBUTE
kono
parents:
diff changeset
30 # define SANITIZER_WEAK_ATTRIBUTE
kono
parents:
diff changeset
31 #else
kono
parents:
diff changeset
32 # define SANITIZER_INTERFACE_ATTRIBUTE __attribute__((visibility("default")))
kono
parents:
diff changeset
33 # define SANITIZER_WEAK_ATTRIBUTE __attribute__((weak))
kono
parents:
diff changeset
34 #endif
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 // TLS is handled differently on different platforms
kono
parents:
diff changeset
37 #if SANITIZER_LINUX
kono
parents:
diff changeset
38 # define SANITIZER_TLS_INITIAL_EXEC_ATTRIBUTE \
kono
parents:
diff changeset
39 __attribute__((tls_model("initial-exec"))) thread_local
kono
parents:
diff changeset
40 #else
kono
parents:
diff changeset
41 # define SANITIZER_TLS_INITIAL_EXEC_ATTRIBUTE
kono
parents:
diff changeset
42 #endif
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 //--------------------------- WEAK FUNCTIONS ---------------------------------//
kono
parents:
diff changeset
45 // When working with weak functions, to simplify the code and make it more
kono
parents:
diff changeset
46 // portable, when possible define a default implementation using this macro:
kono
parents:
diff changeset
47 //
kono
parents:
diff changeset
48 // SANITIZER_INTERFACE_WEAK_DEF(<return_type>, <name>, <parameter list>)
kono
parents:
diff changeset
49 //
kono
parents:
diff changeset
50 // For example:
kono
parents:
diff changeset
51 // SANITIZER_INTERFACE_WEAK_DEF(bool, compare, int a, int b) { return a > b; }
kono
parents:
diff changeset
52 //
kono
parents:
diff changeset
53 #if SANITIZER_WINDOWS
kono
parents:
diff changeset
54 #include "sanitizer_win_defs.h"
kono
parents:
diff changeset
55 # define SANITIZER_INTERFACE_WEAK_DEF(ReturnType, Name, ...) \
kono
parents:
diff changeset
56 WIN_WEAK_EXPORT_DEF(ReturnType, Name, __VA_ARGS__)
kono
parents:
diff changeset
57 #else
kono
parents:
diff changeset
58 # define SANITIZER_INTERFACE_WEAK_DEF(ReturnType, Name, ...) \
kono
parents:
diff changeset
59 extern "C" SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE \
kono
parents:
diff changeset
60 ReturnType Name(__VA_ARGS__)
kono
parents:
diff changeset
61 #endif
kono
parents:
diff changeset
62
kono
parents:
diff changeset
63 // SANITIZER_SUPPORTS_WEAK_HOOKS means that we support real weak functions that
kono
parents:
diff changeset
64 // will evaluate to a null pointer when not defined.
kono
parents:
diff changeset
65 #ifndef SANITIZER_SUPPORTS_WEAK_HOOKS
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
66 #if SANITIZER_LINUX && !SANITIZER_GO
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
67 # define SANITIZER_SUPPORTS_WEAK_HOOKS 1
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
68 // Before Xcode 4.5, the Darwin linker doesn't reliably support undefined
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
69 // weak symbols. Mac OS X 10.9/Darwin 13 is the first release only supported
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
70 // by Xcode >= 4.5.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
71 #elif SANITIZER_MAC && \
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
72 __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1090 && !SANITIZER_GO
111
kono
parents:
diff changeset
73 # define SANITIZER_SUPPORTS_WEAK_HOOKS 1
kono
parents:
diff changeset
74 #else
kono
parents:
diff changeset
75 # define SANITIZER_SUPPORTS_WEAK_HOOKS 0
kono
parents:
diff changeset
76 #endif
kono
parents:
diff changeset
77 #endif // SANITIZER_SUPPORTS_WEAK_HOOKS
kono
parents:
diff changeset
78 // For some weak hooks that will be called very often and we want to avoid the
kono
parents:
diff changeset
79 // overhead of executing the default implementation when it is not necessary,
kono
parents:
diff changeset
80 // we can use the flag SANITIZER_SUPPORTS_WEAK_HOOKS to only define the default
kono
parents:
diff changeset
81 // implementation for platforms that doesn't support weak symbols. For example:
kono
parents:
diff changeset
82 //
kono
parents:
diff changeset
83 // #if !SANITIZER_SUPPORT_WEAK_HOOKS
kono
parents:
diff changeset
84 // SANITIZER_INTERFACE_WEAK_DEF(bool, compare_hook, int a, int b) {
kono
parents:
diff changeset
85 // return a > b;
kono
parents:
diff changeset
86 // }
kono
parents:
diff changeset
87 // #endif
kono
parents:
diff changeset
88 //
kono
parents:
diff changeset
89 // And then use it as: if (compare_hook) compare_hook(a, b);
kono
parents:
diff changeset
90 //----------------------------------------------------------------------------//
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92
kono
parents:
diff changeset
93 // We can use .preinit_array section on Linux to call sanitizer initialization
kono
parents:
diff changeset
94 // functions very early in the process startup (unless PIC macro is defined).
kono
parents:
diff changeset
95 // FIXME: do we have anything like this on Mac?
kono
parents:
diff changeset
96 #if SANITIZER_LINUX && !SANITIZER_ANDROID && !defined(PIC)
kono
parents:
diff changeset
97 # define SANITIZER_CAN_USE_PREINIT_ARRAY 1
kono
parents:
diff changeset
98 #else
kono
parents:
diff changeset
99 # define SANITIZER_CAN_USE_PREINIT_ARRAY 0
kono
parents:
diff changeset
100 #endif
kono
parents:
diff changeset
101
kono
parents:
diff changeset
102 // GCC does not understand __has_feature
kono
parents:
diff changeset
103 #if !defined(__has_feature)
kono
parents:
diff changeset
104 # define __has_feature(x) 0
kono
parents:
diff changeset
105 #endif
kono
parents:
diff changeset
106
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
107 // Older GCCs do not understand __has_attribute.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
108 #if !defined(__has_attribute)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
109 # define __has_attribute(x) 0
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
110 #endif
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
111
111
kono
parents:
diff changeset
112 // For portability reasons we do not include stddef.h, stdint.h or any other
kono
parents:
diff changeset
113 // system header, but we do need some basic types that are not defined
kono
parents:
diff changeset
114 // in a portable way by the language itself.
kono
parents:
diff changeset
115 namespace __sanitizer {
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 #if defined(_WIN64)
kono
parents:
diff changeset
118 // 64-bit Windows uses LLP64 data model.
kono
parents:
diff changeset
119 typedef unsigned long long uptr; // NOLINT
kono
parents:
diff changeset
120 typedef signed long long sptr; // NOLINT
kono
parents:
diff changeset
121 #else
kono
parents:
diff changeset
122 typedef unsigned long uptr; // NOLINT
kono
parents:
diff changeset
123 typedef signed long sptr; // NOLINT
kono
parents:
diff changeset
124 #endif // defined(_WIN64)
kono
parents:
diff changeset
125 #if defined(__x86_64__)
kono
parents:
diff changeset
126 // Since x32 uses ILP32 data model in 64-bit hardware mode, we must use
kono
parents:
diff changeset
127 // 64-bit pointer to unwind stack frame.
kono
parents:
diff changeset
128 typedef unsigned long long uhwptr; // NOLINT
kono
parents:
diff changeset
129 #else
kono
parents:
diff changeset
130 typedef uptr uhwptr; // NOLINT
kono
parents:
diff changeset
131 #endif
kono
parents:
diff changeset
132 typedef unsigned char u8;
kono
parents:
diff changeset
133 typedef unsigned short u16; // NOLINT
kono
parents:
diff changeset
134 typedef unsigned int u32;
kono
parents:
diff changeset
135 typedef unsigned long long u64; // NOLINT
kono
parents:
diff changeset
136 typedef signed char s8;
kono
parents:
diff changeset
137 typedef signed short s16; // NOLINT
kono
parents:
diff changeset
138 typedef signed int s32;
kono
parents:
diff changeset
139 typedef signed long long s64; // NOLINT
kono
parents:
diff changeset
140 #if SANITIZER_WINDOWS
kono
parents:
diff changeset
141 // On Windows, files are HANDLE, which is a synonim of void*.
kono
parents:
diff changeset
142 // Use void* to avoid including <windows.h> everywhere.
kono
parents:
diff changeset
143 typedef void* fd_t;
kono
parents:
diff changeset
144 typedef unsigned error_t;
kono
parents:
diff changeset
145 #else
kono
parents:
diff changeset
146 typedef int fd_t;
kono
parents:
diff changeset
147 typedef int error_t;
kono
parents:
diff changeset
148 #endif
kono
parents:
diff changeset
149 typedef int pid_t;
kono
parents:
diff changeset
150
kono
parents:
diff changeset
151 #if SANITIZER_FREEBSD || SANITIZER_NETBSD || SANITIZER_MAC || \
kono
parents:
diff changeset
152 (SANITIZER_LINUX && defined(__x86_64__))
kono
parents:
diff changeset
153 typedef u64 OFF_T;
kono
parents:
diff changeset
154 #else
kono
parents:
diff changeset
155 typedef uptr OFF_T;
kono
parents:
diff changeset
156 #endif
kono
parents:
diff changeset
157 typedef u64 OFF64_T;
kono
parents:
diff changeset
158
kono
parents:
diff changeset
159 #if (SANITIZER_WORDSIZE == 64) || SANITIZER_MAC
kono
parents:
diff changeset
160 typedef uptr operator_new_size_type;
kono
parents:
diff changeset
161 #else
kono
parents:
diff changeset
162 # if defined(__s390__) && !defined(__s390x__)
kono
parents:
diff changeset
163 // Special case: 31-bit s390 has unsigned long as size_t.
kono
parents:
diff changeset
164 typedef unsigned long operator_new_size_type;
kono
parents:
diff changeset
165 # else
kono
parents:
diff changeset
166 typedef u32 operator_new_size_type;
kono
parents:
diff changeset
167 # endif
kono
parents:
diff changeset
168 #endif
kono
parents:
diff changeset
169
kono
parents:
diff changeset
170 #if SANITIZER_MAC
kono
parents:
diff changeset
171 // On Darwin, thread IDs are 64-bit even on 32-bit systems.
kono
parents:
diff changeset
172 typedef u64 tid_t;
kono
parents:
diff changeset
173 #else
kono
parents:
diff changeset
174 typedef uptr tid_t;
kono
parents:
diff changeset
175 #endif
kono
parents:
diff changeset
176
kono
parents:
diff changeset
177 // ----------- ATTENTION -------------
kono
parents:
diff changeset
178 // This header should NOT include any other headers to avoid portability issues.
kono
parents:
diff changeset
179
kono
parents:
diff changeset
180 // Common defs.
kono
parents:
diff changeset
181 #define INLINE inline
kono
parents:
diff changeset
182 #define INTERFACE_ATTRIBUTE SANITIZER_INTERFACE_ATTRIBUTE
kono
parents:
diff changeset
183 #define SANITIZER_WEAK_DEFAULT_IMPL \
kono
parents:
diff changeset
184 extern "C" SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE NOINLINE
kono
parents:
diff changeset
185 #define SANITIZER_WEAK_CXX_DEFAULT_IMPL \
kono
parents:
diff changeset
186 extern "C++" SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE NOINLINE
kono
parents:
diff changeset
187
kono
parents:
diff changeset
188 // Platform-specific defs.
kono
parents:
diff changeset
189 #if defined(_MSC_VER)
kono
parents:
diff changeset
190 # define ALWAYS_INLINE __forceinline
kono
parents:
diff changeset
191 // FIXME(timurrrr): do we need this on Windows?
kono
parents:
diff changeset
192 # define ALIAS(x)
kono
parents:
diff changeset
193 # define ALIGNED(x) __declspec(align(x))
kono
parents:
diff changeset
194 # define FORMAT(f, a)
kono
parents:
diff changeset
195 # define NOINLINE __declspec(noinline)
kono
parents:
diff changeset
196 # define NORETURN __declspec(noreturn)
kono
parents:
diff changeset
197 # define THREADLOCAL __declspec(thread)
kono
parents:
diff changeset
198 # define LIKELY(x) (x)
kono
parents:
diff changeset
199 # define UNLIKELY(x) (x)
kono
parents:
diff changeset
200 # define PREFETCH(x) /* _mm_prefetch(x, _MM_HINT_NTA) */ (void)0
kono
parents:
diff changeset
201 #else // _MSC_VER
kono
parents:
diff changeset
202 # define ALWAYS_INLINE inline __attribute__((always_inline))
kono
parents:
diff changeset
203 # define ALIAS(x) __attribute__((alias(x)))
kono
parents:
diff changeset
204 // Please only use the ALIGNED macro before the type.
kono
parents:
diff changeset
205 // Using ALIGNED after the variable declaration is not portable!
kono
parents:
diff changeset
206 # define ALIGNED(x) __attribute__((aligned(x)))
kono
parents:
diff changeset
207 # define FORMAT(f, a) __attribute__((format(printf, f, a)))
kono
parents:
diff changeset
208 # define NOINLINE __attribute__((noinline))
kono
parents:
diff changeset
209 # define NORETURN __attribute__((noreturn))
kono
parents:
diff changeset
210 # define THREADLOCAL __thread
kono
parents:
diff changeset
211 # define LIKELY(x) __builtin_expect(!!(x), 1)
kono
parents:
diff changeset
212 # define UNLIKELY(x) __builtin_expect(!!(x), 0)
kono
parents:
diff changeset
213 # if defined(__i386__) || defined(__x86_64__)
kono
parents:
diff changeset
214 // __builtin_prefetch(x) generates prefetchnt0 on x86
kono
parents:
diff changeset
215 # define PREFETCH(x) __asm__("prefetchnta (%0)" : : "r" (x))
kono
parents:
diff changeset
216 # else
kono
parents:
diff changeset
217 # define PREFETCH(x) __builtin_prefetch(x)
kono
parents:
diff changeset
218 # endif
kono
parents:
diff changeset
219 #endif // _MSC_VER
kono
parents:
diff changeset
220
kono
parents:
diff changeset
221 #if !defined(_MSC_VER) || defined(__clang__)
kono
parents:
diff changeset
222 # define UNUSED __attribute__((unused))
kono
parents:
diff changeset
223 # define USED __attribute__((used))
kono
parents:
diff changeset
224 #else
kono
parents:
diff changeset
225 # define UNUSED
kono
parents:
diff changeset
226 # define USED
kono
parents:
diff changeset
227 #endif
kono
parents:
diff changeset
228
kono
parents:
diff changeset
229 #if !defined(_MSC_VER) || defined(__clang__) || MSC_PREREQ(1900)
kono
parents:
diff changeset
230 # define NOEXCEPT noexcept
kono
parents:
diff changeset
231 #else
kono
parents:
diff changeset
232 # define NOEXCEPT throw()
kono
parents:
diff changeset
233 #endif
kono
parents:
diff changeset
234
kono
parents:
diff changeset
235 // Unaligned versions of basic types.
kono
parents:
diff changeset
236 typedef ALIGNED(1) u16 uu16;
kono
parents:
diff changeset
237 typedef ALIGNED(1) u32 uu32;
kono
parents:
diff changeset
238 typedef ALIGNED(1) u64 uu64;
kono
parents:
diff changeset
239 typedef ALIGNED(1) s16 us16;
kono
parents:
diff changeset
240 typedef ALIGNED(1) s32 us32;
kono
parents:
diff changeset
241 typedef ALIGNED(1) s64 us64;
kono
parents:
diff changeset
242
kono
parents:
diff changeset
243 #if SANITIZER_WINDOWS
kono
parents:
diff changeset
244 } // namespace __sanitizer
kono
parents:
diff changeset
245 typedef unsigned long DWORD; // NOLINT
kono
parents:
diff changeset
246 namespace __sanitizer {
kono
parents:
diff changeset
247 typedef DWORD thread_return_t;
kono
parents:
diff changeset
248 # define THREAD_CALLING_CONV __stdcall
kono
parents:
diff changeset
249 #else // _WIN32
kono
parents:
diff changeset
250 typedef void* thread_return_t;
kono
parents:
diff changeset
251 # define THREAD_CALLING_CONV
kono
parents:
diff changeset
252 #endif // _WIN32
kono
parents:
diff changeset
253 typedef thread_return_t (THREAD_CALLING_CONV *thread_callback_t)(void* arg);
kono
parents:
diff changeset
254
kono
parents:
diff changeset
255 // NOTE: Functions below must be defined in each run-time.
kono
parents:
diff changeset
256 void NORETURN Die();
kono
parents:
diff changeset
257
kono
parents:
diff changeset
258 // FIXME: No, this shouldn't be in the sanitizer interface.
kono
parents:
diff changeset
259 SANITIZER_INTERFACE_ATTRIBUTE
kono
parents:
diff changeset
260 void NORETURN CheckFailed(const char *file, int line, const char *cond,
kono
parents:
diff changeset
261 u64 v1, u64 v2);
kono
parents:
diff changeset
262
kono
parents:
diff changeset
263 // Check macro
kono
parents:
diff changeset
264 #define RAW_CHECK_MSG(expr, msg) do { \
kono
parents:
diff changeset
265 if (UNLIKELY(!(expr))) { \
kono
parents:
diff changeset
266 RawWrite(msg); \
kono
parents:
diff changeset
267 Die(); \
kono
parents:
diff changeset
268 } \
kono
parents:
diff changeset
269 } while (0)
kono
parents:
diff changeset
270
kono
parents:
diff changeset
271 #define RAW_CHECK(expr) RAW_CHECK_MSG(expr, #expr)
kono
parents:
diff changeset
272
kono
parents:
diff changeset
273 #define CHECK_IMPL(c1, op, c2) \
kono
parents:
diff changeset
274 do { \
kono
parents:
diff changeset
275 __sanitizer::u64 v1 = (__sanitizer::u64)(c1); \
kono
parents:
diff changeset
276 __sanitizer::u64 v2 = (__sanitizer::u64)(c2); \
kono
parents:
diff changeset
277 if (UNLIKELY(!(v1 op v2))) \
kono
parents:
diff changeset
278 __sanitizer::CheckFailed(__FILE__, __LINE__, \
kono
parents:
diff changeset
279 "(" #c1 ") " #op " (" #c2 ")", v1, v2); \
kono
parents:
diff changeset
280 } while (false) \
kono
parents:
diff changeset
281 /**/
kono
parents:
diff changeset
282
kono
parents:
diff changeset
283 #define CHECK(a) CHECK_IMPL((a), !=, 0)
kono
parents:
diff changeset
284 #define CHECK_EQ(a, b) CHECK_IMPL((a), ==, (b))
kono
parents:
diff changeset
285 #define CHECK_NE(a, b) CHECK_IMPL((a), !=, (b))
kono
parents:
diff changeset
286 #define CHECK_LT(a, b) CHECK_IMPL((a), <, (b))
kono
parents:
diff changeset
287 #define CHECK_LE(a, b) CHECK_IMPL((a), <=, (b))
kono
parents:
diff changeset
288 #define CHECK_GT(a, b) CHECK_IMPL((a), >, (b))
kono
parents:
diff changeset
289 #define CHECK_GE(a, b) CHECK_IMPL((a), >=, (b))
kono
parents:
diff changeset
290
kono
parents:
diff changeset
291 #if SANITIZER_DEBUG
kono
parents:
diff changeset
292 #define DCHECK(a) CHECK(a)
kono
parents:
diff changeset
293 #define DCHECK_EQ(a, b) CHECK_EQ(a, b)
kono
parents:
diff changeset
294 #define DCHECK_NE(a, b) CHECK_NE(a, b)
kono
parents:
diff changeset
295 #define DCHECK_LT(a, b) CHECK_LT(a, b)
kono
parents:
diff changeset
296 #define DCHECK_LE(a, b) CHECK_LE(a, b)
kono
parents:
diff changeset
297 #define DCHECK_GT(a, b) CHECK_GT(a, b)
kono
parents:
diff changeset
298 #define DCHECK_GE(a, b) CHECK_GE(a, b)
kono
parents:
diff changeset
299 #else
kono
parents:
diff changeset
300 #define DCHECK(a)
kono
parents:
diff changeset
301 #define DCHECK_EQ(a, b)
kono
parents:
diff changeset
302 #define DCHECK_NE(a, b)
kono
parents:
diff changeset
303 #define DCHECK_LT(a, b)
kono
parents:
diff changeset
304 #define DCHECK_LE(a, b)
kono
parents:
diff changeset
305 #define DCHECK_GT(a, b)
kono
parents:
diff changeset
306 #define DCHECK_GE(a, b)
kono
parents:
diff changeset
307 #endif
kono
parents:
diff changeset
308
kono
parents:
diff changeset
309 #define UNREACHABLE(msg) do { \
kono
parents:
diff changeset
310 CHECK(0 && msg); \
kono
parents:
diff changeset
311 Die(); \
kono
parents:
diff changeset
312 } while (0)
kono
parents:
diff changeset
313
kono
parents:
diff changeset
314 #define UNIMPLEMENTED() UNREACHABLE("unimplemented")
kono
parents:
diff changeset
315
kono
parents:
diff changeset
316 #define COMPILER_CHECK(pred) IMPL_COMPILER_ASSERT(pred, __LINE__)
kono
parents:
diff changeset
317
kono
parents:
diff changeset
318 #define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
kono
parents:
diff changeset
319
kono
parents:
diff changeset
320 #define IMPL_PASTE(a, b) a##b
kono
parents:
diff changeset
321 #define IMPL_COMPILER_ASSERT(pred, line) \
kono
parents:
diff changeset
322 typedef char IMPL_PASTE(assertion_failed_##_, line)[2*(int)(pred)-1]
kono
parents:
diff changeset
323
kono
parents:
diff changeset
324 // Limits for integral types. We have to redefine it in case we don't
kono
parents:
diff changeset
325 // have stdint.h (like in Visual Studio 9).
kono
parents:
diff changeset
326 #undef __INT64_C
kono
parents:
diff changeset
327 #undef __UINT64_C
kono
parents:
diff changeset
328 #if SANITIZER_WORDSIZE == 64
kono
parents:
diff changeset
329 # define __INT64_C(c) c ## L
kono
parents:
diff changeset
330 # define __UINT64_C(c) c ## UL
kono
parents:
diff changeset
331 #else
kono
parents:
diff changeset
332 # define __INT64_C(c) c ## LL
kono
parents:
diff changeset
333 # define __UINT64_C(c) c ## ULL
kono
parents:
diff changeset
334 #endif // SANITIZER_WORDSIZE == 64
kono
parents:
diff changeset
335 #undef INT32_MIN
kono
parents:
diff changeset
336 #define INT32_MIN (-2147483647-1)
kono
parents:
diff changeset
337 #undef INT32_MAX
kono
parents:
diff changeset
338 #define INT32_MAX (2147483647)
kono
parents:
diff changeset
339 #undef UINT32_MAX
kono
parents:
diff changeset
340 #define UINT32_MAX (4294967295U)
kono
parents:
diff changeset
341 #undef INT64_MIN
kono
parents:
diff changeset
342 #define INT64_MIN (-__INT64_C(9223372036854775807)-1)
kono
parents:
diff changeset
343 #undef INT64_MAX
kono
parents:
diff changeset
344 #define INT64_MAX (__INT64_C(9223372036854775807))
kono
parents:
diff changeset
345 #undef UINT64_MAX
kono
parents:
diff changeset
346 #define UINT64_MAX (__UINT64_C(18446744073709551615))
kono
parents:
diff changeset
347
kono
parents:
diff changeset
348 enum LinkerInitialized { LINKER_INITIALIZED = 0 };
kono
parents:
diff changeset
349
kono
parents:
diff changeset
350 #if !defined(_MSC_VER) || defined(__clang__)
kono
parents:
diff changeset
351 #if SANITIZER_S390_31
kono
parents:
diff changeset
352 #define GET_CALLER_PC() \
kono
parents:
diff changeset
353 (__sanitizer::uptr) __builtin_extract_return_addr(__builtin_return_address(0))
kono
parents:
diff changeset
354 #else
kono
parents:
diff changeset
355 #define GET_CALLER_PC() (__sanitizer::uptr) __builtin_return_address(0)
kono
parents:
diff changeset
356 #endif
kono
parents:
diff changeset
357 #define GET_CURRENT_FRAME() (__sanitizer::uptr) __builtin_frame_address(0)
kono
parents:
diff changeset
358 inline void Trap() {
kono
parents:
diff changeset
359 __builtin_trap();
kono
parents:
diff changeset
360 }
kono
parents:
diff changeset
361 #else
kono
parents:
diff changeset
362 extern "C" void* _ReturnAddress(void);
kono
parents:
diff changeset
363 extern "C" void* _AddressOfReturnAddress(void);
kono
parents:
diff changeset
364 # pragma intrinsic(_ReturnAddress)
kono
parents:
diff changeset
365 # pragma intrinsic(_AddressOfReturnAddress)
kono
parents:
diff changeset
366 #define GET_CALLER_PC() (__sanitizer::uptr) _ReturnAddress()
kono
parents:
diff changeset
367 // CaptureStackBackTrace doesn't need to know BP on Windows.
kono
parents:
diff changeset
368 #define GET_CURRENT_FRAME() \
kono
parents:
diff changeset
369 (((__sanitizer::uptr)_AddressOfReturnAddress()) + sizeof(__sanitizer::uptr))
kono
parents:
diff changeset
370
kono
parents:
diff changeset
371 extern "C" void __ud2(void);
kono
parents:
diff changeset
372 # pragma intrinsic(__ud2)
kono
parents:
diff changeset
373 inline void Trap() {
kono
parents:
diff changeset
374 __ud2();
kono
parents:
diff changeset
375 }
kono
parents:
diff changeset
376 #endif
kono
parents:
diff changeset
377
kono
parents:
diff changeset
378 #define HANDLE_EINTR(res, f) \
kono
parents:
diff changeset
379 { \
kono
parents:
diff changeset
380 int rverrno; \
kono
parents:
diff changeset
381 do { \
kono
parents:
diff changeset
382 res = (f); \
kono
parents:
diff changeset
383 } while (internal_iserror(res, &rverrno) && rverrno == EINTR); \
kono
parents:
diff changeset
384 }
kono
parents:
diff changeset
385
kono
parents:
diff changeset
386 // Forces the compiler to generate a frame pointer in the function.
kono
parents:
diff changeset
387 #define ENABLE_FRAME_POINTER \
kono
parents:
diff changeset
388 do { \
kono
parents:
diff changeset
389 volatile __sanitizer::uptr enable_fp; \
kono
parents:
diff changeset
390 enable_fp = GET_CURRENT_FRAME(); \
kono
parents:
diff changeset
391 (void)enable_fp; \
kono
parents:
diff changeset
392 } while (0)
kono
parents:
diff changeset
393
kono
parents:
diff changeset
394 } // namespace __sanitizer
kono
parents:
diff changeset
395
kono
parents:
diff changeset
396 namespace __asan { using namespace __sanitizer; } // NOLINT
kono
parents:
diff changeset
397 namespace __dsan { using namespace __sanitizer; } // NOLINT
kono
parents:
diff changeset
398 namespace __dfsan { using namespace __sanitizer; } // NOLINT
kono
parents:
diff changeset
399 namespace __esan { using namespace __sanitizer; } // NOLINT
kono
parents:
diff changeset
400 namespace __lsan { using namespace __sanitizer; } // NOLINT
kono
parents:
diff changeset
401 namespace __msan { using namespace __sanitizer; } // NOLINT
kono
parents:
diff changeset
402 namespace __tsan { using namespace __sanitizer; } // NOLINT
kono
parents:
diff changeset
403 namespace __scudo { using namespace __sanitizer; } // NOLINT
kono
parents:
diff changeset
404 namespace __ubsan { using namespace __sanitizer; } // NOLINT
kono
parents:
diff changeset
405 namespace __xray { using namespace __sanitizer; } // NOLINT
kono
parents:
diff changeset
406 namespace __interception { using namespace __sanitizer; } // NOLINT
kono
parents:
diff changeset
407
kono
parents:
diff changeset
408
kono
parents:
diff changeset
409 #endif // SANITIZER_DEFS_H