This is the mail archive of the cygwin-cvs@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[newlib-cygwin] cygwin: mmap: fix a fork failure with private, anonymous mappings


https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=67a657cb1d41e6ae90e9fdeba9e69fff09a2ea06

commit 67a657cb1d41e6ae90e9fdeba9e69fff09a2ea06
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Sun Dec 10 14:11:03 2017 +0100

    cygwin: mmap: fix a fork failure with private, anonymous mappings
    
    Rounddown incoming addr on a page boundary. Without this, we may end
    up with a fork error for private, anonymous maps.  The reason is, we
    use VirtualAlloc in this case which will potentially overcommit if
    addr is not on a page boundary.  This isn't taken into account in
    bookkeeping, but fixup_mmaps_after_fork will eventually stumble over
    this when trying to reproduce the copy-on-write pages: VirtualQuery
    returns a region reaching beyond the supposedly allocated address
    range and from there it goes downhill.
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/mmap.cc | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/winsup/cygwin/mmap.cc b/winsup/cygwin/mmap.cc
index 4218466..d4eddfc 100644
--- a/winsup/cygwin/mmap.cc
+++ b/winsup/cygwin/mmap.cc
@@ -917,6 +917,13 @@ mmap64 (void *addr, size_t len, int prot, int flags, int fd, off_t off)
       goto out;
     }
 
+  /* POSIX: When MAP_FIXED is not set, the implementation uses addr in an
+     implementation-defined manner to arrive at pa [the return address].
+     Given that we refuse addr if it's not exactly at a page boundary, we
+     can just make sure addr does so indiscriminately.  Just round down
+     to the next lower page boundary. */
+  addr = (void *) rounddown ((uintptr_t) addr, pagesize);
+
   if (!anonymous (flags) && fd != -1)
     {
       /* Ensure that fd is open */


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