Create a huge array in bss to reserve the memory area we need for PE
binaries, to prevent exec shield from mapping system libraries there.
This commit is contained in:
parent
33f9dcb1f9
commit
c6d44be3e5
109
configure
vendored
109
configure
vendored
@ -12360,57 +12360,7 @@ echo "${ECHO_T}$ac_cv_c_dll_zdefs" >&6
|
|||||||
then
|
then
|
||||||
LDDLL="$LDDLL,-z,defs"
|
LDDLL="$LDDLL,-z,defs"
|
||||||
fi
|
fi
|
||||||
echo "$as_me:$LINENO: checking whether we can relocate the executable to 0x3c000000" >&5
|
|
||||||
echo $ECHO_N "checking whether we can relocate the executable to 0x3c000000... $ECHO_C" >&6
|
|
||||||
if test "${ac_cv_ld_reloc_exec+set}" = set; then
|
|
||||||
echo $ECHO_N "(cached) $ECHO_C" >&6
|
|
||||||
else
|
|
||||||
saved_CFLAGS="$CFLAGS"
|
|
||||||
CFLAGS="$CFLAGS -Wl,--section-start,.interp=0x3c000100"
|
|
||||||
if test "$cross_compiling" = yes; then
|
|
||||||
ac_cv_ld_reloc_exec="no"
|
|
||||||
else
|
|
||||||
cat >conftest.$ac_ext <<_ACEOF
|
|
||||||
#line $LINENO "configure"
|
|
||||||
/* confdefs.h. */
|
|
||||||
_ACEOF
|
|
||||||
cat confdefs.h >>conftest.$ac_ext
|
|
||||||
cat >>conftest.$ac_ext <<_ACEOF
|
|
||||||
/* end confdefs.h. */
|
|
||||||
#include <unistd.h>
|
|
||||||
int main() { return (sbrk(32*1024*1024) == (void *)-1); }
|
|
||||||
_ACEOF
|
|
||||||
rm -f conftest$ac_exeext
|
|
||||||
if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
|
|
||||||
(eval $ac_link) 2>&5
|
|
||||||
ac_status=$?
|
|
||||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
|
||||||
(exit $ac_status); } && { ac_try='./conftest$ac_exeext'
|
|
||||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
|
||||||
(eval $ac_try) 2>&5
|
|
||||||
ac_status=$?
|
|
||||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
|
||||||
(exit $ac_status); }; }; then
|
|
||||||
ac_cv_ld_reloc_exec="yes"
|
|
||||||
else
|
|
||||||
echo "$as_me: program exited with status $ac_status" >&5
|
|
||||||
echo "$as_me: failed program was:" >&5
|
|
||||||
sed 's/^/| /' conftest.$ac_ext >&5
|
|
||||||
|
|
||||||
( exit $ac_status )
|
|
||||||
ac_cv_ld_reloc_exec="no"
|
|
||||||
fi
|
|
||||||
rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
|
|
||||||
fi
|
|
||||||
CFLAGS="$saved_CFLAGS"
|
|
||||||
fi
|
|
||||||
echo "$as_me:$LINENO: result: $ac_cv_ld_reloc_exec" >&5
|
|
||||||
echo "${ECHO_T}$ac_cv_ld_reloc_exec" >&6
|
|
||||||
if test "$ac_cv_ld_reloc_exec" = "yes"
|
|
||||||
then
|
|
||||||
LDEXECFLAGS="-Wl,--section-start,.interp=0x3c000100"
|
|
||||||
|
|
||||||
fi
|
|
||||||
echo "$as_me:$LINENO: checking whether the linker accepts --export-dynamic" >&5
|
echo "$as_me:$LINENO: checking whether the linker accepts --export-dynamic" >&5
|
||||||
echo $ECHO_N "checking whether the linker accepts --export-dynamic... $ECHO_C" >&6
|
echo $ECHO_N "checking whether the linker accepts --export-dynamic... $ECHO_C" >&6
|
||||||
if test "${ac_cv_c_export_dynamic+set}" = set; then
|
if test "${ac_cv_c_export_dynamic+set}" = set; then
|
||||||
@ -12460,8 +12410,65 @@ echo "$as_me:$LINENO: result: $ac_cv_c_export_dynamic" >&5
|
|||||||
echo "${ECHO_T}$ac_cv_c_export_dynamic" >&6
|
echo "${ECHO_T}$ac_cv_c_export_dynamic" >&6
|
||||||
if test "$ac_cv_c_export_dynamic" = "yes"
|
if test "$ac_cv_c_export_dynamic" = "yes"
|
||||||
then
|
then
|
||||||
LDEXECFLAGS="$LDEXECFLAGS -Wl,--export-dynamic"
|
LDEXECFLAGS="-Wl,--export-dynamic"
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
case $host_cpu in
|
||||||
|
*i[3456789]86*)
|
||||||
|
echo "$as_me:$LINENO: checking whether we can relocate the executable to 0x00110000" >&5
|
||||||
|
echo $ECHO_N "checking whether we can relocate the executable to 0x00110000... $ECHO_C" >&6
|
||||||
|
if test "${ac_cv_ld_reloc_exec+set}" = set; then
|
||||||
|
echo $ECHO_N "(cached) $ECHO_C" >&6
|
||||||
|
else
|
||||||
|
saved_CFLAGS="$CFLAGS"
|
||||||
|
CFLAGS="$CFLAGS -Wl,--section-start,.interp=0x00110400"
|
||||||
|
if test "$cross_compiling" = yes; then
|
||||||
|
ac_cv_ld_reloc_exec="no"
|
||||||
|
else
|
||||||
|
cat >conftest.$ac_ext <<_ACEOF
|
||||||
|
#line $LINENO "configure"
|
||||||
|
/* confdefs.h. */
|
||||||
|
_ACEOF
|
||||||
|
cat confdefs.h >>conftest.$ac_ext
|
||||||
|
cat >>conftest.$ac_ext <<_ACEOF
|
||||||
|
/* end confdefs.h. */
|
||||||
|
#include <unistd.h>
|
||||||
|
int main() { return (sbrk(32*1024*1024) == (void *)-1); }
|
||||||
|
_ACEOF
|
||||||
|
rm -f conftest$ac_exeext
|
||||||
|
if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
|
||||||
|
(eval $ac_link) 2>&5
|
||||||
|
ac_status=$?
|
||||||
|
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||||
|
(exit $ac_status); } && { ac_try='./conftest$ac_exeext'
|
||||||
|
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||||
|
(eval $ac_try) 2>&5
|
||||||
|
ac_status=$?
|
||||||
|
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||||
|
(exit $ac_status); }; }; then
|
||||||
|
ac_cv_ld_reloc_exec="yes"
|
||||||
|
else
|
||||||
|
echo "$as_me: program exited with status $ac_status" >&5
|
||||||
|
echo "$as_me: failed program was:" >&5
|
||||||
|
sed 's/^/| /' conftest.$ac_ext >&5
|
||||||
|
|
||||||
|
( exit $ac_status )
|
||||||
|
ac_cv_ld_reloc_exec="no"
|
||||||
|
fi
|
||||||
|
rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
|
||||||
|
fi
|
||||||
|
CFLAGS="$saved_CFLAGS"
|
||||||
|
fi
|
||||||
|
echo "$as_me:$LINENO: result: $ac_cv_ld_reloc_exec" >&5
|
||||||
|
echo "${ECHO_T}$ac_cv_ld_reloc_exec" >&6
|
||||||
|
if test "$ac_cv_ld_reloc_exec" = "yes"
|
||||||
|
then
|
||||||
|
LDEXECFLAGS="$LDEXECFLAGS -Wl,--section-start,.interp=0x00110400"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
else
|
else
|
||||||
echo "$as_me:$LINENO: checking whether we can build a UnixWare (Solaris) dll" >&5
|
echo "$as_me:$LINENO: checking whether we can build a UnixWare (Solaris) dll" >&5
|
||||||
echo $ECHO_N "checking whether we can build a UnixWare (Solaris) dll... $ECHO_C" >&6
|
echo $ECHO_N "checking whether we can build a UnixWare (Solaris) dll... $ECHO_C" >&6
|
||||||
|
33
configure.ac
33
configure.ac
@ -882,26 +882,31 @@ case $host_os in
|
|||||||
then
|
then
|
||||||
LDDLL="$LDDLL,-z,defs"
|
LDDLL="$LDDLL,-z,defs"
|
||||||
fi
|
fi
|
||||||
AC_CACHE_CHECK([whether we can relocate the executable to 0x3c000000], ac_cv_ld_reloc_exec,
|
|
||||||
[saved_CFLAGS="$CFLAGS"
|
|
||||||
CFLAGS="$CFLAGS -Wl,--section-start,.interp=0x3c000100"
|
|
||||||
AC_TRY_RUN([#include <unistd.h>
|
|
||||||
int main() { return (sbrk(32*1024*1024) == (void *)-1); }],
|
|
||||||
ac_cv_ld_reloc_exec="yes",
|
|
||||||
ac_cv_ld_reloc_exec="no",
|
|
||||||
ac_cv_ld_reloc_exec="no")
|
|
||||||
CFLAGS="$saved_CFLAGS"])
|
|
||||||
if test "$ac_cv_ld_reloc_exec" = "yes"
|
|
||||||
then
|
|
||||||
AC_SUBST(LDEXECFLAGS,["-Wl,--section-start,.interp=0x3c000100"])
|
|
||||||
fi
|
|
||||||
AC_CACHE_CHECK([whether the linker accepts --export-dynamic], ac_cv_c_export_dynamic,
|
AC_CACHE_CHECK([whether the linker accepts --export-dynamic], ac_cv_c_export_dynamic,
|
||||||
[WINE_TRY_CFLAGS([-fPIC -Wl,--export-dynamic],
|
[WINE_TRY_CFLAGS([-fPIC -Wl,--export-dynamic],
|
||||||
ac_cv_c_export_dynamic="yes",ac_cv_c_export_dynamic="no")])
|
ac_cv_c_export_dynamic="yes",ac_cv_c_export_dynamic="no")])
|
||||||
if test "$ac_cv_c_export_dynamic" = "yes"
|
if test "$ac_cv_c_export_dynamic" = "yes"
|
||||||
then
|
then
|
||||||
LDEXECFLAGS="$LDEXECFLAGS -Wl,--export-dynamic"
|
AC_SUBST(LDEXECFLAGS,["-Wl,--export-dynamic"])
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
case $host_cpu in
|
||||||
|
*i[[3456789]]86*)
|
||||||
|
AC_CACHE_CHECK([whether we can relocate the executable to 0x00110000], ac_cv_ld_reloc_exec,
|
||||||
|
[saved_CFLAGS="$CFLAGS"
|
||||||
|
CFLAGS="$CFLAGS -Wl,--section-start,.interp=0x00110400"
|
||||||
|
AC_TRY_RUN([#include <unistd.h>
|
||||||
|
int main() { return (sbrk(32*1024*1024) == (void *)-1); }],
|
||||||
|
ac_cv_ld_reloc_exec="yes", ac_cv_ld_reloc_exec="no", ac_cv_ld_reloc_exec="no")
|
||||||
|
CFLAGS="$saved_CFLAGS"])
|
||||||
|
if test "$ac_cv_ld_reloc_exec" = "yes"
|
||||||
|
then
|
||||||
|
LDEXECFLAGS="$LDEXECFLAGS -Wl,--section-start,.interp=0x00110400"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
else
|
else
|
||||||
AC_CACHE_CHECK(whether we can build a UnixWare (Solaris) dll, ac_cv_c_dll_unixware,
|
AC_CACHE_CHECK(whether we can build a UnixWare (Solaris) dll, ac_cv_c_dll_unixware,
|
||||||
[WINE_TRY_CFLAGS([-fPIC -Wl,-G,-h,conftest.so.1.0,-B,symbolic],
|
[WINE_TRY_CFLAGS([-fPIC -Wl,-G,-h,conftest.so.1.0,-B,symbolic],
|
||||||
|
@ -879,6 +879,8 @@ void __wine_kernel_init(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
found:
|
found:
|
||||||
|
wine_free_pe_load_area(); /* the main binary is loaded, we don't need this anymore */
|
||||||
|
|
||||||
/* build command line */
|
/* build command line */
|
||||||
set_library_wargv( __wine_main_argv );
|
set_library_wargv( __wine_main_argv );
|
||||||
if (!build_command_line( __wine_main_wargv )) goto error;
|
if (!build_command_line( __wine_main_wargv )) goto error;
|
||||||
|
@ -52,6 +52,7 @@ extern int __wine_main_argc;
|
|||||||
extern char **__wine_main_argv;
|
extern char **__wine_main_argv;
|
||||||
extern WCHAR **__wine_main_wargv;
|
extern WCHAR **__wine_main_wargv;
|
||||||
extern char **__wine_main_environ;
|
extern char **__wine_main_environ;
|
||||||
|
extern void wine_init( int argc, char *argv[], char *error, int error_size );
|
||||||
|
|
||||||
/* debugging */
|
/* debugging */
|
||||||
|
|
||||||
@ -69,6 +70,8 @@ extern int wine_dbg_parse_options( const char *str );
|
|||||||
|
|
||||||
extern void DECLSPEC_NORETURN wine_switch_to_stack( void (*func)(void *), void *arg, void *stack );
|
extern void DECLSPEC_NORETURN wine_switch_to_stack( void (*func)(void *), void *arg, void *stack );
|
||||||
extern void *wine_anon_mmap( void *start, size_t size, int prot, int flags );
|
extern void *wine_anon_mmap( void *start, size_t size, int prot, int flags );
|
||||||
|
extern void wine_set_pe_load_area( void *base, size_t size );
|
||||||
|
extern void wine_free_pe_load_area(void);
|
||||||
|
|
||||||
/* LDT management */
|
/* LDT management */
|
||||||
|
|
||||||
|
@ -144,6 +144,36 @@ __ASM_GLOBAL_FUNC( wine_switch_to_stack,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
static char *pe_area;
|
||||||
|
static size_t pe_area_size;
|
||||||
|
|
||||||
|
/***********************************************************************
|
||||||
|
* wine_set_pe_load_area
|
||||||
|
*
|
||||||
|
* Define the reserved area to use for loading the main PE binary.
|
||||||
|
*/
|
||||||
|
void wine_set_pe_load_area( void *base, size_t size )
|
||||||
|
{
|
||||||
|
unsigned int page_mask = getpagesize() - 1;
|
||||||
|
char *end = (char *)base + size;
|
||||||
|
|
||||||
|
pe_area = (char *)(((unsigned long)base + page_mask) & ~page_mask);
|
||||||
|
pe_area_size = (end - pe_area) & ~page_mask;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***********************************************************************
|
||||||
|
* wine_free_pe_load_area
|
||||||
|
*
|
||||||
|
* Free the reserved area to use for loading the main PE binary.
|
||||||
|
*/
|
||||||
|
void wine_free_pe_load_area(void)
|
||||||
|
{
|
||||||
|
if (pe_area) munmap( pe_area, pe_area_size );
|
||||||
|
pe_area = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#if (defined(__svr4__) || defined(__NetBSD__)) && !defined(MAP_TRYFIXED)
|
#if (defined(__svr4__) || defined(__NetBSD__)) && !defined(MAP_TRYFIXED)
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* try_mmap_fixed
|
* try_mmap_fixed
|
||||||
@ -257,6 +287,16 @@ void *wine_anon_mmap( void *start, size_t size, int prot, int flags )
|
|||||||
flags |= MAP_PRIVATE;
|
flags |= MAP_PRIVATE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (pe_area && start &&
|
||||||
|
(char *)start >= pe_area &&
|
||||||
|
(char *)start + size <= pe_area + pe_area_size)
|
||||||
|
{
|
||||||
|
wine_free_pe_load_area();
|
||||||
|
flags |= MAP_FIXED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(flags & MAP_FIXED))
|
||||||
|
{
|
||||||
#ifdef MAP_TRYFIXED
|
#ifdef MAP_TRYFIXED
|
||||||
/* If available, this will attempt a fixed mapping in-kernel */
|
/* If available, this will attempt a fixed mapping in-kernel */
|
||||||
flags |= MAP_TRYFIXED;
|
flags |= MAP_TRYFIXED;
|
||||||
@ -264,7 +304,7 @@ void *wine_anon_mmap( void *start, size_t size, int prot, int flags )
|
|||||||
if ( try_mmap_fixed( start, size, prot, flags, fdzero, 0 ) )
|
if ( try_mmap_fixed( start, size, prot, flags, fdzero, 0 ) )
|
||||||
return start;
|
return start;
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
return mmap( start, size, prot, flags, fdzero, 0 );
|
return mmap( start, size, prot, flags, fdzero, 0 );
|
||||||
#else
|
#else
|
||||||
return (void *)-1;
|
return (void *)-1;
|
||||||
|
@ -10,8 +10,8 @@ C_SRCS = \
|
|||||||
main.c \
|
main.c \
|
||||||
pthread.c
|
pthread.c
|
||||||
|
|
||||||
KTHREAD_OBJS = main.o kthread.o
|
KTHREAD_OBJS = kthread.o main.o
|
||||||
PTHREAD_OBJS = main.o pthread.o
|
PTHREAD_OBJS = pthread.o main.o
|
||||||
|
|
||||||
WINE_BINARIES = @WINE_BINARIES@
|
WINE_BINARIES = @WINE_BINARIES@
|
||||||
MAIN_BINARY = @MAIN_BINARY@
|
MAIN_BINARY = @MAIN_BINARY@
|
||||||
|
@ -20,8 +20,7 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include "wine/library.h"
|
||||||
extern void wine_init( int argc, char *argv[], char *error, int error_size );
|
|
||||||
|
|
||||||
/**********************************************************************
|
/**********************************************************************
|
||||||
* main
|
* main
|
||||||
@ -30,6 +29,11 @@ int main( int argc, char *argv[] )
|
|||||||
{
|
{
|
||||||
char error[1024];
|
char error[1024];
|
||||||
|
|
||||||
|
#ifdef __i386__
|
||||||
|
static char pe_load[256*1024*1024] __attribute__((aligned(4096)));
|
||||||
|
wine_set_pe_load_area( pe_load, sizeof(pe_load) );
|
||||||
|
#endif
|
||||||
|
|
||||||
wine_init( argc, argv, error, sizeof(error) );
|
wine_init( argc, argv, error, sizeof(error) );
|
||||||
fprintf( stderr, "wine: failed to initialize: %s\n", error );
|
fprintf( stderr, "wine: failed to initialize: %s\n", error );
|
||||||
exit(1);
|
exit(1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user