1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use core::alloc::Layout;
use linked_list_allocator::LockedHeap;
use crate::constant::KERNEL_HEAP_SIZE;
#[global_allocator]
static HEAP_ALLOCATOR: LockedHeap = LockedHeap::empty();
static mut KERNEL_HEAP: [u8; KERNEL_HEAP_SIZE] = [0; KERNEL_HEAP_SIZE];
pub fn init() {
unsafe {
HEAP_ALLOCATOR
.lock()
.init(KERNEL_HEAP.as_mut_ptr(), KERNEL_HEAP_SIZE);
}
}
#[alloc_error_handler]
pub fn handle_alloc_error(layout: Layout) -> ! {
panic!("failed to allocate the desired layout {:?}", layout);
}