mirror of
https://github.com/wiiu-env/WiiUPluginLoaderBackend.git
synced 2026-08-24 20:04:11 -05:00
Fix resolving symbolnames while cleaning up plugins
This commit is contained in:
@@ -14,6 +14,7 @@ StoredBuffer gStoredTVBuffer = {};
|
||||
StoredBuffer gStoredDRCBuffer = {};
|
||||
|
||||
std::vector<PluginContainer> gLoadedPlugins;
|
||||
std::vector<PluginContainer> gPluginsToBeDeInitialized;
|
||||
|
||||
std::set<std::shared_ptr<PluginData>, PluginDataSharedPtrComparator> gLoadedData;
|
||||
std::vector<PluginLoadWrapper> gLoadOnNextLaunch;
|
||||
|
||||
@@ -26,6 +26,7 @@ extern StoredBuffer gStoredTVBuffer;
|
||||
extern StoredBuffer gStoredDRCBuffer;
|
||||
|
||||
extern std::vector<PluginContainer> gLoadedPlugins;
|
||||
extern std::vector<PluginContainer> gPluginsToBeDeInitialized;
|
||||
|
||||
extern std::set<std::shared_ptr<PluginData>, PluginDataSharedPtrComparator> gLoadedData;
|
||||
extern std::vector<PluginLoadWrapper> gLoadOnNextLaunch;
|
||||
|
||||
@@ -154,7 +154,7 @@ WUMS_APPLICATION_ENDS() {
|
||||
}
|
||||
|
||||
void CheckCleanupCallbackUsage(const std::vector<PluginContainer> &plugins);
|
||||
void CleanupPlugins(std::vector<PluginContainer> &&pluginsToDeinit);
|
||||
void CleanupPlugins(std::vector<PluginContainer> &pluginsToDeinit);
|
||||
|
||||
|
||||
WUMS_APPLICATION_STARTS() {
|
||||
@@ -283,11 +283,12 @@ WUMS_APPLICATION_STARTS() {
|
||||
}
|
||||
|
||||
// deinit all plugins that are still in gLoadedPlugins list.
|
||||
std::vector<PluginContainer> 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<PluginContainer> &&pluginsToDeinit) {
|
||||
void CleanupPlugins(std::vector<PluginContainer> &pluginsToDeinit) {
|
||||
auto *currentThread = OSGetCurrentThread();
|
||||
const auto saved_reent = currentThread->reserved[4];
|
||||
const auto saved_cleanupCallback = currentThread->cleanupCallback;
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "plugin/PluginData.h"
|
||||
#include "plugin/SectionInfo.h"
|
||||
#include "utils/config/ConfigUtils.h"
|
||||
#include "utils/logger.h"
|
||||
|
||||
#include <coreinit/cache.h>
|
||||
#include <coreinit/core.h>
|
||||
@@ -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<PluginContainer> *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<uint32_t>(functionSymbolData->getAddress());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
strncpy(symbolNameBuffer, ".text", symbolNameBufferLength - 1);
|
||||
symbolNameBuffer[symbolNameBufferLength - 1] = '\0';
|
||||
if (outDistance) {
|
||||
*outDistance = addr - reinterpret_cast<uint32_t>(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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user