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

Implement raise and tgkill #1250

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions src/backend/linux_raw/runtime/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ pub(crate) unsafe fn tkill(tid: Pid, sig: Signal) -> io::Result<()> {
ret(syscall_readonly!(__NR_tkill, tid, sig))
}

#[inline]
pub(crate) unsafe fn tgkill(tid: Pid, sig: Signal) -> io::Result<()> {
ret(syscall_readonly!(__NR_tgkill, tid, sig))
}

#[inline]
pub(crate) unsafe fn sigprocmask(how: How, new: Option<&Sigset>) -> io::Result<Sigset> {
let mut old = MaybeUninit::<Sigset>::uninit();
Expand Down
28 changes: 28 additions & 0 deletions src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,34 @@ pub unsafe fn tkill(tid: Pid, sig: Signal) -> io::Result<()> {
backend::runtime::syscalls::tkill(tid, sig)
}

/// `tgkill(tid, sig)`—Send a signal to a thread group.
///
/// # Safety
///
/// You're on your own. And on top of all the troubles with signal handlers,
/// this implementation is highly experimental.
///
/// # References
/// - [Linux]
///
/// [Linux]: https://man7.org/linux/man-pages/man2/tgkill.2.html
#[inline]
pub unsafe fn tgkill(tid: Pid, sig: Signal) -> io::Result<()> {
backend::runtime::syscalls::tgkill(tid, sig)
}

/// `raise(sig)`—Send a signal to the current thread.
///
/// # References
/// - [Linux]
///
/// [Linux]: https://man7.org/linux/man-pages/man3/raise.3.html
#[inline]
pub fn raise(sig: Signal) -> io::Result<()> {
// SAFETY: This sends a signal to the current thread, and our own thread ID can't be recycled.
unsafe { backend::runtime::syscalls::tkill(backend::thread::syscalls::gettid(), sig) }
}

/// `rt_sigprocmask(how, set, oldset)`—Adjust the process signal mask.
///
/// # Safety
Expand Down
Loading