summaryrefslogtreecommitdiffstats
path: root/toolkit/crashreporter/rust_minidump_writer_linux
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 05:35:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 05:35:29 +0000
commit59203c63bb777a3bacec32fb8830fba33540e809 (patch)
tree58298e711c0ff0575818c30485b44a2f21bf28a0 /toolkit/crashreporter/rust_minidump_writer_linux
parentAdding upstream version 126.0.1. (diff)
downloadfirefox-59203c63bb777a3bacec32fb8830fba33540e809.tar.xz
firefox-59203c63bb777a3bacec32fb8830fba33540e809.zip
Adding upstream version 127.0.upstream/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.toml3
-rw-r--r--toolkit/crashreporter/rust_minidump_writer_linux/src/lib.rs74
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) };
+}