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>
This commit is contained in:
Damjan Jovanovic 2020-05-18 21:04:58 +02:00 committed by Alexandre Julliard
parent b9dc3324d7
commit 55ba364837
1 changed files with 8 additions and 5 deletions

View File

@ -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 );
}