Skip to content

Commit

Permalink
Change futex_wait errno from Scalar to IoError
Browse files Browse the repository at this point in the history
To shift more Scalars to IoErrors, implement this change, allowing
for a few other changes in the Linux and Windows shims. This also
requires introducing a WindowsError variant in the IoError enum
and implementing the VisitProvenance trait for IoErrors.
  • Loading branch information
noahmbright committed Oct 29, 2024
1 parent f5c38d6 commit e9f70f3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/concurrency/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
retval_succ: Scalar,
retval_timeout: Scalar,
dest: MPlaceTy<'tcx>,
errno_timeout: Scalar,
errno_timeout: shims::io_error::IoError,
) {
let this = self.eval_context_mut();
let thread = this.active_thread();
Expand All @@ -713,7 +713,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
retval_succ: Scalar,
retval_timeout: Scalar,
dest: MPlaceTy<'tcx>,
errno_timeout: Scalar,
errno_timeout: shims::io_error::IoError,
}
@unblock = |this| {
let futex = this.machine.sync.futexes.get(&addr).unwrap();
Expand Down
12 changes: 12 additions & 0 deletions src/provenance_gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use either::Either;
use rustc_data_structures::fx::FxHashSet;

use crate::*;
use crate::shims::io_error::IoError::*;

pub type VisitWith<'a> = dyn FnMut(Option<AllocId>, Option<BorTag>) + 'a;

Expand Down Expand Up @@ -89,6 +90,17 @@ impl VisitProvenance for Scalar {
}
}

impl VisitProvenance for IoError{
fn visit_provenance(&self, visit: &mut VisitWith<'_>) {
match self{
LibcError(_name) => (),
WindowsError(_name) => (),
HostError(_io_error) => (),
Raw(scalar) => scalar.visit_provenance(visit),
}
}
}

impl VisitProvenance for Immediate<Provenance> {
fn visit_provenance(&self, visit: &mut VisitWith<'_>) {
match self {
Expand Down
2 changes: 2 additions & 0 deletions src/shims/io_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::*;
#[derive(Debug)]
pub enum IoError {
LibcError(&'static str),
WindowsError(&'static str),
HostError(io::Error),
Raw(Scalar),
}
Expand Down Expand Up @@ -113,6 +114,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
let errno = match err.into() {
HostError(err) => this.io_error_to_errnum(err)?,
LibcError(name) => this.eval_libc(name),
WindowsError(name) => this.eval_windows("c", name),
Raw(val) => val,
};
let errno_place = this.last_error_place()?;
Expand Down
2 changes: 1 addition & 1 deletion src/shims/unix/linux/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ 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"), // errno_timeout
LibcError("ETIMEDOUT"), // errno_timeout
);
} else {
// The futex value doesn't match the expected value, so we return failure
Expand Down
3 changes: 2 additions & 1 deletion src/shims/windows/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::time::Duration;
use rustc_target::abi::Size;

use crate::concurrency::init_once::InitOnceStatus;
use crate::shims::io_error::IoError::WindowsError;
use crate::*;

#[derive(Copy, Clone)]
Expand Down Expand Up @@ -202,7 +203,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"), // errno_timeout
WindowsError("ERROR_TIMEOUT"), // errno_timeout
);
}

Expand Down

0 comments on commit e9f70f3

Please sign in to comment.