Skip to content

Commit 15f69be

Browse files
jpnurmiclaude
andcommitted
fix: gate signal masking to Android where Mono resets handler and re-raises
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent a804de3 commit 15f69be

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

src/backends/sentry_backend_inproc.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include <limits.h>
2626
#ifdef SENTRY_PLATFORM_UNIX
2727
# include <poll.h>
28+
#endif
29+
#ifdef SENTRY_PLATFORM_ANDROID
2830
# include <sys/syscall.h>
2931
#endif
3032
#include <string.h>
@@ -1564,17 +1566,15 @@ process_ucontext(const sentry_ucontext_t *uctx)
15641566
uintptr_t ip = get_instruction_pointer(uctx);
15651567
uintptr_t sp = get_stack_pointer(uctx);
15661568

1569+
# ifdef SENTRY_PLATFORM_ANDROID
15671570
// Mask the signal so SA_NODEFER doesn't let re-raises from the chained
15681571
// handler kill the process before we regain control.
15691572
sigset_t mask, old_mask;
15701573
sigemptyset(&mask);
15711574
sigaddset(&mask, uctx->signum);
1572-
# ifdef SENTRY_PLATFORM_ANDROID
15731575
// Raw syscall to bypass libsigchain, whose sigprocmask guard
15741576
// is only active inside its own special handlers.
15751577
syscall(SYS_rt_sigprocmask, SIG_BLOCK, &mask, &old_mask, _NSIG / 8);
1576-
# else
1577-
sigprocmask(SIG_BLOCK, &mask, &old_mask);
15781578
# endif
15791579

15801580
// invoke the previous handler (typically the CLR/Mono
@@ -1592,6 +1592,7 @@ process_ucontext(const sentry_ucontext_t *uctx)
15921592
return;
15931593
}
15941594

1595+
# ifdef SENTRY_PLATFORM_ANDROID
15951596
// restore our handler
15961597
struct sigaction current;
15971598
sigaction(uctx->signum, NULL, &current);
@@ -1604,10 +1605,7 @@ process_ucontext(const sentry_ucontext_t *uctx)
16041605
syscall(SYS_rt_sigtimedwait, &mask, NULL, &timeout, _NSIG / 8);
16051606

16061607
// unmask
1607-
# ifdef SENTRY_PLATFORM_ANDROID
16081608
syscall(SYS_rt_sigprocmask, SIG_SETMASK, &old_mask, NULL, _NSIG / 8);
1609-
# else
1610-
sigprocmask(SIG_SETMASK, &old_mask, NULL);
16111609
# endif
16121610

16131611
// return from runtime handler; continue processing the crash on the

0 commit comments

Comments
 (0)