From 20018141193e166b7275111ebb70850886f957b3 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Fri, 10 Jan 2020 13:00:16 +0100 Subject: [PATCH] Implement LinkedListAllocator::size_align --- src/allocator/linked_list.rs | 13 +++++++++++++ src/lib.rs | 1 + 2 files changed, 14 insertions(+) diff --git a/src/allocator/linked_list.rs b/src/allocator/linked_list.rs index 079f7cdb..699efbdf 100644 --- a/src/allocator/linked_list.rs +++ b/src/allocator/linked_list.rs @@ -103,6 +103,19 @@ impl LinkedListAllocator { // region suitable for allocation Ok(alloc_start) } + + /// Adjust the given layout so that the resulting allocated memory + /// region is also capable of storing a `ListNode`. + /// + /// Returns the adjusted size and alignment as a (size, align) tuple. + fn size_align(layout: Layout) -> (usize, usize) { + let layout = layout + .align_to(mem::align_of::()) + .expect("adjusting alignment failed") + .pad_to_align(); + let size = layout.size().max(mem::size_of::()); + (size, layout.align()) + } } unsafe impl GlobalAlloc for Locked { diff --git a/src/lib.rs b/src/lib.rs index 79956351..8b1c46f9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,6 +4,7 @@ #![feature(abi_x86_interrupt)] #![feature(alloc_error_handler)] #![feature(const_fn)] +#![feature(alloc_layout_extra)] #![test_runner(crate::test_runner)] #![reexport_test_harness_main = "test_main"]