Add installation information for the tarball users and from a git checkout.
[libsigsegv.git] / m4 / mmap-anon.m4
blobc4620898ba3fe8257db6c09855deeccbe5770159
1 # mmap-anon.m4
2 # serial 5 (libsigsegv-2.15)
3 dnl Copyright (C) 2002-2024 Bruno Haible <bruno@clisp.org>
4 dnl This file is free software, distributed under the terms of the GNU
5 dnl General Public License as published by the Free Software Foundation;
6 dnl either version 2 of the License, or (at your option) any later version.
7 dnl As a special exception to the GNU General Public License, this file
8 dnl may be distributed as part of a program that contains a configuration
9 dnl script generated by Autoconf, under the same distribution terms as
10 dnl the rest of that program.
12 # How to allocate fresh memory using mmap.
13 AC_DEFUN([SV_MMAP_ANON],
15   AC_REQUIRE([AC_PROG_CC])
16   AC_REQUIRE([AC_CANONICAL_HOST])
18   dnl 1) MAP_ANON
20   AC_CACHE_CHECK([for mmap with MAP_ANON], [sv_cv_func_mmap_anon], [
21     AC_RUN_IFELSE([
22       AC_LANG_SOURCE([[
23 #include <sys/types.h>
24 #include <sys/mman.h>
25 int main ()
27   void *p = mmap (0, 0x10000, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
28   return (p == (void *)(-1));
29 }]])],
30       [sv_cv_func_mmap_anon=yes],
31       [sv_cv_func_mmap_anon=no],
32       [
33         dnl FIXME: Put in some more known values here.
34         case "$host_os" in
35           freebsd* | linux* | osf* | darwin*)
36             sv_cv_func_mmap_anon=yes ;;
37           *)
38             AC_LINK_IFELSE([
39               AC_LANG_PROGRAM([[
40 #include <sys/types.h>
41 #include <sys/mman.h>
42 ]],
43                 [[mmap (0, 0x10000, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);]])],
44               [sv_cv_func_mmap_anon="guessing yes"],
45               [sv_cv_func_mmap_anon=no])
46             ;;
47         esac
48       ])
49   ])
50   if test "$sv_cv_func_mmap_anon" != no; then
51     AC_DEFINE([HAVE_MMAP_ANON], [1],
52       [Define if <sys/mman.h> defines MAP_ANON and mmaping with MAP_ANON works.])
53   fi
55   dnl 2) MAP_ANONYMOUS
57   AC_CACHE_CHECK([for mmap with MAP_ANONYMOUS], [sv_cv_func_mmap_anonymous], [
58     AC_RUN_IFELSE([
59       AC_LANG_SOURCE([[
60 #include <sys/types.h>
61 #include <sys/mman.h>
62 int main ()
64   void *p = mmap (0, 0x10000, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
65   return (p == (void *)(-1));
66 }]])],
67       [sv_cv_func_mmap_anonymous=yes],
68       [sv_cv_func_mmap_anonymous=no],
69       [
70         dnl FIXME: Put in some more known values here.
71         case "$host_os" in
72           hpux* | linux* | osf*)
73             sv_cv_func_mmap_anonymous=yes ;;
74           darwin*)
75             sv_cv_func_mmap_anonymous=no ;;
76           *)
77             AC_LINK_IFELSE([
78               AC_LANG_PROGRAM([[
79 #include <sys/types.h>
80 #include <sys/mman.h>
81 ]],
82                 [[mmap (0, 0x10000, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);]])],
83               [sv_cv_func_mmap_anonymous="guessing yes"],
84               [sv_cv_func_mmap_anonymous=no])
85             ;;
86         esac
87       ])
88   ])
89   if test "$sv_cv_func_mmap_anonymous" != no; then
90     AC_DEFINE([HAVE_MMAP_ANONYMOUS], [1],
91       [Define if <sys/mman.h> defines MAP_ANONYMOUS and mmaping with MAP_ANONYMOUS
92    works.])
93   fi
95   dnl 3) MAP_FILE of /dev/zero
97   AC_CACHE_CHECK([for mmap of /dev/zero], [sv_cv_func_mmap_devzero], [
98     AC_RUN_IFELSE([
99       AC_LANG_SOURCE([[
100 #include <sys/types.h>
101 #include <sys/mman.h>
102 #include <fcntl.h>
103 #ifndef MAP_FILE
104 #define MAP_FILE 0
105 #endif
106 int main ()
108   int fd;
109   void *p;
110   fd = open ("/dev/zero", O_RDONLY, 0666);
111   if (fd < 0) return 1;
112   p = mmap (0, 0x10000, PROT_READ | PROT_WRITE, MAP_FILE | MAP_PRIVATE, fd, 0);
113   return (p == (void *)(-1));
114 }]])],
115       [sv_cv_func_mmap_devzero=yes],
116       [sv_cv_func_mmap_devzero=no],
117       [
118         dnl FIXME: Put in some more known values here.
119         case "$host_os" in
120           freebsd* | irix* | linux* | osf* | solaris* | sunos4*)
121             sv_cv_func_mmap_devzero=yes ;;
122           darwin*)
123             sv_cv_func_mmap_devzero=no ;;
124           *)
125             AC_LINK_IFELSE([
126               AC_LANG_PROGRAM([[
127 #include <sys/types.h>
128 #include <sys/mman.h>
129 #ifndef MAP_FILE
130 #define MAP_FILE 0
131 #endif
132 ]], [[mmap (0, 0x10000, PROT_READ | PROT_WRITE, MAP_FILE | MAP_PRIVATE, 7, 0);]])],
133               [sv_cv_func_mmap_devzero="guessing yes"],
134               [sv_cv_func_mmap_devzero=no])
135             ;;
136         esac
137       ])
138   ])
139   if test "$sv_cv_func_mmap_devzero" != no; then
140     AC_DEFINE([HAVE_MMAP_DEVZERO], [1],
141       [Define if mmaping of the special device /dev/zero works.])
142   fi