150
|
1 // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t 2>&1 | FileCheck %s
|
|
2 #include "test.h"
|
|
3 #include <stdint.h>
|
|
4 #include <errno.h>
|
|
5 #include <sys/mman.h>
|
|
6
|
|
7 // Test for issue:
|
|
8 // https://github.com/google/sanitizers/issues/412
|
|
9
|
|
10 // MAP_32BIT flag for mmap is supported only for x86_64.
|
252
|
11 // XFAIL: target=mips{{.*}}
|
|
12 // XFAIL: target=aarch64{{.*}}
|
|
13 // XFAIL: target=powerpc64{{.*}}
|
|
14 // XFAIL: target=s390x{{.*}}
|
|
15 // XFAIL: target=loongarch64{{.*}}
|
150
|
16
|
|
17 // MAP_32BIT doesn't exist on OS X and NetBSD.
|
252
|
18 // UNSUPPORTED: darwin,target={{.*netbsd.*}}
|
150
|
19
|
|
20 void *Thread(void *ptr) {
|
|
21 *(int*)ptr = 42;
|
|
22 barrier_wait(&barrier);
|
|
23 return 0;
|
|
24 }
|
|
25
|
|
26 int main() {
|
|
27 barrier_init(&barrier, 2);
|
|
28 void *ptr = mmap(0, 128 << 10, PROT_READ|PROT_WRITE,
|
|
29 MAP_32BIT|MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
|
|
30 fprintf(stderr, "ptr=%p\n", ptr);
|
|
31 if (ptr == MAP_FAILED) {
|
|
32 fprintf(stderr, "mmap failed: %d\n", errno);
|
|
33 return 1;
|
|
34 }
|
|
35 if ((uintptr_t)ptr >= (1ull << 32)) {
|
|
36 fprintf(stderr, "ptr is too high\n");
|
|
37 return 1;
|
|
38 }
|
|
39 pthread_t t;
|
|
40 pthread_create(&t, 0, Thread, ptr);
|
|
41 barrier_wait(&barrier);
|
|
42 *(int*)ptr = 42;
|
|
43 pthread_join(t, 0);
|
|
44 munmap(ptr, 128 << 10);
|
|
45 fprintf(stderr, "DONE\n");
|
|
46 }
|
|
47
|
|
48 // CHECK: WARNING: ThreadSanitizer: data race
|
|
49 // CHECK: DONE
|