rust: file: mark LocalFile as repr(transparent)

Unsafe code in `LocalFile`'s methods assumes that the type has the same
layout as the inner `bindings::file`. This is not guaranteed by the default
struct representation in Rust, but requires specifying the `transparent`
representation.

The `File` struct (which also wraps `bindings::file`) is already marked as
`repr(transparent)`, so this change makes their layouts equivalent.

Fixes: 851849824b ("rust: file: add Rust abstraction for `struct file`")
Closes: https://github.com/Rust-for-Linux/linux/issues/1165
Signed-off-by: Pekka Ristola <pekkarr@protonmail.com>
Link: https://lore.kernel.org/20250527204636.12573-1-pekkarr@protonmail.com
Reviewed-by: Benno Lossin <lossin@kernel.org>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
Pekka Ristola 2025-05-27 20:48:55 +00:00 committed by Christian Brauner
parent 34ecde3c56
commit 15ecd83dc0
No known key found for this signature in database
GPG Key ID: 91C61BC06578DCA2

View File

@ -219,6 +219,7 @@ unsafe fn dec_ref(obj: ptr::NonNull<File>) {
/// must be on the same thread as this file.
///
/// [`assume_no_fdget_pos`]: LocalFile::assume_no_fdget_pos
#[repr(transparent)]
pub struct LocalFile {
inner: Opaque<bindings::file>,
}