- implemented a custom allocator (fixed size block) with a fallback (linked list allocator) for larger block sizes

- apic code still not working (commented out, check lib.rs)
This commit is contained in:
2025-02-28 04:18:35 +00:00
parent e38c20dbd3
commit 8a3e9e3afc
7 changed files with 280 additions and 34 deletions
+20 -4
View File
@@ -1,15 +1,15 @@
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.
pub type FoundryAllocator = LockedHeap;
#[global_allocator]
/// This is now Rust's global allocator, so we can use stuff requiring heap allocations.
static ALLOCATOR: FoundryAllocator = FoundryAllocator::empty();
static ALLOCATOR: Locked<FoundryAllocator> = Locked::new(FoundryAllocator::new());
pub const HEAP_START: usize = 0x4444_4444_0000;
pub const HEAP_SIZE: usize = 1024 * 1024 * 1024;
@@ -19,8 +19,24 @@ pub fn init_heap() -> Result<(), MapToError<Size4KiB>> {
// code to allocate frames is now done in the page fault interrupt handler!
unsafe {
ALLOCATOR.lock().init(HEAP_START as *mut u8, HEAP_SIZE);
ALLOCATOR.lock().init(HEAP_START, HEAP_SIZE);
}
Ok(())
}
pub struct Locked<T> {
inner: Mutex<T>,
}
impl<T> Locked<T> {
pub const fn new(inner: T) -> Self {
Locked {
inner: Mutex::new(inner)
}
}
pub fn lock(&self) -> MutexGuard<T> {
self.inner.lock()
}
}