summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cc
diff options
context:
space:
mode:
authorAlexander Potapenko <glider@google.com>2014-01-28 11:12:29 +0000
committerAlexander Potapenko <glider@google.com>2014-01-28 11:12:29 +0000
commitd8d490ed50272b62eb9721a007efd5a2e58e18f4 (patch)
tree552fe02d2f339ade1f341f1ac4ba72740952b3e0 /compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cc
parent625b65a90c62e17881b3e64653d8fcbaff066a43 (diff)
downloadbcm5719-llvm-d8d490ed50272b62eb9721a007efd5a2e58e18f4.tar.gz
bcm5719-llvm-d8d490ed50272b62eb9721a007efd5a2e58e18f4.zip
[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
Diffstat (limited to 'compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cc')
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cc28
1 files changed, 28 insertions, 0 deletions
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 <errno.h>
#include <pthread.h>
+#include <signal.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/resource.h>
@@ -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
OpenPOWER on IntegriCloud