diff options
author | bunnei <bunneidev@gmail.com> | 2021-04-30 23:53:22 +0200 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2021-05-06 01:40:52 +0200 |
commit | 0b27c721c994e10200893c3306cdab2184e5143c (patch) | |
tree | 4b5242fc2ed4f3ebfa34f0568c2b662c617d48ff /src/core/hle/kernel/k_page_table.cpp | |
parent | hle: kernel: Rename Process to KProcess. (diff) | |
download | yuzu-0b27c721c994e10200893c3306cdab2184e5143c.tar yuzu-0b27c721c994e10200893c3306cdab2184e5143c.tar.gz yuzu-0b27c721c994e10200893c3306cdab2184e5143c.tar.bz2 yuzu-0b27c721c994e10200893c3306cdab2184e5143c.tar.lz yuzu-0b27c721c994e10200893c3306cdab2184e5143c.tar.xz yuzu-0b27c721c994e10200893c3306cdab2184e5143c.tar.zst yuzu-0b27c721c994e10200893c3306cdab2184e5143c.zip |
Diffstat (limited to '')
-rw-r--r-- | src/core/hle/kernel/k_page_table.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/core/hle/kernel/k_page_table.cpp b/src/core/hle/kernel/k_page_table.cpp index 2f33cb6c1..6c5d7d602 100644 --- a/src/core/hle/kernel/k_page_table.cpp +++ b/src/core/hle/kernel/k_page_table.cpp @@ -641,6 +641,45 @@ ResultCode KPageTable::MapPages(VAddr addr, KPageLinkedList& page_linked_list, K return RESULT_SUCCESS; } +ResultCode KPageTable::UnmapPages(VAddr addr, const KPageLinkedList& page_linked_list) { + VAddr cur_addr{addr}; + + for (const auto& node : page_linked_list.Nodes()) { + const std::size_t num_pages{(addr - cur_addr) / PageSize}; + if (const auto result{ + Operate(addr, num_pages, KMemoryPermission::None, OperationType::Unmap)}; + result.IsError()) { + return result; + } + + cur_addr += node.GetNumPages() * PageSize; + } + + return RESULT_SUCCESS; +} + +ResultCode KPageTable::UnmapPages(VAddr addr, KPageLinkedList& page_linked_list, + KMemoryState state) { + std::lock_guard lock{page_table_lock}; + + const std::size_t num_pages{page_linked_list.GetNumPages()}; + const std::size_t size{num_pages * PageSize}; + + if (!CanContain(addr, size, state)) { + return ResultInvalidCurrentMemory; + } + + if (IsRegionMapped(addr, num_pages * PageSize)) { + return ResultInvalidCurrentMemory; + } + + CASCADE_CODE(UnmapPages(addr, page_linked_list)); + + block_manager->Update(addr, num_pages, state, KMemoryPermission::None); + + return RESULT_SUCCESS; +} + ResultCode KPageTable::SetCodeMemoryPermission(VAddr addr, std::size_t size, KMemoryPermission perm) { |