2018-01-13 16:22:39 -05:00
|
|
|
// Copyright 2018 yuzu emulator team
|
2017-10-14 22:18:42 -04:00
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2018-02-13 01:44:53 -05:00
|
|
|
#include <sstream>
|
2017-10-18 21:41:24 -04:00
|
|
|
#include <string>
|
2018-07-25 22:32:42 -04:00
|
|
|
|
2017-10-14 22:18:42 -04:00
|
|
|
#include "common/logging/log.h"
|
2019-06-29 17:17:35 -04:00
|
|
|
#include "common/scope_exit.h"
|
2020-11-08 15:49:45 -05:00
|
|
|
#include "core/core.h"
|
2017-10-14 22:18:42 -04:00
|
|
|
#include "core/hle/ipc_helpers.h"
|
|
|
|
#include "core/hle/service/lm/lm.h"
|
2019-06-29 17:17:35 -04:00
|
|
|
#include "core/hle/service/lm/manager.h"
|
2018-07-25 22:32:42 -04:00
|
|
|
#include "core/hle/service/service.h"
|
|
|
|
#include "core/memory.h"
|
2017-10-14 22:18:42 -04:00
|
|
|
|
2018-04-19 21:41:44 -04:00
|
|
|
namespace Service::LM {
|
2017-10-14 22:18:42 -04:00
|
|
|
|
2018-08-01 17:08:41 -04:00
|
|
|
class ILogger final : public ServiceFramework<ILogger> {
|
2017-10-18 21:41:24 -04:00
|
|
|
public:
|
2020-03-31 15:10:44 -04:00
|
|
|
explicit ILogger(Manager& manager_, Core::Memory::Memory& memory_)
|
2019-11-26 14:10:49 -05:00
|
|
|
: ServiceFramework("ILogger"), manager{manager_}, memory{memory_} {
|
2017-10-18 21:41:24 -04:00
|
|
|
static const FunctionInfo functions[] = {
|
2019-06-29 17:18:33 -04:00
|
|
|
{0, &ILogger::Log, "Log"},
|
|
|
|
{1, &ILogger::SetDestination, "SetDestination"},
|
2017-10-18 21:41:24 -04:00
|
|
|
};
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2019-06-29 17:18:33 -04:00
|
|
|
void Log(Kernel::HLERequestContext& ctx) {
|
2018-01-05 00:45:13 -05:00
|
|
|
// This function only succeeds - Get that out of the way
|
2018-01-23 19:52:18 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2018-01-05 00:45:13 -05:00
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
|
|
|
|
// Read MessageHeader, despite not doing anything with it right now
|
2017-10-18 21:41:24 -04:00
|
|
|
MessageHeader header{};
|
2018-01-05 00:45:13 -05:00
|
|
|
VAddr addr{ctx.BufferDescriptorX()[0].Address()};
|
|
|
|
const VAddr end_addr{addr + ctx.BufferDescriptorX()[0].size};
|
2019-11-26 16:29:34 -05:00
|
|
|
memory.ReadBlock(addr, &header, sizeof(MessageHeader));
|
2018-01-05 00:45:13 -05:00
|
|
|
addr += sizeof(MessageHeader);
|
2017-10-18 21:41:24 -04:00
|
|
|
|
2019-06-29 17:18:33 -04:00
|
|
|
FieldMap fields;
|
2018-01-05 00:45:13 -05:00
|
|
|
while (addr < end_addr) {
|
2019-11-26 16:29:34 -05:00
|
|
|
const auto field = static_cast<Field>(memory.Read8(addr++));
|
|
|
|
const auto length = memory.Read8(addr++);
|
2018-01-18 00:08:38 -05:00
|
|
|
|
2019-11-26 16:29:34 -05:00
|
|
|
if (static_cast<Field>(memory.Read8(addr)) == Field::Skip) {
|
2018-01-18 00:08:38 -05:00
|
|
|
++addr;
|
|
|
|
}
|
|
|
|
|
2019-06-29 17:18:33 -04:00
|
|
|
SCOPE_EXIT({ addr += length; });
|
2018-01-18 00:08:38 -05:00
|
|
|
|
2019-06-29 17:18:33 -04:00
|
|
|
if (field == Field::Skip) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-10-18 21:41:24 -04:00
|
|
|
|
2019-06-29 17:18:33 -04:00
|
|
|
std::vector<u8> data(length);
|
2019-11-26 16:29:34 -05:00
|
|
|
memory.ReadBlock(addr, data.data(), length);
|
2019-06-29 17:18:33 -04:00
|
|
|
fields.emplace(field, std::move(data));
|
2018-01-05 00:45:13 -05:00
|
|
|
}
|
|
|
|
|
2019-06-29 17:18:33 -04:00
|
|
|
manager.Log({header, std::move(fields)});
|
2017-10-18 21:41:24 -04:00
|
|
|
}
|
2018-02-13 01:44:53 -05:00
|
|
|
|
2018-11-19 18:00:11 -05:00
|
|
|
void SetDestination(Kernel::HLERequestContext& ctx) {
|
2019-06-29 17:18:33 -04:00
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
const auto destination = rp.PopEnum<DestinationFlag>();
|
|
|
|
|
|
|
|
LOG_DEBUG(Service_LM, "called, destination={:08X}", static_cast<u32>(destination));
|
|
|
|
|
|
|
|
manager.SetDestination(destination);
|
2018-11-19 18:00:11 -05:00
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2019-06-29 17:18:33 -04:00
|
|
|
Manager& manager;
|
2020-03-31 15:10:44 -04:00
|
|
|
Core::Memory::Memory& memory;
|
2017-10-18 21:41:24 -04:00
|
|
|
};
|
|
|
|
|
2018-07-25 22:32:42 -04:00
|
|
|
class LM final : public ServiceFramework<LM> {
|
|
|
|
public:
|
2020-03-31 15:10:44 -04:00
|
|
|
explicit LM(Manager& manager_, Core::Memory::Memory& memory_)
|
2019-11-26 14:10:49 -05:00
|
|
|
: ServiceFramework{"lm"}, manager{manager_}, memory{memory_} {
|
2019-06-29 17:17:35 -04:00
|
|
|
// clang-format off
|
2018-07-25 22:32:42 -04:00
|
|
|
static const FunctionInfo functions[] = {
|
2019-06-29 17:17:35 -04:00
|
|
|
{0, &LM::OpenLogger, "OpenLogger"},
|
2018-07-25 22:32:42 -04:00
|
|
|
};
|
2019-06-29 17:17:35 -04:00
|
|
|
// clang-format on
|
|
|
|
|
2018-07-25 22:32:42 -04:00
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
2017-10-14 22:18:42 -04:00
|
|
|
|
2019-06-29 17:17:35 -04:00
|
|
|
private:
|
2018-07-25 22:32:42 -04:00
|
|
|
void OpenLogger(Kernel::HLERequestContext& ctx) {
|
2018-11-26 01:06:13 -05:00
|
|
|
LOG_DEBUG(Service_LM, "called");
|
|
|
|
|
2018-07-25 22:32:42 -04:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
2019-11-26 14:10:49 -05:00
|
|
|
rb.PushIpcInterface<ILogger>(manager, memory);
|
2018-07-25 22:32:42 -04:00
|
|
|
}
|
2019-06-29 17:17:35 -04:00
|
|
|
|
|
|
|
Manager& manager;
|
2020-03-31 15:10:44 -04:00
|
|
|
Core::Memory::Memory& memory;
|
2018-07-25 22:32:42 -04:00
|
|
|
};
|
|
|
|
|
2019-06-29 17:17:35 -04:00
|
|
|
void InstallInterfaces(Core::System& system) {
|
2019-11-26 14:10:49 -05:00
|
|
|
std::make_shared<LM>(system.GetLogManager(), system.Memory())
|
|
|
|
->InstallAsService(system.ServiceManager());
|
2017-10-14 22:18:42 -04:00
|
|
|
}
|
|
|
|
|
2018-04-19 21:41:44 -04:00
|
|
|
} // namespace Service::LM
|