|
5 | 5 | //! [`bpf_loader`]: crate::bpf_loader |
6 | 6 |
|
7 | 7 | extern crate alloc; |
| 8 | +// Re-exporting for custom_panic |
| 9 | +pub use solana_define_syscall::definitions::{sol_log_ as __log, sol_panic_ as __panic}; |
8 | 10 | use { |
9 | 11 | alloc::vec::Vec, |
10 | 12 | solana_account_info::AccountInfo, |
@@ -233,8 +235,8 @@ macro_rules! custom_heap_default { |
233 | 235 | /// Define the default global panic handler. |
234 | 236 | /// |
235 | 237 | /// 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. |
238 | 240 | /// |
239 | 241 | /// The default global allocator is enabled only if the calling crate has not |
240 | 242 | /// disabled it using [Cargo features] as described below. It is only defined |
@@ -272,16 +274,28 @@ macro_rules! custom_heap_default { |
272 | 274 | /// $crate::msg!("{}", info); |
273 | 275 | /// } |
274 | 276 | /// ``` |
275 | | -/// |
276 | | -/// The above is how Solana defines the default panic handler. |
277 | 277 | #[macro_export] |
278 | 278 | macro_rules! custom_panic_default { |
279 | 279 | () => { |
280 | 280 | #[cfg(all(not(feature = "custom-panic"), target_os = "solana"))] |
281 | 281 | #[no_mangle] |
282 | 282 | 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 | + } |
285 | 299 | } |
286 | 300 | }; |
287 | 301 | } |
|
0 commit comments