2018-01-13 18:22:39 -03:00
|
|
|
// Copyright 2018 yuzu emulator team
|
2017-10-14 23:18:42 -03:00
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2018-09-25 18:14:19 -03:00
|
|
|
#include "common/assert.h"
|
2017-10-14 23:18:42 -03:00
|
|
|
#include "common/logging/log.h"
|
2021-05-16 02:49:03 -04:00
|
|
|
#include "core/core.h"
|
2017-10-14 23:18:42 -03:00
|
|
|
#include "core/hle/ipc_helpers.h"
|
2021-05-16 02:49:03 -04:00
|
|
|
#include "core/hle/kernel/k_client_port.h"
|
2021-04-13 20:48:37 -04:00
|
|
|
#include "core/hle/kernel/k_client_session.h"
|
2021-05-16 02:49:03 -04:00
|
|
|
#include "core/hle/kernel/k_port.h"
|
|
|
|
#include "core/hle/kernel/k_scoped_resource_reservation.h"
|
|
|
|
#include "core/hle/kernel/k_server_port.h"
|
2021-04-13 20:48:37 -04:00
|
|
|
#include "core/hle/kernel/k_server_session.h"
|
|
|
|
#include "core/hle/kernel/k_session.h"
|
2017-10-14 23:18:42 -03:00
|
|
|
#include "core/hle/service/sm/controller.h"
|
|
|
|
|
2018-04-19 22:41:44 -03:00
|
|
|
namespace Service::SM {
|
2017-10-14 23:18:42 -03:00
|
|
|
|
2020-06-28 22:01:34 -04:00
|
|
|
void Controller::ConvertCurrentObjectToDomain(Kernel::HLERequestContext& ctx) {
|
2021-05-16 02:49:03 -04:00
|
|
|
ASSERT_MSG(!ctx.Session()->IsDomain(), "Session is already a domain");
|
2021-04-24 00:50:04 -04:00
|
|
|
LOG_DEBUG(Service, "called, server_session={}", ctx.Session()->GetId());
|
2018-01-23 20:03:09 -03:00
|
|
|
ctx.Session()->ConvertToDomain();
|
2017-12-29 02:36:22 -03:00
|
|
|
|
2018-01-23 21:52:18 -03:00
|
|
|
IPC::ResponseBuilder rb{ctx, 3};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2018-01-23 20:03:09 -03:00
|
|
|
rb.Push<u32>(1); // Converted sessions start with 1 request handler
|
2017-10-15 02:24:22 -03:00
|
|
|
}
|
|
|
|
|
2020-06-28 22:01:34 -04:00
|
|
|
void Controller::CloneCurrentObject(Kernel::HLERequestContext& ctx) {
|
2018-11-26 03:06:13 -03:00
|
|
|
LOG_DEBUG(Service, "called");
|
|
|
|
|
2021-06-04 22:26:48 -04:00
|
|
|
auto& parent_session = *ctx.Session()->GetParent();
|
|
|
|
auto& parent_port = parent_session.GetParent()->GetParent()->GetClientPort();
|
|
|
|
auto& session_manager = parent_session.GetServerSession().GetSessionRequestManager();
|
2021-05-10 18:53:07 -04:00
|
|
|
|
2021-06-04 22:26:48 -04:00
|
|
|
// Create a session.
|
|
|
|
Kernel::KClientSession* session{};
|
|
|
|
const ResultCode result = parent_port.CreateSession(std::addressof(session), session_manager);
|
|
|
|
if (result.IsError()) {
|
|
|
|
LOG_CRITICAL(Service, "CreateSession failed with error 0x{:08X}", result.raw);
|
2021-05-16 02:49:03 -04:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-06-04 22:26:48 -04:00
|
|
|
rb.Push(result);
|
2021-05-16 02:49:03 -04:00
|
|
|
}
|
2021-05-10 18:53:07 -04:00
|
|
|
|
2021-05-16 02:49:03 -04:00
|
|
|
// We succeeded.
|
2018-01-24 00:33:30 -03:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1, IPC::ResponseBuilder::Flags::AlwaysMoveHandles};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2021-06-04 22:26:48 -04:00
|
|
|
rb.PushMoveObjects(session);
|
2017-12-29 02:39:34 -03:00
|
|
|
}
|
|
|
|
|
2020-06-28 22:01:34 -04:00
|
|
|
void Controller::CloneCurrentObjectEx(Kernel::HLERequestContext& ctx) {
|
2021-05-10 18:53:07 -04:00
|
|
|
LOG_DEBUG(Service, "called");
|
2018-02-03 14:09:33 -03:00
|
|
|
|
2020-06-28 22:01:34 -04:00
|
|
|
CloneCurrentObject(ctx);
|
2018-01-17 16:41:43 -03:00
|
|
|
}
|
|
|
|
|
2017-10-14 23:18:42 -03:00
|
|
|
void Controller::QueryPointerBufferSize(Kernel::HLERequestContext& ctx) {
|
2018-11-26 03:06:13 -03:00
|
|
|
LOG_WARNING(Service, "(STUBBED) called");
|
|
|
|
|
2018-01-23 21:52:18 -03:00
|
|
|
IPC::ResponseBuilder rb{ctx, 3};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2021-05-10 18:43:42 -04:00
|
|
|
rb.Push<u16>(0x8000);
|
2017-10-14 23:18:42 -03:00
|
|
|
}
|
|
|
|
|
2020-06-28 22:01:34 -04:00
|
|
|
// https://switchbrew.org/wiki/IPC_Marshalling
|
2020-11-26 17:19:08 -03:00
|
|
|
Controller::Controller(Core::System& system_) : ServiceFramework{system_, "IpcController"} {
|
2017-10-14 23:18:42 -03:00
|
|
|
static const FunctionInfo functions[] = {
|
2020-06-28 22:21:10 -04:00
|
|
|
{0, &Controller::ConvertCurrentObjectToDomain, "ConvertCurrentObjectToDomain"},
|
|
|
|
{1, nullptr, "CopyFromCurrentDomain"},
|
|
|
|
{2, &Controller::CloneCurrentObject, "CloneCurrentObject"},
|
|
|
|
{3, &Controller::QueryPointerBufferSize, "QueryPointerBufferSize"},
|
|
|
|
{4, &Controller::CloneCurrentObjectEx, "CloneCurrentObjectEx"},
|
2017-10-14 23:18:42 -03:00
|
|
|
};
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
|
|
|
|
2018-09-06 15:32:25 -03:00
|
|
|
Controller::~Controller() = default;
|
|
|
|
|
2018-04-19 22:41:44 -03:00
|
|
|
} // namespace Service::SM
|