summaryrefslogtreecommitdiff
path: root/components/rust/core/src/panic.rs
diff options
context:
space:
mode:
authorzhang san <[email protected]>2025-12-08 18:34:25 +0800
committerGitHub <[email protected]>2025-12-08 18:34:25 +0800
commit69980f8b9d29b38dbd4ddf6373b4b45f3a138409 (patch)
tree21dd9a8ce80e3d30192e9ffa56ea39a199bae309 /components/rust/core/src/panic.rs
parentcd1d47b87c5d47e131730e5506eb3ad77d357653 (diff)
Adding Rust Language Support for RT-Thread #10910
Diffstat (limited to 'components/rust/core/src/panic.rs')
-rw-r--r--components/rust/core/src/panic.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/components/rust/core/src/panic.rs b/components/rust/core/src/panic.rs
new file mode 100644
index 0000000000..371f86fdb6
--- /dev/null
+++ b/components/rust/core/src/panic.rs
@@ -0,0 +1,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"]
+#[unsafe(no_mangle)]
+fn __rust_panic() -> ! {
+ /* Default weak panic handler: loops forever to halt execution. */
+ print!("Entered weak panic handler: system will halt.");
+ loop {}
+}