1#ifndef TSAN_INTERCEPTORS_H
2#define TSAN_INTERCEPTORS_H
3
4#include "sanitizer_common/sanitizer_stacktrace.h"
5#include "tsan_rtl.h"
6
7namespace __tsan {
8
9class 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
22LibIgnore *libignore();
23
24#if !SANITIZER_GO
25INLINE bool in_symbolizer() {
26  cur_thread_init();
27  return UNLIKELY(cur_thread()->in_symbolizer);
28}
29#endif
30
31}  // namespace __tsan
32
33#define SCOPED_INTERCEPTOR_RAW(func, ...) \
34    cur_thread_init(); \
35    ThreadState *thr = cur_thread(); \
36    const uptr caller_pc = GET_CALLER_PC(); \
37    ScopedInterceptor si(thr, #func, caller_pc); \
38    const uptr pc = StackTrace::GetCurrentPc(); \
39    (void)pc; \
40/**/
41
42#define SCOPED_TSAN_INTERCEPTOR(func, ...) \
43    SCOPED_INTERCEPTOR_RAW(func, __VA_ARGS__); \
44    if (REAL(func) == 0) { \
45      Report("FATAL: ThreadSanitizer: failed to intercept %s\n", #func); \
46      Die(); \
47    }                                                    \
48    if (!thr->is_inited || thr->ignore_interceptors || thr->in_ignored_lib) \
49      return REAL(func)(__VA_ARGS__); \
50/**/
51
52#define SCOPED_TSAN_INTERCEPTOR_USER_CALLBACK_START() \
53    si.DisableIgnores();
54
55#define SCOPED_TSAN_INTERCEPTOR_USER_CALLBACK_END() \
56    si.EnableIgnores();
57
58#define TSAN_INTERCEPTOR(ret, func, ...) INTERCEPTOR(ret, func, __VA_ARGS__)
59
60#if SANITIZER_NETBSD
61# define TSAN_INTERCEPTOR_NETBSD_ALIAS(ret, func, ...) \
62  TSAN_INTERCEPTOR(ret, __libc_##func, __VA_ARGS__) \
63  ALIAS(WRAPPER_NAME(pthread_##func));
64# define TSAN_INTERCEPTOR_NETBSD_ALIAS_THR(ret, func, ...) \
65  TSAN_INTERCEPTOR(ret, __libc_thr_##func, __VA_ARGS__) \
66  ALIAS(WRAPPER_NAME(pthread_##func));
67# define TSAN_INTERCEPTOR_NETBSD_ALIAS_THR2(ret, func, func2, ...) \
68  TSAN_INTERCEPTOR(ret, __libc_thr_##func, __VA_ARGS__) \
69  ALIAS(WRAPPER_NAME(pthread_##func2));
70#else
71# define TSAN_INTERCEPTOR_NETBSD_ALIAS(ret, func, ...)
72# define TSAN_INTERCEPTOR_NETBSD_ALIAS_THR(ret, func, ...)
73# define TSAN_INTERCEPTOR_NETBSD_ALIAS_THR2(ret, func, func2, ...)
74#endif
75
76#endif  // TSAN_INTERCEPTORS_H
77