Skip to content

Commit

Permalink
Attempt to fix unmapping
Browse files Browse the repository at this point in the history
Unity tries to do an unmap after releasing the direct memory.
  • Loading branch information
polybiusproxy committed Dec 7, 2024
1 parent 71940b7 commit 6912c21
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
3 changes: 1 addition & 2 deletions src/core/libraries/kernel/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,7 @@ int PS4_SYSV_ABI sceKernelMunmap(void* addr, size_t len) {
return ORBIS_OK;
}
auto* memory = Core::Memory::Instance();
memory->UnmapMemory(std::bit_cast<VAddr>(addr), len);
return ORBIS_OK;
return memory->UnmapMemory(std::bit_cast<VAddr>(addr), len);;
}

int PS4_SYSV_ABI posix_munmap(void* addr, size_t len) {
Expand Down
15 changes: 10 additions & 5 deletions src/core/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,16 +375,19 @@ void MemoryManager::PoolDecommit(VAddr virtual_addr, size_t size) {
TRACK_FREE(virtual_addr, "VMEM");
}

void MemoryManager::UnmapMemory(VAddr virtual_addr, size_t size) {
s32 MemoryManager::UnmapMemory(VAddr virtual_addr, size_t size) {
std::scoped_lock lk{mutex};
UnmapMemoryImpl(virtual_addr, size);
return UnmapMemoryImpl(virtual_addr, size);
}

void MemoryManager::UnmapMemoryImpl(VAddr virtual_addr, size_t size) {
s32 MemoryManager::UnmapMemoryImpl(VAddr virtual_addr, size_t size) {
const auto it = FindVMA(virtual_addr);
const auto& vma_base = it->second;
ASSERT_MSG(vma_base.Contains(virtual_addr, size),
"Existing mapping does not contain requested unmap range");

if (!vma_base.Contains(virtual_addr, size)) {
LOG_ERROR(Kernel_Vmm, "Existing mapping does not contain requested unmap range");
return ORBIS_KERNEL_ERROR_EINVAL;
}

const auto vma_base_addr = vma_base.base;
const auto vma_base_size = vma_base.size;
Expand Down Expand Up @@ -415,6 +418,8 @@ void MemoryManager::UnmapMemoryImpl(VAddr virtual_addr, size_t size) {
impl.Unmap(vma_base_addr, vma_base_size, start_in_vma, start_in_vma + size, phys_base, is_exec,
has_backing, readonly_file);
TRACK_FREE(virtual_addr, "VMEM");

return ORBIS_OK;
}

int MemoryManager::QueryProtection(VAddr addr, void** start, void** end, u32* prot) {
Expand Down
4 changes: 2 additions & 2 deletions src/core/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class MemoryManager {

void PoolDecommit(VAddr virtual_addr, size_t size);

void UnmapMemory(VAddr virtual_addr, size_t size);
s32 UnmapMemory(VAddr virtual_addr, size_t size);

int QueryProtection(VAddr addr, void** start, void** end, u32* prot);

Expand Down Expand Up @@ -250,7 +250,7 @@ class MemoryManager {

DMemHandle Split(DMemHandle dmem_handle, size_t offset_in_area);

void UnmapMemoryImpl(VAddr virtual_addr, size_t size);
s32 UnmapMemoryImpl(VAddr virtual_addr, size_t size);

private:
AddressSpace impl;
Expand Down

0 comments on commit 6912c21

Please sign in to comment.