From 8a9ddc30e0c0e5938ed5fe73306522db3046e45b Mon Sep 17 00:00:00 2001 From: yellows8 Date: Thu, 18 Feb 2021 19:25:59 -0500 Subject: [PATCH] uart.mitm: Abort on memalloc failure and adjust stack size. --- .../source/uart_mitm/uart_mitm_logger.cpp | 11 ++++---- .../source/uart_mitm/uart_mitm_service.cpp | 26 +++++++------------ 2 files changed, 15 insertions(+), 22 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 7eaac88d9..1bf444809 100644 --- a/stratosphere/ams_mitm/source/uart_mitm/uart_mitm_logger.cpp +++ b/stratosphere/ams_mitm/source/uart_mitm/uart_mitm_logger.cpp @@ -19,7 +19,7 @@ namespace ams::mitm::uart { - alignas(os::ThreadStackAlignment) u8 g_logger_stack[0x4000]; + alignas(os::ThreadStackAlignment) u8 g_logger_stack[0x1000]; std::shared_ptr g_logger; @@ -29,9 +29,8 @@ namespace ams::mitm::uart { std::memset(msg, 0, sizeof(UartLogMessage)); msg->data = static_cast(std::malloc(this->QueueBufferSize)); - if (msg->data != nullptr) { - std::memset(msg->data, 0, this->QueueBufferSize); - } + AMS_ABORT_UNLESS(msg->data != nullptr); + std::memset(msg->data, 0, this->QueueBufferSize); this->m_client_queue.Send(reinterpret_cast(msg)); } @@ -214,7 +213,7 @@ namespace ams::mitm::uart { UartLogMessage *msg=nullptr; this->m_client_queue.Receive(reinterpret_cast(&msg)); - if (msg->data == nullptr) return true; + AMS_ABORT_UNLESS(msg->data != nullptr); /* Setup the msg and send it. */ msg->type = 1; @@ -243,7 +242,7 @@ namespace ams::mitm::uart { UartLogMessage *msg=nullptr; this->m_client_queue.Receive(reinterpret_cast(&msg)); - if (msg->data == nullptr) return; + AMS_ABORT_UNLESS(msg->data != nullptr); /* Setup the msg and send it. */ msg->type = 2; 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 a357b4bf2..323a8076b 100644 --- a/stratosphere/ams_mitm/source/uart_mitm/uart_mitm_service.cpp +++ b/stratosphere/ams_mitm/source/uart_mitm/uart_mitm_service.cpp @@ -67,28 +67,22 @@ namespace ams::mitm::uart { /* Initialize the Send cache-buffer. */ this->m_send_cache_buffer = static_cast(std::malloc(this->CacheBufferSize)); - if (this->m_send_cache_buffer != nullptr) { - std::memset(this->m_send_cache_buffer, 0, this->CacheBufferSize); - } + AMS_ABORT_UNLESS(this->m_send_cache_buffer != nullptr); + std::memset(this->m_send_cache_buffer, 0, this->CacheBufferSize); this->m_send_cache_pos = 0; /* Initialize the Receive cache-buffer. */ this->m_receive_cache_buffer = static_cast(std::malloc(this->CacheBufferSize)); - if (this->m_receive_cache_buffer != nullptr) { - std::memset(this->m_receive_cache_buffer, 0, this->CacheBufferSize); - } + AMS_ABORT_UNLESS(this->m_receive_cache_buffer != nullptr); + std::memset(this->m_receive_cache_buffer, 0, this->CacheBufferSize); this->m_receive_cache_pos = 0; - this->m_datalog_ready = false; - - /* When the above is successful, initialize the datalog. */ - if (this->m_send_cache_buffer != nullptr && this->m_receive_cache_buffer != nullptr) { - std::snprintf(tmp_path, sizeof(tmp_path), "%s/%s", this->m_base_path, "btsnoop_hci.log"); - ams::mitm::fs::CreateAtmosphereSdFile(tmp_path, 0, 0); - rc = ams::mitm::fs::OpenAtmosphereSdFile(&this->m_datalog_file, tmp_path, FsOpenMode_Read | FsOpenMode_Write | FsOpenMode_Append); - /* Set datalog_ready to whether initialization was successful. */ - this->m_datalog_ready = R_SUCCEEDED(rc); - } + /* Initialize the datalog. */ + std::snprintf(tmp_path, sizeof(tmp_path), "%s/%s", this->m_base_path, "btsnoop_hci.log"); + ams::mitm::fs::CreateAtmosphereSdFile(tmp_path, 0, 0); + rc = ams::mitm::fs::OpenAtmosphereSdFile(&this->m_datalog_file, tmp_path, FsOpenMode_Read | FsOpenMode_Write | FsOpenMode_Append); + /* Set datalog_ready to whether initialization was successful. */ + this->m_datalog_ready = R_SUCCEEDED(rc); if (this->m_datalog_ready) { std::shared_ptr logger = mitm::uart::g_logger;