Skip to content

Commit 4a6345e

Browse files
committed
Fmt
1 parent 0079cad commit 4a6345e

File tree

7 files changed

+64
-53
lines changed

7 files changed

+64
-53
lines changed

src/shims/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
mod alloc;
44
mod backtrace;
5+
mod files;
56
#[cfg(unix)]
67
mod native_lib;
78
mod unix;
89
mod wasi;
910
mod windows;
1011
mod x86;
11-
mod files;
1212

1313
pub mod env;
1414
pub mod extern_static;
@@ -19,8 +19,8 @@ pub mod panic;
1919
pub mod time;
2020
pub mod tls;
2121

22-
pub use self::unix::{DirTable, EpollInterestTable};
2322
pub use self::files::FdTable;
23+
pub use self::unix::{DirTable, EpollInterestTable};
2424

2525
/// What needs to be done after emulating an item (a shim or an intrinsic) is done.
2626
pub enum EmulateItemResult {

src/shims/unix/linux/epoll.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use std::rc::{Rc, Weak};
55
use std::time::Duration;
66

77
use crate::concurrency::VClock;
8+
use crate::shims::files::{FdId, FileDescription, FileDescriptionRef, WeakFileDescriptionRef};
89
use crate::*;
9-
use crate::shims::files::{FdId, WeakFileDescriptionRef, FileDescriptionRef, FileDescription};
1010

1111
/// An `Epoll` file descriptor connects file handles and epoll events
1212
#[derive(Clone, Debug, Default)]

src/shims/unix/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ mod solarish;
1616

1717
// All the Unix-specific extension traits
1818
pub use self::env::{EvalContextExt as _, UnixEnvVars};
19-
pub use self::fd::{UnixFileDescription, EvalContextExt as _};
19+
pub use self::fd::{EvalContextExt as _, UnixFileDescription};
2020
pub use self::fs::{DirTable, EvalContextExt as _};
2121
pub use self::linux::epoll::EpollInterestTable;
2222
pub use self::mem::EvalContextExt as _;

src/shims/unix/unnamed_socket.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ use std::io::{ErrorKind, Read};
1010
use rustc_abi::Size;
1111

1212
use crate::concurrency::VClock;
13+
use crate::shims::files::{
14+
EvalContextExt as _, FileDescription, FileDescriptionRef, WeakFileDescriptionRef,
15+
};
1316
use crate::shims::unix::fd::UnixFileDescription;
1417
use crate::shims::unix::linux::epoll::{EpollReadyEvents, EvalContextExt as _};
1518
use crate::*;
16-
use crate::shims::files::{FileDescription, FileDescriptionRef, WeakFileDescriptionRef, EvalContextExt as _};
1719

1820
/// The maximum capacity of the socketpair buffer in bytes.
1921
/// This number is arbitrary as the value can always

src/shims/windows/env.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::env;
22
use std::ffi::{OsStr, OsString};
33
use std::io::ErrorKind;
4+
45
use rustc_data_structures::fx::FxHashMap;
56

67
use self::helpers::windows_check_buffer_size;

src/shims/windows/fs.rs

+54-46
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ use std::io;
33
use std::io::{IsTerminal, Read, Seek, SeekFrom, Write};
44
use std::path::{Path, PathBuf};
55
use std::time::SystemTime;
6+
67
use rustc_abi::Size;
78

8-
use crate::shims::windows::handle::{Handle, EvalContextExt as _, PseudoHandle};
9-
use crate::*;
10-
use crate::shims::files::{FileDescription, FileDescriptionRef, EvalContextExt as _};
9+
use crate::shims::files::{EvalContextExt as _, FileDescription, FileDescriptionRef};
1110
use crate::shims::time::system_time_to_duration;
11+
use crate::shims::windows::handle::{EvalContextExt as _, Handle, PseudoHandle};
12+
use crate::*;
1213

1314
#[derive(Debug)]
1415
pub struct FileHandle {
@@ -149,7 +150,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
149150
this.assert_target_os("windows", "CreateFileW");
150151
this.check_no_isolation("`CreateFileW`")?;
151152

152-
let file_name = String::from_utf16_lossy(&this.read_wide_str(this.read_pointer(file_name)?)?);
153+
let file_name =
154+
String::from_utf16_lossy(&this.read_wide_str(this.read_pointer(file_name)?)?);
153155
let file_name = Path::new(&file_name);
154156
let desired_access = this.read_scalar(desired_access)?.to_u32()?;
155157
let share_mode = this.read_scalar(share_mode)?.to_u32()?;
@@ -169,7 +171,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
169171
let file_share_read = this.eval_windows_u32("c", "FILE_SHARE_READ");
170172
let file_share_write = this.eval_windows_u32("c", "FILE_SHARE_WRITE");
171173

172-
if share_mode & !(file_share_delete | file_share_read | file_share_write) != 0 || share_mode == 0 {
174+
if share_mode & !(file_share_delete | file_share_read | file_share_write) != 0
175+
|| share_mode == 0
176+
{
173177
throw_unsup_format!("CreateFileW: Unsupported share mode: {share_mode}");
174178
}
175179
if !this.ptr_is_null(security_attributes)? {
@@ -182,25 +186,37 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
182186
let open_existing = this.eval_windows_u32("c", "OPEN_EXISTING");
183187
let truncate_existing = this.eval_windows_u32("c", "TRUNCATE_EXISTING");
184188

185-
if ![create_always, create_new, open_always, open_existing, truncate_existing].contains(&creation_disposition) {
186-
throw_unsup_format!("CreateFileW: Unsupported creation disposition: {creation_disposition}");
189+
if ![create_always, create_new, open_always, open_existing, truncate_existing]
190+
.contains(&creation_disposition)
191+
{
192+
throw_unsup_format!(
193+
"CreateFileW: Unsupported creation disposition: {creation_disposition}"
194+
);
187195
}
188196

189197
let file_attribute_normal = this.eval_windows_u32("c", "FILE_ATTRIBUTE_NORMAL");
190198
// This must be passed to allow getting directory handles. If not passed, we error on trying
191199
// to open directories below
192200
let file_flag_backup_semantics = this.eval_windows_u32("c", "FILE_FLAG_BACKUP_SEMANTICS");
193-
let file_flag_open_reparse_point = this.eval_windows_u32("c", "FILE_FLAG_OPEN_REPARSE_POINT");
201+
let file_flag_open_reparse_point =
202+
this.eval_windows_u32("c", "FILE_FLAG_OPEN_REPARSE_POINT");
194203

195204
let flags_and_attributes = match flags_and_attributes {
196205
0 => file_attribute_normal,
197206
_ => flags_and_attributes,
198207
};
199-
if !(file_attribute_normal | file_flag_backup_semantics | file_flag_open_reparse_point) & flags_and_attributes != 0 {
200-
throw_unsup_format!("CreateFileW: Unsupported flags_and_attributes: {flags_and_attributes}");
208+
if !(file_attribute_normal | file_flag_backup_semantics | file_flag_open_reparse_point)
209+
& flags_and_attributes
210+
!= 0
211+
{
212+
throw_unsup_format!(
213+
"CreateFileW: Unsupported flags_and_attributes: {flags_and_attributes}"
214+
);
201215
}
202216

203-
if flags_and_attributes & file_flag_open_reparse_point != 0 && creation_disposition == create_always {
217+
if flags_and_attributes & file_flag_open_reparse_point != 0
218+
&& creation_disposition == create_always
219+
{
204220
throw_machine_stop!(TerminationInfo::Abort("Invalid CreateFileW argument combination: FILE_FLAG_OPEN_REPARSE_POINT with CREATE_ALWAYS".to_string()));
205221
}
206222

@@ -286,7 +302,10 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
286302
this.check_no_isolation("`GetFileInformationByHandle`")?;
287303

288304
let file = this.read_handle(file)?;
289-
let file_information = this.deref_pointer_as(file_information, this.windows_ty_layout("BY_HANDLE_FILE_INFORMATION"))?;
305+
let file_information = this.deref_pointer_as(
306+
file_information,
307+
this.windows_ty_layout("BY_HANDLE_FILE_INFORMATION"),
308+
)?;
290309

291310
let fd = if let Handle::File(fd) = file {
292311
fd
@@ -302,7 +321,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
302321
Ok(meta) => meta,
303322
Err(e) => {
304323
this.set_last_error(e)?;
305-
return interp_ok(this.eval_windows("c", "FALSE"))
324+
return interp_ok(this.eval_windows("c", "FALSE"));
306325
}
307326
};
308327

@@ -317,12 +336,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
317336
this.eval_windows_u32("c", "FILE_ATTRIBUTE_DEVICE")
318337
};
319338

320-
let created = extract_windows_epoch(metadata.created())?
321-
.unwrap_or((0, 0));
322-
let accessed = extract_windows_epoch(metadata.accessed())?
323-
.unwrap_or((0, 0));
324-
let written = extract_windows_epoch(metadata.modified())?
325-
.unwrap_or((0, 0));
339+
let created = extract_windows_epoch(metadata.created())?.unwrap_or((0, 0));
340+
let accessed = extract_windows_epoch(metadata.accessed())?.unwrap_or((0, 0));
341+
let written = extract_windows_epoch(metadata.modified())?.unwrap_or((0, 0));
326342

327343
this.write_int_fields_named(
328344
&[("dwFileAttributes", attributes as i128)],
@@ -354,7 +370,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
354370
let this = self.eval_context_mut();
355371
this.assert_target_os("windows", "DeleteFileW");
356372
this.check_no_isolation("`DeleteFileW`")?;
357-
let file_name = String::from_utf16_lossy(&this.read_wide_str(this.read_pointer(file_name)?)?);
373+
let file_name =
374+
String::from_utf16_lossy(&this.read_wide_str(this.read_pointer(file_name)?)?);
358375
let file_name = Path::new(&file_name);
359376
match std::fs::remove_file(file_name) {
360377
Ok(_) => interp_ok(this.eval_windows("c", "TRUE")),
@@ -387,8 +404,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
387404
let n = this.read_scalar(n)?.to_u32()?;
388405
let byte_offset = this.read_target_usize(byte_offset)?; // is actually a pointer
389406
let key = this.read_pointer(key)?;
390-
let io_status_block = this
391-
.deref_pointer_as(io_status_block, this.windows_ty_layout("IO_STATUS_BLOCK"))?;
407+
let io_status_block =
408+
this.deref_pointer_as(io_status_block, this.windows_ty_layout("IO_STATUS_BLOCK"))?;
392409

393410
if event != Handle::Null {
394411
throw_unsup_format!(
@@ -415,9 +432,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
415432
}
416433

417434
if !this.ptr_is_null(key)? {
418-
throw_unsup_format!(
419-
"`NtWriteFile` `Key` parameter is not null, which is unsupported"
420-
);
435+
throw_unsup_format!("`NtWriteFile` `Key` parameter is not null, which is unsupported");
421436
}
422437

423438
let written = match handle {
@@ -454,10 +469,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
454469
if let Some(n) = written {
455470
let io_status_information =
456471
this.project_field_named(&io_status_block, "Information")?;
457-
this.write_scalar(
458-
Scalar::from_target_usize(n.into(), this),
459-
&io_status_information,
460-
)?;
472+
this.write_scalar(Scalar::from_target_usize(n.into(), this), &io_status_information)?;
461473
}
462474

463475
// Return whether this was a success. >= 0 is success.
@@ -487,8 +499,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
487499
let n = this.read_scalar(n)?.to_u32()?;
488500
let byte_offset = this.read_target_usize(byte_offset)?; // is actually a pointer
489501
let key = this.read_pointer(key)?;
490-
let io_status_block = this
491-
.deref_pointer_as(io_status_block, this.windows_ty_layout("IO_STATUS_BLOCK"))?;
502+
let io_status_block =
503+
this.deref_pointer_as(io_status_block, this.windows_ty_layout("IO_STATUS_BLOCK"))?;
492504

493505
if event != Handle::Null {
494506
throw_unsup_format!(
@@ -515,17 +527,14 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
515527
}
516528

517529
if !this.ptr_is_null(key)? {
518-
throw_unsup_format!(
519-
"`NtWriteFile` `Key` parameter is not null, which is unsupported"
520-
);
530+
throw_unsup_format!("`NtWriteFile` `Key` parameter is not null, which is unsupported");
521531
}
522532

523533
let read = match handle {
524534
Handle::Pseudo(PseudoHandle::Stdin) => {
525535
// stdout/stderr
526536
let mut buf_cont = vec![0u8; n as usize];
527-
let res =
528-
io::Read::read(&mut io::stdin(), &mut buf_cont);
537+
let res = io::Read::read(&mut io::stdin(), &mut buf_cont);
529538
this.write_bytes_ptr(buf, buf_cont)?;
530539
// We write at most `n` bytes, which is a `u32`, so we cannot have written more than that.
531540
res.ok().map(|n| u32::try_from(n).unwrap())
@@ -549,10 +558,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
549558
if let Some(n) = read {
550559
let io_status_information =
551560
this.project_field_named(&io_status_block, "Information")?;
552-
this.write_scalar(
553-
Scalar::from_target_usize(n.into(), this),
554-
&io_status_information,
555-
)?;
561+
this.write_scalar(Scalar::from_target_usize(n.into(), this), &io_status_information)?;
556562
}
557563

558564
// Return whether this was a success. >= 0 is success.
@@ -598,12 +604,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
598604

599605
match desc.seek(this.machine.communicate(), seek)? {
600606
Ok(n) => {
601-
this.write_scalar(
602-
Scalar::from_i64(n as i64),
603-
&this.deref_pointer(new_fp)?,
604-
)?;
607+
this.write_scalar(Scalar::from_i64(n as i64), &this.deref_pointer(new_fp)?)?;
605608
interp_ok(this.eval_windows("c", "TRUE"))
606-
},
609+
}
607610
Err(e) => {
608611
this.set_last_error(e)?;
609612
interp_ok(this.eval_windows("c", "FALSE"))
@@ -630,7 +633,12 @@ fn extract_windows_epoch<'tcx>(
630633
}
631634
}
632635

633-
fn write_filetime_field<'tcx>(cx: &mut MiriInterpCx<'tcx>, val: &MPlaceTy<'tcx>, name: &str, (low, high): (u32, u32)) -> InterpResult<'tcx> {
636+
fn write_filetime_field<'tcx>(
637+
cx: &mut MiriInterpCx<'tcx>,
638+
val: &MPlaceTy<'tcx>,
639+
name: &str,
640+
(low, high): (u32, u32),
641+
) -> InterpResult<'tcx> {
634642
cx.write_int_fields_named(
635643
&[("dwLowDateTime", low as i128), ("dwHighDateTime", high as i128)],
636644
&cx.project_field_named(val, name)?,

src/shims/windows/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
pub mod foreign_items;
22

33
mod env;
4+
mod fs;
45
mod handle;
56
mod sync;
67
mod thread;
7-
mod fs;
88

99
// All the Windows-specific extension traits
1010
pub use self::env::{EvalContextExt as _, WindowsEnvVars};
11+
pub use self::fs::EvalContextExt as _;
1112
pub use self::handle::EvalContextExt as _;
1213
pub use self::sync::EvalContextExt as _;
1314
pub use self::thread::EvalContextExt as _;
14-
pub use self::fs::EvalContextExt as _;

0 commit comments

Comments
 (0)