Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libc/arch/x86_64 Decorate the x86_64 signal trampoline w...
details: https://anonhg.NetBSD.org/src/rev/bfcff07602a1
branches: trunk
changeset: 977039:bfcff07602a1
user: kamil <kamil%NetBSD.org@localhost>
date: Mon Oct 12 17:55:53 2020 +0000
description:
Decorate the x86_64 signal trampoline with CFI attributes easing unwinding
Combine the approach provided by Nikhil Benesch and Andrew Cagney.
Now, the unwinders (in gccgo, backtrace(3), etc) can unwind properly
the stack from a signal handler.
Fixes lib/55719 by Nikhil Benesch
diffstat:
lib/libc/arch/x86_64/Makefile.inc | 4 ++-
lib/libc/arch/x86_64/genassym.cf | 45 ++++++++++++++++++++++++++++++++++
lib/libc/arch/x86_64/sys/__sigtramp2.S | 32 +++++++++++++++++++++--
3 files changed, 77 insertions(+), 4 deletions(-)
diffs (113 lines):
diff -r ac655687c437 -r bfcff07602a1 lib/libc/arch/x86_64/Makefile.inc
--- a/lib/libc/arch/x86_64/Makefile.inc Mon Oct 12 16:54:43 2020 +0000
+++ b/lib/libc/arch/x86_64/Makefile.inc Mon Oct 12 17:55:53 2020 +0000
@@ -1,5 +1,7 @@
-# $NetBSD: Makefile.inc,v 1.6 2015/07/15 14:27:49 pooka Exp $
+# $NetBSD: Makefile.inc,v 1.7 2020/10/12 17:55:53 kamil Exp $
.if ${RUMPRUN} != "yes"
SRCS+= __sigaction14_sigtramp.c __sigtramp2.S
.endif
+
+CPPFLAGS+= -I.
diff -r ac655687c437 -r bfcff07602a1 lib/libc/arch/x86_64/genassym.cf
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libc/arch/x86_64/genassym.cf Mon Oct 12 17:55:53 2020 +0000
@@ -0,0 +1,45 @@
+#
+# Copyright (c) 2020 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 <ucontext.h>
+
+define UC_GREGS_RAX offsetof(ucontext_t, uc_mcontext.__gregs[_REG_RAX])
+define UC_GREGS_RDX offsetof(ucontext_t, uc_mcontext.__gregs[_REG_RDX])
+define UC_GREGS_RCX offsetof(ucontext_t, uc_mcontext.__gregs[_REG_RCX])
+define UC_GREGS_RBX offsetof(ucontext_t, uc_mcontext.__gregs[_REG_RBX])
+define UC_GREGS_RSI offsetof(ucontext_t, uc_mcontext.__gregs[_REG_RSI])
+define UC_GREGS_RDI offsetof(ucontext_t, uc_mcontext.__gregs[_REG_RDI])
+define UC_GREGS_RBP offsetof(ucontext_t, uc_mcontext.__gregs[_REG_RBP])
+define UC_GREGS_RSP offsetof(ucontext_t, uc_mcontext.__gregs[_REG_RSP])
+define UC_GREGS_R8 offsetof(ucontext_t, uc_mcontext.__gregs[_REG_R8])
+define UC_GREGS_R9 offsetof(ucontext_t, uc_mcontext.__gregs[_REG_R9])
+define UC_GREGS_R10 offsetof(ucontext_t, uc_mcontext.__gregs[_REG_R10])
+define UC_GREGS_R11 offsetof(ucontext_t, uc_mcontext.__gregs[_REG_R11])
+define UC_GREGS_R12 offsetof(ucontext_t, uc_mcontext.__gregs[_REG_R12])
+define UC_GREGS_R13 offsetof(ucontext_t, uc_mcontext.__gregs[_REG_R13])
+define UC_GREGS_R14 offsetof(ucontext_t, uc_mcontext.__gregs[_REG_R14])
+define UC_GREGS_R15 offsetof(ucontext_t, uc_mcontext.__gregs[_REG_R15])
+define UC_GREGS_RIP offsetof(ucontext_t, uc_mcontext.__gregs[_REG_RIP])
diff -r ac655687c437 -r bfcff07602a1 lib/libc/arch/x86_64/sys/__sigtramp2.S
--- a/lib/libc/arch/x86_64/sys/__sigtramp2.S Mon Oct 12 16:54:43 2020 +0000
+++ b/lib/libc/arch/x86_64/sys/__sigtramp2.S Mon Oct 12 17:55:53 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: __sigtramp2.S,v 1.7 2019/12/02 01:38:54 christos Exp $ */
+/* $NetBSD: __sigtramp2.S,v 1.8 2020/10/12 17:55:54 kamil Exp $ */
/*
* Copyright (c) 2001 Wasabi Systems, Inc.
@@ -36,14 +36,40 @@
*/
#include "SYS.h"
+#include "assym.h"
/*
* The x86-64 signal trampoline is invoked only to return from
* the signal; the kernel calls the signal handler directly.
+ *
+ * The unwind entry includes the one byte prior to the trampoline
+ * because the unwinder will look up (return PC - 1) while unwinding.
+ * Normally (return PC - 1) computes an address inside the call
+ * instruction that created the child frame, but here there is no call
+ * instruction so we have to manually add padding.
*/
+ .cfi_startproc simple
+ .cfi_signal_frame
+ .cfi_def_cfa r15, 0
+ .cfi_offset rax, UC_GREGS_RAX
+ .cfi_offset rdx, UC_GREGS_RDX
+ .cfi_offset rcx, UC_GREGS_RCX
+ .cfi_offset rbx, UC_GREGS_RBX
+ .cfi_offset rsi, UC_GREGS_RSI
+ .cfi_offset rdi, UC_GREGS_RDI
+ .cfi_offset rbp, UC_GREGS_RBP
+ /* The unwinder will use the CFA to restore RSP. */
+ .cfi_offset r8, UC_GREGS_R8
+ .cfi_offset r9, UC_GREGS_R9
+ .cfi_offset r10, UC_GREGS_R10
+ .cfi_offset r11, UC_GREGS_R11
+ .cfi_offset r12, UC_GREGS_R12
+ .cfi_offset r13, UC_GREGS_R13
+ .cfi_offset r14, UC_GREGS_R14
+ .cfi_offset r15, UC_GREGS_R15
+ .cfi_offset rip, UC_GREGS_RIP
+ nop
NENTRY(__sigtramp_siginfo_2)
- .cfi_startproc
- .cfi_def_cfa rsp, 8
movq %r15,%rdi
movq $SYS_setcontext, %rax
syscall
Home |
Main Index |
Thread Index |
Old Index