Skip to content

Commit 436941b

Browse files
committed
Space efficient panic
1 parent ac11e3e commit 436941b

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

define-syscall/src/definitions.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ define_syscall!(fn sol_remaining_compute_units() -> u64);
3131
define_syscall!(fn sol_alt_bn128_compression(op: u64, input: *const u8, input_size: u64, result: *mut u8) -> u64);
3232
define_syscall!(fn sol_get_sysvar(sysvar_id_addr: *const u8, result: *mut u8, offset: u64, length: u64) -> u64);
3333
define_syscall!(fn sol_get_epoch_stake(vote_address: *const u8) -> u64);
34+
define_syscall!(fn sol_panic_(filename: *const u8, filename_len: u64, line: u64, column: u64));
3435

3536
// these are to be deprecated once they are superceded by sol_get_sysvar
3637
define_syscall!(fn sol_get_clock_sysvar(addr: *mut u8) -> u64);

program-entrypoint/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ edition = { workspace = true }
1111

1212
[dependencies]
1313
solana-account-info = { workspace = true }
14+
solana-define-syscall = { workspace = true }
1415
solana-msg = { workspace = true }
1516
solana-program-error = { workspace = true }
1617
solana-pubkey = { workspace = true, default-features = false }

program-entrypoint/src/lib.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
//! [`bpf_loader`]: crate::bpf_loader
66
77
extern crate alloc;
8+
// Re-exporting for custom_panic
9+
pub use solana_define_syscall::definitions::{sol_log_ as __log, sol_panic_ as __panic};
810
use {
911
alloc::vec::Vec,
1012
solana_account_info::AccountInfo,
@@ -233,8 +235,8 @@ macro_rules! custom_heap_default {
233235
/// Define the default global panic handler.
234236
///
235237
/// This must be used if the [`entrypoint`] macro is not used, and no other
236-
/// panic handler has been defined; otherwise compilation will fail with a
237-
/// missing `custom_panic` symbol.
238+
/// panic handler has been defined; otherwise a program will crash without an
239+
/// explicit panic message.
238240
///
239241
/// The default global allocator is enabled only if the calling crate has not
240242
/// disabled it using [Cargo features] as described below. It is only defined
@@ -272,16 +274,28 @@ macro_rules! custom_heap_default {
272274
/// $crate::msg!("{}", info);
273275
/// }
274276
/// ```
275-
///
276-
/// The above is how Solana defines the default panic handler.
277277
#[macro_export]
278278
macro_rules! custom_panic_default {
279279
() => {
280280
#[cfg(all(not(feature = "custom-panic"), target_os = "solana"))]
281281
#[no_mangle]
282282
fn custom_panic(info: &core::panic::PanicInfo<'_>) {
283-
// Full panic reporting
284-
$crate::__msg!("{}", info);
283+
if let Some(mm) = info.message().as_str() {
284+
unsafe {
285+
$crate::__log(mm.as_ptr(), mm.len() as u64);
286+
}
287+
}
288+
289+
if let Some(loc) = info.location() {
290+
unsafe {
291+
$crate::__panic(
292+
loc.file().as_ptr(),
293+
loc.file().len() as u64,
294+
loc.line() as u64,
295+
loc.column() as u64,
296+
)
297+
}
298+
}
285299
}
286300
};
287301
}

0 commit comments

Comments
 (0)