summaryrefslogtreecommitdiff
path: root/sys/arch
diff options
context:
space:
mode:
authorVisa Hankala <visa@cvs.openbsd.org>2022-02-22 07:47:47 +0000
committerVisa Hankala <visa@cvs.openbsd.org>2022-02-22 07:47:47 +0000
commitbf2ed1a15d1a1fda5e1d2c3cc1b56fb04528d250 (patch)
tree29f9b42e675a0cb9f07375b8e6cdca89d06d7d57 /sys/arch
parent91a21e3d176543e31896b2698a9c4f2dcad60722 (diff)
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@
Diffstat (limited to 'sys/arch')
-rw-r--r--sys/arch/riscv64/riscv64/cpuswitch.S6
-rw-r--r--sys/arch/riscv64/riscv64/vm_machdep.c7
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 <drahn@dalerahn.com>
@@ -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;
}