[llvm-commits] [compiler-rt] r158051 - in /compiler-rt/trunk/lib/asan: asan_internal.h asan_linux.cc asan_mac.cc asan_posix.cc asan_printf.cc asan_rtl.cc

Alexey Samsonov samsonov at google.com
Wed Jun 6 00:02:44 PDT 2012


Author: samsonov
Date: Wed Jun  6 02:02:44 2012
New Revision: 158051

URL: http://llvm.org/viewvc/llvm-project?rev=158051&view=rev
Log:
[ASan] Use __sanitizer::Die() in ASan runtime.

Modified:
    compiler-rt/trunk/lib/asan/asan_internal.h
    compiler-rt/trunk/lib/asan/asan_linux.cc
    compiler-rt/trunk/lib/asan/asan_mac.cc
    compiler-rt/trunk/lib/asan/asan_posix.cc
    compiler-rt/trunk/lib/asan/asan_printf.cc
    compiler-rt/trunk/lib/asan/asan_rtl.cc

Modified: compiler-rt/trunk/lib/asan/asan_internal.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_internal.h?rev=158051&r1=158050&r2=158051&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_internal.h (original)
+++ compiler-rt/trunk/lib/asan/asan_internal.h Wed Jun  6 02:02:44 2012
@@ -14,6 +14,7 @@
 #ifndef ASAN_INTERNAL_H
 #define ASAN_INTERNAL_H
 
+#include "sanitizer_common/sanitizer_common.h"
 #include "sanitizer_common/sanitizer_internal_defs.h"
 #include "sanitizer_common/sanitizer_libc.h"
 
@@ -209,14 +210,16 @@
 extern bool    FLAG_handle_segv;
 extern bool    FLAG_use_sigaltstack;
 extern bool    FLAG_check_malloc_usable_size;
+extern bool    FLAG_unmap_shadow_on_exit;
+extern bool    FLAG_abort_on_error;
 
 extern int asan_inited;
 // Used to avoid infinite recursion in __asan_init().
 extern bool asan_init_is_running;
+extern void (*death_callback)(void);
 
 enum LinkerInitialized { LINKER_INITIALIZED = 0 };
 
-void NORETURN AsanDie();
 void SleepForSeconds(int seconds);
 void NORETURN Exit(int exitcode);
 void NORETURN Abort();
@@ -229,7 +232,7 @@
 #define RAW_CHECK_MSG(expr, msg) do { \
   if (!(expr)) { \
     RawWrite(msg); \
-    AsanDie(); \
+    Die(); \
   } \
 } while (0)
 

Modified: compiler-rt/trunk/lib/asan/asan_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_linux.cc?rev=158051&r1=158050&r2=158051&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_linux.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_linux.cc Wed Jun  6 02:02:44 2012
@@ -104,7 +104,7 @@
   int res = internal_munmap(addr, size);
   if (res != 0) {
     Report("Failed to unmap\n");
-    AsanDie();
+    Die();
   }
 }
 

Modified: compiler-rt/trunk/lib/asan/asan_mac.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_mac.cc?rev=158051&r1=158050&r2=158051&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_mac.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_mac.cc Wed Jun  6 02:02:44 2012
@@ -128,7 +128,7 @@
   int res = internal_munmap(addr, size);
   if (res != 0) {
     Report("Failed to unmap\n");
-    AsanDie();
+    Die();
   }
 }
 

