rust: ptr: add projection infrastructureAdd a generic infrastructure for performing field and index projections onraw pointers. This will form the basis of performing I/O projections.Pointers ma
rust: ptr: add projection infrastructureAdd a generic infrastructure for performing field and index projections onraw pointers. This will form the basis of performing I/O projections.Pointers manipulations are intentionally using the safe wrapping variantsinstead of the unsafe variants, as the latter requires pointers to beinside an allocation which is not necessarily true for I/O pointers.This projection macro protects against rogue `Deref` implementation, whichcan causes the projected pointer to be outside the bounds of startingpointer. This is extremely unlikely and Rust has a lint to catch this, butis unsoundness regardless. The protection works by inducing type inferenceambiguity when `Deref` is implemented.This projection macro also stops projecting into unaligned fields (i.e.fields of `#[repr(packed)]` structs), as misaligned pointers requirespecial handling. This is implemented by attempting to create reference toprojected field inside a `if false` block. Despite being unreachable, Ruststill checks that they're not unaligned fields.The projection macro supports both fallible and infallible indexprojections. These are described in detail inside the documentation.Signed-off-by: Gary Guo <gary@garyguo.net>Reviewed-by: Benno Lossin <lossin@kernel.org>Acked-by: Miguel Ojeda <ojeda@kernel.org>Link: https://patch.msgid.link/20260302164239.284084-3-gary@kernel.org[ * Add intro-doc links where possible, * Fix typos and slightly improve wording, e.g. "as documentation describes" -> "as the documentation of [`Self::proj`] describes", * Add an empty line between regular and safety comments, before examples, and between logically independent comments, * Capitalize various safety comments. - Danilo ]Signed-off-by: Danilo Krummrich <dakr@kernel.org>
show more ...