From 57b3f773e3bfec21e2bb57fa2b1bca5f3540e15d Mon Sep 17 00:00:00 2001 From: visa Date: Tue, 22 Feb 2022 07:47:46 +0000 Subject: [PATCH] Clear frame pointer in cpu_fork() on riscv64 This ensures the chain of call frames is terminated properly, preventing errors when unwinding kernel stacks. OK miod@ kettenis@ --- sys/arch/riscv64/riscv64/cpuswitch.S | 6 +++--- sys/arch/riscv64/riscv64/vm_machdep.c | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/sys/arch/riscv64/riscv64/cpuswitch.S b/sys/arch/riscv64/riscv64/cpuswitch.S index 45319ea6ee4..ea5fa634a4c 100644 --- a/sys/arch/riscv64/riscv64/cpuswitch.S +++ b/sys/arch/riscv64/riscv64/cpuswitch.S @@ -1,4 +1,4 @@ -/* $OpenBSD: cpuswitch.S,v 1.5 2021/07/02 14:58:33 kettenis Exp $ */ +/* $OpenBSD: cpuswitch.S,v 1.6 2022/02/22 07:47:46 visa Exp $ */ /* * Copyright (c) 2015 Dale Rahn @@ -100,8 +100,8 @@ ENTRY(proc_trampoline) li a0, IPL_NONE la t0, spllower jalr t0 - mv a0, s1 - jalr s0 + mv a0, s2 + jalr s1 la t0, syscall_return jr t0 END(cpu_switch) diff --git a/sys/arch/riscv64/riscv64/vm_machdep.c b/sys/arch/riscv64/riscv64/vm_machdep.c index 419455ef335..d5868a341c1 100644 --- a/sys/arch/riscv64/riscv64/vm_machdep.c +++ b/sys/arch/riscv64/riscv64/vm_machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vm_machdep.c,v 1.7 2021/06/30 22:20:56 kettenis Exp $ */ +/* $OpenBSD: vm_machdep.c,v 1.8 2022/02/22 07:47:46 visa Exp $ */ /*- * Copyright (c) 1995 Charles M. Hannum. All rights reserved. @@ -92,8 +92,9 @@ cpu_fork(struct proc *p1, struct proc *p2, void *stack, void *tcb, tf->tf_sstatus &= ~(SSTATUS_SPP); /* Enter user mode. */ sf = (struct switchframe *)tf - 1; - sf->sf_s[0] = (uint64_t)func; - sf->sf_s[1] = (uint64_t)arg; + sf->sf_s[0] = 0; /* Terminate chain of call frames. */ + sf->sf_s[1] = (uint64_t)func; + sf->sf_s[2] = (uint64_t)arg; sf->sf_ra = (u_int64_t)&proc_trampoline; pcb->pcb_sp = (uint64_t)sf; } -- 2.20.1