2014-05-01 05:34:17 +08:00
|
|
|
// RUN: %clangxx_msan -std=c++11 -O0 %s -o %t && %run %t
|
2015-09-16 23:12:25 +08:00
|
|
|
//
|
2013-08-27 20:59:39 +08:00
|
|
|
// Test that va_arg shadow from a signal handler does not leak outside.
|
|
|
|
|
|
|
|
#include <signal.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <sanitizer/msan_interface.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2013-08-27 22:08:15 +08:00
|
|
|
const int kSigCnt = 200;
|
2013-08-27 20:59:39 +08:00
|
|
|
|
2013-08-27 22:08:15 +08:00
|
|
|
void f(bool poisoned, int n, ...) {
|
2013-08-27 20:59:39 +08:00
|
|
|
va_list vl;
|
2013-08-27 22:08:15 +08:00
|
|
|
va_start(vl, n);
|
|
|
|
for (int i = 0; i < n; ++i) {
|
2013-08-27 20:59:39 +08:00
|
|
|
void *p = va_arg(vl, void *);
|
2013-08-27 22:08:15 +08:00
|
|
|
if (!poisoned)
|
2013-08-27 20:59:39 +08:00
|
|
|
assert(__msan_test_shadow(&p, sizeof(p)) == -1);
|
|
|
|
}
|
|
|
|
va_end(vl);
|
|
|
|
}
|
|
|
|
|
|
|
|
int sigcnt;
|
|
|
|
|
|
|
|
void SignalHandler(int signo) {
|
|
|
|
assert(signo == SIGPROF);
|
|
|
|
void *p;
|
2013-08-27 22:08:15 +08:00
|
|
|
void **volatile q = &p;
|
|
|
|
f(true, 10,
|
|
|
|
*q, *q, *q, *q, *q,
|
|
|
|
*q, *q, *q, *q, *q);
|
2013-08-27 20:59:39 +08:00
|
|
|
++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);
|
|
|
|
|
2013-08-27 22:08:15 +08:00
|
|
|
void *p;
|
|
|
|
void **volatile q = &p;
|
|
|
|
|
2013-08-27 20:59:39 +08:00
|
|
|
do {
|
2013-08-27 22:08:15 +08:00
|
|
|
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);
|
2013-08-27 20:59:39 +08:00
|
|
|
} 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;
|
|
|
|
}
|