10 #define CHECK(x) !(x) ? abort() : 0
12 /* Define __UNUSED__ that also other compilers than gcc can run the tests. */
15 #define __UNUSED__ __attribute__((__unused__))
20 /* Prefer MAP_ANON(YMOUS) to /dev/zero, since we don't need to keep a
23 # undef HAVE_MMAP_DEV_ZERO
25 # include <sys/mman.h>
27 # define MAP_FAILED -1
29 # if !defined (MAP_ANONYMOUS) && defined (MAP_ANON)
30 # define MAP_ANONYMOUS MAP_ANON
36 #ifdef HAVE_MMAP_DEV_ZERO
38 # include <sys/mman.h>
40 # define MAP_FAILED -1
48 allocate_mmap (size_t size
)
51 #if defined (HAVE_MMAP_DEV_ZERO)
52 static int dev_zero_fd
= -1;
55 #ifdef HAVE_MMAP_DEV_ZERO
56 if (dev_zero_fd
== -1)
58 dev_zero_fd
= open ("/dev/zero", O_RDONLY
);
59 if (dev_zero_fd
== -1)
61 perror ("open /dev/zero: %m");
69 page
= mmap (NULL
, size
, PROT_READ
| PROT_WRITE
| PROT_EXEC
,
70 MAP_PRIVATE
| MAP_ANONYMOUS
, -1, 0);
72 #ifdef HAVE_MMAP_DEV_ZERO
73 page
= mmap (NULL
, size
, PROT_READ
| PROT_WRITE
| PROT_EXEC
,
74 MAP_PRIVATE
, dev_zero_fd
, 0);
77 if (page
== (void *) MAP_FAILED
)
79 perror ("virtual memory exhausted");