diff options
| author | 2014-07-05 00:55:39 -0400 | |
|---|---|---|
| committer | 2014-07-05 01:21:05 -0400 | |
| commit | e547128185c7bc1c2081d3ee25b6207f4d24509b (patch) | |
| tree | e11e7eacfa9898ca828b883da2ca32d482a65c69 /src/core/hle/kernel | |
| parent | mem_map: Updated interface to expose template functions to other modules. (diff) | |
| download | yuzu-e547128185c7bc1c2081d3ee25b6207f4d24509b.tar.gz yuzu-e547128185c7bc1c2081d3ee25b6207f4d24509b.tar.xz yuzu-e547128185c7bc1c2081d3ee25b6207f4d24509b.zip | |
Kernel: Added support for shared memory objects.
SharedMemory: Added optional name field for tracking known objects.
Diffstat (limited to 'src/core/hle/kernel')
| -rw-r--r-- | src/core/hle/kernel/shared_memory.cpp | 94 | ||||
| -rw-r--r-- | src/core/hle/kernel/shared_memory.h | 38 |
2 files changed, 132 insertions, 0 deletions
diff --git a/src/core/hle/kernel/shared_memory.cpp b/src/core/hle/kernel/shared_memory.cpp new file mode 100644 index 000000000..3030d66fa --- /dev/null +++ b/src/core/hle/kernel/shared_memory.cpp | |||
| @@ -0,0 +1,94 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "common/common.h" | ||
| 6 | |||
| 7 | #include "core/mem_map.h" | ||
| 8 | #include "core/hle/kernel/shared_memory.h" | ||
| 9 | |||
| 10 | namespace Kernel { | ||
| 11 | |||
| 12 | class SharedMemory : public Object { | ||
| 13 | public: | ||
| 14 | const char* GetTypeName() const { return "SharedMemory"; } | ||
| 15 | |||
| 16 | static Kernel::HandleType GetStaticHandleType() { return Kernel::HandleType::SharedMemory; } | ||
| 17 | Kernel::HandleType GetHandleType() const { return Kernel::HandleType::SharedMemory; } | ||
| 18 | |||
| 19 | /** | ||
| 20 | * Wait for kernel object to synchronize | ||
| 21 | * @param wait Boolean wait set if current thread should wait as a result of sync operation | ||
| 22 | * @return Result of operation, 0 on success, otherwise error code | ||
| 23 | */ | ||
| 24 | Result WaitSynchronization(bool* wait) { | ||
| 25 | // TODO(bunnei): ImplementMe | ||
| 26 | ERROR_LOG(OSHLE, "(UNIMPLEMENTED)"); | ||
| 27 | return 0; | ||
| 28 | } | ||
| 29 | |||
| 30 | u32 base_address; ///< Address of shared memory block in RAM | ||
| 31 | u32 permissions; ///< Permissions of shared memory block (specified by SVC field) | ||
| 32 | u32 other_permissions; ///< Other permissions of shared memory block (specified by SVC field) | ||
| 33 | std::string name; ///< Name of shared memory object (optional) | ||
| 34 | }; | ||
| 35 | |||
| 36 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 37 | |||
| 38 | /** | ||
| 39 | * Creates a shared memory object | ||
| 40 | * @param handle Handle of newly created shared memory object | ||
| 41 | * @param name Name of shared memory object | ||
| 42 | * @return Pointer to newly created shared memory object | ||
| 43 | */ | ||
| 44 | SharedMemory* CreateSharedMemory(Handle& handle, const std::string& name) { | ||
| 45 | SharedMemory* shared_memory = new SharedMemory; | ||
| 46 | handle = Kernel::g_object_pool.Create(shared_memory); | ||
| 47 | shared_memory->name = name; | ||
| 48 | return shared_memory; | ||
| 49 | } | ||
| 50 | |||
| 51 | /** | ||
| 52 | * Creates a shared memory object | ||
| 53 | * @param name Optional name of shared memory object | ||
| 54 | * @return Handle of newly created shared memory object | ||
| 55 | */ | ||
| 56 | Handle CreateSharedMemory(const std::string& name) { | ||
| 57 | Handle handle; | ||
| 58 | CreateSharedMemory(handle, name); | ||
| 59 | return handle; | ||
| 60 | } | ||
| 61 | |||
| 62 | /** | ||
| 63 | * Maps a shared memory block to an address in system memory | ||
| 64 | * @param handle Shared memory block handle | ||
| 65 | * @param address Address in system memory to map shared memory block to | ||
| 66 | * @param permissions Memory block map permissions (specified by SVC field) | ||
| 67 | * @param other_permissions Memory block map other permissions (specified by SVC field) | ||
| 68 | * @return Result of operation, 0 on success, otherwise error code | ||
| 69 | */ | ||
| 70 | Result MapSharedMemory(u32 handle, u32 address, u32 permissions, u32 other_permissions) { | ||
| 71 | SharedMemory* shared_memory = Kernel::g_object_pool.GetFast<SharedMemory>(handle); | ||
| 72 | shared_memory->base_address = address; | ||
| 73 | shared_memory->permissions = permissions; | ||
| 74 | shared_memory->other_permissions = other_permissions; | ||
| 75 | return 0; | ||
| 76 | } | ||
| 77 | |||
| 78 | /** | ||
| 79 | * Gets a pointer to the shared memory block | ||
| 80 | * @param handle Shared memory block handle | ||
| 81 | * @param offset Offset from the start of the shared memory block to get pointer | ||
| 82 | * @return Pointer to the shared memory block from the specified offset | ||
| 83 | */ | ||
| 84 | u8* GetSharedMemoryPointer(Handle handle, u32 offset) { | ||
| 85 | SharedMemory* shared_memory = Kernel::g_object_pool.GetFast<SharedMemory>(handle); | ||
| 86 | _assert_msg_(KERNEL, (shared_memory != nullptr), "handle 0x%08X is not valid!", handle); | ||
| 87 | if (0 != shared_memory->base_address) | ||
| 88 | return Memory::GetPointer(shared_memory->base_address + offset); | ||
| 89 | |||
| 90 | ERROR_LOG(KERNEL, "memory block handle=0x%08X not mapped!", handle); | ||
| 91 | return nullptr; | ||
| 92 | } | ||
| 93 | |||
| 94 | } // namespace | ||
diff --git a/src/core/hle/kernel/shared_memory.h b/src/core/hle/kernel/shared_memory.h new file mode 100644 index 000000000..4e235f605 --- /dev/null +++ b/src/core/hle/kernel/shared_memory.h | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "common/common_types.h" | ||
| 8 | |||
| 9 | #include "core/hle/kernel/kernel.h" | ||
| 10 | |||
| 11 | namespace Kernel { | ||
| 12 | |||
| 13 | /** | ||
| 14 | * Creates a shared memory object | ||
| 15 | * @param name Optional name of shared memory object | ||
| 16 | * @return Handle of newly created shared memory object | ||
| 17 | */ | ||
| 18 | Handle CreateSharedMemory(const std::string& name="Unknown"); | ||
| 19 | |||
| 20 | /** | ||
| 21 | * Maps a shared memory block to an address in system memory | ||
| 22 | * @param handle Shared memory block handle | ||
| 23 | * @param address Address in system memory to map shared memory block to | ||
| 24 | * @param permissions Memory block map permissions (specified by SVC field) | ||
| 25 | * @param other_permissions Memory block map other permissions (specified by SVC field) | ||
| 26 | * @return Result of operation, 0 on success, otherwise error code | ||
| 27 | */ | ||
| 28 | Result MapSharedMemory(u32 handle, u32 address, u32 permissions, u32 other_permissions); | ||
| 29 | |||
| 30 | /** | ||
| 31 | * Gets a pointer to the shared memory block | ||
| 32 | * @param handle Shared memory block handle | ||
| 33 | * @param offset Offset from the start of the shared memory block to get pointer | ||
| 34 | * @return Pointer to the shared memory block from the specified offset | ||
| 35 | */ | ||
| 36 | u8* GetSharedMemoryPointer(Handle handle, u32 offset); | ||
| 37 | |||
| 38 | } // namespace | ||