| 1 | use crate::{owned, report, string}; |
| 2 | use std::ffi::c_char; |
| 3 | |
| 4 | #[unsafe(no_mangle)] |
| 5 | pub extern "C" fn sb_crash_address() -> *const c_char { |
| 6 | crash_report::ADDRESS.as_ptr() |
| 7 | } |
| 8 | |
| 9 | /// # Safety |
| 10 | /// Each argument is NUL-terminated UTF-8; `path` is a private local report file. |
| 11 | #[unsafe(no_mangle)] |
| 12 | pub unsafe extern "C" fn sb_crash_start( |
| 13 | path: *const c_char, |
| 14 | build: *const c_char, |
| 15 | system: *const c_char, |
| 16 | ) -> bool { |
| 17 | crash_report::hook( |
| 18 | &string(build), |
| 19 | format!("{}-{}", std::env::consts::OS, std::env::consts::ARCH), |
| 20 | string(system), |
| 21 | |report| eprint!("{report}"), |
| 22 | ); |
| 23 | report(crash_report::set_path(string(path).into()).map_err(Into::into)).is_some() |
| 24 | } |
| 25 | |
| 26 | /// The saved report, freed with `sb_string_free`, or null. |
| 27 | #[unsafe(no_mangle)] |
| 28 | pub extern "C" fn sb_crash_report() -> *mut c_char { |
| 29 | crash_report::kept().map_or(std::ptr::null_mut(), owned) |
| 30 | } |
| 31 | |
| 32 | #[unsafe(no_mangle)] |
| 33 | pub extern "C" fn sb_crash_forget() { |
| 34 | crash_report::forget(); |
| 35 | } |