mmap.m4 3.4 KB

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