diff options
author | bunnei <bunneidev@gmail.com> | 2021-12-28 08:33:11 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-28 08:33:11 +0100 |
commit | 9a0648ff0ad38195d7211b8c65d82b93fe123949 (patch) | |
tree | 65389f6208ea88028e095dc65e881b733c7402de /src/core/hle/kernel/k_page_table.cpp | |
parent | Merge pull request #7630 from ameerj/glasm-get-int (diff) | |
parent | core: hle: kernel: Implement SetMemoryPermission. (diff) | |
download | yuzu-9a0648ff0ad38195d7211b8c65d82b93fe123949.tar yuzu-9a0648ff0ad38195d7211b8c65d82b93fe123949.tar.gz yuzu-9a0648ff0ad38195d7211b8c65d82b93fe123949.tar.bz2 yuzu-9a0648ff0ad38195d7211b8c65d82b93fe123949.tar.lz yuzu-9a0648ff0ad38195d7211b8c65d82b93fe123949.tar.xz yuzu-9a0648ff0ad38195d7211b8c65d82b93fe123949.tar.zst yuzu-9a0648ff0ad38195d7211b8c65d82b93fe123949.zip |
Diffstat (limited to 'src/core/hle/kernel/k_page_table.cpp')
-rw-r--r-- | src/core/hle/kernel/k_page_table.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/core/hle/kernel/k_page_table.cpp b/src/core/hle/kernel/k_page_table.cpp index 99982e5a3..f2f88c147 100644 --- a/src/core/hle/kernel/k_page_table.cpp +++ b/src/core/hle/kernel/k_page_table.cpp @@ -806,6 +806,33 @@ ResultCode KPageTable::ResetTransferMemory(VAddr addr, std::size_t size) { KMemoryAttribute::Locked, KMemoryAttribute::IpcAndDeviceMapped)); block_manager->Update(addr, size / PageSize, state, KMemoryPermission::ReadAndWrite); + return ResultSuccess; +} + +ResultCode KPageTable::SetMemoryPermission(VAddr addr, std::size_t size, + Svc::MemoryPermission svc_perm) { + const size_t num_pages = size / PageSize; + + // Lock the table. + std::lock_guard lock{page_table_lock}; + + // Verify we can change the memory permission. + KMemoryState old_state; + KMemoryPermission old_perm; + R_TRY(this->CheckMemoryState( + std::addressof(old_state), std::addressof(old_perm), nullptr, addr, size, + KMemoryState::FlagCanReprotect, KMemoryState::FlagCanReprotect, KMemoryPermission::None, + KMemoryPermission::None, KMemoryAttribute::All, KMemoryAttribute::None)); + + // Determine new perm. + const KMemoryPermission new_perm = ConvertToKMemoryPermission(svc_perm); + R_SUCCEED_IF(old_perm == new_perm); + + // Perform mapping operation. + R_TRY(Operate(addr, num_pages, new_perm, OperationType::ChangePermissions)); + + // Update the blocks. + block_manager->Update(addr, num_pages, old_state, new_perm, KMemoryAttribute::None); return ResultSuccess; } |