Skip to content

Commit 00dcdcf

Browse files
Danilo Krummrichojeda
authored andcommitted
rust: alloc: implement kernel Vec type
`Vec` provides a contiguous growable array type with contents allocated with the kernel's allocators (e.g. `Kmalloc`, `Vmalloc` or `KVmalloc`). In contrast to Rust's stdlib `Vec` type, the kernel `Vec` type considers the kernel's GFP flags for all appropriate functions, always reports allocation failures through `Result<_, AllocError>` and remains independent from unstable features. [ This patch starts using a new unstable feature, `inline_const`, but it was stabilized in Rust 1.79.0, i.e. the next version after the minimum one, thus it will not be an issue. - Miguel ] 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-17-dakr@kernel.org [ Cleaned `rustdoc` unescaped backtick warning, added a couple more backticks elsewhere, fixed typos, sorted `feature`s, rewrapped documentation line. - Miguel ] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
1 parent 9e7bbfa commit 00dcdcf

File tree

4 files changed

+657
-1
lines changed

4 files changed

+657
-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 kbox;
8+
pub mod kvec;
89
pub mod layout;
910
pub mod vec_ext;
1011

@@ -19,6 +20,11 @@ pub use self::kbox::KBox;
1920
pub use self::kbox::KVBox;
2021
pub use self::kbox::VBox;
2122

23+
pub use self::kvec::KVVec;
24+
pub use self::kvec::KVec;
25+
pub use self::kvec::VVec;
26+
pub use self::kvec::Vec;
27+
2228
/// Indicates an allocation error.
2329
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
2430
pub struct AllocError;

0 commit comments

Comments
 (0)