Skip to content

Commit 6f340f8

Browse files
Danilo Krummrichfbq
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. Signed-off-by: Danilo Krummrich <[email protected]> Link: https://lore.kernel.org/r/[email protected] [boqun: Resolve the conflict against InPlaceInit::PinnedSelf]
1 parent 300f443 commit 6f340f8

File tree

3 files changed

+470
-1
lines changed

3 files changed

+470
-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)