Skip to content

Commit 7319630

Browse files
authored
Fix issue with regenerating patched functions with no base functions regenerated, add 1kB of padding between mods to mitigate OOB accesses in mods, update N64Recomp (#84)
1 parent 3474514 commit 7319630

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

N64Recomp

librecomp/src/mods.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,13 +1320,15 @@ std::vector<recomp::mods::ModLoadErrorDetails> recomp::mods::ModContext::regener
13201320
}
13211321

13221322
// Apply the regenlist.
1323-
regenerated_code_handle = apply_regenlist(regenlist, decompressed_rom);
1324-
if (!regenerated_code_handle || !regenerated_code_handle->good()) {
1325-
regenerated_code_handle.reset();
1326-
ret.emplace_back(ModLoadErrorDetails{
1327-
"", ModLoadError::FailedToLoadCode, error_to_string(CodeModLoadError::InternalError)
1328-
});
1329-
return ret;
1323+
if (!regenlist.functions.empty()) {
1324+
regenerated_code_handle = apply_regenlist(regenlist, decompressed_rom);
1325+
if (!regenerated_code_handle || !regenerated_code_handle->good()) {
1326+
regenerated_code_handle.reset();
1327+
ret.emplace_back(ModLoadErrorDetails{
1328+
"", ModLoadError::FailedToLoadCode, error_to_string(CodeModLoadError::InternalError)
1329+
});
1330+
return ret;
1331+
}
13301332
}
13311333

13321334
if (!regenlist.patched_hooks.empty()) {
@@ -1484,6 +1486,8 @@ recomp::mods::CodeModLoadError recomp::mods::ModContext::init_mod_code(uint8_t*
14841486
cur_section_addr += section.size + section.bss_size;
14851487
// Align the next section's address to 16 bytes.
14861488
cur_section_addr = (cur_section_addr + 15) & ~15;
1489+
// Add some empty space between mods to act as a buffer for misbehaving mods that have out of bounds accesses.
1490+
cur_section_addr += 0x400;
14871491
}
14881492

14891493
// Iterate over each section again after loading them to perform R_MIPS_32 relocations.

0 commit comments

Comments
 (0)