rust: types: add `ForeignOwnable::PointedTo`
authorTamir Duberstein <tamird@gmail.com>
Wed, 23 Apr 2025 13:54:37 +0000 (09:54 -0400)
committerAndreas Hindborg <a.hindborg@kernel.org>
Thu, 1 May 2025 09:35:49 +0000 (11:35 +0200)
commit1a4736c3d8394f5e64557a41b4b2b8d6dcd04622
tree89467c5abc9bdfb43df6a5b9763cfab9582fb260
parent9c32cda43eb78f78c73aee4aa344b777714e259b
rust: types: add `ForeignOwnable::PointedTo`

Allow implementors to specify the foreign pointer type; this exposes
information about the pointed-to type such as its alignment.

This requires the trait to be `unsafe` since it is now possible for
implementors to break soundness by returning a misaligned pointer.

Encoding the pointer type in the trait (and avoiding pointer casts)
allows the compiler to check that implementors return the correct
pointer type. This is preferable to directly encoding the alignment in
the trait using a constant as the compiler would be unable to check it.

Acked-by: Danilo Krummrich <dakr@kernel.org>
Signed-off-by: Tamir Duberstein <tamird@gmail.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Link: https://lore.kernel.org/r/20250423-rust-xarray-bindings-v19-1-83cdcf11c114@gmail.com
Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
rust/kernel/alloc/kbox.rs
rust/kernel/miscdevice.rs
rust/kernel/pci.rs
rust/kernel/platform.rs
rust/kernel/sync/arc.rs
rust/kernel/types.rs