Split out Rust BPF no-std stuff (#4968)

This commit is contained in:
Jack May
2019-07-08 20:28:05 -08:00
committed by GitHub
parent 49250f62aa
commit f9a2254688
35 changed files with 164 additions and 217 deletions

View File

@@ -0,0 +1,31 @@
//! @brief Solana Rust-based BPF program panic handling
use core::panic::PanicInfo;
use core::ptr;
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
// Message is ignored for now to avoid incurring formatting program size overhead
match info.location() {
Some(location) => {
let mut file: [u8; 128] = [0; 128];
for (i, c) in location.file().as_bytes().iter().enumerate() {
if i > 127 {
break;
}
file[i] = *c;
}
unsafe {
sol_panic_(
file.as_ptr(),
u64::from(location.line()),
u64::from(location.column()),
);
}
}
None => unsafe { sol_panic_(ptr::null(), 0, 0) },
}
}
extern "C" {
pub fn sol_panic_(file: *const u8, line: u64, column: u64) -> !;
}