Skip to content

Commit a26b26a

Browse files
committed
cleanup: the *64 functions are Linux-specific
1 parent 44aaae3 commit a26b26a

File tree

5 files changed

+80
-75
lines changed

5 files changed

+80
-75
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/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: 2 additions & 2 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)?;

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)