From 4c5f9c091bafaadd8d80edc417e8c42b4b20fd56 Mon Sep 17 00:00:00 2001 From: Wolfgang Thaller Date: Mon, 20 Jun 2005 11:43:47 +0000 Subject: [PATCH] Implement try_mmap_fixed for Darwin. --- libs/wine/mmap.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/libs/wine/mmap.c b/libs/wine/mmap.c index a2528821886..335e1489705 100644 --- a/libs/wine/mmap.c +++ b/libs/wine/mmap.c @@ -137,6 +137,28 @@ static int try_mmap_fixed (void *addr, size_t len, int prot, int flags, return result == addr; } + +#elif defined(__APPLE__) + +/* + * 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. + */ +static int try_mmap_fixed (void *addr, size_t len, int prot, int flags, + int fildes, off_t off) +{ + void *result; + result = addr; + if(vm_allocate(mach_task_self(),&result,len,0)) + return 0; + else + { + result = mmap( addr, len, prot, flags | MAP_FIXED, fildes, off ); + return result == addr; + } +} + #endif /* (__svr4__ || __NetBSD__) && !MAP_TRYFIXED */ @@ -182,7 +204,7 @@ void *wine_anon_mmap( void *start, size_t size, int prot, int flags ) #ifdef MAP_TRYFIXED /* If available, this will attempt a fixed mapping in-kernel */ flags |= MAP_TRYFIXED; -#elif defined(__svr4__) || defined(__NetBSD__) +#elif defined(__svr4__) || defined(__NetBSD__) || defined(__APPLE__) if ( try_mmap_fixed( start, size, prot, flags, fdzero, 0 ) ) return start; #endif -- 2.11.4.GIT