about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2021-04-12 14:29:38 +0200
committerptitSeb <sebastien.chev@gmail.com>2021-04-12 14:29:38 +0200
commit88798b78fcfef6128480d95c35f3a6970403eb34 (patch)
tree08471705134a5b0dddfb3d6798a340e2ed6116ad /src
parent0ce7390ac1fa5221f47b954ae954586de7df13ab (diff)
downloadbox64-88798b78fcfef6128480d95c35f3a6970403eb34.tar.gz
box64-88798b78fcfef6128480d95c35f3a6970403eb34.zip
Improved pthread wrapping
Diffstat (limited to 'src')
-rwxr-xr-xsrc/libtools/threads.c21
-rw-r--r--src/wrapped/generated/functions_list.txt1
-rw-r--r--src/wrapped/generated/wrappedlibpthreadtypes.h24
-rw-r--r--src/wrapped/generated/wrapper.c2
-rw-r--r--src/wrapped/generated/wrapper.h1
-rwxr-xr-xsrc/wrapped/wrappedlibpthread_private.h11
6 files changed, 51 insertions, 9 deletions
diff --git a/src/libtools/threads.c b/src/libtools/threads.c
index 1d7540f8..3c73105b 100755
--- a/src/libtools/threads.c
+++ b/src/libtools/threads.c
@@ -633,7 +633,7 @@ EXPORT int my_pthread_cond_wait(x64emu_t* emu, pthread_cond_t* cond, void* mutex
 	return pthread_cond_wait(cond, getAlignedMutex((pthread_mutex_t*)mutex));
 }
 
-//EXPORT int my_pthread_attr_setscope(x64emu_t* emu, void* attr, int scope)
+//EXPORT int my_pthread_attr_setscope(x64emu_t* emu, void* at*tr, int scope)
 //{
 //    if(scope!=PTHREAD_SCOPE_SYSTEM) printf_log(LOG_INFO, "Warning, scope of call to pthread_attr_setscope(...) changed from %d to PTHREAD_SCOPE_SYSTEM\n", scope);
 //	return pthread_attr_setscope(attr, PTHREAD_SCOPE_SYSTEM);
@@ -719,15 +719,16 @@ static kh_mutex_t* unaligned_mutex = NULL;
 #endif
 
 typedef struct aligned_mutex_s {
-	uint64_t sign;
+	uint64_t	dummy;
 	pthread_mutex_t *m;
+	uint64_t sign;
 } aligned_mutex_t;
-#define SIGN *(uint64_t*)"BOX64MTX"
+#define SIGNMTX *(uint64_t*)"BOX64MTX"
 
 pthread_mutex_t* getAlignedMutexWithInit(pthread_mutex_t* m, int init)
 {
 	aligned_mutex_t* am = (aligned_mutex_t*)m;
-	if(init && am->sign==SIGN)
+	if(init && (am->sign==SIGNMTX))
 		return am->m;
 	#ifdef TRACK_MUTEX
 	khint_t k = kh_get(mutex, unaligned_mutex, (uintptr_t)m);
@@ -739,10 +740,12 @@ pthread_mutex_t* getAlignedMutexWithInit(pthread_mutex_t* m, int init)
 	#else
 	pthread_mutex_t* ret = (pthread_mutex_t*)calloc(1, sizeof(pthread_mutex_t));
 	#endif
-	am->sign = SIGN;
+	if(init) {
+		int kind = ((int*)m)[4];	// extract kind from original mutex
+		((int*)ret)[3+__PTHREAD_MUTEX_HAVE_PREV] = kind;		// inject in new one (i.e. "init" it)
+	}
+	am->sign = SIGNMTX;
 	am->m = ret;
-	if(init)
-		pthread_mutex_init(ret, NULL);	// default init, same as with static constructor
 	return ret;
 }
 pthread_mutex_t* getAlignedMutex(pthread_mutex_t* m)
