-> 3.23.0 final
[valgrind.git] / tests / sys_mman.h
blob0cdc434f7176216f95276ebb736f6e3314491eaa
1 // Replacement for sys/mman.h which factors out platform differences.
3 #include <sys/mman.h>
5 #if defined(VGO_darwin)
6 # define MAP_ANONYMOUS MAP_ANON
7 #endif
10 #include <assert.h>
11 #include <unistd.h>
13 // Map a page, then unmap it, then return that address. That
14 // guarantees to give an address which will fault when accessed,
15 // without making any assumptions about the layout of the address
16 // space.
18 __attribute__((unused))
19 static void* get_unmapped_page(void)
21 void* ptr;
22 int r;
23 long pagesz = sysconf(_SC_PAGE_SIZE);
24 assert(pagesz == 4096 || pagesz == 8192 || pagesz == 16384 || pagesz == 32768
25 || pagesz == 65536);
26 ptr = mmap(0, pagesz, PROT_READ, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
27 assert(ptr != (void*)-1);
28 r = munmap(ptr, pagesz);
29 assert(r == 0);
30 return ptr;