From 30c72e23bd3f11f7081ff8bea95103d762020001 Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Wed, 6 Nov 2024 16:06:13 +0100 Subject: [PATCH] Added some new functions and a few fixes (for Steam) --- src/library_list.h | 2 +- src/wrapped/generated/functions_list.txt | 1 + src/wrapped/generated/wrappedlibctypes.h | 1 + src/wrapped/wrappedldlinux.c | 2 +- src/wrapped/wrappedlibc.c | 44 ++++++++++++++++++++++++ src/wrapped/wrappedlibc_private.h | 29 ++++++++-------- 6 files changed, 63 insertions(+), 16 deletions(-) diff --git a/src/library_list.h b/src/library_list.h index f90b98af..64dae0b4 100755 --- a/src/library_list.h +++ b/src/library_list.h @@ -265,5 +265,5 @@ GO("libxml2.so.2", xml2) GO("ld-linux.so.2", ldlinux) -GO("crashhandler.so", crashhandler) +//GO("crashhandler.so", crashhandler) GO("libv4l2.so.0", libv4l2) diff --git a/src/wrapped/generated/functions_list.txt b/src/wrapped/generated/functions_list.txt index d01fe695..642ca123 100644 --- a/src/wrapped/generated/functions_list.txt +++ b/src/wrapped/generated/functions_list.txt @@ -3226,6 +3226,7 @@ wrappedlibc: - iFppL: - iFppp: - _IO_vfscanf + - execvpe - iFppV: - __isoc23_fscanf - __isoc23_sscanf diff --git a/src/wrapped/generated/wrappedlibctypes.h b/src/wrapped/generated/wrappedlibctypes.h index 0fe285e6..636f1b4f 100644 --- a/src/wrapped/generated/wrappedlibctypes.h +++ b/src/wrapped/generated/wrappedlibctypes.h @@ -158,6 +158,7 @@ typedef int32_t (*iFpLiLppp_t)(void*, uintptr_t, int32_t, uintptr_t, void*, void GO(getopt, iFipp_t) \ GO(dprintf, iFipV_t) \ GO(_IO_vfscanf, iFppp_t) \ + GO(execvpe, iFppp_t) \ GO(__isoc23_fscanf, iFppV_t) \ GO(__isoc23_sscanf, iFppV_t) \ GO(__isoc23_sscanf, iFppV_t) \ diff --git a/src/wrapped/wrappedldlinux.c b/src/wrapped/wrappedldlinux.c index dd0a5141..d6f9f926 100755 --- a/src/wrapped/wrappedldlinux.c +++ b/src/wrapped/wrappedldlinux.c @@ -36,7 +36,7 @@ EXPORT void* my____tls_get_addr(x86emu_t* emu) EXPORT void* my___libc_stack_end; void stSetup(box86context_t* context) { - my___libc_stack_end = context->stack; // is this the end, or should I add stasz? + my___libc_stack_end = context->stack + context->stacksz; } const char* ldlinuxName = "ld-linux.so.3"; diff --git a/src/wrapped/wrappedlibc.c b/src/wrapped/wrappedlibc.c index 5ae54fa3..f27d3baf 100755 --- a/src/wrapped/wrappedlibc.c +++ b/src/wrapped/wrappedlibc.c @@ -2573,6 +2573,50 @@ EXPORT int32_t my_execvp(x86emu_t* emu, const char* path, char* const argv[]) return execvp(path, argv); } +// execvpe should use PATH to search for the program first +EXPORT int32_t my_execvpe(x86emu_t* emu, const char* path, char* const argv[], char* const envv[]) +{ + // need to use BOX86_PATH / PATH here... + char* fullpath = ResolveFile(path, &my_context->box86_path); + // use fullpath... + int self = isProcSelf(fullpath, "exe"); + int x86 = FileIsX86ELF(fullpath); + int x64 = my_context->box86path?FileIsX64ELF(path):0; + int script = (my_context->bashpath && FileIsShell(path))?1:0; + if(script && FileIsX64ELF(my_context->bashpath)) x64 = 1; + printf_log(LOG_DEBUG, "execvp(\"%s\", %p), IsX86=%d / fullpath=\"%s\"\n", path, argv, x86, fullpath); + if (x86 || x64 || script || self) { + // count argv... + int i=0; + while(argv[i]) ++i; + int toadd = script?2:1; + char** newargv = (char**)alloca((i+toadd+1)*sizeof(char*)); + memset(newargv, 0, (i+toadd+1)*sizeof(char*)); + newargv[0] = x64?emu->context->box64path:emu->context->box86path; + if(script) newargv[1] = emu->context->bashpath; // script needs to be launched with bash + for (int j=0; jcontext->fullpath; + if(script) newargv[2] = emu->context->bashpath; + printf_log(LOG_DEBUG, " => execvp(\"%s\", %p [\"%s\", \"%s\"...:%d])\n", newargv[0], newargv, newargv[1], i?newargv[2]:"", i); + int ret = execvpe(newargv[0], newargv, envv); + box_free(fullpath); + return ret; + } + box_free(fullpath); + if((!strcmp(path + strlen(path) - strlen("/uname"), "/uname") || !strcmp(path, "uname")) + && argv[1] && (!strcmp(argv[1], "-m") || !strcmp(argv[1], "-p") || !strcmp(argv[1], "-i")) + && !argv[2]) { + // uname -m is redirected to box86 -m + path = my_context->box86path; + char *argv2[3] = { my_context->box86path, argv[1], NULL }; + return execvpe(path, argv2, envv); + } + + // fullpath is gone, so the search will only be on PATH, not on BOX86_PATH (is that an issue?) + return execvpe(path, argv, envv); +} + // execvp should use PATH to search for the program first EXPORT int32_t my_posix_spawnp(x86emu_t* emu, pid_t* pid, const char* path, const posix_spawn_file_actions_t *actions, const posix_spawnattr_t* attrp, char* const argv[], char* const envp[]) diff --git a/src/wrapped/wrappedlibc_private.h b/src/wrapped/wrappedlibc_private.h index 9850b197..86833cbd 100755 --- a/src/wrapped/wrappedlibc_private.h +++ b/src/wrapped/wrappedlibc_private.h @@ -293,6 +293,7 @@ GO2(execlp, iFpV, execvp) GOWM(execv, iFEpp) //%% GOM(execve, iFEppp) //%% and this one too... GOWM(execvp, iFEpp) +GOWM(execvpe, iFEppp) GOM(exit, vFEi) GOM(_exit, vFEi) GOWM(_Exit, vFEi) @@ -1281,20 +1282,20 @@ GO(posix_fallocate64, iFiII) GOW(posix_memalign, iFpLL) // posix_openpt // Weak GO(posix_spawn, iFpppppp) -// posix_spawnattr_destroy -// posix_spawnattr_getflags -// posix_spawnattr_getpgroup -// posix_spawnattr_getschedparam -// posix_spawnattr_getschedpolicy -// posix_spawnattr_getsigdefault -// posix_spawnattr_getsigmask -// posix_spawnattr_init -// posix_spawnattr_setflags -// posix_spawnattr_setpgroup -// posix_spawnattr_setschedparam -// posix_spawnattr_setschedpolicy -// posix_spawnattr_setsigdefault -// posix_spawnattr_setsigmask +GOW(posix_spawnattr_destroy, iFp) +GO(posix_spawnattr_getflags, iFpp) +GO(posix_spawnattr_getpgroup, iFpp) +GO(posix_spawnattr_getschedparam, iFpp) +GO(posix_spawnattr_getschedpolicy, iFpp) +GO(posix_spawnattr_getsigdefault, iFpp) +GO(posix_spawnattr_getsigmask, iFpp) +GOW(posix_spawnattr_init, iFp) +GOW(posix_spawnattr_setflags, iFpw) +GO(posix_spawnattr_setpgroup, iFpi) +GO(posix_spawnattr_setschedparam, iFpp) +GO(posix_spawnattr_setschedpolicy, iFpi) +GOW(posix_spawnattr_setsigdefault, iFpp) +GOW(posix_spawnattr_setsigmask, iFpp) GO(posix_spawn_file_actions_addclose, iFpi) GO(posix_spawn_file_actions_adddup2, iFpii) GO(posix_spawn_file_actions_addopen, iFpipii)