32 lines
845 B
Rust
Raw Normal View History

2019-05-21 13:39:27 -07:00
//! @brief Solana Rust-based BPF program panic handling
use core::panic::PanicInfo;
2019-06-20 07:43:31 -07:00
use core::ptr;
2019-05-21 13:39:27 -07:00
#[cfg(not(test))]
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
2019-06-10 11:00:15 -07:00
match info.location() {
Some(location) => {
let mut file: [u8; 128] = [0; 128];
for (i, c) in location.file().as_bytes().iter().enumerate() {
if i >= 126 {
break;
}
file[i] = *c;
}
2019-05-21 13:39:27 -07:00
unsafe {
2019-06-10 11:00:15 -07:00
sol_panic_(
file.as_ptr(),
u64::from(location.line()),
u64::from(location.column()),
);
2019-05-21 13:39:27 -07:00
}
}
2019-06-20 07:43:31 -07:00
None => unsafe { sol_panic_(ptr::null(), 0, 0) },
2019-05-21 13:39:27 -07:00
}
}
extern "C" {
2019-06-10 11:00:15 -07:00
pub fn sol_panic_(message: *const u8, line: u64, column: u64) -> !;
2019-05-21 13:39:27 -07:00
}