Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
863 changes: 459 additions & 404 deletions Cargo.lock

Large diffs are not rendered by default.

28 changes: 16 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,34 @@ authors = ["Martin Sirringhaus"]
description = "Rust rewrite of Breakpad's minidump_writer"
repository = "https://github.com/rust-minidump/minidump-writer"
homepage = "https://github.com/rust-minidump/minidump-writer"
edition = "2021"
edition = "2024"
rust-version = "1.85.0"
license = "MIT"

[dependencies]
bitflags = "2.8"
byteorder = "1.4"
bitflags = "2.10"
cfg-if = "1.0"
crash-context = "0.6"
error-graph = { version = "0.1.1", features = ["serde"] }
failspot = "0.2.0"
log = "0.4"
memoffset = "0.9"
# Type definitions and utilities for working with the Minidump format
minidump-common = "0.26"
# Reading and writing to memory. Keep aligned with version used by minidump-common and goblin
scroll = "0.12"
serde = { version = "1.0.208", features = ["derive"] }
serde_json = "1.0.116"
tempfile = "3.16"
thiserror = "2.0"

[target.'cfg(unix)'.dependencies]
libc = "0.2"
goblin = "0.9.2"
# goblin >= 0.10 uses scroll 0.13
goblin = "0.9"
memmap2 = "0.9"

