[compiler-rt] r191903 - asan/msan/tsan: move _exit interceptor to common interceptors

Dmitry Vyukov dvyukov at google.com
Thu Oct 3 08:22:29 PDT 2013


Author: dvyukov
Date: Thu Oct  3 10:22:29 2013
New Revision: 191903

URL: http://llvm.org/viewvc/llvm-project?rev=191903&view=rev
Log:
asan/msan/tsan: move _exit interceptor to common interceptors


Modified:
    compiler-rt/trunk/lib/asan/asan_interceptors.cc
    compiler-rt/trunk/lib/msan/msan_interceptors.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
    compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc

Modified: compiler-rt/trunk/lib/asan/asan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_interceptors.cc?rev=191903&r1=191902&r2=191903&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_interceptors.cc Thu Oct  3 10:22:29 2013
@@ -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,
   } 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)

Modified: compiler-rt/trunk/lib/msan/msan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_interceptors.cc?rev=191903&r1=191902&r2=191903&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_interceptors.cc Thu Oct  3 10:22:29 2013
@@ -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)

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=191903&r1=191902&r2=191903&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Thu Oct  3 10:22:29 2013
@@ -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,
 #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,
   INIT_SIGSETOPS;                          \
   INIT_SIGPENDING;                         \
   INIT_SIGPROCMASK;                        \
-  INIT_BACKTRACE;
+  INIT_BACKTRACE;                          \
+  INIT__EXIT;                              \
+/**/

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=191903&r1=191902&r2=191903&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Thu Oct  3 10:22:29 2013
@@ -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

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc?rev=191903&r1=191902&r2=191903&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc Thu Oct  3 10:22:29 2013
@@ -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, i
   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);





More information about the llvm-commits mailing list