X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Ftools%2Fmiri%2Fsrc%2Fmachine.rs;h=01a3d7550e2e0c480b5bb545ef77782837471924;hb=a5fa99eed20a46a88c0c85eed6552a94b6656634;hp=ab629e4711b10c0e2ca8e5fec502336575f2ab9a;hpb=1d12c3cea30b8ba4a09650a9e9c46fe9fbe25f0b;p=rust.git diff --git a/src/tools/miri/src/machine.rs b/src/tools/miri/src/machine.rs index ab629e4711b..01a3d7550e2 100644 --- a/src/tools/miri/src/machine.rs +++ b/src/tools/miri/src/machine.rs @@ -9,6 +9,7 @@ use rand::SeedableRng; use rustc_ast::ast::Mutability; +use rustc_const_eval::const_eval::CheckAlignment; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; #[allow(unused)] use rustc_data_structures::static_assert_size; @@ -22,9 +23,8 @@ }; use rustc_span::def_id::{CrateNum, DefId}; use rustc_span::Symbol; -use rustc_target::abi::{Size, Align}; +use rustc_target::abi::{Align, Size}; use rustc_target::spec::abi::Abi; -use rustc_const_eval::const_eval::CheckAlignment; use crate::{ concurrency::{data_race, weak_memory}, @@ -32,10 +32,9 @@ *, }; -// Some global facts about the emulated machine. -pub const PAGE_SIZE: u64 = 4 * 1024; // FIXME: adjust to target architecture -pub const STACK_ADDR: u64 = 32 * PAGE_SIZE; // not really about the "stack", but where we start assigning integer addresses to allocations -pub const STACK_SIZE: u64 = 16 * PAGE_SIZE; // whatever +/// The number of the available real-time signal with the lowest priority. +/// Dummy constant related to epoll, must be between 32 and 64. +pub const SIGRTMAX: i32 = 42; /// Extra data stored with each stack frame pub struct FrameExtra<'tcx> { @@ -470,6 +469,10 @@ pub struct MiriMachine<'mir, 'tcx> { pub(crate) since_gc: u32, /// The number of CPUs to be reported by miri. pub(crate) num_cpus: u32, + /// Determines Miri's page size and associated values + pub(crate) page_size: u64, + pub(crate) stack_addr: u64, + pub(crate) stack_size: u64, } impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> { @@ -483,11 +486,31 @@ pub(crate) fn new(config: &MiriConfig, layout_cx: LayoutCx<'tcx, TyCtxt<'tcx>>) let rng = StdRng::seed_from_u64(config.seed.unwrap_or(0)); let borrow_tracker = config.borrow_tracker.map(|bt| bt.instanciate_global_state(config)); let data_race = config.data_race_detector.then(|| data_race::GlobalState::new(config)); + let page_size = if let Some(page_size) = config.page_size { + page_size + } else { + let target = &layout_cx.tcx.sess.target; + match target.arch.as_ref() { + "wasm32" | "wasm64" => 64 * 1024, // https://webassembly.github.io/spec/core/exec/runtime.html#memory-instances + "aarch64" => + if target.options.vendor.as_ref() == "apple" { + // No "definitive" source, but see: + // https://www.wwdcnotes.com/notes/wwdc20/10214/ + // https://github.com/ziglang/zig/issues/11308 etc. + 16 * 1024 + } else { + 4 * 1024 + }, + _ => 4 * 1024, + } + }; + let stack_addr = page_size * 32; + let stack_size = page_size * 16; MiriMachine { tcx: layout_cx.tcx, borrow_tracker, data_race, - intptrcast: RefCell::new(intptrcast::GlobalStateInner::new(config)), + intptrcast: RefCell::new(intptrcast::GlobalStateInner::new(config, stack_addr)), // `env_vars` depends on a full interpreter so we cannot properly initialize it yet. env_vars: EnvVars::default(), main_fn_ret_place: None, @@ -549,6 +572,9 @@ pub(crate) fn new(config: &MiriConfig, layout_cx: LayoutCx<'tcx, TyCtxt<'tcx>>) gc_interval: config.gc_interval, since_gc: 0, num_cpus: config.num_cpus, + page_size, + stack_addr, + stack_size, } } @@ -693,6 +719,9 @@ fn visit_tags(&self, visit: &mut dyn FnMut(BorTag)) { gc_interval: _, since_gc: _, num_cpus: _, + page_size: _, + stack_addr: _, + stack_size: _, } = self; threads.visit_tags(visit); @@ -927,6 +956,7 @@ fn adjust_allocation<'b>( &ecx.machine.threads, alloc.size(), kind, + ecx.machine.current_span(), ) }); let buffer_alloc = ecx.machine.weak_memory.then(weak_memory::AllocState::new_allocation); @@ -981,9 +1011,8 @@ fn expose_ptr( ptr: Pointer, ) -> InterpResult<'tcx> { match ptr.provenance { - Provenance::Concrete { alloc_id, tag } => { - intptrcast::GlobalStateInner::expose_ptr(ecx, alloc_id, tag) - } + Provenance::Concrete { alloc_id, tag } => + intptrcast::GlobalStateInner::expose_ptr(ecx, alloc_id, tag), Provenance::Wildcard => { // No need to do anything for wildcard pointers as // their provenances have already been previously exposed.