From 3452cdd3c52a6aa6b0ead88e4d41b81b1b2e844b Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Wed, 10 Jan 2007 09:30:38 +0000 Subject: [PATCH] * mmap.cc (mmap64): Pre-Reserve space for the whole mapping to get a useful, valid address before the actual mappings take place. Fix typo in comment. --- winsup/cygwin/ChangeLog | 6 ++++++ winsup/cygwin/mmap.cc | 26 +++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index d34ab0e8f..b0b59447a 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,9 @@ +2007-01-10 Corinna Vinschen + + * mmap.cc (mmap64): Pre-Reserve space for the whole mapping to get a + useful, valid address before the actual mappings take place. + Fix typo in comment. + 2007-01-10 Corinna Vinschen * syscalls.cc (sync): Use b_drive for B: drive (Thanks to Howard Chu). diff --git a/winsup/cygwin/mmap.cc b/winsup/cygwin/mmap.cc index 14a09b5bd..76524e020 100644 --- a/winsup/cygwin/mmap.cc +++ b/winsup/cygwin/mmap.cc @@ -1217,6 +1217,28 @@ go_ahead: goto out; } + if (orig_len) + { + /* If the requested length is bigger than the file size, we try to + allocate an area of the full size first. This area is immediately + deallocated and the address we got is used as base address for the + subsequent real mappings. This ensures that we have enough space + for the whole thing. */ + orig_len = roundup2 (orig_len, pagesize); + addr = VirtualAlloc (addr, orig_len, MEM_TOP_DOWN | MEM_RESERVE, + PAGE_READWRITE); + if (!addr) + { + __seterrno (); + goto out; + } + if (!VirtualFree (addr, 0, MEM_RELEASE)) + { + __seterrno (); + goto out; + } + } + base = mmap_worker (fh, (caddr_t) addr, len, prot, flags, fd, off); if (!base) goto out; @@ -1225,7 +1247,7 @@ go_ahead: { /* If the requested length is bigger than the file size, the remainder is created as anonymous mapping. Actually two - mappings are created, first the reminder from the file end to + mappings are created, first the remainder from the file end to the next 64K boundary as accessible pages with the same protection as the file's pages, then as much pages as necessary to accomodate the requested length, but as reserved pages which @@ -1233,7 +1255,9 @@ go_ahead: and page protection on shared pages is only supported by 32 bit NT, so don't even try on 9x and in WOW64. This is accomplished by not setting orig_len on 9x and in WOW64 above. */ +#if 0 orig_len = roundup2 (orig_len, pagesize); +#endif len = roundup2 (len, getsystempagesize ()); if (orig_len - len) {