2019-05-21 13:39:27 -07:00
|
|
|
//! @brief Solana Rust-based BPF program panic handling
|
|
|
|
|
|
|
|
use core::panic::PanicInfo;
|
|
|
|
|
|
|
|
#[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-10 11:00:15 -07:00
|
|
|
None => unsafe { sol_panic_(0 as *const u8, 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
|
|
|
}
|