diff options
Diffstat (limited to 'crates/alloc_vma_tree/src')
-rw-r--r-- | crates/alloc_vma_tree/src/lib.rs | 11 |
1 files changed, 8 insertions, 3 deletions
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<const PAGE_SIZE_BITS: usize, ALLOCATOR: Allocator> { } impl<const PAGE_SIZE_BITS: usize, ALLOCATOR: Allocator> VMATree<PAGE_SIZE_BITS, ALLOCATOR> { + /// 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::<VMANode<PAGE_SIZE_BITS>>(); + /// Creates a new VMATree that will use the given allocator. pub const fn new_in(allocator: ALLOCATOR) -> VMATree<PAGE_SIZE_BITS, ALLOCATOR> { VMATree { @@ -167,19 +172,19 @@ impl<const PAGE_SIZE_BITS: usize> VMANode<PAGE_SIZE_BITS> { let mut ptr: NonNull<MaybeUninit<Self>> = 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<VMANode<PAGE_SIZE_BITS>>, addrs: Range<usize>) { + pub fn init(maybe_uninit: &mut MaybeUninit<VMANode<PAGE_SIZE_BITS>>, addrs: Range<usize>) { let ptr = NonNull::from(&*maybe_uninit).cast(); maybe_uninit.write(VMANode { addr_and_state: addrs.start, |