diff --git a/src/mm/allocator.rs b/src/mm/allocator.rs index 615a3e2c09..941fff33b6 100644 --- a/src/mm/allocator.rs +++ b/src/mm/allocator.rs @@ -3,7 +3,6 @@ use core::alloc::{GlobalAlloc, Layout}; -use align_address::Align; use hermit_sync::RawInterruptTicketMutex; use talc::{ErrOnOom, Span, Talc, Talck}; @@ -16,13 +15,10 @@ impl LockedAllocator { #[inline] fn align_layout(layout: Layout) -> Layout { - let size = layout - .size() - .align_up(core::mem::size_of::>()); let align = layout .align() .max(core::mem::align_of::>()); - Layout::from_size_align(size, align).unwrap() + Layout::from_size_align(layout.size(), align).unwrap() } pub unsafe fn init(&self, heap_bottom: *mut u8, heap_size: usize) { @@ -45,6 +41,16 @@ unsafe impl GlobalAlloc for LockedAllocator { let layout = Self::align_layout(layout); unsafe { self.0.dealloc(ptr, layout) } } + + unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 { + let layout = Self::align_layout(layout); + unsafe { self.0.alloc_zeroed(layout) } + } + + unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 { + let layout = Self::align_layout(layout); + unsafe { self.0.realloc(ptr, layout, new_size) } + } } #[cfg(all(test, not(target_os = "none")))]