Fix reference getting moved

The sigaction handler called map on an option, creating a pointer to a
move value. This in turned caused UB for signal handlers. Avoid using
pointers directly, and instead prefer references.
This commit is contained in:
Xavier L'Heureux
2019-08-11 20:47:18 -04:00
parent 225583230f
commit 0a558de76c
5 changed files with 29 additions and 32 deletions
+10 -9
View File
@@ -35,15 +35,16 @@ impl PalSignal for Sys {
e(unsafe { syscall!(SETITIMER, which, new, old) }) as c_int
}
unsafe fn sigaction(sig: c_int, act: *const sigaction, oact: *mut sigaction) -> c_int {
println!("in: {:?}", (*act));
e(syscall!(
RT_SIGACTION,
sig,
act,
oact,
mem::size_of::<sigset_t>()
)) as c_int
fn sigaction(sig: c_int, act: Option<&sigaction>, oact: Option<&mut sigaction>) -> c_int {
e(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>()
)
}) as c_int
}
fn sigaltstack(ss: *const stack_t, old_ss: *mut stack_t) -> c_int {