summaryrefslogtreecommitdiff
path: root/components/rust/core/src/panic.rs
blob: b45ad7d1a34b2b6fa2aac0d1b4da872752c6dd76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
 * Copyright (c) 2006-2025, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2025-10-10     foxglove     RT-Thread Panic implementation
 */
use crate::print;

pub fn panic_on_atomic_context(s: &str) {
    use crate::api::is_irq_context;
    if is_irq_context() {
        panic!("In irq context {}", s);
    }
}

#[panic_handler]
#[inline(never)]
fn panic(info: &core::panic::PanicInfo) -> ! {
    print!("{:}", info);
    __rust_panic()
}

#[linkage = "weak"]
#[no_mangle]
fn __rust_panic() -> ! {
    /* Default weak panic handler: loops forever to halt execution. */
    print!("Entered weak panic handler: system will halt.");
    loop {}
}