1 #ifndef TSAN_INTERCEPTORS_H 2 #include "sanitizer_common/sanitizer_stacktrace.h" 3 #include "tsan_rtl.h" 4 5 namespace __tsan { 6 7 class ScopedInterceptor { 8 public: 9 ScopedInterceptor(ThreadState *thr, const char *fname, uptr pc); 10 ~ScopedInterceptor(); 11 private: 12 ThreadState *const thr_; 13 const uptr pc_; 14 bool in_ignored_lib_; 15 }; 16 17 } // namespace __tsan 18 19 #define SCOPED_INTERCEPTOR_RAW(func, ...) \ 20 ThreadState *thr = cur_thread(); \ 21 const uptr caller_pc = GET_CALLER_PC(); \ 22 ScopedInterceptor si(thr, #func, caller_pc); \ 23 const uptr pc = StackTrace::GetCurrentPc(); \ 24 (void)pc; \ 25 /**/ 26 27 #define SCOPED_TSAN_INTERCEPTOR(func, ...) \ 28 SCOPED_INTERCEPTOR_RAW(func, __VA_ARGS__); \ 29 if (REAL(func) == 0) { \ 30 Report("FATAL: ThreadSanitizer: failed to intercept %s\n", #func); \ 31 Die(); \ 32 } \ 33 if (thr->ignore_interceptors || thr->in_ignored_lib) \ 34 return REAL(func)(__VA_ARGS__); \ 35 /**/ 36 37 #define TSAN_INTERCEPTOR(ret, func, ...) INTERCEPTOR(ret, func, __VA_ARGS__) 38 39 #if SANITIZER_FREEBSD 40 #define __libc_free __free 41 #define __libc_malloc __malloc 42 #endif 43 44 extern "C" void __libc_free(void *ptr); 45 extern "C" void *__libc_malloc(uptr size); 46 47 #endif // TSAN_INTERCEPTORS_H 48