about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2024-02-02 16:44:50 +0100
committerptitSeb <sebastien.chev@gmail.com>2024-02-02 16:44:50 +0100
commit153d8d2cf0085aba42c83e7d2d31ec6d3346075a (patch)
treeced3ec368ac40ff0b826d0a32c24706bb8e8ffab /src
parent1b07a10b5d04d2453406b7c8a778155cc44ccead (diff)
downloadbox64-153d8d2cf0085aba42c83e7d2d31ec6d3346075a.tar.gz
box64-153d8d2cf0085aba42c83e7d2d31ec6d3346075a.zip
Block signals while traicking memory protection
Diffstat (limited to 'src')
-rw-r--r--src/custommem.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/custommem.c b/src/custommem.c
index 068baede..478e5950 100644
--- a/src/custommem.c
+++ b/src/custommem.c
@@ -369,15 +369,19 @@ static size_t roundSize(size_t size)
 static uintptr_t    defered_prot_p = 0;
 static size_t       defered_prot_sz = 0;
 static uint32_t     defered_prot_prot = 0;
-#define LOCK_PROT()         mutex_lock(&mutex_prot)
-#define LOCK_PROT_READ()    mutex_lock(&mutex_prot)
-#define UNLOCK_PROT()       if(defered_prot_p) {    \
+static sigset_t     critical_prot = {0};
+#define LOCK_PROT()         sigset_t old_sig = {0}; pthread_sigmask(SIG_BLOCK, &critical_prot, &old_sig); mutex_lock(&mutex_prot)
+#define LOCK_PROT_READ()    sigset_t old_sig = {0}; pthread_sigmask(SIG_BLOCK, &critical_prot, &old_sig); mutex_lock(&mutex_prot)
+#define UNLOCK_PROT()       if(defered_prot_p) {                                \
                                 uintptr_t p = defered_prot_p; size_t sz = defered_prot_sz; uint32_t prot = defered_prot_prot; \
-                                defered_prot_p = 0; \
-                                mutex_unlock(&mutex_prot); \
-                                setProtection(p, sz, prot); \
-                            } else mutex_unlock(&mutex_prot)
-#define UNLOCK_PROT_READ()  mutex_unlock(&mutex_prot)
+                                defered_prot_p = 0;                             \
+                                mutex_unlock(&mutex_prot);                      \
+                                setProtection(p, sz, prot);                     \
+                            } else {                                            \
+                                mutex_unlock(&mutex_prot);                      \
+                            }                                                   \
+                            pthread_sigmask(SIG_SETMASK, &old_sig, NULL)
+#define UNLOCK_PROT_READ()  mutex_unlock(&mutex_prot); pthread_sigmask(SIG_SETMASK, &old_sig, NULL)
 
 
 #ifdef TRACE_MEMSTAT
@@ -1464,6 +1468,7 @@ void init_custommem_helper(box64context_t* ctx)
         return;
     inited = 1;
     memprot = init_rbtree();
+    sigfillset(&critical_prot);
     init_mutexes();
 #ifdef DYNAREC
     if(box64_dynarec) {