From fe4e7c17165dd0ebd80a78023598d442911f0495 Mon Sep 17 00:00:00 2001 From: Kuba Brecka Date: Wed, 5 Nov 2014 18:58:41 +0000 Subject: [PATCH] Fix failing allow_user_segv.cc test on OS X 10.10 The current ASan testcase Posix/allow_user_segv.cc expects SIGBUS to be triggered on 32-bit Darwin. This has apparently changed on 10.10 to trigger SIGSEGV instead, just as on 64-bit. Let's just install handlers for both SIGSEGV and SIGBUS instead of #ifdef'ing. Reviewed at http://reviews.llvm.org/D6121 llvm-svn: 221381 --- .../test/asan/TestCases/Posix/allow_user_segv.cc | 35 ++++++++++++++-------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/compiler-rt/test/asan/TestCases/Posix/allow_user_segv.cc b/compiler-rt/test/asan/TestCases/Posix/allow_user_segv.cc index 1768643..b6443fa 100644 --- a/compiler-rt/test/asan/TestCases/Posix/allow_user_segv.cc +++ b/compiler-rt/test/asan/TestCases/Posix/allow_user_segv.cc @@ -6,12 +6,22 @@ #include #include +#include -struct sigaction user_sigaction; -struct sigaction original_sigaction; +struct sigaction original_sigaction_sigbus; +struct sigaction original_sigaction_sigsegv; void User_OnSIGSEGV(int signum, siginfo_t *siginfo, void *context) { fprintf(stderr, "User sigaction called\n"); + struct sigaction original_sigaction; + if (signum == SIGBUS) + original_sigaction = original_sigaction_sigbus; + else if (signum == SIGSEGV) + original_sigaction = original_sigaction_sigsegv; + else { + printf("Invalid signum"); + exit(1); + } if (original_sigaction.sa_flags | SA_SIGINFO) original_sigaction.sa_sigaction(signum, siginfo, context); else @@ -23,21 +33,22 @@ int DoSEGV() { return *x; } -int main() { +int InstallHandler(int signum, struct sigaction *original_sigaction) { + struct sigaction user_sigaction; user_sigaction.sa_sigaction = User_OnSIGSEGV; user_sigaction.sa_flags = SA_SIGINFO; -#if defined(__APPLE__) && !defined(__LP64__) - // On 32-bit Darwin KERN_PROTECTION_FAILURE (SIGBUS) is delivered. - int signum = SIGBUS; -#else - // On 64-bit Darwin KERN_INVALID_ADDRESS (SIGSEGV) is delivered. - // On Linux SIGSEGV is delivered as well. - int signum = SIGSEGV; -#endif - if (sigaction(signum, &user_sigaction, &original_sigaction)) { + if (sigaction(signum, &user_sigaction, original_sigaction)) { perror("sigaction"); return 1; } + return 0; +} + +int main() { + // Let's install handlers for both SIGSEGV and SIGBUS, since pre-Yosemite + // 32-bit Darwin triggers SIGBUS instead. + if (InstallHandler(SIGSEGV, &original_sigaction_sigsegv)) return 1; + if (InstallHandler(SIGBUS, &original_sigaction_sigbus)) return 1; fprintf(stderr, "User sigaction installed\n"); return DoSEGV(); } -- 2.7.4