MCPcopy Create free account
hub / github.com/bytecodealliance/rustix / kernel_sigtimedwait

Function kernel_sigtimedwait

src/backend/linux_raw/runtime/syscalls.rs:245–335  ·  view source on GitHub ↗
(
    set: &KernelSigSet,
    timeout: Option<&Timespec>,
)

Source from the content-addressed store, hash-verified

243
244#[inline]
245pub(crate) unsafe fn kernel_sigtimedwait(
246 set: &KernelSigSet,
247 timeout: Option<&Timespec>,
248) -> io::Result<Siginfo> {
249 let mut info = MaybeUninit::<Siginfo>::uninit();
250
251 // `rt_sigtimedwait_time64` was introduced in Linux 5.1. The old
252 // `rt_sigtimedwait` syscall is not y2038-compatible on 32-bit
253 // architectures.
254 #[cfg(target_pointer_width = "32")]
255 {
256 // If we don't have Linux 5.1, and the timeout fits in a
257 // `__kernel_old_timespec`, use plain `rt_sigtimedwait`.
258 //
259 // We do this unconditionally, rather than trying
260 // `rt_sigtimedwait_time64` and falling back on `Errno::NOSYS`, because
261 // seccomp configurations will sometimes abort the process on syscalls
262 // they don't recognize.
263 #[cfg(not(feature = "linux_5_1"))]
264 {
265 // If we don't have a timeout, or if we can convert the timeout to
266 // a `__kernel_old_timespec`, the use `__NR_futex`.
267 fn convert(timeout: &Timespec) -> Option<__kernel_old_timespec> {
268 Some(__kernel_old_timespec {
269 tv_sec: timeout.tv_sec.try_into().ok()?,
270 tv_nsec: timeout.tv_nsec.try_into().ok()?,
271 })
272 }
273 let old_timeout = if let Some(timeout) = timeout {
274 match convert(timeout) {
275 // Could not convert timeout.
276 None => None,
277 // Could convert timeout. Ok!
278 Some(old_timeout) => Some(Some(old_timeout)),
279 }
280 } else {
281 // No timeout. Ok!
282 Some(None)
283 };
284 if let Some(old_timeout) = old_timeout {
285 return ret_c_int(syscall!(
286 __NR_rt_sigtimedwait,
287 by_ref(set),
288 &mut info,
289 opt_ref(old_timeout.as_ref()),
290 size_of::<KernelSigSet, _>()
291 ))
292 .map(|sig| {
293 debug_assert_eq!(
294 sig,
295 info.assume_init_ref()
296 .__bindgen_anon_1
297 .__bindgen_anon_1
298 .si_signo
299 );
300 info.assume_init()
301 });
302 }

Callers

nothing calls this directly

Calls 3

assume_initMethod · 0.80
convertFunction · 0.70
ret_c_intFunction · 0.50

Tested by

no test coverage detected