From c71134c4ab9839ff55beb3c17a3b9d920a7be47d Mon Sep 17 00:00:00 2001 From: Sepalani Date: Sat, 3 Feb 2024 14:52:04 +0400 Subject: [PATCH] BBA/HLE: Check queue overrun --- Source/Core/Core/HW/EXI/BBA/BuiltIn.cpp | 14 +++++++++++--- Source/Core/Core/HW/EXI/EXI_DeviceEthernet.h | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Source/Core/Core/HW/EXI/BBA/BuiltIn.cpp b/Source/Core/Core/HW/EXI/BBA/BuiltIn.cpp index 733053b6a6..47044c4c9e 100644 --- a/Source/Core/Core/HW/EXI/BBA/BuiltIn.cpp +++ b/Source/Core/Core/HW/EXI/BBA/BuiltIn.cpp @@ -126,6 +126,13 @@ void CEXIETHERNET::BuiltInBBAInterface::WriteToQueue(const std::vector& data const u8 next_write_index = (m_queue_write + 1) & 15; if (next_write_index != m_queue_read) m_queue_write = next_write_index; + else + WARN_LOG_FMT(SP1, "BBA queue overrun, data might be lost"); +} + +bool CEXIETHERNET::BuiltInBBAInterface::WillQueueOverrun() const +{ + return ((m_queue_write + 1) & 15) == m_queue_read; } void CEXIETHERNET::BuiltInBBAInterface::PollData(std::size_t* datasize) @@ -140,13 +147,14 @@ void CEXIETHERNET::BuiltInBBAInterface::PollData(std::size_t* datasize) { for (auto& tcp_buf : net_ref.tcp_buffers) { + if (WillQueueOverrun()) + break; if (!tcp_buf.used || (GetTickCountStd() - tcp_buf.tick) <= 1000) continue; - tcp_buf.tick = GetTickCountStd(); // Timed out packet, resend - if (((m_queue_write + 1) & 15) != m_queue_read) - WriteToQueue(tcp_buf.data); + tcp_buf.tick = GetTickCountStd(); + WriteToQueue(tcp_buf.data); } } diff --git a/Source/Core/Core/HW/EXI/EXI_DeviceEthernet.h b/Source/Core/Core/HW/EXI/EXI_DeviceEthernet.h index 094487c9e9..e432056038 100644 --- a/Source/Core/Core/HW/EXI/EXI_DeviceEthernet.h +++ b/Source/Core/Core/HW/EXI/EXI_DeviceEthernet.h @@ -463,6 +463,7 @@ private: static void ReadThreadHandler(BuiltInBBAInterface* self); #endif void WriteToQueue(const std::vector& data); + bool WillQueueOverrun() const; void PollData(std::size_t* datasize); std::optional> TryGetDataFromSocket(StackRef* ref);