1 // RUN: %clang_safestack %s -pthread -o %t 2 // RUN: %run %t 3 4 // XFAIL: darwin 5 6 // Test that pthreads receive their own unsafe stack. 7 8 #include <stdlib.h> 9 #include <string.h> 10 #include <pthread.h> 11 #include "utils.h" 12 13 static int ptr_test = 42; 14 t1_start(void * ptr)15void *t1_start(void *ptr) 16 { 17 if (ptr != &ptr_test) 18 abort(); 19 20 // safe stack 21 int val = ptr_test * 5; 22 23 // unsafe stack 24 char buffer[8096]; // two pages 25 memset(buffer, val, sizeof (buffer)); 26 break_optimization(buffer); 27 28 return ptr; 29 } 30 main(int argc,char ** argv)31int main(int argc, char **argv) 32 { 33 pthread_t t1; 34 void *ptr = NULL; 35 if (pthread_create(&t1, NULL, t1_start, &ptr_test)) 36 abort(); 37 if (pthread_join(t1, &ptr)) 38 abort(); 39 if (ptr != &ptr_test) 40 abort(); 41 return 0; 42 } 43