mirror of
https://github.com/wiiu-env/FunctionPatcherModule.git
synced 2026-03-21 17:44:19 -05:00
Use std::recursive vs std::mutex
This commit is contained in:
parent
c083708f1a
commit
67a527010d
|
|
@ -2,8 +2,11 @@
|
|||
#include "PatchedFunctionData.h"
|
||||
#include "function_patcher.h"
|
||||
#include "utils/globals.h"
|
||||
|
||||
#include <mutex>
|
||||
#include <ranges>
|
||||
#include <vector>
|
||||
|
||||
#include <wums/exports.h>
|
||||
|
||||
WUT_CHECK_OFFSET(function_replacement_data_v2_t, 0x00, VERSION);
|
||||
|
|
@ -50,7 +53,7 @@ FunctionPatcherStatus FPAddFunctionPatch(function_replacement_data_t *function_d
|
|||
}
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(gPatchedFunctionsMutex);
|
||||
std::lock_guard lock(gPatchedFunctionsMutex);
|
||||
gPatchedFunctions.push_back(std::move(functionData));
|
||||
|
||||
OSMemoryBarrier();
|
||||
|
|
@ -64,7 +67,7 @@ bool FunctionPatcherPatchFunction(function_replacement_data_t *function_data, Pa
|
|||
}
|
||||
|
||||
FunctionPatcherStatus FPRemoveFunctionPatch(PatchedFunctionHandle handle) {
|
||||
std::lock_guard<std::mutex> lock(gPatchedFunctionsMutex);
|
||||
std::lock_guard lock(gPatchedFunctionsMutex);
|
||||
std::vector<std::shared_ptr<PatchedFunctionData>> toBeTempRestored;
|
||||
bool found = false;
|
||||
int32_t erasePosition = 0;
|
||||
|
|
@ -132,7 +135,7 @@ FunctionPatcherStatus FPIsFunctionPatched(PatchedFunctionHandle handle, bool *ou
|
|||
if (outIsFunctionPatched == nullptr) {
|
||||
return FUNCTION_PATCHER_RESULT_INVALID_ARGUMENT;
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(gPatchedFunctionsMutex);
|
||||
std::lock_guard lock(gPatchedFunctionsMutex);
|
||||
for (auto &cur : gPatchedFunctions) {
|
||||
if (cur->getHandle() == handle) {
|
||||
*outIsFunctionPatched = cur->isPatched;
|
||||
|
|
|
|||
|
|
@ -4,11 +4,15 @@
|
|||
#include "utils/CThread.h"
|
||||
#include "utils/logger.h"
|
||||
#include "utils/utils.h"
|
||||
|
||||
#include <coreinit/cache.h>
|
||||
#include <coreinit/debug.h>
|
||||
#include <coreinit/memorymap.h>
|
||||
|
||||
#include <kernel/kernel.h>
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
static void writeDataAndFlushIC(CThread *thread, void *arg) {
|
||||
auto *data = (PatchedFunctionData *) arg;
|
||||
|
|
|
|||
|
|
@ -4,9 +4,11 @@
|
|||
#include "utils/globals.h"
|
||||
#include "utils/logger.h"
|
||||
#include "utils/utils.h"
|
||||
|
||||
#include <coreinit/memdefaultheap.h>
|
||||
#include <coreinit/memexpheap.h>
|
||||
#include <kernel/kernel.h>
|
||||
#include <mutex>
|
||||
#include <ranges>
|
||||
#include <set>
|
||||
#include <wums.h>
|
||||
|
|
@ -41,7 +43,7 @@ void UpdateFunctionPointer() {
|
|||
}
|
||||
|
||||
void CheckIfPatchedFunctionsAreStillInMemory() {
|
||||
std::lock_guard<std::mutex> lock(gPatchedFunctionsMutex);
|
||||
std::lock_guard lock(gPatchedFunctionsMutex);
|
||||
// Check if rpl has been unloaded by comparing the instruction.
|
||||
std::set<uint32_t> physicalAddressesUnchanged;
|
||||
std::set<uint32_t> physicalAddressesChanged;
|
||||
|
|
@ -129,12 +131,12 @@ void notify_callback(OSDynLoad_Module module,
|
|||
OSDynLoad_NotifyReason reason,
|
||||
OSDynLoad_NotifyData *infos) {
|
||||
if (reason == OS_DYNLOAD_NOTIFY_LOADED) {
|
||||
std::lock_guard<std::mutex> lock(gPatchedFunctionsMutex);
|
||||
std::lock_guard lock(gPatchedFunctionsMutex);
|
||||
for (auto &cur : gPatchedFunctions) {
|
||||
PatchFunction(cur);
|
||||
}
|
||||
} else if (reason == OS_DYNLOAD_NOTIFY_UNLOADED) {
|
||||
std::lock_guard<std::mutex> lock(gPatchedFunctionsMutex);
|
||||
std::lock_guard lock(gPatchedFunctionsMutex);
|
||||
auto library = gFunctionAddressProvider->getTypeForHandle(module);
|
||||
if (library != LIBRARY_OTHER) {
|
||||
for (auto &cur : gPatchedFunctions) {
|
||||
|
|
@ -162,7 +164,7 @@ WUMS_APPLICATION_STARTS() {
|
|||
|
||||
initLogging();
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(gPatchedFunctionsMutex);
|
||||
std::lock_guard lock(gPatchedFunctionsMutex);
|
||||
// reset function patch status if the rpl they were patching has been unloaded from memory.
|
||||
CheckIfPatchedFunctionsAreStillInMemory();
|
||||
DEBUG_FUNCTION_LINE_VERBOSE("Patch all functions");
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ char gJumpHeapData[JUMP_HEAP_DATA_SIZE] __attribute__((section(".data")));
|
|||
MEMHeapHandle gJumpHeapHandle __attribute__((section(".data")));
|
||||
|
||||
std::shared_ptr<FunctionAddressProvider> gFunctionAddressProvider;
|
||||
std::mutex gPatchedFunctionsMutex;
|
||||
std::recursive_mutex gPatchedFunctionsMutex;
|
||||
std::vector<std::shared_ptr<PatchedFunctionData>> gPatchedFunctions;
|
||||
|
||||
void *(*gMEMAllocFromDefaultHeapExForThreads)(uint32_t size, int align);
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
#include "version.h"
|
||||
#include <coreinit/memheap.h>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
|
||||
#define MODULE_VERSION "v0.2.3"
|
||||
|
|
@ -13,7 +14,7 @@ extern char gJumpHeapData[];
|
|||
extern MEMHeapHandle gJumpHeapHandle;
|
||||
|
||||
extern std::shared_ptr<FunctionAddressProvider> gFunctionAddressProvider;
|
||||
extern std::mutex gPatchedFunctionsMutex;
|
||||
extern std::recursive_mutex gPatchedFunctionsMutex;
|
||||
extern std::vector<std::shared_ptr<PatchedFunctionData>> gPatchedFunctions;
|
||||
|
||||
extern void *(*gMEMAllocFromDefaultHeapExForThreads)(uint32_t size, int align);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user