diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2007-01-17 10:49:28 +0000 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2007-01-17 10:49:28 +0000 |
commit | 2f8578c316bfa80ac40e33c1716d63af45c8aeae (patch) | |
tree | 4e5ea61d6ecf14b9c2ce4aba366a3ecfcdc921e7 /winsup | |
parent | c46b24b2bfeaacd5d6099db65b5cb52d7773050f (diff) | |
download | newlib-2f8578c316bfa80ac40e33c1716d63af45c8aeae.zip newlib-2f8578c316bfa80ac40e33c1716d63af45c8aeae.tar.gz newlib-2f8578c316bfa80ac40e33c1716d63af45c8aeae.tar.bz2 |
* mmap.cc (MapView9x): Note possible uselessness of retrying.
(MapViewNT): Ditto.
(mmap64): Fix pre-reservation to work for non NULL, non MAP_FIXED.
Diffstat (limited to 'winsup')
-rw-r--r-- | winsup/cygwin/ChangeLog | 6 | ||||
-rw-r--r-- | winsup/cygwin/mmap.cc | 31 |
2 files changed, 29 insertions, 8 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index ec4d0ce..5f621f8 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,9 @@ +2007-01-17 Corinna Vinschen <corinna@vinschen.de> + + * mmap.cc (MapView9x): Note possible uselessness of retrying. + (MapViewNT): Ditto. + (mmap64): Fix pre-reservation to work for non NULL, non MAP_FIXED. + 2007-01-15 Corinna Vinschen <corinna@vinschen.de> * CYGWIN_LICENSE: Fix web pages and contact information. diff --git a/winsup/cygwin/mmap.cc b/winsup/cygwin/mmap.cc index 13eb8c9..8d068ac 100644 --- a/winsup/cygwin/mmap.cc +++ b/winsup/cygwin/mmap.cc @@ -328,7 +328,10 @@ MapView9x (HANDLE h, void *addr, size_t len, DWORD openflags, /* Try mapping using the given address first, even if it's NULL. If it failed, and addr was not NULL and flags is not MAP_FIXED, - try again with NULL address. */ + try again with NULL address. + + Note: Retrying the mapping might be unnecessary, now that mmap64 checks + for a valid memory area first. */ if (!addr) base = MapViewOfFile (h, access, high, low, len); else @@ -357,7 +360,10 @@ MapViewNT (HANDLE h, void *addr, size_t len, DWORD openflags, /* Try mapping using the given address first, even if it's NULL. If it failed, and addr was not NULL and flags is not MAP_FIXED, - try again with NULL address. */ + try again with NULL address. + + Note: Retrying the mapping might be unnecessary, now that mmap64 checks + for a valid memory area first. */ ret = NtMapViewOfSection (h, GetCurrentProcess (), &base, 0, commitsize, &offset, &viewsize, ViewShare, alloc_type, protect); if (!NT_SUCCESS (ret) && addr && !fixed (flags)) @@ -1205,18 +1211,27 @@ go_ahead: 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) + PVOID newaddr = VirtualAlloc (addr, orig_len, MEM_TOP_DOWN | MEM_RESERVE, + PAGE_READWRITE); + if (!newaddr) { - __seterrno (); - goto out; + /* If addr is not NULL, but MAP_FIXED isn't given, allow the OS + to choose. */ + if (addr && !fixed (flags)) + newaddr = VirtualAlloc (NULL, orig_len, MEM_TOP_DOWN | MEM_RESERVE, + PAGE_READWRITE); + if (!newaddr) + { + __seterrno (); + goto out; + } } - if (!VirtualFree (addr, 0, MEM_RELEASE)) + if (!VirtualFree (newaddr, 0, MEM_RELEASE)) { __seterrno (); goto out; } + addr = newaddr; } base = mmap_worker (fh, (caddr_t) addr, len, prot, flags, fd, off); |