Skip to contentSkip to conversation

rust: kernel: Mark rust_fmt_argument as extern "C"

PATCH Applied David Gow 5 participants 6 messages Feb 14, 2023 – Apr 6, 2023

Subsystems (2)
lore
Share & tools
lore

David Gow

author
#0 lore raw

PATCH 1/1 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.

Fixes 247b365dc8dc ("rust: add `kernel` crate")

---

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(-)
rust/kernel/print.rs +1 -1
index 30103325696d..ec457f0952fe 100644
@@ -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()) };
Signature · 1 line
2.39.1.581.gbfd45094c4-goog
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · 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.

Fixes 247b365dc8dc ("rust: add `kernel` crate")
Quoted 24 lines

---

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(-)
rust/kernel/print.rs +1 -1
index 30103325696d..ec457f0952fe 100644
@@ -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()) };
reviewer Reviewed-by on v1 1/1
#2 lore raw
In reply to David Gow
Quoted 9 lines · David Gow

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.

Fixes 247b365dc8dc ("rust: add `kernel` crate")
Quoted 27 lines

---

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(-)
rust/kernel/print.rs +1 -2
index 30103325696d..ec457f0952fe 100644
@@ -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

#3 lore raw
In reply to David Gow
Quoted 10 lines · David Gow

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.

Fixes 247b365dc8dc ("rust: add `kernel` crate")

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

Cheers,
Miguel

Applied
#5 lore raw
In reply to David Gow
Quoted 6 lines · David Gow

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