[compiler-rt] r250752 - [msan] Intercept pthread_getcancel*.

Evgeniy Stepanov via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 19 16:00:13 PDT 2015


Author: eugenis
Date: Mon Oct 19 18:00:13 2015
New Revision: 250752

URL: http://llvm.org/viewvc/llvm-project?rev=250752&view=rev
Log:
[msan] Intercept pthread_getcancel*.

Added:
    compiler-rt/trunk/test/msan/pthread_setcancelstate.cc
Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc?rev=250752&r1=250751&r2=250752&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Mon Oct 19 18:00:13 2015
@@ -5194,6 +5194,31 @@ INTERCEPTOR(int, sem_getvalue, __sanitiz
 #define INIT_SEM
 #endif // SANITIZER_INTERCEPT_SEM
 
+#if SANITIZER_INTERCEPT_PTHREAD_SETCANCEL
+INTERCEPTOR(int, pthread_setcancelstate, int state, int *oldstate) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, pthread_setcancelstate, state, oldstate);
+  int res = REAL(pthread_setcancelstate)(state, oldstate);
+  if (res == 0)
+    COMMON_INTERCEPTOR_WRITE_RANGE(ctx, oldstate, sizeof(*oldstate));
+  return res;
+}
+
+INTERCEPTOR(int, pthread_setcanceltype, int type, int *oldtype) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, pthread_setcanceltype, type, oldtype);
+  int res = REAL(pthread_setcanceltype)(type, oldtype);
+  if (res == 0)
+    COMMON_INTERCEPTOR_WRITE_RANGE(ctx, oldtype, sizeof(*oldtype));
+  return res;
+}
+#define INIT_PTHREAD_SETCANCEL                                                 \
+  COMMON_INTERCEPT_FUNCTION(pthread_setcancelstate);                           \
+  COMMON_INTERCEPT_FUNCTION(pthread_setcanceltype);
+#else
+#define INIT_PTHREAD_SETCANCEL
+#endif
+
 static void InitializeCommonInterceptors() {
   static u64 metadata_mem[sizeof(MetadataHashMap) / sizeof(u64) + 1];
   interceptor_metadata_map = new((void *)&metadata_mem) MetadataHashMap();
@@ -5365,4 +5390,5 @@ static void InitializeCommonInterceptors
   INIT_MLOCKX;
   INIT_FOPENCOOKIE;
   INIT_SEM;
+  INIT_PTHREAD_SETCANCEL;
 }

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h?rev=250752&r1=250751&r2=250752&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Mon Oct 19 18:00:13 2015
@@ -257,6 +257,7 @@
 #define SANITIZER_INTERCEPT_MLOCKX SI_NOT_WINDOWS
 #define SANITIZER_INTERCEPT_FOPENCOOKIE SI_LINUX_NOT_ANDROID
 #define SANITIZER_INTERCEPT_SEM SI_LINUX || SI_FREEBSD
+#define SANITIZER_INTERCEPT_PTHREAD_SETCANCEL SI_NOT_WINDOWS
 
 #define SANITIZER_INTERCEPTOR_HOOKS SI_LINUX
 

Added: compiler-rt/trunk/test/msan/pthread_setcancelstate.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/msan/pthread_setcancelstate.cc?rev=250752&view=auto
==============================================================================
--- compiler-rt/trunk/test/msan/pthread_setcancelstate.cc (added)
+++ compiler-rt/trunk/test/msan/pthread_setcancelstate.cc Mon Oct 19 18:00:13 2015
@@ -0,0 +1,19 @@
+// RUN: %clangxx_msan -O0 %s -o %t && %run %t
+
+#include <assert.h>
+#include <pthread.h>
+#include <sanitizer/msan_interface.h>
+
+int main(void) {
+  int oldstate;
+  int oldtype;
+  int res = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate);
+  assert(res == 0);
+  __msan_check_mem_is_initialized(&oldstate, sizeof(oldstate));
+
+  res = pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldtype);
+  assert(res == 0);
+  __msan_check_mem_is_initialized(&oldtype, sizeof(oldtype));
+
+  return 0;
+}




More information about the llvm-commits mailing list