From 42488e1e4a38b32c5cc2bbf49964c30d2808e811 Mon Sep 17 00:00:00 2001 From: Erin Date: Wed, 15 Nov 2023 19:17:25 +0100 Subject: [PATCH] Added stack hopefully maybe who knows --- hbxrt/src/main.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/hbxrt/src/main.rs b/hbxrt/src/main.rs index ed875f5..d2935cc 100644 --- a/hbxrt/src/main.rs +++ b/hbxrt/src/main.rs @@ -19,6 +19,25 @@ fn main() -> Result<(), Box> { exit(1); }; + // Allocate stack + const STACK_SIZE: usize = 1024 * 1024 * 2; + + let stack_ptr = unsafe { + mmap::( + None, + NonZeroUsize::new(STACK_SIZE).expect("Stack size should be > 0"), + ProtFlags::PROT_GROWSDOWN | ProtFlags::PROT_READ | ProtFlags::PROT_WRITE, + MapFlags::MAP_GROWSDOWN + | MapFlags::MAP_STACK + | MapFlags::MAP_ANON + | MapFlags::MAP_PRIVATE, + None, + 0, + ) + }?; + + eprintln!("[I] Stack allocated at {stack_ptr:p}"); + // Load program eprintln!("[I] Loading image from \"{image_path}\""); let file = File::open(image_path)?; @@ -36,6 +55,7 @@ fn main() -> Result<(), Box> { eprintln!("[I] Image loaded at {ptr:p}"); let mut vm = unsafe { Vm::<_, 0>::new(mem::HostMemory, Address::new(ptr as u64)) }; + vm.write_reg(254, stack_ptr as u64); // Memory access fault handling unsafe {