[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230330114946.696c8e72.gary@garyguo.net>
Date: Thu, 30 Mar 2023 11:49:46 +0100
From: Gary Guo <gary@...yguo.net>
To: y86-dev@...tonmail.com
Cc: Miguel Ojeda <ojeda@...nel.org>,
Alex Gaynor <alex.gaynor@...il.com>,
Wedson Almeida Filho <wedsonaf@...il.com>,
Boqun Feng <boqun.feng@...il.com>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Alice Ryhl <alice@...l.io>, rust-for-linux@...r.kernel.org,
linux-kernel@...r.kernel.org, patches@...ts.linux.dev
Subject: Re: [PATCH v3 03/13] rust: types: add `Opaque::raw_get`
On Wed, 29 Mar 2023 22:33:03 +0000
y86-dev@...tonmail.com wrote:
> From: Benno Lossin <y86-dev@...tonmail.com>
>
> This function mirrors `UnsafeCell::raw_get`. It avoids creating a
> reference and allows solely using raw pointers.
> The `pin-init` API will be using this, since uninitialized memory
> requires raw pointers.
>
> Signed-off-by: Benno Lossin <y86-dev@...tonmail.com>
Reviewed-by: Gary Guo <gary@...yguo.net>
> ---
> rust/kernel/types.rs | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/rust/kernel/types.rs b/rust/kernel/types.rs
> index 9d0fdbc55843..ff2b2fac951d 100644
> --- a/rust/kernel/types.rs
> +++ b/rust/kernel/types.rs
> @@ -238,6 +238,14 @@ impl<T> Opaque<T> {
> pub fn get(&self) -> *mut T {
> UnsafeCell::raw_get(self.0.as_ptr())
> }
> +
> + /// Gets the value behind `this`.
> + ///
> + /// This function is useful to get access to the value without creating intermediate
> + /// references.
> + pub const fn raw_get(this: *const Self) -> *mut T {
> + UnsafeCell::raw_get(this.cast::<UnsafeCell<T>>())
> + }
> }
>
> /// A sum type that always holds either a value of type `L` or `R`.
> --
> 2.39.2
>
>
Powered by blists - more mailing lists