From 4cb8034ac8e116e7e45a892d25bee8352cdf0045 Mon Sep 17 00:00:00 2001 From: yellows8 Date: Thu, 18 Feb 2021 14:36:21 -0500 Subject: [PATCH] uart.mitm: Log when the data for SendLogData is too large. --- .../ams_mitm/source/uart_mitm/uart_mitm_logger.cpp | 7 ++++--- .../ams_mitm/source/uart_mitm/uart_mitm_logger.hpp | 2 +- .../ams_mitm/source/uart_mitm/uart_mitm_service.cpp | 6 +++++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/stratosphere/ams_mitm/source/uart_mitm/uart_mitm_logger.cpp b/stratosphere/ams_mitm/source/uart_mitm/uart_mitm_logger.cpp index 9341c8cac..7eaac88d9 100644 --- a/stratosphere/ams_mitm/source/uart_mitm/uart_mitm_logger.cpp +++ b/stratosphere/ams_mitm/source/uart_mitm/uart_mitm_logger.cpp @@ -208,13 +208,13 @@ namespace ams::mitm::uart { /* Send the specified data to the Logger thread. */ /* dir: false = Send (host->controller), true = Receive (controller->host). */ - void UartLogger::SendLogData(FsFile *f, size_t *file_pos, s64 timestamp_base, s64 tick_base, bool dir, const void* buffer, size_t size) { + bool UartLogger::SendLogData(FsFile *f, size_t *file_pos, s64 timestamp_base, s64 tick_base, bool dir, const void* buffer, size_t size) { /* Ignore log data which is too large. */ - if (size > this->QueueBufferSize) return; + if (size > this->QueueBufferSize) return false; UartLogMessage *msg=nullptr; this->m_client_queue.Receive(reinterpret_cast(&msg)); - if (msg->data == nullptr) return; + if (msg->data == nullptr) return true; /* Setup the msg and send it. */ msg->type = 1; @@ -233,6 +233,7 @@ namespace ams::mitm::uart { this->m_finish_event.Clear(); this->m_thread_queue.Send(reinterpret_cast(msg)); this->m_request_event.Signal(); + return true; } /* Send the specified text log to the Logger thread. */ diff --git a/stratosphere/ams_mitm/source/uart_mitm/uart_mitm_logger.hpp b/stratosphere/ams_mitm/source/uart_mitm/uart_mitm_logger.hpp index 4aea59fa5..138010af5 100644 --- a/stratosphere/ams_mitm/source/uart_mitm/uart_mitm_logger.hpp +++ b/stratosphere/ams_mitm/source/uart_mitm/uart_mitm_logger.hpp @@ -67,7 +67,7 @@ namespace ams::mitm::uart { void InitializeDataLog(FsFile *f, size_t *datalog_pos); - void SendLogData(FsFile *f, size_t *file_pos, s64 timestamp_base, s64 tick_base, bool dir, const void* buffer, size_t size); + bool SendLogData(FsFile *f, size_t *file_pos, s64 timestamp_base, s64 tick_base, bool dir, const void* buffer, size_t size); void SendTextLogData(const char *path, size_t *file_pos, const char *str); }; diff --git a/stratosphere/ams_mitm/source/uart_mitm/uart_mitm_service.cpp b/stratosphere/ams_mitm/source/uart_mitm/uart_mitm_service.cpp index 776c8e4a0..a357b4bf2 100644 --- a/stratosphere/ams_mitm/source/uart_mitm/uart_mitm_service.cpp +++ b/stratosphere/ams_mitm/source/uart_mitm/uart_mitm_service.cpp @@ -211,7 +211,11 @@ namespace ams::mitm::uart { /* Only write to the file if data-logging is enabled and initialized. */ if (this->m_data_logging_enabled && this->m_datalog_ready) { std::shared_ptr logger = mitm::uart::g_logger; - logger->SendLogData(&this->m_datalog_file, &this->m_datalog_pos, this->m_timestamp_base, this->m_tick_base, dir, cache_buffer, pkt_len); + if (!logger->SendLogData(&this->m_datalog_file, &this->m_datalog_pos, this->m_timestamp_base, this->m_tick_base, dir, cache_buffer, pkt_len)) { + char str[256]; + std::snprintf(str, sizeof(str), "WriteUartData(): SendLogData dropped packet with size = 0x%lx\n", pkt_len); + this->WriteCmdLog(str); + } } (*cache_pos)-= pkt_len; if (*cache_pos) {