about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2023-12-20 17:49:29 +0100
committerptitSeb <sebastien.chev@gmail.com>2023-12-20 17:49:29 +0100
commit1005cee4bc6479a169407d4c71482f0daff4cb82 (patch)
treee6cb1088b4b13a1f19606af12453d1dd5de2111a /src
parent95a1b12c07653ff53e8b681f4d06d101935fa129 (diff)
downloadbox64-1005cee4bc6479a169407d4c71482f0daff4cb82.tar.gz
box64-1005cee4bc6479a169407d4c71482f0daff4cb82.zip
Small improvment on memory tracking
Diffstat (limited to 'src')
-rw-r--r--src/custommem.c16
1 files changed, 6 insertions, 10 deletions
diff --git a/src/custommem.c b/src/custommem.c
index 6facc46d..0e2b1a09 100644
--- a/src/custommem.c
+++ b/src/custommem.c
@@ -1248,13 +1248,13 @@ void removeMapMem(mapmem_t* mapmem, uintptr_t begin, uintptr_t end)
 void updateProtection(uintptr_t addr, size_t size, uint32_t prot)
 {
     dynarec_log(LOG_DEBUG, "updateProtection %p:%p 0x%x\n", (void*)addr, (void*)(addr+size-1), prot);
+    mutex_lock(&mutex_prot);
+    addMapMem(mapallmem, addr, addr+size-1);
+    UNLOCK_DYNAREC();
     uintptr_t idx = (addr>>MEMPROT_SHIFT);
     uintptr_t end = ((addr+size-1)>>MEMPROT_SHIFT);
     if(end>=(1LL<<(48-MEMPROT_SHIFT)))
         end = (1LL<<(48-MEMPROT_SHIFT))-1;
-    mutex_lock(&mutex_prot);
-    addMapMem(mapallmem, addr, addr+size-1);
-    UNLOCK_DYNAREC();
     uintptr_t bidx = ~1LL;
     uint8_t *block = NULL;
     for (uintptr_t i=idx; i<=end; ++i) {
@@ -1279,13 +1279,13 @@ void updateProtection(uintptr_t addr, size_t size, uint32_t prot)
 
 void setProtection(uintptr_t addr, size_t size, uint32_t prot)
 {
+    mutex_lock(&mutex_prot);
+    addMapMem(mapallmem, addr, addr+size-1);
+    UNLOCK_DYNAREC();
     uintptr_t idx = (addr>>MEMPROT_SHIFT);
     uintptr_t end = ((addr+size-1)>>MEMPROT_SHIFT);
     if(end>=(1LL<<(48-MEMPROT_SHIFT)))
         end = (1LL<<(48-MEMPROT_SHIFT))-1;
-    mutex_lock(&mutex_prot);
-    addMapMem(mapallmem, addr, addr+size-1);
-    UNLOCK_DYNAREC();
     for (uintptr_t i=(idx>>16); i<=(end>>16); ++i) {
         uint8_t* block = getProtBlock(i, prot?1:0);
         if(prot || block!=memprot_default) {
@@ -1342,10 +1342,6 @@ printf_log(LOG_INFO, "refreshProtection(%p): %p/0x%x (ret=%d/%s)\n", (void*)addr
 void allocProtection(uintptr_t addr, size_t size, uint32_t prot)
 {
     dynarec_log(LOG_DEBUG, "allocProtection %p:%p 0x%x\n", (void*)addr, (void*)(addr+size-1), prot);
-    uintptr_t idx = (addr>>MEMPROT_SHIFT);
-    uintptr_t end = ((addr+size-1LL)>>MEMPROT_SHIFT);
-    if(end>=(1LL<<(48-MEMPROT_SHIFT)))
-        end = (1LL<<(48-MEMPROT_SHIFT))-1;
     mutex_lock(&mutex_prot);
     addMapMem(mapallmem, addr, addr+size-1);
     mutex_unlock(&mutex_prot);