Skip to content

Commit 042f762

Browse files
committed
Change futex_wait errno from Scalar to IoError
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.
1 parent d581d80 commit 042f762

File tree

5 files changed

+18
-4
lines changed

5 files changed

+18
-4
lines changed

src/tools/miri/src/concurrency/sync.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
696696
retval_succ: Scalar,
697697
retval_timeout: Scalar,
698698
dest: MPlaceTy<'tcx>,
699-
errno_timeout: Scalar,
699+
errno_timeout: IoError,
700700
) {
701701
let this = self.eval_context_mut();
702702
let thread = this.active_thread();
@@ -713,7 +713,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
713713
retval_succ: Scalar,
714714
retval_timeout: Scalar,
715715
dest: MPlaceTy<'tcx>,
716-
errno_timeout: Scalar,
716+
errno_timeout: IoError,
717717
}
718718
@unblock = |this| {
719719
let futex = this.machine.sync.futexes.get(&addr).unwrap();

src/tools/miri/src/provenance_gc.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,18 @@ impl VisitProvenance for Scalar {
8989
}
9090
}
9191

92+
impl VisitProvenance for IoError {
93+
fn visit_provenance(&self, visit: &mut VisitWith<'_>) {
94+
use crate::shims::io_error::IoError::*;
95+
match self {
96+
LibcError(_name) => (),
97+
WindowsError(_name) => (),
98+
HostError(_io_error) => (),
99+
Raw(scalar) => scalar.visit_provenance(visit),
100+
}
101+
}
102+
}
103+
92104
impl VisitProvenance for Immediate<Provenance> {
93105
fn visit_provenance(&self, visit: &mut VisitWith<'_>) {
94106
match self {

src/tools/miri/src/shims/io_error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::*;
77
#[derive(Debug)]
88
pub enum IoError {
99
LibcError(&'static str),
10+
WindowsError(&'static str),
1011
HostError(io::Error),
1112
Raw(Scalar),
1213
}
@@ -113,6 +114,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
113114
let errno = match err.into() {
114115
HostError(err) => this.io_error_to_errnum(err)?,
115116
LibcError(name) => this.eval_libc(name),
117+
WindowsError(name) => this.eval_windows("c", name),
116118
Raw(val) => val,
117119
};
118120
let errno_place = this.last_error_place()?;

src/tools/miri/src/shims/unix/linux/sync.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ pub fn futex<'tcx>(
150150
Scalar::from_target_isize(0, this), // retval_succ
151151
Scalar::from_target_isize(-1, this), // retval_timeout
152152
dest.clone(),
153-
this.eval_libc("ETIMEDOUT"), // errno_timeout
153+
LibcError("ETIMEDOUT"), // errno_timeout
154154
);
155155
} else {
156156
// The futex value doesn't match the expected value, so we return failure

src/tools/miri/src/shims/windows/sync.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
202202
Scalar::from_i32(1), // retval_succ
203203
Scalar::from_i32(0), // retval_timeout
204204
dest.clone(),
205-
this.eval_windows("c", "ERROR_TIMEOUT"), // errno_timeout
205+
IoError::WindowsError("ERROR_TIMEOUT"), // errno_timeout
206206
);
207207
}
208208

0 commit comments

Comments
 (0)