summaryrefslogtreecommitdiffstats
path: root/runtime/thread_linux.cc
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2013-07-16 14:19:52 -0700
committerElliott Hughes <enh@google.com>2013-07-16 14:19:52 -0700
commitd6a23bd327c38b08aaf6846d426fd6824fe9780b (patch)
tree73dd31e20ce3a6cf13d55e91bc89ab0638dbd5d1 /runtime/thread_linux.cc
parent1754938e68bf53d674ffac364336a5dd2f3a60f0 (diff)
downloadart-d6a23bd327c38b08aaf6846d426fd6824fe9780b.tar.gz
art-d6a23bd327c38b08aaf6846d426fd6824fe9780b.tar.bz2
art-d6a23bd327c38b08aaf6846d426fd6824fe9780b.zip
Don't manually mess with sigaltstack on Android any more.
Bionic now takes care of things. Bug: 8557703 Change-Id: I0510a193f2433eaf54c9c6ac3415c85b50a7f1d2
Diffstat (limited to 'runtime/thread_linux.cc')
-rw-r--r--runtime/thread_linux.cc37
1 files changed, 37 insertions, 0 deletions
diff --git a/runtime/thread_linux.cc b/runtime/thread_linux.cc
index 6f4b75dac1..1bd708ae45 100644
--- a/runtime/thread_linux.cc
+++ b/runtime/thread_linux.cc
@@ -26,4 +26,41 @@ int Thread::GetNativePriority() {
return kNormThreadPriority;
}
+static void SigAltStack(stack_t* new_stack, stack_t* old_stack) {
+ if (sigaltstack(new_stack, old_stack) == -1) {
+ PLOG(FATAL) << "sigaltstack failed";
+ }
+}
+
+void Thread::SetUpAlternateSignalStack() {
+ // Create and set an alternate signal stack.
+ stack_t ss;
+ ss.ss_sp = new uint8_t[SIGSTKSZ];
+ ss.ss_size = SIGSTKSZ;
+ ss.ss_flags = 0;
+ CHECK(ss.ss_sp != NULL);
+ SigAltStack(&ss, NULL);
+
+ // Double-check that it worked.
+ ss.ss_sp = NULL;
+ SigAltStack(NULL, &ss);
+ VLOG(threads) << "Alternate signal stack is " << PrettySize(ss.ss_size) << " at " << ss.ss_sp;
+}
+
+void Thread::TearDownAlternateSignalStack() {
+ // Get the pointer so we can free the memory.
+ stack_t ss;
+ SigAltStack(NULL, &ss);
+ uint8_t* allocated_signal_stack = reinterpret_cast<uint8_t*>(ss.ss_sp);
+
+ // Tell the kernel to stop using it.
+ ss.ss_sp = NULL;
+ ss.ss_flags = SS_DISABLE;
+ ss.ss_size = SIGSTKSZ; // Avoid ENOMEM failure with Mac OS' buggy libc.
+ SigAltStack(&ss, NULL);
+
+ // Free it.
+ delete[] allocated_signal_stack;
+}
+
} // namespace art