From 74f3c8a599318623a59c7da52ec978443054b169 Mon Sep 17 00:00:00 2001 From: Maschell Date: Tue, 20 Jan 2026 17:56:27 +0100 Subject: [PATCH] Fix compiling with latest/upcoming devkitppc/wut version --- .gitignore | 1 + Makefile | 2 +- source/crt.c | 7 ++----- wumsloader/Makefile | 4 +++- wumsloader/src/crt.c | 7 ++----- wumsloader/src/entry.cpp | 22 ++++++++++----------- wumsloader/src/module/ModuleDataFactory.cpp | 10 +++++----- wumsloader/src/utils/hooks.cpp | 16 ++++++++++----- wumsloader/src/utils/imports.h | 12 +++++++++++ 9 files changed, 47 insertions(+), 34 deletions(-) diff --git a/.gitignore b/.gitignore index 698dbae..5904512 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ cmake-build-debug/ *.txt build1/ cmake-build-default/ +*.zip diff --git a/Makefile b/Makefile index 06cf9ac..332d672 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,7 @@ INCLUDES := source #------------------------------------------------------------------------------- # options for code generation #------------------------------------------------------------------------------- -CFLAGS := -Wall -Os -ffunction-sections \ +CFLAGS := -Wall -Werror -Os -ffunction-sections \ $(MACHDEP) CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__ diff --git a/source/crt.c b/source/crt.c index 2fcd925..ae76143 100644 --- a/source/crt.c +++ b/source/crt.c @@ -2,7 +2,7 @@ void __init_wut_malloc(); void __init_wut_newlib(); -void __init_wut_stdcpp(); +void __init_wut_thread(); void __init_wut_devoptab(); @@ -12,17 +12,15 @@ void __fini_wut_malloc(); void __fini_wut_newlib(); -void __fini_wut_stdcpp(); - void __fini_wut_devoptab(); void __attribute__((weak)) __fini_wut_socket(); void __attribute__((weak)) __init_wut_() { + __init_wut_thread(); __init_wut_malloc(); __init_wut_newlib(); - __init_wut_stdcpp(); __init_wut_devoptab(); if (&__init_wut_socket) __init_wut_socket(); } @@ -30,7 +28,6 @@ __init_wut_() { void __attribute__((weak)) __fini_wut_() { __fini_wut_devoptab(); - __fini_wut_stdcpp(); __fini_wut_newlib(); __fini_wut_malloc(); } diff --git a/wumsloader/Makefile b/wumsloader/Makefile index 3617d8b..2001dc7 100644 --- a/wumsloader/Makefile +++ b/wumsloader/Makefile @@ -47,7 +47,7 @@ INCLUDES := src #--------------------------------------------------------------------------------- # options for code generation #--------------------------------------------------------------------------------- -CFLAGS := -g -Wall -O2 -ffunction-sections $(MACHDEP) $(INCLUDE) -D__WIIU__ -D__WUT__ +CFLAGS := -g -Wall -Werror -O2 -ffunction-sections $(MACHDEP) $(INCLUDE) -D__WIIU__ -D__WUT__ CXXFLAGS := $(CFLAGS) -std=c++20 -fno-exceptions -fno-rtti ASFLAGS := -mregnames LDFLAGS := -Wl,--gc-sections,--allow-multiple-definition @@ -125,6 +125,8 @@ export OUTPUT := $(CURDIR)/$(TARGET) .PHONY: $(BUILD) clean install #--------------------------------------------------------------------------------- +all: $(BUILD) + $(BUILD): @$(shell [ ! -d $(BUILD) ] && mkdir -p $(BUILD)) @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile diff --git a/wumsloader/src/crt.c b/wumsloader/src/crt.c index 61717a5..c281f5c 100644 --- a/wumsloader/src/crt.c +++ b/wumsloader/src/crt.c @@ -5,7 +5,7 @@ void __init_wut_malloc(); void __init_wut_newlib(); -void __init_wut_stdcpp(); +void __init_wut_thread(); void __init_wut_devoptab(); @@ -15,17 +15,15 @@ void __fini_wut_malloc(); void __fini_wut_newlib(); -void __fini_wut_stdcpp(); - void __fini_wut_devoptab(); void __attribute__((weak)) __fini_wut_socket(); void __attribute__((weak)) init_wut() { + __init_wut_thread(); __init_wut_malloc(); __init_wut_newlib(); - __init_wut_stdcpp(); __init_wut_devoptab(); if (&__init_wut_socket) __init_wut_socket(); } @@ -33,7 +31,6 @@ init_wut() { void __attribute__((weak)) fini_wut() { __fini_wut_devoptab(); - __fini_wut_stdcpp(); __fini_wut_newlib(); __fini_wut_malloc(); } diff --git a/wumsloader/src/entry.cpp b/wumsloader/src/entry.cpp index 4543a59..33f6e37 100644 --- a/wumsloader/src/entry.cpp +++ b/wumsloader/src/entry.cpp @@ -16,7 +16,7 @@ #include #include -#define VERSION "v0.2.8" +#define VERSION "v0.2.9" void CallInitHooksForModule(const std::shared_ptr &curModule); @@ -86,7 +86,7 @@ void doStart(int argc, char **argv) { * Bit 13 - OS relaunch (OSForceFullRelaunch()). See more https://wiiubrew.org/wiki/Boot1#PowerFlags */ if ((bootFlags & 0x00002000) != 0 && argc == WUMS_LOADER_SETUP_MAGIC_WORD) { - OSReport("OSForceFullRelaunch detected, skipping WUMS\n", bootFlags); + OSReport("OSForceFullRelaunch detected, skipping WUMS\n"); return; } init_wut(); @@ -98,7 +98,7 @@ void doStart(int argc, char **argv) { // If an allocated rpl was not released properly (e.g. if something else calls OSDynload_Acquire without releasing it) // memory gets leaked. Let's clean this up! for (auto &addr : gAllocatedAddresses) { - DEBUG_FUNCTION_LINE_WARN("Memory allocated by OSDynload was not freed properly, let's clean it up! (%08X)", addr); + DEBUG_FUNCTION_LINE_WARN("Memory allocated by OSDynload was not freed properly, let's clean it up! (%p)", addr); free((void *) addr); } gAllocatedAddresses.clear(); @@ -121,8 +121,7 @@ void doStart(int argc, char **argv) { continue; } DEBUG_FUNCTION_LINE("Loading module %s", modules.GetFilepath(i)); - auto moduleData = ModuleDataFactory::load(modules.GetFilepath(i)); - if (moduleData) { + if (auto moduleData = ModuleDataFactory::load(modules.GetFilepath(i))) { DEBUG_FUNCTION_LINE("Successfully loaded %s", modules.GetFilepath(i)); gLoadedModules.push_back(std::move(moduleData.value())); } else { @@ -138,9 +137,8 @@ void doStart(int argc, char **argv) { { // make sure the plugin backend module is at the end. - auto it = std::find_if(gLoadedModules.begin(), - gLoadedModules.end(), - [](auto &cur) { return std::string_view(cur->getExportName()) == "homebrew_wupsbackend"; }); + const auto it = std::ranges::find_if(gLoadedModules, + [](auto &cur) { return std::string_view(cur->getExportName()) == "homebrew_wupsbackend"; }); if (it != gLoadedModules.end()) { auto module = *it; gLoadedModules.erase(it); @@ -180,9 +178,8 @@ void doStart(int argc, char **argv) { } // move homebrew_basemodule to the front - auto it = std::find_if(gLoadedModulesCopy.begin(), - gLoadedModulesCopy.end(), - [](auto &cur) { return std::string_view(cur->getExportName()) == "homebrew_basemodule"; }); + const auto it = std::ranges::find_if(gLoadedModulesCopy, + [](auto &cur) { return std::string_view(cur->getExportName()) == "homebrew_basemodule"; }); if (it != gLoadedModulesCopy.end()) { auto module = *it; gLoadedModulesCopy.erase(it); @@ -251,6 +248,7 @@ void doStart(int argc, char **argv) { } void CallInitHooksForModule(const std::shared_ptr &curModule) { + CallHook(curModule, WUMS_HOOK_INIT_WUT_THREAD); CallHook(curModule, WUMS_HOOK_INIT_WUT_MALLOC); CallHook(curModule, WUMS_HOOK_INIT_WUT_NEWLIB); CallHook(curModule, WUMS_HOOK_INIT_WUT_STDCPP); @@ -308,7 +306,7 @@ std::vector> OrderModulesByDependencies(const std::v OSFatal("Error: module depends on homebrew_wupsbackend, this is not supported"); } if (!loadedModulesExportNames.contains(curImportRPL)) { - DEBUG_FUNCTION_LINE_VERBOSE("We can't load the module, because %s is not loaded yet", curImportRPL.begin()); + DEBUG_FUNCTION_LINE_VERBOSE("We can't load the module, because %s is not loaded yet", curImportRPL.c_str()); canLoad = false; break; } diff --git a/wumsloader/src/module/ModuleDataFactory.cpp b/wumsloader/src/module/ModuleDataFactory.cpp index fe0569e..0f21442 100644 --- a/wumsloader/src/module/ModuleDataFactory.cpp +++ b/wumsloader/src/module/ModuleDataFactory.cpp @@ -95,7 +95,7 @@ std::optional> ModuleDataFactory::load(const std::st } } else if (key == "wums" || key == "wum") { checkedVersion = true; - if (value != "0.3.1" && value != "0.3.2" && value != "0.3.3" && value != "0.3.4") { + if (value != "0.3.1" && value != "0.3.2" && value != "0.3.3" && value != "0.3.4" && value != "0.3.5") { DEBUG_FUNCTION_LINE_WARN("Ignoring module - Unsupported WUMS version: %s.", value.c_str()); return std::nullopt; } @@ -198,7 +198,7 @@ std::optional> ModuleDataFactory::load(const std::st DEBUG_FUNCTION_LINE("memset section %s %08X to 0 (%d bytes)", psec->get_name().c_str(), destination, sectionSize); memset((void *) destination, 0, sectionSize); } else if (psec->get_type() == SHT_PROGBITS) { - DEBUG_FUNCTION_LINE("Copy section %s %08X -> %08X (%d bytes)", psec->get_name().c_str(), p, destination, sectionSize); + DEBUG_FUNCTION_LINE("Copy section %s %p -> %08X (%d bytes)", psec->get_name().c_str(), p, destination, sectionSize); memcpy((void *) destination, p, sectionSize); } @@ -242,7 +242,7 @@ std::optional> ModuleDataFactory::load(const std::st if (entries != nullptr) { for (size_t j = 0; j < entries_count; j++) { wums_entry_t *exp = &entries[j]; - DEBUG_FUNCTION_LINE("Saving export of type %08X, name %s, target: %08X", exp->type, exp->name, exp->address); + DEBUG_FUNCTION_LINE("Saving export of type %d, name %s, target: %p", exp->type, exp->name, exp->address); auto exportData = make_unique_nothrow(exp->type, exp->name, exp->address); if (!exportData) { DEBUG_FUNCTION_LINE_ERR("Failed to alloc ExportData"); @@ -275,7 +275,7 @@ std::optional> ModuleDataFactory::load(const std::st if (hooks != nullptr) { for (size_t j = 0; j < entries_count; j++) { wums_hook_t *hook = &hooks[j]; - DEBUG_FUNCTION_LINE("Saving hook of type %08X, target: %08X", hook->type, hook->target); + DEBUG_FUNCTION_LINE("Saving hook of type %08X, target: %p", hook->type, hook->target); auto hookData = make_unique_nothrow(hook->type, hook->target); if (!hookData) { DEBUG_FUNCTION_LINE_ERR("Failed to alloc HookData"); @@ -403,7 +403,7 @@ bool ModuleDataFactory::getImportRelocationData(std::shared_ptr &mod uint32_t section_index = psec->get_info(); if (!infoMap.contains(sym_section_index)) { - DEBUG_FUNCTION_LINE_ERR("Relocation is referencing a unknown section. %d destination: %08X sym_name %s", section_index, destinations[section_index], sym_name.c_str()); + DEBUG_FUNCTION_LINE_ERR("Relocation is referencing a unknown section. %d destination: %p sym_name %s", section_index, destinations[section_index], sym_name.c_str()); OSFatal("Relocation is referencing a unknown section."); } diff --git a/wumsloader/src/utils/hooks.cpp b/wumsloader/src/utils/hooks.cpp index d553d10..246dda3 100644 --- a/wumsloader/src/utils/hooks.cpp +++ b/wumsloader/src/utils/hooks.cpp @@ -36,7 +36,8 @@ static const char **hook_names = (const char *[]){ "WUMS_HOOK_GET_CUSTOM_RPL_ALLOCATOR", "WUMS_HOOK_CLEAR_ALLOCATED_RPL_MEMORY", -}; + "WUMS_HOOK_CLEAR_ALLOCATED_RPL_MEMORY", + "WUMS_HOOK_INIT_WUT_THREAD"}; #endif void CallHook(const std::vector> &modules, wums_hook_type_t type, bool condition) { @@ -59,7 +60,9 @@ void CallHook(const std::shared_ptr &module, wums_hook_type_t type, } void CallHook(const std::shared_ptr &module, wums_hook_type_t type) { +#ifdef DEBUG bool foundHook = false; +#endif for (auto &curHook : module->getHookDataList()) { auto func_ptr = (uint32_t) curHook->getTarget(); if (func_ptr == 0) { @@ -68,7 +71,9 @@ void CallHook(const std::shared_ptr &module, wums_hook_type_t type) } if (type == curHook->getType()) { +#ifdef DEBUG foundHook = true; +#endif if ((type == WUMS_HOOK_APPLICATION_STARTS || type == WUMS_HOOK_APPLICATION_ENDS || type == WUMS_HOOK_INIT_WUT_MALLOC || @@ -88,18 +93,19 @@ void CallHook(const std::shared_ptr &module, wums_hook_type_t type) type == WUMS_HOOK_ALL_APPLICATION_STARTS_DONE || type == WUMS_HOOK_ALL_APPLICATION_ENDS_DONE || type == WUMS_HOOK_CLEAR_ALLOCATED_RPL_MEMORY || - type == WUMS_HOOK_ALL_APPLICATION_REQUESTS_EXIT_DONE)) { - DEBUG_FUNCTION_LINE("Calling hook of type %s [%d] %d for %s: %08X", hook_names[type], type, curHook->getType(), module->getExportName().c_str(), curHook->getTarget()); + type == WUMS_HOOK_ALL_APPLICATION_REQUESTS_EXIT_DONE || + type == WUMS_HOOK_INIT_WUT_THREAD)) { + DEBUG_FUNCTION_LINE("Calling hook of type %s [%d] %d for %s: %p", hook_names[type], type, curHook->getType(), module->getExportName().c_str(), curHook->getTarget()); ((void (*)())((uint32_t *) func_ptr))(); break; } else if (type == WUMS_HOOK_INIT || type == WUMS_HOOK_RELOCATIONS_DONE) { - DEBUG_FUNCTION_LINE("Calling hook of type %s [%d] %d for %s: %08X", hook_names[type], type, curHook->getType(), module->getExportName().c_str(), curHook->getTarget()); + DEBUG_FUNCTION_LINE("Calling hook of type %s [%d] %d for %s: %p", hook_names[type], type, curHook->getType(), module->getExportName().c_str(), curHook->getTarget()); wums_app_init_args_t args; args.module_information = &gModuleInformation; ((void (*)(wums_app_init_args_t *))((uint32_t *) func_ptr))(&args); } else if (type == WUMS_HOOK_GET_CUSTOM_RPL_ALLOCATOR) { - DEBUG_FUNCTION_LINE("Calling hook of type %s [%d] %d for %s: %08X", hook_names[type], type, curHook->getType(), module->getExportName().c_str(), curHook->getTarget()); + DEBUG_FUNCTION_LINE("Calling hook of type %s [%d] %d for %s: %p", hook_names[type], type, curHook->getType(), module->getExportName().c_str(), curHook->getTarget()); const auto [allocFn, freeFn] = reinterpret_cast(reinterpret_cast(func_ptr))(); gCustomRPLAllocatorAllocFn = allocFn; diff --git a/wumsloader/src/utils/imports.h b/wumsloader/src/utils/imports.h index ffc24cc..375996b 100644 --- a/wumsloader/src/utils/imports.h +++ b/wumsloader/src/utils/imports.h @@ -44,6 +44,18 @@ IMPORT(MEMCheckHeap); IMPORT(MEMGetBaseHeapHandle); IMPORT(MEMCheckExpHeap); IMPORT(OSGetBootPMFlags); +IMPORT(OSFastMutex_Lock); +IMPORT(OSFastMutex_Init); +IMPORT(OSFastCond_Init); +IMPORT(OSCancelAlarm); +IMPORT(OSFastCond_Wait); +IMPORT(OSSetAlarm); +IMPORT(OSSetAlarmUserData); +IMPORT(OSCreateAlarm); +IMPORT(OSFastCond_Signal); +IMPORT(OSFastMutex_Unlock); +IMPORT(OSInitSpinLock); +IMPORT(OSGetAlarmUserData); IMPORT(FSTimeToCalendarTime); IMPORT(FSInit);