Annotate the RISC-V signal trampoline with CFI attributes.

This commit is contained in:
skrll 2024-05-30 15:56:43 +00:00
parent 588e74af68
commit 95bbc8c712
2 changed files with 92 additions and 3 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: genassym.cf,v 1.3 2023/05/19 06:31:01 skrll Exp $
# $NetBSD: genassym.cf,v 1.4 2024/05/30 15:56:43 skrll Exp $
#
# Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -37,9 +37,40 @@ include <sys/ucontext.h>
include <machine/setjmp.h>
define UC_GREGS_RA offsetof(ucontext_t, uc_mcontext.__gregs[_REG_RA])
define UC_GREGS_SP offsetof(ucontext_t, uc_mcontext.__gregs[_REG_SP])
define UC_GREGS_GP offsetof(ucontext_t, uc_mcontext.__gregs[_REG_GP])
define UC_GREGS_TP offsetof(ucontext_t, uc_mcontext.__gregs[_REG_TP])
define UC_GREGS_T0 offsetof(ucontext_t, uc_mcontext.__gregs[_REG_T0])
define UC_GREGS_T1 offsetof(ucontext_t, uc_mcontext.__gregs[_REG_T1])
define UC_GREGS_T2 offsetof(ucontext_t, uc_mcontext.__gregs[_REG_T2])
define UC_GREGS_S0 offsetof(ucontext_t, uc_mcontext.__gregs[_REG_S0])
define UC_GREGS_S1 offsetof(ucontext_t, uc_mcontext.__gregs[_REG_S1])
define UC_GREGS_A0 offsetof(ucontext_t, uc_mcontext.__gregs[_REG_A0])
define UC_GREGS_A1 offsetof(ucontext_t, uc_mcontext.__gregs[_REG_A1])
define UC_GREGS_A2 offsetof(ucontext_t, uc_mcontext.__gregs[_REG_A2])
define UC_GREGS_A3 offsetof(ucontext_t, uc_mcontext.__gregs[_REG_A3])
define UC_GREGS_A4 offsetof(ucontext_t, uc_mcontext.__gregs[_REG_A4])
define UC_GREGS_A5 offsetof(ucontext_t, uc_mcontext.__gregs[_REG_A5])
define UC_GREGS_A6 offsetof(ucontext_t, uc_mcontext.__gregs[_REG_A6])
define UC_GREGS_A7 offsetof(ucontext_t, uc_mcontext.__gregs[_REG_A7])
define UC_GREGS_S2 offsetof(ucontext_t, uc_mcontext.__gregs[_REG_S2])
define UC_GREGS_S3 offsetof(ucontext_t, uc_mcontext.__gregs[_REG_S3])
define UC_GREGS_S4 offsetof(ucontext_t, uc_mcontext.__gregs[_REG_S4])
define UC_GREGS_S5 offsetof(ucontext_t, uc_mcontext.__gregs[_REG_S5])
define UC_GREGS_S6 offsetof(ucontext_t, uc_mcontext.__gregs[_REG_S6])
define UC_GREGS_S7 offsetof(ucontext_t, uc_mcontext.__gregs[_REG_S7])
define UC_GREGS_S8 offsetof(ucontext_t, uc_mcontext.__gregs[_REG_S8])
define UC_GREGS_S9 offsetof(ucontext_t, uc_mcontext.__gregs[_REG_S9])
define UC_GREGS_S10 offsetof(ucontext_t, uc_mcontext.__gregs[_REG_S10])
define UC_GREGS_S11 offsetof(ucontext_t, uc_mcontext.__gregs[_REG_S11])
define UC_GREGS_T3 offsetof(ucontext_t, uc_mcontext.__gregs[_REG_T3])
define UC_GREGS_T4 offsetof(ucontext_t, uc_mcontext.__gregs[_REG_T4])
define UC_GREGS_T5 offsetof(ucontext_t, uc_mcontext.__gregs[_REG_T5])
define UC_GREGS_T6 offsetof(ucontext_t, uc_mcontext.__gregs[_REG_T6])
define UC_GREGS_RV offsetof(ucontext_t, uc_mcontext.__gregs[_REG_RV])
define UC_GREGS_PC offsetof(ucontext_t, uc_mcontext.__gregs[_REG_PC])
define UC_GREGS offsetof(ucontext_t, uc_mcontext.__gregs[0])
define SIG_BLOCK SIG_BLOCK
define SIG_SETMASK SIG_SETMASK

