Home | History | Annotate | Download | only in config
      1 dnl ----------------------------------------------------------------------
      2 dnl This whole bit snagged from gcc
      3 
      4 dnl
      5 dnl mmap(2) blacklisting.  Some platforms provide the mmap library routine
      6 dnl but don't support all of the features we need from it.
      7 dnl
      8 AC_DEFUN([GCC_AC_FUNC_MMAP_BLACKLIST],
      9 [
     10 AC_CHECK_HEADER([sys/mman.h],
     11 		[gcc_header_sys_mman_h=yes], [gcc_header_sys_mman_h=no])
     12 AC_CHECK_FUNC([mmap], [gcc_func_mmap=yes], [gcc_func_mmap=no])
     13 if test "$gcc_header_sys_mman_h" != yes \
     14  || test "$gcc_func_mmap" != yes; then
     15    gcc_cv_func_mmap_file=no
     16    gcc_cv_func_mmap_dev_zero=no
     17    gcc_cv_func_mmap_anon=no
     18 else
     19    AC_CACHE_CHECK([whether read-only mmap of a plain file works], 
     20   gcc_cv_func_mmap_file,
     21   [# Add a system to this blacklist if 
     22    # mmap(0, stat_size, PROT_READ, MAP_PRIVATE, fd, 0) doesn't return a
     23    # memory area containing the same data that you'd get if you applied
     24    # read() to the same fd.  The only system known to have a problem here
     25    # is VMS, where text files have record structure.
     26    case "$host_os" in
     27      *vms* | ultrix*)
     28         gcc_cv_func_mmap_file=no ;;
     29      *)
     30         gcc_cv_func_mmap_file=yes;;
     31    esac])
     32    AC_CACHE_CHECK([whether mmap from /dev/zero works],
     33   gcc_cv_func_mmap_dev_zero,
     34   [# Add a system to this blacklist if it has mmap() but /dev/zero
     35    # does not exist, or if mmapping /dev/zero does not give anonymous
     36    # zeroed pages with both the following properties:
     37    # 1. If you map N consecutive pages in with one call, and then
     38    #    unmap any subset of those pages, the pages that were not
     39    #    explicitly unmapped remain accessible.
     40    # 2. If you map two adjacent blocks of memory and then unmap them
     41    #    both at once, they must both go away.
     42    # Systems known to be in this category are Windows (all variants),
     43    # VMS, and Darwin.
     44    case "$host_os" in
     45      *vms* | cygwin* | pe | mingw* | darwin* | ultrix* | hpux10* | hpux11.00)
     46         gcc_cv_func_mmap_dev_zero=no ;;
     47      *)
     48         gcc_cv_func_mmap_dev_zero=yes;;
     49    esac])
     50 
     51    # Unlike /dev/zero, the MAP_ANON(YMOUS) defines can be probed for.
     52    AC_CACHE_CHECK([for MAP_ANON(YMOUS)], gcc_cv_decl_map_anon,
     53     [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
     54 [#include <sys/types.h>
     55 #include <sys/mman.h>
     56 #include <unistd.h>
     57 
     58 #ifndef MAP_ANONYMOUS
     59 #define MAP_ANONYMOUS MAP_ANON
     60 #endif
     61 ],
     62 [int n = MAP_ANONYMOUS;])],
     63     gcc_cv_decl_map_anon=yes,
     64     gcc_cv_decl_map_anon=no)])
     65 
     66    if test $gcc_cv_decl_map_anon = no; then
     67      gcc_cv_func_mmap_anon=no
     68    else
     69      AC_CACHE_CHECK([whether mmap with MAP_ANON(YMOUS) works],
     70      gcc_cv_func_mmap_anon,
     71   [# Add a system to this blacklist if it has mmap() and MAP_ANON or
     72    # MAP_ANONYMOUS, but using mmap(..., MAP_PRIVATE|MAP_ANONYMOUS, -1, 0)
     73    # doesn't give anonymous zeroed pages with the same properties listed
     74    # above for use of /dev/zero.
     75    # Systems known to be in this category are Windows, VMS, and SCO Unix.
     76    case "$host_os" in
     77      *vms* | cygwin* | pe | mingw* | sco* | udk* )
     78         gcc_cv_func_mmap_anon=no ;;
     79      *)
     80         gcc_cv_func_mmap_anon=yes;;
     81    esac])
     82    fi
     83 fi
     84 
     85 if test $gcc_cv_func_mmap_file = yes; then
     86   AC_DEFINE(HAVE_MMAP_FILE, 1,
     87 	    [Define if read-only mmap of a plain file works.])
     88 fi
     89 if test $gcc_cv_func_mmap_dev_zero = yes; then
     90   AC_DEFINE(HAVE_MMAP_DEV_ZERO, 1,
     91 	    [Define if mmap of /dev/zero works.])
     92 fi
     93 if test $gcc_cv_func_mmap_anon = yes; then
     94   AC_DEFINE(HAVE_MMAP_ANON, 1,
     95 	    [Define if mmap with MAP_ANON(YMOUS) works.])
     96 fi
     97 ])
     98