Skip to content

Commit ccefb74

Browse files
authored
Merge pull request #4745 from RalfJung/fs-shim-cleanup
fs shims: remove some aliases that don't actually exist or are not used on those targets
2 parents e7650fd + a26b26a commit ccefb74

File tree

7 files changed

+85
-111
lines changed

7 files changed

+85
-111
lines changed

src/tools/miri/src/shims/unix/foreign_items.rs

Lines changed: 1 addition & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -235,33 +235,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
235235
trace!("Called pwrite({:?}, {:?}, {:?}, {:?})", fd, buf, count, offset);
236236
this.write(fd, buf, count, Some(offset), dest)?;
237237
}
238-
"pread64" => {
239-
let [fd, buf, count, offset] = this.check_shim_sig(
240-
shim_sig!(extern "C" fn(i32, *mut _, usize, libc::off64_t) -> isize),
241-
link_name,
242-
abi,
243-
args,
244-
)?;
245-
let fd = this.read_scalar(fd)?.to_i32()?;
246-
let buf = this.read_pointer(buf)?;
247-
let count = this.read_target_usize(count)?;
248-
let offset = this.read_scalar(offset)?.to_int(offset.layout.size)?;
249-
this.read(fd, buf, count, Some(offset), dest)?;
250-
}
251-
"pwrite64" => {
252-
let [fd, buf, n, offset] = this.check_shim_sig(
253-
shim_sig!(extern "C" fn(i32, *const _, usize, libc::off64_t) -> isize),
254-
link_name,
255-
abi,
256-
args,
257-
)?;
258-
let fd = this.read_scalar(fd)?.to_i32()?;
259-
let buf = this.read_pointer(buf)?;
260-
let count = this.read_target_usize(n)?;
261-
let offset = this.read_scalar(offset)?.to_int(offset.layout.size)?;
262-
trace!("Called pwrite64({:?}, {:?}, {:?}, {:?})", fd, buf, count, offset);
263-
this.write(fd, buf, count, Some(offset), dest)?;
264-
}
265238
"close" => {
266239
let [fd] = this.check_shim_sig(
267240
shim_sig!(extern "C" fn(i32) -> i32),
@@ -317,7 +290,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
317290
}
318291

319292
// File and file system access
320-
"open" | "open64" => {
293+
"open" => {
321294
// `open` is variadic, the third argument is only present when the second argument
322295
// has O_CREAT (or on linux O_TMPFILE, but miri doesn't support that) set
323296
let ([path_raw, flag], varargs) =
@@ -400,18 +373,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
400373
let result = this.closedir(dirp)?;
401374
this.write_scalar(result, dest)?;
402375
}
403-
"lseek64" => {
404-
let [fd, offset, whence] = this.check_shim_sig(
405-
shim_sig!(extern "C" fn(i32, libc::off64_t, i32) -> libc::off64_t),
406-
link_name,
407-
abi,
408-
args,
409-
)?;
410-
let fd = this.read_scalar(fd)?.to_i32()?;
411-
let offset = this.read_scalar(offset)?.to_int(offset.layout.size)?;
412-
let whence = this.read_scalar(whence)?.to_i32()?;
413-
this.lseek64(fd, offset, whence, dest)?;
414-
}
415376
"lseek" => {
416377
let [fd, offset, whence] = this.check_shim_sig(
417378
shim_sig!(extern "C" fn(i32, libc::off_t, i32) -> libc::off_t),
@@ -424,18 +385,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
424385
let whence = this.read_scalar(whence)?.to_i32()?;
425386
this.lseek64(fd, offset, whence, dest)?;
426387
}
427-
"ftruncate64" => {
428-
let [fd, length] = this.check_shim_sig(
429-
shim_sig!(extern "C" fn(i32, libc::off64_t) -> i32),
430-
link_name,
431-
abi,
432-
args,
433-
)?;
434-
let fd = this.read_scalar(fd)?.to_i32()?;
435-
let length = this.read_scalar(length)?.to_int(length.layout.size)?;
436-
let result = this.ftruncate64(fd, length)?;
437-
this.write_scalar(result, dest)?;
438-
}
439388
"ftruncate" => {
440389
let [fd, length] = this.check_shim_sig(
441390
shim_sig!(extern "C" fn(i32, libc::off_t) -> i32),
@@ -516,24 +465,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
516465
this.write_scalar(result, dest)?;
517466
}
518467

519-
"posix_fallocate64" => {
520-
// posix_fallocate64 is only supported on Linux and Android
521-
this.check_target_os(&[Os::Linux, Os::Android], link_name)?;
522-
let [fd, offset, len] = this.check_shim_sig(
523-
shim_sig!(extern "C" fn(i32, libc::off64_t, libc::off64_t) -> i32),
524-
link_name,
525-
abi,
526-
args,
527-
)?;
528-
529-
let fd = this.read_scalar(fd)?.to_i32()?;
530-
let offset = this.read_scalar(offset)?.to_i64()?;
531-
let len = this.read_scalar(len)?.to_i64()?;
532-
533-
let result = this.posix_fallocate(fd, offset, len)?;
534-
this.write_scalar(result, dest)?;
535-
}
536-
537468
"realpath" => {
538469
let [path, resolved_path] = this.check_shim_sig(
539470
shim_sig!(extern "C" fn(*const _, *mut _) -> *mut _),

src/tools/miri/src/shims/unix/freebsd/foreign_items.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
153153
let result = this.fstat(fd, buf)?;
154154
this.write_scalar(result, dest)?;
155155
}
156-
"readdir_r" | "readdir_r@FBSD_1.0" => {
157-
let [dirp, entry, result] =
158-
this.check_shim_sig_lenient(abi, CanonAbi::C, link_name, args)?;
159-
let result = this.macos_fbsd_readdir_r(dirp, entry, result)?;
160-
this.write_scalar(result, dest)?;
161-
}
162156
"readdir" | "readdir@FBSD_1.0" => {
163157
let [dirp] = this.check_shim_sig_lenient(abi, CanonAbi::C, link_name, args)?;
164158
let result = this.readdir64("dirent", dirp)?;

src/tools/miri/src/shims/unix/fs.rs

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,17 +1030,15 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
10301030
interp_ok(Scalar::from_maybe_pointer(entry.unwrap_or_else(Pointer::null), this))
10311031
}
10321032

1033-
fn macos_fbsd_readdir_r(
1033+
fn macos_readdir_r(
10341034
&mut self,
10351035
dirp_op: &OpTy<'tcx>,
10361036
entry_op: &OpTy<'tcx>,
10371037
result_op: &OpTy<'tcx>,
10381038
) -> InterpResult<'tcx, Scalar> {
10391039
let this = self.eval_context_mut();
10401040

1041-
if !matches!(&this.tcx.sess.target.os, Os::MacOs | Os::FreeBsd) {
1042-
panic!("`macos_fbsd_readdir_r` should not be called on {}", this.tcx.sess.target.os);
1043-
}
1041+
this.assert_target_os(Os::MacOs, "readdir_r");
10441042

10451043
let dirp = this.read_target_usize(dirp_op)?;
10461044
let result_place = this.deref_pointer_as(result_op, this.machine.layouts.mut_raw_ptr)?;
@@ -1096,39 +1094,16 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
10961094

10971095
let file_type = this.file_type_to_d_type(dir_entry.file_type())?;
10981096

1099-
// Common fields.
11001097
this.write_int_fields_named(
11011098
&[
11021099
("d_reclen", 0),
11031100
("d_namlen", file_name_len.into()),
11041101
("d_type", file_type.into()),
1102+
("d_ino", ino.into()),
1103+
("d_seekoff", 0),
11051104
],
11061105
&entry_place,
11071106
)?;
1108-
// Special fields.
1109-
match this.tcx.sess.target.os {
1110-
Os::MacOs => {
1111-
#[rustfmt::skip]
1112-
this.write_int_fields_named(
1113-
&[
1114-
("d_ino", ino.into()),
1115-
("d_seekoff", 0),
1116-
],
1117-
&entry_place,
1118-
)?;
1119-
}
1120-
Os::FreeBsd => {
1121-
#[rustfmt::skip]
1122-
this.write_int_fields_named(
1123-
&[
1124-
("d_fileno", ino.into()),
1125-
("d_off", 0),
1126-
],
1127-
&entry_place,
1128-
)?;
1129-
}
1130-
_ => unreachable!(),
1131-
}
11321107
this.write_scalar(this.read_scalar(entry_op)?, &result_place)?;
11331108

11341109
Scalar::from_i32(0)

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

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,80 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
3636

3737
match link_name.as_str() {
3838
// File related shims
39+
"open64" => {
40+
// `open64` is variadic, the third argument is only present when the second argument
41+
// has O_CREAT (or on linux O_TMPFILE, but miri doesn't support that) set
42+
let ([path_raw, flag], varargs) =
43+
this.check_shim_sig_variadic_lenient(abi, CanonAbi::C, link_name, args)?;
44+
let result = this.open(path_raw, flag, varargs)?;
45+
this.write_scalar(result, dest)?;
46+
}
47+
"pread64" => {
48+
let [fd, buf, count, offset] = this.check_shim_sig(
49+
shim_sig!(extern "C" fn(i32, *mut _, usize, libc::off64_t) -> isize),
50+
link_name,
51+
abi,
52+
args,
53+
)?;
54+
let fd = this.read_scalar(fd)?.to_i32()?;
55+
let buf = this.read_pointer(buf)?;
56+
let count = this.read_target_usize(count)?;
57+
let offset = this.read_scalar(offset)?.to_int(offset.layout.size)?;
58+
this.read(fd, buf, count, Some(offset), dest)?;
59+
}
60+
"pwrite64" => {
61+
let [fd, buf, n, offset] = this.check_shim_sig(
62+
shim_sig!(extern "C" fn(i32, *const _, usize, libc::off64_t) -> isize),
63+
link_name,
64+
abi,
65+
args,
66+
)?;
67+
let fd = this.read_scalar(fd)?.to_i32()?;
68+
let buf = this.read_pointer(buf)?;
69+
let count = this.read_target_usize(n)?;
70+
let offset = this.read_scalar(offset)?.to_int(offset.layout.size)?;
71+
trace!("Called pwrite64({:?}, {:?}, {:?}, {:?})", fd, buf, count, offset);
72+
this.write(fd, buf, count, Some(offset), dest)?;
73+
}
74+
"lseek64" => {
75+
let [fd, offset, whence] = this.check_shim_sig(
76+
shim_sig!(extern "C" fn(i32, libc::off64_t, i32) -> libc::off64_t),
77+
link_name,
78+
abi,
79+
args,
80+
)?;
81+
let fd = this.read_scalar(fd)?.to_i32()?;
82+
let offset = this.read_scalar(offset)?.to_int(offset.layout.size)?;
83+
let whence = this.read_scalar(whence)?.to_i32()?;
84+
this.lseek64(fd, offset, whence, dest)?;
85+
}
86+
"ftruncate64" => {
87+
let [fd, length] = this.check_shim_sig(
88+
shim_sig!(extern "C" fn(i32, libc::off64_t) -> i32),
89+
link_name,
90+
abi,
91+
args,
92+
)?;
93+
let fd = this.read_scalar(fd)?.to_i32()?;
94+
let length = this.read_scalar(length)?.to_int(length.layout.size)?;
95+
let result = this.ftruncate64(fd, length)?;
96+
this.write_scalar(result, dest)?;
97+
}
98+
"posix_fallocate64" => {
99+
let [fd, offset, len] = this.check_shim_sig(
100+
shim_sig!(extern "C" fn(i32, libc::off64_t, libc::off64_t) -> i32),
101+
link_name,
102+
abi,
103+
args,
104+
)?;
105+
106+
let fd = this.read_scalar(fd)?.to_i32()?;
107+
let offset = this.read_scalar(offset)?.to_i64()?;
108+
let len = this.read_scalar(len)?.to_i64()?;
109+
110+
let result = this.posix_fallocate(fd, offset, len)?;
111+
this.write_scalar(result, dest)?;
112+
}
39113
"readdir64" => {
40114
let [dirp] = this.check_shim_sig_lenient(abi, CanonAbi::C, link_name, args)?;
41115
let result = this.readdir64("dirent64", dirp)?;

src/tools/miri/src/shims/unix/macos/foreign_items.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
4646
let result = this.close(result)?;
4747
this.write_scalar(result, dest)?;
4848
}
49-
"stat" | "stat64" | "stat$INODE64" => {
49+
"stat" | "stat$INODE64" => {
5050
let [path, buf] = this.check_shim_sig_lenient(abi, CanonAbi::C, link_name, args)?;
5151
let result = this.macos_fbsd_solarish_stat(path, buf)?;
5252
this.write_scalar(result, dest)?;
5353
}
54-
"lstat" | "lstat64" | "lstat$INODE64" => {
54+
"lstat" | "lstat$INODE64" => {
5555
let [path, buf] = this.check_shim_sig_lenient(abi, CanonAbi::C, link_name, args)?;
5656
let result = this.macos_fbsd_solarish_lstat(path, buf)?;
5757
this.write_scalar(result, dest)?;
@@ -69,7 +69,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
6969
"readdir_r" | "readdir_r$INODE64" => {
7070
let [dirp, entry, result] =
7171
this.check_shim_sig_lenient(abi, CanonAbi::C, link_name, args)?;
72-
let result = this.macos_fbsd_readdir_r(dirp, entry, result)?;
72+
let result = this.macos_readdir_r(dirp, entry, result)?;
7373
this.write_scalar(result, dest)?;
7474
}
7575
"realpath$DARWIN_EXTSN" => {

src/tools/miri/src/shims/unix/solarish/foreign_items.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
9090
}
9191

9292
// File related shims
93-
"stat" | "stat64" => {
93+
"stat" => {
9494
let [path, buf] = this.check_shim_sig_lenient(abi, CanonAbi::C, link_name, args)?;
9595
let result = this.macos_fbsd_solarish_stat(path, buf)?;
9696
this.write_scalar(result, dest)?;
9797
}
98-
"lstat" | "lstat64" => {
98+
"lstat" => {
9999
let [path, buf] = this.check_shim_sig_lenient(abi, CanonAbi::C, link_name, args)?;
100100
let result = this.macos_fbsd_solarish_lstat(path, buf)?;
101101
this.write_scalar(result, dest)?;

src/tools/miri/tests/pass-dep/libc/libc-fs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn main() {
3838
test_posix_fadvise();
3939
#[cfg(not(target_os = "macos"))]
4040
test_posix_fallocate::<libc::off_t>(libc::posix_fallocate);
41-
#[cfg(any(target_os = "linux", target_os = "android"))]
41+
#[cfg(target_os = "linux")]
4242
test_posix_fallocate::<libc::off64_t>(libc::posix_fallocate64);
4343
#[cfg(target_os = "linux")]
4444
test_sync_file_range();

0 commit comments

Comments
 (0)