Ken Thomases : libwine: On Mac, use a more capable Mach function to map memory and avoid calling mmap() in some cases.
Module: wine Branch: master Commit: 91d5d5674892028a4423a86b5c6b85f7d5758b12 URL: https://source.winehq.org/git/wine.git/?a=commit;h=91d5d5674892028a4423a86b5... Author: Ken Thomases <ken(a)codeweavers.com> Date: Wed Mar 6 18:59:37 2019 -0600 libwine: On Mac, use a more capable Mach function to map memory and avoid calling mmap() in some cases. Signed-off-by: Ken Thomases <ken(a)codeweavers.com> Signed-off-by: Alexandre Julliard <julliard(a)winehq.org> --- 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 458cc13..affdc0a 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 <mach/mach_init.h> -#include <mach/vm_map.h> +#include <mach/mach_vm.h> /* - * 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; }
participants (1)
-
Alexandre Julliard