diff options
author | Lioncash <mathew1800@gmail.com> | 2019-06-05 20:20:13 +0200 |
---|---|---|
committer | Lioncash <mathew1800@gmail.com> | 2019-07-04 02:29:49 +0200 |
commit | 55481df50f98feb04b18beb518904681b8fcc345 (patch) | |
tree | 204f9e55abae9b53e4ba78ad0a7a3251b828734b /src/core/hle/kernel/vm_manager.cpp | |
parent | Merge pull request #2613 from ogniK5377/InitalizeApplicationInfo (diff) | |
download | yuzu-55481df50f98feb04b18beb518904681b8fcc345.tar yuzu-55481df50f98feb04b18beb518904681b8fcc345.tar.gz yuzu-55481df50f98feb04b18beb518904681b8fcc345.tar.bz2 yuzu-55481df50f98feb04b18beb518904681b8fcc345.tar.lz yuzu-55481df50f98feb04b18beb518904681b8fcc345.tar.xz yuzu-55481df50f98feb04b18beb518904681b8fcc345.tar.zst yuzu-55481df50f98feb04b18beb518904681b8fcc345.zip |
Diffstat (limited to '')
-rw-r--r-- | src/core/hle/kernel/vm_manager.cpp | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/src/core/hle/kernel/vm_manager.cpp b/src/core/hle/kernel/vm_manager.cpp index c929c2a52..3df5ccb7f 100644 --- a/src/core/hle/kernel/vm_manager.cpp +++ b/src/core/hle/kernel/vm_manager.cpp @@ -152,22 +152,33 @@ ResultVal<VMManager::VMAHandle> VMManager::MapBackingMemory(VAddr target, u8* me } 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; + return FindFreeRegion(GetASLRRegionBaseAddress(), GetASLRRegionEndAddress(), size); +} - const VAddr vma_end = vma.second.base + vma.second.size; - return vma_end > base && vma_end >= base + size; - }); +ResultVal<VAddr> VMManager::FindFreeRegion(VAddr begin, VAddr end, u64 size) const { + ASSERT(begin < end); + ASSERT(size <= end - begin); - if (vma_handle == vma_map.end()) { + const VMAHandle vma_handle = + std::find_if(vma_map.begin(), vma_map.end(), [begin, end, size](const auto& vma) { + if (vma.second.type != VMAType::Free) { + return false; + } + const VAddr vma_base = vma.second.base; + const VAddr vma_end = vma_base + vma.second.size; + const VAddr assumed_base = (begin < vma_base) ? vma_base : begin; + const VAddr used_range = assumed_base + size; + + return vma_base <= assumed_base && assumed_base < used_range && used_range < end && + used_range <= vma_end; + }); + + if (vma_handle == vma_map.cend()) { // TODO(Subv): Find the correct error code here. return ResultCode(-1); } - const VAddr target = std::max(base, vma_handle->second.base); + const VAddr target = std::max(begin, vma_handle->second.base); return MakeResult<VAddr>(target); } |