Files
RedBear-OS/src/platform/linux/signal.rs
T
2024-07-09 15:00:55 +02:00

84 lines
2.4 KiB
Rust

use core::mem;
use super::{
super::{types::*, PalSignal},
e, e_raw, Sys,
};
use crate::header::{
signal::{sigaction, siginfo_t, sigset_t, stack_t, NSIG},
sys_time::itimerval,
time::timespec,
};
use crate::pthread::Errno;
impl PalSignal for Sys {
unsafe fn getitimer(which: c_int, out: *mut itimerval) -> c_int {
e(syscall!(GETITIMER, which, out)) as c_int
}
fn kill(pid: pid_t, sig: c_int) -> c_int {
e(unsafe { syscall!(KILL, pid, sig) }) as c_int
}
fn killpg(pgrp: pid_t, sig: c_int) -> c_int {
e(unsafe { syscall!(KILL, -(pgrp as isize) as pid_t, sig) }) as c_int
}
fn raise(sig: c_int) -> c_int {
let tid = e(unsafe { syscall!(GETTID) }) as pid_t;
if tid == !0 {
-1
} else {
e(unsafe { syscall!(TKILL, tid, sig) }) as c_int
}
}
unsafe fn setitimer(which: c_int, new: *const itimerval, old: *mut itimerval) -> c_int {
e(syscall!(SETITIMER, which, new, old)) as c_int
}
fn sigaction(sig: c_int, act: Option<&sigaction>, oact: Option<&mut sigaction>) -> Result<(), Errno> {
e_raw(unsafe {
syscall!(
RT_SIGACTION,
sig,
act.map_or_else(core::ptr::null, |x| x as *const _),
oact.map_or_else(core::ptr::null_mut, |x| x as *mut _),
mem::size_of::<sigset_t>()
)
}).map(|_| ())
}
unsafe fn sigaltstack(ss: *const stack_t, old_ss: *mut stack_t) -> c_int {
e(syscall!(SIGALTSTACK, ss, old_ss)) as c_int
}
unsafe fn sigpending(set: *mut sigset_t) -> c_int {
e(syscall!(RT_SIGPENDING, set, NSIG / 8)) as c_int
}
fn sigprocmask(how: c_int, set: Option<&sigset_t>, oset: Option<&mut sigset_t>) -> Result<(), Errno> {
e_raw(unsafe {
syscall!(
RT_SIGPROCMASK,
how,
set.map_or_else(core::ptr::null, |x| x as *const _),
oset.map_or_else(core::ptr::null_mut, |x| x as *mut _),
mem::size_of::<sigset_t>()
)
}).map(|_| ())
}
unsafe fn sigsuspend(set: *const sigset_t) -> c_int {
e(syscall!(RT_SIGSUSPEND, set, NSIG / 8)) as c_int
}
unsafe fn sigtimedwait(
set: *const sigset_t,
sig: *mut siginfo_t,
tp: *const timespec,
) -> c_int {
e(syscall!(RT_SIGTIMEDWAIT, set, sig, tp, NSIG / 8)) as c_int
}
}