Implement sigpending on Redox.

This commit is contained in:
4lDO2
2024-07-01 20:10:00 +02:00
parent c639fd37ba
commit 8298417dee
5 changed files with 28 additions and 8 deletions
+9
View File
@@ -497,3 +497,12 @@ pub unsafe fn sigaltstack(new: Option<&Sigaltstack>, old_out: Option<&mut Sigalt
}
pub const MIN_SIGALTSTACK_SIZE: usize = 8192;
pub fn currently_pending() -> u64 {
let control = &unsafe { Tcb::current().unwrap() }.os_specific.control;
let w0 = control.word[0].load(Ordering::Relaxed);
let w1 = control.word[0].load(Ordering::Relaxed);
let pending_blocked_lo = w0 & !(w0 >> 32);
let pending_unblocked_hi = w1 & !(w0 >> 32);
pending_blocked_lo | (pending_unblocked_hi << 32)
}
+6 -2
View File
@@ -7,11 +7,13 @@ use cbitset::BitSet;
use crate::{
header::{errno, time::timespec},
platform::{self, types::*, Pal, PalSignal, Sys},
pthread::{self, ResultExt},
pthread::{self, Errno, ResultExt},
};
pub use self::sys::*;
use super::errno::EFAULT;
#[cfg(target_os = "linux")]
#[path = "linux.rs"]
pub mod sys;
@@ -241,7 +243,9 @@ pub unsafe extern "C" fn sigpause(sig: c_int) -> c_int {
#[no_mangle]
pub unsafe extern "C" fn sigpending(set: *mut sigset_t) -> c_int {
Sys::sigpending(set)
(|| Sys::sigpending(set.as_mut().ok_or(Errno(EFAULT))?))()
.map(|()| 0)
.or_minus_one_errno()
}
const BELOW_SIGRTMIN_MASK: sigset_t = (1 << SIGRTMIN) - 1;
+9 -2
View File
@@ -74,8 +74,15 @@ impl PalSignal for Sys {
.map(|_| ())
}
unsafe fn sigpending(set: *mut sigset_t) -> c_int {
e(syscall!(RT_SIGPENDING, set, NSIG / 8)) as c_int
fn sigpending(set: &mut sigset_t) -> Result<(), Errno> {
e_raw(unsafe {
syscall!(
RT_SIGPENDING,
set as *mut sigset_t as usize,
mem::size_of::<sigset_t>()
)
})
.map(|_| ())
}
fn sigprocmask(
+1 -1
View File
@@ -27,7 +27,7 @@ pub trait PalSignal: Pal {
unsafe fn sigaltstack(ss: Option<&stack_t>, old_ss: Option<&mut stack_t>) -> Result<(), Errno>;
unsafe fn sigpending(set: *mut sigset_t) -> c_int;
fn sigpending(set: &mut sigset_t) -> Result<(), Errno>;
fn sigprocmask(
how: c_int,
+3 -3
View File
@@ -223,9 +223,9 @@ impl PalSignal for Sys {
Ok(())
}
unsafe fn sigpending(set: *mut sigset_t) -> c_int {
ERRNO.set(ENOSYS);
-1
fn sigpending(set: &mut sigset_t) -> Result<(), Errno> {
*set = redox_rt::signal::currently_pending();
Ok(())
}
fn sigprocmask(