View File

@ -1,4 +1,4 @@
/* $NetBSD: __sigtramp2.S,v 1.4 2024/05/28 06:57:17 skrll Exp $ */
/* $NetBSD: __sigtramp2.S,v 1.5 2024/05/30 15:56:43 skrll Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@ -33,7 +33,7 @@
#include "assym.h"
#if defined(SYSLIBC_SCCS) && !defined(lint)
RCSID("$NetBSD: __sigtramp2.S,v 1.4 2024/05/28 06:57:17 skrll Exp $")
RCSID("$NetBSD: __sigtramp2.S,v 1.5 2024/05/30 15:56:43 skrll Exp $")
#endif /* SYSLIBC_SCCS and not lint */
@ -45,9 +45,67 @@
*
* sp -> siginfo_t structure
* sp + SIGINFO_SIZE -> ucontext_t structure
*
* The DWARF register numbers for the general purpose registers are the
* same as the architected register numbers. For RISC-V, there is a DWARF
* pseudo-register for signal handler return address.
*/
#if defined(__LIBGCC_DWARF_ALT_FRAME_RETURN_COLUMN__)
#define DWARF_SIGRETURN_REG __LIBGCC_DWARF_ALT_FRAME_RETURN_COLUMN__
#else
#define DWARF_SIGRETURN_REG 64
#endif
.text
.cfi_startproc
.cfi_signal_frame
.cfi_def_cfa sp, SIGINFO_SIZE
.cfi_offset ra, UC_GREGS_RA
.cfi_offset sp, UC_GREGS_SP
.cfi_offset gp, UC_GREGS_GP
.cfi_offset tp, UC_GREGS_TP
.cfi_offset t0, UC_GREGS_T0
.cfi_offset t1, UC_GREGS_T1
.cfi_offset t2, UC_GREGS_T2
.cfi_offset s0, UC_GREGS_S0
.cfi_offset s1, UC_GREGS_S1
.cfi_offset a0, UC_GREGS_A0
.cfi_offset a1, UC_GREGS_A1
.cfi_offset a2, UC_GREGS_A2
.cfi_offset a3, UC_GREGS_A3
.cfi_offset a4, UC_GREGS_A4
.cfi_offset a5, UC_GREGS_A5
.cfi_offset a6, UC_GREGS_A6
.cfi_offset a7, UC_GREGS_A7
.cfi_offset s2, UC_GREGS_S2
.cfi_offset s3, UC_GREGS_S3
.cfi_offset s4, UC_GREGS_S4
.cfi_offset s5, UC_GREGS_S5
.cfi_offset s6, UC_GREGS_S6
.cfi_offset s7, UC_GREGS_S7
.cfi_offset s8, UC_GREGS_S8
.cfi_offset s9, UC_GREGS_S9
.cfi_offset s10, UC_GREGS_S10
.cfi_offset s11, UC_GREGS_S11
.cfi_offset t3, UC_GREGS_T3
.cfi_offset t4, UC_GREGS_T4
.cfi_offset t5, UC_GREGS_T5
.cfi_offset t6, UC_GREGS_T6
.cfi_return_column DWARF_SIGRETURN_REG
.cfi_offset DWARF_SIGRETURN_REG, UC_GREGS_PC
/*
* The unwind entry includes one instruction slot prior to the trampoline
* because the unwinder will look up to (return PC - 1 insn) 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.
*/
nop
ENTRY_NP(__sigtramp_siginfo_2)
addi a0, sp, SIGINFO_SIZE /* address of ucontext */
SYSTRAP_NOERROR(setcontext) /* and do setcontext */
SYSTRAP(exit) /* if sigreturn fails */
.cfi_endproc
END(__sigtramp_siginfo_2)