Skip to content

Commit

Permalink
test-resume-sig-rt: test unw_resume() in presence of "realtime" signa…
Browse files Browse the repository at this point in the history
…l frame

Introduce a new test case that is derived from test-resume-sig, but
using the SA_SIGINFO sigaction() flag. This case is referred in the
linux kernel sources as "realtime" signal handler, and is handled
differently in the kernel on many architectures and in libunwind as
well.
  • Loading branch information
rantala committed Aug 21, 2012
1 parent 5738bac commit 5b55e55
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ tests/[GL]test-dyn1
tests/[GL]test-exc
tests/[GL]test-init
tests/[GL]test-resume-sig
tests/[GL]test-resume-sig-rt
tests/[GL]perf-simple
tests/Ltest-nomalloc
tests/Ltest-nocalloc
Expand Down
31 changes: 31 additions & 0 deletions tests/Gtest-resume-sig-rt.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* libunwind - a platform-independent unwind library
Copyright (C) 2003-2004 Hewlett-Packard Co
Contributed by David Mosberger-Tang <[email protected]>
Copyright (C) 2012 Tommi Rantala <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */

/* The purpose of this test is to invoke different code paths in libunwind (on
* some architectures), that are executed when the SA_SIGINFO sigaction() flag
* is used.
*/

#define TEST_WITH_SIGINFO 1
#include "Gtest-resume-sig.c"
28 changes: 25 additions & 3 deletions tests/Gtest-resume-sig.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>

#ifdef HAVE_IA64INTRIN_H
# include <ia64intrin.h>
Expand Down Expand Up @@ -59,8 +61,15 @@ get_bsp (void)
#endif
}

#ifdef TEST_WITH_SIGINFO
void
handler (int sig,
siginfo_t *si __attribute__((unused)),
void *ucontext __attribute__((unused)))
#else
void
handler (int sig)
#endif
{
unw_word_t ip;
sigset_t mask, oldmask;
Expand Down Expand Up @@ -88,7 +97,6 @@ handler (int sig)
kill (getpid (), SIGUSR2); /* pend SIGUSR2 */

signal (SIGUSR1, SIG_IGN);
signal (SIGUSR2, handler);

if ((ret = unw_getcontext (&uc)) < 0)
panic ("unw_getcontext() failed: ret=%d\n", ret);
Expand All @@ -102,7 +110,7 @@ handler (int sig)
if ((ret = unw_step (&c)) < 0) /* step to signal trampoline */
panic ("unw_step(1) failed: ret=%d\n", ret);

if ((ret = unw_step (&c)) < 0) /* step to signal trampoline */
if ((ret = unw_step (&c)) < 0) /* step to kill() */
panic ("unw_step(2) failed: ret=%d\n", ret);

if ((ret = unw_get_reg (&c, UNW_REG_IP, &ip)) < 0)
Expand All @@ -129,13 +137,27 @@ handler (int sig)
int
main (int argc, char **argv __attribute__((unused)))
{
struct sigaction sa;
float d = 1.0;
int n = 0;

if (argc > 1)
verbose = 1;

signal (SIGUSR1, handler);
memset (&sa, 0, sizeof(sa));
#ifdef TEST_WITH_SIGINFO
sa.sa_sigaction = handler;
sa.sa_flags = SA_SIGINFO;
#else
sa.sa_handler = handler;
#endif

if (sigaction (SIGUSR1, &sa, NULL) != 0 ||
sigaction (SIGUSR2, &sa, NULL) != 0)
{
fprintf (stderr, "sigaction() failed: %s\n", strerror (errno));
return -1;
}

/* Use the FPU a bit; otherwise we get spurious errors should the
signal handler need to use the FPU for any reason. This seems to
Expand Down
5 changes: 5 additions & 0 deletions tests/Ltest-resume-sig-rt.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#define UNW_LOCAL_ONLY
#include <libunwind.h>
#if !defined(UNW_REMOTE_ONLY)
#include "Gtest-resume-sig-rt.c"
#endif
3 changes: 3 additions & 0 deletions tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ endif #ARCH_IA64
Gtest-init Ltest-init \
Gtest-concurrent Ltest-concurrent \
Gtest-resume-sig Ltest-resume-sig \
Gtest-resume-sig-rt Ltest-resume-sig-rt \
Gtest-dyn1 Ltest-dyn1 \
Gtest-trace Ltest-trace \
test-async-sig test-flush-cache test-init-remote \
Expand Down Expand Up @@ -154,6 +155,7 @@ Gtest_dyn1_LDADD = $(LIBUNWIND) $(LIBUNWIND_local)
Gtest_exc_LDADD = $(LIBUNWIND) $(LIBUNWIND_local)
Gtest_init_LDADD = $(LIBUNWIND) $(LIBUNWIND_local)
Gtest_resume_sig_LDADD = $(LIBUNWIND) $(LIBUNWIND_local)
Gtest_resume_sig_rt_LDADD = $(LIBUNWIND) $(LIBUNWIND_local)
Gperf_simple_LDADD = $(LIBUNWIND) $(LIBUNWIND_local)
Gtest_trace_LDADD=$(LIBUNWIND) $(LIBUNWIND_local)
Gperf_trace_LDADD = $(LIBUNWIND) $(LIBUNWIND_local)
Expand All @@ -166,6 +168,7 @@ Ltest_init_LDADD = $(LIBUNWIND_local)
Ltest_nomalloc_LDADD = $(LIBUNWIND_local) @DLLIB@
Ltest_nocalloc_LDADD = $(LIBUNWIND_local) @DLLIB@ -lpthread
Ltest_resume_sig_LDADD = $(LIBUNWIND_local)
Ltest_resume_sig_rt_LDADD = $(LIBUNWIND_local)
Lperf_simple_LDADD = $(LIBUNWIND_local)
Ltest_trace_LDADD = $(LIBUNWIND_local)
Lperf_trace_LDADD = $(LIBUNWIND_local)
Expand Down

0 comments on commit 5b55e55

Please sign in to comment.