From c1c75949262605bf2d0e9817510709c72190bb0f Mon Sep 17 00:00:00 2001 From: Maschell Date: Sun, 3 May 2020 12:23:50 +0200 Subject: [PATCH] Save the address of memory allocated on the plugin heap --- source/common/plugin_defines.h | 2 ++ source/plugin/PluginContainerPersistence.cpp | 5 +++++ source/plugin/PluginInformation.h | 6 +++++- source/plugin/PluginInformationFactory.cpp | 4 ++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/source/common/plugin_defines.h b/source/common/plugin_defines.h index eedd5ca..1b45242 100644 --- a/source/common/plugin_defines.h +++ b/source/common/plugin_defines.h @@ -64,6 +64,8 @@ struct plugin_info_t { 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. uint8_t trampolinId; + void * allocatedTextMemoryAddress = nullptr; + void * allocatedDataMemoryAddress = nullptr; }; struct plugin_data_t { diff --git a/source/plugin/PluginContainerPersistence.cpp b/source/plugin/PluginContainerPersistence.cpp index 494917f..9d58183 100644 --- a/source/plugin/PluginContainerPersistence.cpp +++ b/source/plugin/PluginContainerPersistence.cpp @@ -159,6 +159,9 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t * pluginInforma } } plugin_data->info.trampolinId = pluginInfo.getTrampolinId(); + plugin_data->info.allocatedTextMemoryAddress = pluginInfo.allocatedTextMemoryAddress; + plugin_data->info.allocatedDataMemoryAddress = pluginInfo.allocatedDataMemoryAddress; + /* Copy plugin data */ auto pluginData = plugin.getPluginData(); @@ -219,6 +222,8 @@ std::vector PluginContainerPersistence::loadPlugins(plugin_info PluginInformation pluginInformation; 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++) { plugin_section_info_t * sectionInfo = &(plugin_data->info.sectionInfos[i]); diff --git a/source/plugin/PluginInformation.h b/source/plugin/PluginInformation.h index 1bda3d8..37ef07b 100644 --- a/source/plugin/PluginInformation.h +++ b/source/plugin/PluginInformation.h @@ -81,6 +81,7 @@ public: uint8_t getTrampolinId() const { return trampolinId; } + private: std::vector hook_data_list; @@ -90,6 +91,9 @@ private: uint8_t trampolinId = 0; + void* allocatedTextMemoryAddress = 0; + void* allocatedDataMemoryAddress = 0; + friend class PluginInformationFactory; - friend class PluginInformationPersistence; + friend class PluginContainerPersistence; }; diff --git a/source/plugin/PluginInformationFactory.cpp b/source/plugin/PluginInformationFactory.cpp index e542293..312b7a8 100644 --- a/source/plugin/PluginInformationFactory.cpp +++ b/source/plugin/PluginInformationFactory.cpp @@ -197,6 +197,10 @@ std::optional 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; }