2023-02-14 22:48:02

by David Gow

[permalink] [raw]
Subject: [PATCH] rust: kernel: Mark rust_fmt_argument as extern "C"

The rust_fmt_argument function is called from printk() to handle the %pA
format specifier.

Since it's called from C, we should mark it extern "C" to make sure it's
ABI compatible.

Cc: [email protected]
Fixes: 247b365dc8dc ("rust: add `kernel` crate")
Signed-off-by: David Gow <[email protected]>
---

See discussion in:
https://github.com/Rust-for-Linux/linux/pull/967
and
https://github.com/Rust-for-Linux/linux/pull/966

---
rust/kernel/print.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/rust/kernel/print.rs b/rust/kernel/print.rs
index 30103325696d..ec457f0952fe 100644
--- a/rust/kernel/print.rs
+++ b/rust/kernel/print.rs
@@ -18,7 +18,7 @@ use crate::bindings;

// Called from `vsprintf` with format specifier `%pA`.
#[no_mangle]
-unsafe fn rust_fmt_argument(buf: *mut c_char, end: *mut c_char, ptr: *const c_void) -> *mut c_char {
+unsafe extern "C" fn rust_fmt_argument(buf: *mut c_char, end: *mut c_char, ptr: *const c_void) -> *mut c_char {
use fmt::Write;
// SAFETY: The C contract guarantees that `buf` is valid if it's less than `end`.
let mut w = unsafe { RawFormatter::from_ptrs(buf.cast(), end.cast()) };
--
2.39.1.581.gbfd45094c4-goog



2023-02-15 07:28:52

by Gary Guo

[permalink] [raw]
Subject: Re: [PATCH] rust: kernel: Mark rust_fmt_argument as extern "C"

On Wed, 15 Feb 2023 06:47:35 +0800
David Gow <[email protected]> wrote:

> The rust_fmt_argument function is called from printk() to handle the %pA
> format specifier.
>
> Since it's called from C, we should mark it extern "C" to make sure it's
> ABI compatible.
>
> Cc: [email protected]
> Fixes: 247b365dc8dc ("rust: add `kernel` crate")
> Signed-off-by: David Gow <[email protected]>

Reviewed-by: Gary Guo <[email protected]>

> ---
>
> See discussion in:
> https://github.com/Rust-for-Linux/linux/pull/967
> and
> https://github.com/Rust-for-Linux/linux/pull/966
>
> ---
> rust/kernel/print.rs | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/rust/kernel/print.rs b/rust/kernel/print.rs
> index 30103325696d..ec457f0952fe 100644
> --- a/rust/kernel/print.rs
> +++ b/rust/kernel/print.rs
> @@ -18,7 +18,7 @@ use crate::bindings;
>
> // Called from `vsprintf` with format specifier `%pA`.
> #[no_mangle]
> -unsafe fn rust_fmt_argument(buf: *mut c_char, end: *mut c_char, ptr: *const c_void) -> *mut c_char {
> +unsafe extern "C" fn rust_fmt_argument(buf: *mut c_char, end: *mut c_char, ptr: *const c_void) -> *mut c_char {
> use fmt::Write;
> // SAFETY: The C contract guarantees that `buf` is valid if it's less than `end`.
> let mut w = unsafe { RawFormatter::from_ptrs(buf.cast(), end.cast()) };


2023-02-15 17:55:16

by Björn Roy Baron

[permalink] [raw]
Subject: Re: [PATCH] rust: kernel: Mark rust_fmt_argument as extern "C"

On Tuesday, February 14th, 2023 at 23:47, David Gow <[email protected]> wrote:

> The rust_fmt_argument function is called from printk() to handle the %pA
> format specifier.
>
> Since it's called from C, we should mark it extern "C" to make sure it's
> ABI compatible.
>
> Cc: [email protected]
> Fixes: 247b365dc8dc ("rust: add `kernel` crate")
> Signed-off-by: David Gow [email protected]

Reviewed-by: Björn Roy Baron <[email protected]>

>
> ---
>
> See discussion in:
> https://github.com/Rust-for-Linux/linux/pull/967
> and
> https://github.com/Rust-for-Linux/linux/pull/966
>
> ---
> rust/kernel/print.rs | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/rust/kernel/print.rs b/rust/kernel/print.rs
> index 30103325696d..ec457f0952fe 100644
> --- a/rust/kernel/print.rs
> +++ b/rust/kernel/print.rs
> @@ -18,7 +18,7 @@ use crate::bindings;
>
> // Called from `vsprintf` with format specifier `%pA`.
> #[no_mangle]
> -unsafe fn rust_fmt_argument(buf: *mut c_char, end: *mut c_char, ptr: *const c_void) -> *mut c_char {
> +unsafe extern "C" fn rust_fmt_argument(buf: *mut c_char, end: *mut c_char, ptr: *const c_void) -> *mut c_char {
> use fmt::Write;
> // SAFETY: The C contract guarantees that `buf` is valid if it's less than `end`.
> let mut w = unsafe { RawFormatter::from_ptrs(buf.cast(), end.cast()) };
> --
> 2.39.1.581.gbfd45094c4-goog

2023-02-15 19:18:03

by Miguel Ojeda

[permalink] [raw]
Subject: Re: [PATCH] rust: kernel: Mark rust_fmt_argument as extern "C"

On Tue, Feb 14, 2023 at 11:47 PM David Gow <[email protected]> wrote:
>
> The rust_fmt_argument function is called from printk() to handle the %pA
> format specifier.
>
> Since it's called from C, we should mark it extern "C" to make sure it's
> ABI compatible.
>
> Cc: [email protected]
> Fixes: 247b365dc8dc ("rust: add `kernel` crate")
> Signed-off-by: David Gow <[email protected]>

Thanks David -- I will apply `rustfmt` on my side.

Cheers,
Miguel

2023-02-15 22:30:48

by Vincenzo Palazzo

[permalink] [raw]
Subject: Re: [PATCH] rust: kernel: Mark rust_fmt_argument as extern "C"

> The rust_fmt_argument function is called from printk() to handle the %pA
> format specifier.
>
> Since it's called from C, we should mark it extern "C" to make sure it's
> ABI compatible.
>
> Cc: [email protected]
> Fixes: 247b365dc8dc ("rust: add `kernel` crate")
> Signed-off-by: David Gow <[email protected]>
> ---

Reviewed-by: Vincenzo Palazzo <[email protected]>

2023-04-06 21:12:59

by Miguel Ojeda

[permalink] [raw]
Subject: Re: [PATCH] rust: kernel: Mark rust_fmt_argument as extern "C"

On Tue, Feb 14, 2023 at 11:47 PM David Gow <[email protected]> wrote:
>
> The rust_fmt_argument function is called from printk() to handle the %pA
> format specifier.
>
> Since it's called from C, we should mark it extern "C" to make sure it's
> ABI compatible.

Applied to `rust-fixes`, thanks!

Cheers,
Miguel