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