about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorYang Liu <numbksco@gmail.com>2024-05-24 16:14:49 +0800
committerGitHub <noreply@github.com>2024-05-24 10:14:49 +0200
commit2ee846f48e7fa9b103f0949f63f91712ca7b03ca (patch)
treee9521f080520ee0361275a4a6b3f5a5c4fca136f
parent9c846a3e40ca96e580e4ab4b3db38f1ed7f791ea (diff)
downloadbox64-2ee846f48e7fa9b103f0949f63f91712ca7b03ca.tar.gz
box64-2ee846f48e7fa9b103f0949f63f91712ca7b03ca.zip
Workaround on a race condition on SDL_GetThreadID (#1530)
-rw-r--r--src/wrapped/generated/functions_list.txt3
-rw-r--r--src/wrapped/generated/wrappedsdl2types.h2
-rw-r--r--src/wrapped/generated/wrapper.c2
-rw-r--r--src/wrapped/generated/wrapper.h1
-rw-r--r--src/wrapped/wrappedsdl2.c11
-rw-r--r--src/wrapped/wrappedsdl2_private.h2
6 files changed, 20 insertions, 1 deletions
diff --git a/src/wrapped/generated/functions_list.txt b/src/wrapped/generated/functions_list.txt
index efd28192..6137a407 100644
--- a/src/wrapped/generated/functions_list.txt
+++ b/src/wrapped/generated/functions_list.txt
@@ -290,6 +290,7 @@
 #() lFpl
 #() lFpp
 #() LFEL
+#() LFEp
 #() LFii
 #() LFuu
 #() LFUp
@@ -5268,6 +5269,8 @@ wrappedsdl2:
 - UFp:
   - SDL_ReadBE64
   - SDL_ReadLE64
+- LFp:
+  - SDL_GetThreadID
 - pFv:
   - SDL_GetBasePath
   - SDL_Vulkan_GetVkGetInstanceProcAddr
diff --git a/src/wrapped/generated/wrappedsdl2types.h b/src/wrapped/generated/wrappedsdl2types.h
index ef568de9..8386e999 100644
--- a/src/wrapped/generated/wrappedsdl2types.h
+++ b/src/wrapped/generated/wrappedsdl2types.h
@@ -17,6 +17,7 @@ typedef int32_t (*iFp_t)(void*);
 typedef int64_t (*IFp_t)(void*);
 typedef uint32_t (*uFp_t)(void*);
 typedef uint64_t (*UFp_t)(void*);
+typedef uintptr_t (*LFp_t)(void*);
 typedef void* (*pFv_t)(void);
 typedef void* (*pFp_t)(void*);
 typedef void (*vFpp_t)(void*, void*);
@@ -74,6 +75,7 @@ typedef void* (*pFpippp_t)(void*, int32_t, void*, void*, void*);
 	GO(SDL_ReadU8, uFp_t) \
 	GO(SDL_ReadBE64, UFp_t) \
 	GO(SDL_ReadLE64, UFp_t) \
+	GO(SDL_GetThreadID, LFp_t) \
 	GO(SDL_GetBasePath, pFv_t) \
 	GO(SDL_Vulkan_GetVkGetInstanceProcAddr, pFv_t) \
 	GO(SDL_GL_GetProcAddress, pFp_t) \
diff --git a/src/wrapped/generated/wrapper.c b/src/wrapped/generated/wrapper.c
index 35756ba3..dbe6fb4c 100644
--- a/src/wrapped/generated/wrapper.c
+++ b/src/wrapped/generated/wrapper.c
@@ -328,6 +328,7 @@ typedef intptr_t (*lFpd_t)(void*, double);
 typedef intptr_t (*lFpl_t)(void*, intptr_t);
 typedef intptr_t (*lFpp_t)(void*, void*);
 typedef uintptr_t (*LFEL_t)(x64emu_t*, uintptr_t);
+typedef uintptr_t (*LFEp_t)(x64emu_t*, void*);
 typedef uintptr_t (*LFii_t)(int32_t, int32_t);
 typedef uintptr_t (*LFuu_t)(uint32_t, uint32_t);
 typedef uintptr_t (*LFUp_t)(uint64_t, void*);
@@ -3408,6 +3409,7 @@ void lFpd(x64emu_t *emu, uintptr_t fcn) { lFpd_t fn = (lFpd_t)fcn; R_RAX=(intptr
 void lFpl(x64emu_t *emu, uintptr_t fcn) { lFpl_t fn = (lFpl_t)fcn; R_RAX=(intptr_t)fn((void*)R_RDI, (intptr_t)R_RSI); }
 void lFpp(x64emu_t *emu, uintptr_t fcn) { lFpp_t fn = (lFpp_t)fcn; R_RAX=(intptr_t)fn((void*)R_RDI, (void*)R_RSI); }
 void LFEL(x64emu_t *emu, uintptr_t fcn) { LFEL_t fn = (LFEL_t)fcn; R_RAX=(uintptr_t)fn(emu, (uintptr_t)R_RDI); }
+void LFEp(x64emu_t *emu, uintptr_t fcn) { LFEp_t fn = (LFEp_t)fcn; R_RAX=(uintptr_t)fn(emu, (void*)R_RDI); }
 void LFii(x64emu_t *emu, uintptr_t fcn) { LFii_t fn = (LFii_t)fcn; R_RAX=(uintptr_t)fn((int32_t)R_RDI, (int32_t)R_RSI); }
 void LFuu(x64emu_t *emu, uintptr_t fcn) { LFuu_t fn = (LFuu_t)fcn; R_RAX=(uintptr_t)fn((uint32_t)R_RDI, (uint32_t)R_RSI); }
 void LFUp(x64emu_t *emu, uintptr_t fcn) { LFUp_t fn = (LFUp_t)fcn; R_RAX=(uintptr_t)fn((uint64_t)R_RDI, (void*)R_RSI); }
diff --git a/src/wrapped/generated/wrapper.h b/src/wrapped/generated/wrapper.h
index 84ab7636..089530ab 100644
--- a/src/wrapped/generated/wrapper.h
+++ b/src/wrapped/generated/wrapper.h
@@ -328,6 +328,7 @@ void lFpd(x64emu_t *emu, uintptr_t fnc);
 void lFpl(x64emu_t *emu, uintptr_t fnc);
 void lFpp(x64emu_t *emu, uintptr_t fnc);
 void LFEL(x64emu_t *emu, uintptr_t fnc);
+void LFEp(x64emu_t *emu, uintptr_t fnc);
 void LFii(x64emu_t *emu, uintptr_t fnc);
 void LFuu(x64emu_t *emu, uintptr_t fnc);
 void LFUp(x64emu_t *emu, uintptr_t fnc);
diff --git a/src/wrapped/wrappedsdl2.c b/src/wrapped/wrappedsdl2.c
index d12cea24..299237f2 100644
--- a/src/wrapped/wrappedsdl2.c
+++ b/src/wrapped/wrappedsdl2.c
@@ -820,6 +820,17 @@ EXPORT void my2_SDL_GetJoystickGUIDInfo(SDL_JoystickGUID guid, uint16_t *vend, u
     }
 }
 
+EXPORT unsigned long my2_SDL_GetThreadID(x64emu_t* emu, void* thread)
+{
+    unsigned long ret = my->SDL_GetThreadID(thread);
+    int max = 10;
+    while (!ret && max--) {
+        sched_yield();
+        ret = my->SDL_GetThreadID(thread);
+    }
+    return ret;
+}
+
 #undef HAS_MY
 
 #define ALTMY my2_
diff --git a/src/wrapped/wrappedsdl2_private.h b/src/wrapped/wrappedsdl2_private.h
index b3e6ef7d..b3c100ca 100644
--- a/src/wrapped/wrappedsdl2_private.h
+++ b/src/wrapped/wrappedsdl2_private.h
@@ -265,7 +265,7 @@ GO(SDL_GetSystemRAM, iFv)
 GO(SDL_GetTextureAlphaMod, iFpp)
 GO(SDL_GetTextureBlendMode, iFpp)
 GO(SDL_GetTextureColorMod, iFpppp)
-GO(SDL_GetThreadID, LFp)
+GOM(SDL_GetThreadID, LFEp)
 GO(SDL_GetThreadName, pFp)
 GO(SDL_GetTicks, uFv)
 GO(SDL_GetTicks64, UFv)