Only use OSDynload_Acquire if really needed

This commit is contained in:
Maschell 2020-12-26 13:22:12 +01:00
parent 42d73fa539
commit 6e352b0085
2 changed files with 9 additions and 2 deletions

View File

@ -59,7 +59,10 @@ bool doRelocation(std::vector<RelocationData> &relocData, relocation_trampolin_e
int32_t isData = curReloc.getImportRPLInformation().isData(); int32_t isData = curReloc.getImportRPLInformation().isData();
OSDynLoad_Module rplHandle = 0; OSDynLoad_Module rplHandle = 0;
if (moduleCache.count(rplName) == 0) { if (moduleCache.count(rplName) == 0) {
OSDynLoad_Acquire(rplName.c_str(), &rplHandle); if(OSDynLoad_IsModuleLoaded(rplName.c_str(), &rplHandle) != OS_DYNLOAD_OK) {
// only acquire if not already loaded.
OSDynLoad_Acquire(rplName.c_str(), &rplHandle);
}
moduleCache[rplName] = rplHandle; moduleCache[rplName] = rplHandle;
} }
rplHandle = moduleCache.at(rplName); rplHandle = moduleCache.at(rplName);

View File

@ -46,7 +46,11 @@ bool doRelocation(std::vector<RelocationData> &relocData, relocation_trampolin_e
std::string rplName = curReloc.getImportRPLInformation().getName(); std::string rplName = curReloc.getImportRPLInformation().getName();
int32_t isData = curReloc.getImportRPLInformation().isData(); int32_t isData = curReloc.getImportRPLInformation().isData();
OSDynLoad_Module rplHandle = nullptr; OSDynLoad_Module rplHandle = nullptr;
OSDynLoad_Acquire(rplName.c_str(), &rplHandle);
if(OSDynLoad_IsModuleLoaded(rplName.c_str(), &rplHandle) != OS_DYNLOAD_OK) {
// only acquire if not already loaded.
OSDynLoad_Acquire(rplName.c_str(), &rplHandle);
}
uint32_t functionAddress = 0; uint32_t functionAddress = 0;
OSDynLoad_FindExport(rplHandle, isData, functionName.c_str(), (void **) &functionAddress); OSDynLoad_FindExport(rplHandle, isData, functionName.c_str(), (void **) &functionAddress);