summaryrefslogtreecommitdiff
path: root/crates/alloc_buddy/src/lib.rs
diff options
context:
space:
mode:
authorNathan Ringo <nathan@remexre.com>2024-09-02 02:07:07 -0500
committerNathan Ringo <nathan@remexre.com>2024-09-02 02:07:07 -0500
commit52e33eee454766940d1987199868f0d892ce34a3 (patch)
tree64515ac26d363dcfe4304b1dd34665502746d82d /crates/alloc_buddy/src/lib.rs
parent1afb23196b9882f85c8fbcfbfbd5f92a58960e14 (diff)
Set up the physical memory allocators.
Diffstat (limited to 'crates/alloc_buddy/src/lib.rs')
-rw-r--r--crates/alloc_buddy/src/lib.rs28
1 files changed, 14 insertions, 14 deletions
diff --git a/crates/alloc_buddy/src/lib.rs b/crates/alloc_buddy/src/lib.rs
index c890e79..fc5d245 100644
--- a/crates/alloc_buddy/src/lib.rs
+++ b/crates/alloc_buddy/src/lib.rs
@@ -369,6 +369,19 @@ impl<
self.free_list(size_class).push(ptr);
}
+ /// Returns a `Debug` that prints the free lists of the allocator.
+ pub fn debug_free_lists(&self) -> impl '_ + fmt::Debug {
+ debug(|fmt| {
+ fmt.debug_list()
+ .entries((0..SIZE_CLASS_COUNT).map(|size_class| {
+ // SAFETY: The free lists are kept valid, and the range of size classes is
+ // necessarily in-bounds.
+ unsafe { FreeList::from_sentinel(self.free_list_sentinels.add(size_class)) }
+ }))
+ .finish()
+ })
+ }
+
/// Returns the free list with the given size class.
#[requires(size_class < SIZE_CLASS_COUNT)]
fn free_list(&mut self, size_class: usize) -> FreeList {
@@ -411,20 +424,7 @@ impl<
{
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt.debug_struct("BuddyAllocator")
- .field(
- "free_lists",
- &debug(|fmt| {
- fmt.debug_list()
- .entries((0..SIZE_CLASS_COUNT).map(|size_class| {
- // SAFETY: The free lists are kept valid, and the range of size classes is
- // necessarily in-bounds.
- unsafe {
- FreeList::from_sentinel(self.free_list_sentinels.add(size_class))
- }
- }))
- .finish()
- }),
- )
+ .field("free_lists", &self.debug_free_lists())
.field(
"trees",
&debug(|fmt| {