From 61cf3f3e033d2d7d13b06e0ae009ff12db787860 Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Tue, 8 Mar 2016 15:27:15 -0800 Subject: debuggerd: rethrow the full signal we receive, always. The previous code assumed that returning would be sufficient to rethrow signals like SIGSEGV. This is not true, for example, in the case where a SIGSEGV is sent via kill(2). We were previously only sending the signal to ourselves in some cases, because using kill(2) would lose information in the siginfo_t argument. Use rt_tgsigqueueinfo(2) instead to preserve its contents. Bug: http://b/27367422 Change-Id: I1be822818d5905461979c7e12dc4e9c25049273b --- tests/signal_test.cpp | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (limited to 'tests/signal_test.cpp') diff --git a/tests/signal_test.cpp b/tests/signal_test.cpp index f8fdc3f99..8c1e83469 100644 --- a/tests/signal_test.cpp +++ b/tests/signal_test.cpp @@ -14,12 +14,14 @@ * limitations under the License. */ +#include #include +#include +#include +#include #include -#include - #include "ScopedSignalHandler.h" static size_t SIGNAL_MIN() { @@ -375,3 +377,36 @@ TEST(signal, sigtimedwait_timeout) { ASSERT_EQ(0, sigprocmask(SIG_SETMASK, &original_set, NULL)); } + +#if defined(__BIONIC__) +TEST(signal, rt_tgsigqueueinfo) { + // Test whether rt_tgsigqueueinfo allows sending arbitrary si_code values to self. + // If this fails, your kernel needs commit 66dd34a to be backported. + static constexpr char error_msg[] = + "\nPlease ensure that the following kernel patch has been applied:\n" + "* https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=66dd34ad31e5963d72a700ec3f2449291d322921\n"; + static siginfo received; + + struct sigaction handler = {}; + handler.sa_sigaction = [](int, siginfo_t* siginfo, void*) { received = *siginfo; }; + handler.sa_flags = SA_SIGINFO; + + ASSERT_EQ(0, sigaction(SIGUSR1, &handler, nullptr)); + + siginfo sent = {}; + + sent.si_code = SI_TKILL; + ASSERT_EQ(0, syscall(SYS_rt_tgsigqueueinfo, getpid(), gettid(), SIGUSR1, &sent)) + << "rt_tgsigqueueinfo failed: " << strerror(errno) << error_msg; + ASSERT_EQ(sent.si_code, received.si_code) << "rt_tgsigqueueinfo modified si_code, expected " + << sent.si_code << ", received " << received.si_code + << error_msg; + + sent.si_code = SI_USER; + ASSERT_EQ(0, syscall(SYS_rt_tgsigqueueinfo, getpid(), gettid(), SIGUSR1, &sent)) + << "rt_tgsigqueueinfo failed: " << strerror(errno) << error_msg; + ASSERT_EQ(sent.si_code, received.si_code) << "rt_tgsigqueueinfo modified si_code, expected " + << sent.si_code << ", received " << received.si_code + << error_msg; +} +#endif -- cgit v1.2.3