[PATCH v2 0/5] Check Rust signatures at compile time

Greg Kroah-Hartman gregkh at linuxfoundation.org
Sat Mar 1 04:43:49 UTC 2025


On Fri, Feb 28, 2025 at 12:39:29PM +0000, Alice Ryhl wrote:
> Rust has two different tools for generating function declarations to
> call across the FFI boundary:
> 
> * bindgen. Generates Rust declarations from a C header.
> * cbindgen. Generates C headers from Rust declarations.
> 
> In the kernel, we only use bindgen. This is because cbindgen assumes a
> cargo-based buildsystem, so it is not compatible with the kernel's build
> system. This means that when C code calls a Rust function by name, its
> signature must be duplicated in both Rust code and a C header, and the
> signature needs to be kept in sync manually.
> 
> To eliminate this manual checking, introduce a new macro that verifies
> at compile time that the two function declarations use the same
> signature. The idea is to run the C declaration through bindgen, and
> then have rustc verify that the function pointers have the same type.
> 
> The main commit of this series is "rust: add #[export] macro". Please
> see its commit message for more details.
> 
> Signed-off-by: Alice Ryhl <aliceryhl at google.com>


Acked-by: Greg Kroah-Hartman <gregkh at linuxfoundation.org>


More information about the dri-devel mailing list