[PATCH 2/2] libwine: add support for mmap at fixed start addresses on FreeBSD

Damjan Jovanovic damjan.jov at gmail.com
Mon May 18 14:04:58 CDT 2020


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 at gmail.com>
---
 libs/wine/mmap.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
-------------- next part --------------
diff --git a/libs/wine/mmap.c b/libs/wine/mmap.c
index 6bcd15619c..e167c782d3 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 );
 }


More information about the wine-devel mailing list