2014-10-25 01:07:29 +08:00
|
|
|
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t 2>&1 | FileCheck %s
|
2015-01-21 21:50:02 +08:00
|
|
|
#include "test.h"
|
2014-10-25 01:07:29 +08:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
|
|
|
|
// Test for issue:
|
2015-11-30 22:11:48 +08:00
|
|
|
// https://github.com/google/sanitizers/issues/412
|
2014-10-25 01:07:29 +08:00
|
|
|
|
2015-02-20 17:32:45 +08:00
|
|
|
// MAP_32BIT flag for mmap is supported only for x86_64.
|
2016-08-30 21:01:04 +08:00
|
|
|
// XFAIL: mips
|
2015-08-05 23:17:59 +08:00
|
|
|
// XFAIL: aarch64
|
2015-12-09 05:54:39 +08:00
|
|
|
// XFAIL: powerpc64
|
2021-07-02 08:43:49 +08:00
|
|
|
// XFAIL: s390x
|
2015-02-20 17:32:45 +08:00
|
|
|
|
2017-10-26 01:09:05 +08:00
|
|
|
// MAP_32BIT doesn't exist on OS X and NetBSD.
|
|
|
|
// UNSUPPORTED: darwin,netbsd
|
2015-11-28 17:22:27 +08:00
|
|
|
|
2014-10-25 01:07:29 +08:00
|
|
|
void *Thread(void *ptr) {
|
|
|
|
*(int*)ptr = 42;
|
2015-01-21 21:50:02 +08:00
|
|
|
barrier_wait(&barrier);
|
2014-10-25 01:07:29 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
2015-01-21 21:50:02 +08:00
|
|
|
barrier_init(&barrier, 2);
|
2014-10-25 01:07:29 +08:00
|
|
|
void *ptr = mmap(0, 128 << 10, PROT_READ|PROT_WRITE,
|
|
|
|
MAP_32BIT|MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
|
|
|
|
fprintf(stderr, "ptr=%p\n", ptr);
|
|
|
|
if (ptr == MAP_FAILED) {
|
|
|
|
fprintf(stderr, "mmap failed: %d\n", errno);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if ((uintptr_t)ptr >= (1ull << 32)) {
|
|
|
|
fprintf(stderr, "ptr is too high\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
pthread_t t;
|
|
|
|
pthread_create(&t, 0, Thread, ptr);
|
2015-01-21 21:50:02 +08:00
|
|
|
barrier_wait(&barrier);
|
2014-10-25 01:07:29 +08:00
|
|
|
*(int*)ptr = 42;
|
|
|
|
pthread_join(t, 0);
|
|
|
|
munmap(ptr, 128 << 10);
|
|
|
|
fprintf(stderr, "DONE\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK: WARNING: ThreadSanitizer: data race
|
|
|
|
// CHECK: DONE
|