1 // RUN: %clangxx_msan -std=c++11 -O0 %s -o %t && %run %t
2 // RUN: %clangxx_msan -std=c++11 -O0 %s -o %t -DPOSITIVE && not %run %t |& FileCheck %s
6 #include <sanitizer/msan_interface.h>
13 typedef ssize_t (*process_vm_readwritev_fn)(pid_t, const iovec *, unsigned long,
14 const iovec *, unsigned long,
18 // This requires glibc 2.15.
19 process_vm_readwritev_fn libc_process_vm_readv =
20 (process_vm_readwritev_fn)dlsym(RTLD_NEXT, "process_vm_readv");
21 if (!libc_process_vm_readv) {
22 // Exit with success, emulating the expected output.
24 printf("process_vm_readv not found!\n");
26 "WARNING: MemorySanitizer: use-of-uninitialized-value (not really)\n");
33 process_vm_readwritev_fn process_vm_readv =
34 (process_vm_readwritev_fn)dlsym(RTLD_DEFAULT, "process_vm_readv");
35 process_vm_readwritev_fn process_vm_writev =
36 (process_vm_readwritev_fn)dlsym(RTLD_DEFAULT, "process_vm_writev");
42 iovec iov_a[] = {{(void *)a, 20}, (void *)(a + 50), 10};
43 iovec iov_b[] = {{(void *)(b + 10), 10}, (void *)(b + 30), 20};
45 __msan_poison(&b, sizeof(b));
46 ssize_t res = process_vm_readv(getpid(), iov_b, 2, iov_a, 2, 0);
48 __msan_check_mem_is_initialized(b + 10, 10);
49 __msan_check_mem_is_initialized(b + 30, 20);
50 assert(__msan_test_shadow(b + 9, 1) == 0);
51 assert(__msan_test_shadow(b + 20, 1) == 0);
52 assert(__msan_test_shadow(b + 29, 1) == 0);
53 assert(__msan_test_shadow(b + 50, 1) == 0);
56 __msan_unpoison(&b, sizeof(b));
57 __msan_poison(b + 32, 1);
58 res = process_vm_writev(getpid(), iov_b, 2, iov_a, 2, 0);
59 // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value
61 __msan_unpoison(&b, sizeof(b));
62 res = process_vm_writev(getpid(), iov_b, 2, iov_a, 2, 0);