rust: alloc: implement kernel `Box`
authorDanilo Krummrich <dakr@kernel.org>
Fri, 4 Oct 2024 15:41:15 +0000 (17:41 +0200)
committerMiguel Ojeda <ojeda@kernel.org>
Tue, 15 Oct 2024 20:56:59 +0000 (22:56 +0200)
commitc8cfa8d0c0b10be216861fe904ea68978b1dcc97
tree14e1a23a8c4f8883e0243bb0e25d9cabd8da2da9
parent01b2196e5aac8af9343282d0044fa0d6b07d484c
rust: alloc: implement kernel `Box`

`Box` provides the simplest way to allocate memory for a generic type
with one of the kernel's allocators, e.g. `Kmalloc`, `Vmalloc` or
`KVmalloc`.

In contrast to Rust's `Box` type, the kernel `Box` type considers the
kernel's GFP flags for all appropriate functions, always reports
allocation failures through `Result<_, AllocError>` and remains
independent from unstable features.

Reviewed-by: Benno Lossin <benno.lossin@proton.me>
Reviewed-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
Link: https://lore.kernel.org/r/20241004154149.93856-12-dakr@kernel.org
[ Added backticks, fixed typos. - Miguel ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
rust/kernel/alloc.rs
rust/kernel/alloc/kbox.rs [new file with mode: 0644]
rust/kernel/prelude.rs