Skip to content

Commit

Permalink
some more opportunities for set_last_error_and_return
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Oct 25, 2024
1 parent 82b041e commit 2350ba7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
4 changes: 1 addition & 3 deletions src/tools/miri/src/shims/unix/linux/epoll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,9 +433,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
let timeout = this.read_scalar(timeout)?.to_i32()?;

if epfd_value <= 0 || maxevents <= 0 {
this.set_last_error(LibcError("EINVAL"))?;
this.write_int(-1, dest)?;
return interp_ok(());
return this.set_last_error_and_return(LibcError("EINVAL"), dest);
}

// This needs to come after the maxevents value check, or else maxevents.try_into().unwrap()
Expand Down
15 changes: 5 additions & 10 deletions src/tools/miri/src/shims/unix/linux/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ pub fn futex<'tcx>(
};

if bitset == 0 {
this.set_last_error(LibcError("EINVAL"))?;
this.write_scalar(Scalar::from_target_isize(-1, this), dest)?;
this.set_last_error_and_return(LibcError("EINVAL"), dest)?;
return interp_ok(());
}

Expand All @@ -75,9 +74,7 @@ pub fn futex<'tcx>(
let duration = match this.read_timespec(&timeout)? {
Some(duration) => duration,
None => {
this.set_last_error(LibcError("EINVAL"))?;
this.write_scalar(Scalar::from_target_isize(-1, this), dest)?;
return interp_ok(());
return this.set_last_error_and_return(LibcError("EINVAL"), dest);
}
};
let timeout_clock = if op & futex_realtime == futex_realtime {
Expand Down Expand Up @@ -153,12 +150,12 @@ pub fn futex<'tcx>(
Scalar::from_target_isize(0, this), // retval_succ
Scalar::from_target_isize(-1, this), // retval_timeout
dest.clone(),
this.eval_libc("ETIMEDOUT"),
this.eval_libc("ETIMEDOUT"), // errno_timeout
);
} else {
// The futex value doesn't match the expected value, so we return failure
// right away without sleeping: -1 and errno set to EAGAIN.
this.set_last_error_and_return(LibcError("EAGAIN"), dest)?;
return this.set_last_error_and_return(LibcError("EAGAIN"), dest);
}
}
// FUTEX_WAKE: (int *addr, int op = FUTEX_WAKE, int val)
Expand All @@ -178,9 +175,7 @@ pub fn futex<'tcx>(
u32::MAX
};
if bitset == 0 {
this.set_last_error(LibcError("EINVAL"))?;
this.write_scalar(Scalar::from_target_isize(-1, this), dest)?;
return interp_ok(());
return this.set_last_error_and_return(LibcError("EINVAL"), dest);
}
// Together with the SeqCst fence in futex_wait, this makes sure that futex_wait
// will see the latest value on addr which could be changed by our caller
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/src/shims/windows/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
Scalar::from_i32(1), // retval_succ
Scalar::from_i32(0), // retval_timeout
dest.clone(),
this.eval_windows("c", "ERROR_TIMEOUT"),
this.eval_windows("c", "ERROR_TIMEOUT"), // errno_timeout
);
}

Expand Down

0 comments on commit 2350ba7

Please sign in to comment.