diff options
author | bunnei <bunneidev@gmail.com> | 2014-07-05 06:55:39 +0200 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2014-07-05 07:21:05 +0200 |
commit | e547128185c7bc1c2081d3ee25b6207f4d24509b (patch) | |
tree | e11e7eacfa9898ca828b883da2ca32d482a65c69 | |
parent | mem_map: Updated interface to expose template functions to other modules. (diff) | |
download | yuzu-e547128185c7bc1c2081d3ee25b6207f4d24509b.tar yuzu-e547128185c7bc1c2081d3ee25b6207f4d24509b.tar.gz yuzu-e547128185c7bc1c2081d3ee25b6207f4d24509b.tar.bz2 yuzu-e547128185c7bc1c2081d3ee25b6207f4d24509b.tar.lz yuzu-e547128185c7bc1c2081d3ee25b6207f4d24509b.tar.xz yuzu-e547128185c7bc1c2081d3ee25b6207f4d24509b.tar.zst yuzu-e547128185c7bc1c2081d3ee25b6207f4d24509b.zip |
-rw-r--r-- | src/core/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/core/core.vcxproj | 2 | ||||
-rw-r--r-- | src/core/core.vcxproj.filters | 6 | ||||
-rw-r--r-- | src/core/hle/kernel/shared_memory.cpp | 94 | ||||
-rw-r--r-- | src/core/hle/kernel/shared_memory.h | 38 |
5 files changed, 142 insertions, 0 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 9ee803fda..0d3189d29 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -38,6 +38,7 @@ set(SRCS core.cpp hle/kernel/event.cpp hle/kernel/kernel.cpp hle/kernel/mutex.cpp + hle/kernel/shared_memory.cpp hle/kernel/thread.cpp hle/service/apt.cpp hle/service/fs.cpp @@ -85,6 +86,7 @@ set(HEADERS core.h hle/kernel/archive.h hle/kernel/kernel.h hle/kernel/mutex.h + hle/kernel/shared_memory.h hle/kernel/thread.h hle/function_wrappers.h hle/service/apt.h diff --git a/src/core/core.vcxproj b/src/core/core.vcxproj index 4e521903c..a09a4a1f1 100644 --- a/src/core/core.vcxproj +++ b/src/core/core.vcxproj @@ -170,6 +170,7 @@ <ClCompile Include="hle\kernel\event.cpp" /> <ClCompile Include="hle\kernel\kernel.cpp" /> <ClCompile Include="hle\kernel\mutex.cpp" /> + <ClCompile Include="hle\kernel\shared_memory.cpp" /> <ClCompile Include="hle\kernel\thread.cpp" /> <ClCompile Include="hle\service\apt.cpp" /> <ClCompile Include="hle\service\fs.cpp" /> @@ -222,6 +223,7 @@ <ClInclude Include="hle\kernel\event.h" /> <ClInclude Include="hle\kernel\kernel.h" /> <ClInclude Include="hle\kernel\mutex.h" /> + <ClInclude Include="hle\kernel\shared_memory.h" /> <ClInclude Include="hle\kernel\thread.h" /> <ClInclude Include="hle\service\apt.h" /> <ClInclude Include="hle\service\fs.h" /> diff --git a/src/core/core.vcxproj.filters b/src/core/core.vcxproj.filters index 17829b8b1..7e6a7f91b 100644 --- a/src/core/core.vcxproj.filters +++ b/src/core/core.vcxproj.filters @@ -179,6 +179,9 @@ <ClCompile Include="file_sys\archive_romfs.cpp"> <Filter>file_sys</Filter> </ClCompile> + <ClCompile Include="hle\kernel\shared_memory.cpp"> + <Filter>hle\kernel</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <ClInclude Include="arm\disassembler\arm_disasm.h"> @@ -320,6 +323,9 @@ <ClInclude Include="file_sys\archive_romfs.h"> <Filter>file_sys</Filter> </ClInclude> + <ClInclude Include="hle\kernel\shared_memory.h"> + <Filter>hle\kernel</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <Text Include="CMakeLists.txt" /> 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 @@ +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#include "common/common.h" + +#include "core/mem_map.h" +#include "core/hle/kernel/shared_memory.h" + +namespace Kernel { + +class SharedMemory : public Object { +public: + const char* GetTypeName() const { return "SharedMemory"; } + + static Kernel::HandleType GetStaticHandleType() { return Kernel::HandleType::SharedMemory; } + Kernel::HandleType GetHandleType() const { return Kernel::HandleType::SharedMemory; } + + /** + * Wait for kernel object to synchronize + * @param wait Boolean wait set if current thread should wait as a result of sync operation + * @return Result of operation, 0 on success, otherwise error code + */ + Result WaitSynchronization(bool* wait) { + // TODO(bunnei): ImplementMe + ERROR_LOG(OSHLE, "(UNIMPLEMENTED)"); + return 0; + } + + u32 base_address; ///< Address of shared memory block in RAM + u32 permissions; ///< Permissions of shared memory block (specified by SVC field) + u32 other_permissions; ///< Other permissions of shared memory block (specified by SVC field) + std::string name; ///< Name of shared memory object (optional) +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/** + * Creates a shared memory object + * @param handle Handle of newly created shared memory object + * @param name Name of shared memory object + * @return Pointer to newly created shared memory object + */ +SharedMemory* CreateSharedMemory(Handle& handle, const std::string& name) { + SharedMemory* shared_memory = new SharedMemory; + handle = Kernel::g_object_pool.Create(shared_memory); + shared_memory->name = name; + return shared_memory; +} + +/** + * Creates a shared memory object + * @param name Optional name of shared memory object + * @return Handle of newly created shared memory object + */ +Handle CreateSharedMemory(const std::string& name) { + Handle handle; + CreateSharedMemory(handle, name); + return handle; +} + +/** + * Maps a shared memory block to an address in system memory + * @param handle Shared memory block handle + * @param address Address in system memory to map shared memory block to + * @param permissions Memory block map permissions (specified by SVC field) + * @param other_permissions Memory block map other permissions (specified by SVC field) + * @return Result of operation, 0 on success, otherwise error code + */ +Result MapSharedMemory(u32 handle, u32 address, u32 permissions, u32 other_permissions) { + SharedMemory* shared_memory = Kernel::g_object_pool.GetFast<SharedMemory>(handle); + shared_memory->base_address = address; + shared_memory->permissions = permissions; + shared_memory->other_permissions = other_permissions; + return 0; +} + +/** + * Gets a pointer to the shared memory block + * @param handle Shared memory block handle + * @param offset Offset from the start of the shared memory block to get pointer + * @return Pointer to the shared memory block from the specified offset + */ +u8* GetSharedMemoryPointer(Handle handle, u32 offset) { + SharedMemory* shared_memory = Kernel::g_object_pool.GetFast<SharedMemory>(handle); + _assert_msg_(KERNEL, (shared_memory != nullptr), "handle 0x%08X is not valid!", handle); + if (0 != shared_memory->base_address) + return Memory::GetPointer(shared_memory->base_address + offset); + + ERROR_LOG(KERNEL, "memory block handle=0x%08X not mapped!", handle); + return nullptr; +} + +} // 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 @@ +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#pragma once + +#include "common/common_types.h" + +#include "core/hle/kernel/kernel.h" + +namespace Kernel { + +/** + * Creates a shared memory object + * @param name Optional name of shared memory object + * @return Handle of newly created shared memory object + */ +Handle CreateSharedMemory(const std::string& name="Unknown"); + +/** + * Maps a shared memory block to an address in system memory + * @param handle Shared memory block handle + * @param address Address in system memory to map shared memory block to + * @param permissions Memory block map permissions (specified by SVC field) + * @param other_permissions Memory block map other permissions (specified by SVC field) + * @return Result of operation, 0 on success, otherwise error code + */ +Result MapSharedMemory(u32 handle, u32 address, u32 permissions, u32 other_permissions); + +/** + * Gets a pointer to the shared memory block + * @param handle Shared memory block handle + * @param offset Offset from the start of the shared memory block to get pointer + * @return Pointer to the shared memory block from the specified offset + */ +u8* GetSharedMemoryPointer(Handle handle, u32 offset); + +} // namespace |