1// RUN: %clangxx_msan -std=c++11 -O0 %s -o %t && %run %t
2
3#include <assert.h>
4#include <unistd.h>
5#include <sys/mman.h>
6#include <sanitizer/msan_interface.h>
7
8int main(void) {
9 unsigned char vec[20];
10 int res;
11 size_t PS = sysconf(_SC_PAGESIZE);
12 void *addr = mmap(addr: nullptr, len: 20 * PS, PROT_READ | PROT_WRITE,
13 MAP_PRIVATE | MAP_ANONYMOUS, fd: 0, offset: 0);
14
15 __msan_poison(a: &vec, size: sizeof(vec));
16 res = mincore(start: addr, len: 10 * PS, vec: vec);
17 assert(res == 0);
18 assert(__msan_test_shadow(vec, sizeof(vec)) == 10);
19
20 __msan_poison(a: &vec, size: sizeof(vec));
21 res = mincore(start: addr, len: 10 * PS + 42, vec: vec);
22 assert(res == 0);
23 assert(__msan_test_shadow(vec, sizeof(vec)) == 11);
24
25 __msan_poison(a: &vec, size: sizeof(vec));
26 res = mincore(start: addr, len: 10 * PS - 1, vec: vec);
27 assert(res == 0);
28 assert(__msan_test_shadow(vec, sizeof(vec)) == 10);
29
30 __msan_poison(a: &vec, size: sizeof(vec));
31 res = mincore(start: addr, len: 1, vec: vec);
32 assert(res == 0);
33 assert(__msan_test_shadow(vec, sizeof(vec)) == 1);
34
35 return 0;
36}
37

source code of compiler-rt/test/msan/Linux/mincore.cpp