forked from AbleOS/holey-bytes
Fixed stack allocation for debug
This commit is contained in:
parent
bcbe47bcd6
commit
5f8864e251
|
@ -31,7 +31,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allocate stack
|
// Allocate stack
|
||||||
let mut stack = Box::new(MaybeUninit::<[u8; 1024 * 1024 * 2]>::uninit());
|
let mut stack = unsafe { mem::alloc_stack() };
|
||||||
eprintln!("[I] Stack allocated at {:p}", stack.as_ptr());
|
eprintln!("[I] Stack allocated at {:p}", stack.as_ptr());
|
||||||
|
|
||||||
// Load program
|
// Load program
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::alloc::Layout;
|
||||||
|
|
||||||
use hbvm::mem::{Address, LoadError, Memory, StoreError};
|
use hbvm::mem::{Address, LoadError, Memory, StoreError};
|
||||||
|
|
||||||
pub struct HostMemory;
|
pub struct HostMemory;
|
||||||
|
@ -29,3 +31,17 @@ impl Memory for HostMemory {
|
||||||
unsafe { core::ptr::read(addr.get() as *const T) }
|
unsafe { core::ptr::read(addr.get() as *const T) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const STACK_SIZE: usize = 2; // MiB
|
||||||
|
type Stack = [u8; 1024 * 1024 * STACK_SIZE];
|
||||||
|
|
||||||
|
/// Allocate stack of size [`STACK_SIZE`] MiB
|
||||||
|
pub unsafe fn alloc_stack() -> Box<Stack> {
|
||||||
|
let layout = Layout::new::<Stack>();
|
||||||
|
let ptr = unsafe { std::alloc::alloc(layout) };
|
||||||
|
if ptr.is_null() {
|
||||||
|
std::alloc::handle_alloc_error(layout);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe { Box::from_raw(ptr.cast()) }
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue