summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar bunnei2018-08-02 23:18:03 -0400
committerGravatar GitHub2018-08-02 23:18:03 -0400
commit61ed68f3d04e91870d9cd8970e0dbd0a3beb3ed0 (patch)
tree9604696344c3410e3f4846880f27a1e573e269d7 /src
parentMerge pull request #903 from lioncash/copy (diff)
parentkernel/vm_manager: Convert loop into std::any_of() (diff)
downloadyuzu-61ed68f3d04e91870d9cd8970e0dbd0a3beb3ed0.tar.gz
yuzu-61ed68f3d04e91870d9cd8970e0dbd0a3beb3ed0.tar.xz
yuzu-61ed68f3d04e91870d9cd8970e0dbd0a3beb3ed0.zip
Merge pull request #905 from lioncash/vma
kernel/vm_manager: Minor changes
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/kernel/svc.cpp2
-rw-r--r--src/core/hle/kernel/vm_manager.cpp36
-rw-r--r--src/core/hle/kernel/vm_manager.h8
3 files changed, 23 insertions, 23 deletions
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index d1cbbc1f2..5db2db687 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -267,7 +267,7 @@ static ResultCode GetInfo(u64* result, u64 info_id, u64 handle, u64 info_sub_id)
267 LOG_TRACE(Kernel_SVC, "called info_id=0x{:X}, info_sub_id=0x{:X}, handle=0x{:08X}", info_id, 267 LOG_TRACE(Kernel_SVC, "called info_id=0x{:X}, info_sub_id=0x{:X}, handle=0x{:08X}", info_id,
268 info_sub_id, handle); 268 info_sub_id, handle);
269 269
270 auto& vm_manager = Core::CurrentProcess()->vm_manager; 270 const auto& vm_manager = Core::CurrentProcess()->vm_manager;
271 271
272 switch (static_cast<GetInfoType>(info_id)) { 272 switch (static_cast<GetInfoType>(info_id)) {
273 case GetInfoType::AllowedCpuIdBitmask: 273 case GetInfoType::AllowedCpuIdBitmask:
diff --git a/src/core/hle/kernel/vm_manager.cpp b/src/core/hle/kernel/vm_manager.cpp
index 9d26fd781..479cacb62 100644
--- a/src/core/hle/kernel/vm_manager.cpp
+++ b/src/core/hle/kernel/vm_manager.cpp
@@ -2,6 +2,7 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <algorithm>
5#include <iterator> 6#include <iterator>
6#include <utility> 7#include <utility>
7#include "common/assert.h" 8#include "common/assert.h"
@@ -175,9 +176,9 @@ VMManager::VMAIter VMManager::Unmap(VMAIter vma_handle) {
175 176
176ResultCode VMManager::UnmapRange(VAddr target, u64 size) { 177ResultCode VMManager::UnmapRange(VAddr target, u64 size) {
177 CASCADE_RESULT(VMAIter vma, CarveVMARange(target, size)); 178 CASCADE_RESULT(VMAIter vma, CarveVMARange(target, size));
178 VAddr target_end = target + size; 179 const VAddr target_end = target + size;
179 180
180 VMAIter end = vma_map.end(); 181 const VMAIter end = vma_map.end();
181 // The comparison against the end of the range must be done using addresses since VMAs can be 182 // The comparison against the end of the range must be done using addresses since VMAs can be
182 // merged during this process, causing invalidation of the iterators. 183 // merged during this process, causing invalidation of the iterators.
183 while (vma != end && vma->second.base < target_end) { 184 while (vma != end && vma->second.base < target_end) {
@@ -207,9 +208,9 @@ VMManager::VMAHandle VMManager::Reprotect(VMAHandle vma_handle, VMAPermission ne
207 208
208ResultCode VMManager::ReprotectRange(VAddr target, u64 size, VMAPermission new_perms) { 209ResultCode VMManager::ReprotectRange(VAddr target, u64 size, VMAPermission new_perms) {
209 CASCADE_RESULT(VMAIter vma, CarveVMARange(target, size)); 210 CASCADE_RESULT(VMAIter vma, CarveVMARange(target, size));
210 VAddr target_end = target + size; 211 const VAddr target_end = target + size;
211 212
212 VMAIter end = vma_map.end(); 213 const VMAIter end = vma_map.end();
213 // The comparison against the end of the range must be done using addresses since VMAs can be 214 // The comparison against the end of the range must be done using addresses since VMAs can be
214 // merged during this process, causing invalidation of the iterators. 215 // merged during this process, causing invalidation of the iterators.
215 while (vma != end && vma->second.base < target_end) { 216 while (vma != end && vma->second.base < target_end) {
@@ -258,14 +259,14 @@ ResultVal<VMManager::VMAIter> VMManager::CarveVMA(VAddr base, u64 size) {
258 return ERR_INVALID_ADDRESS; 259 return ERR_INVALID_ADDRESS;
259 } 260 }
260 261
261 VirtualMemoryArea& vma = vma_handle->second; 262 const VirtualMemoryArea& vma = vma_handle->second;
262 if (vma.type != VMAType::Free) { 263 if (vma.type != VMAType::Free) {
263 // Region is already allocated 264 // Region is already allocated
264 return ERR_INVALID_ADDRESS_STATE; 265 return ERR_INVALID_ADDRESS_STATE;
265 } 266 }
266 267
267 u64 start_in_vma = base - vma.base; 268 const VAddr start_in_vma = base - vma.base;
268 u64 end_in_vma = start_in_vma + size; 269 const VAddr end_in_vma = start_in_vma + size;
269 270
270 if (end_in_vma > vma.size) { 271 if (end_in_vma > vma.size) {
271 // Requested allocation doesn't fit inside VMA 272 // Requested allocation doesn't fit inside VMA
@@ -288,17 +289,16 @@ ResultVal<VMManager::VMAIter> VMManager::CarveVMARange(VAddr target, u64 size) {
288 ASSERT_MSG((size & Memory::PAGE_MASK) == 0, "non-page aligned size: 0x{:016X}", size); 289 ASSERT_MSG((size & Memory::PAGE_MASK) == 0, "non-page aligned size: 0x{:016X}", size);
289 ASSERT_MSG((target & Memory::PAGE_MASK) == 0, "non-page aligned base: 0x{:016X}", target); 290 ASSERT_MSG((target & Memory::PAGE_MASK) == 0, "non-page aligned base: 0x{:016X}", target);
290 291
291 VAddr target_end = target + size; 292 const VAddr target_end = target + size;
292 ASSERT(target_end >= target); 293 ASSERT(target_end >= target);
293 ASSERT(target_end <= MAX_ADDRESS); 294 ASSERT(target_end <= MAX_ADDRESS);
294 ASSERT(size > 0); 295 ASSERT(size > 0);
295 296
296 VMAIter begin_vma = StripIterConstness(FindVMA(target)); 297 VMAIter begin_vma = StripIterConstness(FindVMA(target));
297 VMAIter i_end = vma_map.lower_bound(target_end); 298 const VMAIter i_end = vma_map.lower_bound(target_end);
298 for (auto i = begin_vma; i != i_end; ++i) { 299 if (std::any_of(begin_vma, i_end,
299 if (i->second.type == VMAType::Free) { 300 [](const auto& entry) { return entry.second.type == VMAType::Free; })) {
300 return ERR_INVALID_ADDRESS_STATE; 301 return ERR_INVALID_ADDRESS_STATE;
301 }
302 } 302 }
303 303
304 if (target != begin_vma->second.base) { 304 if (target != begin_vma->second.base) {
@@ -346,7 +346,7 @@ VMManager::VMAIter VMManager::SplitVMA(VMAIter vma_handle, u64 offset_in_vma) {
346} 346}
347 347
348VMManager::VMAIter VMManager::MergeAdjacent(VMAIter iter) { 348VMManager::VMAIter VMManager::MergeAdjacent(VMAIter iter) {
349 VMAIter next_vma = std::next(iter); 349 const VMAIter next_vma = std::next(iter);
350 if (next_vma != vma_map.end() && iter->second.CanBeMergedWith(next_vma->second)) { 350 if (next_vma != vma_map.end() && iter->second.CanBeMergedWith(next_vma->second)) {
351 iter->second.size += next_vma->second.size; 351 iter->second.size += next_vma->second.size;
352 vma_map.erase(next_vma); 352 vma_map.erase(next_vma);
@@ -382,22 +382,22 @@ void VMManager::UpdatePageTableForVMA(const VirtualMemoryArea& vma) {
382 } 382 }
383} 383}
384 384
385u64 VMManager::GetTotalMemoryUsage() { 385u64 VMManager::GetTotalMemoryUsage() const {
386 LOG_WARNING(Kernel, "(STUBBED) called"); 386 LOG_WARNING(Kernel, "(STUBBED) called");
387 return 0xF8000000; 387 return 0xF8000000;
388} 388}
389 389
390u64 VMManager::GetTotalHeapUsage() { 390u64 VMManager::GetTotalHeapUsage() const {
391 LOG_WARNING(Kernel, "(STUBBED) called"); 391 LOG_WARNING(Kernel, "(STUBBED) called");
392 return 0x0; 392 return 0x0;
393} 393}
394 394
395VAddr VMManager::GetAddressSpaceBaseAddr() { 395VAddr VMManager::GetAddressSpaceBaseAddr() const {
396 LOG_WARNING(Kernel, "(STUBBED) called"); 396 LOG_WARNING(Kernel, "(STUBBED) called");
397 return 0x8000000; 397 return 0x8000000;
398} 398}
399 399
400u64 VMManager::GetAddressSpaceSize() { 400u64 VMManager::GetAddressSpaceSize() const {
401 LOG_WARNING(Kernel, "(STUBBED) called"); 401 LOG_WARNING(Kernel, "(STUBBED) called");
402 return MAX_ADDRESS; 402 return MAX_ADDRESS;
403} 403}
diff --git a/src/core/hle/kernel/vm_manager.h b/src/core/hle/kernel/vm_manager.h
index 38e4ebcd3..98bd04bea 100644
--- a/src/core/hle/kernel/vm_manager.h
+++ b/src/core/hle/kernel/vm_manager.h
@@ -190,16 +190,16 @@ public:
190 void LogLayout() const; 190 void LogLayout() const;
191 191
192 /// Gets the total memory usage, used by svcGetInfo 192 /// Gets the total memory usage, used by svcGetInfo
193 u64 GetTotalMemoryUsage(); 193 u64 GetTotalMemoryUsage() const;
194 194
195 /// Gets the total heap usage, used by svcGetInfo 195 /// Gets the total heap usage, used by svcGetInfo
196 u64 GetTotalHeapUsage(); 196 u64 GetTotalHeapUsage() const;
197 197
198 /// Gets the total address space base address, used by svcGetInfo 198 /// Gets the total address space base address, used by svcGetInfo
199 VAddr GetAddressSpaceBaseAddr(); 199 VAddr GetAddressSpaceBaseAddr() const;
200 200
201 /// Gets the total address space address size, used by svcGetInfo 201 /// Gets the total address space address size, used by svcGetInfo
202 u64 GetAddressSpaceSize(); 202 u64 GetAddressSpaceSize() const;
203 203
204 /// Each VMManager has its own page table, which is set as the main one when the owning process 204 /// Each VMManager has its own page table, which is set as the main one when the owning process
205 /// is scheduled. 205 /// is scheduled.