Skip to content

Commit

Permalink
Removed isDBFromAddressRange and added that function to cleanDBFromAd…
Browse files Browse the repository at this point in the history
…dressRange as it was used only 1 time and followed by that function anyway
  • Loading branch information
ptitSeb committed Mar 7, 2025
1 parent 9444ce0 commit c8b6f80
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 29 deletions.
25 changes: 5 additions & 20 deletions src/custommem.c
Original file line number Diff line number Diff line change
Expand Up @@ -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?((addr<my_context->max_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_addr<end) {
start_addr = getDBSize(start_addr, end-start_addr, &db);
if(db) {
ret = 1;
if(destroy)
FreeRangeDynablock(db, addr, size);
else
MarkRangeDynablock(db, addr, size);
}
}
return ret;
}

// 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?((addr<my_context->max_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_addr<end) {
start_addr = getDBSize(start_addr, end-start_addr, &db);
if(db) {
dynarec_log_prefix(0, LOG_DEBUG, "1\n");
return 1;
}
}
dynarec_log_prefix(0, LOG_DEBUG, "0\n");
return 0;
}


#ifdef JMPTABL_SHIFT4
static uintptr_t *create_jmptbl(uintptr_t idx0, uintptr_t idx1, uintptr_t idx2, uintptr_t idx3, uintptr_t idx4)
{
Expand Down
3 changes: 1 addition & 2 deletions src/include/custommem.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ uintptr_t AllocDynarecMap(size_t size);
void FreeDynarecMap(uintptr_t addr);

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 isDBFromAddressRange(uintptr_t addr, size_t size);
int cleanDBFromAddressRange(uintptr_t addr, size_t size, int destroy);

dynablock_t* getDB(uintptr_t idx);
int getNeedTest(uintptr_t idx);
Expand Down
14 changes: 7 additions & 7 deletions src/libtools/signals.c
Original file line number Diff line number Diff line change
Expand Up @@ -1809,13 +1809,13 @@ dynarec_log(/*LOG_DEBUG*/LOG_INFO, "%04d|Repeated SIGSEGV with Access error on %
if((sig==SIGSEGV) && (info->si_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) {
Expand Down

0 comments on commit c8b6f80

Please sign in to comment.