llvm-project/compiler-rt/test/msan/signal_stress_test.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

75 lines
1.6 KiB
C++
Raw Normal View History

// RUN: %clangxx_msan -std=c++11 -O0 %s -o %t && %run %t
[MSan] Enable MSAN for aarch64 This patch enabled msan for aarch64 with 39-bit VMA and 42-bit VMA. As defined by lib/msan/msan.h the memory layout used is for 39-bit is: 00 0000 0000 - 40 0000 0000: invalid 40 0000 0000 - 43 0000 0000: shadow 43 0000 0000 - 46 0000 0000: origin 46 0000 0000 - 55 0000 0000: invalid 55 0000 0000 - 56 0000 0000: app (low) 56 0000 0000 - 70 0000 0000: invalid 70 0000 0000 - 80 0000 0000: app (high) And for 42-bit VMA: 000 0000 0000 - 100 0000 0000: invalid 100 0000 0000 - 11b 0000 0000: shadow 11b 0000 0000 - 120 0000 0000: invalid 120 0000 0000 - 13b 0000 0000: origin 13b 0000 0000 - 2aa 0000 0000: invalid 2aa 0000 0000 - 2ab 0000 0000: app (low) 2ab 0000 0000 - 3f0 0000 0000: invalid 3f0 0000 0000 - 400 0000 0000: app (high) Most of tests are passing with exception of: * Linux/mallinfo.cc * chained_origin_limits.cc * dlerror.cc * param_tls_limit.cc * signal_stress_test.cc * nonnull-arg.cpp The 'Linux/mallinfo.cc' is due the fact AArch64 returns the sret in 'x8' instead of default first argument 'x1'. So a function prototype that aims to mimic (by using first argument as the return of function) won't work. For GCC one can make a register alias (register var asm ("r8")), but for clang it detects is an unused variable and generate wrong code. The 'chained_origin_limits' is probably due a wrong code generation, since it fails only when origin memory is used (-fsanitize-memory-track-origins=2) and only in the returned code (return buf[50]). The 'signal_streess_test' and 'nonnull-arg' are due currently missing variadic argument handling in memory sanitizer code instrumentation on LLVM side. Both 'dlerror' and 'param_tls_test' are unknown failures that require further investigation. All the failures are XFAIL for aarch64 for now. llvm-svn: 247809
2015-09-16 23:12:25 +08:00
//
// Test that va_arg shadow from a signal handler does not leak outside.
// Reported deadly signal due to stack-overflow
// XFAIL: netbsd
#include <signal.h>
#include <stdarg.h>
#include <sanitizer/msan_interface.h>
#include <assert.h>
#include <sys/time.h>
#include <stdio.h>
const int kSigCnt = 200;
void f(bool poisoned, int n, ...) {
va_list vl;
va_start(vl, n);
for (int i = 0; i < n; ++i) {
void *p = va_arg(vl, void *);
if (!poisoned)
assert(__msan_test_shadow(&p, sizeof(p)) == -1);
}
va_end(vl);
}
int sigcnt;
void SignalHandler(int signo) {
assert(signo == SIGPROF);
void *p;
void **volatile q = &p;
f(true, 10,
*q, *q, *q, *q, *q,
*q, *q, *q, *q, *q);
++sigcnt;
}
int main() {
signal(SIGPROF, SignalHandler);
itimerval itv;
itv.it_interval.tv_sec = 0;
itv.it_interval.tv_usec = 100;
itv.it_value.tv_sec = 0;
itv.it_value.tv_usec = 100;
setitimer(ITIMER_PROF, &itv, NULL);
void *p;
void **volatile q = &p;
do {
f(false, 20,
nullptr, nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr, nullptr);
f(true, 20,
*q, *q, *q, *q, *q,
*q, *q, *q, *q, *q,
*q, *q, *q, *q, *q,
*q, *q, *q, *q, *q);
} while (sigcnt < kSigCnt);
itv.it_interval.tv_sec = 0;
itv.it_interval.tv_usec = 0;
itv.it_value.tv_sec = 0;
itv.it_value.tv_usec = 0;
setitimer(ITIMER_PROF, &itv, NULL);
signal(SIGPROF, SIG_DFL);
return 0;
}