diff options
author | bunnei <bunneidev@gmail.com> | 2018-10-24 00:39:10 +0200 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2018-10-26 00:03:54 +0200 |
commit | a609b6907a67e927d1dd0ade0135c004c9507fad (patch) | |
tree | d0bf42917ad5c2f857ccbc7cd0e842521ad4f991 /src/core/hle/kernel/vm_manager.cpp | |
parent | nro: Make LoadNro method accessible outside of apploader code. (diff) | |
download | yuzu-a609b6907a67e927d1dd0ade0135c004c9507fad.tar yuzu-a609b6907a67e927d1dd0ade0135c004c9507fad.tar.gz yuzu-a609b6907a67e927d1dd0ade0135c004c9507fad.tar.bz2 yuzu-a609b6907a67e927d1dd0ade0135c004c9507fad.tar.lz yuzu-a609b6907a67e927d1dd0ade0135c004c9507fad.tar.xz yuzu-a609b6907a67e927d1dd0ade0135c004c9507fad.tar.zst yuzu-a609b6907a67e927d1dd0ade0135c004c9507fad.zip |
Diffstat (limited to '')
-rw-r--r-- | src/core/hle/kernel/vm_manager.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/core/hle/kernel/vm_manager.cpp b/src/core/hle/kernel/vm_manager.cpp index e1a34eef1..1a92c8f70 100644 --- a/src/core/hle/kernel/vm_manager.cpp +++ b/src/core/hle/kernel/vm_manager.cpp @@ -143,6 +143,26 @@ ResultVal<VMManager::VMAHandle> VMManager::MapBackingMemory(VAddr target, u8* me return MakeResult<VMAHandle>(MergeAdjacent(vma_handle)); } +ResultVal<VAddr> VMManager::FindFreeRegion(u64 size) const { + // Find the first Free VMA. + const VAddr base = GetASLRRegionBaseAddress(); + const VMAHandle vma_handle = std::find_if(vma_map.begin(), vma_map.end(), [&](const auto& vma) { + if (vma.second.type != VMAType::Free) + return false; + + const VAddr vma_end = vma.second.base + vma.second.size; + return vma_end > base && vma_end >= base + size; + }); + + if (vma_handle == vma_map.end()) { + // TODO(Subv): Find the correct error code here. + return ResultCode(-1); + } + + const VAddr target = std::max(base, vma_handle->second.base); + return MakeResult<VAddr>(target); +} + ResultVal<VMManager::VMAHandle> VMManager::MapMMIO(VAddr target, PAddr paddr, u64 size, MemoryState state, Memory::MemoryHookPointer mmio_handler) { |