1 // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
2 #include "java.h"
3 #include <errno.h>
4 #include <sys/mman.h>
5
main()6 int main() {
7 // Test that munmap interceptor resets meta shadow for the memory range.
8 // Previously __tsan_java_move failed because it encountered non-zero meta
9 // shadow for the destination.
10 int const kHeapSize = 1024 * 1024;
11 jptr jheap = (jptr)mmap(0, kHeapSize, PROT_READ | PROT_WRITE,
12 MAP_ANON | MAP_PRIVATE, -1, 0);
13 if (jheap == (jptr)MAP_FAILED)
14 return printf("mmap failed with %d\n", errno);
15 __atomic_store_n((int*)jheap, 1, __ATOMIC_RELEASE);
16 munmap((void*)jheap, kHeapSize);
17 jheap = (jptr)mmap((void*)jheap, kHeapSize, PROT_READ | PROT_WRITE,
18 MAP_ANON | MAP_PRIVATE, -1, 0);
19 if (jheap == (jptr)MAP_FAILED)
20 return printf("second mmap failed with %d\n", errno);
21 __tsan_java_init(jheap, kHeapSize);
22 __tsan_java_move(jheap + 16, jheap, 16);
23 fprintf(stderr, "DONE\n");
24 return __tsan_java_fini();
25 }
26
27 // CHECK-NOT: WARNING: ThreadSanitizer: data race
28 // CHECK: DONE
29