Fix panic in futex and rt_sigprocmask

This commit is contained in:
Marsman1996
2024-08-16 14:24:15 +08:00
committed by Tate, Hongliang Tian
parent 364ef48e2f
commit 4c1f6a4e32
2 changed files with 8 additions and 8 deletions

View File

@ -19,7 +19,7 @@ pub fn sys_futex(
ctx: &Context, ctx: &Context,
) -> Result<SyscallReturn> { ) -> Result<SyscallReturn> {
// FIXME: we current ignore futex flags // FIXME: we current ignore futex flags
let (futex_op, futex_flags) = futex_op_and_flags_from_u32(futex_op as _).unwrap(); let (futex_op, futex_flags) = futex_op_and_flags_from_u32(futex_op as _)?;
debug!( debug!(
"futex_op = {:?}, futex_flags = {:?}, futex_addr = 0x{:x}", "futex_op = {:?}, futex_flags = {:?}, futex_addr = 0x{:x}",
futex_op, futex_flags, futex_addr futex_op, futex_flags, futex_addr
@ -42,24 +42,24 @@ pub fn sys_futex(
let res = match futex_op { let res = match futex_op {
FutexOp::FUTEX_WAIT => { FutexOp::FUTEX_WAIT => {
let timeout = get_futex_timeout(utime_addr).expect("Invalid time addr"); let timeout = get_futex_timeout(utime_addr)?;
futex_wait(futex_addr as _, futex_val as _, &timeout).map(|_| 0) futex_wait(futex_addr as _, futex_val as _, &timeout).map(|_| 0)
} }
FutexOp::FUTEX_WAIT_BITSET => { FutexOp::FUTEX_WAIT_BITSET => {
let timeout = get_futex_timeout(utime_addr).expect("Invalid time addr"); let timeout = get_futex_timeout(utime_addr)?;
futex_wait_bitset(futex_addr as _, futex_val as _, &timeout, bitset as _).map(|_| 0) futex_wait_bitset(futex_addr as _, futex_val as _, &timeout, bitset as _).map(|_| 0)
} }
FutexOp::FUTEX_WAKE => { FutexOp::FUTEX_WAKE => {
let max_count = get_futex_val(futex_val as i32).expect("Invalid futex val"); let max_count = get_futex_val(futex_val as i32)?;
futex_wake(futex_addr as _, max_count).map(|count| count as isize) futex_wake(futex_addr as _, max_count).map(|count| count as isize)
} }
FutexOp::FUTEX_WAKE_BITSET => { FutexOp::FUTEX_WAKE_BITSET => {
let max_count = get_futex_val(futex_val as i32).expect("Invalid futex val"); let max_count = get_futex_val(futex_val as i32)?;
futex_wake_bitset(futex_addr as _, max_count, bitset as _).map(|count| count as isize) futex_wake_bitset(futex_addr as _, max_count, bitset as _).map(|count| count as isize)
} }
FutexOp::FUTEX_REQUEUE => { FutexOp::FUTEX_REQUEUE => {
let max_nwakes = get_futex_val(futex_val as i32).expect("Invalid futex val"); let max_nwakes = get_futex_val(futex_val as i32)?;
let max_nrequeues = get_futex_val(utime_addr as i32).expect("Invalid utime addr"); let max_nrequeues = get_futex_val(utime_addr as i32)?;
futex_requeue( futex_requeue(
futex_addr as _, futex_addr as _,
max_nwakes, max_nwakes,

View File

@ -26,7 +26,7 @@ pub fn sys_rt_sigprocmask(
if sigset_size != 8 { if sigset_size != 8 {
error!("sigset size is not equal to 8"); error!("sigset size is not equal to 8");
} }
do_rt_sigprocmask(mask_op, set_ptr, oldset_ptr, ctx).unwrap(); do_rt_sigprocmask(mask_op, set_ptr, oldset_ptr, ctx)?;
Ok(SyscallReturn::Return(0)) Ok(SyscallReturn::Return(0))
} }