Broken autoconf mmap test

Corinna Vinschen corinna-cygwin@cygwin.com
Fri Mar 25 10:17:00 GMT 2011


On Mar 25 10:34, Corinna Vinschen wrote:
> If you guys think that cheating for autoconf on 64 bit systems is a good
> idea, I'm willing to implement it.

Here's a patch which works fine for me:

Index: mmap.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/mmap.cc,v
retrieving revision 1.166
diff -u -p -r1.166 mmap.cc
--- mmap.cc	18 Mar 2011 13:56:56 -0000	1.166
+++ mmap.cc	25 Mar 2011 10:17:09 -0000
@@ -801,6 +801,38 @@ mmap64 (void *addr, size_t len, int prot
       /* mmap /dev/zero is like MAP_ANONYMOUS. */
       if (fh->get_device () == FH_ZERO)
 	flags |= MAP_ANONYMOUS;
+
+      /* The autoconf mmap test maps a file of size 1 byte.  It then tests
+	 every byte of the entire mapped page of 64K for 0-bytes since that's
+	 what POSIX requires.  The problem is, we can't create that mapping on
+	 64 bit systems.  The file mapping will be only a single page, 4K, and
+	 since 64 bit systems don't support the AT_ROUND_TO_PAGE flag, the
+	 remainder of the 64K slot will result in a SEGV when accessed.
+
+	 So, what we do here is cheating for autoconf.  We know exactly what
+	 autoconf is doing.  The file is called conftest.txt, it has a size of
+	 1 byte, the requested mapping size is 64K, the requested protection
+	 is PROT_READ | PROT_WRITE, the mapping is MAP_SHARED, the offset is 0.
+
+	 If all these requirements are given, we just return an anonymous map
+	 of 64K.  This will help to get over the autoconf test even on 64 bit
+	 systems. */
+      if (wincap.is_wow64 ())
+	{
+	  UNICODE_STRING fname;
+	  unsigned long long fsize = fh->pc.fs_is_nfs ()
+				     ? fh->pc.nfsattr ()->size
+				     : fh->pc.fnoi ()->EndOfFile.QuadPart;
+
+	  RtlSplitUnicodePath (fh->pc.get_nt_native_path (), NULL, &fname);
+	  if (wcscmp (fname.Buffer, L"conftest.txt") == 0
+	      && fsize == 1LL
+	      && len == pagesize
+	      && prot == (PROT_READ | PROT_WRITE)
+	      && flags == MAP_SHARED
+	      && off == 0)
+	    flags |= MAP_ANONYMOUS;
+	}
     }
 
   if (anonymous (flags) || fd == -1)


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat



More information about the Cygwin-developers mailing list