From c8b6f80f995d0ee00a46b423a360c38bf20cacee Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Fri, 7 Mar 2025 13:45:41 +0100 Subject: Removed isDBFromAddressRange and added that function to cleanDBFromAddressRange as it was used only 1 time and followed by that function anyway --- src/custommem.c | 25 +++++-------------------- src/include/custommem.h | 3 +-- src/libtools/signals.c | 14 +++++++------- 3 files changed, 13 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/custommem.c b/src/custommem.c index 87328bc1..940280bf 100644 --- a/src/custommem.c +++ b/src/custommem.c @@ -1020,42 +1020,27 @@ void addDBFromAddressRange(uintptr_t addr, size_t size) } } -void cleanDBFromAddressRange(uintptr_t addr, size_t size, int destroy) +// Will return 1 if at least 1 db in the address range +int cleanDBFromAddressRange(uintptr_t addr, size_t size, int destroy) { uintptr_t start_addr = my_context?((addrmax_db_size)?0:(addr-my_context->max_db_size)):addr; dynarec_log(LOG_DEBUG, "cleanDBFromAddressRange %p/%p -> %p %s\n", (void*)addr, (void*)start_addr, (void*)(addr+size-1), destroy?"destroy":"mark"); dynablock_t* db = NULL; uintptr_t end = addr+size; + int ret = 0; while (start_addrmax_db_size)?0:(addr-my_context->max_db_size)):addr; - dynarec_log(LOG_DEBUG, "isDBFromAddressRange %p/%p -> %p => ", (void*)addr, (void*)start_addr, (void*)(addr+size-1)); - dynablock_t* db = NULL; - uintptr_t end = addr+size; - while (start_addrsi_code == SEGV_ACCERR) && ((prot&~PROT_CUSTOM)==(PROT_READ|PROT_WRITE) || (prot&~PROT_CUSTOM)==(PROT_READ|PROT_WRITE|PROT_EXEC))) { static uintptr_t old_addr = 0; #ifdef DYNAREC - if((prot==(PROT_READ|PROT_WRITE|PROT_EXEC)) && isDBFromAddressRange(((uintptr_t)addr)&~(box64_pagesize-1), box64_pagesize)) { - printf_log(/*LOG_DEBUG*/LOG_INFO, "%04d| Strange SIGSEGV with Access error on %p for %p with DynaBlock(s) in range, db=%p, Lock=0x%x)\n", tid, pc, addr, db, Locks); - cleanDBFromAddressRange(((uintptr_t)addr)&~(box64_pagesize-1), box64_pagesize, 0); - refreshProtection((uintptr_t)addr); - relockMutex(Locks); - return; - } + if(prot==(PROT_READ|PROT_WRITE|PROT_EXEC)) + if(cleanDBFromAddressRange(((uintptr_t)addr)&~(box64_pagesize-1), box64_pagesize, 0)) { + printf_log(/*LOG_DEBUG*/LOG_INFO, "%04d| Strange SIGSEGV with Access error on %p for %p with DynaBlock(s) in range, db=%p, Lock=0x%x)\n", tid, pc, addr, db, Locks); + refreshProtection((uintptr_t)addr); + relockMutex(Locks); + return; + } #endif printf_log(/*LOG_DEBUG*/LOG_INFO, "%04d| Strange SIGSEGV with Access error on %p for %p%s, db=%p, prot=0x%x (old_addr=%p, Lock=0x%x)\n", tid, pc, addr, mapped?" mapped":"", db, prot, (void*)old_addr, Locks); if(!(old_addr==(uintptr_t)addr && old_prot==prot) || mapped) { -- cgit 1.4.1