Bug 223954 - unwinding the context in signal handler fails
unwinding the context in signal handler fails
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: libunwind (Show other bugs)
ia64 Linux
medium Severity high
: ---
: ---
Assigned To: Jeff Johnston
Depends On:
  Show dependency treegraph
Reported: 2007-01-23 04:12 EST by Oliver Stabel
Modified: 2007-11-30 17:07 EST (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2007-01-26 14:00:58 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)
test case (9.17 KB, text/x-csrc)
2007-01-23 04:12 EST, Oliver Stabel
no flags Details
Fix/workaround for the kernel signal frames unwinding. (572 bytes, patch)
2007-01-23 20:04 EST, Jan Kratochvil
no flags Details | Diff

  None (edit)
Description Oliver Stabel 2007-01-23 04:12:08 EST
Description of problem:
When using sigaction to set a handler for SIGSEGV (including sa_flags |=
SA_SIGINFO), the man page for sigaction states that the third parameter of the
handler is actually ucontext_t*.
"man libunwind-ia64" states, that "unw_context_t is simply an alias for
ucontext_t". I would therefore assume that it is safe to use this context in the
signal handler to unwind the stack on IA64.
However, this does not seem to be working.

Version-Release number of selected component (if applicable):

How reproducible:
compile an test case

Steps to Reproduce:
1.gcc 1.c -lunwind -ldl
Actual results:
unw_step fails with -6:

>Called with -Xtest=9999 causes me to crash, for test purposes.
>stack dump start (ucontext 0x60000fffffd4a8e0)
>unw_step failed rc = -6
>stack dump end
>Segmentation fault

Expected results:
unwinding should work within the signal handler

Additional info:
Is the context intended for this use or do I need to get a new context with

Comment 1 Oliver Stabel 2007-01-23 04:12:08 EST
Created attachment 146274 [details]
test case
Comment 2 Jakub Jelinek 2007-01-23 05:18:40 EST
This has nothing to do with glibc, the ucontext_t * passed to signal handler
is set up by the kernel and the crash is in libunwind.  Though, the fact that
signal handler is passed a pointer to the same structure as libunwind uses
doesn't mean necessarily that the kernel fills in all fields libunwind needs.
Comment 3 Oliver Stabel 2007-01-23 06:20:57 EST

ok .. I was assuming that it is glibc related as the signal includes are
supplied by glibc :)

Anyway, does that mean that unw_context_t is n not compatible with ucontext_t or
just not in the signal handler case?

From 'man unw_getcontext':
On IA-64, unw_context_t has a layout that is compatible with that of ucontext_t
and such structures can be initialized with getcontext() instead of
unw_getcontext().  However, the reverse is  not true  and  it  is not safe to
use structures initialized by unw_getcontext() in places where a structure
initialized by getcontext() is expected.

I therefore assumed that the ucontext_t* passed is safe to use for unwinding.

So what is there a preferred/official way to do unwinding in the signal handler
(like using unw_getcontext to get a context) or should the provided context in
the signal handler be usable after all?

Comment 4 Jan Kratochvil 2007-01-23 20:04:53 EST
Created attachment 146386 [details]
Fix/workaround for the kernel signal frames unwinding.

So far it looks to me more as a kernel bug and this patch is only a workaround.
Comment 5 Jan Kratochvil 2007-01-23 20:12:13 EST
For debugging you may find useful a trivia debugging fix in Bug 224097.
Comment 6 RHEL Product and Program Management 2007-01-23 20:20:36 EST
This request was evaluated by Red Hat Product Management for inclusion in a Red
Hat Enterprise Linux major release.  Product Management has requested further
review of this request by Red Hat Engineering, for potential inclusion in a Red
Hat Enterprise Linux Major release.  This request is not yet committed for
Comment 8 Jan Kratochvil 2007-01-26 14:00:58 EST
On Fri, 26 Jan 2007 16:05:50 +0100, David Mosberger-Tang wrote:

I'm afraid what Oliver is trying to do can't really work.  The ia64
linux book actually goes into a fair amount of detail on this topic,
but the quick summary is that a signal-context cannot be used to
initialize an unwind-context.  The proper way to do this is to either
create do an unw_get_context() in the signal handler or to initiate
unwinding at the inner-most frame and then do unw_step() until the
signal handler is reached (both methods are described with examples in
the book).

The reason you can't unwind directly out of a signal context is
because the kernel optimizes for speed and doesn't save any
"preserved" (callee-saved) registers in the signal context.

Mails should show up shortly on:

Referenced paper book: http://www.lia64.org/book/

Note You need to log in before you can comment on or make changes to this bug.