Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 337fdf9

Browse files
committedOct 19, 2024
Implement set_last_error_and_return_i64, bug fixes
1 parent f7548cc commit 337fdf9

File tree

4 files changed

+28
-17
lines changed

4 files changed

+28
-17
lines changed
 

‎src/shims/io_error.rs

+10
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,16 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
141141
interp_ok(Scalar::from_i32(-1))
142142
}
143143

144+
/// Sets the last OS error and return `-1` as a `i32`-typed Scalar
145+
fn set_last_error_and_return_i64(
146+
&mut self,
147+
err: impl Into<IoError>,
148+
) -> InterpResult<'tcx, Scalar> {
149+
let this = self.eval_context_mut();
150+
this.set_last_error(err)?;
151+
interp_ok(Scalar::from_i64(-1))
152+
}
153+
144154
/// Gets the last error variable.
145155
fn get_last_error(&mut self) -> InterpResult<'tcx, Scalar> {
146156
let this = self.eval_context_mut();

‎src/shims/unix/fd.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
561561
/// types (like `read`, that returns an `i64`).
562562
fn fd_not_found<T: From<i32>>(&mut self) -> InterpResult<'tcx, T> {
563563
let this = self.eval_context_mut();
564-
return this.set_last_error_and_return_i32(LibcError("EBADF"));
564+
this.set_last_error(LibcError("EBADF"))?;
565+
Ok((-1).into())
565566
}
566567

567568
/// Read data from `fd` into buffer specified by `buf` and `count`.

‎src/shims/unix/fs.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use std::borrow::Cow;
44
use std::fs::{
5-
read_dir, remove_dir, remove_file, rename, DirBuilder, File, FileType, OpenOptions, ReadDir,
5+
DirBuilder, File, FileType, OpenOptions, ReadDir, read_dir, remove_dir, remove_file, rename,
66
};
77
use std::io::{self, ErrorKind, IsTerminal, Read, Seek, SeekFrom, Write};
88
use std::path::{Path, PathBuf};
@@ -203,7 +203,7 @@ impl FileDescription for FileHandle {
203203
ERROR_IO_PENDING, ERROR_LOCK_VIOLATION, FALSE, HANDLE, TRUE,
204204
};
205205
use windows_sys::Win32::Storage::FileSystem::{
206-
LockFileEx, UnlockFile, LOCKFILE_EXCLUSIVE_LOCK, LOCKFILE_FAIL_IMMEDIATELY,
206+
LOCKFILE_EXCLUSIVE_LOCK, LOCKFILE_FAIL_IMMEDIATELY, LockFileEx, UnlockFile,
207207
};
208208

209209
let fh = self.file.as_raw_handle() as HANDLE;
@@ -632,11 +632,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
632632
#[cfg(windows)]
633633
fn create_link(src: &Path, dst: &Path) -> std::io::Result<()> {
634634
use std::os::windows::fs;
635-
if src.is_dir() {
636-
fs::symlink_dir(src, dst)
637-
} else {
638-
fs::symlink_file(src, dst)
639-
}
635+
if src.is_dir() { fs::symlink_dir(src, dst) } else { fs::symlink_file(src, dst) }
640636
}
641637

642638
let this = self.eval_context_mut();
@@ -1227,13 +1223,17 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
12271223
this.write_null(&this.deref_pointer(result_op)?)?;
12281224
0
12291225
}
1230-
Some(Err(e)) => match e.raw_os_error() {
1231-
// return positive error number on error
1232-
Some(error) => error,
1233-
None => {
1234-
throw_unsup_format!("the error {} couldn't be converted to a return value", e)
1235-
}
1236-
},
1226+
Some(Err(e)) =>
1227+
match e.raw_os_error() {
1228+
// return positive error number on error
1229+
Some(error) => error,
1230+
None => {
1231+
throw_unsup_format!(
1232+
"the error {} couldn't be converted to a return value",
1233+
e
1234+
)
1235+
}
1236+
},
12371237
}))
12381238
}
12391239

@@ -1432,7 +1432,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
14321432
this.write_bytes_ptr(buf, path_bytes.iter().copied())?;
14331433
interp_ok(path_bytes.len().try_into().unwrap())
14341434
}
1435-
Err(e) => Ok(this.set_last_error_and_return_i64(e)),
1435+
Err(e) => this.set_last_error_and_return_i64(e),
14361436
}
14371437
}
14381438

‎src/shims/unix/linux/epoll.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
266266

267267
// Throw EINVAL if epfd and fd have the same value.
268268
if epfd_value == fd {
269-
this.set_last_error_and_return_i32(LibcError("EINVAL"))
269+
return this.set_last_error_and_return_i32(LibcError("EINVAL"));
270270
}
271271

272272
// Check if epfd is a valid epoll file descriptor.

0 commit comments

Comments
 (0)
Please sign in to comment.