diff options
Diffstat (limited to 'src/core/hle/svc.cpp')
| -rw-r--r-- | src/core/hle/svc.cpp | 49 |
1 files changed, 37 insertions, 12 deletions
diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index 60c8747f3..3a53126c1 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp | |||
| @@ -99,6 +99,7 @@ static ResultCode ControlMemory(u32* out_addr, u32 operation, u32 addr0, u32 add | |||
| 99 | switch (operation & MEMOP_OPERATION_MASK) { | 99 | switch (operation & MEMOP_OPERATION_MASK) { |
| 100 | case MEMOP_FREE: | 100 | case MEMOP_FREE: |
| 101 | { | 101 | { |
| 102 | // TODO(Subv): What happens if an application tries to FREE a block of memory that has a SharedMemory pointing to it? | ||
| 102 | if (addr0 >= Memory::HEAP_VADDR && addr0 < Memory::HEAP_VADDR_END) { | 103 | if (addr0 >= Memory::HEAP_VADDR && addr0 < Memory::HEAP_VADDR_END) { |
| 103 | ResultCode result = process.HeapFree(addr0, size); | 104 | ResultCode result = process.HeapFree(addr0, size); |
| 104 | if (result.IsError()) return result; | 105 | if (result.IsError()) return result; |
| @@ -160,8 +161,6 @@ static ResultCode MapMemoryBlock(Handle handle, u32 addr, u32 permissions, u32 o | |||
| 160 | LOG_TRACE(Kernel_SVC, "called memblock=0x%08X, addr=0x%08X, mypermissions=0x%08X, otherpermission=%d", | 161 | LOG_TRACE(Kernel_SVC, "called memblock=0x%08X, addr=0x%08X, mypermissions=0x%08X, otherpermission=%d", |
| 161 | handle, addr, permissions, other_permissions); | 162 | handle, addr, permissions, other_permissions); |
| 162 | 163 | ||
| 163 | // TODO(Subv): The same process that created a SharedMemory object can not map it in its own address space | ||
| 164 | |||
| 165 | SharedPtr<SharedMemory> shared_memory = Kernel::g_handle_table.Get<SharedMemory>(handle); | 164 | SharedPtr<SharedMemory> shared_memory = Kernel::g_handle_table.Get<SharedMemory>(handle); |
| 166 | if (shared_memory == nullptr) | 165 | if (shared_memory == nullptr) |
| 167 | return ERR_INVALID_HANDLE; | 166 | return ERR_INVALID_HANDLE; |
| @@ -176,7 +175,7 @@ static ResultCode MapMemoryBlock(Handle handle, u32 addr, u32 permissions, u32 o | |||
| 176 | case MemoryPermission::WriteExecute: | 175 | case MemoryPermission::WriteExecute: |
| 177 | case MemoryPermission::ReadWriteExecute: | 176 | case MemoryPermission::ReadWriteExecute: |
| 178 | case MemoryPermission::DontCare: | 177 | case MemoryPermission::DontCare: |
| 179 | return shared_memory->Map(addr, permissions_type, | 178 | return shared_memory->Map(Kernel::g_current_process.get(), addr, permissions_type, |
| 180 | static_cast<MemoryPermission>(other_permissions)); | 179 | static_cast<MemoryPermission>(other_permissions)); |
| 181 | default: | 180 | default: |
| 182 | LOG_ERROR(Kernel_SVC, "unknown permissions=0x%08X", permissions); | 181 | LOG_ERROR(Kernel_SVC, "unknown permissions=0x%08X", permissions); |
| @@ -196,7 +195,7 @@ static ResultCode UnmapMemoryBlock(Handle handle, u32 addr) { | |||
| 196 | if (shared_memory == nullptr) | 195 | if (shared_memory == nullptr) |
| 197 | return ERR_INVALID_HANDLE; | 196 | return ERR_INVALID_HANDLE; |
| 198 | 197 | ||
| 199 | return shared_memory->Unmap(addr); | 198 | return shared_memory->Unmap(Kernel::g_current_process.get(), addr); |
| 200 | } | 199 | } |
| 201 | 200 | ||
| 202 | /// Connect to an OS service given the port name, returns the handle to the port to out | 201 | /// Connect to an OS service given the port name, returns the handle to the port to out |
| @@ -790,18 +789,44 @@ static ResultCode CreateMemoryBlock(Handle* out_handle, u32 addr, u32 size, u32 | |||
| 790 | if (size % Memory::PAGE_SIZE != 0) | 789 | if (size % Memory::PAGE_SIZE != 0) |
| 791 | return ResultCode(ErrorDescription::MisalignedSize, ErrorModule::OS, ErrorSummary::InvalidArgument, ErrorLevel::Usage); | 790 | return ResultCode(ErrorDescription::MisalignedSize, ErrorModule::OS, ErrorSummary::InvalidArgument, ErrorLevel::Usage); |
| 792 | 791 | ||
| 793 | // TODO(Subv): Return E0A01BF5 if the address is not in the application's heap | 792 | SharedPtr<SharedMemory> shared_memory = nullptr; |
| 794 | |||
| 795 | // TODO(Subv): Implement this function properly | ||
| 796 | 793 | ||
| 797 | using Kernel::MemoryPermission; | 794 | using Kernel::MemoryPermission; |
| 798 | SharedPtr<SharedMemory> shared_memory = SharedMemory::Create(size, | 795 | auto VerifyPermissions = [](MemoryPermission permission) { |
| 799 | (MemoryPermission)my_permission, (MemoryPermission)other_permission); | 796 | // SharedMemory blocks can not be created with Execute permissions |
| 800 | // Map the SharedMemory to the specified address | 797 | switch (permission) { |
| 801 | shared_memory->base_address = addr; | 798 | case MemoryPermission::None: |
| 799 | case MemoryPermission::Read: | ||
| 800 | case MemoryPermission::Write: | ||
| 801 | case MemoryPermission::ReadWrite: | ||
| 802 | case MemoryPermission::DontCare: | ||
| 803 | return true; | ||
| 804 | default: | ||
| 805 | return false; | ||
| 806 | } | ||
| 807 | }; | ||
| 808 | |||
| 809 | if (!VerifyPermissions(static_cast<MemoryPermission>(my_permission)) || | ||
| 810 | !VerifyPermissions(static_cast<MemoryPermission>(other_permission))) | ||
| 811 | return ResultCode(ErrorDescription::InvalidCombination, ErrorModule::OS, | ||
| 812 | ErrorSummary::InvalidArgument, ErrorLevel::Usage); | ||
| 813 | |||
| 814 | if (addr < Memory::PROCESS_IMAGE_VADDR || addr + size > Memory::SHARED_MEMORY_VADDR_END) { | ||
| 815 | return ResultCode(ErrorDescription::InvalidAddress, ErrorModule::OS, ErrorSummary::InvalidArgument, ErrorLevel::Usage); | ||
| 816 | } | ||
| 817 | |||
| 818 | // When trying to create a memory block with address = 0, | ||
| 819 | // if the process has the Shared Device Memory flag in the exheader, | ||
| 820 | // then we have to allocate from the same region as the caller process instead of the BASE region. | ||
| 821 | Kernel::MemoryRegion region = Kernel::MemoryRegion::BASE; | ||
| 822 | if (addr == 0 && Kernel::g_current_process->flags.shared_device_mem) | ||
| 823 | region = Kernel::g_current_process->flags.memory_region; | ||
| 824 | |||
| 825 | shared_memory = SharedMemory::Create(Kernel::g_current_process, size, | ||
| 826 | static_cast<MemoryPermission>(my_permission), static_cast<MemoryPermission>(other_permission), addr, region); | ||
| 802 | CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(shared_memory))); | 827 | CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(shared_memory))); |
| 803 | 828 | ||
| 804 | LOG_WARNING(Kernel_SVC, "(STUBBED) called addr=0x%08X", addr); | 829 | LOG_WARNING(Kernel_SVC, "called addr=0x%08X", addr); |
| 805 | return RESULT_SUCCESS; | 830 | return RESULT_SUCCESS; |
| 806 | } | 831 | } |
| 807 | 832 | ||