@@ -754,7 +757,7 @@ EXPORT int my_pthread_mutex_destroy(pthread_mutex_t *m)
 {
 	aligned_mutex_t* am = (aligned_mutex_t*)m;
 	#ifdef TRACK_MUTEX
-	if(am->sign==SIGN) {
+	if(am->sign==SIGNMTX) {
 		am->sign = 0;
 		am->m = NULL;
 	}
@@ -768,7 +771,7 @@ EXPORT int my_pthread_mutex_destroy(pthread_mutex_t *m)
 	}
 	return pthread_mutex_destroy(m);
 	#else
-	if(am->sign!=SIGN) {
+	if(am->sign!=SIGNMTX) {
 		return 1;	//???
 	}
 	int ret = pthread_mutex_destroy(am->m);
diff --git a/src/wrapped/generated/functions_list.txt b/src/wrapped/generated/functions_list.txt
index eef2095b..64481086 100644
--- a/src/wrapped/generated/functions_list.txt
+++ b/src/wrapped/generated/functions_list.txt
@@ -1179,6 +1179,7 @@
 #() pFiiiippppppppppppppp
 #() pFipppppppppppppppppppppp
 #!defined(NOALIGN) iFEpLp
+#!defined(NOALIGN) iFEppu
 #defined(HAVE_LD80BITS) DFD
 #defined(HAVE_LD80BITS) DFDD
 #defined(HAVE_LD80BITS) DFDp
diff --git a/src/wrapped/generated/wrappedlibpthreadtypes.h b/src/wrapped/generated/wrappedlibpthreadtypes.h
index 6b2f2751..87d38988 100644
--- a/src/wrapped/generated/wrappedlibpthreadtypes.h
+++ b/src/wrapped/generated/wrappedlibpthreadtypes.h
@@ -19,6 +19,7 @@ typedef int64_t (*iFpL_t)(void*, uintptr_t);
 typedef int64_t (*iFpp_t)(void*, void*);
 typedef void (*vFppp_t)(void*, void*, void*);
 typedef int64_t (*iFpLp_t)(void*, uintptr_t, void*);
+typedef int64_t (*iFppu_t)(void*, void*, uint64_t);
 typedef int64_t (*iFppL_t)(void*, void*, uintptr_t);
 typedef int64_t (*iFppp_t)(void*, void*, void*);
 typedef int64_t (*iFpppp_t)(void*, void*, void*, void*);
@@ -27,15 +28,31 @@ typedef int64_t (*iFpppp_t)(void*, void*, void*, void*);
 	GO(__pthread_register_cancel, vFp_t) \
 	GO(__pthread_unregister_cancel, vFp_t) \
 	GO(__pthread_unwind_next, vFp_t) \
+	GO(__pthread_mutexattr_destroy, iFp_t) \
+	GO(__pthread_mutexattr_init, iFp_t) \
 	GO(pthread_attr_destroy, iFp_t) \
 	GO(pthread_attr_init, iFp_t) \
+	GO(pthread_barrierattr_destroy, iFp_t) \
+	GO(pthread_barrierattr_init, iFp_t) \
+	GO(pthread_condattr_destroy, iFp_t) \
+	GO(pthread_condattr_init, iFp_t) \
+	GO(pthread_mutexattr_destroy, iFp_t) \
+	GO(pthread_mutexattr_init, iFp_t) \
 	GO(_pthread_cleanup_pop, vFpi_t) \
 	GO(_pthread_cleanup_pop_restore, vFpi_t) \
+	GO(__pthread_mutexattr_settype, iFpi_t) \
 	GO(pthread_attr_setdetachstate, iFpi_t) \
 	GO(pthread_attr_setinheritsched, iFpi_t) \
 	GO(pthread_attr_setschedpolicy, iFpi_t) \
 	GO(pthread_attr_setscope, iFpi_t) \
+	GO(pthread_barrierattr_setpshared, iFpi_t) \
+	GO(pthread_condattr_setclock, iFpi_t) \
+	GO(pthread_condattr_setpshared, iFpi_t) \
 	GO(pthread_kill, iFpi_t) \
+	GO(pthread_mutexattr_setkind_np, iFpi_t) \
+	GO(pthread_mutexattr_setprotocol, iFpi_t) \
+	GO(pthread_mutexattr_setpshared, iFpi_t) \
+	GO(pthread_mutexattr_settype, iFpi_t) \
 	GO(pthread_attr_setguardsize, iFpL_t) \
 	GO(pthread_attr_setstacksize, iFpL_t) \
 	GO(__pthread_key_create, iFpp_t) \
@@ -50,12 +67,19 @@ typedef int64_t (*iFpppp_t)(void*, void*, void*, void*);
 	GO(pthread_attr_getstacksize, iFpp_t) \
 	GO(pthread_attr_setschedparam, iFpp_t) \
 	GO(pthread_attr_setstackaddr, iFpp_t) \
+	GO(pthread_barrierattr_getpshared, iFpp_t) \
+	GO(pthread_cond_init, iFpp_t) \
 	GO(pthread_cond_wait, iFpp_t) \
+	GO(pthread_condattr_getclock, iFpp_t) \
+	GO(pthread_condattr_getpshared, iFpp_t) \
 	GO(pthread_key_create, iFpp_t) \
+	GO(pthread_mutexattr_getkind_np, iFpp_t) \
+	GO(pthread_mutexattr_gettype, iFpp_t) \
 	GO(pthread_once, iFpp_t) \
 	GO(_pthread_cleanup_push, vFppp_t) \
 	GO(_pthread_cleanup_push_defer, vFppp_t) \
 	GO(pthread_attr_setaffinity_np, iFpLp_t) \
+	GO(pthread_barrier_init, iFppu_t) \
 	GO(pthread_attr_setstack, iFppL_t) \
 	GO(__pthread_atfork, iFppp_t) \
 	GO(pthread_atfork, iFppp_t) \
diff --git a/src/wrapped/generated/wrapper.c b/src/wrapped/generated/wrapper.c
index 32952925..94bbbc70 100644
--- a/src/wrapped/generated/wrapper.c
+++ b/src/wrapped/generated/wrapper.c
@@ -1215,6 +1215,7 @@ typedef void* (*pFipppppppppppppppppppppp_t)(int64_t, void*, void*, void*, void*
 
 #if !defined(NOALIGN)
 typedef int64_t (*iFEpLp_t)(x64emu_t*, void*, uintptr_t, void*);
+typedef int64_t (*iFEppu_t)(x64emu_t*, void*, void*, uint64_t);
 #endif
 
 #if defined(HAVE_LD80BITS)
@@ -2412,6 +2413,7 @@ void pFipppppppppppppppppppppp(x64emu_t *emu, uintptr_t fcn) { pFipppppppppppppp
 
 #if !defined(NOALIGN)
 void iFEpLp(x64emu_t *emu, uintptr_t fcn) { iFEpLp_t fn = (iFEpLp_t)fcn; R_RAX=(int64_t)fn(emu, (void*)R_RDI, (uintptr_t)R_RSI, (void*)R_RDX); }
+void iFEppu(x64emu_t *emu, uintptr_t fcn) { iFEppu_t fn = (iFEppu_t)fcn; R_RAX=(int64_t)fn(emu, (void*)R_RDI, (void*)R_RSI, (uint64_t)R_RDX); }
 #endif
 
 #if defined(HAVE_LD80BITS)
diff --git a/src/wrapped/generated/wrapper.h b/src/wrapped/generated/wrapper.h
index 295f051c..a0a0ba98 100644
--- a/src/wrapped/generated/wrapper.h
+++ b/src/wrapped/generated/wrapper.h
@@ -1211,6 +1211,7 @@ void pFipppppppppppppppppppppp(x64emu_t *emu, uintptr_t fnc);
 
 #if !defined(NOALIGN)
 void iFEpLp(x64emu_t *emu, uintptr_t fnc);
+void iFEppu(x64emu_t *emu, uintptr_t fnc);
 #endif
 
 #if defined(HAVE_LD80BITS)
diff --git a/src/wrapped/wrappedlibpthread_private.h b/src/wrapped/wrappedlibpthread_private.h
index 4b36d306..ca0202b0 100755
--- a/src/wrapped/wrappedlibpthread_private.h
+++ b/src/wrapped/wrappedlibpthread_private.h
@@ -62,12 +62,23 @@ GOM(pthread_attr_setstackaddr, iFEpp)
 #endif
 GOM(pthread_attr_setstack, iFEppL)
 GOM(pthread_attr_setstacksize, iFEpL)
+#ifdef NOALIGN
 GO(pthread_barrierattr_destroy, iFp)
 GO(pthread_barrierattr_getpshared, iFpp)
 GO(pthread_barrierattr_init, iFp)
 GO(pthread_barrierattr_setpshared, iFpi)
+#else
+GOM(pthread_barrierattr_destroy, iFEp)
+GOM(pthread_barrierattr_getpshared, iFEpp)
+GOM(pthread_barrierattr_init, iFEp)
+GOM(pthread_barrierattr_setpshared, iFEpi)
+#endif
 GO(pthread_barrier_destroy, iFp)
+#ifdef NOALIGN
 GO(pthread_barrier_init, iFppu)
+#else
+GOM(pthread_barrier_init, iFEppu)
+#endif
 GO(pthread_barrier_wait, iFp)
 GO(pthread_cancel, iFL)
 GOM(_pthread_cleanup_pop, vFEpi)