File: sys_mman.h

package info (click to toggle)
valgrind 1:3.10.0-4~bpo7+1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy-backports
  • size: 97,940 kB
  • sloc: ansic: 589,429; xml: 21,096; exp: 8,751; cpp: 7,366; asm: 6,526; perl: 5,656; sh: 5,334; makefile: 4,946; haskell: 195
file content (31 lines) | stat: -rw-r--r-- 763 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Replacement for sys/mman.h which factors out platform differences.

#include <sys/mman.h>

#if defined(VGO_darwin)
#  define MAP_ANONYMOUS MAP_ANON
#endif


#include <assert.h>
#include <unistd.h>

// Map a page, then unmap it, then return that address.  That
// guarantees to give an address which will fault when accessed,
// without making any assumptions about the layout of the address
// space.

__attribute__((unused))
static void* get_unmapped_page(void)
{
   void* ptr;
   int r;
   long pagesz = sysconf(_SC_PAGE_SIZE);
   assert(pagesz == 4096 || pagesz == 16384 || pagesz == 65536);
   ptr = mmap(0, pagesz, PROT_READ, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
   assert(ptr != (void*)-1);
   r = munmap(ptr, pagesz);
   assert(r == 0);
   return ptr;
}