userspace/
panic.rs

1#[cfg(not(feature = "with_std"))]
2use core::panic::PanicInfo;
3
4pub use crate::info;
5
6#[panic_handler]
7#[cfg(not(feature = "with_std"))]
8pub fn panic(info: &PanicInfo) -> ! {
9    hook();
10    if let Some(location) = info.location() {
11        // Example: send to UART or RTT instead of println
12        let filename = location.file();
13        let fileline = location.line() as u32;
14        let filecolumn = location.column() as u32;
15        info!(
16            "\npanic at file: {}:{}:{}\n",
17            filename, fileline, filecolumn
18        );
19    }
20    let mut count = 5;
21    loop {
22        count -= 1;
23        info!("x.");
24        if count == 0 {
25            info!("..:");
26            // unsafe { core::arch::asm!("call flag_license") };
27            crate::target::os::syscall::exit(23);
28        }
29    }
30}
31
32pub fn hook() -> () {
33    // #[cfg(feature = "with_std")]
34    // std::panic::set_hook(std::boxed::Box::new(|info| {
35    //     info!("Custom panic: {}", info);
36    //     unsafe { core::arch::asm!("call flag_license") };
37    // }));
38}