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