about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2023-03-05 09:59:26 +0100
committerptitSeb <sebastien.chev@gmail.com>2023-03-05 09:59:26 +0100
commit219ac40a7dffe17a3417dd94910bedf6ea06fe45 (patch)
tree207a6ba4b5aa572a662fe88320398bae4dac14fd /src
parentb9378fe4c17a61318f1d27a7f0611df5a84423ab (diff)
downloadbox64-219ac40a7dffe17a3417dd94910bedf6ea06fe45.tar.gz
box64-219ac40a7dffe17a3417dd94910bedf6ea06fe45.zip
[DYNAREC] Fixed (again) and improved new jmptable memory manager
Diffstat (limited to 'src')
-rw-r--r--src/custommem.c24
-rw-r--r--src/include/custommem.h6
2 files changed, 16 insertions, 14 deletions
diff --git a/src/custommem.c b/src/custommem.c
index 6cb011c1..633e15fe 100644
--- a/src/custommem.c
+++ b/src/custommem.c
@@ -581,21 +581,23 @@ static uintptr_t getDBSize(uintptr_t addr, size_t maxsize, dynablock_t** db)
     uintptr_t idx0 = addr&JMPTABLE_MASK0;
     *db = *(dynablock_t**)(box64_jmptbl3[idx3][idx2][idx1][idx0]- sizeof(void*));
     if(*db)
-        return 1;
+        return addr+1;
     if(box64_jmptbl3[idx3] == box64_jmptbldefault2)
-        return (addr|((1LL<<JMPTABL_START3)-1))+1-addr;
+        return ((idx3+1)<<JMPTABL_START3);
     if(box64_jmptbl3[idx3][idx2] == box64_jmptbldefault1)
-        return (addr|((1LL<<JMPTABL_START2)-1))+1-addr;
+        return (((addr>>JMPTABL_START2)+1)<<JMPTABL_START2);
     uintptr_t* block = box64_jmptbl3[idx3][idx2][idx1];
     if(block == box64_jmptbldefault0)
-        return (addr|JMPTABLE_MASK0)+1-addr;
-    if (maxsize>JMPTABLE_MASK0+1)
-        maxsize = JMPTABLE_MASK0+1;
-    while(idx0<maxsize && block[idx0]==(uintptr_t)native_next)
+        return (((addr>>JMPTABL_START1)+1)<<JMPTABL_START1);
+    if (maxsize>JMPTABLE_MASK0)
+        maxsize = JMPTABLE_MASK0;
+    while(block[idx0]==(uintptr_t)native_next) {
         ++idx0;
-    if(idx0<JMPTABLE_MASK0+1)
-        *db = *(dynablock_t**)(block[idx0]- sizeof(void*));
-    return idx0+1-(addr&JMPTABLE_MASK0);
+        if(idx0>maxsize)
+            return (addr&~JMPTABLE_MASK0)+idx0;
+    }
+    *db = *(dynablock_t**)(block[idx0]- sizeof(void*));
+    return (addr&~JMPTABLE_MASK0)+idx0+1;
 }
 
 // each dynmap is 64k of size
@@ -613,7 +615,7 @@ void cleanDBFromAddressRange(uintptr_t addr, size_t size, int destroy)
     dynablock_t* db = NULL;
     uintptr_t end = addr+size;
     while (start_addr<end) {
-        start_addr += getDBSize(start_addr, end-start_addr, &db);
+        start_addr = getDBSize(start_addr, end-start_addr, &db);
         if(db) {
             if(destroy)
                 FreeRangeDynablock(db, addr, size);
diff --git a/src/include/custommem.h b/src/include/custommem.h
index b1645133..e03db81c 100644
--- a/src/include/custommem.h
+++ b/src/include/custommem.h
@@ -39,9 +39,9 @@ uintptr_t getJumpAddress64(uintptr_t addr);
 #define JMPTABL_SHIFT2 18
 #define JMPTABL_SHIFT1 18
 #define JMPTABL_SHIFT0 10
-#define JMPTABL_START3 (JMPTABL_SHIFT0+JMPTABL_SHIFT1+JMPTABL_SHIFT2)
-#define JMPTABL_START2 (JMPTABL_SHIFT0+JMPTABL_SHIFT1)
-#define JMPTABL_START1 (JMPTABL_SHIFT0)
+#define JMPTABL_START3 (JMPTABL_START2+JMPTABL_SHIFT2)
+#define JMPTABL_START2 (JMPTABL_START1+JMPTABL_SHIFT1)
+#define JMPTABL_START1 (JMPTABL_START0+JMPTABL_SHIFT0)
 #define JMPTABL_START0 0
 #define JMPTABLE_MASK3 ((1<<JMPTABL_SHIFT3)-1)
 #define JMPTABLE_MASK2 ((1<<JMPTABL_SHIFT2)-1)