@@ -31,11 +31,6 @@ use crate::{
3131 * ,
3232} ;
3333
34- // Some global facts about the emulated machine.
35- pub const PAGE_SIZE : u64 = 4 * 1024 ; // FIXME: adjust to target architecture
36- pub const STACK_ADDR : u64 = 32 * PAGE_SIZE ; // not really about the "stack", but where we start assigning integer addresses to allocations
37- pub const STACK_SIZE : u64 = 16 * PAGE_SIZE ; // whatever
38-
3934/// Extra data stored with each stack frame
4035pub struct FrameExtra < ' tcx > {
4136 /// Extra data for Stacked Borrows.
@@ -469,6 +464,10 @@ pub struct MiriMachine<'mir, 'tcx> {
469464 pub ( crate ) since_gc : u32 ,
470465 /// The number of CPUs to be reported by miri.
471466 pub ( crate ) num_cpus : u32 ,
467+ /// Determines Miri's page size and associated values
468+ pub ( crate ) page_size : u64 ,
469+ pub ( crate ) stack_addr : u64 ,
470+ pub ( crate ) stack_size : u64 ,
472471}
473472
474473impl < ' mir , ' tcx > MiriMachine < ' mir , ' tcx > {
@@ -482,11 +481,31 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
482481 let rng = StdRng :: seed_from_u64 ( config. seed . unwrap_or ( 0 ) ) ;
483482 let borrow_tracker = config. borrow_tracker . map ( |bt| bt. instanciate_global_state ( config) ) ;
484483 let data_race = config. data_race_detector . then ( || data_race:: GlobalState :: new ( config) ) ;
484+ let page_size = if let Some ( page_size) = config. page_size {
485+ page_size
486+ } else {
487+ let target = & layout_cx. tcx . sess . target ;
488+ match target. arch . as_ref ( ) {
489+ "wasm32" | "wasm64" => 64 * 1024 , // https://webassembly.github.io/spec/core/exec/runtime.html#memory-instances
490+ "aarch64" =>
491+ if target. options . vendor . as_ref ( ) == "apple" {
492+ // No "definitive" source, but see:
493+ // https://www.wwdcnotes.com/notes/wwdc20/10214/
494+ // https://github.com/ziglang/zig/issues/11308 etc.
495+ 16 * 1024
496+ } else {
497+ 4 * 1024
498+ } ,
499+ _ => 4 * 1024 ,
500+ }
501+ } ;
502+ let stack_addr = page_size * 32 ;
503+ let stack_size = page_size * 16 ;
485504 MiriMachine {
486505 tcx : layout_cx. tcx ,
487506 borrow_tracker,
488507 data_race,
489- intptrcast : RefCell :: new ( intptrcast:: GlobalStateInner :: new ( config) ) ,
508+ intptrcast : RefCell :: new ( intptrcast:: GlobalStateInner :: new ( config, stack_addr ) ) ,
490509 // `env_vars` depends on a full interpreter so we cannot properly initialize it yet.
491510 env_vars : EnvVars :: default ( ) ,
492511 main_fn_ret_place : None ,
@@ -548,6 +567,9 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
548567 gc_interval : config. gc_interval ,
549568 since_gc : 0 ,
550569 num_cpus : config. num_cpus ,
570+ page_size,
571+ stack_addr,
572+ stack_size,
551573 }
552574 }
553575
@@ -692,6 +714,9 @@ impl VisitTags for MiriMachine<'_, '_> {
692714 gc_interval : _,
693715 since_gc : _,
694716 num_cpus : _,
717+ page_size : _,
718+ stack_addr : _,
719+ stack_size : _,
695720 } = self ;
696721
697722 threads. visit_tags ( visit) ;
0 commit comments