Skip to content

Commit c2f0204

Browse files
wedsonaffbq
authored andcommitted
rust: rbtree: add red-black tree implementation backed by the C version
The rust rbtree exposes a map-like interface over keys and values, backed by the kernel red-black tree implementation. Values can be inserted, deleted, and retrieved from a `RBTree` by key. This base abstraction is used by binder to store key/value pairs and perform lookups, for example the patch "[PATCH RFC 03/20] rust_binder: add threading support" in the binder RFC [1]. Link: https://lore.kernel.org/rust-for-linux/20231101-rust-binder-v1-3-08ba9197f637@google.com/ [1] Signed-off-by: Wedson Almeida Filho <wedsonaf@gmail.com> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Tested-by: Alice Ryhl <aliceryhl@google.com> Signed-off-by: Matt Gilbride <mattgilbride@google.com> Link: https://lore.kernel.org/r/20240727-b4-rbtree-v8-2-951600ada434@google.com
1 parent 76c469c commit c2f0204

3 files changed

Lines changed: 440 additions & 0 deletions

File tree

rust/helpers.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,13 @@ rust_helper_krealloc(const void *objp, size_t new_size, gfp_t flags)
200200
}
201201
EXPORT_SYMBOL_GPL(rust_helper_krealloc);
202202

203+
void rust_helper_rb_link_node(struct rb_node *node, struct rb_node *parent,
204+
struct rb_node **rb_link)
205+
{
206+
rb_link_node(node, parent, rb_link);
207+
}
208+
EXPORT_SYMBOL_GPL(rust_helper_rb_link_node);
209+
203210
/*
204211
* `bindgen` binds the C `size_t` type as the Rust `usize` type, so we can
205212
* use it in contexts where Rust expects a `usize` like slice (array) indices.

rust/kernel/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ pub mod net;
4343
pub mod page;
4444
pub mod prelude;
4545
pub mod print;
46+
pub mod rbtree;
4647
mod static_assert;
4748
#[doc(hidden)]
4849
pub mod std_vendor;

0 commit comments

Comments
 (0)