Sergey Matveev | 12d01ba | 2013-05-29 13:09:44 +0000 | [diff] [blame^] | 1 | // Test that TLS is unpoisoned on thread death. |
| 2 | // REQUIRES: x86_64-supported-target,i386-supported-target |
| 3 | |
| 4 | // RUN: %clangxx_asan -m64 -O1 %p/SharedLibs/dlclose-test-so.cc \ |
| 5 | // RUN: -fPIC -shared -o %t-so.so |
| 6 | // RUN: %clangxx_asan -m64 -O1 %s -o %t && %t 2>&1 |
| 7 | // RUN: %clangxx_asan -m32 -O1 %p/SharedLibs/dlclose-test-so.cc \ |
| 8 | // RUN: -fPIC -shared -o %t-so.so |
| 9 | // RUN: %clangxx_asan -m32 -O1 %s -o %t && %t 2>&1 |
| 10 | |
| 11 | #include <assert.h> |
| 12 | #include <pthread.h> |
| 13 | #include <stdio.h> |
| 14 | |
| 15 | #include <sanitizer/asan_interface.h> |
| 16 | |
| 17 | __thread int64_t tls_var[2]; |
| 18 | |
| 19 | volatile int64_t *p_tls_var; |
| 20 | |
| 21 | void *first(void *arg) { |
| 22 | ASAN_POISON_MEMORY_REGION(&tls_var, sizeof(tls_var)); |
| 23 | p_tls_var = tls_var; |
| 24 | return 0; |
| 25 | } |
| 26 | |
| 27 | void *second(void *arg) { |
| 28 | assert(tls_var == p_tls_var); |
| 29 | *p_tls_var = 1; |
| 30 | return 0; |
| 31 | } |
| 32 | |
| 33 | int main(int argc, char *argv[]) { |
| 34 | pthread_t p; |
| 35 | assert(0 == pthread_create(&p, 0, first, 0)); |
| 36 | assert(0 == pthread_join(p, 0)); |
| 37 | assert(0 == pthread_create(&p, 0, second, 0)); |
| 38 | assert(0 == pthread_join(p, 0)); |
| 39 | return 0; |
| 40 | } |