diff --git a/Dockerfile b/Dockerfile index 7a2662b..3ebd3c9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ -FROM wiiuenv/devkitppc:20220806 +FROM wiiuenv/devkitppc:20221228 COPY --from=wiiuenv/libkernel:20220904 /artifacts $DEVKITPRO -COPY --from=wiiuenv/libfunctionpatcher:20220904 /artifacts $DEVKITPRO -COPY --from=wiiuenv/wiiumodulesystem:20220904 /artifacts $DEVKITPRO +COPY --from=wiiuenv/libfunctionpatcher:20230106 /artifacts $DEVKITPRO +COPY --from=wiiuenv/wiiumodulesystem:20221005 /artifacts $DEVKITPRO WORKDIR project diff --git a/Makefile b/Makefile index 91b6322..0769c07 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,7 @@ CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__ CXXFLAGS := $(CFLAGS) -std=c++17 -fno-exceptions -fno-rtti ASFLAGS := -g $(ARCH) -LDFLAGS = -g $(ARCH) $(RPXSPECS) -Wl,-Map,$(notdir $*.map) -T$(WUMS_ROOT)/share/libkernel.ld -T$(WUMS_ROOT)/share/libfunctionpatcher.ld $(WUMSSPECS) +LDFLAGS = -g $(ARCH) $(RPXSPECS) -Wl,-Map,$(notdir $*.map) -T$(WUMS_ROOT)/share/libkernel.ld -Tfunctionpatcher.ld $(WUMSSPECS) ifeq ($(DEBUG),1) CXXFLAGS += -DDEBUG -g @@ -74,6 +74,7 @@ export DEPSDIR := $(CURDIR)/$(BUILD) CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) +DEFFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.def))) BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) #------------------------------------------------------------------------------- @@ -91,7 +92,7 @@ endif #------------------------------------------------------------------------------- export OFILES_BIN := $(addsuffix .o,$(BINFILES)) -export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) +export OFILES_SRC := $(DEFFILES:.def=.o) $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) export OFILES := $(OFILES_BIN) $(OFILES_SRC) export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES))) @@ -138,7 +139,11 @@ $(OFILES_SRC) : $(HFILES_BIN) #------------------------------------------------------------------------------- @echo $(notdir $<) @$(bin2o) - +#--------------------------------------------------------------------------------- +%.o: %.def + $(SILENTMSG) $(notdir $<) + $(SILENTCMD)rplimportgen $< $*.s $*.ld $(ERROR_FILTER) + $(SILENTCMD)$(CC) -x assembler-with-cpp $(ASFLAGS) -c $*.s -o $@ $(ERROR_FILTER) #--------------------------------------------------------------------------------- %.o: %.s @echo $(notdir $<) diff --git a/source/functionpatcher.def b/source/functionpatcher.def new file mode 100644 index 0000000..0c87cbc --- /dev/null +++ b/source/functionpatcher.def @@ -0,0 +1,4 @@ +:NAME homebrew_functionpatcher + +:TEXT +FPAddFunctionPatch \ No newline at end of file diff --git a/source/main.cpp b/source/main.cpp index 8c6d377..68e08b0 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -14,6 +14,9 @@ WUMS_MODULE_EXPORT_NAME("homebrew_memorymapping"); WUMS_MODULE_SKIP_INIT_FINI(); WUMS_MODULE_INIT_BEFORE_RELOCATION_DONE_HOOK(); +// We can't use the functions from libfunctionpatcher. Defined in functionpatcher.def +extern "C" FunctionPatcherStatus FPAddFunctionPatch(function_replacement_data_t *function_data, PatchedFunctionHandle *outHandle, bool *outHasBeenPatched); + WUMS_INITIALIZE(args) { static uint8_t ucSetupRequired = 1; if (!ucSetupRequired) { @@ -24,14 +27,20 @@ WUMS_INITIALIZE(args) { MemoryMapping_setupMemoryMapping(); MemoryMapping_CreateHeaps(); + /* We can not use FunctionPatcher_InitLibrary here because OSDynLoadAcquire is not patched yet. + if (FunctionPatcher_InitLibrary() != FUNCTION_PATCHER_RESULT_SUCCESS) { + OSFatal("homebrew_memorymapping: FunctionPatcher_InitLibrary failed"); + }*/ + for (uint32_t i = 0; i < function_replacements_size; i++) { - if (!FunctionPatcherPatchFunction(&function_replacements[i], nullptr)) { + bool wasPatched = false; + // We don't need to save the handles because we never restore them anyway. + if (FPAddFunctionPatch(&function_replacements[i], nullptr, &wasPatched) != FUNCTION_PATCHER_RESULT_SUCCESS || !wasPatched) { OSFatal("homebrew_memorymapping: Failed to patch function"); } } } - WUMS_APPLICATION_STARTS() { OSReport("Running MemoryMappingModule " VERSION VERSION_EXTRA "\n"); #ifdef DEBUG