1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-11-08 05:01:44 +00:00

uart.mitm: Abort on memalloc failure and adjust stack size.

This commit is contained in:
yellows8 2021-02-18 19:25:59 -05:00
parent 4cb8034ac8
commit 8a9ddc30e0
No known key found for this signature in database
GPG key ID: 0AF90DA3F1E60E43
2 changed files with 15 additions and 22 deletions

View file

@ -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<UartLogger> g_logger;
@ -29,9 +29,8 @@ namespace ams::mitm::uart {
std::memset(msg, 0, sizeof(UartLogMessage));
msg->data = static_cast<u8 *>(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<uintptr_t>(msg));
}
@ -214,7 +213,7 @@ namespace ams::mitm::uart {
UartLogMessage *msg=nullptr;
this->m_client_queue.Receive(reinterpret_cast<uintptr_t *>(&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<uintptr_t *>(&msg));
if (msg->data == nullptr) return;
AMS_ABORT_UNLESS(msg->data != nullptr);
/* Setup the msg and send it. */
msg->type = 2;

View file

@ -67,28 +67,22 @@ namespace ams::mitm::uart {
/* Initialize the Send cache-buffer. */
this->m_send_cache_buffer = static_cast<u8 *>(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<u8 *>(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<UartLogger> logger = mitm::uart::g_logger;