Some changes

This commit is contained in:
XorTroll 2021-01-28 08:57:58 +01:00
commit 2159b52c89
22 changed files with 136 additions and 155 deletions

View file

@ -121,6 +121,7 @@ namespace ams::impl {
AMS_DEFINE_SYSTEM_THREAD(21, pgl, ProcessControlTask); AMS_DEFINE_SYSTEM_THREAD(21, pgl, ProcessControlTask);
/* lm. */ /* lm. */
AMS_DEFINE_SYSTEM_THREAD(10, lm, MainThread);
AMS_DEFINE_SYSTEM_THREAD(10, lm, IpcServer); AMS_DEFINE_SYSTEM_THREAD(10, lm, IpcServer);
AMS_DEFINE_SYSTEM_THREAD(10, lm, Flush); AMS_DEFINE_SYSTEM_THREAD(10, lm, Flush);
AMS_DEFINE_SYSTEM_THREAD(10, lm, HtcsConnection); AMS_DEFINE_SYSTEM_THREAD(10, lm, HtcsConnection);

View file

@ -13,7 +13,6 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* 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/diag/diag_log_observer.hpp> #include <stratosphere/diag/diag_log_observer.hpp>

View file

@ -18,8 +18,8 @@
namespace ams::diag::detail { namespace ams::diag::detail {
void LogImpl(const LogMetaData &log_metadata, const char *fmt, ...); 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 va_args); void VLogImpl(const LogMetaData &log_metadata, const char *fmt, std::va_list vl);
void CallAllLogObserver(const LogMetaData &log_metadata, const LogBody &log_body); void CallAllLogObserver(const LogMetaData &log_metadata, const LogBody &log_body);
#define AMS_LOG(fmt, ...) ({ \ #define AMS_LOG(fmt, ...) ({ \
@ -27,9 +27,9 @@ namespace ams::diag::detail {
.source_info = { \ .source_info = { \
.line_number = __LINE__, \ .line_number = __LINE__, \
.file_name = __FILE__, \ .file_name = __FILE__, \
.function_name = __func__ \ .function_name = AMS_CURRENT_FUNCTION_NAME \
}, \ }, \
.log_severity = LogSeverity_Info \ .log_severity = ::ams::diag::LogSeverity_Info \
}; \ }; \
::ams::diag::detail::LogImpl(log_metadata, fmt, __VA_ARGS__); \ ::ams::diag::detail::LogImpl(log_metadata, fmt, __VA_ARGS__); \
}) })

View file

@ -18,21 +18,21 @@
namespace ams::diag { namespace ams::diag {
struct LogObserverHolder {
using LogFunction = void (*)(const LogMetaData &log_metadata, const LogBody &log_body, void *user_data); using LogFunction = void (*)(const LogMetaData &log_metadata, const LogBody &log_body, void *user_data);
struct LogObserverHolder {
LogFunction log_function; LogFunction log_function;
LogObserverHolder *next; LogObserverHolder *next;
bool is_registered; bool is_registered;
void *user_data; void *user_data;
}; };
void InitializeLogObserverHolder(LogObserverHolder *observer_holder, LogObserverHolder::LogFunction log_function, void *user_data); void InitializeLogObserverHolder(LogObserverHolder *observer_holder, LogFunction log_function, void *user_data);
void RegisterLogObserver(LogObserverHolder *observer_holder); void RegisterLogObserver(LogObserverHolder *observer_holder);
void UnregisterLogObserver(LogObserverHolder *observer_holder); void UnregisterLogObserver(LogObserverHolder *observer_holder);
void ResetDefaultLogObserver(); void ResetDefaultLogObserver();
void ReplaceDefaultLogObserver(LogObserverHolder::LogFunction log_function); void ReplaceDefaultLogObserver(LogFunction log_function);
} }

View file

