• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Test that TLS is unpoisoned on thread death.
2 // REQUIRES: x86-target-arch && !android
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 
first(void * arg)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 
second(void * arg)22 void *second(void *arg) {
23   assert(tls_var == p_tls_var);
24   *p_tls_var = 1;
25   return 0;
26 }
27 
main(int argc,char * argv[])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