File: mmap-anon.m4

package info (click to toggle)
gnu-smalltalk 3.1-6
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 33,300 kB
  • ctags: 13,999
  • sloc: ansic: 88,106; sh: 23,223; asm: 7,889; perl: 4,493; cpp: 3,539; awk: 1,483; yacc: 1,355; xml: 1,272; makefile: 1,192; lex: 843; sed: 258; objc: 124
file content (136 lines) | stat: -rw-r--r-- 4,074 bytes parent folder | download | duplicates (10)
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
# mmap-anon.m4 serial 2 (libsigsegv-2.2)
dnl Copyright (C) 2002-2003 Bruno Haible <bruno@clisp.org>
dnl This file is free software, distributed under the terms of the GNU
dnl General Public License.  As a special exception to the GNU General
dnl Public License, this file may be distributed as part of a program
dnl that contains a configuration script generated by Autoconf, under
dnl the same distribution terms as the rest of that program.

# How to allocate fresh memory using mmap.
AC_DEFUN([SV_MMAP_ANON],
[
  AC_REQUIRE([AC_PROG_CC])
  AC_REQUIRE([AC_CANONICAL_HOST])

  dnl 1) MAP_ANON

  AC_CACHE_CHECK([for mmap with MAP_ANON], sv_cv_func_mmap_anon, [
    AC_RUN_IFELSE([
      AC_LANG_SOURCE([[
#include <sys/types.h>
#include <sys/mman.h>
int main ()
{
  void *p = mmap (0, 0x10000, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
  return (p == (void *)(-1));
}]])],
      [sv_cv_func_mmap_anon=yes],
      [sv_cv_func_mmap_anon=no],
      [
        dnl FIXME: Put in some more known values here.
        case "$host_os" in
          freebsd* | linux* | osf*)
            sv_cv_func_mmap_anon=yes ;;
          *)
            AC_LINK_IFELSE([
              AC_LANG_PROGRAM([[
#include <sys/types.h>
#include <sys/mman.h>
]],
                [[mmap (0, 0x10000, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);]])],
              [sv_cv_func_mmap_anon="guessing yes"],
              [sv_cv_func_mmap_anon=no])
            ;;
        esac
      ])
  ])
  if test "$sv_cv_func_mmap_anon" != no; then
    AC_DEFINE(HAVE_MMAP_ANON, 1,
      [Define if <sys/mman.h> defines MAP_ANON and mmaping with MAP_ANON works.])
  fi

  dnl 2) MAP_ANONYMOUS

  AC_CACHE_CHECK([for mmap with MAP_ANONYMOUS], sv_cv_func_mmap_anonymous, [
    AC_RUN_IFELSE([
      AC_LANG_SOURCE([[
#include <sys/types.h>
#include <sys/mman.h>
int main ()
{
  void *p = mmap (0, 0x10000, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
  return (p == (void *)(-1));
}]])],
      [sv_cv_func_mmap_anonymous=yes],
      [sv_cv_func_mmap_anonymous=no],
      [
        dnl FIXME: Put in some more known values here.
        case "$host_os" in
          hpux* | linux* | osf*)
            sv_cv_func_mmap_anonymous=yes ;;
          *)
            AC_LINK_IFELSE([
              AC_LANG_PROGRAM([[
#include <sys/types.h>
#include <sys/mman.h>
]],
                [[mmap (0, 0x10000, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);]])],
              [sv_cv_func_mmap_anonymous="guessing yes"],
              [sv_cv_func_mmap_anonymous=no])
            ;;
        esac
      ])
  ])
  if test "$sv_cv_func_mmap_anonymous" != no; then
    AC_DEFINE(HAVE_MMAP_ANONYMOUS, 1,
      [Define if <sys/mman.h> defines MAP_ANONYMOUS and mmaping with MAP_ANONYMOUS
   works.])
  fi

  dnl 3) MAP_FILE of /dev/zero

  AC_CACHE_CHECK([for mmap of /dev/zero], sv_cv_func_mmap_devzero, [
    AC_RUN_IFELSE([
      AC_LANG_SOURCE([[
#include <sys/types.h>
#include <sys/mman.h>
#include <fcntl.h>
#ifndef MAP_FILE
#define MAP_FILE 0
#endif
int main ()
{
  int fd;
  void *p;
  fd = open ("/dev/zero", O_RDONLY, 0666);
  if (fd < 0) return 1;
  p = mmap (0, 0x10000, PROT_READ | PROT_WRITE, MAP_FILE | MAP_PRIVATE, fd, 0);
  return (p == (void *)(-1));
}]])],
      [sv_cv_func_mmap_devzero=yes],
      [sv_cv_func_mmap_devzero=no],
      [
        dnl FIXME: Put in some more known values here.
        case "$host_os" in
          freebsd* | irix* | linux* | osf* | solaris* | sunos4*)
            sv_cv_func_mmap_devzero=yes ;;
          *)
            AC_LINK_IFELSE([
              AC_LANG_PROGRAM([[
#include <sys/types.h>
#include <sys/mman.h>
#ifndef MAP_FILE
#define MAP_FILE 0
#endif
]], [[mmap (0, 0x10000, PROT_READ | PROT_WRITE, MAP_FILE | MAP_PRIVATE, 7, 0);]])],
              [sv_cv_func_mmap_devzero="guessing yes"],
              [sv_cv_func_mmap_devzero=no])
            ;;
        esac
      ])
  ])
  if test "$sv_cv_func_mmap_devzero" != no; then
    AC_DEFINE(HAVE_MMAP_DEVZERO, 1,
      [Define if mmaping of the special device /dev/zero works.])
  fi
])