Implement LinkedListAllocator::size_align

This commit is contained in:
Philipp Oppermann
2020-01-10 13:00:16 +01:00
parent a5c50e7408
commit 2001814119
2 changed files with 14 additions and 0 deletions

View File

@@ -103,6 +103,19 @@ impl LinkedListAllocator {
// region suitable for allocation // region suitable for allocation
Ok(alloc_start) 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::<ListNode>())
.expect("adjusting alignment failed")
.pad_to_align();
let size = layout.size().max(mem::size_of::<ListNode>());
(size, layout.align())
}
} }
unsafe impl GlobalAlloc for Locked<LinkedListAllocator> { unsafe impl GlobalAlloc for Locked<LinkedListAllocator> {

View File

@@ -4,6 +4,7 @@
#![feature(abi_x86_interrupt)] #![feature(abi_x86_interrupt)]
#![feature(alloc_error_handler)] #![feature(alloc_error_handler)]
#![feature(const_fn)] #![feature(const_fn)]
#![feature(alloc_layout_extra)]
#![test_runner(crate::test_runner)] #![test_runner(crate::test_runner)]
#![reexport_test_harness_main = "test_main"] #![reexport_test_harness_main = "test_main"]