More requested changes

This commit is contained in:
XorTroll 2021-02-09 01:06:30 +01:00
commit 35f21a95fd
20 changed files with 77 additions and 73 deletions

View file

@ -15,7 +15,4 @@
*/ */
#pragma once #pragma once
#include <stratosphere/diag/diag_log_observer.hpp>
#include <stratosphere/diag/diag_log_types.hpp> #include <stratosphere/diag/diag_log_types.hpp>
#include <stratosphere/diag/detail/diag_detail_log.hpp>
#include <stratosphere/diag/detail/diag_detail_string.hpp>

View file

@ -16,7 +16,7 @@
#pragma once #pragma once
#include <stratosphere/diag/diag_log_types.hpp> #include <stratosphere/diag/diag_log_types.hpp>
namespace ams::diag::detail { namespace ams::diag::impl {
void LogImpl(const LogMetaData &log_metadata, const char *fmt, ...) __attribute__((format(printf, 2, 3))); void LogImpl(const LogMetaData &log_metadata, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
void VLogImpl(const LogMetaData &log_metadata, const char *fmt, std::va_list vl); void VLogImpl(const LogMetaData &log_metadata, const char *fmt, std::va_list vl);
@ -31,7 +31,7 @@ namespace ams::diag::detail {
}, \ }, \
.log_severity = ::ams::diag::LogSeverity_Info \ .log_severity = ::ams::diag::LogSeverity_Info \
}; \ }; \
::ams::diag::detail::LogImpl(log_metadata, fmt, __VA_ARGS__); \ ::ams::diag::impl::LogImpl(log_metadata, fmt, __VA_ARGS__); \
}) })
} }

View file

@ -16,9 +16,9 @@
#pragma once #pragma once
#include <vapours.hpp> #include <vapours.hpp>
namespace ams::diag::detail { namespace ams::diag::impl {
void PrintDebugString(const char *str, size_t len); void PrintDebugString(const char *str, size_t len);
ssize_t GetValidSizeAsUtf8String(const char *str, size_t len); int GetValidSizeAsUtf8String(const char *str, int len);
} }

View file

@ -17,5 +17,5 @@
#pragma once #pragma once
#include <vapours.hpp> #include <vapours.hpp>
#include <stratosphere/lm/lm_api.hpp> #include <stratosphere/lm/lm_api.hpp>
#include <stratosphere/lm/detail/lm_detail_log_types.hpp> #include <stratosphere/lm/impl/lm_impl_log_types.hpp>
#include <stratosphere/lm/detail/lm_detail_log_packet_transmitter.hpp> #include <stratosphere/lm/impl/lm_impl_log_packet_transmitter.hpp>

View file

