summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Lioncash2018-12-15 14:29:39 -0500
committerGravatar Lioncash2018-12-19 10:59:40 -0500
commit622242e3451fd562425f67317f3f0d7855eb5741 (patch)
tree8b0ed78dffd57cf69ec042a39318d12c67bb7fb7
parentvm_manager: Add member function for checking a memory range adheres to certai... (diff)
downloadyuzu-622242e3451fd562425f67317f3f0d7855eb5741.tar.gz
yuzu-622242e3451fd562425f67317f3f0d7855eb5741.tar.xz
yuzu-622242e3451fd562425f67317f3f0d7855eb5741.zip
vm_manager: Add member function for setting memory attributes across an address range
This puts the backing functionality for svcSetMemoryAttribute in place, which will be utilized in a following change.
Diffstat (limited to '')
-rw-r--r--src/core/hle/kernel/vm_manager.cpp28
-rw-r--r--src/core/hle/kernel/vm_manager.h13
2 files changed, 41 insertions, 0 deletions
diff --git a/src/core/hle/kernel/vm_manager.cpp b/src/core/hle/kernel/vm_manager.cpp
index 02504d750..f39e096ca 100644
--- a/src/core/hle/kernel/vm_manager.cpp
+++ b/src/core/hle/kernel/vm_manager.cpp
@@ -322,6 +322,34 @@ MemoryInfo VMManager::QueryMemory(VAddr address) const {
322 return memory_info; 322 return memory_info;
323} 323}
324 324
325ResultCode VMManager::SetMemoryAttribute(VAddr address, u64 size, MemoryAttribute mask,
326 MemoryAttribute attribute) {
327 constexpr auto ignore_mask = MemoryAttribute::Uncached | MemoryAttribute::DeviceMapped;
328 constexpr auto attribute_mask = ~ignore_mask;
329
330 const auto result = CheckRangeState(
331 address, size, MemoryState::FlagUncached, MemoryState::FlagUncached, VMAPermission::None,
332 VMAPermission::None, attribute_mask, MemoryAttribute::None, ignore_mask);
333
334 if (result.Failed()) {
335 return result.Code();
336 }
337
338 const auto [prev_state, prev_permissions, prev_attributes] = *result;
339 const auto new_attribute = (prev_attributes & ~mask) | (mask & attribute);
340
341 const auto carve_result = CarveVMARange(address, size);
342 if (carve_result.Failed()) {
343 return carve_result.Code();
344 }
345
346 auto vma_iter = *carve_result;
347 vma_iter->second.attribute = new_attribute;
348
349 MergeAdjacent(vma_iter);
350 return RESULT_SUCCESS;
351}
352
325ResultCode VMManager::MirrorMemory(VAddr dst_addr, VAddr src_addr, u64 size, MemoryState state) { 353ResultCode VMManager::MirrorMemory(VAddr dst_addr, VAddr src_addr, u64 size, MemoryState state) {
326 const auto vma = FindVMA(src_addr); 354 const auto vma = FindVMA(src_addr);
327 355
diff --git a/src/core/hle/kernel/vm_manager.h b/src/core/hle/kernel/vm_manager.h
index 9fa9a18fb..6091533bc 100644
--- a/src/core/hle/kernel/vm_manager.h
+++ b/src/core/hle/kernel/vm_manager.h
@@ -392,6 +392,19 @@ public:
392 /// 392 ///
393 MemoryInfo QueryMemory(VAddr address) const; 393 MemoryInfo QueryMemory(VAddr address) const;
394 394
395 /// Sets an attribute across the given address range.
396 ///
397 /// @param address The starting address
398 /// @param size The size of the range to set the attribute on.
399 /// @param mask The attribute mask
400 /// @param attribute The attribute to set across the given address range
401 ///
402 /// @returns RESULT_SUCCESS if successful
403 /// @returns ERR_INVALID_ADDRESS_STATE if the attribute could not be set.
404 ///
405 ResultCode SetMemoryAttribute(VAddr address, u64 size, MemoryAttribute mask,
406 MemoryAttribute attribute);
407
395 /** 408 /**
396 * Scans all VMAs and updates the page table range of any that use the given vector as backing 409 * Scans all VMAs and updates the page table range of any that use the given vector as backing
397 * memory. This should be called after any operation that causes reallocation of the vector. 410 * memory. This should be called after any operation that causes reallocation of the vector.