2016-10-21 Paul Thomas <pault@gcc.gnu.org>
[official-gcc.git] / libsanitizer / tsan / tsan_interceptors.h
blobed68eb96bf815d1bdb934466d332736f773eecef
1 #ifndef TSAN_INTERCEPTORS_H
2 #include "sanitizer_common/sanitizer_stacktrace.h"
3 #include "tsan_rtl.h"
5 namespace __tsan {
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_;
17 } // namespace __tsan
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 /**/
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 /**/
37 #define TSAN_INTERCEPTOR(ret, func, ...) INTERCEPTOR(ret, func, __VA_ARGS__)
39 #if SANITIZER_FREEBSD
40 #define __libc_free __free
41 #define __libc_malloc __malloc
42 #endif
44 extern "C" void __libc_free(void *ptr);
45 extern "C" void *__libc_malloc(uptr size);
47 #endif // TSAN_INTERCEPTORS_H