From 54cf7ed9e7d13b7b3cf1c3a5cf5c13692fc69d17 Mon Sep 17 00:00:00 2001 From: Maschell Date: Mon, 9 Feb 2026 14:18:50 +0100 Subject: [PATCH 1/3] Fix resolving symbolnames while cleaning up plugins --- source/globals.cpp | 1 + source/globals.h | 1 + source/main.cpp | 11 ++--- source/patcher/hooks_patcher_static.cpp | 56 ++++++++++++++----------- 4 files changed, 40 insertions(+), 29 deletions(-) diff --git a/source/globals.cpp b/source/globals.cpp index 01f6771..749c750 100644 --- a/source/globals.cpp +++ b/source/globals.cpp @@ -14,6 +14,7 @@ StoredBuffer gStoredTVBuffer = {}; StoredBuffer gStoredDRCBuffer = {}; std::vector gLoadedPlugins; +std::vector gPluginsToBeDeInitialized; std::set, PluginDataSharedPtrComparator> gLoadedData; std::vector gLoadOnNextLaunch; diff --git a/source/globals.h b/source/globals.h index 52d9528..b45e134 100644 --- a/source/globals.h +++ b/source/globals.h @@ -26,6 +26,7 @@ extern StoredBuffer gStoredTVBuffer; extern StoredBuffer gStoredDRCBuffer; extern std::vector gLoadedPlugins; +extern std::vector gPluginsToBeDeInitialized; extern std::set, PluginDataSharedPtrComparator> gLoadedData; extern std::vector gLoadOnNextLaunch; diff --git a/source/main.cpp b/source/main.cpp index 3ca864f..98958b3 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -154,7 +154,7 @@ WUMS_APPLICATION_ENDS() { } void CheckCleanupCallbackUsage(const std::vector &plugins); -void CleanupPlugins(std::vector &&pluginsToDeinit); +void CleanupPlugins(std::vector &pluginsToDeinit); WUMS_APPLICATION_STARTS() { @@ -283,11 +283,12 @@ WUMS_APPLICATION_STARTS() { } // deinit all plugins that are still in gLoadedPlugins list. - std::vector pluginsToDeinit = std::move(gLoadedPlugins); - gLoadedPlugins = std::move(pluginsToKeep); + gPluginsToBeDeInitialized = std::move(gLoadedPlugins); + gLoadedPlugins = std::move(pluginsToKeep); DEBUG_FUNCTION_LINE("Deinit unused plugins"); - CleanupPlugins(std::move(pluginsToDeinit)); + CleanupPlugins(gPluginsToBeDeInitialized); + gPluginsToBeDeInitialized.clear(); DEBUG_FUNCTION_LINE("Load new plugins"); newLoadedPlugins = PluginManagement::loadPlugins(toBeLoaded); @@ -338,7 +339,7 @@ WUMS_APPLICATION_STARTS() { } } -void CleanupPlugins(std::vector &&pluginsToDeinit) { +void CleanupPlugins(std::vector &pluginsToDeinit) { auto *currentThread = OSGetCurrentThread(); const auto saved_reent = currentThread->reserved[4]; const auto saved_cleanupCallback = currentThread->cleanupCallback; diff --git a/source/patcher/hooks_patcher_static.cpp b/source/patcher/hooks_patcher_static.cpp index 75e163c..4d04460 100644 --- a/source/patcher/hooks_patcher_static.cpp +++ b/source/patcher/hooks_patcher_static.cpp @@ -7,6 +7,7 @@ #include "plugin/PluginData.h" #include "plugin/SectionInfo.h" #include "utils/config/ConfigUtils.h" +#include "utils/logger.h" #include #include @@ -176,37 +177,43 @@ DECL_FUNCTION(uint32_t, SC17_FindClosestSymbol, char *moduleNameBuffer, uint32_t moduleNameBufferLength) { if (symbolNameBuffer && symbolNameBufferLength > 0 && moduleNameBuffer && moduleNameBufferLength > 0) { - for (const auto &plugin : gLoadedPlugins) { - if (!plugin.isLinkedAndLoaded()) { - continue; - } - const auto sectionInfo = plugin.getPluginLinkInformation().getSectionInfo(".text"); - if (!sectionInfo) { - continue; - } + const std::vector *pluginLists[] = {&gLoadedPlugins, &gPluginsToBeDeInitialized}; + for (const auto *list : pluginLists) { + for (const auto &plugin : *list) { + if (!plugin.isLinkedAndLoaded()) { + continue; + } - if (!sectionInfo->isInSection(addr)) { - continue; - } - strncpy(moduleNameBuffer, plugin.getMetaInformation().getName().c_str(), moduleNameBufferLength - 1); - moduleNameBuffer[moduleNameBufferLength - 1] = '\0'; - if (const auto functionSymbolData = plugin.getPluginLinkInformation().getNearestFunctionSymbolData(addr)) { - strncpy(symbolNameBuffer, functionSymbolData->getName().c_str(), symbolNameBufferLength - 1); + const auto sectionInfo = plugin.getPluginLinkInformation().getSectionInfo(".text"); + if (!sectionInfo) { + continue; + } + + if (!sectionInfo->isInSection(addr)) { + continue; + } + + + strncpy(moduleNameBuffer, plugin.getMetaInformation().getName().c_str(), moduleNameBufferLength - 1); + moduleNameBuffer[moduleNameBufferLength - 1] = '\0'; + if (const auto functionSymbolData = plugin.getPluginLinkInformation().getNearestFunctionSymbolData(addr)) { + strncpy(symbolNameBuffer, functionSymbolData->getName().c_str(), symbolNameBufferLength - 1); + symbolNameBuffer[symbolNameBufferLength - 1] = '\0'; + if (outDistance) { + *outDistance = addr - reinterpret_cast(functionSymbolData->getAddress()); + } + return 0; + } + + strncpy(symbolNameBuffer, ".text", symbolNameBufferLength - 1); symbolNameBuffer[symbolNameBufferLength - 1] = '\0'; if (outDistance) { - *outDistance = addr - reinterpret_cast(functionSymbolData->getAddress()); + *outDistance = addr - sectionInfo->getAddress(); } - return 0; - } - strncpy(symbolNameBuffer, ".text", symbolNameBufferLength - 1); - symbolNameBuffer[symbolNameBufferLength - 1] = '\0'; - if (outDistance) { - *outDistance = addr - sectionInfo->getAddress(); + return 0; } - - return 0; } } @@ -219,6 +226,7 @@ DECL_FUNCTION(uint32_t, KiGetAppSymbolName, uint32_t addr, char *buffer, int32_t if (!plugin.isLinkedAndLoaded()) { continue; } + const auto sectionInfo = plugin.getPluginLinkInformation().getSectionInfo(".text"); if (!sectionInfo) { continue; From c8f82a1ff1c464dc4551e071b6f879eb4b54b574 Mon Sep 17 00:00:00 2001 From: Maschell Date: Tue, 10 Feb 2026 17:15:51 +0100 Subject: [PATCH 2/3] Add missing FINI_WRAPPER hook call before deinit --- source/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/source/main.cpp b/source/main.cpp index 98958b3..e1fa5d7 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -351,6 +351,7 @@ void CleanupPlugins(std::vector &pluginsToDeinit) { currentThread->reserved[4] = 0; CallHook(pluginsToDeinit, WUPS_LOADER_HOOK_DEINIT_PLUGIN); + CallHook(pluginsToDeinit, WUPS_LOADER_HOOK_FINI_WRAPPER); CheckCleanupCallbackUsage(pluginsToDeinit); From df4fcc88abc3cb1f1bb7766bc50a8c5d77b3eab6 Mon Sep 17 00:00:00 2001 From: Maschell Date: Wed, 11 Feb 2026 13:51:34 +0100 Subject: [PATCH 3/3] Fix function signature of SC17_FindClosestSymbol hook --- source/patcher/hooks_patcher_static.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/patcher/hooks_patcher_static.cpp b/source/patcher/hooks_patcher_static.cpp index 4d04460..5f06921 100644 --- a/source/patcher/hooks_patcher_static.cpp +++ b/source/patcher/hooks_patcher_static.cpp @@ -171,7 +171,7 @@ DECL_FUNCTION(void, WPADRead, WPADChan chan, WPADStatus *data) { DECL_FUNCTION(uint32_t, SC17_FindClosestSymbol, uint32_t addr, - uint32_t *outDistance, + int32_t *outDistance, char *symbolNameBuffer, uint32_t symbolNameBufferLength, char *moduleNameBuffer,