module organization: move platform-specific code to shims::{posix::{linux, macos}, windows}
This commit is contained in:
parent
395f5d40dc
commit
af5887e869
@ -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<GlobalState>;
|
||||
|
||||
|
@ -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 _;
|
||||
|
||||
|
@ -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.
|
||||
|
@ -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),
|
||||
}
|
||||
};
|
||||
|
@ -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;
|
||||
|
@ -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!(),
|
||||
}
|
||||
}
|
@ -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,
|
||||
}
|
@ -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(
|
1
src/shims/posix/linux/mod.rs
Normal file
1
src/shims/posix/linux/mod.rs
Normal file
@ -0,0 +1 @@
|
||||
pub mod foreign_items;
|
@ -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> {
|
1
src/shims/posix/macos/mod.rs
Normal file
1
src/shims/posix/macos/mod.rs
Normal file
@ -0,0 +1 @@
|
||||
pub mod foreign_items;
|
10
src/shims/posix/mod.rs
Normal file
10
src/shims/posix/mod.rs
Normal file
@ -0,0 +1,10 @@
|
||||
pub mod foreign_items;
|
||||
|
||||
mod fs;
|
||||
mod sync;
|
||||
mod thread;
|
||||
|
||||
mod linux;
|
||||
mod macos;
|
||||
|
||||
pub use fs::{DirHandler, FileHandler};
|
@ -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>,
|
@ -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;
|
||||
|
||||
|
1
src/shims/windows/mod.rs
Normal file
1
src/shims/windows/mod.rs
Normal file
@ -0,0 +1 @@
|
||||
pub mod foreign_items;
|
Loading…
Reference in New Issue
Block a user