Skip to content

Commit 84215a3

Browse files
committed
sched::clone() adding argument related to parent/child PIDs and tls.
adding CLONE_PIDFD flag to set pid fd (with cloexec) on last argument.
1 parent e4895d3 commit 84215a3

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/sched.rs

+21
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ mod sched_linux_like {
8080
CLONE_NEWNET;
8181
/// The new process shares an I/O context with the calling process.
8282
CLONE_IO;
83+
/// Allocates a child process file descriptor (O_CLOEXEC)
84+
/// for the `child_tid` argument.
85+
CLONE_PIDFD;
8386
}
8487
}
8588

@@ -109,13 +112,28 @@ mod sched_linux_like {
109112
stack: &mut [u8],
110113
flags: CloneFlags,
111114
signal: Option<c_int>,
115+
parent_tid: Option<Pid>,
116+
tls: Option<&mut [u8]>,
117+
child_tid: Option<Pid>,
112118
) -> Result<Pid> {
113119
extern "C" fn callback(data: *mut CloneCb) -> c_int {
114120
let cb: &mut CloneCb = unsafe { &mut *data };
115121
(*cb)() as c_int
116122
}
117123

118124
let combined = flags.bits() | signal.unwrap_or(0);
125+
let parent_tid = match parent_tid {
126+
Some(mut ptid) => &mut ptid as *mut Pid,
127+
_ => std::ptr::null_mut(),
128+
};
129+
let tls = match tls {
130+
Some(s) => s.as_mut_ptr(),
131+
_ => std::ptr::null_mut(),
132+
};
133+
let child_tid = match child_tid {
134+
Some(mut ctid) => &mut ctid as *mut Pid,
135+
_ => std::ptr::null_mut(),
136+
};
119137
let res = unsafe {
120138
let ptr = stack.as_mut_ptr().add(stack.len());
121139
let ptr_aligned = ptr.sub(ptr as usize % 16);
@@ -130,6 +148,9 @@ mod sched_linux_like {
130148
ptr_aligned as *mut c_void,
131149
combined,
132150
&mut cb as *mut _ as *mut c_void,
151+
parent_tid,
152+
tls,
153+
child_tid,
133154
)
134155
};
135156

0 commit comments

Comments
 (0)