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 + +// 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 + +// 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 similarity index 89% rename from libc/arch-arm64/bionic/__rt_sigreturn.S rename to 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 -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 + +// 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 + +// 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 similarity index 87% rename from libc/arch-x86_64/bionic/__rt_sigreturn.S rename to 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 -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(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 +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 }