From d636939b51479e7311163ba07dff18c86f2ec6be Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Mon, 20 Jan 2020 14:05:01 +0100 Subject: [PATCH] Add FixedSizeBlockAllocator::fallback_alloc method --- src/allocator/fixed_size_block.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/allocator/fixed_size_block.rs b/src/allocator/fixed_size_block.rs index a4c517bb..c83a12cd 100644 --- a/src/allocator/fixed_size_block.rs +++ b/src/allocator/fixed_size_block.rs @@ -1,3 +1,6 @@ +use alloc::alloc::Layout; +use core::ptr; + /// The block sizes to use. /// /// The sizes must each be power of 2 because they are also used as @@ -30,4 +33,12 @@ impl FixedSizeBlockAllocator { pub unsafe fn init(&mut self, heap_start: usize, heap_size: usize) { self.fallback_allocator.init(heap_start, heap_size); } + + /// Allocates using the fallback allocator. + fn fallback_alloc(&mut self, layout: Layout) -> *mut u8 { + match self.fallback_allocator.allocate_first_fit(layout) { + Ok(ptr) => ptr.as_ptr(), + Err(_) => ptr::null_mut(), + } + } }