about summary refs log tree commit diff stats
path: root/src/libtools/signals.c
diff options
context:
space:
mode:
authorYang Liu <liuyang22@iscas.ac.cn>2025-04-10 20:09:23 +0800
committerGitHub <noreply@github.com>2025-04-10 14:09:23 +0200
commit0bb41a73c27df807ba8fcaa205612be7b3a1ac95 (patch)
treee789a5ff074bae6d492c6ea19f824cdecc7e3d37 /src/libtools/signals.c
parentf9f082ee53ae0ab8e12b0c1bf1de339af8b92282 (diff)
downloadbox64-0bb41a73c27df807ba8fcaa205612be7b3a1ac95.tar.gz
box64-0bb41a73c27df807ba8fcaa205612be7b3a1ac95.zip
[WOW64] More tweaks towards PE build (#2519)
Diffstat (limited to 'src/libtools/signals.c')
-rw-r--r--src/libtools/signals.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/libtools/signals.c b/src/libtools/signals.c
index 99ddd41e..c85c4401 100644
--- a/src/libtools/signals.c
+++ b/src/libtools/signals.c
@@ -1069,6 +1069,51 @@ int sigbus_specialcases(siginfo_t* info, void * ucntx, void* pc, void* _fpsimd,
 #undef CHECK
 }
 
+#ifdef USE_CUSTOM_MUTEX
+extern uint32_t mutex_prot;
+extern uint32_t mutex_blocks;
+#else
+extern pthread_mutex_t mutex_prot;
+extern pthread_mutex_t mutex_blocks;
+#endif
+
+// unlock mutex that are locked by current thread (for signal handling). Return a mask of unlock mutex
+int unlockMutex()
+{
+    int ret = 0;
+    int i;
+    #ifdef USE_CUSTOM_MUTEX
+    uint32_t tid = (uint32_t)GetTID();
+    #define GO(A, B)                                    \
+    i = (native_lock_storeifref2_d(&A, 0, tid) == tid); \
+    if (i) {                                            \
+        ret |= (1 << B);                                \
+    }
+    #else
+    #define GO(A, B)          \
+    i = checkUnlockMutex(&A); \
+    if (i) {                  \
+        ret |= (1 << B);      \
+    }
+    #endif
+
+    GO(mutex_blocks, 0)
+    GO(mutex_prot, 1)
+
+    GO(my_context->mutex_trace, 7)
+    #ifdef DYNAREC
+    GO(my_context->mutex_dyndump, 8)
+    #else
+    GO(my_context->mutex_lock, 8)
+    #endif
+    GO(my_context->mutex_tls, 9)
+    GO(my_context->mutex_thread, 10)
+    GO(my_context->mutex_bridge, 11)
+    #undef GO
+
+    return ret;
+}
+
 #ifdef BOX32
 void my_sigactionhandler_oldcode_32(x64emu_t* emu, int32_t sig, int simple, siginfo_t* info, void * ucntx, int* old_code, void* cur_db);
 #endif