Fix the setjmp tests for mips.

Although the LP32 mips sigset_t is large enough to represent all signals,
their jmp_buf is too small. This test succeeded on arm and x86 because the
RT signals were never in the 'expected' sigset_t, so the equality comparison
with the 'actual' sigset_t worked fine --- everyone was blind to the RT
signal. On mips the tests fail because the 'expected' sigset_t does contain
the RT signal but the 'actual' doesn't because the jmp_buf only saves and
restores the first 32 signals.

There are 32 free bits (currently used as padding) in the LP32 mips jmp_buf,
and they might choose to use those to provide better support than the other
two platforms, but I'll leave that to them. It will be easy to just remove
the #if defined(__LP64__) from this change in that case.

For mips64 it's not to late to increase the size of the jmp_buf and fix
the setjmp family, but since there are decisions to be made here for LP32,
I'll leave it all to Imagination folks...

Bug: 16918359
Change-Id: I6b723712fce0e9210dafa165d8599d950b2d3500
This commit is contained in:
Elliott Hughes 2014-12-10 09:31:04 -08:00
parent 6a6845244c
commit 1510a1c1ae

View File

@ -63,15 +63,27 @@ TEST(setjmp, sigsetjmp_1_smoke) {
}
}
static sigset_t SigSetOf(int signal, int rt_signal = 0) {
sigset_t ss;
sigemptyset(&ss);
sigaddset(&ss, signal);
if (rt_signal != 0) {
sigaddset(&ss, rt_signal);
// Two distinct signal sets, pipu
struct SigSets {
SigSets() : one(MakeSigSet(0)), two(MakeSigSet(1)) {
}
return ss;
}
static sigset_t MakeSigSet(int offset) {
sigset_t ss;
sigemptyset(&ss);
sigaddset(&ss, SIGUSR1 + offset);
#if defined(__LP64__)
// For arm and x86, sigset_t was too small for the RT signals.
// For mips, sigset_t was large enough but jmp_buf wasn't.
sigaddset(&ss, SIGRTMIN + offset);
#endif
return ss;
}
sigset_t one;
sigset_t two;
sigset_t original;
};
void AssertSigmaskEquals(const sigset_t& expected) {
sigset_t actual;
@ -84,76 +96,68 @@ void AssertSigmaskEquals(const sigset_t& expected) {
TEST(setjmp, _setjmp_signal_mask) {
// _setjmp/_longjmp do not save/restore the signal mask.
sigset_t ss1(SigSetOf(SIGUSR1, SIGRTMIN + 8));
sigset_t ss2(SigSetOf(SIGUSR2, SIGRTMIN + 9));
sigset_t original_set;
sigprocmask(SIG_SETMASK, &ss1, &original_set);
SigSets ss;
sigprocmask(SIG_SETMASK, &ss.one, &ss.original);
jmp_buf jb;
if (_setjmp(jb) == 0) {
sigprocmask(SIG_SETMASK, &ss2, NULL);
sigprocmask(SIG_SETMASK, &ss.two, NULL);
_longjmp(jb, 1);
FAIL(); // Unreachable.
} else {
AssertSigmaskEquals(ss2);
AssertSigmaskEquals(ss.two);
}
sigprocmask(SIG_SETMASK, &original_set, NULL);
sigprocmask(SIG_SETMASK, &ss.original, NULL);
}
TEST(setjmp, setjmp_signal_mask) {
// setjmp/longjmp do save/restore the signal mask on bionic, but not on glibc.
// This is a BSD versus System V historical accident. POSIX leaves the
// behavior unspecified, so any code that cares needs to use sigsetjmp.
sigset_t ss1(SigSetOf(SIGUSR1, SIGRTMIN + 8));
sigset_t ss2(SigSetOf(SIGUSR2, SIGRTMIN + 9));
sigset_t original_set;
sigprocmask(SIG_SETMASK, &ss1, &original_set);
SigSets ss;
sigprocmask(SIG_SETMASK, &ss.one, &ss.original);
jmp_buf jb;
if (setjmp(jb) == 0) {
sigprocmask(SIG_SETMASK, &ss2, NULL);
sigprocmask(SIG_SETMASK, &ss.two, NULL);
longjmp(jb, 1);
FAIL(); // Unreachable.
} else {
#if defined(__BIONIC__)
// bionic behaves like BSD and does save/restore the signal mask.
AssertSigmaskEquals(ss1);
AssertSigmaskEquals(ss.one);
#else
// glibc behaves like System V and doesn't save/restore the signal mask.
AssertSigmaskEquals(ss2);
AssertSigmaskEquals(ss.two);
#endif
}
sigprocmask(SIG_SETMASK, &original_set, NULL);
sigprocmask(SIG_SETMASK, &ss.original, NULL);
}
TEST(setjmp, sigsetjmp_0_signal_mask) {
// sigsetjmp(0)/siglongjmp do not save/restore the signal mask.
sigset_t ss1(SigSetOf(SIGUSR1, SIGRTMIN + 8));
sigset_t ss2(SigSetOf(SIGUSR2, SIGRTMIN + 9));
sigset_t original_set;
sigprocmask(SIG_SETMASK, &ss1, &original_set);
SigSets ss;
sigprocmask(SIG_SETMASK, &ss.one, &ss.original);
sigjmp_buf sjb;
if (sigsetjmp(sjb, 0) == 0) {
sigprocmask(SIG_SETMASK, &ss2, NULL);
sigprocmask(SIG_SETMASK, &ss.two, NULL);
siglongjmp(sjb, 1);
FAIL(); // Unreachable.
} else {
AssertSigmaskEquals(ss2);
AssertSigmaskEquals(ss.two);
}
sigprocmask(SIG_SETMASK, &original_set, NULL);
sigprocmask(SIG_SETMASK, &ss.original, NULL);
}
TEST(setjmp, sigsetjmp_1_signal_mask) {
// sigsetjmp(1)/siglongjmp does save/restore the signal mask.
sigset_t ss1(SigSetOf(SIGUSR1, SIGRTMIN + 8));
sigset_t ss2(SigSetOf(SIGUSR2, SIGRTMIN + 9));
sigset_t original_set;
sigprocmask(SIG_SETMASK, &ss1, &original_set);
SigSets ss;
sigprocmask(SIG_SETMASK, &ss.one, &ss.original);
sigjmp_buf sjb;
if (sigsetjmp(sjb, 1) == 0) {
sigprocmask(SIG_SETMASK, &ss2, NULL);
sigprocmask(SIG_SETMASK, &ss.two, NULL);
siglongjmp(sjb, 1);
FAIL(); // Unreachable.
} else {
AssertSigmaskEquals(ss1);
AssertSigmaskEquals(ss.one);
}
sigprocmask(SIG_SETMASK, &original_set, NULL);
sigprocmask(SIG_SETMASK, &ss.original, NULL);
}