Module: wine Branch: master Commit: 55ba3648379d90642f174e74809b84130d6d1ddc URL: https://source.winehq.org/git/wine.git/?a=commit;h=55ba3648379d90642f174e748...
Author: Damjan Jovanovic damjan.jov@gmail.com Date: Mon May 18 21:04:58 2020 +0200
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 damjan.jov@gmail.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
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 f2b5adc1d2..0fbe2efea7 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 ); }