Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 1 | // Check that init-order checking is properly disabled if pthread_create is |
| 2 | // called. |
| 3 | |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 4 | // RUN: %clangxx_asan %s %p/Helpers/init-order-pthread-create-extra.cc -pthread -o %t |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 5 | // RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_init_order=true %run %t |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 6 | |
| 7 | #include <stdio.h> |
| 8 | #include <pthread.h> |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 9 | #include <unistd.h> |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 10 | |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 11 | void *bar(void *input, bool sleep_before_init) { |
| 12 | if (sleep_before_init) |
| 13 | usleep(500000); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 14 | return input; |
| 15 | } |
| 16 | |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 17 | void *glob = bar((void*)0x1234, false); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 18 | extern void *glob2; |
| 19 | |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 20 | void *poll(void *arg) { |
| 21 | void **glob = (void**)arg; |
| 22 | while (true) { |
| 23 | usleep(100000); |
| 24 | printf("glob is now: %p\n", *glob); |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | struct GlobalPollerStarter { |
| 29 | GlobalPollerStarter() { |
| 30 | pthread_t p; |
| 31 | pthread_attr_t attr; |
| 32 | pthread_attr_init(&attr); |
| 33 | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); |
| 34 | pthread_create(&p, 0, poll, &glob); |
| 35 | pthread_attr_destroy(&attr); |
| 36 | printf("glob poller is started"); |
| 37 | } |
| 38 | } global_poller; |
| 39 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 40 | int main() { |
| 41 | printf("%p %p\n", glob, glob2); |
| 42 | return 0; |
| 43 | } |