2018-01-13 21:22:39 +00:00
|
|
|
// Copyright 2018 yuzu emulator team
|
2017-10-15 02:18:42 +00:00
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2017-10-19 01:41:24 +00:00
|
|
|
#include <string>
|
2017-10-15 02:18:42 +00:00
|
|
|
#include "common/logging/log.h"
|
|
|
|
#include "core/hle/ipc_helpers.h"
|
2017-10-19 01:41:24 +00:00
|
|
|
#include "core/hle/kernel/client_session.h"
|
2017-10-15 02:18:42 +00:00
|
|
|
#include "core/hle/service/lm/lm.h"
|
|
|
|
|
|
|
|
namespace Service {
|
|
|
|
namespace LM {
|
|
|
|
|
2017-10-19 01:41:24 +00:00
|
|
|
class Logger final : public ServiceFramework<Logger> {
|
|
|
|
public:
|
|
|
|
Logger() : ServiceFramework("Logger") {
|
|
|
|
static const FunctionInfo functions[] = {
|
|
|
|
{0x00000000, &Logger::Log, "Log"},
|
|
|
|
};
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
|
|
|
|
|
|
|
~Logger() = default;
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct MessageHeader {
|
2018-01-05 05:45:13 +00:00
|
|
|
enum Flags : u32_le {
|
|
|
|
IsHead = 1,
|
|
|
|
IsTail = 2,
|
|
|
|
};
|
|
|
|
|
2017-10-19 01:41:24 +00:00
|
|
|
u64_le pid;
|
|
|
|
u64_le threadContext;
|
|
|
|
union {
|
2018-01-05 05:45:13 +00:00
|
|
|
BitField<0, 16, Flags> flags;
|
2017-10-19 01:41:24 +00:00
|
|
|
BitField<16, 8, u32_le> severity;
|
|
|
|
BitField<24, 8, u32_le> verbosity;
|
|
|
|
};
|
|
|
|
u32_le payload_size;
|
2018-01-06 19:41:56 +00:00
|
|
|
|
|
|
|
/// Returns true if this is part of a single log message
|
|
|
|
bool IsSingleMessage() const {
|
|
|
|
return (flags & Flags::IsHead) && (flags & Flags::IsTail);
|
|
|
|
}
|
2017-10-19 01:41:24 +00:00
|
|
|
};
|
2018-01-05 05:45:13 +00:00
|
|
|
static_assert(sizeof(MessageHeader) == 0x18, "MessageHeader is incorrect size");
|
|
|
|
|
|
|
|
/// Log field type
|
|
|
|
enum class Field : u8 {
|
2018-01-18 05:08:38 +00:00
|
|
|
Skip = 1,
|
2018-01-05 05:45:13 +00:00
|
|
|
Message = 2,
|
|
|
|
Line = 3,
|
|
|
|
Filename = 4,
|
|
|
|
Function = 5,
|
|
|
|
Module = 6,
|
|
|
|
Thread = 7,
|
|
|
|
};
|
2017-10-19 01:41:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* LM::Initialize service function
|
|
|
|
* Inputs:
|
|
|
|
* 0: 0x00000000
|
|
|
|
* Outputs:
|
|
|
|
* 0: ResultCode
|
|
|
|
*/
|
|
|
|
void Log(Kernel::HLERequestContext& ctx) {
|
2018-01-05 05:45:13 +00:00
|
|
|
// This function only succeeds - Get that out of the way
|
2018-01-24 00:52:18 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2018-01-05 05:45:13 +00:00
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
|
|
|
|
// Read MessageHeader, despite not doing anything with it right now
|
2017-10-19 01:41:24 +00:00
|
|
|
MessageHeader header{};
|
2018-01-05 05:45:13 +00:00
|
|
|
VAddr addr{ctx.BufferDescriptorX()[0].Address()};
|
|
|
|
const VAddr end_addr{addr + ctx.BufferDescriptorX()[0].size};
|
|
|
|
Memory::ReadBlock(addr, &header, sizeof(MessageHeader));
|
|
|
|
addr += sizeof(MessageHeader);
|
2017-10-19 01:41:24 +00:00
|
|
|
|
2018-01-06 19:41:56 +00:00
|
|
|
if (!header.IsSingleMessage()) {
|
2018-02-05 03:41:55 +00:00
|
|
|
LOG_WARNING(Service_LM, "Multi message logs are unimplemeneted");
|
2018-01-09 20:14:21 +00:00
|
|
|
return;
|
2018-01-06 19:41:56 +00:00
|
|
|
}
|
|
|
|
|
2018-01-05 05:45:13 +00:00
|
|
|
// Parse out log metadata
|
|
|
|
u32 line{};
|
|
|
|
std::string message, filename, function;
|
|
|
|
while (addr < end_addr) {
|
|
|
|
const Field field{static_cast<Field>(Memory::Read8(addr++))};
|
|
|
|
size_t length{Memory::Read8(addr++)};
|
2018-01-18 05:08:38 +00:00
|
|
|
|
|
|
|
if (static_cast<Field>(Memory::Read8(addr)) == Field::Skip) {
|
|
|
|
++addr;
|
|
|
|
}
|
|
|
|
|
2018-01-05 05:45:13 +00:00
|
|
|
switch (field) {
|
|
|
|
case Field::Message:
|
|
|
|
message = Memory::ReadCString(addr, length);
|
|
|
|
break;
|
|
|
|
case Field::Line:
|
|
|
|
line = Memory::Read32(addr);
|
|
|
|
break;
|
|
|
|
case Field::Filename:
|
|
|
|
filename = Memory::ReadCString(addr, length);
|
|
|
|
break;
|
|
|
|
case Field::Function:
|
|
|
|
function = Memory::ReadCString(addr, length);
|
|
|
|
break;
|
|
|
|
}
|
2018-01-18 05:08:38 +00:00
|
|
|
|
2018-01-05 05:45:13 +00:00
|
|
|
addr += length;
|
|
|
|
}
|
2017-10-19 01:41:24 +00:00
|
|
|
|
2018-01-05 05:45:13 +00:00
|
|
|
// Empty log - nothing to do here
|
2018-01-09 20:14:21 +00:00
|
|
|
if (message.empty()) {
|
2018-01-05 05:45:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Format a nicely printable string out of the log metadata
|
|
|
|
std::string output;
|
|
|
|
if (filename.size()) {
|
|
|
|
output += filename + ':';
|
|
|
|
}
|
|
|
|
if (function.size()) {
|
|
|
|
output += function + ':';
|
|
|
|
}
|
|
|
|
if (line) {
|
|
|
|
output += std::to_string(line) + ':';
|
|
|
|
}
|
2018-02-05 03:36:57 +00:00
|
|
|
if (output.length() > 0 && output.back() == ':') {
|
2018-01-05 05:45:13 +00:00
|
|
|
output += ' ';
|
|
|
|
}
|
|
|
|
output += message;
|
|
|
|
|
2018-01-24 00:43:59 +00:00
|
|
|
LOG_INFO(Debug_Emulated, "%s", output.c_str());
|
2017-10-19 01:41:24 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-10-15 02:18:42 +00:00
|
|
|
void InstallInterfaces(SM::ServiceManager& service_manager) {
|
|
|
|
std::make_shared<LM>()->InstallAsService(service_manager);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-10-15 02:50:04 +00:00
|
|
|
* LM::Initialize service function
|
2017-10-15 02:18:42 +00:00
|
|
|
* Inputs:
|
|
|
|
* 0: 0x00000000
|
|
|
|
* Outputs:
|
2017-10-15 05:24:22 +00:00
|
|
|
* 0: ResultCode
|
2017-10-15 02:18:42 +00:00
|
|
|
*/
|
|
|
|
void LM::Initialize(Kernel::HLERequestContext& ctx) {
|
2018-01-24 00:52:18 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
2018-01-22 22:35:40 +00:00
|
|
|
rb.Push(RESULT_SUCCESS);
|
2018-01-24 00:43:59 +00:00
|
|
|
rb.PushIpcInterface<Logger>();
|
2017-10-19 01:41:24 +00:00
|
|
|
|
2018-02-05 03:41:55 +00:00
|
|
|
LOG_DEBUG(Service_LM, "called");
|
2017-10-15 02:18:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LM::LM() : ServiceFramework("lm") {
|
|
|
|
static const FunctionInfo functions[] = {
|
|
|
|
{0x00000000, &LM::Initialize, "Initialize"},
|
|
|
|
};
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace LM
|
|
|
|
} // namespace Service
|