diff --git a/Dockerfile b/Dockerfile index 2f60025..66d345c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,3 @@ -FROM wiiuenv/devkitppc:20220801 +FROM wiiuenv/devkitppc:20220806 WORKDIR project diff --git a/src/crt.c b/src/crt.c new file mode 100644 index 0000000..954c654 --- /dev/null +++ b/src/crt.c @@ -0,0 +1,36 @@ +void __init_wut_malloc(); + +void __init_wut_newlib(); + +void __init_wut_stdcpp(); + +void __init_wut_devoptab(); + +void __attribute__((weak)) __init_wut_socket(); + +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_malloc(); + __init_wut_newlib(); + __init_wut_stdcpp(); + __init_wut_devoptab(); + if (&__init_wut_socket) __init_wut_socket(); +} + +void __attribute__((weak)) +fini_wut() { + __fini_wut_devoptab(); + __fini_wut_stdcpp(); + __fini_wut_newlib(); + __fini_wut_malloc(); +} diff --git a/src/imports.h b/src/imports.h index a408604..5f47fc6 100644 --- a/src/imports.h +++ b/src/imports.h @@ -59,7 +59,7 @@ IMPORT(OSCompareAndSwapAtomic); IMPORT(OSGetThreadSpecific); IMPORT(OSSetThreadSpecific); IMPORT(FSTimeToCalendarTime); -IMPORT(OSIsDebuggerInitialized); +IMPORT(OSSwapAtomic); IMPORT(exit); IMPORT(_Exit); diff --git a/src/main.cpp b/src/main.cpp index aa08dd4..ff9f4b9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -64,19 +64,16 @@ bool CheckRunning() { return true; } -extern "C" void __init_wut(); -extern "C" void __fini_wut(); -extern "C" void __init_wut_malloc(); +extern "C" void init_wut(); +extern "C" void fini_wut(); extern "C" int _start(int argc, char **argv) __attribute__((section(".start_code"))); extern "C" int _start(int argc, char **argv) { - // We need to call __init_wut_malloc somewhere so wut_malloc will be used for the memory allocation. - __init_wut_malloc(); doKernelSetup(); InitFunctionPointers(); doKernelSetup2(); - __init_wut(); + init_wut(); // Save last entry on mem2 heap to detect leaked memory MEMHeapHandle mem2_heap_handle = MEMGetBaseHeapHandle(MEM_BASE_HEAP_MEM2); @@ -105,7 +102,7 @@ extern "C" int _start(int argc, char **argv) { OSReport("Freed %d leaked memory blocks\n", leak_count); } - __fini_wut(); + fini_wut(); if (entrypoint > 0) { // clang-format off