From 42d73fa539248ea3fb3c3123a8f23f14f067055b Mon Sep 17 00:00:00 2001 From: Maschell Date: Sat, 26 Dec 2020 13:18:47 +0100 Subject: [PATCH] relocator: UseOSDynLoad_IsModuleLoaded instead of OSDynLoad_Acquire --- relocator/src/utils/dynamic.c | 11 ++++++----- relocator/src/utils/imports.h | 1 + 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/relocator/src/utils/dynamic.c b/relocator/src/utils/dynamic.c index 45f5b07..a770105 100644 --- a/relocator/src/utils/dynamic.c +++ b/relocator/src/utils/dynamic.c @@ -12,8 +12,7 @@ #undef IMPORT_END #define IMPORT(name) do{if(OSDynLoad_FindExport(handle, 0, #name, &addr_##name) < 0)OSFatal("Function " # name " is NULL");} while(0) -#define IMPORT_BEGIN(lib) OSDynLoad_Acquire(#lib ".rpl", &handle) -/* #define IMPORT_END() OSDynLoad_Release(handle) */ +#define IMPORT_BEGIN(lib) do{if(OSDynLoad_IsModuleLoaded(#lib ".rpl", &handle) != OS_DYNLOAD_OK) OSFatal(#lib ".rpl is not loaded");} while(0) #define IMPORT_END() #define EXPORT_VAR(type, var) type var __attribute__((section(".data"))); @@ -24,13 +23,15 @@ EXPORT_VAR(uint32_t *, pMEMFreeToDefaultHeap); void InitFunctionPointers(void) { OSDynLoad_Module handle; - addr_OSDynLoad_Acquire = (void *) 0x0102A3B4; - addr_OSDynLoad_FindExport = (void *) 0x0102B828; + addr_OSDynLoad_Acquire = (void *) 0x0102A3B4; // 0x0200dfb4 - 0xFE3C00 + addr_OSDynLoad_FindExport = (void *) 0x0102B828; // 0200f428 - 0xFE3C00 + addr_OSDynLoad_IsModuleLoaded = (void *) 0x0102A59C; // 0200e19c - 0xFE3C00 - OSDynLoad_Acquire("coreinit.rpl", &handle); + IMPORT_BEGIN(coreinit); OSDynLoad_FindExport(handle, 1, "MEMAllocFromDefaultHeapEx", (void **) &pMEMAllocFromDefaultHeapEx); OSDynLoad_FindExport(handle, 1, "MEMAllocFromDefaultHeap", (void **) &pMEMAllocFromDefaultHeap); OSDynLoad_FindExport(handle, 1, "MEMFreeToDefaultHeap", (void **) &pMEMFreeToDefaultHeap); + IMPORT_END() #include "imports.h" diff --git a/relocator/src/utils/imports.h b/relocator/src/utils/imports.h index 87d1d73..1563cf7 100644 --- a/relocator/src/utils/imports.h +++ b/relocator/src/utils/imports.h @@ -3,6 +3,7 @@ IMPORT_BEGIN(coreinit); IMPORT(OSDynLoad_Acquire); IMPORT(OSDynLoad_FindExport); +IMPORT(OSDynLoad_IsModuleLoaded); IMPORT(DCFlushRange); IMPORT(ICInvalidateRange); IMPORT(OSGetSystemInfo);