1 // Test for mmap/munmap interceptors.
2 // RUN: %clang_asan %s -o %t
6 #include <sanitizer/asan_interface.h>
11 int main(int argc
, char **argv
) {
15 // Get any mmaped pointer.
17 mmap(0, size
, PROT_READ
| PROT_WRITE
, MAP_ANON
| MAP_PRIVATE
, -1, 0);
18 assert(r
!= MAP_FAILED
);
20 // Make sure the memory is unpoisoned.
21 if (__asan_region_is_poisoned(r
, size
) != 0) {
22 fprintf(stderr
, "Memory returned by mmap should be unpoisoned.\n");
26 // First munmmap and then mmap the same pointer using MAP_FIXED.
27 __asan_poison_memory_region(r
, size
);
29 if (__asan_region_is_poisoned(r
, size
) != 0) {
30 fprintf(stderr
, "Shadow memory was not cleaned by munmap.\n");
33 __asan_poison_memory_region(r
, size
);
34 void *p
= mmap(r
, size
, PROT_READ
| PROT_WRITE
,
35 MAP_FIXED
| MAP_ANON
| MAP_PRIVATE
, -1, 0);
38 // Make sure the memory is unpoisoned.
39 if (__asan_region_is_poisoned(r
, size
) != 0) {
40 fprintf(stderr
, "Memory returned by mmap should be unpoisoned.\n");