about summary refs log tree commit diff stats
path: root/src/wrapped
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2024-11-06 16:09:38 +0100
committerptitSeb <sebastien.chev@gmail.com>2024-11-06 16:09:38 +0100
commitcd55c12e44f7cbfd048dbdd3cf9ef2b5b06bfa93 (patch)
tree8c593a4fdcee1193afbdaa6ba5624fd8ad334ee2 /src/wrapped
parentcb2cf7c9b1deda43323877caa429f65caefeab3a (diff)
downloadbox64-cd55c12e44f7cbfd048dbdd3cf9ef2b5b06bfa93.tar.gz
box64-cd55c12e44f7cbfd048dbdd3cf9ef2b5b06bfa93.zip
Added a few wrapped function and fixed some other (for Steam)
Diffstat (limited to 'src/wrapped')
-rw-r--r--src/wrapped/generated/functions_list.txt1
-rw-r--r--src/wrapped/generated/wrappedlibctypes.h1
-rw-r--r--src/wrapped/wrappedldlinux.c2
-rw-r--r--src/wrapped/wrappedlibc.c54
-rw-r--r--src/wrapped/wrappedlibc_private.h2
5 files changed, 58 insertions, 2 deletions
diff --git a/src/wrapped/generated/functions_list.txt b/src/wrapped/generated/functions_list.txt
index 80429074..7518a658 100644
--- a/src/wrapped/generated/functions_list.txt
+++ b/src/wrapped/generated/functions_list.txt
@@ -4449,6 +4449,7 @@ wrappedlibc:
   - __vfprintf_chk
   - __vsscanf
   - execve
+  - execvpe
 - iFppV:
   - __asprintf
   - __isoc23_sscanf
diff --git a/src/wrapped/generated/wrappedlibctypes.h b/src/wrapped/generated/wrappedlibctypes.h
index 206d429f..ea45efda 100644
--- a/src/wrapped/generated/wrappedlibctypes.h
+++ b/src/wrapped/generated/wrappedlibctypes.h
@@ -219,6 +219,7 @@ typedef int32_t (*iFppipppp_t)(void*, void*, int32_t, void*, void*, void*, void*
 	GO(__vfprintf_chk, iFppp_t) \
 	GO(__vsscanf, iFppp_t) \
 	GO(execve, iFppp_t) \
+	GO(execvpe, iFppp_t) \
 	GO(__asprintf, iFppV_t) \
 	GO(__isoc23_sscanf, iFppV_t) \
 	GO(__isoc99_fscanf, iFppV_t) \
diff --git a/src/wrapped/wrappedldlinux.c b/src/wrapped/wrappedldlinux.c
index 90ec1b23..cd2ee420 100644
--- a/src/wrapped/wrappedldlinux.c
+++ b/src/wrapped/wrappedldlinux.c
@@ -31,7 +31,7 @@ EXPORT void* my___tls_get_addr(void* p)
 EXPORT void* my___libc_stack_end;
 void stSetup(box64context_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;
 }
 
 #ifdef STATICBUILD
diff --git a/src/wrapped/wrappedlibc.c b/src/wrapped/wrappedlibc.c
index 01b5bc69..f341abaf 100644
--- a/src/wrapped/wrappedlibc.c
+++ b/src/wrapped/wrappedlibc.c
@@ -2442,6 +2442,60 @@ EXPORT int32_t my_execvp(x64emu_t* emu, const char* path, char* const argv[])
     // fullpath is gone, so the search will only be on PATH, not on BOX64_PATH (is that an issue?)
     return execvp(path, argv);
 }
+// execvp should use PATH to search for the program first
+EXPORT int32_t my_execvpe(x64emu_t* emu, const char* path, char* const argv[], char* const envp[])
+{
+    // need to use BOX64_PATH / PATH here...
+    char* fullpath = ResolveFileSoft(path, &my_context->box64_path);
+    // use fullpath...
+    int self = isProcSelf(fullpath, "exe");
+    int x64 = FileIsX64ELF(fullpath);
+    int x86 = my_context->box86path?FileIsX86ELF(fullpath):0;
+    int script = (my_context->bashpath && FileIsShell(fullpath))?1:0;
+    printf_log(LOG_DEBUG, "execvpe(\"%s\", %p, %p), IsX86=%d / fullpath=\"%s\"\n", path, argv, envp, x64, fullpath);
+    // hack to update the environ var if needed
+    if(envp == my_context->envv && environ) {
+        envp = environ;
+    }
+    if (x64 || x86 || 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] = x86?emu->context->box86path:emu->context->box64path;
+        if(script) newargv[1] = emu->context->bashpath; // script needs to be launched with bash
+        for (int j=0; j<i; ++j)
+            newargv[j+toadd] = argv[j];
+        if(self) newargv[1] = emu->context->fullpath;
+        //else if(script) newargv[2] = fullpath;
+        else {
+            // TODO check if envp is not environ and add the value on a copy
+            if(strcmp(newargv[toadd], path))
+                setenv(x86?"BOX86_ARG0":"BOX64_ARG0", newargv[toadd], 1);
+            newargv[toadd] = fullpath;
+        }
+
+        printf_log(LOG_DEBUG, " => execvp(\"%s\", %p [\"%s\", \"%s\"...:%d])\n", newargv[0], newargv, newargv[1], i?newargv[2]:"", i);
+        int ret;
+        ret = execvpe(newargv[0], newargv, envp);
+        box_free(fullpath);
+        return ret;
+    }
+    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 box64 -m
+        path = my_context->box64path;
+        char *argv2[3] = { my_context->box64path, argv[1], NULL };
+
+        return execvpe(path, argv2, envp);
+    }
+
+    // fullpath is gone, so the search will only be on PATH, not on BOX64_PATH (is that an issue?)
+    return execvpe(path, argv, envp);
+}
 
 EXPORT int32_t my_execl(x64emu_t* emu, const char* path)
 {
diff --git a/src/wrapped/wrappedlibc_private.h b/src/wrapped/wrappedlibc_private.h
index ce9f3976..18eb894c 100644
--- a/src/wrapped/wrappedlibc_private.h
+++ b/src/wrapped/wrappedlibc_private.h
@@ -344,7 +344,7 @@ GOM(execlp, iFEpV) // First argument is also part of the variadic
 GOM(execv, iFEpp)
 GOM(execve, iFEppp)
 GOM(execvp, iFEpp)
-GOW(execvpe, iFppp)
+GOWM(execvpe, iFEppp)
 GO(_exit, vFi)
 GOM(exit, vFEi)
 GOW(_Exit, vFi)