32 lines
909 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
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
2019-06-20 16:07:12 -07:00
// Message is ignored for now to avoid incurring formatting program size overhead
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() {
2019-06-20 16:07:12 -07:00
if i > 127 {
2019-06-10 11:00:15 -07:00
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" {
pub fn sol_panic_(file: *const u8, line: u64, column: u64) -> !;
2019-05-21 13:39:27 -07:00
}