summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2022-01-15 08:27:36 +0100
committerbunnei <bunneidev@gmail.com>2022-01-23 05:51:34 +0100
commit07add23251880d142d0b11115d4cb239d60c57bd (patch)
treeaa0d28773b3a6636c2c4247f2803c08a069f2938
parentcore: hle: kernel: KPageTable: ReserveTransferMemory: Various cleanup. (diff)
downloadyuzu-07add23251880d142d0b11115d4cb239d60c57bd.tar
yuzu-07add23251880d142d0b11115d4cb239d60c57bd.tar.gz
yuzu-07add23251880d142d0b11115d4cb239d60c57bd.tar.bz2
yuzu-07add23251880d142d0b11115d4cb239d60c57bd.tar.lz
yuzu-07add23251880d142d0b11115d4cb239d60c57bd.tar.xz
yuzu-07add23251880d142d0b11115d4cb239d60c57bd.tar.zst
yuzu-07add23251880d142d0b11115d4cb239d60c57bd.zip
-rw-r--r--src/core/hle/kernel/k_page_table.cpp23
1 files changed, 12 insertions, 11 deletions
diff --git a/src/core/hle/kernel/k_page_table.cpp b/src/core/hle/kernel/k_page_table.cpp
index 223c0d491..d78c5e37a 100644
--- a/src/core/hle/kernel/k_page_table.cpp
+++ b/src/core/hle/kernel/k_page_table.cpp
@@ -276,22 +276,23 @@ ResultCode KPageTable::InitializeForProcess(FileSys::ProgramAddressSpaceType as_
ResultCode KPageTable::MapProcessCode(VAddr addr, std::size_t num_pages, KMemoryState state,
KMemoryPermission perm) {
- std::lock_guard lock{page_table_lock};
-
const u64 size{num_pages * PageSize};
- if (!CanContain(addr, size, state)) {
- return ResultInvalidCurrentMemory;
- }
+ // Validate the mapping request.
+ R_UNLESS(this->CanContain(addr, size, state), ResultInvalidCurrentMemory);
- if (IsRegionMapped(addr, size)) {
- return ResultInvalidCurrentMemory;
- }
+ // Lock the table.
+ std::lock_guard lock{page_table_lock};
+
+ // Verify that the destination memory is unmapped.
+ R_TRY(this->CheckMemoryState(addr, size, KMemoryState::All, KMemoryState::Free,
+ KMemoryPermission::None, KMemoryPermission::None,
+ KMemoryAttribute::None, KMemoryAttribute::None));
KPageLinkedList page_linked_list;
- CASCADE_CODE(system.Kernel().MemoryManager().Allocate(page_linked_list, num_pages, memory_pool,
- allocation_option));
- CASCADE_CODE(Operate(addr, num_pages, page_linked_list, OperationType::MapGroup));
+ R_TRY(system.Kernel().MemoryManager().Allocate(page_linked_list, num_pages, memory_pool,
+ allocation_option));
+ R_TRY(Operate(addr, num_pages, page_linked_list, OperationType::MapGroup));
block_manager->Update(addr, num_pages, state, perm);