Skip to content
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

Support SIGRTMIN+n signals. #1292

Merged
merged 10 commits into from
Jan 28, 2025
Prev Previous commit
Next Next commit
Add a runtime::sigrt function for constructing no-libc "realtime" s…
…ignals.
sunfishcode committed Jan 27, 2025
commit bbad16fa1be5dff9eb6966996c28b5936b13d2f2
21 changes: 21 additions & 0 deletions src/runtime.rs
Original file line number Diff line number Diff line change
@@ -613,3 +613,24 @@ pub const SIGRTMAX: u32 = {
linux_raw_sys::general::_NSIG - 1
}
};

/// Return a signal corresponding to `SIGRTMIN + n`.
///
/// This is similar to [`Signal::rt`], but uses the raw OS `SIGRTMIN` value
/// instead of the libc `SIGRTMIN` value. Don't use this unless you know your
/// code won't share a process with a libc (perhaps because you yourself are
/// implementing a libc).
#[cfg(linux_raw)]
#[doc(alias = "SIGRTMIN")]
pub fn sigrt(n: u32) -> Option<Signal> {
let sig = SIGRTMIN.wrapping_add(n);
if (SIGRTMIN..=SIGRTMAX).contains(&sig) {
// SAFETY: We've checked that `sig` is in the expected range. It could
// still conflict with libc's reserved values, however users of the
// `runtime` module here must already know that there's no other libc
// to conflict with.
Some(unsafe { Signal::from_raw_unchecked(sig as i32) })
} else {
None
}
}