@ -19,13 +19,13 @@
namespace ams::diag { namespace ams::diag {
enum LogSeverity : u8 { enum LogSeverity : u8 {
LogSeverity_Trace, LogSeverity_Trace = 0,
LogSeverity_Info, LogSeverity_Info = 1,
LogSeverity_Warn, LogSeverity_Warn = 2,
LogSeverity_Error, LogSeverity_Error = 3,
LogSeverity_Fatal, LogSeverity_Fatal = 4,
LogSeverity_Count LogSeverity_Count = 5,
}; };
struct SourceInfo { struct SourceInfo {
@ -45,10 +45,10 @@ namespace ams::diag {
}; };
struct LogBody { struct LogBody {
const char *log_text; const char *text;
size_t log_text_length; size_t text_length;
bool log_is_head; bool is_head;
bool log_is_tail; bool is_tail;
}; };
} }

View file

@ -22,7 +22,7 @@ namespace ams::lm::detail {
NON_COPYABLE(LogPacketTransmitterBase); NON_COPYABLE(LogPacketTransmitterBase);
NON_MOVEABLE(LogPacketTransmitterBase); NON_MOVEABLE(LogPacketTransmitterBase);
public: public:
using FlushFunction = bool (*)(const void*, size_t); using FlushFunction = bool (*)(const u8*, size_t);
private: private:
LogPacketHeader *header; LogPacketHeader *header;
u8 *log_buffer_start; u8 *log_buffer_start;
@ -32,7 +32,7 @@ namespace ams::lm::detail {
bool is_tail; bool is_tail;
FlushFunction flush_function; FlushFunction flush_function;
public: public:
LogPacketTransmitterBase(u8 *log_buffer, size_t log_buffer_size, FlushFunction flush_fn, diag::LogSeverity severity, bool verbosity, u64 process_id, bool head, bool tail); LogPacketTransmitterBase(void *log_buffer, size_t log_buffer_size, FlushFunction flush_func, u8 severity, u8 verbosity, u64 process_id, bool head, bool tail);
~LogPacketTransmitterBase() { ~LogPacketTransmitterBase() {
this->Flush(this->is_tail); this->Flush(this->is_tail);
@ -73,13 +73,13 @@ namespace ams::lm::detail {
using LogPacketTransmitterBase::LogPacketTransmitterBase; using LogPacketTransmitterBase::LogPacketTransmitterBase;
void PushLogSessionBegin() { void PushLogSessionBegin() {
u8 dummy_value = 1; bool value = true;
this->PushDataChunk(LogDataChunkKey_LogSessionBegin, std::addressof(dummy_value), sizeof(dummy_value)); this->PushDataChunk(LogDataChunkKey_LogSessionBegin, std::addressof(value), sizeof(value));
} }
void PushLogSessionEnd() { void PushLogSessionEnd() {
u8 dummy_value = 1; bool value = true;
this->PushDataChunk(LogDataChunkKey_LogSessionEnd, std::addressof(dummy_value), sizeof(dummy_value)); this->PushDataChunk(LogDataChunkKey_LogSessionEnd, std::addressof(value), sizeof(value));
} }
void PushTextLog(const char *log, size_t log_len) { void PushTextLog(const char *log, size_t log_len) {

View file

@ -25,7 +25,7 @@ namespace ams::lm::detail {
}; };
struct BinaryLogHeader { struct BinaryLogHeader {
static constexpr u32 Magic = util::FourCC<'h','p','h','p'>::Code; static constexpr u32 Magic = util::FourCC<'p','h','p','h'>::Code;
u32 magic; u32 magic;
u8 version; u8 version;
@ -37,8 +37,8 @@ namespace ams::lm::detail {
u64 thread_id; u64 thread_id;
u8 flags; u8 flags;
u8 pad; u8 pad;
diag::LogSeverity severity; u8 severity;
char verbosity; u8 verbosity;
u32 payload_size; u32 payload_size;
constexpr inline u64 GetProcessId() const { constexpr inline u64 GetProcessId() const {
@ -60,17 +60,16 @@ namespace ams::lm::detail {
constexpr inline void SetLittleEndian(bool le) { constexpr inline void SetLittleEndian(bool le) {
if (le) { if (le) {
this->flags |= LogPacketFlags_LittleEndian; this->flags |= LogPacketFlags_LittleEndian;
} } else {
else {
this->flags &= ~LogPacketFlags_LittleEndian; this->flags &= ~LogPacketFlags_LittleEndian;
} }
} }
constexpr inline void SetSeverity(diag::LogSeverity severity) { constexpr inline void SetSeverity(u8 severity) {
this->severity = severity; this->severity = severity;
} }
constexpr inline void SetVerbosity(char verbosity) { constexpr inline void SetVerbosity(u8 verbosity) {
this->verbosity = verbosity; this->verbosity = verbosity;
} }
@ -81,8 +80,7 @@ namespace ams::lm::detail {
constexpr inline void SetHead(bool head) { constexpr inline void SetHead(bool head) {
if (head) { if (head) {
this->flags |= LogPacketFlags_Head; this->flags |= LogPacketFlags_Head;
} } else {
else {
this->flags &= ~LogPacketFlags_Head; this->flags &= ~LogPacketFlags_Head;
} }
} }
@ -109,20 +107,20 @@ namespace ams::lm::detail {
} }
}; };
static_assert(sizeof(LogPacketHeader) == 0x18); static_assert(util::is_pod<LogPacketHeader>::value && sizeof(LogPacketHeader) == 0x18);
enum LogDataChunkKey : u8 { enum LogDataChunkKey : u8 {
LogDataChunkKey_LogSessionBegin = 0, ///< Log session begin. LogDataChunkKey_LogSessionBegin = 0,
LogDataChunkKey_LogSessionEnd = 1, ///< Log session end. LogDataChunkKey_LogSessionEnd = 1,
LogDataChunkKey_TextLog = 2, ///< Text to be logged. LogDataChunkKey_TextLog = 2,
LogDataChunkKey_LineNumber = 3, ///< Source line number. LogDataChunkKey_LineNumber = 3,
LogDataChunkKey_FileName = 4, ///< Source file name. LogDataChunkKey_FileName = 4,
LogDataChunkKey_FunctionName = 5, ///< Source function name. LogDataChunkKey_FunctionName = 5,
LogDataChunkKey_ModuleName = 6, ///< Process module name. LogDataChunkKey_ModuleName = 6,
LogDataChunkKey_ThreadName = 7, ///< Process thread name. LogDataChunkKey_ThreadName = 7,
LogDataChunkKey_LogPacketDropCount = 8, ///< Log packet drop count. LogDataChunkKey_LogPacketDropCount = 8,
LogDataChunkKey_UserSystemClock = 9, ///< User system clock. LogDataChunkKey_UserSystemClock = 9,
LogDataChunkKey_ProcessName = 10, ///< Process name. LogDataChunkKey_ProcessName = 10,
}; };
} }

View file

@ -13,7 +13,6 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* 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
namespace ams::lm { namespace ams::lm {

View file

@ -23,7 +23,7 @@ namespace ams::diag::detail {
constexpr const char *g_log_severity_color_table[LogSeverity_Count] = { constexpr const char *g_log_severity_color_table[LogSeverity_Count] = {
"\x1B[90m", /* Dark gray for Trace. */ "\x1B[90m", /* Dark gray for Trace. */
"", /* No special color for Info. */ nullptr, /* No special color for Info. */
"\x1B[33m", /* Yellow for Warn. */ "\x1B[33m", /* Yellow for Warn. */
"\x1B[31m", /* Red for Error. */ "\x1B[31m", /* Red for Error. */
"\x1B[41m\x1B[37m" /* White + red for Fatal. */ "\x1B[41m\x1B[37m" /* White + red for Fatal. */
@ -41,51 +41,41 @@ namespace ams::diag::detail {
if (log_metadata.log_severity < LogSeverity_Count) { if (log_metadata.log_severity < LogSeverity_Count) {
color_type = g_log_severity_color_table[log_metadata.log_severity]; color_type = g_log_severity_color_table[log_metadata.log_severity];
} }
auto has_module_name = false;
if (log_metadata.module_name != nullptr) { /* Avoid '$' as module name. */
has_module_name = strlen(log_metadata.module_name) > 1; /* Avoid '$' as module name. */ const auto has_module_name = log_metadata.module_name != nullptr && std::strlen(log_metadata.module_name) > 1;
}
if (!has_module_name && !color_type) { if (!has_module_name && !color_type) {
/* Just send the text log. */ /* Just send the text log. */
PrintDebugString(log_body.log_text, log_body.log_text_length); return PrintDebugString(log_body.text, log_body.text_length);
return;
} }
size_t used_buffer_space = 0; size_t used_buffer_space = 0;
if (has_module_name && log_body.log_is_head) { if (has_module_name && log_body.is_head) {
auto fmt_prefix = (color_type != nullptr) ? color_type : ""; const auto fmt_prefix = (color_type != nullptr) ? color_type : "";
auto module_name = log_metadata.module_name; const char *module_name = log_metadata.module_name;
if (module_name[0] == '$') { if (module_name[0] == '$') {
/* Skip logging this initial character if it's present. */ /* Skip logging this initial character if it's present. */
module_name++; module_name++;
} }
auto system_tick = os::GetSystemTick(); const auto tick = os::ConvertToTimeSpan(os::GetSystemTick());
auto tick_ts = os::ConvertToTimeSpan(system_tick); used_buffer_space += util::SNPrintf(g_default_log_observer_text_buffer, sizeof(g_default_log_observer_text_buffer), "%s%d:%02d:%02d.%03d [%-5s] ", fmt_prefix, tick.GetHours(), tick.GetMinutes(), tick.GetSeconds(), tick.GetMilliSeconds(), module_name);
used_buffer_space += util::SNPrintf(g_default_log_observer_text_buffer, sizeof(g_default_log_observer_text_buffer), "%s%d:%02d:%02d.%03d [%-5s] ", fmt_prefix, tick_ts.GetHours(), tick_ts.GetMinutes(), tick_ts.GetSeconds(), tick_ts.GetMilliSeconds(), module_name); } else if (color_type != nullptr) {
}
else if (color_type) {
used_buffer_space += util::SNPrintf(g_default_log_observer_text_buffer, sizeof(g_default_log_observer_text_buffer), "%s", color_type); used_buffer_space += util::SNPrintf(g_default_log_observer_text_buffer, sizeof(g_default_log_observer_text_buffer), "%s", color_type);
} }
auto left_buffer_space = sizeof(g_default_log_observer_text_buffer) - used_buffer_space; const auto max_buffer_size = sizeof(g_default_log_observer_text_buffer) - used_buffer_space - (color_type != nullptr ? std::strlen(color_type) - 1 : 0);
if (color_type) {
/* Also subtract the size of the color formatting, if present. */
left_buffer_space -= strlen(color_type);
}
auto log_text_size = std::min(left_buffer_space, log_body.log_text_length); const auto log_text_size = std::min<size_t>(max_buffer_size, log_body.text_length);
if (log_body.log_text_length && (log_body.log_text[log_body.log_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--;
} }
/* If we used a color before, reset it now. */ /* If we used a color before, reset it now. */
auto fmt_prefix = (color_type != nullptr) ? "\x1B[0m" : ""; used_buffer_space += util::SNPrintf(g_default_log_observer_text_buffer + used_buffer_space, max_buffer_size, "%.*s%s%s", log_text_size, log_body.text, (color_type != nullptr) ? "\x1B[0m" : "");
used_buffer_space += util::SNPrintf(g_default_log_observer_text_buffer + used_buffer_space, left_buffer_space, "%.*s%s%s", log_text_size, log_body.log_text, fmt_prefix);
PrintDebugString(g_default_log_observer_text_buffer, used_buffer_space); PrintDebugString(g_default_log_observer_text_buffer, used_buffer_space);
} }

View file

@ -53,10 +53,10 @@ namespace ams::diag::detail {
*print_str_cur_end = '\0'; *print_str_cur_end = '\0';
const LogBody log_body = { const LogBody log_body = {
.log_text = print_data->print_str_start, .text = print_data->print_str_start,
.log_text_length = actual_print_str_len, .text_length = actual_print_str_len,
.log_is_head = print_data->is_head, .is_head = print_data->is_head,
.log_is_tail = false, .is_tail = false,
}; };
CallAllLogObserver(print_data->log_metadata, log_body); CallAllLogObserver(print_data->log_metadata, log_body);
auto move_len = cur_print_str_len - actual_print_str_len; auto move_len = cur_print_str_len - actual_print_str_len;
@ -69,10 +69,10 @@ namespace ams::diag::detail {
*print_data->print_str_cur = '\0'; *print_data->print_str_cur = '\0';
const LogBody log_body = { const LogBody log_body = {
.log_text = print_data->print_str_start, .text = print_data->print_str_start,
.log_text_length = static_cast<size_t>(print_data->print_str_cur - print_data->print_str_start), .text_length = static_cast<size_t>(print_data->print_str_cur - print_data->print_str_start),
.log_is_head = print_data->is_head, .is_head = print_data->is_head,
.log_is_tail = false, .is_tail = false,
}; };
CallAllLogObserver(print_data->log_metadata, log_body); CallAllLogObserver(print_data->log_metadata, log_body);
print_data->print_str_cur = print_data->print_str_start; print_data->print_str_cur = print_data->print_str_start;
@ -107,10 +107,10 @@ namespace ams::diag::detail {
util::VFormatString(PutCharacters, std::addressof(print_data), fmt, vl); util::VFormatString(PutCharacters, std::addressof(print_data), fmt, vl);
const LogBody log_body = { const LogBody log_body = {
.log_text = print_data.print_str_start, .text = print_data.print_str_start,
.log_text_length = static_cast<size_t>(print_data.print_str_cur - print_data.print_str_start), .text_length = static_cast<size_t>(print_data.print_str_cur - print_data.print_str_start),
.log_is_head = print_data.is_head, .is_head = print_data.is_head,
.log_is_tail = true, .is_tail = true,
}; };
CallAllLogObserver(print_data.log_metadata, log_body); CallAllLogObserver(print_data.log_metadata, log_body);
} }

View file

@ -26,7 +26,7 @@ namespace ams::diag {
} }
void InitializeLogObserverHolder(LogObserverHolder *observer_holder, LogObserverHolder::LogFunction log_function, void *user_data) { void InitializeLogObserverHolder(LogObserverHolder *observer_holder, LogFunction log_function, void *user_data) {
observer_holder->log_function = log_function; observer_holder->log_function = log_function;
observer_holder->next = nullptr; observer_holder->next = nullptr;
observer_holder->is_registered = false; observer_holder->is_registered = false;
@ -80,7 +80,7 @@ namespace ams::diag {
ReplaceDefaultLogObserver(detail::DefaultLogObserver); ReplaceDefaultLogObserver(detail::DefaultLogObserver);
} }
void ReplaceDefaultLogObserver(LogObserverHolder::LogFunction log_function) { void ReplaceDefaultLogObserver(LogFunction log_function) {
UnregisterLogObserver(std::addressof(detail::g_default_log_observer)); UnregisterLogObserver(std::addressof(detail::g_default_log_observer));
InitializeLogObserverHolder(std::addressof(detail::g_default_log_observer), log_function, nullptr); InitializeLogObserverHolder(std::addressof(detail::g_default_log_observer), log_function, nullptr);
RegisterLogObserver(std::addressof(detail::g_default_log_observer)); RegisterLogObserver(std::addressof(detail::g_default_log_observer));

View file

@ -35,52 +35,46 @@ namespace ams::lm::detail {
AMS_ASSERT(!log_metadata.use_default_locale_charset); AMS_ASSERT(!log_metadata.use_default_locale_charset);
std::scoped_lock lk(g_log_observer_lock); std::scoped_lock lk(g_log_observer_lock);
LogPacketTransmitter packet_transmitter(g_packet_transmitter_buffer, sizeof(g_packet_transmitter_buffer), LogPacketTransmitterFlushFunction, log_metadata.log_severity, log_metadata.verbosity, 0, log_body.log_is_head, log_body.log_is_tail); LogPacketTransmitter packet_transmitter(g_packet_transmitter_buffer, sizeof(g_packet_transmitter_buffer), LogPacketTransmitterFlushFunction, log_metadata.log_severity, log_metadata.verbosity, 0, log_body.is_head, log_body.is_tail);
if (log_body.log_is_head) { if (log_body.is_head) {
/* Push time. */ /* Push time. */
auto system_tick = os::GetSystemTick(); packet_transmitter.PushUserSystemClock(static_cast<u64>(os::ConvertToTimeSpan(os::GetSystemTick()).GetSeconds()));
auto tick_ts = os::ConvertToTimeSpan(system_tick);
packet_transmitter.PushUserSystemClock(static_cast<u64>(tick_ts.GetSeconds()));
/* Push line number. */ /* Push line number. */
auto line_number = log_metadata.source_info.line_number; packet_transmitter.PushLineNumber(log_metadata.source_info.line_number);
packet_transmitter.PushLineNumber(line_number);
/* Push file name. */ /* Push file name. */
auto file_name = log_metadata.source_info.file_name; if (std::strlen(log_metadata.source_info.file_name) /* && !util::VerifyUtf8String(log_metadata.source_info.file_name, std::strlen(log_metadata.source_info.file_name)) */) {
auto file_name_len = strlen(file_name); packet_transmitter.PushFileName(DefaultInvalidString, __builtin_strlen(DefaultInvalidString));
if (file_name /* && !util::VerifyUtf8String(file_name, file_name_len) */) { }
file_name = DefaultInvalidString; else {
file_name_len = __builtin_strlen(DefaultInvalidString); packet_transmitter.PushFileName(log_metadata.source_info.file_name, std::strlen(log_metadata.source_info.file_name));
} }
packet_transmitter.PushFileName(file_name, file_name_len);
/* Push function name. */ /* Push function name. */
auto function_name = log_metadata.source_info.function_name; if (std::strlen(log_metadata.source_info.function_name) /* && !util::VerifyUtf8String(log_metadata.source_info.function_name, std::strlen(log_metadata.source_info.function_name)) */) {
auto function_name_len = strlen(function_name); packet_transmitter.PushFunctionName(DefaultInvalidString, __builtin_strlen(DefaultInvalidString));
if (function_name /* && !util::VerifyUtf8String(function_name, function_name_len) */) { }
function_name = DefaultInvalidString; else {
function_name_len = __builtin_strlen(DefaultInvalidString); packet_transmitter.PushFunctionName(log_metadata.source_info.function_name, std::strlen(log_metadata.source_info.function_name));
} }
packet_transmitter.PushFunctionName(function_name, function_name_len);
/* Push module name. */ /* Push module name. */
auto module_name = log_metadata.module_name; if (std::strlen(log_metadata.module_name) /* && !util::VerifyUtf8String(log_metadata.module_name, std::strlen(log_metadata.module_name)) */) {
auto module_name_len = strlen(module_name); packet_transmitter.PushModuleName(DefaultInvalidString, __builtin_strlen(DefaultInvalidString));
if (module_name /* && !util::VerifyUtf8String(module_name, module_name_len) */) { }
module_name = DefaultInvalidString; else {
module_name_len = __builtin_strlen(DefaultInvalidString); packet_transmitter.PushModuleName(log_metadata.module_name, std::strlen(log_metadata.module_name));
} }
packet_transmitter.PushModuleName(module_name, module_name_len);
/* Push thread name. */ /* Push thread name. */
auto thread_name = os::GetThreadNamePointer(os::GetCurrentThread()); const auto thread_name = os::GetThreadNamePointer(os::GetCurrentThread());
auto thread_name_len = strlen(thread_name); if (std::strlen(thread_name) /* && !util::VerifyUtf8String(thread_name, std::strlen(thread_name)) */) {
if (thread_name /* && !util::VerifyUtf8String(thread_name, thread_name_len) */) { packet_transmitter.PushThreadName(DefaultInvalidString, __builtin_strlen(DefaultInvalidString));
thread_name = DefaultInvalidString; }
thread_name_len = __builtin_strlen(DefaultInvalidString); else {
packet_transmitter.PushThreadName(thread_name, std::strlen(thread_name));
} }
packet_transmitter.PushThreadName(thread_name, thread_name_len);
/* TODO: Push process name. */ /* TODO: Push process name. */
/* /*
@ -92,7 +86,7 @@ namespace ams::lm::detail {
} }
/* Push text log. */ /* Push text log. */
packet_transmitter.PushTextLog(log_body.log_text, log_body.log_text_length); packet_transmitter.PushTextLog(log_body.text, log_body.text_length);
/* Packet transmitter's destructor flushes everything automatically. */ /* Packet transmitter's destructor flushes everything automatically. */
} }

View file

@ -2,10 +2,10 @@
namespace ams::lm::detail { namespace ams::lm::detail {
LogPacketTransmitterBase::LogPacketTransmitterBase(u8 *log_buffer, size_t log_buffer_size, LogPacketTransmitterBase::FlushFunction flush_fn, diag::LogSeverity severity, bool 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);
AMS_ABORT_UNLESS(log_buffer_size > sizeof(LogPacketHeader)); AMS_ABORT_UNLESS(log_buffer_size > sizeof(LogPacketHeader));
AMS_ABORT_UNLESS(flush_fn != 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 = log_buffer;
@ -13,7 +13,7 @@ namespace ams::lm::detail {
this->log_buffer_payload_start = log_buffer + sizeof(LogPacketHeader); this->log_buffer_payload_start = log_buffer + sizeof(LogPacketHeader);
this->log_buffer_payload_current = log_buffer + sizeof(LogPacketHeader); this->log_buffer_payload_current = log_buffer + sizeof(LogPacketHeader);
this->is_tail = tail; this->is_tail = tail;
this->flush_function = flush_fn; this->flush_function = flush_func;
this->header->SetProcessId(process_id); this->header->SetProcessId(process_id);
auto current_thread = os::GetCurrentThread(); auto current_thread = os::GetCurrentThread();

View file

@ -28,7 +28,7 @@ namespace ams::util {
using PrintFunction = void (*)(void *user_data, const char *str, int unk); using PrintFunction = void (*)(void *user_data, const char *str, int unk);
void FormatString(PrintFunction print_fn, void *user_data, const char *fmt, ...); void FormatString(PrintFunction print_func, void *user_data, const char *fmt, ...);
void VFormatString(PrintFunction print_fn, void *user_data, const char *fmt, std::va_list vl); void VFormatString(PrintFunction print_func, void *user_data, const char *fmt, std::va_list vl);
} }

View file

@ -431,14 +431,14 @@ namespace ams::util {
return len; return len;
} }
void FormatString(PrintFunction print_fn, void *user_data, const char *fmt, ...) { void FormatString(PrintFunction print_func, void *user_data, const char *fmt, ...) {
std::va_list vl; std::va_list vl;
va_start(vl, fmt); va_start(vl, fmt);
VFormatString(print_fn, user_data, fmt, vl); VFormatString(print_func, user_data, fmt, vl);
va_end(vl); va_end(vl);
} }
void VFormatString(PrintFunction print_fn, void *user_data, const char *fmt, std::va_list vl) { void VFormatString(PrintFunction print_func, void *user_data, const char *fmt, std::va_list vl) {
/* TODO */ /* TODO */
} }

View file

@ -39,7 +39,7 @@ namespace ams::lm::impl {
} }
/* Update log data with our values. */ /* Update log data with our values. */
const auto ok = this->flush_fn(this->log_data_buffer, this->cur_offset); const auto ok = this->flush_func(this->log_data_buffer, this->cur_offset);
if (!ok) { if (!ok) {
return false; return false;
} }

View file

@ -27,10 +27,10 @@ namespace ams::lm::impl {
u8 *log_data_buffer; u8 *log_data_buffer;
size_t size; size_t size;
size_t cur_offset; size_t cur_offset;
FlushFunction flush_fn; FlushFunction flush_func;
bool expects_more_packets; bool expects_more_packets;
public: public:
CustomSinkBuffer(u8 *log_data_buf, size_t size, FlushFunction flush_fn) : log_data_buffer(log_data_buf), size(size), cur_offset(0), flush_fn(flush_fn), expects_more_packets(false) {} CustomSinkBuffer(u8 *log_data_buf, size_t size, FlushFunction flush_func) : log_data_buffer(log_data_buf), size(size), cur_offset(0), flush_func(flush_func), expects_more_packets(false) {}
bool HasLogData(); bool HasLogData();
bool Log(const void *log_data, size_t size); bool Log(const void *log_data, size_t size);

View file

@ -16,7 +16,7 @@ namespace ams::lm::impl {
/* ------------ 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(detail::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_fn, diag::LogSeverity_Info, false, process_id, true, true); detail::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);
@ -30,7 +30,7 @@ namespace ams::lm::impl {
/* ------------ 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(detail::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_fn, diag::LogSeverity_Info, false, process_id, true, true); detail::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);
@ -48,7 +48,7 @@ namespace ams::lm::impl {
/* ------------ 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(detail::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_fn, diag::LogSeverity_Info, false, 0, true, true); detail::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_fn; detail::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_fn) : flush_fn(flush_fn), log_packet_drop_count(0), log_packet_drop_count_lock() {} EventLogTransmitter(detail::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

@ -31,7 +31,7 @@ namespace ams::lm::impl {
LogBuffer *main_target_buffer; LogBuffer *main_target_buffer;
LogBuffer *sub_target_buffer; LogBuffer *sub_target_buffer;
size_t data_buffer_size; size_t data_buffer_size;
FlushFunction flush_fn; FlushFunction flush_func;
os::SdkMutex main_target_buffer_lock; os::SdkMutex main_target_buffer_lock;
os::SdkMutex sub_target_buffer_lock; os::SdkMutex sub_target_buffer_lock;
os::SdkConditionVariable flush_done_cv; os::SdkConditionVariable flush_done_cv;
@ -39,13 +39,13 @@ namespace ams::lm::impl {
bool some_flag; bool some_flag;
uint64_t some_count_2; uint64_t some_count_2;
public: public:
LogBuffer(void *data_buffer, size_t data_buffer_size, FlushFunction flush_fn, LogBuffer *second_log_buffer) : data_buffer(data_buffer), second_log_buffer(second_log_buffer), main_target_buffer(this), sub_target_buffer(second_log_buffer), data_buffer_size(data_buffer_size), flush_fn(flush_fn) {} LogBuffer(void *data_buffer, size_t data_buffer_size, FlushFunction flush_func, LogBuffer *second_log_buffer) : data_buffer(data_buffer), second_log_buffer(second_log_buffer), main_target_buffer(this), sub_target_buffer(second_log_buffer), data_buffer_size(data_buffer_size), flush_func(flush_func) {}
bool Log(const void *log_data, size_t log_data_size, bool flush); bool Log(const void *log_data, size_t log_data_size, bool flush);
bool Flush(); bool Flush();
inline bool DoFlush(LogBuffer *log_buffer) { inline bool DoFlush(LogBuffer *log_buffer) {
auto ok = this->flush_fn(log_buffer->data_buffer, log_buffer->current_data_size); auto ok = this->flush_func(log_buffer->data_buffer, log_buffer->current_data_size);
if (ok) { if (ok) {
this->sub_target_buffer->current_data_size = 0; this->sub_target_buffer->current_data_size = 0;
} }

View file

@ -27,20 +27,20 @@ namespace ams::lm::impl {
os::SdkConditionVariable some_cond_var; os::SdkConditionVariable some_cond_var;
os::Event finalize_event; os::Event finalize_event;
os::SdkMutex some_cond_var_lock; os::SdkMutex some_cond_var_lock;
os::SdkMutex update_enabled_fn_lock; os::SdkMutex update_enabled_func_lock;
std::atomic_int htcs_server_fd; std::atomic_int htcs_server_fd;
std::atomic_int htcs_client_fd; std::atomic_int htcs_client_fd;
UpdateEnabledFunction update_enabled_fn; UpdateEnabledFunction update_enabled_func;
public: public:
LogServerProxy() : htcs_thread_stack{}, htcs_thread(), some_cond_var(), finalize_event(os::EventClearMode_ManualClear), some_cond_var_lock(), update_enabled_fn_lock(), htcs_server_fd(INT_MAX), htcs_client_fd(INT_MAX), update_enabled_fn(nullptr) /*, data_4(0), data_5{}*/ {} LogServerProxy() : htcs_thread_stack{}, htcs_thread(), some_cond_var(), finalize_event(os::EventClearMode_ManualClear), some_cond_var_lock(), update_enabled_func_lock(), htcs_server_fd(INT_MAX), htcs_client_fd(INT_MAX), update_enabled_func(nullptr) /*, data_4(0), data_5{}*/ {}
void StartHtcsThread(ThreadFunc htcs_entry); void StartHtcsThread(ThreadFunc htcs_entry);
void DisposeHtcsThread(); void DisposeHtcsThread();
bool LogOverHtcs(const void *log_data, size_t log_size); bool LogOverHtcs(const void *log_data, size_t log_size);
void SetUpdateEnabledFunction(UpdateEnabledFunction update_enabled_fn) { void SetUpdateEnabledFunction(UpdateEnabledFunction update_enabled_func) {
std::scoped_lock lk(this->update_enabled_fn_lock); std::scoped_lock lk(this->update_enabled_func_lock);
this->update_enabled_fn = update_enabled_fn; this->update_enabled_func = update_enabled_func;
} }
inline void SetHtcsClientFd(int fd) { inline void SetHtcsClientFd(int fd) {
@ -61,9 +61,9 @@ namespace ams::lm::impl {
} }
void SetEnabled(bool enabled) { void SetEnabled(bool enabled) {
std::scoped_lock lk(this->update_enabled_fn_lock); std::scoped_lock lk(this->update_enabled_func_lock);
if (this->update_enabled_fn) { if (this->update_enabled_func) {
this->update_enabled_fn(enabled); this->update_enabled_func(enabled);
} }
} }
}; };

View file

@ -29,15 +29,15 @@ namespace ams::lm::impl {
NON_COPYABLE(SdCardLogging); NON_COPYABLE(SdCardLogging);
NON_MOVEABLE(SdCardLogging); NON_MOVEABLE(SdCardLogging);
private: private:
os::SdkMutex update_enabled_fn_lock; os::SdkMutex update_enabled_func_lock;
bool enabled; bool enabled;
bool sd_card_mounted; bool sd_card_mounted;
bool sd_card_ok; bool sd_card_ok;
char log_file_path[0x80]; char log_file_path[0x80];
size_t log_file_offset; size_t log_file_offset;
UpdateEnabledFunction update_enabled_fn; UpdateEnabledFunction update_enabled_func;
public: public:
SdCardLogging() : update_enabled_fn_lock(), enabled(false), sd_card_mounted(false), sd_card_ok(false), log_file_path{}, log_file_offset(0), update_enabled_fn(nullptr) {} SdCardLogging() : update_enabled_func_lock(), enabled(false), sd_card_mounted(false), sd_card_ok(false), log_file_path{}, log_file_offset(0), update_enabled_func(nullptr) {}
bool Initialize(); bool Initialize();
void Dispose(); void Dispose();
@ -45,18 +45,18 @@ namespace ams::lm::impl {
bool SaveLog(const void *log_data, size_t log_data_size); bool SaveLog(const void *log_data, size_t log_data_size);
void SetEnabled(bool enabled) { void SetEnabled(bool enabled) {
std::scoped_lock lk(this->update_enabled_fn_lock); std::scoped_lock lk(this->update_enabled_func_lock);
if (this->enabled != enabled) { if (this->enabled != enabled) {
this->enabled = enabled; this->enabled = enabled;
if (this->update_enabled_fn) { if (this->update_enabled_func) {
this->update_enabled_fn(enabled); this->update_enabled_func(enabled);
} }
} }
} }
void SetUpdateEnabledFunction(UpdateEnabledFunction update_enabled_fn) { void SetUpdateEnabledFunction(UpdateEnabledFunction update_enabled_func) {
std::scoped_lock lk(this->update_enabled_fn_lock); std::scoped_lock lk(this->update_enabled_func_lock);
this->update_enabled_fn = update_enabled_fn; this->update_enabled_func = update_enabled_func;
} }
}; };