diff options
| author | Alexey Samsonov <samsonov@google.com> | 2012-06-06 07:02:44 +0000 | 
|---|---|---|
| committer | Alexey Samsonov <samsonov@google.com> | 2012-06-06 07:02:44 +0000 | 
| commit | c4b201308bdd19138c21b7b92db235a7ad0e4665 (patch) | |
| tree | b4c11ed488bfb6ec0219b1d889bbc4375046c390 | |
| parent | bc3a7e3fe2dcc1679672e37faeaca727f2634eec (diff) | |
| download | bcm5719-llvm-c4b201308bdd19138c21b7b92db235a7ad0e4665.tar.gz bcm5719-llvm-c4b201308bdd19138c21b7b92db235a7ad0e4665.zip  | |
[ASan] Use __sanitizer::Die() in ASan runtime.
llvm-svn: 158051
| -rw-r--r-- | compiler-rt/lib/asan/asan_internal.h | 7 | ||||
| -rw-r--r-- | compiler-rt/lib/asan/asan_linux.cc | 2 | ||||
| -rw-r--r-- | compiler-rt/lib/asan/asan_mac.cc | 2 | ||||
| -rw-r--r-- | compiler-rt/lib/asan/asan_posix.cc | 2 | ||||
| -rw-r--r-- | compiler-rt/lib/asan/asan_printf.cc | 2 | ||||
| -rw-r--r-- | compiler-rt/lib/asan/asan_rtl.cc | 51 | 
6 files changed, 37 insertions, 29 deletions
diff --git a/compiler-rt/lib/asan/asan_internal.h b/compiler-rt/lib/asan/asan_internal.h index a4578a6f2d2..0d1d208bfd5 100644 --- a/compiler-rt/lib/asan/asan_internal.h +++ b/compiler-rt/lib/asan/asan_internal.h @@ -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 s64 FLAG_sleep_before_dying;  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 @@ int Atexit(void (*function)(void));  #define RAW_CHECK_MSG(expr, msg) do { \    if (!(expr)) { \      RawWrite(msg); \ -    AsanDie(); \ +    Die(); \    } \  } while (0) diff --git a/compiler-rt/lib/asan/asan_linux.cc b/compiler-rt/lib/asan/asan_linux.cc index 87ff8317895..7661b8c069d 100644 --- a/compiler-rt/lib/asan/asan_linux.cc +++ b/compiler-rt/lib/asan/asan_linux.cc @@ -104,7 +104,7 @@ void AsanUnmapOrDie(void *addr, uptr size) {    int res = internal_munmap(addr, size);    if (res != 0) {      Report("Failed to unmap\n"); -    AsanDie(); +    Die();    }  } diff --git a/compiler-rt/lib/asan/asan_mac.cc b/compiler-rt/lib/asan/asan_mac.cc index d807778fa7e..ce23714fcf7 100644 --- a/compiler-rt/lib/asan/asan_mac.cc +++ b/compiler-rt/lib/asan/asan_mac.cc @@ -128,7 +128,7 @@ void AsanUnmapOrDie(void *addr, uptr size) {    int res = internal_munmap(addr, size);    if (res != 0) {      Report("Failed to unmap\n"); -    AsanDie(); +    Die();    }  } diff --git a/compiler-rt/lib/asan/asan_posix.cc b/compiler-rt/lib/asan/asan_posix.cc index 41b59dd5d93..762c340e631 100644 --- a/compiler-rt/lib/asan/asan_posix.cc +++ b/compiler-rt/lib/asan/asan_posix.cc @@ -83,7 +83,7 @@ static void MaybeInstallSigaction(int signum,  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" diff --git a/compiler-rt/lib/asan/asan_printf.cc b/compiler-rt/lib/asan/asan_printf.cc index be94fd8f508..e8ede765978 100644 --- a/compiler-rt/lib/asan/asan_printf.cc +++ b/compiler-rt/lib/asan/asan_printf.cc @@ -31,7 +31,7 @@ void RawWrite(const char *buffer) {    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; diff --git a/compiler-rt/lib/asan/asan_rtl.cc b/compiler-rt/lib/asan/asan_rtl.cc index 9c8201c18ba..d0dff1da04e 100644 --- a/compiler-rt/lib/asan/asan_rtl.cc +++ b/compiler-rt/lib/asan/asan_rtl.cc @@ -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 @@ bool    FLAG_check_malloc_usable_size = 1;  // -------------------------- 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 @@ uptr error_message_buffer_size = 0;  // -------------------------- Misc ---------------- {{{1  void ShowStatsAndAbort() {    __asan_print_accumulated_stats(); -  AsanDie(); +  Die();  }  static void PrintBytes(const char *before, uptr *a) { @@ -109,25 +133,6 @@ uptr ReadFileToBuffer(const char *file_name, char **buff,    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 @@ void __asan_report_error(uptr pc, uptr bp, uptr sp,    if (error_report_callback) {      error_report_callback(error_message_buffer);    } -  AsanDie(); +  Die();  }  static void ParseAsanOptions(const char *options) { @@ -571,7 +576,7 @@ void __asan_init() {      Report("Shadow memory range interleaves with an existing memory mapping. "             "ASan cannot proceed correctly. ABORTING.\n");      AsanDumpProcessMap(); -    AsanDie(); +    Die();    }    InstallSignalHandlers();  | 

