diff --git a/programs/bpf/c/src/panic/panic.c b/programs/bpf/c/src/panic/panic.c new file mode 100644 index 0000000000..c6e773643f --- /dev/null +++ b/programs/bpf/c/src/panic/panic.c @@ -0,0 +1,11 @@ +/** + * @brief Example C-based BPF program that prints out the parameters + * passed to it + */ +#include + +extern bool entrypoint(const uint8_t *input) { + sol_panic(); + return true; +} + diff --git a/programs/bpf/tests/programs.rs b/programs/bpf/tests/programs.rs index af51c0c03d..ca066e350d 100644 --- a/programs/bpf/tests/programs.rs +++ b/programs/bpf/tests/programs.rs @@ -37,17 +37,18 @@ mod bpf { solana_logger::setup(); let programs = [ - "bpf_to_bpf", - "multiple_static", - "noop", - "noop++", - "relative_call", - "struct_pass", - "struct_ret", + ("bpf_to_bpf", true), + ("multiple_static", true), + ("noop", true), + ("noop++", true), + ("panic", false), + ("relative_call", true), + ("struct_pass", true), + ("struct_ret", true), ]; for program in programs.iter() { - println!("Test program: {:?}", program); - let mut file = File::open(create_bpf_path(program)).expect("file open failed"); + println!("Test program: {:?}", program.0); + let mut file = File::open(create_bpf_path(program.0)).expect("file open failed"); let mut elf = Vec::new(); file.read_to_end(&mut elf).unwrap(); @@ -63,9 +64,12 @@ mod bpf { let program_id = load_program(&bank_client, &mint_keypair, &bpf_loader::id(), elf); let instruction = create_invoke_instruction(mint_keypair.pubkey(), program_id, &1u8); - bank_client - .send_instruction(&mint_keypair, instruction) - .unwrap(); + let result = bank_client.send_instruction(&mint_keypair, instruction); + if program.1 { + assert!(result.is_ok()); + } else { + assert!(result.is_err()); + } } } } diff --git a/sdk/bpf/c/inc/solana_sdk.h b/sdk/bpf/c/inc/solana_sdk.h index aeb6c8df81..da2d3396f4 100644 --- a/sdk/bpf/c/inc/solana_sdk.h +++ b/sdk/bpf/c/inc/solana_sdk.h @@ -175,19 +175,15 @@ SOL_FN_PREFIX size_t sol_strlen(const char *s) { * Prints the line number where the panic occurred and then causes * the BPF VM to immediately halt execution. No accounts' userdata are updated */ -#define sol_panic() _sol_panic(__LINE__) -SOL_FN_PREFIX void _sol_panic(uint64_t line) { - sol_log_64(0xFF, 0xFF, 0xFF, 0xFF, line); - uint8_t *pv = (uint8_t *)1; - *pv = 1; -} +void sol_panic_(const char *, uint64_t, uint64_t); +#define sol_panic() sol_panic_(__FILE__, __LINE__, 0) /** * Asserts */ #define sol_assert(expr) \ if (!(expr)) { \ - _sol_panic(__LINE__); \ + sol_panic(); \ } /** diff --git a/sdk/bpf/rust/rust-utils/src/panic.rs b/sdk/bpf/rust/rust-utils/src/panic.rs index 6b7fdd2dec..85a318a995 100644 --- a/sdk/bpf/rust/rust-utils/src/panic.rs +++ b/sdk/bpf/rust/rust-utils/src/panic.rs @@ -28,5 +28,5 @@ fn panic(info: &PanicInfo) -> ! { } } extern "C" { - pub fn sol_panic_(message: *const u8, line: u64, column: u64) -> !; + pub fn sol_panic_(file: *const u8, line: u64, column: u64) -> !; }