diff options
| author | ptitSeb <sebastien.chev@gmail.com> | 2023-02-20 19:50:26 +0100 |
|---|---|---|
| committer | ptitSeb <sebastien.chev@gmail.com> | 2023-02-20 19:50:26 +0100 |
| commit | fb5ac9c4cddf2bf03ee62dc4addac719c0cf02ab (patch) | |
| tree | 25dbc143e0c097e5c72f9a50a0703798fd911f60 /src | |
| parent | ed4e33d8886a7e8c89318fa41535e9158a3c9893 (diff) | |
| download | box64-fb5ac9c4cddf2bf03ee62dc4addac719c0cf02ab.tar.gz box64-fb5ac9c4cddf2bf03ee62dc4addac719c0cf02ab.zip | |
Fixed a improved HotPage handling
Diffstat (limited to 'src')
| -rw-r--r-- | src/custommem.c | 58 | ||||
| -rwxr-xr-x | src/main.c | 2 |
2 files changed, 28 insertions, 32 deletions
diff --git a/src/custommem.c b/src/custommem.c index 00e24246..6638af31 100644 --- a/src/custommem.c +++ b/src/custommem.c @@ -557,25 +557,29 @@ void FreeDynarecMap(uintptr_t addr) } } -uintptr_t getSizeJmpDefault(uintptr_t addr, size_t maxsize) +static uintptr_t getDBSize(uintptr_t addr, size_t maxsize, dynablock_t** db) { - uintptr_t idx3, idx2, idx1, idx0; - idx3 = (((uintptr_t)addr)>>48)&0xffff; + const uintptr_t idx3 = (addr>>48)&0xffff; + const uintptr_t idx2 = (addr>>32)&0xffff; + const uintptr_t idx1 = (addr>>16)&0xffff; + uintptr_t idx0 = addr&0xffff; + *db = *(dynablock_t**)(box64_jmptbl3[idx3][idx2][idx1][idx0]- sizeof(void*)); + if(*db) + return 1; if(box64_jmptbl3[idx3] == box64_jmptbldefault2) - return ((addr&~((1LL<<48)-1))|0xffffffffffffLL)-addr + 1; - idx2 = (((uintptr_t)addr)>>32)&0xffff; + return (addr|0xffffffffffffLL)+1-addr; if(box64_jmptbl3[idx3][idx2] == box64_jmptbldefault1) - return ((addr&~((1LL<<32)-1))|0xffffffffLL)-addr + 1; - idx1 = (((uintptr_t)addr)>>16)&0xffff; + return (addr|0xffffffffLL)+1-addr; uintptr_t* block = box64_jmptbl3[idx3][idx2][idx1]; if(block == box64_jmptbldefault0) - return ((addr&~((1LL<<16)-1))|0xffffLL)-addr + 1; - idx0 = addr&0xffff; + return (addr|0xffffLL)+1-addr; if (maxsize>0x10000) maxsize = 0x10000; while(idx0<maxsize && block[idx0]==(uintptr_t)native_next) ++idx0; - return idx0 - (addr&0xffff); + if(idx0<0x10000) + *db = *(dynablock_t**)(block[idx0]- sizeof(void*)); + return idx0+1-(addr&0xffff); } // each dynmap is 64k of size @@ -590,17 +594,15 @@ void 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"); - for (uintptr_t i=start_addr; i<addr+size; ++i) { - dynablock_t* db = getDB(i); + dynablock_t* db = NULL; + uintptr_t end = addr+size; + while (start_addr<end) { + start_addr += getDBSize(start_addr, end-start_addr, &db); if(db) { if(destroy) FreeRangeDynablock(db, addr, size); else MarkRangeDynablock(db, addr, size); - } else { - uintptr_t next = getSizeJmpDefault(i, size-i); - if(next) - i+=next-1; } } } @@ -785,9 +787,6 @@ void protectDB(uintptr_t addr, uintptr_t size) for (uintptr_t i=(idx>>16); i<=(end>>16); ++i) if(memprot[i].prot==memprot_default) { uint8_t* newblock = box_calloc(1<<16, sizeof(uint8_t)); - /*if (native_lock_storeifref(&memprot[i], newblock, memprot_default) != newblock) { - box_free(newblock); - }*/ memprot[i].prot = newblock; } for (uintptr_t i=idx; i<=end; ++i) { @@ -817,14 +816,11 @@ void unprotectDB(uintptr_t addr, size_t size, int mark) if(end<idx) // memory addresses higher than 48bits are not tracked return; mutex_lock(&mutex_prot); - for (uintptr_t i=(idx>>16); i<=(end>>16); ++i) + /*for (uintptr_t i=(idx>>16); i<=(end>>16); ++i) if(memprot[i].prot==memprot_default) { uint8_t* newblock = box_calloc(1<<16, sizeof(uint8_t)); - /*if (native_lock_storeifref(&memprot[i], newblock, memprot_default) != newblock) { - box_free(newblock); - }*/ memprot[i].prot = newblock; - } + }*/ for (uintptr_t i=idx; i<=end; ++i) { uint32_t prot = memprot[i>>16].prot[i&0xffff]; if(prot&PROT_DYNAREC) { @@ -1028,7 +1024,7 @@ void allocProtection(uintptr_t addr, size_t size, uint32_t prot) end = (1LL<<(48-MEMPROT_SHIFT))-1; mutex_lock(&mutex_prot); addMapMem(addr, addr+size-1); - for (uintptr_t i=(idx>>16); i<=(end>>16); ++i) + /*for (uintptr_t i=(idx>>16); i<=(end>>16); ++i) if(memprot[i].prot==memprot_default) { uint8_t* newblock = box_calloc(1<<16, sizeof(uint8_t)); memprot[i].prot = newblock; @@ -1042,23 +1038,23 @@ void allocProtection(uintptr_t addr, size_t size, uint32_t prot) block[ii] = prot; } i+=finish-start; // +1 from the "for" loop - } + }*/ mutex_unlock(&mutex_prot); } #ifdef DYNAREC int IsInHotPage(uintptr_t addr) { - if(addr<=(1LL<<48)) + if(addr>=(1LL<<48)) return 0; int idx = (addr>>MEMPROT_SHIFT)>>16; - uint8_t *block = memprot[idx].hot; - if(!block) + uint8_t *hot = memprot[idx].hot; + if(!hot) return 0; int base = (addr>>MEMPROT_SHIFT)&0xffff; - if(!block[base]) + if(!hot[base]) return 0; // decrement hot - native_lock_decifnot0b(&block[base]); + native_lock_decifnot0b(&hot[base]); return 1; } diff --git a/src/main.c b/src/main.c index 55a18473..6b5e6dc7 100755 --- a/src/main.c +++ b/src/main.c @@ -56,7 +56,7 @@ int box64_dynarec_fastnan = 1; int box64_dynarec_fastround = 1; int box64_dynarec_safeflags = 1; int box64_dynarec_callret = 0; -int box64_dynarec_hotpage = 16; +int box64_dynarec_hotpage = 4; int box64_dynarec_fastpage = 0; int box64_dynarec_bleeding_edge = 1; int box64_dynarec_wait = 1; |