Skip to content

sched::clone() adding argument related to parent/child PIDs and tls. #2607

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/sched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ mod sched_linux_like {
CLONE_NEWNET;
/// The new process shares an I/O context with the calling process.
CLONE_IO;
/// Allocates a child process file descriptor (O_CLOEXEC)
/// for the `child_tid` argument.
CLONE_PIDFD;
}
}

Expand Down Expand Up @@ -109,13 +112,28 @@ mod sched_linux_like {
stack: &mut [u8],
flags: CloneFlags,
signal: Option<c_int>,
parent_tid: Option<Pid>,
tls: Option<&mut [u8]>,
child_tid: Option<Pid>,
) -> Result<Pid> {
extern "C" fn callback(data: *mut CloneCb) -> c_int {
let cb: &mut CloneCb = unsafe { &mut *data };
(*cb)() as c_int
}

let combined = flags.bits() | signal.unwrap_or(0);
let parent_tid = match parent_tid {
Some(mut ptid) => &mut ptid as *mut Pid,
_ => std::ptr::null_mut(),
};
let tls = match tls {
Some(s) => s.as_mut_ptr(),
_ => std::ptr::null_mut(),
};
let child_tid = match child_tid {
Some(mut ctid) => &mut ctid as *mut Pid,
_ => std::ptr::null_mut(),
};
let res = unsafe {
let ptr = stack.as_mut_ptr().add(stack.len());
let ptr_aligned = ptr.sub(ptr as usize % 16);
Expand All @@ -130,6 +148,9 @@ mod sched_linux_like {
ptr_aligned as *mut c_void,
combined,
&mut cb as *mut _ as *mut c_void,
parent_tid,
tls,
child_tid,
)
};

Expand Down
Loading