Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 1 | // RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 2 | #include "test.h" |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 3 | #include <signal.h> |
| 4 | #include <sys/types.h> |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 5 | #include <errno.h> |
| 6 | |
| 7 | pthread_t mainth; |
| 8 | volatile int done; |
| 9 | |
| 10 | static void MyHandler(int, siginfo_t *s, void *c) { |
| 11 | errno = 1; |
| 12 | done = 1; |
| 13 | } |
| 14 | |
| 15 | static void* sendsignal(void *p) { |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 16 | barrier_wait(&barrier); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 17 | pthread_kill(mainth, SIGPROF); |
| 18 | return 0; |
| 19 | } |
| 20 | |
| 21 | static __attribute__((noinline)) void loop() { |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 22 | barrier_wait(&barrier); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 23 | while (done == 0) { |
| 24 | volatile char *p = (char*)malloc(1); |
| 25 | p[0] = 0; |
| 26 | free((void*)p); |
| 27 | pthread_yield(); |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | int main() { |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 32 | barrier_init(&barrier, 2); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 33 | mainth = pthread_self(); |
| 34 | struct sigaction act = {}; |
| 35 | act.sa_sigaction = &MyHandler; |
| 36 | sigaction(SIGPROF, &act, 0); |
| 37 | pthread_t th; |
| 38 | pthread_create(&th, 0, sendsignal, 0); |
| 39 | loop(); |
| 40 | pthread_join(th, 0); |
| 41 | return 0; |
| 42 | } |
| 43 | |
| 44 | // CHECK: WARNING: ThreadSanitizer: signal handler spoils errno |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 45 | // CHECK: #0 MyHandler(int, {{(__)?}}siginfo{{(_t)?}}*, void*) {{.*}}signal_errno.cc |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 46 | // CHECK: main |
| 47 | // CHECK: SUMMARY: ThreadSanitizer: signal handler spoils errno{{.*}}MyHandler |
| 48 | |