From 6546789b7e6e191ce2650c6f0a91c6645e14c837 Mon Sep 17 00:00:00 2001 From: Ville Juven Date: Tue, 19 Apr 2022 15:41:09 +0300 Subject: [PATCH] RISC-V: Add syscall support for vfork If vfork is called via syscall (PROTECTED/KERNEL build) need to set up return parameters for syscall. Otherwise the SW will get lost. --- arch/risc-v/src/common/riscv_vfork.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/arch/risc-v/src/common/riscv_vfork.c b/arch/risc-v/src/common/riscv_vfork.c index 0e2c3ebc82..7403b94670 100644 --- a/arch/risc-v/src/common/riscv_vfork.c +++ b/arch/risc-v/src/common/riscv_vfork.c @@ -224,6 +224,29 @@ pid_t up_vfork(const struct vfork_s *context) child->cmn.xcp.regs[REG_GP] = newsp; /* Global pointer */ #endif +#ifdef CONFIG_LIB_SYSCALL + /* If we got here via a syscall, then we are going to have to setup some + * syscall return information as well. + */ + + if (parent->xcp.nsyscalls > 0) + { + int index; + for (index = 0; index < parent->xcp.nsyscalls; index++) + { + child->cmn.xcp.syscall[index].sysreturn = + parent->xcp.syscall[index].sysreturn; + +#ifndef CONFIG_BUILD_FLAT + child->cmn.xcp.syscall[index].int_ctx = + parent->xcp.syscall[index].int_ctx; +#endif + } + + child->cmn.xcp.nsyscalls = parent->xcp.nsyscalls; + } +#endif /* CONFIG_LIB_SYSCALL */ + /* And, finally, start the child task. On a failure, nxtask_start_vfork() * will discard the TCB by calling nxtask_abort_vfork(). */