diff --git a/src/intptrcast.rs b/src/intptrcast.rs index f51c8a7ce74..c908bdf24eb 100644 --- a/src/intptrcast.rs +++ b/src/intptrcast.rs @@ -9,7 +9,7 @@ use rustc_mir::interpret::{AllocCheck, AllocId, InterpResult, Memory, Machine, Pointer, PointerArithmetic}; use rustc_target::abi::{Size, HasDataLayout}; -use crate::{Evaluator, Tag, STACK_ADDR, CheckInAllocMsg}; +use crate::*; pub type MemoryExtra = RefCell; diff --git a/src/lib.rs b/src/lib.rs index e0da83840ed..fa357eb9b13 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,6 +34,8 @@ mod sync; mod thread; +// Establish a "crate-wide prelude": we often import `crate::*`. + // Make all those symbols available in the same place as our own. pub use rustc_mir::interpret::*; // Resolve ambiguity. @@ -42,13 +44,10 @@ pub use crate::shims::dlsym::{Dlsym, EvalContextExt as _}; pub use crate::shims::env::{EnvVars, EvalContextExt as _}; pub use crate::shims::foreign_items::EvalContextExt as _; -pub use crate::shims::fs::{DirHandler, EvalContextExt as _, FileHandler}; pub use crate::shims::intrinsics::EvalContextExt as _; pub use crate::shims::os_str::EvalContextExt as _; -pub use crate::shims::panic::{CatchUnwindData, EvalContextExt as _}; -pub use crate::shims::posix_sync::{EvalContextExt as _}; -pub use crate::shims::thread::EvalContextExt as _; pub use crate::shims::time::EvalContextExt as _; +pub use crate::shims::panic::{CatchUnwindData, EvalContextExt as _}; pub use crate::shims::tls::{EvalContextExt as _, TlsData}; pub use crate::shims::EvalContextExt as _; diff --git a/src/machine.rs b/src/machine.rs index 4f45b4f93f1..6233222c004 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -241,8 +241,8 @@ pub struct Evaluator<'mir, 'tcx> { /// Whether to enforce the validity invariant. pub(crate) validate: bool, - pub(crate) file_handler: FileHandler, - pub(crate) dir_handler: DirHandler, + pub(crate) file_handler: shims::posix::FileHandler, + pub(crate) dir_handler: shims::posix::DirHandler, /// The temporary used for storing the argument of /// the call to `miri_start_panic` (the panic payload) when unwinding. diff --git a/src/shims/foreign_items.rs b/src/shims/foreign_items.rs index 8a75fb03a53..14c5aac4899 100644 --- a/src/shims/foreign_items.rs +++ b/src/shims/foreign_items.rs @@ -1,6 +1,3 @@ -mod windows; -mod posix; - use std::{convert::{TryInto, TryFrom}, iter}; use rustc_hir::def_id::DefId; @@ -455,13 +452,13 @@ fn emulate_foreign_item_by_name( // Architecture-specific shims "llvm.x86.sse2.pause" if this.tcx.sess.target.target.arch == "x86" || this.tcx.sess.target.target.arch == "x86_64" => { let &[] = check_arg_count(args)?; - this.sched_yield()?; + this.yield_active_thread(); } // Platform-specific shims _ => match this.tcx.sess.target.target.target_os.as_str() { - "linux" | "macos" => return posix::EvalContextExt::emulate_foreign_item_by_name(this, link_name, args, dest, ret), - "windows" => return windows::EvalContextExt::emulate_foreign_item_by_name(this, link_name, args, dest, ret), + "linux" | "macos" => return shims::posix::foreign_items::EvalContextExt::emulate_foreign_item_by_name(this, link_name, args, dest, ret), + "windows" => return shims::windows::foreign_items::EvalContextExt::emulate_foreign_item_by_name(this, link_name, args, dest, ret), target => throw_unsup_format!("the target `{}` is not supported", target), } }; diff --git a/src/shims/mod.rs b/src/shims/mod.rs index cd525e173ed..37e7b8c4046 100644 --- a/src/shims/mod.rs +++ b/src/shims/mod.rs @@ -1,15 +1,18 @@ + +pub mod foreign_items; +pub mod intrinsics; +pub mod posix; +pub mod windows; + pub mod dlsym; pub mod env; -pub mod foreign_items; -pub mod fs; -pub mod intrinsics; pub mod os_str; pub mod panic; -pub mod sync; -pub mod thread; pub mod time; pub mod tls; +// End module management, begin local code + use std::convert::TryFrom; use log::trace; diff --git a/src/shims/foreign_items/posix.rs b/src/shims/posix/foreign_items.rs similarity index 98% rename from src/shims/foreign_items/posix.rs rename to src/shims/posix/foreign_items.rs index 8e4d140b06c..bbda40def62 100644 --- a/src/shims/foreign_items/posix.rs +++ b/src/shims/posix/foreign_items.rs @@ -1,15 +1,16 @@ -mod linux; -mod macos; - use std::convert::TryFrom; use log::trace; -use crate::*; -use helpers::check_arg_count; use rustc_middle::mir; use rustc_target::abi::{Align, LayoutOf, Size}; +use crate::*; +use helpers::check_arg_count; +use shims::posix::fs::EvalContextExt as _; +use shims::posix::sync::EvalContextExt as _; +use shims::posix::thread::EvalContextExt as _; + impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {} pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> { fn emulate_foreign_item_by_name( @@ -476,8 +477,8 @@ fn emulate_foreign_item_by_name( // Platform-specific shims _ => { match this.tcx.sess.target.target.target_os.as_str() { - "linux" => return linux::EvalContextExt::emulate_foreign_item_by_name(this, link_name, args, dest, ret), - "macos" => return macos::EvalContextExt::emulate_foreign_item_by_name(this, link_name, args, dest, ret), + "linux" => return shims::posix::linux::foreign_items::EvalContextExt::emulate_foreign_item_by_name(this, link_name, args, dest, ret), + "macos" => return shims::posix::macos::foreign_items::EvalContextExt::emulate_foreign_item_by_name(this, link_name, args, dest, ret), _ => unreachable!(), } } diff --git a/src/shims/fs.rs b/src/shims/posix/fs.rs similarity index 99% rename from src/shims/fs.rs rename to src/shims/posix/fs.rs index 29e0da14ff1..87aa28120c2 100644 --- a/src/shims/fs.rs +++ b/src/shims/posix/fs.rs @@ -10,13 +10,13 @@ use rustc_data_structures::fx::FxHashMap; use rustc_target::abi::{Align, LayoutOf, Size}; -use crate::stacked_borrows::Tag; use crate::*; +use stacked_borrows::Tag; use helpers::{check_arg_count, immty_from_int_checked, immty_from_uint_checked}; use shims::time::system_time_to_duration; #[derive(Debug)] -pub struct FileHandle { +struct FileHandle { file: File, writable: bool, } diff --git a/src/shims/foreign_items/posix/linux.rs b/src/shims/posix/linux/foreign_items.rs similarity index 97% rename from src/shims/foreign_items/posix/linux.rs rename to src/shims/posix/linux/foreign_items.rs index 2d124f9d8c6..ff30609d9ab 100644 --- a/src/shims/foreign_items/posix/linux.rs +++ b/src/shims/posix/linux/foreign_items.rs @@ -1,7 +1,11 @@ -use crate::*; -use helpers::check_arg_count; use rustc_middle::mir; +use crate::*; +use crate::helpers::check_arg_count; +use shims::posix::fs::EvalContextExt as _; +use shims::posix::sync::EvalContextExt as _; +use shims::posix::thread::EvalContextExt as _; + impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {} pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> { fn emulate_foreign_item_by_name( diff --git a/src/shims/posix/linux/mod.rs b/src/shims/posix/linux/mod.rs new file mode 100644 index 00000000000..09c6507b24f --- /dev/null +++ b/src/shims/posix/linux/mod.rs @@ -0,0 +1 @@ +pub mod foreign_items; diff --git a/src/shims/foreign_items/posix/macos.rs b/src/shims/posix/macos/foreign_items.rs similarity index 98% rename from src/shims/foreign_items/posix/macos.rs rename to src/shims/posix/macos/foreign_items.rs index fb50e4d9181..ef649c3e840 100644 --- a/src/shims/foreign_items/posix/macos.rs +++ b/src/shims/posix/macos/foreign_items.rs @@ -1,6 +1,9 @@ +use rustc_middle::mir; + use crate::*; use helpers::check_arg_count; -use rustc_middle::mir; +use shims::posix::fs::EvalContextExt as _; +use shims::posix::thread::EvalContextExt as _; impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {} pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> { diff --git a/src/shims/posix/macos/mod.rs b/src/shims/posix/macos/mod.rs new file mode 100644 index 00000000000..09c6507b24f --- /dev/null +++ b/src/shims/posix/macos/mod.rs @@ -0,0 +1 @@ +pub mod foreign_items; diff --git a/src/shims/posix/mod.rs b/src/shims/posix/mod.rs new file mode 100644 index 00000000000..2f505cfb9c0 --- /dev/null +++ b/src/shims/posix/mod.rs @@ -0,0 +1,10 @@ +pub mod foreign_items; + +mod fs; +mod sync; +mod thread; + +mod linux; +mod macos; + +pub use fs::{DirHandler, FileHandler}; diff --git a/src/shims/posix_sync.rs b/src/shims/posix/sync.rs similarity index 99% rename from src/shims/posix_sync.rs rename to src/shims/posix/sync.rs index cdc1f8cc763..a61c80d5118 100644 --- a/src/shims/posix_sync.rs +++ b/src/shims/posix/sync.rs @@ -5,10 +5,10 @@ use rustc_middle::ty::{layout::TyAndLayout, TyKind, TypeAndMut}; use rustc_target::abi::{LayoutOf, Size}; -use crate::stacked_borrows::Tag; -use crate::thread::Time; - use crate::*; +use stacked_borrows::Tag; +use thread::Time; + fn assert_ptr_target_min_size<'mir, 'tcx: 'mir>( ecx: &MiriEvalContext<'mir, 'tcx>, diff --git a/src/shims/thread.rs b/src/shims/posix/thread.rs similarity index 100% rename from src/shims/thread.rs rename to src/shims/posix/thread.rs diff --git a/src/shims/tls.rs b/src/shims/tls.rs index 69561463368..704598ef2c6 100644 --- a/src/shims/tls.rs +++ b/src/shims/tls.rs @@ -10,10 +10,7 @@ use rustc_middle::ty; use rustc_target::abi::{Size, HasDataLayout}; -use crate::{ - HelpersEvalContextExt, InterpResult, MPlaceTy, Scalar, StackPopCleanup, Tag, ThreadId, - ThreadsEvalContextExt, -}; +use crate::*; pub type TlsKey = u128; diff --git a/src/shims/foreign_items/windows.rs b/src/shims/windows/foreign_items.rs similarity index 100% rename from src/shims/foreign_items/windows.rs rename to src/shims/windows/foreign_items.rs diff --git a/src/shims/windows/mod.rs b/src/shims/windows/mod.rs new file mode 100644 index 00000000000..09c6507b24f --- /dev/null +++ b/src/shims/windows/mod.rs @@ -0,0 +1 @@ +pub mod foreign_items;