This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

New Autoconf test: HAVE_MMAP_FILE


This patch adds a new test to configure, HAVE_MMAP_FILE.  It tests
whether you can set up a read-only, private mapping of a normal file
with no specified address.  This case is used by loadmsgcat.c and
fixincl.c, and will shortly be used by cpplib.

zw

	* aclocal.m4 (AM_GNU_GETTEXT): Don't AC_REQUIRE([AC_FUNC_MMAP]).
	(AC_FUNC_MMAP_FILE): New macro, tests read-only private map of
	a plain file.
	* configure.in: Call AC_FUNC_MMAP_FILE.
	* configure: Regenerate.
	* config.in: Regenerate.

	* intl/loadmsgcat.c: Test HAVE_MMAP_FILE not HAVE_MMAP.
	* fixinc/fixincl.c: Likewise.

===================================================================
Index: aclocal.m4
--- aclocal.m4	2000/01/16 18:49:31	1.21
+++ aclocal.m4	2000/04/05 02:31:13
@@ -503,7 +503,6 @@ AC_DEFUN(AM_GNU_GETTEXT,
    AC_REQUIRE([AC_TYPE_OFF_T])dnl
    AC_REQUIRE([AC_TYPE_SIZE_T])dnl
    AC_REQUIRE([AC_FUNC_ALLOCA])dnl
-   AC_REQUIRE([AC_FUNC_MMAP])dnl
 
    AC_CHECK_HEADERS([argz.h limits.h locale.h nl_types.h malloc.h string.h \
 unistd.h sys/param.h])
@@ -760,5 +759,57 @@ 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 from /dev/zero.])
+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
 ])
===================================================================
Index: configure.in
--- configure.in	2000/04/05 01:22:36	1.350
+++ configure.in	2000/04/05 02:31:14
@@ -398,6 +398,7 @@ case "${host}" in
 esac
 AC_FUNC_VFORK
 AC_FUNC_MMAP_ANYWHERE
+AC_FUNC_MMAP_FILE
 
 GCC_NEED_DECLARATIONS(bcopy bzero bcmp \
 	index rindex getenv atol sbrk abort atof getcwd getwd \
===================================================================
Index: intl/loadmsgcat.c
--- intl/loadmsgcat.c	1999/09/04 15:08:49	1.2
+++ intl/loadmsgcat.c	2000/04/05 02:31:14
@@ -31,7 +31,7 @@
 # include <unistd.h>
 #endif
 
-#if (defined HAVE_MMAP && defined HAVE_MUNMAP) || defined _LIBC
+#if defined HAVE_MMAP_FILE || defined _LIBC
 # include <sys/mman.h>
 #endif
 
@@ -68,7 +68,7 @@ _nl_load_domain (domain_file)
   size_t size;
   struct stat st;
   struct mo_file_header *data = (struct mo_file_header *) -1;
-#if (defined HAVE_MMAP && defined HAVE_MUNMAP && !defined DISALLOW_MMAP) \
+#if (defined HAVE_MMAP_FILE && !defined DISALLOW_MMAP) \
     || defined _LIBC
   int use_mmap = 0;
 #endif
@@ -99,7 +99,7 @@ _nl_load_domain (domain_file)
       return;
     }
 
-#if (defined HAVE_MMAP && defined HAVE_MUNMAP && !defined DISALLOW_MMAP) \
+#if (defined HAVE_MMAP_FILE && !defined DISALLOW_MMAP) \
     || defined _LIBC
   /* Now we are ready to load the file.  If mmap() is available we try
      this first.  If not available or it failed we try to load it.  */
@@ -149,7 +149,7 @@ _nl_load_domain (domain_file)
   if (data->magic != _MAGIC && data->magic != _MAGIC_SWAPPED)
     {
       /* The magic number is wrong: not a message catalog file.  */
-#if (defined HAVE_MMAP && defined HAVE_MUNMAP && !defined DISALLOW_MMAP) \
+#if (defined HAVE_MMAP_FILE && !defined DISALLOW_MMAP) \
     || defined _LIBC
       if (use_mmap)
 	munmap ((caddr_t) data, size);
@@ -166,7 +166,7 @@ _nl_load_domain (domain_file)
 
   domain = (struct loaded_domain *) domain_file->data;
   domain->data = (char *) data;
-#if (defined HAVE_MMAP && defined HAVE_MUNMAP && !defined DISALLOW_MMAP) \
+#if (defined HAVE_MMAP_FILE && !defined DISALLOW_MMAP) \
     || defined _LIBC
   domain->use_mmap = use_mmap;
 #endif
@@ -188,7 +188,7 @@ _nl_load_domain (domain_file)
       break;
     default:
       /* This is an illegal revision.  */
-#if (defined HAVE_MMAP && defined HAVE_MUNMAP && !defined DISALLOW_MMAP) \
+#if (defined HAVE_MMAP_FILE && !defined DISALLOW_MMAP) \
     || defined _LIBC
       if (use_mmap)
 	munmap ((caddr_t) data, size);
===================================================================
Index: fixinc/fixincl.c
--- fixinc/fixincl.c	2000/02/27 00:10:15	1.28
+++ fixinc/fixincl.c	2000/04/05 02:31:14
@@ -24,7 +24,7 @@ Boston, MA 02111-1307, USA.  */
 
 #include "fixlib.h"
 
-#if HAVE_MMAP
+#if HAVE_MMAP_FILE
 #include <sys/mman.h>
 #define  BAD_ADDR ((void*)-1)
 #endif
@@ -136,7 +136,7 @@ int fixed_ct = 0;
 int altered_ct = 0;
 #endif /* DO_STATS */
 
-#ifdef HAVE_MMAP
+#ifdef HAVE_MMAP_FILE
 #define UNLOAD_DATA() do { if (curr_data_mapped) { \
   munmap ((void*)pz_curr_data, data_map_size); close (data_map_fd); } \
   else free ((void*)pz_curr_data); } while(0)
@@ -510,7 +510,7 @@ load_file ( fname )
       return (char*)NULL;
     }
 
-#ifdef HAVE_MMAP
+#ifdef HAVE_MMAP_FILE
   curr_data_mapped = BOOL_TRUE;
   res = (char*)mmap ((void*)NULL, data_map_size, PROT_READ, MAP_PRIVATE,
                      data_map_fd, 0);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]