autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Check for `mmap' fails on Cygwin/Windows


From: Alexandre Oliva
Subject: Re: Check for `mmap' fails on Cygwin/Windows
Date: 26 Oct 2000 07:03:51 -0200
User-agent: Gnus/5.0807 (Gnus v5.8.7) XEmacs/21.1 (Channel Islands)

On Oct 26, 2000, Corinna Vinschen <address@hidden> wrote:

> This isn't the problem I'm addressing. I'm talking about many
> existing packages which check for mmap and they all fail on
> Cygwin because of the usage of a depricated functionality.

Yep.  The problem is that the macro that is currently in autoconf was
borrowed from a package (GNU grep, IIRC) that actually depended on
MAP_FIXED.  We shouldn't just change its meaning.  We should have
never added such a specific macro with such a generic name.  It should
have always been called AC_FUNC_MMAP_FIXED, or something alike.  Maybe
it's time to rename it and make the original name a deprecated alias
that would be adjusted by autoupdate, so that we can easily add other
alternatives of MMAP later on.

> This is what I think is an error in autoconf _and_ in the packages
> which use the MAP_FIXED flag.

Agreed.  It's just the kind of error we can't just fix, because some
packages depend on its current behavior.

> No, it's the other way around. It fails due to the usage of MAP_FIXED
> so Cygwin is treated as having no mmap while it has.

Yep.  It just doesn't have the kind of mmap the test tests for.  It's
just the test macro that's mis-named, and misleads people into using
it for things other than its original purpose.  What you probably want
is something like GCC's AC_FUNC_MMAP_ANYWHERE and AC_FUNC_MMAP_FILE.
We might just steal those macros as part of the renaming of
AC_FUNC_MMAP.  Here they are, for the record:

# Check whether mmap can map an arbitrary page from /dev/zero or with
# MAP_ANONYMOUS, without MAP_FIXED.
AC_DEFUN([AC_FUNC_MMAP_ANYWHERE],
[AC_CHECK_HEADERS(unistd.h)
AC_CHECK_FUNCS(getpagesize)
AC_CACHE_CHECK(for working mmap which provides zeroed pages anywhere,
  ac_cv_func_mmap_anywhere,
[AC_TRY_RUN([
/* Test by Richard Henderson and Alexandre Oliva.
   Check whether mmap MAP_ANONYMOUS or mmap from /dev/zero works. */
#include <sys/types.h>
#include <fcntl.h>
#include <sys/mman.h>

#if !defined (MAP_ANONYMOUS) && defined (MAP_ANON)
# define MAP_ANONYMOUS MAP_ANON
#endif

/* This mess was copied from the GNU getpagesize.h.  */
#ifndef HAVE_GETPAGESIZE
# ifdef HAVE_UNISTD_H
#  include <unistd.h>
# endif

/* Assume that all systems that can run configure have sys/param.h.  */
# ifndef HAVE_SYS_PARAM_H
#  define HAVE_SYS_PARAM_H 1
# endif

# ifdef _SC_PAGESIZE
#  define getpagesize() sysconf(_SC_PAGESIZE)
# else /* no _SC_PAGESIZE */
#  ifdef HAVE_SYS_PARAM_H
#   include <sys/param.h>
#   ifdef EXEC_PAGESIZE
#    define getpagesize() EXEC_PAGESIZE
#   else /* no EXEC_PAGESIZE */
#    ifdef NBPG
#     define getpagesize() NBPG * CLSIZE
#     ifndef CLSIZE
#      define CLSIZE 1
#     endif /* no CLSIZE */
#    else /* no NBPG */
#     ifdef NBPC
#      define getpagesize() NBPC
#     else /* no NBPC */
#      ifdef PAGESIZE
#       define getpagesize() PAGESIZE
#      endif /* PAGESIZE */
#     endif /* no NBPC */
#    endif /* no NBPG */
#   endif /* no EXEC_PAGESIZE */
#  else /* no HAVE_SYS_PARAM_H */
#   define getpagesize() 8192   /* punt totally */
#  endif /* no HAVE_SYS_PARAM_H */
# endif /* no _SC_PAGESIZE */

#endif /* no HAVE_GETPAGESIZE */

int main()
{
  char *x;
  int fd, pg;

#ifndef MAP_ANONYMOUS
  fd = open("/dev/zero", O_RDWR);
  if (fd < 0)
    exit(1);
#endif

  pg = getpagesize();
#ifdef MAP_ANONYMOUS
  x = (char*)mmap(0, pg, PROT_READ|PROT_WRITE,
                  MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
#else
  x = (char*)mmap(0, pg, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
#endif
  if (x == (char *) -1)
    exit(2);

  *(int *)x += 1;

  if (munmap(x, pg) < 0)
    exit(3);

  exit(0);
}], ac_cv_func_mmap_anywhere=yes, ac_cv_func_mmap_anywhere=no,
ac_cv_func_mmap_anywhere=no)])
if test $ac_cv_func_mmap_anywhere = yes; then
  AC_DEFINE(HAVE_MMAP_ANYWHERE, 1,
            [Define if mmap can get us zeroed pages without MAP_FIXED.])
fi
])

# Check whether mmap can map a plain file, without MAP_FIXED.
AC_DEFUN([AC_FUNC_MMAP_FILE], 
[AC_REQUIRE([AC_FUNC_MMAP_ANYWHERE])dnl
AC_CACHE_CHECK(for working mmap of a file, ac_cv_func_mmap_file,
[# Create a file one thousand bytes long.
for i in 1 2 3 4 5 6 7 8 9 0
do for j in 1 2 3 4 5 6 7 8 9 0
do echo $i $j xxxxx
done
done > conftestdata$$

AC_TRY_RUN([
/* Test by Zack Weinberg.  Modified from MMAP_ANYWHERE test by
   Richard Henderson and Alexandre Oliva.
   Check whether read-only mmap of a plain file works. */
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>

int main()
{
  char *x;
  int fd;
  struct stat st;

  fd = open("conftestdata$$", O_RDONLY);
  if (fd < 0)
    exit(1);

  if (fstat (fd, &st))
    exit(2);

  x = (char*)mmap(0, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
  if (x == (char *) -1)
    exit(3);

  if (x[0] != '1' || x[1] != ' ' || x[2] != '1' || x[3] != ' ')
    exit(4);

  if (munmap(x, st.st_size) < 0)
    exit(5);

  exit(0);
}], ac_cv_func_mmap_file=yes, ac_cv_func_mmap_file=no,
ac_cv_func_mmap_file=no)])
if test $ac_cv_func_mmap_file = yes; then
  AC_DEFINE(HAVE_MMAP_FILE, 1,
            [Define if read-only mmap of a plain file works.])
fi
])

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  address@hidden, redhat.com}
CS PhD student at IC-Unicamp        address@hidden, gnu.org}
Free Software Evangelist    *Please* write to mailing lists, not to me



reply via email to

[Prev in Thread] Current Thread [Next in Thread]