Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only check heap in debug mode #46

Merged
merged 1 commit into from
Apr 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}