1 // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
3 // Test that mmap does not return unexpected addresses
4 // (the check is in the interceptor).
12 #include <sys/types.h>
16 int fd
= open("/dev/zero", O_RDWR
);
17 if (fd
== -1) perror("open(/dev/zero)"), exit(1);
18 for (size_t mmap_size
= 64ull << 30; mmap_size
>= 4 << 10; mmap_size
/= 2) {
20 while (mmap(0, mmap_size
, PROT_READ
| PROT_WRITE
, MAP_ANON
| MAP_PRIVATE
,
21 fd
, 0) != MAP_FAILED
) {
22 allocated
+= mmap_size
;
24 fprintf(stderr
, "allocated %zu with size %zu\n", allocated
, mmap_size
);
26 fprintf(stderr
, "DONE\n");
27 // If tsan runtime will try to allocate something during exit handling,
28 // the allocation will fail because there is no VA whatsoever.
29 // It's observed to fail with the following error in some cases:
30 // failed to allocate 0x1000 (4096) bytes of DTLS_NextBlock.
31 // So terminate the process immediately.