[tsan] move prctl interceptor from asan to common_interceptors thus enabling it for tsan too

llvm-svn: 172719
This commit is contained in:
Kostya Serebryany 2013-01-17 13:38:16 +00:00
parent fefb1e6257
commit f7f5566055
8 changed files with 44 additions and 44 deletions

View File

@ -42,10 +42,8 @@ using __sanitizer::uptr;
#if defined(__linux__)
# define ASAN_USE_ALIAS_ATTRIBUTE_FOR_INDEX 1
# define ASAN_INTERCEPT_PRCTL 1
#else
# define ASAN_USE_ALIAS_ATTRIBUTE_FOR_INDEX 0
# define ASAN_INTERCEPT_PRCTL 0
#endif
#if !defined(__APPLE__)

View File

@ -75,6 +75,12 @@ static inline uptr MaybeRealStrnlen(const char *s, uptr maxlen) {
return internal_strnlen(s, maxlen);
}
static void SetThreadName(const char *name) {
AsanThread *t = asanThreadRegistry().GetCurrent();
if (t)
t->summary()->set_name(name);
}
} // namespace __asan
// ---------------------- Wrappers ---------------- {{{1
@ -83,8 +89,9 @@ using namespace __asan; // NOLINT
#define COMMON_INTERCEPTOR_WRITE_RANGE(ptr, size) ASAN_WRITE_RANGE(ptr, size)
#define COMMON_INTERCEPTOR_READ_RANGE(ptr, size) ASAN_READ_RANGE(ptr, size)
#define COMMON_INTERCEPTOR_ENTER(func, ...) ENSURE_ASAN_INITED()
#define COMMON_INTERCEPTOR_FD_ACQUIRE(fd)
#define COMMON_INTERCEPTOR_FD_RELEASE(fd)
#define COMMON_INTERCEPTOR_FD_ACQUIRE(fd) do { } while (false)
#define COMMON_INTERCEPTOR_FD_RELEASE(fd) do { } while (false)
#define COMMON_INTERCEPTOR_SET_THREAD_NAME(name) SetThreadName(name)
#include "sanitizer_common/sanitizer_common_interceptors.h"
static thread_return_t THREAD_CALLING_CONV asan_thread_start(void *arg) {
@ -166,25 +173,6 @@ INTERCEPTOR(void, siglongjmp, void *env, int val) {
}
#endif
#if ASAN_INTERCEPT_PRCTL
#define PR_SET_NAME 15
INTERCEPTOR(int, prctl, int option,
unsigned long arg2, unsigned long arg3, // NOLINT
unsigned long arg4, unsigned long arg5) { // NOLINT
int res = REAL(prctl(option, arg2, arg3, arg4, arg5));
if (option == PR_SET_NAME) {
AsanThread *t = asanThreadRegistry().GetCurrent();
if (t) {
char buff[17];
internal_strncpy(buff, (char*)arg2, 16);
buff[16] = 0;
t->summary()->set_name(buff);
}
}
return res;
}
#endif
#if ASAN_INTERCEPT___CXA_THROW
INTERCEPTOR(void, __cxa_throw, void *a, void *b, void *c) {
CHECK(REAL(__cxa_throw));
@ -731,9 +719,6 @@ void InitializeAsanInterceptors() {
#if ASAN_INTERCEPT_SIGLONGJMP
ASAN_INTERCEPT_FUNC(siglongjmp);
#endif
#if ASAN_INTERCEPT_PRCTL
ASAN_INTERCEPT_FUNC(prctl);
#endif
// Intercept exception handling functions.
#if ASAN_INTERCEPT___CXA_THROW

View File

@ -17,6 +17,7 @@
// COMMON_INTERCEPTOR_WRITE_RANGE
// COMMON_INTERCEPTOR_FD_ACQUIRE
// COMMON_INTERCEPTOR_FD_RELEASE
// COMMON_INTERCEPTOR_SET_THREAD_NAME
//===----------------------------------------------------------------------===//
#ifndef SANITIZER_COMMON_INTERCEPTORS_H
#define SANITIZER_COMMON_INTERCEPTORS_H
@ -34,6 +35,9 @@ INTERCEPTOR(SSIZE_T, read, int fd, void *ptr, SIZE_T count) {
COMMON_INTERCEPTOR_FD_ACQUIRE(fd);
return res;
}
# define INIT_READ INTERCEPT_FUNCTION(read)
#else
# define INIT_READ
#endif
#if SANITIZER_INTERCEPT_PREAD
@ -46,6 +50,9 @@ INTERCEPTOR(SSIZE_T, pread, int fd, void *ptr, SIZE_T count, OFF_T offset) {
COMMON_INTERCEPTOR_FD_ACQUIRE(fd);
return res;
}
# define INIT_PREAD INTERCEPT_FUNCTION(pread)
#else
# define INIT_PREAD
#endif
#if SANITIZER_INTERCEPT_PREAD64
@ -58,29 +65,35 @@ INTERCEPTOR(SSIZE_T, pread64, int fd, void *ptr, SIZE_T count, OFF64_T offset) {
COMMON_INTERCEPTOR_FD_ACQUIRE(fd);
return res;
}
#endif
#if SANITIZER_INTERCEPT_READ
# define INIT_READ INTERCEPT_FUNCTION(read)
#else
# define INIT_READ
#endif
#if SANITIZER_INTERCEPT_PREAD
# define INIT_PREAD INTERCEPT_FUNCTION(pread)
#else
# define INIT_PREAD
#endif
#if SANITIZER_INTERCEPT_PREAD64
# define INIT_PREAD64 INTERCEPT_FUNCTION(pread64)
#else
# define INIT_PREAD64
#endif
#if SANITIZER_INTERCEPT_PRCTL
INTERCEPTOR(int, prctl, int option,
unsigned long arg2, unsigned long arg3, // NOLINT
unsigned long arg4, unsigned long arg5) { // NOLINT
COMMON_INTERCEPTOR_ENTER(prctl, option, arg2, arg3, arg4, arg5);
static const int PR_SET_NAME = 15;
int res = REAL(prctl(option, arg2, arg3, arg4, arg5));
if (option == PR_SET_NAME) {
char buff[16];
internal_strncpy(buff, (char*)arg2, 15);
buff[15] = 0;
COMMON_INTERCEPTOR_SET_THREAD_NAME(buff);
}
return res;
}
# define INIT_PRCTL INTERCEPT_FUNCTION(prctl)
#else
# define INIT_PRCTL
#endif // SANITIZER_INTERCEPT_PRCTL
#define SANITIZER_COMMON_INTERCEPTORS_INIT \
INIT_READ; \
INIT_PREAD; \
INIT_PREAD64; \
INIT_PRCTL; \
#endif // SANITIZER_COMMON_INTERCEPTORS_H

View File

@ -24,7 +24,9 @@
#if defined(__linux__) && !defined(ANDROID)
# define SANITIZER_INTERCEPT_PREAD64 1
# define SANITIZER_INTERCEPT_PRCTL 1
#else
# define SANITIZER_INTERCEPT_PRCTL 0
# define SANITIZER_INTERCEPT_PREAD64 0
#endif

View File

@ -15,8 +15,7 @@ void *Thread1(void *x) {
}
void *Thread2(void *x) {
AnnotateThreadName(__FILE__, __LINE__, "Thread2");
// TODO: pthread_setname_np(pthread_self(), "Thread2");
pthread_setname_np(pthread_self(), "Thread2");
Global--;
return NULL;
}

View File

@ -1623,9 +1623,10 @@ TSAN_INTERCEPTOR(int, fork, int fake) {
#define COMMON_INTERCEPTOR_READ_RANGE(ptr, size) \
MemoryAccessRange(thr, pc, (uptr)ptr, size, false)
#define COMMON_INTERCEPTOR_ENTER(func, ...) \
SCOPED_TSAN_INTERCEPTOR(func, __VA_ARGS__)
SCOPED_TSAN_INTERCEPTOR(func, __VA_ARGS__)
#define COMMON_INTERCEPTOR_FD_ACQUIRE(fd) FdAcquire(thr, pc, fd)
#define COMMON_INTERCEPTOR_FD_RELEASE(fd) FdRelease(thr, pc, fd)
#define COMMON_INTERCEPTOR_SET_THREAD_NAME(name) ThreadSetName(thr, name)
#include "sanitizer_common/sanitizer_common_interceptors.h"
namespace __tsan {

View File

@ -204,6 +204,7 @@ void StatOutput(u64 *stat) {
name[StatInt_pipe] = " pipe ";
name[StatInt_pipe2] = " pipe2 ";
name[StatInt_read] = " read ";
name[StatInt_prctl] = " prctl ";
name[StatInt_pread] = " pread ";
name[StatInt_pread64] = " pread64 ";
name[StatInt_readv] = " readv ";

View File

@ -199,6 +199,7 @@ enum StatType {
StatInt_pipe,
StatInt_pipe2,
StatInt_read,
StatInt_prctl,
StatInt_pread,
StatInt_pread64,
StatInt_readv,