Home | History | Annotate | Line # | Download | only in rtl
      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 DisableIgnores();
     14   void EnableIgnores();
     15  private:
     16   ThreadState *const thr_;
     17   const uptr pc_;
     18   bool in_ignored_lib_;
     19   bool ignoring_;
     20 };
     21 
     22 LibIgnore *libignore();
     23 
     24 }  // namespace __tsan
     25 
     26 #define SCOPED_INTERCEPTOR_RAW(func, ...) \
     27     ThreadState *thr = cur_thread(); \
     28     const uptr caller_pc = GET_CALLER_PC(); \
     29     ScopedInterceptor si(thr, #func, caller_pc); \
     30     const uptr pc = StackTrace::GetCurrentPc(); \
     31     (void)pc; \
     32 /**/
     33 
     34 #define SCOPED_TSAN_INTERCEPTOR(func, ...) \
     35     SCOPED_INTERCEPTOR_RAW(func, __VA_ARGS__); \
     36     if (REAL(func) == 0) { \
     37       Report("FATAL: ThreadSanitizer: failed to intercept %s\n", #func); \
     38       Die(); \
     39     }                                                    \
     40     if (!thr->is_inited || thr->ignore_interceptors || thr->in_ignored_lib) \
     41       return REAL(func)(__VA_ARGS__); \
     42 /**/
     43 
     44 #define SCOPED_TSAN_INTERCEPTOR_USER_CALLBACK_START() \
     45     si.DisableIgnores();
     46 
     47 #define SCOPED_TSAN_INTERCEPTOR_USER_CALLBACK_END() \
     48     si.EnableIgnores();
     49 
     50 #define TSAN_INTERCEPTOR(ret, func, ...) INTERCEPTOR(ret, func, __VA_ARGS__)
     51 
     52 #if SANITIZER_NETBSD
     53 # define TSAN_INTERCEPTOR_NETBSD_ALIAS(ret, func, ...) \
     54   TSAN_INTERCEPTOR(ret, __libc_##func, __VA_ARGS__) \
     55   ALIAS(WRAPPER_NAME(pthread_##func));
     56 # define TSAN_INTERCEPTOR_NETBSD_ALIAS_THR(ret, func, ...) \
     57   TSAN_INTERCEPTOR(ret, __libc_thr_##func, __VA_ARGS__) \
     58   ALIAS(WRAPPER_NAME(pthread_##func));
     59 # define TSAN_INTERCEPTOR_NETBSD_ALIAS_THR2(ret, func, func2, ...) \
     60   TSAN_INTERCEPTOR(ret, __libc_thr_##func, __VA_ARGS__) \
     61   ALIAS(WRAPPER_NAME(pthread_##func2));
     62 #else
     63 # define TSAN_INTERCEPTOR_NETBSD_ALIAS(ret, func, ...)
     64 # define TSAN_INTERCEPTOR_NETBSD_ALIAS_THR(ret, func, ...)
     65 # define TSAN_INTERCEPTOR_NETBSD_ALIAS_THR2(ret, func, func2, ...)
     66 #endif
     67 
     68 #endif  // TSAN_INTERCEPTORS_H
     69