From 55ba3648379d90642f174e74809b84130d6d1ddc Mon Sep 17 00:00:00 2001 From: Damjan Jovanovic Date: Mon, 18 May 2020 21:04:58 +0200 Subject: [PATCH] libwine: Add support for mmap at fixed start addresses on FreeBSD. The way to implement MAP_TRYFIXED on FreeBSD is call mmap() with MAP_FIXED | MAP_EXCL, which will allocate the mapping from the exact starting address if possible, and if that fails, call mmap() again without them. This gets PE DLLs loading at their correct base addresses, and fixes a FreeBSD-specific problem with Cygwin's fork() caused by cygwin1.dll loading at different base addresses in the parent and child. Signed-off-by: Damjan Jovanovic Signed-off-by: Alexandre Julliard --- libs/wine/mmap.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/libs/wine/mmap.c b/libs/wine/mmap.c index f2b5adc1d29..0fbe2efea7c 100644 --- a/libs/wine/mmap.c +++ b/libs/wine/mmap.c @@ -211,18 +211,21 @@ void *wine_anon_mmap( void *start, size_t size, int prot, int flags ) if (!(flags & MAP_FIXED)) { -#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) - /* Even FreeBSD 5.3 does not properly support NULL here. */ - if( start == NULL ) start = (void *)0x110000; -#endif - #ifdef MAP_TRYFIXED /* If available, this will attempt a fixed mapping in-kernel */ flags |= MAP_TRYFIXED; +#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) + if ( start && mmap( start, size, prot, flags | MAP_FIXED | MAP_EXCL, get_fdzero(), 0 ) ) + return start; #elif defined(__svr4__) || defined(__NetBSD__) || defined(__APPLE__) if ( try_mmap_fixed( start, size, prot, flags, get_fdzero(), 0 ) ) return start; #endif + +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) + /* Even FreeBSD 5.3 does not properly support NULL here. */ + if( start == NULL ) start = (void *)0x110000; +#endif } return mmap( start, size, prot, flags, get_fdzero(), 0 ); }