diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /toolkit/crashreporter/rust_minidump_writer_linux/src | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/crashreporter/rust_minidump_writer_linux/src')
-rw-r--r-- | toolkit/crashreporter/rust_minidump_writer_linux/src/lib.rs | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/toolkit/crashreporter/rust_minidump_writer_linux/src/lib.rs b/toolkit/crashreporter/rust_minidump_writer_linux/src/lib.rs new file mode 100644 index 0000000000..dd6ed9a32b --- /dev/null +++ b/toolkit/crashreporter/rust_minidump_writer_linux/src/lib.rs @@ -0,0 +1,81 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ +extern crate minidump_writer_linux; + +use libc::pid_t; +use std::ffi::CStr; +use std::os::raw::{c_char, c_void}; + +use minidump_writer_linux::crash_context::CrashContext; +use minidump_writer_linux::minidump_writer::MinidumpWriter; + +// This function will be exposed to C++ +#[no_mangle] +pub unsafe extern "C" fn write_minidump_linux( + dump_path: *const c_char, + child: pid_t, + child_blamed_thread: pid_t, +) -> 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(_) => { + return false; + } + }; + + let mut dump_file = match std::fs::OpenOptions::new() + .create(true) // Create file if it doesn't exist + .write(true) // Truncate file + .open(path) + { + Ok(f) => f, + Err(_) => { + return false; + } + }; + + MinidumpWriter::new(child, child_blamed_thread) + .dump(&mut dump_file) + .is_ok() +} + +// This function will be exposed to C++ +#[no_mangle] +pub unsafe extern "C" fn write_minidump_linux_with_context( + dump_path: *const c_char, + child: pid_t, + context: *const c_void, +) -> bool { + assert!(!dump_path.is_null()); + let c_path = CStr::from_ptr(dump_path); + + assert!(!context.is_null()); + let cc = (&*(context as *const CrashContext)).clone(); + + let path = match c_path.to_str() { + Ok(s) => s, + Err(_) => { + return false; + } + }; + + let mut dump_file = match std::fs::OpenOptions::new() + .create(true) // Create file if it doesn't exist + .write(true) // Truncate file + .open(path) + { + Ok(f) => f, + Err(_) => { + return false; + } + }; + + MinidumpWriter::new(child, cc.tid) + .set_crash_context(cc) + .dump(&mut dump_file) + .is_ok() +} |