From b3a2031484465e26f71c9bee00ce5e2e9d6fc65a Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Sun, 2 Apr 2023 18:45:04 +0200 Subject: [DYNAREC] Never protect bridge memory (ported from box86) --- src/custommem.c | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) (limited to 'src/custommem.c') diff --git a/src/custommem.c b/src/custommem.c index 239af030..2872aa7d 100644 --- a/src/custommem.c +++ b/src/custommem.c @@ -798,11 +798,11 @@ void protectDB(uintptr_t addr, uintptr_t size) prot&=~PROT_CUSTOM; if(!prot) prot = PROT_READ | PROT_WRITE | PROT_EXEC; // comes from malloc & co, so should not be able to execute - if((prot&PROT_WRITE)) { + if((prot&PROT_WRITE) && !(prot&PROT_NOPROT)) { if(!dyn) mprotect((void*)(i<>16].prot[i&0xffff] = prot|mapped|PROT_DYNAREC; // need to use atomic exchange? - } else - memprot[i>>16].prot[i&0xffff] = prot|mapped|PROT_DYNAREC_R; + memprot[i>>16].prot[i&0xffff] = prot|mapped|PROT_DYNAREC; // need to use atomic exchange? + } else + memprot[i>>16].prot[i&0xffff] = prot|mapped|PROT_DYNAREC_R; } mutex_unlock(&mutex_prot); } @@ -824,14 +824,16 @@ void unprotectDB(uintptr_t addr, size_t size, int mark) i=(((i>>16)+1)<<16)-1; // next block } else { uint32_t prot = memprot[i>>16].prot[i&0xffff]; - if(prot&PROT_DYNAREC) { - prot&=~PROT_DYN; - if(mark) - cleanDBFromAddressRange((i<>16].prot[i&0xffff] = prot; // need to use atomic exchange? - } else if(prot&PROT_DYNAREC_R) - memprot[i>>16].prot[i&0xffff] = prot&~PROT_CUSTOM; + if(!(prot&PROT_NOPROT)) { + if(prot&PROT_DYNAREC) { + prot&=~PROT_DYN; + if(mark) + cleanDBFromAddressRange((i<>16].prot[i&0xffff] = prot; // need to use atomic exchange? + } else if(prot&PROT_DYNAREC_R) + memprot[i>>16].prot[i&0xffff] = prot&~PROT_CUSTOM; + } } } mutex_unlock(&mutex_prot); @@ -850,7 +852,7 @@ int isprotectedDB(uintptr_t addr, size_t size) } for (uintptr_t i=idx; i<=end; ++i) { uint32_t prot = memprot[i>>16].prot[i&0xffff]; - if(!(prot&PROT_DYN)) { + if(!(prot&PROT_DYN) && !(prot&PROT_NOPROT)) { dynarec_log(LOG_DEBUG, "0\n"); return 0; } @@ -977,11 +979,13 @@ void updateProtection(uintptr_t addr, size_t size, uint32_t prot) uint32_t old_prot = memprot[i>>16].prot[i&0xffff]; uint32_t dyn=(old_prot&PROT_DYN); uint32_t mapped=(old_prot&PROT_MMAP); - if(dyn && (prot&PROT_WRITE)) { // need to remove the write protection from this block - dyn = PROT_DYNAREC; - mprotect((void*)(i<>16].prot[i&0xffff] = prot|dyn|mapped; } -- cgit 1.4.1