Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Regression test for
// https://code.google.com/p/address-sanitizer/issues/detail?id=180
// Fails with debug checks: https://bugs.llvm.org/show_bug.cgi?id=46860
// XFAIL: !compiler-rt-optimized && tsan

// FIXME: Implement.
// XFAIL: hwasan
Expand Down Expand Up @@ -31,15 +29,12 @@
#include <stdio.h>
#include <stdlib.h>

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)
if (signum == SIGSEGV)
original_sigaction = original_sigaction_sigsegv;
else {
printf("Invalid signum");
Expand All @@ -55,11 +50,6 @@ void User_OnSIGSEGV(int signum, siginfo_t *siginfo, void *context) {
exit(1);
}

int DoSEGV() {
volatile int *x = 0;
return *x;
}

bool InstallHandler(int signum, struct sigaction *original_sigaction) {
struct sigaction user_sigaction = {};
user_sigaction.sa_sigaction = User_OnSIGSEGV;
Expand All @@ -72,13 +62,15 @@ bool InstallHandler(int signum, struct sigaction *original_sigaction) {
}

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) &&
InstallHandler(SIGBUS, &original_sigaction_sigbus)) {
if (InstallHandler(SIGSEGV, &original_sigaction_sigsegv))
fprintf(stderr, "User sigaction installed\n");
}
return DoSEGV();

// Trying to organically segfault by dereferencing a pointer can be tricky
// when the sanitizer runtime is built with assertions. Additionally, some
// older platforms may SIGBUS instead.
raise(SIGSEGV);

return 0;
}

// CHECK0-NOT: Sanitizer:DEADLYSIGNAL
Expand Down