1
0
Fork 0
mirror of https://github.com/tobast/libunwind-eh_elf.git synced 2024-11-21 23:27:39 +01:00

test-resume-sig-rt: test unw_resume() in presence of "realtime" signal 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.
This commit is contained in:
Tommi Rantala 2012-08-10 10:54:09 +03:00
parent 5738bac171
commit 5b55e556ca
5 changed files with 65 additions and 3 deletions

1
.gitignore vendored
View file

@ -36,6 +36,7 @@ tests/[GL]test-dyn1
tests/[GL]test-exc tests/[GL]test-exc
tests/[GL]test-init tests/[GL]test-init
tests/[GL]test-resume-sig tests/[GL]test-resume-sig
tests/[GL]test-resume-sig-rt
tests/[GL]perf-simple tests/[GL]perf-simple
tests/Ltest-nomalloc tests/Ltest-nomalloc
tests/Ltest-nocalloc tests/Ltest-nocalloc

View file

@ -0,0 +1,31 @@
/* libunwind - a platform-independent unwind library
Copyright (C) 2003-2004 Hewlett-Packard Co
Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
Copyright (C) 2012 Tommi Rantala <tt.rantala@gmail.com>
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"

View file

@ -31,7 +31,9 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#include <signal.h> #include <signal.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h>
#ifdef HAVE_IA64INTRIN_H #ifdef HAVE_IA64INTRIN_H
# include <ia64intrin.h> # include <ia64intrin.h>
@ -59,8 +61,15 @@ get_bsp (void)
#endif #endif
} }
#ifdef TEST_WITH_SIGINFO
void
handler (int sig,
siginfo_t *si __attribute__((unused)),
void *ucontext __attribute__((unused)))
#else
void void
handler (int sig) handler (int sig)
#endif
{ {
unw_word_t ip; unw_word_t ip;
sigset_t mask, oldmask; sigset_t mask, oldmask;
@ -88,7 +97,6 @@ handler (int sig)
kill (getpid (), SIGUSR2); /* pend SIGUSR2 */ kill (getpid (), SIGUSR2); /* pend SIGUSR2 */
signal (SIGUSR1, SIG_IGN); signal (SIGUSR1, SIG_IGN);
signal (SIGUSR2, handler);
if ((ret = unw_getcontext (&uc)) < 0) if ((ret = unw_getcontext (&uc)) < 0)
panic ("unw_getcontext() failed: ret=%d\n", ret); panic ("unw_getcontext() failed: ret=%d\n", ret);
@ -102,7 +110,7 @@ handler (int sig)
if ((ret = unw_step (&c)) < 0) /* step to signal trampoline */ if ((ret = unw_step (&c)) < 0) /* step to signal trampoline */
panic ("unw_step(1) failed: ret=%d\n", ret); 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); panic ("unw_step(2) failed: ret=%d\n", ret);
if ((ret = unw_get_reg (&c, UNW_REG_IP, &ip)) < 0) if ((ret = unw_get_reg (&c, UNW_REG_IP, &ip)) < 0)
@ -129,13 +137,27 @@ handler (int sig)
int int
main (int argc, char **argv __attribute__((unused))) main (int argc, char **argv __attribute__((unused)))
{ {
struct sigaction sa;
float d = 1.0; float d = 1.0;
int n = 0; int n = 0;
if (argc > 1) if (argc > 1)
verbose = 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 /* 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 signal handler need to use the FPU for any reason. This seems to

View file

@ -0,0 +1,5 @@
#define UNW_LOCAL_ONLY
#include <libunwind.h>
#if !defined(UNW_REMOTE_ONLY)
#include "Gtest-resume-sig-rt.c"
#endif

View file

@ -42,6 +42,7 @@ endif #ARCH_IA64
Gtest-init Ltest-init \ Gtest-init Ltest-init \
Gtest-concurrent Ltest-concurrent \ Gtest-concurrent Ltest-concurrent \
Gtest-resume-sig Ltest-resume-sig \ Gtest-resume-sig Ltest-resume-sig \
Gtest-resume-sig-rt Ltest-resume-sig-rt \
Gtest-dyn1 Ltest-dyn1 \ Gtest-dyn1 Ltest-dyn1 \
Gtest-trace Ltest-trace \ Gtest-trace Ltest-trace \
test-async-sig test-flush-cache test-init-remote \ test-async-sig test-flush-cache test-init-remote \
@ -154,6 +155,7 @@ Gtest_dyn1_LDADD = $(LIBUNWIND) $(LIBUNWIND_local)
Gtest_exc_LDADD = $(LIBUNWIND) $(LIBUNWIND_local) Gtest_exc_LDADD = $(LIBUNWIND) $(LIBUNWIND_local)
Gtest_init_LDADD = $(LIBUNWIND) $(LIBUNWIND_local) Gtest_init_LDADD = $(LIBUNWIND) $(LIBUNWIND_local)
Gtest_resume_sig_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) Gperf_simple_LDADD = $(LIBUNWIND) $(LIBUNWIND_local)
Gtest_trace_LDADD=$(LIBUNWIND) $(LIBUNWIND_local) Gtest_trace_LDADD=$(LIBUNWIND) $(LIBUNWIND_local)
Gperf_trace_LDADD = $(LIBUNWIND) $(LIBUNWIND_local) Gperf_trace_LDADD = $(LIBUNWIND) $(LIBUNWIND_local)
@ -166,6 +168,7 @@ Ltest_init_LDADD = $(LIBUNWIND_local)
Ltest_nomalloc_LDADD = $(LIBUNWIND_local) @DLLIB@ Ltest_nomalloc_LDADD = $(LIBUNWIND_local) @DLLIB@
Ltest_nocalloc_LDADD = $(LIBUNWIND_local) @DLLIB@ -lpthread Ltest_nocalloc_LDADD = $(LIBUNWIND_local) @DLLIB@ -lpthread
Ltest_resume_sig_LDADD = $(LIBUNWIND_local) Ltest_resume_sig_LDADD = $(LIBUNWIND_local)
Ltest_resume_sig_rt_LDADD = $(LIBUNWIND_local)
Lperf_simple_LDADD = $(LIBUNWIND_local) Lperf_simple_LDADD = $(LIBUNWIND_local)
Ltest_trace_LDADD = $(LIBUNWIND_local) Ltest_trace_LDADD = $(LIBUNWIND_local)
Lperf_trace_LDADD = $(LIBUNWIND_local) Lperf_trace_LDADD = $(LIBUNWIND_local)