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