From 5b55e556ca00ee02083b340d29346b9d55105233 Mon Sep 17 00:00:00 2001 From: Tommi Rantala Date: Fri, 10 Aug 2012 10:54:09 +0300 Subject: [PATCH] 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. --- .gitignore | 1 + tests/Gtest-resume-sig-rt.c | 31 +++++++++++++++++++++++++++++++ tests/Gtest-resume-sig.c | 28 +++++++++++++++++++++++++--- tests/Ltest-resume-sig-rt.c | 5 +++++ tests/Makefile.am | 3 +++ 5 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 tests/Gtest-resume-sig-rt.c create mode 100644 tests/Ltest-resume-sig-rt.c diff --git a/.gitignore b/.gitignore index eee3921a..f5fe6dca 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/tests/Gtest-resume-sig-rt.c b/tests/Gtest-resume-sig-rt.c new file mode 100644 index 00000000..df515fc1 --- /dev/null +++ b/tests/Gtest-resume-sig-rt.c @@ -0,0 +1,31 @@ +/* libunwind - a platform-independent unwind library + Copyright (C) 2003-2004 Hewlett-Packard Co + Contributed by David Mosberger-Tang + Copyright (C) 2012 Tommi Rantala + +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" diff --git a/tests/Gtest-resume-sig.c b/tests/Gtest-resume-sig.c index 4ed42e3c..57939cdb 100644 --- a/tests/Gtest-resume-sig.c +++ b/tests/Gtest-resume-sig.c @@ -31,7 +31,9 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include #include #include +#include #include +#include #ifdef HAVE_IA64INTRIN_H # include @@ -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; @@ -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); @@ -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) @@ -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 diff --git a/tests/Ltest-resume-sig-rt.c b/tests/Ltest-resume-sig-rt.c new file mode 100644 index 00000000..01fd6dc7 --- /dev/null +++ b/tests/Ltest-resume-sig-rt.c @@ -0,0 +1,5 @@ +#define UNW_LOCAL_ONLY +#include +#if !defined(UNW_REMOTE_ONLY) +#include "Gtest-resume-sig-rt.c" +#endif diff --git a/tests/Makefile.am b/tests/Makefile.am index dafd1c62..f4f6f3ed 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 \ @@ -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) @@ -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)