Skip to content

Commit ddcbab3

Browse files
[compiler-rt] Also consider SIGPROF as a synchronous signal
Blocking that signal causes inter-blocking for profilers that monitor threads through that signal. Update tests accordingly to use an uncaught signal. This is a recommit of 6f3f659 with the tests fixed. Fix #83844 and #83561
1 parent 01a31ce commit ddcbab3

File tree

5 files changed

+12
-10
lines changed

5 files changed

+12
-10
lines changed

compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ const int SIGFPE = 8;
126126
const int SIGSEGV = 11;
127127
const int SIGPIPE = 13;
128128
const int SIGTERM = 15;
129+
const int SIGPROF = 27;
129130
#if defined(__mips__) || SANITIZER_FREEBSD || SANITIZER_APPLE || SANITIZER_NETBSD
130131
const int SIGBUS = 10;
131132
const int SIGSYS = 12;
@@ -2168,7 +2169,8 @@ static bool is_sync_signal(ThreadSignalContext *sctx, int sig,
21682169
return false;
21692170
#endif
21702171
return sig == SIGSEGV || sig == SIGBUS || sig == SIGILL || sig == SIGTRAP ||
2171-
sig == SIGABRT || sig == SIGFPE || sig == SIGPIPE || sig == SIGSYS;
2172+
sig == SIGABRT || sig == SIGFPE || sig == SIGPIPE || sig == SIGSYS ||
2173+
sig == SIGPROF;
21722174
}
21732175

21742176
void sighandler(int sig, __sanitizer_siginfo *info, void *ctx) {

compiler-rt/test/tsan/signal_errno.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ static void MyHandler(int, siginfo_t *s, void *c) {
1818

1919
static void* sendsignal(void *p) {
2020
barrier_wait(&barrier);
21-
pthread_kill(mainth, SIGPROF);
21+
pthread_kill(mainth, SIGALRM);
2222
return 0;
2323
}
2424

@@ -37,7 +37,7 @@ int main() {
3737
mainth = pthread_self();
3838
struct sigaction act = {};
3939
act.sa_sigaction = &MyHandler;
40-
sigaction(SIGPROF, &act, 0);
40+
sigaction(SIGALRM, &act, 0);
4141
pthread_t th;
4242
pthread_create(&th, 0, sendsignal, 0);
4343
loop();
@@ -46,7 +46,7 @@ int main() {
4646
}
4747

4848
// CHECK: WARNING: ThreadSanitizer: signal handler spoils errno
49-
// CHECK: Signal 27 handler invoked at:
49+
// CHECK: Signal 14 handler invoked at:
5050
// CHECK: #0 MyHandler(int, {{(__)?}}siginfo{{(_t)?}}*, void*) {{.*}}signal_errno.cpp
5151
// CHECK: main
5252
// CHECK: SUMMARY: ThreadSanitizer: signal handler spoils errno{{.*}}MyHandler

compiler-rt/test/tsan/signal_sync.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ int main() {
3030

3131
struct sigaction act = {};
3232
act.sa_handler = &handler;
33-
if (sigaction(SIGPROF, &act, 0)) {
33+
if (sigaction(SIGALRM, &act, 0)) {
3434
perror("sigaction");
3535
exit(1);
3636
}
@@ -39,7 +39,7 @@ int main() {
3939
t.it_value.tv_sec = 0;
4040
t.it_value.tv_usec = 10;
4141
t.it_interval = t.it_value;
42-
if (setitimer(ITIMER_PROF, &t, 0)) {
42+
if (setitimer(ITIMER_REAL, &t, 0)) {
4343
perror("setitimer");
4444
exit(1);
4545
}

compiler-rt/test/tsan/signal_thread.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ static void* thr(void *p) {
2424
int main() {
2525
struct sigaction act = {};
2626
act.sa_handler = &handler;
27-
if (sigaction(SIGPROF, &act, 0)) {
27+
if (sigaction(SIGALRM, &act, 0)) {
2828
perror("sigaction");
2929
exit(1);
3030
}
@@ -33,7 +33,7 @@ int main() {
3333
t.it_value.tv_sec = 0;
3434
t.it_value.tv_usec = 10;
3535
t.it_interval = t.it_value;
36-
if (setitimer(ITIMER_PROF, &t, 0)) {
36+
if (setitimer(ITIMER_REAL, &t, 0)) {
3737
perror("setitimer");
3838
exit(1);
3939
}

compiler-rt/test/tsan/signal_thread2.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static void *thr(void *p) {
4040
int main() {
4141
struct sigaction act = {};
4242
act.sa_handler = &handler;
43-
if (sigaction(SIGPROF, &act, 0)) {
43+
if (sigaction(SIGALRM, &act, 0)) {
4444
perror("sigaction");
4545
exit(1);
4646
}
@@ -49,7 +49,7 @@ int main() {
4949
t.it_value.tv_sec = 0;
5050
t.it_value.tv_usec = 10;
5151
t.it_interval = t.it_value;
52-
if (setitimer(ITIMER_PROF, &t, 0)) {
52+
if (setitimer(ITIMER_REAL, &t, 0)) {
5353
perror("setitimer");
5454
exit(1);
5555
}

0 commit comments

Comments
 (0)