acinclude.m4 3.2 KB

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