[target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies]
nix = { version = "0.29", default-features = false, features = [
byteorder = "1.4"
error-graph = { version = "0.1.1", features = ["serde"] }
failspot = "0.2.0"
nix = { version = "0.30", default-features = false, features = [
"mman",
"process",
"ptrace",
Expand All @@ -40,13 +42,14 @@ nix = { version = "0.29", default-features = false, features = [
] }
# Used for parsing procfs info.
# default-features is disabled since it pulls in chrono
procfs-core = { version = "0.17", default-features = false, features = ["serde1"] }
procfs-core = { version = "0.18", default-features = false, features = ["serde1"] }

[target.'cfg(target_os = "windows")'.dependencies]
bitflags = "2.4"

[target.'cfg(target_os = "macos")'.dependencies]
# Binds some additional mac specifics not in libc
# Binds some additional mac specifics not in libc, note that other dependents
# such as wasmtime still use 0.4, so only bump if the ecosystem moves to newer versions
mach2 = "0.4"

[dev-dependencies]
Expand All @@ -58,11 +61,12 @@ failspot = { version = "0.2.0", features = ["enabled"] }
futures = { version = "0.3", features = ["executor"] }
minidump = "0.26"
memmap2 = "0.9"
tempfile = "3.16"

[target.'cfg(target_os = "macos")'.dev-dependencies]
# We dump symbols for the `test` executable so that we can validate that minidumps
# created by this crate can be processed by minidump-processor
dump_syms = { version = "2.2", default-features = false }
dump_syms = { version = "2.3", default-features = false }
#minidump-processor = { version = "0.25", default-features = false }
minidump-unwind = { version = "0.26", features = ["debuginfo"] }
similar-asserts = "1.6"
Expand Down
2 changes: 1 addition & 1 deletion examples/synthetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use {
minidump_writer::{
dir_section::DirSection,
mem_writer::{Buffer, MemoryWriter},
minidump_format::{MDRawHeader, MD_HEADER_SIGNATURE, MD_HEADER_VERSION},
minidump_format::{MD_HEADER_SIGNATURE, MD_HEADER_VERSION, MDRawHeader},
},
std::fs::File,
};
Expand Down
44 changes: 34 additions & 10 deletions src/bin/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ mod linux {
super::*,
error_graph::ErrorList,
minidump_writer::{
LINUX_GATE_LIBRARY_NAME,
minidump_writer::{MinidumpWriter, MinidumpWriterConfig},
module_reader, LINUX_GATE_LIBRARY_NAME,
module_reader,
},
nix::{
sys::mman::{mmap_anonymous, MapFlags, ProtFlags},
sys::mman::{MapFlags, ProtFlags, mmap_anonymous},
unistd::getppid,
},
};
Expand Down Expand Up @@ -339,14 +340,37 @@ mod linux {
}

fn create_files_wait(num: usize) -> Result<()> {
let mut file_array = Vec::<tempfile::NamedTempFile>::with_capacity(num);
use std::{fmt::Write, io::Read};

let mut file_array = Vec::<std::fs::File>::with_capacity(num);

let mut rand = std::fs::File::open("/dev/urandom").expect("failed to open /dev/urandom");
const CHARS: &[u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

let mut root = std::env::temp_dir();
root.push("minidump-writer");

if !root.exists() {
std::fs::create_dir_all(&root).expect("failed to create $TMP/minidump-writer dir")
}

let mut rand_indices = [0u8; 6];

for id in 0..num {
let file = tempfile::Builder::new()
.prefix("test_file")
.suffix::<str>(id.to_string().as_ref())
.tempfile()
.unwrap();
file_array.push(file);
let mut name = String::new();
name.push_str("test_file");

rand.read_exact(&mut rand_indices)
.expect("failed to read /dev/urandom");

for index in rand_indices {
name.push(CHARS[index as usize % CHARS.len()] as char);
}

write!(&mut name, "{id}").unwrap();

let path = root.join(name);
file_array.push(std::fs::File::create(&path).expect("failed to create path"));
Comment thread
gabrielesvelto marked this conversation as resolved.
println!("1");
}
println!("1");
Expand Down Expand Up @@ -420,7 +444,7 @@ mod windows {
use std::mem;

#[link(name = "kernel32")]
extern "system" {
unsafe extern "system" {
pub fn GetCurrentProcessId() -> u32;
pub fn GetCurrentThreadId() -> u32;
pub fn GetCurrentThread() -> isize;
Expand Down
20 changes: 10 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ cfg_if::cfg_if! {
if #[cfg(any(target_os = "linux", target_os = "android"))] {
mod linux;

failspot::failspot_name! {
pub enum FailSpotName {
StopProcess,
FillMissingAuxvInfo,
ThreadName,
SuspendThreads,
CpuInfoFileOpen,
}
}

pub use linux::*;
} else if #[cfg(target_os = "windows")] {
mod windows;
Expand All @@ -20,13 +30,3 @@ pub mod minidump_cpu;
pub mod minidump_format;

mod serializers;

failspot::failspot_name! {
pub enum FailSpotName {
StopProcess,
FillMissingAuxvInfo,
ThreadName,
SuspendThreads,
CpuInfoFileOpen,
}
}
4 changes: 2 additions & 2 deletions src/linux/android.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use {
super::{
maps_reader::MappingInfo, mem_reader::CopyFromProcessError,
minidump_writer::MinidumpWriter, Pid,
Pid, maps_reader::MappingInfo, mem_reader::CopyFromProcessError,
minidump_writer::MinidumpWriter,
},
goblin::elf,
};
Expand Down
2 changes: 1 addition & 1 deletion src/linux/crash_context/aarch64.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use {
super::CrashContext,
crate::{
minidump_cpu::{RawContextCPU, FP_REG_COUNT, GP_REG_COUNT},
minidump_cpu::{FP_REG_COUNT, GP_REG_COUNT, RawContextCPU},
minidump_format::format,
},
};
Expand Down
2 changes: 1 addition & 1 deletion src/linux/crash_context/x86_64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use {
super::{super::thread_info::copy_u32_registers, CrashContext},
crate::{minidump_cpu::RawContextCPU, minidump_format::format},
libc::{
REG_CSGSFS, REG_EFL, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15, REG_R8, REG_R9,
REG_CSGSFS, REG_EFL, REG_R8, REG_R9, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15,
REG_RAX, REG_RBP, REG_RBX, REG_RCX, REG_RDI, REG_RDX, REG_RIP, REG_RSI, REG_RSP,
},
scroll::Pwrite,
Expand Down
2 changes: 1 addition & 1 deletion src/linux/dso_debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use {
},
crate::{
mem_writer::{
write_string_to_location, Buffer, MemoryArrayWriter, MemoryWriter, MemoryWriterError,
Buffer, MemoryArrayWriter, MemoryWriter, MemoryWriterError, write_string_to_location,
},
minidump_format::*,
},
Expand Down
7 changes: 6 additions & 1 deletion src/linux/maps_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,12 @@ a4840000-a4873000 rw-p 09021000 08:12 393449 /data/app/org.mozilla.firefox-1
.get_mapping_effective_path_name_and_version(None)
.expect("Couldn't get effective name for mapping");
assert_eq!(file_name, "libmozgtk.so");
assert_eq!(file_path, PathBuf::from("/home/martin/Documents/mozilla/devel/mozilla-central/obj/widget/gtk/mozgtk/gtk3/libmozgtk.so"));
assert_eq!(
file_path,
PathBuf::from(
"/home/martin/Documents/mozilla/devel/mozilla-central/obj/widget/gtk/mozgtk/gtk3/libmozgtk.so"
)
);
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/linux/mem_reader.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Functionality for reading a remote process's memory

use {
super::{minidump_writer::MinidumpWriter, serializers::*, Pid},
super::{Pid, minidump_writer::MinidumpWriter, serializers::*},
std::sync::OnceLock,
};

Expand Down
2 changes: 1 addition & 1 deletion src/linux/minidump_writer/errors.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use {
super::super::{
Pid,
auxv::AuxvError,
dso_debug::SectionDsoDebugError,
maps_reader::MapsReaderError,
Expand All @@ -13,7 +14,6 @@ use {
},
module_reader::ModuleReaderError,
serializers::*,
Pid,
},
crate::{dir_section::FileWriterError, mem_writer::MemoryWriterError, serializers::*},
error_graph::ErrorList,
Expand Down
6 changes: 1 addition & 5 deletions src/linux/minidump_writer/handle_data_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ fn file_stat(path: &Path) -> Option<libc::stat> {
let mut stat = unsafe { std::mem::zeroed::<libc::stat>() };
let result = unsafe { libc::stat(c_path.as_ptr(), &mut stat) };

if result == 0 {
Some(stat)
} else {
None
}
if result == 0 { Some(stat) } else { None }
}

fn direntry_to_descriptor(buffer: &mut DumpBuf, entry: &DirEntry) -> Option<MDRawHandleDescriptor> {
Expand Down
2 changes: 1 addition & 1 deletion src/linux/minidump_writer/memory_info_list_stream.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use {
super::*,
minidump_common::format::{MemoryProtection, MemoryState, MemoryType},
procfs_core::{process::MMPermissions, FromRead},
procfs_core::{FromRead, process::MMPermissions},
};

#[derive(Debug, Error, serde::Serialize)]
Expand Down
6 changes: 3 additions & 3 deletions src/linux/minidump_writer/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use {
super::{
Pid,
app_memory::AppMemoryList,
auxv::AuxvDumpInfo,
crash_context::CrashContext,
Expand All @@ -10,12 +11,11 @@ use {
module_reader,
serializers::*,
thread_info::{ThreadInfo, ThreadInfoError},
Pid,
},
crate::{
dir_section::{DirSection, DumpBuf},
mem_writer::{
write_string_to_location, Buffer, MemoryArrayWriter, MemoryWriter, MemoryWriterError,
Buffer, MemoryArrayWriter, MemoryWriter, MemoryWriterError, write_string_to_location,
},
minidump_format::*,
serializers::*,
Expand All @@ -28,8 +28,8 @@ use {
sys::{ptrace, signal, wait},
},
procfs_core::{
process::{MMPermissions, ProcState, Stat},
FromRead,
process::{MMPermissions, ProcState, Stat},
},
std::{
io::{Seek, Write},
Expand Down
Loading
Loading