Paul Gofman : ntdll: Use MAP_FIXED_NOREPLACE flag in try_map_free_area() if available.

Alexandre Julliard julliard at winehq.org
Mon Jul 13 16:08:50 CDT 2020


Module: wine
Branch: master
Commit: fdb3d9ae320363c1bd9fa716b167a7ad313e638b
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=fdb3d9ae320363c1bd9fa716b167a7ad313e638b

Author: Paul Gofman <pgofman at codeweavers.com>
Date:   Fri Jul 10 14:39:21 2020 +0300

ntdll: Use MAP_FIXED_NOREPLACE flag in try_map_free_area() if available.

Avoids actual mapping followed by unmapping back if the memory range is
already mapped.

Signed-off-by: Paul Gofman <pgofman at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/ntdll/unix/virtual.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/dlls/ntdll/unix/virtual.c b/dlls/ntdll/unix/virtual.c
index 20bf5ff066..63efb74382 100644
--- a/dlls/ntdll/unix/virtual.c
+++ b/dlls/ntdll/unix/virtual.c
@@ -175,6 +175,9 @@ static struct list teb_list = LIST_INIT( teb_list );
 #ifndef MAP_TRYFIXED
 #define MAP_TRYFIXED 0
 #endif
+#ifndef MAP_FIXED_NOREPLACE
+#define MAP_FIXED_NOREPLACE 0
+#endif
 
 #ifdef _WIN64  /* on 64-bit the page protection bytes use a 2-level table */
 static const size_t pages_vprot_shift = 20;
@@ -1005,18 +1008,19 @@ static void* try_map_free_area( void *base, void *end, ptrdiff_t step,
 
     while (start && base <= start && (char*)start + size <= (char*)end)
     {
-        if ((ptr = wine_anon_mmap( start, size, unix_prot, 0 )) == start)
+        if ((ptr = wine_anon_mmap( start, size, unix_prot, MAP_FIXED_NOREPLACE )) == start)
             return start;
         TRACE( "Found free area is already mapped, start %p.\n", start );
 
-        if (ptr == (void *)-1)
+        if (ptr == (void *)-1 && errno != EEXIST)
         {
             ERR( "wine_anon_mmap() error %s, range %p-%p, unix_prot %#x.\n",
                     strerror(errno), start, (char *)start + size, unix_prot );
             return NULL;
         }
 
-        munmap( ptr, size );
+        if (ptr != (void *)-1)
+            munmap( ptr, size );
 
         if ((step > 0 && (char *)end - (char *)start < step) ||
             (step < 0 && (char *)start - (char *)base < -step) ||




More information about the wine-cvs mailing list