Save the address of memory allocated on the plugin heap

This commit is contained in:
Maschell 2020-05-03 12:23:50 +02:00
parent 53f454f6ed
commit c1c7594926
4 changed files with 16 additions and 1 deletions

View File

@ -64,6 +64,8 @@ struct plugin_info_t {
uint32_t number_used_hooks; // Number of used hooks. Maximum is MAXIMUM_HOOKS_PER_PLUGIN uint32_t number_used_hooks; // Number of used hooks. Maximum is MAXIMUM_HOOKS_PER_PLUGIN
replacement_data_hook_t hooks[MAXIMUM_HOOKS_PER_PLUGIN]; // Replacement information for each function. replacement_data_hook_t hooks[MAXIMUM_HOOKS_PER_PLUGIN]; // Replacement information for each function.
uint8_t trampolinId; uint8_t trampolinId;
void * allocatedTextMemoryAddress = nullptr;
void * allocatedDataMemoryAddress = nullptr;
}; };
struct plugin_data_t { struct plugin_data_t {

View File

@ -159,6 +159,9 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t * pluginInforma
} }
} }
plugin_data->info.trampolinId = pluginInfo.getTrampolinId(); plugin_data->info.trampolinId = pluginInfo.getTrampolinId();
plugin_data->info.allocatedTextMemoryAddress = pluginInfo.allocatedTextMemoryAddress;
plugin_data->info.allocatedDataMemoryAddress = pluginInfo.allocatedDataMemoryAddress;
/* Copy plugin data */ /* Copy plugin data */
auto pluginData = plugin.getPluginData(); auto pluginData = plugin.getPluginData();
@ -219,6 +222,8 @@ std::vector<PluginContainer> PluginContainerPersistence::loadPlugins(plugin_info
PluginInformation pluginInformation; PluginInformation pluginInformation;
pluginInformation.setTrampolinId(plugin_data->info.trampolinId); pluginInformation.setTrampolinId(plugin_data->info.trampolinId);
pluginInformation.allocatedTextMemoryAddress = plugin_data->info.allocatedTextMemoryAddress;
pluginInformation.allocatedDataMemoryAddress = plugin_data->info.allocatedDataMemoryAddress;
for(uint32_t i = 0; i < MAXIMUM_PLUGIN_SECTION_LENGTH; i++) { for(uint32_t i = 0; i < MAXIMUM_PLUGIN_SECTION_LENGTH; i++) {
plugin_section_info_t * sectionInfo = &(plugin_data->info.sectionInfos[i]); plugin_section_info_t * sectionInfo = &(plugin_data->info.sectionInfos[i]);

View File

@ -81,6 +81,7 @@ public:
uint8_t getTrampolinId() const { uint8_t getTrampolinId() const {
return trampolinId; return trampolinId;
} }
private: private:
std::vector<HookData> hook_data_list; std::vector<HookData> hook_data_list;
@ -90,6 +91,9 @@ private:
uint8_t trampolinId = 0; uint8_t trampolinId = 0;
void* allocatedTextMemoryAddress = 0;
void* allocatedDataMemoryAddress = 0;
friend class PluginInformationFactory; friend class PluginInformationFactory;
friend class PluginInformationPersistence; friend class PluginContainerPersistence;
}; };

View File

@ -197,6 +197,10 @@ std::optional<PluginInformation> PluginInformationFactory::load(const PluginData
} }
} }
// Save the addresses for the allocated. This way we can free it again :)
pluginInfo.allocatedDataMemoryAddress = data_data;
pluginInfo.allocatedTextMemoryAddress = text_data;
return pluginInfo; return pluginInfo;
} }