diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/custommem.c | 10 | ||||
| -rw-r--r-- | src/dynarec/dynablock.c | 16 | ||||
| -rw-r--r-- | src/include/custommem.h | 1 |
3 files changed, 23 insertions, 4 deletions
diff --git a/src/custommem.c b/src/custommem.c index 3f067148..3307335e 100644 --- a/src/custommem.c +++ b/src/custommem.c @@ -440,6 +440,7 @@ static uint32_t defered_prot_prot = 0; static sigset_t critical_prot = {0}; #define LOCK_PROT() sigset_t old_sig = {0}; pthread_sigmask(SIG_BLOCK, &critical_prot, &old_sig); mutex_lock(&mutex_prot) #define LOCK_PROT_READ() sigset_t old_sig = {0}; pthread_sigmask(SIG_BLOCK, &critical_prot, &old_sig); mutex_lock(&mutex_prot) +#define LOCK_PROT_FAST() mutex_lock(&mutex_prot) #define UNLOCK_PROT() if(defered_prot_p) { \ uintptr_t p = defered_prot_p; size_t sz = defered_prot_sz; uint32_t prot = defered_prot_prot; \ defered_prot_p = 0; \ @@ -451,6 +452,7 @@ static sigset_t critical_prot = {0}; mutex_unlock(&mutex_prot); \ } #define UNLOCK_PROT_READ() mutex_unlock(&mutex_prot); pthread_sigmask(SIG_SETMASK, &old_sig, NULL) +#define UNLOCK_PROT_FAST() mutex_unlock(&mutex_prot) #ifdef TRACE_MEMSTAT @@ -1642,6 +1644,14 @@ uint32_t getProtection(uintptr_t addr) return ret; } +uint32_t getProtection_fast(uintptr_t addr) +{ + LOCK_PROT_FAST(); + uint32_t ret = rb_get(memprot, addr); + UNLOCK_PROT_FAST(); + return ret; +} + int getMmapped(uintptr_t addr) { return rb_get(mmapmem, addr); diff --git a/src/dynarec/dynablock.c b/src/dynarec/dynablock.c index bfe10758..35c2fb03 100644 --- a/src/dynarec/dynablock.c +++ b/src/dynarec/dynablock.c @@ -199,11 +199,12 @@ static dynablock_t* internalDBGetBlock(x64emu_t* emu, uintptr_t addr, uintptr_t { if(hasAlternate((void*)addr)) return NULL; - if((getProtection(addr)&(PROT_EXEC|PROT_READ))!=(PROT_EXEC|PROT_READ)) // cannot be run, get out of the Dynarec - return NULL; dynablock_t* block = getDB(addr); - if(block || !create) + if(block || !create) { + if(block && getNeedTest(addr) && (getProtection(addr)&(PROT_EXEC|PROT_READ))!=(PROT_EXEC|PROT_READ)) + block = NULL; return block; + } if(need_lock) { if(box64_dynarec_wait) { @@ -214,11 +215,18 @@ static dynablock_t* internalDBGetBlock(x64emu_t* emu, uintptr_t addr, uintptr_t } block = getDB(addr); // just in case if(block) { + if(block && getNeedTest(addr) && (getProtection_fast(addr)&(PROT_EXEC|PROT_READ))!=(PROT_EXEC|PROT_READ)) + block = NULL; mutex_unlock(&my_context->mutex_dyndump); return block; } } - + + if((getProtection_fast(addr)&(PROT_EXEC|PROT_READ))!=(PROT_EXEC|PROT_READ)) {// cannot be run, get out of the Dynarec + if(need_lock) + mutex_unlock(&my_context->mutex_dyndump); + return NULL; + } block = AddNewDynablock(addr); // fill the block diff --git a/src/include/custommem.h b/src/include/custommem.h index 653af5e2..d892079e 100644 --- a/src/include/custommem.h +++ b/src/include/custommem.h @@ -100,6 +100,7 @@ void setProtection_elf(uintptr_t addr, size_t size, uint32_t prot); void freeProtection(uintptr_t addr, size_t size); void refreshProtection(uintptr_t addr); uint32_t getProtection(uintptr_t addr); +uint32_t getProtection_fast(uintptr_t addr); int getMmapped(uintptr_t addr); void loadProtectionFromMap(void); #ifdef DYNAREC |