about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2024-09-11 18:01:23 +0200
committerptitSeb <sebastien.chev@gmail.com>2024-09-11 18:01:23 +0200
commitfc7f83c60b82e77712165dd600501af2c59b8d3b (patch)
tree7fcb1621a399ca98bec55b6ec08158949ae4e494 /src
parentaf028c9bad11d4e8d6a4f4c01b4856a2c8f2d2ce (diff)
downloadbox64-fc7f83c60b82e77712165dd600501af2c59b8d3b.tar.gz
box64-fc7f83c60b82e77712165dd600501af2c59b8d3b.zip
[BOX32][WRAPPER] Added support for old pthread_kill (fixing hanging steamcmd)
Diffstat (limited to 'src')
-rwxr-xr-xsrc/libtools/threads32.c23
-rw-r--r--src/wrapped32/generated/functions_list.txt2
-rw-r--r--src/wrapped32/generated/wrappedlibpthreadtypes32.h2
-rwxr-xr-xsrc/wrapped32/wrappedlibpthread_private.h3
4 files changed, 24 insertions, 6 deletions
diff --git a/src/libtools/threads32.c b/src/libtools/threads32.c
index 74820c4f..f8996650 100755
--- a/src/libtools/threads32.c
+++ b/src/libtools/threads32.c
@@ -35,10 +35,14 @@
 
 typedef void (*vFppp_t)(void*, void*, void*);
 typedef void (*vFpi_t)(void*, int);
+typedef int  (*iFLi_t)(unsigned long, int);
 //starting with glibc 2.34+, those 2 functions are in libc.so as versionned symbol only
 // So use dlsym to get the symbol unversionned, as simple link will not work.
 static vFppp_t real_pthread_cleanup_push_defer = NULL;
 static vFpi_t real_pthread_cleanup_pop_restore = NULL;
+// with glibc 2.34+, pthread_kill changed behaviour and might break some program, so using old version if possible
+// it will be pthread_kill@GLIBC_2.0+, need to be found, while it's GLIBC_2.0 on i386
+static iFLi_t real_phtread_kill_old = NULL;
 // those function can be used simply
 void _pthread_cleanup_push(void* buffer, void* routine, void* arg);	// declare hidden functions
 void _pthread_cleanup_pop(void* buffer, int exec);
@@ -762,12 +766,12 @@ EXPORT int my32_pthread_attr_setaffinity_np(x64emu_t* emu, void* attr, uint32_t
 }
 #endif
 
-EXPORT int my32_pthread_kill(x64emu_t* emu, void* thread, int sig)
+EXPORT int my32_pthread_kill_old(x64emu_t* emu, void* thread, int sig)
 {
     // check for old "is everything ok?"
     if((thread==NULL) && (sig==0))
-        return pthread_kill(pthread_self(), 0);
-    return pthread_kill((pthread_t)thread, sig);
+        return real_phtread_kill_old(pthread_self(), 0);
+    return real_phtread_kill_old((pthread_t)thread, sig);
 }
 
 //EXPORT void my32_pthread_exit(x64emu_t* emu, void* retval)
@@ -866,6 +870,19 @@ void init_pthread_helper_32()
 	real_pthread_cleanup_push_defer = (vFppp_t)dlsym(NULL, "_pthread_cleanup_push_defer");
 	real_pthread_cleanup_pop_restore = (vFpi_t)dlsym(NULL, "_pthread_cleanup_pop_restore");
 
+	// search for older symbol for pthread_kill
+	{
+		char buff[50];
+		for(int i=0; i<34 && !real_phtread_kill_old; ++i) {
+			snprintf(buff, 50, "GLIBC_2.%d", i);
+			real_phtread_kill_old = (iFLi_t)dlvsym(NULL, "pthread_kill", buff);
+		}
+	}
+	if(!real_phtread_kill_old) {
+		printf_log(LOG_INFO, "Warning, older than 2.34 pthread_kill not found, using current one\n");
+		real_phtread_kill_old = (iFLi_t)pthread_kill;
+	}
+
 	mapcond = kh_init(mapcond);
 	unaligned_mutex = kh_init(mutex);
 	pthread_key_create(&thread_key, emuthread_destroy);
diff --git a/src/wrapped32/generated/functions_list.txt b/src/wrapped32/generated/functions_list.txt
index 2cd368f9..fdb450c0 100644
--- a/src/wrapped32/generated/functions_list.txt
+++ b/src/wrapped32/generated/functions_list.txt
@@ -568,7 +568,7 @@ wrappedlibpthread:
   - pthread_once
   - pthread_rwlock_init
 - iFhi:
-  - pthread_kill
+  - pthread_kill@GLIBC_2.0
 - vFppp:
   - _pthread_cleanup_push
   - _pthread_cleanup_push_defer
diff --git a/src/wrapped32/generated/wrappedlibpthreadtypes32.h b/src/wrapped32/generated/wrappedlibpthreadtypes32.h
index 16481475..200ad68a 100644
--- a/src/wrapped32/generated/wrappedlibpthreadtypes32.h
+++ b/src/wrapped32/generated/wrappedlibpthreadtypes32.h
@@ -87,7 +87,7 @@ typedef int32_t (*iFhppp_t)(uintptr_t, void*, void*, void*);
 	GO(pthread_mutex_timedlock, iFpp_t) \
 	GO(pthread_once, iFpp_t) \
 	GO(pthread_rwlock_init, iFpp_t) \
-	GO(pthread_kill, iFhi_t) \
+	GO(pthread_kill@GLIBC_2.0, iFhi_t) \
 	GO(_pthread_cleanup_push, vFppp_t) \
 	GO(_pthread_cleanup_push_defer, vFppp_t) \
 	GO(pthread_attr_setaffinity_np, iFpup_t) \
diff --git a/src/wrapped32/wrappedlibpthread_private.h b/src/wrapped32/wrappedlibpthread_private.h
index e5eb9fc7..fea570ab 100755
--- a/src/wrapped32/wrappedlibpthread_private.h
+++ b/src/wrapped32/wrappedlibpthread_private.h
@@ -88,7 +88,8 @@ GO(pthread_join, iFHBp_)
 GOM(__pthread_key_create, iFEpp)
 GOM(pthread_key_create, iFEpp)
 GO(pthread_key_delete, iFu)
-GOM(pthread_kill, iFEhi)
+GO(pthread_kill, iFhi)
+GO2(pthread_kill@GLIBC_2.0, iFEhi, my32_pthread_kill_old)
 // pthread_kill_other_threads_np
 GO(__pthread_mutexattr_destroy, iFp)
 GO(pthread_mutexattr_destroy, iFp)