mirror of
https://github.com/wiiu-env/PatchMemoryRelocationsModule.git
synced 2024-11-24 10:49:18 +01:00
Use latest WUMS version, fix spelling of trampoline
This commit is contained in:
parent
83f17556c8
commit
1bd36b9ba1
@ -1,6 +1,6 @@
|
|||||||
FROM wiiuenv/devkitppc:20211229
|
FROM wiiuenv/devkitppc:20211229
|
||||||
|
|
||||||
COPY --from=wiiuenv/libmappedmemory:20210924 /artifacts $DEVKITPRO
|
COPY --from=wiiuenv/libmappedmemory:20210924 /artifacts $DEVKITPRO
|
||||||
COPY --from=wiiuenv/wiiumodulesystem:20220123 /artifacts $DEVKITPRO
|
COPY --from=wiiuenv/wiiumodulesystem:20220127 /artifacts $DEVKITPRO
|
||||||
|
|
||||||
WORKDIR project
|
WORKDIR project
|
@ -10,7 +10,7 @@ WUMS_MODULE_EXPORT_NAME("homebrew_patchmemoryrelocations");
|
|||||||
WUMS_MODULE_INIT_BEFORE_RELOCATION_DONE_HOOK();
|
WUMS_MODULE_INIT_BEFORE_RELOCATION_DONE_HOOK();
|
||||||
WUMS_MODULE_SKIP_INIT_FINI();
|
WUMS_MODULE_SKIP_INIT_FINI();
|
||||||
|
|
||||||
bool elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination, uint32_t symbol_addr, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length,
|
bool elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination, uint32_t symbol_addr, relocation_trampoline_entry_t *trampoline_data, uint32_t trampoline_data_length,
|
||||||
RelocationType reloc_type);
|
RelocationType reloc_type);
|
||||||
|
|
||||||
WUMS_RELOCATIONS_DONE(args) {
|
WUMS_RELOCATIONS_DONE(args) {
|
||||||
@ -71,7 +71,7 @@ WUMS_RELOCATIONS_DONE(args) {
|
|||||||
#define R_PPC_GHS_REL16_LO 253
|
#define R_PPC_GHS_REL16_LO 253
|
||||||
|
|
||||||
// See https://github.com/decaf-emu/decaf-emu/blob/43366a34e7b55ab9d19b2444aeb0ccd46ac77dea/src/libdecaf/src/cafe/loader/cafe_loader_reloc.cpp#L144
|
// See https://github.com/decaf-emu/decaf-emu/blob/43366a34e7b55ab9d19b2444aeb0ccd46ac77dea/src/libdecaf/src/cafe/loader/cafe_loader_reloc.cpp#L144
|
||||||
bool elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination, uint32_t symbol_addr, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length,
|
bool elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination, uint32_t symbol_addr, relocation_trampoline_entry_t *trampoline_data, uint32_t trampoline_data_length,
|
||||||
RelocationType reloc_type) {
|
RelocationType reloc_type) {
|
||||||
if (type == R_PPC_NONE) {
|
if (type == R_PPC_NONE) {
|
||||||
return true;
|
return true;
|
||||||
@ -140,42 +140,42 @@ bool elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination,
|
|||||||
// }
|
// }
|
||||||
auto distance = static_cast<int32_t>(value) - static_cast<int32_t>(target);
|
auto distance = static_cast<int32_t>(value) - static_cast<int32_t>(target);
|
||||||
if (distance > 0x1FFFFFC || distance < -0x1FFFFFC) {
|
if (distance > 0x1FFFFFC || distance < -0x1FFFFFC) {
|
||||||
if (trampolin_data == nullptr) {
|
if (trampoline_data == nullptr) {
|
||||||
DEBUG_FUNCTION_LINE("***24-bit relative branch cannot hit target. Trampoline isn't provided\n");
|
DEBUG_FUNCTION_LINE("***24-bit relative branch cannot hit target. Trampoline isn't provided\n");
|
||||||
DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X\n", value, target, distance);
|
DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X\n", value, target, distance);
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
relocation_trampolin_entry_t *freeSlot = nullptr;
|
relocation_trampoline_entry_t *freeSlot = nullptr;
|
||||||
for (uint32_t i = 0; i < trampolin_data_length; i++) {
|
for (uint32_t i = 0; i < trampoline_data_length; i++) {
|
||||||
// We want to override "old" relocations of imports
|
// We want to override "old" relocations of imports
|
||||||
// Pending relocations have the status RELOC_TRAMP_IMPORT_IN_PROGRESS.
|
// Pending relocations have the status RELOC_TRAMP_IMPORT_IN_PROGRESS.
|
||||||
// When all relocations are done successfully, they will be turned into RELOC_TRAMP_IMPORT_DONE
|
// When all relocations are done successfully, they will be turned into RELOC_TRAMP_IMPORT_DONE
|
||||||
// so they can be overridden/updated/reused on the next application launch.
|
// so they can be overridden/updated/reused on the next application launch.
|
||||||
//
|
//
|
||||||
// Relocations that won't change will have the status RELOC_TRAMP_FIXED and are set to free when the module is unloaded.
|
// Relocations that won't change will have the status RELOC_TRAMP_FIXED and are set to free when the module is unloaded.
|
||||||
if (trampolin_data[i].status == RELOC_TRAMP_FREE ||
|
if (trampoline_data[i].status == RELOC_TRAMP_FREE ||
|
||||||
trampolin_data[i].status == RELOC_TRAMP_IMPORT_DONE) {
|
trampoline_data[i].status == RELOC_TRAMP_IMPORT_DONE) {
|
||||||
freeSlot = &(trampolin_data[i]);
|
freeSlot = &(trampoline_data[i]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (freeSlot == nullptr) {
|
if (freeSlot == nullptr) {
|
||||||
DEBUG_FUNCTION_LINE("***24-bit relative branch cannot hit target. Trampolin data list is full\n");
|
DEBUG_FUNCTION_LINE("***24-bit relative branch cannot hit target. Trampoline data list is full\n");
|
||||||
DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X\n", value, target, distance);
|
DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X\n", value, target, distance);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (target - (uint32_t) &(freeSlot->trampolin[0]) > 0x1FFFFFC) {
|
if (target - (uint32_t) &(freeSlot->trampoline[0]) > 0x1FFFFFC) {
|
||||||
DEBUG_FUNCTION_LINE("**Cannot link 24-bit jump (too far to tramp buffer).");
|
DEBUG_FUNCTION_LINE("**Cannot link 24-bit jump (too far to tramp buffer).");
|
||||||
DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X\n", value, target, distance);
|
DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X\n", value, target, distance);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
freeSlot->trampolin[0] = 0x3D600000 | ((((uint32_t) value) >> 16) & 0x0000FFFF); // lis r11, real_addr@h
|
freeSlot->trampoline[0] = 0x3D600000 | ((((uint32_t) value) >> 16) & 0x0000FFFF); // lis r11, real_addr@h
|
||||||
freeSlot->trampolin[1] = 0x616B0000 | (((uint32_t) value) & 0x0000ffff); // ori r11, r11, real_addr@l
|
freeSlot->trampoline[1] = 0x616B0000 | (((uint32_t) value) & 0x0000ffff); // ori r11, r11, real_addr@l
|
||||||
freeSlot->trampolin[2] = 0x7D6903A6; // mtctr r11
|
freeSlot->trampoline[2] = 0x7D6903A6; // mtctr r11
|
||||||
freeSlot->trampolin[3] = 0x4E800420; // bctr
|
freeSlot->trampoline[3] = 0x4E800420; // bctr
|
||||||
DCFlushRange((void *) freeSlot->trampolin, sizeof(freeSlot->trampolin));
|
DCFlushRange((void *) freeSlot->trampoline, sizeof(freeSlot->trampoline));
|
||||||
ICInvalidateRange((unsigned char *) freeSlot->trampolin, sizeof(freeSlot->trampolin));
|
ICInvalidateRange((unsigned char *) freeSlot->trampoline, sizeof(freeSlot->trampoline));
|
||||||
|
|
||||||
if (reloc_type == RELOC_TYPE_FIXED) {
|
if (reloc_type == RELOC_TYPE_FIXED) {
|
||||||
freeSlot->status = RELOC_TRAMP_FIXED;
|
freeSlot->status = RELOC_TRAMP_FIXED;
|
||||||
@ -183,7 +183,7 @@ bool elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination,
|
|||||||
// Relocations for the imports may be overridden
|
// Relocations for the imports may be overridden
|
||||||
freeSlot->status = RELOC_TRAMP_IMPORT_IN_PROGRESS;
|
freeSlot->status = RELOC_TRAMP_IMPORT_IN_PROGRESS;
|
||||||
}
|
}
|
||||||
uint32_t symbolValue = (uint32_t) &(freeSlot->trampolin[0]);
|
uint32_t symbolValue = (uint32_t) &(freeSlot->trampoline[0]);
|
||||||
value = symbolValue + addend;
|
value = symbolValue + addend;
|
||||||
distance = static_cast<int32_t>(value) - static_cast<int32_t>(target);
|
distance = static_cast<int32_t>(value) - static_cast<int32_t>(target);
|
||||||
DEBUG_FUNCTION_LINE("Created tramp\n");
|
DEBUG_FUNCTION_LINE("Created tramp\n");
|
||||||
|
Loading…
Reference in New Issue
Block a user