]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
rust: alloc: implement kernel `Box`
authorDanilo Krummrich <dakr@kernel.org>
Fri, 7 Mar 2025 22:49:37 +0000 (23:49 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 13 Mar 2025 12:01:44 +0000 (13:01 +0100)
commit3ca8b102ef6229eb859f84f0f6a43a84a5d60c1b
tree5eb741a8bf010c9afc85031147dd555ddc2ed578
parent10027707e1cafe3761b3268bef090a7d4f968013
rust: alloc: implement kernel `Box`

commit c8cfa8d0c0b10be216861fe904ea68978b1dcc97 upstream.

`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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
rust/kernel/alloc.rs
rust/kernel/alloc/kbox.rs [new file with mode: 0644]
rust/kernel/prelude.rs