diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/function_wrappers.h | 4 | ||||
| -rw-r--r-- | src/core/hle/kernel/shared_memory.cpp | 21 | ||||
| -rw-r--r-- | src/core/hle/kernel/shared_memory.h | 7 | ||||
| -rw-r--r-- | src/core/hle/result.h | 1 | ||||
| -rw-r--r-- | src/core/hle/svc.cpp | 32 |
5 files changed, 60 insertions, 5 deletions
diff --git a/src/core/hle/function_wrappers.h b/src/core/hle/function_wrappers.h index 3501e45db..882a51df1 100644 --- a/src/core/hle/function_wrappers.h +++ b/src/core/hle/function_wrappers.h | |||
| @@ -188,6 +188,10 @@ template<ResultCode func(s64*, Handle, u32)> void Wrap() { | |||
| 188 | FuncReturn(retval); | 188 | FuncReturn(retval); |
| 189 | } | 189 | } |
| 190 | 190 | ||
| 191 | template<ResultCode func(Handle, u32)> void Wrap() { | ||
| 192 | FuncReturn(func(PARAM(0), PARAM(1)).raw); | ||
| 193 | } | ||
| 194 | |||
| 191 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 195 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 192 | // Function wrappers that return type u32 | 196 | // Function wrappers that return type u32 |
| 193 | 197 | ||
diff --git a/src/core/hle/kernel/shared_memory.cpp b/src/core/hle/kernel/shared_memory.cpp index 1f477664b..d90f0f00f 100644 --- a/src/core/hle/kernel/shared_memory.cpp +++ b/src/core/hle/kernel/shared_memory.cpp | |||
| @@ -39,6 +39,12 @@ ResultCode SharedMemory::Map(VAddr address, MemoryPermission permissions, | |||
| 39 | ErrorSummary::InvalidArgument, ErrorLevel::Permanent); | 39 | ErrorSummary::InvalidArgument, ErrorLevel::Permanent); |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | // TODO(Subv): Return E0E01BEE when permissions and other_permissions don't | ||
| 43 | // match what was specified when the memory block was created. | ||
| 44 | |||
| 45 | // TODO(Subv): Return E0E01BEE when address should be 0. | ||
| 46 | // Note: Find out when that's the case. | ||
| 47 | |||
| 42 | if (fixed_address != 0) { | 48 | if (fixed_address != 0) { |
| 43 | if (address != 0 && address != fixed_address) { | 49 | if (address != 0 && address != fixed_address) { |
| 44 | LOG_ERROR(Kernel, "cannot map id=%u, address=0x%08X name=%s: fixed_addres is 0x%08X!", | 50 | LOG_ERROR(Kernel, "cannot map id=%u, address=0x%08X name=%s: fixed_addres is 0x%08X!", |
| @@ -74,6 +80,21 @@ ResultCode SharedMemory::Map(VAddr address, MemoryPermission permissions, | |||
| 74 | return RESULT_SUCCESS; | 80 | return RESULT_SUCCESS; |
| 75 | } | 81 | } |
| 76 | 82 | ||
| 83 | ResultCode SharedMemory::Unmap(VAddr address) { | ||
| 84 | if (base_address == 0) { | ||
| 85 | // TODO(Subv): Verify what actually happens when you want to unmap a memory block that | ||
| 86 | // was originally mapped with address = 0 | ||
| 87 | return ResultCode(ErrorDescription::InvalidAddress, ErrorModule::OS, ErrorSummary::InvalidArgument, ErrorLevel::Usage); | ||
| 88 | } | ||
| 89 | |||
| 90 | if (base_address != address) | ||
| 91 | return ResultCode(ErrorDescription::WrongAddress, ErrorModule::OS, ErrorSummary::InvalidState, ErrorLevel::Usage); | ||
| 92 | |||
| 93 | base_address = 0; | ||
| 94 | |||
| 95 | return RESULT_SUCCESS; | ||
| 96 | } | ||
| 97 | |||
| 77 | u8* SharedMemory::GetPointer(u32 offset) { | 98 | u8* SharedMemory::GetPointer(u32 offset) { |
| 78 | if (base_address != 0) | 99 | if (base_address != 0) |
| 79 | return Memory::GetPointer(base_address + offset); | 100 | return Memory::GetPointer(base_address + offset); |
diff --git a/src/core/hle/kernel/shared_memory.h b/src/core/hle/kernel/shared_memory.h index 35b550d12..b51049ad0 100644 --- a/src/core/hle/kernel/shared_memory.h +++ b/src/core/hle/kernel/shared_memory.h | |||
| @@ -53,6 +53,13 @@ public: | |||
| 53 | ResultCode Map(VAddr address, MemoryPermission permissions, MemoryPermission other_permissions); | 53 | ResultCode Map(VAddr address, MemoryPermission permissions, MemoryPermission other_permissions); |
| 54 | 54 | ||
| 55 | /** | 55 | /** |
| 56 | * Unmaps a shared memory block from the specified address in system memory | ||
| 57 | * @param address Address in system memory where the shared memory block is mapped | ||
| 58 | * @return Result code of the unmap operation | ||
| 59 | */ | ||
| 60 | ResultCode Unmap(VAddr address); | ||
| 61 | |||
| 62 | /** | ||
| 56 | * Gets a pointer to the shared memory block | 63 | * Gets a pointer to the shared memory block |
| 57 | * @param offset Offset from the start of the shared memory block to get pointer | 64 | * @param offset Offset from the start of the shared memory block to get pointer |
| 58 | * @return Pointer to the shared memory block from the specified offset | 65 | * @return Pointer to the shared memory block from the specified offset |
diff --git a/src/core/hle/result.h b/src/core/hle/result.h index cb2d681e0..ea3abb5f6 100644 --- a/src/core/hle/result.h +++ b/src/core/hle/result.h | |||
| @@ -18,6 +18,7 @@ | |||
| 18 | /// Detailed description of the error. This listing is likely incomplete. | 18 | /// Detailed description of the error. This listing is likely incomplete. |
| 19 | enum class ErrorDescription : u32 { | 19 | enum class ErrorDescription : u32 { |
| 20 | Success = 0, | 20 | Success = 0, |
| 21 | WrongAddress = 53, | ||
| 21 | FS_NotFound = 100, | 22 | FS_NotFound = 100, |
| 22 | FS_NotFormatted = 340, ///< This is used by the FS service when creating a SaveData archive | 23 | FS_NotFormatted = 340, ///< This is used by the FS service when creating a SaveData archive |
| 23 | InvalidSection = 1000, | 24 | InvalidSection = 1000, |
diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index e39edcc16..ba21e06d5 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp | |||
| @@ -161,6 +161,8 @@ static ResultCode MapMemoryBlock(Handle handle, u32 addr, u32 permissions, u32 o | |||
| 161 | 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", |
| 162 | handle, addr, permissions, other_permissions); | 162 | handle, addr, permissions, other_permissions); |
| 163 | 163 | ||
| 164 | // TODO(Subv): The same process that created a SharedMemory object can not map it in its own address space | ||
| 165 | |||
| 164 | SharedPtr<SharedMemory> shared_memory = Kernel::g_handle_table.Get<SharedMemory>(handle); | 166 | SharedPtr<SharedMemory> shared_memory = Kernel::g_handle_table.Get<SharedMemory>(handle); |
| 165 | if (shared_memory == nullptr) | 167 | if (shared_memory == nullptr) |
| 166 | return ERR_INVALID_HANDLE; | 168 | return ERR_INVALID_HANDLE; |
| @@ -175,13 +177,27 @@ static ResultCode MapMemoryBlock(Handle handle, u32 addr, u32 permissions, u32 o | |||
| 175 | case MemoryPermission::WriteExecute: | 177 | case MemoryPermission::WriteExecute: |
| 176 | case MemoryPermission::ReadWriteExecute: | 178 | case MemoryPermission::ReadWriteExecute: |
| 177 | case MemoryPermission::DontCare: | 179 | case MemoryPermission::DontCare: |
| 178 | shared_memory->Map(addr, permissions_type, | 180 | return shared_memory->Map(addr, permissions_type, |
| 179 | static_cast<MemoryPermission>(other_permissions)); | 181 | static_cast<MemoryPermission>(other_permissions)); |
| 180 | break; | ||
| 181 | default: | 182 | default: |
| 182 | LOG_ERROR(Kernel_SVC, "unknown permissions=0x%08X", permissions); | 183 | LOG_ERROR(Kernel_SVC, "unknown permissions=0x%08X", permissions); |
| 183 | } | 184 | } |
| 184 | return RESULT_SUCCESS; | 185 | |
| 186 | return ResultCode(ErrorDescription::InvalidCombination, ErrorModule::OS, ErrorSummary::InvalidArgument, ErrorLevel::Usage); | ||
| 187 | } | ||
| 188 | |||
| 189 | static ResultCode UnmapMemoryBlock(Handle handle, u32 addr) { | ||
| 190 | using Kernel::SharedMemory; | ||
| 191 | |||
| 192 | LOG_TRACE(Kernel_SVC, "called memblock=0x%08X, addr=0x%08X", handle, addr); | ||
| 193 | |||
| 194 | // TODO(Subv): Return E0A01BF5 if the address is not in the application's heap | ||
| 195 | |||
| 196 | SharedPtr<SharedMemory> shared_memory = Kernel::g_handle_table.Get<SharedMemory>(handle); | ||
| 197 | if (shared_memory == nullptr) | ||
| 198 | return ERR_INVALID_HANDLE; | ||
| 199 | |||
| 200 | return shared_memory->Unmap(addr); | ||
| 185 | } | 201 | } |
| 186 | 202 | ||
| 187 | /// Connect to an OS service given the port name, returns the handle to the port to out | 203 | /// Connect to an OS service given the port name, returns the handle to the port to out |
| @@ -765,7 +781,13 @@ static s64 GetSystemTick() { | |||
| 765 | static ResultCode CreateMemoryBlock(Handle* out_handle, u32 addr, u32 size, u32 my_permission, | 781 | static ResultCode CreateMemoryBlock(Handle* out_handle, u32 addr, u32 size, u32 my_permission, |
| 766 | u32 other_permission) { | 782 | u32 other_permission) { |
| 767 | using Kernel::SharedMemory; | 783 | using Kernel::SharedMemory; |
| 768 | // TODO(Subv): Implement this function | 784 | |
| 785 | if (size % Memory::PAGE_SIZE != 0) | ||
| 786 | return ResultCode(ErrorDescription::MisalignedSize, ErrorModule::OS, ErrorSummary::InvalidArgument, ErrorLevel::Usage); | ||
| 787 | |||
| 788 | // TODO(Subv): Return E0A01BF5 if the address is not in the application's heap | ||
| 789 | |||
| 790 | // TODO(Subv): Implement this function properly | ||
| 769 | 791 | ||
| 770 | using Kernel::MemoryPermission; | 792 | using Kernel::MemoryPermission; |
| 771 | SharedPtr<SharedMemory> shared_memory = SharedMemory::Create(size, | 793 | SharedPtr<SharedMemory> shared_memory = SharedMemory::Create(size, |
| @@ -912,7 +934,7 @@ static const FunctionDef SVC_Table[] = { | |||
| 912 | {0x1D, HLE::Wrap<ClearTimer>, "ClearTimer"}, | 934 | {0x1D, HLE::Wrap<ClearTimer>, "ClearTimer"}, |
| 913 | {0x1E, HLE::Wrap<CreateMemoryBlock>, "CreateMemoryBlock"}, | 935 | {0x1E, HLE::Wrap<CreateMemoryBlock>, "CreateMemoryBlock"}, |
| 914 | {0x1F, HLE::Wrap<MapMemoryBlock>, "MapMemoryBlock"}, | 936 | {0x1F, HLE::Wrap<MapMemoryBlock>, "MapMemoryBlock"}, |
| 915 | {0x20, nullptr, "UnmapMemoryBlock"}, | 937 | {0x20, HLE::Wrap<UnmapMemoryBlock>, "UnmapMemoryBlock"}, |
| 916 | {0x21, HLE::Wrap<CreateAddressArbiter>, "CreateAddressArbiter"}, | 938 | {0x21, HLE::Wrap<CreateAddressArbiter>, "CreateAddressArbiter"}, |
| 917 | {0x22, HLE::Wrap<ArbitrateAddress>, "ArbitrateAddress"}, | 939 | {0x22, HLE::Wrap<ArbitrateAddress>, "ArbitrateAddress"}, |
| 918 | {0x23, HLE::Wrap<CloseHandle>, "CloseHandle"}, | 940 | {0x23, HLE::Wrap<CloseHandle>, "CloseHandle"}, |