From 9349f06963759705f69bd3a23a4df5354bbf6951 Mon Sep 17 00:00:00 2001 From: ameerj <52414509+ameerj@users.noreply.github.com> Date: Sun, 25 Dec 2022 13:20:59 -0500 Subject: [PATCH 01/10] hle_ipc: Add ReadBufferSpan function Returns a std::span to the buffer address, rather than create a copy of the memory into a std::vector --- src/core/hle/kernel/hle_ipc.cpp | 19 +++++++++++++++++++ src/core/hle/kernel/hle_ipc.h | 3 +++ 2 files changed, 22 insertions(+) diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp index 738b6d0f1..549fd8aea 100644 --- a/src/core/hle/kernel/hle_ipc.cpp +++ b/src/core/hle/kernel/hle_ipc.cpp @@ -345,6 +345,25 @@ std::vector HLERequestContext::ReadBuffer(std::size_t buffer_index) const { } } +std::span HLERequestContext::ReadBufferSpan(std::size_t buffer_index) const { + LOG_CRITICAL(Debug, "called"); + const bool is_buffer_a{BufferDescriptorA().size() > buffer_index && + BufferDescriptorA()[buffer_index].Size()}; + if (is_buffer_a) { + ASSERT_OR_EXECUTE_MSG( + BufferDescriptorA().size() > buffer_index, { return {}; }, + "BufferDescriptorA invalid buffer_index {}", buffer_index); + const u8* const mem_ptr = memory.GetPointer(BufferDescriptorA()[buffer_index].Address()); + return std::span(mem_ptr, BufferDescriptorA()[buffer_index].Size()); + } else { + ASSERT_OR_EXECUTE_MSG( + BufferDescriptorX().size() > buffer_index, { return {}; }, + "BufferDescriptorX invalid buffer_index {}", buffer_index); + const u8* const mem_ptr = memory.GetPointer(BufferDescriptorX()[buffer_index].Address()); + return std::span(mem_ptr, BufferDescriptorX()[buffer_index].Size()); + } +} + std::size_t HLERequestContext::WriteBuffer(const void* buffer, std::size_t size, std::size_t buffer_index) const { if (size == 0) { diff --git a/src/core/hle/kernel/hle_ipc.h b/src/core/hle/kernel/hle_ipc.h index e252b5f4b..2242ff922 100644 --- a/src/core/hle/kernel/hle_ipc.h +++ b/src/core/hle/kernel/hle_ipc.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -273,6 +274,8 @@ public: /// Helper function to read a buffer using the appropriate buffer descriptor [[nodiscard]] std::vector ReadBuffer(std::size_t buffer_index = 0) const; + [[nodiscard]] std::span ReadBufferSpan(std::size_t buffer_index = 0) const; + /// Helper function to write a buffer using the appropriate buffer descriptor std::size_t WriteBuffer(const void* buffer, std::size_t size, std::size_t buffer_index = 0) const; From fbc375f0de26342a22c52bb78e14b4f78d2243c1 Mon Sep 17 00:00:00 2001 From: ameerj <52414509+ameerj@users.noreply.github.com> Date: Sun, 25 Dec 2022 13:21:15 -0500 Subject: [PATCH 02/10] fsp_srv: Use ReadBufferSpan --- src/common/string_util.cpp | 2 +- src/common/string_util.h | 3 +- src/core/hle/service/filesystem/fsp_srv.cpp | 31 ++++++++++----------- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp index b26db4796..e0b6180c5 100644 --- a/src/common/string_util.cpp +++ b/src/common/string_util.cpp @@ -30,7 +30,7 @@ std::string ToUpper(std::string str) { return str; } -std::string StringFromBuffer(const std::vector& data) { +std::string StringFromBuffer(std::span data) { return std::string(data.begin(), std::find(data.begin(), data.end(), '\0')); } diff --git a/src/common/string_util.h b/src/common/string_util.h index ce18a33cf..f8aecc875 100644 --- a/src/common/string_util.h +++ b/src/common/string_util.h @@ -5,6 +5,7 @@ #pragma once #include +#include #include #include #include "common/common_types.h" @@ -17,7 +18,7 @@ namespace Common { /// Make a string uppercase [[nodiscard]] std::string ToUpper(std::string str); -[[nodiscard]] std::string StringFromBuffer(const std::vector& data); +[[nodiscard]] std::string StringFromBuffer(std::span data); [[nodiscard]] std::string StripSpaces(const std::string& s); [[nodiscard]] std::string StripQuotes(const std::string& s); diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp index fbb16a7da..efebb0ccc 100644 --- a/src/core/hle/service/filesystem/fsp_srv.cpp +++ b/src/core/hle/service/filesystem/fsp_srv.cpp @@ -190,7 +190,7 @@ private: return; } - const std::vector data = ctx.ReadBuffer(); + const auto data = ctx.ReadBufferSpan(); ASSERT_MSG( static_cast(data.size()) <= length, @@ -337,7 +337,7 @@ public: void CreateFile(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - const auto file_buffer = ctx.ReadBuffer(); + const auto file_buffer = ctx.ReadBufferSpan(); const std::string name = Common::StringFromBuffer(file_buffer); const u64 file_mode = rp.Pop(); @@ -351,7 +351,7 @@ public: } void DeleteFile(Kernel::HLERequestContext& ctx) { - const auto file_buffer = ctx.ReadBuffer(); + const auto file_buffer = ctx.ReadBufferSpan(); const std::string name = Common::StringFromBuffer(file_buffer); LOG_DEBUG(Service_FS, "called. file={}", name); @@ -361,7 +361,7 @@ public: } void CreateDirectory(Kernel::HLERequestContext& ctx) { - const auto file_buffer = ctx.ReadBuffer(); + const auto file_buffer = ctx.ReadBufferSpan(); const std::string name = Common::StringFromBuffer(file_buffer); LOG_DEBUG(Service_FS, "called. directory={}", name); @@ -371,7 +371,7 @@ public: } void DeleteDirectory(Kernel::HLERequestContext& ctx) { - const auto file_buffer = ctx.ReadBuffer(); + const auto file_buffer = ctx.ReadBufferSpan(); const std::string name = Common::StringFromBuffer(file_buffer); LOG_DEBUG(Service_FS, "called. directory={}", name); @@ -381,7 +381,7 @@ public: } void DeleteDirectoryRecursively(Kernel::HLERequestContext& ctx) { - const auto file_buffer = ctx.ReadBuffer(); + const auto file_buffer = ctx.ReadBufferSpan(); const std::string name = Common::StringFromBuffer(file_buffer); LOG_DEBUG(Service_FS, "called. directory={}", name); @@ -391,7 +391,7 @@ public: } void CleanDirectoryRecursively(Kernel::HLERequestContext& ctx) { - const auto file_buffer = ctx.ReadBuffer(); + const auto file_buffer = ctx.ReadBufferSpan(); const std::string name = Common::StringFromBuffer(file_buffer); LOG_DEBUG(Service_FS, "called. Directory: {}", name); @@ -401,11 +401,8 @@ public: } void RenameFile(Kernel::HLERequestContext& ctx) { - std::vector buffer = ctx.ReadBuffer(0); - const std::string src_name = Common::StringFromBuffer(buffer); - - buffer = ctx.ReadBuffer(1); - const std::string dst_name = Common::StringFromBuffer(buffer); + const std::string src_name = Common::StringFromBuffer(ctx.ReadBufferSpan(0)); + const std::string dst_name = Common::StringFromBuffer(ctx.ReadBufferSpan(1)); LOG_DEBUG(Service_FS, "called. file '{}' to file '{}'", src_name, dst_name); @@ -416,7 +413,7 @@ public: void OpenFile(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - const auto file_buffer = ctx.ReadBuffer(); + const auto file_buffer = ctx.ReadBufferSpan(); const std::string name = Common::StringFromBuffer(file_buffer); const auto mode = static_cast(rp.Pop()); @@ -440,7 +437,7 @@ public: void OpenDirectory(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - const auto file_buffer = ctx.ReadBuffer(); + const auto file_buffer = ctx.ReadBufferSpan(); const std::string name = Common::StringFromBuffer(file_buffer); // TODO(Subv): Implement this filter. @@ -463,7 +460,7 @@ public: } void GetEntryType(Kernel::HLERequestContext& ctx) { - const auto file_buffer = ctx.ReadBuffer(); + const auto file_buffer = ctx.ReadBufferSpan(); const std::string name = Common::StringFromBuffer(file_buffer); LOG_DEBUG(Service_FS, "called. file={}", name); @@ -504,7 +501,7 @@ public: } void GetFileTimeStampRaw(Kernel::HLERequestContext& ctx) { - const auto file_buffer = ctx.ReadBuffer(); + const auto file_buffer = ctx.ReadBufferSpan(); const std::string name = Common::StringFromBuffer(file_buffer); LOG_WARNING(Service_FS, "(Partial Implementation) called. file={}", name); @@ -1086,7 +1083,7 @@ void FSP_SRV::GetGlobalAccessLogMode(Kernel::HLERequestContext& ctx) { } void FSP_SRV::OutputAccessLogToSdCard(Kernel::HLERequestContext& ctx) { - const auto raw = ctx.ReadBuffer(); + const auto raw = ctx.ReadBufferSpan(); auto log = Common::StringFromFixedZeroTerminatedBuffer( reinterpret_cast(raw.data()), raw.size()); From 7ffd62424804eceb73f01b1c4e8dc216134c8295 Mon Sep 17 00:00:00 2001 From: ameerj <52414509+ameerj@users.noreply.github.com> Date: Sun, 25 Dec 2022 13:42:32 -0500 Subject: [PATCH 03/10] service: Use ReadBufferSpan where it is trivial to do so --- src/core/hle/kernel/hle_ipc.cpp | 1 - src/core/hle/service/acc/acc.cpp | 6 ++--- src/core/hle/service/am/am.cpp | 2 +- src/core/hle/service/aoc/aoc_u.cpp | 4 ++-- src/core/hle/service/audio/audin_u.cpp | 6 ++--- src/core/hle/service/audio/audout_u.cpp | 4 ++-- src/core/hle/service/audio/audren_u.cpp | 6 ++--- src/core/hle/service/audio/hwopus.cpp | 6 ++--- src/core/hle/service/bcat/bcat_module.cpp | 2 +- src/core/hle/service/es/es.cpp | 4 ++-- src/core/hle/service/fatal/fatal.cpp | 2 +- src/core/hle/service/glue/notif.cpp | 4 ++-- src/core/hle/service/hid/controllers/npad.cpp | 2 +- src/core/hle/service/hid/controllers/npad.h | 2 +- src/core/hle/service/hid/hid.cpp | 8 +++---- src/core/hle/service/jit/jit.cpp | 6 ++--- src/core/hle/service/ldn/ldn.cpp | 4 ++-- src/core/hle/service/lm/lm.cpp | 2 +- src/core/hle/service/nfc/mifare_user.cpp | 4 ++-- src/core/hle/service/nfc/nfc_user.cpp | 2 +- src/core/hle/service/nfp/nfp_user.cpp | 6 ++--- src/core/hle/service/ngct/ngct.cpp | 4 ++-- src/core/hle/service/nifm/nifm.cpp | 2 +- src/core/hle/service/prepo/prepo.cpp | 24 +++++++++---------- src/core/hle/service/set/set_sys.cpp | 8 +++---- src/core/hle/service/sockets/sfdnsres.cpp | 6 ++--- src/core/hle/service/ssl/ssl.cpp | 10 ++++---- src/core/hle/service/time/time.cpp | 8 +++---- .../hle/service/time/time_zone_service.cpp | 4 ++-- src/core/reporter.cpp | 2 +- src/core/reporter.h | 4 +++- 31 files changed, 78 insertions(+), 77 deletions(-) diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp index 549fd8aea..9bc72da02 100644 --- a/src/core/hle/kernel/hle_ipc.cpp +++ b/src/core/hle/kernel/hle_ipc.cpp @@ -346,7 +346,6 @@ std::vector HLERequestContext::ReadBuffer(std::size_t buffer_index) const { } std::span HLERequestContext::ReadBufferSpan(std::size_t buffer_index) const { - LOG_CRITICAL(Debug, "called"); const bool is_buffer_a{BufferDescriptorA().size() > buffer_index && BufferDescriptorA()[buffer_index].Size()}; if (is_buffer_a) { diff --git a/src/core/hle/service/acc/acc.cpp b/src/core/hle/service/acc/acc.cpp index 6d1084fd1..398bbc793 100644 --- a/src/core/hle/service/acc/acc.cpp +++ b/src/core/hle/service/acc/acc.cpp @@ -367,7 +367,7 @@ protected: IPC::RequestParser rp{ctx}; const auto base = rp.PopRaw(); - const auto user_data = ctx.ReadBuffer(); + const auto user_data = ctx.ReadBufferSpan(); LOG_DEBUG(Service_ACC, "called, username='{}', timestamp={:016X}, uuid=0x{}", Common::StringFromFixedZeroTerminatedBuffer( @@ -399,8 +399,8 @@ protected: IPC::RequestParser rp{ctx}; const auto base = rp.PopRaw(); - const auto user_data = ctx.ReadBuffer(); - const auto image_data = ctx.ReadBuffer(1); + const auto user_data = ctx.ReadBufferSpan(); + const auto image_data = ctx.ReadBufferSpan(1); LOG_DEBUG(Service_ACC, "called, username='{}', timestamp={:016X}, uuid=0x{}", Common::StringFromFixedZeroTerminatedBuffer( diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index 22999c942..958e40648 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp @@ -1124,7 +1124,7 @@ void IStorageAccessor::Write(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const u64 offset{rp.Pop()}; - const std::vector data{ctx.ReadBuffer()}; + const auto data{ctx.ReadBufferSpan()}; const std::size_t size{std::min(data.size(), backing.GetSize() - offset)}; LOG_DEBUG(Service_AM, "called, offset={}, size={}", offset, size); diff --git a/src/core/hle/service/aoc/aoc_u.cpp b/src/core/hle/service/aoc/aoc_u.cpp index 368ccd52f..cc976b155 100644 --- a/src/core/hle/service/aoc/aoc_u.cpp +++ b/src/core/hle/service/aoc/aoc_u.cpp @@ -72,7 +72,7 @@ private: IPC::RequestParser rp{ctx}; const auto unknown_1 = rp.Pop(); - [[maybe_unused]] const auto unknown_2 = ctx.ReadBuffer(); + [[maybe_unused]] const auto unknown_2 = ctx.ReadBufferSpan(); LOG_WARNING(Service_AOC, "(STUBBED) called, unknown_1={}", unknown_1); @@ -84,7 +84,7 @@ private: IPC::RequestParser rp{ctx}; const auto unknown_1 = rp.Pop(); - [[maybe_unused]] const auto unknown_2 = ctx.ReadBuffer(); + [[maybe_unused]] const auto unknown_2 = ctx.ReadBufferSpan(); LOG_WARNING(Service_AOC, "(STUBBED) called, unknown_1={}", unknown_1); diff --git a/src/core/hle/service/audio/audin_u.cpp b/src/core/hle/service/audio/audin_u.cpp index 053e8f9dd..f3dd8397d 100644 --- a/src/core/hle/service/audio/audin_u.cpp +++ b/src/core/hle/service/audio/audin_u.cpp @@ -98,7 +98,7 @@ private: LOG_ERROR(Service_Audio, "Input buffer is too small for an AudioInBuffer!"); } - const auto& in_buffer = ctx.ReadBuffer(); + const auto& in_buffer = ctx.ReadBufferSpan(); AudioInBuffer buffer{}; std::memcpy(&buffer, in_buffer.data(), sizeof(AudioInBuffer)); @@ -266,7 +266,7 @@ void AudInU::OpenAudioIn(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; auto in_params{rp.PopRaw()}; auto applet_resource_user_id{rp.PopRaw()}; - const auto device_name_data{ctx.ReadBuffer()}; + const auto device_name_data{ctx.ReadBufferSpan()}; auto device_name = Common::StringFromBuffer(device_name_data); auto handle{ctx.GetCopyHandle(0)}; @@ -317,7 +317,7 @@ void AudInU::OpenAudioInProtocolSpecified(Kernel::HLERequestContext& ctx) { auto protocol_specified{rp.PopRaw()}; auto in_params{rp.PopRaw()}; auto applet_resource_user_id{rp.PopRaw()}; - const auto device_name_data{ctx.ReadBuffer()}; + const auto device_name_data{ctx.ReadBufferSpan()}; auto device_name = Common::StringFromBuffer(device_name_data); auto handle{ctx.GetCopyHandle(0)}; diff --git a/src/core/hle/service/audio/audout_u.cpp b/src/core/hle/service/audio/audout_u.cpp index 29751f075..4bf388055 100644 --- a/src/core/hle/service/audio/audout_u.cpp +++ b/src/core/hle/service/audio/audout_u.cpp @@ -105,7 +105,7 @@ private: LOG_ERROR(Service_Audio, "Input buffer is too small for an AudioOutBuffer!"); } - const auto& in_buffer = ctx.ReadBuffer(); + const auto& in_buffer = ctx.ReadBufferSpan(); AudioOutBuffer buffer{}; std::memcpy(&buffer, in_buffer.data(), sizeof(AudioOutBuffer)); @@ -264,7 +264,7 @@ void AudOutU::OpenAudioOut(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; auto in_params{rp.PopRaw()}; auto applet_resource_user_id{rp.PopRaw()}; - const auto device_name_data{ctx.ReadBuffer()}; + const auto device_name_data{ctx.ReadBufferSpan()}; auto device_name = Common::StringFromBuffer(device_name_data); auto handle{ctx.GetCopyHandle(0)}; diff --git a/src/core/hle/service/audio/audren_u.cpp b/src/core/hle/service/audio/audren_u.cpp index 3a1c231b6..1a48c155e 100644 --- a/src/core/hle/service/audio/audren_u.cpp +++ b/src/core/hle/service/audio/audren_u.cpp @@ -112,7 +112,7 @@ private: void RequestUpdate(Kernel::HLERequestContext& ctx) { LOG_TRACE(Service_Audio, "called"); - std::vector input{ctx.ReadBuffer(0)}; + const auto input{ctx.ReadBufferSpan(0)}; // These buffers are written manually to avoid an issue with WriteBuffer throwing errors for // checking size 0. Performance size is 0 for most games. @@ -306,7 +306,7 @@ private: IPC::RequestParser rp{ctx}; const f32 volume = rp.Pop(); - const auto device_name_buffer = ctx.ReadBuffer(); + const auto device_name_buffer = ctx.ReadBufferSpan(); const std::string name = Common::StringFromBuffer(device_name_buffer); LOG_DEBUG(Service_Audio, "called. name={}, volume={}", name, volume); @@ -320,7 +320,7 @@ private: } void GetAudioDeviceOutputVolume(Kernel::HLERequestContext& ctx) { - const auto device_name_buffer = ctx.ReadBuffer(); + const auto device_name_buffer = ctx.ReadBufferSpan(); const std::string name = Common::StringFromBuffer(device_name_buffer); LOG_DEBUG(Service_Audio, "called. Name={}", name); diff --git a/src/core/hle/service/audio/hwopus.cpp b/src/core/hle/service/audio/hwopus.cpp index 825fb8bcc..7c3f25c67 100644 --- a/src/core/hle/service/audio/hwopus.cpp +++ b/src/core/hle/service/audio/hwopus.cpp @@ -74,7 +74,7 @@ private: ResetDecoderContext(); } - if (!DecodeOpusData(consumed, sample_count, ctx.ReadBuffer(), samples, performance)) { + if (!DecodeOpusData(consumed, sample_count, ctx.ReadBufferSpan(), samples, performance)) { LOG_ERROR(Audio, "Failed to decode opus data"); IPC::ResponseBuilder rb{ctx, 2}; // TODO(ogniK): Use correct error code @@ -93,7 +93,7 @@ private: ctx.WriteBuffer(samples); } - bool DecodeOpusData(u32& consumed, u32& sample_count, const std::vector& input, + bool DecodeOpusData(u32& consumed, u32& sample_count, std::span input, std::vector& output, u64* out_performance_time) const { const auto start_time = std::chrono::steady_clock::now(); const std::size_t raw_output_sz = output.size() * sizeof(opus_int16); @@ -257,7 +257,7 @@ void HwOpus::GetWorkBufferSizeEx(Kernel::HLERequestContext& ctx) { void HwOpus::GetWorkBufferSizeForMultiStreamEx(Kernel::HLERequestContext& ctx) { OpusMultiStreamParametersEx param; - std::memcpy(¶m, ctx.ReadBuffer().data(), ctx.GetReadBufferSize()); + std::memcpy(¶m, ctx.ReadBufferSpan().data(), ctx.GetReadBufferSize()); const auto sample_rate = param.sample_rate; const auto channel_count = param.channel_count; diff --git a/src/core/hle/service/bcat/bcat_module.cpp b/src/core/hle/service/bcat/bcat_module.cpp index cbe690a5d..c1a012739 100644 --- a/src/core/hle/service/bcat/bcat_module.cpp +++ b/src/core/hle/service/bcat/bcat_module.cpp @@ -206,7 +206,7 @@ private: IPC::RequestParser rp{ctx}; const auto title_id = rp.PopRaw(); - const auto passphrase_raw = ctx.ReadBuffer(); + const auto passphrase_raw = ctx.ReadBufferSpan(); LOG_DEBUG(Service_BCAT, "called, title_id={:016X}, passphrase={}", title_id, Common::HexToString(passphrase_raw)); diff --git a/src/core/hle/service/es/es.cpp b/src/core/hle/service/es/es.cpp index d183e5829..5ea61c430 100644 --- a/src/core/hle/service/es/es.cpp +++ b/src/core/hle/service/es/es.cpp @@ -121,8 +121,8 @@ private: } void ImportTicket(Kernel::HLERequestContext& ctx) { - const auto ticket = ctx.ReadBuffer(); - const auto cert = ctx.ReadBuffer(1); + const auto ticket = ctx.ReadBufferSpan(); + [[maybe_unused]] const auto cert = ctx.ReadBufferSpan(1); if (ticket.size() < sizeof(Core::Crypto::Ticket)) { LOG_ERROR(Service_ETicket, "The input buffer is not large enough!"); diff --git a/src/core/hle/service/fatal/fatal.cpp b/src/core/hle/service/fatal/fatal.cpp index 27675615b..ff896ea10 100644 --- a/src/core/hle/service/fatal/fatal.cpp +++ b/src/core/hle/service/fatal/fatal.cpp @@ -152,7 +152,7 @@ void Module::Interface::ThrowFatalWithCpuContext(Kernel::HLERequestContext& ctx) IPC::RequestParser rp(ctx); const auto error_code = rp.Pop(); const auto fatal_type = rp.PopEnum(); - const auto fatal_info = ctx.ReadBuffer(); + const auto fatal_info = ctx.ReadBufferSpan(); FatalInfo info{}; ASSERT_MSG(fatal_info.size() == sizeof(FatalInfo), "Invalid fatal info buffer size!"); diff --git a/src/core/hle/service/glue/notif.cpp b/src/core/hle/service/glue/notif.cpp index 3ace2dabd..ee5c6d3a4 100644 --- a/src/core/hle/service/glue/notif.cpp +++ b/src/core/hle/service/glue/notif.cpp @@ -38,7 +38,7 @@ void NOTIF_A::RegisterAlarmSetting(Kernel::HLERequestContext& ctx) { "application_parameter_size is bigger than 0x400 bytes"); AlarmSetting new_alarm{}; - memcpy(&new_alarm, ctx.ReadBuffer(0).data(), sizeof(AlarmSetting)); + memcpy(&new_alarm, ctx.ReadBufferSpan(0).data(), sizeof(AlarmSetting)); // TODO: Count alarms per game id if (alarms.size() >= max_alarms) { @@ -73,7 +73,7 @@ void NOTIF_A::UpdateAlarmSetting(Kernel::HLERequestContext& ctx) { "application_parameter_size is bigger than 0x400 bytes"); AlarmSetting alarm_setting{}; - memcpy(&alarm_setting, ctx.ReadBuffer(0).data(), sizeof(AlarmSetting)); + memcpy(&alarm_setting, ctx.ReadBufferSpan(0).data(), sizeof(AlarmSetting)); const auto alarm_it = GetAlarmFromId(alarm_setting.alarm_setting_id); if (alarm_it != alarms.end()) { diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp index 2f871de31..df63083a8 100644 --- a/src/core/hle/service/hid/controllers/npad.cpp +++ b/src/core/hle/service/hid/controllers/npad.cpp @@ -737,7 +737,7 @@ Core::HID::NpadStyleTag Controller_NPad::GetSupportedStyleSet() const { return hid_core.GetSupportedStyleTag(); } -void Controller_NPad::SetSupportedNpadIdTypes(u8* data, std::size_t length) { +void Controller_NPad::SetSupportedNpadIdTypes(const u8* const data, std::size_t length) { ASSERT(length > 0 && (length % sizeof(u32)) == 0); supported_npad_id_types.clear(); supported_npad_id_types.resize(length / sizeof(u32)); diff --git a/src/core/hle/service/hid/controllers/npad.h b/src/core/hle/service/hid/controllers/npad.h index 1a589cca2..988ac8ec4 100644 --- a/src/core/hle/service/hid/controllers/npad.h +++ b/src/core/hle/service/hid/controllers/npad.h @@ -95,7 +95,7 @@ public: void SetSupportedStyleSet(Core::HID::NpadStyleTag style_set); Core::HID::NpadStyleTag GetSupportedStyleSet() const; - void SetSupportedNpadIdTypes(u8* data, std::size_t length); + void SetSupportedNpadIdTypes(const u8* const data, std::size_t length); void GetSupportedNpadIdTypes(u32* data, std::size_t max_length); std::size_t GetSupportedNpadIdTypesSize() const; diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index bf28440c6..80db6af06 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp @@ -1026,7 +1026,7 @@ void Hid::SetSupportedNpadIdType(Kernel::HLERequestContext& ctx) { const auto applet_resource_user_id{rp.Pop()}; applet_resource->GetController(HidController::NPad) - .SetSupportedNpadIdTypes(ctx.ReadBuffer().data(), ctx.GetReadBufferSize()); + .SetSupportedNpadIdTypes(ctx.ReadBufferSpan().data(), ctx.GetReadBufferSize()); LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); @@ -1564,8 +1564,8 @@ void Hid::SendVibrationValues(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop()}; - const auto handles = ctx.ReadBuffer(0); - const auto vibrations = ctx.ReadBuffer(1); + const auto handles = ctx.ReadBufferSpan(0); + const auto vibrations = ctx.ReadBufferSpan(1); std::vector vibration_device_handles( handles.size() / sizeof(Core::HID::VibrationDeviceHandle)); @@ -2104,7 +2104,7 @@ void Hid::WritePalmaRgbLedPatternEntry(Kernel::HLERequestContext& ctx) { const auto connection_handle{rp.PopRaw()}; const auto unknown{rp.Pop()}; - const auto buffer = ctx.ReadBuffer(); + [[maybe_unused]] const auto buffer = ctx.ReadBufferSpan(); LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}, unknown={}", connection_handle.npad_id, unknown); diff --git a/src/core/hle/service/jit/jit.cpp b/src/core/hle/service/jit/jit.cpp index 8f2920c51..534639ff9 100644 --- a/src/core/hle/service/jit/jit.cpp +++ b/src/core/hle/service/jit/jit.cpp @@ -62,7 +62,7 @@ public: const auto parameters{rp.PopRaw()}; // Optional input/output buffers - std::vector input_buffer{ctx.CanReadBuffer() ? ctx.ReadBuffer() : std::vector()}; + const auto input_buffer{ctx.CanReadBuffer() ? ctx.ReadBufferSpan() : std::span()}; std::vector output_buffer(ctx.CanWriteBuffer() ? ctx.GetWriteBufferSize() : 0); // Function call prototype: @@ -132,7 +132,7 @@ public: const auto command{rp.PopRaw()}; // Optional input/output buffers - std::vector input_buffer{ctx.CanReadBuffer() ? ctx.ReadBuffer() : std::vector()}; + const auto input_buffer{ctx.CanReadBuffer() ? ctx.ReadBufferSpan() : std::span()}; std::vector output_buffer(ctx.CanWriteBuffer() ? ctx.GetWriteBufferSize() : 0); // Function call prototype: @@ -176,7 +176,7 @@ public: IPC::RequestParser rp{ctx}; const auto tmem_size{rp.PopRaw()}; const auto tmem_handle{ctx.GetCopyHandle(0)}; - const auto nro_plugin{ctx.ReadBuffer(1)}; + const auto nro_plugin{ctx.ReadBufferSpan(1)}; if (tmem_size == 0) { LOG_ERROR(Service_JIT, "attempted to load plugin with empty transfer memory"); diff --git a/src/core/hle/service/ldn/ldn.cpp b/src/core/hle/service/ldn/ldn.cpp index c49c61cff..ad097a6ef 100644 --- a/src/core/hle/service/ldn/ldn.cpp +++ b/src/core/hle/service/ldn/ldn.cpp @@ -412,7 +412,7 @@ public: } void SetAdvertiseData(Kernel::HLERequestContext& ctx) { - std::vector read_buffer = ctx.ReadBuffer(); + const auto read_buffer = ctx.ReadBufferSpan(); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(lan_discovery.SetAdvertiseData(read_buffer)); @@ -464,7 +464,7 @@ public: parameters.security_config.passphrase_size, parameters.security_config.security_mode, parameters.local_communication_version); - const std::vector read_buffer = ctx.ReadBuffer(); + const auto read_buffer = ctx.ReadBufferSpan(); if (read_buffer.size() != sizeof(NetworkInfo)) { LOG_ERROR(Frontend, "NetworkInfo doesn't match read_buffer size!"); IPC::ResponseBuilder rb{ctx, 2}; diff --git a/src/core/hle/service/lm/lm.cpp b/src/core/hle/service/lm/lm.cpp index ef4b54046..0da461e6c 100644 --- a/src/core/hle/service/lm/lm.cpp +++ b/src/core/hle/service/lm/lm.cpp @@ -94,7 +94,7 @@ public: private: void Log(Kernel::HLERequestContext& ctx) { std::size_t offset{}; - const auto data = ctx.ReadBuffer(); + const auto data = ctx.ReadBufferSpan(); // This function only succeeds - Get that out of the way IPC::ResponseBuilder rb{ctx, 2}; diff --git a/src/core/hle/service/nfc/mifare_user.cpp b/src/core/hle/service/nfc/mifare_user.cpp index 51523a3ae..7d391c936 100644 --- a/src/core/hle/service/nfc/mifare_user.cpp +++ b/src/core/hle/service/nfc/mifare_user.cpp @@ -168,7 +168,7 @@ void MFIUser::StopDetection(Kernel::HLERequestContext& ctx) { void MFIUser::Read(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop()}; - const auto buffer{ctx.ReadBuffer()}; + const auto buffer{ctx.ReadBufferSpan()}; const auto number_of_commands{ctx.GetReadBufferNumElements()}; std::vector read_commands(number_of_commands); @@ -209,7 +209,7 @@ void MFIUser::Read(Kernel::HLERequestContext& ctx) { void MFIUser::Write(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop()}; - const auto buffer{ctx.ReadBuffer()}; + const auto buffer{ctx.ReadBufferSpan()}; const auto number_of_commands{ctx.GetReadBufferNumElements()}; std::vector write_commands(number_of_commands); diff --git a/src/core/hle/service/nfc/nfc_user.cpp b/src/core/hle/service/nfc/nfc_user.cpp index 89aa6b3f5..5dcf8a423 100644 --- a/src/core/hle/service/nfc/nfc_user.cpp +++ b/src/core/hle/service/nfc/nfc_user.cpp @@ -325,7 +325,7 @@ void IUser::SendCommandByPassThrough(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop()}; const auto timeout{rp.PopRaw()}; - const auto command_data{ctx.ReadBuffer()}; + const auto command_data{ctx.ReadBufferSpan()}; LOG_INFO(Service_NFC, "(STUBBED) called, device_handle={}, timeout={}, data_size={}", device_handle, timeout.ToSeconds(), command_data.size()); diff --git a/src/core/hle/service/nfp/nfp_user.cpp b/src/core/hle/service/nfp/nfp_user.cpp index a4d3d1bc7..0a5606756 100644 --- a/src/core/hle/service/nfp/nfp_user.cpp +++ b/src/core/hle/service/nfp/nfp_user.cpp @@ -290,7 +290,7 @@ void IUser::GetApplicationArea(Kernel::HLERequestContext& ctx) { void IUser::SetApplicationArea(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop()}; - const auto data{ctx.ReadBuffer()}; + const auto data{ctx.ReadBufferSpan()}; LOG_INFO(Service_NFP, "called, device_handle={}, data_size={}", device_handle, data.size()); if (state == State::NonInitialized) { @@ -370,7 +370,7 @@ void IUser::CreateApplicationArea(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop()}; const auto access_id{rp.Pop()}; - const auto data{ctx.ReadBuffer()}; + const auto data{ctx.ReadBufferSpan()}; LOG_INFO(Service_NFP, "called, device_handle={}, data_size={}, access_id={}", device_handle, access_id, data.size()); @@ -637,7 +637,7 @@ void IUser::RecreateApplicationArea(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop()}; const auto access_id{rp.Pop()}; - const auto data{ctx.ReadBuffer()}; + const auto data{ctx.ReadBufferSpan()}; LOG_INFO(Service_NFP, "called, device_handle={}, data_size={}, access_id={}", device_handle, access_id, data.size()); diff --git a/src/core/hle/service/ngct/ngct.cpp b/src/core/hle/service/ngct/ngct.cpp index 8af8a835d..bee62b054 100644 --- a/src/core/hle/service/ngct/ngct.cpp +++ b/src/core/hle/service/ngct/ngct.cpp @@ -24,7 +24,7 @@ public: private: void Match(Kernel::HLERequestContext& ctx) { - const auto buffer = ctx.ReadBuffer(); + const auto buffer = ctx.ReadBufferSpan(); const auto text = Common::StringFromFixedZeroTerminatedBuffer( reinterpret_cast(buffer.data()), buffer.size()); @@ -37,7 +37,7 @@ private: } void Filter(Kernel::HLERequestContext& ctx) { - const auto buffer = ctx.ReadBuffer(); + const auto buffer = ctx.ReadBufferSpan(); const auto text = Common::StringFromFixedZeroTerminatedBuffer( reinterpret_cast(buffer.data()), buffer.size()); diff --git a/src/core/hle/service/nifm/nifm.cpp b/src/core/hle/service/nifm/nifm.cpp index 4fa9f51a6..a6446fdcc 100644 --- a/src/core/hle/service/nifm/nifm.cpp +++ b/src/core/hle/service/nifm/nifm.cpp @@ -414,7 +414,7 @@ void IGeneralService::CreateTemporaryNetworkProfile(Kernel::HLERequestContext& c ASSERT_MSG(ctx.GetReadBufferSize() == 0x17c, "SfNetworkProfileData is not the correct size"); u128 uuid{}; - auto buffer = ctx.ReadBuffer(); + auto buffer = ctx.ReadBufferSpan(); std::memcpy(&uuid, buffer.data() + 8, sizeof(u128)); IPC::ResponseBuilder rb{ctx, 6, 0, 1}; diff --git a/src/core/hle/service/prepo/prepo.cpp b/src/core/hle/service/prepo/prepo.cpp index 78f897d3e..f6a141b2e 100644 --- a/src/core/hle/service/prepo/prepo.cpp +++ b/src/core/hle/service/prepo/prepo.cpp @@ -57,13 +57,13 @@ private: IPC::RequestParser rp{ctx}; const auto process_id = rp.PopRaw(); - const auto data1 = ctx.ReadBuffer(0); + const auto data1 = ctx.ReadBufferSpan(0); const auto data2 = [&ctx] { if (ctx.CanReadBuffer(1)) { - return ctx.ReadBuffer(1); + return ctx.ReadBufferSpan(1); } - return std::vector{}; + return std::span{}; }(); LOG_DEBUG(Service_PREPO, @@ -84,13 +84,13 @@ private: const auto user_id = rp.PopRaw(); const auto process_id = rp.PopRaw(); - const auto data1 = ctx.ReadBuffer(0); + const auto data1 = ctx.ReadBufferSpan(0); const auto data2 = [&ctx] { if (ctx.CanReadBuffer(1)) { - return ctx.ReadBuffer(1); + return ctx.ReadBufferSpan(1); } - return std::vector{}; + return std::span{}; }(); LOG_DEBUG(Service_PREPO, @@ -136,13 +136,13 @@ private: IPC::RequestParser rp{ctx}; const auto title_id = rp.PopRaw(); - const auto data1 = ctx.ReadBuffer(0); + const auto data1 = ctx.ReadBufferSpan(0); const auto data2 = [&ctx] { if (ctx.CanReadBuffer(1)) { - return ctx.ReadBuffer(1); + return ctx.ReadBufferSpan(1); } - return std::vector{}; + return std::span{}; }(); LOG_DEBUG(Service_PREPO, "called, title_id={:016X}, data1_size={:016X}, data2_size={:016X}", @@ -160,13 +160,13 @@ private: const auto user_id = rp.PopRaw(); const auto title_id = rp.PopRaw(); - const auto data1 = ctx.ReadBuffer(0); + const auto data1 = ctx.ReadBufferSpan(0); const auto data2 = [&ctx] { if (ctx.CanReadBuffer(1)) { - return ctx.ReadBuffer(1); + return ctx.ReadBufferSpan(1); } - return std::vector{}; + return std::span{}; }(); LOG_DEBUG(Service_PREPO, diff --git a/src/core/hle/service/set/set_sys.cpp b/src/core/hle/service/set/set_sys.cpp index 94c20edda..f1ace8184 100644 --- a/src/core/hle/service/set/set_sys.cpp +++ b/src/core/hle/service/set/set_sys.cpp @@ -131,12 +131,12 @@ void SET_SYS::GetSettingsItemValueSize(Kernel::HLERequestContext& ctx) { // The category of the setting. This corresponds to the top-level keys of // system_settings.ini. - const auto setting_category_buf{ctx.ReadBuffer(0)}; + const auto setting_category_buf{ctx.ReadBufferSpan(0)}; const std::string setting_category{setting_category_buf.begin(), setting_category_buf.end()}; // The name of the setting. This corresponds to the second-level keys of // system_settings.ini. - const auto setting_name_buf{ctx.ReadBuffer(1)}; + const auto setting_name_buf{ctx.ReadBufferSpan(1)}; const std::string setting_name{setting_name_buf.begin(), setting_name_buf.end()}; auto settings{GetSettings()}; @@ -156,12 +156,12 @@ void SET_SYS::GetSettingsItemValue(Kernel::HLERequestContext& ctx) { // The category of the setting. This corresponds to the top-level keys of // system_settings.ini. - const auto setting_category_buf{ctx.ReadBuffer(0)}; + const auto setting_category_buf{ctx.ReadBufferSpan(0)}; const std::string setting_category{setting_category_buf.begin(), setting_category_buf.end()}; // The name of the setting. This corresponds to the second-level keys of // system_settings.ini. - const auto setting_name_buf{ctx.ReadBuffer(1)}; + const auto setting_name_buf{ctx.ReadBufferSpan(1)}; const std::string setting_name{setting_name_buf.begin(), setting_name_buf.end()}; auto settings{GetSettings()}; diff --git a/src/core/hle/service/sockets/sfdnsres.cpp b/src/core/hle/service/sockets/sfdnsres.cpp index 097c37d7a..6d0e1dd6c 100644 --- a/src/core/hle/service/sockets/sfdnsres.cpp +++ b/src/core/hle/service/sockets/sfdnsres.cpp @@ -199,10 +199,10 @@ static std::pair GetAddrInfoRequestImpl(Kernel::HLERequestContext& ctx "called with ignored parameters: use_nsd_resolve={}, unknown={}, process_id={}", parameters.use_nsd_resolve, parameters.unknown, parameters.process_id); - const auto host_buffer = ctx.ReadBuffer(0); + const auto host_buffer = ctx.ReadBufferSpan(0); const std::string host = Common::StringFromBuffer(host_buffer); - const auto service_buffer = ctx.ReadBuffer(1); + const auto service_buffer = ctx.ReadBufferSpan(1); const std::string service = Common::StringFromBuffer(service_buffer); addrinfo* addrinfo; @@ -243,4 +243,4 @@ void SFDNSRES::GetAddrInfoRequestWithOptions(Kernel::HLERequestContext& ctx) { rb.Push(0); } -} // namespace Service::Sockets \ No newline at end of file +} // namespace Service::Sockets diff --git a/src/core/hle/service/ssl/ssl.cpp b/src/core/hle/service/ssl/ssl.cpp index 3735e0452..10851f08f 100644 --- a/src/core/hle/service/ssl/ssl.cpp +++ b/src/core/hle/service/ssl/ssl.cpp @@ -101,7 +101,7 @@ private: void ImportServerPki(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto certificate_format = rp.PopEnum(); - const auto pkcs_12_certificates = ctx.ReadBuffer(0); + [[maybe_unused]] const auto pkcs_12_certificates = ctx.ReadBufferSpan(0); constexpr u64 server_id = 0; @@ -113,13 +113,13 @@ private: } void ImportClientPki(Kernel::HLERequestContext& ctx) { - const auto pkcs_12_certificate = ctx.ReadBuffer(0); - const auto ascii_password = [&ctx] { + [[maybe_unused]] const auto pkcs_12_certificate = ctx.ReadBufferSpan(0); + [[maybe_unused]] const auto ascii_password = [&ctx] { if (ctx.CanReadBuffer(1)) { - return ctx.ReadBuffer(1); + return ctx.ReadBufferSpan(1); } - return std::vector{}; + return std::span{}; }(); constexpr u64 client_id = 0; diff --git a/src/core/hle/service/time/time.cpp b/src/core/hle/service/time/time.cpp index f77cdbb43..9376e0902 100644 --- a/src/core/hle/service/time/time.cpp +++ b/src/core/hle/service/time/time.cpp @@ -328,8 +328,8 @@ void Module::Interface::CalculateStandardUserSystemClockDifferenceByUser( Clock::ClockSnapshot snapshot_a; Clock::ClockSnapshot snapshot_b; - const auto snapshot_a_data = ctx.ReadBuffer(0); - const auto snapshot_b_data = ctx.ReadBuffer(1); + const auto snapshot_a_data = ctx.ReadBufferSpan(0); + const auto snapshot_b_data = ctx.ReadBufferSpan(1); std::memcpy(&snapshot_a, snapshot_a_data.data(), sizeof(Clock::ClockSnapshot)); std::memcpy(&snapshot_b, snapshot_b_data.data(), sizeof(Clock::ClockSnapshot)); @@ -355,8 +355,8 @@ void Module::Interface::CalculateSpanBetween(Kernel::HLERequestContext& ctx) { Clock::ClockSnapshot snapshot_a; Clock::ClockSnapshot snapshot_b; - const auto snapshot_a_data = ctx.ReadBuffer(0); - const auto snapshot_b_data = ctx.ReadBuffer(1); + const auto snapshot_a_data = ctx.ReadBufferSpan(0); + const auto snapshot_b_data = ctx.ReadBufferSpan(1); std::memcpy(&snapshot_a, snapshot_a_data.data(), sizeof(Clock::ClockSnapshot)); std::memcpy(&snapshot_b, snapshot_b_data.data(), sizeof(Clock::ClockSnapshot)); diff --git a/src/core/hle/service/time/time_zone_service.cpp b/src/core/hle/service/time/time_zone_service.cpp index 961040bfc..6d05a66f1 100644 --- a/src/core/hle/service/time/time_zone_service.cpp +++ b/src/core/hle/service/time/time_zone_service.cpp @@ -84,7 +84,7 @@ void ITimeZoneService::ToCalendarTime(Kernel::HLERequestContext& ctx) { LOG_DEBUG(Service_Time, "called, posix_time=0x{:016X}", posix_time); TimeZone::TimeZoneRule time_zone_rule{}; - const auto buffer{ctx.ReadBuffer()}; + const auto buffer{ctx.ReadBufferSpan()}; std::memcpy(&time_zone_rule, buffer.data(), buffer.size()); TimeZone::CalendarInfo calendar_info{}; @@ -128,7 +128,7 @@ void ITimeZoneService::ToPosixTime(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto calendar_time{rp.PopRaw()}; TimeZone::TimeZoneRule time_zone_rule{}; - std::memcpy(&time_zone_rule, ctx.ReadBuffer().data(), sizeof(TimeZone::TimeZoneRule)); + std::memcpy(&time_zone_rule, ctx.ReadBufferSpan().data(), sizeof(TimeZone::TimeZoneRule)); s64 posix_time{}; if (const Result result{time_zone_content_manager.GetTimeZoneManager().ToPosixTime( diff --git a/src/core/reporter.cpp b/src/core/reporter.cpp index 77821e047..59dfb8767 100644 --- a/src/core/reporter.cpp +++ b/src/core/reporter.cpp @@ -312,7 +312,7 @@ void Reporter::SaveUnimplementedAppletReport( } void Reporter::SavePlayReport(PlayReportType type, u64 title_id, - const std::vector>& data, + const std::vector>& data, std::optional process_id, std::optional user_id) const { if (!IsReportingEnabled()) { return; diff --git a/src/core/reporter.h b/src/core/reporter.h index 9fdb9d6c1..bb11f8e7c 100644 --- a/src/core/reporter.h +++ b/src/core/reporter.h @@ -5,6 +5,7 @@ #include #include +#include #include #include #include "common/common_types.h" @@ -56,7 +57,8 @@ public: System, }; - void SavePlayReport(PlayReportType type, u64 title_id, const std::vector>& data, + void SavePlayReport(PlayReportType type, u64 title_id, + const std::vector>& data, std::optional process_id = {}, std::optional user_id = {}) const; // Used by error applet From 32d01a39b010e3aabca8551767909fd388febf99 Mon Sep 17 00:00:00 2001 From: ameerj <52414509+ameerj@users.noreply.github.com> Date: Sun, 25 Dec 2022 13:57:16 -0500 Subject: [PATCH 04/10] nvflinger: Split Parcel class into InputParcel and OutputParcel The usages of the Parcel class were already unique to either Read or Write operations. Avoids needing a vector of the input payload for the InputParcel use-case, instead it can remain as a span. --- .../nvflinger/buffer_queue_producer.cpp | 4 +- .../nvflinger/graphic_buffer_producer.cpp | 2 +- .../nvflinger/graphic_buffer_producer.h | 4 +- src/core/hle/service/nvflinger/parcel.h | 87 ++++++++++--------- src/core/hle/service/vi/vi.cpp | 4 +- 5 files changed, 53 insertions(+), 48 deletions(-) diff --git a/src/core/hle/service/nvflinger/buffer_queue_producer.cpp b/src/core/hle/service/nvflinger/buffer_queue_producer.cpp index e601b5da1..abed92d06 100644 --- a/src/core/hle/service/nvflinger/buffer_queue_producer.cpp +++ b/src/core/hle/service/nvflinger/buffer_queue_producer.cpp @@ -815,8 +815,8 @@ Status BufferQueueProducer::SetPreallocatedBuffer(s32 slot, void BufferQueueProducer::Transact(Kernel::HLERequestContext& ctx, TransactionId code, u32 flags) { Status status{Status::NoError}; - Parcel parcel_in{ctx.ReadBuffer()}; - Parcel parcel_out{}; + InputParcel parcel_in{ctx.ReadBufferSpan()}; + OutputParcel parcel_out{}; switch (code) { case TransactionId::Connect: { diff --git a/src/core/hle/service/nvflinger/graphic_buffer_producer.cpp b/src/core/hle/service/nvflinger/graphic_buffer_producer.cpp index 4043c91f1..769e8c0a3 100644 --- a/src/core/hle/service/nvflinger/graphic_buffer_producer.cpp +++ b/src/core/hle/service/nvflinger/graphic_buffer_producer.cpp @@ -9,7 +9,7 @@ namespace Service::android { -QueueBufferInput::QueueBufferInput(Parcel& parcel) { +QueueBufferInput::QueueBufferInput(InputParcel& parcel) { parcel.ReadFlattened(*this); } diff --git a/src/core/hle/service/nvflinger/graphic_buffer_producer.h b/src/core/hle/service/nvflinger/graphic_buffer_producer.h index 6ea327bbe..2969f0fd5 100644 --- a/src/core/hle/service/nvflinger/graphic_buffer_producer.h +++ b/src/core/hle/service/nvflinger/graphic_buffer_producer.h @@ -14,11 +14,11 @@ namespace Service::android { -class Parcel; +class InputParcel; #pragma pack(push, 1) struct QueueBufferInput final { - explicit QueueBufferInput(Parcel& parcel); + explicit QueueBufferInput(InputParcel& parcel); void Deflate(s64* timestamp_, bool* is_auto_timestamp_, Common::Rectangle* crop_, NativeWindowScalingMode* scaling_mode_, NativeWindowTransform* transform_, diff --git a/src/core/hle/service/nvflinger/parcel.h b/src/core/hle/service/nvflinger/parcel.h index f3fa2587d..d1b6201e0 100644 --- a/src/core/hle/service/nvflinger/parcel.h +++ b/src/core/hle/service/nvflinger/parcel.h @@ -4,6 +4,7 @@ #pragma once #include +#include #include #include "common/alignment.h" @@ -12,18 +13,17 @@ namespace Service::android { -class Parcel final { +struct ParcelHeader { + u32 data_size; + u32 data_offset; + u32 objects_size; + u32 objects_offset; +}; +static_assert(sizeof(ParcelHeader) == 16, "ParcelHeader has wrong size"); + +class InputParcel final { public: - static constexpr std::size_t DefaultBufferSize = 0x40; - - Parcel() : buffer(DefaultBufferSize) {} - - template - explicit Parcel(const T& out_data) : buffer(DefaultBufferSize) { - Write(out_data); - } - - explicit Parcel(std::vector in_data) : buffer(std::move(in_data)) { + explicit InputParcel(std::span in_data) : read_buffer(std::move(in_data)) { DeserializeHeader(); [[maybe_unused]] const std::u16string token = ReadInterfaceToken(); } @@ -31,9 +31,9 @@ public: template void Read(T& val) { static_assert(std::is_trivially_copyable_v, "T must be trivially copyable."); - ASSERT(read_index + sizeof(T) <= buffer.size()); + ASSERT(read_index + sizeof(T) <= read_buffer.size()); - std::memcpy(&val, buffer.data() + read_index, sizeof(T)); + std::memcpy(&val, read_buffer.data() + read_index, sizeof(T)); read_index += sizeof(T); read_index = Common::AlignUp(read_index, 4); } @@ -62,10 +62,10 @@ public: template T ReadUnaligned() { static_assert(std::is_trivially_copyable_v, "T must be trivially copyable."); - ASSERT(read_index + sizeof(T) <= buffer.size()); + ASSERT(read_index + sizeof(T) <= read_buffer.size()); T val; - std::memcpy(&val, buffer.data() + read_index, sizeof(T)); + std::memcpy(&val, read_buffer.data() + read_index, sizeof(T)); read_index += sizeof(T); return val; } @@ -101,6 +101,31 @@ public: return token; } + void DeserializeHeader() { + ASSERT(read_buffer.size() > sizeof(ParcelHeader)); + + ParcelHeader header{}; + std::memcpy(&header, read_buffer.data(), sizeof(ParcelHeader)); + + read_index = header.data_offset; + } + +private: + std::span read_buffer; + std::size_t read_index = 0; +}; + +class OutputParcel final { +public: + static constexpr std::size_t DefaultBufferSize = 0x40; + + OutputParcel() : buffer(DefaultBufferSize) {} + + template + explicit OutputParcel(const T& out_data) : buffer(DefaultBufferSize) { + Write(out_data); + } + template void Write(const T& val) { static_assert(std::is_trivially_copyable_v, "T must be trivially copyable."); @@ -133,40 +158,20 @@ public: WriteObject(ptr.get()); } - void DeserializeHeader() { - ASSERT(buffer.size() > sizeof(Header)); - - Header header{}; - std::memcpy(&header, buffer.data(), sizeof(Header)); - - read_index = header.data_offset; - } - std::vector Serialize() const { - ASSERT(read_index == 0); - - Header header{}; - header.data_size = static_cast(write_index - sizeof(Header)); - header.data_offset = sizeof(Header); + ParcelHeader header{}; + header.data_size = static_cast(write_index - sizeof(ParcelHeader)); + header.data_offset = sizeof(ParcelHeader); header.objects_size = 4; - header.objects_offset = static_cast(sizeof(Header) + header.data_size); - std::memcpy(buffer.data(), &header, sizeof(Header)); + header.objects_offset = static_cast(sizeof(ParcelHeader) + header.data_size); + std::memcpy(buffer.data(), &header, sizeof(ParcelHeader)); return buffer; } private: - struct Header { - u32 data_size; - u32 data_offset; - u32 objects_size; - u32 objects_offset; - }; - static_assert(sizeof(Header) == 16, "ParcelHeader has wrong size"); - mutable std::vector buffer; - std::size_t read_index = 0; - std::size_t write_index = sizeof(Header); + std::size_t write_index = sizeof(ParcelHeader); }; } // namespace Service::android diff --git a/src/core/hle/service/vi/vi.cpp b/src/core/hle/service/vi/vi.cpp index bb283e74e..2fb631183 100644 --- a/src/core/hle/service/vi/vi.cpp +++ b/src/core/hle/service/vi/vi.cpp @@ -603,7 +603,7 @@ private: return; } - const auto parcel = android::Parcel{NativeWindow{*buffer_queue_id}}; + const auto parcel = android::OutputParcel{NativeWindow{*buffer_queue_id}}; const auto buffer_size = ctx.WriteBuffer(parcel.Serialize()); IPC::ResponseBuilder rb{ctx, 4}; @@ -649,7 +649,7 @@ private: return; } - const auto parcel = android::Parcel{NativeWindow{*buffer_queue_id}}; + const auto parcel = android::OutputParcel{NativeWindow{*buffer_queue_id}}; const auto buffer_size = ctx.WriteBuffer(parcel.Serialize()); IPC::ResponseBuilder rb{ctx, 6}; From e7032d9e641f99366242000fbc9ca59a55d1a95f Mon Sep 17 00:00:00 2001 From: ameerj <52414509+ameerj@users.noreply.github.com> Date: Sun, 25 Dec 2022 14:00:20 -0500 Subject: [PATCH 05/10] hidbus: Use ReadBufferSpan --- src/core/hle/service/hid/controllers/npad.cpp | 5 +++-- src/core/hle/service/hid/controllers/npad.h | 3 ++- src/core/hle/service/hid/hid.cpp | 2 +- src/core/hle/service/hid/hidbus.cpp | 2 +- src/core/hle/service/hid/hidbus/hidbus_base.h | 3 ++- src/core/hle/service/hid/hidbus/ringcon.cpp | 2 +- src/core/hle/service/hid/hidbus/ringcon.h | 3 ++- src/core/hle/service/hid/hidbus/starlink.cpp | 2 +- src/core/hle/service/hid/hidbus/starlink.h | 2 +- src/core/hle/service/hid/hidbus/stubbed.cpp | 2 +- src/core/hle/service/hid/hidbus/stubbed.h | 2 +- 11 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp index df63083a8..713f8e0c6 100644 --- a/src/core/hle/service/hid/controllers/npad.cpp +++ b/src/core/hle/service/hid/controllers/npad.cpp @@ -737,11 +737,12 @@ Core::HID::NpadStyleTag Controller_NPad::GetSupportedStyleSet() const { return hid_core.GetSupportedStyleTag(); } -void Controller_NPad::SetSupportedNpadIdTypes(const u8* const data, std::size_t length) { +void Controller_NPad::SetSupportedNpadIdTypes(std::span data) { + const auto length = data.size(); ASSERT(length > 0 && (length % sizeof(u32)) == 0); supported_npad_id_types.clear(); supported_npad_id_types.resize(length / sizeof(u32)); - std::memcpy(supported_npad_id_types.data(), data, length); + std::memcpy(supported_npad_id_types.data(), data.data(), length); } void Controller_NPad::GetSupportedNpadIdTypes(u32* data, std::size_t max_length) { diff --git a/src/core/hle/service/hid/controllers/npad.h b/src/core/hle/service/hid/controllers/npad.h index 988ac8ec4..1f7d33459 100644 --- a/src/core/hle/service/hid/controllers/npad.h +++ b/src/core/hle/service/hid/controllers/npad.h @@ -6,6 +6,7 @@ #include #include #include +#include #include "common/bit_field.h" #include "common/common_types.h" @@ -95,7 +96,7 @@ public: void SetSupportedStyleSet(Core::HID::NpadStyleTag style_set); Core::HID::NpadStyleTag GetSupportedStyleSet() const; - void SetSupportedNpadIdTypes(const u8* const data, std::size_t length); + void SetSupportedNpadIdTypes(std::span data); void GetSupportedNpadIdTypes(u32* data, std::size_t max_length); std::size_t GetSupportedNpadIdTypesSize() const; diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index 80db6af06..294fe927b 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp @@ -1026,7 +1026,7 @@ void Hid::SetSupportedNpadIdType(Kernel::HLERequestContext& ctx) { const auto applet_resource_user_id{rp.Pop()}; applet_resource->GetController(HidController::NPad) - .SetSupportedNpadIdTypes(ctx.ReadBufferSpan().data(), ctx.GetReadBufferSize()); + .SetSupportedNpadIdTypes(ctx.ReadBufferSpan()); LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); diff --git a/src/core/hle/service/hid/hidbus.cpp b/src/core/hle/service/hid/hidbus.cpp index e5e50845f..abc15c34e 100644 --- a/src/core/hle/service/hid/hidbus.cpp +++ b/src/core/hle/service/hid/hidbus.cpp @@ -351,7 +351,7 @@ void HidBus::GetExternalDeviceId(Kernel::HLERequestContext& ctx) { void HidBus::SendCommandAsync(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - const auto data = ctx.ReadBuffer(); + const auto data = ctx.ReadBufferSpan(); const auto bus_handle_{rp.PopRaw()}; LOG_DEBUG(Service_HID, diff --git a/src/core/hle/service/hid/hidbus/hidbus_base.h b/src/core/hle/service/hid/hidbus/hidbus_base.h index d3960f506..65e301137 100644 --- a/src/core/hle/service/hid/hidbus/hidbus_base.h +++ b/src/core/hle/service/hid/hidbus/hidbus_base.h @@ -4,6 +4,7 @@ #pragma once #include +#include #include "common/common_types.h" #include "core/hle/result.h" @@ -150,7 +151,7 @@ public: } // Assigns a command from data - virtual bool SetCommand(const std::vector& data) { + virtual bool SetCommand(std::span data) { return {}; } diff --git a/src/core/hle/service/hid/hidbus/ringcon.cpp b/src/core/hle/service/hid/hidbus/ringcon.cpp index 57f1a2a26..7ab3903dc 100644 --- a/src/core/hle/service/hid/hidbus/ringcon.cpp +++ b/src/core/hle/service/hid/hidbus/ringcon.cpp @@ -112,7 +112,7 @@ std::vector RingController::GetReply() const { } } -bool RingController::SetCommand(const std::vector& data) { +bool RingController::SetCommand(std::span data) { if (data.size() < 4) { LOG_ERROR(Service_HID, "Command size not supported {}", data.size()); command = RingConCommands::Error; diff --git a/src/core/hle/service/hid/hidbus/ringcon.h b/src/core/hle/service/hid/hidbus/ringcon.h index b37df50ac..8e195ca79 100644 --- a/src/core/hle/service/hid/hidbus/ringcon.h +++ b/src/core/hle/service/hid/hidbus/ringcon.h @@ -4,6 +4,7 @@ #pragma once #include +#include #include "common/common_types.h" #include "core/hle/service/hid/hidbus/hidbus_base.h" @@ -31,7 +32,7 @@ public: u8 GetDeviceId() const override; // Assigns a command from data - bool SetCommand(const std::vector& data) override; + bool SetCommand(std::span data) override; // Returns a reply from a command std::vector GetReply() const override; diff --git a/src/core/hle/service/hid/hidbus/starlink.cpp b/src/core/hle/service/hid/hidbus/starlink.cpp index dd439f60a..d0e760314 100644 --- a/src/core/hle/service/hid/hidbus/starlink.cpp +++ b/src/core/hle/service/hid/hidbus/starlink.cpp @@ -42,7 +42,7 @@ std::vector Starlink::GetReply() const { return {}; } -bool Starlink::SetCommand(const std::vector& data) { +bool Starlink::SetCommand(std::span data) { LOG_ERROR(Service_HID, "Command not implemented"); return false; } diff --git a/src/core/hle/service/hid/hidbus/starlink.h b/src/core/hle/service/hid/hidbus/starlink.h index 0b1b7ba49..07c800e6e 100644 --- a/src/core/hle/service/hid/hidbus/starlink.h +++ b/src/core/hle/service/hid/hidbus/starlink.h @@ -29,7 +29,7 @@ public: u8 GetDeviceId() const override; // Assigns a command from data - bool SetCommand(const std::vector& data) override; + bool SetCommand(std::span data) override; // Returns a reply from a command std::vector GetReply() const override; diff --git a/src/core/hle/service/hid/hidbus/stubbed.cpp b/src/core/hle/service/hid/hidbus/stubbed.cpp index e477443e3..07632c872 100644 --- a/src/core/hle/service/hid/hidbus/stubbed.cpp +++ b/src/core/hle/service/hid/hidbus/stubbed.cpp @@ -43,7 +43,7 @@ std::vector HidbusStubbed::GetReply() const { return {}; } -bool HidbusStubbed::SetCommand(const std::vector& data) { +bool HidbusStubbed::SetCommand(std::span data) { LOG_ERROR(Service_HID, "Command not implemented"); return false; } diff --git a/src/core/hle/service/hid/hidbus/stubbed.h b/src/core/hle/service/hid/hidbus/stubbed.h index 91165ceff..38eaa0ecc 100644 --- a/src/core/hle/service/hid/hidbus/stubbed.h +++ b/src/core/hle/service/hid/hidbus/stubbed.h @@ -29,7 +29,7 @@ public: u8 GetDeviceId() const override; // Assigns a command from data - bool SetCommand(const std::vector& data) override; + bool SetCommand(std::span data) override; // Returns a reply from a command std::vector GetReply() const override; From f517f824167a6d01a65dcbb8662e4a071b5210bb Mon Sep 17 00:00:00 2001 From: ameerj <52414509+ameerj@users.noreply.github.com> Date: Sun, 25 Dec 2022 14:13:07 -0500 Subject: [PATCH 06/10] nvdrv: Use std::span for inputs Allows the use of HLERequestContext::ReadBufferSpan --- src/core/hle/service/nvdrv/devices/nvdevice.h | 10 +++--- .../service/nvdrv/devices/nvdisp_disp0.cpp | 8 ++--- .../hle/service/nvdrv/devices/nvdisp_disp0.h | 10 +++--- .../service/nvdrv/devices/nvhost_as_gpu.cpp | 26 +++++++------- .../hle/service/nvdrv/devices/nvhost_as_gpu.h | 28 +++++++-------- .../hle/service/nvdrv/devices/nvhost_ctrl.cpp | 21 ++++++----- .../hle/service/nvdrv/devices/nvhost_ctrl.h | 22 ++++++------ .../service/nvdrv/devices/nvhost_ctrl_gpu.cpp | 31 ++++++++-------- .../service/nvdrv/devices/nvhost_ctrl_gpu.h | 32 ++++++++--------- .../hle/service/nvdrv/devices/nvhost_gpu.cpp | 35 +++++++++--------- .../hle/service/nvdrv/devices/nvhost_gpu.h | 36 +++++++++---------- .../service/nvdrv/devices/nvhost_nvdec.cpp | 8 ++--- .../hle/service/nvdrv/devices/nvhost_nvdec.h | 10 +++--- .../nvdrv/devices/nvhost_nvdec_common.cpp | 17 +++++---- .../nvdrv/devices/nvhost_nvdec_common.h | 14 ++++---- .../service/nvdrv/devices/nvhost_nvjpg.cpp | 10 +++--- .../hle/service/nvdrv/devices/nvhost_nvjpg.h | 12 +++---- .../hle/service/nvdrv/devices/nvhost_vic.cpp | 8 ++--- .../hle/service/nvdrv/devices/nvhost_vic.h | 10 +++--- src/core/hle/service/nvdrv/devices/nvmap.cpp | 20 +++++------ src/core/hle/service/nvdrv/devices/nvmap.h | 22 ++++++------ src/core/hle/service/nvdrv/nvdrv.cpp | 8 ++--- src/core/hle/service/nvdrv/nvdrv.h | 12 +++---- .../hle/service/nvdrv/nvdrv_interface.cpp | 10 +++--- 24 files changed, 209 insertions(+), 211 deletions(-) diff --git a/src/core/hle/service/nvdrv/devices/nvdevice.h b/src/core/hle/service/nvdrv/devices/nvdevice.h index 204b0e757..c562e04d2 100644 --- a/src/core/hle/service/nvdrv/devices/nvdevice.h +++ b/src/core/hle/service/nvdrv/devices/nvdevice.h @@ -3,7 +3,9 @@ #pragma once +#include #include + #include "common/common_types.h" #include "core/hle/service/nvdrv/nvdata.h" @@ -31,7 +33,7 @@ public: * @param output A buffer where the output data will be written to. * @returns The result code of the ioctl. */ - virtual NvResult Ioctl1(DeviceFD fd, Ioctl command, const std::vector& input, + virtual NvResult Ioctl1(DeviceFD fd, Ioctl command, std::span input, std::vector& output) = 0; /** @@ -42,8 +44,8 @@ public: * @param output A buffer where the output data will be written to. * @returns The result code of the ioctl. */ - virtual NvResult Ioctl2(DeviceFD fd, Ioctl command, const std::vector& input, - const std::vector& inline_input, std::vector& output) = 0; + virtual NvResult Ioctl2(DeviceFD fd, Ioctl command, std::span input, + std::span inline_input, std::vector& output) = 0; /** * Handles an ioctl3 request. @@ -53,7 +55,7 @@ public: * @param inline_output A buffer where the inlined output data will be written to. * @returns The result code of the ioctl. */ - virtual NvResult Ioctl3(DeviceFD fd, Ioctl command, const std::vector& input, + virtual NvResult Ioctl3(DeviceFD fd, Ioctl command, std::span input, std::vector& output, std::vector& inline_output) = 0; /** diff --git a/src/core/hle/service/nvdrv/devices/nvdisp_disp0.cpp b/src/core/hle/service/nvdrv/devices/nvdisp_disp0.cpp index 4122fc98d..5a5b2e305 100644 --- a/src/core/hle/service/nvdrv/devices/nvdisp_disp0.cpp +++ b/src/core/hle/service/nvdrv/devices/nvdisp_disp0.cpp @@ -17,19 +17,19 @@ nvdisp_disp0::nvdisp_disp0(Core::System& system_, NvCore::Container& core) : nvdevice{system_}, container{core}, nvmap{core.GetNvMapFile()} {} nvdisp_disp0::~nvdisp_disp0() = default; -NvResult nvdisp_disp0::Ioctl1(DeviceFD fd, Ioctl command, const std::vector& input, +NvResult nvdisp_disp0::Ioctl1(DeviceFD fd, Ioctl command, std::span input, std::vector& output) { UNIMPLEMENTED_MSG("Unimplemented ioctl={:08X}", command.raw); return NvResult::NotImplemented; } -NvResult nvdisp_disp0::Ioctl2(DeviceFD fd, Ioctl command, const std::vector& input, - const std::vector& inline_input, std::vector& output) { +NvResult nvdisp_disp0::Ioctl2(DeviceFD fd, Ioctl command, std::span input, + std::span inline_input, std::vector& output) { UNIMPLEMENTED_MSG("Unimplemented ioctl={:08X}", command.raw); return NvResult::NotImplemented; } -NvResult nvdisp_disp0::Ioctl3(DeviceFD fd, Ioctl command, const std::vector& input, +NvResult nvdisp_disp0::Ioctl3(DeviceFD fd, Ioctl command, std::span input, std::vector& output, std::vector& inline_output) { UNIMPLEMENTED_MSG("Unimplemented ioctl={:08X}", command.raw); return NvResult::NotImplemented; diff --git a/src/core/hle/service/nvdrv/devices/nvdisp_disp0.h b/src/core/hle/service/nvdrv/devices/nvdisp_disp0.h index 04217ab12..81bd7960a 100644 --- a/src/core/hle/service/nvdrv/devices/nvdisp_disp0.h +++ b/src/core/hle/service/nvdrv/devices/nvdisp_disp0.h @@ -25,12 +25,12 @@ public: explicit nvdisp_disp0(Core::System& system_, NvCore::Container& core); ~nvdisp_disp0() override; - NvResult Ioctl1(DeviceFD fd, Ioctl command, const std::vector& input, + NvResult Ioctl1(DeviceFD fd, Ioctl command, std::span input, std::vector& output) override; - NvResult Ioctl2(DeviceFD fd, Ioctl command, const std::vector& input, - const std::vector& inline_input, std::vector& output) override; - NvResult Ioctl3(DeviceFD fd, Ioctl command, const std::vector& input, - std::vector& output, std::vector& inline_output) override; + NvResult Ioctl2(DeviceFD fd, Ioctl command, std::span input, + std::span inline_input, std::vector& output) override; + NvResult Ioctl3(DeviceFD fd, Ioctl command, std::span input, std::vector& output, + std::vector& inline_output) override; void OnOpen(DeviceFD fd) override; void OnClose(DeviceFD fd) override; diff --git a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp index b635e6ed1..681bd0867 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp +++ b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp @@ -27,7 +27,7 @@ nvhost_as_gpu::nvhost_as_gpu(Core::System& system_, Module& module_, NvCore::Con nvhost_as_gpu::~nvhost_as_gpu() = default; -NvResult nvhost_as_gpu::Ioctl1(DeviceFD fd, Ioctl command, const std::vector& input, +NvResult nvhost_as_gpu::Ioctl1(DeviceFD fd, Ioctl command, std::span input, std::vector& output) { switch (command.group) { case 'A': @@ -60,13 +60,13 @@ NvResult nvhost_as_gpu::Ioctl1(DeviceFD fd, Ioctl command, const std::vector return NvResult::NotImplemented; } -NvResult nvhost_as_gpu::Ioctl2(DeviceFD fd, Ioctl command, const std::vector& input, - const std::vector& inline_input, std::vector& output) { +NvResult nvhost_as_gpu::Ioctl2(DeviceFD fd, Ioctl command, std::span input, + std::span inline_input, std::vector& output) { UNIMPLEMENTED_MSG("Unimplemented ioctl={:08X}", command.raw); return NvResult::NotImplemented; } -NvResult nvhost_as_gpu::Ioctl3(DeviceFD fd, Ioctl command, const std::vector& input, +NvResult nvhost_as_gpu::Ioctl3(DeviceFD fd, Ioctl command, std::span input, std::vector& output, std::vector& inline_output) { switch (command.group) { case 'A': @@ -87,7 +87,7 @@ NvResult nvhost_as_gpu::Ioctl3(DeviceFD fd, Ioctl command, const std::vector void nvhost_as_gpu::OnOpen(DeviceFD fd) {} void nvhost_as_gpu::OnClose(DeviceFD fd) {} -NvResult nvhost_as_gpu::AllocAsEx(const std::vector& input, std::vector& output) { +NvResult nvhost_as_gpu::AllocAsEx(std::span input, std::vector& output) { IoctlAllocAsEx params{}; std::memcpy(¶ms, input.data(), input.size()); @@ -141,7 +141,7 @@ NvResult nvhost_as_gpu::AllocAsEx(const std::vector& input, std::vector& return NvResult::Success; } -NvResult nvhost_as_gpu::AllocateSpace(const std::vector& input, std::vector& output) { +NvResult nvhost_as_gpu::AllocateSpace(std::span input, std::vector& output) { IoctlAllocSpace params{}; std::memcpy(¶ms, input.data(), input.size()); @@ -220,7 +220,7 @@ void nvhost_as_gpu::FreeMappingLocked(u64 offset) { mapping_map.erase(offset); } -NvResult nvhost_as_gpu::FreeSpace(const std::vector& input, std::vector& output) { +NvResult nvhost_as_gpu::FreeSpace(std::span input, std::vector& output) { IoctlFreeSpace params{}; std::memcpy(¶ms, input.data(), input.size()); @@ -266,7 +266,7 @@ NvResult nvhost_as_gpu::FreeSpace(const std::vector& input, std::vector& return NvResult::Success; } -NvResult nvhost_as_gpu::Remap(const std::vector& input, std::vector& output) { +NvResult nvhost_as_gpu::Remap(std::span input, std::vector& output) { const auto num_entries = input.size() / sizeof(IoctlRemapEntry); LOG_DEBUG(Service_NVDRV, "called, num_entries=0x{:X}", num_entries); @@ -320,7 +320,7 @@ NvResult nvhost_as_gpu::Remap(const std::vector& input, std::vector& out return NvResult::Success; } -NvResult nvhost_as_gpu::MapBufferEx(const std::vector& input, std::vector& output) { +NvResult nvhost_as_gpu::MapBufferEx(std::span input, std::vector& output) { IoctlMapBufferEx params{}; std::memcpy(¶ms, input.data(), input.size()); @@ -424,7 +424,7 @@ NvResult nvhost_as_gpu::MapBufferEx(const std::vector& input, std::vector& input, std::vector& output) { +NvResult nvhost_as_gpu::UnmapBuffer(std::span input, std::vector& output) { IoctlUnmapBuffer params{}; std::memcpy(¶ms, input.data(), input.size()); @@ -463,7 +463,7 @@ NvResult nvhost_as_gpu::UnmapBuffer(const std::vector& input, std::vector& input, std::vector& output) { +NvResult nvhost_as_gpu::BindChannel(std::span input, std::vector& output) { IoctlBindChannel params{}; std::memcpy(¶ms, input.data(), input.size()); LOG_DEBUG(Service_NVDRV, "called, fd={:X}", params.fd); @@ -492,7 +492,7 @@ void nvhost_as_gpu::GetVARegionsImpl(IoctlGetVaRegions& params) { }; } -NvResult nvhost_as_gpu::GetVARegions(const std::vector& input, std::vector& output) { +NvResult nvhost_as_gpu::GetVARegions(std::span input, std::vector& output) { IoctlGetVaRegions params{}; std::memcpy(¶ms, input.data(), input.size()); @@ -511,7 +511,7 @@ NvResult nvhost_as_gpu::GetVARegions(const std::vector& input, std::vector& input, std::vector& output, +NvResult nvhost_as_gpu::GetVARegions(std::span input, std::vector& output, std::vector& inline_output) { IoctlGetVaRegions params{}; std::memcpy(¶ms, input.data(), input.size()); diff --git a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.h b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.h index 86fe71c75..1aba8d579 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.h +++ b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.h @@ -47,12 +47,12 @@ public: explicit nvhost_as_gpu(Core::System& system_, Module& module, NvCore::Container& core); ~nvhost_as_gpu() override; - NvResult Ioctl1(DeviceFD fd, Ioctl command, const std::vector& input, + NvResult Ioctl1(DeviceFD fd, Ioctl command, std::span input, std::vector& output) override; - NvResult Ioctl2(DeviceFD fd, Ioctl command, const std::vector& input, - const std::vector& inline_input, std::vector& output) override; - NvResult Ioctl3(DeviceFD fd, Ioctl command, const std::vector& input, - std::vector& output, std::vector& inline_output) override; + NvResult Ioctl2(DeviceFD fd, Ioctl command, std::span input, + std::span inline_input, std::vector& output) override; + NvResult Ioctl3(DeviceFD fd, Ioctl command, std::span input, std::vector& output, + std::vector& inline_output) override; void OnOpen(DeviceFD fd) override; void OnClose(DeviceFD fd) override; @@ -138,17 +138,17 @@ private: static_assert(sizeof(IoctlGetVaRegions) == 16 + sizeof(VaRegion) * 2, "IoctlGetVaRegions is incorrect size"); - NvResult AllocAsEx(const std::vector& input, std::vector& output); - NvResult AllocateSpace(const std::vector& input, std::vector& output); - NvResult Remap(const std::vector& input, std::vector& output); - NvResult MapBufferEx(const std::vector& input, std::vector& output); - NvResult UnmapBuffer(const std::vector& input, std::vector& output); - NvResult FreeSpace(const std::vector& input, std::vector& output); - NvResult BindChannel(const std::vector& input, std::vector& output); + NvResult AllocAsEx(std::span input, std::vector& output); + NvResult AllocateSpace(std::span input, std::vector& output); + NvResult Remap(std::span input, std::vector& output); + NvResult MapBufferEx(std::span input, std::vector& output); + NvResult UnmapBuffer(std::span input, std::vector& output); + NvResult FreeSpace(std::span input, std::vector& output); + NvResult BindChannel(std::span input, std::vector& output); void GetVARegionsImpl(IoctlGetVaRegions& params); - NvResult GetVARegions(const std::vector& input, std::vector& output); - NvResult GetVARegions(const std::vector& input, std::vector& output, + NvResult GetVARegions(std::span input, std::vector& output); + NvResult GetVARegions(std::span input, std::vector& output, std::vector& inline_output); void FreeMappingLocked(u64 offset); diff --git a/src/core/hle/service/nvdrv/devices/nvhost_ctrl.cpp b/src/core/hle/service/nvdrv/devices/nvhost_ctrl.cpp index eee11fab8..0cdde82a7 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_ctrl.cpp +++ b/src/core/hle/service/nvdrv/devices/nvhost_ctrl.cpp @@ -34,7 +34,7 @@ nvhost_ctrl::~nvhost_ctrl() { } } -NvResult nvhost_ctrl::Ioctl1(DeviceFD fd, Ioctl command, const std::vector& input, +NvResult nvhost_ctrl::Ioctl1(DeviceFD fd, Ioctl command, std::span input, std::vector& output) { switch (command.group) { case 0x0: @@ -63,13 +63,13 @@ NvResult nvhost_ctrl::Ioctl1(DeviceFD fd, Ioctl command, const std::vector& return NvResult::NotImplemented; } -NvResult nvhost_ctrl::Ioctl2(DeviceFD fd, Ioctl command, const std::vector& input, - const std::vector& inline_input, std::vector& output) { +NvResult nvhost_ctrl::Ioctl2(DeviceFD fd, Ioctl command, std::span input, + std::span inline_input, std::vector& output) { UNIMPLEMENTED_MSG("Unimplemented ioctl={:08X}", command.raw); return NvResult::NotImplemented; } -NvResult nvhost_ctrl::Ioctl3(DeviceFD fd, Ioctl command, const std::vector& input, +NvResult nvhost_ctrl::Ioctl3(DeviceFD fd, Ioctl command, std::span input, std::vector& output, std::vector& inline_outpu) { UNIMPLEMENTED_MSG("Unimplemented ioctl={:08X}", command.raw); return NvResult::NotImplemented; @@ -79,7 +79,7 @@ void nvhost_ctrl::OnOpen(DeviceFD fd) {} void nvhost_ctrl::OnClose(DeviceFD fd) {} -NvResult nvhost_ctrl::NvOsGetConfigU32(const std::vector& input, std::vector& output) { +NvResult nvhost_ctrl::NvOsGetConfigU32(std::span input, std::vector& output) { IocGetConfigParams params{}; std::memcpy(¶ms, input.data(), sizeof(params)); LOG_TRACE(Service_NVDRV, "called, setting={}!{}", params.domain_str.data(), @@ -87,7 +87,7 @@ NvResult nvhost_ctrl::NvOsGetConfigU32(const std::vector& input, std::vector return NvResult::ConfigVarNotFound; // Returns error on production mode } -NvResult nvhost_ctrl::IocCtrlEventWait(const std::vector& input, std::vector& output, +NvResult nvhost_ctrl::IocCtrlEventWait(std::span input, std::vector& output, bool is_allocation) { IocCtrlEventWaitParams params{}; std::memcpy(¶ms, input.data(), sizeof(params)); @@ -231,7 +231,7 @@ NvResult nvhost_ctrl::FreeEvent(u32 slot) { return NvResult::Success; } -NvResult nvhost_ctrl::IocCtrlEventRegister(const std::vector& input, std::vector& output) { +NvResult nvhost_ctrl::IocCtrlEventRegister(std::span input, std::vector& output) { IocCtrlEventRegisterParams params{}; std::memcpy(¶ms, input.data(), sizeof(params)); const u32 event_id = params.user_event_id; @@ -252,8 +252,7 @@ NvResult nvhost_ctrl::IocCtrlEventRegister(const std::vector& input, std::ve return NvResult::Success; } -NvResult nvhost_ctrl::IocCtrlEventUnregister(const std::vector& input, - std::vector& output) { +NvResult nvhost_ctrl::IocCtrlEventUnregister(std::span input, std::vector& output) { IocCtrlEventUnregisterParams params{}; std::memcpy(¶ms, input.data(), sizeof(params)); const u32 event_id = params.user_event_id & 0x00FF; @@ -263,7 +262,7 @@ NvResult nvhost_ctrl::IocCtrlEventUnregister(const std::vector& input, return FreeEvent(event_id); } -NvResult nvhost_ctrl::IocCtrlEventUnregisterBatch(const std::vector& input, +NvResult nvhost_ctrl::IocCtrlEventUnregisterBatch(std::span input, std::vector& output) { IocCtrlEventUnregisterBatchParams params{}; std::memcpy(¶ms, input.data(), sizeof(params)); @@ -282,7 +281,7 @@ NvResult nvhost_ctrl::IocCtrlEventUnregisterBatch(const std::vector& input, return NvResult::Success; } -NvResult nvhost_ctrl::IocCtrlClearEventWait(const std::vector& input, std::vector& output) { +NvResult nvhost_ctrl::IocCtrlClearEventWait(std::span input, std::vector& output) { IocCtrlEventClearParams params{}; std::memcpy(¶ms, input.data(), sizeof(params)); diff --git a/src/core/hle/service/nvdrv/devices/nvhost_ctrl.h b/src/core/hle/service/nvdrv/devices/nvhost_ctrl.h index 0b56d7070..dd2e7888a 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_ctrl.h +++ b/src/core/hle/service/nvdrv/devices/nvhost_ctrl.h @@ -25,12 +25,12 @@ public: NvCore::Container& core); ~nvhost_ctrl() override; - NvResult Ioctl1(DeviceFD fd, Ioctl command, const std::vector& input, + NvResult Ioctl1(DeviceFD fd, Ioctl command, std::span input, std::vector& output) override; - NvResult Ioctl2(DeviceFD fd, Ioctl command, const std::vector& input, - const std::vector& inline_input, std::vector& output) override; - NvResult Ioctl3(DeviceFD fd, Ioctl command, const std::vector& input, - std::vector& output, std::vector& inline_output) override; + NvResult Ioctl2(DeviceFD fd, Ioctl command, std::span input, + std::span inline_input, std::vector& output) override; + NvResult Ioctl3(DeviceFD fd, Ioctl command, std::span input, std::vector& output, + std::vector& inline_output) override; void OnOpen(DeviceFD fd) override; void OnClose(DeviceFD fd) override; @@ -186,13 +186,13 @@ private: static_assert(sizeof(IocCtrlEventUnregisterBatchParams) == 8, "IocCtrlEventKill is incorrect size"); - NvResult NvOsGetConfigU32(const std::vector& input, std::vector& output); - NvResult IocCtrlEventWait(const std::vector& input, std::vector& output, + NvResult NvOsGetConfigU32(std::span input, std::vector& output); + NvResult IocCtrlEventWait(std::span input, std::vector& output, bool is_allocation); - NvResult IocCtrlEventRegister(const std::vector& input, std::vector& output); - NvResult IocCtrlEventUnregister(const std::vector& input, std::vector& output); - NvResult IocCtrlEventUnregisterBatch(const std::vector& input, std::vector& output); - NvResult IocCtrlClearEventWait(const std::vector& input, std::vector& output); + NvResult IocCtrlEventRegister(std::span input, std::vector& output); + NvResult IocCtrlEventUnregister(std::span input, std::vector& output); + NvResult IocCtrlEventUnregisterBatch(std::span input, std::vector& output); + NvResult IocCtrlClearEventWait(std::span input, std::vector& output); NvResult FreeEvent(u32 slot); diff --git a/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.cpp b/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.cpp index b97813fbc..be3c083db 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.cpp +++ b/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.cpp @@ -21,7 +21,7 @@ nvhost_ctrl_gpu::~nvhost_ctrl_gpu() { events_interface.FreeEvent(unknown_event); } -NvResult nvhost_ctrl_gpu::Ioctl1(DeviceFD fd, Ioctl command, const std::vector& input, +NvResult nvhost_ctrl_gpu::Ioctl1(DeviceFD fd, Ioctl command, std::span input, std::vector& output) { switch (command.group) { case 'G': @@ -53,13 +53,13 @@ NvResult nvhost_ctrl_gpu::Ioctl1(DeviceFD fd, Ioctl command, const std::vector& input, - const std::vector& inline_input, std::vector& output) { +NvResult nvhost_ctrl_gpu::Ioctl2(DeviceFD fd, Ioctl command, std::span input, + std::span inline_input, std::vector& output) { UNIMPLEMENTED_MSG("Unimplemented ioctl={:08X}", command.raw); return NvResult::NotImplemented; } -NvResult nvhost_ctrl_gpu::Ioctl3(DeviceFD fd, Ioctl command, const std::vector& input, +NvResult nvhost_ctrl_gpu::Ioctl3(DeviceFD fd, Ioctl command, std::span input, std::vector& output, std::vector& inline_output) { switch (command.group) { case 'G': @@ -82,8 +82,7 @@ NvResult nvhost_ctrl_gpu::Ioctl3(DeviceFD fd, Ioctl command, const std::vector& input, - std::vector& output) { +NvResult nvhost_ctrl_gpu::GetCharacteristics(std::span input, std::vector& output) { LOG_DEBUG(Service_NVDRV, "called"); IoctlCharacteristics params{}; std::memcpy(¶ms, input.data(), input.size()); @@ -128,7 +127,7 @@ NvResult nvhost_ctrl_gpu::GetCharacteristics(const std::vector& input, return NvResult::Success; } -NvResult nvhost_ctrl_gpu::GetCharacteristics(const std::vector& input, std::vector& output, +NvResult nvhost_ctrl_gpu::GetCharacteristics(std::span input, std::vector& output, std::vector& inline_output) { LOG_DEBUG(Service_NVDRV, "called"); IoctlCharacteristics params{}; @@ -176,7 +175,7 @@ NvResult nvhost_ctrl_gpu::GetCharacteristics(const std::vector& input, std:: return NvResult::Success; } -NvResult nvhost_ctrl_gpu::GetTPCMasks(const std::vector& input, std::vector& output) { +NvResult nvhost_ctrl_gpu::GetTPCMasks(std::span input, std::vector& output) { IoctlGpuGetTpcMasksArgs params{}; std::memcpy(¶ms, input.data(), input.size()); LOG_DEBUG(Service_NVDRV, "called, mask_buffer_size=0x{:X}", params.mask_buffer_size); @@ -187,7 +186,7 @@ NvResult nvhost_ctrl_gpu::GetTPCMasks(const std::vector& input, std::vector< return NvResult::Success; } -NvResult nvhost_ctrl_gpu::GetTPCMasks(const std::vector& input, std::vector& output, +NvResult nvhost_ctrl_gpu::GetTPCMasks(std::span input, std::vector& output, std::vector& inline_output) { IoctlGpuGetTpcMasksArgs params{}; std::memcpy(¶ms, input.data(), input.size()); @@ -200,7 +199,7 @@ NvResult nvhost_ctrl_gpu::GetTPCMasks(const std::vector& input, std::vector< return NvResult::Success; } -NvResult nvhost_ctrl_gpu::GetActiveSlotMask(const std::vector& input, std::vector& output) { +NvResult nvhost_ctrl_gpu::GetActiveSlotMask(std::span input, std::vector& output) { LOG_DEBUG(Service_NVDRV, "called"); IoctlActiveSlotMask params{}; @@ -213,7 +212,7 @@ NvResult nvhost_ctrl_gpu::GetActiveSlotMask(const std::vector& input, std::v return NvResult::Success; } -NvResult nvhost_ctrl_gpu::ZCullGetCtxSize(const std::vector& input, std::vector& output) { +NvResult nvhost_ctrl_gpu::ZCullGetCtxSize(std::span input, std::vector& output) { LOG_DEBUG(Service_NVDRV, "called"); IoctlZcullGetCtxSize params{}; @@ -225,7 +224,7 @@ NvResult nvhost_ctrl_gpu::ZCullGetCtxSize(const std::vector& input, std::vec return NvResult::Success; } -NvResult nvhost_ctrl_gpu::ZCullGetInfo(const std::vector& input, std::vector& output) { +NvResult nvhost_ctrl_gpu::ZCullGetInfo(std::span input, std::vector& output) { LOG_DEBUG(Service_NVDRV, "called"); IoctlNvgpuGpuZcullGetInfoArgs params{}; @@ -248,7 +247,7 @@ NvResult nvhost_ctrl_gpu::ZCullGetInfo(const std::vector& input, std::vector return NvResult::Success; } -NvResult nvhost_ctrl_gpu::ZBCSetTable(const std::vector& input, std::vector& output) { +NvResult nvhost_ctrl_gpu::ZBCSetTable(std::span input, std::vector& output) { LOG_WARNING(Service_NVDRV, "(STUBBED) called"); IoctlZbcSetTable params{}; @@ -264,7 +263,7 @@ NvResult nvhost_ctrl_gpu::ZBCSetTable(const std::vector& input, std::vector< return NvResult::Success; } -NvResult nvhost_ctrl_gpu::ZBCQueryTable(const std::vector& input, std::vector& output) { +NvResult nvhost_ctrl_gpu::ZBCQueryTable(std::span input, std::vector& output) { LOG_WARNING(Service_NVDRV, "(STUBBED) called"); IoctlZbcQueryTable params{}; @@ -274,7 +273,7 @@ NvResult nvhost_ctrl_gpu::ZBCQueryTable(const std::vector& input, std::vecto return NvResult::Success; } -NvResult nvhost_ctrl_gpu::FlushL2(const std::vector& input, std::vector& output) { +NvResult nvhost_ctrl_gpu::FlushL2(std::span input, std::vector& output) { LOG_WARNING(Service_NVDRV, "(STUBBED) called"); IoctlFlushL2 params{}; @@ -284,7 +283,7 @@ NvResult nvhost_ctrl_gpu::FlushL2(const std::vector& input, std::vector& return NvResult::Success; } -NvResult nvhost_ctrl_gpu::GetGpuTime(const std::vector& input, std::vector& output) { +NvResult nvhost_ctrl_gpu::GetGpuTime(std::span input, std::vector& output) { LOG_DEBUG(Service_NVDRV, "called"); IoctlGetGpuTime params{}; diff --git a/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.h b/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.h index 1e8f254e2..b9333d9d3 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.h +++ b/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.h @@ -21,12 +21,12 @@ public: explicit nvhost_ctrl_gpu(Core::System& system_, EventInterface& events_interface_); ~nvhost_ctrl_gpu() override; - NvResult Ioctl1(DeviceFD fd, Ioctl command, const std::vector& input, + NvResult Ioctl1(DeviceFD fd, Ioctl command, std::span input, std::vector& output) override; - NvResult Ioctl2(DeviceFD fd, Ioctl command, const std::vector& input, - const std::vector& inline_input, std::vector& output) override; - NvResult Ioctl3(DeviceFD fd, Ioctl command, const std::vector& input, - std::vector& output, std::vector& inline_output) override; + NvResult Ioctl2(DeviceFD fd, Ioctl command, std::span input, + std::span inline_input, std::vector& output) override; + NvResult Ioctl3(DeviceFD fd, Ioctl command, std::span input, std::vector& output, + std::vector& inline_output) override; void OnOpen(DeviceFD fd) override; void OnClose(DeviceFD fd) override; @@ -151,21 +151,21 @@ private: }; static_assert(sizeof(IoctlGetGpuTime) == 0x10, "IoctlGetGpuTime is incorrect size"); - NvResult GetCharacteristics(const std::vector& input, std::vector& output); - NvResult GetCharacteristics(const std::vector& input, std::vector& output, + NvResult GetCharacteristics(std::span input, std::vector& output); + NvResult GetCharacteristics(std::span input, std::vector& output, std::vector& inline_output); - NvResult GetTPCMasks(const std::vector& input, std::vector& output); - NvResult GetTPCMasks(const std::vector& input, std::vector& output, + NvResult GetTPCMasks(std::span input, std::vector& output); + NvResult GetTPCMasks(std::span input, std::vector& output, std::vector& inline_output); - NvResult GetActiveSlotMask(const std::vector& input, std::vector& output); - NvResult ZCullGetCtxSize(const std::vector& input, std::vector& output); - NvResult ZCullGetInfo(const std::vector& input, std::vector& output); - NvResult ZBCSetTable(const std::vector& input, std::vector& output); - NvResult ZBCQueryTable(const std::vector& input, std::vector& output); - NvResult FlushL2(const std::vector& input, std::vector& output); - NvResult GetGpuTime(const std::vector& input, std::vector& output); + NvResult GetActiveSlotMask(std::span input, std::vector& output); + NvResult ZCullGetCtxSize(std::span input, std::vector& output); + NvResult ZCullGetInfo(std::span input, std::vector& output); + NvResult ZBCSetTable(std::span input, std::vector& output); + NvResult ZBCQueryTable(std::span input, std::vector& output); + NvResult FlushL2(std::span input, std::vector& output); + NvResult GetGpuTime(std::span input, std::vector& output); EventInterface& events_interface; diff --git a/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp b/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp index e123564c6..d2308fffc 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp +++ b/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp @@ -46,7 +46,7 @@ nvhost_gpu::~nvhost_gpu() { syncpoint_manager.FreeSyncpoint(channel_syncpoint); } -NvResult nvhost_gpu::Ioctl1(DeviceFD fd, Ioctl command, const std::vector& input, +NvResult nvhost_gpu::Ioctl1(DeviceFD fd, Ioctl command, std::span input, std::vector& output) { switch (command.group) { case 0x0: @@ -98,8 +98,8 @@ NvResult nvhost_gpu::Ioctl1(DeviceFD fd, Ioctl command, const std::vector& i return NvResult::NotImplemented; }; -NvResult nvhost_gpu::Ioctl2(DeviceFD fd, Ioctl command, const std::vector& input, - const std::vector& inline_input, std::vector& output) { +NvResult nvhost_gpu::Ioctl2(DeviceFD fd, Ioctl command, std::span input, + std::span inline_input, std::vector& output) { switch (command.group) { case 'H': switch (command.cmd) { @@ -112,7 +112,7 @@ NvResult nvhost_gpu::Ioctl2(DeviceFD fd, Ioctl command, const std::vector& i return NvResult::NotImplemented; } -NvResult nvhost_gpu::Ioctl3(DeviceFD fd, Ioctl command, const std::vector& input, +NvResult nvhost_gpu::Ioctl3(DeviceFD fd, Ioctl command, std::span input, std::vector& output, std::vector& inline_output) { UNIMPLEMENTED_MSG("Unimplemented ioctl={:08X}", command.raw); return NvResult::NotImplemented; @@ -121,7 +121,7 @@ NvResult nvhost_gpu::Ioctl3(DeviceFD fd, Ioctl command, const std::vector& i void nvhost_gpu::OnOpen(DeviceFD fd) {} void nvhost_gpu::OnClose(DeviceFD fd) {} -NvResult nvhost_gpu::SetNVMAPfd(const std::vector& input, std::vector& output) { +NvResult nvhost_gpu::SetNVMAPfd(std::span input, std::vector& output) { IoctlSetNvmapFD params{}; std::memcpy(¶ms, input.data(), input.size()); LOG_DEBUG(Service_NVDRV, "called, fd={}", params.nvmap_fd); @@ -130,7 +130,7 @@ NvResult nvhost_gpu::SetNVMAPfd(const std::vector& input, std::vector& o return NvResult::Success; } -NvResult nvhost_gpu::SetClientData(const std::vector& input, std::vector& output) { +NvResult nvhost_gpu::SetClientData(std::span input, std::vector& output) { LOG_DEBUG(Service_NVDRV, "called"); IoctlClientData params{}; @@ -139,7 +139,7 @@ NvResult nvhost_gpu::SetClientData(const std::vector& input, std::vector return NvResult::Success; } -NvResult nvhost_gpu::GetClientData(const std::vector& input, std::vector& output) { +NvResult nvhost_gpu::GetClientData(std::span input, std::vector& output) { LOG_DEBUG(Service_NVDRV, "called"); IoctlClientData params{}; @@ -149,7 +149,7 @@ NvResult nvhost_gpu::GetClientData(const std::vector& input, std::vector return NvResult::Success; } -NvResult nvhost_gpu::ZCullBind(const std::vector& input, std::vector& output) { +NvResult nvhost_gpu::ZCullBind(std::span input, std::vector& output) { std::memcpy(&zcull_params, input.data(), input.size()); LOG_DEBUG(Service_NVDRV, "called, gpu_va={:X}, mode={:X}", zcull_params.gpu_va, zcull_params.mode); @@ -158,7 +158,7 @@ NvResult nvhost_gpu::ZCullBind(const std::vector& input, std::vector& ou return NvResult::Success; } -NvResult nvhost_gpu::SetErrorNotifier(const std::vector& input, std::vector& output) { +NvResult nvhost_gpu::SetErrorNotifier(std::span input, std::vector& output) { IoctlSetErrorNotifier params{}; std::memcpy(¶ms, input.data(), input.size()); LOG_WARNING(Service_NVDRV, "(STUBBED) called, offset={:X}, size={:X}, mem={:X}", params.offset, @@ -168,14 +168,14 @@ NvResult nvhost_gpu::SetErrorNotifier(const std::vector& input, std::vector< return NvResult::Success; } -NvResult nvhost_gpu::SetChannelPriority(const std::vector& input, std::vector& output) { +NvResult nvhost_gpu::SetChannelPriority(std::span input, std::vector& output) { std::memcpy(&channel_priority, input.data(), input.size()); LOG_DEBUG(Service_NVDRV, "(STUBBED) called, priority={:X}", channel_priority); return NvResult::Success; } -NvResult nvhost_gpu::AllocGPFIFOEx2(const std::vector& input, std::vector& output) { +NvResult nvhost_gpu::AllocGPFIFOEx2(std::span input, std::vector& output) { IoctlAllocGpfifoEx2 params{}; std::memcpy(¶ms, input.data(), input.size()); LOG_WARNING(Service_NVDRV, @@ -197,7 +197,7 @@ NvResult nvhost_gpu::AllocGPFIFOEx2(const std::vector& input, std::vector& input, std::vector& output) { +NvResult nvhost_gpu::AllocateObjectContext(std::span input, std::vector& output) { IoctlAllocObjCtx params{}; std::memcpy(¶ms, input.data(), input.size()); LOG_WARNING(Service_NVDRV, "(STUBBED) called, class_num={:X}, flags={:X}", params.class_num, @@ -293,7 +293,7 @@ NvResult nvhost_gpu::SubmitGPFIFOImpl(IoctlSubmitGpfifo& params, std::vector return NvResult::Success; } -NvResult nvhost_gpu::SubmitGPFIFOBase(const std::vector& input, std::vector& output, +NvResult nvhost_gpu::SubmitGPFIFOBase(std::span input, std::vector& output, bool kickoff) { if (input.size() < sizeof(IoctlSubmitGpfifo)) { UNIMPLEMENTED(); @@ -314,8 +314,7 @@ NvResult nvhost_gpu::SubmitGPFIFOBase(const std::vector& input, std::vector< return SubmitGPFIFOImpl(params, output, std::move(entries)); } -NvResult nvhost_gpu::SubmitGPFIFOBase(const std::vector& input, - const std::vector& input_inline, +NvResult nvhost_gpu::SubmitGPFIFOBase(std::span input, std::span input_inline, std::vector& output) { if (input.size() < sizeof(IoctlSubmitGpfifo)) { UNIMPLEMENTED(); @@ -328,7 +327,7 @@ NvResult nvhost_gpu::SubmitGPFIFOBase(const std::vector& input, return SubmitGPFIFOImpl(params, output, std::move(entries)); } -NvResult nvhost_gpu::GetWaitbase(const std::vector& input, std::vector& output) { +NvResult nvhost_gpu::GetWaitbase(std::span input, std::vector& output) { IoctlGetWaitbase params{}; std::memcpy(¶ms, input.data(), sizeof(IoctlGetWaitbase)); LOG_INFO(Service_NVDRV, "called, unknown=0x{:X}", params.unknown); @@ -338,7 +337,7 @@ NvResult nvhost_gpu::GetWaitbase(const std::vector& input, std::vector& return NvResult::Success; } -NvResult nvhost_gpu::ChannelSetTimeout(const std::vector& input, std::vector& output) { +NvResult nvhost_gpu::ChannelSetTimeout(std::span input, std::vector& output) { IoctlChannelSetTimeout params{}; std::memcpy(¶ms, input.data(), sizeof(IoctlChannelSetTimeout)); LOG_INFO(Service_NVDRV, "called, timeout=0x{:X}", params.timeout); @@ -346,7 +345,7 @@ NvResult nvhost_gpu::ChannelSetTimeout(const std::vector& input, std::vector return NvResult::Success; } -NvResult nvhost_gpu::ChannelSetTimeslice(const std::vector& input, std::vector& output) { +NvResult nvhost_gpu::ChannelSetTimeslice(std::span input, std::vector& output) { IoctlSetTimeslice params{}; std::memcpy(¶ms, input.data(), sizeof(IoctlSetTimeslice)); LOG_INFO(Service_NVDRV, "called, timeslice=0x{:X}", params.timeslice); diff --git a/src/core/hle/service/nvdrv/devices/nvhost_gpu.h b/src/core/hle/service/nvdrv/devices/nvhost_gpu.h index 1e4ecd55b..3ca58202d 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_gpu.h +++ b/src/core/hle/service/nvdrv/devices/nvhost_gpu.h @@ -40,12 +40,12 @@ public: NvCore::Container& core); ~nvhost_gpu() override; - NvResult Ioctl1(DeviceFD fd, Ioctl command, const std::vector& input, + NvResult Ioctl1(DeviceFD fd, Ioctl command, std::span input, std::vector& output) override; - NvResult Ioctl2(DeviceFD fd, Ioctl command, const std::vector& input, - const std::vector& inline_input, std::vector& output) override; - NvResult Ioctl3(DeviceFD fd, Ioctl command, const std::vector& input, - std::vector& output, std::vector& inline_output) override; + NvResult Ioctl2(DeviceFD fd, Ioctl command, std::span input, + std::span inline_input, std::vector& output) override; + NvResult Ioctl3(DeviceFD fd, Ioctl command, std::span input, std::vector& output, + std::vector& inline_output) override; void OnOpen(DeviceFD fd) override; void OnClose(DeviceFD fd) override; @@ -186,23 +186,23 @@ private: u32_le channel_priority{}; u32_le channel_timeslice{}; - NvResult SetNVMAPfd(const std::vector& input, std::vector& output); - NvResult SetClientData(const std::vector& input, std::vector& output); - NvResult GetClientData(const std::vector& input, std::vector& output); - NvResult ZCullBind(const std::vector& input, std::vector& output); - NvResult SetErrorNotifier(const std::vector& input, std::vector& output); - NvResult SetChannelPriority(const std::vector& input, std::vector& output); - NvResult AllocGPFIFOEx2(const std::vector& input, std::vector& output); - NvResult AllocateObjectContext(const std::vector& input, std::vector& output); + NvResult SetNVMAPfd(std::span input, std::vector& output); + NvResult SetClientData(std::span input, std::vector& output); + NvResult GetClientData(std::span input, std::vector& output); + NvResult ZCullBind(std::span input, std::vector& output); + NvResult SetErrorNotifier(std::span input, std::vector& output); + NvResult SetChannelPriority(std::span input, std::vector& output); + NvResult AllocGPFIFOEx2(std::span input, std::vector& output); + NvResult AllocateObjectContext(std::span input, std::vector& output); NvResult SubmitGPFIFOImpl(IoctlSubmitGpfifo& params, std::vector& output, Tegra::CommandList&& entries); - NvResult SubmitGPFIFOBase(const std::vector& input, std::vector& output, + NvResult SubmitGPFIFOBase(std::span input, std::vector& output, bool kickoff = false); - NvResult SubmitGPFIFOBase(const std::vector& input, const std::vector& input_inline, + NvResult SubmitGPFIFOBase(std::span input, std::span input_inline, std::vector& output); - NvResult GetWaitbase(const std::vector& input, std::vector& output); - NvResult ChannelSetTimeout(const std::vector& input, std::vector& output); - NvResult ChannelSetTimeslice(const std::vector& input, std::vector& output); + NvResult GetWaitbase(std::span input, std::vector& output); + NvResult ChannelSetTimeout(std::span input, std::vector& output); + NvResult ChannelSetTimeslice(std::span input, std::vector& output); EventInterface& events_interface; NvCore::Container& core; diff --git a/src/core/hle/service/nvdrv/devices/nvhost_nvdec.cpp b/src/core/hle/service/nvdrv/devices/nvhost_nvdec.cpp index 1703f9cc3..0c7aee1b8 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_nvdec.cpp +++ b/src/core/hle/service/nvdrv/devices/nvhost_nvdec.cpp @@ -15,7 +15,7 @@ nvhost_nvdec::nvhost_nvdec(Core::System& system_, NvCore::Container& core_) : nvhost_nvdec_common{system_, core_, NvCore::ChannelType::NvDec} {} nvhost_nvdec::~nvhost_nvdec() = default; -NvResult nvhost_nvdec::Ioctl1(DeviceFD fd, Ioctl command, const std::vector& input, +NvResult nvhost_nvdec::Ioctl1(DeviceFD fd, Ioctl command, std::span input, std::vector& output) { switch (command.group) { case 0x0: @@ -55,13 +55,13 @@ NvResult nvhost_nvdec::Ioctl1(DeviceFD fd, Ioctl command, const std::vector& return NvResult::NotImplemented; } -NvResult nvhost_nvdec::Ioctl2(DeviceFD fd, Ioctl command, const std::vector& input, - const std::vector& inline_input, std::vector& output) { +NvResult nvhost_nvdec::Ioctl2(DeviceFD fd, Ioctl command, std::span input, + std::span inline_input, std::vector& output) { UNIMPLEMENTED_MSG("Unimplemented ioctl={:08X}", command.raw); return NvResult::NotImplemented; } -NvResult nvhost_nvdec::Ioctl3(DeviceFD fd, Ioctl command, const std::vector& input, +NvResult nvhost_nvdec::Ioctl3(DeviceFD fd, Ioctl command, std::span input, std::vector& output, std::vector& inline_output) { UNIMPLEMENTED_MSG("Unimplemented ioctl={:08X}", command.raw); return NvResult::NotImplemented; diff --git a/src/core/hle/service/nvdrv/devices/nvhost_nvdec.h b/src/core/hle/service/nvdrv/devices/nvhost_nvdec.h index c1b4e53e8..0d615bbcb 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_nvdec.h +++ b/src/core/hle/service/nvdrv/devices/nvhost_nvdec.h @@ -13,12 +13,12 @@ public: explicit nvhost_nvdec(Core::System& system_, NvCore::Container& core); ~nvhost_nvdec() override; - NvResult Ioctl1(DeviceFD fd, Ioctl command, const std::vector& input, + NvResult Ioctl1(DeviceFD fd, Ioctl command, std::span input, std::vector& output) override; - NvResult Ioctl2(DeviceFD fd, Ioctl command, const std::vector& input, - const std::vector& inline_input, std::vector& output) override; - NvResult Ioctl3(DeviceFD fd, Ioctl command, const std::vector& input, - std::vector& output, std::vector& inline_output) override; + NvResult Ioctl2(DeviceFD fd, Ioctl command, std::span input, + std::span inline_input, std::vector& output) override; + NvResult Ioctl3(DeviceFD fd, Ioctl command, std::span input, std::vector& output, + std::vector& inline_output) override; void OnOpen(DeviceFD fd) override; void OnClose(DeviceFD fd) override; diff --git a/src/core/hle/service/nvdrv/devices/nvhost_nvdec_common.cpp b/src/core/hle/service/nvdrv/devices/nvhost_nvdec_common.cpp index 99eede702..7bcef105b 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_nvdec_common.cpp +++ b/src/core/hle/service/nvdrv/devices/nvhost_nvdec_common.cpp @@ -23,7 +23,7 @@ namespace { // Copies count amount of type T from the input vector into the dst vector. // Returns the number of bytes written into dst. template -std::size_t SliceVectors(const std::vector& input, std::vector& dst, std::size_t count, +std::size_t SliceVectors(std::span input, std::vector& dst, std::size_t count, std::size_t offset) { if (dst.empty()) { return 0; @@ -63,7 +63,7 @@ nvhost_nvdec_common::~nvhost_nvdec_common() { core.Host1xDeviceFile().syncpts_accumulated.push_back(channel_syncpoint); } -NvResult nvhost_nvdec_common::SetNVMAPfd(const std::vector& input) { +NvResult nvhost_nvdec_common::SetNVMAPfd(std::span input) { IoctlSetNvmapFD params{}; std::memcpy(¶ms, input.data(), sizeof(IoctlSetNvmapFD)); LOG_DEBUG(Service_NVDRV, "called, fd={}", params.nvmap_fd); @@ -72,7 +72,7 @@ NvResult nvhost_nvdec_common::SetNVMAPfd(const std::vector& input) { return NvResult::Success; } -NvResult nvhost_nvdec_common::Submit(DeviceFD fd, const std::vector& input, +NvResult nvhost_nvdec_common::Submit(DeviceFD fd, std::span input, std::vector& output) { IoctlSubmit params{}; std::memcpy(¶ms, input.data(), sizeof(IoctlSubmit)); @@ -121,7 +121,7 @@ NvResult nvhost_nvdec_common::Submit(DeviceFD fd, const std::vector& input, return NvResult::Success; } -NvResult nvhost_nvdec_common::GetSyncpoint(const std::vector& input, std::vector& output) { +NvResult nvhost_nvdec_common::GetSyncpoint(std::span input, std::vector& output) { IoctlGetSyncpoint params{}; std::memcpy(¶ms, input.data(), sizeof(IoctlGetSyncpoint)); LOG_DEBUG(Service_NVDRV, "called GetSyncpoint, id={}", params.param); @@ -133,7 +133,7 @@ NvResult nvhost_nvdec_common::GetSyncpoint(const std::vector& input, std::ve return NvResult::Success; } -NvResult nvhost_nvdec_common::GetWaitbase(const std::vector& input, std::vector& output) { +NvResult nvhost_nvdec_common::GetWaitbase(std::span input, std::vector& output) { IoctlGetWaitbase params{}; LOG_CRITICAL(Service_NVDRV, "called WAITBASE"); std::memcpy(¶ms, input.data(), sizeof(IoctlGetWaitbase)); @@ -142,7 +142,7 @@ NvResult nvhost_nvdec_common::GetWaitbase(const std::vector& input, std::vec return NvResult::Success; } -NvResult nvhost_nvdec_common::MapBuffer(const std::vector& input, std::vector& output) { +NvResult nvhost_nvdec_common::MapBuffer(std::span input, std::vector& output) { IoctlMapBuffer params{}; std::memcpy(¶ms, input.data(), sizeof(IoctlMapBuffer)); std::vector cmd_buffer_handles(params.num_entries); @@ -159,7 +159,7 @@ NvResult nvhost_nvdec_common::MapBuffer(const std::vector& input, std::vecto return NvResult::Success; } -NvResult nvhost_nvdec_common::UnmapBuffer(const std::vector& input, std::vector& output) { +NvResult nvhost_nvdec_common::UnmapBuffer(std::span input, std::vector& output) { IoctlMapBuffer params{}; std::memcpy(¶ms, input.data(), sizeof(IoctlMapBuffer)); std::vector cmd_buffer_handles(params.num_entries); @@ -173,8 +173,7 @@ NvResult nvhost_nvdec_common::UnmapBuffer(const std::vector& input, std::vec return NvResult::Success; } -NvResult nvhost_nvdec_common::SetSubmitTimeout(const std::vector& input, - std::vector& output) { +NvResult nvhost_nvdec_common::SetSubmitTimeout(std::span input, std::vector& output) { std::memcpy(&submit_timeout, input.data(), input.size()); LOG_WARNING(Service_NVDRV, "(STUBBED) called"); return NvResult::Success; diff --git a/src/core/hle/service/nvdrv/devices/nvhost_nvdec_common.h b/src/core/hle/service/nvdrv/devices/nvhost_nvdec_common.h index fe76100c8..5af26a26f 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_nvdec_common.h +++ b/src/core/hle/service/nvdrv/devices/nvhost_nvdec_common.h @@ -107,13 +107,13 @@ protected: static_assert(sizeof(IoctlMapBuffer) == 0x0C, "IoctlMapBuffer is incorrect size"); /// Ioctl command implementations - NvResult SetNVMAPfd(const std::vector& input); - NvResult Submit(DeviceFD fd, const std::vector& input, std::vector& output); - NvResult GetSyncpoint(const std::vector& input, std::vector& output); - NvResult GetWaitbase(const std::vector& input, std::vector& output); - NvResult MapBuffer(const std::vector& input, std::vector& output); - NvResult UnmapBuffer(const std::vector& input, std::vector& output); - NvResult SetSubmitTimeout(const std::vector& input, std::vector& output); + NvResult SetNVMAPfd(std::span input); + NvResult Submit(DeviceFD fd, std::span input, std::vector& output); + NvResult GetSyncpoint(std::span input, std::vector& output); + NvResult GetWaitbase(std::span input, std::vector& output); + NvResult MapBuffer(std::span input, std::vector& output); + NvResult UnmapBuffer(std::span input, std::vector& output); + NvResult SetSubmitTimeout(std::span input, std::vector& output); Kernel::KEvent* QueryEvent(u32 event_id) override; diff --git a/src/core/hle/service/nvdrv/devices/nvhost_nvjpg.cpp b/src/core/hle/service/nvdrv/devices/nvhost_nvjpg.cpp index bdbc2f9e1..39f30e7c8 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_nvjpg.cpp +++ b/src/core/hle/service/nvdrv/devices/nvhost_nvjpg.cpp @@ -12,7 +12,7 @@ namespace Service::Nvidia::Devices { nvhost_nvjpg::nvhost_nvjpg(Core::System& system_) : nvdevice{system_} {} nvhost_nvjpg::~nvhost_nvjpg() = default; -NvResult nvhost_nvjpg::Ioctl1(DeviceFD fd, Ioctl command, const std::vector& input, +NvResult nvhost_nvjpg::Ioctl1(DeviceFD fd, Ioctl command, std::span input, std::vector& output) { switch (command.group) { case 'H': @@ -31,13 +31,13 @@ NvResult nvhost_nvjpg::Ioctl1(DeviceFD fd, Ioctl command, const std::vector& return NvResult::NotImplemented; } -NvResult nvhost_nvjpg::Ioctl2(DeviceFD fd, Ioctl command, const std::vector& input, - const std::vector& inline_input, std::vector& output) { +NvResult nvhost_nvjpg::Ioctl2(DeviceFD fd, Ioctl command, std::span input, + std::span inline_input, std::vector& output) { UNIMPLEMENTED_MSG("Unimplemented ioctl={:08X}", command.raw); return NvResult::NotImplemented; } -NvResult nvhost_nvjpg::Ioctl3(DeviceFD fd, Ioctl command, const std::vector& input, +NvResult nvhost_nvjpg::Ioctl3(DeviceFD fd, Ioctl command, std::span input, std::vector& output, std::vector& inline_output) { UNIMPLEMENTED_MSG("Unimplemented ioctl={:08X}", command.raw); return NvResult::NotImplemented; @@ -46,7 +46,7 @@ NvResult nvhost_nvjpg::Ioctl3(DeviceFD fd, Ioctl command, const std::vector& void nvhost_nvjpg::OnOpen(DeviceFD fd) {} void nvhost_nvjpg::OnClose(DeviceFD fd) {} -NvResult nvhost_nvjpg::SetNVMAPfd(const std::vector& input, std::vector& output) { +NvResult nvhost_nvjpg::SetNVMAPfd(std::span input, std::vector& output) { IoctlSetNvmapFD params{}; std::memcpy(¶ms, input.data(), input.size()); LOG_DEBUG(Service_NVDRV, "called, fd={}", params.nvmap_fd); diff --git a/src/core/hle/service/nvdrv/devices/nvhost_nvjpg.h b/src/core/hle/service/nvdrv/devices/nvhost_nvjpg.h index 440e7d371..41b57e872 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_nvjpg.h +++ b/src/core/hle/service/nvdrv/devices/nvhost_nvjpg.h @@ -15,12 +15,12 @@ public: explicit nvhost_nvjpg(Core::System& system_); ~nvhost_nvjpg() override; - NvResult Ioctl1(DeviceFD fd, Ioctl command, const std::vector& input, + NvResult Ioctl1(DeviceFD fd, Ioctl command, std::span input, std::vector& output) override; - NvResult Ioctl2(DeviceFD fd, Ioctl command, const std::vector& input, - const std::vector& inline_input, std::vector& output) override; - NvResult Ioctl3(DeviceFD fd, Ioctl command, const std::vector& input, - std::vector& output, std::vector& inline_output) override; + NvResult Ioctl2(DeviceFD fd, Ioctl command, std::span input, + std::span inline_input, std::vector& output) override; + NvResult Ioctl3(DeviceFD fd, Ioctl command, std::span input, std::vector& output, + std::vector& inline_output) override; void OnOpen(DeviceFD fd) override; void OnClose(DeviceFD fd) override; @@ -33,7 +33,7 @@ private: s32_le nvmap_fd{}; - NvResult SetNVMAPfd(const std::vector& input, std::vector& output); + NvResult SetNVMAPfd(std::span input, std::vector& output); }; } // namespace Service::Nvidia::Devices diff --git a/src/core/hle/service/nvdrv/devices/nvhost_vic.cpp b/src/core/hle/service/nvdrv/devices/nvhost_vic.cpp index 73f97136e..b0ea402a7 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_vic.cpp +++ b/src/core/hle/service/nvdrv/devices/nvhost_vic.cpp @@ -15,7 +15,7 @@ nvhost_vic::nvhost_vic(Core::System& system_, NvCore::Container& core_) nvhost_vic::~nvhost_vic() = default; -NvResult nvhost_vic::Ioctl1(DeviceFD fd, Ioctl command, const std::vector& input, +NvResult nvhost_vic::Ioctl1(DeviceFD fd, Ioctl command, std::span input, std::vector& output) { switch (command.group) { case 0x0: @@ -55,13 +55,13 @@ NvResult nvhost_vic::Ioctl1(DeviceFD fd, Ioctl command, const std::vector& i return NvResult::NotImplemented; } -NvResult nvhost_vic::Ioctl2(DeviceFD fd, Ioctl command, const std::vector& input, - const std::vector& inline_input, std::vector& output) { +NvResult nvhost_vic::Ioctl2(DeviceFD fd, Ioctl command, std::span input, + std::span inline_input, std::vector& output) { UNIMPLEMENTED_MSG("Unimplemented ioctl={:08X}", command.raw); return NvResult::NotImplemented; } -NvResult nvhost_vic::Ioctl3(DeviceFD fd, Ioctl command, const std::vector& input, +NvResult nvhost_vic::Ioctl3(DeviceFD fd, Ioctl command, std::span input, std::vector& output, std::vector& inline_output) { UNIMPLEMENTED_MSG("Unimplemented ioctl={:08X}", command.raw); return NvResult::NotImplemented; diff --git a/src/core/hle/service/nvdrv/devices/nvhost_vic.h b/src/core/hle/service/nvdrv/devices/nvhost_vic.h index f164caafb..b5e350a83 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_vic.h +++ b/src/core/hle/service/nvdrv/devices/nvhost_vic.h @@ -12,12 +12,12 @@ public: explicit nvhost_vic(Core::System& system_, NvCore::Container& core); ~nvhost_vic(); - NvResult Ioctl1(DeviceFD fd, Ioctl command, const std::vector& input, + NvResult Ioctl1(DeviceFD fd, Ioctl command, std::span input, std::vector& output) override; - NvResult Ioctl2(DeviceFD fd, Ioctl command, const std::vector& input, - const std::vector& inline_input, std::vector& output) override; - NvResult Ioctl3(DeviceFD fd, Ioctl command, const std::vector& input, - std::vector& output, std::vector& inline_output) override; + NvResult Ioctl2(DeviceFD fd, Ioctl command, std::span input, + std::span inline_input, std::vector& output) override; + NvResult Ioctl3(DeviceFD fd, Ioctl command, std::span input, std::vector& output, + std::vector& inline_output) override; void OnOpen(DeviceFD fd) override; void OnClose(DeviceFD fd) override; diff --git a/src/core/hle/service/nvdrv/devices/nvmap.cpp b/src/core/hle/service/nvdrv/devices/nvmap.cpp index fa29db758..29c1e0f01 100644 --- a/src/core/hle/service/nvdrv/devices/nvmap.cpp +++ b/src/core/hle/service/nvdrv/devices/nvmap.cpp @@ -25,7 +25,7 @@ nvmap::nvmap(Core::System& system_, NvCore::Container& container_) nvmap::~nvmap() = default; -NvResult nvmap::Ioctl1(DeviceFD fd, Ioctl command, const std::vector& input, +NvResult nvmap::Ioctl1(DeviceFD fd, Ioctl command, std::span input, std::vector& output) { switch (command.group) { case 0x1: @@ -54,13 +54,13 @@ NvResult nvmap::Ioctl1(DeviceFD fd, Ioctl command, const std::vector& input, return NvResult::NotImplemented; } -NvResult nvmap::Ioctl2(DeviceFD fd, Ioctl command, const std::vector& input, - const std::vector& inline_input, std::vector& output) { +NvResult nvmap::Ioctl2(DeviceFD fd, Ioctl command, std::span input, + std::span inline_input, std::vector& output) { UNIMPLEMENTED_MSG("Unimplemented ioctl={:08X}", command.raw); return NvResult::NotImplemented; } -NvResult nvmap::Ioctl3(DeviceFD fd, Ioctl command, const std::vector& input, +NvResult nvmap::Ioctl3(DeviceFD fd, Ioctl command, std::span input, std::vector& output, std::vector& inline_output) { UNIMPLEMENTED_MSG("Unimplemented ioctl={:08X}", command.raw); return NvResult::NotImplemented; @@ -69,7 +69,7 @@ NvResult nvmap::Ioctl3(DeviceFD fd, Ioctl command, const std::vector& input, void nvmap::OnOpen(DeviceFD fd) {} void nvmap::OnClose(DeviceFD fd) {} -NvResult nvmap::IocCreate(const std::vector& input, std::vector& output) { +NvResult nvmap::IocCreate(std::span input, std::vector& output) { IocCreateParams params; std::memcpy(¶ms, input.data(), sizeof(params)); LOG_DEBUG(Service_NVDRV, "called, size=0x{:08X}", params.size); @@ -89,7 +89,7 @@ NvResult nvmap::IocCreate(const std::vector& input, std::vector& output) return NvResult::Success; } -NvResult nvmap::IocAlloc(const std::vector& input, std::vector& output) { +NvResult nvmap::IocAlloc(std::span input, std::vector& output) { IocAllocParams params; std::memcpy(¶ms, input.data(), sizeof(params)); LOG_DEBUG(Service_NVDRV, "called, addr={:X}", params.address); @@ -137,7 +137,7 @@ NvResult nvmap::IocAlloc(const std::vector& input, std::vector& output) return result; } -NvResult nvmap::IocGetId(const std::vector& input, std::vector& output) { +NvResult nvmap::IocGetId(std::span input, std::vector& output) { IocGetIdParams params; std::memcpy(¶ms, input.data(), sizeof(params)); @@ -161,7 +161,7 @@ NvResult nvmap::IocGetId(const std::vector& input, std::vector& output) return NvResult::Success; } -NvResult nvmap::IocFromId(const std::vector& input, std::vector& output) { +NvResult nvmap::IocFromId(std::span input, std::vector& output) { IocFromIdParams params; std::memcpy(¶ms, input.data(), sizeof(params)); @@ -192,7 +192,7 @@ NvResult nvmap::IocFromId(const std::vector& input, std::vector& output) return NvResult::Success; } -NvResult nvmap::IocParam(const std::vector& input, std::vector& output) { +NvResult nvmap::IocParam(std::span input, std::vector& output) { enum class ParamTypes { Size = 1, Alignment = 2, Base = 3, Heap = 4, Kind = 5, Compr = 6 }; IocParamParams params; @@ -241,7 +241,7 @@ NvResult nvmap::IocParam(const std::vector& input, std::vector& output) return NvResult::Success; } -NvResult nvmap::IocFree(const std::vector& input, std::vector& output) { +NvResult nvmap::IocFree(std::span input, std::vector& output) { IocFreeParams params; std::memcpy(¶ms, input.data(), sizeof(params)); diff --git a/src/core/hle/service/nvdrv/devices/nvmap.h b/src/core/hle/service/nvdrv/devices/nvmap.h index e9bfd0358..82bd3b118 100644 --- a/src/core/hle/service/nvdrv/devices/nvmap.h +++ b/src/core/hle/service/nvdrv/devices/nvmap.h @@ -26,12 +26,12 @@ public: nvmap(const nvmap&) = delete; nvmap& operator=(const nvmap&) = delete; - NvResult Ioctl1(DeviceFD fd, Ioctl command, const std::vector& input, + NvResult Ioctl1(DeviceFD fd, Ioctl command, std::span input, std::vector& output) override; - NvResult Ioctl2(DeviceFD fd, Ioctl command, const std::vector& input, - const std::vector& inline_input, std::vector& output) override; - NvResult Ioctl3(DeviceFD fd, Ioctl command, const std::vector& input, - std::vector& output, std::vector& inline_output) override; + NvResult Ioctl2(DeviceFD fd, Ioctl command, std::span input, + std::span inline_input, std::vector& output) override; + NvResult Ioctl3(DeviceFD fd, Ioctl command, std::span input, std::vector& output, + std::vector& inline_output) override; void OnOpen(DeviceFD fd) override; void OnClose(DeviceFD fd) override; @@ -106,12 +106,12 @@ private: }; static_assert(sizeof(IocGetIdParams) == 8, "IocGetIdParams has wrong size"); - NvResult IocCreate(const std::vector& input, std::vector& output); - NvResult IocAlloc(const std::vector& input, std::vector& output); - NvResult IocGetId(const std::vector& input, std::vector& output); - NvResult IocFromId(const std::vector& input, std::vector& output); - NvResult IocParam(const std::vector& input, std::vector& output); - NvResult IocFree(const std::vector& input, std::vector& output); + NvResult IocCreate(std::span input, std::vector& output); + NvResult IocAlloc(std::span input, std::vector& output); + NvResult IocGetId(std::span input, std::vector& output); + NvResult IocFromId(std::span input, std::vector& output); + NvResult IocParam(std::span input, std::vector& output); + NvResult IocFree(std::span input, std::vector& output); NvCore::Container& container; NvCore::NvMap& file; diff --git a/src/core/hle/service/nvdrv/nvdrv.cpp b/src/core/hle/service/nvdrv/nvdrv.cpp index 6fc8565c0..52d27e755 100644 --- a/src/core/hle/service/nvdrv/nvdrv.cpp +++ b/src/core/hle/service/nvdrv/nvdrv.cpp @@ -124,7 +124,7 @@ DeviceFD Module::Open(const std::string& device_name) { return fd; } -NvResult Module::Ioctl1(DeviceFD fd, Ioctl command, const std::vector& input, +NvResult Module::Ioctl1(DeviceFD fd, Ioctl command, std::span input, std::vector& output) { if (fd < 0) { LOG_ERROR(Service_NVDRV, "Invalid DeviceFD={}!", fd); @@ -141,8 +141,8 @@ NvResult Module::Ioctl1(DeviceFD fd, Ioctl command, const std::vector& input return itr->second->Ioctl1(fd, command, input, output); } -NvResult Module::Ioctl2(DeviceFD fd, Ioctl command, const std::vector& input, - const std::vector& inline_input, std::vector& output) { +NvResult Module::Ioctl2(DeviceFD fd, Ioctl command, std::span input, + std::span inline_input, std::vector& output) { if (fd < 0) { LOG_ERROR(Service_NVDRV, "Invalid DeviceFD={}!", fd); return NvResult::InvalidState; @@ -158,7 +158,7 @@ NvResult Module::Ioctl2(DeviceFD fd, Ioctl command, const std::vector& input return itr->second->Ioctl2(fd, command, input, inline_input, output); } -NvResult Module::Ioctl3(DeviceFD fd, Ioctl command, const std::vector& input, +NvResult Module::Ioctl3(DeviceFD fd, Ioctl command, std::span input, std::vector& output, std::vector& inline_output) { if (fd < 0) { LOG_ERROR(Service_NVDRV, "Invalid DeviceFD={}!", fd); diff --git a/src/core/hle/service/nvdrv/nvdrv.h b/src/core/hle/service/nvdrv/nvdrv.h index f3c81bd88..b09b6e585 100644 --- a/src/core/hle/service/nvdrv/nvdrv.h +++ b/src/core/hle/service/nvdrv/nvdrv.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -79,14 +80,13 @@ public: DeviceFD Open(const std::string& device_name); /// Sends an ioctl command to the specified file descriptor. - NvResult Ioctl1(DeviceFD fd, Ioctl command, const std::vector& input, - std::vector& output); + NvResult Ioctl1(DeviceFD fd, Ioctl command, std::span input, std::vector& output); - NvResult Ioctl2(DeviceFD fd, Ioctl command, const std::vector& input, - const std::vector& inline_input, std::vector& output); + NvResult Ioctl2(DeviceFD fd, Ioctl command, std::span input, + std::span inline_input, std::vector& output); - NvResult Ioctl3(DeviceFD fd, Ioctl command, const std::vector& input, - std::vector& output, std::vector& inline_output); + NvResult Ioctl3(DeviceFD fd, Ioctl command, std::span input, std::vector& output, + std::vector& inline_output); /// Closes a device file descriptor and returns operation success. NvResult Close(DeviceFD fd); diff --git a/src/core/hle/service/nvdrv/nvdrv_interface.cpp b/src/core/hle/service/nvdrv/nvdrv_interface.cpp index edbdfee43..39a4443a0 100644 --- a/src/core/hle/service/nvdrv/nvdrv_interface.cpp +++ b/src/core/hle/service/nvdrv/nvdrv_interface.cpp @@ -27,7 +27,7 @@ void NVDRV::Open(Kernel::HLERequestContext& ctx) { return; } - const auto& buffer = ctx.ReadBuffer(); + const auto& buffer = ctx.ReadBufferSpan(); const std::string device_name(buffer.begin(), buffer.end()); if (device_name == "/dev/nvhost-prof-gpu") { @@ -64,7 +64,7 @@ void NVDRV::Ioctl1(Kernel::HLERequestContext& ctx) { // Check device std::vector output_buffer(ctx.GetWriteBufferSize(0)); - const auto input_buffer = ctx.ReadBuffer(0); + const auto input_buffer = ctx.ReadBufferSpan(0); const auto nv_result = nvdrv->Ioctl1(fd, command, input_buffer, output_buffer); if (command.is_out != 0) { @@ -88,8 +88,8 @@ void NVDRV::Ioctl2(Kernel::HLERequestContext& ctx) { return; } - const auto input_buffer = ctx.ReadBuffer(0); - const auto input_inlined_buffer = ctx.ReadBuffer(1); + const auto input_buffer = ctx.ReadBufferSpan(0); + const auto input_inlined_buffer = ctx.ReadBufferSpan(1); std::vector output_buffer(ctx.GetWriteBufferSize(0)); const auto nv_result = @@ -115,7 +115,7 @@ void NVDRV::Ioctl3(Kernel::HLERequestContext& ctx) { return; } - const auto input_buffer = ctx.ReadBuffer(0); + const auto input_buffer = ctx.ReadBufferSpan(0); std::vector output_buffer(ctx.GetWriteBufferSize(0)); std::vector output_buffer_inline(ctx.GetWriteBufferSize(1)); From 7c1bf68bb411b5f20fc0fd93306127032340ef60 Mon Sep 17 00:00:00 2001 From: ameerj <52414509+ameerj@users.noreply.github.com> Date: Sun, 25 Dec 2022 14:29:53 -0500 Subject: [PATCH 07/10] bsd: Use std::span for read payloads Allows the use of HLERequestContext::ReadBufferSpan --- src/core/hle/service/sockets/bsd.cpp | 29 +++++++++++----------- src/core/hle/service/sockets/bsd.h | 23 +++++++++-------- src/core/internal_network/network.cpp | 4 +-- src/core/internal_network/socket_proxy.cpp | 4 +-- src/core/internal_network/socket_proxy.h | 5 ++-- src/core/internal_network/sockets.h | 9 ++++--- 6 files changed, 38 insertions(+), 36 deletions(-) diff --git a/src/core/hle/service/sockets/bsd.cpp b/src/core/hle/service/sockets/bsd.cpp index 9e94a462f..119d6ba5b 100644 --- a/src/core/hle/service/sockets/bsd.cpp +++ b/src/core/hle/service/sockets/bsd.cpp @@ -186,7 +186,7 @@ void BSD::Poll(Kernel::HLERequestContext& ctx) { ExecuteWork(ctx, PollWork{ .nfds = nfds, .timeout = timeout, - .read_buffer = ctx.ReadBuffer(), + .read_buffer = ctx.ReadBufferSpan(), .write_buffer = std::vector(ctx.GetWriteBufferSize()), }); } @@ -208,8 +208,7 @@ void BSD::Bind(Kernel::HLERequestContext& ctx) { const s32 fd = rp.Pop(); LOG_DEBUG(Service, "called. fd={} addrlen={}", fd, ctx.GetReadBufferSize()); - - BuildErrnoResponse(ctx, BindImpl(fd, ctx.ReadBuffer())); + BuildErrnoResponse(ctx, BindImpl(fd, ctx.ReadBufferSpan())); } void BSD::Connect(Kernel::HLERequestContext& ctx) { @@ -220,7 +219,7 @@ void BSD::Connect(Kernel::HLERequestContext& ctx) { ExecuteWork(ctx, ConnectWork{ .fd = fd, - .addr = ctx.ReadBuffer(), + .addr = ctx.ReadBufferSpan(), }); } @@ -312,7 +311,7 @@ void BSD::SetSockOpt(Kernel::HLERequestContext& ctx) { const u32 level = rp.Pop(); const OptName optname = static_cast(rp.Pop()); - const std::vector buffer = ctx.ReadBuffer(); + const auto buffer = ctx.ReadBufferSpan(); const u8* optval = buffer.empty() ? nullptr : buffer.data(); size_t optlen = buffer.size(); @@ -383,7 +382,7 @@ void BSD::Send(Kernel::HLERequestContext& ctx) { ExecuteWork(ctx, SendWork{ .fd = fd, .flags = flags, - .message = ctx.ReadBuffer(), + .message = ctx.ReadBufferSpan(), }); } @@ -398,8 +397,8 @@ void BSD::SendTo(Kernel::HLERequestContext& ctx) { ExecuteWork(ctx, SendToWork{ .fd = fd, .flags = flags, - .message = ctx.ReadBuffer(0), - .addr = ctx.ReadBuffer(1), + .message = ctx.ReadBufferSpan(0), + .addr = ctx.ReadBufferSpan(1), }); } @@ -412,7 +411,7 @@ void BSD::Write(Kernel::HLERequestContext& ctx) { ExecuteWork(ctx, SendWork{ .fd = fd, .flags = 0, - .message = ctx.ReadBuffer(), + .message = ctx.ReadBufferSpan(), }); } @@ -489,7 +488,7 @@ std::pair BSD::SocketImpl(Domain domain, Type type, Protocol protoco return {fd, Errno::SUCCESS}; } -std::pair BSD::PollImpl(std::vector& write_buffer, std::vector read_buffer, +std::pair BSD::PollImpl(std::vector& write_buffer, std::span read_buffer, s32 nfds, s32 timeout) { if (write_buffer.size() < nfds * sizeof(PollFD)) { return {-1, Errno::INVAL}; @@ -584,7 +583,7 @@ std::pair BSD::AcceptImpl(s32 fd, std::vector& write_buffer) { return {new_fd, Errno::SUCCESS}; } -Errno BSD::BindImpl(s32 fd, const std::vector& addr) { +Errno BSD::BindImpl(s32 fd, std::span addr) { if (!IsFileDescriptorValid(fd)) { return Errno::BADF; } @@ -595,7 +594,7 @@ Errno BSD::BindImpl(s32 fd, const std::vector& addr) { return Translate(file_descriptors[fd]->socket->Bind(Translate(addr_in))); } -Errno BSD::ConnectImpl(s32 fd, const std::vector& addr) { +Errno BSD::ConnectImpl(s32 fd, std::span addr) { if (!IsFileDescriptorValid(fd)) { return Errno::BADF; } @@ -800,15 +799,15 @@ std::pair BSD::RecvFromImpl(s32 fd, u32 flags, std::vector& mess return {ret, bsd_errno}; } -std::pair BSD::SendImpl(s32 fd, u32 flags, const std::vector& message) { +std::pair BSD::SendImpl(s32 fd, u32 flags, std::span message) { if (!IsFileDescriptorValid(fd)) { return {-1, Errno::BADF}; } return Translate(file_descriptors[fd]->socket->Send(message, flags)); } -std::pair BSD::SendToImpl(s32 fd, u32 flags, const std::vector& message, - const std::vector& addr) { +std::pair BSD::SendToImpl(s32 fd, u32 flags, std::span message, + std::span addr) { if (!IsFileDescriptorValid(fd)) { return {-1, Errno::BADF}; } diff --git a/src/core/hle/service/sockets/bsd.h b/src/core/hle/service/sockets/bsd.h index 81e855e0f..56bb3f8b1 100644 --- a/src/core/hle/service/sockets/bsd.h +++ b/src/core/hle/service/sockets/bsd.h @@ -4,6 +4,7 @@ #pragma once #include +#include #include #include "common/common_types.h" @@ -44,7 +45,7 @@ private: s32 nfds; s32 timeout; - std::vector read_buffer; + std::span read_buffer; std::vector write_buffer; s32 ret{}; Errno bsd_errno{}; @@ -65,7 +66,7 @@ private: void Response(Kernel::HLERequestContext& ctx); s32 fd; - std::vector addr; + std::span addr; Errno bsd_errno{}; }; @@ -98,7 +99,7 @@ private: s32 fd; u32 flags; - std::vector message; + std::span message; s32 ret{}; Errno bsd_errno{}; }; @@ -109,8 +110,8 @@ private: s32 fd; u32 flags; - std::vector message; - std::vector addr; + std::span message; + std::span addr; s32 ret{}; Errno bsd_errno{}; }; @@ -143,11 +144,11 @@ private: void ExecuteWork(Kernel::HLERequestContext& ctx, Work work); std::pair SocketImpl(Domain domain, Type type, Protocol protocol); - std::pair PollImpl(std::vector& write_buffer, std::vector read_buffer, + std::pair PollImpl(std::vector& write_buffer, std::span read_buffer, s32 nfds, s32 timeout); std::pair AcceptImpl(s32 fd, std::vector& write_buffer); - Errno BindImpl(s32 fd, const std::vector& addr); - Errno ConnectImpl(s32 fd, const std::vector& addr); + Errno BindImpl(s32 fd, std::span addr); + Errno ConnectImpl(s32 fd, std::span addr); Errno GetPeerNameImpl(s32 fd, std::vector& write_buffer); Errno GetSockNameImpl(s32 fd, std::vector& write_buffer); Errno ListenImpl(s32 fd, s32 backlog); @@ -157,9 +158,9 @@ private: std::pair RecvImpl(s32 fd, u32 flags, std::vector& message); std::pair RecvFromImpl(s32 fd, u32 flags, std::vector& message, std::vector& addr); - std::pair SendImpl(s32 fd, u32 flags, const std::vector& message); - std::pair SendToImpl(s32 fd, u32 flags, const std::vector& message, - const std::vector& addr); + std::pair SendImpl(s32 fd, u32 flags, std::span message); + std::pair SendToImpl(s32 fd, u32 flags, std::span message, + std::span addr); Errno CloseImpl(s32 fd); s32 FindFreeFileDescriptorHandle() noexcept; diff --git a/src/core/internal_network/network.cpp b/src/core/internal_network/network.cpp index 447fbffaa..452212964 100644 --- a/src/core/internal_network/network.cpp +++ b/src/core/internal_network/network.cpp @@ -546,7 +546,7 @@ std::pair Socket::RecvFrom(int flags, std::vector& message, Sock return {-1, GetAndLogLastError()}; } -std::pair Socket::Send(const std::vector& message, int flags) { +std::pair Socket::Send(std::span message, int flags) { ASSERT(message.size() < static_cast(std::numeric_limits::max())); ASSERT(flags == 0); @@ -559,7 +559,7 @@ std::pair Socket::Send(const std::vector& message, int flags) { return {-1, GetAndLogLastError()}; } -std::pair Socket::SendTo(u32 flags, const std::vector& message, +std::pair Socket::SendTo(u32 flags, std::span message, const SockAddrIn* addr) { ASSERT(flags == 0); diff --git a/src/core/internal_network/socket_proxy.cpp b/src/core/internal_network/socket_proxy.cpp index 1e1c42cea..7a77171c2 100644 --- a/src/core/internal_network/socket_proxy.cpp +++ b/src/core/internal_network/socket_proxy.cpp @@ -182,7 +182,7 @@ std::pair ProxySocket::ReceivePacket(int flags, std::vector& mes return {static_cast(read_bytes), Errno::SUCCESS}; } -std::pair ProxySocket::Send(const std::vector& message, int flags) { +std::pair ProxySocket::Send(std::span message, int flags) { LOG_WARNING(Network, "(STUBBED) called"); ASSERT(message.size() < static_cast(std::numeric_limits::max())); ASSERT(flags == 0); @@ -200,7 +200,7 @@ void ProxySocket::SendPacket(ProxyPacket& packet) { } } -std::pair ProxySocket::SendTo(u32 flags, const std::vector& message, +std::pair ProxySocket::SendTo(u32 flags, std::span message, const SockAddrIn* addr) { ASSERT(flags == 0); diff --git a/src/core/internal_network/socket_proxy.h b/src/core/internal_network/socket_proxy.h index f12b5f567..9421492bc 100644 --- a/src/core/internal_network/socket_proxy.h +++ b/src/core/internal_network/socket_proxy.h @@ -4,6 +4,7 @@ #pragma once #include +#include #include #include @@ -48,11 +49,11 @@ public: std::pair ReceivePacket(int flags, std::vector& message, SockAddrIn* addr, std::size_t max_length); - std::pair Send(const std::vector& message, int flags) override; + std::pair Send(std::span message, int flags) override; void SendPacket(ProxyPacket& packet); - std::pair SendTo(u32 flags, const std::vector& message, + std::pair SendTo(u32 flags, std::span message, const SockAddrIn* addr) override; Errno SetLinger(bool enable, u32 linger) override; diff --git a/src/core/internal_network/sockets.h b/src/core/internal_network/sockets.h index 2e328c645..4c7489258 100644 --- a/src/core/internal_network/sockets.h +++ b/src/core/internal_network/sockets.h @@ -5,6 +5,7 @@ #include #include +#include #include #if defined(_WIN32) @@ -66,9 +67,9 @@ public: virtual std::pair RecvFrom(int flags, std::vector& message, SockAddrIn* addr) = 0; - virtual std::pair Send(const std::vector& message, int flags) = 0; + virtual std::pair Send(std::span message, int flags) = 0; - virtual std::pair SendTo(u32 flags, const std::vector& message, + virtual std::pair SendTo(u32 flags, std::span message, const SockAddrIn* addr) = 0; virtual Errno SetLinger(bool enable, u32 linger) = 0; @@ -138,9 +139,9 @@ public: std::pair RecvFrom(int flags, std::vector& message, SockAddrIn* addr) override; - std::pair Send(const std::vector& message, int flags) override; + std::pair Send(std::span message, int flags) override; - std::pair SendTo(u32 flags, const std::vector& message, + std::pair SendTo(u32 flags, std::span message, const SockAddrIn* addr) override; Errno SetLinger(bool enable, u32 linger) override; From 59c0f85407d1d5d80fb88e5a6b0bab8d1abf438f Mon Sep 17 00:00:00 2001 From: ameerj <52414509+ameerj@users.noreply.github.com> Date: Sun, 25 Dec 2022 14:30:21 -0500 Subject: [PATCH 08/10] hle_ipc: Rename ReadBuffer to ReadBufferCopy Indicates explicitly that a copy is occurring --- src/core/hle/kernel/hle_ipc.cpp | 2 +- src/core/hle/kernel/hle_ipc.h | 5 +++-- src/core/hle/service/glue/arp.cpp | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp index 9bc72da02..36cf750de 100644 --- a/src/core/hle/kernel/hle_ipc.cpp +++ b/src/core/hle/kernel/hle_ipc.cpp @@ -325,7 +325,7 @@ Result HLERequestContext::WriteToOutgoingCommandBuffer(KThread& requesting_threa return ResultSuccess; } -std::vector HLERequestContext::ReadBuffer(std::size_t buffer_index) const { +std::vector HLERequestContext::ReadBufferCopy(std::size_t buffer_index) const { const bool is_buffer_a{BufferDescriptorA().size() > buffer_index && BufferDescriptorA()[buffer_index].Size()}; if (is_buffer_a) { diff --git a/src/core/hle/kernel/hle_ipc.h b/src/core/hle/kernel/hle_ipc.h index 2242ff922..27f9628c7 100644 --- a/src/core/hle/kernel/hle_ipc.h +++ b/src/core/hle/kernel/hle_ipc.h @@ -271,9 +271,10 @@ public: return domain_message_header.has_value(); } - /// Helper function to read a buffer using the appropriate buffer descriptor - [[nodiscard]] std::vector ReadBuffer(std::size_t buffer_index = 0) const; + /// Helper function to read a copy of a buffer using the appropriate buffer descriptor + [[nodiscard]] std::vector ReadBufferCopy(std::size_t buffer_index = 0) const; + /// Helper function to get a span of a buffer using the appropriate buffer descriptor [[nodiscard]] std::span ReadBufferSpan(std::size_t buffer_index = 0) const; /// Helper function to write a buffer using the appropriate buffer descriptor diff --git a/src/core/hle/service/glue/arp.cpp b/src/core/hle/service/glue/arp.cpp index 49b6d45fe..ce21b69e3 100644 --- a/src/core/hle/service/glue/arp.cpp +++ b/src/core/hle/service/glue/arp.cpp @@ -228,7 +228,8 @@ private: return; } - control = ctx.ReadBuffer(); + // TODO: Can this be a span? + control = ctx.ReadBufferCopy(); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); From a1490d77ace26ec01a60541239d9a8524b88fcec Mon Sep 17 00:00:00 2001 From: ameerj <52414509+ameerj@users.noreply.github.com> Date: Sun, 25 Dec 2022 14:31:53 -0500 Subject: [PATCH 09/10] hle_ipc: Rename ReadBufferSpan to ReadBuffer --- src/core/hle/kernel/hle_ipc.cpp | 2 +- src/core/hle/kernel/hle_ipc.h | 6 ++-- src/core/hle/service/acc/acc.cpp | 6 ++-- src/core/hle/service/am/am.cpp | 2 +- src/core/hle/service/aoc/aoc_u.cpp | 4 +-- src/core/hle/service/audio/audin_u.cpp | 6 ++-- src/core/hle/service/audio/audout_u.cpp | 4 +-- src/core/hle/service/audio/audren_u.cpp | 6 ++-- src/core/hle/service/audio/hwopus.cpp | 4 +-- src/core/hle/service/bcat/bcat_module.cpp | 2 +- src/core/hle/service/es/es.cpp | 4 +-- src/core/hle/service/fatal/fatal.cpp | 2 +- src/core/hle/service/filesystem/fsp_srv.cpp | 28 +++++++++---------- src/core/hle/service/glue/notif.cpp | 4 +-- src/core/hle/service/hid/hid.cpp | 8 +++--- src/core/hle/service/hid/hidbus.cpp | 2 +- src/core/hle/service/jit/jit.cpp | 6 ++-- src/core/hle/service/ldn/ldn.cpp | 4 +-- src/core/hle/service/lm/lm.cpp | 2 +- src/core/hle/service/nfc/mifare_user.cpp | 4 +-- src/core/hle/service/nfc/nfc_user.cpp | 2 +- src/core/hle/service/nfp/nfp_user.cpp | 6 ++-- src/core/hle/service/ngct/ngct.cpp | 4 +-- src/core/hle/service/nifm/nifm.cpp | 2 +- .../hle/service/nvdrv/nvdrv_interface.cpp | 10 +++---- .../nvflinger/buffer_queue_producer.cpp | 2 +- src/core/hle/service/prepo/prepo.cpp | 16 +++++------ src/core/hle/service/set/set_sys.cpp | 8 +++--- src/core/hle/service/sockets/bsd.cpp | 16 +++++------ src/core/hle/service/sockets/sfdnsres.cpp | 4 +-- src/core/hle/service/ssl/ssl.cpp | 6 ++-- src/core/hle/service/time/time.cpp | 8 +++--- .../hle/service/time/time_zone_service.cpp | 4 +-- 33 files changed, 97 insertions(+), 97 deletions(-) diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp index 36cf750de..f6654f56c 100644 --- a/src/core/hle/kernel/hle_ipc.cpp +++ b/src/core/hle/kernel/hle_ipc.cpp @@ -345,7 +345,7 @@ std::vector HLERequestContext::ReadBufferCopy(std::size_t buffer_index) cons } } -std::span HLERequestContext::ReadBufferSpan(std::size_t buffer_index) const { +std::span HLERequestContext::ReadBuffer(std::size_t buffer_index) const { const bool is_buffer_a{BufferDescriptorA().size() > buffer_index && BufferDescriptorA()[buffer_index].Size()}; if (is_buffer_a) { diff --git a/src/core/hle/kernel/hle_ipc.h b/src/core/hle/kernel/hle_ipc.h index 27f9628c7..5bf4f171b 100644 --- a/src/core/hle/kernel/hle_ipc.h +++ b/src/core/hle/kernel/hle_ipc.h @@ -271,12 +271,12 @@ public: return domain_message_header.has_value(); } + /// Helper function to get a span of a buffer using the appropriate buffer descriptor + [[nodiscard]] std::span ReadBuffer(std::size_t buffer_index = 0) const; + /// Helper function to read a copy of a buffer using the appropriate buffer descriptor [[nodiscard]] std::vector ReadBufferCopy(std::size_t buffer_index = 0) const; - /// Helper function to get a span of a buffer using the appropriate buffer descriptor - [[nodiscard]] std::span ReadBufferSpan(std::size_t buffer_index = 0) const; - /// Helper function to write a buffer using the appropriate buffer descriptor std::size_t WriteBuffer(const void* buffer, std::size_t size, std::size_t buffer_index = 0) const; diff --git a/src/core/hle/service/acc/acc.cpp b/src/core/hle/service/acc/acc.cpp index 398bbc793..6d1084fd1 100644 --- a/src/core/hle/service/acc/acc.cpp +++ b/src/core/hle/service/acc/acc.cpp @@ -367,7 +367,7 @@ protected: IPC::RequestParser rp{ctx}; const auto base = rp.PopRaw(); - const auto user_data = ctx.ReadBufferSpan(); + const auto user_data = ctx.ReadBuffer(); LOG_DEBUG(Service_ACC, "called, username='{}', timestamp={:016X}, uuid=0x{}", Common::StringFromFixedZeroTerminatedBuffer( @@ -399,8 +399,8 @@ protected: IPC::RequestParser rp{ctx}; const auto base = rp.PopRaw(); - const auto user_data = ctx.ReadBufferSpan(); - const auto image_data = ctx.ReadBufferSpan(1); + const auto user_data = ctx.ReadBuffer(); + const auto image_data = ctx.ReadBuffer(1); LOG_DEBUG(Service_ACC, "called, username='{}', timestamp={:016X}, uuid=0x{}", Common::StringFromFixedZeroTerminatedBuffer( diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index 958e40648..ebcf6e164 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp @@ -1124,7 +1124,7 @@ void IStorageAccessor::Write(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const u64 offset{rp.Pop()}; - const auto data{ctx.ReadBufferSpan()}; + const auto data{ctx.ReadBuffer()}; const std::size_t size{std::min(data.size(), backing.GetSize() - offset)}; LOG_DEBUG(Service_AM, "called, offset={}, size={}", offset, size); diff --git a/src/core/hle/service/aoc/aoc_u.cpp b/src/core/hle/service/aoc/aoc_u.cpp index cc976b155..368ccd52f 100644 --- a/src/core/hle/service/aoc/aoc_u.cpp +++ b/src/core/hle/service/aoc/aoc_u.cpp @@ -72,7 +72,7 @@ private: IPC::RequestParser rp{ctx}; const auto unknown_1 = rp.Pop(); - [[maybe_unused]] const auto unknown_2 = ctx.ReadBufferSpan(); + [[maybe_unused]] const auto unknown_2 = ctx.ReadBuffer(); LOG_WARNING(Service_AOC, "(STUBBED) called, unknown_1={}", unknown_1); @@ -84,7 +84,7 @@ private: IPC::RequestParser rp{ctx}; const auto unknown_1 = rp.Pop(); - [[maybe_unused]] const auto unknown_2 = ctx.ReadBufferSpan(); + [[maybe_unused]] const auto unknown_2 = ctx.ReadBuffer(); LOG_WARNING(Service_AOC, "(STUBBED) called, unknown_1={}", unknown_1); diff --git a/src/core/hle/service/audio/audin_u.cpp b/src/core/hle/service/audio/audin_u.cpp index f3dd8397d..053e8f9dd 100644 --- a/src/core/hle/service/audio/audin_u.cpp +++ b/src/core/hle/service/audio/audin_u.cpp @@ -98,7 +98,7 @@ private: LOG_ERROR(Service_Audio, "Input buffer is too small for an AudioInBuffer!"); } - const auto& in_buffer = ctx.ReadBufferSpan(); + const auto& in_buffer = ctx.ReadBuffer(); AudioInBuffer buffer{}; std::memcpy(&buffer, in_buffer.data(), sizeof(AudioInBuffer)); @@ -266,7 +266,7 @@ void AudInU::OpenAudioIn(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; auto in_params{rp.PopRaw()}; auto applet_resource_user_id{rp.PopRaw()}; - const auto device_name_data{ctx.ReadBufferSpan()}; + const auto device_name_data{ctx.ReadBuffer()}; auto device_name = Common::StringFromBuffer(device_name_data); auto handle{ctx.GetCopyHandle(0)}; @@ -317,7 +317,7 @@ void AudInU::OpenAudioInProtocolSpecified(Kernel::HLERequestContext& ctx) { auto protocol_specified{rp.PopRaw()}; auto in_params{rp.PopRaw()}; auto applet_resource_user_id{rp.PopRaw()}; - const auto device_name_data{ctx.ReadBufferSpan()}; + const auto device_name_data{ctx.ReadBuffer()}; auto device_name = Common::StringFromBuffer(device_name_data); auto handle{ctx.GetCopyHandle(0)}; diff --git a/src/core/hle/service/audio/audout_u.cpp b/src/core/hle/service/audio/audout_u.cpp index 4bf388055..29751f075 100644 --- a/src/core/hle/service/audio/audout_u.cpp +++ b/src/core/hle/service/audio/audout_u.cpp @@ -105,7 +105,7 @@ private: LOG_ERROR(Service_Audio, "Input buffer is too small for an AudioOutBuffer!"); } - const auto& in_buffer = ctx.ReadBufferSpan(); + const auto& in_buffer = ctx.ReadBuffer(); AudioOutBuffer buffer{}; std::memcpy(&buffer, in_buffer.data(), sizeof(AudioOutBuffer)); @@ -264,7 +264,7 @@ void AudOutU::OpenAudioOut(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; auto in_params{rp.PopRaw()}; auto applet_resource_user_id{rp.PopRaw()}; - const auto device_name_data{ctx.ReadBufferSpan()}; + const auto device_name_data{ctx.ReadBuffer()}; auto device_name = Common::StringFromBuffer(device_name_data); auto handle{ctx.GetCopyHandle(0)}; diff --git a/src/core/hle/service/audio/audren_u.cpp b/src/core/hle/service/audio/audren_u.cpp index 1a48c155e..0ee28752c 100644 --- a/src/core/hle/service/audio/audren_u.cpp +++ b/src/core/hle/service/audio/audren_u.cpp @@ -112,7 +112,7 @@ private: void RequestUpdate(Kernel::HLERequestContext& ctx) { LOG_TRACE(Service_Audio, "called"); - const auto input{ctx.ReadBufferSpan(0)}; + const auto input{ctx.ReadBuffer(0)}; // These buffers are written manually to avoid an issue with WriteBuffer throwing errors for // checking size 0. Performance size is 0 for most games. @@ -306,7 +306,7 @@ private: IPC::RequestParser rp{ctx}; const f32 volume = rp.Pop(); - const auto device_name_buffer = ctx.ReadBufferSpan(); + const auto device_name_buffer = ctx.ReadBuffer(); const std::string name = Common::StringFromBuffer(device_name_buffer); LOG_DEBUG(Service_Audio, "called. name={}, volume={}", name, volume); @@ -320,7 +320,7 @@ private: } void GetAudioDeviceOutputVolume(Kernel::HLERequestContext& ctx) { - const auto device_name_buffer = ctx.ReadBufferSpan(); + const auto device_name_buffer = ctx.ReadBuffer(); const std::string name = Common::StringFromBuffer(device_name_buffer); LOG_DEBUG(Service_Audio, "called. Name={}", name); diff --git a/src/core/hle/service/audio/hwopus.cpp b/src/core/hle/service/audio/hwopus.cpp index 7c3f25c67..e01f87356 100644 --- a/src/core/hle/service/audio/hwopus.cpp +++ b/src/core/hle/service/audio/hwopus.cpp @@ -74,7 +74,7 @@ private: ResetDecoderContext(); } - if (!DecodeOpusData(consumed, sample_count, ctx.ReadBufferSpan(), samples, performance)) { + if (!DecodeOpusData(consumed, sample_count, ctx.ReadBuffer(), samples, performance)) { LOG_ERROR(Audio, "Failed to decode opus data"); IPC::ResponseBuilder rb{ctx, 2}; // TODO(ogniK): Use correct error code @@ -257,7 +257,7 @@ void HwOpus::GetWorkBufferSizeEx(Kernel::HLERequestContext& ctx) { void HwOpus::GetWorkBufferSizeForMultiStreamEx(Kernel::HLERequestContext& ctx) { OpusMultiStreamParametersEx param; - std::memcpy(¶m, ctx.ReadBufferSpan().data(), ctx.GetReadBufferSize()); + std::memcpy(¶m, ctx.ReadBuffer().data(), ctx.GetReadBufferSize()); const auto sample_rate = param.sample_rate; const auto channel_count = param.channel_count; diff --git a/src/core/hle/service/bcat/bcat_module.cpp b/src/core/hle/service/bcat/bcat_module.cpp index c1a012739..cbe690a5d 100644 --- a/src/core/hle/service/bcat/bcat_module.cpp +++ b/src/core/hle/service/bcat/bcat_module.cpp @@ -206,7 +206,7 @@ private: IPC::RequestParser rp{ctx}; const auto title_id = rp.PopRaw(); - const auto passphrase_raw = ctx.ReadBufferSpan(); + const auto passphrase_raw = ctx.ReadBuffer(); LOG_DEBUG(Service_BCAT, "called, title_id={:016X}, passphrase={}", title_id, Common::HexToString(passphrase_raw)); diff --git a/src/core/hle/service/es/es.cpp b/src/core/hle/service/es/es.cpp index 5ea61c430..fb8686859 100644 --- a/src/core/hle/service/es/es.cpp +++ b/src/core/hle/service/es/es.cpp @@ -121,8 +121,8 @@ private: } void ImportTicket(Kernel::HLERequestContext& ctx) { - const auto ticket = ctx.ReadBufferSpan(); - [[maybe_unused]] const auto cert = ctx.ReadBufferSpan(1); + const auto ticket = ctx.ReadBuffer(); + [[maybe_unused]] const auto cert = ctx.ReadBuffer(1); if (ticket.size() < sizeof(Core::Crypto::Ticket)) { LOG_ERROR(Service_ETicket, "The input buffer is not large enough!"); diff --git a/src/core/hle/service/fatal/fatal.cpp b/src/core/hle/service/fatal/fatal.cpp index ff896ea10..27675615b 100644 --- a/src/core/hle/service/fatal/fatal.cpp +++ b/src/core/hle/service/fatal/fatal.cpp @@ -152,7 +152,7 @@ void Module::Interface::ThrowFatalWithCpuContext(Kernel::HLERequestContext& ctx) IPC::RequestParser rp(ctx); const auto error_code = rp.Pop(); const auto fatal_type = rp.PopEnum(); - const auto fatal_info = ctx.ReadBufferSpan(); + const auto fatal_info = ctx.ReadBuffer(); FatalInfo info{}; ASSERT_MSG(fatal_info.size() == sizeof(FatalInfo), "Invalid fatal info buffer size!"); diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp index efebb0ccc..cab44bf9c 100644 --- a/src/core/hle/service/filesystem/fsp_srv.cpp +++ b/src/core/hle/service/filesystem/fsp_srv.cpp @@ -190,7 +190,7 @@ private: return; } - const auto data = ctx.ReadBufferSpan(); + const auto data = ctx.ReadBuffer(); ASSERT_MSG( static_cast(data.size()) <= length, @@ -337,7 +337,7 @@ public: void CreateFile(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - const auto file_buffer = ctx.ReadBufferSpan(); + const auto file_buffer = ctx.ReadBuffer(); const std::string name = Common::StringFromBuffer(file_buffer); const u64 file_mode = rp.Pop(); @@ -351,7 +351,7 @@ public: } void DeleteFile(Kernel::HLERequestContext& ctx) { - const auto file_buffer = ctx.ReadBufferSpan(); + const auto file_buffer = ctx.ReadBuffer(); const std::string name = Common::StringFromBuffer(file_buffer); LOG_DEBUG(Service_FS, "called. file={}", name); @@ -361,7 +361,7 @@ public: } void CreateDirectory(Kernel::HLERequestContext& ctx) { - const auto file_buffer = ctx.ReadBufferSpan(); + const auto file_buffer = ctx.ReadBuffer(); const std::string name = Common::StringFromBuffer(file_buffer); LOG_DEBUG(Service_FS, "called. directory={}", name); @@ -371,7 +371,7 @@ public: } void DeleteDirectory(Kernel::HLERequestContext& ctx) { - const auto file_buffer = ctx.ReadBufferSpan(); + const auto file_buffer = ctx.ReadBuffer(); const std::string name = Common::StringFromBuffer(file_buffer); LOG_DEBUG(Service_FS, "called. directory={}", name); @@ -381,7 +381,7 @@ public: } void DeleteDirectoryRecursively(Kernel::HLERequestContext& ctx) { - const auto file_buffer = ctx.ReadBufferSpan(); + const auto file_buffer = ctx.ReadBuffer(); const std::string name = Common::StringFromBuffer(file_buffer); LOG_DEBUG(Service_FS, "called. directory={}", name); @@ -391,7 +391,7 @@ public: } void CleanDirectoryRecursively(Kernel::HLERequestContext& ctx) { - const auto file_buffer = ctx.ReadBufferSpan(); + const auto file_buffer = ctx.ReadBuffer(); const std::string name = Common::StringFromBuffer(file_buffer); LOG_DEBUG(Service_FS, "called. Directory: {}", name); @@ -401,8 +401,8 @@ public: } void RenameFile(Kernel::HLERequestContext& ctx) { - const std::string src_name = Common::StringFromBuffer(ctx.ReadBufferSpan(0)); - const std::string dst_name = Common::StringFromBuffer(ctx.ReadBufferSpan(1)); + const std::string src_name = Common::StringFromBuffer(ctx.ReadBuffer(0)); + const std::string dst_name = Common::StringFromBuffer(ctx.ReadBuffer(1)); LOG_DEBUG(Service_FS, "called. file '{}' to file '{}'", src_name, dst_name); @@ -413,7 +413,7 @@ public: void OpenFile(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - const auto file_buffer = ctx.ReadBufferSpan(); + const auto file_buffer = ctx.ReadBuffer(); const std::string name = Common::StringFromBuffer(file_buffer); const auto mode = static_cast(rp.Pop()); @@ -437,7 +437,7 @@ public: void OpenDirectory(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - const auto file_buffer = ctx.ReadBufferSpan(); + const auto file_buffer = ctx.ReadBuffer(); const std::string name = Common::StringFromBuffer(file_buffer); // TODO(Subv): Implement this filter. @@ -460,7 +460,7 @@ public: } void GetEntryType(Kernel::HLERequestContext& ctx) { - const auto file_buffer = ctx.ReadBufferSpan(); + const auto file_buffer = ctx.ReadBuffer(); const std::string name = Common::StringFromBuffer(file_buffer); LOG_DEBUG(Service_FS, "called. file={}", name); @@ -501,7 +501,7 @@ public: } void GetFileTimeStampRaw(Kernel::HLERequestContext& ctx) { - const auto file_buffer = ctx.ReadBufferSpan(); + const auto file_buffer = ctx.ReadBuffer(); const std::string name = Common::StringFromBuffer(file_buffer); LOG_WARNING(Service_FS, "(Partial Implementation) called. file={}", name); @@ -1083,7 +1083,7 @@ void FSP_SRV::GetGlobalAccessLogMode(Kernel::HLERequestContext& ctx) { } void FSP_SRV::OutputAccessLogToSdCard(Kernel::HLERequestContext& ctx) { - const auto raw = ctx.ReadBufferSpan(); + const auto raw = ctx.ReadBuffer(); auto log = Common::StringFromFixedZeroTerminatedBuffer( reinterpret_cast(raw.data()), raw.size()); diff --git a/src/core/hle/service/glue/notif.cpp b/src/core/hle/service/glue/notif.cpp index ee5c6d3a4..3ace2dabd 100644 --- a/src/core/hle/service/glue/notif.cpp +++ b/src/core/hle/service/glue/notif.cpp @@ -38,7 +38,7 @@ void NOTIF_A::RegisterAlarmSetting(Kernel::HLERequestContext& ctx) { "application_parameter_size is bigger than 0x400 bytes"); AlarmSetting new_alarm{}; - memcpy(&new_alarm, ctx.ReadBufferSpan(0).data(), sizeof(AlarmSetting)); + memcpy(&new_alarm, ctx.ReadBuffer(0).data(), sizeof(AlarmSetting)); // TODO: Count alarms per game id if (alarms.size() >= max_alarms) { @@ -73,7 +73,7 @@ void NOTIF_A::UpdateAlarmSetting(Kernel::HLERequestContext& ctx) { "application_parameter_size is bigger than 0x400 bytes"); AlarmSetting alarm_setting{}; - memcpy(&alarm_setting, ctx.ReadBufferSpan(0).data(), sizeof(AlarmSetting)); + memcpy(&alarm_setting, ctx.ReadBuffer(0).data(), sizeof(AlarmSetting)); const auto alarm_it = GetAlarmFromId(alarm_setting.alarm_setting_id); if (alarm_it != alarms.end()) { diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index 294fe927b..f15f1a6bb 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp @@ -1026,7 +1026,7 @@ void Hid::SetSupportedNpadIdType(Kernel::HLERequestContext& ctx) { const auto applet_resource_user_id{rp.Pop()}; applet_resource->GetController(HidController::NPad) - .SetSupportedNpadIdTypes(ctx.ReadBufferSpan()); + .SetSupportedNpadIdTypes(ctx.ReadBuffer()); LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); @@ -1564,8 +1564,8 @@ void Hid::SendVibrationValues(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop()}; - const auto handles = ctx.ReadBufferSpan(0); - const auto vibrations = ctx.ReadBufferSpan(1); + const auto handles = ctx.ReadBuffer(0); + const auto vibrations = ctx.ReadBuffer(1); std::vector vibration_device_handles( handles.size() / sizeof(Core::HID::VibrationDeviceHandle)); @@ -2104,7 +2104,7 @@ void Hid::WritePalmaRgbLedPatternEntry(Kernel::HLERequestContext& ctx) { const auto connection_handle{rp.PopRaw()}; const auto unknown{rp.Pop()}; - [[maybe_unused]] const auto buffer = ctx.ReadBufferSpan(); + [[maybe_unused]] const auto buffer = ctx.ReadBuffer(); LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}, unknown={}", connection_handle.npad_id, unknown); diff --git a/src/core/hle/service/hid/hidbus.cpp b/src/core/hle/service/hid/hidbus.cpp index abc15c34e..e5e50845f 100644 --- a/src/core/hle/service/hid/hidbus.cpp +++ b/src/core/hle/service/hid/hidbus.cpp @@ -351,7 +351,7 @@ void HidBus::GetExternalDeviceId(Kernel::HLERequestContext& ctx) { void HidBus::SendCommandAsync(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - const auto data = ctx.ReadBufferSpan(); + const auto data = ctx.ReadBuffer(); const auto bus_handle_{rp.PopRaw()}; LOG_DEBUG(Service_HID, diff --git a/src/core/hle/service/jit/jit.cpp b/src/core/hle/service/jit/jit.cpp index 534639ff9..1295a44c7 100644 --- a/src/core/hle/service/jit/jit.cpp +++ b/src/core/hle/service/jit/jit.cpp @@ -62,7 +62,7 @@ public: const auto parameters{rp.PopRaw()}; // Optional input/output buffers - const auto input_buffer{ctx.CanReadBuffer() ? ctx.ReadBufferSpan() : std::span()}; + const auto input_buffer{ctx.CanReadBuffer() ? ctx.ReadBuffer() : std::span()}; std::vector output_buffer(ctx.CanWriteBuffer() ? ctx.GetWriteBufferSize() : 0); // Function call prototype: @@ -132,7 +132,7 @@ public: const auto command{rp.PopRaw()}; // Optional input/output buffers - const auto input_buffer{ctx.CanReadBuffer() ? ctx.ReadBufferSpan() : std::span()}; + const auto input_buffer{ctx.CanReadBuffer() ? ctx.ReadBuffer() : std::span()}; std::vector output_buffer(ctx.CanWriteBuffer() ? ctx.GetWriteBufferSize() : 0); // Function call prototype: @@ -176,7 +176,7 @@ public: IPC::RequestParser rp{ctx}; const auto tmem_size{rp.PopRaw()}; const auto tmem_handle{ctx.GetCopyHandle(0)}; - const auto nro_plugin{ctx.ReadBufferSpan(1)}; + const auto nro_plugin{ctx.ReadBuffer(1)}; if (tmem_size == 0) { LOG_ERROR(Service_JIT, "attempted to load plugin with empty transfer memory"); diff --git a/src/core/hle/service/ldn/ldn.cpp b/src/core/hle/service/ldn/ldn.cpp index ad097a6ef..e5099d61f 100644 --- a/src/core/hle/service/ldn/ldn.cpp +++ b/src/core/hle/service/ldn/ldn.cpp @@ -412,7 +412,7 @@ public: } void SetAdvertiseData(Kernel::HLERequestContext& ctx) { - const auto read_buffer = ctx.ReadBufferSpan(); + const auto read_buffer = ctx.ReadBuffer(); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(lan_discovery.SetAdvertiseData(read_buffer)); @@ -464,7 +464,7 @@ public: parameters.security_config.passphrase_size, parameters.security_config.security_mode, parameters.local_communication_version); - const auto read_buffer = ctx.ReadBufferSpan(); + const auto read_buffer = ctx.ReadBuffer(); if (read_buffer.size() != sizeof(NetworkInfo)) { LOG_ERROR(Frontend, "NetworkInfo doesn't match read_buffer size!"); IPC::ResponseBuilder rb{ctx, 2}; diff --git a/src/core/hle/service/lm/lm.cpp b/src/core/hle/service/lm/lm.cpp index 0da461e6c..ef4b54046 100644 --- a/src/core/hle/service/lm/lm.cpp +++ b/src/core/hle/service/lm/lm.cpp @@ -94,7 +94,7 @@ public: private: void Log(Kernel::HLERequestContext& ctx) { std::size_t offset{}; - const auto data = ctx.ReadBufferSpan(); + const auto data = ctx.ReadBuffer(); // This function only succeeds - Get that out of the way IPC::ResponseBuilder rb{ctx, 2}; diff --git a/src/core/hle/service/nfc/mifare_user.cpp b/src/core/hle/service/nfc/mifare_user.cpp index 7d391c936..51523a3ae 100644 --- a/src/core/hle/service/nfc/mifare_user.cpp +++ b/src/core/hle/service/nfc/mifare_user.cpp @@ -168,7 +168,7 @@ void MFIUser::StopDetection(Kernel::HLERequestContext& ctx) { void MFIUser::Read(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop()}; - const auto buffer{ctx.ReadBufferSpan()}; + const auto buffer{ctx.ReadBuffer()}; const auto number_of_commands{ctx.GetReadBufferNumElements()}; std::vector read_commands(number_of_commands); @@ -209,7 +209,7 @@ void MFIUser::Read(Kernel::HLERequestContext& ctx) { void MFIUser::Write(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop()}; - const auto buffer{ctx.ReadBufferSpan()}; + const auto buffer{ctx.ReadBuffer()}; const auto number_of_commands{ctx.GetReadBufferNumElements()}; std::vector write_commands(number_of_commands); diff --git a/src/core/hle/service/nfc/nfc_user.cpp b/src/core/hle/service/nfc/nfc_user.cpp index 5dcf8a423..89aa6b3f5 100644 --- a/src/core/hle/service/nfc/nfc_user.cpp +++ b/src/core/hle/service/nfc/nfc_user.cpp @@ -325,7 +325,7 @@ void IUser::SendCommandByPassThrough(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop()}; const auto timeout{rp.PopRaw()}; - const auto command_data{ctx.ReadBufferSpan()}; + const auto command_data{ctx.ReadBuffer()}; LOG_INFO(Service_NFC, "(STUBBED) called, device_handle={}, timeout={}, data_size={}", device_handle, timeout.ToSeconds(), command_data.size()); diff --git a/src/core/hle/service/nfp/nfp_user.cpp b/src/core/hle/service/nfp/nfp_user.cpp index 0a5606756..a4d3d1bc7 100644 --- a/src/core/hle/service/nfp/nfp_user.cpp +++ b/src/core/hle/service/nfp/nfp_user.cpp @@ -290,7 +290,7 @@ void IUser::GetApplicationArea(Kernel::HLERequestContext& ctx) { void IUser::SetApplicationArea(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop()}; - const auto data{ctx.ReadBufferSpan()}; + const auto data{ctx.ReadBuffer()}; LOG_INFO(Service_NFP, "called, device_handle={}, data_size={}", device_handle, data.size()); if (state == State::NonInitialized) { @@ -370,7 +370,7 @@ void IUser::CreateApplicationArea(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop()}; const auto access_id{rp.Pop()}; - const auto data{ctx.ReadBufferSpan()}; + const auto data{ctx.ReadBuffer()}; LOG_INFO(Service_NFP, "called, device_handle={}, data_size={}, access_id={}", device_handle, access_id, data.size()); @@ -637,7 +637,7 @@ void IUser::RecreateApplicationArea(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto device_handle{rp.Pop()}; const auto access_id{rp.Pop()}; - const auto data{ctx.ReadBufferSpan()}; + const auto data{ctx.ReadBuffer()}; LOG_INFO(Service_NFP, "called, device_handle={}, data_size={}, access_id={}", device_handle, access_id, data.size()); diff --git a/src/core/hle/service/ngct/ngct.cpp b/src/core/hle/service/ngct/ngct.cpp index bee62b054..8af8a835d 100644 --- a/src/core/hle/service/ngct/ngct.cpp +++ b/src/core/hle/service/ngct/ngct.cpp @@ -24,7 +24,7 @@ public: private: void Match(Kernel::HLERequestContext& ctx) { - const auto buffer = ctx.ReadBufferSpan(); + const auto buffer = ctx.ReadBuffer(); const auto text = Common::StringFromFixedZeroTerminatedBuffer( reinterpret_cast(buffer.data()), buffer.size()); @@ -37,7 +37,7 @@ private: } void Filter(Kernel::HLERequestContext& ctx) { - const auto buffer = ctx.ReadBufferSpan(); + const auto buffer = ctx.ReadBuffer(); const auto text = Common::StringFromFixedZeroTerminatedBuffer( reinterpret_cast(buffer.data()), buffer.size()); diff --git a/src/core/hle/service/nifm/nifm.cpp b/src/core/hle/service/nifm/nifm.cpp index a6446fdcc..4fa9f51a6 100644 --- a/src/core/hle/service/nifm/nifm.cpp +++ b/src/core/hle/service/nifm/nifm.cpp @@ -414,7 +414,7 @@ void IGeneralService::CreateTemporaryNetworkProfile(Kernel::HLERequestContext& c ASSERT_MSG(ctx.GetReadBufferSize() == 0x17c, "SfNetworkProfileData is not the correct size"); u128 uuid{}; - auto buffer = ctx.ReadBufferSpan(); + auto buffer = ctx.ReadBuffer(); std::memcpy(&uuid, buffer.data() + 8, sizeof(u128)); IPC::ResponseBuilder rb{ctx, 6, 0, 1}; diff --git a/src/core/hle/service/nvdrv/nvdrv_interface.cpp b/src/core/hle/service/nvdrv/nvdrv_interface.cpp index 39a4443a0..edbdfee43 100644 --- a/src/core/hle/service/nvdrv/nvdrv_interface.cpp +++ b/src/core/hle/service/nvdrv/nvdrv_interface.cpp @@ -27,7 +27,7 @@ void NVDRV::Open(Kernel::HLERequestContext& ctx) { return; } - const auto& buffer = ctx.ReadBufferSpan(); + const auto& buffer = ctx.ReadBuffer(); const std::string device_name(buffer.begin(), buffer.end()); if (device_name == "/dev/nvhost-prof-gpu") { @@ -64,7 +64,7 @@ void NVDRV::Ioctl1(Kernel::HLERequestContext& ctx) { // Check device std::vector output_buffer(ctx.GetWriteBufferSize(0)); - const auto input_buffer = ctx.ReadBufferSpan(0); + const auto input_buffer = ctx.ReadBuffer(0); const auto nv_result = nvdrv->Ioctl1(fd, command, input_buffer, output_buffer); if (command.is_out != 0) { @@ -88,8 +88,8 @@ void NVDRV::Ioctl2(Kernel::HLERequestContext& ctx) { return; } - const auto input_buffer = ctx.ReadBufferSpan(0); - const auto input_inlined_buffer = ctx.ReadBufferSpan(1); + const auto input_buffer = ctx.ReadBuffer(0); + const auto input_inlined_buffer = ctx.ReadBuffer(1); std::vector output_buffer(ctx.GetWriteBufferSize(0)); const auto nv_result = @@ -115,7 +115,7 @@ void NVDRV::Ioctl3(Kernel::HLERequestContext& ctx) { return; } - const auto input_buffer = ctx.ReadBufferSpan(0); + const auto input_buffer = ctx.ReadBuffer(0); std::vector output_buffer(ctx.GetWriteBufferSize(0)); std::vector output_buffer_inline(ctx.GetWriteBufferSize(1)); diff --git a/src/core/hle/service/nvflinger/buffer_queue_producer.cpp b/src/core/hle/service/nvflinger/buffer_queue_producer.cpp index abed92d06..bcbe05b0d 100644 --- a/src/core/hle/service/nvflinger/buffer_queue_producer.cpp +++ b/src/core/hle/service/nvflinger/buffer_queue_producer.cpp @@ -815,7 +815,7 @@ Status BufferQueueProducer::SetPreallocatedBuffer(s32 slot, void BufferQueueProducer::Transact(Kernel::HLERequestContext& ctx, TransactionId code, u32 flags) { Status status{Status::NoError}; - InputParcel parcel_in{ctx.ReadBufferSpan()}; + InputParcel parcel_in{ctx.ReadBuffer()}; OutputParcel parcel_out{}; switch (code) { diff --git a/src/core/hle/service/prepo/prepo.cpp b/src/core/hle/service/prepo/prepo.cpp index f6a141b2e..01040b32a 100644 --- a/src/core/hle/service/prepo/prepo.cpp +++ b/src/core/hle/service/prepo/prepo.cpp @@ -57,10 +57,10 @@ private: IPC::RequestParser rp{ctx}; const auto process_id = rp.PopRaw(); - const auto data1 = ctx.ReadBufferSpan(0); + const auto data1 = ctx.ReadBuffer(0); const auto data2 = [&ctx] { if (ctx.CanReadBuffer(1)) { - return ctx.ReadBufferSpan(1); + return ctx.ReadBuffer(1); } return std::span{}; @@ -84,10 +84,10 @@ private: const auto user_id = rp.PopRaw(); const auto process_id = rp.PopRaw(); - const auto data1 = ctx.ReadBufferSpan(0); + const auto data1 = ctx.ReadBuffer(0); const auto data2 = [&ctx] { if (ctx.CanReadBuffer(1)) { - return ctx.ReadBufferSpan(1); + return ctx.ReadBuffer(1); } return std::span{}; @@ -136,10 +136,10 @@ private: IPC::RequestParser rp{ctx}; const auto title_id = rp.PopRaw(); - const auto data1 = ctx.ReadBufferSpan(0); + const auto data1 = ctx.ReadBuffer(0); const auto data2 = [&ctx] { if (ctx.CanReadBuffer(1)) { - return ctx.ReadBufferSpan(1); + return ctx.ReadBuffer(1); } return std::span{}; @@ -160,10 +160,10 @@ private: const auto user_id = rp.PopRaw(); const auto title_id = rp.PopRaw(); - const auto data1 = ctx.ReadBufferSpan(0); + const auto data1 = ctx.ReadBuffer(0); const auto data2 = [&ctx] { if (ctx.CanReadBuffer(1)) { - return ctx.ReadBufferSpan(1); + return ctx.ReadBuffer(1); } return std::span{}; diff --git a/src/core/hle/service/set/set_sys.cpp b/src/core/hle/service/set/set_sys.cpp index f1ace8184..94c20edda 100644 --- a/src/core/hle/service/set/set_sys.cpp +++ b/src/core/hle/service/set/set_sys.cpp @@ -131,12 +131,12 @@ void SET_SYS::GetSettingsItemValueSize(Kernel::HLERequestContext& ctx) { // The category of the setting. This corresponds to the top-level keys of // system_settings.ini. - const auto setting_category_buf{ctx.ReadBufferSpan(0)}; + const auto setting_category_buf{ctx.ReadBuffer(0)}; const std::string setting_category{setting_category_buf.begin(), setting_category_buf.end()}; // The name of the setting. This corresponds to the second-level keys of // system_settings.ini. - const auto setting_name_buf{ctx.ReadBufferSpan(1)}; + const auto setting_name_buf{ctx.ReadBuffer(1)}; const std::string setting_name{setting_name_buf.begin(), setting_name_buf.end()}; auto settings{GetSettings()}; @@ -156,12 +156,12 @@ void SET_SYS::GetSettingsItemValue(Kernel::HLERequestContext& ctx) { // The category of the setting. This corresponds to the top-level keys of // system_settings.ini. - const auto setting_category_buf{ctx.ReadBufferSpan(0)}; + const auto setting_category_buf{ctx.ReadBuffer(0)}; const std::string setting_category{setting_category_buf.begin(), setting_category_buf.end()}; // The name of the setting. This corresponds to the second-level keys of // system_settings.ini. - const auto setting_name_buf{ctx.ReadBufferSpan(1)}; + const auto setting_name_buf{ctx.ReadBuffer(1)}; const std::string setting_name{setting_name_buf.begin(), setting_name_buf.end()}; auto settings{GetSettings()}; diff --git a/src/core/hle/service/sockets/bsd.cpp b/src/core/hle/service/sockets/bsd.cpp index 119d6ba5b..bdb499268 100644 --- a/src/core/hle/service/sockets/bsd.cpp +++ b/src/core/hle/service/sockets/bsd.cpp @@ -186,7 +186,7 @@ void BSD::Poll(Kernel::HLERequestContext& ctx) { ExecuteWork(ctx, PollWork{ .nfds = nfds, .timeout = timeout, - .read_buffer = ctx.ReadBufferSpan(), + .read_buffer = ctx.ReadBuffer(), .write_buffer = std::vector(ctx.GetWriteBufferSize()), }); } @@ -208,7 +208,7 @@ void BSD::Bind(Kernel::HLERequestContext& ctx) { const s32 fd = rp.Pop(); LOG_DEBUG(Service, "called. fd={} addrlen={}", fd, ctx.GetReadBufferSize()); - BuildErrnoResponse(ctx, BindImpl(fd, ctx.ReadBufferSpan())); + BuildErrnoResponse(ctx, BindImpl(fd, ctx.ReadBuffer())); } void BSD::Connect(Kernel::HLERequestContext& ctx) { @@ -219,7 +219,7 @@ void BSD::Connect(Kernel::HLERequestContext& ctx) { ExecuteWork(ctx, ConnectWork{ .fd = fd, - .addr = ctx.ReadBufferSpan(), + .addr = ctx.ReadBuffer(), }); } @@ -311,7 +311,7 @@ void BSD::SetSockOpt(Kernel::HLERequestContext& ctx) { const u32 level = rp.Pop(); const OptName optname = static_cast(rp.Pop()); - const auto buffer = ctx.ReadBufferSpan(); + const auto buffer = ctx.ReadBuffer(); const u8* optval = buffer.empty() ? nullptr : buffer.data(); size_t optlen = buffer.size(); @@ -382,7 +382,7 @@ void BSD::Send(Kernel::HLERequestContext& ctx) { ExecuteWork(ctx, SendWork{ .fd = fd, .flags = flags, - .message = ctx.ReadBufferSpan(), + .message = ctx.ReadBuffer(), }); } @@ -397,8 +397,8 @@ void BSD::SendTo(Kernel::HLERequestContext& ctx) { ExecuteWork(ctx, SendToWork{ .fd = fd, .flags = flags, - .message = ctx.ReadBufferSpan(0), - .addr = ctx.ReadBufferSpan(1), + .message = ctx.ReadBuffer(0), + .addr = ctx.ReadBuffer(1), }); } @@ -411,7 +411,7 @@ void BSD::Write(Kernel::HLERequestContext& ctx) { ExecuteWork(ctx, SendWork{ .fd = fd, .flags = 0, - .message = ctx.ReadBufferSpan(), + .message = ctx.ReadBuffer(), }); } diff --git a/src/core/hle/service/sockets/sfdnsres.cpp b/src/core/hle/service/sockets/sfdnsres.cpp index 6d0e1dd6c..e96eda7f3 100644 --- a/src/core/hle/service/sockets/sfdnsres.cpp +++ b/src/core/hle/service/sockets/sfdnsres.cpp @@ -199,10 +199,10 @@ static std::pair GetAddrInfoRequestImpl(Kernel::HLERequestContext& ctx "called with ignored parameters: use_nsd_resolve={}, unknown={}, process_id={}", parameters.use_nsd_resolve, parameters.unknown, parameters.process_id); - const auto host_buffer = ctx.ReadBufferSpan(0); + const auto host_buffer = ctx.ReadBuffer(0); const std::string host = Common::StringFromBuffer(host_buffer); - const auto service_buffer = ctx.ReadBufferSpan(1); + const auto service_buffer = ctx.ReadBuffer(1); const std::string service = Common::StringFromBuffer(service_buffer); addrinfo* addrinfo; diff --git a/src/core/hle/service/ssl/ssl.cpp b/src/core/hle/service/ssl/ssl.cpp index 10851f08f..dcf47083f 100644 --- a/src/core/hle/service/ssl/ssl.cpp +++ b/src/core/hle/service/ssl/ssl.cpp @@ -101,7 +101,7 @@ private: void ImportServerPki(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto certificate_format = rp.PopEnum(); - [[maybe_unused]] const auto pkcs_12_certificates = ctx.ReadBufferSpan(0); + [[maybe_unused]] const auto pkcs_12_certificates = ctx.ReadBuffer(0); constexpr u64 server_id = 0; @@ -113,10 +113,10 @@ private: } void ImportClientPki(Kernel::HLERequestContext& ctx) { - [[maybe_unused]] const auto pkcs_12_certificate = ctx.ReadBufferSpan(0); + [[maybe_unused]] const auto pkcs_12_certificate = ctx.ReadBuffer(0); [[maybe_unused]] const auto ascii_password = [&ctx] { if (ctx.CanReadBuffer(1)) { - return ctx.ReadBufferSpan(1); + return ctx.ReadBuffer(1); } return std::span{}; diff --git a/src/core/hle/service/time/time.cpp b/src/core/hle/service/time/time.cpp index 9376e0902..f77cdbb43 100644 --- a/src/core/hle/service/time/time.cpp +++ b/src/core/hle/service/time/time.cpp @@ -328,8 +328,8 @@ void Module::Interface::CalculateStandardUserSystemClockDifferenceByUser( Clock::ClockSnapshot snapshot_a; Clock::ClockSnapshot snapshot_b; - const auto snapshot_a_data = ctx.ReadBufferSpan(0); - const auto snapshot_b_data = ctx.ReadBufferSpan(1); + const auto snapshot_a_data = ctx.ReadBuffer(0); + const auto snapshot_b_data = ctx.ReadBuffer(1); std::memcpy(&snapshot_a, snapshot_a_data.data(), sizeof(Clock::ClockSnapshot)); std::memcpy(&snapshot_b, snapshot_b_data.data(), sizeof(Clock::ClockSnapshot)); @@ -355,8 +355,8 @@ void Module::Interface::CalculateSpanBetween(Kernel::HLERequestContext& ctx) { Clock::ClockSnapshot snapshot_a; Clock::ClockSnapshot snapshot_b; - const auto snapshot_a_data = ctx.ReadBufferSpan(0); - const auto snapshot_b_data = ctx.ReadBufferSpan(1); + const auto snapshot_a_data = ctx.ReadBuffer(0); + const auto snapshot_b_data = ctx.ReadBuffer(1); std::memcpy(&snapshot_a, snapshot_a_data.data(), sizeof(Clock::ClockSnapshot)); std::memcpy(&snapshot_b, snapshot_b_data.data(), sizeof(Clock::ClockSnapshot)); diff --git a/src/core/hle/service/time/time_zone_service.cpp b/src/core/hle/service/time/time_zone_service.cpp index 6d05a66f1..961040bfc 100644 --- a/src/core/hle/service/time/time_zone_service.cpp +++ b/src/core/hle/service/time/time_zone_service.cpp @@ -84,7 +84,7 @@ void ITimeZoneService::ToCalendarTime(Kernel::HLERequestContext& ctx) { LOG_DEBUG(Service_Time, "called, posix_time=0x{:016X}", posix_time); TimeZone::TimeZoneRule time_zone_rule{}; - const auto buffer{ctx.ReadBufferSpan()}; + const auto buffer{ctx.ReadBuffer()}; std::memcpy(&time_zone_rule, buffer.data(), buffer.size()); TimeZone::CalendarInfo calendar_info{}; @@ -128,7 +128,7 @@ void ITimeZoneService::ToPosixTime(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto calendar_time{rp.PopRaw()}; TimeZone::TimeZoneRule time_zone_rule{}; - std::memcpy(&time_zone_rule, ctx.ReadBufferSpan().data(), sizeof(TimeZone::TimeZoneRule)); + std::memcpy(&time_zone_rule, ctx.ReadBuffer().data(), sizeof(TimeZone::TimeZoneRule)); s64 posix_time{}; if (const Result result{time_zone_content_manager.GetTimeZoneManager().ToPosixTime( From b0722591c9b8c1aed5b8bfc5e67e7e957b08f209 Mon Sep 17 00:00:00 2001 From: ameerj <52414509+ameerj@users.noreply.github.com> Date: Wed, 28 Dec 2022 18:24:57 -0500 Subject: [PATCH 10/10] hle_ipc: Use thread_local ReadBuffer --- src/core/hle/kernel/hle_ipc.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp index f6654f56c..494151eef 100644 --- a/src/core/hle/kernel/hle_ipc.cpp +++ b/src/core/hle/kernel/hle_ipc.cpp @@ -11,6 +11,7 @@ #include "common/common_funcs.h" #include "common/common_types.h" #include "common/logging/log.h" +#include "common/scratch_buffer.h" #include "core/hle/ipc_helpers.h" #include "core/hle/kernel/hle_ipc.h" #include "core/hle/kernel/k_auto_object.h" @@ -346,20 +347,29 @@ std::vector HLERequestContext::ReadBufferCopy(std::size_t buffer_index) cons } std::span HLERequestContext::ReadBuffer(std::size_t buffer_index) const { + static thread_local std::array, 2> read_buffer_a; + static thread_local std::array, 2> read_buffer_x; + const bool is_buffer_a{BufferDescriptorA().size() > buffer_index && BufferDescriptorA()[buffer_index].Size()}; if (is_buffer_a) { ASSERT_OR_EXECUTE_MSG( BufferDescriptorA().size() > buffer_index, { return {}; }, "BufferDescriptorA invalid buffer_index {}", buffer_index); - const u8* const mem_ptr = memory.GetPointer(BufferDescriptorA()[buffer_index].Address()); - return std::span(mem_ptr, BufferDescriptorA()[buffer_index].Size()); + auto& read_buffer = read_buffer_a[buffer_index]; + read_buffer.resize_destructive(BufferDescriptorA()[buffer_index].Size()); + memory.ReadBlock(BufferDescriptorA()[buffer_index].Address(), read_buffer.data(), + read_buffer.size()); + return read_buffer; } else { ASSERT_OR_EXECUTE_MSG( BufferDescriptorX().size() > buffer_index, { return {}; }, "BufferDescriptorX invalid buffer_index {}", buffer_index); - const u8* const mem_ptr = memory.GetPointer(BufferDescriptorX()[buffer_index].Address()); - return std::span(mem_ptr, BufferDescriptorX()[buffer_index].Size()); + auto& read_buffer = read_buffer_x[buffer_index]; + read_buffer.resize_destructive(BufferDescriptorX()[buffer_index].Size()); + memory.ReadBlock(BufferDescriptorX()[buffer_index].Address(), read_buffer.data(), + read_buffer.size()); + return read_buffer; } }