Add the preloader itself as argv[0] and remove it again before running

the real loader, this way the ps output makes more sense.
This commit is contained in:
Alexandre Julliard 2004-06-15 20:31:06 +00:00
parent 497709b9bb
commit c3193925d8
2 changed files with 17 additions and 4 deletions

View File

@ -279,6 +279,7 @@ static void preloader_exec( char **argv, char **envp, int use_preloader )
{
static const char preloader[] = "wine-preloader";
char *p, *full_name;
char **last_arg = argv, **new_argv;
if (!(p = strrchr( argv[0], '/' ))) p = argv[0];
else p++;
@ -286,8 +287,15 @@ static void preloader_exec( char **argv, char **envp, int use_preloader )
full_name = xmalloc( p - argv[0] + sizeof(preloader) );
memcpy( full_name, argv[0], p - argv[0] );
memcpy( full_name + (p - argv[0]), preloader, sizeof(preloader) );
if (envp) execve( full_name, argv, envp );
else execv( full_name, argv );
/* make a copy of argv */
while (*last_arg) last_arg++;
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;
if (envp) execve( full_name, new_argv, envp );
else execv( full_name, new_argv );
free( new_argv );
free( full_name );
return;
}

View File

@ -2,7 +2,7 @@
* Preloader for ld.so
*
* Copyright (C) 1995,96,97,98,99,2000,2001,2002 Free Software Foundation, Inc.
* Copyright (C) 2004 Mike McCormack for Codeweavers
* Copyright (C) 2004 Mike McCormack for CodeWeavers
* Copyright (C) 2004 Alexandre Julliard
*
* This library is free software; you can redistribute it and/or
@ -685,6 +685,7 @@ void* wld_start( void **stack )
pargc = *stack;
argv = (char **)pargc + 1;
if (*pargc < 2) fatal_error( "Usage: %s wine_binary [args]\n", argv[0] );
/* skip over the parameters */
p = argv + *pargc + 1;
@ -717,7 +718,7 @@ void* wld_start( void **stack )
PROT_NONE, MAP_FIXED | MAP_PRIVATE | MAP_ANON | MAP_NORESERVE, -1, 0 );
/* load the main binary */
map_so_lib( argv[0], &main_binary_map );
map_so_lib( argv[1], &main_binary_map );
/* load the ELF interpreter */
interp = (char *)main_binary_map.l_addr + main_binary_map.l_interp;
@ -743,6 +744,10 @@ void* wld_start( void **stack )
SET_NEW_AV(10, AT_EGID, get_auxiliary( av, AT_EGID, getegid() ) );
#undef SET_NEW_AV
/* get rid of first argument */
pargc[1] = pargc[0] - 1;
*stack = pargc + 1;
set_auxiliary_values( av, new_av, stack );
#ifdef DUMP_AUX_INFO