1 // Test StopTheWorld behavior during signal storm.
2 // Historically StopTheWorld crashed because did not handle EINTR properly.
3 // The test is somewhat convoluted, but that's what caused crashes previously.
5 // RUN: %clangxx_lsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
11 #include <sys/types.h>
12 #include <sys/prctl.h>
16 #include <sanitizer/lsan_interface.h>
18 static void handler(int signo
);
19 static void *thr(void *arg
);
22 struct sigaction act
= {};
23 act
.sa_handler
= handler
;
24 sigaction(SIGPROF
, &act
, 0);
28 fprintf(stderr
, "failed to fork\n");
32 // Child constantly sends signals to parent to cause spurious return from
33 // waitpid in StopTheWorld.
34 prctl(PR_SET_PDEATHSIG
, SIGTERM
, 0, 0, 0);
35 pid_t parent
= getppid();
37 // There is no strong reason for these two particular signals,
38 // but at least one of them ought to unblock waitpid.
39 kill(parent
, SIGCHLD
);
40 kill(parent
, SIGPROF
);
43 usleep(10000); // Let the child start.
44 __lsan_do_leak_check();
45 // Kill and join the child.
48 sleep(1); // If the tracer thread still runs, give it time to crash.
49 fprintf(stderr
, "DONE\n");
53 static void handler(int signo
) {
56 static void *thr(void *arg
) {