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
//! Kernel memory allocator

use {
    buddy_system_allocator::LockedHeap,
    log::{error, info},
    xen::memory::VirtualAddress,
};

#[global_allocator]
pub static ALLOCATOR: LockedHeap<32> = LockedHeap::empty();

/// Initialize allocator
pub unsafe fn init(heap_start: VirtualAddress, heap_size: usize) {
    info!(
        "Initialising allocator with heap start {:#x} and length {}",
        heap_start.0, heap_size
    );

    ALLOCATOR.lock().init(heap_start.0, heap_size);
}

#[alloc_error_handler]
fn alloc_error_handler(layout: alloc::alloc::Layout) -> ! {
    error!("ALLOCATOR: {:?}", ALLOCATOR.lock());
    panic!("allocation error: {:?}", layout);
}