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@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Paul Gofman 2020-07-10 14:39:21 +03:00 committed by Alexandre Julliard
parent 5498ebd8c0
commit fdb3d9ae32
1 changed files with 7 additions and 3 deletions

View File

@ -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) ||