diff --git a/src/shims/files.rs b/src/shims/files.rs index 0deecbfb0a..394211107c 100644 --- a/src/shims/files.rs +++ b/src/shims/files.rs @@ -301,8 +301,7 @@ impl FileDescription for FileHandle { } fn read<'tcx>( - &self, - _self_ref: &FileDescriptionRef, + self: FileDescriptionRef, communicate_allowed: bool, ptr: Pointer, len: usize, @@ -319,8 +318,7 @@ impl FileDescription for FileHandle { } fn write<'tcx>( - &self, - _self_ref: &FileDescriptionRef, + self: FileDescriptionRef, communicate_allowed: bool, ptr: Pointer, len: usize, @@ -346,7 +344,7 @@ impl FileDescription for FileHandle { } fn close<'tcx>( - self: Box, + self, communicate_allowed: bool, _ecx: &mut MiriInterpCx<'tcx>, ) -> InterpResult<'tcx, io::Result<()>> { @@ -357,7 +355,7 @@ impl FileDescription for FileHandle { // to handle possible errors correctly. let result = self.file.sync_all(); // Now we actually close the file and return the result. - drop(*self); + drop(self); interp_ok(result) } else { // We drop the file, this closes it but ignores any errors @@ -366,7 +364,7 @@ impl FileDescription for FileHandle { // `/dev/urandom` which are read-only. Check // https://github.com/rust-lang/miri/issues/999#issuecomment-568920439 // for a deeper discussion. - drop(*self); + drop(self); interp_ok(Ok(())) } } diff --git a/src/shims/unix/fs.rs b/src/shims/unix/fs.rs index db53e40fba..5da9f95ce0 100644 --- a/src/shims/unix/fs.rs +++ b/src/shims/unix/fs.rs @@ -13,7 +13,7 @@ use rustc_data_structures::fx::FxHashMap; use self::shims::time::system_time_to_duration; use crate::helpers::check_min_vararg_count; -use crate::shims::files::{EvalContextExt as _, FileHandle, FileDescription, FileDescriptionRef}; +use crate::shims::files::{EvalContextExt as _, FileHandle}; use crate::shims::os_str::bytes_to_os_str; use crate::shims::unix::fd::{FlockOp, UnixFileDescription}; use crate::*; diff --git a/src/shims/windows/foreign_items.rs b/src/shims/windows/foreign_items.rs index 588109e92c..72d76fef67 100644 --- a/src/shims/windows/foreign_items.rs +++ b/src/shims/windows/foreign_items.rs @@ -250,7 +250,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { creation_disposition, flags_and_attributes, template_file, - ] = this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?; + ] = this.check_shim(abi, sys_conv, link_name, args)?; let handle = this.CreateFileW( file_name, desired_access, @@ -263,8 +263,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { this.write_scalar(handle.to_scalar(this), dest)?; } "GetFileInformationByHandle" => { - let [handle, info] = - this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?; + let [handle, info] = this.check_shim(abi, sys_conv, link_name, args)?; let res = this.GetFileInformationByHandle(handle, info)?; this.write_scalar(res, dest)?; } diff --git a/src/shims/windows/fs.rs b/src/shims/windows/fs.rs index 0b0ff34e5e..13ed4d5475 100644 --- a/src/shims/windows/fs.rs +++ b/src/shims/windows/fs.rs @@ -1,6 +1,5 @@ use std::fs::{Metadata, OpenOptions}; use std::io; -use std::io::ErrorKind; use std::path::PathBuf; use std::time::SystemTime; @@ -25,7 +24,7 @@ impl FileDescription for DirHandle { } fn close<'tcx>( - self: Box, + self, _communicate_allowed: bool, _ecx: &mut MiriInterpCx<'tcx>, ) -> InterpResult<'tcx, io::Result<()>> { @@ -51,7 +50,7 @@ impl FileDescription for MetadataHandle { } fn close<'tcx>( - self: Box, + self, _communicate_allowed: bool, _ecx: &mut MiriInterpCx<'tcx>, ) -> InterpResult<'tcx, io::Result<()>> { @@ -115,7 +114,7 @@ impl FileAttributes { fn new<'tcx>( mut value: u32, ecx: &mut MiriInterpCx<'tcx>, - ) -> InterpResult<'tcx, Result> { + ) -> InterpResult<'tcx, FileAttributes> { let file_attribute_normal = ecx.eval_windows_u32("c", "FILE_ATTRIBUTE_NORMAL"); let file_flag_backup_semantics = ecx.eval_windows_u32("c", "FILE_FLAG_BACKUP_SEMANTICS"); let file_flag_open_reparse_point = @@ -128,7 +127,7 @@ impl FileAttributes { } else if value & file_flag_open_reparse_point != 0 { value &= !file_flag_open_reparse_point; out |= FileAttributes::OPEN_REPARSE; - } else if value & file_attribute_normal { + } else if value & file_attribute_normal != 0 { value &= !file_attribute_normal; out |= FileAttributes::NORMAL; } @@ -140,7 +139,7 @@ impl FileAttributes { if out == FileAttributes::ZERO { out = FileAttributes::NORMAL; } - interp_ok(Ok(out)) + interp_ok(out) } } @@ -189,7 +188,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { throw_unsup_format!("CreateFileW: Security attributes are not supported"); } - if attributes & FileAttributes::OPEN_REPARSE != 0 && creation_disposition == CreateAlways { + if attributes.contains(FileAttributes::OPEN_REPARSE) && creation_disposition == CreateAlways + { throw_machine_stop!(TerminationInfo::Abort("Invalid CreateFileW argument combination: FILE_FLAG_OPEN_REPARSE_POINT with CREATE_ALWAYS".to_string())); } diff --git a/src/shims/windows/handle.rs b/src/shims/windows/handle.rs index e47478533e..917a3a7a46 100644 --- a/src/shims/windows/handle.rs +++ b/src/shims/windows/handle.rs @@ -233,7 +233,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } Handle::File(fd_num) => if let Some(fd) = this.machine.fds.remove(fd_num) { - let err = fd.close(this.machine.communicate(), this)?; + let err = fd.close_ref(this.machine.communicate(), this)?; if let Err(e) = err { this.set_last_error(e)?; this.eval_windows("c", "FALSE")