8000 Enable support for freeBSD by G36maid · Pull Request #1 · G36maid/minidump-writer · GitHub
[go: up one dir, main page]

Skip to content

Enable support for freeBSD - #1

Open
G36maid wants to merge 121 commits into
mainfrom
freebsd
Open

G36maid wants to merge 121 commits into
mainfrom
freebsd

Conversation

@G36maid
@G36maid G36maid commented May 15, 2026 •
Copy link
Copy Markdown
Owner

Implements a complete FreeBSD x86_64 platform module for minidump-writer,
enabling minidump generation for FreeBSD processes
Core components:

  • ProcessReader using PT_IO for process memory reading
  • MapsReader using kinfo_getvmmap() for VM mapping enumeration
  • ThreadInfo using PT_GETREGS/PT_GETFPREGS for register extraction
  • AuxvReader using sysctl KERN_PROC_AUXV
  • CpuInfo using sysctl hw.model/hw.ncpu
  • CrashContext with FreeBSD-native ucontext_t (no crash-context crate)
  • VmPermissions bitflags replacing procfs-core MMPermissions

Stream writers:

  • Module list, thread list, memory list, exception stream
  • System info, thread names, handle data, memory info list
  • App memory support

Infrastructure:

  • Test helper (src/bin/test.rs) with FreeBSD spawn commands
  • Integration tests (tests/freebsd_minidump_writer.rs)
  • CI job using vmactions/freebsd-vm
  • build.rs links -lutil for kinfo_getvmmap/kinfo_getfile
  • deny.toml updated with x86_64-unknown-freebsd target

36 files changed, 4089 insertions(+)

Copilot AI left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot AI left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot AI left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

G36maid added a commit that referenced this pull request May 16, 2026
…k logging, procfs test

- Use getcontext() instead of zeroed ucontext in tests (Finding rust-minidump#3)
  so register extraction is actually tested with non-zero values.
- Assert exception thread_id exists in thread list (Finding rust-minidump#2)
  to catch orphaned exception references.
- Store mapping names as OsString instead of String (Finding rust-minidump#5)
  to preserve non-UTF-8 paths until lossy conversion at write time,
  matching Linux implementation.
- Log stack copy failures instead of silently ignoring (Finding rust-minidump#4)
  with log::warn for both crash and non-crash thread paths.
- Make handle_data_stream test procfs-aware (Finding #1)
  so it doesn't silently pass when /proc/<pid>/fd is absent.
G36maid added a commit that referenced this pull request May 16, 2026
…k logging, procfs test

- Use getcontext() instead of zeroed ucontext in tests (Finding rust-minidump#3)
  so register extraction is actually tested with non-zero values.
- Assert exception thread_id exists in thread list (Finding rust-minidump#2)
  to catch orphaned exception references.
- Store mapping names as OsString instead of String (Finding rust-minidump#5)
  to preserve non-UTF-8 paths until lossy conversion at write time,
  matching Linux implementation.
- Log stack copy failures instead of silently ignoring (Finding rust-minidump#4)
  with log::warn for both crash and non-crash thread paths.
- Make handle_data_stream test procfs-aware (Finding #1)
  so it doesn't silently pass when /proc/<pid>/fd is absent.
@G36maid
G36maid force-pushed the freebsd branch 5 times, most recently from 12c9339 to 2a46b57 Compare May 16, 2026 10:07
@G36maid
G36maid force-pushed the freebsd branch 5 times, most recently from f60892f to 99ca085 Compare May 26, 2026 16:44
schopin-mozilla and others added 14 commits September 14, 2026 18:07
This data comes from a process that has potentially corrupted memory,
it's probably a good idea to validate the data as much as possible.

We also abstract LinkMap over the Iterator trait to make it easier to
reuse it later on, e.g. for module list generation.
We'll need this elsewhere as well. We also use the read_until helper
rather than rolling our own, thus avoid the arbitrary 256 char limit.
At this stage, the main effect of suspend_threads is to attach ptrace,
which we'll need when we start reading the target's memory to build the
module list.

Co-Authored-By: Simon Chopin <schopin@mozilla.com>
…DEBUG

We use the dso_debug data source, enhanced with data mined out of
module_reader to create an alternative module list source. Since the
output data format is a bit limited, each candidate spans all of the
module's segments.

The main executable needs a bit of massaging as it's sometimes unnamed
and we can't really have that, hence the pid-based fallback.

Not wired up yet.

Co-authored-by: Chris Martin <marti4d@live.ca>
Wire up a config toggle to switch to the rendezvous data source.

If the primary source fails, log the error and fall back to the
secondary source.
linux: optionally get module data from the debugger rendez-vous
While playing around with edge cases scenarii, one of them stood out:
what would happen if there was a crash *during* a dlopen() call? That's
what this patch is about.

Luckily for us, the libc folks know their stuff, and have a marker field
in the RT_DEBUG structure: `r_state`. It is present in both bionic and
glibc, with the same standard values, so we can probably assume it's
fairly standard, probably part of the SVR4 ABI – not that it's
documented anywhere besides random blog articles that lamented at the
same thing.

In any case, we can now bail early if the linker doesn't explicitly mark
its data as consistent. Note that this impacts the DSO data dump, that
will now be empty rather than filled with garbage, as well as the module
stream that'll fall back to procmaps.
…atus

linux: don't walk the rendez-vous while the linker is mid-update
In recent glibc (>= 2.42), guard pages use the MADV_GUARD_INSTALL
mechanism which isn't reflected in procmaps, so some stacks are merged
together in a single mapping, and reading that entire mapping fails due
to some pages within it being guarded.

Instead, we take another approach: we know where the stack starts, so we
just read from there up until we can't anymore, which would be our guard
page.

Fixes rust-minidump#244
More functions to be used later on, with only one small observable
effect: when get_stack_info can't find the end of the guard area, it now
errors out rather than return the last visited page, which would
inevitably trigger a failure down the road.
As it turns out, just because a page permissions tell you it's readable
doesn't actually mean it is. You can madvise() the kernel to segfault on
that page via MADV_GUARD_INSTALL, so we actually try and read stuff to
be sure that we're safe.
This should allow us a decent coverage of the various glibc quirks over
time. That would have caught the madvise thing.
…-regions

Linux: handle stack guards protected via MADV_GUARD_INSTALL
@G36maid
G36maid force-pushed the freebsd branch 5 times, most recently from 6ec5404 to 1a32551 Compare October 21, 2026 19:33
@G36maid
G36maid force-pushed the freebsd branch 2 times, most recently from bfeae55 to 30a14a9 Compare November 2, 2026 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

0