Add kernel patches to allow usage of the memory mapping

This commit is contained in:
Maschell 2020-06-06 22:39:25 +02:00
parent 4e0010da0b
commit 51c92881af
4 changed files with 71 additions and 1 deletions

View File

@ -38,7 +38,7 @@ CXXFLAGS := $(CFLAGS) -std=c++17
ASFLAGS := -g $(ARCH) ASFLAGS := -g $(ARCH)
LDFLAGS = -g $(ARCH) $(WUMSSPECS) -Wl,-Map,$(notdir $*.map) LDFLAGS = -g $(ARCH) $(WUMSSPECS) -Wl,-Map,$(notdir $*.map)
LIBS := -lwums -lwut -lkernel LIBS := -lwums -lwut -lkernel -lfunctionpatcher
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level # list of directories containing libraries, this must be the top level

View File

@ -0,0 +1,57 @@
#include "function_replacements.h"
#include "memory_mapping.h"
DECL_FUNCTION(int32_t, KiEffectiveToPhysical, uint32_t addressSpace, uint32_t virtualAddress) {
int32_t result = real_KiEffectiveToPhysical(addressSpace, virtualAddress);
if (result == 0) {
return MemoryMapping_EffectiveToPhysical(virtualAddress);
}
return result;
}
DECL_FUNCTION(int32_t, KiPhysicalToEffectiveCached, uint32_t addressSpace, uint32_t virtualAddress) {
int32_t result = real_KiPhysicalToEffectiveCached(addressSpace, virtualAddress);
if (result == 0) {
return MemoryMapping_PhysicalToEffective(virtualAddress);
}
return result;
}
DECL_FUNCTION(int32_t, KiPhysicalToEffectiveUncached, uint32_t addressSpace, uint32_t virtualAddress) {
int32_t result = real_KiPhysicalToEffectiveUncached(addressSpace, virtualAddress);
if (result == 0) {
return MemoryMapping_PhysicalToEffective(virtualAddress);
}
return result;
}
DECL_FUNCTION(uint32_t, IPCKDriver_ValidatePhysicalAddress, uint32_t u1, uint32_t physStart, uint32_t physEnd) {
uint32_t result = MemoryMapping_PhysicalToEffective(physStart) > 0;
if (result) {
return result;
}
return real_IPCKDriver_ValidatePhysicalAddress(u1, physStart, physEnd);
}
DECL_FUNCTION(uint32_t, KiIsEffectiveRangeValid, uint32_t addressSpace, uint32_t virtualAddress, uint32_t size) {
uint32_t result = real_KiIsEffectiveRangeValid(addressSpace, virtualAddress, size);
if (result == 0) {
result = MemoryMapping_EffectiveToPhysical(virtualAddress) > 0;
}
return result;
}
function_replacement_data_t function_replacements[] __attribute__((section(".data"))) = {
REPLACE_FUNCTION_VIA_ADDRESS(KiEffectiveToPhysical, 0xffee0aac, 0xffee0aac),
REPLACE_FUNCTION_VIA_ADDRESS(KiPhysicalToEffectiveCached, 0xffee0a3c, 0xffee0a3c),
REPLACE_FUNCTION_VIA_ADDRESS(KiPhysicalToEffectiveUncached, 0xffee0a80, 0xffee0a80),
REPLACE_FUNCTION_VIA_ADDRESS(KiIsEffectiveRangeValid, 0xffee0d6c, 0xffee0d6c),
REPLACE_FUNCTION_VIA_ADDRESS(IPCKDriver_ValidatePhysicalAddress, 0xfff0cb5c, 0xfff0cb5c),
};
uint32_t function_replacements_size __attribute__((section(".data"))) = sizeof(function_replacements) / sizeof(function_replacement_data_t);

View File

@ -0,0 +1,7 @@
#pragma once
#include <function_patcher/function_patching.h>
#include <stdint.h>
extern function_replacement_data_t function_replacements[] __attribute__((section(".data")));
extern uint32_t function_replacements_size __attribute__((section(".data")));

View File

@ -6,7 +6,9 @@
#include <whb/log_udp.h> #include <whb/log_udp.h>
#include <coreinit/memexpheap.h> #include <coreinit/memexpheap.h>
#include "memory_mapping.h" #include "memory_mapping.h"
#include <function_patcher/function_patching.h>
#include "logger.h" #include "logger.h"
#include "function_replacements.h"
WUMS_MODULE_EXPORT_NAME("homebrew_memorymapping"); WUMS_MODULE_EXPORT_NAME("homebrew_memorymapping");
@ -21,6 +23,10 @@ WUMS_INITIALIZE() {
MemoryMapping_setupMemoryMapping(); MemoryMapping_setupMemoryMapping();
MemoryMapping_CreateHeaps(); MemoryMapping_CreateHeaps();
DEBUG_FUNCTION_LINE("total free space %d KiB", MemoryMapping_GetFreeSpace() / 1024); DEBUG_FUNCTION_LINE("total free space %d KiB", MemoryMapping_GetFreeSpace() / 1024);
DEBUG_FUNCTION_LINE("Patch functions");
FunctionPatcherPatchFunction(function_replacements, function_replacements_size);
DEBUG_FUNCTION_LINE("Patch functions finished");
} }
WUMS_APPLICATION_STARTS() { WUMS_APPLICATION_STARTS() {