Skip to content

feat(android): allow NDK preload for .NET/CoreCLR#1613

Open
jpnurmi wants to merge 12 commits intomasterfrom
jpnurmi/feat/android-ndk-preload
Open

feat(android): allow NDK preload for .NET/CoreCLR#1613
jpnurmi wants to merge 12 commits intomasterfrom
jpnurmi/feat/android-ndk-preload

Conversation

@jpnurmi
Copy link
Copy Markdown
Collaborator

@jpnurmi jpnurmi commented Mar 31, 2026

.NET 10.0 added support for CoreCLR on Android (experimental). Unlike with the Mono runtime, where we're stuck with CHAIN_AT_START (dotnet/runtime#125835), with CoreCLR we can already reorder the signal handlers to the preferred order:

┌───────────┐     ┌───────────────┐     ┌────────────────────┐
│ .NET/Mono │────>│ Sentry Native │────>│ System (debuggerd) │
└───────────┘     └───────────────┘     └────────────────────┘

This gives the .NET runtime a chance to process managed .NET exceptions without Sentry Native stepping on its toes. This is much safer than CHAIN_AT_START, and will be automatically enabled (io.sentry.ndk.preload=true) by Sentry.NET when targeting Android .NET 10.0 or later with CoreCLR.

Changes

Add sentry__backend_preload() for installing signal handlers before sentry_init(). For the inproc backend on Unix/Android, this allows establishing the correct signal handler chain order when another runtime (e.g. Mono/.NET) installs its own handlers later.

  • Backend dispatch: sentry__backend_preload() (no-op for non-inproc)
  • Extracted install_signal_handlers() with idempotency flag
  • Preload fallthrough: if handler thread not ready, invoke previous handler
  • NDK: SentryNdkPreloadProvider content provider with high init order for early signal handler installation before the CoreCLR runtime
  • NDK: Java/JNI preload() method on SentryNdk

See also

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 31, 2026

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

Generated by 🚫 dangerJS against 0aa6a80

@jpnurmi jpnurmi changed the title feat(android): preload NDK integration feat(android): allow NDK preload for .NET Mar 31, 2026
@jpnurmi jpnurmi force-pushed the jpnurmi/feat/android-ndk-preload branch from 8fb200b to 593a225 Compare March 31, 2026 18:22
jpnurmi and others added 7 commits March 31, 2026 21:35
Add sentry__backend_preload() for installing signal handlers before
sentry_init(). For the inproc backend on Unix/Android, this allows
establishing the correct signal handler chain order when another
runtime (e.g. Mono/.NET) installs its own handlers later.

- Backend dispatch: sentry__backend_preload() (no-op for non-inproc)
- Extracted install_signal_handlers() with idempotency flag
- Preload fallthrough: if handler thread not ready, invoke previous handler
- NDK: SentryNdkPreloadProvider ContentProvider with high initOrder
  for early signal handler installation before Mono runtime
- NDK: Java/JNI preload() method on SentryNdk

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Mono: chain-at-start (preload requires dotnet/runtime#125835)
- CoreCLR: preload (chain-at-start blocked by libsigchain)
- Auto-build the NDK AAR for preload tests
…preload

When preloaded, skip handler teardown on sentry_close() so the
runtime's handler chain remains intact for subsequent sentry_init().

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jpnurmi jpnurmi force-pushed the jpnurmi/feat/android-ndk-preload branch from 593a225 to 750c178 Compare March 31, 2026 19:35
Fixes unused variable warning on Windows.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jpnurmi jpnurmi changed the title feat(android): allow NDK preload for .NET feat(android): allow NDK preload for .NET/CoreCLR Apr 1, 2026
@jpnurmi jpnurmi marked this pull request as ready for review April 1, 2026 07:58
Prevents infinite loop when the previous handler is SIG_DFL: without
resetting, raise() re-enters sentry's handler due to SA_NODEFER.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The refactoring into install_signal_handlers() lost the error return.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

jpnurmi and others added 2 commits April 1, 2026 10:38
In practice, the process is about to die (SIG_DFL on a fatal signal),
so this state is never observed. But clear it anyway for consistency.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jpnurmi jpnurmi requested review from markushi and supervacuus April 1, 2026 10:29
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.

1 participant