diff options
Diffstat (limited to 'src/core/hle/kernel')
| -rw-r--r-- | src/core/hle/kernel/shared_memory.cpp | 65 | ||||
| -rw-r--r-- | src/core/hle/kernel/shared_memory.h | 60 |
2 files changed, 54 insertions, 71 deletions
diff --git a/src/core/hle/kernel/shared_memory.cpp b/src/core/hle/kernel/shared_memory.cpp index fa8fc6f92..536d134b0 100644 --- a/src/core/hle/kernel/shared_memory.cpp +++ b/src/core/hle/kernel/shared_memory.cpp | |||
| @@ -9,68 +9,39 @@ | |||
| 9 | 9 | ||
| 10 | namespace Kernel { | 10 | namespace Kernel { |
| 11 | 11 | ||
| 12 | class SharedMemory : public Object { | 12 | ResultVal<SharedPtr<SharedMemory>> SharedMemory::Create(std::string name) { |
| 13 | public: | 13 | SharedPtr<SharedMemory> shared_memory(new SharedMemory); |
| 14 | std::string GetTypeName() const override { return "SharedMemory"; } | ||
| 15 | 14 | ||
| 16 | static const HandleType HANDLE_TYPE = HandleType::SharedMemory; | 15 | // TOOD(yuriks): Don't create Handle (see Thread::Create()) |
| 17 | HandleType GetHandleType() const override { return HANDLE_TYPE; } | 16 | CASCADE_RESULT(auto unused, Kernel::g_handle_table.Create(shared_memory)); |
| 18 | 17 | ||
| 19 | u32 base_address; ///< Address of shared memory block in RAM | 18 | shared_memory->name = std::move(name); |
| 20 | MemoryPermission permissions; ///< Permissions of shared memory block (SVC field) | 19 | return MakeResult<SharedPtr<SharedMemory>>(std::move(shared_memory)); |
| 21 | MemoryPermission other_permissions; ///< Other permissions of shared memory block (SVC field) | ||
| 22 | std::string name; ///< Name of shared memory object (optional) | ||
| 23 | }; | ||
| 24 | |||
| 25 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 26 | |||
| 27 | /** | ||
| 28 | * Creates a shared memory object | ||
| 29 | * @param handle Handle of newly created shared memory object | ||
| 30 | * @param name Name of shared memory object | ||
| 31 | * @return Pointer to newly created shared memory object | ||
| 32 | */ | ||
| 33 | static SharedMemory* CreateSharedMemory(Handle& handle, const std::string& name) { | ||
| 34 | SharedMemory* shared_memory = new SharedMemory; | ||
| 35 | // TOOD(yuriks): Fix error reporting | ||
| 36 | handle = Kernel::g_handle_table.Create(shared_memory).ValueOr(INVALID_HANDLE); | ||
| 37 | shared_memory->name = name; | ||
| 38 | return shared_memory; | ||
| 39 | } | 20 | } |
| 40 | 21 | ||
| 41 | Handle CreateSharedMemory(const std::string& name) { | 22 | ResultCode SharedMemory::Map(VAddr address, MemoryPermission permissions, |
| 42 | Handle handle; | 23 | MemoryPermission other_permissions) { |
| 43 | CreateSharedMemory(handle, name); | ||
| 44 | return handle; | ||
| 45 | } | ||
| 46 | |||
| 47 | ResultCode MapSharedMemory(u32 handle, u32 address, MemoryPermission permissions, | ||
| 48 | MemoryPermission other_permissions) { | ||
| 49 | 24 | ||
| 50 | if (address < Memory::SHARED_MEMORY_VADDR || address >= Memory::SHARED_MEMORY_VADDR_END) { | 25 | if (address < Memory::SHARED_MEMORY_VADDR || address >= Memory::SHARED_MEMORY_VADDR_END) { |
| 51 | LOG_ERROR(Kernel_SVC, "cannot map handle=0x%08X, address=0x%08X outside of shared mem bounds!", | 26 | LOG_ERROR(Kernel, "cannot map handle=0x%08X, address=0x%08X outside of shared mem bounds!", |
| 52 | handle, address); | 27 | GetHandle(), address); |
| 28 | // TODO: Verify error code with hardware | ||
| 53 | return ResultCode(ErrorDescription::InvalidAddress, ErrorModule::Kernel, | 29 | return ResultCode(ErrorDescription::InvalidAddress, ErrorModule::Kernel, |
| 54 | ErrorSummary::InvalidArgument, ErrorLevel::Permanent); | 30 | ErrorSummary::InvalidArgument, ErrorLevel::Permanent); |
| 55 | } | 31 | } |
| 56 | SharedMemory* shared_memory = Kernel::g_handle_table.Get<SharedMemory>(handle).get(); | ||
| 57 | if (shared_memory == nullptr) return InvalidHandle(ErrorModule::Kernel); | ||
| 58 | 32 | ||
| 59 | shared_memory->base_address = address; | 33 | base_address = address; |
| 60 | shared_memory->permissions = permissions; | 34 | permissions = permissions; |
| 61 | shared_memory->other_permissions = other_permissions; | 35 | other_permissions = other_permissions; |
| 62 | 36 | ||
| 63 | return RESULT_SUCCESS; | 37 | return RESULT_SUCCESS; |
| 64 | } | 38 | } |
| 65 | 39 | ||
| 66 | ResultVal<u8*> GetSharedMemoryPointer(Handle handle, u32 offset) { | 40 | ResultVal<u8*> SharedMemory::GetPointer(u32 offset) { |
| 67 | SharedMemory* shared_memory = Kernel::g_handle_table.Get<SharedMemory>(handle).get(); | 41 | if (base_address != 0) |
| 68 | if (shared_memory == nullptr) return InvalidHandle(ErrorModule::Kernel); | 42 | return MakeResult<u8*>(Memory::GetPointer(base_address + offset)); |
| 69 | |||
| 70 | if (0 != shared_memory->base_address) | ||
| 71 | return MakeResult<u8*>(Memory::GetPointer(shared_memory->base_address + offset)); | ||
| 72 | 43 | ||
| 73 | LOG_ERROR(Kernel_SVC, "memory block handle=0x%08X not mapped!", handle); | 44 | LOG_ERROR(Kernel_SVC, "memory block handle=0x%08X not mapped!", GetHandle()); |
| 74 | // TODO(yuriks): Verify error code. | 45 | // TODO(yuriks): Verify error code. |
| 75 | return ResultCode(ErrorDescription::InvalidAddress, ErrorModule::Kernel, | 46 | return ResultCode(ErrorDescription::InvalidAddress, ErrorModule::Kernel, |
| 76 | ErrorSummary::InvalidState, ErrorLevel::Permanent); | 47 | ErrorSummary::InvalidState, ErrorLevel::Permanent); |
diff --git a/src/core/hle/kernel/shared_memory.h b/src/core/hle/kernel/shared_memory.h index bb65c7ccd..eb063d39d 100644 --- a/src/core/hle/kernel/shared_memory.h +++ b/src/core/hle/kernel/shared_memory.h | |||
| @@ -23,29 +23,41 @@ enum class MemoryPermission : u32 { | |||
| 23 | DontCare = (1u << 28) | 23 | DontCare = (1u << 28) |
| 24 | }; | 24 | }; |
| 25 | 25 | ||
| 26 | /** | 26 | class SharedMemory : public Object { |
| 27 | * Creates a shared memory object | 27 | public: |
| 28 | * @param name Optional name of shared memory object | 28 | /** |
| 29 | * @return Handle of newly created shared memory object | 29 | * Creates a shared memory object |
| 30 | */ | 30 | * @param name Optional object name, used only for debugging purposes. |
| 31 | Handle CreateSharedMemory(const std::string& name="Unknown"); | 31 | */ |
| 32 | 32 | static ResultVal<SharedPtr<SharedMemory>> Create(std::string name = "Unknown"); | |
| 33 | /** | 33 | |
| 34 | * Maps a shared memory block to an address in system memory | 34 | std::string GetTypeName() const override { return "SharedMemory"; } |
| 35 | * @param handle Shared memory block handle | 35 | |
| 36 | * @param address Address in system memory to map shared memory block to | 36 | static const HandleType HANDLE_TYPE = HandleType::SharedMemory; |
| 37 | * @param permissions Memory block map permissions (specified by SVC field) | 37 | HandleType GetHandleType() const override { return HANDLE_TYPE; } |
| 38 | * @param other_permissions Memory block map other permissions (specified by SVC field) | 38 | |
| 39 | */ | 39 | /** |
| 40 | ResultCode MapSharedMemory(Handle handle, u32 address, MemoryPermission permissions, | 40 | * Maps a shared memory block to an address in system memory |
| 41 | MemoryPermission other_permissions); | 41 | * @param address Address in system memory to map shared memory block to |
| 42 | 42 | * @param permissions Memory block map permissions (specified by SVC field) | |
| 43 | /** | 43 | * @param other_permissions Memory block map other permissions (specified by SVC field) |
| 44 | * Gets a pointer to the shared memory block | 44 | */ |
| 45 | * @param handle Shared memory block handle | 45 | ResultCode Map(VAddr address, MemoryPermission permissions, MemoryPermission other_permissions); |
| 46 | * @param offset Offset from the start of the shared memory block to get pointer | 46 | |
| 47 | * @return Pointer to the shared memory block from the specified offset | 47 | /** |
| 48 | */ | 48 | * Gets a pointer to the shared memory block |
| 49 | ResultVal<u8*> GetSharedMemoryPointer(Handle handle, u32 offset); | 49 | * @param offset Offset from the start of the shared memory block to get pointer |
| 50 | * @return Pointer to the shared memory block from the specified offset | ||
| 51 | */ | ||
| 52 | ResultVal<u8*> GetPointer(u32 offset = 0); | ||
| 53 | |||
| 54 | VAddr base_address; ///< Address of shared memory block in RAM | ||
| 55 | MemoryPermission permissions; ///< Permissions of shared memory block (SVC field) | ||
| 56 | MemoryPermission other_permissions; ///< Other permissions of shared memory block (SVC field) | ||
| 57 | std::string name; ///< Name of shared memory object (optional) | ||
| 58 | |||
| 59 | private: | ||
| 60 | SharedMemory() = default; | ||
| 61 | }; | ||
| 50 | 62 | ||
| 51 | } // namespace | 63 | } // namespace |