@@ -31,11 +31,6 @@ use crate::{
31
31
* ,
32
32
} ;
33
33
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
-
39
34
/// Extra data stored with each stack frame
40
35
pub struct FrameExtra < ' tcx > {
41
36
/// Extra data for Stacked Borrows.
@@ -469,6 +464,10 @@ pub struct MiriMachine<'mir, 'tcx> {
469
464
pub ( crate ) since_gc : u32 ,
470
465
/// The number of CPUs to be reported by miri.
471
466
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 ,
472
471
}
473
472
474
473
impl < ' mir , ' tcx > MiriMachine < ' mir , ' tcx > {
@@ -482,11 +481,31 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
482
481
let rng = StdRng :: seed_from_u64 ( config. seed . unwrap_or ( 0 ) ) ;
483
482
let borrow_tracker = config. borrow_tracker . map ( |bt| bt. instanciate_global_state ( config) ) ;
484
483
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 ;
485
504
MiriMachine {
486
505
tcx : layout_cx. tcx ,
487
506
borrow_tracker,
488
507
data_race,
489
- intptrcast : RefCell :: new ( intptrcast:: GlobalStateInner :: new ( config) ) ,
508
+ intptrcast : RefCell :: new ( intptrcast:: GlobalStateInner :: new ( config, stack_addr ) ) ,
490
509
// `env_vars` depends on a full interpreter so we cannot properly initialize it yet.
491
510
env_vars : EnvVars :: default ( ) ,
492
511
main_fn_ret_place : None ,
@@ -548,6 +567,9 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
548
567
gc_interval : config. gc_interval ,
549
568
since_gc : 0 ,
550
569
num_cpus : config. num_cpus ,
570
+ page_size,
571
+ stack_addr,
572
+ stack_size,
551
573
}
552
574
}
553
575
@@ -692,6 +714,9 @@ impl VisitTags for MiriMachine<'_, '_> {
692
714
gc_interval : _,
693
715
since_gc : _,
694
716
num_cpus : _,
717
+ page_size : _,
718
+ stack_addr : _,
719
+ stack_size : _,
695
720
} = self ;
696
721
697
722
threads. visit_tags ( visit) ;
0 commit comments