mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-22 08:53:29 +00:00
21 lines
527 B
Rust
21 lines
527 B
Rust
use crate::config::KERNEL_HEAP_SIZE;
|
|
use buddy_system_allocator::LockedHeap;
|
|
|
|
#[global_allocator]
|
|
static HEAP_ALLOCATOR: LockedHeap<32> = LockedHeap::empty();
|
|
|
|
#[alloc_error_handler]
|
|
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];
|
|
|
|
pub fn init() {
|
|
unsafe {
|
|
HEAP_ALLOCATOR
|
|
.lock()
|
|
.init(HEAP_SPACE.as_ptr() as usize, KERNEL_HEAP_SIZE);
|
|
}
|
|
}
|