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-09-25 17:14:19 -04:00
|
|
|
#include "common/assert.h"
|
2017-10-14 22:18:42 -04:00
|
|
|
#include "common/logging/log.h"
|
2021-05-15 23:49:03 -07:00
|
|
|
#include "core/core.h"
|
2017-10-14 22:18:42 -04:00
|
|
|
#include "core/hle/ipc_helpers.h"
|
2021-05-15 23:49:03 -07:00
|
|
|
#include "core/hle/kernel/k_client_port.h"
|
2021-04-13 17:48:37 -07:00
|
|
|
#include "core/hle/kernel/k_client_session.h"
|
2021-05-15 23:49:03 -07: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 17:48:37 -07:00
|
|
|
#include "core/hle/kernel/k_server_session.h"
|
|
|
|
#include "core/hle/kernel/k_session.h"
|
2017-10-14 22:18:42 -04:00
|
|
|
#include "core/hle/service/sm/controller.h"
|
|
|
|
|
2018-04-19 21:41:44 -04:00
|
|
|
namespace Service::SM {
|
2017-10-14 22:18:42 -04:00
|
|
|
|
2020-06-29 04:01:34 +02:00
|
|
|
void Controller::ConvertCurrentObjectToDomain(Kernel::HLERequestContext& ctx) {
|
2021-05-15 23:49:03 -07:00
|
|
|
ASSERT_MSG(!ctx.Session()->IsDomain(), "Session is already a domain");
|
2021-04-23 21:50:04 -07:00
|
|
|
LOG_DEBUG(Service, "called, server_session={}", ctx.Session()->GetId());
|
2018-01-23 18:03:09 -05:00
|
|
|
ctx.Session()->ConvertToDomain();
|
2017-12-29 00:36:22 -05:00
|
|
|
|
2018-01-23 19:52:18 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 3};
|
2017-10-15 01:24:22 -04:00
|
|
|
rb.Push(RESULT_SUCCESS);
|
2018-01-23 18:03:09 -05:00
|
|
|
rb.Push<u32>(1); // Converted sessions start with 1 request handler
|
2017-10-15 01:24:22 -04:00
|
|
|
}
|
|
|
|
|
2020-06-29 04:01:34 +02:00
|
|
|
void Controller::CloneCurrentObject(Kernel::HLERequestContext& ctx) {
|
2018-02-03 12:09:33 -05:00
|
|
|
// TODO(bunnei): This is just creating a new handle to the same Session. I assume this is wrong
|
|
|
|
// and that we probably want to actually make an entirely new Session, but we still need to
|
|
|
|
// verify this on hardware.
|
2021-05-10 15:53:07 -07:00
|
|
|
|
2018-11-26 17:06:13 +11:00
|
|
|
LOG_DEBUG(Service, "called");
|
|
|
|
|
2021-05-15 23:49:03 -07:00
|
|
|
auto& kernel = system.Kernel();
|
|
|
|
auto* session = ctx.Session()->GetParent();
|
|
|
|
auto* port = session->GetParent()->GetParent();
|
2021-05-10 15:53:07 -07:00
|
|
|
|
2021-05-15 23:49:03 -07:00
|
|
|
// Reserve a new session from the process resource limit.
|
|
|
|
Kernel::KScopedResourceReservation session_reservation(
|
|
|
|
kernel.CurrentProcess()->GetResourceLimit(), Kernel::LimitableResource::Sessions);
|
|
|
|
if (!session_reservation.Succeeded()) {
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(Kernel::ResultLimitReached);
|
|
|
|
}
|
2021-05-10 15:53:07 -07:00
|
|
|
|
2021-05-15 23:49:03 -07:00
|
|
|
// Create a new session.
|
|
|
|
auto* clone = Kernel::KSession::Create(kernel);
|
|
|
|
clone->Initialize(&port->GetClientPort(), session->GetName());
|
|
|
|
|
|
|
|
// Commit the session reservation.
|
|
|
|
session_reservation.Commit();
|
|
|
|
|
|
|
|
// Enqueue the session with the named port.
|
|
|
|
port->EnqueueSession(&clone->GetServerSession());
|
|
|
|
|
|
|
|
// Set the session request manager.
|
|
|
|
clone->GetServerSession().SetSessionRequestManager(
|
|
|
|
session->GetServerSession().GetSessionRequestManager());
|
|
|
|
|
|
|
|
// We succeeded.
|
2018-01-23 22:33:30 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1, IPC::ResponseBuilder::Flags::AlwaysMoveHandles};
|
2017-12-29 00:39:34 -05:00
|
|
|
rb.Push(RESULT_SUCCESS);
|
2021-05-15 23:49:03 -07:00
|
|
|
rb.PushMoveObjects(clone->GetClientSession());
|
2017-12-29 00:39:34 -05:00
|
|
|
}
|
|
|
|
|
2020-06-29 04:01:34 +02:00
|
|
|
void Controller::CloneCurrentObjectEx(Kernel::HLERequestContext& ctx) {
|
2021-05-10 15:53:07 -07:00
|
|
|
LOG_DEBUG(Service, "called");
|
2018-02-03 12:09:33 -05:00
|
|
|
|
2020-06-29 04:01:34 +02:00
|
|
|
CloneCurrentObject(ctx);
|
2018-01-17 14:41:43 -05:00
|
|
|
}
|
|
|
|
|
2017-10-14 22:18:42 -04:00
|
|
|
void Controller::QueryPointerBufferSize(Kernel::HLERequestContext& ctx) {
|
2018-11-26 17:06:13 +11:00
|
|
|
LOG_WARNING(Service, "(STUBBED) called");
|
|
|
|
|
2018-01-23 19:52:18 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 3};
|
2017-10-14 22:18:42 -04:00
|
|
|
rb.Push(RESULT_SUCCESS);
|
2021-05-10 15:43:42 -07:00
|
|
|
rb.Push<u16>(0x8000);
|
2017-10-14 22:18:42 -04:00
|
|
|
}
|
|
|
|
|
2020-06-29 04:01:34 +02:00
|
|
|
// https://switchbrew.org/wiki/IPC_Marshalling
|
2020-11-26 15:19:08 -05:00
|
|
|
Controller::Controller(Core::System& system_) : ServiceFramework{system_, "IpcController"} {
|
2017-10-14 22:18:42 -04:00
|
|
|
static const FunctionInfo functions[] = {
|
2020-06-29 04:21:10 +02:00
|
|
|
{0, &Controller::ConvertCurrentObjectToDomain, "ConvertCurrentObjectToDomain"},
|
|
|
|
{1, nullptr, "CopyFromCurrentDomain"},
|
|
|
|
{2, &Controller::CloneCurrentObject, "CloneCurrentObject"},
|
|
|
|
{3, &Controller::QueryPointerBufferSize, "QueryPointerBufferSize"},
|
|
|
|
{4, &Controller::CloneCurrentObjectEx, "CloneCurrentObjectEx"},
|
2017-10-14 22:18:42 -04:00
|
|
|
};
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
|
|
|
|
2018-09-06 14:32:25 -04:00
|
|
|
Controller::~Controller() = default;
|
|
|
|
|
2018-04-19 21:41:44 -04:00
|
|
|
} // namespace Service::SM
|