Enable support for FreeBSD#183
Conversation
12c9339 to
2a46b57
Compare
|
Thank you for this work, FreeBSD support in this crate together with some upstream work I'm making in Firefox would make it possible to have proper crash reporting enabled on the platform. It's worth mentioning that we're refactoring the interfaces we use to read from a process to make room from a proxy'd process reader which we need on Android. Check the changes in both the pending and already merged PRs that are called "Isolated Processes X: ...". Those changes are largely mechanical and do not affect the logic, just where some pieces live and how they're accessed. |
|
Thanks for the quick response! It's great to know this work could help. I'm currently running some bare-metal testing on FreeBSD — things are looking good so far. I'd be happy if you'd like to start reviewing this PR while I finish up the testing. I've also taken a peek at the Isolated Processes PR series (#/174–#/182). Once the testing is done and this PR is in a good state, I plan to follow up by adapting ProcessInspector for FreeBSD to align with the new architecture. One question: would you prefer I do it as a follow-up PR after this one lands, or fold it in here? I 'd prefer to keep them separate — this PR is already fairly large. Happy to go either way though. |
It's fine to make that a follow up if it makes life easier for you. |
Add FreeBSD minidump writer core modules
Add FreeBSD minidump writer streams
Add FreeBSD CI
Add FreeBSD integration tests
Hardening fixes for FreeBSD platform support
- Add explicit #[link(name = "util")] on kinfo_getvmmap FFI declaration
instead of relying solely on build.rs implicit linking
- Remove empty [target.'cfg(target_os = "freebsd")'.dependencies] from
Cargo.toml (deps inherited via cfg(unix))
- Guard __cpuid behind #[cfg(target_arch = "x86_64")] with safe fallback
for future aarch64 support
- Update FreeBSD CI matrix: drop EOL versions (12.4, 13.5, 14.2), add
14.4, keep 15.0, simplify prepare script
Move FreeBSD module_reader tests to tests/ directory
Match the Linux pattern by extracting #[cfg(test)] module from
src/freebsd/module_reader.rs into tests/freebsd_module_reader.rs,
using include_bytes!("tiny.elf") instead of an inline byte array.
CI: add freebsd_module_reader test and remove unused libc-freebsd-version
- Add cargo test --test freebsd_module_reader to FreeBSD CI
- Remove libc-freebsd-version matrix variable (no longer needed
after dropping EOL versions that required rustup)
- Add unknown-freebsd column to Client Statuses table (x86_64:⚠️ , i686: ⭕️, arm: ❌, aarch64: ⭕️) - Add FreeBSD usage example under External process section Add FreeBSD Local process documentation matching Linux pattern
c438a76 to
4a78a62
Compare
Add FreeBSD platform support Add FreeBSD process_inspection module with ProcessInspector Remove duplicated sanitize_stack_copy block in FreeBSD minidump writer Fix issues - Fix module_reader sh_offset vs sh_addr: use section_offset() for process memory reads in build_id_from_section, build_id_generate_from_text, and section_header_with_name - Fix stale thread count in get_thread_name: recompute count after second sysctl call to handle threads exiting between calls - Fix Drop double-resume: only send SIGCONT when process was stopped via SIGSTOP fallback, not after PT_DETACH (which already resumes) - Add logging for build-id fallback in mappings.rs to match Linux - Use so_name() in fill_raw_module for module names (match Linux) - Remove unused MappingInfo methods and cleanup imports Style: make FreeBSD match Linux conventions Isolated Processes: redirect all FreeBSD target-process I/O through ProcessInspector Route get_thread_list, get_thread_name, read_auxv, MappingInfo::for_pid, and handle_data_stream through ProcessInspector, matching the Linux side's architecture from Steps 2-5 of the isolated process refactoring. - Add get_thread_list/get_thread_name/read_auxv methods to ProcessInspector - Redirect all call sites, remove free functions - Change MappingInfo::for_pid signature to accept &ProcessInspector - Rewrite handle_data_stream with descriptor_from_path pattern - Simplify AuxvError variants (pid now implicit via ProcessInspector) - Update test for new ProcessInspector-based API
Consolidate read_hw_ncpu, read_hw_model, and VM mapping retrieval into ProcessInspector to centralize process inspection logic.
Replaces manual byte chunk parsing with an AuxvIter that uses the byteorder crate for endian-aware reading. Non-fatal parse errors are now collected via a soft_errors parameter rather than failing immediately.
The previous code incorrectly used PlatformId::Linux. PlatformId::Unix is the Breakpad extension intended for generic Unix-like platforms.
When reading from process memory, use p_vaddr and p_memsz instead of p_offset and p_filesz for ELF segment access. File offsets are meaningless when reading from a mapped process address space. Also relax test assertions for stack data_size when a crash context is present, as the crash thread's stack pointer from getcontext() in the parent doesn't map to the child's address space.
Use the mapping offset to correctly calculate the base address when reading build IDs and sonames, ensuring compatibility with mapped files that do not start at a zero offset.
The module_base_address, segment_offset, segment_size, and section_offset helpers contained conditional logic for process memory that was never exercised. Use the ELF header fields directly instead.
When reading build IDs and sonames from mappings with non-zero offsets, use the ELF base address instead of the mapping start address so the ELF header is found correctly.
|
Sorry for the delay over the past few weeks. I was caught up with some unexpected interviews and tests, so I didn't have time to push this PR forward. I have some free time now, so I'll review where I left off and pick this back up. |
CLOSES #162
WIP