]> git.proxmox.com Git - rustc.git/blame - src/compiler-rt/test/safestack/pthread.c
New upstream version 1.19.0+dfsg3
[rustc.git] / src / compiler-rt / test / safestack / pthread.c
CommitLineData
92a42be0
SL
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
13static int ptr_test = 42;
14
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
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}