From 1ce6fff0648008b7510e9feb3cf6696a2c25dd5c Mon Sep 17 00:00:00 2001 From: bunnei Date: Tue, 13 Feb 2018 21:41:20 -0500 Subject: hle_ipc: Add helper functions for reading and writing buffers. --- src/core/hle/kernel/hle_ipc.cpp | 39 +++++++++++++++++++++++++++++++++++++++ src/core/hle/kernel/hle_ipc.h | 12 ++++++++++++ 2 files changed, 51 insertions(+) (limited to 'src/core/hle/kernel') diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp index db104e8a2..a5a3d4fe4 100644 --- a/src/core/hle/kernel/hle_ipc.cpp +++ b/src/core/hle/kernel/hle_ipc.cpp @@ -12,6 +12,7 @@ #include "core/hle/kernel/kernel.h" #include "core/hle/kernel/process.h" #include "core/hle/kernel/server_session.h" +#include "core/memory.h" namespace Kernel { @@ -210,4 +211,42 @@ ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(u32_le* dst_cmdbuf, P return RESULT_SUCCESS; } +std::vector HLERequestContext::ReadBuffer() const { + std::vector buffer; + const bool is_buffer_a{BufferDescriptorA().size() && BufferDescriptorA()[0].Size()}; + + if (is_buffer_a) { + buffer.resize(BufferDescriptorA()[0].Size()); + Memory::ReadBlock(BufferDescriptorA()[0].Address(), buffer.data(), buffer.size()); + } else { + buffer.resize(BufferDescriptorX()[0].Size()); + Memory::ReadBlock(BufferDescriptorX()[0].Address(), buffer.data(), buffer.size()); + } + + return buffer; +} + +size_t HLERequestContext::WriteBuffer(const void* buffer, const size_t size) const { + const bool is_buffer_b{BufferDescriptorB().size() && BufferDescriptorB()[0].Size()}; + + if (is_buffer_b) { + const size_t size{std::min(BufferDescriptorB()[0].Size(), size)}; + Memory::WriteBlock(BufferDescriptorB()[0].Address(), buffer, size); + return size; + } else { + const size_t size{std::min(BufferDescriptorC()[0].Size(), size)}; + Memory::WriteBlock(BufferDescriptorC()[0].Address(), buffer, size); + return size; + } +} + +size_t HLERequestContext::WriteBuffer(const std::vector& buffer) const { + return WriteBuffer(buffer.data(), buffer.size()); +} + +size_t HLERequestContext::GetWriteBufferSize() const { + const bool is_buffer_b{BufferDescriptorB().size() && BufferDescriptorB()[0].Size()}; + return is_buffer_b ? BufferDescriptorB()[0].Size() : BufferDescriptorC()[0].Size(); +} + } // namespace Kernel diff --git a/src/core/hle/kernel/hle_ipc.h b/src/core/hle/kernel/hle_ipc.h index da8335b35..0cc270909 100644 --- a/src/core/hle/kernel/hle_ipc.h +++ b/src/core/hle/kernel/hle_ipc.h @@ -143,6 +143,18 @@ public: return domain_message_header; } + /// Helper function to read a buffer using the appropriate buffer descriptor + std::vector ReadBuffer() const; + + /// Helper function to write a buffer using the appropriate buffer descriptor + size_t WriteBuffer(const void* buffer, const size_t size) const; + + /// Helper function to write a buffer using the appropriate buffer descriptor + size_t WriteBuffer(const std::vector& buffer) const; + + /// Helper function to get the size of the output buffer + size_t GetWriteBufferSize() const; + template SharedPtr GetCopyObject(size_t index) { ASSERT(index < copy_objects.size()); -- cgit v1.2.3 From fc1b425520d750335131f6ddc20f1d964ab384c5 Mon Sep 17 00:00:00 2001 From: bunnei Date: Tue, 13 Feb 2018 23:53:18 -0500 Subject: hle_ipc: Add helper functions for reading and writing buffers. --- src/core/hle/kernel/hle_ipc.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/core/hle/kernel') diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp index a5a3d4fe4..0a9986c18 100644 --- a/src/core/hle/kernel/hle_ipc.cpp +++ b/src/core/hle/kernel/hle_ipc.cpp @@ -230,14 +230,12 @@ size_t HLERequestContext::WriteBuffer(const void* buffer, const size_t size) con const bool is_buffer_b{BufferDescriptorB().size() && BufferDescriptorB()[0].Size()}; if (is_buffer_b) { - const size_t size{std::min(BufferDescriptorB()[0].Size(), size)}; Memory::WriteBlock(BufferDescriptorB()[0].Address(), buffer, size); - return size; } else { - const size_t size{std::min(BufferDescriptorC()[0].Size(), size)}; Memory::WriteBlock(BufferDescriptorC()[0].Address(), buffer, size); - return size; } + + return size; } size_t HLERequestContext::WriteBuffer(const std::vector& buffer) const { -- cgit v1.2.3 From 6fd19f05f1eba884a20e79ee43fce1af388204d4 Mon Sep 17 00:00:00 2001 From: bunnei Date: Wed, 14 Feb 2018 00:14:17 -0500 Subject: hle_ipc: Add GetReadBufferSize and check write buffer size. --- src/core/hle/kernel/hle_ipc.cpp | 7 +++++++ src/core/hle/kernel/hle_ipc.h | 3 +++ 2 files changed, 10 insertions(+) (limited to 'src/core/hle/kernel') diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp index 0a9986c18..d592f502d 100644 --- a/src/core/hle/kernel/hle_ipc.cpp +++ b/src/core/hle/kernel/hle_ipc.cpp @@ -229,6 +229,8 @@ std::vector HLERequestContext::ReadBuffer() const { size_t HLERequestContext::WriteBuffer(const void* buffer, const size_t size) const { const bool is_buffer_b{BufferDescriptorB().size() && BufferDescriptorB()[0].Size()}; + ASSERT_MSG(size <= GetWriteBufferSize(), "Size %d is too big", size); + if (is_buffer_b) { Memory::WriteBlock(BufferDescriptorB()[0].Address(), buffer, size); } else { @@ -242,6 +244,11 @@ size_t HLERequestContext::WriteBuffer(const std::vector& buffer) const { return WriteBuffer(buffer.data(), buffer.size()); } +size_t HLERequestContext::GetReadBufferSize() const { + const bool is_buffer_a{BufferDescriptorA().size() && BufferDescriptorA()[0].Size()}; + return is_buffer_a ? BufferDescriptorA()[0].Size() : BufferDescriptorX()[0].Size(); +} + size_t HLERequestContext::GetWriteBufferSize() const { const bool is_buffer_b{BufferDescriptorB().size() && BufferDescriptorB()[0].Size()}; return is_buffer_b ? BufferDescriptorB()[0].Size() : BufferDescriptorC()[0].Size(); diff --git a/src/core/hle/kernel/hle_ipc.h b/src/core/hle/kernel/hle_ipc.h index 0cc270909..5b1eae74a 100644 --- a/src/core/hle/kernel/hle_ipc.h +++ b/src/core/hle/kernel/hle_ipc.h @@ -152,6 +152,9 @@ public: /// Helper function to write a buffer using the appropriate buffer descriptor size_t WriteBuffer(const std::vector& buffer) const; + /// Helper function to get the size of the input buffer + size_t GetReadBufferSize() const; + /// Helper function to get the size of the output buffer size_t GetWriteBufferSize() const; -- cgit v1.2.3 From 88bfec37ce445db30fe36bb2d00b115df6a24838 Mon Sep 17 00:00:00 2001 From: bunnei Date: Wed, 14 Feb 2018 14:21:10 -0500 Subject: hle_ipc: Remove const from WriteBuffer size. --- src/core/hle/kernel/hle_ipc.cpp | 2 +- src/core/hle/kernel/hle_ipc.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/core/hle/kernel') diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp index d592f502d..6d16f71a7 100644 --- a/src/core/hle/kernel/hle_ipc.cpp +++ b/src/core/hle/kernel/hle_ipc.cpp @@ -226,7 +226,7 @@ std::vector HLERequestContext::ReadBuffer() const { return buffer; } -size_t HLERequestContext::WriteBuffer(const void* buffer, const size_t size) const { +size_t HLERequestContext::WriteBuffer(const void* buffer, size_t size) const { const bool is_buffer_b{BufferDescriptorB().size() && BufferDescriptorB()[0].Size()}; ASSERT_MSG(size <= GetWriteBufferSize(), "Size %d is too big", size); diff --git a/src/core/hle/kernel/hle_ipc.h b/src/core/hle/kernel/hle_ipc.h index 5b1eae74a..81e3489c8 100644 --- a/src/core/hle/kernel/hle_ipc.h +++ b/src/core/hle/kernel/hle_ipc.h @@ -147,7 +147,7 @@ public: std::vector ReadBuffer() const; /// Helper function to write a buffer using the appropriate buffer descriptor - size_t WriteBuffer(const void* buffer, const size_t size) const; + size_t WriteBuffer(const void* buffer, size_t size) const; /// Helper function to write a buffer using the appropriate buffer descriptor size_t WriteBuffer(const std::vector& buffer) const; -- cgit v1.2.3