Avoids actual mapping followed by unmapping back if the memory range is already mapped.
Signed-off-by: Paul Gofman pgofman@codeweavers.com --- dlls/ntdll/unix/virtual.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/dlls/ntdll/unix/virtual.c b/dlls/ntdll/unix/virtual.c index 5636d1b5f8d..3f74a34001f 100644 --- a/dlls/ntdll/unix/virtual.c +++ b/dlls/ntdll/unix/virtual.c @@ -1001,22 +1001,28 @@ static struct wine_rb_entry *find_view_inside_range( void **base_ptr, void **end static void* try_map_free_area( void *base, void *end, ptrdiff_t step, void *start, size_t size, int unix_prot ) { +#ifdef MAP_FIXED_NOREPLACE + static const int flags = MAP_FIXED_NOREPLACE; +#else + static const int flags = 0; +#endif void *ptr;
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, flags )) == 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) ||