Module Name:    src
Committed By:   thorpej
Date:           Wed Nov 24 15:05:16 UTC 2021

Modified Files:
        src/lib/libc/arch/vax: genassym.cf
        src/lib/libc/arch/vax/sys: __sigtramp3.S

Log Message:
Decorate the VAX signal trampoline with the appropriate .cfi
directives to allow exception unwind / backtrace across a signal
handler.

N.B. This is currently disabled, as these .cfi directives cause
linker warnings about incompatible TEXTREL relocations in .eh_frame.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/lib/libc/arch/vax/genassym.cf
cvs rdiff -u -r1.2 -r1.3 src/lib/libc/arch/vax/sys/__sigtramp3.S

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/arch/vax/genassym.cf
diff -u src/lib/libc/arch/vax/genassym.cf:1.5 src/lib/libc/arch/vax/genassym.cf:1.6
--- src/lib/libc/arch/vax/genassym.cf:1.5	Tue Jan 25 02:38:15 2011
+++ src/lib/libc/arch/vax/genassym.cf	Wed Nov 24 15:05:15 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: genassym.cf,v 1.5 2011/01/25 02:38:15 matt Exp $
+#	$NetBSD: genassym.cf,v 1.6 2021/11/24 15:05:15 thorpej Exp $
 
 #
 # Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -43,18 +43,25 @@ define _UC_SIGMASK	_UC_SIGMASK
 define _UC_STACK	_UC_STACK
 define _UC_CPU		_UC_CPU
 
-define _REG_R0		4*_REG_R0
-define _REG_R1		4*_REG_R1
-define _REG_R2		4*_REG_R2
-define _REG_R4		4*_REG_R4
-define _REG_R6		4*_REG_R6
-define _REG_R8		4*_REG_R8
-define _REG_R10		4*_REG_R10
-define _REG_AP		4*_REG_AP
-define _REG_SP		4*_REG_SP
-define _REG_FP		4*_REG_FP
-define _REG_PC		4*_REG_PC
-define _REG_PSL		4*_REG_PSL
+define _REG_R0		_REG_R0
+define _REG_R1		_REG_R1
+define _REG_R2		_REG_R2
+define _REG_R3		_REG_R3
+define _REG_R4		_REG_R4
+define _REG_R5		_REG_R5
+define _REG_R6		_REG_R6
+define _REG_R7		_REG_R7
+define _REG_R8		_REG_R8
+define _REG_R9		_REG_R9
+define _REG_R10		_REG_R10
+define _REG_R11		_REG_R11
+define _REG_AP		_REG_AP
+define _REG_FP		_REG_FP
+define _REG_SP		_REG_SP
+define _REG_PC		_REG_PC
+define _REG_PSL		_REG_PSL
+
+define SIZEOF_SIGINFO	sizeof(siginfo_t)
 
 define	SS_SP		offsetof(stack_t, ss_sp)
 define	SS_SIZE		offsetof(stack_t, ss_size)

Index: src/lib/libc/arch/vax/sys/__sigtramp3.S
diff -u src/lib/libc/arch/vax/sys/__sigtramp3.S:1.2 src/lib/libc/arch/vax/sys/__sigtramp3.S:1.3
--- src/lib/libc/arch/vax/sys/__sigtramp3.S:1.2	Tue Jan 25 02:38:15 2011
+++ src/lib/libc/arch/vax/sys/__sigtramp3.S	Wed Nov 24 15:05:16 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: __sigtramp3.S,v 1.2 2011/01/25 02:38:15 matt Exp $	*/
+/*	$NetBSD: __sigtramp3.S,v 1.3 2021/11/24 15:05:16 thorpej Exp $	*/
 
 /*
  * Copyright (c) 2003 Matt Thomas <m...@3am-software.com>
@@ -27,23 +27,70 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include "SYS.h"
+#include "assym.h"
+
+#ifdef SYSLIBC_SCCS
+RCSID("$NetBSD: __sigtramp3.S,v 1.3 2021/11/24 15:05:16 thorpej Exp $")
+#endif
+
 /*
  * Signal trampoline; registers when called:
  *	pc, psl - obvious
- *	sp, ap - points to argument list
- *	    4(ap) -- signo
- *	    8(ap) -- pointer to siginfo
- *	   12(ap) -- pointer to ucontext
+ *	sp, ap - points to a CALLG argument list
  *	fp - address of signal handler
+ *
+ * Stack is set up like so:
+ *		ucontext structure
+ *		siginfo structure
+ *		vvvv CALLG argument list vvvv
+ *		12(ap) -- pointer to ucontext
+ *		 8(ap) -- pointer to siginfo
+ *		 4(ap) -- signal number
+ *	sp ->	 0(ap) -- argument count
+ *		^^^^ CALLG argument list ^^^^
+ *
+ * N.B. all of the DWARF register numbers match our _REG_* constants.
+ * Also notice that while the %ap is adjusted inside the trampoline,
+ * the %sp is not adjusted, and so the CFA base does not change.
  */
 
-#include "SYS.h"
+#define	CFI_OFFSET(r)			.cfi_offset r, r * 4
 
-#ifdef SYSLIBC_SCCS
-RCSID("$NetBSD: __sigtramp3.S,v 1.2 2011/01/25 02:38:15 matt Exp $")
+	.text
+#if 0
+	.cfi_startproc simple
+	.cfi_signal_frame
+	.cfi_def_cfa _REG_SP, 16 + SIZEOF_SIGINFO + UC_GREGS
+	CFI_OFFSET(_REG_R0)
+	CFI_OFFSET(_REG_R1)
+	CFI_OFFSET(_REG_R2)
+	CFI_OFFSET(_REG_R3)
+	CFI_OFFSET(_REG_R4)
+	CFI_OFFSET(_REG_R5)
+	CFI_OFFSET(_REG_R6)
+	CFI_OFFSET(_REG_R7)
+	CFI_OFFSET(_REG_R8)
+	CFI_OFFSET(_REG_R9)
+	CFI_OFFSET(_REG_R10)
+	CFI_OFFSET(_REG_R11)
+	CFI_OFFSET(_REG_AP)
+	CFI_OFFSET(_REG_FP)
+	CFI_OFFSET(_REG_SP)
+	CFI_OFFSET(_REG_PC)
+	CFI_OFFSET(_REG_PSL)
 #endif
 
-	.text
+/*
+ * The unwind entry includes one instruction slot prior to the trampoline
+ * because the unwinder will look up to (return PC - 1) while unwinding.
+ * Normally this would be the jump / branch, but since there isn't one in
+ * this case, we place an explicit nop there instead.
+ */
+
+#if 0
+	nop
+#endif
 	_ALIGN_TEXT
 
 	.globl	_C_LABEL(__sigtramp_siginfo_3)
@@ -53,3 +100,6 @@ _C_LABEL(__sigtramp_siginfo_3):
 	addl2 $8,%ap			# arg is pointer to ucontext
 	SYSTRAP(setcontext)		# exit from here
 	halt				# illegal insn
+#if 0
+	.cfi_endproc
+#endif

Reply via email to