mmap-anon.m4 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # mmap-anon.m4 serial 9
  2. dnl Copyright (C) 2005, 2007, 2009-2011 Free Software Foundation, Inc.
  3. dnl This file is free software; the Free Software Foundation
  4. dnl gives unlimited permission to copy and/or distribute it,
  5. dnl with or without modifications, as long as this notice is preserved.
  6. # Detect how mmap can be used to create anonymous (not file-backed) memory
  7. # mappings.
  8. # - On Linux, AIX, OSF/1, Solaris, Cygwin, Interix, Haiku, both MAP_ANONYMOUS
  9. # and MAP_ANON exist and have the same value.
  10. # - On HP-UX, only MAP_ANONYMOUS exists.
  11. # - On MacOS X, FreeBSD, NetBSD, OpenBSD, only MAP_ANON exists.
  12. # - On IRIX, neither exists, and a file descriptor opened to /dev/zero must be
  13. # used.
  14. AC_DEFUN([gl_FUNC_MMAP_ANON],
  15. [
  16. dnl Persuade glibc <sys/mman.h> to define MAP_ANONYMOUS.
  17. AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
  18. # Check for mmap(). Don't use AC_FUNC_MMAP, because it checks too much: it
  19. # fails on HP-UX 11, because MAP_FIXED mappings do not work. But this is
  20. # irrelevant for anonymous mappings.
  21. AC_CHECK_FUNC([mmap], [gl_have_mmap=yes], [gl_have_mmap=no])
  22. # Try to allow MAP_ANONYMOUS.
  23. gl_have_mmap_anonymous=no
  24. if test $gl_have_mmap = yes; then
  25. AC_MSG_CHECKING([for MAP_ANONYMOUS])
  26. AC_EGREP_CPP([I cant identify this map.], [
  27. #include <sys/mman.h>
  28. #ifdef MAP_ANONYMOUS
  29. I cant identify this map.
  30. #endif
  31. ],
  32. [gl_have_mmap_anonymous=yes])
  33. if test $gl_have_mmap_anonymous != yes; then
  34. AC_EGREP_CPP([I cant identify this map.], [
  35. #include <sys/mman.h>
  36. #ifdef MAP_ANON
  37. I cant identify this map.
  38. #endif
  39. ],
  40. [AC_DEFINE([MAP_ANONYMOUS], [MAP_ANON],
  41. [Define to a substitute value for mmap()'s MAP_ANONYMOUS flag.])
  42. gl_have_mmap_anonymous=yes])
  43. fi
  44. AC_MSG_RESULT([$gl_have_mmap_anonymous])
  45. if test $gl_have_mmap_anonymous = yes; then
  46. AC_DEFINE([HAVE_MAP_ANONYMOUS], [1],
  47. [Define to 1 if mmap()'s MAP_ANONYMOUS flag is available after including
  48. config.h and <sys/mman.h>.])
  49. fi
  50. fi
  51. ])