[PATCH v1 5/5] rust: Add warn_on and warn_on_once
Alice Ryhl
aliceryhl at google.com
Tue Dec 10 01:05:07 PST 2024
On Tue, Dec 10, 2024 at 1:19 AM FUJITA Tomonori
<fujita.tomonori at gmail.com> wrote:
>
> Add warn_on and warn_on_once macros. Wrapping the C's WARN_* and BUG_*
> macros doesn't work so this uses the assembly code exported by the C
> side via ARCH_WARN_ASM macro. Like the static branch code, this
> generates the assembly code for rust dynamically by using the C
> preprocessor.
>
> file()! macro doesn't work for the Rust inline assembly in the same
> way as __FILE__ for the C inline assembly. So the code to handle a
> file name is different from the C assembly code (similar to the
> arm64/loongarch assembly).
>
> ASM_REACHABLE definition works in the same way to get objtool's
> reachable asm code. The architectures which use objtool (x86 and
> loongarch) needs it.
>
> Signed-off-by: FUJITA Tomonori <fujita.tomonori at gmail.com>
> +#[macro_export]
> +#[doc(hidden)]
> +#[cfg(all(CONFIG_BUG, not(CONFIG_UML)))]
> +#[cfg(any(target_arch = "x86_64", target_arch = "riscv64"))]
> +#[macro_export]
> +#[doc(hidden)]
> +#[cfg(all(CONFIG_BUG, not(CONFIG_UML)))]
> +#[cfg(any(target_arch = "aarch64", target_arch = "loongarch64"))]
What's the reason for this arch-specific code? The file!()/line!()
invocations? Could they be passed as an argument to the asm instead so
that we don't need target_arch cfgs? I understand that they don't work
exactly the same way, but maybe it could still work?
> +#[macro_export]
> +#[doc(hidden)]
> +#[cfg(all(CONFIG_BUG, CONFIG_UML))]
> +macro_rules! warn_flags {
> + ($flags:expr) => {
> + // SAFETY: Just an FFI call.
> + unsafe {
> + $crate::bindings::warn_slowpath_fmt(
> + $crate::c_str!(::core::file!()).as_ptr() as *const ::core::ffi::c_char,
> + line!() as i32,
> + $flags as u32,
> + ::core::ptr::null() as *const ::core::ffi::c_char,
I wonder if this could be written to utilize Location::caller()
instead so that `#[track_caller]` works?
Alice
More information about the linux-arm-kernel
mailing list