[PATCH 1/2] rust: sync: add Arc::DATA_OFFSET

Alice Ryhl posted 2 patches 2 weeks, 2 days ago
[PATCH 1/2] rust: sync: add Arc::DATA_OFFSET
Posted by Alice Ryhl 2 weeks, 2 days ago
This constant will be used to expose some offset constants from the Rust
Binder driver to tracepoints which are implemented in C. The constant is
usually equal to sizeof(refcount_t), but may be larger if T has a large
alignment.

Signed-off-by: Alice Ryhl <aliceryhl@google.com>
---
 rust/kernel/sync/arc.rs | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs
index 289f77abf415a2a52e039a2c0291413eda01217c..921e19333b895f0d971591c4753047d0248a3029 100644
--- a/rust/kernel/sync/arc.rs
+++ b/rust/kernel/sync/arc.rs
@@ -240,6 +240,9 @@ pub fn new(contents: T, flags: Flags) -> Result<Self, AllocError> {
         // `Arc` object.
         Ok(unsafe { Self::from_inner(inner) })
     }
+
+    /// The offset that the value is stored at.
+    pub const DATA_OFFSET: usize = core::mem::offset_of!(ArcInner<T>, data);
 }
 
 impl<T: ?Sized> Arc<T> {

-- 
2.52.0.158.g65b55ccf14-goog
Re: [PATCH 1/2] rust: sync: add Arc::DATA_OFFSET
Posted by Daniel Almeida 2 weeks, 1 day ago

> On 3 Dec 2025, at 08:48, Alice Ryhl <aliceryhl@google.com> wrote:
> 
> This constant will be used to expose some offset constants from the Rust
> Binder driver to tracepoints which are implemented in C. The constant is
> usually equal to sizeof(refcount_t), but may be larger if T has a large
> alignment.
> 
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>
> ---
> rust/kernel/sync/arc.rs | 3 +++
> 1 file changed, 3 insertions(+)
> 
> diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs
> index 289f77abf415a2a52e039a2c0291413eda01217c..921e19333b895f0d971591c4753047d0248a3029 100644
> --- a/rust/kernel/sync/arc.rs
> +++ b/rust/kernel/sync/arc.rs
> @@ -240,6 +240,9 @@ pub fn new(contents: T, flags: Flags) -> Result<Self, AllocError> {
>         // `Arc` object.
>         Ok(unsafe { Self::from_inner(inner) })
>     }
> +
> +    /// The offset that the value is stored at.
> +    pub const DATA_OFFSET: usize = core::mem::offset_of!(ArcInner<T>, data);
> }
> 
> impl<T: ?Sized> Arc<T> {
> 
> -- 
> 2.52.0.158.g65b55ccf14-goog
> 
> 


Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>