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 2>&1 | FileCheck %s
6 #include <sanitizer/msan_interface.h>
14 typedef ssize_t (*process_vm_readwritev_fn
)(pid_t
, const iovec
*, unsigned long,
15 const iovec
*, unsigned long,
18 // Exit with success, emulating the expected output.
22 printf("process_vm_readv not found or not implemented!\n");
24 "WARNING: MemorySanitizer: use-of-uninitialized-value (not really)\n");
32 // This requires glibc 2.15.
33 process_vm_readwritev_fn libc_process_vm_readv
=
34 (process_vm_readwritev_fn
)dlsym(RTLD_NEXT
, "process_vm_readv");
35 if (!libc_process_vm_readv
)
38 process_vm_readwritev_fn process_vm_readv
=
39 (process_vm_readwritev_fn
)dlsym(RTLD_DEFAULT
, "process_vm_readv");
40 process_vm_readwritev_fn process_vm_writev
=
41 (process_vm_readwritev_fn
)dlsym(RTLD_DEFAULT
, "process_vm_writev");
47 iovec iov_a
[] = {{(void *)a
, 20}, (void *)(a
+ 50), 10};
48 iovec iov_b
[] = {{(void *)(b
+ 10), 10}, (void *)(b
+ 30), 20};
50 __msan_poison(&b
, sizeof(b
));
51 ssize_t res
= process_vm_readv(getpid(), iov_b
, 2, iov_a
, 2, 0);
52 if (errno
== ENOSYS
) // Function not implemented
56 __msan_check_mem_is_initialized(b
+ 10, 10);
57 __msan_check_mem_is_initialized(b
+ 30, 20);
58 assert(__msan_test_shadow(b
+ 9, 1) == 0);
59 assert(__msan_test_shadow(b
+ 20, 1) == 0);
60 assert(__msan_test_shadow(b
+ 29, 1) == 0);
61 assert(__msan_test_shadow(b
+ 50, 1) == 0);
64 __msan_unpoison(&b
, sizeof(b
));
65 __msan_poison(b
+ 32, 1);
66 res
= process_vm_writev(getpid(), iov_b
, 2, iov_a
, 2, 0);
67 // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value
69 __msan_unpoison(&b
, sizeof(b
));
70 res
= process_vm_writev(getpid(), iov_b
, 2, iov_a
, 2, 0);