This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Detecting if executing in a signal handler



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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]