Skip to content

Commit

Permalink
RO: Unmap CROs when unloaded
Browse files Browse the repository at this point in the history
Thanks @noumidev
  • Loading branch information
PSI-Rockin committed May 11, 2024
1 parent 6c4c20f commit 546be9b
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/core/services/ldr_ro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace CROHeader {
NameOffset = 0x084,
NextCRO = 0x088,
PrevCRO = 0x08C,
FileSize = 0x090,
OnUnresolved = 0x0AC,
CodeOffset = 0x0B0,
DataOffset = 0x0B8,
Expand Down Expand Up @@ -177,6 +178,10 @@ class CRO {
mem.write32(croPointer + CROHeader::PrevCRO, prevCRO);
}

u32 getSize() {
return mem.read32(croPointer + CROHeader::FileSize);
}

void write32(u32 addr, u32 value) {
// Note: some games export symbols to the static module, which doesn't contain any segments.
// Instead, its segments point to ROM segments. We need this special write handler for writes to .text, which
Expand Down Expand Up @@ -1400,7 +1405,12 @@ void LDRService::unloadCRO(u32 messagePointer) {
Helpers::panic("Failed to unrebase CRO");
}

// TODO: unmap the CRO from the pagetable
u32 size = cro.getSize();
bool succeeded = mem.mapVirtualMemory(mapVaddr, croPointer, size >> 12, false, false, false,
MemoryState::Locked, MemoryState::AliasCode, MemoryState::Free, MemoryState::Private);
if (!succeeded) {
Helpers::panic("Failed to unmap CRO");
}

kernel.clearInstructionCache();

Expand Down

0 comments on commit 546be9b

Please sign in to comment.