mirror of
https://github.com/UberGames/lilium-voyager.git
synced 2024-11-10 14:41:42 +00:00
fix cdpath, deuglify dlopen code, load dll also from cdpath
This commit is contained in:
parent
8200e26360
commit
77eb7e4147
1 changed files with 45 additions and 37 deletions
|
@ -37,6 +37,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <libgen.h> // dirname
|
||||||
#ifdef __linux__ // rb010123
|
#ifdef __linux__ // rb010123
|
||||||
#include <mntent.h>
|
#include <mntent.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -707,6 +708,31 @@ changed the load procedure to match VFS logic, and allow developer use
|
||||||
*/
|
*/
|
||||||
extern char *FS_BuildOSPath( const char *base, const char *game, const char *qpath );
|
extern char *FS_BuildOSPath( const char *base, const char *game, const char *qpath );
|
||||||
|
|
||||||
|
static void* try_dlopen(const char* base, const char* gamedir, const char* fname, char* fqpath )
|
||||||
|
{
|
||||||
|
void* libHandle;
|
||||||
|
char* fn;
|
||||||
|
|
||||||
|
*fqpath = 0;
|
||||||
|
|
||||||
|
// bk001129 - was RTLD_LAZY
|
||||||
|
#define Q_RTLD RTLD_NOW
|
||||||
|
|
||||||
|
fn = FS_BuildOSPath( base, gamedir, fname );
|
||||||
|
Com_Printf( "Sys_LoadDll(%s)... \n", fn );
|
||||||
|
libHandle = dlopen( fn, Q_RTLD );
|
||||||
|
|
||||||
|
if(!libHandle) {
|
||||||
|
Com_Printf( "Sys_LoadDll(%s) failed:\n\"%s\"\n", fn, dlerror() );
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
Com_Printf ( "Sys_LoadDll(%s): succeeded ...\n", fn );
|
||||||
|
Q_strncpyz ( fqpath , fn , MAX_QPATH ) ; // added 7/20/02 by T.Ray
|
||||||
|
|
||||||
|
return libHandle;
|
||||||
|
}
|
||||||
|
|
||||||
void *Sys_LoadDll( const char *name, char *fqpath ,
|
void *Sys_LoadDll( const char *name, char *fqpath ,
|
||||||
long (**entryPoint)(long, ...),
|
long (**entryPoint)(long, ...),
|
||||||
long (*systemcalls)(long, ...) )
|
long (*systemcalls)(long, ...) )
|
||||||
|
@ -718,12 +744,10 @@ void *Sys_LoadDll( const char *name, char *fqpath ,
|
||||||
char *basepath;
|
char *basepath;
|
||||||
char *homepath;
|
char *homepath;
|
||||||
char *pwdpath;
|
char *pwdpath;
|
||||||
|
char *cdpath;
|
||||||
char *gamedir;
|
char *gamedir;
|
||||||
char *fn;
|
|
||||||
const char* err = NULL;
|
const char* err = NULL;
|
||||||
|
|
||||||
*fqpath = 0;
|
|
||||||
|
|
||||||
// bk001206 - let's have some paranoia
|
// bk001206 - let's have some paranoia
|
||||||
assert( name );
|
assert( name );
|
||||||
|
|
||||||
|
@ -744,50 +768,33 @@ void *Sys_LoadDll( const char *name, char *fqpath ,
|
||||||
#error Unknown arch
|
#error Unknown arch
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// bk001129 - was RTLD_LAZY
|
// TODO: use fs_searchpaths from files.c
|
||||||
#define Q_RTLD RTLD_NOW
|
|
||||||
|
|
||||||
pwdpath = Sys_Cwd();
|
pwdpath = Sys_Cwd();
|
||||||
basepath = Cvar_VariableString( "fs_basepath" );
|
basepath = Cvar_VariableString( "fs_basepath" );
|
||||||
homepath = Cvar_VariableString( "fs_homepath" );
|
homepath = Cvar_VariableString( "fs_homepath" );
|
||||||
|
cdpath = Cvar_VariableString( "fs_cdpath" );
|
||||||
gamedir = Cvar_VariableString( "fs_game" );
|
gamedir = Cvar_VariableString( "fs_game" );
|
||||||
|
|
||||||
// pwdpath
|
libHandle = try_dlopen(pwdpath, gamedir, fname, fqpath);
|
||||||
fn = FS_BuildOSPath( pwdpath, gamedir, fname );
|
|
||||||
Com_Printf( "Sys_LoadDll(%s)... \n", fn );
|
|
||||||
libHandle = dlopen( fn, Q_RTLD );
|
|
||||||
|
|
||||||
if ( !libHandle )
|
if(!libHandle && homepath)
|
||||||
{
|
libHandle = try_dlopen(homepath, gamedir, fname, fqpath);
|
||||||
Com_Printf( "Sys_LoadDll(%s) failed:\n\"%s\"\n", fn, dlerror() );
|
|
||||||
// fs_homepath
|
|
||||||
fn = FS_BuildOSPath( homepath, gamedir, fname );
|
|
||||||
Com_Printf( "Sys_LoadDll(%s)... \n", fn );
|
|
||||||
libHandle = dlopen( fn, Q_RTLD );
|
|
||||||
|
|
||||||
if ( !libHandle )
|
if(!libHandle && basepath)
|
||||||
{
|
libHandle = try_dlopen(basepath, gamedir, fname, fqpath);
|
||||||
Com_Printf( "Sys_LoadDll(%s) failed:\n\"%s\"\n", fn, dlerror() );
|
|
||||||
// fs_basepath
|
|
||||||
fn = FS_BuildOSPath( basepath, gamedir, fname );
|
|
||||||
Com_Printf( "Sys_LoadDll(%s)... \n", fn );
|
|
||||||
libHandle = dlopen( fn, Q_RTLD );
|
|
||||||
|
|
||||||
if ( !libHandle )
|
if(!libHandle && cdpath)
|
||||||
{
|
libHandle = try_dlopen(cdpath, gamedir, fname, fqpath);
|
||||||
|
|
||||||
|
if(!libHandle) {
|
||||||
#if 0 // don't abort -- ln
|
#if 0 // don't abort -- ln
|
||||||
//#ifndef NDEBUG // bk001206 - in debug abort on failure
|
//#ifndef NDEBUG // bk001206 - in debug abort on failure
|
||||||
Com_Error ( ERR_FATAL, "Sys_LoadDll(%s) failed dlopen() completely!\n", name );
|
Com_Error ( ERR_FATAL, "Sys_LoadDll(%s) failed dlopen() completely!\n", name );
|
||||||
#else
|
#else
|
||||||
Com_Printf ( "Sys_LoadDll(%s) failed dlopen() completely!\n", name );
|
Com_Printf ( "Sys_LoadDll(%s) failed dlopen() completely!\n", name );
|
||||||
#endif
|
#endif
|
||||||
return NULL;
|
return NULL;
|
||||||
} else
|
}
|
||||||
Com_Printf ( "Sys_LoadDll(%s): succeeded ...\n", fn );
|
|
||||||
} else
|
|
||||||
Com_Printf ( "Sys_LoadDll(%s): succeeded ...\n", fn );
|
|
||||||
} else
|
|
||||||
Com_Printf ( "Sys_LoadDll(%s): succeeded ...\n", fn );
|
|
||||||
|
|
||||||
dllEntry = dlsym( libHandle, "dllEntry" );
|
dllEntry = dlsym( libHandle, "dllEntry" );
|
||||||
*entryPoint = dlsym( libHandle, "vmMain" );
|
*entryPoint = dlsym( libHandle, "vmMain" );
|
||||||
|
@ -808,7 +815,6 @@ void *Sys_LoadDll( const char *name, char *fqpath ,
|
||||||
Com_Printf ( "Sys_LoadDll(%s) found **vmMain** at %p \n", name, *entryPoint ); // bk001212
|
Com_Printf ( "Sys_LoadDll(%s) found **vmMain** at %p \n", name, *entryPoint ); // bk001212
|
||||||
dllEntry( systemcalls );
|
dllEntry( systemcalls );
|
||||||
Com_Printf ( "Sys_LoadDll(%s) succeeded!\n", name );
|
Com_Printf ( "Sys_LoadDll(%s) succeeded!\n", name );
|
||||||
if ( libHandle ) Q_strncpyz ( fqpath , fn , MAX_QPATH ) ; // added 7/20/02 by T.Ray
|
|
||||||
return libHandle;
|
return libHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1236,6 +1242,7 @@ int main ( int argc, char* argv[] )
|
||||||
// int oldtime, newtime; // bk001204 - unused
|
// int oldtime, newtime; // bk001204 - unused
|
||||||
int len, i;
|
int len, i;
|
||||||
char *cmdline;
|
char *cmdline;
|
||||||
|
char cdpath[PATH_MAX] = {0};
|
||||||
void Sys_SetDefaultCDPath(const char *path);
|
void Sys_SetDefaultCDPath(const char *path);
|
||||||
|
|
||||||
// go back to real user for config loads
|
// go back to real user for config loads
|
||||||
|
@ -1244,7 +1251,8 @@ int main ( int argc, char* argv[] )
|
||||||
|
|
||||||
Sys_ParseArgs( argc, argv ); // bk010104 - added this for support
|
Sys_ParseArgs( argc, argv ); // bk010104 - added this for support
|
||||||
|
|
||||||
Sys_SetDefaultCDPath(argv[0]);
|
strncat(cdpath, argv[0], sizeof(cdpath)-1);
|
||||||
|
Sys_SetDefaultCDPath(dirname(cdpath));
|
||||||
|
|
||||||
// merge the command line, this is kinda silly
|
// merge the command line, this is kinda silly
|
||||||
for (len = 1, i = 1; i < argc; i++)
|
for (len = 1, i = 1; i < argc; i++)
|
||||||
|
|
Loading…
Reference in a new issue