summaryrefslogtreecommitdiffstats
path: root/rust/kernel/alloc.rs
diff options
context:
space:
mode:
authorDanilo Krummrich <dakr@kernel.org>2024-10-04 17:41:15 +0200
committerMiguel Ojeda <ojeda@kernel.org>2024-10-15 22:56:59 +0200
commitc8cfa8d0c0b10be216861fe904ea68978b1dcc97 (patch)
tree14e1a23a8c4f8883e0243bb0e25d9cabd8da2da9 /rust/kernel/alloc.rs
parent01b2196e5aac8af9343282d0044fa0d6b07d484c (diff)
downloadlinux-c8cfa8d0c0b10be216861fe904ea68978b1dcc97.tar.gz
linux-c8cfa8d0c0b10be216861fe904ea68978b1dcc97.tar.bz2
linux-c8cfa8d0c0b10be216861fe904ea68978b1dcc97.zip
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>
Diffstat (limited to 'rust/kernel/alloc.rs')
-rw-r--r--rust/kernel/alloc.rs6
1 files changed, 6 insertions, 0 deletions
diff --git a/rust/kernel/alloc.rs b/rust/kernel/alloc.rs
index 8172106a1423..3628e16240a6 100644
--- a/rust/kernel/alloc.rs
+++ b/rust/kernel/alloc.rs
@@ -5,6 +5,7 @@
#[cfg(not(any(test, testlib)))]
pub mod allocator;
pub mod box_ext;
+pub mod kbox;
pub mod vec_ext;
#[cfg(any(test, testlib))]
@@ -13,6 +14,11 @@ pub mod allocator_test;
#[cfg(any(test, testlib))]
pub use self::allocator_test as allocator;
+pub use self::kbox::Box;
+pub use self::kbox::KBox;
+pub use self::kbox::KVBox;
+pub use self::kbox::VBox;
+
/// Indicates an allocation error.
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub struct AllocError;