about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2023-07-16 10:54:32 +0200
committerptitSeb <sebastien.chev@gmail.com>2023-07-16 10:54:32 +0200
commit7607a87617a827f5cfe019a2c561e4d88bae0a61 (patch)
treecd4ad8e44a35b203788fa405a913b8f0cc78c46a /src
parentb2d37d4ddb227a33ffb00b858b77cdafddc53560 (diff)
downloadbox64-7607a87617a827f5cfe019a2c561e4d88bae0a61.tar.gz
box64-7607a87617a827f5cfe019a2c561e4d88bae0a61.zip
Added wrapped execle (for #850)
Diffstat (limited to 'src')
-rwxr-xr-xsrc/wrapped/wrappedlibc.c34
1 files changed, 32 insertions, 2 deletions
diff --git a/src/wrapped/wrappedlibc.c b/src/wrapped/wrappedlibc.c
index cb218412..ff20404e 100755
--- a/src/wrapped/wrappedlibc.c
+++ b/src/wrapped/wrappedlibc.c
@@ -2089,7 +2089,7 @@ EXPORT int32_t my_execl(x64emu_t* emu, const char* path)
     int x64 = FileIsX64ELF(path);
     int x86 = my_context->box86path?FileIsX86ELF(path):0;
     int script = (my_context->bashpath && FileIsShell(path))?1:0;
-    printf_log(LOG_DEBUG, "execl(\"%s\", ...), IsX86=%d, self=%d\n", path, x64, self);
+    printf_log(LOG_DEBUG, "execle(\"%s\", ...), IsX86=%d, self=%d\n", path, x64, self);
     // count argv...
     int i=0;
     while(getVargN(emu, i+1)) ++i;
@@ -2102,12 +2102,42 @@ EXPORT int32_t my_execl(x64emu_t* emu, const char* path)
     for (int k=0; k<i; ++k)
         newargv[j++] = getVargN(emu, k+1);
     if(self) newargv[1] = emu->context->fullpath;
-    printf_log(LOG_DEBUG, " => execl(\"%s\", %p [\"%s\", \"%s\"...:%d])\n", newargv[0], newargv, newargv[1], i?newargv[2]:"", i);
+    printf_log(LOG_DEBUG, " => execle(\"%s\", %p [\"%s\", \"%s\"...:%d])\n", newargv[0], newargv, newargv[1], i?newargv[2]:"", i);
     int ret = execv(newargv[0], newargv);
     box_free(newargv);
     return ret;
 }
 
+EXPORT int32_t my_execle(x64emu_t* emu, const char* path)
+{
+    int self = isProcSelf(path, "exe");
+    int x64 = FileIsX64ELF(path);
+    int x86 = my_context->box86path?FileIsX86ELF(path):0;
+    int script = (my_context->bashpath && FileIsShell(path))?1:0;
+    printf_log(LOG_DEBUG, "execl(\"%s\", ...), IsX86=%d, self=%d\n", path, x64, self);
+    // hack to update the environ var if needed
+    // count argv...
+    int i=0;
+    while(getVargN(emu, i+1)) ++i;
+    int toadd = script?2:((x64||self)?1:0);
+    char** newargv = (char**)box_calloc(i+toadd+1, sizeof(char*));
+    char** envp = (char**)getVargN(emu, i+2);
+    if(envp == my_context->envv && environ) {
+        envp = environ;
+    }
+    int j=0;
+    if ((x64 || x86 || script || self))
+        newargv[j++] = x86?emu->context->box86path:emu->context->box64path;
+    if(script) newargv[j++] = emu->context->bashpath;
+    for (int k=0; k<i; ++k)
+        newargv[j++] = getVargN(emu, k+1);
+    if(self) newargv[1] = emu->context->fullpath;
+    printf_log(LOG_DEBUG, " => execle(\"%s\", %p [\"%s\", \"%s\"...:%d], %p)\n", newargv[0], newargv, newargv[1], i?newargv[2]:"", i, envp);
+    int ret = execve(newargv[0], newargv, envp);
+    box_free(newargv);
+    return ret;
+}
+
 EXPORT int32_t my_execlp(x64emu_t* emu, const char* path)
 {
     // need to use BOX64_PATH / PATH here...