1 // Replacement for sys/mman.h which factors out platform differences. 2 3 #include <sys/mman.h> 4 5 #if defined(VGO_darwin) 6 # define MAP_ANONYMOUS MAP_ANON 7 #endif 8 9 10 #include <assert.h> 11 #include <unistd.h> 12 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. 17 18 __attribute__((unused)) get_unmapped_page(void)19static void* get_unmapped_page(void) 20 { 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; 30 } 31 32