libwine: On Mac, disable ASLR for Wine processes.

ASLR can allow dyld to be loaded where it overlaps one of the regions that the
preloader would like to reserve.  That, in turn, can prevent Wine from using the
shared user data region.  With ASLR disabled, dyld will be loaded immediately
after the preloader, which has a defined base address.

This uses an Apple extension to posix_spawn() that allows it to replace the
calling process's image, like a more featureful execve().  The flag to disable
ASLR is technically private SPI, but has remained stable for many versions of
the OS.  And the Mac preloader is already stepping over that line.

Signed-off-by: Ken Thomases <ken@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Ken Thomases 2019-01-31 17:08:24 -06:00 committed by Alexandre Julliard
parent 6428c45667
commit ecd53057b5
1 changed files with 16 additions and 0 deletions

View File

@ -33,6 +33,13 @@
#ifdef HAVE_PWD_H
#include <pwd.h>
#endif
#ifdef __APPLE__
#include <crt_externs.h>
#include <spawn.h>
#ifndef _POSIX_SPAWN_DISABLE_ASLR
#define _POSIX_SPAWN_DISABLE_ASLR 0x0100
#endif
#endif
#include "wine/library.h"
static const char server_config_dir[] = "/.wine"; /* config dir relative to $HOME */
@ -558,6 +565,15 @@ static void preloader_exec( char **argv, int use_preloader )
new_argv = xmalloc( (last_arg - argv + 2) * sizeof(*argv) );
memcpy( new_argv + 1, argv, (last_arg - argv + 1) * sizeof(*argv) );
new_argv[0] = full_name;
#ifdef __APPLE__
{
posix_spawnattr_t attr;
posix_spawnattr_init( &attr );
posix_spawnattr_setflags( &attr, POSIX_SPAWN_SETEXEC | _POSIX_SPAWN_DISABLE_ASLR );
posix_spawn( NULL, full_name, NULL, &attr, new_argv, *_NSGetEnviron() );
posix_spawnattr_destroy( &attr );
}
#endif
execv( full_name, new_argv );
free( new_argv );
free( full_name );