From b2e72be198aff455ba43ad4b8e1227a0ef901e4c Mon Sep 17 00:00:00 2001 From: Maschell Date: Mon, 4 May 2026 18:57:49 +0200 Subject: [PATCH] Patch functions while holding the lock --- source/export.cpp | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/source/export.cpp b/source/export.cpp index b6d15b6..f3c148b 100644 --- a/source/export.cpp +++ b/source/export.cpp @@ -38,22 +38,21 @@ FunctionPatcherStatus FPAddFunctionPatch(function_replacement_data_t *function_d return FUNCTION_PATCHER_RESULT_UNKNOWN_ERROR; } - auto &functionData = functionDataOpt.value(); - - // PatchFunction calls OSFatal on fatal errors. - // If this function returns false the target function was not patched - // Usually this means the target RPL is not (yet) loaded. - auto patchResult = PatchFunction(functionData); - if (outHasBeenPatched) { - *outHasBeenPatched = patchResult; - } - - if (outHandle) { - *outHandle = functionData->getHandle(); - } - { std::lock_guard lock(gPatchedFunctionsMutex); + auto &functionData = functionDataOpt.value(); + // PatchFunction calls OSFatal on fatal errors. + // If this function returns false the target function was not patched + // Usually this means the target RPL is not (yet) loaded. + auto patchResult = PatchFunction(functionData); + if (outHasBeenPatched) { + *outHasBeenPatched = patchResult; + } + + if (outHandle) { + *outHandle = functionData->getHandle(); + } + gPatchedFunctions.push_back(std::move(functionData)); OSMemoryBarrier();