about summary refs log tree commit diff stats
path: root/src/wrapped32/wrappedlibc.c
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2024-12-15 14:15:34 +0100
committerptitSeb <sebastien.chev@gmail.com>2024-12-15 14:15:34 +0100
commit5ce3e2991360771bf5ed9b2b8c7228c742e5134b (patch)
treefe26d176af47ca77d3f2ef8aba021164b6056a5f /src/wrapped32/wrappedlibc.c
parent1a7cff559aa23e935a12cedb6ce84fd81e4548f2 (diff)
downloadbox64-5ce3e2991360771bf5ed9b2b8c7228c742e5134b.tar.gz
box64-5ce3e2991360771bf5ed9b2b8c7228c742e5134b.zip
[BOX32][WRAPPER] More work on libc wrapping, and some new syscall too
Diffstat (limited to 'src/wrapped32/wrappedlibc.c')
-rwxr-xr-xsrc/wrapped32/wrappedlibc.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/wrapped32/wrappedlibc.c b/src/wrapped32/wrappedlibc.c
index 284d04e8..b0ba7c52 100755
--- a/src/wrapped32/wrappedlibc.c
+++ b/src/wrapped32/wrappedlibc.c
@@ -1720,6 +1720,7 @@ EXPORT int32_t my32_execv(x64emu_t* emu, const char* path, ptr_t argv[])
     int self = isProcSelf(path, "exe");
     int x86 = FileIsX86ELF(path);
     int x64 = FileIsX64ELF(path);
+    int script = (my_context->bashpath && FileIsShell(path))?1:0;
     printf_log(LOG_DEBUG, "execv(\"%s\", %p) is x86=%d\n", path, argv, x86);
     if (x86 || x64 || self) {
         int skip_first = 0;
@@ -1728,11 +1729,19 @@ EXPORT int32_t my32_execv(x64emu_t* emu, const char* path, ptr_t argv[])
         // count argv...
         int n=skip_first;
         while(argv[n]) ++n;
-        const char** newargv = (const char**)calloc(n+2, sizeof(char*));
+        int toadd = script?2:1;
+        const char** newargv = (const char**)calloc(n+toadd+2, sizeof(char*));
         newargv[0] = x64?emu->context->box64path:emu->context->box64path;
         for(int i=0; i<n; ++i)
             newargv[i+1] = from_ptrv(argv[skip_first+i]);
-        if(self) newargv[1] = emu->context->fullpath;
+        if(self)
+            newargv[1] = emu->context->fullpath;
+        else {
+            // TODO check if envp is not environ and add the value on a copy
+            if(strcmp(newargv[toadd], skip_first?from_ptrv(argv[skip_first]):path))
+                setenv(x86?"BOX86_ARG0":"BOX64_ARG0", newargv[toadd], 1);
+            newargv[toadd] = skip_first?from_ptrv(argv[skip_first]):path;
+        }
         printf_log(LOG_DEBUG, " => execv(\"%s\", %p [\"%s\", \"%s\", \"%s\"...:%d])\n", emu->context->box64path, newargv, newargv[0], n?newargv[1]:"", (n>1)?newargv[2]:"",n);
         int ret = execv(newargv[0], (char* const*)newargv);
         free(newargv);
@@ -3255,6 +3264,8 @@ EXPORT ptr_t my32_stdin = 0;
 EXPORT ptr_t my32_stdout = 0;
 EXPORT ptr_t my32_stderr = 0;
 
+EXPORT int __libc_enable_secure = 1;
+
 EXPORT long_t my32_timezone = 0;
 EXPORT void my32_tzset()
 {