mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
Implement LinkedListAllocator::size_align
This commit is contained in:
@@ -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> {
|
||||||
|
|||||||
@@ -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"]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user