@ -14,9 +14,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include <stratosphere/lm/detail/lm_detail_log_types.hpp> #include <stratosphere/lm/impl/lm_impl_log_types.hpp>
namespace ams::lm::detail { namespace ams::lm::impl {
class LogPacketTransmitterBase { class LogPacketTransmitterBase {
NON_COPYABLE(LogPacketTransmitterBase); NON_COPYABLE(LogPacketTransmitterBase);

View file

@ -16,7 +16,7 @@
#pragma once #pragma once
#include <stratosphere/diag/diag_log_types.hpp> #include <stratosphere/diag/diag_log_types.hpp>
namespace ams::lm::detail { namespace ams::lm::impl {
enum LogPacketFlags { enum LogPacketFlags {
LogPacketFlags_Head = (1 << 0), LogPacketFlags_Head = (1 << 0),

View file

@ -14,10 +14,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <stratosphere.hpp> #include <stratosphere.hpp>
#include <stratosphere/diag/diag_log_observer.hpp>
namespace ams::diag { namespace ams::diag {
namespace detail { namespace impl {
extern LogObserverHolder g_default_log_observer; extern LogObserverHolder g_default_log_observer;
extern LogObserverHolder *g_log_observer_list_head; extern LogObserverHolder *g_log_observer_list_head;
@ -36,9 +37,9 @@ namespace ams::diag {
void RegisterLogObserver(LogObserverHolder *observer_holder) { void RegisterLogObserver(LogObserverHolder *observer_holder) {
AMS_ASSERT(!observer_holder->is_registered); AMS_ASSERT(!observer_holder->is_registered);
if (detail::g_log_observer_list_head) { if (impl::g_log_observer_list_head) {
/* Find the last registered observer and append this one. */ /* Find the last registered observer and append this one. */
auto observer = detail::g_log_observer_list_head; auto observer = impl::g_log_observer_list_head;
LogObserverHolder *observer_parent = nullptr; LogObserverHolder *observer_parent = nullptr;
do { do {
observer_parent = observer; observer_parent = observer;
@ -48,7 +49,7 @@ namespace ams::diag {
} }
else { else {
/* There are no observers yet, this will be the first one. */ /* There are no observers yet, this will be the first one. */
detail::g_log_observer_list_head = observer_holder; impl::g_log_observer_list_head = observer_holder;
} }
observer_holder->is_registered = true; observer_holder->is_registered = true;
observer_holder->next = nullptr; observer_holder->next = nullptr;
@ -57,13 +58,13 @@ namespace ams::diag {
void UnregisterLogObserver(LogObserverHolder *observer_holder) { void UnregisterLogObserver(LogObserverHolder *observer_holder) {
AMS_ASSERT(observer_holder->is_registered); AMS_ASSERT(observer_holder->is_registered);
if (observer_holder == detail::g_log_observer_list_head) { if (observer_holder == impl::g_log_observer_list_head) {
/* Move the next item to be the list head. */ /* Move the next item to be the list head. */
detail::g_log_observer_list_head = observer_holder->next; impl::g_log_observer_list_head = observer_holder->next;
} }
else { else {
/* Find this observer's parent observer and move the following observer, removing the observer. */ /* Find this observer's parent observer and move the following observer, removing the observer. */
auto observer = detail::g_log_observer_list_head; auto observer = impl::g_log_observer_list_head;
while (observer) { while (observer) {
auto observer_parent = observer; auto observer_parent = observer;
observer = observer->next; observer = observer->next;
@ -77,13 +78,13 @@ namespace ams::diag {
} }
void ResetDefaultLogObserver() { void ResetDefaultLogObserver() {
ReplaceDefaultLogObserver(detail::DefaultLogObserver); ReplaceDefaultLogObserver(impl::DefaultLogObserver);
} }
void ReplaceDefaultLogObserver(LogFunction log_function) { void ReplaceDefaultLogObserver(LogFunction log_function) {
UnregisterLogObserver(std::addressof(detail::g_default_log_observer)); UnregisterLogObserver(std::addressof(impl::g_default_log_observer));
InitializeLogObserverHolder(std::addressof(detail::g_default_log_observer), log_function, nullptr); InitializeLogObserverHolder(std::addressof(impl::g_default_log_observer), log_function, nullptr);
RegisterLogObserver(std::addressof(detail::g_default_log_observer)); RegisterLogObserver(std::addressof(impl::g_default_log_observer));
} }
} }

View file

@ -14,8 +14,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <stratosphere.hpp> #include <stratosphere.hpp>
#include <stratosphere/diag/impl/diag_impl_string.hpp>
namespace ams::diag::detail { namespace ams::diag::impl {
namespace { namespace {
@ -68,7 +69,7 @@ namespace ams::diag::detail {
const auto max_buffer_size = sizeof(g_default_log_observer_text_buffer) - used_buffer_space - (color_type != nullptr ? std::strlen(color_type) - 1 : 0); const auto max_buffer_size = sizeof(g_default_log_observer_text_buffer) - used_buffer_space - (color_type != nullptr ? std::strlen(color_type) - 1 : 0);
const auto log_text_size = std::min<size_t>(max_buffer_size, log_body.text_length); auto log_text_size = std::min<size_t>(max_buffer_size, log_body.text_length);
if (log_body.text_length && (log_body.text[log_body.text_length - 1] == '\n')) { if (log_body.text_length && (log_body.text[log_body.text_length - 1] == '\n')) {
/* If the last character is a newline character, skip it. */ /* If the last character is a newline character, skip it. */
log_text_size--; log_text_size--;

View file

@ -14,8 +14,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <stratosphere.hpp> #include <stratosphere.hpp>
#include <stratosphere/diag/diag_log_observer.hpp>
#include <stratosphere/diag/impl/diag_impl_log.hpp>
#include <stratosphere/diag/impl/diag_impl_string.hpp>
namespace ams::diag::detail { namespace ams::diag::impl {
namespace { namespace {
@ -36,7 +39,7 @@ namespace ams::diag::detail {
break; break;
} }
auto copy_len = std::min(static_cast<size_t>(chars_len), static_cast<size_t>(print_data->print_str_end - print_data->print_str_cur)); const auto copy_len = std::min(static_cast<size_t>(chars_len), static_cast<size_t>(print_data->print_str_end - print_data->print_str_cur));
std::memcpy(print_data->print_str_cur, chars, copy_len); std::memcpy(print_data->print_str_cur, chars, copy_len);
chars_len -= copy_len; chars_len -= copy_len;
chars += copy_len; chars += copy_len;
@ -47,7 +50,7 @@ namespace ams::diag::detail {
} }
if (!print_data->log_metadata.use_default_locale_charset) { if (!print_data->log_metadata.use_default_locale_charset) {
const auto cur_print_str_len = static_cast<size_t>(print_data->print_str_cur - print_data->print_str_start); const auto cur_print_str_len = static_cast<size_t>(print_data->print_str_cur - print_data->print_str_start);
auto actual_print_str_len = GetValidSizeAsUtf8String(print_data->print_str_start, cur_print_str_len); const auto actual_print_str_len = GetValidSizeAsUtf8String(print_data->print_str_start, cur_print_str_len);
if (actual_print_str_len < cur_print_str_len) { if (actual_print_str_len < cur_print_str_len) {
auto print_str_cur_end = print_data->print_str_start + actual_print_str_len; auto print_str_cur_end = print_data->print_str_start + actual_print_str_len;
*print_str_cur_end = '\0'; *print_str_cur_end = '\0';

View file

@ -15,21 +15,21 @@
*/ */
#include <stratosphere.hpp> #include <stratosphere.hpp>
namespace ams::diag::detail { namespace ams::diag::impl {
void PrintDebugString(const char *str, size_t len) { void PrintDebugString(const char *str, size_t len) {
AMS_ASSERT(str && len); AMS_ASSERT(str && len);
svc::OutputDebugString(str, len); svc::OutputDebugString(str, len);
} }
ssize_t GetValidSizeAsUtf8String(const char *str, size_t len) { int GetValidSizeAsUtf8String(const char *str, int len) {
AMS_ABORT_UNLESS(str != nullptr); AMS_ABORT_UNLESS(str != nullptr);
if (len == 0) { if (len == 0) {
return 0; return 0;
} }
auto str_nul_end = str + len; const char *str_nul_end = str + len;
auto str_end = str + len - 1; const char *str_end = str + len - 1;
char some_c = '\0'; char some_c = '\0';
do { do {
@ -39,9 +39,9 @@ namespace ams::diag::detail {
some_c = *str_end--; some_c = *str_end--;
} while ((some_c & 0xC0) == 0x80); } while ((some_c & 0xC0) == 0x80);
size_t tmp_len = 0; int tmp_len = 0;
if (!(some_c & 0x80)) { if (!(some_c & 0x80)) {
tmp_len = static_cast<size_t>(str_nul_end - (str_end + 1)); tmp_len = static_cast<int>(str_nul_end - (str_end + 1));
if (tmp_len < 1) { if (tmp_len < 1) {
return len; return len;
} }
@ -53,7 +53,7 @@ namespace ams::diag::detail {
if ((some_c & 0xE0) == 0xC0) { if ((some_c & 0xE0) == 0xC0) {
tmp_len = static_cast<size_t>(str_nul_end - (str_end + 1)); tmp_len = static_cast<int>(str_nul_end - (str_end + 1));
if (tmp_len >= 2) { if (tmp_len >= 2) {
if (tmp_len == 2) { if (tmp_len == 2) {
return len; return len;
@ -66,7 +66,7 @@ namespace ams::diag::detail {
if ((some_c & 0xF8) != 0xF0) { if ((some_c & 0xF8) != 0xF0) {
return -1; return -1;
} }
tmp_len = static_cast<size_t>(str_nul_end - (str_end + 1)); tmp_len = static_cast<int>(str_nul_end - (str_end + 1));
if (tmp_len < 4) { if (tmp_len < 4) {
if (tmp_len < len) { if (tmp_len < len) {
return len - tmp_len; return len - tmp_len;
@ -79,7 +79,7 @@ namespace ams::diag::detail {
} }
return 1; return 1;
} }
tmp_len = static_cast<size_t>(str_nul_end - (str_end + 1)); tmp_len = static_cast<int>(str_nul_end - (str_end + 1));
if (tmp_len >= 3) { if (tmp_len >= 3) {
if (tmp_len == 3) { if (tmp_len == 3) {
return len; return len;

View file

@ -15,14 +15,14 @@
*/ */
#include <stratosphere.hpp> #include <stratosphere.hpp>
namespace ams::lm::detail { namespace ams::lm::impl {
namespace { namespace {
os::SdkMutex g_log_observer_lock; os::SdkMutex g_log_observer_lock;
u8 g_packet_transmitter_buffer[0x400]; u8 g_packet_transmitter_buffer[0x400];
bool LogPacketTransmitterFlushFunction(const void *log_data, size_t log_data_size) { bool LogPacketTransmitterFlushFunction(const u8 *log_data, size_t log_data_size) {
/* TODO: libnx bindings. */ /* TODO: libnx bindings. */
return true; return true;
} }
@ -80,7 +80,7 @@ namespace ams::lm::detail {
/* /*
const char *process_name; const char *process_name;
size_t process_name_len; size_t process_name_len;
diag::detail::GetProcessNamePointer(std::addressof(process_name), std::addressof(process_name_len)); diag::impl::GetProcessNamePointer(std::addressof(process_name), std::addressof(process_name_len));
packet_transmitter.PushProcessName(process_name, process_name_len); packet_transmitter.PushProcessName(process_name, process_name_len);
*/ */
} }

View file

@ -1,6 +1,7 @@
#include <stratosphere.hpp> #include <stratosphere.hpp>
#include <stratosphere/diag/impl/diag_impl_string.hpp>
namespace ams::lm::detail { namespace ams::lm::impl {
LogPacketTransmitterBase::LogPacketTransmitterBase(void *log_buffer, size_t log_buffer_size, LogPacketTransmitterBase::FlushFunction flush_func, u8 severity, u8 verbosity, u64 process_id, bool head, bool tail) { LogPacketTransmitterBase::LogPacketTransmitterBase(void *log_buffer, size_t log_buffer_size, LogPacketTransmitterBase::FlushFunction flush_func, u8 severity, u8 verbosity, u64 process_id, bool head, bool tail) {
AMS_ABORT_UNLESS(log_buffer != nullptr); AMS_ABORT_UNLESS(log_buffer != nullptr);
@ -8,10 +9,10 @@ namespace ams::lm::detail {
AMS_ABORT_UNLESS(flush_func != nullptr); AMS_ABORT_UNLESS(flush_func != nullptr);
this->header = reinterpret_cast<LogPacketHeader*>(log_buffer); this->header = reinterpret_cast<LogPacketHeader*>(log_buffer);
this->log_buffer_start = log_buffer; this->log_buffer_start = reinterpret_cast<u8*>(log_buffer);
this->log_buffer_end = log_buffer + log_buffer_size; this->log_buffer_end = this->log_buffer_start + log_buffer_size;
this->log_buffer_payload_start = log_buffer + sizeof(LogPacketHeader); this->log_buffer_payload_start = this->log_buffer_start + sizeof(LogPacketHeader);
this->log_buffer_payload_current = log_buffer + sizeof(LogPacketHeader); this->log_buffer_payload_current = this->log_buffer_start + sizeof(LogPacketHeader);
this->is_tail = tail; this->is_tail = tail;
this->flush_function = flush_func; this->flush_function = flush_func;
this->header->SetProcessId(process_id); this->header->SetProcessId(process_id);
@ -83,7 +84,7 @@ namespace ams::lm::detail {
size_t data_chunk_size = 0; size_t data_chunk_size = 0;
if (is_string) { if (is_string) {
auto tmp_chunk_size = cur_pushable_size; auto tmp_chunk_size = cur_pushable_size;
auto utf8_size = diag::detail::GetValidSizeAsUtf8String(reinterpret_cast<const char*>(data_cur), tmp_chunk_size); auto utf8_size = diag::impl::GetValidSizeAsUtf8String(reinterpret_cast<const char*>(data_cur), tmp_chunk_size);
if (utf8_size >= 0) { if (utf8_size >= 0) {
tmp_chunk_size = static_cast<size_t>(utf8_size); tmp_chunk_size = static_cast<size_t>(utf8_size);
} }

View file

@ -14,10 +14,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <stratosphere.hpp> #include <stratosphere.hpp>
#include <stratosphere/diag/diag_log_observer.hpp>
namespace ams::lm { namespace ams::lm {
namespace detail { namespace impl {
void LogManagerLogObserver(const diag::LogMetaData &log_metadata, const diag::LogBody &log_body, void *user_data); void LogManagerLogObserver(const diag::LogMetaData &log_metadata, const diag::LogBody &log_body, void *user_data);
@ -36,7 +37,7 @@ namespace ams::lm {
/* R_ABORT_UNLESS(lmInitialize()); */ /* R_ABORT_UNLESS(lmInitialize()); */
/* Log by default via LogManager. */ /* Log by default via LogManager. */
diag::ReplaceDefaultLogObserver(detail::LogManagerLogObserver); diag::ReplaceDefaultLogObserver(impl::LogManagerLogObserver);
g_initialized = true; g_initialized = true;
} }

View file

@ -66,7 +66,7 @@ namespace ams::lm::impl {
return std::addressof(custom_sink_buffer); return std::addressof(custom_sink_buffer);
} }
void WriteLogToCustomSink(const detail::LogPacketHeader *log_packet_header, size_t log_packet_size, u64 unk_param) { void WriteLogToCustomSink(const impl::LogPacketHeader *log_packet_header, size_t log_packet_size, u64 unk_param) {
/* Process ID value is set earlier, so it's guaranteed to be valid. */ /* Process ID value is set earlier, so it's guaranteed to be valid. */
if (log_packet_header->GetProcessId() != g_sink_buffer_current_process_id) { if (log_packet_header->GetProcessId() != g_sink_buffer_current_process_id) {
/* We're starting to log from a different process, so we need first a head packet. */ /* We're starting to log from a different process, so we need first a head packet. */
@ -82,11 +82,11 @@ namespace ams::lm::impl {
} }
} }
auto log_payload_start = reinterpret_cast<const u8*>(log_packet_header) + sizeof(detail::LogPacketHeader); auto log_payload_start = reinterpret_cast<const u8*>(log_packet_header) + sizeof(impl::LogPacketHeader);
auto log_payload_cur = log_payload_start; auto log_payload_cur = log_payload_start;
/* No need to check packet header's payload size, since it has already been validated. */ /* No need to check packet header's payload size, since it has already been validated. */
auto log_payload_size = log_packet_size - sizeof(detail::LogPacketHeader); auto log_payload_size = log_packet_size - sizeof(impl::LogPacketHeader);
if (logging_in_same_thread && (g_sink_buffer_remaining_size > 0)) { if (logging_in_same_thread && (g_sink_buffer_remaining_size > 0)) {
auto log_remaining_size = log_payload_size; auto log_remaining_size = log_payload_size;
if (log_payload_size >= g_sink_buffer_remaining_size) { if (log_payload_size >= g_sink_buffer_remaining_size) {
@ -105,8 +105,8 @@ namespace ams::lm::impl {
if (log_payload_size) { if (log_payload_size) {
auto log_payload_end = log_payload_start + log_payload_size; auto log_payload_end = log_payload_start + log_payload_size;
while (true) { while (true) {
const auto chunk_key = static_cast<detail::LogDataChunkKey>(PopUleb128(std::addressof(log_payload_cur), log_payload_end)); const auto chunk_key = static_cast<impl::LogDataChunkKey>(PopUleb128(std::addressof(log_payload_cur), log_payload_end));
const auto chunk_is_text_log = chunk_key == detail::LogDataChunkKey_TextLog; const auto chunk_is_text_log = chunk_key == impl::LogDataChunkKey_TextLog;
const auto chunk_size = PopUleb128(std::addressof(log_payload_cur), log_payload_end); const auto chunk_size = PopUleb128(std::addressof(log_payload_cur), log_payload_end);
auto left_payload_size = static_cast<size_t>(log_payload_end - log_payload_cur); auto left_payload_size = static_cast<size_t>(log_payload_end - log_payload_cur);
if (chunk_size >= left_payload_size) { if (chunk_size >= left_payload_size) {

View file

@ -46,7 +46,7 @@ namespace ams::lm::impl {
CustomSinkBuffer *GetCustomSinkBuffer(); CustomSinkBuffer *GetCustomSinkBuffer();
void WriteLogToCustomSink(const detail::LogPacketHeader *log_packet_header, size_t log_packet_size, u64 unk_param); void WriteLogToCustomSink(const impl::LogPacketHeader *log_packet_header, size_t log_packet_size, u64 unk_param);
size_t ReadLogFromCustomSink(void *out_log_data, size_t data_size, u64 *out_packet_drop_count); size_t ReadLogFromCustomSink(void *out_log_data, size_t data_size, u64 *out_packet_drop_count);
} }

View file

@ -14,9 +14,9 @@ namespace ams::lm::impl {
bool EventLogTransmitter::SendLogSessionBeginPacket(u64 process_id) { bool EventLogTransmitter::SendLogSessionBeginPacket(u64 process_id) {
/* ------------ Log buffer size: packet header (0x18) + chunk header (0x2) + LogSessionBegin dummy value (0x1) = 0x1B */ /* ------------ Log buffer size: packet header (0x18) + chunk header (0x2) + LogSessionBegin dummy value (0x1) = 0x1B */
constexpr auto log_buffer_size = sizeof(detail::LogPacketHeader) + 2 + sizeof(u8); constexpr auto log_buffer_size = sizeof(impl::LogPacketHeader) + 2 + sizeof(u8);
u8 log_buffer[log_buffer_size] = {}; u8 log_buffer[log_buffer_size] = {};
detail::LogPacketTransmitter log_packet_transmitter(log_buffer, log_buffer_size, this->flush_func, diag::LogSeverity_Info, false, process_id, true, true); impl::LogPacketTransmitter log_packet_transmitter(log_buffer, log_buffer_size, this->flush_func, diag::LogSeverity_Info, false, process_id, true, true);
log_packet_transmitter.PushLogSessionBegin(); log_packet_transmitter.PushLogSessionBegin();
const auto ok = log_packet_transmitter.Flush(true); const auto ok = log_packet_transmitter.Flush(true);
@ -28,9 +28,9 @@ namespace ams::lm::impl {
bool EventLogTransmitter::SendLogSessionEndPacket(u64 process_id) { bool EventLogTransmitter::SendLogSessionEndPacket(u64 process_id) {
/* ------------ Log buffer size: packet header (0x18) + chunk header (0x2) + LogSessionEnd dummy value (0x1) = 0x1B */ /* ------------ Log buffer size: packet header (0x18) + chunk header (0x2) + LogSessionEnd dummy value (0x1) = 0x1B */
constexpr auto log_buffer_size = sizeof(detail::LogPacketHeader) + 2 + sizeof(u8); constexpr auto log_buffer_size = sizeof(impl::LogPacketHeader) + 2 + sizeof(u8);
u8 log_buffer[log_buffer_size] = {}; u8 log_buffer[log_buffer_size] = {};
detail::LogPacketTransmitter log_packet_transmitter(log_buffer, log_buffer_size, this->flush_func, diag::LogSeverity_Info, false, process_id, true, true); impl::LogPacketTransmitter log_packet_transmitter(log_buffer, log_buffer_size, this->flush_func, diag::LogSeverity_Info, false, process_id, true, true);
log_packet_transmitter.PushLogSessionEnd(); log_packet_transmitter.PushLogSessionEnd();
const auto ok = log_packet_transmitter.Flush(true); const auto ok = log_packet_transmitter.Flush(true);
@ -46,9 +46,9 @@ namespace ams::lm::impl {
/* Only send the log packet if there were any dropped packets. */ /* Only send the log packet if there were any dropped packets. */
if (this->log_packet_drop_count > 0) { if (this->log_packet_drop_count > 0) {
/* ------------ Log buffer size: packet header (0x18) + chunk header (0x2) + log packet drop count (0x8) = 0x22 */ /* ------------ Log buffer size: packet header (0x18) + chunk header (0x2) + log packet drop count (0x8) = 0x22 */
constexpr auto log_buffer_size = sizeof(detail::LogPacketHeader) + 2 + sizeof(this->log_packet_drop_count); constexpr auto log_buffer_size = sizeof(impl::LogPacketHeader) + 2 + sizeof(this->log_packet_drop_count);
u8 log_buffer[log_buffer_size] = {}; u8 log_buffer[log_buffer_size] = {};
detail::LogPacketTransmitter log_packet_transmitter(log_buffer, log_buffer_size, this->flush_func, diag::LogSeverity_Info, false, 0, true, true); impl::LogPacketTransmitter log_packet_transmitter(log_buffer, log_buffer_size, this->flush_func, diag::LogSeverity_Info, false, 0, true, true);
log_packet_transmitter.PushLogPacketDropCount(this->log_packet_drop_count); log_packet_transmitter.PushLogPacketDropCount(this->log_packet_drop_count);
const auto ok = log_packet_transmitter.Flush(true); const auto ok = log_packet_transmitter.Flush(true);

View file

@ -22,11 +22,11 @@ namespace ams::lm::impl {
NON_COPYABLE(EventLogTransmitter); NON_COPYABLE(EventLogTransmitter);
NON_MOVEABLE(EventLogTransmitter); NON_MOVEABLE(EventLogTransmitter);
private: private:
detail::LogPacketTransmitter::FlushFunction flush_func; impl::LogPacketTransmitter::FlushFunction flush_func;
u64 log_packet_drop_count; u64 log_packet_drop_count;
os::SdkMutex log_packet_drop_count_lock; os::SdkMutex log_packet_drop_count_lock;
public: public:
EventLogTransmitter(detail::LogPacketTransmitter::FlushFunction flush_func) : flush_func(flush_func), log_packet_drop_count(0), log_packet_drop_count_lock() {} EventLogTransmitter(impl::LogPacketTransmitter::FlushFunction flush_func) : flush_func(flush_func), log_packet_drop_count(0), log_packet_drop_count_lock() {}
bool SendLogSessionBeginPacket(u64 process_id); bool SendLogSessionBeginPacket(u64 process_id);
bool SendLogSessionEndPacket(u64 process_id); bool SendLogSessionEndPacket(u64 process_id);

View file

@ -27,15 +27,15 @@ namespace ams::lm::impl {
return ok; return ok;
} }
inline bool ModifyUserSystemClockInfoImpl(detail::LogDataChunkKey chunk_key, u8 *log_payload_data, size_t log_payload_size, time::PosixTime &time_ref) { inline bool ModifyUserSystemClockInfoImpl(impl::LogDataChunkKey chunk_key, u8 *log_payload_data, size_t log_payload_size, time::PosixTime &time_ref) {
if(chunk_key == detail::LogDataChunkKey_UserSystemClock) { if(chunk_key == impl::LogDataChunkKey_UserSystemClock) {
/* TODO: properly implement this...? */ /* TODO: properly implement this...? */
reinterpret_cast<time::PosixTime*>(log_payload_data)->value += time_ref.value; reinterpret_cast<time::PosixTime*>(log_payload_data)->value += time_ref.value;
} }
return true; return true;
} }
bool ModifyUserSystemClockInfo(detail::LogPacketHeader *packet_header, void *log_payload_data, size_t log_payload_size, time::PosixTime &time_ref) { bool ModifyUserSystemClockInfo(impl::LogPacketHeader *packet_header, void *log_payload_data, size_t log_payload_size, time::PosixTime &time_ref) {
if (!packet_header->IsHead()) { if (!packet_header->IsHead()) {
/* Only modify this field on head packets. */ /* Only modify this field on head packets. */
return true; return true;
@ -51,7 +51,7 @@ namespace ams::lm::impl {
auto payload_end = payload_start + log_payload_size; auto payload_end = payload_start + log_payload_size;
/* Read chunk key and size. */ /* Read chunk key and size. */
const auto chunk_key = static_cast<detail::LogDataChunkKey>(PopUleb128(const_cast<const u8**>(std::addressof(payload_cur)), const_cast<const u8*>(payload_end))); const auto chunk_key = static_cast<impl::LogDataChunkKey>(PopUleb128(const_cast<const u8**>(std::addressof(payload_cur)), const_cast<const u8*>(payload_end)));
if (payload_cur >= payload_end) { if (payload_cur >= payload_end) {
return false; return false;
} }
@ -71,18 +71,18 @@ namespace ams::lm::impl {
} }
/* Iterate (for potential multiple packets?) and change the UserSystemClock for each value. */ /* Iterate (for potential multiple packets?) and change the UserSystemClock for each value. */
auto packet_header = reinterpret_cast<detail::LogPacketHeader*>(log_data); auto packet_header = reinterpret_cast<impl::LogPacketHeader*>(log_data);
auto data_start = reinterpret_cast<u8*>(log_data); auto data_start = reinterpret_cast<u8*>(log_data);
auto data_cur = data_start; auto data_cur = data_start;
auto data_end = data_start + log_data_size; auto data_end = data_start + log_data_size;
auto cur_packet_header = packet_header; auto cur_packet_header = packet_header;
while (static_cast<size_t>(data_end - data_start) >= sizeof(detail::LogPacketHeader)) { while (static_cast<size_t>(data_end - data_start) >= sizeof(impl::LogPacketHeader)) {
auto payload_size = cur_packet_header->GetPayloadSize(); auto payload_size = cur_packet_header->GetPayloadSize();
if ((static_cast<size_t>(data_end - data_cur) < payload_size) || !ModifyUserSystemClockInfo(cur_packet_header, data_cur, static_cast<size_t>(payload_size), time_ref)) { if ((static_cast<size_t>(data_end - data_cur) < payload_size) || !ModifyUserSystemClockInfo(cur_packet_header, data_cur, static_cast<size_t>(payload_size), time_ref)) {
break; break;
} }
cur_packet_header = reinterpret_cast<detail::LogPacketHeader*>(data_cur + payload_size); cur_packet_header = reinterpret_cast<impl::LogPacketHeader*>(data_cur + payload_size);
if ((data_cur + payload_size) >= data_end) { if ((data_cur + payload_size) >= data_end) {
return true; return true;
} }

View file

@ -147,7 +147,7 @@ namespace ams::lm::impl {
ON_SCOPE_EXIT { fs::CloseFile(log_file_h); }; ON_SCOPE_EXIT { fs::CloseFile(log_file_h); };
/* 8-byte binary log header, current version is 1. */ /* 8-byte binary log header, current version is 1. */
const detail::BinaryLogHeader bin_log_header = { detail::BinaryLogHeader::Magic, 1 }; const impl::BinaryLogHeader bin_log_header = { impl::BinaryLogHeader::Magic, 1 };
if (R_SUCCEEDED(fs::WriteFile(log_file_h, 0, std::addressof(bin_log_header), sizeof(bin_log_header), fs::WriteOption::Flush))) { if (R_SUCCEEDED(fs::WriteFile(log_file_h, 0, std::addressof(bin_log_header), sizeof(bin_log_header), fs::WriteOption::Flush))) {
this->log_file_offset = sizeof(bin_log_header); this->log_file_offset = sizeof(bin_log_header);
return true; return true;

View file

@ -42,10 +42,10 @@ namespace ams::lm {
} }
void Logger::Log(const sf::InAutoSelectBuffer &log_buffer) { void Logger::Log(const sf::InAutoSelectBuffer &log_buffer) {
auto log_packet_header = (detail::LogPacketHeader*)log_buffer.GetPointer(); auto log_packet_header = (impl::LogPacketHeader*)log_buffer.GetPointer();
/* Don't log anything if payload size isn't correct. */ /* Don't log anything if payload size isn't correct. */
if ((log_packet_header->GetPayloadSize() + sizeof(detail::LogPacketHeader)) != log_buffer.GetSize()) { if ((log_packet_header->GetPayloadSize() + sizeof(impl::LogPacketHeader)) != log_buffer.GetSize()) {
return; return;
} }
@ -66,7 +66,7 @@ namespace ams::lm {
if (g_is_logging_to_custom_sink) { if (g_is_logging_to_custom_sink) {
/* Log to custom sink if enabled. */ /* Log to custom sink if enabled. */
impl::WriteLogToCustomSink(const_cast<const detail::LogPacketHeader*>(log_packet_header), log_buffer.GetSize(), 0); impl::WriteLogToCustomSink(const_cast<const impl::LogPacketHeader*>(log_packet_header), log_buffer.GetSize(), 0);
} }
} }