citra-emu
/
citra
Archived
1
0
Fork 0

Merge pull request #4122 from FearlessTobi/port-905

Port #905 from yuzu: "kernel/vm_manager: Minor changes"
This commit is contained in:
Merry 2018-08-24 19:01:57 +01:00 committed by GitHub
commit cf4f8463f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 14 deletions

View File

@ -2,6 +2,7 @@
// Licensed under GPLv2 or any later version // Licensed under GPLv2 or any later version
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <algorithm>
#include <iterator> #include <iterator>
#include "common/assert.h" #include "common/assert.h"
#include "core/hle/kernel/errors.h" #include "core/hle/kernel/errors.h"
@ -209,9 +210,9 @@ VMManager::VMAIter VMManager::Unmap(VMAIter vma_handle) {
ResultCode VMManager::UnmapRange(VAddr target, u32 size) { ResultCode VMManager::UnmapRange(VAddr target, u32 size) {
CASCADE_RESULT(VMAIter vma, CarveVMARange(target, size)); CASCADE_RESULT(VMAIter vma, CarveVMARange(target, size));
VAddr target_end = target + size; const VAddr target_end = target + size;
VMAIter end = vma_map.end(); const VMAIter end = vma_map.end();
// The comparison against the end of the range must be done using addresses since VMAs can be // The comparison against the end of the range must be done using addresses since VMAs can be
// merged during this process, causing invalidation of the iterators. // merged during this process, causing invalidation of the iterators.
while (vma != end && vma->second.base < target_end) { while (vma != end && vma->second.base < target_end) {
@ -234,9 +235,9 @@ VMManager::VMAHandle VMManager::Reprotect(VMAHandle vma_handle, VMAPermission ne
ResultCode VMManager::ReprotectRange(VAddr target, u32 size, VMAPermission new_perms) { ResultCode VMManager::ReprotectRange(VAddr target, u32 size, VMAPermission new_perms) {
CASCADE_RESULT(VMAIter vma, CarveVMARange(target, size)); CASCADE_RESULT(VMAIter vma, CarveVMARange(target, size));
VAddr target_end = target + size; const VAddr target_end = target + size;
VMAIter end = vma_map.end(); const VMAIter end = vma_map.end();
// The comparison against the end of the range must be done using addresses since VMAs can be // The comparison against the end of the range must be done using addresses since VMAs can be
// merged during this process, causing invalidation of the iterators. // merged during this process, causing invalidation of the iterators.
while (vma != end && vma->second.base < target_end) { while (vma != end && vma->second.base < target_end) {
@ -285,14 +286,14 @@ ResultVal<VMManager::VMAIter> VMManager::CarveVMA(VAddr base, u32 size) {
return ERR_INVALID_ADDRESS; return ERR_INVALID_ADDRESS;
} }
VirtualMemoryArea& vma = vma_handle->second; const VirtualMemoryArea& vma = vma_handle->second;
if (vma.type != VMAType::Free) { if (vma.type != VMAType::Free) {
// Region is already allocated // Region is already allocated
return ERR_INVALID_ADDRESS_STATE; return ERR_INVALID_ADDRESS_STATE;
} }
u32 start_in_vma = base - vma.base; const VAddr start_in_vma = base - vma.base;
u32 end_in_vma = start_in_vma + size; const VAddr end_in_vma = start_in_vma + size;
if (end_in_vma > vma.size) { if (end_in_vma > vma.size) {
// Requested allocation doesn't fit inside VMA // Requested allocation doesn't fit inside VMA
@ -315,18 +316,17 @@ ResultVal<VMManager::VMAIter> VMManager::CarveVMARange(VAddr target, u32 size) {
ASSERT_MSG((size & Memory::PAGE_MASK) == 0, "non-page aligned size: {:#10X}", size); ASSERT_MSG((size & Memory::PAGE_MASK) == 0, "non-page aligned size: {:#10X}", size);
ASSERT_MSG((target & Memory::PAGE_MASK) == 0, "non-page aligned base: {:#010X}", target); ASSERT_MSG((target & Memory::PAGE_MASK) == 0, "non-page aligned base: {:#010X}", target);
VAddr target_end = target + size; const VAddr target_end = target + size;
ASSERT(target_end >= target); ASSERT(target_end >= target);
ASSERT(target_end <= MAX_ADDRESS); ASSERT(target_end <= MAX_ADDRESS);
ASSERT(size > 0); ASSERT(size > 0);
VMAIter begin_vma = StripIterConstness(FindVMA(target)); VMAIter begin_vma = StripIterConstness(FindVMA(target));
VMAIter i_end = vma_map.lower_bound(target_end); const VMAIter i_end = vma_map.lower_bound(target_end);
for (auto i = begin_vma; i != i_end; ++i) { if (std::any_of(begin_vma, i_end,
if (i->second.type == VMAType::Free) { [](const auto& entry) { return entry.second.type == VMAType::Free; })) {
return ERR_INVALID_ADDRESS_STATE; return ERR_INVALID_ADDRESS_STATE;
} }
}
if (target != begin_vma->second.base) { if (target != begin_vma->second.base) {
begin_vma = SplitVMA(begin_vma, target - begin_vma->second.base); begin_vma = SplitVMA(begin_vma, target - begin_vma->second.base);
@ -373,7 +373,7 @@ VMManager::VMAIter VMManager::SplitVMA(VMAIter vma_handle, u32 offset_in_vma) {
} }
VMManager::VMAIter VMManager::MergeAdjacent(VMAIter iter) { VMManager::VMAIter VMManager::MergeAdjacent(VMAIter iter) {
VMAIter next_vma = std::next(iter); const VMAIter next_vma = std::next(iter);
if (next_vma != vma_map.end() && iter->second.CanBeMergedWith(next_vma->second)) { if (next_vma != vma_map.end() && iter->second.CanBeMergedWith(next_vma->second)) {
iter->second.size += next_vma->second.size; iter->second.size += next_vma->second.size;
vma_map.erase(next_vma); vma_map.erase(next_vma);