diff options
author | Lioncash <mathew1800@gmail.com> | 2019-04-12 05:21:13 +0200 |
---|---|---|
committer | Lioncash <mathew1800@gmail.com> | 2019-04-13 03:55:50 +0200 |
commit | 76a2465655be493492446b4ef686f4b59b2e3969 (patch) | |
tree | dc28b70dfd697390427ea013b0925999a9f19578 /src/core/hle/kernel/vm_manager.cpp | |
parent | Merge pull request #2235 from ReinUsesLisp/spirv-decompiler (diff) | |
download | yuzu-76a2465655be493492446b4ef686f4b59b2e3969.tar yuzu-76a2465655be493492446b4ef686f4b59b2e3969.tar.gz yuzu-76a2465655be493492446b4ef686f4b59b2e3969.tar.bz2 yuzu-76a2465655be493492446b4ef686f4b59b2e3969.tar.lz yuzu-76a2465655be493492446b4ef686f4b59b2e3969.tar.xz yuzu-76a2465655be493492446b4ef686f4b59b2e3969.tar.zst yuzu-76a2465655be493492446b4ef686f4b59b2e3969.zip |
Diffstat (limited to '')
-rw-r--r-- | src/core/hle/kernel/vm_manager.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/core/hle/kernel/vm_manager.cpp b/src/core/hle/kernel/vm_manager.cpp index ec0a480ce..76b491c47 100644 --- a/src/core/hle/kernel/vm_manager.cpp +++ b/src/core/hle/kernel/vm_manager.cpp @@ -302,6 +302,35 @@ ResultVal<VAddr> VMManager::SetHeapSize(u64 size) { return MakeResult<VAddr>(heap_region_base); } +ResultCode VMManager::MapCodeMemory(VAddr dst_address, VAddr src_address, u64 size) { + constexpr auto ignore_attribute = MemoryAttribute::LockedForIPC | MemoryAttribute::DeviceMapped; + const auto src_check_result = CheckRangeState( + src_address, size, MemoryState::All, MemoryState::Heap, VMAPermission::All, + VMAPermission::ReadWrite, MemoryAttribute::Mask, MemoryAttribute::None, ignore_attribute); + + if (src_check_result.Failed()) { + return src_check_result.Code(); + } + + const auto mirror_result = + MirrorMemory(dst_address, src_address, size, MemoryState::ModuleCode); + if (mirror_result.IsError()) { + return mirror_result; + } + + // Ensure we lock the source memory region. + const auto src_vma_result = CarveVMARange(src_address, size); + if (src_vma_result.Failed()) { + return src_vma_result.Code(); + } + auto src_vma_iter = *src_vma_result; + src_vma_iter->second.attribute = MemoryAttribute::Locked; + Reprotect(src_vma_iter, VMAPermission::Read); + + // The destination memory region is fine as is, however we need to make it read-only. + return ReprotectRange(dst_address, size, VMAPermission::Read); +} + MemoryInfo VMManager::QueryMemory(VAddr address) const { const auto vma = FindVMA(address); MemoryInfo memory_info{}; |