2
1
Fork 0
mirror of https://github.com/yuzu-emu/yuzu.git synced 2024-07-04 23:31:19 +01:00

hle: kernel: k_page_table: Fix implementations of LockForCodeMemory & UnlockForCodeMemory.

This commit is contained in:
bunnei 2022-03-26 01:49:34 -07:00
parent 0c75913bf2
commit 9408100a80

View file

@ -1682,57 +1682,21 @@ ResultCode KPageTable::UnlockForDeviceAddressSpace(VAddr addr, std::size_t size)
} }
ResultCode KPageTable::LockForCodeMemory(VAddr addr, std::size_t size) { ResultCode KPageTable::LockForCodeMemory(VAddr addr, std::size_t size) {
KScopedLightLock lk(general_lock); return this->LockMemoryAndOpen(
nullptr, nullptr, addr, size, KMemoryState::FlagCanCodeMemory,
KMemoryPermission new_perm = KMemoryPermission::NotMapped | KMemoryPermission::KernelReadWrite; KMemoryState::FlagCanCodeMemory, KMemoryPermission::All, KMemoryPermission::UserReadWrite,
KMemoryAttribute::All, KMemoryAttribute::None,
KMemoryPermission old_perm{}; static_cast<KMemoryPermission>(KMemoryPermission::NotMapped |
KMemoryPermission::KernelReadWrite),
if (const ResultCode result{CheckMemoryState( KMemoryAttribute::Locked);
nullptr, &old_perm, nullptr, nullptr, addr, size, KMemoryState::FlagCanCodeMemory,
KMemoryState::FlagCanCodeMemory, KMemoryPermission::All,
KMemoryPermission::UserReadWrite, KMemoryAttribute::All, KMemoryAttribute::None)};
result.IsError()) {
return result;
}
new_perm = (new_perm != KMemoryPermission::None) ? new_perm : old_perm;
block_manager->UpdateLock(
addr, size / PageSize,
[](KMemoryBlockManager::iterator block, KMemoryPermission permission) {
block->ShareToDevice(permission);
},
new_perm);
return ResultSuccess;
} }
ResultCode KPageTable::UnlockForCodeMemory(VAddr addr, std::size_t size) { ResultCode KPageTable::UnlockForCodeMemory(VAddr addr, std::size_t size) {
KScopedLightLock lk(general_lock); return this->UnlockMemory(addr, size, KMemoryState::FlagCanCodeMemory,
KMemoryState::FlagCanCodeMemory, KMemoryPermission::None,
KMemoryPermission new_perm = KMemoryPermission::UserReadWrite; KMemoryPermission::None, KMemoryAttribute::All,
KMemoryAttribute::Locked, KMemoryPermission::UserReadWrite,
KMemoryPermission old_perm{}; KMemoryAttribute::Locked, nullptr);
if (const ResultCode result{CheckMemoryState(
nullptr, &old_perm, nullptr, nullptr, addr, size, KMemoryState::FlagCanCodeMemory,
KMemoryState::FlagCanCodeMemory, KMemoryPermission::None, KMemoryPermission::None,
KMemoryAttribute::All, KMemoryAttribute::Locked)};
result.IsError()) {
return result;
}
new_perm = (new_perm != KMemoryPermission::None) ? new_perm : old_perm;
block_manager->UpdateLock(
addr, size / PageSize,
[](KMemoryBlockManager::iterator block, KMemoryPermission permission) {
block->UnshareToDevice(permission);
},
new_perm);
return ResultSuccess;
} }
ResultCode KPageTable::InitializeMemoryLayout(VAddr start, VAddr end) { ResultCode KPageTable::InitializeMemoryLayout(VAddr start, VAddr end) {