Implement add_free_region

This commit is contained in:
Philipp Oppermann
2020-01-10 11:44:17 +01:00
parent 63e8577d77
commit 2e1d132a9a

View File

@@ -1,3 +1,6 @@
use super::align_up;
use core::mem;
struct ListNode { struct ListNode {
size: usize, size: usize,
next: Option<&'static mut ListNode>, next: Option<&'static mut ListNode>,
@@ -43,6 +46,15 @@ impl LinkedListAllocator {
/// Adds the given memory region to the front of the list. /// Adds the given memory region to the front of the list.
unsafe fn add_free_region(&mut self, addr: usize, size: usize) { unsafe fn add_free_region(&mut self, addr: usize, size: usize) {
todo!(); // ensure that the freed region is capable of holding ListNode
assert!(align_up(addr, mem::align_of::<ListNode>()) == addr);
assert!(size >= mem::size_of::<ListNode>());
// create a new list node and append it at the start of the list
let mut node = ListNode::new(size);
node.next = self.head.next.take();
let node_ptr = addr as *mut ListNode;
node_ptr.write(node);
self.head.next = Some(&mut *node_ptr)
} }
} }