From 91d5d5674892028a4423a86b5c6b85f7d5758b12 Mon Sep 17 00:00:00 2001 From: Ken Thomases Date: Wed, 6 Mar 2019 18:59:37 -0600 Subject: [PATCH] libwine: On Mac, use a more capable Mach function to map memory and avoid calling mmap() in some cases. Signed-off-by: Ken Thomases Signed-off-by: Alexandre Julliard --- libs/wine/mmap.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/libs/wine/mmap.c b/libs/wine/mmap.c index 458cc132b5a..affdc0a0cf1 100644 --- a/libs/wine/mmap.c +++ b/libs/wine/mmap.c @@ -165,23 +165,29 @@ static int try_mmap_fixed (void *addr, size_t len, int prot, int flags, #elif defined(__APPLE__) #include -#include +#include /* - * On Darwin, we can use the Mach call vm_allocate to allocate - * anonymous memory at the specified address, and then use mmap with - * MAP_FIXED to replace the mapping. + * On Darwin, we can use the Mach call mach_vm_map to allocate + * anonymous memory at the specified address and then, if necessary, use + * mmap with MAP_FIXED to replace the mapping. */ static int try_mmap_fixed (void *addr, size_t len, int prot, int flags, int fildes, off_t off) { - vm_address_t result = (vm_address_t)addr; + mach_vm_address_t result = (mach_vm_address_t)addr; + int vm_flags = VM_FLAGS_FIXED; - if (!vm_allocate(mach_task_self(),&result,len,0)) + if (flags & MAP_NOCACHE) + vm_flags |= VM_FLAGS_NO_CACHE; + if (!mach_vm_map( mach_task_self(), &result, len, 0, vm_flags, MEMORY_OBJECT_NULL, + 0, 0, prot, VM_PROT_ALL, VM_INHERIT_COPY )) { - if (mmap( (void *)result, len, prot, flags | MAP_FIXED, fildes, off ) != MAP_FAILED) + flags |= MAP_FIXED; + if (((flags & ~(MAP_NORESERVE | MAP_NOCACHE)) == (MAP_ANON | MAP_FIXED | MAP_PRIVATE)) || + mmap( (void *)result, len, prot, flags, fildes, off ) != MAP_FAILED) return 1; - vm_deallocate(mach_task_self(),result,len); + mach_vm_deallocate(mach_task_self(),result,len); } return 0; }