Skip to content

feat(native): support preloading the crash handler - #2268

Merged
jpnurmi merged 5 commits into
v1from
jpnurmi/feat/native-preload
Oct 29, 2026
Merged

jpnurmi merged 5 commits into
v1from
jpnurmi/feat/native-preload

Conversation

@jpnurmi

@jpnurmi jpnurmi commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

sentry__backend_preload() was a no-op for the native backend. Install its signal handlers early, so that they keep their place in the signal chain ahead of a managed runtime, and let a later sentry_init() adopt them. Like with inproc, shutdown keeps the preloaded handlers installed, forwarding crashes to the previous handlers until the next initialization.

#skip-changelog (extracted from #1725)

The minidump writer and `capture_modules_from_proc_maps()` grouped
`/proc/<pid>/maps` entries by file name and expected an ELF header at
offset 0. An ELF image can also start inside a larger file, such as an
uncompressed library that Android maps straight from an APK, and such
images were dropped from the module list.

Start a module at each mapping whose file offset holds an ELF header,
group the image's other segments by its load range, and read the build
ID, size, and SONAME at that offset. Move
`compute_elf_size_from_phdrs()` to `sentry_elf.h` to share it.

This prepares the native backend for Android, where AGP's default
packaging maps every app library from the APK.

Ref: #1725
The previous commit adjusted the section header offset in
`elf_locate_symtab()` instead of `extract_elf_build_id_for_module()`,
where `elf_offset` is not declared, so the crash daemon failed to
compile. Move the adjustment to where the build ID is read.
The `offset > start` guard in `capture_modules_from_proc_maps()` dropped
mappings before an ELF image inside a larger file could be detected.
The guard only protects the `start - offset` load base of a regular ELF
file, so apply it there instead.
The crash daemon could only unwind the threads that did not crash with
`libunwind_remote`, which Android builds lack because they use
libunwindstack. Add a `libunwindstack_remote` backend, compiled in only
with the native backend, that attaches to a thread with ptrace, reads
its registers with `Regs::RemoteGet()`, and unwinds it. Share the
ptrace attach loop with `libunwind_remote`.

This prepares the native backend for Android.
`sentry__backend_preload()` was a no-op for the native backend. Install
its signal handlers early, so that they keep their place in the signal
chain ahead of a managed runtime, and let a later `sentry_init()` adopt
them. Like with `inproc`, shutdown keeps the preloaded handlers
installed, forwarding crashes to the previous handlers until the next
initialization.
@jpnurmi jpnurmi added the v1 Targets 1.0 (v1 branch) label Oct 28, 2026
@github-actions

Copy link
Copy Markdown
Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against bb0341b

Base automatically changed from jpnurmi/feat/libunwindstack-remote to v1 October 29, 2026 11:22
@jpnurmi
jpnurmi merged commit f815b40 into v1 Oct 29, 2026
105 of 107 checks passed
@jpnurmi
jpnurmi deleted the jpnurmi/feat/native-preload branch October 29, 2026 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v1 Targets 1.0 (v1 branch)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants