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...
(cherry picked from commit 36f451a6d9
)
Bug: 17436734
Change-Id: Ic1ea1184db6655c5d96180dc07bcc09628e647cb
This commit is contained in:
parent
aa6cd5819c
commit
7dc2b7b30d
@ -55,6 +55,8 @@ libc_bionic_src_files_arm += \
|
|||||||
arch-arm/bionic/_exit_with_stack_teardown.S \
|
arch-arm/bionic/_exit_with_stack_teardown.S \
|
||||||
arch-arm/bionic/libgcc_compat.c \
|
arch-arm/bionic/libgcc_compat.c \
|
||||||
arch-arm/bionic/memcmp.S \
|
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/setjmp.S \
|
arch-arm/bionic/setjmp.S \
|
||||||
arch-arm/bionic/sigsetjmp.S \
|
arch-arm/bionic/sigsetjmp.S \
|
||||||
|
35
libc/arch-arm/bionic/__restore.S
Normal file
35
libc/arch-arm/bionic/__restore.S
Normal file
@ -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)
|
35
libc/arch-arm/bionic/__restore_rt.S
Normal file
35
libc/arch-arm/bionic/__restore_rt.S
Normal file
@ -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)
|
@ -29,7 +29,7 @@ libc_common_src_files_arm64 += \
|
|||||||
libc_bionic_src_files_arm64 := \
|
libc_bionic_src_files_arm64 := \
|
||||||
arch-arm64/bionic/__bionic_clone.S \
|
arch-arm64/bionic/__bionic_clone.S \
|
||||||
arch-arm64/bionic/_exit_with_stack_teardown.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/setjmp.S \
|
arch-arm64/bionic/setjmp.S \
|
||||||
arch-arm64/bionic/__set_tls.c \
|
arch-arm64/bionic/__set_tls.c \
|
||||||
|
@ -28,7 +28,8 @@
|
|||||||
|
|
||||||
#include <private/bionic_asm.h>
|
#include <private/bionic_asm.h>
|
||||||
|
|
||||||
ENTRY_PRIVATE(__rt_sigreturn)
|
// This function must have exactly this instruction sequence for gdb and libunwind.
|
||||||
mov x8, __NR_rt_sigreturn
|
ENTRY_PRIVATE(__restore_rt)
|
||||||
svc #0
|
mov x8, __NR_rt_sigreturn
|
||||||
END(__rt_sigreturn)
|
svc #0
|
||||||
|
END(__restore_rt)
|
37
libc/arch-x86/bionic/__restore.S
Normal file
37
libc/arch-x86/bionic/__restore.S
Normal file
@ -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)
|
36
libc/arch-x86/bionic/__restore_rt.S
Normal file
36
libc/arch-x86/bionic/__restore_rt.S
Normal file
@ -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)
|
@ -26,6 +26,8 @@ libc_bionic_src_files_x86 += \
|
|||||||
arch-x86/bionic/__bionic_clone.S \
|
arch-x86/bionic/__bionic_clone.S \
|
||||||
arch-x86/bionic/_exit_with_stack_teardown.S \
|
arch-x86/bionic/_exit_with_stack_teardown.S \
|
||||||
arch-x86/bionic/libgcc_compat.c \
|
arch-x86/bionic/libgcc_compat.c \
|
||||||
|
arch-x86/bionic/__restore_rt.S \
|
||||||
|
arch-x86/bionic/__restore.S \
|
||||||
arch-x86/bionic/_setjmp.S \
|
arch-x86/bionic/_setjmp.S \
|
||||||
arch-x86/bionic/setjmp.S \
|
arch-x86/bionic/setjmp.S \
|
||||||
arch-x86/bionic/__set_tls.c \
|
arch-x86/bionic/__set_tls.c \
|
||||||
|
@ -28,7 +28,9 @@
|
|||||||
|
|
||||||
#include <private/bionic_asm.h>
|
#include <private/bionic_asm.h>
|
||||||
|
|
||||||
ENTRY_PRIVATE(__rt_sigreturn)
|
// This function must have exactly this instruction sequence for gdb and libunwind.
|
||||||
movl $__NR_rt_sigreturn, %eax
|
// This function must have exactly this name for gdb.
|
||||||
|
ENTRY(__restore_rt)
|
||||||
|
mov $__NR_rt_sigreturn, %rax
|
||||||
syscall
|
syscall
|
||||||
END(__rt_sigreturn)
|
END(__restore_rt)
|
@ -30,7 +30,7 @@ libc_common_src_files_x86_64 += \
|
|||||||
libc_bionic_src_files_x86_64 := \
|
libc_bionic_src_files_x86_64 := \
|
||||||
arch-x86_64/bionic/__bionic_clone.S \
|
arch-x86_64/bionic/__bionic_clone.S \
|
||||||
arch-x86_64/bionic/_exit_with_stack_teardown.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/setjmp.S \
|
arch-x86_64/bionic/setjmp.S \
|
||||||
arch-x86_64/bionic/__set_tls.c \
|
arch-x86_64/bionic/__set_tls.c \
|
||||||
|
@ -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.
|
// Try the VDSO if that didn't work.
|
||||||
ElfW(Ehdr)* ehdr_vdso = reinterpret_cast<ElfW(Ehdr)*>(getauxval(AT_SYSINFO_EHDR));
|
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;
|
struct dl_phdr_info vdso_info;
|
||||||
vdso_info.dlpi_addr = 0;
|
vdso_info.dlpi_addr = 0;
|
||||||
vdso_info.dlpi_name = NULL;
|
vdso_info.dlpi_name = NULL;
|
||||||
|
@ -28,8 +28,10 @@
|
|||||||
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
|
extern "C" void __restore_rt(void);
|
||||||
|
extern "C" void __restore(void);
|
||||||
|
|
||||||
#if __LP64__
|
#if __LP64__
|
||||||
extern "C" void __rt_sigreturn(void);
|
|
||||||
extern "C" int __rt_sigaction(int, const struct __kernel_sigaction*, struct __kernel_sigaction*, size_t);
|
extern "C" int __rt_sigaction(int, const struct __kernel_sigaction*, struct __kernel_sigaction*, size_t);
|
||||||
#else
|
#else
|
||||||
extern "C" int __sigaction(int, const struct sigaction*, struct sigaction*);
|
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)) {
|
if (!(kernel_new_action.sa_flags & SA_RESTORER)) {
|
||||||
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
|
#endif
|
||||||
}
|
}
|
||||||
@ -75,6 +77,20 @@ int sigaction(int signal, const struct sigaction* bionic_new_action, struct siga
|
|||||||
#else
|
#else
|
||||||
// The 32-bit ABI is broken. struct sigaction includes a too-small sigset_t.
|
// 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.
|
// 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
|
#endif
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user