diff options
Diffstat (limited to '')
| -rw-r--r-- | src/core/hle/kernel/svc.cpp | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index c8b9e8aeb..9d57b6650 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp | |||
| @@ -1590,6 +1590,62 @@ static ResultCode CreateTransferMemory(Handle* handle, VAddr addr, u64 size, u32 | |||
| 1590 | return RESULT_SUCCESS; | 1590 | return RESULT_SUCCESS; |
| 1591 | } | 1591 | } |
| 1592 | 1592 | ||
| 1593 | static ResultCode MapTransferMemory(Handle handle, VAddr address, u64 size, u32 permission_raw) { | ||
| 1594 | LOG_DEBUG(Kernel_SVC, | ||
| 1595 | "called. handle=0x{:08X}, address=0x{:016X}, size=0x{:016X}, permissions=0x{:08X}", | ||
| 1596 | handle, address, size, permission_raw); | ||
| 1597 | |||
| 1598 | if (!Common::Is4KBAligned(address)) { | ||
| 1599 | LOG_ERROR(Kernel_SVC, "Transfer memory addresses must be 4KB aligned (size=0x{:016X}).", | ||
| 1600 | address); | ||
| 1601 | return ERR_INVALID_ADDRESS; | ||
| 1602 | } | ||
| 1603 | |||
| 1604 | if (size == 0 || !Common::Is4KBAligned(size)) { | ||
| 1605 | LOG_ERROR(Kernel_SVC, | ||
| 1606 | "Transfer memory sizes must be 4KB aligned and not be zero (size=0x{:016X}).", | ||
| 1607 | size); | ||
| 1608 | return ERR_INVALID_SIZE; | ||
| 1609 | } | ||
| 1610 | |||
| 1611 | if (!IsValidAddressRange(address, size)) { | ||
| 1612 | LOG_ERROR(Kernel_SVC, | ||
| 1613 | "Given address and size overflows the 64-bit range (address=0x{:016X}, " | ||
| 1614 | "size=0x{:016X}).", | ||
| 1615 | address, size); | ||
| 1616 | return ERR_INVALID_ADDRESS_STATE; | ||
| 1617 | } | ||
| 1618 | |||
| 1619 | const auto permissions = static_cast<MemoryPermission>(permission_raw); | ||
| 1620 | if (permissions != MemoryPermission::None && permissions != MemoryPermission::Read && | ||
| 1621 | permissions != MemoryPermission::ReadWrite) { | ||
| 1622 | LOG_ERROR(Kernel_SVC, "Invalid transfer memory permissions given (permissions=0x{:08X}).", | ||
| 1623 | permission_raw); | ||
| 1624 | return ERR_INVALID_STATE; | ||
| 1625 | } | ||
| 1626 | |||
| 1627 | const auto& kernel = Core::System::GetInstance().Kernel(); | ||
| 1628 | const auto* const current_process = kernel.CurrentProcess(); | ||
| 1629 | const auto& handle_table = current_process->GetHandleTable(); | ||
| 1630 | |||
| 1631 | auto transfer_memory = handle_table.Get<TransferMemory>(handle); | ||
| 1632 | if (!transfer_memory) { | ||
| 1633 | LOG_ERROR(Kernel_SVC, "Nonexistent transfer memory handle given (handle=0x{:08X}).", | ||
| 1634 | handle); | ||
| 1635 | return ERR_INVALID_HANDLE; | ||
| 1636 | } | ||
| 1637 | |||
| 1638 | if (!current_process->VMManager().IsWithinASLRRegion(address, size)) { | ||
| 1639 | LOG_ERROR(Kernel_SVC, | ||
| 1640 | "Given address and size don't fully fit within the ASLR region " | ||
| 1641 | "(address=0x{:016X}, size=0x{:016X}).", | ||
| 1642 | address, size); | ||
| 1643 | return ERR_INVALID_MEMORY_RANGE; | ||
| 1644 | } | ||
| 1645 | |||
| 1646 | return transfer_memory->MapMemory(address, size, permissions); | ||
| 1647 | } | ||
| 1648 | |||
| 1593 | static ResultCode GetThreadCoreMask(Handle thread_handle, u32* core, u64* mask) { | 1649 | static ResultCode GetThreadCoreMask(Handle thread_handle, u32* core, u64* mask) { |
| 1594 | LOG_TRACE(Kernel_SVC, "called, handle=0x{:08X}", thread_handle); | 1650 | LOG_TRACE(Kernel_SVC, "called, handle=0x{:08X}", thread_handle); |
| 1595 | 1651 | ||
| @@ -1965,7 +2021,7 @@ static const FunctionDef SVC_Table[] = { | |||
| 1965 | {0x4E, nullptr, "ReadWriteRegister"}, | 2021 | {0x4E, nullptr, "ReadWriteRegister"}, |
| 1966 | {0x4F, nullptr, "SetProcessActivity"}, | 2022 | {0x4F, nullptr, "SetProcessActivity"}, |
| 1967 | {0x50, SvcWrap<CreateSharedMemory>, "CreateSharedMemory"}, | 2023 | {0x50, SvcWrap<CreateSharedMemory>, "CreateSharedMemory"}, |
| 1968 | {0x51, nullptr, "MapTransferMemory"}, | 2024 | {0x51, SvcWrap<MapTransferMemory>, "MapTransferMemory"}, |
| 1969 | {0x52, nullptr, "UnmapTransferMemory"}, | 2025 | {0x52, nullptr, "UnmapTransferMemory"}, |
| 1970 | {0x53, nullptr, "CreateInterruptEvent"}, | 2026 | {0x53, nullptr, "CreateInterruptEvent"}, |
| 1971 | {0x54, nullptr, "QueryPhysicalAddress"}, | 2027 | {0x54, nullptr, "QueryPhysicalAddress"}, |