BBA/HLE: Fix random PCAP file corruption

Concurrency between RecvHandlePacket and SendFromDirectFIFO
This commit is contained in:
Sepalani 2023-11-19 01:17:46 +04:00
parent aa1311cd78
commit 91020ac4fa
3 changed files with 6 additions and 0 deletions

View File

@ -49,6 +49,7 @@ void PCAP::AddHeader(u32 link_type)
m_fp->WriteBytes(&hdr, sizeof(hdr));
}
// Not thread-safe, concurrency between multiple calls to IOFile::WriteBytes.
void PCAP::AddPacket(const u8* bytes, size_t size)
{
std::chrono::system_clock::time_point now(std::chrono::system_clock::now());

View File

@ -123,6 +123,9 @@ void PCAPSSLCaptureLogger::LogBBA(const void* data, std::size_t length)
{
if (!Config::Get(Config::MAIN_NETWORK_DUMP_BBA))
return;
// Concurrency between CEXIETHERNET's RecvHandlePacket and SendFromDirectFIFO
const std::lock_guard lock(m_io_mutex);
m_file->AddPacket(static_cast<const u8*>(data), length);
}

View File

@ -7,6 +7,7 @@
#include <cstddef>
#include <map>
#include <memory>
#include <mutex>
#ifdef _WIN32
#include <WinSock2.h>
@ -111,6 +112,7 @@ private:
const sockaddr_in& to);
std::unique_ptr<Common::PCAP> m_file;
std::mutex m_io_mutex;
std::map<s32, u32> m_read_sequence_number;
std::map<s32, u32> m_write_sequence_number;
};