Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 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 | |
| 8 | int main(void) { |
| 9 | unsigned char vec[20]; |
| 10 | int res; |
| 11 | size_t PS = sysconf(_SC_PAGESIZE); |
| 12 | void *addr = mmap(nullptr, 20 * PS, PROT_READ | PROT_WRITE, |
| 13 | MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); |
| 14 | |
| 15 | __msan_poison(&vec, sizeof(vec)); |
| 16 | res = mincore(addr, 10 * PS, vec); |
| 17 | assert(res == 0); |
| 18 | assert(__msan_test_shadow(vec, sizeof(vec)) == 10); |
| 19 | |
| 20 | __msan_poison(&vec, sizeof(vec)); |
| 21 | res = mincore(addr, 10 * PS + 42, vec); |
| 22 | assert(res == 0); |
| 23 | assert(__msan_test_shadow(vec, sizeof(vec)) == 11); |
| 24 | |
| 25 | __msan_poison(&vec, sizeof(vec)); |
| 26 | res = mincore(addr, 10 * PS - 1, vec); |
| 27 | assert(res == 0); |
| 28 | assert(__msan_test_shadow(vec, sizeof(vec)) == 10); |
| 29 | |
| 30 | __msan_poison(&vec, sizeof(vec)); |
| 31 | res = mincore(addr, 1, vec); |
| 32 | assert(res == 0); |
| 33 | assert(__msan_test_shadow(vec, sizeof(vec)) == 1); |
| 34 | |
| 35 | return 0; |
| 36 | } |