-
Notifications
You must be signed in to change notification settings - Fork 486
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
Undefined behavior in signal handler? #297
Comments
Actually, this might be that another library, our embedded javascript engine, is causing the issue by registering a secondary signal handler and calling it when the engine doesn't have an active context. I'm a bit uncertain - but the issue almost looks like there's some kind of pingpong going on between a valid and invalid error handler:
Would it be worthwhile (or even possible considering exception handling rules) to detect when sig_handler is already in the stack and if so not do this? 😄 |
The ping pong is likely because you do have multiple signal handlers. It would be possible to modify the code to not raise on SIGABRT. Then, not calling raise recursively is much harder, if not downright impossible. The reason for calling raise btw, is so that if you have your own signal handler, you could recover. For example, consider a segfault, in a thread, and you want to catch it and do something about it. backward-cpp will print a trace, then your very own handler can recover the situation. Otherwise, SignalHandling would terminate your application without your control. With that said, again, it is mostly a default/example to get started, and you shouldn't be afraid of writing your own or subclassing it. |
Great input, thanks! I'll set up a subclass and solve it that way. 😁
Den tis 16 maj 2023 07:09François-Xavier Bourlet ***@***.***>
skrev:
… The ping pong is likely because you do have multiple signal handlers.
raise works only once I think? You can subclass and override the
behavior. Or just write your own signal handler class of course. This one
is merely a reasonable default to start with.
It would be possible to modify the code to not raise on SIGABRT. Then, not
calling raise recursively is much harder, if not downright impossible.
The reason for calling raise btw, is so that if you have your own signal
handler, you could recover.
For example, consider a segfault, in a thread, and you want to catch it
and do something about it. backward-cpp will print a trace, then your very
own handler can recover the situation.
Otherwise, SignalHandling would terminate your application without your
control. With that said, again, it is mostly a default/example to get
started, and you shouldn't be afraid of writing your own or subclassing it.
—
Reply to this email directly, view it on GitHub
<#297 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADOMSLN7F3SVHANESTWPK3XGMDY5ANCNFSM6AAAAAAYCLKIZY>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Hi @bombela and maintainers in backward-cpp!
I'm working with an issue in a bit of a complicated setup where I'm trying to handle error printing in a multithreaded app using backward-cpp. This errors triggers here:
backward-cpp/backward.hpp
Line 4298 in dc8b8c7
Specfically, it looks like this at the tip of the stack:
si_signo in this specific case is SIGSEGV, and I'm expecting the program to terminate. Instead it's infinitely recursing in a signal handler, where it looks like a segfault is occurring in __pthread_kill_internal, as a result of the exception being raised from within the exception handler. While this is SIGSEGV, I'm pretty sure the same behavior occurs with other signals.
The original exception source is a background thread:
Thread 26 "[core] bkg" received signal SIGSEGV, Segmentation fault.
The initial occurrence of SIGSEGV is correct behavior, as I am committing an access violation to trigger this behavior. The issue at hand is the infinite loop occurring after it (and I've seen it in other circumstances before.)
Looking at cppreference.com (https://en.cppreference.com/w/c/program/signal), I'm finding this quote:
If the signal handler is called as a result of [abort] or [raise], the behavior is undefined if the signal handler calls [raise].
Is it viable to remove this raise() call, or should there be some special consideration when the exception is occurring off the main thread?
The text was updated successfully, but these errors were encountered: