From f91c51467a58b66a2ca2ae78a67f9ca076299c2e Mon Sep 17 00:00:00 2001 From: Lectem Date: Mon, 26 Dec 2016 14:42:06 +0100 Subject: move Pop methods out of class body --- src/core/hle/ipc_helpers.h | 160 +++++++++++++++++++++++++-------------------- 1 file changed, 88 insertions(+), 72 deletions(-) (limited to 'src/core/hle/ipc_helpers.h') diff --git a/src/core/hle/ipc_helpers.h b/src/core/hle/ipc_helpers.h index 6089c39c7..68508caba 100644 --- a/src/core/hle/ipc_helpers.h +++ b/src/core/hle/ipc_helpers.h @@ -50,9 +50,9 @@ public: template void Push(T value); - template <> - void Push(u32); - + void Push(u32 value) { + cmdbuf[index++] = value; + } template void Push(First first_value, const Other&... other_values) { Push(first_value); @@ -86,7 +86,7 @@ public: void PushCurrentPIDHandle() { Push(CallingPidDesc()); - Push(0); + Push(u32(0)); } void PushStaticBuffer(VAddr buffer_vaddr, u32 size, u8 buffer_id) { @@ -100,6 +100,24 @@ public: } }; +/// Push /// + +template <> +inline void RequestBuilder::Push(u32 value) { + Push(value); +} + +template <> +inline void RequestBuilder::Push(u64 value) { + Push(static_cast(value)); + Push(static_cast(value >> 32)); +} + +template <> +inline void RequestBuilder::Push(ResultCode value) { + Push(value.raw); +} + class RequestParser : public RequestHelperBase { public: RequestParser(u32* command_buffer, Header command_header) @@ -123,39 +141,16 @@ public: template T Pop(); - template <> - u32 Pop(); - template - void Pop(T& value) { - value = Pop(); - } + void Pop(T& value); template - void Pop(First& first_value, Other&... other_values) { - first_value = Pop(); - Pop(other_values...); - } + void Pop(First& first_value, Other&... other_values); - Kernel::Handle PopHandle() { - const u32 handle_descriptor = Pop(); - DEBUG_ASSERT_MSG(IsHandleDescriptor(handle_descriptor), - "Tried to pop handle(s) but the descriptor is not a handle descriptor"); - DEBUG_ASSERT_MSG(HandleNumberFromDesc(handle_descriptor) == 1, - "Descriptor indicates that there isn't exactly one handle"); - return Pop(); - } + Kernel::Handle PopHandle(); template - void PopHandles(H&... handles) { - const u32 handle_descriptor = Pop(); - const int handles_number = sizeof...(H); - DEBUG_ASSERT_MSG(IsHandleDescriptor(handle_descriptor), - "Tried to pop handle(s) but the descriptor is not a handle descriptor"); - DEBUG_ASSERT_MSG(handles_number == HandleNumberFromDesc(handle_descriptor), - "Number of handles doesn't match the descriptor"); - Pop(static_cast(handles)...); - } + void PopHandles(H&... handles); /** * @brief Pops the static buffer vaddr @@ -171,22 +166,7 @@ public: * buffer information * Please note that the setup uses virtual addresses. */ - VAddr PopStaticBuffer(size_t* data_size = nullptr, bool useStaticBuffersToGetVaddr = false) { - const u32 sbuffer_descriptor = Pop(); - StaticBufferDescInfo bufferInfo{sbuffer_descriptor}; - if (data_size != nullptr) - *data_size = bufferInfo.size; - if (!useStaticBuffersToGetVaddr) - return Pop(); - else { - ASSERT_MSG(0, "remove the assert if multiprocess/IPC translation are implemented."); - // The buffer has already been copied to the static buffer by the kernel during - // translation - Pop(); // Pop the calling process buffer address - // and get the vaddr from the static buffers - return cmdbuf[(0x100 >> 2) + bufferInfo.buffer_id * 2 + 1]; - } - } + VAddr PopStaticBuffer(size_t* data_size = nullptr, bool useStaticBuffersToGetVaddr = false); /** * @brief Pops the mapped buffer vaddr @@ -197,26 +177,14 @@ public: * buffer */ VAddr PopMappedBuffer(size_t* data_size = nullptr, - MappedBufferPermissions* buffer_perms = nullptr) { - const u32 sbuffer_descriptor = Pop(); - MappedBufferDescInfo bufferInfo{sbuffer_descriptor}; - if (data_size != nullptr) - *data_size = bufferInfo.size; - if (buffer_perms != nullptr) - *buffer_perms = bufferInfo.perms; - return Pop(); - } + MappedBufferPermissions* buffer_perms = nullptr); /** * @brief Reads the next normal parameters as a struct, by copying it * @note: The output class must be correctly packed/padded to fit hardware layout. */ template - void PopRaw(T& value) { - static_assert(std::is_trivially_copyable(), "Raw types should be trivially copyable"); - std::memcpy(&value, cmdbuf + index, sizeof(T)); - index += (sizeof(T) + 3) / 4; // round up to word length - } + void PopRaw(T& value); }; /// Pop /// @@ -238,22 +206,70 @@ inline ResultCode RequestParser::Pop() { return ResultCode{Pop()}; } -/// Push /// +template +void RequestParser::Pop(T& value) { + value = Pop(); +} -template <> -inline void RequestBuilder::Push(u32 value) { - cmdbuf[index++] = value; +template +void RequestParser::Pop(First& first_value, Other&... other_values) { + first_value = Pop(); + Pop(other_values...); } -template <> -inline void RequestBuilder::Push(u64 value) { - Push(static_cast(value)); - Push(static_cast(value >> 32)); +inline Kernel::Handle RequestParser::PopHandle() { + const u32 handle_descriptor = Pop(); + DEBUG_ASSERT_MSG(IsHandleDescriptor(handle_descriptor), + "Tried to pop handle(s) but the descriptor is not a handle descriptor"); + DEBUG_ASSERT_MSG(HandleNumberFromDesc(handle_descriptor) == 1, + "Descriptor indicates that there isn't exactly one handle"); + return Pop(); } -template <> -inline void RequestBuilder::Push(ResultCode value) { - Push(value.raw); +template +void RequestParser::PopHandles(H&... handles) { + const u32 handle_descriptor = Pop(); + const int handles_number = sizeof...(H); + DEBUG_ASSERT_MSG(IsHandleDescriptor(handle_descriptor), + "Tried to pop handle(s) but the descriptor is not a handle descriptor"); + DEBUG_ASSERT_MSG(handles_number == HandleNumberFromDesc(handle_descriptor), + "Number of handles doesn't match the descriptor"); + Pop(static_cast(handles)...); +} + +inline VAddr RequestParser::PopStaticBuffer(size_t* data_size, bool useStaticBuffersToGetVaddr) { + const u32 sbuffer_descriptor = Pop(); + StaticBufferDescInfo bufferInfo{sbuffer_descriptor}; + if (data_size != nullptr) + *data_size = bufferInfo.size; + if (!useStaticBuffersToGetVaddr) + return Pop(); + else { + ASSERT_MSG(0, "remove the assert if multiprocess/IPC translation are implemented."); + // The buffer has already been copied to the static buffer by the kernel during + // translation + Pop(); // Pop the calling process buffer address + // and get the vaddr from the static buffers + return cmdbuf[(0x100 >> 2) + bufferInfo.buffer_id * 2 + 1]; + } +} + +inline VAddr RequestParser::PopMappedBuffer(size_t* data_size, + MappedBufferPermissions* buffer_perms) { + const u32 sbuffer_descriptor = Pop(); + MappedBufferDescInfo bufferInfo{sbuffer_descriptor}; + if (data_size != nullptr) + *data_size = bufferInfo.size; + if (buffer_perms != nullptr) + *buffer_perms = bufferInfo.perms; + return Pop(); +} + +template +void RequestParser::PopRaw(T& value) { + static_assert(std::is_trivially_copyable(), "Raw types should be trivially copyable"); + std::memcpy(&value, cmdbuf + index, sizeof(T)); + index += (sizeof(T) + 3) / 4; // round up to word length } } // namespace IPC -- cgit v1.2.3