Add real vfork logics

This commit is contained in:
Chen Chengjun
2025-04-03 14:16:17 +08:00
committed by Jianfeng Jiang
parent 43e43ca133
commit e4f07b76a0
8 changed files with 164 additions and 63 deletions

View File

@ -195,8 +195,18 @@ pub fn clone_child(
Ok(child_tid)
} else {
let child_process = clone_child_process(ctx, parent_context, clone_args)?;
if clone_args.flags.contains(CloneFlags::CLONE_VFORK) {
child_process.status().set_vfork_child(true);
}
child_process.run();
if child_process.status().is_vfork_child() {
let cond = || (!child_process.status().is_vfork_child()).then_some(());
let current = ctx.process;
current.children_wait_queue().wait_until(cond);
}
let child_pid = child_process.pid();
Ok(child_pid)
}
@ -435,8 +445,10 @@ fn clone_user_ctx(
// The return value of child thread is zero
child_context.set_syscall_ret(0);
if clone_flags.contains(CloneFlags::CLONE_VM) {
// if parent and child shares the same address space, a new stack must be specified.
if clone_flags.contains(CloneFlags::CLONE_VM) && !clone_flags.contains(CloneFlags::CLONE_VFORK)
{
// If parent and child shares the same address space and not in vfork situation,
// a new stack must be specified.
debug_assert!(new_sp != 0);
}
if new_sp != 0 {