about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2024-11-17 11:00:28 +0100
committerptitSeb <sebastien.chev@gmail.com>2024-11-17 11:00:28 +0100
commitc4d3d734b1a625ab5142a3f43ff955945a783faa (patch)
tree447b65ff46b3ecb53ac19b3042335e2b2255b680 /src
parent6e8c244b775cd46d4d20dfe5ce1de1894e2921e2 (diff)
downloadbox64-c4d3d734b1a625ab5142a3f43ff955945a783faa.tar.gz
box64-c4d3d734b1a625ab5142a3f43ff955945a783faa.zip
[DYNAREC] Mark existing block as dirty when re-creating a memory block
Diffstat (limited to 'src')
-rw-r--r--src/custommem.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/custommem.c b/src/custommem.c
index 3307335e..dc7280e9 100644
--- a/src/custommem.c
+++ b/src/custommem.c
@@ -1008,7 +1008,15 @@ static uintptr_t getDBSize(uintptr_t addr, size_t maxsize, dynablock_t** db)
 void addDBFromAddressRange(uintptr_t addr, size_t size)
 {
     dynarec_log(LOG_DEBUG, "addDBFromAddressRange %p -> %p\n", (void*)addr, (void*)(addr+size-1));
-    // do nothing, dynablock are allowed based on memory protection flags
+    // mark existing blocks as unclean, to be sure...
+    uintptr_t start_addr = my_context?((addr<my_context->max_db_size)?0:(addr-my_context->max_db_size)):addr;
+    dynablock_t* db = NULL;
+    uintptr_t end = addr+size;
+    while (start_addr<end) {
+        start_addr = getDBSize(start_addr, end-start_addr, &db);
+        if(db)
+            MarkRangeDynablock(db, addr, size);
+    }
 }
 
 void cleanDBFromAddressRange(uintptr_t addr, size_t size, int destroy)
@@ -1514,7 +1522,8 @@ void updateProtection(uintptr_t addr, size_t size, uint32_t prot)
         if(!(dyn&PROT_NEVERPROT)) {
             if(dyn && (prot&PROT_WRITE)) {   // need to remove the write protection from this block
                 dyn = PROT_DYNAREC;
-                mprotect((void*)cur, bend-cur, prot&~PROT_WRITE);
+                int ret = mprotect((void*)cur, bend-cur, prot&~PROT_WRITE);
+                dynarec_log(LOG_DEBUG, " mprotect %p:%p 0x%hhx => %d\n", (void*)cur, (void*)(bend-1), prot&~PROT_WRITE, ret);
             } else if(dyn && !(prot&PROT_WRITE)) {
                 dyn = PROT_DYNAREC_R;
             }