Skip to content

Commit 2d8addb

Browse files
committed
don't waste half the address space on AVR targets
1 parent 67f6daf commit 2d8addb

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/machine.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,8 @@ pub struct MiriMachine<'mir, 'tcx> {
477477

478478
impl<'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)),

0 commit comments

Comments
 (0)