Fix checking the size of modules before linking

This commit is contained in:
Maschell 2020-12-01 13:06:58 +01:00
parent c68e375567
commit 6a2a7ca1fd
2 changed files with 8 additions and 4 deletions

View File

@ -111,8 +111,7 @@ int main(int argc, char **argv) {
uint32_t destination_address = ((uint32_t) gModuleData + (sizeof(module_information_t) + 0x0000FFFF)) & 0xFFFF0000;
for (int i = 0; i < modules.GetFilecount(); i++) {
DEBUG_FUNCTION_LINE("Loading module %s", modules.GetFilepath(i));
std::optional<ModuleData> moduleData = ModuleDataFactory::load(modules.GetFilepath(i), &destination_address, MEMORY_REGION_USABLE_END - textSectionStart, gModuleData->trampolines, DYN_LINK_TRAMPOLIN_LIST_LENGTH);
std::optional<ModuleData> moduleData = ModuleDataFactory::load(modules.GetFilepath(i), &destination_address, MEMORY_REGION_USABLE_END - destination_address, gModuleData->trampolines, DYN_LINK_TRAMPOLIN_LIST_LENGTH);
if (moduleData) {
DEBUG_FUNCTION_LINE("Successfully loaded %s", modules.GetFilepath(i));

View File

@ -54,7 +54,6 @@ std::optional<ModuleData> ModuleDataFactory::load(std::string path, uint32_t *de
uint32_t totalSize = 0;
uint32_t endAddress = 0;
for (uint32_t i = 0; i < sec_num; ++i) {
section *psec = reader.sections[i];
if (psec->get_type() == 0x80000002) {
@ -63,6 +62,13 @@ std::optional<ModuleData> ModuleDataFactory::load(std::string path, uint32_t *de
if ((psec->get_type() == SHT_PROGBITS || psec->get_type() == SHT_NOBITS) && (psec->get_flags() & SHF_ALLOC)) {
uint32_t sectionSize = psec->get_size();
totalSize += sectionSize;
if(totalSize > maximum_size){
DEBUG_FUNCTION_LINE("Couldn't load setup module because it's too big.");
return {};
}
uint32_t address = (uint32_t) psec->get_address();
destinations[psec->get_index()] = (uint8_t *) baseOffset;
@ -107,7 +113,6 @@ std::optional<ModuleData> ModuleDataFactory::load(std::string path, uint32_t *de
moduleData.addSectionInfo(SectionInfo(psec->get_name(), destination, sectionSize));
DEBUG_FUNCTION_LINE("Saved %s section info. Location: %08X size: %08X", psec->get_name().c_str(), destination, sectionSize);
totalSize += sectionSize;
if (endAddress < destination + sectionSize) {
endAddress = destination + sectionSize;