Skip to content

Commit

Permalink
Fix a possible whereby, if a game used fewer than 32768 bytes of code…
Browse files Browse the repository at this point in the history
… in EWRAM and that

code modified itself, it overwrote bytes after itself with zeroes.
Merged upstream fix :
Nebuleon/ReGBA@7f76745
  • Loading branch information
gameblabla committed Jun 27, 2019
1 parent 53c7026 commit 9fe6602
Showing 1 changed file with 44 additions and 44 deletions.
88 changes: 44 additions & 44 deletions cpu_threaded.c
Original file line number Diff line number Diff line change
Expand Up @@ -3411,50 +3411,50 @@ void flush_translation_cache_ram()
#endif
ram_translation_ptr = ram_translation_cache;
ram_block_tag_top = 0x0101;
if(iwram_code_min != 0xFFFFFFFF)
{
iwram_code_min &= 0x7FFF;
iwram_code_max &= 0x7FFF;
memset(iwram + iwram_code_min, 0, iwram_code_max - iwram_code_min);
}

if(ewram_code_min != 0xFFFFFFFF)
{
u32 ewram_code_min_page;
u32 ewram_code_max_page;
u32 ewram_code_min_offset;
u32 ewram_code_max_offset;
u32 i;

ewram_code_min &= 0x3FFFF;
ewram_code_max &= 0x3FFFF;

ewram_code_min_page = ewram_code_min >> 15;
ewram_code_max_page = ewram_code_max >> 15;
ewram_code_min_offset = ewram_code_min & 0x7FFF;
ewram_code_max_offset = ewram_code_max & 0x7FFF;

if(ewram_code_min_page == ewram_code_max_page)
{
memset(ewram + (ewram_code_min_page * 0x10000) +
ewram_code_min_offset, 0,
ewram_code_max_offset - ewram_code_min_offset);
}
else
{
for(i = ewram_code_min_page + 1; i < ewram_code_max_page; i++)
{
memset(ewram + (i * 0x10000), 0, 0x8000);
}

memset(ewram, 0, ewram_code_max_offset);
}
}

iwram_code_min = 0xFFFFFFFF;
iwram_code_max = 0xFFFFFFFF;
ewram_code_min = 0xFFFFFFFF;
ewram_code_max = 0xFFFFFFFF;

if(iwram_code_min != 0xFFFFFFFF)
{
iwram_code_min &= 0x7FFF;
iwram_code_max &= 0x7FFF;
memset(iwram + iwram_code_min, 0, iwram_code_max - iwram_code_min);
iwram_code_min = 0xFFFFFFFF;
iwram_code_max = 0xFFFFFFFF;
}

if(ewram_code_min != 0xFFFFFFFF)
{
u32 ewram_code_min_page;
u32 ewram_code_max_page;
u32 ewram_code_min_offset;
u32 ewram_code_max_offset;
u32 i;

ewram_code_min &= 0x3FFFF;
ewram_code_max &= 0x3FFFF;

ewram_code_min_page = ewram_code_min >> 15;
ewram_code_max_page = ewram_code_max >> 15;
ewram_code_min_offset = ewram_code_min & 0x7FFF;
ewram_code_max_offset = ewram_code_max & 0x7FFF;

if(ewram_code_min_page == ewram_code_max_page)
{
memset(ewram + (ewram_code_min_page * 0x10000) +
ewram_code_min_offset, 0,
ewram_code_max_offset - ewram_code_min_offset);
}
else
{
for(i = ewram_code_min_page + 1; i < ewram_code_max_page; i++)
{
memset(ewram + (i * 0x10000), 0, 0x8000);
}

memset(ewram, 0, ewram_code_max_offset);
ewram_code_min = 0xFFFFFFFF;
ewram_code_max = 0xFFFFFFFF;
}
}
}

void flush_translation_cache_rom()
Expand Down

0 comments on commit 9fe6602

Please sign in to comment.