diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp index 911e6fbc12..8f40bdd5a2 100644 --- a/src/core/hle/kernel/hle_ipc.cpp +++ b/src/core/hle/kernel/hle_ipc.cpp @@ -301,10 +301,6 @@ size_t HLERequestContext::WriteBuffer(const void* buffer, size_t size, int buffe return size; } -size_t HLERequestContext::WriteBuffer(const std::vector& buffer, int buffer_index) const { - return WriteBuffer(buffer.data(), buffer.size(), buffer_index); -} - size_t HLERequestContext::GetReadBufferSize(int buffer_index) const { const bool is_buffer_a{BufferDescriptorA().size() && BufferDescriptorA()[buffer_index].Size()}; return is_buffer_a ? BufferDescriptorA()[buffer_index].Size() diff --git a/src/core/hle/kernel/hle_ipc.h b/src/core/hle/kernel/hle_ipc.h index 88f93ad224..01b805df8d 100644 --- a/src/core/hle/kernel/hle_ipc.h +++ b/src/core/hle/kernel/hle_ipc.h @@ -5,8 +5,10 @@ #pragma once #include +#include #include #include +#include #include #include #include "common/common_types.h" @@ -171,8 +173,25 @@ public: /// Helper function to write a buffer using the appropriate buffer descriptor size_t WriteBuffer(const void* buffer, size_t size, int buffer_index = 0) const; - /// Helper function to write a buffer using the appropriate buffer descriptor - size_t WriteBuffer(const std::vector& buffer, int buffer_index = 0) const; + /* Helper function to write a buffer using the appropriate buffer descriptor + * + * @tparam ContiguousContainer an arbitrary container that satisfies the + * ContiguousContainer concept in the C++ standard library. + * + * @param container The container to write the data of into a buffer. + * @param buffer_index The buffer in particular to write to. + */ + template >> + size_t WriteBuffer(const ContiguousContainer& container, int buffer_index = 0) const { + using ContiguousType = typename ContiguousContainer::value_type; + + static_assert(std::is_trivially_copyable_v, + "Container to WriteBuffer must contain trivially copyable objects"); + + return WriteBuffer(std::data(container), std::size(container) * sizeof(ContiguousType), + buffer_index); + } /// Helper function to get the size of the input buffer size_t GetReadBufferSize(int buffer_index = 0) const; diff --git a/src/core/hle/service/audio/audout_u.cpp b/src/core/hle/service/audio/audout_u.cpp index 8bf273b221..4217ea4fb4 100644 --- a/src/core/hle/service/audio/audout_u.cpp +++ b/src/core/hle/service/audio/audout_u.cpp @@ -168,7 +168,7 @@ void AudOutU::ListAudioOutsImpl(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const std::string audio_interface = "AudioInterface"; - ctx.WriteBuffer(audio_interface.c_str(), audio_interface.size()); + ctx.WriteBuffer(audio_interface); IPC::ResponseBuilder rb = rp.MakeBuilder(3, 0, 0); diff --git a/src/core/hle/service/audio/audren_u.cpp b/src/core/hle/service/audio/audren_u.cpp index 2a8b3e2169..6903f52d60 100644 --- a/src/core/hle/service/audio/audren_u.cpp +++ b/src/core/hle/service/audio/audren_u.cpp @@ -299,7 +299,7 @@ private: IPC::RequestParser rp{ctx}; const std::string audio_interface = "AudioInterface"; - ctx.WriteBuffer(audio_interface.c_str(), audio_interface.size()); + ctx.WriteBuffer(audio_interface); IPC::ResponseBuilder rb = rp.MakeBuilder(3, 0, 0); rb.Push(RESULT_SUCCESS); @@ -324,7 +324,7 @@ private: IPC::RequestParser rp{ctx}; const std::string audio_interface = "AudioDevice"; - ctx.WriteBuffer(audio_interface.c_str(), audio_interface.size()); + ctx.WriteBuffer(audio_interface); IPC::ResponseBuilder rb = rp.MakeBuilder(3, 0, 0); rb.Push(RESULT_SUCCESS); diff --git a/src/core/hle/service/set/set.cpp b/src/core/hle/service/set/set.cpp index bd295cdf63..886133b746 100644 --- a/src/core/hle/service/set/set.cpp +++ b/src/core/hle/service/set/set.cpp @@ -31,7 +31,7 @@ void SET::GetAvailableLanguageCodes(Kernel::HLERequestContext& ctx) { LanguageCode::ZH_HANS, LanguageCode::ZH_HANT, }}; - ctx.WriteBuffer(available_language_codes.data(), available_language_codes.size()); + ctx.WriteBuffer(available_language_codes); IPC::ResponseBuilder rb{ctx, 4}; rb.Push(RESULT_SUCCESS);