@@ -477,7 +477,8 @@ pub struct MiriMachine<'mir, 'tcx> {
477
477
478
478
impl < ' mir , ' tcx > MiriMachine < ' mir , ' tcx > {
479
479
pub ( crate ) fn new ( config : & MiriConfig , layout_cx : LayoutCx < ' tcx , TyCtxt < ' tcx > > ) -> Self {
480
- let local_crates = helpers:: get_local_crates ( layout_cx. tcx ) ;
480
+ let tcx = layout_cx. tcx ;
481
+ let local_crates = helpers:: get_local_crates ( tcx) ;
481
482
let layouts =
482
483
PrimitiveLayouts :: new ( layout_cx) . expect ( "Couldn't get layouts of primitive types" ) ;
483
484
let profiler = config. measureme_out . as_ref ( ) . map ( |out| {
@@ -486,10 +487,13 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
486
487
let rng = StdRng :: seed_from_u64 ( config. seed . unwrap_or ( 0 ) ) ;
487
488
let borrow_tracker = config. borrow_tracker . map ( |bt| bt. instanciate_global_state ( config) ) ;
488
489
let data_race = config. data_race_detector . then ( || data_race:: GlobalState :: new ( config) ) ;
490
+ // Determinine page size, stack address, and stack size.
491
+ // These values are mostly meaningless, but the stack address is also where we start
492
+ // allocating physical integer addresses for all allocations.
489
493
let page_size = if let Some ( page_size) = config. page_size {
490
494
page_size
491
495
} else {
492
- let target = & layout_cx . tcx . sess . target ;
496
+ let target = & tcx. sess . target ;
493
497
match target. arch . as_ref ( ) {
494
498
"wasm32" | "wasm64" => 64 * 1024 , // https://webassembly.github.io/spec/core/exec/runtime.html#memory-instances
495
499
"aarch64" =>
@@ -504,10 +508,12 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
504
508
_ => 4 * 1024 ,
505
509
}
506
510
} ;
507
- let stack_addr = page_size * 32 ;
508
- let stack_size = page_size * 16 ;
511
+ // On 16bit targets, 32 pages is more than the entire address space!
512
+ let stack_addr = if tcx. pointer_size ( ) . bits ( ) < 32 { page_size } else { page_size * 32 } ;
513
+ let stack_size =
514
+ if tcx. pointer_size ( ) . bits ( ) < 32 { page_size * 4 } else { page_size * 16 } ;
509
515
MiriMachine {
510
- tcx : layout_cx . tcx ,
516
+ tcx,
511
517
borrow_tracker,
512
518
data_race,
513
519
intptrcast : RefCell :: new ( intptrcast:: GlobalStateInner :: new ( config, stack_addr) ) ,
0 commit comments