about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2021-11-11 12:37:01 +0100
committerptitSeb <sebastien.chev@gmail.com>2021-11-11 12:37:01 +0100
commit79d7e9f8eb4c702fe5558798bce79468dd7a0888 (patch)
tree3f3bd1e1b6692dbf15592da604e0d821917a5cb1 /src
parentf5c9439f9110fcb4fde3c7db9f68be7c107b17f6 (diff)
downloadbox64-79d7e9f8eb4c702fe5558798bce79468dd7a0888.tar.gz
box64-79d7e9f8eb4c702fe5558798bce79468dd7a0888.zip
Mark memprot as volatile to try help stability in heavily multithread programs
Diffstat (limited to 'src')
-rw-r--r--src/custommem.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/custommem.c b/src/custommem.c
index 54864d90..72fa4db4 100644
--- a/src/custommem.c
+++ b/src/custommem.c
@@ -45,7 +45,7 @@ static pthread_mutex_t     mutex_prot;
 #define MEMPROT_SHIFT 12
 #define MEMPROT_SHIFT2 (16+12)
 #define MEMPROT_SIZE (1<<16)
-static uint8_t *memprot[1<<20];    // x86_64 mem is 48bits, page is 12bits, so memory is tracked as [20][16][page protection]
+static uint8_t *volatile memprot[1<<20];    // x86_64 mem is 48bits, page is 12bits, so memory is tracked as [20][16][page protection]
 static uint8_t memprot_default[MEMPROT_SIZE];
 static int inited = 0;
 
@@ -774,9 +774,10 @@ void protectDB(uintptr_t addr, uintptr_t size)
     for (uintptr_t i=(idx>>16); i<=(end>>16); ++i)
         if(memprot[i]==memprot_default) {
             uint8_t* newblock = calloc(1<<16, sizeof(uint8_t));
-            if (arm64_lock_storeifref(&memprot[i], newblock, memprot_default) != newblock) {
+            /*if (arm64_lock_storeifref(&memprot[i], newblock, memprot_default) != newblock) {
                 free(newblock);
-            }
+            }*/
+            memprot[i] = newblock;
         }
     for (uintptr_t i=idx; i<=end; ++i) {
         uint32_t prot = memprot[i>>16][i&0xffff];
@@ -805,9 +806,10 @@ void unprotectDB(uintptr_t addr, size_t size)
     for (uintptr_t i=(idx>>16); i<=(end>>16); ++i)
         if(memprot[i]==memprot_default) {
             uint8_t* newblock = calloc(1<<16, sizeof(uint8_t));
-            if (arm64_lock_storeifref(&memprot[i], newblock, memprot_default) != newblock) {
+            /*if (arm64_lock_storeifref(&memprot[i], newblock, memprot_default) != newblock) {
                 free(newblock);
-            }
+            }*/
+            memprot[i] = newblock;
         }
     for (uintptr_t i=idx; i<=end; ++i) {
         uint32_t prot = memprot[i>>16][i&0xffff];