1// RUN: %clangxx_tsan %s -o %t
2// RUN: %run %t 2>&1 | FileCheck %s
3
4#include <pthread.h>
5#include <stdlib.h>
6#include <stddef.h>
7#include <unistd.h>
8#include <stdio.h>
9#include <time.h>
10#include <sys/mman.h>
11
12const long kSmallPage = 4 << 10;
13const long kLargePage = 2 << 20;
14const long kStride = 1 << 10;
15
16typedef unsigned long uptr;
17
18int main(int argc, const char **argv) {
19 uptr mem_size = 4 << 20;
20 if (argc > 1)
21 mem_size = (uptr)atoi(nptr: argv[1]) << 20;
22 uptr stride = kSmallPage;
23 if (argc > 2)
24 stride = (uptr)atoi(nptr: argv[2]) << 10;
25 int niter = 1;
26 if (argc > 3)
27 niter = atoi(nptr: argv[3]);
28 int stride2 = 1;
29 if (argc > 4)
30 stride2 = atoi(nptr: argv[4]);
31
32 uptr sz = mem_size + stride2 * kStride + kLargePage;
33 void *p = mmap(addr: 0, len: sz, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, fd: -1, offset: 0);
34 uptr a = ((uptr)p + kLargePage - 1) & ~(kLargePage - 1);
35 volatile char *mem = (volatile char *)a;
36
37 for (int i = 0; i < niter; i++) {
38 for (uptr off = 0; off < mem_size; off += stride) {
39 for (uptr off2 = 0; off2 < stride2; off2++)
40 mem[off + off2 * kStride] = 42;
41 }
42 }
43
44 fprintf(stderr, format: "DONE\n");
45}
46
47// CHECK: DONE
48
49

source code of compiler-rt/test/tsan/bench_shadow_flush.cpp