From b45d75c16871ec95019b43c8e30dbab62d8f038e Mon Sep 17 00:00:00 2001 From: Yuhao Zhou Date: Tue, 30 Apr 2019 00:10:39 +0800 Subject: [PATCH] Align base address in init_heap(). --- kernel/src/memory.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/kernel/src/memory.rs b/kernel/src/memory.rs index f98f1ad..a20a70b 100644 --- a/kernel/src/memory.rs +++ b/kernel/src/memory.rs @@ -1,4 +1,5 @@ use super::HEAP_ALLOCATOR; +use core::mem; pub use crate::arch::paging::*; use crate::consts::MEMORY_OFFSET; use crate::process::process_unsafe; @@ -114,11 +115,13 @@ pub fn handle_page_fault(addr: usize) -> bool { pub fn init_heap() { use crate::consts::KERNEL_HEAP_SIZE; - static mut HEAP: [u8; KERNEL_HEAP_SIZE] = [0; KERNEL_HEAP_SIZE]; + const machine_align: usize = mem::size_of::(); + const heap_block: usize = KERNEL_HEAP_SIZE / machine_align; + static mut HEAP: [usize; heap_block] = [0; heap_block]; unsafe { HEAP_ALLOCATOR .lock() - .init(HEAP.as_ptr() as usize, KERNEL_HEAP_SIZE); + .init(HEAP.as_ptr() as usize, heap_block * machine_align); } info!("heap init end"); }