Skip to content

Commit

Permalink
Added some new functions and a few fixes (for Steam)
Browse files Browse the repository at this point in the history
  • Loading branch information
ptitSeb committed Nov 6, 2024
1 parent ce0b4d1 commit 30c72e2
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/library_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 1 addition & 0 deletions src/wrapped/generated/functions_list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3226,6 +3226,7 @@ wrappedlibc:
- iFppL:
- iFppp:
- _IO_vfscanf
- execvpe
- iFppV:
- __isoc23_fscanf
- __isoc23_sscanf
Expand Down
1 change: 1 addition & 0 deletions src/wrapped/generated/wrappedlibctypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down
2 changes: 1 addition & 1 deletion src/wrapped/wrappedldlinux.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
44 changes: 44 additions & 0 deletions src/wrapped/wrappedlibc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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; j<i; ++j)
newargv[j+1] = argv[j];
if(self) newargv[1] = emu->context->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[])
Expand Down
29 changes: 15 additions & 14 deletions src/wrapped/wrappedlibc_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 30c72e2

Please sign in to comment.