Fix sigaction test on Linux, and rustfmt.

This commit is contained in:
4lDO2
2024-06-24 11:59:39 +02:00
parent 0ea2b5d45f
commit f37bb3cb16
7 changed files with 102 additions and 70 deletions
+8 -10
View File
@@ -107,7 +107,9 @@ pub unsafe extern "C" fn sigaction(
act: *const sigaction,
oact: *mut sigaction,
) -> c_int {
Sys::sigaction(sig, act.as_ref(), oact.as_mut()).map(|()| 0).or_minus_one_errno()
Sys::sigaction(sig, act.as_ref(), oact.as_mut())
.map(|()| 0)
.or_minus_one_errno()
}
#[no_mangle]
@@ -216,11 +218,6 @@ pub unsafe extern "C" fn sigismember(set: *const sigset_t, signo: c_int) -> c_in
0
}
extern "C" {
// Defined in assembly inside platform/x/mod.rs
fn __restore_rt();
}
#[no_mangle]
pub extern "C" fn signal(
sig: c_int,
@@ -228,8 +225,8 @@ pub extern "C" fn signal(
) -> Option<extern "C" fn(c_int)> {
let sa = sigaction {
sa_handler: func,
sa_flags: SA_RESTART as c_ulong,
sa_restorer: Some(__restore_rt),
sa_flags: SA_RESTART as _,
sa_restorer: None, // set by platform if applicable
sa_mask: sigset_t::default(),
};
let mut old_sa = mem::MaybeUninit::uninit();
@@ -279,7 +276,8 @@ pub unsafe extern "C" fn sigprocmask(
}
Ok(0)
})().or_minus_one_errno()
})()
.or_minus_one_errno()
}
#[no_mangle]
@@ -318,7 +316,7 @@ pub unsafe extern "C" fn sigset(
let mut sa = sigaction {
sa_handler: func,
sa_flags: 0 as c_ulong,
sa_restorer: Some(__restore_rt),
sa_restorer: None, // set by platform if applicable
sa_mask: sigset_t::default(),
};
sigemptyset(&mut sa.sa_mask);
-33
View File
@@ -1,38 +1,5 @@
use core::arch::global_asm;
// x8 is register, 119 is SIGRETURN
#[cfg(target_arch = "aarch64")]
global_asm!(
"
.global __restore_rt
__restore_rt:
mov x8, #119
svc 0
"
);
// Needs to be defined in assembly because it can't have a function prologue
// eax is register, 119 is SIGRETURN
#[cfg(target_arch = "x86")]
global_asm!(
"
.global __restore_rt
__restore_rt:
mov eax, 119
int 0x80
"
);
// Needs to be defined in assembly because it can't have a function prologue
// rax is register, 119 is SIGRETURN
#[cfg(target_arch = "x86_64")]
global_asm!(
"
.global __restore_rt
__restore_rt:
mov rax, 119
syscall
"
);
pub const SIGHUP: usize = 1;
pub const SIGINT: usize = 2;
pub const SIGQUIT: usize = 3;
+8 -1
View File
@@ -1,6 +1,13 @@
use alloc::vec::Vec;
use core::{
arch::asm,
cell::UnsafeCell,
mem,
ops::{Deref, DerefMut},
ptr, slice,
sync::atomic::AtomicBool,
};
use generic_rt::GenericTcb;
use core::{arch::asm, cell::UnsafeCell, mem, ops::{Deref, DerefMut}, ptr, slice, sync::atomic::AtomicBool};
use goblin::error::{Error, Result};
use super::ExpectTlsFree;
+31 -10
View File
@@ -4,12 +4,14 @@ 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::{
header::{
signal::{sigaction, siginfo_t, sigset_t, stack_t, NSIG, SA_RESTORER},
sys_time::itimerval,
time::timespec,
},
pthread::Errno,
};
use crate::pthread::Errno;
impl PalSignal for Sys {
unsafe fn getitimer(which: c_int, out: *mut itimerval) -> c_int {
@@ -37,16 +39,30 @@ impl PalSignal for Sys {
e(syscall!(SETITIMER, which, new, old)) as c_int
}
fn sigaction(sig: c_int, act: Option<&sigaction>, oact: Option<&mut sigaction>) -> Result<(), Errno> {
fn sigaction(
sig: c_int,
act: Option<&sigaction>,
oact: Option<&mut sigaction>,
) -> Result<(), Errno> {
extern "C" {
fn __restore_rt();
}
let act = act.map(|act| {
let mut act_clone = act.clone();
act_clone.sa_flags |= SA_RESTORER as c_ulong;
act_clone.sa_restorer = Some(__restore_rt);
act_clone
});
e_raw(unsafe {
syscall!(
RT_SIGACTION,
sig,
act.map_or_else(core::ptr::null, |x| x as *const _),
act.as_ref().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(|_| ())
})
.map(|_| ())
}
unsafe fn sigaltstack(ss: *const stack_t, old_ss: *mut stack_t) -> c_int {
@@ -57,7 +73,11 @@ impl PalSignal for Sys {
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> {
fn sigprocmask(
how: c_int,
set: Option<&sigset_t>,
oset: Option<&mut sigset_t>,
) -> Result<(), Errno> {
e_raw(unsafe {
syscall!(
RT_SIGPROCMASK,
@@ -66,7 +86,8 @@ impl PalSignal for Sys {
oset.map_or_else(core::ptr::null_mut, |x| x as *mut _),
mem::size_of::<sigset_t>()
)
}).map(|_| ())
})
.map(|_| ())
}
unsafe fn sigsuspend(set: *const sigset_t) -> c_int {
+18 -7
View File
@@ -1,9 +1,12 @@
use super::super::{types::*, Pal};
use crate::{header::{
signal::{sigaction, siginfo_t, sigset_t, stack_t},
sys_time::itimerval,
time::timespec,
}, pthread::Errno};
use crate::{
header::{
signal::{sigaction, siginfo_t, sigset_t, stack_t},
sys_time::itimerval,
time::timespec,
},
pthread::Errno,
};
pub trait PalSignal: Pal {
unsafe fn getitimer(which: c_int, out: *mut itimerval) -> c_int;
@@ -16,13 +19,21 @@ pub trait PalSignal: Pal {
unsafe fn setitimer(which: c_int, new: *const itimerval, old: *mut itimerval) -> c_int;
fn sigaction(sig: c_int, act: Option<&sigaction>, oact: Option<&mut sigaction>) -> Result<(), Errno>;
fn sigaction(
sig: c_int,
act: Option<&sigaction>,
oact: Option<&mut sigaction>,
) -> Result<(), Errno>;
unsafe fn sigaltstack(ss: *const stack_t, old_ss: *mut stack_t) -> c_int;
unsafe fn sigpending(set: *mut sigset_t) -> c_int;
fn sigprocmask(how: c_int, set: Option<&sigset_t>, oset: Option<&mut sigset_t>) -> Result<(), Errno>;
fn sigprocmask(
how: c_int,
set: Option<&sigset_t>,
oset: Option<&mut sigset_t>,
) -> Result<(), Errno>;
unsafe fn sigsuspend(set: *const sigset_t) -> c_int;
+15 -3
View File
@@ -4,7 +4,11 @@ use syscall::{Error, Result, WaitFlags, EMFILE};
use crate::{
header::{
errno::EINVAL, signal::{sigaction, SIG_BLOCK, SIG_SETMASK, SIG_UNBLOCK}, sys_stat::UTIME_NOW, sys_uio::iovec, time::timespec,
errno::EINVAL,
signal::{sigaction, SIG_BLOCK, SIG_SETMASK, SIG_UNBLOCK},
sys_stat::UTIME_NOW,
sys_uio::iovec,
time::timespec,
},
platform::{types::*, PalSignal},
};
@@ -251,7 +255,11 @@ pub unsafe extern "C" fn redox_sigaction_v1(
new: *const sigaction,
old: *mut sigaction,
) -> RawResult {
Error::mux(Sys::sigaction(signal as c_int, new.as_ref(), old.as_mut()).map(|()| 0).map_err(Into::into))
Error::mux(
Sys::sigaction(signal as c_int, new.as_ref(), old.as_mut())
.map(|()| 0)
.map_err(Into::into),
)
}
#[no_mangle]
@@ -260,7 +268,11 @@ pub unsafe extern "C" fn redox_sigprocmask_v1(
new: *const u64,
old: *mut u64,
) -> RawResult {
Error::mux(Sys::sigprocmask(how as c_int, new.as_ref(), old.as_mut()).map(|()| 0).map_err(Into::into))
Error::mux(
Sys::sigprocmask(how as c_int, new.as_ref(), old.as_mut())
.map(|()| 0)
.map_err(Into::into),
)
}
#[no_mangle]
pub unsafe extern "C" fn redox_mmap_v1(
+22 -6
View File
@@ -9,11 +9,15 @@ use super::{
use crate::{
header::{
errno::{EINVAL, ENOSYS},
signal::{sigaction, siginfo_t, sigset_t, stack_t, SA_SIGINFO, SIG_BLOCK, SIG_DFL, SIG_IGN, SIG_SETMASK, SIG_UNBLOCK},
signal::{
sigaction, siginfo_t, sigset_t, stack_t, SA_SIGINFO, SIG_BLOCK, SIG_DFL, SIG_IGN,
SIG_SETMASK, SIG_UNBLOCK,
},
sys_time::{itimerval, ITIMER_REAL},
time::timespec,
},
platform::ERRNO, pthread::Errno,
platform::ERRNO,
pthread::Errno,
};
impl PalSignal for Sys {
@@ -105,7 +109,11 @@ impl PalSignal for Sys {
0
}
fn sigaction(sig: c_int, c_act: Option<&sigaction>, c_oact: Option<&mut sigaction>) -> Result<(), Errno> {
fn sigaction(
sig: c_int,
c_act: Option<&sigaction>,
c_oact: Option<&mut sigaction>,
) -> Result<(), Errno> {
let sig = u8::try_from(sig).map_err(|_| syscall::Error::new(syscall::EINVAL))?;
let new_action = c_act.map(|c_act| {
@@ -118,9 +126,13 @@ impl PalSignal for Sys {
} else {
SigactionKind::Handled {
handler: if c_act.sa_flags & crate::header::signal::SA_SIGINFO as u64 != 0 {
SignalHandler { sigaction: unsafe { core::mem::transmute(c_act.sa_handler) } }
SignalHandler {
sigaction: unsafe { core::mem::transmute(c_act.sa_handler) },
}
} else {
SignalHandler { handler: c_act.sa_handler }
SignalHandler {
handler: c_act.sa_handler,
}
},
}
};
@@ -173,7 +185,11 @@ impl PalSignal for Sys {
-1
}
fn sigprocmask(how: c_int, set: Option<&sigset_t>, oset: Option<&mut sigset_t>) -> Result<(), Errno> {
fn sigprocmask(
how: c_int,
set: Option<&sigset_t>,
oset: Option<&mut sigset_t>,
) -> Result<(), Errno> {
Ok(match how {
SIG_SETMASK => redox_rt::signal::set_sigmask(set.copied(), oset)?,
SIG_BLOCK => redox_rt::signal::or_sigmask(set.copied(), oset)?,