diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:43:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:43:14 +0000 |
commit | 8dd16259287f58f9273002717ec4d27e97127719 (patch) | |
tree | 3863e62a53829a84037444beab3abd4ed9dfc7d0 /toolkit/crashreporter/rust_minidump_writer_linux | |
parent | Releasing progress-linux version 126.0.1-1~progress7.99u1. (diff) | |
download | firefox-8dd16259287f58f9273002717ec4d27e97127719.tar.xz firefox-8dd16259287f58f9273002717ec4d27e97127719.zip |
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/crashreporter/rust_minidump_writer_linux')
-rw-r--r-- | toolkit/crashreporter/rust_minidump_writer_linux/Cargo.toml | 3 | ||||
-rw-r--r-- | toolkit/crashreporter/rust_minidump_writer_linux/src/lib.rs | 74 |
2 files changed, 51 insertions, 26 deletions
diff --git a/toolkit/crashreporter/rust_minidump_writer_linux/Cargo.toml b/toolkit/crashreporter/rust_minidump_writer_linux/Cargo.toml index b4bbd8e40b..8c414d8acf 100644 --- a/toolkit/crashreporter/rust_minidump_writer_linux/Cargo.toml +++ b/toolkit/crashreporter/rust_minidump_writer_linux/Cargo.toml @@ -9,7 +9,6 @@ license = "MPL-2.0" [dependencies] crash-context = "0.6.1" -minidump-writer = "0.8.3" +minidump-writer = "0.8.9" libc = "0.2.74" anyhow = "1.0" -nsstring = { path = "../../../xpcom/rust/nsstring/" } diff --git a/toolkit/crashreporter/rust_minidump_writer_linux/src/lib.rs b/toolkit/crashreporter/rust_minidump_writer_linux/src/lib.rs index 21ae630c5e..06ad386484 100644 --- a/toolkit/crashreporter/rust_minidump_writer_linux/src/lib.rs +++ b/toolkit/crashreporter/rust_minidump_writer_linux/src/lib.rs @@ -6,10 +6,10 @@ extern crate minidump_writer; use libc::pid_t; use minidump_writer::crash_context::CrashContext; use minidump_writer::minidump_writer::MinidumpWriter; -use nsstring::nsCString; -use std::ffi::CStr; +use std::ffi::{CStr, CString}; use std::mem::{self, MaybeUninit}; use std::os::raw::c_char; +use std::ptr::null_mut; // This function will be exposed to C++ #[no_mangle] @@ -17,17 +17,20 @@ pub unsafe extern "C" fn write_minidump_linux( dump_path: *const c_char, child: pid_t, child_blamed_thread: pid_t, - error_msg: &mut nsCString, + error_msg: *mut *mut c_char, ) -> bool { assert!(!dump_path.is_null()); let c_path = CStr::from_ptr(dump_path); let path = match c_path.to_str() { Ok(s) => s, Err(x) => { - error_msg.assign(&format!( - "Wrapper error. Path not convertable: {:#}", - anyhow::Error::new(x) - )); + error_message_to_c( + error_msg, + format!( + "Wrapper error. Path not convertable: {:#}", + anyhow::Error::new(x) + ), + ); return false; } }; @@ -39,11 +42,14 @@ pub unsafe extern "C" fn write_minidump_linux( { Ok(f) => f, Err(x) => { - error_msg.assign(&format!( - "Wrapper error when opening minidump destination at {:?}: {:#}", - path, - anyhow::Error::new(x) - )); + error_message_to_c( + error_msg, + format!( + "Wrapper error when opening minidump destination at {:?}: {:#}", + path, + anyhow::Error::new(x) + ), + ); return false; } }; @@ -53,7 +59,7 @@ pub unsafe extern "C" fn write_minidump_linux( return true; } Err(x) => { - error_msg.assign(&format!("{:#}", anyhow::Error::new(x))); + error_message_to_c(error_msg, format!("{:#}", anyhow::Error::new(x))); return false; } } @@ -75,7 +81,7 @@ pub unsafe extern "C" fn write_minidump_linux_with_context( #[allow(unused)] float_state: *const fpregset_t, siginfo: *const libc::signalfd_siginfo, child_thread: libc::pid_t, - error_msg: &mut nsCString, + error_msg: *mut *mut c_char, ) -> bool { let c_path = CStr::from_ptr(dump_path); @@ -97,10 +103,13 @@ pub unsafe extern "C" fn write_minidump_linux_with_context( let path = match c_path.to_str() { Ok(s) => s, Err(x) => { - error_msg.assign(&format!( - "Wrapper error. Path not convertable: {:#}", - anyhow::Error::new(x) - )); + error_message_to_c( + error_msg, + format!( + "Wrapper error. Path not convertable: {:#}", + anyhow::Error::new(x) + ), + ); return false; } }; @@ -112,11 +121,14 @@ pub unsafe extern "C" fn write_minidump_linux_with_context( { Ok(f) => f, Err(x) => { - error_msg.assign(&format!( - "Wrapper error when opening minidump destination at {:?}: {:#}", - path, - anyhow::Error::new(x) - )); + error_message_to_c( + error_msg, + format!( + "Wrapper error when opening minidump destination at {:?}: {:#}", + path, + anyhow::Error::new(x) + ), + ); return false; } }; @@ -129,8 +141,22 @@ pub unsafe extern "C" fn write_minidump_linux_with_context( return true; } Err(x) => { - error_msg.assign(&format!("{:#}", anyhow::Error::new(x))); + error_message_to_c(error_msg, format!("{:#}", anyhow::Error::new(x))); return false; } } } + +fn error_message_to_c(c_string_pointer: *mut *mut c_char, error_message: String) { + if c_string_pointer != null_mut() { + let c_error_message = CString::new(error_message).unwrap_or_default(); + unsafe { *c_string_pointer = c_error_message.into_raw() }; + } +} + +// This function will be exposed to C++ +#[no_mangle] +pub unsafe extern "C" fn free_minidump_error_msg(c_string: *mut c_char) { + // Unused because we just need to drop it + let _c_string = unsafe { CString::from_raw(c_string) }; +} |