From 98d20490f4dd104f684f52e33adbdbedc92ab720 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 2 Jul 2022 08:58:04 -0400 Subject: [PATCH] move some POSIX file shims from linux to unix module --- src/shims/unix/foreign_items.rs | 19 +++++++++++++++++-- src/shims/unix/linux/foreign_items.rs | 18 ------------------ src/shims/unix/macos/foreign_items.rs | 12 ++++++++++-- 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/shims/unix/foreign_items.rs b/src/shims/unix/foreign_items.rs index 4a452800044..43b0f7df7f0 100644 --- a/src/shims/unix/foreign_items.rs +++ b/src/shims/unix/foreign_items.rs @@ -62,6 +62,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx let result = this.open(args)?; this.write_scalar(Scalar::from_i32(result), dest)?; } + "close" => { + let [fd] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; + let result = this.close(fd)?; + this.write_scalar(Scalar::from_i32(result), dest)?; + } "fcntl" => { // `fcntl` is variadic. The argument count is checked based on the first argument // in `this.fcntl()`, so we do not use `check_shim` here. @@ -112,17 +117,27 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx let result = this.rmdir(path)?; this.write_scalar(Scalar::from_i32(result), dest)?; } + "opendir" => { + let [name] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; + let result = this.opendir(name)?; + this.write_scalar(result, dest)?; + } "closedir" => { let [dirp] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let result = this.closedir(dirp)?; this.write_scalar(Scalar::from_i32(result), dest)?; } - "lseek" | "lseek64" => { + "lseek64" => { let [fd, offset, whence] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let result = this.lseek64(fd, offset, whence)?; - // "lseek" is only used on macOS which is 64bit-only, so `i64` always works. this.write_scalar(Scalar::from_i64(result), dest)?; } + "ftruncate64" => { + let [fd, length] = + this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; + let result = this.ftruncate64(fd, length)?; + this.write_scalar(Scalar::from_i32(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/linux/foreign_items.rs b/src/shims/unix/linux/foreign_items.rs index 48abe9bf08c..d89a2c78f4b 100644 --- a/src/shims/unix/linux/foreign_items.rs +++ b/src/shims/unix/linux/foreign_items.rs @@ -30,29 +30,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx } // File related shims (but also see "syscall" below for statx) - // These symbols have different names on Linux and macOS, which is the only reason they are not - // in the `posix` module. - "close" => { - let [fd] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; - let result = this.close(fd)?; - this.write_scalar(Scalar::from_i32(result), dest)?; - } - "opendir" => { - let [name] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; - let result = this.opendir(name)?; - this.write_scalar(result, dest)?; - } "readdir64" => { let [dirp] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let result = this.linux_readdir64(dirp)?; this.write_scalar(result, dest)?; } - "ftruncate64" => { - let [fd, length] = - this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; - let result = this.ftruncate64(fd, length)?; - this.write_scalar(Scalar::from_i32(result), dest)?; - } // Linux-only "posix_fadvise" => { let [fd, offset, len, advice] = diff --git a/src/shims/unix/macos/foreign_items.rs b/src/shims/unix/macos/foreign_items.rs index 5cd885db709..089a082fa36 100644 --- a/src/shims/unix/macos/foreign_items.rs +++ b/src/shims/unix/macos/foreign_items.rs @@ -28,7 +28,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx } // File related shims - "close" | "close$NOCANCEL" => { + "close$NOCANCEL" => { let [result] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let result = this.close(result)?; this.write_scalar(Scalar::from_i32(result), dest)?; @@ -50,7 +50,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx let result = this.macos_fstat(fd, buf)?; this.write_scalar(Scalar::from_i32(result), dest)?; } - "opendir" | "opendir$INODE64" => { + "opendir$INODE64" => { let [name] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let result = this.opendir(name)?; this.write_scalar(result, dest)?; @@ -61,9 +61,17 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx let result = this.macos_readdir_r(dirp, entry, result)?; this.write_scalar(Scalar::from_i32(result), dest)?; } + "lseek" => { + let [fd, offset, whence] = + this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; + // macOS is 64bit-only, so this is lseek64 + let result = this.lseek64(fd, offset, whence)?; + this.write_scalar(Scalar::from_i64(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(Scalar::from_i32(result), dest)?; }