mirror of
https://github.com/XunilGroup/XunilOS.git
synced 2026-04-25 19:59:02 +02:00
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:
36
kernel/src/util.rs
Normal file
36
kernel/src/util.rs
Normal 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()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user