about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2024-07-03 11:19:55 +0200
committerptitSeb <sebastien.chev@gmail.com>2024-07-03 11:19:55 +0200
commit0ba46403c622f1c60695852a0c61f15880a95d2c (patch)
tree5c2ef08acc753703b5937277fd3ab82dafa9fd44 /src
parentcac43a1f5f6e5289db67ffac45954aec51ff9c15 (diff)
downloadbox64-0ba46403c622f1c60695852a0c61f15880a95d2c.tar.gz
box64-0ba46403c622f1c60695852a0c61f15880a95d2c.zip
Detect UnityPlayer.dll to apply strongmem=1 automatically (can be disabled with BOX64_UNITYPLAYER=0)
Diffstat (limited to 'src')
-rw-r--r--src/core.c10
-rw-r--r--src/include/debug.h1
-rw-r--r--src/tools/rcfile.c1
-rw-r--r--src/wrapped/wrappedlibc.c16
4 files changed, 28 insertions, 0 deletions
diff --git a/src/core.c b/src/core.c
index fbd41ba4..f31efadd 100644
--- a/src/core.c
+++ b/src/core.c
@@ -129,6 +129,7 @@ int box64_dynarec = 0;
 #endif
 int box64_libcef = 1;
 int box64_jvm = 1;
+int box64_unityplayer = 1;
 int box64_sdl2_jguid = 0;
 int dlsym_error = 0;
 int cycle_log = 0;
@@ -924,6 +925,15 @@ void LoadLogEnv()
         if(!box64_jvm)
             printf_log(LOG_INFO, "BOX64 will not detect libjvm\n");
     }
+    p = getenv("BOX64_UNITYPLAYER");
+    if(p) {
+        if(strlen(p)==1) {
+            if(p[0]>='0' && p[0]<='1')
+                box64_unityplayer = p[0]-'0';
+        }
+        if(!box64_unityplayer)
+            printf_log(LOG_INFO, "BOX64 will not detect UnityPlayer.dll\n");
+    }
     p = getenv("BOX64_SDL2_JGUID");
     if(p) {
         if(strlen(p)==1) {
diff --git a/src/include/debug.h b/src/include/debug.h
index 98f6281e..45b8e560 100644
--- a/src/include/debug.h
+++ b/src/include/debug.h
@@ -73,6 +73,7 @@ extern int la64_scq;
 #endif
 extern int box64_libcef;
 extern int box64_jvm;
+extern int box64_unityplayer;
 extern int box64_sdl2_jguid;
 extern int dlsym_error;    // log dlsym error
 extern int cycle_log;      // if using rolling logs
diff --git a/src/tools/rcfile.c b/src/tools/rcfile.c
index 3147cc4a..26f3aabb 100644
--- a/src/tools/rcfile.c
+++ b/src/tools/rcfile.c
@@ -112,6 +112,7 @@ ENTRYBOOL(BOX64_CEFDISABLEGPUCOMPOSITOR, box64_cefdisablegpucompositor)\
 ENTRYBOOL(BOX64_EXIT, want_exit)                        \
 ENTRYBOOL(BOX64_LIBCEF, box64_libcef)                   \
 ENTRYBOOL(BOX64_JVM, box64_jvm)                         \
+ENTRYBOOL(BOX64_UNITYPLAYER, box64_unityplayer)         \
 ENTRYBOOL(BOX64_SDL2_JGUID, box64_sdl2_jguid)           \
 ENTRYINT(BOX64_MALLOC_HACK, box64_malloc_hack, 0, 2, 2) \
 ENTRYINTPOS(BOX64_MAXCPU, new_maxcpu)                   \
diff --git a/src/wrapped/wrappedlibc.c b/src/wrapped/wrappedlibc.c
index f0e51241..76ac38f8 100644
--- a/src/wrapped/wrappedlibc.c
+++ b/src/wrapped/wrappedlibc.c
@@ -2883,6 +2883,22 @@ EXPORT void* my_mmap64(x64emu_t* emu, void *addr, unsigned long length, int prot
                 prot |= PROT_NEVERCLEAN;
             }
         }
+        static int unityplayer_detected = 0;
+        if(fd>0 && box64_unityplayer && !unityplayer_detected) {
+            char filename[4096];
+            char buf[128];
+            sprintf(buf, "/proc/self/fd/%d", fd);
+            ssize_t r = readlink(buf, filename, sizeof(filename)-1);
+            if(r!=1) filename[r]=0;
+            if(r>0 && strlen(filename)>strlen("UnityPlayer.dll") && !strcasecmp(filename+strlen(filename)-strlen("UnityPlayer.dll"), "UnityPlayer.dll")) {
+                printf_log(LOG_INFO, "BOX64: Detected UnityPlayer.dll\n");
+                #ifdef DYNAREC
+                if(!box64_dynarec_strongmem)
+                    box64_dynarec_strongmem = 1;
+                #endif
+                unityplayer_detected = 1;
+            }
+        }
         if(emu)
             setProtection_mmap((uintptr_t)ret, length, prot);
         else