forked from OSchip/llvm-project
asan/msan/tsan: move _exit interceptor to common interceptors
llvm-svn: 191903
This commit is contained in:
parent
bfe7bb7034
commit
fdfb2ade8f
|
@ -94,6 +94,11 @@ void SetThreadName(const char *name) {
|
|||
asanThreadRegistry().SetThreadName(t->tid(), name);
|
||||
}
|
||||
|
||||
static int OnExit() {
|
||||
// FIXME: ask frontend whether we need to return failure.
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace __asan
|
||||
|
||||
// ---------------------- Wrappers ---------------- {{{1
|
||||
|
@ -126,6 +131,7 @@ DECLARE_REAL_AND_INTERCEPTOR(void, free, void *)
|
|||
} while (false)
|
||||
#define COMMON_INTERCEPTOR_SET_THREAD_NAME(ctx, name) SetThreadName(name)
|
||||
#define COMMON_INTERCEPTOR_BLOCK_REAL(name) REAL(name)
|
||||
#define COMMON_INTERCEPTOR_ON_EXIT(ctx) OnExit()
|
||||
#include "sanitizer_common/sanitizer_common_interceptors.inc"
|
||||
|
||||
#define COMMON_SYSCALL_PRE_READ_RANGE(p, s) ASAN_READ_RANGE(p, s)
|
||||
|
|
|
@ -1112,6 +1112,11 @@ struct MSanInterceptorContext {
|
|||
bool in_interceptor_scope;
|
||||
};
|
||||
|
||||
static int OnExit() {
|
||||
// FIXME: ask frontend whether we need to return failure.
|
||||
return 0;
|
||||
}
|
||||
|
||||
// A version of CHECK_UNPOISED using a saved scope value. Used in common
|
||||
// interceptors.
|
||||
#define CHECK_UNPOISONED_CTX(ctx, x, n) \
|
||||
|
@ -1148,6 +1153,7 @@ struct MSanInterceptorContext {
|
|||
do { \
|
||||
} while (false) // FIXME
|
||||
#define COMMON_INTERCEPTOR_BLOCK_REAL(name) REAL(name)
|
||||
#define COMMON_INTERCEPTOR_ON_EXIT(ctx) OnExit()
|
||||
#include "sanitizer_common/sanitizer_common_interceptors.inc"
|
||||
|
||||
#define COMMON_SYSCALL_PRE_READ_RANGE(p, s) CHECK_UNPOISONED(p, s)
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
// COMMON_INTERCEPTOR_FD_ACQUIRE
|
||||
// COMMON_INTERCEPTOR_FD_RELEASE
|
||||
// COMMON_INTERCEPTOR_SET_THREAD_NAME
|
||||
// COMMON_INTERCEPTOR_ON_EXIT
|
||||
//===----------------------------------------------------------------------===//
|
||||
#include "interception/interception.h"
|
||||
#include "sanitizer_platform_interceptors.h"
|
||||
|
@ -2159,6 +2160,20 @@ INTERCEPTOR(char **, backtrace_symbols, void **buffer, int size) {
|
|||
#define INIT_BACKTRACE
|
||||
#endif
|
||||
|
||||
#if SANITIZER_INTERCEPT__EXIT
|
||||
INTERCEPTOR(void, _exit, int status) {
|
||||
void *ctx;
|
||||
COMMON_INTERCEPTOR_ENTER(ctx, _exit, status);
|
||||
int status1 = COMMON_INTERCEPTOR_ON_EXIT(ctx);
|
||||
if (status == 0)
|
||||
status = status1;
|
||||
REAL(_exit)(status);
|
||||
}
|
||||
#define INIT__EXIT INTERCEPT_FUNCTION(_exit);
|
||||
#else
|
||||
#define INIT__EXIT
|
||||
#endif
|
||||
|
||||
#define SANITIZER_COMMON_INTERCEPTORS_INIT \
|
||||
INIT_STRCMP; \
|
||||
INIT_STRNCMP; \
|
||||
|
@ -2235,4 +2250,6 @@ INTERCEPTOR(char **, backtrace_symbols, void **buffer, int size) {
|
|||
INIT_SIGSETOPS; \
|
||||
INIT_SIGPENDING; \
|
||||
INIT_SIGPROCMASK; \
|
||||
INIT_BACKTRACE;
|
||||
INIT_BACKTRACE; \
|
||||
INIT__EXIT; \
|
||||
/**/
|
||||
|
|
|
@ -127,4 +127,6 @@
|
|||
# define SANITIZER_INTERCEPT_SIGPROCMASK SI_NOT_WINDOWS
|
||||
# define SANITIZER_INTERCEPT_BACKTRACE SI_LINUX_NOT_ANDROID
|
||||
|
||||
# define SANITIZER_INTERCEPT__EXIT SI_LINUX
|
||||
|
||||
#endif // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H
|
||||
|
|
|
@ -1852,6 +1852,12 @@ TSAN_INTERCEPTOR(int, fork, int fake) {
|
|||
return pid;
|
||||
}
|
||||
|
||||
static int OnExit(ThreadState *thr) {
|
||||
int status = Finalize(thr);
|
||||
REAL(fflush)(0);
|
||||
return status;
|
||||
}
|
||||
|
||||
struct TsanInterceptorContext {
|
||||
ThreadState *thr;
|
||||
const uptr caller_pc;
|
||||
|
@ -1893,6 +1899,8 @@ struct TsanInterceptorContext {
|
|||
#define COMMON_INTERCEPTOR_SET_THREAD_NAME(ctx, name) \
|
||||
ThreadSetName(((TsanInterceptorContext *) ctx)->thr, name)
|
||||
#define COMMON_INTERCEPTOR_BLOCK_REAL(name) BLOCK_REAL(name)
|
||||
#define COMMON_INTERCEPTOR_ON_EXIT(ctx) \
|
||||
OnExit(((TsanInterceptorContext *) ctx)->thr)
|
||||
#include "sanitizer_common/sanitizer_common_interceptors.inc"
|
||||
|
||||
#define TSAN_SYSCALL() \
|
||||
|
@ -1958,19 +1966,10 @@ static void syscall_post_fork(uptr pc, int res) {
|
|||
syscall_post_fork(GET_CALLER_PC(), res)
|
||||
#include "sanitizer_common/sanitizer_common_syscalls.inc"
|
||||
|
||||
TSAN_INTERCEPTOR(void, _exit, int status) {
|
||||
ThreadState * thr = cur_thread();
|
||||
int status1 = Finalize(thr);
|
||||
REAL(fflush)(0);
|
||||
if (status == 0)
|
||||
status = status1;
|
||||
REAL(_exit)(status);
|
||||
}
|
||||
|
||||
namespace __tsan {
|
||||
|
||||
static void finalize(void *arg) {
|
||||
ThreadState * thr = cur_thread();
|
||||
ThreadState *thr = cur_thread();
|
||||
uptr pc = 0;
|
||||
atexit_ctx->exit(thr, pc);
|
||||
int status = Finalize(thr);
|
||||
|
|
Loading…
Reference in New Issue