1
0
Fork 0

Fix NULL issues in CPU emulation code

This commit is contained in:
krcroft 2020-01-15 07:43:10 -08:00 committed by Patryk Obara
parent 02506d293e
commit df9fac4e61
3 changed files with 33 additions and 6 deletions

View file

@ -361,7 +361,7 @@ run_block:
CodePageHandler * temp_handler=(CodePageHandler *)get_tlb_readhandler(temp_ip);
if (temp_handler->flags & (cpu.code.big ? PFLAG_HASCODE32:PFLAG_HASCODE16)) {
block=temp_handler->FindCacheBlock(temp_ip & 4095);
if (!block) goto restart_core;
if (!block || !cache.block.running) goto restart_core;
cache.block.running->LinkTo(ret==BR_Link2,block);
goto run_block;
}

View file

@ -121,6 +121,9 @@ public:
return;
} else if (!invalidation_map) {
invalidation_map=(Bit8u*)malloc(4096);
if (!invalidation_map) {
E_Exit("wb:failed to allocate invalidation_map's memory");
}
memset(invalidation_map,0,4096);
}
invalidation_map[addr]++;
@ -141,6 +144,9 @@ public:
return;
} else if (!invalidation_map) {
invalidation_map=(Bit8u*)malloc(4096);
if (!invalidation_map) {
E_Exit("ww:failed to allocate invalidation_map's memory");
}
memset(invalidation_map,0,4096);
}
(*(Bit16u*)&invalidation_map[addr])+=0x101;
@ -161,6 +167,9 @@ public:
return;
} else if (!invalidation_map) {
invalidation_map=(Bit8u*)malloc(4096);
if (!invalidation_map) {
E_Exit("wd:failed to allocate invalidation_map's memory");
}
memset(invalidation_map,0,4096);
}
(*(Bit32u*)&invalidation_map[addr])+=0x1010101;
@ -181,6 +190,9 @@ public:
} else {
if (!invalidation_map) {
invalidation_map=(Bit8u*)malloc(4096);
if (!invalidation_map) {
E_Exit("cb:failed to allocate invalidation_map's memory");
}
memset(invalidation_map,0,4096);
}
invalidation_map[addr]++;
@ -207,6 +219,9 @@ public:
} else {
if (!invalidation_map) {
invalidation_map=(Bit8u*)malloc(4096);
if (!invalidation_map) {
E_Exit("cw:failed to allocate invalidation_map's memory");
}
memset(invalidation_map,0,4096);
}
(*(Bit16u*)&invalidation_map[addr])+=0x101;
@ -233,6 +248,9 @@ public:
} else {
if (!invalidation_map) {
invalidation_map=(Bit8u*)malloc(4096);
if (!invalidation_map) {
E_Exit("cd:failed to allocate invalidation_map's memory");
}
memset(invalidation_map,0,4096);
}
(*(Bit32u*)&invalidation_map[addr])+=0x1010101;
@ -428,10 +446,10 @@ static void cache_closeblock(void) {
if (written>block->cache.size) {
if (!block->cache.next) {
if (written>block->cache.size+CACHE_MAXSIZE)
E_Exit("CacheBlock overrun 1 %lu",
E_Exit("CacheBlock overrun 1 %" PRIuPTR,
written-block->cache.size);
} else {
E_Exit("CacheBlock overrun 2 written %lu size %lu",
E_Exit("CacheBlock overrun 2 written %" PRIuPTR " size %" PRIuPTR,
written, block->cache.size);
}
} else {

View file

@ -86,10 +86,11 @@ static bool MakeCodePage(Bitu lin_addr,CodePageHandler * &cph) {
cph=0; return false;
}
/* Find a free CodePage */
if (!cache.free_pages) {
if (cache.used_pages!=decode.page.code) cache.used_pages->ClearRelease();
if (!cache.free_pages && cache.used_pages) {
if (cache.used_pages != decode.page.code)
cache.used_pages->ClearRelease();
else {
if ((cache.used_pages->next) && (cache.used_pages->next!=decode.page.code))
if ((cache.used_pages->next) && (cache.used_pages->next != decode.page.code))
cache.used_pages->next->ClearRelease();
else {
LOG_MSG("DYNX86:Invalid cache links");
@ -97,6 +98,10 @@ static bool MakeCodePage(Bitu lin_addr,CodePageHandler * &cph) {
}
}
}
if (!cache.free_pages) {
LOG_MSG("DYNX86:cache.free_pages is not useable");
return false;
}
CodePageHandler * cpagehandler=cache.free_pages;
cache.free_pages=cache.free_pages->next;
cpagehandler->prev=cache.last_page;
@ -176,6 +181,10 @@ static INLINE void decode_increase_wmapmask(Bitu size) {
Bitu newmasklen=activecb->cache.masklen*4;
if (newmasklen<mapidx+size) newmasklen=((mapidx+size)&~3)*2;
Bit8u* tempmem=(Bit8u*)malloc(newmasklen);
if (tempmem == nullptr) {
LOG_MSG("Unable to allocate %" PRIuPTR " bytes for tempmem", newmasklen);
return;
}
memset(tempmem,0,newmasklen);
memcpy(tempmem,activecb->cache.wmapmask,activecb->cache.masklen);
free(activecb->cache.wmapmask);