Skip to content

Commit c8cfa8d

Browse files
Danilo Krummrichojeda
authored andcommitted
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>
1 parent 01b2196 commit c8cfa8d

File tree

3 files changed

+463
-1
lines changed

3 files changed

+463
-1
lines changed

rust/kernel/alloc.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#[cfg(not(any(test, testlib)))]
66
pub mod allocator;
77
pub mod box_ext;
8+
pub mod kbox;
89
pub mod vec_ext;
910

1011
#[cfg(any(test, testlib))]
@@ -13,6 +14,11 @@ pub mod allocator_test;
1314
#[cfg(any(test, testlib))]
1415
pub use self::allocator_test as allocator;
1516

17+
pub use self::kbox::Box;
18+
pub use self::kbox::KBox;
19+
pub use self::kbox::KVBox;
20+
pub use self::kbox::VBox;
21+
1622
/// Indicates an allocation error.
1723
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
1824
pub struct AllocError;

0 commit comments

Comments
 (0)