mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-04-22 04:24:48 +00:00
Some changes
This commit is contained in:
parent
519bf31ec7
commit
2159b52c89
22 changed files with 136 additions and 155 deletions
|
@ -121,6 +121,7 @@ namespace ams::impl {
|
|||
AMS_DEFINE_SYSTEM_THREAD(21, pgl, ProcessControlTask);
|
||||
|
||||
/* lm. */
|
||||
AMS_DEFINE_SYSTEM_THREAD(10, lm, MainThread);
|
||||
AMS_DEFINE_SYSTEM_THREAD(10, lm, IpcServer);
|
||||
AMS_DEFINE_SYSTEM_THREAD(10, lm, Flush);
|
||||
AMS_DEFINE_SYSTEM_THREAD(10, lm, HtcsConnection);
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stratosphere/diag/diag_log_observer.hpp>
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
|
||||
namespace ams::diag::detail {
|
||||
|
||||
void LogImpl(const LogMetaData &log_metadata, const char *fmt, ...);
|
||||
void VLogImpl(const LogMetaData &log_metadata, const char *fmt, std::va_list va_args);
|
||||
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 CallAllLogObserver(const LogMetaData &log_metadata, const LogBody &log_body);
|
||||
|
||||
#define AMS_LOG(fmt, ...) ({ \
|
||||
|
@ -27,9 +27,9 @@ namespace ams::diag::detail {
|
|||
.source_info = { \
|
||||
.line_number = __LINE__, \
|
||||
.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__); \
|
||||
})
|
||||
|
|
|
@ -18,21 +18,21 @@
|
|||
|
||||
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;
|
||||
LogObserverHolder *next;
|
||||
bool is_registered;
|
||||
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 UnregisterLogObserver(LogObserverHolder *observer_holder);
|
||||
|
||||
void ResetDefaultLogObserver();
|
||||
void ReplaceDefaultLogObserver(LogObserverHolder::LogFunction log_function);
|
||||
void ReplaceDefaultLogObserver(LogFunction log_function);
|
||||
|
||||
}
|
||||
|
|
|
@ -19,13 +19,13 @@
|
|||
namespace ams::diag {
|
||||
|
||||
enum LogSeverity : u8 {
|
||||
LogSeverity_Trace,
|
||||
LogSeverity_Info,
|
||||
LogSeverity_Warn,
|
||||
LogSeverity_Error,
|
||||
LogSeverity_Fatal,
|
||||
LogSeverity_Trace = 0,
|
||||
LogSeverity_Info = 1,
|
||||
LogSeverity_Warn = 2,
|
||||
LogSeverity_Error = 3,
|
||||
LogSeverity_Fatal = 4,
|
||||
|
||||
LogSeverity_Count
|
||||
LogSeverity_Count = 5,
|
||||
};
|
||||
|
||||
struct SourceInfo {
|
||||
|
@ -45,10 +45,10 @@ namespace ams::diag {
|
|||
};
|
||||
|
||||
struct LogBody {
|
||||
const char *log_text;
|
||||
size_t log_text_length;
|
||||
bool log_is_head;
|
||||
bool log_is_tail;
|
||||
const char *text;
|
||||
size_t text_length;
|
||||
bool is_head;
|
||||
bool is_tail;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace ams::lm::detail {
|
|||
NON_COPYABLE(LogPacketTransmitterBase);
|
||||
NON_MOVEABLE(LogPacketTransmitterBase);
|
||||
public:
|
||||
using FlushFunction = bool (*)(const void*, size_t);
|
||||
using FlushFunction = bool (*)(const u8*, size_t);
|
||||
private:
|
||||
LogPacketHeader *header;
|
||||
u8 *log_buffer_start;
|
||||
|
@ -32,7 +32,7 @@ namespace ams::lm::detail {
|
|||
bool is_tail;
|
||||
FlushFunction flush_function;
|
||||
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() {
|
||||
this->Flush(this->is_tail);
|
||||
|
@ -73,13 +73,13 @@ namespace ams::lm::detail {
|
|||
using LogPacketTransmitterBase::LogPacketTransmitterBase;
|
||||
|
||||
void PushLogSessionBegin() {
|
||||
u8 dummy_value = 1;
|
||||
this->PushDataChunk(LogDataChunkKey_LogSessionBegin, std::addressof(dummy_value), sizeof(dummy_value));
|
||||
bool value = true;
|
||||
this->PushDataChunk(LogDataChunkKey_LogSessionBegin, std::addressof(value), sizeof(value));
|
||||
}
|
||||
|
||||
void PushLogSessionEnd() {
|
||||
u8 dummy_value = 1;
|
||||
this->PushDataChunk(LogDataChunkKey_LogSessionEnd, std::addressof(dummy_value), sizeof(dummy_value));
|
||||
bool value = true;
|
||||
this->PushDataChunk(LogDataChunkKey_LogSessionEnd, std::addressof(value), sizeof(value));
|
||||
}
|
||||
|
||||
void PushTextLog(const char *log, size_t log_len) {
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace ams::lm::detail {
|
|||
};
|
||||
|
||||
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;
|
||||
u8 version;
|
||||
|
@ -37,8 +37,8 @@ namespace ams::lm::detail {
|
|||
u64 thread_id;
|
||||
u8 flags;
|
||||
u8 pad;
|
||||
diag::LogSeverity severity;
|
||||
char verbosity;
|
||||
u8 severity;
|
||||
u8 verbosity;
|
||||
u32 payload_size;
|
||||
|
||||
constexpr inline u64 GetProcessId() const {
|
||||
|
@ -60,17 +60,16 @@ namespace ams::lm::detail {
|
|||
constexpr inline void SetLittleEndian(bool le) {
|
||||
if (le) {
|
||||
this->flags |= LogPacketFlags_LittleEndian;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
this->flags &= ~LogPacketFlags_LittleEndian;
|
||||
}
|
||||
}
|
||||
|
||||
constexpr inline void SetSeverity(diag::LogSeverity severity) {
|
||||
constexpr inline void SetSeverity(u8 severity) {
|
||||
this->severity = severity;
|
||||
}
|
||||
|
||||
constexpr inline void SetVerbosity(char verbosity) {
|
||||
constexpr inline void SetVerbosity(u8 verbosity) {
|
||||
this->verbosity = verbosity;
|
||||
}
|
||||
|
||||
|
@ -81,8 +80,7 @@ namespace ams::lm::detail {
|
|||
constexpr inline void SetHead(bool head) {
|
||||
if (head) {
|
||||
this->flags |= LogPacketFlags_Head;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
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 {
|
||||
LogDataChunkKey_LogSessionBegin = 0, ///< Log session begin.
|
||||
LogDataChunkKey_LogSessionEnd = 1, ///< Log session end.
|
||||
LogDataChunkKey_TextLog = 2, ///< Text to be logged.
|
||||
LogDataChunkKey_LineNumber = 3, ///< Source line number.
|
||||
LogDataChunkKey_FileName = 4, ///< Source file name.
|
||||
LogDataChunkKey_FunctionName = 5, ///< Source function name.
|
||||
LogDataChunkKey_ModuleName = 6, ///< Process module name.
|
||||
LogDataChunkKey_ThreadName = 7, ///< Process thread name.
|
||||
LogDataChunkKey_LogPacketDropCount = 8, ///< Log packet drop count.
|
||||
LogDataChunkKey_UserSystemClock = 9, ///< User system clock.
|
||||
LogDataChunkKey_ProcessName = 10, ///< Process name.
|
||||
LogDataChunkKey_LogSessionBegin = 0,
|
||||
LogDataChunkKey_LogSessionEnd = 1,
|
||||
LogDataChunkKey_TextLog = 2,
|
||||
LogDataChunkKey_LineNumber = 3,
|
||||
LogDataChunkKey_FileName = 4,
|
||||
LogDataChunkKey_FunctionName = 5,
|
||||
LogDataChunkKey_ModuleName = 6,
|
||||
LogDataChunkKey_ThreadName = 7,
|
||||
LogDataChunkKey_LogPacketDropCount = 8,
|
||||
LogDataChunkKey_UserSystemClock = 9,
|
||||
LogDataChunkKey_ProcessName = 10,
|
||||
};
|
||||
|
||||
}
|
|
@ -13,7 +13,6 @@
|
|||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace ams::lm {
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace ams::diag::detail {
|
|||
|
||||
constexpr const char *g_log_severity_color_table[LogSeverity_Count] = {
|
||||
"\x1B[90m", /* Dark gray for Trace. */
|
||||
"", /* No special color for Info. */
|
||||
nullptr, /* No special color for Info. */
|
||||
"\x1B[33m", /* Yellow for Warn. */
|
||||
"\x1B[31m", /* Red for Error. */
|
||||
"\x1B[41m\x1B[37m" /* White + red for Fatal. */
|
||||
|
@ -41,51 +41,41 @@ namespace ams::diag::detail {
|
|||
if (log_metadata.log_severity < LogSeverity_Count) {
|
||||
color_type = g_log_severity_color_table[log_metadata.log_severity];
|
||||
}
|
||||
auto has_module_name = false;
|
||||
if (log_metadata.module_name != nullptr) {
|
||||
has_module_name = strlen(log_metadata.module_name) > 1; /* Avoid '$' as module name. */
|
||||
}
|
||||
|
||||
/* 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) {
|
||||
/* Just send the text log. */
|
||||
PrintDebugString(log_body.log_text, log_body.log_text_length);
|
||||
return;
|
||||
return PrintDebugString(log_body.text, log_body.text_length);
|
||||
}
|
||||
|
||||
size_t used_buffer_space = 0;
|
||||
if (has_module_name && log_body.log_is_head) {
|
||||
auto fmt_prefix = (color_type != nullptr) ? color_type : "";
|
||||
if (has_module_name && log_body.is_head) {
|
||||
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] == '$') {
|
||||
/* Skip logging this initial character if it's present. */
|
||||
module_name++;
|
||||
}
|
||||
|
||||
auto system_tick = 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_ts.GetHours(), tick_ts.GetMinutes(), tick_ts.GetSeconds(), tick_ts.GetMilliSeconds(), module_name);
|
||||
}
|
||||
else if (color_type) {
|
||||
const auto tick = os::ConvertToTimeSpan(os::GetSystemTick());
|
||||
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);
|
||||
} else if (color_type != nullptr) {
|
||||
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;
|
||||
if (color_type) {
|
||||
/* Also subtract the size of the color formatting, if present. */
|
||||
left_buffer_space -= strlen(color_type);
|
||||
}
|
||||
const auto max_buffer_size = sizeof(g_default_log_observer_text_buffer) - used_buffer_space - (color_type != nullptr ? std::strlen(color_type) - 1 : 0);
|
||||
|
||||
auto log_text_size = std::min(left_buffer_space, log_body.log_text_length);
|
||||
if (log_body.log_text_length && (log_body.log_text[log_body.log_text_length - 1] == '\n')) {
|
||||
const 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 the last character is a newline character, skip it. */
|
||||
log_text_size--;
|
||||
}
|
||||
|
||||
/* 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, left_buffer_space, "%.*s%s%s", log_text_size, log_body.log_text, fmt_prefix);
|
||||
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" : "");
|
||||
PrintDebugString(g_default_log_observer_text_buffer, used_buffer_space);
|
||||
}
|
||||
|
||||
|
|
|
@ -53,10 +53,10 @@ namespace ams::diag::detail {
|
|||
*print_str_cur_end = '\0';
|
||||
|
||||
const LogBody log_body = {
|
||||
.log_text = print_data->print_str_start,
|
||||
.log_text_length = actual_print_str_len,
|
||||
.log_is_head = print_data->is_head,
|
||||
.log_is_tail = false,
|
||||
.text = print_data->print_str_start,
|
||||
.text_length = actual_print_str_len,
|
||||
.is_head = print_data->is_head,
|
||||
.is_tail = false,
|
||||
};
|
||||
CallAllLogObserver(print_data->log_metadata, log_body);
|
||||
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';
|
||||
|
||||
const LogBody log_body = {
|
||||
.log_text = print_data->print_str_start,
|
||||
.log_text_length = static_cast<size_t>(print_data->print_str_cur - print_data->print_str_start),
|
||||
.log_is_head = print_data->is_head,
|
||||
.log_is_tail = false,
|
||||
.text = print_data->print_str_start,
|
||||
.text_length = static_cast<size_t>(print_data->print_str_cur - print_data->print_str_start),
|
||||
.is_head = print_data->is_head,
|
||||
.is_tail = false,
|
||||
};
|
||||
CallAllLogObserver(print_data->log_metadata, log_body);
|
||||
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);
|
||||
|
||||
const LogBody log_body = {
|
||||
.log_text = print_data.print_str_start,
|
||||
.log_text_length = static_cast<size_t>(print_data.print_str_cur - print_data.print_str_start),
|
||||
.log_is_head = print_data.is_head,
|
||||
.log_is_tail = true,
|
||||
.text = print_data.print_str_start,
|
||||
.text_length = static_cast<size_t>(print_data.print_str_cur - print_data.print_str_start),
|
||||
.is_head = print_data.is_head,
|
||||
.is_tail = true,
|
||||
};
|
||||
CallAllLogObserver(print_data.log_metadata, log_body);
|
||||
}
|
||||
|
|
|
@ -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->next = nullptr;
|
||||
observer_holder->is_registered = false;
|
||||
|
@ -80,7 +80,7 @@ namespace ams::diag {
|
|||
ReplaceDefaultLogObserver(detail::DefaultLogObserver);
|
||||
}
|
||||
|
||||
void ReplaceDefaultLogObserver(LogObserverHolder::LogFunction log_function) {
|
||||
void ReplaceDefaultLogObserver(LogFunction log_function) {
|
||||
UnregisterLogObserver(std::addressof(detail::g_default_log_observer));
|
||||
InitializeLogObserverHolder(std::addressof(detail::g_default_log_observer), log_function, nullptr);
|
||||
RegisterLogObserver(std::addressof(detail::g_default_log_observer));
|
||||
|
|
|
@ -35,52 +35,46 @@ namespace ams::lm::detail {
|
|||
AMS_ASSERT(!log_metadata.use_default_locale_charset);
|
||||
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);
|
||||
if (log_body.log_is_head) {
|
||||
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.is_head) {
|
||||
/* Push time. */
|
||||
auto system_tick = os::GetSystemTick();
|
||||
auto tick_ts = os::ConvertToTimeSpan(system_tick);
|
||||
packet_transmitter.PushUserSystemClock(static_cast<u64>(tick_ts.GetSeconds()));
|
||||
packet_transmitter.PushUserSystemClock(static_cast<u64>(os::ConvertToTimeSpan(os::GetSystemTick()).GetSeconds()));
|
||||
|
||||
/* Push line number. */
|
||||
auto line_number = log_metadata.source_info.line_number;
|
||||
packet_transmitter.PushLineNumber(line_number);
|
||||
packet_transmitter.PushLineNumber(log_metadata.source_info.line_number);
|
||||
|
||||
/* Push file name. */
|
||||
auto file_name = log_metadata.source_info.file_name;
|
||||
auto file_name_len = strlen(file_name);
|
||||
if (file_name /* && !util::VerifyUtf8String(file_name, file_name_len) */) {
|
||||
file_name = DefaultInvalidString;
|
||||
file_name_len = __builtin_strlen(DefaultInvalidString);
|
||||
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)) */) {
|
||||
packet_transmitter.PushFileName(DefaultInvalidString, __builtin_strlen(DefaultInvalidString));
|
||||
}
|
||||
else {
|
||||
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. */
|
||||
auto function_name = log_metadata.source_info.function_name;
|
||||
auto function_name_len = strlen(function_name);
|
||||
if (function_name /* && !util::VerifyUtf8String(function_name, function_name_len) */) {
|
||||
function_name = DefaultInvalidString;
|
||||
function_name_len = __builtin_strlen(DefaultInvalidString);
|
||||
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)) */) {
|
||||
packet_transmitter.PushFunctionName(DefaultInvalidString, __builtin_strlen(DefaultInvalidString));
|
||||
}
|
||||
else {
|
||||
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. */
|
||||
auto module_name = log_metadata.module_name;
|
||||
auto module_name_len = strlen(module_name);
|
||||
if (module_name /* && !util::VerifyUtf8String(module_name, module_name_len) */) {
|
||||
module_name = DefaultInvalidString;
|
||||
module_name_len = __builtin_strlen(DefaultInvalidString);
|
||||
if (std::strlen(log_metadata.module_name) /* && !util::VerifyUtf8String(log_metadata.module_name, std::strlen(log_metadata.module_name)) */) {
|
||||
packet_transmitter.PushModuleName(DefaultInvalidString, __builtin_strlen(DefaultInvalidString));
|
||||
}
|
||||
else {
|
||||
packet_transmitter.PushModuleName(log_metadata.module_name, std::strlen(log_metadata.module_name));
|
||||
}
|
||||
packet_transmitter.PushModuleName(module_name, module_name_len);
|
||||
|
||||
/* Push thread name. */
|
||||
auto thread_name = os::GetThreadNamePointer(os::GetCurrentThread());
|
||||
auto thread_name_len = strlen(thread_name);
|
||||
if (thread_name /* && !util::VerifyUtf8String(thread_name, thread_name_len) */) {
|
||||
thread_name = DefaultInvalidString;
|
||||
thread_name_len = __builtin_strlen(DefaultInvalidString);
|
||||
const auto thread_name = os::GetThreadNamePointer(os::GetCurrentThread());
|
||||
if (std::strlen(thread_name) /* && !util::VerifyUtf8String(thread_name, std::strlen(thread_name)) */) {
|
||||
packet_transmitter.PushThreadName(DefaultInvalidString, __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. */
|
||||
/*
|
||||
|
@ -92,7 +86,7 @@ namespace ams::lm::detail {
|
|||
}
|
||||
|
||||
/* 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. */
|
||||
}
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
|
||||
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_size > sizeof(LogPacketHeader));
|
||||
AMS_ABORT_UNLESS(flush_fn != nullptr);
|
||||
AMS_ABORT_UNLESS(flush_func != nullptr);
|
||||
|
||||
this->header = reinterpret_cast<LogPacketHeader*>(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_current = log_buffer + sizeof(LogPacketHeader);
|
||||
this->is_tail = tail;
|
||||
this->flush_function = flush_fn;
|
||||
this->flush_function = flush_func;
|
||||
this->header->SetProcessId(process_id);
|
||||
|
||||
auto current_thread = os::GetCurrentThread();
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace ams::util {
|
|||
|
||||
using PrintFunction = void (*)(void *user_data, const char *str, int unk);
|
||||
|
||||
void FormatString(PrintFunction print_fn, void *user_data, const char *fmt, ...);
|
||||
void VFormatString(PrintFunction print_fn, void *user_data, const char *fmt, std::va_list vl);
|
||||
void FormatString(PrintFunction print_func, void *user_data, const char *fmt, ...);
|
||||
void VFormatString(PrintFunction print_func, void *user_data, const char *fmt, std::va_list vl);
|
||||
|
||||
}
|
|
@ -431,14 +431,14 @@ namespace ams::util {
|
|||
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;
|
||||
va_start(vl, fmt);
|
||||
VFormatString(print_fn, user_data, fmt, vl);
|
||||
VFormatString(print_func, user_data, fmt, 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 */
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ namespace ams::lm::impl {
|
|||
}
|
||||
|
||||
/* 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) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -27,10 +27,10 @@ namespace ams::lm::impl {
|
|||
u8 *log_data_buffer;
|
||||
size_t size;
|
||||
size_t cur_offset;
|
||||
FlushFunction flush_fn;
|
||||
FlushFunction flush_func;
|
||||
bool expects_more_packets;
|
||||
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 Log(const void *log_data, size_t size);
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace ams::lm::impl {
|
|||
/* ------------ 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);
|
||||
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();
|
||||
|
||||
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 */
|
||||
constexpr auto log_buffer_size = sizeof(detail::LogPacketHeader) + 2 + sizeof(u8);
|
||||
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();
|
||||
|
||||
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 */
|
||||
constexpr auto log_buffer_size = sizeof(detail::LogPacketHeader) + 2 + sizeof(this->log_packet_drop_count);
|
||||
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);
|
||||
|
||||
const auto ok = log_packet_transmitter.Flush(true);
|
||||
|
|
|
@ -22,11 +22,11 @@ namespace ams::lm::impl {
|
|||
NON_COPYABLE(EventLogTransmitter);
|
||||
NON_MOVEABLE(EventLogTransmitter);
|
||||
private:
|
||||
detail::LogPacketTransmitter::FlushFunction flush_fn;
|
||||
detail::LogPacketTransmitter::FlushFunction flush_func;
|
||||
u64 log_packet_drop_count;
|
||||
os::SdkMutex log_packet_drop_count_lock;
|
||||
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 SendLogSessionEndPacket(u64 process_id);
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace ams::lm::impl {
|
|||
LogBuffer *main_target_buffer;
|
||||
LogBuffer *sub_target_buffer;
|
||||
size_t data_buffer_size;
|
||||
FlushFunction flush_fn;
|
||||
FlushFunction flush_func;
|
||||
os::SdkMutex main_target_buffer_lock;
|
||||
os::SdkMutex sub_target_buffer_lock;
|
||||
os::SdkConditionVariable flush_done_cv;
|
||||
|
@ -39,13 +39,13 @@ namespace ams::lm::impl {
|
|||
bool some_flag;
|
||||
uint64_t some_count_2;
|
||||
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 Flush();
|
||||
|
||||
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) {
|
||||
this->sub_target_buffer->current_data_size = 0;
|
||||
}
|
||||
|
|
|
@ -27,20 +27,20 @@ namespace ams::lm::impl {
|
|||
os::SdkConditionVariable some_cond_var;
|
||||
os::Event finalize_event;
|
||||
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_client_fd;
|
||||
UpdateEnabledFunction update_enabled_fn;
|
||||
UpdateEnabledFunction update_enabled_func;
|
||||
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 DisposeHtcsThread();
|
||||
bool LogOverHtcs(const void *log_data, size_t log_size);
|
||||
|
||||
void SetUpdateEnabledFunction(UpdateEnabledFunction update_enabled_fn) {
|
||||
std::scoped_lock lk(this->update_enabled_fn_lock);
|
||||
this->update_enabled_fn = update_enabled_fn;
|
||||
void SetUpdateEnabledFunction(UpdateEnabledFunction update_enabled_func) {
|
||||
std::scoped_lock lk(this->update_enabled_func_lock);
|
||||
this->update_enabled_func = update_enabled_func;
|
||||
}
|
||||
|
||||
inline void SetHtcsClientFd(int fd) {
|
||||
|
@ -61,9 +61,9 @@ namespace ams::lm::impl {
|
|||
}
|
||||
|
||||
void SetEnabled(bool enabled) {
|
||||
std::scoped_lock lk(this->update_enabled_fn_lock);
|
||||
if (this->update_enabled_fn) {
|
||||
this->update_enabled_fn(enabled);
|
||||
std::scoped_lock lk(this->update_enabled_func_lock);
|
||||
if (this->update_enabled_func) {
|
||||
this->update_enabled_func(enabled);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -29,15 +29,15 @@ namespace ams::lm::impl {
|
|||
NON_COPYABLE(SdCardLogging);
|
||||
NON_MOVEABLE(SdCardLogging);
|
||||
private:
|
||||
os::SdkMutex update_enabled_fn_lock;
|
||||
os::SdkMutex update_enabled_func_lock;
|
||||
bool enabled;
|
||||
bool sd_card_mounted;
|
||||
bool sd_card_ok;
|
||||
char log_file_path[0x80];
|
||||
size_t log_file_offset;
|
||||
UpdateEnabledFunction update_enabled_fn;
|
||||
UpdateEnabledFunction update_enabled_func;
|
||||
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();
|
||||
void Dispose();
|
||||
|
@ -45,18 +45,18 @@ namespace ams::lm::impl {
|
|||
bool SaveLog(const void *log_data, size_t log_data_size);
|
||||
|
||||
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) {
|
||||
this->enabled = enabled;
|
||||
if (this->update_enabled_fn) {
|
||||
this->update_enabled_fn(enabled);
|
||||
if (this->update_enabled_func) {
|
||||
this->update_enabled_func(enabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SetUpdateEnabledFunction(UpdateEnabledFunction update_enabled_fn) {
|
||||
std::scoped_lock lk(this->update_enabled_fn_lock);
|
||||
this->update_enabled_fn = update_enabled_fn;
|
||||
void SetUpdateEnabledFunction(UpdateEnabledFunction update_enabled_func) {
|
||||
std::scoped_lock lk(this->update_enabled_func_lock);
|
||||
this->update_enabled_func = update_enabled_func;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue