Fix signal trampolines.
* LP32 should use sa_restorer too. gdb expects this, and future (>= 3.15) x86
kernels will apparently stop supporting the case where SA_RESTORER isn't
set.
* gdb and libunwind care about the exact instruction sequences, so we need to
modify the code slightly in a few cases to match what they're looking for.
* gdb also cares about the exact function names (for some architectures),
so we need to use __restore and __restore_rt rather than __sigreturn and
__rt_sigreturn.
* It's possible that we don't have a VDSO; dl_iterate_phdr shouldn't assume
that getauxval(AT_SYSINFO_EHDR) will return a non-null pointer.
This fixes unwinding through a signal handler in gdb for all architectures.
It doesn't fix libunwind for arm and arm64. I'll keep investigating that...
Bug: 17436734
Change-Id: Ic1ea1184db6655c5d96180dc07bcc09628e647cb
diff --git a/libc/bionic/sigaction.cpp b/libc/bionic/sigaction.cpp
index e1a031f..920303b 100644
--- a/libc/bionic/sigaction.cpp
+++ b/libc/bionic/sigaction.cpp
@@ -28,8 +28,10 @@
#include <signal.h>
+extern "C" void __restore_rt(void);
+extern "C" void __restore(void);
+
#if __LP64__
-extern "C" void __rt_sigreturn(void);
extern "C" int __rt_sigaction(int, const struct __kernel_sigaction*, struct __kernel_sigaction*, size_t);
#else
extern "C" int __sigaction(int, const struct sigaction*, struct sigaction*);
@@ -47,7 +49,7 @@
if (!(kernel_new_action.sa_flags & SA_RESTORER)) {
kernel_new_action.sa_flags |= SA_RESTORER;
- kernel_new_action.sa_restorer = &__rt_sigreturn;
+ kernel_new_action.sa_restorer = &__restore_rt;
}
#endif
}
@@ -71,6 +73,20 @@
#else
// The 32-bit ABI is broken. struct sigaction includes a too-small sigset_t.
// TODO: if we also had correct struct sigaction definitions available, we could copy in and out.
- return __sigaction(signal, bionic_new_action, bionic_old_action);
+ struct sigaction kernel_new_action;
+ if (bionic_new_action != NULL) {
+ kernel_new_action.sa_flags = bionic_new_action->sa_flags;
+ kernel_new_action.sa_handler = bionic_new_action->sa_handler;
+ kernel_new_action.sa_mask = bionic_new_action->sa_mask;
+#ifdef SA_RESTORER
+ kernel_new_action.sa_restorer = bionic_new_action->sa_restorer;
+
+ if (!(kernel_new_action.sa_flags & SA_RESTORER)) {
+ kernel_new_action.sa_flags |= SA_RESTORER;
+ kernel_new_action.sa_restorer = (kernel_new_action.sa_flags & SA_SIGINFO) ? &__restore_rt : &__restore;
+ }
+#endif
+ }
+ return __sigaction(signal, (bionic_new_action != NULL) ? &kernel_new_action : NULL, bionic_old_action);
#endif
}