1 # mmap-anon.m4 serial 4 (libsigsegv-2.9)
2 dnl Copyright (C) 2002-2003, 2008, 2010 Bruno Haible <bruno@clisp.org>
3 dnl This file is free software, distributed under the terms of the GNU
4 dnl General Public License. As a special exception to the GNU General
5 dnl Public License, this file may be distributed as part of a program
6 dnl that contains a configuration script generated by Autoconf, under
7 dnl the same distribution terms as the rest of that program.
9 # How to allocate fresh memory using mmap.
10 AC_DEFUN([SV_MMAP_ANON],
12 AC_REQUIRE([AC_PROG_CC])
13 AC_REQUIRE([AC_CANONICAL_HOST])
17 AC_CACHE_CHECK([for mmap with MAP_ANON], [sv_cv_func_mmap_anon], [
20 #include <sys/types.h>
24 void *p = mmap (0, 0x10000, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
25 return (p == (void *)(-1));
27 [sv_cv_func_mmap_anon=yes],
28 [sv_cv_func_mmap_anon=no],
30 dnl FIXME: Put in some more known values here.
32 freebsd* | linux* | osf* | darwin*)
33 sv_cv_func_mmap_anon=yes ;;
37 #include <sys/types.h>
40 [[mmap (0, 0x10000, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);]])],
41 [sv_cv_func_mmap_anon="guessing yes"],
42 [sv_cv_func_mmap_anon=no])
47 if test "$sv_cv_func_mmap_anon" != no; then
48 AC_DEFINE([HAVE_MMAP_ANON], [1],
49 [Define if <sys/mman.h> defines MAP_ANON and mmaping with MAP_ANON works.])
54 AC_CACHE_CHECK([for mmap with MAP_ANONYMOUS], [sv_cv_func_mmap_anonymous], [
57 #include <sys/types.h>
61 void *p = mmap (0, 0x10000, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
62 return (p == (void *)(-1));
64 [sv_cv_func_mmap_anonymous=yes],
65 [sv_cv_func_mmap_anonymous=no],
67 dnl FIXME: Put in some more known values here.
69 hpux* | linux* | osf*)
70 sv_cv_func_mmap_anonymous=yes ;;
72 sv_cv_func_mmap_anonymous=no ;;
76 #include <sys/types.h>
79 [[mmap (0, 0x10000, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);]])],
80 [sv_cv_func_mmap_anonymous="guessing yes"],
81 [sv_cv_func_mmap_anonymous=no])
86 if test "$sv_cv_func_mmap_anonymous" != no; then
87 AC_DEFINE([HAVE_MMAP_ANONYMOUS], [1],
88 [Define if <sys/mman.h> defines MAP_ANONYMOUS and mmaping with MAP_ANONYMOUS
92 dnl 3) MAP_FILE of /dev/zero
94 AC_CACHE_CHECK([for mmap of /dev/zero], [sv_cv_func_mmap_devzero], [
97 #include <sys/types.h>
107 fd = open ("/dev/zero", O_RDONLY, 0666);
108 if (fd < 0) return 1;
109 p = mmap (0, 0x10000, PROT_READ | PROT_WRITE, MAP_FILE | MAP_PRIVATE, fd, 0);
110 return (p == (void *)(-1));
112 [sv_cv_func_mmap_devzero=yes],
113 [sv_cv_func_mmap_devzero=no],
115 dnl FIXME: Put in some more known values here.
117 freebsd* | irix* | linux* | osf* | solaris* | sunos4*)
118 sv_cv_func_mmap_devzero=yes ;;
120 sv_cv_func_mmap_devzero=no ;;
124 #include <sys/types.h>
125 #include <sys/mman.h>
129 ]], [[mmap (0, 0x10000, PROT_READ | PROT_WRITE, MAP_FILE | MAP_PRIVATE, 7, 0);]])],
130 [sv_cv_func_mmap_devzero="guessing yes"],
131 [sv_cv_func_mmap_devzero=no])
136 if test "$sv_cv_func_mmap_devzero" != no; then
137 AC_DEFINE([HAVE_MMAP_DEVZERO], [1],
138 [Define if mmaping of the special device /dev/zero works.])