Modified: compiler-rt/trunk/lib/asan/asan_posix.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_posix.cc?rev=158051&r1=158050&r2=158051&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_posix.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_posix.cc Wed Jun  6 02:02:44 2012
@@ -83,7 +83,7 @@
 static void     ASAN_OnSIGSEGV(int, siginfo_t *siginfo, void *context) {
   uptr addr = (uptr)siginfo->si_addr;
   // Write the first message using the bullet-proof write.
-  if (13 != internal_write(2, "ASAN:SIGSEGV\n", 13)) AsanDie();
+  if (13 != internal_write(2, "ASAN:SIGSEGV\n", 13)) Die();
   uptr pc, sp, bp;
   GetPcSpBp(context, &pc, &sp, &bp);
   Report("ERROR: AddressSanitizer crashed on unknown address %p"

Modified: compiler-rt/trunk/lib/asan/asan_printf.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_printf.cc?rev=158051&r1=158050&r2=158051&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_printf.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_printf.cc Wed Jun  6 02:02:44 2012
@@ -31,7 +31,7 @@
   uptr length = (uptr)internal_strlen(buffer);
   if (length != internal_write(2, buffer, length)) {
     internal_write(2, kRawWriteError, internal_strlen(kRawWriteError));
-    AsanDie();
+    Die();
   }
   if (error_message_buffer) {
     int remaining = error_message_buffer_size - error_message_buffer_pos;

Modified: compiler-rt/trunk/lib/asan/asan_rtl.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_rtl.cc?rev=158051&r1=158050&r2=158051&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_rtl.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_rtl.cc Wed Jun  6 02:02:44 2012
@@ -23,6 +23,30 @@
 #include "asan_thread_registry.h"
 #include "sanitizer_common/sanitizer_libc.h"
 
+namespace __sanitizer {
+using namespace __asan;
+
+void Die() {
+  static int num_calls = 0;
+  if (AtomicInc(&num_calls) > 1) {
+    // Don't die twice - run a busy loop.
+    while (1) { }
+  }
+  if (FLAG_sleep_before_dying) {
+    Report("Sleeping for %d second(s)\n", FLAG_sleep_before_dying);
+    SleepForSeconds(FLAG_sleep_before_dying);
+  }
+  if (FLAG_unmap_shadow_on_exit)
+    AsanUnmapOrDie((void*)kLowShadowBeg, kHighShadowEnd - kLowShadowBeg);
+  if (death_callback)
+    death_callback();
+  if (FLAG_abort_on_error)
+    Abort();
+  Exit(FLAG_exitcode);
+}
+
+}  // namespace __sanitizer
+
 namespace __asan {
 
 // -------------------------- Flags ------------------------- {{{1
@@ -56,7 +80,7 @@
 // -------------------------- Globals --------------------- {{{1
 int asan_inited;
 bool asan_init_is_running;
-static void (*death_callback)(void);
+void (*death_callback)(void);
 static void (*error_report_callback)(const char*);
 char *error_message_buffer = 0;
 uptr error_message_buffer_pos = 0;
@@ -65,7 +89,7 @@
 // -------------------------- Misc ---------------- {{{1
 void ShowStatsAndAbort() {
   __asan_print_accumulated_stats();
-  AsanDie();
+  Die();
 }
 
 static void PrintBytes(const char *before, uptr *a) {
@@ -109,25 +133,6 @@
   return read_len;
 }
 
-void AsanDie() {
-  static int num_calls = 0;
-  if (AtomicInc(&num_calls) > 1) {
-    // Don't die twice - run a busy loop.
-    while (1) { }
-  }
-  if (FLAG_sleep_before_dying) {
-    Report("Sleeping for %d second(s)\n", FLAG_sleep_before_dying);
-    SleepForSeconds(FLAG_sleep_before_dying);
-  }
-  if (FLAG_unmap_shadow_on_exit)
-    AsanUnmapOrDie((void*)kLowShadowBeg, kHighShadowEnd - kLowShadowBeg);
-  if (death_callback)
-    death_callback();
-  if (FLAG_abort_on_error)
-    Abort();
-  Exit(FLAG_exitcode);
-}
-
 // ---------------------- mmap -------------------- {{{1
 void OutOfMemoryMessageAndDie(const char *mem_type, uptr size) {
   Report("ERROR: AddressSanitizer failed to allocate "
@@ -451,7 +456,7 @@
   if (error_report_callback) {
     error_report_callback(error_message_buffer);
   }
-  AsanDie();
+  Die();
 }
 
 static void ParseAsanOptions(const char *options) {
@@ -571,7 +576,7 @@
     Report("Shadow memory range interleaves with an existing memory mapping. "
            "ASan cannot proceed correctly. ABORTING.\n");
     AsanDumpProcessMap();
-    AsanDie();
+    Die();
   }
 
   InstallSignalHandlers();





More information about the llvm-commits mailing list