2015-10-21 09:32:45 +02:00
|
|
|
#ifndef TSAN_INTERCEPTORS_H
|
|
|
|
#include "sanitizer_common/sanitizer_stacktrace.h"
|
|
|
|
#include "tsan_rtl.h"
|
|
|
|
|
|
|
|
namespace __tsan {
|
|
|
|
|
|
|
|
class ScopedInterceptor {
|
|
|
|
public:
|
|
|
|
ScopedInterceptor(ThreadState *thr, const char *fname, uptr pc);
|
|
|
|
~ScopedInterceptor();
|
2016-11-08 23:04:09 +01:00
|
|
|
void UserCallbackStart();
|
|
|
|
void UserCallbackEnd();
|
2015-10-21 09:32:45 +02:00
|
|
|
private:
|
|
|
|
ThreadState *const thr_;
|
|
|
|
const uptr pc_;
|
|
|
|
bool in_ignored_lib_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace __tsan
|
|
|
|
|
|
|
|
#define SCOPED_INTERCEPTOR_RAW(func, ...) \
|
|
|
|
ThreadState *thr = cur_thread(); \
|
|
|
|
const uptr caller_pc = GET_CALLER_PC(); \
|
|
|
|
ScopedInterceptor si(thr, #func, caller_pc); \
|
|
|
|
const uptr pc = StackTrace::GetCurrentPc(); \
|
|
|
|
(void)pc; \
|
|
|
|
/**/
|
|
|
|
|
2015-11-23 10:07:18 +01:00
|
|
|
#define SCOPED_TSAN_INTERCEPTOR(func, ...) \
|
|
|
|
SCOPED_INTERCEPTOR_RAW(func, __VA_ARGS__); \
|
|
|
|
if (REAL(func) == 0) { \
|
|
|
|
Report("FATAL: ThreadSanitizer: failed to intercept %s\n", #func); \
|
|
|
|
Die(); \
|
|
|
|
} \
|
2016-11-08 23:04:09 +01:00
|
|
|
if (!thr->is_inited || thr->ignore_interceptors || thr->in_ignored_lib) \
|
2015-11-23 10:07:18 +01:00
|
|
|
return REAL(func)(__VA_ARGS__); \
|
|
|
|
/**/
|
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
#define SCOPED_TSAN_INTERCEPTOR_USER_CALLBACK_START() \
|
|
|
|
si.UserCallbackStart();
|
2015-11-23 10:07:18 +01:00
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
#define SCOPED_TSAN_INTERCEPTOR_USER_CALLBACK_END() \
|
|
|
|
si.UserCallbackEnd();
|
2015-10-21 09:32:45 +02:00
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
#define TSAN_INTERCEPTOR(ret, func, ...) INTERCEPTOR(ret, func, __VA_ARGS__)
|
2015-10-21 09:32:45 +02:00
|
|
|
|
|
|
|
#endif // TSAN_INTERCEPTORS_H
|