Add a linked list allocator for heap that can now do 256 mib due to

frame allocator optimizations, make a basic init function in arch that
will initialize everything for a given arch. Add tests in kmain for
alloc, and add a Locked struct used for static mutables and the linked
list.
This commit is contained in:
csd4ni3l
2026-03-28 15:06:16 +01:00
parent 269d900d97
commit 4a3c1c9ced
8 changed files with 285 additions and 67 deletions

36
kernel/src/util.rs Normal file
View File

@@ -0,0 +1,36 @@
use spin::{Mutex, MutexGuard};
pub struct LinkedNode {
pub size: usize,
pub next: Option<&'static mut LinkedNode>,
}
impl LinkedNode {
pub const fn new(size: usize) -> LinkedNode {
LinkedNode { size, next: None }
}
pub fn start_addr(&self) -> usize {
self as *const Self as usize
}
pub fn end_addr(&self) -> usize {
self.start_addr() + self.size
}
}
pub struct Locked<A> {
inner: Mutex<A>,
}
impl<A> Locked<A> {
pub const fn new(inner: A) -> Self {
Locked {
inner: Mutex::new(inner),
}
}
pub fn lock(&self) -> MutexGuard<A> {
self.inner.lock()
}
}