Index: lib/sanitizer_common/sanitizer_posix_libcdep.cc =================================================================== --- lib/sanitizer_common/sanitizer_posix_libcdep.cc +++ lib/sanitizer_common/sanitizer_posix_libcdep.cc @@ -189,25 +189,7 @@ static void MaybeInstallSigaction(int signum, SignalHandlerType handler) { - switch (GetHandleSignalMode(signum)) { - case kHandleSignalNo: - return; - case kHandleSignalYes: { - struct sigaction sigact; - internal_memset(&sigact, 0, sizeof(sigact)); - CHECK_EQ(0, internal_sigaction(signum, nullptr, &sigact)); - if (sigact.sa_flags & SA_SIGINFO) { - if (sigact.sa_sigaction) return; - } else { - if (sigact.sa_handler != SIG_DFL && sigact.sa_handler != SIG_IGN && - sigact.sa_handler != SIG_ERR) - return; - } - break; - } - case kHandleSignalExclusive: - break; - } + if (GetHandleSignalMode(signum) == kHandleSignalNo) return; struct sigaction sigact; internal_memset(&sigact, 0, sizeof(sigact)); Index: test/asan/TestCases/Linux/preinstalled_signal.cc =================================================================== --- test/asan/TestCases/Linux/preinstalled_signal.cc +++ test/asan/TestCases/Linux/preinstalled_signal.cc @@ -4,11 +4,13 @@ // RUN: env LD_PRELOAD=%shared_libasan %env_asan_opts=handle_segv=2 not %run %t 2>&1 | FileCheck %s // RUN: %clangxx -std=c++11 -DTEST_INSTALL_SIG_HANDLER %s -o %t -// RUN: env LD_PRELOAD=%shared_libasan %env_asan_opts=handle_segv=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-HANDLER %s +// RUN: env LD_PRELOAD=%shared_libasan %env_asan_opts=handle_segv=0 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-HANDLER +// RUN: env LD_PRELOAD=%shared_libasan %env_asan_opts=handle_segv=1 not %run %t 2>&1 | FileCheck %s // RUN: env LD_PRELOAD=%shared_libasan %env_asan_opts=handle_segv=2 not %run %t 2>&1 | FileCheck %s // RUN: %clangxx -std=c++11 -DTEST_INSTALL_SIG_ACTION %s -o %t -// RUN: env LD_PRELOAD=%shared_libasan %env_asan_opts=handle_segv=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ACTION %s +// RUN: env LD_PRELOAD=%shared_libasan %env_asan_opts=handle_segv=0 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-ACTION +// RUN: env LD_PRELOAD=%shared_libasan %env_asan_opts=handle_segv=1 not %run %t 2>&1 | FileCheck %s // RUN: env LD_PRELOAD=%shared_libasan %env_asan_opts=handle_segv=2 not %run %t 2>&1 | FileCheck %s // REQUIRES: asan-dynamic-runtime @@ -51,22 +53,22 @@ return syscall(__NR_rt_sigaction, sig, act, oact, NSIG / 8); } -struct KernelSigaction sigact = {}; +struct KernelSigaction pre_asan = {}; static void Init() { - int res = InternalSigaction(SIGSEGV, nullptr, &sigact); + int res = InternalSigaction(SIGSEGV, nullptr, &pre_asan); assert(res >= 0); - assert(sigact.handler == SIG_DFL || sigact.handler == SIG_IGN); + assert(pre_asan.handler == SIG_DFL || pre_asan.handler == SIG_IGN); #if defined(TEST_INSTALL_SIG_HANDLER) - sigact = {}; - sigact.handler = &SigHandler; - res = InternalSigaction(SIGSEGV, &sigact, nullptr); + pre_asan = {}; + pre_asan.handler = &SigHandler; + res = InternalSigaction(SIGSEGV, &pre_asan, nullptr); assert(res >= 0); #elif defined(TEST_INSTALL_SIG_ACTION) - sigact = {}; - sigact.flags = SA_SIGINFO | SA_NODEFER; - sigact.handler = (__sighandler_t)&SigAction; - res = InternalSigaction(SIGSEGV, &sigact, nullptr); + pre_asan = {}; + pre_asan.flags = SA_SIGINFO | SA_NODEFER; + pre_asan.handler = (__sighandler_t)&SigAction; + res = InternalSigaction(SIGSEGV, &pre_asan, nullptr); assert(res >= 0); #endif } @@ -74,21 +76,21 @@ __attribute__((section(".preinit_array"), used)) void (*__local_test_preinit)(void) = Init; -bool ShouldAsanInstallHandlers() { +bool ExpectUserHandler() { #if defined(TEST_INSTALL_SIG_HANDLER) || defined(TEST_INSTALL_SIG_ACTION) - return !strcmp(getenv("ASAN_OPTIONS"), "handle_segv=2"); + return !strcmp(getenv("ASAN_OPTIONS"), "handle_segv=0"); #endif - return true; + return false; } int main(int argc, char *argv[]) { - KernelSigaction sigact_asan = {}; - InternalSigaction(SIGSEGV, nullptr, &sigact_asan); + KernelSigaction post_asan = {}; + InternalSigaction(SIGSEGV, nullptr, &post_asan); - assert(sigact_asan.handler != SIG_DFL); - assert(sigact_asan.handler != SIG_IGN); - assert(ShouldAsanInstallHandlers() == - (sigact_asan.handler != sigact.handler)); + assert(post_asan.handler != SIG_DFL); + assert(post_asan.handler != SIG_IGN); + assert(ExpectUserHandler() == + (post_asan.handler == pre_asan.handler)); raise(SIGSEGV); printf("%s\n", handler);