This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: Detecting if executing in a signal handler
- From: Adhemerval Zanella <adhemerval dot zanella at linaro dot org>
- To: libc-help at sourceware dot org
- Date: Mon, 22 Feb 2016 09:56:28 -0300
- Subject: Re: Detecting if executing in a signal handler
- Authentication-results: sourceware.org; auth=none
- References: <87egc66zuw dot fsf at mid dot deneb dot enyo dot de>
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