mirror of
https://github.com/wiiu-env/WUMSLoader.git
synced 2025-01-13 16:59:10 +01:00
Set a custom OSDynLoad Allocator when processing relocations
This commit is contained in:
parent
28cefca560
commit
6555a8138f
@ -1,13 +1,42 @@
|
|||||||
#include "RelocationUtils.h"
|
#include "RelocationUtils.h"
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
|
#include "malloc.h"
|
||||||
#include "utils/ElfUtils.h"
|
#include "utils/ElfUtils.h"
|
||||||
#include "utils/memory.h"
|
#include "utils/memory.h"
|
||||||
#include <coreinit/cache.h>
|
#include <coreinit/cache.h>
|
||||||
#include <coreinit/dynload.h>
|
#include <coreinit/dynload.h>
|
||||||
|
|
||||||
|
static OSDynLoad_Error CustomDynLoadAlloc(int32_t size, int32_t align, void **outAddr) {
|
||||||
|
if (!outAddr) {
|
||||||
|
return OS_DYNLOAD_INVALID_ALLOCATOR_PTR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (align >= 0 && align < 4) {
|
||||||
|
align = 4;
|
||||||
|
} else if (align < 0 && align > -4) {
|
||||||
|
align = -4;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(*outAddr = memalign(align, size))) {
|
||||||
|
return OS_DYNLOAD_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
return OS_DYNLOAD_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void CustomDynLoadFree(void *addr) {
|
||||||
|
free(addr);
|
||||||
|
}
|
||||||
|
|
||||||
bool ResolveRelocations(std::vector<std::shared_ptr<ModuleData>> &loadedModules, bool skipMemoryMappingModule) {
|
bool ResolveRelocations(std::vector<std::shared_ptr<ModuleData>> &loadedModules, bool skipMemoryMappingModule) {
|
||||||
bool wasSuccessful = true;
|
bool wasSuccessful = true;
|
||||||
|
|
||||||
|
OSDynLoadAllocFn prevDynLoadAlloc = nullptr;
|
||||||
|
OSDynLoadFreeFn prevDynLoadFree = nullptr;
|
||||||
|
|
||||||
|
OSDynLoad_GetAllocator(&prevDynLoadAlloc, &prevDynLoadFree);
|
||||||
|
OSDynLoad_SetAllocator(CustomDynLoadAlloc, CustomDynLoadFree);
|
||||||
|
|
||||||
for (auto &curModule : loadedModules) {
|
for (auto &curModule : loadedModules) {
|
||||||
DEBUG_FUNCTION_LINE("Let's do the relocations for %s", curModule->getExportName().c_str());
|
DEBUG_FUNCTION_LINE("Let's do the relocations for %s", curModule->getExportName().c_str());
|
||||||
|
|
||||||
@ -25,6 +54,8 @@ bool ResolveRelocations(std::vector<std::shared_ptr<ModuleData>> &loadedModules,
|
|||||||
OSFatal("Failed to do Reloations");
|
OSFatal("Failed to do Reloations");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
OSDynLoad_SetAllocator(prevDynLoadAlloc, prevDynLoadFree);
|
||||||
|
|
||||||
DCFlushRange((void *) MEMORY_REGION_START, MEMORY_REGION_SIZE);
|
DCFlushRange((void *) MEMORY_REGION_START, MEMORY_REGION_SIZE);
|
||||||
ICInvalidateRange((void *) MEMORY_REGION_START, MEMORY_REGION_SIZE);
|
ICInvalidateRange((void *) MEMORY_REGION_START, MEMORY_REGION_SIZE);
|
||||||
return wasSuccessful;
|
return wasSuccessful;
|
||||||
|
@ -34,6 +34,8 @@ IMPORT(OSSignalCond);
|
|||||||
IMPORT(MEMAllocFromDefaultHeapEx);
|
IMPORT(MEMAllocFromDefaultHeapEx);
|
||||||
IMPORT(MEMFreeToDefaultHeap);
|
IMPORT(MEMFreeToDefaultHeap);
|
||||||
IMPORT(OSSwapAtomic);
|
IMPORT(OSSwapAtomic);
|
||||||
|
IMPORT(OSDynLoad_GetAllocator);
|
||||||
|
IMPORT(OSDynLoad_SetAllocator);
|
||||||
|
|
||||||
IMPORT(FSTimeToCalendarTime);
|
IMPORT(FSTimeToCalendarTime);
|
||||||
IMPORT(FSInit);
|
IMPORT(FSInit);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user