diff options
| author | ptitSeb <sebastien.chev@gmail.com> | 2021-06-06 08:30:57 +0200 |
|---|---|---|
| committer | ptitSeb <sebastien.chev@gmail.com> | 2021-06-06 08:30:57 +0200 |
| commit | 3b181576c847249303498621e609f7bf059c7597 (patch) | |
| tree | 1283bf08fa2830ecf2cd3e3fad27df1da3ef8774 /src | |
| parent | 409334ea5650fa706827abd08676dfbb2244b0a4 (diff) | |
| download | box64-3b181576c847249303498621e609f7bf059c7597.tar.gz box64-3b181576c847249303498621e609f7bf059c7597.zip | |
Added a wrapped pthread function, and improved mutex handling
Diffstat (limited to 'src')
| -rwxr-xr-x | src/libtools/threads.c | 22 | ||||
| -rwxr-xr-x | src/wrapped/wrappedlibpthread_private.h | 4 |
2 files changed, 20 insertions, 6 deletions
diff --git a/src/libtools/threads.c b/src/libtools/threads.c index 054451ff..d92472a7 100755 --- a/src/libtools/threads.c +++ b/src/libtools/threads.c @@ -741,10 +741,11 @@ KHASH_MAP_INIT_INT(mutex, pthread_mutex_t*) static kh_mutex_t* unaligned_mutex = NULL; #endif - +// x86_64 pthread_mutex_t is 40 bytes (ARM64 one is 48) typedef struct aligned_mutex_s { uint64_t dummy; pthread_mutex_t *m; + struct aligned_mutex_s *self; uint64_t sign; } aligned_mutex_t; #define SIGNMTX *(uint64_t*)"BOX64MTX" @@ -754,7 +755,7 @@ pthread_mutex_t* getAlignedMutexWithInit(pthread_mutex_t* m, int init) if(!m) return NULL; aligned_mutex_t* am = (aligned_mutex_t*)m; - if(init && (am->sign==SIGNMTX)) + if(init && (am->sign==SIGNMTX && am->self==am)) return am->m; #ifdef TRACK_MUTEX khint_t k = kh_get(mutex, unaligned_mutex, (uintptr_t)m); @@ -767,8 +768,13 @@ pthread_mutex_t* getAlignedMutexWithInit(pthread_mutex_t* m, int init) pthread_mutex_t* ret = (pthread_mutex_t*)calloc(1, sizeof(pthread_mutex_t)); #endif 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) + if(am->sign == SIGNMTX) { + int kind = ((int*)am->m)[3+__PTHREAD_MUTEX_HAVE_PREV]; // extract kind from original mutex + ((int*)ret)[3+__PTHREAD_MUTEX_HAVE_PREV] = kind; // inject in new one (i.e. "init" it) + } else { + 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; @@ -828,6 +834,14 @@ EXPORT int my_pthread_mutexattr_getkind_np(x64emu_t* emu, my_mutexattr_t *attr, attr->x86 = mattr.x86; return ret; } +EXPORT int my_pthread_mutexattr_getprotocol(x64emu_t* emu, my_mutexattr_t *attr, void* p) +{ + my_mutexattr_t mattr = {0}; + mattr.x86 = attr->x86; + int ret = pthread_mutexattr_getprotocol(&mattr.nat, p); + attr->x86 = mattr.x86; + return ret; +} EXPORT int my_pthread_mutexattr_gettype(x64emu_t* emu, my_mutexattr_t *attr, void* p) { my_mutexattr_t mattr = {0}; diff --git a/src/wrapped/wrappedlibpthread_private.h b/src/wrapped/wrappedlibpthread_private.h index 2b1405ff..1b16199d 100755 --- a/src/wrapped/wrappedlibpthread_private.h +++ b/src/wrapped/wrappedlibpthread_private.h @@ -136,7 +136,7 @@ GO(__pthread_mutexattr_destroy, iFp) GO(pthread_mutexattr_destroy, iFp) GO(pthread_mutexattr_getkind_np, iFpp) // pthread_mutexattr_getprioceiling -// pthread_mutexattr_getprotocol +GO(pthread_mutexattr_getprotocol, iFpp) // pthread_mutexattr_getpshared // pthread_mutexattr_getrobust_np GO(pthread_mutexattr_gettype, iFpp) @@ -154,7 +154,7 @@ GOM(__pthread_mutexattr_destroy, iFEp) GOM(pthread_mutexattr_destroy, iFEp) GOM(pthread_mutexattr_getkind_np, iFEpp) // pthread_mutexattr_getprioceiling -// pthread_mutexattr_getprotocol +GOM(pthread_mutexattr_getprotocol, iFEpp) // pthread_mutexattr_getpshared // pthread_mutexattr_getrobust_np GOM(pthread_mutexattr_gettype, iFEpp) |