diff options
-rw-r--r-- | compiler-rt/lib/asan/asan_posix.cc | 2 | ||||
-rw-r--r-- | compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cc | 11 | ||||
-rw-r--r-- | compiler-rt/test/asan/TestCases/Posix/handle_abort_on_error.cc | 9 |
3 files changed, 21 insertions, 1 deletions
diff --git a/compiler-rt/lib/asan/asan_posix.cc b/compiler-rt/lib/asan/asan_posix.cc index 84a29ec6a9d..6ff2b168139 100644 --- a/compiler-rt/lib/asan/asan_posix.cc +++ b/compiler-rt/lib/asan/asan_posix.cc @@ -88,6 +88,8 @@ void AsanOnDeadlySignal(int signo, void *siginfo, void *context) { ReportDeadlySignal("FPE", sig); else if (signo == SIGILL) ReportDeadlySignal("ILL", sig); + else if (signo == SIGABRT) + ReportDeadlySignal("ABRT", sig); else ReportDeadlySignal("SEGV", sig); } diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cc b/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cc index a1c26e47f59..773de69d4d9 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cc @@ -44,6 +44,8 @@ #define MAP_NORESERVE 0 #endif +typedef void (*sa_sigaction_t)(int, siginfo_t *, void *); + namespace __sanitizer { u32 GetUid() { @@ -126,6 +128,14 @@ void SleepForMillis(int millis) { } void Abort() { + // If we are handling SIGABRT, unhandle it first. + if (IsHandledDeadlySignal(SIGABRT)) { + struct sigaction sigact; + internal_memset(&sigact, 0, sizeof(sigact)); + sigact.sa_sigaction = (sa_sigaction_t)SIG_DFL; + internal_sigaction(SIGABRT, &sigact, nullptr); + } + abort(); } @@ -170,7 +180,6 @@ void UnsetAlternateSignalStack() { UnmapOrDie(oldstack.ss_sp, oldstack.ss_size); } -typedef void (*sa_sigaction_t)(int, siginfo_t *, void *); static void MaybeInstallSigaction(int signum, SignalHandlerType handler) { if (!IsHandledDeadlySignal(signum)) diff --git a/compiler-rt/test/asan/TestCases/Posix/handle_abort_on_error.cc b/compiler-rt/test/asan/TestCases/Posix/handle_abort_on_error.cc new file mode 100644 index 00000000000..fa8cdd4ce0c --- /dev/null +++ b/compiler-rt/test/asan/TestCases/Posix/handle_abort_on_error.cc @@ -0,0 +1,9 @@ +// Regression test: this used to abort() in SIGABRT handler in an infinite loop. +// RUN: %clangxx_asan -O0 %s -o %t && %env_asan_opts=handle_abort=1,abort_on_error=1 not --crash %run %t 2>&1 | FileCheck %s + +#include <stdlib.h> + +int main() { + abort(); + // CHECK: ERROR: AddressSanitizer: ABRT +} |