Allocate everything on the stack instead of the heap

This commit is contained in:
Maschell
2020-05-17 13:11:52 +02:00
parent d36ad9bf3d
commit b526acbded
20 changed files with 146 additions and 181 deletions

View File

@@ -6,7 +6,7 @@
#include "ModuleData.h"
#include "RelocationData.h"
bool ModuleDataPersistence::saveModuleData(module_information_t * moduleInformation, ModuleData * module) {
bool ModuleDataPersistence::saveModuleData(module_information_t * moduleInformation, const ModuleData& module) {
int32_t module_count = moduleInformation->number_used_modules;
if(module_count >= MAXIMUM_MODULES) {
@@ -16,9 +16,9 @@ bool ModuleDataPersistence::saveModuleData(module_information_t * moduleInformat
// Copy data to global struct.
module_information_single_t * module_data = &(moduleInformation->module_data[module_count]);
DEBUG_FUNCTION_LINE("Saving reloation data for module at %08X", module->getEntrypoint());
DEBUG_FUNCTION_LINE("Saving reloation data for module at %08X", module.getEntrypoint());
// Relocation
std::vector<RelocationData *> relocationData = module->getRelocationDataList();
std::vector<RelocationData> relocationData = module.getRelocationDataList();
for (auto const& reloc : relocationData) {
if(!DynamicLinkingHelper::addReloationEntry(&(moduleInformation->linking_data), module_data->linking_entries, DYN_LINK_RELOCATION_LIST_LENGTH, reloc)) {
DEBUG_FUNCTION_LINE("Failed to add relocation entry\n");
@@ -26,14 +26,14 @@ bool ModuleDataPersistence::saveModuleData(module_information_t * moduleInformat
}
}
module_data->bssAddr = module->getBSSAddr();
module_data->bssSize = module->getBSSSize();
module_data->sbssAddr = module->getSBSSAddr();
module_data->sbssSize = module->getSBSSSize();
module_data->startAddress = module->getStartAddress();
module_data->endAddress = module->getEndAddress();
module_data->bssAddr = module.getBSSAddr();
module_data->bssSize = module.getBSSSize();
module_data->sbssAddr = module.getSBSSAddr();
module_data->sbssSize = module.getSBSSSize();
module_data->startAddress = module.getStartAddress();
module_data->endAddress = module.getEndAddress();
module_data->entrypoint = module->getEntrypoint();
module_data->entrypoint = module.getEntrypoint();
moduleInformation->number_used_modules++;
@@ -43,8 +43,8 @@ bool ModuleDataPersistence::saveModuleData(module_information_t * moduleInformat
return true;
}
std::vector<ModuleData*> ModuleDataPersistence::loadModuleData(module_information_t * moduleInformation) {
std::vector<ModuleData*> result;
std::vector<ModuleData> ModuleDataPersistence::loadModuleData(module_information_t * moduleInformation) {
std::vector<ModuleData> result;
if(moduleInformation == NULL) {
DEBUG_FUNCTION_LINE("moduleInformation == NULL\n");
return result;
@@ -60,16 +60,12 @@ std::vector<ModuleData*> ModuleDataPersistence::loadModuleData(module_informatio
for(int32_t i = 0; i < module_count; i++) {
// Copy data from struct.
module_information_single_t * module_data = &(moduleInformation->module_data[i]);
ModuleData * moduleData = new ModuleData();
if(moduleData == NULL){
DEBUG_FUNCTION_LINE("Failed to allocate data for ModuleData object\n");
continue;
}
moduleData->setBSSLocation(module_data->bssAddr, module_data->bssSize);
moduleData->setSBSSLocation(module_data->sbssAddr, module_data->sbssSize);
moduleData->setEntrypoint(module_data->entrypoint);
moduleData->setStartAddress(module_data->startAddress);
moduleData->setEndAddress(module_data->endAddress);
ModuleData moduleData;
moduleData.setBSSLocation(module_data->bssAddr, module_data->bssSize);
moduleData.setSBSSLocation(module_data->sbssAddr, module_data->sbssSize);
moduleData.setEntrypoint(module_data->entrypoint);
moduleData.setStartAddress(module_data->startAddress);
moduleData.setEndAddress(module_data->endAddress);
for(uint32_t j = 0; j < DYN_LINK_RELOCATION_LIST_LENGTH; j++) {
dyn_linking_relocation_entry_t * linking_entry = &(module_data->linking_entries[j]);
@@ -95,17 +91,10 @@ std::vector<ModuleData*> ModuleDataPersistence::loadModuleData(module_informatio
DEBUG_FUNCTION_LINE("functionEntry->functionName was NULL, skipping relocation entry\n");
continue;
}
ImportRPLInformation * rplInfo = new ImportRPLInformation(importEntry->importName, importEntry->isData);
if(rplInfo == NULL){
DEBUG_FUNCTION_LINE("Failed to allocate ImportRPLInformation object. Skipping relocation entry.\n");
continue;
}
RelocationData * reloc = new RelocationData(linking_entry->type, linking_entry->offset, linking_entry->addend, linking_entry->destination, functionEntry->functionName, rplInfo);
if(reloc == NULL){
DEBUG_FUNCTION_LINE("Failed to allocate RelocationData object. Skipping relocation entry.\n");
continue;
}
moduleData->addRelocationData(reloc);
ImportRPLInformation rplInfo(importEntry->importName, importEntry->isData);
RelocationData reloc(linking_entry->type, linking_entry->offset, linking_entry->addend, linking_entry->destination, functionEntry->functionName, rplInfo);
moduleData.addRelocationData(reloc);
}
result.push_back(moduleData);
}