Compare commits

...

10 Commits

Author SHA1 Message Date
Maschell 4774694061 Update Dockerfile 2024-04-25 20:29:37 +02:00
Maschell 506cad85a9 Bump version 2024-04-25 20:29:37 +02:00
Maschell 3121941e26 Update error message when using an outdated aroma version 2024-04-25 20:29:37 +02:00
dependabot[bot] ca65a86993 Bump softprops/action-gh-release from 1 to 2
Bumps [softprops/action-gh-release](https://github.com/softprops/action-gh-release) from 1 to 2.
- [Release notes](https://github.com/softprops/action-gh-release/releases)
- [Changelog](https://github.com/softprops/action-gh-release/blob/master/CHANGELOG.md)
- [Commits](https://github.com/softprops/action-gh-release/compare/v1...v2)

---
updated-dependencies:
- dependency-name: softprops/action-gh-release
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-04-25 20:29:37 +02:00
dependabot[bot] 711bf03448 Bump wiiu-env/devkitppc from 20230621 to 20231112
Bumps wiiu-env/devkitppc from 20230621 to 20231112.

---
updated-dependencies:
- dependency-name: wiiu-env/devkitppc
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-04-25 20:29:37 +02:00
dependabot[bot] f5fb777870 Bump actions/checkout from 3 to 4
Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-04-25 20:29:37 +02:00
Maschell 705c6104fb Check if the MEM2 heap is corrupted after calling a hook 2024-04-25 20:29:37 +02:00
Maschell 27dbc97eca Move iteration into own scope 2024-04-25 20:29:37 +02:00
Maschell e237ba6e8c Move the wumsrelocator to 0x00800000 2024-04-25 20:29:37 +02:00
Maschell 40420432e2 Allow early init of the Module System, check EnvrionmentLoader version 2024-04-25 20:29:37 +02:00
11 changed files with 72 additions and 31 deletions

View File

@ -9,7 +9,7 @@ jobs:
clang-format:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: clang-format
run: |
docker run --rm -v ${PWD}:/src ghcr.io/wiiu-env/clang-format:13.0.0-2 -r ./source ./wumsloader/src --exclude ./wumsloader/src/elfio
@ -17,7 +17,7 @@ jobs:
runs-on: ubuntu-22.04
needs: clang-format
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: create version.h
run: |
git_hash=$(git rev-parse --short "$GITHUB_SHA")
@ -48,7 +48,7 @@ jobs:
- name: zip artifact
run: zip -r ${{ env.REPOSITORY_NAME }}_${{ env.DATETIME }}.zip *.rpx
- name: Create Release
uses: "softprops/action-gh-release@v1"
uses: "softprops/action-gh-release@v2"
with:
tag_name: ${{ env.REPOSITORY_NAME }}-${{ env.DATETIME }}
draft: false

View File

@ -6,7 +6,7 @@ jobs:
clang-format:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: clang-format
run: |
docker run --rm -v ${PWD}:/src ghcr.io/wiiu-env/clang-format:13.0.0-2 -r ./source ./wumsloader/src --exclude ./wumsloader/src/elfio
@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-22.04
needs: clang-format
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: build binary with logging
run: |
docker build . -t builder
@ -25,7 +25,7 @@ jobs:
runs-on: ubuntu-22.04
needs: clang-format
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: create version.h
run: |
git_hash=$(git rev-parse --short "${{ github.event.pull_request.head.sha }}")

View File

@ -1,5 +1,5 @@
FROM ghcr.io/wiiu-env/devkitppc:20230621
FROM ghcr.io/wiiu-env/devkitppc:20240423
COPY --from=ghcr.io/wiiu-env/wiiumodulesystem:20230622 /artifacts $DEVKITPRO
COPY --from=ghcr.io/wiiu-env/wiiumodulesystem:20240424 /artifacts $DEVKITPRO
WORKDIR project

View File

@ -1,4 +1,5 @@
#include "kernel.h"
#include "../wumsloader/src/globals.h"
#include "ElfUtils.h"
#include "wumsloader_elf.h"
#include <coreinit/cache.h>
@ -20,6 +21,9 @@ void SetupWUMSLoader() {
KernelWriteU32(repl_addr, 0x48000003 | entryPoint);
DCFlushRange((void *) repl_addr, 4);
ICInvalidateRange((void *) (repl_addr), 4);
// We call the mainhook (wumloader) once with a MAGIC number to set up the WUMS Modules but not actually call the original main function
((int (*)(int, char **))(entryPoint))(WUMS_LOADER_SETUP_MAGIC_WORD, nullptr);
}
void KernelWriteU32(uint32_t addr, uint32_t value) {

View File

@ -12,6 +12,15 @@ int main(int argc, char **argv) {
if (argc >= 1) {
basePath = argv[0];
}
if (argc < 4 || std::string_view("EnvironmentLoader") != argv[1] || (uint32_t) argv[2] < 2 || (uint32_t) argv[3] == 0) {
OSFatal("WUMSLoader:\n"
"Failed to parse arguments! Make sure to use the latest\n"
"version of the EnvironmentLoader.\n"
"\n\n"
"See https://wiiu.hacks.guide/ for instructions on how to update!");
}
memcpy(MEMORY_REGION_USABLE_MEM_REGION_END_VALUE_PTR, &argv[3], sizeof(uint32_t));
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Warray-bounds"

View File

@ -70,7 +70,7 @@ MAKEFLAGS += --no-print-directory
#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
LIBS := -lwums -lwut -lz
LIBS := -lwut -lz
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing

View File

@ -16,7 +16,7 @@
#include <cstdint>
#include <list>
#define VERSION "v0.2.3"
#define VERSION "v0.2.4"
void CallInitHooksForModule(const std::shared_ptr<ModuleData> &curModule);
@ -53,6 +53,10 @@ extern "C" int _start(int argc, char **argv) {
:);
OSCheckActiveThreads();
if (argc == WUMS_LOADER_SETUP_MAGIC_WORD) {
DEBUG_FUNCTION_LINE("Skip calling the real main function because we just want to setup WUMS");
return 0;
}
return ((int (*)(int, char **))(*(unsigned int *) 0x1005E040))(argc, argv);
}
@ -122,14 +126,16 @@ void doStart(int argc, char **argv) {
// Order modules list by dependencies.
gLoadedModules = OrderModulesByDependencies(gLoadedModules);
// 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"; });
if (it != gLoadedModules.end()) {
auto module = *it;
gLoadedModules.erase(it);
gLoadedModules.push_back(module);
{
// 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"; });
if (it != gLoadedModules.end()) {
auto module = *it;
gLoadedModules.erase(it);
gLoadedModules.push_back(module);
}
}
bool aromaBaseModuleLoaded = false;

View File

@ -14,15 +14,23 @@ extern std::unique_ptr<module_information_single_t[]> gModuleDataInfo;
extern std::map<std::string, OSDynLoad_Module> gUsedRPLs;
extern std::vector<void *> gAllocatedAddresses;
#define MEMORY_REGION_START 0x00800000
#define MEMORY_REGION_SIZE 0x00800000
#define MEMORY_REGION_START 0x00800000
#define MEMORY_REGION_SIZE 0x00800000
#define CUSTOM_RPX_LOADER_RETURN_CODE 0x00009000 // We have to skip the first 0x00009000 bytes because it's still used
#define RELOCATOR_SIZE 0x52000 // Maximum size of the wumsloader, needs to match the one defined in link.ld
#define ENVIRONMENT_PATH_LENGTH 0x100 // Length of the EnvironmentPath.
#define RELOCATOR_SIZE 0x50000 // Maximum size of the wumsloader, needs to match the one defined in link.ld
#define ENVIRONMENT_PATH_LENGTH 0x100 // Length of the EnvironmentPath.
#define MEMORY_REGION_USABLE_MEM_REGION_END_LENGTH 0x04 // sizeof(uint32_t)
#define MEMORY_REGION_ENVIRONMENT_STRING_ADRR (MEMORY_REGION_START + CUSTOM_RPX_LOADER_RETURN_CODE + RELOCATOR_SIZE)
#define MEMORY_REGION_USABLE_HEAP_START (MEMORY_REGION_ENVIRONMENT_STRING_ADRR + ENVIRONMENT_PATH_LENGTH)
#define MEMORY_REGION_USABLE_HEAP_END (0x00FFF000) // We need to leave space for the BAT hook
#define ENVRIONMENT_STRING ((char *) MEMORY_REGION_ENVIRONMENT_STRING_ADRR)
#define MEMORY_REGION_ENVIRONMENT_STRING_ADRR (MEMORY_REGION_START + RELOCATOR_SIZE)
#define MEMORY_REGION_USABLE_MEM_REGION_END_VALUE_PTR ((uint32_t *) (MEMORY_REGION_ENVIRONMENT_STRING_ADRR + ENVIRONMENT_PATH_LENGTH))
#define MEMORY_REGION_USABLE_MEM_REGION_END_VALUE (*MEMORY_REGION_USABLE_MEM_REGION_END_VALUE_PTR)
// Technically we overwrite the CustomRPXLoader that is still loaded at 0x00800000...
// We can get away with it because the EnvironmentLoader exits instead of returning to the CustomRPXLoader.
#define MEMORY_REGION_USABLE_HEAP_START ((uint32_t) MEMORY_REGION_USABLE_MEM_REGION_END_VALUE_PTR + MEMORY_REGION_USABLE_MEM_REGION_END_LENGTH)
#define MEMORY_REGION_USABLE_HEAP_END MEMORY_REGION_USABLE_MEM_REGION_END_VALUE
#define ENVRIONMENT_STRING ((char *) MEMORY_REGION_ENVIRONMENT_STRING_ADRR)
#define WUMS_LOADER_SETUP_MAGIC_WORD 0x13371337

View File

@ -3,7 +3,7 @@ OUTPUT(loader.elf);
ENTRY(_start);
SECTIONS {
. = 0x00809000;
. = 0x00800000;
.text ALIGN(32) : {
KEEP (*(.crt0))
KEEP (*(SORT_NONE(.init)))
@ -92,4 +92,4 @@ SECTIONS {
}
}
ASSERT((SIZEOF(.text) + SIZEOF(.data) + SIZEOF(.rodata) + SIZEOF(.eh_frame) + SIZEOF(.bss)) < 0x52000, "Memory overlapping with modules.");
ASSERT((SIZEOF(.text) + SIZEOF(.data) + SIZEOF(.rodata) + SIZEOF(.eh_frame) + SIZEOF(.bss)) < 0x50000, "Memory overlapping with modules.");

View File

@ -5,7 +5,6 @@
#include <memory>
#include <wums.h>
#ifdef DEBUG
static const char **hook_names = (const char *[]){
"WUMS_HOOK_INIT_WUT_MALLOC",
"WUMS_HOOK_FINI_WUT_MALLOC",
@ -27,7 +26,6 @@ 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) {
@ -48,7 +46,10 @@ 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()) {
auto func_ptr = (uint32_t) curHook->getTarget();
if (func_ptr == 0) {
@ -57,6 +58,7 @@ void CallHook(const std::shared_ptr<ModuleData> &module, wums_hook_type_t type)
}
if (type == curHook->getType()) {
foundHook = true;
if ((type == WUMS_HOOK_APPLICATION_STARTS ||
type == WUMS_HOOK_APPLICATION_ENDS ||
type == WUMS_HOOK_INIT_WUT_MALLOC ||
@ -90,4 +92,11 @@ 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
OSFatal("WUMSLoader: MEM2 default heap is corrupted. \n Please restart the console.");
#endif
}
}

View File

@ -38,6 +38,11 @@ IMPORT(__KernelGetInfo);
IMPORT(OSCheckActiveThreads);
IMPORT(OSGetCurrentThread);
IMPORT(OSSetThreadCleanupCallback);
IMPORT(OSIsDebuggerPresent);
IMPORT(__os_snprintf);
IMPORT(MEMCheckHeap);
IMPORT(MEMGetBaseHeapHandle);
IMPORT(MEMCheckExpHeap);
IMPORT(FSTimeToCalendarTime);
IMPORT(FSInit);