about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2022-06-19 20:50:15 +0200
committerptitSeb <sebastien.chev@gmail.com>2022-06-19 20:50:15 +0200
commit3e764fdc45d6413622855fe784a0cb76386a2cd3 (patch)
tree79d34dbfb42874b3a11450d059ac0b713c9bf298 /src
parentf52ee794dbca33616d55e98c20b62a217755efbd (diff)
downloadbox64-3e764fdc45d6413622855fe784a0cb76386a2cd3.tar.gz
box64-3e764fdc45d6413622855fe784a0cb76386a2cd3.zip
Change process name (hidding box64, helps mesa find the correct hack for some binaries)
Diffstat (limited to 'src')
-rwxr-xr-xsrc/main.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
index 96cd8ee2..b13fa827 100755
--- a/src/main.c
+++ b/src/main.c
@@ -10,6 +10,7 @@
 #include <sys/syscall.h>
 #include <sys/mman.h>
 #include <pthread.h>
+#include <sys/prctl.h>
 #ifdef DYNAREC
 #ifdef ARM64
 #include <linux/auxvec.h>
@@ -1292,6 +1293,28 @@ int main(int argc, const char **argv, char **env) {
             printf_log(LOG_INFO, "BOX64: Using tcmalloc_minimal.so.4, and it's in the LD_PRELOAD command\n");
         }
     }
+    // change process name
+    {
+        char* p = strrchr(my_context->argv[0], '/');
+        if(p)
+            ++p;
+        else
+            p = my_context->argv[0];
+        if(prctl(PR_SET_NAME, p)==-1)
+            printf_log(LOG_NONE, "Error setting process name (%s)\n", strerror(errno));
+        else
+            printf_log(LOG_INFO, "Rename process to \"%s\"\n", p);
+        // and now all change the argv (so libs libs mesa find the correct program names)
+        char* endp = (char*)argv[argc-1];
+        while(*endp)
+            ++endp;    // find last argv[] address
+        uintptr_t diff = prog - argv[0]; // this is the difference we need to compensate
+        for(p=(char*)prog; p<=endp; ++p)
+            *(p - diff) = *p;  // copy all element at argv[nextarg] to argv[0]
+        memset(endp - diff, 0, diff); // fill reminder with NULL
+        for(int i=nextarg; i<argc; ++i)
+            argv[i] -= diff;    // adjust strings
+    }
     // get and alloc stack size and align
     if(CalcStackSize(my_context)) {
         printf_log(LOG_NONE, "Error: allocating stack\n");