1 #ifndef TSAN_INTERCEPTORS_H
2 #define TSAN_INTERCEPTORS_H
4 #include "sanitizer_common/sanitizer_stacktrace.h"
9 class ScopedInterceptor
{
11 ScopedInterceptor(ThreadState
*thr
, const char *fname
, uptr pc
);
13 void DisableIgnores() {
14 if (UNLIKELY(ignoring_
))
17 void EnableIgnores() {
18 if (UNLIKELY(ignoring_
))
23 ThreadState
*const thr_
;
24 bool in_ignored_lib_
= false;
25 bool in_blocking_func_
= false;
26 bool ignoring_
= false;
28 void DisableIgnoresImpl();
29 void EnableIgnoresImpl();
32 LibIgnore
*libignore();
35 inline bool in_symbolizer() {
36 return UNLIKELY(cur_thread_init()->in_symbolizer
);
40 inline bool MustIgnoreInterceptor(ThreadState
*thr
) {
41 return !thr
->is_inited
|| thr
->ignore_interceptors
|| thr
->in_ignored_lib
;
46 #define SCOPED_INTERCEPTOR_RAW(func, ...) \
47 ThreadState *thr = cur_thread_init(); \
48 ScopedInterceptor si(thr, #func, GET_CALLER_PC()); \
49 UNUSED const uptr pc = GET_CURRENT_PC();
52 // Debugging of crashes on powerpc after commit:
53 // c80604f7a3 ("tsan: remove real func check from interceptors")
54 // Somehow replacing if with DCHECK leads to strange failures in:
55 // SanitizerCommon-tsan-powerpc64le-Linux :: Linux/ptrace.cpp
56 // https://lab.llvm.org/buildbot/#/builders/105
57 // https://lab.llvm.org/buildbot/#/builders/121
58 // https://lab.llvm.org/buildbot/#/builders/57
59 # define CHECK_REAL_FUNC(func) \
60 if (REAL(func) == 0) { \
61 Report("FATAL: ThreadSanitizer: failed to intercept %s\n", #func); \
65 # define CHECK_REAL_FUNC(func) DCHECK(REAL(func))
68 #define SCOPED_TSAN_INTERCEPTOR(func, ...) \
69 SCOPED_INTERCEPTOR_RAW(func, __VA_ARGS__); \
70 CHECK_REAL_FUNC(func); \
71 if (MustIgnoreInterceptor(thr)) \
72 return REAL(func)(__VA_ARGS__);
74 #define SCOPED_TSAN_INTERCEPTOR_USER_CALLBACK_START() \
77 #define SCOPED_TSAN_INTERCEPTOR_USER_CALLBACK_END() \
80 #define TSAN_INTERCEPTOR(ret, func, ...) INTERCEPTOR(ret, func, __VA_ARGS__)
83 # define TSAN_INTERCEPTOR_FREEBSD_ALIAS(ret, func, ...) \
84 TSAN_INTERCEPTOR(ret, _pthread_##func, __VA_ARGS__) \
85 ALIAS(WRAPPER_NAME(pthread_##func));
87 # define TSAN_INTERCEPTOR_FREEBSD_ALIAS(ret, func, ...)
91 # define TSAN_INTERCEPTOR_NETBSD_ALIAS(ret, func, ...) \
92 TSAN_INTERCEPTOR(ret, __libc_##func, __VA_ARGS__) \
93 ALIAS(WRAPPER_NAME(pthread_##func));
94 # define TSAN_INTERCEPTOR_NETBSD_ALIAS_THR(ret, func, ...) \
95 TSAN_INTERCEPTOR(ret, __libc_thr_##func, __VA_ARGS__) \
96 ALIAS(WRAPPER_NAME(pthread_##func));
97 # define TSAN_INTERCEPTOR_NETBSD_ALIAS_THR2(ret, func, func2, ...) \
98 TSAN_INTERCEPTOR(ret, __libc_thr_##func, __VA_ARGS__) \
99 ALIAS(WRAPPER_NAME(pthread_##func2));
101 # define TSAN_INTERCEPTOR_NETBSD_ALIAS(ret, func, ...)
102 # define TSAN_INTERCEPTOR_NETBSD_ALIAS_THR(ret, func, ...)
103 # define TSAN_INTERCEPTOR_NETBSD_ALIAS_THR2(ret, func, func2, ...)
106 #endif // TSAN_INTERCEPTORS_H