Fix non portability spotted by Florian:
[valgrind.git] / tests / sys_mman.h
blobc059308c1259ade7b2184f9766b2c6b16221ec6d
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 == 16384 || pagesz == 65536);
25 ptr = mmap(0, pagesz, PROT_READ, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
26 assert(ptr != (void*)-1);
27 r = munmap(ptr, pagesz);
28 assert(r == 0);
29 return ptr;