Skip to content

Commit

Permalink
riscv/fork: fix tp for PROTECTED
Browse files Browse the repository at this point in the history
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 e6973c7.

Signed-off-by: Yanfeng Liu <[email protected]>
  • Loading branch information
yf13 authored and xiaoxiang781216 committed Jul 17, 2024
1 parent 70c5c94 commit 08c4686
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions arch/risc-v/src/common/riscv_fork.c
Original file line number Diff line number Diff line change
Expand Up @@ -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().
*/
Expand Down

0 comments on commit 08c4686

Please sign in to comment.