Skip to content

Commit

Permalink
Only check heap in debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Maschell committed Apr 28, 2024
1 parent 4774694 commit 488fbc0
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions wumsloader/src/utils/hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
#include "globals.h"
#include "module/ModuleData.h"
#include "utils/logger.h"
#include <coreinit/memexpheap.h>
#include <memory>
#include <wums.h>

#ifdef DEBUG
static const char **hook_names = (const char *[]){
"WUMS_HOOK_INIT_WUT_MALLOC",
"WUMS_HOOK_FINI_WUT_MALLOC",
Expand All @@ -26,6 +28,7 @@ static const char **hook_names = (const char *[]){
"WUMS_HOOK_RELOCATIONS_DONE",
"WUMS_HOOK_APPLICATION_REQUESTS_EXIT",
"WUMS_HOOK_DEINIT"};
#endif

void CallHook(const std::vector<std::shared_ptr<ModuleData>> &modules, wums_hook_type_t type, bool condition) {
if (condition) {
Expand All @@ -46,8 +49,6 @@ void CallHook(const std::shared_ptr<ModuleData> &module, wums_hook_type_t type,
}
}

extern "C" bool MEMCheckExpHeap(void *heap, bool logProblems);

void CallHook(const std::shared_ptr<ModuleData> &module, wums_hook_type_t type) {
bool foundHook = false;
for (auto &curHook : module->getHookDataList()) {
Expand Down Expand Up @@ -92,11 +93,10 @@ void CallHook(const std::shared_ptr<ModuleData> &module, wums_hook_type_t type)
break;
}
}

if (foundHook && !MEMCheckExpHeap(MEMGetBaseHeapHandle(MEM_BASE_HEAP_MEM2), true)) {
DEBUG_FUNCTION_LINE_ERR("MEM2 default heap is corrupted while calling hook %s for module %s", hook_names[type], module->getExportName().c_str());
#ifdef DEBUG
if (foundHook && !MEMCheckExpHeap(MEMGetBaseHeapHandle(MEM_BASE_HEAP_MEM2), MEM_EXP_HEAP_CHECK_FLAGS_LOG_ERRORS)) {
DEBUG_FUNCTION_LINE_ERR("MEM2 default heap is corrupted while calling hook %s for module %s", hook_names[type], module->getExportName().c_str());
OSFatal("WUMSLoader: MEM2 default heap is corrupted. \n Please restart the console.");
#endif
}
#endif
}

0 comments on commit 488fbc0

Please sign in to comment.