aboutsummaryrefslogtreecommitdiff
path: root/test/asan
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-05-29 16:25:57 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-05-29 16:25:57 +0000
commit224c1c721b03784d0da2af00884ea8d4eb7a1650 (patch)
treeac9e50e358e85ab37022d6fdafaa0c8dbb4adad2 /test/asan
parent99ea5e489fa5765bf0eb50ca4261ab5cc20abeeb (diff)
downloadsrc-224c1c721b03784d0da2af00884ea8d4eb7a1650.tar.gz
src-224c1c721b03784d0da2af00884ea8d4eb7a1650.zip
Notes
Notes: svn path=/vendor/compiler-rt/dist/; revision=319144 svn path=/vendor/compiler-rt/compiler-rt-trunk-r304222/; revision=319235; tag=vendor/compiler-rt/compiler-rt-trunk-r304222
Diffstat (limited to 'test/asan')
-rw-r--r--test/asan/TestCases/Linux/preinstalled_signal.cc105
-rw-r--r--test/asan/TestCases/Linux/sanbox_read_proc_self_maps_test.cc8
-rw-r--r--test/asan/TestCases/Posix/allow_user_segv.cc53
-rw-r--r--test/asan/TestCases/Posix/current_allocated_bytes.cc3
-rw-r--r--test/asan/TestCases/Posix/wait.cc1
-rw-r--r--test/asan/TestCases/Posix/wait3.cc2
-rw-r--r--test/asan/TestCases/Posix/wait4.cc1
-rw-r--r--test/asan/TestCases/Posix/waitid.cc2
8 files changed, 150 insertions, 25 deletions
diff --git a/test/asan/TestCases/Linux/preinstalled_signal.cc b/test/asan/TestCases/Linux/preinstalled_signal.cc
new file mode 100644
index 000000000000..40dadf43dc4e
--- /dev/null
+++ b/test/asan/TestCases/Linux/preinstalled_signal.cc
@@ -0,0 +1,105 @@
+// clang-format off
+// RUN: %clangxx -std=c++11 %s -o %t
+// RUN: env LD_PRELOAD=%shared_libasan %env_asan_opts=handle_segv=1 not %run %t 2>&1 | FileCheck %s
+// RUN: env LD_PRELOAD=%shared_libasan %env_asan_opts=handle_segv=2 not %run %t 2>&1 | FileCheck %s
+
+// RUN: %clangxx -std=c++11 -DTEST_INSTALL_SIG_HANDLER %s -o %t
+// RUN: env LD_PRELOAD=%shared_libasan %env_asan_opts=handle_segv=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-HANDLER %s
+// RUN: env LD_PRELOAD=%shared_libasan %env_asan_opts=handle_segv=2 not %run %t 2>&1 | FileCheck %s
+
+// RUN: %clangxx -std=c++11 -DTEST_INSTALL_SIG_ACTION %s -o %t
+// RUN: env LD_PRELOAD=%shared_libasan %env_asan_opts=handle_segv=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ACTION %s
+// RUN: env LD_PRELOAD=%shared_libasan %env_asan_opts=handle_segv=2 not %run %t 2>&1 | FileCheck %s
+
+// REQUIRES: asan-dynamic-runtime
+
+// This way of setting LD_PRELOAD does not work with Android test runner.
+// REQUIRES: not-android
+// clang-format on
+
+#include <assert.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+
+const char *handler = nullptr;
+void SigHandler(int signum) { handler = "TestSigHandler"; }
+void SigAction(int, siginfo_t *, void *) { handler = "TestSigAction"; }
+
+struct KernelSigaction {
+ __sighandler_t handler;
+ unsigned long flags;
+ void (*restorer)();
+ char unused[1024];
+};
+
+#if defined(__x86_64__)
+extern "C" void restorer();
+asm("restorer:mov $15,%rax\nsyscall");
+#endif
+
+int InternalSigaction(int sig, KernelSigaction *act, KernelSigaction *oact) {
+ if (act) {
+#if defined(__x86_64__)
+ act->flags |= 0x04000000;
+ act->restorer = &restorer;
+#endif
+ }
+ return syscall(__NR_rt_sigaction, sig, act, oact, NSIG / 8);
+}
+
+struct KernelSigaction sigact = {};
+
+static void Init() {
+ int res = InternalSigaction(SIGSEGV, nullptr, &sigact);
+ assert(res >= 0);
+ assert(sigact.handler == SIG_DFL || sigact.handler == SIG_IGN);
+#if defined(TEST_INSTALL_SIG_HANDLER)
+ sigact = {};
+ sigact.handler = &SigHandler;
+ res = InternalSigaction(SIGSEGV, &sigact, nullptr);
+ assert(res >= 0);
+#elif defined(TEST_INSTALL_SIG_ACTION)
+ sigact = {};
+ sigact.flags = SA_SIGINFO | SA_NODEFER;
+ sigact.handler = (__sighandler_t)&SigAction;
+ res = InternalSigaction(SIGSEGV, &sigact, nullptr);
+ assert(res >= 0);
+#endif
+}
+
+__attribute__((section(".preinit_array"), used))
+void (*__local_test_preinit)(void) = Init;
+
+bool ShouldAsanInstallHandlers() {
+#if defined(TEST_INSTALL_SIG_HANDLER) || defined(TEST_INSTALL_SIG_ACTION)
+ return !strcmp(getenv("ASAN_OPTIONS"), "handle_segv=2");
+#endif
+ return true;
+}
+
+int main(int argc, char *argv[]) {
+ KernelSigaction sigact_asan = {};
+ InternalSigaction(SIGSEGV, nullptr, &sigact_asan);
+
+ assert(sigact_asan.handler != SIG_DFL);
+ assert(sigact_asan.handler != SIG_IGN);
+ assert(ShouldAsanInstallHandlers() ==
+ (sigact_asan.handler != sigact.handler));
+
+ raise(SIGSEGV);
+ printf("%s\n", handler);
+ return 1;
+}
+
+// CHECK-NOT: TestSig
+// CHECK: ASAN:DEADLYSIGNAL
+
+// CHECK-HANDLER-NOT: ASAN:DEADLYSIGNAL
+// CHECK-HANDLER: TestSigHandler
+
+// CHECK-ACTION-NOT: ASAN:DEADLYSIGNAL
+// CHECK-ACTION: TestSigAction
diff --git a/test/asan/TestCases/Linux/sanbox_read_proc_self_maps_test.cc b/test/asan/TestCases/Linux/sanbox_read_proc_self_maps_test.cc
index a845721d5982..d9099edffcac 100644
--- a/test/asan/TestCases/Linux/sanbox_read_proc_self_maps_test.cc
+++ b/test/asan/TestCases/Linux/sanbox_read_proc_self_maps_test.cc
@@ -14,17 +14,15 @@ int main() {
if (unshare(CLONE_NEWUSER)) {
printf("unshare failed\n");
- abort();
+ return 1;
}
// remove access to /proc/self/maps
if (chroot("/tmp")) {
printf("chroot failed\n");
- abort();
+ return 2;
}
*(volatile int*)0x42 = 0;
-// CHECK: AddressSanitizer: SEGV on unknown address 0x000000000042
-// CHECK-NOT: AddressSanitizer CHECK failed
-// CHECK: SUMMARY: AddressSanitizer: SEGV
+// CHECK-NOT: CHECK failed
}
diff --git a/test/asan/TestCases/Posix/allow_user_segv.cc b/test/asan/TestCases/Posix/allow_user_segv.cc
index 69c1df9a1d3f..52f4f046da9d 100644
--- a/test/asan/TestCases/Posix/allow_user_segv.cc
+++ b/test/asan/TestCases/Posix/allow_user_segv.cc
@@ -1,8 +1,14 @@
// Regression test for
// https://code.google.com/p/address-sanitizer/issues/detail?id=180
-// RUN: %clangxx_asan -O0 %s -o %t && %env_asan_opts=allow_user_segv_handler=true not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx_asan -O2 %s -o %t && %env_asan_opts=allow_user_segv_handler=true not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O0 %s -o %t && %env_asan_opts=handle_segv=0 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK0
+// RUN: %clangxx_asan -O2 %s -o %t && %env_asan_opts=handle_segv=0 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK0
+
+// RUN: %clangxx_asan -O0 %s -o %t && %env_asan_opts=handle_segv=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1
+// RUN: %clangxx_asan -O2 %s -o %t && %env_asan_opts=handle_segv=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1
+
+// RUN: %clangxx_asan -O0 %s -o %t && %env_asan_opts=handle_segv=2 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK2
+// RUN: %clangxx_asan -O2 %s -o %t && %env_asan_opts=handle_segv=2 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK2
#include <signal.h>
#include <stdio.h>
@@ -22,10 +28,14 @@ void User_OnSIGSEGV(int signum, siginfo_t *siginfo, void *context) {
printf("Invalid signum");
exit(1);
}
- if (original_sigaction.sa_flags | SA_SIGINFO)
- original_sigaction.sa_sigaction(signum, siginfo, context);
- else
- original_sigaction.sa_handler(signum);
+ if (original_sigaction.sa_flags | SA_SIGINFO) {
+ if (original_sigaction.sa_sigaction)
+ original_sigaction.sa_sigaction(signum, siginfo, context);
+ } else {
+ if (original_sigaction.sa_handler)
+ original_sigaction.sa_handler(signum);
+ }
+ exit(1);
}
int DoSEGV() {
@@ -33,27 +43,38 @@ int DoSEGV() {
return *x;
}
-int InstallHandler(int signum, struct sigaction *original_sigaction) {
+bool InstallHandler(int signum, struct sigaction *original_sigaction) {
struct sigaction user_sigaction;
user_sigaction.sa_sigaction = User_OnSIGSEGV;
user_sigaction.sa_flags = SA_SIGINFO;
if (sigaction(signum, &user_sigaction, original_sigaction)) {
perror("sigaction");
- return 1;
+ return false;
}
- return 0;
+ return true;
}
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");
+ if (InstallHandler(SIGSEGV, &original_sigaction_sigsegv) &&
+ InstallHandler(SIGBUS, &original_sigaction_sigbus)) {
+ fprintf(stderr, "User sigaction installed\n");
+ }
return DoSEGV();
}
-// CHECK: User sigaction installed
-// CHECK-NEXT: User sigaction called
-// CHECK-NEXT: ASAN:DEADLYSIGNAL
-// CHECK: AddressSanitizer: SEGV on unknown address
+// CHECK0-NOT: ASAN:DEADLYSIGNAL
+// CHECK0-NOT: AddressSanitizer: SEGV on unknown address
+// CHECK0: User sigaction installed
+// CHECK0-NEXT: User sigaction called
+
+// CHECK1: User sigaction installed
+// CHECK1-NEXT: User sigaction called
+// CHECK1-NEXT: ASAN:DEADLYSIGNAL
+// CHECK1: AddressSanitizer: SEGV on unknown address
+
+// CHECK2-NOT: User sigaction called
+// CHECK2: User sigaction installed
+// CHECK2-NEXT: ASAN:DEADLYSIGNAL
+// CHECK2: AddressSanitizer: SEGV on unknown address
diff --git a/test/asan/TestCases/Posix/current_allocated_bytes.cc b/test/asan/TestCases/Posix/current_allocated_bytes.cc
index 51630cfd8a6b..c49e433b1e8b 100644
--- a/test/asan/TestCases/Posix/current_allocated_bytes.cc
+++ b/test/asan/TestCases/Posix/current_allocated_bytes.cc
@@ -1,9 +1,6 @@
// RUN: %clangxx_asan -O0 %s -pthread -o %t && %run %t
// RUN: %clangxx_asan -O2 %s -pthread -o %t && %run %t
// REQUIRES: stable-runtime
-// UNSUPPORTED: powerpc64le
-// FIXME: This test occasionally fails on powerpc64 LE possibly starting with
-// r279664. Re-enable the test once the problem(s) have been fixed.
#include <assert.h>
#include <pthread.h>
diff --git a/test/asan/TestCases/Posix/wait.cc b/test/asan/TestCases/Posix/wait.cc
index ed6f326b57d6..85e819369c0d 100644
--- a/test/asan/TestCases/Posix/wait.cc
+++ b/test/asan/TestCases/Posix/wait.cc
@@ -4,6 +4,7 @@
// RUN: %clangxx_asan -DWAITPID -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
// RUN: %clangxx_asan -DWAITPID -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// UNSUPPORTED: darwin
#include <assert.h>
#include <sys/wait.h>
diff --git a/test/asan/TestCases/Posix/wait3.cc b/test/asan/TestCases/Posix/wait3.cc
index 2da816fed1aa..081a73e16f0b 100644
--- a/test/asan/TestCases/Posix/wait3.cc
+++ b/test/asan/TestCases/Posix/wait3.cc
@@ -4,7 +4,7 @@
// RUN: %clangxx_asan -DWAIT3_RUSAGE -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
// RUN: %clangxx_asan -DWAIT3_RUSAGE -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s
-// UNSUPPORTED: android
+// UNSUPPORTED: android,darwin
#include <assert.h>
#include <sys/wait.h>
diff --git a/test/asan/TestCases/Posix/wait4.cc b/test/asan/TestCases/Posix/wait4.cc
index b95246efa0e4..aee5570b82e1 100644
--- a/test/asan/TestCases/Posix/wait4.cc
+++ b/test/asan/TestCases/Posix/wait4.cc
@@ -5,6 +5,7 @@
// RUN: %clangxx_asan -DWAIT4_RUSAGE -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s
// XFAIL: android
+// UNSUPPORTED: darwin
#include <assert.h>
#include <sys/wait.h>
diff --git a/test/asan/TestCases/Posix/waitid.cc b/test/asan/TestCases/Posix/waitid.cc
index 8b516dca9086..20fb0c694386 100644
--- a/test/asan/TestCases/Posix/waitid.cc
+++ b/test/asan/TestCases/Posix/waitid.cc
@@ -1,6 +1,8 @@
// RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
// RUN: %clangxx_asan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// UNSUPPORTED: darwin
+
#include <assert.h>
#include <sys/wait.h>
#include <unistd.h>