Re: [PATCH v9 25/29] rust: alloc: implement `Cmalloc` in module allocator_test
From: Danilo Krummrich
Date: Tue Oct 08 2024 - 10:33:36 EST
On Fri, Oct 04, 2024 at 05:41:29PM +0200, Danilo Krummrich wrote:
> So far the kernel's `Box` and `Vec` types can't be used by userspace
> test cases, since all users of those types (e.g. `CString`) use kernel
> allocators for instantiation.
>
> In order to allow userspace test cases to make use of such types as
> well, implement the `Cmalloc` allocator within the allocator_test module
> and type alias all kernel allocators to `Cmalloc`. The `Cmalloc`
> allocator uses libc's realloc() function as allocator backend.
>
> Reviewed-by: Benno Lossin <benno.lossin@xxxxxxxxx>
> Reviewed-by: Gary Guo <gary@xxxxxxxxxxx>
> Signed-off-by: Danilo Krummrich <dakr@xxxxxxxxxx>
> ---
> rust/kernel/alloc/allocator_test.rs | 88 ++++++++++++++++++++++++++---
> 1 file changed, 81 insertions(+), 7 deletions(-)
>
Here we can remove it again:
diff --git a/rust/kernel/alloc.rs b/rust/kernel/alloc.rs
index 912b6ba2abaa..8acaa24a8f1f 100644
--- a/rust/kernel/alloc.rs
+++ b/rust/kernel/alloc.rs
@@ -215,7 +215,6 @@ unsafe fn free(ptr: NonNull<u8>, layout: Layout) {
}
}
-#[allow(dead_code)]
/// Returns a properly aligned dangling pointer from the given `layout`.
pub(crate) fn dangling_from_layout(layout: Layout) -> NonNull<u8> {
let ptr = layout.align() as *mut u8;
@Miguel: I pushed [1], which is already rebased to rust-next (-rc2) and contains
the fixups.
[1] https://git.kernel.org/pub/scm/linux/kernel/git/dakr/linux.git/log/?h=rust/mm