From: Carlos O'Donell <carlos@redhat.com>
To: Yubin Ruan <ablacktshirt@gmail.com>
Cc: Will Hawkins <whh8b@virginia.edu>,
"libc-help@sourceware.org" <libc-help@sourceware.org>
Subject: Re: determine whether code is running in a signal handler context
Date: Thu, 19 Oct 2017 04:56:00 -0000 [thread overview]
Message-ID: <d6172532-2ccf-d279-9f86-f2e379f74a08@redhat.com> (raw)
In-Reply-To: <CAJYFCiP7Z=jLWKHOuizH8p=JZg1QL-M=Vg+5Ha1kkUp4FjsbDw@mail.gmail.com>
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.
next prev parent reply other threads:[~2017-10-19 4:56 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-18 14:18 Yubin Ruan
2017-10-18 18:34 ` Carlos O'Donell
2017-10-19 1:52 ` Yubin Ruan
2017-10-19 2:19 ` Carlos O'Donell
2017-10-19 2:39 ` Will Hawkins
2017-10-19 3:12 ` Carlos O'Donell
2017-10-19 4:07 ` Yubin Ruan
2017-10-19 4:56 ` Carlos O'Donell [this message]
2017-10-19 4:19 ` Will Hawkins
2017-10-19 4:01 ` Yubin Ruan
2017-10-19 2:59 ` Sean Conner
2017-10-19 3:12 ` Sean Conner
2017-10-19 3:51 ` Yubin Ruan
2017-10-19 7:10 ` Jeffrey Walton
2017-10-20 10:32 ` Szabolcs Nagy
2017-10-20 11:23 ` Yubin Ruan
2017-10-20 11:31 ` Szabolcs Nagy
2017-10-20 17:19 ` Carlos O'Donell
2017-10-20 17:48 ` Szabolcs Nagy
2017-10-22 6:09 ` Carlos O'Donell
2017-10-22 23:39 ` where is the definition of idtype_t supposed to live? John Lumby
2017-10-23 13:57 ` Florian Weimer
[not found] ` <BN6PR22MB16662DE3DFB590B3D6006F81A3460@BN6PR22MB1666.namprd22.prod.outlook.com>
2017-10-23 14:20 ` Florian Weimer
2017-10-23 10:01 ` determine whether code is running in a signal handler context Szabolcs Nagy
2017-10-23 14:30 ` Carlos O'Donell
2017-10-24 1:00 ` Yubin Ruan
2017-11-27 8:43 ` Yubin Ruan
2017-11-27 11:55 ` Florian Weimer
2017-11-27 12:50 ` Yubin Ruan
2017-11-27 12:51 ` Florian Weimer
2017-11-27 12:58 ` Adhemerval Zanella
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d6172532-2ccf-d279-9f86-f2e379f74a08@redhat.com \
--to=carlos@redhat.com \
--cc=ablacktshirt@gmail.com \
--cc=libc-help@sourceware.org \
--cc=whh8b@virginia.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).