@@ -477,7 +477,8 @@ pub struct MiriMachine<'mir, 'tcx> {
477477
478478impl < ' mir , ' tcx > MiriMachine < ' mir , ' tcx > {
479479 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) ;
481482 let layouts =
482483 PrimitiveLayouts :: new ( layout_cx) . expect ( "Couldn't get layouts of primitive types" ) ;
483484 let profiler = config. measureme_out . as_ref ( ) . map ( |out| {
@@ -486,10 +487,13 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
486487 let rng = StdRng :: seed_from_u64 ( config. seed . unwrap_or ( 0 ) ) ;
487488 let borrow_tracker = config. borrow_tracker . map ( |bt| bt. instanciate_global_state ( config) ) ;
488489 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.
489493 let page_size = if let Some ( page_size) = config. page_size {
490494 page_size
491495 } else {
492- let target = & layout_cx . tcx . sess . target ;
496+ let target = & tcx. sess . target ;
493497 match target. arch . as_ref ( ) {
494498 "wasm32" | "wasm64" => 64 * 1024 , // https://webassembly.github.io/spec/core/exec/runtime.html#memory-instances
495499 "aarch64" =>
@@ -504,10 +508,12 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
504508 _ => 4 * 1024 ,
505509 }
506510 } ;
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 } ;
509515 MiriMachine {
510- tcx : layout_cx . tcx ,
516+ tcx,
511517 borrow_tracker,
512518 data_race,
513519 intptrcast : RefCell :: new ( intptrcast:: GlobalStateInner :: new ( config, stack_addr) ) ,
@@ -902,8 +908,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
902908 } ;
903909 let ( shim_size, shim_align, _kind) = ecx. get_alloc_info ( alloc_id) ;
904910 let def_ty = ecx. tcx . type_of ( def_id) . subst_identity ( ) ;
905- let extern_decl_layout =
906- ecx. tcx . layout_of ( ty:: ParamEnv :: empty ( ) . and ( def_ty) ) . unwrap ( ) ;
911+ let extern_decl_layout = ecx. tcx . layout_of ( ty:: ParamEnv :: empty ( ) . and ( def_ty) ) . unwrap ( ) ;
907912 if extern_decl_layout. size != shim_size || extern_decl_layout. align . abi != shim_align {
908913 throw_unsup_format ! (
909914 "`extern` static `{name}` from crate `{krate}` has been declared \
0 commit comments