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: determine whether code is running in a signal handler context


On 10/18/2017 09:07 PM, Yubin Ruan wrote:
> By "auxiliary information", do you mean those auxiliary information
> provided by the kernel (to the dynamic loader), e.g., environment
> variables, or what? It seems to me that if we have the frame pointers,
> it would be a lot easier. And it would be better if we limit our code
> to X86/64.

No, by 'auxiliary information' I mean .eh_frame/.debug_frame, the information
that tells you where the current frame's data is located (on stack or in
registers), so you can, from your current IP, find enough data to attempt
a frame unwind.

> Yes. I should have emphasized that I need only detect that the code is
> *in* a signal handler, and that is all I want. So if anyone can
> provide more info/heuristic about that (just about that) I will be
> very thankful.

You have to do architecture specific things, which I don't have immediately
off the top of my head.

gdb has a architecture-specific signal call recognizer:

gdb/gdb/i386-linux-tdep.c:
  71 /* Recognizing signal handler frames.  */
  72 
  73 /* GNU/Linux has two flavors of signals.  Normal signal handlers, and
  74    "realtime" (RT) signals.  The RT signals can provide additional
  75    information to the signal handler if the SA_SIGINFO flag is set
  76    when establishing a signal handler using `sigaction'.  It is not
  77    unlikely that future versions of GNU/Linux will support SA_SIGINFO
  78    for normal signals too.  */
...

gdb/gdb/aarch64-linux-tdep.c:
  49 /* Signal frame handling.
  50 
  51       +------------+  ^
  52       | saved lr   |  |
  53    +->| saved fp   |--+
  54    |  |            |
  55    |  |            |
  56    |  +------------+
  57    |  | saved lr   |
  58    +--| saved fp   |
  59    ^  |            |
  60    |  |            |
  61    |  +------------+
  62    ^  |            |
  63    |  | signal     |
  64    |  |            |        SIGTRAMP_FRAME (struct rt_sigframe)
  65    |  | saved regs |
  66    +--| saved sp   |--> interrupted_sp
  67    |  | saved pc   |--> interrupted_pc
  68    |  |            |
  69    |  +------------+
  70    |  | saved lr   |--> default_restorer (movz x8, NR_sys_rt_sigreturn; svc 0)
  71    +--| saved fp   |<- FP
  72       |            |         NORMAL_FRAME
  73       |            |<- SP
  74       +------------+
  75 
  76   On signal delivery, the kernel will create a signal handler stack
  77   frame and setup the return address in LR to point at restorer stub.
  78   The signal stack frame is defined by:
....

And so on and so forth...

-- 
Cheers,
Carlos.


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