llvm-project
48 строк · 1.1 Кб
1// RUN: %clang_dfsan -DUSE_SIGNAL_ACTION -Wno-error=int-conversion %s -o %t && %run %t
2// RUN: %clang_dfsan -Wno-error=int-conversion %s -o %t && %run %t
3
4#include <sanitizer/dfsan_interface.h>5
6#include <assert.h>7#include <signal.h>8#include <string.h>9#include <sys/types.h>10#include <unistd.h>11
12volatile int x;13volatile int z = 1;14
15void SignalHandler(int signo) {16assert(dfsan_get_label(signo) == 0);17x = z;18}
19
20void SignalAction(int signo, siginfo_t *si, void *uc) {21assert(dfsan_get_label(signo) == 0);22assert(dfsan_get_label(si) == 0);23assert(dfsan_get_label(uc) == 0);24assert(0 == dfsan_read_label(si, sizeof(*si)));25assert(0 == dfsan_read_label(uc, sizeof(ucontext_t)));26x = z;27}
28
29int main(int argc, char *argv[]) {30dfsan_set_label(8, (void *)&z, sizeof(z));31
32struct sigaction sa = {};33#ifdef USE_SIGNAL_ACTION34sa.sa_flags = SA_SIGINFO;35sa.sa_sigaction = SignalAction;36#else37sa.sa_handler = SignalHandler;38#endif39int r = sigaction(SIGHUP, &sa, NULL);40assert(dfsan_get_label(r) == 0);41
42kill(getpid(), SIGHUP);43signal(SIGHUP, SIG_DFL);44
45assert(x == 1);46
47return 0;48}
49