Understanding memory space and move higher the stack

This commit is contained in:
Zhang Junyang
2024-03-13 13:56:04 +08:00
committed by Tate, Hongliang Tian
parent dede22843a
commit 52f07458f7
29 changed files with 155 additions and 125 deletions

View File

@ -11,11 +11,10 @@ use log::debug;
use super::paddr_to_vaddr;
use crate::{
config::{KERNEL_HEAP_SIZE, PAGE_SIZE},
prelude::*,
sync::SpinLock,
trap::disable_local,
vm::frame_allocator::FRAME_ALLOCATOR,
vm::{frame_allocator::FRAME_ALLOCATOR, PAGE_SIZE},
Error,
};
@ -27,12 +26,14 @@ pub fn handle_alloc_error(layout: core::alloc::Layout) -> ! {
panic!("Heap allocation error, layout = {:?}", layout);
}
static mut HEAP_SPACE: [u8; KERNEL_HEAP_SIZE] = [0; KERNEL_HEAP_SIZE];
const INIT_KERNEL_HEAP_SIZE: usize = PAGE_SIZE * 256;
static mut HEAP_SPACE: [u8; INIT_KERNEL_HEAP_SIZE] = [0; INIT_KERNEL_HEAP_SIZE];
pub fn init() {
// Safety: The HEAP_SPACE is a static memory range, so it's always valid.
unsafe {
HEAP_ALLOCATOR.init(HEAP_SPACE.as_ptr(), KERNEL_HEAP_SIZE);
HEAP_ALLOCATOR.init(HEAP_SPACE.as_ptr(), INIT_KERNEL_HEAP_SIZE);
}
}