From 442ac6bc26bcc81c3a3e27a308da0ed41d05af0d Mon Sep 17 00:00:00 2001 From: Douglas Raillard Date: Mon, 7 Oct 2024 01:24:23 +0100 Subject: [PATCH] lisa/_assets/kmodules/lisa: Assert alignment of Rust allocation FEATURE Ensure the addresses returned by the allocator are aligned as expected. --- lisa/_assets/kmodules/lisa/rust/src/runtime.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lisa/_assets/kmodules/lisa/rust/src/runtime.rs b/lisa/_assets/kmodules/lisa/rust/src/runtime.rs index 6e3721ca2..826729f99 100644 --- a/lisa/_assets/kmodules/lisa/rust/src/runtime.rs +++ b/lisa/_assets/kmodules/lisa/rust/src/runtime.rs @@ -34,7 +34,9 @@ fn with_size *mut u8>(layout: Layout, f: F) -> *mut u8 { // For sizes which are a power of two, the kmalloc() alignment is also guaranteed to be at // least the respective size. if align <= 8 || (size.is_power_of_two() && align <= size) { - f(layout.size()) + let ptr = f(layout.size()); + assert!((ptr as usize % align) == 0); + ptr } else { pr_info!("Rust: cannot allocate memory with alignment > 8"); core::ptr::null_mut() -- GitLab