about summary refs log tree commit diff stats
path: root/src/custommem.c
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2023-04-16 10:50:12 +0200
committerptitSeb <sebastien.chev@gmail.com>2023-04-16 10:50:12 +0200
commit3adf31c85b8bb4366d063fbe8f7d9fc36084366d (patch)
tree42d8fb12e6079f362c54226a862cabd8b1980ad9 /src/custommem.c
parent9b2c6caf22e6dc91ad72f4d90116b80237bd3487 (diff)
downloadbox64-3adf31c85b8bb4366d063fbe8f7d9fc36084366d.tar.gz
box64-3adf31c85b8bb4366d063fbe8f7d9fc36084366d.zip
[DYNAREC] General fixes and improvment for multithread and jit program. Helps Java, mono and Unity3d program... (should help #519, #464, #433, #272, #232, #193, #112...)
Diffstat (limited to 'src/custommem.c')
-rw-r--r--src/custommem.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/custommem.c b/src/custommem.c
index 4cf1dd0a..45c7a01f 100644
--- a/src/custommem.c
+++ b/src/custommem.c
@@ -26,6 +26,7 @@
 #include "threads.h"
 #ifdef DYNAREC
 #include "dynablock.h"
+#include "dynarec/dynablock_private.h"
 #include "dynarec/native_lock.h"
 #include "dynarec/dynarec_next.h"
 
@@ -770,6 +771,28 @@ dynablock_t* getDB(uintptr_t addr)
     return *(dynablock_t**)(ret - sizeof(void*));
 }
 
+int getNeedTest(uintptr_t addr)
+{
+    uintptr_t idx3, idx2, idx1, idx0;
+    idx3 = ((addr)>>JMPTABL_START3)&JMPTABLE_MASK3;
+    idx2 = ((addr)>>JMPTABL_START2)&JMPTABLE_MASK2;
+    idx1 = ((addr)>>JMPTABL_START1)&JMPTABLE_MASK1;
+    idx0 = ((addr)                )&JMPTABLE_MASK0;
+    uintptr_t ret = (uintptr_t)box64_jmptbl3[idx3][idx2][idx1][idx0];
+    dynablock_t* db = *(dynablock_t**)(ret - sizeof(void*));
+    return db?((ret!=(uintptr_t)db->block)?1:0):0;
+}
+
+uintptr_t getJumpAddress64(uintptr_t addr)
+{
+    uintptr_t idx3, idx2, idx1, idx0;
+    idx3 = ((addr)>>JMPTABL_START3)&JMPTABLE_MASK3;
+    idx2 = ((addr)>>JMPTABL_START2)&JMPTABLE_MASK2;
+    idx1 = ((addr)>>JMPTABL_START1)&JMPTABLE_MASK1;
+    idx0 = ((addr)                )&JMPTABLE_MASK0;
+    return (uintptr_t)box64_jmptbl3[idx3][idx2][idx1][idx0];
+}
+
 // Remove the Write flag from an adress range, so DB can be executed safely
 void protectDB(uintptr_t addr, uintptr_t size)
 {
@@ -1032,8 +1055,10 @@ void refreshProtection(uintptr_t addr)
     uintptr_t idx = (addr>>MEMPROT_SHIFT);
     if(memprot[idx>>16].prot!=memprot_default) {
         int prot = memprot[idx>>16].prot[idx&0xffff];
-        int ret = mprotect((void*)(idx<<MEMPROT_SHIFT), box64_pagesize, prot&~PROT_CUSTOM);
+        if(!(prot&PROT_DYNAREC)) {
+            int ret = mprotect((void*)(idx<<MEMPROT_SHIFT), box64_pagesize, prot&~PROT_CUSTOM);
 printf_log(LOG_INFO, "refreshProtection(%p): %p/0x%x (ret=%d/%s)\n", (void*)addr, (void*)(idx<<MEMPROT_SHIFT), prot, ret, ret?strerror(errno):"ok");
+        }
     }
     mutex_unlock(&mutex_prot);
 }