Skip to content

csighandler3: try a fallback interpreter if none in TLS #22530

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion mg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1564,6 +1564,33 @@ Perl_csighandler3(int sig, Siginfo_t *sip PERL_UNUSED_DECL, void *uap PERL_UNUSE
dTHX;
#endif

bool can_deliver = true;
#ifdef MULTIPLICITY
/* If a C library creates a thread, signals may be delivered to
* the library thread which doesn't have the perl context set in
* TLS.
*
* So fallback to the interpreter stored during interpreter
* initialization.
*
* This isn't great, but it's better than a segfault or dropping
* the signal on the floor.
*/
if (!aTHX) {
aTHX = PERL_GET_INTERP;
/* Trying to deliver from here is not just unsafe, it's
* foolish, since we'd have two threads working with the
* same interpreter structure.
*
* The signals like SIGSEGV listed below should only be
* delivered to the current thread (I think) so we shouldn't
* get here.
*/
can_deliver = false;
assert(aTHX);
}
#endif

#ifdef PERL_USE_3ARG_SIGHANDLER
#if defined(__cplusplus) && defined(__GNUC__)
/* g++ doesn't support PERL_UNUSED_DECL, so the sip and uap
Expand Down Expand Up @@ -1598,7 +1625,7 @@ Perl_csighandler3(int sig, Siginfo_t *sip PERL_UNUSED_DECL, void *uap PERL_UNUSE
#ifdef SIGFPE
sig == SIGFPE ||
#endif
(PL_signals & PERL_SIGNALS_UNSAFE_FLAG))
((PL_signals & PERL_SIGNALS_UNSAFE_FLAG) && can_deliver))
/* Call the perl level handler now--
* with risk we may be in malloc() or being destructed etc. */
{
Expand Down