From d8d490ed50272b62eb9721a007efd5a2e58e18f4 Mon Sep 17 00:00:00 2001 From: Alexander Potapenko Date: Tue, 28 Jan 2014 11:12:29 +0000 Subject: [ASan] Move the sigaltstack() bits to sanitizer_common. This change is a part of refactoring intended to have common signal handling behavior in all tools. Note that this particular change doesn't enable use_sigaltstack support in every tool. llvm-svn: 200310 --- .../sanitizer_common/sanitizer_posix_libcdep.cc | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cc') diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cc b/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cc index 6032f520dee..73b7886c21c 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cc @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -89,6 +90,33 @@ int internal_isatty(fd_t fd) { return isatty(fd); } +// TODO(glider): different tools may require different altstack size. +static const uptr kAltStackSize = SIGSTKSZ * 4; // SIGSTKSZ is not enough. + +void SetAlternateSignalStack() { + stack_t altstack, oldstack; + CHECK_EQ(0, sigaltstack(0, &oldstack)); + // If the alternate stack is already in place, do nothing. + if ((oldstack.ss_flags & SS_DISABLE) == 0) return; + // TODO(glider): the mapped stack should have the MAP_STACK flag in the + // future. It is not required by man 2 sigaltstack now (they're using + // malloc()). + void* base = MmapOrDie(kAltStackSize, __FUNCTION__); + altstack.ss_sp = base; + altstack.ss_flags = 0; + altstack.ss_size = kAltStackSize; + CHECK_EQ(0, sigaltstack(&altstack, 0)); +} + +void UnsetAlternateSignalStack() { + stack_t altstack, oldstack; + altstack.ss_sp = 0; + altstack.ss_flags = SS_DISABLE; + altstack.ss_size = 0; + CHECK_EQ(0, sigaltstack(&altstack, &oldstack)); + UnmapOrDie(oldstack.ss_sp, oldstack.ss_size); +} + } // namespace __sanitizer #endif -- cgit v1.2.3