mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
Add FixedSizeBlockAllocator::fallback_alloc method
This commit is contained in:
@@ -1,3 +1,6 @@
|
|||||||
|
use alloc::alloc::Layout;
|
||||||
|
use core::ptr;
|
||||||
|
|
||||||
/// The block sizes to use.
|
/// The block sizes to use.
|
||||||
///
|
///
|
||||||
/// The sizes must each be power of 2 because they are also used as
|
/// 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) {
|
pub unsafe fn init(&mut self, heap_start: usize, heap_size: usize) {
|
||||||
self.fallback_allocator.init(heap_start, heap_size);
|
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(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user