forked from ROMEO/fsw-ws
44 lines
1.1 KiB
Rust
44 lines
1.1 KiB
Rust
use core::panic::PanicInfo;
|
|
use core::fmt::Write;
|
|
|
|
extern "C" {
|
|
fn done();
|
|
}
|
|
|
|
#[cfg(not(test))]
|
|
#[panic_handler]
|
|
fn panic(panic: &PanicInfo<'_>) -> ! {
|
|
// unsafe { this breaks in ISR
|
|
// osal::stop_it();
|
|
// }
|
|
_ = writeln!(crate::fsrc::sif::Stderr {}, "");
|
|
_ = writeln!(
|
|
crate::fsrc::sif::Stderr {},
|
|
"Thread '{}' {}",
|
|
crate::fsrc::osal::thread::current().name(),
|
|
panic
|
|
);
|
|
//TODO: stop RTOS, exit if hosted
|
|
unsafe { done() };
|
|
loop {}
|
|
}
|
|
|
|
#[no_mangle]
|
|
extern "C" fn rust_assert_called(ptr: *const core::ffi::c_char, line: core::ffi::c_ulong) {
|
|
let file_name = unsafe {
|
|
//TODO is from_ptr safe enough?
|
|
let file_name = core::ffi::CStr::from_ptr(ptr);
|
|
let file_name_utf8 = core::str::from_utf8(file_name.to_bytes());
|
|
match file_name_utf8 {
|
|
Ok(string) => string,
|
|
Err(_) => "Schei� Encoding",
|
|
}
|
|
};
|
|
|
|
panic!("assertion failed at {file_name}:{line}");
|
|
}
|
|
|
|
#[no_mangle]
|
|
extern "C" fn rust_alloc_failed() {
|
|
panic!("allocation failed!");
|
|
} |