Skip to content

Commit d9ecd77

Browse files
committed
add dummy stat shim
1 parent aafb7c9 commit d9ecd77

File tree

3 files changed

+54
-7
lines changed

3 files changed

+54
-7
lines changed

src/shims/foreign_items.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
494494
this.write_scalar(Scalar::from_int(result, dest.layout.size), dest)?;
495495
}
496496

497+
"stat64" => {
498+
let result = this.stat(args[0], args[1])?;
499+
this.write_scalar(Scalar::from_int(result, dest.layout.size), dest)?;
500+
}
501+
497502
"clock_gettime" => {
498503
let result = this.clock_gettime(args[0], args[1])?;
499504
this.write_scalar(Scalar::from_int(result, dest.layout.size), dest)?;

src/shims/fs.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,55 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
261261
this.try_unwrap_io_result(result)
262262
}
263263

264+
fn stat(&mut self,
265+
_path_op: OpTy<'tcx, Tag>,
266+
buf_op: OpTy<'tcx, Tag>,
267+
) -> InterpResult<'tcx, i32> {
268+
let this = self.eval_context_mut();
269+
270+
let buf = this.deref_operand(buf_op)?;
271+
272+
let dev_t_layout = this.libc_ty_layout("dev_t")?;
273+
let mode_t_layout = this.libc_ty_layout("mode_t")?;
274+
let nlink_t_layout = this.libc_ty_layout("nlink_t")?;
275+
let ino_t_layout = this.libc_ty_layout("ino_t")?;
276+
let uid_t_layout = this.libc_ty_layout("uid_t")?;
277+
let gid_t_layout = this.libc_ty_layout("gid_t")?;
278+
let time_t_layout = this.libc_ty_layout("time_t")?;
279+
let long_layout = this.libc_ty_layout("c_long")?;
280+
let off_t_layout = this.libc_ty_layout("off_t")?;
281+
let blkcnt_t_layout = this.libc_ty_layout("blkcnt_t")?;
282+
let blksize_t_layout = this.libc_ty_layout("blksize_t")?;
283+
let uint32_t_layout = this.libc_ty_layout("uint32_t")?;
284+
285+
let imms = [
286+
immty_from_uint_checked(0u128, dev_t_layout)?, // st_dev
287+
immty_from_uint_checked(0u128, mode_t_layout)?, // st_mode
288+
immty_from_uint_checked(0u128, nlink_t_layout)?, // st_nlink
289+
immty_from_uint_checked(0u128, ino_t_layout)?, // st_ino
290+
immty_from_uint_checked(0u128, uid_t_layout)?, // st_uid
291+
immty_from_uint_checked(0u128, gid_t_layout)?, // st_gid
292+
immty_from_uint_checked(0u128, dev_t_layout)?, // st_rdev
293+
immty_from_uint_checked(0u128, time_t_layout)?, // st_atime
294+
immty_from_uint_checked(0u128, long_layout)?, // st_atime_nsec
295+
immty_from_uint_checked(0u128, time_t_layout)?, // st_mtime
296+
immty_from_uint_checked(0u128, long_layout)?, // st_mtime_nsec
297+
immty_from_uint_checked(0u128, time_t_layout)?, // st_ctime
298+
immty_from_uint_checked(0u128, long_layout)?, // st_ctime_nsec
299+
immty_from_uint_checked(0u128, time_t_layout)?, // st_birthtime
300+
immty_from_uint_checked(0u128, long_layout)?, // st_birthtime_nsec
301+
immty_from_uint_checked(0u128, off_t_layout)?, // st_size
302+
immty_from_uint_checked(0u128, blkcnt_t_layout)?, // st_blocks
303+
immty_from_uint_checked(0u128, blksize_t_layout)?, // st_blksize
304+
immty_from_uint_checked(0u128, uint32_t_layout)?, // st_flags
305+
immty_from_uint_checked(0u128, uint32_t_layout)?, // st_gen
306+
];
307+
308+
this.write_packed_immediates(&buf, &imms)?;
309+
310+
Ok(0)
311+
}
312+
264313
fn statx(
265314
&mut self,
266315
dirfd_op: OpTy<'tcx, Tag>, // Should be an `int`

tests/run-pass/fs.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use std::fs::{File, remove_file};
55
use std::io::{Read, Write, ErrorKind, Result};
66
use std::path::{PathBuf, Path};
77

8-
#[cfg(target_os = "linux")]
98
fn test_metadata(bytes: &[u8], path: &Path) -> Result<()> {
109
// Test that the file metadata is correct.
1110
let metadata = path.metadata()?;
@@ -16,12 +15,6 @@ fn test_metadata(bytes: &[u8], path: &Path) -> Result<()> {
1615
Ok(())
1716
}
1817

19-
// FIXME: Implement stat64 for macos.
20-
#[cfg(not(target_os = "linux"))]
21-
fn test_metadata(_bytes: &[u8], _path: &Path) -> Result<()> {
22-
Ok(())
23-
}
24-
2518
fn main() {
2619
let tmp = std::env::temp_dir();
2720
let filename = PathBuf::from("miri_test_fs.txt");

0 commit comments

Comments
 (0)