diff options
author | Fernando S <fsahmkow27@gmail.com> | 2023-10-10 11:45:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-10 11:45:56 +0200 |
commit | 8ac8d703b9af7ebe858cb8957d42eb42c5ffdf75 (patch) | |
tree | 55fbc13601b432c459ed07ae60eb308f284d94cc /src/core/hle/kernel/svc | |
parent | Merge pull request #11716 from Squall-Leonhart/Z327444 (diff) | |
parent | kernel: implement transfer memory (diff) | |
download | yuzu-8ac8d703b9af7ebe858cb8957d42eb42c5ffdf75.tar yuzu-8ac8d703b9af7ebe858cb8957d42eb42c5ffdf75.tar.gz yuzu-8ac8d703b9af7ebe858cb8957d42eb42c5ffdf75.tar.bz2 yuzu-8ac8d703b9af7ebe858cb8957d42eb42c5ffdf75.tar.lz yuzu-8ac8d703b9af7ebe858cb8957d42eb42c5ffdf75.tar.xz yuzu-8ac8d703b9af7ebe858cb8957d42eb42c5ffdf75.tar.zst yuzu-8ac8d703b9af7ebe858cb8957d42eb42c5ffdf75.zip |
Diffstat (limited to '')
-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, |