From 08c4686f47a56ca15e57bd2ccc1539e538e77ede Mon Sep 17 00:00:00 2001 From: Yanfeng Liu Date: Fri, 5 Jul 2024 10:25:55 +0800 Subject: [PATCH] riscv/fork: fix tp for PROTECTED This fixes `tp` value of forked child in PROTECTED build to support vfork. Why? the optimized `dispatch_syscall` requires `tp` to hold the task TCB since commit e6973c764c. Signed-off-by: Yanfeng Liu --- arch/risc-v/src/common/riscv_fork.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/risc-v/src/common/riscv_fork.c b/arch/risc-v/src/common/riscv_fork.c index 16f6225297..6b7705028c 100644 --- a/arch/risc-v/src/common/riscv_fork.c +++ b/arch/risc-v/src/common/riscv_fork.c @@ -246,6 +246,14 @@ pid_t riscv_fork(const struct fork_s *context) fregs[REG_FS11] = context->fs11; /* Saved register fs11 */ #endif +#ifdef CONFIG_BUILD_PROTECTED + /* Forked task starts at `dispatch_syscall()`, which requires TP holding + * TCB pointer as per e6973c764c, so we please it here to support vfork. + */ + + child->cmn.xcp.regs[REG_TP] = (uintptr_t)child; +#endif + /* And, finally, start the child task. On a failure, nxtask_start_fork() * will discard the TCB by calling nxtask_abort_fork(). */