From 121d986b1114990ae69a6834cea6979200e0c39b Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Sat, 3 Feb 2024 18:01:13 +0100 Subject: [DYNAREC] Reworked a bit the Strange SEGSIGV handling --- src/custommem.c | 19 +++++++++++++++++++ src/include/custommem.h | 2 ++ src/libtools/signals.c | 10 ++++++++-- 3 files changed, 29 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/custommem.c b/src/custommem.c index 478e5950..faac9740 100644 --- a/src/custommem.c +++ b/src/custommem.c @@ -729,6 +729,25 @@ void cleanDBFromAddressRange(uintptr_t addr, size_t size, int destroy) } } +// Will return 1 if at least 1 db in the address range +int isDBFromAddressRange(uintptr_t addr, size_t size) +{ + uintptr_t start_addr = my_context?((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; - 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)\n", tid, pc, addr, mapped?" mapped":"", db, prot, (void*)old_addr); #ifdef DYNAREC - cleanDBFromAddressRange(((uintptr_t)addr)&~(box64_pagesize-1), box64_pagesize, 0); + 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; + } #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) { old_addr = (uintptr_t)addr; old_prot = prot; -- cgit 1.4.1