summaryrefslogtreecommitdiffstats
path: root/toolkit/crashreporter/rust_minidump_writer_linux
diff options
context:
space:
mode:
Diffstat (limited to 'toolkit/crashreporter/rust_minidump_writer_linux')
-rw-r--r--toolkit/crashreporter/rust_minidump_writer_linux/Cargo.toml11
-rw-r--r--toolkit/crashreporter/rust_minidump_writer_linux/cbindgen.toml10
-rw-r--r--toolkit/crashreporter/rust_minidump_writer_linux/moz.build17
-rw-r--r--toolkit/crashreporter/rust_minidump_writer_linux/src/lib.rs81
4 files changed, 119 insertions, 0 deletions
diff --git a/toolkit/crashreporter/rust_minidump_writer_linux/Cargo.toml b/toolkit/crashreporter/rust_minidump_writer_linux/Cargo.toml
new file mode 100644
index 0000000000..f1c86d5433
--- /dev/null
+++ b/toolkit/crashreporter/rust_minidump_writer_linux/Cargo.toml
@@ -0,0 +1,11 @@
+[package]
+name = "rust_minidump_writer_linux"
+version = "0.1.0"
+authors = ["Martin Sirringhaus"]
+edition = "2018"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+minidump_writer_linux = "0.1.0"
+libc = "0.2.74"
diff --git a/toolkit/crashreporter/rust_minidump_writer_linux/cbindgen.toml b/toolkit/crashreporter/rust_minidump_writer_linux/cbindgen.toml
new file mode 100644
index 0000000000..215bb5620d
--- /dev/null
+++ b/toolkit/crashreporter/rust_minidump_writer_linux/cbindgen.toml
@@ -0,0 +1,10 @@
+header = """/* 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/. */"""
+autogen_warning = """/* DO NOT MODIFY THIS MANUALLY! This file was generated using cbindgen. See RunCbindgen.py */
+"""
+include_version = true
+braces = "SameLine"
+line_length = 100
+tab_width = 2
+language = "C++"
diff --git a/toolkit/crashreporter/rust_minidump_writer_linux/moz.build b/toolkit/crashreporter/rust_minidump_writer_linux/moz.build
new file mode 100644
index 0000000000..834a97de28
--- /dev/null
+++ b/toolkit/crashreporter/rust_minidump_writer_linux/moz.build
@@ -0,0 +1,17 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# 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/.
+
+if CONFIG["COMPILE_ENVIRONMENT"]:
+ # This tells mach to run cbindgen and that this header-file should be created
+ CbindgenHeader(
+ "rust_minidump_writer_linux_ffi_generated.h",
+ inputs=["/toolkit/crashreporter/rust_minidump_writer_linux"],
+ )
+
+ # This tells mach to copy that generated file to obj/dist/includes/mozilla/toolkit/crashreporter/
+ EXPORTS.mozilla.toolkit.crashreporter += [
+ "!rust_minidump_writer_linux_ffi_generated.h",
+ ]
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()
+}