diff options
author | liamwhite <liamwhite@users.noreply.github.com> | 2023-07-02 04:38:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-02 04:38:18 +0200 |
commit | 971b89b979cb3b903263234f3a6fdd2bceb03cbe (patch) | |
tree | d32c8012765d9d94c57292ddfac3f84ec247a6e1 /src/core/hle/service | |
parent | Merge pull request #10966 from Morph1984/heap-corruption (diff) | |
parent | parcel: Optimize small_vector sizes (diff) | |
download | yuzu-971b89b979cb3b903263234f3a6fdd2bceb03cbe.tar yuzu-971b89b979cb3b903263234f3a6fdd2bceb03cbe.tar.gz yuzu-971b89b979cb3b903263234f3a6fdd2bceb03cbe.tar.bz2 yuzu-971b89b979cb3b903263234f3a6fdd2bceb03cbe.tar.lz yuzu-971b89b979cb3b903263234f3a6fdd2bceb03cbe.tar.xz yuzu-971b89b979cb3b903263234f3a6fdd2bceb03cbe.tar.zst yuzu-971b89b979cb3b903263234f3a6fdd2bceb03cbe.zip |
Diffstat (limited to '')
-rw-r--r-- | src/core/hle/service/audio/audin_u.cpp | 16 | ||||
-rw-r--r-- | src/core/hle/service/audio/audout_u.cpp | 20 | ||||
-rw-r--r-- | src/core/hle/service/audio/audren_u.cpp | 23 | ||||
-rw-r--r-- | src/core/hle/service/audio/hwopus.cpp | 9 | ||||
-rw-r--r-- | src/core/hle/service/nvdrv/nvdrv_interface.cpp | 25 | ||||
-rw-r--r-- | src/core/hle/service/nvdrv/nvdrv_interface.h | 5 | ||||
-rw-r--r-- | src/core/hle/service/nvnflinger/parcel.h | 24 |
7 files changed, 66 insertions, 56 deletions
diff --git a/src/core/hle/service/audio/audin_u.cpp b/src/core/hle/service/audio/audin_u.cpp index c8d574993..526a39130 100644 --- a/src/core/hle/service/audio/audin_u.cpp +++ b/src/core/hle/service/audio/audin_u.cpp @@ -5,7 +5,7 @@ #include "audio_core/renderer/audio_device.h" #include "common/common_funcs.h" #include "common/logging/log.h" -#include "common/settings.h" +#include "common/scratch_buffer.h" #include "common/string_util.h" #include "core/core.h" #include "core/hle/kernel/k_event.h" @@ -124,12 +124,15 @@ private: void GetReleasedAudioInBuffer(HLERequestContext& ctx) { const auto write_buffer_size = ctx.GetWriteBufferNumElements<u64>(); - tmp_buffer.resize_destructive(write_buffer_size); - tmp_buffer[0] = 0; + released_buffer.resize_destructive(write_buffer_size); + released_buffer[0] = 0; - const auto count = impl->GetReleasedBuffers(tmp_buffer); + const auto count = impl->GetReleasedBuffers(released_buffer); - ctx.WriteBuffer(tmp_buffer); + LOG_TRACE(Service_Audio, "called. Session {} released {} buffers", + impl->GetSystem().GetSessionId(), count); + + ctx.WriteBuffer(released_buffer); IPC::ResponseBuilder rb{ctx, 3}; rb.Push(ResultSuccess); @@ -155,7 +158,6 @@ private: LOG_DEBUG(Service_Audio, "called. Buffer count={}", buffer_count); IPC::ResponseBuilder rb{ctx, 3}; - rb.Push(ResultSuccess); rb.Push(buffer_count); } @@ -195,7 +197,7 @@ private: KernelHelpers::ServiceContext service_context; Kernel::KEvent* event; std::shared_ptr<AudioCore::AudioIn::In> impl; - Common::ScratchBuffer<u64> tmp_buffer; + Common::ScratchBuffer<u64> released_buffer; }; AudInU::AudInU(Core::System& system_) diff --git a/src/core/hle/service/audio/audout_u.cpp b/src/core/hle/service/audio/audout_u.cpp index 032c8c11f..23f84a29f 100644 --- a/src/core/hle/service/audio/audout_u.cpp +++ b/src/core/hle/service/audio/audout_u.cpp @@ -9,6 +9,7 @@ #include "audio_core/renderer/audio_device.h" #include "common/common_funcs.h" #include "common/logging/log.h" +#include "common/scratch_buffer.h" #include "common/string_util.h" #include "common/swap.h" #include "core/core.h" @@ -102,8 +103,8 @@ private: AudioOutBuffer buffer{}; std::memcpy(&buffer, in_buffer.data(), sizeof(AudioOutBuffer)); - [[maybe_unused]] auto sessionid{impl->GetSystem().GetSessionId()}; - LOG_TRACE(Service_Audio, "called. Session {} Appending buffer {:08X}", sessionid, tag); + LOG_TRACE(Service_Audio, "called. Session {} Appending buffer {:08X}", + impl->GetSystem().GetSessionId(), tag); auto result = impl->AppendBuffer(buffer, tag); @@ -123,12 +124,15 @@ private: void GetReleasedAudioOutBuffers(HLERequestContext& ctx) { const auto write_buffer_size = ctx.GetWriteBufferNumElements<u64>(); - tmp_buffer.resize_destructive(write_buffer_size); - tmp_buffer[0] = 0; + released_buffer.resize_destructive(write_buffer_size); + released_buffer[0] = 0; - const auto count = impl->GetReleasedBuffers(tmp_buffer); + const auto count = impl->GetReleasedBuffers(released_buffer); - ctx.WriteBuffer(tmp_buffer); + ctx.WriteBuffer(released_buffer); + + LOG_TRACE(Service_Audio, "called. Session {} released {} buffers", + impl->GetSystem().GetSessionId(), count); IPC::ResponseBuilder rb{ctx, 3}; rb.Push(ResultSuccess); @@ -154,7 +158,6 @@ private: LOG_DEBUG(Service_Audio, "called. Buffer count={}", buffer_count); IPC::ResponseBuilder rb{ctx, 3}; - rb.Push(ResultSuccess); rb.Push(buffer_count); } @@ -165,7 +168,6 @@ private: LOG_DEBUG(Service_Audio, "called. Played samples={}", samples_played); IPC::ResponseBuilder rb{ctx, 4}; - rb.Push(ResultSuccess); rb.Push(samples_played); } @@ -205,7 +207,7 @@ private: KernelHelpers::ServiceContext service_context; Kernel::KEvent* event; std::shared_ptr<AudioCore::AudioOut::Out> impl; - Common::ScratchBuffer<u64> tmp_buffer; + Common::ScratchBuffer<u64> released_buffer; }; AudOutU::AudOutU(Core::System& system_) diff --git a/src/core/hle/service/audio/audren_u.cpp b/src/core/hle/service/audio/audren_u.cpp index 12845c23a..003870176 100644 --- a/src/core/hle/service/audio/audren_u.cpp +++ b/src/core/hle/service/audio/audren_u.cpp @@ -15,6 +15,7 @@ #include "common/common_funcs.h" #include "common/logging/log.h" #include "common/polyfill_ranges.h" +#include "common/scratch_buffer.h" #include "common/string_util.h" #include "core/core.h" #include "core/hle/kernel/k_event.h" @@ -119,23 +120,23 @@ private: auto is_buffer_b{ctx.BufferDescriptorB()[0].Size() != 0}; if (is_buffer_b) { const auto buffersB{ctx.BufferDescriptorB()}; - tmp_output.resize_destructive(buffersB[0].Size()); - tmp_performance.resize_destructive(buffersB[1].Size()); + output_buffer.resize_destructive(buffersB[0].Size()); + performance_buffer.resize_destructive(buffersB[1].Size()); } else { const auto buffersC{ctx.BufferDescriptorC()}; - tmp_output.resize_destructive(buffersC[0].Size()); - tmp_performance.resize_destructive(buffersC[1].Size()); + output_buffer.resize_destructive(buffersC[0].Size()); + performance_buffer.resize_destructive(buffersC[1].Size()); } - auto result = impl->RequestUpdate(input, tmp_performance, tmp_output); + auto result = impl->RequestUpdate(input, performance_buffer, output_buffer); if (result.IsSuccess()) { if (is_buffer_b) { - ctx.WriteBufferB(tmp_output.data(), tmp_output.size(), 0); - ctx.WriteBufferB(tmp_performance.data(), tmp_performance.size(), 1); + ctx.WriteBufferB(output_buffer.data(), output_buffer.size(), 0); + ctx.WriteBufferB(performance_buffer.data(), performance_buffer.size(), 1); } else { - ctx.WriteBufferC(tmp_output.data(), tmp_output.size(), 0); - ctx.WriteBufferC(tmp_performance.data(), tmp_performance.size(), 1); + ctx.WriteBufferC(output_buffer.data(), output_buffer.size(), 0); + ctx.WriteBufferC(performance_buffer.data(), performance_buffer.size(), 1); } } else { LOG_ERROR(Service_Audio, "RequestUpdate failed error 0x{:02X}!", result.description); @@ -233,8 +234,8 @@ private: Kernel::KEvent* rendered_event; Manager& manager; std::unique_ptr<Renderer> impl; - Common::ScratchBuffer<u8> tmp_output; - Common::ScratchBuffer<u8> tmp_performance; + Common::ScratchBuffer<u8> output_buffer; + Common::ScratchBuffer<u8> performance_buffer; }; class IAudioDevice final : public ServiceFramework<IAudioDevice> { diff --git a/src/core/hle/service/audio/hwopus.cpp b/src/core/hle/service/audio/hwopus.cpp index c835f6cb7..fa77007f3 100644 --- a/src/core/hle/service/audio/hwopus.cpp +++ b/src/core/hle/service/audio/hwopus.cpp @@ -11,6 +11,7 @@ #include "common/assert.h" #include "common/logging/log.h" +#include "common/scratch_buffer.h" #include "core/hle/service/audio/hwopus.h" #include "core/hle/service/ipc_helpers.h" @@ -68,13 +69,13 @@ private: ExtraBehavior extra_behavior) { u32 consumed = 0; u32 sample_count = 0; - tmp_samples.resize_destructive(ctx.GetWriteBufferNumElements<opus_int16>()); + samples.resize_destructive(ctx.GetWriteBufferNumElements<opus_int16>()); if (extra_behavior == ExtraBehavior::ResetContext) { ResetDecoderContext(); } - if (!DecodeOpusData(consumed, sample_count, ctx.ReadBuffer(), tmp_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 @@ -90,7 +91,7 @@ private: if (performance) { rb.Push<u64>(*performance); } - ctx.WriteBuffer(tmp_samples); + ctx.WriteBuffer(samples); } bool DecodeOpusData(u32& consumed, u32& sample_count, std::span<const u8> input, @@ -154,7 +155,7 @@ private: OpusDecoderPtr decoder; u32 sample_rate; u32 channel_count; - Common::ScratchBuffer<opus_int16> tmp_samples; + Common::ScratchBuffer<opus_int16> samples; }; class IHardwareOpusDecoderManager final : public ServiceFramework<IHardwareOpusDecoderManager> { diff --git a/src/core/hle/service/nvdrv/nvdrv_interface.cpp b/src/core/hle/service/nvdrv/nvdrv_interface.cpp index 348207e25..c8a880e84 100644 --- a/src/core/hle/service/nvdrv/nvdrv_interface.cpp +++ b/src/core/hle/service/nvdrv/nvdrv_interface.cpp @@ -2,7 +2,6 @@ // SPDX-FileCopyrightText: 2021 Skyline Team and Contributors // SPDX-License-Identifier: GPL-3.0-or-later -#include <cinttypes> #include "common/logging/log.h" #include "core/core.h" #include "core/hle/kernel/k_event.h" @@ -63,12 +62,12 @@ void NVDRV::Ioctl1(HLERequestContext& ctx) { } // Check device - tmp_output.resize_destructive(ctx.GetWriteBufferSize(0)); + output_buffer.resize_destructive(ctx.GetWriteBufferSize(0)); const auto input_buffer = ctx.ReadBuffer(0); - const auto nv_result = nvdrv->Ioctl1(fd, command, input_buffer, tmp_output); + const auto nv_result = nvdrv->Ioctl1(fd, command, input_buffer, output_buffer); if (command.is_out != 0) { - ctx.WriteBuffer(tmp_output); + ctx.WriteBuffer(output_buffer); } IPC::ResponseBuilder rb{ctx, 3}; @@ -90,12 +89,12 @@ void NVDRV::Ioctl2(HLERequestContext& ctx) { const auto input_buffer = ctx.ReadBuffer(0); const auto input_inlined_buffer = ctx.ReadBuffer(1); - tmp_output.resize_destructive(ctx.GetWriteBufferSize(0)); + output_buffer.resize_destructive(ctx.GetWriteBufferSize(0)); const auto nv_result = - nvdrv->Ioctl2(fd, command, input_buffer, input_inlined_buffer, tmp_output); + nvdrv->Ioctl2(fd, command, input_buffer, input_inlined_buffer, output_buffer); if (command.is_out != 0) { - ctx.WriteBuffer(tmp_output); + ctx.WriteBuffer(output_buffer); } IPC::ResponseBuilder rb{ctx, 3}; @@ -116,12 +115,14 @@ void NVDRV::Ioctl3(HLERequestContext& ctx) { } const auto input_buffer = ctx.ReadBuffer(0); - tmp_output.resize_destructive(ctx.GetWriteBufferSize(0)); - tmp_output_inline.resize_destructive(ctx.GetWriteBufferSize(1)); - const auto nv_result = nvdrv->Ioctl3(fd, command, input_buffer, tmp_output, tmp_output_inline); + output_buffer.resize_destructive(ctx.GetWriteBufferSize(0)); + inline_output_buffer.resize_destructive(ctx.GetWriteBufferSize(1)); + + const auto nv_result = + nvdrv->Ioctl3(fd, command, input_buffer, output_buffer, inline_output_buffer); if (command.is_out != 0) { - ctx.WriteBuffer(tmp_output, 0); - ctx.WriteBuffer(tmp_output_inline, 1); + ctx.WriteBuffer(output_buffer, 0); + ctx.WriteBuffer(inline_output_buffer, 1); } IPC::ResponseBuilder rb{ctx, 3}; diff --git a/src/core/hle/service/nvdrv/nvdrv_interface.h b/src/core/hle/service/nvdrv/nvdrv_interface.h index 4b593ff90..6e98115dc 100644 --- a/src/core/hle/service/nvdrv/nvdrv_interface.h +++ b/src/core/hle/service/nvdrv/nvdrv_interface.h @@ -4,6 +4,7 @@ #pragma once #include <memory> + #include "common/scratch_buffer.h" #include "core/hle/service/nvdrv/nvdrv.h" #include "core/hle/service/service.h" @@ -34,8 +35,8 @@ private: u64 pid{}; bool is_initialized{}; - Common::ScratchBuffer<u8> tmp_output; - Common::ScratchBuffer<u8> tmp_output_inline; + Common::ScratchBuffer<u8> output_buffer; + Common::ScratchBuffer<u8> inline_output_buffer; }; } // namespace Service::Nvidia diff --git a/src/core/hle/service/nvnflinger/parcel.h b/src/core/hle/service/nvnflinger/parcel.h index 23ba315a0..e2c9bbd50 100644 --- a/src/core/hle/service/nvnflinger/parcel.h +++ b/src/core/hle/service/nvnflinger/parcel.h @@ -6,6 +6,7 @@ #include <memory> #include <span> #include <vector> + #include <boost/container/small_vector.hpp> #include "common/alignment.h" @@ -148,9 +149,9 @@ public: this->WriteImpl(0U, m_object_buffer); } - std::vector<u8> Serialize() const { - std::vector<u8> output_buffer(sizeof(ParcelHeader) + m_data_buffer.size() + - m_object_buffer.size()); + std::span<u8> Serialize() { + m_output_buffer.resize(sizeof(ParcelHeader) + m_data_buffer.size() + + m_object_buffer.size()); ParcelHeader header{}; header.data_size = static_cast<u32>(m_data_buffer.size()); @@ -158,17 +159,17 @@ public: header.objects_size = static_cast<u32>(m_object_buffer.size()); header.objects_offset = header.data_offset + header.data_size; - std::memcpy(output_buffer.data(), &header, sizeof(header)); - std::ranges::copy(m_data_buffer, output_buffer.data() + header.data_offset); - std::ranges::copy(m_object_buffer, output_buffer.data() + header.objects_offset); + std::memcpy(m_output_buffer.data(), &header, sizeof(ParcelHeader)); + std::ranges::copy(m_data_buffer, m_output_buffer.data() + header.data_offset); + std::ranges::copy(m_object_buffer, m_output_buffer.data() + header.objects_offset); - return output_buffer; + return m_output_buffer; } private: - template <typename T> + template <typename T, size_t BufferSize> requires(std::is_trivially_copyable_v<T>) - void WriteImpl(const T& val, boost::container::small_vector<u8, 0x200>& buffer) { + void WriteImpl(const T& val, boost::container::small_vector<u8, BufferSize>& buffer) { const size_t aligned_size = Common::AlignUp(sizeof(T), 4); const size_t old_size = buffer.size(); buffer.resize(old_size + aligned_size); @@ -177,8 +178,9 @@ private: } private: - boost::container::small_vector<u8, 0x200> m_data_buffer; - boost::container::small_vector<u8, 0x200> m_object_buffer; + boost::container::small_vector<u8, 0x1B0> m_data_buffer; + boost::container::small_vector<u8, 0x40> m_object_buffer; + boost::container::small_vector<u8, 0x200> m_output_buffer; }; } // namespace Service::android |