Updating logging messages, call DCFlushRange on the actual heap instead of a hardcoded address, general clean up.

This commit is contained in:
Maschell
2021-01-10 13:17:47 +01:00
parent 7154824192
commit f0b78caec3
7 changed files with 41 additions and 43 deletions

View File

@@ -8,14 +8,11 @@
#include "plugin/PluginDataPersistence.h"
#include "plugin/PluginContainerPersistence.h"
#include "PluginManagement.h"
#include "utils/logger.h"
#include "hooks.h"
#include "patcher/hooks_patcher_static.h"
WUMS_MODULE_EXPORT_NAME("homebrew_wupsbackend");
std::vector<PluginContainer> loadPlugins(const std::vector<PluginData> &pluginList, MEMHeapHandle heapHandle);
WUMS_INITIALIZE(args) {
WHBLogUdpInit();
@@ -65,24 +62,25 @@ WUMS_APPLICATION_STARTS() {
// If this address is 0, make sure the header common match the one
// in the SetupPayload repo. (I know that's a bad idea)
endAddress = (endAddress + 0x100) & 0xFFFFFF00;
DEBUG_FUNCTION_LINE("endAddress: %08X", endAddress);
DEBUG_FUNCTION_LINE("Create heap");
pluginDataHeap = MEMCreateExpHeapEx((void *) (endAddress), 0x00FFF000 - endAddress, 0);
gPluginDataHeapSize = 0x00FFF000 - endAddress;
if (pluginDataHeap != NULL) {
if (gPluginInformation == NULL) {
DEBUG_FUNCTION_LINE("Create heap to store plugins");
pluginDataHeap = MEMCreateExpHeapEx((void *) (endAddress), gPluginDataHeapSize, 0);
if (pluginDataHeap != nullptr) {
if (gPluginInformation == nullptr) {
DEBUG_FUNCTION_LINE("Allocate gPluginInformation on heap %08X (size: %d bytes)", pluginDataHeap, sizeof(plugin_information_t));
gPluginInformation = (plugin_information_t *) MEMAllocFromExpHeapEx(pluginDataHeap, sizeof(plugin_information_t), 4);
if (gPluginInformation == NULL) {
if (gPluginInformation == nullptr) {
DEBUG_FUNCTION_LINE("Failed to allocate global plugin information");
return;
}
memset((void *) gPluginInformation, 0, sizeof(plugin_information_t));
}
DEBUG_FUNCTION_LINE("MEMGetAllocatableSizeForExpHeapEx %d kb", MEMGetAllocatableSizeForExpHeapEx(pluginDataHeap, 4) / 1024);
DEBUG_FUNCTION_LINE("Available memory for storing plugins: %d kb", MEMGetAllocatableSizeForExpHeapEx(pluginDataHeap, 4) / 1024);
std::vector<PluginData> pluginList = PluginDataFactory::loadDir("fs:/vol/external01/wiiu/plugins/", pluginDataHeap);
DEBUG_FUNCTION_LINE("Loaded %d plugin data", pluginList.size());
DEBUG_FUNCTION_LINE("Loaded data for %d plugins.", pluginList.size());
std::vector<PluginContainer> plugins = PluginManagement::loadPlugins(pluginList, pluginDataHeap, gPluginInformation->trampolines, DYN_LINK_TRAMPOLIN_LIST_LENGTH);
@@ -98,7 +96,7 @@ WUMS_APPLICATION_STARTS() {
}
}
if (gLinkOnReload.loadOnReload) {
DEBUG_FUNCTION_LINE("We would now swap the plugins");
DEBUG_FUNCTION_LINE("Reload with new plugin list.");
std::vector<PluginData> pluginDataList;
for (int32_t i = 0; i < gLinkOnReload.number_used_plugins; i++) {
auto pluginData = PluginDataPersistence::load(&gLinkOnReload.plugin_data[i]);
@@ -108,42 +106,40 @@ WUMS_APPLICATION_STARTS() {
for (int32_t plugin_index = 0; plugin_index < gPluginInformation->number_used_plugins; plugin_index++) {
plugin_information_single_t *plugin = &(gPluginInformation->plugin_data[plugin_index]);
BOOL doDelete = true;
DEBUG_FUNCTION_LINE("Check if we can delete %08X", plugin->data.buffer);
for (auto &pluginData: pluginDataList) {
if (pluginData.buffer == plugin->data.buffer) {
DEBUG_FUNCTION_LINE("We can keep buffer %08X", plugin->data.buffer);
doDelete = false;
break;
}
}
if (doDelete) {
DEBUG_FUNCTION_LINE("We need to delete the plugin data for plugin %s", plugin->meta.name);
if (plugin->data.buffer != nullptr) {
if (plugin->data.memoryType == eMemTypeMEM2) {
DEBUG_FUNCTION_LINE("free %08X", plugin->data.buffer);
DEBUG_FUNCTION_LINE("Free plugin data buffer for %s [%08X]", plugin->meta.name, plugin->data.buffer);
free(plugin->data.buffer);
} else if (plugin->data.memoryType == eMemTypeExpHeap) {
DEBUG_FUNCTION_LINE("free %08X on EXP heap %08X", plugin->data.buffer, plugin->data.heapHandle);
DEBUG_FUNCTION_LINE("Free plugin data buffer for %s [%08X on heap %08X]", plugin->meta.name, plugin->data.buffer, plugin->data.heapHandle);
MEMFreeToExpHeap((MEMHeapHandle) plugin->data.heapHandle, plugin->data.buffer);
} else {
DEBUG_FUNCTION_LINE("########################");
DEBUG_FUNCTION_LINE("Failed to free memory from plugin");
DEBUG_FUNCTION_LINE("########################");
}
plugin->data.buffer = NULL;
plugin->data.buffer = nullptr;
plugin->data.bufferLength = 0;
} else {
DEBUG_FUNCTION_LINE("Plugin has no copy of elf save in memory, can't free it");
DEBUG_FUNCTION_LINE("Plugin %s has no copy of elf saved in memory, can't free it", plugin->meta.name);
}
}
}
DEBUG_FUNCTION_LINE("unloadPlugins");
PluginManagement::unloadPlugins(gPluginInformation, pluginDataHeap, false);
std::vector<PluginContainer> plugins = PluginManagement::loadPlugins(pluginDataList, pluginDataHeap, gPluginInformation->trampolines, DYN_LINK_TRAMPOLIN_LIST_LENGTH);
for (auto &pluginContainer : plugins) {
DEBUG_FUNCTION_LINE("Saving %s from %s", pluginContainer.getMetaInformation().getName().c_str(), pluginContainer.getMetaInformation().getAuthor().c_str());
DEBUG_FUNCTION_LINE("Stored information for plugin %s ; %s", pluginContainer.getMetaInformation().getName().c_str(), pluginContainer.getMetaInformation().getAuthor().c_str());
if (!PluginContainerPersistence::savePlugin(gPluginInformation, pluginContainer)) {
DEBUG_FUNCTION_LINE("Failed to save plugin");
}
@@ -152,21 +148,18 @@ WUMS_APPLICATION_STARTS() {
initNeeded = true;
}
if (pluginDataHeap != NULL) {
if (pluginDataHeap != nullptr) {
std::vector<PluginContainer> plugins = PluginContainerPersistence::loadPlugins(gPluginInformation);
PluginManagement::doRelocations(plugins, gPluginInformation->trampolines, DYN_LINK_TRAMPOLIN_LIST_LENGTH);
// PluginManagement::memsetBSS(plugins);
DCFlushRange((void *) 0x00800000, 0x00800000);
ICInvalidateRange((void *) 0x00800000, 0x00800000);
DCFlushRange((void *) pluginDataHeap, gPluginDataHeapSize);
ICInvalidateRange((void *) pluginDataHeap, gPluginDataHeapSize);
if (initNeeded) {
PluginManagement::callInitHooks(gPluginInformation);
initNeeded = false;
}
PluginManagement::PatchFunctionsAndCallHooks(gPluginInformation);
}
return;
}