[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAH5fLgjJhM5mi_hOF=xhOKxwBWDBh_TEFtqx-1LR_yj2t_HiQA@mail.gmail.com>
Date: Wed, 20 Nov 2024 09:58:17 +0100
From: Alice Ryhl <aliceryhl@...gle.com>
To: Lyude Paul <lyude@...hat.com>
Cc: rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org,
Miguel Ojeda <ojeda@...nel.org>, Alex Gaynor <alex.gaynor@...il.com>,
Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <benno.lossin@...ton.me>, Andreas Hindborg <a.hindborg@...nel.org>,
Trevor Gross <tmgross@...ch.edu>, Martin Rodriguez Reboredo <yakoyoku@...il.com>,
Valentin Obst <kernel@...entinobst.de>, Filipe Xavier <felipe_life@...e.com>
Subject: Re: [PATCH v4 1/2] rust: sync: Add Lock::from_raw() for Lock<(), B>
On Wed, Nov 20, 2024 at 12:11 AM Lyude Paul <lyude@...hat.com> wrote:
>
> The KMS bindings ( https://patchwork.freedesktop.org/series/131522/ ) have
> a few bindings that require manually acquiring specific locks before
> calling certain functions. At the moment though, the only way of acquiring
> these locks in bindings is to simply call the C locking functions directly
> - since said locks are not acquired on the rust side of things.
>
> However - if we add `#[repr(C)]` to `Lock<(), B>`, then given `()` is a ZST
> - `Lock<(), B>` becomes equivalent in data layout to its inner `B::State`
> type. Since locks in C don't have data explicitly associated with them
> anyway, we can take advantage of this to add a `Lock::from_raw()` function
> that can translate a raw pointer to `B::State` into its proper `Lock<(),
> B>` equivalent. This lets us simply acquire a reference to the lock in
> question and work with it like it was initialized on the rust side of
> things, allowing us to use less unsafe code to implement bindings with lock
> requirements.
>
> Signed-off-by: Lyude Paul <lyude@...hat.com>
Reviewed-by: Alice Ryhl <aliceryhl@...gle.com>
Powered by blists - more mailing lists