diff options
author | Anna Zaks <ganna@apple.com> | 2016-05-17 22:24:55 +0000 |
---|---|---|
committer | Anna Zaks <ganna@apple.com> | 2016-05-17 22:24:55 +0000 |
commit | 41a8ddbff8f8092409bbbaa753d5ac508c98ee13 (patch) | |
tree | a8cb8968f2c6b531e3ad03b935c820b2dc56ca66 /test | |
parent | fcc603851ff180536f71bae303d3c024c66c7595 (diff) |
[tsan] Ensure mmap respects ignore_interceptors_accesses
The ignore_interceptors_accesses setting did not have an effect on mmap, so
let's change that. It helps in cases user code is accessing the memory
written to by mmap when the synchronization is ensured by the code that
does not get rebuilt.
(This effects Swift interoperability since it's runtime is mapping memory
which gets accessed by the code emitted into the Swift application by the
compiler.)
Differential Revision: http://reviews.llvm.org/D20294
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@269855 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r-- | test/tsan/ignored-interceptors-mmap.cc | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/test/tsan/ignored-interceptors-mmap.cc b/test/tsan/ignored-interceptors-mmap.cc new file mode 100644 index 000000000..871588323 --- /dev/null +++ b/test/tsan/ignored-interceptors-mmap.cc @@ -0,0 +1,61 @@ +// RUN: %clangxx_tsan -O0 %s -o %t +// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NORMAL +// RUN: %env_tsan_opts=ignore_interceptors_accesses=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-IGNORE + +#include <errno.h> +#include <sys/mman.h> + +#include "test.h" + +extern "C" { +void AnnotateIgnoreReadsBegin(const char *f, int l); +void AnnotateIgnoreReadsEnd(const char *f, int l); +void AnnotateIgnoreWritesBegin(const char *f, int l); +void AnnotateIgnoreWritesEnd(const char *f, int l); +} + +void *global_p; + +int mmap_and_ignore_reads_and_writes() { + const size_t kSize = sysconf(_SC_PAGESIZE); + void *p = mmap(0, kSize, PROT_READ|PROT_WRITE, + MAP_PRIVATE|MAP_ANON, -1, 0); + if (p == MAP_FAILED) + return printf("mmap failed with %d\n", errno); + munmap(p, kSize); + + void *new_p = mmap(p, kSize, PROT_READ|PROT_WRITE, + MAP_PRIVATE|MAP_ANON, -1, 0); + if (p == MAP_FAILED || p != new_p) + return printf("second mmap failed with %d\n", errno); + + AnnotateIgnoreWritesBegin(__FILE__, __LINE__); + global_p = p; + AnnotateIgnoreWritesEnd(__FILE__, __LINE__); + barrier_wait(&barrier); + return 0; +} + +void *Thread(void *a) { + barrier_wait(&barrier); + + ((int*)global_p)[1] = 10; + printf("Read the zero value from mmapped memory %d\n", ((int*)global_p)[1]); + return 0; +} + +int main() { + barrier_init(&barrier, 2); + pthread_t t; + pthread_create(&t, 0, Thread, 0); + if (mmap_and_ignore_reads_and_writes()) + return 1; + pthread_join(t, 0); + printf("OK\n"); + return 0; +} + +// CHECK-NORMAL: WARNING: ThreadSanitizer: data race +// CHECK-NORMAL: OK +// CHECK-IGNORE_NOT: WARNING: ThreadSanitizer: data race +// CHECK-IGNORE: OK |