diff --git a/src/shims/unix/foreign_items.rs b/src/shims/unix/foreign_items.rs index d155623eb7..bace31fe02 100644 --- a/src/shims/unix/foreign_items.rs +++ b/src/shims/unix/foreign_items.rs @@ -163,9 +163,24 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { "ftruncate64" => { let [fd, length] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; + let fd = this.read_scalar(fd)?.to_i32()?; + let length = this.read_scalar(length)?.to_i64()?; let result = this.ftruncate64(fd, length)?; this.write_scalar(result, dest)?; } + "ftruncate" => { + let [fd, length] = + this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; + let fd = this.read_scalar(fd)?.to_i32()?; + let length_type: i64; + if this.tcx.sess.target.pointer_width == 64 { + length_type = this.read_scalar(length)?.to_i64()?; + } else { + length_type = this.read_scalar(length)?.to_i32()? as i64; + } + let result = this.ftruncate64(fd, length_type)?; + this.write_scalar(result, dest)?; + } "fsync" => { let [fd] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let result = this.fsync(fd)?; diff --git a/src/shims/unix/freebsd/foreign_items.rs b/src/shims/unix/freebsd/foreign_items.rs index 41d395dd0c..7c843e106e 100644 --- a/src/shims/unix/freebsd/foreign_items.rs +++ b/src/shims/unix/freebsd/foreign_items.rs @@ -3,7 +3,6 @@ use rustc_target::spec::abi::Abi; use crate::*; use shims::foreign_items::EmulateForeignItemResult; -use shims::unix::fs::EvalContextExt as _; use shims::unix::thread::EvalContextExt as _; pub fn is_dyn_sym(_name: &str) -> bool { @@ -63,15 +62,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { this.gen_random(ptr, len)?; this.write_scalar(Scalar::from_target_usize(len, this), dest)?; } - "ftruncate" => { - if this.tcx.sess.target.pointer_width == 32 { - throw_unsup_format!("`ftruncate` is not supported on 32 bits"); - } - let [fd, length] = - this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; - let result = this.ftruncate64(fd, length)?; - this.write_scalar(result, dest)?; - } // errno "__error" => { diff --git a/src/shims/unix/fs.rs b/src/shims/unix/fs.rs index 062623a7f6..721fa16123 100644 --- a/src/shims/unix/fs.rs +++ b/src/shims/unix/fs.rs @@ -1504,16 +1504,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { } } - fn ftruncate64( - &mut self, - fd_op: &OpTy<'tcx, Provenance>, - length_op: &OpTy<'tcx, Provenance>, - ) -> InterpResult<'tcx, Scalar> { + fn ftruncate64(&mut self, fd: i32, length: i64) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); - let fd = this.read_scalar(fd_op)?.to_i32()?; - let length = this.read_scalar(length_op)?.to_i64()?; - // Reject if isolation is enabled. if let IsolatedOp::Reject(reject_with) = this.machine.isolated_op { this.reject_in_isolation("`ftruncate64`", reject_with)?; diff --git a/src/shims/unix/macos/foreign_items.rs b/src/shims/unix/macos/foreign_items.rs index e8f35e7ba5..07e19cadd6 100644 --- a/src/shims/unix/macos/foreign_items.rs +++ b/src/shims/unix/macos/foreign_items.rs @@ -72,13 +72,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { let result = this.lseek64(fd, offset, whence)?; this.write_scalar(result, dest)?; } - "ftruncate" => { - let [fd, length] = - this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; - // macOS is 64bit-only, so this is ftruncate64 - let result = this.ftruncate64(fd, length)?; - this.write_scalar(result, dest)?; - } "realpath$DARWIN_EXTSN" => { let [path, resolved_path] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; diff --git a/tests/pass-dep/shims/libc-misc.rs b/tests/pass-dep/shims/libc-misc.rs index 635a1215b4..6a8430f356 100644 --- a/tests/pass-dep/shims/libc-misc.rs +++ b/tests/pass-dep/shims/libc-misc.rs @@ -237,7 +237,6 @@ fn test_isatty() { } } -#[cfg(not(all(target_os = "freebsd", pointer_width = "32")))] fn test_posix_mkstemp() { use std::ffi::CString; use std::ffi::OsStr; @@ -416,7 +415,6 @@ fn main() { test_isatty(); - //#[cfg(not(target_os = "freebsd"))] // FIXME we should support this on FreeBSD as well test_clocks(); test_dlsym();