34 lines · cpp
1// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s2 3#include "java.h"4#include <errno.h>5#include <sys/mman.h>6 7int main() {8 // Test a non-regular kHeapSize9 // Previously __tsan_java_init failed because it encountered non-zero meta10 // shadow for the destination.11 size_t const kPageSize = sysconf(_SC_PAGESIZE);12 int const kSize = kPageSize - 1;13 jptr jheap2 = (jptr)mmap(0, kSize, PROT_READ | PROT_WRITE,14 MAP_ANON | MAP_PRIVATE, -1, 0);15 if (jheap2 == (jptr)MAP_FAILED)16 return printf("mmap failed with %d\n", errno);17 __atomic_store_n((int *)(jheap2 + kSize - 3), 1, __ATOMIC_RELEASE);18 // Due to the previous incorrect meta-end calculation, the following munmap19 // did not clear the tail meta shadow.20 munmap((void *)jheap2, kSize);21 int const kHeapSize2 = kSize + 1;22 jheap2 = (jptr)mmap((void *)jheap2, kHeapSize2, PROT_READ | PROT_WRITE,23 MAP_ANON | MAP_PRIVATE, -1, 0);24 if (jheap2 == (jptr)MAP_FAILED)25 return printf("second mmap failed with %d\n", errno);26 __tsan_java_init(jheap2, kHeapSize2);27 __tsan_java_move(jheap2, jheap2 + kHeapSize2 - 8, 8);28 fprintf(stderr, "DONE\n");29 return __tsan_java_fini();30}31 32// CHECK-NOT: WARNING: ThreadSanitizer: data race33// CHECK: DONE34