From 79d7e9f8eb4c702fe5558798bce79468dd7a0888 Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Thu, 11 Nov 2021 12:37:01 +0100 Subject: Mark memprot as volatile to try help stability in heavily multithread programs --- src/custommem.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src') 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]; -- cgit 1.4.1