aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2014-09-10 15:20:40 -0700
committerElliott Hughes <enh@google.com>2014-09-15 15:04:14 -0700
commit36f451a6d93b6807944d99fa23396e039c47e845 (patch)
tree116d52e5cb108eed51b2ff692844facb53f7b804
parent95b0c6a9407d7a4084d956e273ad1697550452d3 (diff)
downloadbionic-36f451a6d93b6807944d99fa23396e039c47e845.tar.gz
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
-rw-r--r--libc/arch-arm/arm.mk2
-rw-r--r--libc/arch-arm/bionic/__restore.S35
-rw-r--r--libc/arch-arm/bionic/__restore_rt.S35
-rw-r--r--libc/arch-arm64/arm64.mk2
-rw-r--r--libc/arch-arm64/bionic/__restore_rt.S (renamed from libc/arch-arm64/bionic/__rt_sigreturn.S)9
-rw-r--r--libc/arch-x86/bionic/__restore.S37
-rw-r--r--libc/arch-x86/bionic/__restore_rt.S36
-rw-r--r--libc/arch-x86/x86.mk2
-rw-r--r--libc/arch-x86_64/bionic/__restore_rt.S (renamed from libc/arch-x86_64/bionic/__rt_sigreturn.S)8
-rw-r--r--libc/arch-x86_64/x86_64.mk2
-rw-r--r--libc/bionic/dl_iterate_phdr_static.cpp5
-rw-r--r--libc/bionic/sigaction.cpp22
12 files changed, 183 insertions, 12 deletions
diff --git a/libc/arch-arm/arm.mk b/libc/arch-arm/arm.mk
index 70cc8eba6..fbde87cef 100644
--- a/libc/arch-arm/arm.mk
+++ b/libc/arch-arm/arm.mk
@@ -55,6 +55,8 @@ libc_bionic_src_files_arm += \
arch-arm/bionic/_exit_with_stack_teardown.S \
arch-arm/bionic/libgcc_compat.c \
arch-arm/bionic/memcmp.S \
+ arch-arm/bionic/__restore_rt.S \
+ arch-arm/bionic/__restore.S \
arch-arm/bionic/_setjmp.S \
arch-arm/bionic/setjmp.S \
arch-arm/bionic/sigsetjmp.S \
diff --git a/libc/arch-arm/bionic/__restore.S b/libc/arch-arm/bionic/__restore.S
new file mode 100644
index 000000000..e76628e16
--- /dev/null
+++ b/libc/arch-arm/bionic/__restore.S
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <private/bionic_asm.h>
+
+// This function must have exactly this instruction sequence for gdb and libunwind.
+ENTRY_PRIVATE(__restore)
+ mov r7, #__NR_sigreturn
+ swi #0
+END(__restore)
diff --git a/libc/arch-arm/bionic/__restore_rt.S b/libc/arch-arm/bionic/__restore_rt.S
new file mode 100644
index 000000000..5a1fca182
--- /dev/null
+++ b/libc/arch-arm/bionic/__restore_rt.S
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <private/bionic_asm.h>
+
+// This function must have exactly this instruction sequence for gdb and libunwind.
+ENTRY_PRIVATE(__restore_rt)
+ mov r7, #__NR_rt_sigreturn
+ swi #0
+END(__restore_rt)
diff --git a/libc/arch-arm64/arm64.mk b/libc/arch-arm64/arm64.mk
index 6c4f6a6e8..91cd9fb1c 100644
--- a/libc/arch-arm64/arm64.mk
+++ b/libc/arch-arm64/arm64.mk
@@ -29,7 +29,7 @@ libc_common_src_files_arm64 += \
libc_bionic_src_files_arm64 := \
arch-arm64/bionic/__bionic_clone.S \
arch-arm64/bionic/_exit_with_stack_teardown.S \
- arch-arm64/bionic/__rt_sigreturn.S \
+ arch-arm64/bionic/__restore_rt.S \
arch-arm64/bionic/_setjmp.S \
arch-arm64/bionic/setjmp.S \
arch-arm64/bionic/__set_tls.c \
diff --git a/libc/arch-arm64/bionic/__rt_sigreturn.S b/libc/arch-arm64/bionic/__restore_rt.S
index 8fb6f0c28..95064903e 100644
--- a/libc/arch-arm64/bionic/__rt_sigreturn.S
+++ b/libc/arch-arm64/bionic/__restore_rt.S
@@ -28,7 +28,8 @@
#include <private/bionic_asm.h>
-ENTRY_PRIVATE(__rt_sigreturn)
- mov x8, __NR_rt_sigreturn
- svc #0
-END(__rt_sigreturn)
+// This function must have exactly this instruction sequence for gdb and libunwind.
+ENTRY_PRIVATE(__restore_rt)
+ mov x8, __NR_rt_sigreturn
+ svc #0
+END(__restore_rt)
diff --git a/libc/arch-x86/bionic/__restore.S b/libc/arch-x86/bionic/__restore.S
new file mode 100644
index 000000000..755c3f8e5
--- /dev/null
+++ b/libc/arch-x86/bionic/__restore.S
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <private/bionic_asm.h>
+
+// This function must have exactly this instruction sequence for gdb and libunwind.
+// This function must have exactly this name for gdb.
+ENTRY(__restore)
+ popl %eax
+ movl $__NR_sigreturn, %eax
+ int $0x80
+END(__restore)
diff --git a/libc/arch-x86/bionic/__restore_rt.S b/libc/arch-x86/bionic/__restore_rt.S
new file mode 100644
index 000000000..0cd808125
--- /dev/null
+++ b/libc/arch-x86/bionic/__restore_rt.S
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <private/bionic_asm.h>
+
+// This function must have exactly this instruction sequence for gdb and libunwind.
+// This function must have exactly this name for gdb.
+ENTRY(__restore_rt)
+ movl $__NR_rt_sigreturn, %eax
+ int $0x80
+END(__restore_rt)
diff --git a/libc/arch-x86/x86.mk b/libc/arch-x86/x86.mk
index a14154866..f45eb658a 100644
--- a/libc/arch-x86/x86.mk
+++ b/libc/arch-x86/x86.mk
@@ -25,6 +25,8 @@ libc_bionic_src_files_x86 := \
libc_bionic_src_files_x86 += \
arch-x86/bionic/__bionic_clone.S \
arch-x86/bionic/_exit_with_stack_teardown.S \
+ arch-x86/bionic/__restore_rt.S \
+ arch-x86/bionic/__restore.S \
arch-x86/bionic/_setjmp.S \
arch-x86/bionic/setjmp.S \
arch-x86/bionic/__set_tls.c \
diff --git a/libc/arch-x86_64/bionic/__rt_sigreturn.S b/libc/arch-x86_64/bionic/__restore_rt.S
index eddceb15b..d84be219a 100644
--- a/libc/arch-x86_64/bionic/__rt_sigreturn.S
+++ b/libc/arch-x86_64/bionic/__restore_rt.S
@@ -28,7 +28,9 @@
#include <private/bionic_asm.h>
-ENTRY_PRIVATE(__rt_sigreturn)
- movl $__NR_rt_sigreturn, %eax
+// This function must have exactly this instruction sequence for gdb and libunwind.
+// This function must have exactly this name for gdb.
+ENTRY(__restore_rt)
+ mov $__NR_rt_sigreturn, %rax
syscall
-END(__rt_sigreturn)
+END(__restore_rt)
diff --git a/libc/arch-x86_64/x86_64.mk b/libc/arch-x86_64/x86_64.mk
index b001b5e98..5f12a49d7 100644
--- a/libc/arch-x86_64/x86_64.mk
+++ b/libc/arch-x86_64/x86_64.mk
@@ -30,7 +30,7 @@ libc_common_src_files_x86_64 += \
libc_bionic_src_files_x86_64 := \
arch-x86_64/bionic/__bionic_clone.S \
arch-x86_64/bionic/_exit_with_stack_teardown.S \
- arch-x86_64/bionic/__rt_sigreturn.S \
+ arch-x86_64/bionic/__restore_rt.S \
arch-x86_64/bionic/_setjmp.S \
arch-x86_64/bionic/setjmp.S \
arch-x86_64/bionic/__set_tls.c \
diff --git a/libc/bionic/dl_iterate_phdr_static.cpp b/libc/bionic/dl_iterate_phdr_static.cpp
index 155a7a00a..2196ac8b2 100644
--- a/libc/bionic/dl_iterate_phdr_static.cpp
+++ b/libc/bionic/dl_iterate_phdr_static.cpp
@@ -62,6 +62,11 @@ int dl_iterate_phdr(int (*cb)(struct dl_phdr_info* info, size_t size, void* data
// Try the VDSO if that didn't work.
ElfW(Ehdr)* ehdr_vdso = reinterpret_cast<ElfW(Ehdr)*>(getauxval(AT_SYSINFO_EHDR));
+ if (ehdr_vdso == nullptr) {
+ // There is no VDSO, so there's nowhere left to look.
+ return rc;
+ }
+
struct dl_phdr_info vdso_info;
vdso_info.dlpi_addr = 0;
vdso_info.dlpi_name = NULL;
diff --git a/libc/bionic/sigaction.cpp b/libc/bionic/sigaction.cpp
index e1a031ffc..920303b37 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 @@ int sigaction(int signal, const struct sigaction* bionic_new_action, struct siga
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 @@ int sigaction(int signal, const struct sigaction* bionic_new_action, struct siga
#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
}