diff options
author | Liam <byteslice@airmail.cc> | 2023-10-05 04:15:10 +0200 |
---|---|---|
committer | Liam <byteslice@airmail.cc> | 2023-10-05 04:32:27 +0200 |
commit | e797a917a927ee5f5a2400cf9e3742c8bc3ec800 (patch) | |
tree | 3a9d0a52f42f31a51ae95077324687a2a030404d /src/core/hle/kernel/svc | |
parent | Merge pull request #11657 from liamwhite/new-codespell (diff) | |
download | yuzu-e797a917a927ee5f5a2400cf9e3742c8bc3ec800.tar yuzu-e797a917a927ee5f5a2400cf9e3742c8bc3ec800.tar.gz yuzu-e797a917a927ee5f5a2400cf9e3742c8bc3ec800.tar.bz2 yuzu-e797a917a927ee5f5a2400cf9e3742c8bc3ec800.tar.lz yuzu-e797a917a927ee5f5a2400cf9e3742c8bc3ec800.tar.xz yuzu-e797a917a927ee5f5a2400cf9e3742c8bc3ec800.tar.zst yuzu-e797a917a927ee5f5a2400cf9e3742c8bc3ec800.zip |
Diffstat (limited to 'src/core/hle/kernel/svc')
-rw-r--r-- | src/core/hle/kernel/svc/svc_transfer_memory.cpp | 54 |
1 files changed, 49 insertions, 5 deletions
diff --git a/src/core/hle/kernel/svc/svc_transfer_memory.cpp b/src/core/hle/kernel/svc/svc_transfer_memory.cpp index 7d94e7f09..1f97121b3 100644 --- a/src/core/hle/kernel/svc/svc_transfer_memory.cpp +++ b/src/core/hle/kernel/svc/svc_transfer_memory.cpp @@ -71,15 +71,59 @@ Result CreateTransferMemory(Core::System& system, Handle* out, u64 address, u64 } Result MapTransferMemory(Core::System& system, Handle trmem_handle, uint64_t address, uint64_t size, - MemoryPermission owner_perm) { - UNIMPLEMENTED(); - R_THROW(ResultNotImplemented); + MemoryPermission map_perm) { + // Validate the address/size. + R_UNLESS(Common::IsAligned(address, PageSize), ResultInvalidAddress); + R_UNLESS(Common::IsAligned(size, PageSize), ResultInvalidSize); + R_UNLESS(size > 0, ResultInvalidSize); + R_UNLESS((address < address + size), ResultInvalidCurrentMemory); + + // Validate the permission. + R_UNLESS(IsValidTransferMemoryPermission(map_perm), ResultInvalidState); + + // Get the transfer memory. + KScopedAutoObject trmem = GetCurrentProcess(system.Kernel()) + .GetHandleTable() + .GetObject<KTransferMemory>(trmem_handle); + R_UNLESS(trmem.IsNotNull(), ResultInvalidHandle); + + // Verify that the mapping is in range. + R_UNLESS(GetCurrentProcess(system.Kernel()) + .GetPageTable() + .CanContain(address, size, KMemoryState::Transfered), + ResultInvalidMemoryRegion); + + // Map the transfer memory. + R_TRY(trmem->Map(address, size, map_perm)); + + // We succeeded. + R_SUCCEED(); } Result UnmapTransferMemory(Core::System& system, Handle trmem_handle, uint64_t address, uint64_t size) { - UNIMPLEMENTED(); - R_THROW(ResultNotImplemented); + // Validate the address/size. + R_UNLESS(Common::IsAligned(address, PageSize), ResultInvalidAddress); + R_UNLESS(Common::IsAligned(size, PageSize), ResultInvalidSize); + R_UNLESS(size > 0, ResultInvalidSize); + R_UNLESS((address < address + size), ResultInvalidCurrentMemory); + + // Get the transfer memory. + KScopedAutoObject trmem = GetCurrentProcess(system.Kernel()) + .GetHandleTable() + .GetObject<KTransferMemory>(trmem_handle); + R_UNLESS(trmem.IsNotNull(), ResultInvalidHandle); + + // Verify that the mapping is in range. + R_UNLESS(GetCurrentProcess(system.Kernel()) + .GetPageTable() + .CanContain(address, size, KMemoryState::Transfered), + ResultInvalidMemoryRegion); + + // Unmap the transfer memory. + R_TRY(trmem->Unmap(address, size)); + + R_SUCCEED(); } Result MapTransferMemory64(Core::System& system, Handle trmem_handle, uint64_t address, |