Skip to content

Commit 2350ba7

Browse files
committed
some more opportunities for set_last_error_and_return
1 parent 82b041e commit 2350ba7

File tree

3 files changed

+7
-14
lines changed

3 files changed

+7
-14
lines changed

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -433,9 +433,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
433433
let timeout = this.read_scalar(timeout)?.to_i32()?;
434434

435435
if epfd_value <= 0 || maxevents <= 0 {
436-
this.set_last_error(LibcError("EINVAL"))?;
437-
this.write_int(-1, dest)?;
438-
return interp_ok(());
436+
return this.set_last_error_and_return(LibcError("EINVAL"), dest);
439437
}
440438

441439
// This needs to come after the maxevents value check, or else maxevents.try_into().unwrap()

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

+5-10
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ pub fn futex<'tcx>(
6363
};
6464

6565
if bitset == 0 {
66-
this.set_last_error(LibcError("EINVAL"))?;
67-
this.write_scalar(Scalar::from_target_isize(-1, this), dest)?;
66+
this.set_last_error_and_return(LibcError("EINVAL"), dest)?;
6867
return interp_ok(());
6968
}
7069

@@ -75,9 +74,7 @@ pub fn futex<'tcx>(
7574
let duration = match this.read_timespec(&timeout)? {
7675
Some(duration) => duration,
7776
None => {
78-
this.set_last_error(LibcError("EINVAL"))?;
79-
this.write_scalar(Scalar::from_target_isize(-1, this), dest)?;
80-
return interp_ok(());
77+
return this.set_last_error_and_return(LibcError("EINVAL"), dest);
8178
}
8279
};
8380
let timeout_clock = if op & futex_realtime == futex_realtime {
@@ -153,12 +150,12 @@ pub fn futex<'tcx>(
153150
Scalar::from_target_isize(0, this), // retval_succ
154151
Scalar::from_target_isize(-1, this), // retval_timeout
155152
dest.clone(),
156-
this.eval_libc("ETIMEDOUT"),
153+
this.eval_libc("ETIMEDOUT"), // errno_timeout
157154
);
158155
} else {
159156
// The futex value doesn't match the expected value, so we return failure
160157
// right away without sleeping: -1 and errno set to EAGAIN.
161-
this.set_last_error_and_return(LibcError("EAGAIN"), dest)?;
158+
return this.set_last_error_and_return(LibcError("EAGAIN"), dest);
162159
}
163160
}
164161
// FUTEX_WAKE: (int *addr, int op = FUTEX_WAKE, int val)
@@ -178,9 +175,7 @@ pub fn futex<'tcx>(
178175
u32::MAX
179176
};
180177
if bitset == 0 {
181-
this.set_last_error(LibcError("EINVAL"))?;
182-
this.write_scalar(Scalar::from_target_isize(-1, this), dest)?;
183-
return interp_ok(());
178+
return this.set_last_error_and_return(LibcError("EINVAL"), dest);
184179
}
185180
// Together with the SeqCst fence in futex_wait, this makes sure that futex_wait
186181
// will see the latest value on addr which could be changed by our caller

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

+1-1
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"),
205+
this.eval_windows("c", "ERROR_TIMEOUT"), // errno_timeout
206206
);
207207
}
208208

0 commit comments

Comments
 (0)