forked from OSchip/llvm-project
[ASan] Use __sanitizer::Die() in ASan runtime.
llvm-svn: 158051
This commit is contained in:
parent
bc3a7e3fe2
commit
c4b201308b
|
@ -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)
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue