| 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 | |
| 11 | static int ptr_test = 42; |
| 12 | |
| 13 | void *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(s: buffer, c: val, n: sizeof (buffer)); |
| 24 | break_optimization(arg: buffer); |
| 25 | |
| 26 | return ptr; |
| 27 | } |
| 28 | |
| 29 | int main(int argc, char **argv) |
| 30 | { |
| 31 | pthread_t t1; |
| 32 | void *ptr = NULL; |
| 33 | if (pthread_create(newthread: &t1, NULL, start_routine: t1_start, arg: &ptr_test)) |
| 34 | abort(); |
| 35 | if (pthread_join(th: t1, thread_return: &ptr)) |
| 36 | abort(); |
| 37 | if (ptr != &ptr_test) |
| 38 | abort(); |
| 39 | return 0; |
| 40 | } |
| 41 |
