From 49bf92a7aaf10a4777ea512303e442588f4ce2e5 Mon Sep 17 00:00:00 2001 From: Nathan Ringo Date: Sun, 15 Sep 2024 03:25:30 -0500 Subject: Start of serious allocator work. --- crates/alloc_vma_tree/src/lib.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'crates/alloc_vma_tree/src/lib.rs') diff --git a/crates/alloc_vma_tree/src/lib.rs b/crates/alloc_vma_tree/src/lib.rs index 38dd312..e188ff7 100644 --- a/crates/alloc_vma_tree/src/lib.rs +++ b/crates/alloc_vma_tree/src/lib.rs @@ -21,6 +21,11 @@ pub struct VMATree { } impl VMATree { + /// The layout of a node in the tree. + /// + /// This is used in bootstrapping a mutually dependent allocator and `VMATree`. + pub const NODE_LAYOUT: Layout = Layout::new::>(); + /// Creates a new VMATree that will use the given allocator. pub const fn new_in(allocator: ALLOCATOR) -> VMATree { VMATree { @@ -167,19 +172,19 @@ impl VMANode { let mut ptr: NonNull> = allocator.allocate(layout)?.cast(); // SAFETY: This needs to be OK for the allocator to meet the conditions of its trait. - VMANode::init_in(unsafe { ptr.as_mut() }, addrs); + VMANode::init(unsafe { ptr.as_mut() }, addrs); Ok(ptr.cast()) } - /// Initializes a node. + /// Initializes a node. After this, the `MaybeUninit` is initialized. /// /// The node has the given range of addresses and is in the `Free` state. All of its pointers /// are self-pointers. #[requires(PAGE_SIZE_BITS > 0)] #[requires(addrs.start & ((1 << PAGE_SIZE_BITS) - 1) == 0)] #[requires(addrs.end & ((1 << PAGE_SIZE_BITS) - 1) == 0)] - pub fn init_in(maybe_uninit: &mut MaybeUninit>, addrs: Range) { + pub fn init(maybe_uninit: &mut MaybeUninit>, addrs: Range) { let ptr = NonNull::from(&*maybe_uninit).cast(); maybe_uninit.write(VMANode { addr_and_state: addrs.start, -- cgit v1.2.3