Skip to content

Commit

Permalink
More work on execv(e) wrapped functions (still for #203)
Browse files Browse the repository at this point in the history
  • Loading branch information
ptitSeb committed Sep 19, 2020
1 parent f423862 commit 0e38790
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
27 changes: 27 additions & 0 deletions src/wrapped/wrappedlibc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1672,6 +1672,33 @@ EXPORT int32_t my_execv(x86emu_t* emu, const char* path, char* const argv[])
return execv(path, argv);
}

EXPORT int32_t my_execve(x86emu_t* emu, const char* path, char* const argv[], char* const envp[])
{
int self = (strcmp(path, "/proc/self/exe")==0)?1:0;
int x86 = FileIsX86ELF(path);
printf_log(LOG_DEBUG, "execv(\"%s\", %p) is x86=%d\n", path, argv, x86);
#if 1
if (x86 || self) {
int skip_first = 0;
if(strlen(path)>=strlen("wine-preloader") && strcmp(path+strlen(path)-strlen("wine-preloader"), "wine-preloader")==0)
skip_first++;
// count argv...
int n=skip_first;
while(argv[n]) ++n;
const char** newargv = (const char**)calloc(n+2, sizeof(char*));
newargv[0] = emu->context->box86path;
memcpy(newargv+1, argv+skip_first, sizeof(char*)*(n+1));
if(self) newargv[1] = emu->context->fullpath;
printf_log(LOG_DEBUG, " => execv(\"%s\", %p [\"%s\", \"%s\", \"%s\"...:%d])\n", emu->context->box86path, newargv, newargv[0], n?newargv[1]:"", (n>1)?newargv[2]:"",n);
int ret = execve(newargv[0], (char* const*)newargv, envp);
free(newargv);
return ret;
}
#endif
return execve(path, argv, envp);
}

// execvp should use PATH to search for the program first
EXPORT int32_t my_execvp(x86emu_t* emu, const char* path, char* const argv[])
{
// need to use BOX86_PATH / PATH here...
Expand Down
6 changes: 3 additions & 3 deletions src/wrapped/wrappedlibc_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,11 @@ GOW(euidaccess, iFpi)
GO(eventfd, iFui)
GO(eventfd_read, iFip)
GO(eventfd_write, iFiU)
GO2(execl, iFEpV, execv)
GO2(execle, iFEpV, execve) //Nope! This one needs wrapping, because if char*, char*, ..., char*[]
GO2(execl, iFEpV, my_execv)
GO2(execle, iFEpV, my_execve) //Nope! This one needs wrapping, because if char*, char*, ..., char*[]
GO2(execlp, iFEpV, execvp)
GOM(execv, iFEpp) // is Weak
GOW(execve, iFppp) // and this one too...
GOM(execve, iFEppp) // and this one too...
GOW(execvp, iFpp)
GO(exit, vFi)
GO(_exit, vFi)
Expand Down

0 comments on commit 0e38790

Please # to comment.