Skip to content

Commit c45f3ce

Browse files
committed
ANDROID: rust: add rcu_dereference_raw
Implement rcu_dereference_raw by calling into READ_ONCE. This function is intended for reading pointers in an rcu_read_lock region. It establishes a consume ordering, so it is valid to read the memory behind the pointer. Signed-off-by: Alice Ryhl <aliceryhl@google.com>
1 parent 96df76d commit c45f3ce

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

rust/bindings/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ mod bindings_helper {
5050
pub use bindings_raw::*;
5151

5252
mod rwonce;
53-
pub use rwonce::{READ_ONCE, WRITE_ONCE};
53+
pub use rwonce::{READ_ONCE, WRITE_ONCE, rcu_dereference_raw};

rust/bindings/rwonce/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,9 @@ pub unsafe fn READ_ONCE<T: Copy>(ptr: *const T) -> T {
3232
pub unsafe fn WRITE_ONCE<T: Copy>(ptr: *mut T, val: T) {
3333
unsafe { __WRITE_ONCE(ptr, val) }
3434
}
35+
36+
/// Dereference the pointer for rcu.
37+
#[inline(always)]
38+
pub unsafe fn rcu_dereference_raw<T>(ptr: *const *mut T) -> *mut T {
39+
unsafe { READ_ONCE(ptr) }
40+
}

0 commit comments

Comments
 (0)