summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2013-01-17 13:38:16 +0000
committerKostya Serebryany <kcc@google.com>2013-01-17 13:38:16 +0000
commitf7f5566055bd9b455a2d628a2d659c0f376e50e3 (patch)
treebad3e772dc9659974400284203edcdcee84a53db
parentfefb1e625743e84068d01a66098d60814197bdbd (diff)
downloadbcm5719-llvm-f7f5566055bd9b455a2d628a2d659c0f376e50e3.tar.gz
bcm5719-llvm-f7f5566055bd9b455a2d628a2d659c0f376e50e3.zip
[tsan] move prctl interceptor from asan to common_interceptors thus enabling it for tsan too
llvm-svn: 172719
-rw-r--r--compiler-rt/lib/asan/asan_intercepted_functions.h2
-rw-r--r--compiler-rt/lib/asan/asan_interceptors.cc33
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.h43
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h2
-rw-r--r--compiler-rt/lib/tsan/lit_tests/thread_name.cc3
-rw-r--r--compiler-rt/lib/tsan/rtl/tsan_interceptors.cc3
-rw-r--r--compiler-rt/lib/tsan/rtl/tsan_stat.cc1
-rw-r--r--compiler-rt/lib/tsan/rtl/tsan_stat.h1
8 files changed, 44 insertions, 44 deletions
diff --git a/compiler-rt/lib/asan/asan_intercepted_functions.h b/compiler-rt/lib/asan/asan_intercepted_functions.h
index 1d82940530e..ff5acdbf3d7 100644
--- a/compiler-rt/lib/asan/asan_intercepted_functions.h
+++ b/compiler-rt/lib/asan/asan_intercepted_functions.h
@@ -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__)
diff --git a/compiler-rt/lib/asan/asan_interceptors.cc b/compiler-rt/lib/asan/asan_interceptors.cc
index a1d09e28d39..ee6975f0912 100644
--- a/compiler-rt/lib/asan/asan_interceptors.cc
+++ b/compiler-rt/lib/asan/asan_interceptors.cc
@@ -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
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.h
index 312e659b9b3..0381216bde4 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.h
@@ -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
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
index 57cf42f2637..1402060a1ae 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -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
diff --git a/compiler-rt/lib/tsan/lit_tests/thread_name.cc b/compiler-rt/lib/tsan/lit_tests/thread_name.cc
index 9a86f4f29ed..0ca0b176997 100644
--- a/compiler-rt/lib/tsan/lit_tests/thread_name.cc
+++ b/compiler-rt/lib/tsan/lit_tests/thread_name.cc
@@ -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;
}
diff --git a/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc b/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc
index e246d2be99d..7dc295d4093 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc
+++ b/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc
@@ -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 {
diff --git a/compiler-rt/lib/tsan/rtl/tsan_stat.cc b/compiler-rt/lib/tsan/rtl/tsan_stat.cc
index 645e1d0f5fc..7c205315f15 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_stat.cc
+++ b/compiler-rt/lib/tsan/rtl/tsan_stat.cc
@@ -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 ";
diff --git a/compiler-rt/lib/tsan/rtl/tsan_stat.h b/compiler-rt/lib/tsan/rtl/tsan_stat.h
index 397e6ee4675..d9e430eaefd 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_stat.h
+++ b/compiler-rt/lib/tsan/rtl/tsan_stat.h
@@ -199,6 +199,7 @@ enum StatType {
StatInt_pipe,
StatInt_pipe2,
StatInt_read,
+ StatInt_prctl,
StatInt_pread,
StatInt_pread64,
StatInt_readv,
OpenPOWER on IntegriCloud