Home | History | Annotate | Download | only in Linux
      1 // Test that TLS is unpoisoned on thread death.
      2 // REQUIRES: x86_64-supported-target,i386-supported-target
      3 
      4 // RUN: %clangxx_asan -O1 %s -pthread -o %t && %run %t 2>&1
      5 
      6 #include <assert.h>
      7 #include <pthread.h>
      8 #include <stdio.h>
      9 
     10 #include <sanitizer/asan_interface.h>
     11 
     12 __thread int64_t tls_var[2];
     13 
     14 volatile int64_t *p_tls_var;
     15 
     16 void *first(void *arg) {
     17   ASAN_POISON_MEMORY_REGION(&tls_var, sizeof(tls_var));
     18   p_tls_var = tls_var;
     19   return 0;
     20 }
     21 
     22 void *second(void *arg) {
     23   assert(tls_var == p_tls_var);
     24   *p_tls_var = 1;
     25   return 0;
     26 }
     27 
     28 int main(int argc, char *argv[]) {
     29   pthread_t p;
     30   assert(0 == pthread_create(&p, 0, first, 0));
     31   assert(0 == pthread_join(p, 0));
     32   assert(0 == pthread_create(&p, 0, second, 0));
     33   assert(0 == pthread_join(p, 0));
     34   return 0;
     35 }
     36