about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorYang Liu <liuyang22@iscas.ac.cn>2025-01-23 18:43:24 +0800
committerGitHub <noreply@github.com>2025-01-23 11:43:24 +0100
commitf0d8712275d2ca1b27d7022acf48cde647bdacd5 (patch)
tree760e60c42e378ade560cb1d0a824ba0cfd9ebe8d /src
parentfe3b66b018adb3d7a89289fc1c74f80309938716 (diff)
downloadbox64-f0d8712275d2ca1b27d7022acf48cde647bdacd5.tar.gz
box64-f0d8712275d2ca1b27d7022acf48cde647bdacd5.zip
Clean up UnityPlayer.dll detection from my_mmap64 (#2286)
Diffstat (limited to 'src')
-rw-r--r--src/include/wine_tools.h2
-rw-r--r--src/tools/wine_tools.c22
-rw-r--r--src/wrapped/wrappedlibc.c17
3 files changed, 26 insertions, 15 deletions
diff --git a/src/include/wine_tools.h b/src/include/wine_tools.h
index 5c60fec2..4529a6d4 100644
--- a/src/include/wine_tools.h
+++ b/src/include/wine_tools.h
@@ -10,4 +10,6 @@ void* get_wine_prereserve(void);
 void dynarec_wine_prereserve(void);
 #endif
 
+void detect_unityplayer(int fd);
+
 #endif //__WINE_TOOLS_H__
diff --git a/src/tools/wine_tools.c b/src/tools/wine_tools.c
index 96978bed..ffbebdf2 100644
--- a/src/tools/wine_tools.c
+++ b/src/tools/wine_tools.c
@@ -149,3 +149,25 @@ void dynarec_wine_prereserve()
     #endif
 }
 #endif
+
+void detect_unityplayer(int fd)
+{
+    static int unityplayer_detected = 0;
+    if (fd > 0 && BOX64ENV(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_NONE, "Detected UnityPlayer.dll\n");
+#ifdef DYNAREC
+            if (!BOX64ENV(dynarec_strongmem)) {
+                SET_BOX64ENV(dynarec_strongmem, 1);
+                PrintEnvVariables();
+            }
+#endif
+            unityplayer_detected = 1;
+        }
+    }
+}
\ No newline at end of file
diff --git a/src/wrapped/wrappedlibc.c b/src/wrapped/wrappedlibc.c
index 7afa134f..ead6574d 100644
--- a/src/wrapped/wrappedlibc.c
+++ b/src/wrapped/wrappedlibc.c
@@ -65,6 +65,7 @@
 #include "bridge.h"
 #include "globalsymbols.h"
 #include "env.h"
+#include "wine_tools.h"
 #ifndef LOG_INFO
 #define LOG_INFO 1
 #endif
@@ -3004,21 +3005,7 @@ EXPORT void* my_mmap64(x64emu_t* emu, void *addr, size_t length, int prot, int f
                 prot |= PROT_NEVERCLEAN;
             }
         }
-        static int unityplayer_detected = 0;
-        if(fd>0 && BOX64ENV(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, "Detected UnityPlayer.dll\n");
-                #ifdef DYNAREC
-                if(!BOX64ENV(dynarec_strongmem)) SET_BOX64ENV(dynarec_strongmem, 1);
-                #endif
-                unityplayer_detected = 1;
-            }
-        }
+        detect_unityplayer(fd);
         if(emu)
             setProtection_mmap((uintptr_t)ret, length, prot);
         else