lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87y0xplx3o.fsf@kernel.org>
Date: Fri, 28 Feb 2025 19:53:31 +0100
From: Andreas Hindborg <a.hindborg@...nel.org>
To: "Alice Ryhl" <aliceryhl@...gle.com>
Cc: "Greg Kroah-Hartman" <gregkh@...uxfoundation.org>,  "Miguel Ojeda"
 <ojeda@...nel.org>,  "Petr Mladek" <pmladek@...e.com>,  "Steven Rostedt"
 <rostedt@...dmis.org>,  "Andy Shevchenko"
 <andriy.shevchenko@...ux.intel.com>,  "Rasmus Villemoes"
 <linux@...musvillemoes.dk>,  "Sergey Senozhatsky"
 <senozhatsky@...omium.org>,  "Andrew Morton" <akpm@...ux-foundation.org>,
  "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>,  "Trevor Gross" <tmgross@...ch.edu>,  "Maarten
 Lankhorst" <maarten.lankhorst@...ux.intel.com>,  "Maxime Ripard"
 <mripard@...nel.org>,  "Thomas Zimmermann" <tzimmermann@...e.de>,  "David
 Airlie" <airlied@...il.com>,  "Simona Vetter" <simona@...ll.ch>,
  <linux-kernel@...r.kernel.org>,  <rust-for-linux@...r.kernel.org>,
  <dri-devel@...ts.freedesktop.org>
Subject: Re: [PATCH v2 3/5] rust: add #[export] macro

"Alice Ryhl" <aliceryhl@...gle.com> writes:

> 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 signature must still be written twice, but at least you can no
> longer get it wrong. If the signatures don't match, you will get errors
> that look like this:
>
> error[E0308]: `if` and `else` have incompatible types
>   --> <linux>/rust/kernel/print.rs:22:22
>    |
> 21 | #[export]
>    | --------- expected because of this
> 22 | unsafe extern "C" fn rust_fmt_argument(
>    |                      ^^^^^^^^^^^^^^^^^ expected `u8`, found `i8`
>    |
>    = note: expected fn item `unsafe extern "C" fn(*mut u8, *mut u8, *mut c_void) -> *mut u8 {bindings::rust_fmt_argument}`
>               found fn item `unsafe extern "C" fn(*mut i8, *mut i8, *const c_void) -> *mut i8 {print::rust_fmt_argument}`
>
> It is unfortunate that the error message starts out by saying "`if` and
> `else` have incompatible types", but I believe the rest of the error
> message is reasonably clear and not too confusing.
>
> Signed-off-by: Alice Ryhl <aliceryhl@...gle.com>


Reviewed-by: Andreas Hindborg <a.hindborg@...nel.org>


Best regards,
Andreas Hindborg




Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