Formatting, fix spelling, clean up

This commit is contained in:
Maschell 2022-01-27 12:47:33 +01:00
parent 84afdb3179
commit 614f58ea8e
25 changed files with 13010 additions and 14975 deletions

View File

@ -1,6 +1,6 @@
FROM wiiuenv/devkitppc:20211229
COPY --from=wiiuenv/wiiumodulesystem:20220123 /artifacts $DEVKITPRO
COPY --from=wiiuenv/wiiumodulesystem:20220127 /artifacts $DEVKITPRO
COPY --from=wiiuenv/wiiupluginsystem:20220123 /artifacts $DEVKITPRO
COPY --from=wiiuenv/libfunctionpatcher:20210924 /artifacts $DEVKITPRO
COPY --from=wiiuenv/libmappedmemory:20210924 /artifacts $DEVKITPRO

View File

@ -14,7 +14,7 @@
#include "hooks.h"
#include "globals.h"
bool PluginManagement::doRelocation(const std::vector<std::shared_ptr<RelocationData>> &relocData, relocation_trampolin_entry_t *tramp_data, uint32_t tramp_length, uint32_t trampolinID) {
bool PluginManagement::doRelocation(const std::vector<std::shared_ptr<RelocationData>> &relocData, relocation_trampoline_entry_t *tramp_data, uint32_t tramp_length, uint32_t trampolineID) {
std::map<std::string, OSDynLoad_Module> moduleHandleCache;
for (auto const &cur: relocData) {
uint32_t functionAddress = 0;
@ -53,23 +53,23 @@ bool PluginManagement::doRelocation(const std::vector<std::shared_ptr<Relocation
} else {
//DEBUG_FUNCTION_LINE("Found export for %s %s", rplName.c_str(), functionName.c_str());
}
if (!ElfUtils::elfLinkOne(cur->getType(), cur->getOffset(), cur->getAddend(), (uint32_t) cur->getDestination(), functionAddress, tramp_data, tramp_length, RELOC_TYPE_IMPORT, trampolinID)) {
if (!ElfUtils::elfLinkOne(cur->getType(), cur->getOffset(), cur->getAddend(), (uint32_t) cur->getDestination(), functionAddress, tramp_data, tramp_length, RELOC_TYPE_IMPORT, trampolineID)) {
DEBUG_FUNCTION_LINE("Relocation failed");
return false;
}
}
DCFlushRange(tramp_data, tramp_length * sizeof(relocation_trampolin_entry_t));
ICInvalidateRange(tramp_data, tramp_length * sizeof(relocation_trampolin_entry_t));
DCFlushRange(tramp_data, tramp_length * sizeof(relocation_trampoline_entry_t));
ICInvalidateRange(tramp_data, tramp_length * sizeof(relocation_trampoline_entry_t));
return true;
}
void PluginManagement::doRelocations(const std::vector<std::shared_ptr<PluginContainer>> &plugins, relocation_trampolin_entry_t *trampData, uint32_t tramp_size) {
void PluginManagement::doRelocations(const std::vector<std::shared_ptr<PluginContainer>> &plugins, relocation_trampoline_entry_t *trampData, uint32_t tramp_size) {
for (auto &pluginContainer: plugins) {
DEBUG_FUNCTION_LINE_VERBOSE("Doing relocations for plugin: %s", pluginContainer->getMetaInformation()->getName().c_str());
if (!PluginManagement::doRelocation(pluginContainer->getPluginInformation()->getRelocationDataList(), trampData, tramp_size, pluginContainer->getPluginInformation()->getTrampolinId())) {
if (!PluginManagement::doRelocation(pluginContainer->getPluginInformation()->getRelocationDataList(), trampData, tramp_size, pluginContainer->getPluginInformation()->getTrampolineId())) {
DEBUG_FUNCTION_LINE("Relocation failed");
}
}
@ -145,7 +145,7 @@ void PluginManagement::unloadPlugins(plugin_information_t *pluginInformation, ME
for (uint32_t i = 0; i < gTrampolineDataSize; i++) {
auto trampoline = &(gTrampolineData[i]);
if (trampoline->id == plugin->info.trampolinId) {
if (trampoline->id == plugin->info.trampolineId) {
trampoline->id = 0;
trampoline->status = RELOC_TRAMP_FREE;
}
@ -189,7 +189,7 @@ void PluginManagement::PatchFunctionsAndCallHooks(plugin_information_t *pluginIn
}
std::vector<std::shared_ptr<PluginContainer>>
PluginManagement::loadPlugins(const std::vector<std::shared_ptr<PluginData>> &pluginList, MEMHeapHandle heapHandle, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length) {
PluginManagement::loadPlugins(const std::vector<std::shared_ptr<PluginData>> &pluginList, MEMHeapHandle heapHandle, relocation_trampoline_entry_t *trampoline_data, uint32_t trampoline_data_length) {
std::vector<std::shared_ptr<PluginContainer>> plugins;
for (auto &pluginData: pluginList) {
@ -206,7 +206,7 @@ PluginManagement::loadPlugins(const std::vector<std::shared_ptr<PluginData>> &pl
}
uint32_t trampolineID = 0;
for (auto &pluginContainer: plugins) {
auto info = PluginInformationFactory::load(pluginContainer->getPluginData(), heapHandle, trampolin_data, trampolin_data_length, trampolineID++);
auto info = PluginInformationFactory::load(pluginContainer->getPluginData(), heapHandle, trampoline_data, trampoline_data_length, trampolineID++);
if (!info) {
DEBUG_FUNCTION_LINE("Failed to load Plugin %s", pluginContainer->getMetaInformation()->getName().c_str());
continue;

View File

@ -6,7 +6,7 @@
class PluginManagement {
public:
static void doRelocations(const std::vector<std::shared_ptr<PluginContainer>> &plugins, relocation_trampolin_entry_t *trampData, uint32_t tramp_size);
static void doRelocations(const std::vector<std::shared_ptr<PluginContainer>> &plugins, relocation_trampoline_entry_t *trampData, uint32_t tramp_size);
static void memsetBSS(const std::vector<std::shared_ptr<PluginContainer>> &plugins);
@ -14,11 +14,12 @@ public:
static void PatchFunctionsAndCallHooks(plugin_information_t *gPluginInformation);
static bool doRelocation(const std::vector<std::shared_ptr<RelocationData>> &relocData, relocation_trampolin_entry_t *tramp_data, uint32_t tramp_length, uint32_t trampolinID);
static bool doRelocation(const std::vector<std::shared_ptr<RelocationData>> &relocData, relocation_trampoline_entry_t *tramp_data, uint32_t tramp_length, uint32_t trampolineID);
static void unloadPlugins(plugin_information_t *pluginInformation, MEMHeapHandle pluginHeap, BOOL freePluginData);
static std::vector<std::shared_ptr<PluginContainer>> loadPlugins(const std::vector<std::shared_ptr<PluginData>> &pluginList, MEMHeapHandle pHeader, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length);
static std::vector<std::shared_ptr<PluginContainer>>
loadPlugins(const std::vector<std::shared_ptr<PluginData>> &pluginList, MEMHeapHandle pHeader, relocation_trampoline_entry_t *trampoline_data, uint32_t trampoline_data_length);
static void RestorePatches(plugin_information_t *pluginInformation, BOOL pluginOnly);
};

View File

@ -78,7 +78,7 @@ struct plugin_info_t {
function_replacement_data_t functions[MAXIMUM_FUNCTION_PER_PLUGIN]{}; // Replacement information for each function.
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{};
uint8_t trampolineId{};
plugin_function_symbol_data_t * function_symbol_data = nullptr;
uint32_t number_function_symbol_data = 0;
void * allocatedTextMemoryAddress = nullptr;

View File

@ -5,7 +5,7 @@ MEMHeapHandle gPluginInformationHeap __attribute__((section(".data"))) = nullptr
plugin_information_t *gPluginInformation __attribute__((section(".data"))) = nullptr;
plugin_information_on_reload_t gLinkOnReload __attribute__((section(".data")));
module_information_t *gModuleData __attribute__((section(".data"))) = nullptr;
relocation_trampolin_entry_t *gTrampolineData __attribute__((section(".data"))) = nullptr;
relocation_trampoline_entry_t *gTrampolineData __attribute__((section(".data"))) = nullptr;
uint32_t gPluginDataHeapSize = 0;
uint32_t gPluginInformationHeapSize = 0;

View File

@ -13,7 +13,7 @@ extern uint32_t gPluginDataHeapSize;
extern uint32_t gPluginInformationHeapSize;
extern plugin_information_on_reload_t gLinkOnReload;
extern module_information_t *gModuleData;
extern relocation_trampolin_entry_t *gTrampolineData;
extern relocation_trampoline_entry_t *gTrampolineData;
extern uint32_t gTrampolineDataSize;
extern StoredBuffer storedTVBuffer;
extern StoredBuffer storedDRCBuffer;

View File

@ -106,14 +106,14 @@ WUMS_APPLICATION_STARTS() {
memset((void *) gPluginInformation, 0, sizeof(plugin_information_t));
}
if (gTrampolineData == nullptr) {
DEBUG_FUNCTION_LINE_VERBOSE("Allocate gTrampolineData on heap %08X (size: %d bytes)", gPluginDataHeap, sizeof(relocation_trampolin_entry_t) * NUMBER_OF_TRAMPS);
gTrampolineData = (relocation_trampolin_entry_t *) MEMAllocFromExpHeapEx(gPluginDataHeap, sizeof(relocation_trampolin_entry_t) * NUMBER_OF_TRAMPS, 4);
DEBUG_FUNCTION_LINE_VERBOSE("Allocate gTrampolineData on heap %08X (size: %d bytes)", gPluginDataHeap, sizeof(relocation_trampoline_entry_t) * NUMBER_OF_TRAMPS);
gTrampolineData = (relocation_trampoline_entry_t *) MEMAllocFromExpHeapEx(gPluginDataHeap, sizeof(relocation_trampoline_entry_t) * NUMBER_OF_TRAMPS, 4);
if (gTrampolineData == nullptr) {
OSFatal("PluginBackend: Failed to allocate gTrampolineData");
return;
}
gTrampolineDataSize = NUMBER_OF_TRAMPS;
memset((void *) gTrampolineData, 0, sizeof(relocation_trampolin_entry_t) * NUMBER_OF_TRAMPS);
memset((void *) gTrampolineData, 0, sizeof(relocation_trampoline_entry_t) * NUMBER_OF_TRAMPS);
}
DEBUG_FUNCTION_LINE("Available memory for storing plugins: %d kb", MEMGetAllocatableSizeForExpHeapEx(gPluginDataHeap, 4) / 1024);
std::vector<std::shared_ptr<PluginData>> pluginList = PluginDataFactory::loadDir("fs:/vol/external01/wiiu/plugins/", gPluginDataHeap);
@ -190,7 +190,7 @@ WUMS_APPLICATION_STARTS() {
if (gPluginDataHeap != nullptr) {
auto plugins = PluginContainerPersistence::loadPlugins(gPluginInformation);
PluginManagement::doRelocations(plugins, gTrampolineData, DYN_LINK_TRAMPOLIN_LIST_LENGTH);
PluginManagement::doRelocations(plugins, gTrampolineData, DYN_LINK_TRAMPOLINE_LIST_LENGTH);
// PluginManagement::memsetBSS(plugins);
DCFlushRange((void *) gPluginDataHeap, gPluginDataHeapSize);

View File

@ -196,7 +196,7 @@ DECL_FUNCTION(uint32_t, KiGetAppSymbolName, uint32_t addr, char *buffer, int32_t
auto symbolData = &plugin->info.function_symbol_data[i];
auto symbolDataNext = &plugin->info.function_symbol_data[i + 1];
if (i == plugin->info.number_function_symbol_data - 2 || (addr >= (uint32_t) symbolData->address && addr < (uint32_t) symbolDataNext->address)) {
if(spaceLeftInBuffer > 2){
if (spaceLeftInBuffer > 2) {
buffer[pluginNameLen] = '|';
buffer[pluginNameLen + 1] = '\0';
strncpy(buffer + pluginNameLen + 1, symbolData->name, spaceLeftInBuffer - 1);
@ -210,6 +210,7 @@ DECL_FUNCTION(uint32_t, KiGetAppSymbolName, uint32_t addr, char *buffer, int32_t
return real_KiGetAppSymbolName(addr, buffer, bufSize);
}
#pragma GCC pop_options
function_replacement_data_t method_hooks_hooks_static[] __attribute__((section(".data"))) = {

View File

@ -10,7 +10,7 @@ dyn_linking_function_t *DynamicLinkingHelper::getOrAddFunctionEntryByName(dyn_li
return nullptr;
}
dyn_linking_function_t *result = nullptr;
for (auto & curEntry : data->functions) {
for (auto &curEntry: data->functions) {
if (strlen(curEntry.functionName) == 0) {
if (strlen(functionName) > DYN_LINK_FUNCTION_NAME_LENGTH) {
DEBUG_FUNCTION_LINE("Failed to add function name, it's too long.");
@ -41,7 +41,7 @@ dyn_linking_import_t *DynamicLinkingHelper::getOrAddImport(dyn_linking_relocatio
return nullptr;
}
dyn_linking_import_t *result = nullptr;
for (auto & curEntry : data->imports) {
for (auto &curEntry: data->imports) {
if (strlen(curEntry.importName) == 0) {
if (strlen(importName) > DYN_LINK_IMPORT_NAME_LENGTH) {
DEBUG_FUNCTION_LINE("Failed to add Import, it's too long.");

View File

@ -47,7 +47,8 @@ public:
**/
static dyn_linking_import_t *getOrAddImport(dyn_linking_relocation_data_t *data, const char *importName, bool isData);
static bool addReloationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, const std::shared_ptr<RelocationData> &relocationData);
static bool addReloationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length,
const std::shared_ptr<RelocationData> &relocationData);
static bool
addReloationEntry(dyn_linking_relocation_data_t *linking_data, dyn_linking_relocation_entry_t *linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend,

View File

@ -18,13 +18,14 @@
#pragma once
#include <string>
#include <utility>
#include "../utils/logger.h"
class ImportRPLInformation {
public:
explicit ImportRPLInformation(std::string name, bool isData = false) {
this->name = name;
this->name = std::move(name);
this->_isData = isData;
}

View File

@ -157,7 +157,7 @@ bool PluginContainerPersistence::savePlugin(plugin_information_t *pluginInformat
return false;
}
}
plugin_data->info.trampolinId = pluginInfo->getTrampolinId();
plugin_data->info.trampolineId = pluginInfo->getTrampolineId();
plugin_data->info.allocatedTextMemoryAddress = pluginInfo->allocatedTextMemoryAddress;
plugin_data->info.allocatedDataMemoryAddress = pluginInfo->allocatedDataMemoryAddress;
@ -253,7 +253,7 @@ std::vector<std::shared_ptr<PluginContainer>> PluginContainerPersistence::loadPl
auto curPluginInformation = std::make_shared<PluginInformation>();
curPluginInformation->setTrampolinId(plugin_data->info.trampolinId);
curPluginInformation->setTrampolineId(plugin_data->info.trampolineId);
curPluginInformation->allocatedTextMemoryAddress = plugin_data->info.allocatedTextMemoryAddress;
curPluginInformation->allocatedDataMemoryAddress = plugin_data->info.allocatedDataMemoryAddress;

View File

@ -43,7 +43,7 @@ public:
void *buffer = nullptr;
MEMHeapHandle heapHandle{};
eMemoryTypes memoryType;
eMemoryTypes memoryType{};
size_t length = 0;
private:

View File

@ -26,7 +26,7 @@
std::vector<std::shared_ptr<PluginData>> PluginDataFactory::loadDir(const std::string &path, MEMHeapHandle heapHandle) {
std::vector<std::shared_ptr<PluginData>> result;
struct dirent *dp;
DIR *dfd = nullptr;
DIR *dfd;
if (path.empty()) {
DEBUG_FUNCTION_LINE("Path was empty");

View File

@ -13,7 +13,7 @@ bool PluginDataPersistence::save(plugin_data_t *pluginDataStruct, const std::sha
return true;
}
bool PluginDataPersistence::save(plugin_data_t *pluginDataStruct, PluginData* plugin) {
bool PluginDataPersistence::save(plugin_data_t *pluginDataStruct, PluginData *plugin) {
if (pluginDataStruct == nullptr) {
return false;
}

View File

@ -6,7 +6,8 @@ class PluginDataPersistence {
public:
static bool save(plugin_data_t *pluginDataStruct, const std::shared_ptr<PluginData> &plugin);
static bool save(plugin_data_t *pluginDataStruct, PluginData* plugin);
static bool save(plugin_data_t *pluginDataStruct, PluginData *plugin);
static std::shared_ptr<PluginData> load(plugin_data_t *pluginDataStruct);
};

View File

@ -14,7 +14,7 @@ PluginInformation::PluginInformation(const PluginInformation &other) {
symbol_data_list.insert(i);
}
section_info_list = other.section_info_list;
trampolinId = other.trampolinId;
trampolineId = other.trampolineId;
allocatedTextMemoryAddress = other.allocatedTextMemoryAddress;
allocatedDataMemoryAddress = other.allocatedDataMemoryAddress;
}

View File

@ -31,9 +31,8 @@
#include "FunctionSymbolData.h"
struct FunctionSymbolDataComparator {
bool operator()(const std::shared_ptr<FunctionSymbolData>& lhs,
const std::shared_ptr<FunctionSymbolData>& rhs) const
{
bool operator()(const std::shared_ptr<FunctionSymbolData> &lhs,
const std::shared_ptr<FunctionSymbolData> &rhs) const {
return (uint32_t) lhs->getAddress() < (uint32_t) rhs->getAddress();
}
};
@ -94,12 +93,12 @@ public:
return std::nullopt;
}
void setTrampolinId(uint8_t _trampolinId) {
this->trampolinId = _trampolinId;
void setTrampolineId(uint8_t _trampolineId) {
this->trampolineId = _trampolineId;
}
[[nodiscard]] uint8_t getTrampolinId() const {
return trampolinId;
[[nodiscard]] uint8_t getTrampolineId() const {
return trampolineId;
}
private:
@ -109,7 +108,7 @@ private:
std::set<std::shared_ptr<FunctionSymbolData>, FunctionSymbolDataComparator> symbol_data_list;
std::map<std::string, std::shared_ptr<SectionInfo>> section_info_list;
uint8_t trampolinId = 0;
uint8_t trampolineId = 0;
void *allocatedTextMemoryAddress = nullptr;
void *allocatedDataMemoryAddress = nullptr;

View File

@ -30,8 +30,8 @@
using namespace ELFIO;
std::optional<std::shared_ptr<PluginInformation>>
PluginInformationFactory::load(const std::shared_ptr<PluginData> &pluginData, MEMHeapHandle heapHandle, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length,
uint8_t trampolinId) {
PluginInformationFactory::load(const std::shared_ptr<PluginData> &pluginData, MEMHeapHandle heapHandle, relocation_trampoline_entry_t *trampoline_data, uint32_t trampoline_data_length,
uint8_t trampolineId) {
if (pluginData->buffer == nullptr) {
DEBUG_FUNCTION_LINE("Buffer was nullptr");
return std::nullopt;
@ -145,7 +145,8 @@ PluginInformationFactory::load(const std::shared_ptr<PluginData> &pluginData, ME
if ((psec->get_type() == SHT_PROGBITS || psec->get_type() == SHT_NOBITS) && (psec->get_flags() & SHF_ALLOC)) {
DEBUG_FUNCTION_LINE_VERBOSE("Linking (%d)... %s at %08X", i, psec->get_name().c_str(), destinations[psec->get_index()]);
if (!linkSection(reader, psec->get_index(), (uint32_t) destinations[psec->get_index()], (uint32_t) text_data, (uint32_t) data_data, trampolin_data, trampolin_data_length, trampolinId)) {
if (!linkSection(reader, psec->get_index(), (uint32_t) destinations[psec->get_index()], (uint32_t) text_data, (uint32_t) data_data, trampoline_data, trampoline_data_length,
trampolineId)) {
DEBUG_FUNCTION_LINE("elfLink failed");
free(destinations);
MEMFreeToExpHeap(heapHandle, text_data);
@ -167,7 +168,7 @@ PluginInformationFactory::load(const std::shared_ptr<PluginData> &pluginData, ME
free(destinations);
pluginInfo->setTrampolinId(trampolinId);
pluginInfo->setTrampolineId(trampolineId);
auto secInfo = pluginInfo->getSectionInfo(".wups.hooks");
if (secInfo && secInfo.value()->getSize() > 0) {
@ -314,9 +315,9 @@ std::vector<std::shared_ptr<RelocationData>> PluginInformationFactory::getImport
return result;
}
bool PluginInformationFactory::linkSection(const elfio &reader, uint32_t section_index, uint32_t destination, uint32_t base_text, uint32_t base_data, relocation_trampolin_entry_t *trampolin_data,
uint32_t trampolin_data_length,
uint8_t trampolinId) {
bool PluginInformationFactory::linkSection(const elfio &reader, uint32_t section_index, uint32_t destination, uint32_t base_text, uint32_t base_data, relocation_trampoline_entry_t *trampoline_data,
uint32_t trampoline_data_length,
uint8_t trampolineId) {
uint32_t sec_num = reader.sections.size();
for (uint32_t i = 0; i < sec_num; ++i) {
@ -372,7 +373,7 @@ bool PluginInformationFactory::linkSection(const elfio &reader, uint32_t section
}
// DEBUG_FUNCTION_LINE_VERBOSE("sym_value %08X adjusted_sym_value %08X offset %08X adjusted_offset %08X", (uint32_t) sym_value, adjusted_sym_value, (uint32_t) offset, adjusted_offset);
if (!ElfUtils::elfLinkOne(type, adjusted_offset, addend, destination, adjusted_sym_value, trampolin_data, trampolin_data_length, RELOC_TYPE_FIXED, trampolinId)) {
if (!ElfUtils::elfLinkOne(type, adjusted_offset, addend, destination, adjusted_sym_value, trampoline_data, trampoline_data_length, RELOC_TYPE_FIXED, trampolineId)) {
DEBUG_FUNCTION_LINE("Link failed");
return false;
}

View File

@ -30,11 +30,12 @@
class PluginInformationFactory {
public:
static std::optional<std::shared_ptr<PluginInformation>>
load(const std::shared_ptr<PluginData> &pluginData, MEMHeapHandle heaphandle, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length, uint8_t trampolinId);
load(const std::shared_ptr<PluginData> &pluginData, MEMHeapHandle heaphandle, relocation_trampoline_entry_t *trampoline_data, uint32_t trampoline_data_length, uint8_t trampolineId);
static bool
linkSection(const elfio &reader, uint32_t section_index, uint32_t destination, uint32_t base_text, uint32_t base_data, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length,
uint8_t trampolinId);
linkSection(const elfio &reader, uint32_t section_index, uint32_t destination, uint32_t base_text, uint32_t base_data, relocation_trampoline_entry_t *trampoline_data,
uint32_t trampoline_data_length,
uint8_t trampolineId);
static std::vector<std::shared_ptr<RelocationData>> getImportRelocationData(const elfio &reader, uint8_t **destinations);
};

View File

@ -146,7 +146,7 @@ void ConfigUtils::displayMenu() {
}
}
if(configs.empty()){
if (configs.empty()) {
return;
}

View File

@ -5,8 +5,8 @@
#include "ElfUtils.h"
// See https://github.com/decaf-emu/decaf-emu/blob/43366a34e7b55ab9d19b2444aeb0ccd46ac77dea/src/libdecaf/src/cafe/loader/cafe_loader_reloc.cpp#L144
bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination, uint32_t symbol_addr, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length,
RelocationType reloc_type, uint8_t trampolinId) {
bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination, uint32_t symbol_addr, relocation_trampoline_entry_t *trampoline_data, uint32_t trampoline_data_length,
RelocationType reloc_type, uint8_t trampolineId) {
if (type == R_PPC_NONE) {
return true;
}
@ -75,44 +75,44 @@ bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t des
// }
auto distance = static_cast<int32_t>(value) - static_cast<int32_t>(target);
if (distance > 0x1FFFFFC || distance < -0x1FFFFFC) {
if (trampolin_data == nullptr) {
DEBUG_FUNCTION_LINE("***24-bit relative branch cannot hit target. Trampolin isn't provided");
if (trampoline_data == nullptr) {
DEBUG_FUNCTION_LINE("***24-bit relative branch cannot hit target. Trampoline isn't provided");
DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X", value, target, distance);
return false;
} else {
relocation_trampolin_entry_t *freeSlot = nullptr;
for (uint32_t i = 0; i < trampolin_data_length; i++) {
relocation_trampoline_entry_t *freeSlot = nullptr;
for (uint32_t i = 0; i < trampoline_data_length; i++) {
// We want to override "old" relocations of imports
// Pending relocations have the status RELOC_TRAMP_IMPORT_IN_PROGRESS.
// When all relocations are done successfully, they will be turned into RELOC_TRAMP_IMPORT_DONE
// so they can be overridden/updated/reused on the next application launch.
//
// Relocations that won't change will have the status RELOC_TRAMP_FIXED and are set to free when the module is unloaded.
if (trampolin_data[i].status == RELOC_TRAMP_FREE ||
trampolin_data[i].status == RELOC_TRAMP_IMPORT_DONE) {
freeSlot = &(trampolin_data[i]);
if (trampoline_data[i].status == RELOC_TRAMP_FREE ||
trampoline_data[i].status == RELOC_TRAMP_IMPORT_DONE) {
freeSlot = &(trampoline_data[i]);
break;
}
}
if (freeSlot == nullptr) {
DEBUG_FUNCTION_LINE("***24-bit relative branch cannot hit target. Trampolin data list is full");
DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X", value, target, target - (uint32_t) &(freeSlot->trampolin[0]));
DEBUG_FUNCTION_LINE("***24-bit relative branch cannot hit target. Trampoline data list is full");
DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X", value, target, target - (uint32_t) &(freeSlot->trampoline[0]));
return false;
}
if (target - (uint32_t) &(freeSlot->trampolin[0]) > 0x1FFFFFC) {
if (target - (uint32_t) &(freeSlot->trampoline[0]) > 0x1FFFFFC) {
DEBUG_FUNCTION_LINE("**Cannot link 24-bit jump (too far to tramp buffer).");
DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X", value, target, (target - (uint32_t) &(freeSlot->trampolin[0])));
DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X", value, target, (target - (uint32_t) &(freeSlot->trampoline[0])));
return false;
}
freeSlot->trampolin[0] = 0x3D600000 | ((((uint32_t) value) >> 16) & 0x0000FFFF); // lis r11, real_addr@h
freeSlot->trampolin[1] = 0x616B0000 | (((uint32_t) value) & 0x0000ffff); // ori r11, r11, real_addr@l
freeSlot->trampolin[2] = 0x7D6903A6; // mtctr r11
freeSlot->trampolin[3] = 0x4E800420; // bctr
DCFlushRange((void *) freeSlot->trampolin, sizeof(freeSlot->trampolin));
ICInvalidateRange((unsigned char *) freeSlot->trampolin, sizeof(freeSlot->trampolin));
freeSlot->trampoline[0] = 0x3D600000 | ((((uint32_t) value) >> 16) & 0x0000FFFF); // lis r11, real_addr@h
freeSlot->trampoline[1] = 0x616B0000 | (((uint32_t) value) & 0x0000ffff); // ori r11, r11, real_addr@l
freeSlot->trampoline[2] = 0x7D6903A6; // mtctr r11
freeSlot->trampoline[3] = 0x4E800420; // bctr
DCFlushRange((void *) freeSlot->trampoline, sizeof(freeSlot->trampoline));
ICInvalidateRange((unsigned char *) freeSlot->trampoline, sizeof(freeSlot->trampoline));
freeSlot->id = trampolinId;
freeSlot->id = trampolineId;
DCFlushRange((void *) &freeSlot->id, sizeof(freeSlot->id));
ICInvalidateRange((unsigned char *) &freeSlot->id, sizeof(freeSlot->id));
@ -122,7 +122,7 @@ bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t des
// Relocations for the imports may be overridden
freeSlot->status = RELOC_TRAMP_IMPORT_DONE;
}
uint32_t symbolValue = (uint32_t) &(freeSlot->trampolin[0]);
auto symbolValue = (uint32_t) &(freeSlot->trampoline[0]);
value = symbolValue + addend;
distance = static_cast<int32_t>(value) - static_cast<int32_t>(target);
}

View File

@ -46,6 +46,6 @@ uint32_t load_loader_elf(unsigned char *baseAddress, char *elf_data, uint32_t fi
class ElfUtils {
public:
static bool elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination, uint32_t symbol_addr, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length,
RelocationType reloc_type, uint8_t trampolinId);
static bool elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination, uint32_t symbol_addr, relocation_trampoline_entry_t *trampoline_data, uint32_t trampoline_data_length,
RelocationType reloc_type, uint8_t trampolineId);
};

View File

@ -9,7 +9,7 @@
#include "exports.h"
#include <wums.h>
void fillPluginInformation(plugin_information *out, const std::shared_ptr<PluginMetaInformation>& metaInformation) {
void fillPluginInformation(plugin_information *out, const std::shared_ptr<PluginMetaInformation> &metaInformation) {
out->plugin_information_version = PLUGIN_INFORMATION_VERSION;
strncpy(out->author, metaInformation->getAuthor().c_str(), sizeof(out->author) - 1);
strncpy(out->buildTimestamp, metaInformation->getBuildTimestamp().c_str(), sizeof(out->buildTimestamp) - 1);

File diff suppressed because it is too large Load Diff