Detecting if executing in a signal handler
Adhemerval Zanella
adhemerval.zanella@linaro.org
Mon Feb 22 12:56:00 GMT 2016
On 21-02-2016 08:56, Florian Weimer wrote:
> Is there a way to check if the current function has been called
> (directly or indirectly) from a signal handler?
>
> For my purpose, this in-signal flag should be preserved across
> longjmp, siglongjmp, and fork.
>
AFAIK not in a architecture/platform independent way. For some
architectures that support vDSO and issues signal through a trampoline
helper you can try walk on the stackframe and check is the frame
is the vDSO symbol (for instance the powerpc backtrace code or this
example [1]).
Now for other architectures I do so see how because the signal handler
will just another function call. I think you can use a backtrace
trick and check the call frame to see if it is what you expect and
assume different call scenarios as a signal trigger. However I am
not sure how reliable it is.
[1] http://stackoverflow.com/questions/4832743/howto-determine-if-code-is-running-in-signal-handler-context
More information about the Libc-help
mailing list