10 /* Define __UNUSED__ that also other compilers than gcc can run the tests. */
13 #define __UNUSED__ __attribute__((__unused__))
18 #define CHECK(x) (!(x) ? abort() : (void)0)
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
58 allocate_mmap (size_t size
)
61 #if defined (HAVE_MMAP_DEV_ZERO)
62 static int dev_zero_fd
= -1;
65 #ifdef HAVE_MMAP_DEV_ZERO
66 if (dev_zero_fd
== -1)
68 dev_zero_fd
= open ("/dev/zero", O_RDONLY
);
69 if (dev_zero_fd
== -1)
71 perror ("open /dev/zero: %m");
79 page
= mmap (NULL
, size
, PROT_READ
| PROT_WRITE
| PROT_EXEC
,
80 MAP_PRIVATE
| MAP_ANONYMOUS
, -1, 0);
82 #ifdef HAVE_MMAP_DEV_ZERO
83 page
= mmap (NULL
, size
, PROT_READ
| PROT_WRITE
| PROT_EXEC
,
84 MAP_PRIVATE
, dev_zero_fd
, 0);
87 if (page
== (char *) MAP_FAILED
)
89 perror ("virtual memory exhausted");