annotate libsanitizer/sanitizer_common/sanitizer_internal_defs.h @ 158:494b0b89df80 default tip

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