File: mmap.m4

package info (click to toggle)
ffcall 2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 5,808 kB
  • sloc: asm: 43,409; ansic: 23,224; sh: 5,383; makefile: 1,517; cpp: 2
file content (140 lines) | stat: -rw-r--r-- 4,843 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
dnl -*- Autoconf -*-
dnl Copyright (C) 1993-2017 Free Software Foundation, Inc.
dnl This file is free software, distributed under the terms of the GNU
dnl General Public License as published by the Free Software Foundation;
dnl either version 2 of the License, or (at your option) any later version.
dnl As a special exception to the GNU General Public License, this file
dnl may be distributed as part of a program that contains a configuration
dnl script generated by Autoconf, under the same distribution terms as
dnl the rest of that program.

dnl From Bruno Haible, Marcus Daniels, Sam Steingold.

AC_PREREQ([2.57])

AC_DEFUN([FFCALL_MMAP],
[
  AC_REQUIRE([AC_CANONICAL_HOST])
  AC_CHECK_HEADER([sys/mman.h], [], [no_mmap=1])
  if test -z "$no_mmap"; then
    AC_CHECK_FUNC([mmap], [], [no_mmap=1])
    if test -z "$no_mmap"; then
      AC_DEFINE([HAVE_MMAP], [], [have <sys/mmap.h> and the mmap() function])
      AC_CACHE_CHECK([for working mmap], [ffcall_cv_func_mmap_works],
        [if test $cross_compiling = no; then
           mmap_prog_1='
             #include <stdlib.h>
             #ifdef HAVE_UNISTD_H
              #include <unistd.h>
             #endif
             #include <fcntl.h>
             #include <sys/types.h>
             #include <sys/mman.h>
             int main ()
             {
           '
           mmap_prog_2='
               if (mmap(NULL,0x100000,PROT_READ|PROT_WRITE,flags,fd,0) == (void*)-1)
                 exit(1);
               exit(0);
             }
           '
           AC_TRY_RUN(GL_NOCRASH
             [$mmap_prog_1
              int flags = MAP_ANON | MAP_PRIVATE;
              int fd = -1;
              nocrash_init();
              $mmap_prog_2
             ],
             [have_mmap_anon=1
              ffcall_cv_func_mmap_anon=yes],
             [],
             [dnl When cross-compiling, don't assume anything.
              :
             ])
           AC_TRY_RUN(GL_NOCRASH
             [$mmap_prog_1
              int flags = MAP_ANONYMOUS | MAP_PRIVATE;
              int fd = -1;
              nocrash_init();
              $mmap_prog_2
             ],
             [have_mmap_anon=1
              ffcall_cv_func_mmap_anonymous=yes],
             [],
             [dnl When cross-compiling, don't assume anything.
              :
             ])
           AC_TRY_RUN(GL_NOCRASH
             [$mmap_prog_1
              #ifndef MAP_FILE
               #define MAP_FILE 0
              #endif
              int flags = MAP_FILE | MAP_PRIVATE;
              int fd = open("/dev/zero",O_RDONLY,0666);
              if (fd<0)
                exit(1);
              nocrash_init();
              $mmap_prog_2
             ],
             [have_mmap_devzero=1
              ffcall_cv_func_mmap_devzero=yes],
             [],
             [dnl When cross-compiling, don't assume anything.
              :
             ])
           if test -n "$have_mmap_anon" -o -n "$have_mmap_devzero"; then
             ffcall_cv_func_mmap_works=yes
           else
             ffcall_cv_func_mmap_works=no
           fi
         else
           dnl When cross-compiling, assume the known behaviour.
           dnl If we don't know, don't assume anything.
           case "$host_os" in
             aix* | cygwin* | darwin* | hpux* | irix* | linux* | solaris*)
               ffcall_cv_func_mmap_works="guessing yes" ;;
             *)
               ffcall_cv_func_mmap_works="guessing no" ;;
           esac
           case "$host_os" in
             aix* | cygwin* | darwin* | linux* | solaris*)
               ffcall_cv_func_mmap_anon="guessing yes" ;;
             *)
               ffcall_cv_func_mmap_anon="guessing no" ;;
           esac
           case "$host_os" in
             aix* | cygwin* | hpux* | linux* | solaris*)
               ffcall_cv_func_mmap_anonymous="guessing yes" ;;
             *)
               ffcall_cv_func_mmap_anonymous="guessing no" ;;
           esac
           case "$host_os" in
             aix* | cygwin* | hpux* | irix* | linux* | solaris*)
               ffcall_cv_func_mmap_devzero="guessing yes" ;;
             *)
               ffcall_cv_func_mmap_devzero="guessing no" ;;
           esac
         fi
        ])
      case "$ffcall_cv_func_mmap_anon" in
        *yes)
          AC_DEFINE([HAVE_MMAP_ANON], [],
            [<sys/mman.h> defines MAP_ANON and mmaping with MAP_ANON works])
          ;;
      esac
      case "$ffcall_cv_func_mmap_anonymous" in
        *yes)
          AC_DEFINE([HAVE_MMAP_ANONYMOUS], [],
            [<sys/mman.h> defines MAP_ANONYMOUS and mmaping with MAP_ANONYMOUS works])
          ;;
      esac
      case "$ffcall_cv_func_mmap_devzero" in
        *yes)
          AC_DEFINE([HAVE_MMAP_DEVZERO], [],
            [mmaping of the special device /dev/zero works])
          ;;
      esac
    fi
  fi
])