mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-18 19:51:30 +12:00
Memory: Implement Unmap in ControlMemory
Also do a sanity check to make sure the memory region is free for linear allocations
This commit is contained in:
parent
c65b91e6f1
commit
ba25ae7eba
2 changed files with 10 additions and 0 deletions
|
@ -89,10 +89,17 @@ void Kernel::controlMemory() {
|
|||
}
|
||||
|
||||
case Operation::Map:
|
||||
// Official kernel only allows Private regions to be mapped to Free regions. An Alias or Aliased region cannot be mapped again
|
||||
if (!mem.mapVirtualMemory(addr0, addr1, pages, r, w, false, MemoryState::Free, MemoryState::Private,
|
||||
MemoryState::Alias, MemoryState::Aliased)) Helpers::panic("ControlMemory: Failed to map memory");
|
||||
break;
|
||||
|
||||
case Operation::Unmap:
|
||||
// The same as a Map operation, except in reverse
|
||||
if (!mem.mapVirtualMemory(addr0, addr1, pages, false, false, false, MemoryState::Alias, MemoryState::Aliased,
|
||||
MemoryState::Free, MemoryState::Private)) Helpers::panic("ControlMemory: Failed to unmap memory");
|
||||
break;
|
||||
|
||||
case Operation::Protect:
|
||||
// Official kernel has an internal state bit to indicate that the region's permissions may be changed
|
||||
// But this should account for all cases
|
||||
|
|
|
@ -426,6 +426,9 @@ bool Memory::allocMemoryLinear(u32& outVaddr, u32 inVaddr, s32 pages, FcramRegio
|
|||
|
||||
u32 paddr = memList.begin()->paddr;
|
||||
u32 vaddr = getLinearHeapVaddr() + paddr;
|
||||
auto res = testMemoryState(vaddr, pages, MemoryState::Free);
|
||||
if (res.isFailure()) Helpers::panic("Unable to map linear allocation (vaddr:%08X pages:%08X)", vaddr, pages);
|
||||
|
||||
Operation op{ .newState = MemoryState::Continuous, .r = r, .w = w, .x = x, .changeState = true, .changePerms = true };
|
||||
changeMemoryState(vaddr, pages, op);
|
||||
mapPhysicalMemory(vaddr, paddr, pages, r, w, x);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue