use linked_list_allocator::LockedHeap; use spin::{Mutex, MutexGuard}; use x86_64::structures::paging::{ mapper::MapToError, Size4KiB, }; use crate::drivers::kalloc::foundry_kalloc::FoundryAllocator; /// We are currently using a linked list heap allocator which uses our underlying page allocator. #[global_allocator] /// This is now Rust's global allocator, so we can use stuff requiring heap allocations. static ALLOCATOR: Locked = Locked::new(FoundryAllocator::new()); pub const HEAP_START: usize = 0x4444_4444_0000; pub const HEAP_SIZE: usize = 1024 * 1024 * 1024; /// Sets up the heap using the backing page frame allocator. pub fn init_heap() -> Result<(), MapToError> { // code to allocate frames is now done in the page fault interrupt handler! unsafe { ALLOCATOR.lock().init(HEAP_START, HEAP_SIZE); } Ok(()) } pub struct Locked { inner: Mutex, } impl Locked { pub const fn new(inner: T) -> Self { Locked { inner: Mutex::new(inner) } } pub fn lock(&self) -> MutexGuard { self.inner.lock() } }