From fc81346321671489e2864f0614bf44b6af5d9bdb Mon Sep 17 00:00:00 2001 From: Alexey Samsonov Date: Thu, 17 Oct 2013 09:24:03 +0000 Subject: [Sanitizer] Move pthread_cond_signal and pthread_cond_broadcast to common interceptors git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@192876 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/msan/tests/msan_test.cc | 19 ++++++++++++++++--- .../sanitizer_common_interceptors.inc | 22 ++++++++++++++++++++++ lib/tsan/rtl/tsan_interceptors.cc | 16 ---------------- 3 files changed, 38 insertions(+), 19 deletions(-) diff --git a/lib/msan/tests/msan_test.cc b/lib/msan/tests/msan_test.cc index 385d6565..30ed04fe 100644 --- a/lib/msan/tests/msan_test.cc +++ b/lib/msan/tests/msan_test.cc @@ -2313,12 +2313,16 @@ namespace { struct SignalCondArg { pthread_cond_t* cond; pthread_mutex_t* mu; + bool broadcast; }; void *SignalCond(void *param) { SignalCondArg *arg = reinterpret_cast(param); pthread_mutex_lock(arg->mu); - pthread_cond_signal(arg->cond); + if (arg->broadcast) + pthread_cond_broadcast(arg->cond); + else + pthread_cond_signal(arg->cond); pthread_mutex_unlock(arg->mu); return 0; } @@ -2327,16 +2331,25 @@ void *SignalCond(void *param) { TEST(MemorySanitizer, pthread_cond_wait) { pthread_cond_t cond; pthread_mutex_t mu; - SignalCondArg args = {&cond, &mu}; + SignalCondArg args = {&cond, &mu, false}; pthread_cond_init(&cond, 0); pthread_mutex_init(&mu, 0); - pthread_mutex_lock(&mu); + + // signal pthread_t thr; pthread_create(&thr, 0, SignalCond, &args); int res = pthread_cond_wait(&cond, &mu); assert(!res); pthread_join(thr, 0); + + // broadcast + args.broadcast = true; + pthread_create(&thr, 0, SignalCond, &args); + res = pthread_cond_wait(&cond, &mu); + assert(!res); + pthread_join(thr, 0); + pthread_mutex_unlock(&mu); pthread_mutex_destroy(&mu); pthread_cond_destroy(&cond); diff --git a/lib/sanitizer_common/sanitizer_common_interceptors.inc b/lib/sanitizer_common/sanitizer_common_interceptors.inc index 11195ca3..a4ad9a7b 100644 --- a/lib/sanitizer_common/sanitizer_common_interceptors.inc +++ b/lib/sanitizer_common/sanitizer_common_interceptors.inc @@ -2243,13 +2243,33 @@ INTERCEPTOR(int, pthread_cond_init, void *c, void *a) { return REAL(pthread_cond_init)(c, a); } +INTERCEPTOR(int, pthread_cond_signal, void *c) { + void *ctx; + COMMON_INTERCEPTOR_ENTER(ctx, pthread_cond_signal, c); + COMMON_INTERCEPTOR_READ_RANGE(ctx, c, pthread_cond_t_sz); + return REAL(pthread_cond_signal)(c); +} + +INTERCEPTOR(int, pthread_cond_broadcast, void *c) { + void *ctx; + COMMON_INTERCEPTOR_ENTER(ctx, pthread_cond_broadcast, c); + COMMON_INTERCEPTOR_READ_RANGE(ctx, c, pthread_cond_t_sz); + return REAL(pthread_cond_broadcast)(c); +} + #define INIT_PTHREAD_COND_WAIT \ INTERCEPT_FUNCTION_VER(pthread_cond_wait, GLIBC_2.3.2) #define INIT_PTHREAD_COND_INIT \ INTERCEPT_FUNCTION_VER(pthread_cond_init, GLIBC_2.3.2) +#define INIT_PTHREAD_COND_SIGNAL \ + INTERCEPT_FUNCTION_VER(pthread_cond_signal, GLIBC_2.3.2) +#define INIT_PTHREAD_COND_BROADCAST \ + INTERCEPT_FUNCTION_VER(pthread_cond_broadcast, GLIBC_2.3.2) #else #define INIT_PTHREAD_COND_WAIT #define INIT_PTHREAD_COND_INIT +#define INIT_PTHREAD_COND_SIGNAL +#define INIT_PTHREAD_COND_BROADCAST #endif #define SANITIZER_COMMON_INTERCEPTORS_INIT \ @@ -2334,4 +2354,6 @@ INTERCEPTOR(int, pthread_cond_init, void *c, void *a) { INIT_PTHREAD_MUTEX_UNLOCK; \ INIT_PTHREAD_COND_WAIT; \ INIT_PTHREAD_COND_INIT; \ + INIT_PTHREAD_COND_SIGNAL; \ + INIT_PTHREAD_COND_BROADCAST; \ /**/ diff --git a/lib/tsan/rtl/tsan_interceptors.cc b/lib/tsan/rtl/tsan_interceptors.cc index d72fb94d..97742ddf 100644 --- a/lib/tsan/rtl/tsan_interceptors.cc +++ b/lib/tsan/rtl/tsan_interceptors.cc @@ -1093,20 +1093,6 @@ TSAN_INTERCEPTOR(int, pthread_cond_destroy, void *c) { return res; } -TSAN_INTERCEPTOR(int, pthread_cond_signal, void *c) { - SCOPED_TSAN_INTERCEPTOR(pthread_cond_signal, c); - MemoryRead(thr, pc, (uptr)c, kSizeLog1); - int res = REAL(pthread_cond_signal)(c); - return res; -} - -TSAN_INTERCEPTOR(int, pthread_cond_broadcast, void *c) { - SCOPED_TSAN_INTERCEPTOR(pthread_cond_broadcast, c); - MemoryRead(thr, pc, (uptr)c, kSizeLog1); - int res = REAL(pthread_cond_broadcast)(c); - return res; -} - TSAN_INTERCEPTOR(int, pthread_cond_timedwait, void *c, void *m, void *abstime) { SCOPED_TSAN_INTERCEPTOR(pthread_cond_timedwait, c, m, abstime); @@ -2091,8 +2077,6 @@ void InitializeInterceptors() { TSAN_INTERCEPT(pthread_rwlock_unlock); INTERCEPT_FUNCTION_VER(pthread_cond_destroy, GLIBC_2.3.2); - INTERCEPT_FUNCTION_VER(pthread_cond_signal, GLIBC_2.3.2); - INTERCEPT_FUNCTION_VER(pthread_cond_broadcast, GLIBC_2.3.2); INTERCEPT_FUNCTION_VER(pthread_cond_timedwait, GLIBC_2.3.2); TSAN_INTERCEPT(pthread_barrier_init); -- cgit v1.2.3