[compiler-rt] r191898 - tsan: intercept _exit so that we can override exit status

Dmitry Vyukov dvyukov at google.com
Thu Oct 3 07:00:46 PDT 2013


Author: dvyukov
Date: Thu Oct  3 09:00:46 2013
New Revision: 191898

URL: http://llvm.org/viewvc/llvm-project?rev=191898&view=rev
Log:
tsan: intercept _exit so that we can override exit status


Modified:
    compiler-rt/trunk/lib/tsan/rtl/tsan_flags.h
    compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
    compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc
    compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_flags.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_flags.h?rev=191898&r1=191897&r2=191898&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_flags.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_flags.h Thu Oct  3 09:00:46 2013
@@ -75,6 +75,9 @@ struct Flags {
   int flush_memory_ms;
   // Flush symbolizer caches every X ms.
   int flush_symbolizer_ms;
+  // Resident memory limit in MB to aim at.
+  // If the process consumes more memory, then TSan will flush shadow memory.
+  int memory_limit_mb;
   // Stops on start until __tsan_resume() is called (for debugging).
   bool stop_on_start;
   // Controls whether RunningOnValgrind() returns true or false.

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=191898&r1=191897&r2=191898&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc Thu Oct  3 09:00:46 2013
@@ -1958,8 +1958,27 @@ 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();
+  uptr pc = 0;
+  atexit_ctx->exit(thr, pc);
+  int status = Finalize(thr);
+  REAL(fflush)(0);
+  if (status)
+    REAL(_exit)(status);
+}
+
 void ProcessPendingSignals(ThreadState *thr) {
   CHECK_EQ(thr->in_rtl, 0);
   SignalContext *sctx = SigCtx(thr);
@@ -2009,16 +2028,6 @@ void ProcessPendingSignals(ThreadState *
   thr->in_signal_handler = false;
 }
 
-static void finalize(void *arg) {
-  ThreadState * thr = cur_thread();
-  uptr pc = 0;
-  atexit_ctx->exit(thr, pc);
-  int status = Finalize(cur_thread());
-  REAL(fflush)(0);
-  if (status)
-    _exit(status);
-}
-
 static void unreachable() {
   Printf("FATAL: ThreadSanitizer: unreachable called\n");
   Die();
@@ -2199,6 +2208,7 @@ void InitializeInterceptors() {
   TSAN_INTERCEPT(dlclose);
   TSAN_INTERCEPT(on_exit);
   TSAN_INTERCEPT(__cxa_atexit);
+  TSAN_INTERCEPT(_exit);
 
   // Need to setup it, because interceptors check that the function is resolved.
   // But atexit is emitted directly into the module, so can't be resolved.

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc?rev=191898&r1=191897&r2=191898&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc Thu Oct  3 09:00:46 2013
@@ -142,6 +142,7 @@ void StatOutput(u64 *stat) {
   name[StatInt_strcasecmp]               = "  strcasecmp                      ";
   name[StatInt_strncasecmp]              = "  strncasecmp                     ";
   name[StatInt_atexit]                   = "  atexit                          ";
+  name[StatInt__exit]                    = "  _exit                           ";
   name[StatInt___cxa_guard_acquire]      = "  __cxa_guard_acquire             ";
   name[StatInt___cxa_guard_release]      = "  __cxa_guard_release             ";
   name[StatInt___cxa_guard_abort]        = "  __cxa_guard_abort               ";

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h?rev=191898&r1=191897&r2=191898&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h Thu Oct  3 09:00:46 2013
@@ -139,6 +139,7 @@ enum StatType {
   StatInt_strstr,
   StatInt_strdup,
   StatInt_atexit,
+  StatInt__exit,
   StatInt___cxa_guard_acquire,
   StatInt___cxa_guard_release,
   StatInt___cxa_guard_abort,





More information about the llvm-commits mailing list