diff options
| author | Lioncash <mathew1800@gmail.com> | 2019-03-13 05:02:14 -0400 | 
|---|---|---|
| committer | Lioncash <mathew1800@gmail.com> | 2019-03-13 06:04:49 -0400 | 
| commit | 537906310863fd5528ca9fbcd4a5ee2d432c7abc (patch) | |
| tree | 68eb5c859c7617ec586b86f0234e8e9efecb5dc4 /src/core/hle | |
| parent | 567134f874c0d753cdc3cadbded8dfdfa7a786da (diff) | |
core/hle/kernel/svc: Implement svcUnmapTransferMemory
Similarly, like svcMapTransferMemory, we can also implement
svcUnmapTransferMemory fairly trivially as well.
Diffstat (limited to 'src/core/hle')
| -rw-r--r-- | src/core/hle/kernel/svc.cpp | 49 | 
1 files changed, 48 insertions, 1 deletions
| diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 9d57b6650..bc89c4880 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp @@ -1646,6 +1646,53 @@ static ResultCode MapTransferMemory(Handle handle, VAddr address, u64 size, u32      return transfer_memory->MapMemory(address, size, permissions);  } +static ResultCode UnmapTransferMemory(Handle handle, VAddr address, u64 size) { +    LOG_DEBUG(Kernel_SVC, "called. handle=0x{:08X}, address=0x{:016X}, size=0x{:016X}", handle, +              address, size); + +    if (!Common::Is4KBAligned(address)) { +        LOG_ERROR(Kernel_SVC, "Transfer memory addresses must be 4KB aligned (size=0x{:016X}).", +                  address); +        return ERR_INVALID_ADDRESS; +    } + +    if (size == 0 || !Common::Is4KBAligned(size)) { +        LOG_ERROR(Kernel_SVC, +                  "Transfer memory sizes must be 4KB aligned and not be zero (size=0x{:016X}).", +                  size); +        return ERR_INVALID_SIZE; +    } + +    if (!IsValidAddressRange(address, size)) { +        LOG_ERROR(Kernel_SVC, +                  "Given address and size overflows the 64-bit range (address=0x{:016X}, " +                  "size=0x{:016X}).", +                  address, size); +        return ERR_INVALID_ADDRESS_STATE; +    } + +    const auto& kernel = Core::System::GetInstance().Kernel(); +    const auto* const current_process = kernel.CurrentProcess(); +    const auto& handle_table = current_process->GetHandleTable(); + +    auto transfer_memory = handle_table.Get<TransferMemory>(handle); +    if (!transfer_memory) { +        LOG_ERROR(Kernel_SVC, "Nonexistent transfer memory handle given (handle=0x{:08X}).", +                  handle); +        return ERR_INVALID_HANDLE; +    } + +    if (!current_process->VMManager().IsWithinASLRRegion(address, size)) { +        LOG_ERROR(Kernel_SVC, +                  "Given address and size don't fully fit within the ASLR region " +                  "(address=0x{:016X}, size=0x{:016X}).", +                  address, size); +        return ERR_INVALID_MEMORY_RANGE; +    } + +    return transfer_memory->UnmapMemory(address, size); +} +  static ResultCode GetThreadCoreMask(Handle thread_handle, u32* core, u64* mask) {      LOG_TRACE(Kernel_SVC, "called, handle=0x{:08X}", thread_handle); @@ -2022,7 +2069,7 @@ static const FunctionDef SVC_Table[] = {      {0x4F, nullptr, "SetProcessActivity"},      {0x50, SvcWrap<CreateSharedMemory>, "CreateSharedMemory"},      {0x51, SvcWrap<MapTransferMemory>, "MapTransferMemory"}, -    {0x52, nullptr, "UnmapTransferMemory"}, +    {0x52, SvcWrap<UnmapTransferMemory>, "UnmapTransferMemory"},      {0x53, nullptr, "CreateInterruptEvent"},      {0x54, nullptr, "QueryPhysicalAddress"},      {0x55, nullptr, "QueryIoMapping"}, | 
