summaryrefslogtreecommitdiffstats
path: root/src/core/hle/service
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/core/hle/service/lm/lm.cpp43
-rw-r--r--src/core/hle/service/lm/lm.h25
-rw-r--r--src/core/hle/service/service.cpp115
-rw-r--r--src/core/hle/service/service.h84
-rw-r--r--src/core/hle/service/sm/controller.cpp42
-rw-r--r--src/core/hle/service/sm/controller.h22
-rw-r--r--src/core/hle/service/sm/sm.cpp91
-rw-r--r--src/core/hle/service/sm/sm.h20
-rw-r--r--src/core/hle/service/sm/srv.cpp235
-rw-r--r--src/core/hle/service/sm/srv.h38
10 files changed, 283 insertions, 432 deletions
diff --git a/src/core/hle/service/lm/lm.cpp b/src/core/hle/service/lm/lm.cpp
new file mode 100644
index 000000000..7296b531b
--- /dev/null
+++ b/src/core/hle/service/lm/lm.cpp
@@ -0,0 +1,43 @@
+// Copyright 2017 Citra Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#include "common/logging/log.h"
+#include "core/hle/ipc_helpers.h"
+#include "core/hle/service/lm/lm.h"
+
+namespace Service {
+namespace LM {
+
+void InstallInterfaces(SM::ServiceManager& service_manager) {
+ std::make_shared<LM>()->InstallAsService(service_manager);
+}
+
+/**
+ * SRV::Initialize service function
+ * Inputs:
+ * 0: 0x00000000
+ * Outputs:
+ * 1: ResultCode
+ */
+void LM::Initialize(Kernel::HLERequestContext& ctx) {
+ IPC::RequestBuilder rb{ctx, 1};
+ rb.Push(RESULT_SUCCESS);
+ LOG_WARNING(Service_SM, "(STUBBED) called");
+}
+
+LM::LM() : ServiceFramework("lm") {
+ static const FunctionInfo functions[] = {
+ {0x00000000, &LM::Initialize, "Initialize"},
+ {0x00000001, nullptr, "Unknown2"},
+ {0x00000002, nullptr, "Unknown3"},
+ {0x00000003, nullptr, "Unknown4"},
+ {0x00000004, nullptr, "Unknown5"},
+ };
+ RegisterHandlers(functions);
+}
+
+LM::~LM() = default;
+
+} // namespace LM
+} // namespace Service
diff --git a/src/core/hle/service/lm/lm.h b/src/core/hle/service/lm/lm.h
new file mode 100644
index 000000000..c497d82eb
--- /dev/null
+++ b/src/core/hle/service/lm/lm.h
@@ -0,0 +1,25 @@
+// Copyright 2017 Citra Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include "core/hle/service/service.h"
+
+namespace Service {
+namespace LM {
+
+class LM final : public ServiceFramework<LM> {
+public:
+ explicit LM();
+ ~LM();
+
+private:
+ void Initialize(Kernel::HLERequestContext& ctx);
+};
+
+/// Registers all LM services with the specified service manager.
+void InstallInterfaces(SM::ServiceManager& service_manager);
+
+} // namespace LM
+} // namespace Service
diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp
index e1f22ca97..3141b71f5 100644
--- a/src/core/hle/service/service.cpp
+++ b/src/core/hle/service/service.cpp
@@ -8,17 +8,20 @@
#include "common/logging/log.h"
#include "common/string_util.h"
#include "core/hle/ipc.h"
+#include "core/hle/ipc_helpers.h"
#include "core/hle/kernel/client_port.h"
#include "core/hle/kernel/process.h"
#include "core/hle/kernel/server_port.h"
#include "core/hle/kernel/server_session.h"
+#include "core/hle/kernel/thread.h"
#include "core/hle/kernel/handle_table.h"
#include "core/hle/service/dsp_dsp.h"
#include "core/hle/service/gsp_gpu.h"
#include "core/hle/service/hid/hid.h"
+#include "core/hle/service/lm/lm.h"
#include "core/hle/service/service.h"
+#include "core/hle/service/sm/controller.h"
#include "core/hle/service/sm/sm.h"
-#include "core/hle/service/sm/srv.h"
using Kernel::ClientPort;
using Kernel::ServerPort;
@@ -46,42 +49,6 @@ static std::string MakeFunctionString(const char* name, const char* port_name,
return function_string;
}
-Interface::Interface(u32 max_sessions) : max_sessions(max_sessions) {}
-Interface::~Interface() = default;
-
-void Interface::HandleSyncRequest(SharedPtr<ServerSession> server_session) {
- // TODO(Subv): Make use of the server_session in the HLE service handlers to distinguish which
- // session triggered each command.
-
- u32* cmd_buff = Kernel::GetCommandBuffer();
- auto itr = m_functions.find(cmd_buff[0]);
-
- if (itr == m_functions.end() || itr->second.func == nullptr) {
- std::string function_name = (itr == m_functions.end())
- ? Common::StringFromFormat("0x%08X", cmd_buff[0])
- : itr->second.name;
- LOG_ERROR(
- Service, "unknown / unimplemented %s",
- MakeFunctionString(function_name.c_str(), GetPortName().c_str(), cmd_buff).c_str());
-
- // TODO(bunnei): Hack - ignore error
- cmd_buff[1] = 0;
- return;
- }
- LOG_TRACE(Service, "%s",
- MakeFunctionString(itr->second.name, GetPortName().c_str(), cmd_buff).c_str());
-
- itr->second.func(this);
-}
-
-void Interface::Register(const FunctionInfo* functions, size_t n) {
- m_functions.reserve(n);
- for (size_t i = 0; i < n; ++i) {
- // Usually this array is sorted by id already, so hint to instead at the end
- m_functions.emplace_hint(m_functions.cend(), functions[i].id, functions[i]);
- }
-}
-
////////////////////////////////////////////////////////////////////////////////////////////////////
ServiceFrameworkBase::ServiceFrameworkBase(const char* service_name, u32 max_sessions,
@@ -113,43 +80,66 @@ void ServiceFrameworkBase::RegisterHandlersBase(const FunctionInfoBase* function
}
}
-void ServiceFrameworkBase::ReportUnimplementedFunction(u32* cmd_buf, const FunctionInfoBase* info) {
- IPC::Header header{cmd_buf[0]};
- int num_params = header.normal_params_size + header.translate_params_size;
+void ServiceFrameworkBase::ReportUnimplementedFunction(Kernel::HLERequestContext& ctx, const FunctionInfoBase* info) {
+ auto cmd_buf = ctx.CommandBuffer();
std::string function_name = info == nullptr ? fmt::format("{:#08x}", cmd_buf[0]) : info->name;
fmt::MemoryWriter w;
w.write("function '{}': port='{}' cmd_buf={{[0]={:#x}", function_name, service_name,
cmd_buf[0]);
- for (int i = 1; i <= num_params; ++i) {
+ for (int i = 1; i <= 8; ++i) {
w.write(", [{}]={:#x}", i, cmd_buf[i]);
}
w << '}';
LOG_ERROR(Service, "unknown / unimplemented %s", w.c_str());
// TODO(bunnei): Hack - ignore error
- cmd_buf[1] = 0;
+ IPC::RequestBuilder rb{ ctx, 1 };
+ rb.Push(RESULT_SUCCESS);
}
-void ServiceFrameworkBase::HandleSyncRequest(SharedPtr<ServerSession> server_session) {
- u32* cmd_buf = Kernel::GetCommandBuffer();
-
- u32 header_code = cmd_buf[0];
- auto itr = handlers.find(header_code);
+void ServiceFrameworkBase::InvokeRequest(Kernel::HLERequestContext& ctx) {
+ auto itr = handlers.find(ctx.GetCommand());
const FunctionInfoBase* info = itr == handlers.end() ? nullptr : &itr->second;
if (info == nullptr || info->handler_callback == nullptr) {
- return ReportUnimplementedFunction(cmd_buf, info);
+ return ReportUnimplementedFunction(ctx, info);
}
+ LOG_TRACE(Service, "%s",
+ MakeFunctionString(info->name, GetServiceName().c_str(), ctx.CommandBuffer()).c_str());
+ handler_invoker(this, info->handler_callback, ctx);
+}
+
+void ServiceFrameworkBase::HandleSyncRequest(SharedPtr<ServerSession> server_session) {
+ u32* cmd_buf = (u32*)Memory::GetPointer(Kernel::GetCurrentThread()->GetTLSAddress());;
+
// TODO(yuriks): The kernel should be the one handling this as part of translation after
// everything else is migrated
Kernel::HLERequestContext context(std::move(server_session));
context.PopulateFromIncomingCommandBuffer(cmd_buf, *Kernel::g_current_process,
Kernel::g_handle_table);
- LOG_TRACE(Service, "%s",
- MakeFunctionString(info->name, GetServiceName().c_str(), cmd_buf).c_str());
- handler_invoker(this, info->handler_callback, context);
+ switch (context.GetCommandType()) {
+ case IPC::CommandType::Close:
+ {
+ IPC::RequestBuilder rb{context, 1};
+ rb.Push(RESULT_SUCCESS);
+ break;
+ }
+ case IPC::CommandType::Control:
+ {
+ SM::g_service_manager->InvokeControlRequest(context);
+ break;
+ }
+ case IPC::CommandType::Request:
+ {
+ InvokeRequest(context);
+ break;
+ }
+ default:
+ UNIMPLEMENTED_MSG("command_type=%d", context.GetCommandType());
+ }
+
context.WriteToOutgoingCommandBuffer(cmd_buf, *Kernel::g_current_process,
Kernel::g_handle_table);
}
@@ -162,33 +152,14 @@ void AddNamedPort(std::string name, SharedPtr<ClientPort> port) {
g_kernel_named_ports.emplace(std::move(name), std::move(port));
}
-static void AddNamedPort(Interface* interface_) {
- SharedPtr<ServerPort> server_port;
- SharedPtr<ClientPort> client_port;
- std::tie(server_port, client_port) =
- ServerPort::CreatePortPair(interface_->GetMaxSessions(), interface_->GetPortName());
-
- server_port->SetHleHandler(std::shared_ptr<Interface>(interface_));
- AddNamedPort(interface_->GetPortName(), std::move(client_port));
-}
-
-void AddService(Interface* interface_) {
- auto server_port =
- SM::g_service_manager
- ->RegisterService(interface_->GetPortName(), interface_->GetMaxSessions())
- .Unwrap();
- server_port->SetHleHandler(std::shared_ptr<Interface>(interface_));
-}
-
/// Initialize ServiceManager
void Init() {
SM::g_service_manager = std::make_shared<SM::ServiceManager>();
SM::ServiceManager::InstallInterfaces(SM::g_service_manager);
- HID::Init();
+ LM::InstallInterfaces(*SM::g_service_manager);
- AddService(new DSP_DSP::Interface);
- AddService(new GSP::GSP_GPU);
+ HID::Init();
LOG_DEBUG(Service, "initialized OK");
}
diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.h
index 281ff99bb..07bc8589a 100644
--- a/src/core/hle/service/service.h
+++ b/src/core/hle/service/service.h
@@ -20,6 +20,7 @@ namespace Kernel {
class ClientPort;
class ServerPort;
class ServerSession;
+class HLERequestContext;
}
namespace Service {
@@ -33,83 +34,6 @@ static const int kMaxPortSize = 8; ///< Maximum size of a port name (8 character
static const u32 DefaultMaxSessions = 10;
/**
- * Framework for implementing HLE service handlers which dispatch incoming SyncRequests based on a
- * table mapping header ids to handler functions.
- *
- * @deprecated Use ServiceFramework for new services instead. It allows services to be stateful and
- * is more extensible going forward.
- */
-class Interface : public Kernel::SessionRequestHandler {
-public:
- /**
- * Creates an HLE interface with the specified max sessions.
- * @param max_sessions Maximum number of sessions that can be
- * connected to this service at the same time.
- */
- Interface(u32 max_sessions = DefaultMaxSessions);
-
- virtual ~Interface();
-
- std::string GetName() const {
- return GetPortName();
- }
-
- virtual void SetVersion(u32 raw_version) {
- version.raw = raw_version;
- }
-
- /**
- * Gets the maximum allowed number of sessions that can be connected to this service
- * at the same time.
- * @returns The maximum number of connections allowed.
- */
- u32 GetMaxSessions() const {
- return max_sessions;
- }
-
- typedef void (*Function)(Interface*);
-
- struct FunctionInfo {
- u32 id;
- Function func;
- const char* name;
- };
-
- /**
- * Gets the string name used by CTROS for a service
- * @return Port name of service
- */
- virtual std::string GetPortName() const {
- return "[UNKNOWN SERVICE PORT]";
- }
-
-protected:
- void HandleSyncRequest(Kernel::SharedPtr<Kernel::ServerSession> server_session) override;
-
- /**
- * Registers the functions in the service
- */
- template <size_t N>
- inline void Register(const FunctionInfo (&functions)[N]) {
- Register(functions, N);
- }
-
- void Register(const FunctionInfo* functions, size_t n);
-
- union {
- u32 raw;
- BitField<0, 8, u32> major;
- BitField<8, 8, u32> minor;
- BitField<16, 8, u32> build;
- BitField<24, 8, u32> revision;
- } version = {};
-
-private:
- u32 max_sessions; ///< Maximum number of concurrent sessions that this service can handle.
- boost::container::flat_map<u32, FunctionInfo> m_functions;
-};
-
-/**
* This is an non-templated base of ServiceFramework to reduce code bloat and compilation times, it
* is not meant to be used directly.
*
@@ -135,6 +59,8 @@ public:
/// Creates a port pair and registers it on the kernel's global port registry.
void InstallAsNamedPort();
+ void InvokeRequest(Kernel::HLERequestContext& ctx);
+
void HandleSyncRequest(Kernel::SharedPtr<Kernel::ServerSession> server_session) override;
protected:
@@ -159,7 +85,7 @@ private:
~ServiceFrameworkBase();
void RegisterHandlersBase(const FunctionInfoBase* functions, size_t n);
- void ReportUnimplementedFunction(u32* cmd_buf, const FunctionInfoBase* info);
+ void ReportUnimplementedFunction(Kernel::HLERequestContext& ctx, const FunctionInfoBase* info);
/// Identifier string used to connect to the service.
std::string service_name;
@@ -260,7 +186,5 @@ extern std::unordered_map<std::string, Kernel::SharedPtr<Kernel::ClientPort>> g_
/// Adds a port to the named port table
void AddNamedPort(std::string name, Kernel::SharedPtr<Kernel::ClientPort> port);
-/// Adds a service to the services table
-void AddService(Interface* interface_);
} // namespace
diff --git a/src/core/hle/service/sm/controller.cpp b/src/core/hle/service/sm/controller.cpp
new file mode 100644
index 000000000..4b250d6ba
--- /dev/null
+++ b/src/core/hle/service/sm/controller.cpp
@@ -0,0 +1,42 @@
+// Copyright 2017 Citra Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#include "common/logging/log.h"
+#include "core/hle/ipc_helpers.h"
+#include "core/hle/service/sm/controller.h"
+
+namespace Service {
+namespace SM {
+
+/**
+ * Controller::QueryPointerBufferSize service function
+ * Inputs:
+ * 0: 0x00000003
+ * Outputs:
+ * 1: ResultCode
+ * 3: Size of memory
+ */
+void Controller::QueryPointerBufferSize(Kernel::HLERequestContext& ctx) {
+ IPC::RequestBuilder rb{ctx, 2};
+ rb.Push(RESULT_SUCCESS);
+ rb.Push(0x0U);
+ rb.Push(0x500U);
+ LOG_WARNING(Service, "(STUBBED) called");
+}
+
+Controller::Controller() : ServiceFramework("IpcController") {
+ static const FunctionInfo functions[] = {
+ {0x00000000, nullptr, "ConvertSessionToDomain"},
+ {0x00000001, nullptr, "ConvertDomainToSession"},
+ {0x00000002, nullptr, "DuplicateSession"},
+ {0x00000003, &Controller::QueryPointerBufferSize, "QueryPointerBufferSize"},
+ {0x00000004, nullptr, "DuplicateSessionEx"},
+ };
+ RegisterHandlers(functions);
+}
+
+Controller::~Controller() = default;
+
+} // namespace SM
+} // namespace Service
diff --git a/src/core/hle/service/sm/controller.h b/src/core/hle/service/sm/controller.h
new file mode 100644
index 000000000..c6aa6f502
--- /dev/null
+++ b/src/core/hle/service/sm/controller.h
@@ -0,0 +1,22 @@
+// Copyright 2017 Citra Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include "core/hle/service/service.h"
+
+namespace Service {
+namespace SM {
+
+class Controller final : public ServiceFramework<Controller> {
+public:
+ explicit Controller();
+ ~Controller();
+
+private:
+ void QueryPointerBufferSize(Kernel::HLERequestContext& ctx);
+};
+
+} // namespace SM
+} // namespace Service
diff --git a/src/core/hle/service/sm/sm.cpp b/src/core/hle/service/sm/sm.cpp
index 854ab9a05..2068471f2 100644
--- a/src/core/hle/service/sm/sm.cpp
+++ b/src/core/hle/service/sm/sm.cpp
@@ -4,16 +4,21 @@
#include <tuple>
#include "common/assert.h"
+#include "core/hle/ipc_helpers.h"
#include "core/hle/kernel/client_port.h"
#include "core/hle/kernel/client_session.h"
#include "core/hle/kernel/server_port.h"
#include "core/hle/result.h"
+#include "core/hle/service/sm/controller.h"
#include "core/hle/service/sm/sm.h"
-#include "core/hle/service/sm/srv.h"
namespace Service {
namespace SM {
+void ServiceManager::InvokeControlRequest(Kernel::HLERequestContext& context) {
+ controller_interface->InvokeRequest(context);
+}
+
static ResultCode ValidateServiceName(const std::string& name) {
if (name.size() <= 0 || name.size() > 8) {
return ERR_INVALID_NAME_SIZE;
@@ -25,11 +30,12 @@ static ResultCode ValidateServiceName(const std::string& name) {
}
void ServiceManager::InstallInterfaces(std::shared_ptr<ServiceManager> self) {
- ASSERT(self->srv_interface.expired());
+ ASSERT(self->sm_interface.expired());
- auto srv = std::make_shared<SRV>(self);
- srv->InstallAsNamedPort();
- self->srv_interface = srv;
+ auto sm = std::make_shared<SM>(self);
+ sm->InstallAsNamedPort();
+ self->sm_interface = sm;
+ self->controller_interface = std::make_unique<Controller>();
}
ResultVal<Kernel::SharedPtr<Kernel::ServerPort>> ServiceManager::RegisterService(
@@ -69,5 +75,80 @@ ResultVal<Kernel::SharedPtr<Kernel::ClientSession>> ServiceManager::ConnectToSer
std::shared_ptr<ServiceManager> g_service_manager;
+/**
+ * SM::Initialize service function
+ * Inputs:
+ * 0: 0x00000000
+ * Outputs:
+ * 1: ResultCode
+ */
+void SM::Initialize(Kernel::HLERequestContext& ctx) {
+ IPC::RequestBuilder rb{ctx, 1};
+ rb.Push(RESULT_SUCCESS);
+ LOG_DEBUG(Service_SM, "called");
+}
+
+/**
+ * SM::GetServiceHandle service function
+ * Inputs:
+ * 0: 0x00000001
+ * 1: Unknown
+ * 2: Unknown
+ * 3-4: 8-byte UTF-8 service name
+ * Outputs:
+ * 1: ResultCode
+ * 3: Service handle
+ */
+void SM::GetService(Kernel::HLERequestContext& ctx) {
+ IPC::RequestParser rp{ctx};
+ u32 unk1 = rp.Pop<u32>();
+ u32 unk2 = rp.Pop<u32>();
+ auto name_buf = rp.PopRaw<std::array<char, 6>>();
+ std::string name(name_buf.data());
+
+ // TODO(yuriks): Permission checks go here
+
+ auto client_port = service_manager->GetServicePort(name);
+ if (client_port.Failed()) {
+ IPC::RequestBuilder rb = rp.MakeBuilder(1, 0, 0);
+ rb.Push(client_port.Code());
+ LOG_ERROR(Service_SM, "called service=%s -> error 0x%08X", name.c_str(),
+ client_port.Code().raw);
+ return;
+ }
+
+ auto session = client_port.Unwrap()->Connect();
+ if (session.Succeeded()) {
+ LOG_DEBUG(Service_SM, "called service=%s -> session=%u", name.c_str(),
+ (*session)->GetObjectId());
+ IPC::RequestBuilder rb = rp.MakeBuilder(1, 0, 1);
+ rb.Push(session.Code());
+ rb.PushObjects(std::move(session).Unwrap());
+ } else if (session.Code() == Kernel::ERR_MAX_CONNECTIONS_REACHED /*&& return_port_on_failure*/) {
+ LOG_WARNING(Service_SM, "called service=%s -> ERR_MAX_CONNECTIONS_REACHED, *port*=%u",
+ name.c_str(), (*client_port)->GetObjectId());
+ IPC::RequestBuilder rb = rp.MakeBuilder(1, 0, 1);
+ rb.Push(ERR_MAX_CONNECTIONS_REACHED);
+ rb.PushObjects(std::move(client_port).Unwrap());
+ } else {
+ LOG_ERROR(Service_SM, "called service=%s -> error 0x%08X", name.c_str(), session.Code());
+ IPC::RequestBuilder rb = rp.MakeBuilder(1, 0, 0);
+ rb.Push(session.Code());
+ }
+}
+
+SM::SM(std::shared_ptr<ServiceManager> service_manager)
+ : ServiceFramework("sm:", 4), service_manager(std::move(service_manager)) {
+ static const FunctionInfo functions[] = {
+ {0x00000000, &SM::Initialize, "Initialize"},
+ {0x00000001, &SM::GetService, "GetService"},
+ {0x00000002, nullptr, "RegisterService"},
+ {0x00000003, nullptr, "UnregisterService"},
+ };
+ RegisterHandlers(functions);
+}
+
+SM::~SM() = default;
+
} // namespace SM
} // namespace Service
diff --git a/src/core/hle/service/sm/sm.h b/src/core/hle/service/sm/sm.h
index 9f60a7965..eaae68ca1 100644
--- a/src/core/hle/service/sm/sm.h
+++ b/src/core/hle/service/sm/sm.h
@@ -20,7 +20,20 @@ class SessionRequestHandler;
namespace Service {
namespace SM {
-class SRV;
+/// Interface to "sm:" service
+class SM final : public ServiceFramework<SM> {
+public:
+ explicit SM(std::shared_ptr<ServiceManager> service_manager);
+ ~SM();
+
+private:
+ void Initialize(Kernel::HLERequestContext& ctx);
+ void GetService(Kernel::HLERequestContext& ctx);
+
+ std::shared_ptr<ServiceManager> service_manager;
+};
+
+class Controller;
constexpr ResultCode ERR_SERVICE_NOT_REGISTERED(1, ErrorModule::SRV, ErrorSummary::WouldBlock,
ErrorLevel::Temporary); // 0xD0406401
@@ -45,8 +58,11 @@ public:
ResultVal<Kernel::SharedPtr<Kernel::ClientPort>> GetServicePort(const std::string& name);
ResultVal<Kernel::SharedPtr<Kernel::ClientSession>> ConnectToService(const std::string& name);
+ void InvokeControlRequest(Kernel::HLERequestContext& context);
+
private:
- std::weak_ptr<SRV> srv_interface;
+ std::weak_ptr<SM> sm_interface;
+ std::unique_ptr<Controller> controller_interface;
/// Map of registered services, retrieved using GetServicePort or ConnectToService.
std::unordered_map<std::string, Kernel::SharedPtr<Kernel::ClientPort>> registered_services;
diff --git a/src/core/hle/service/sm/srv.cpp b/src/core/hle/service/sm/srv.cpp
deleted file mode 100644
index fb873981c..000000000
--- a/src/core/hle/service/sm/srv.cpp
+++ /dev/null
@@ -1,235 +0,0 @@
-// Copyright 2016 Citra Emulator Project
-// Licensed under GPLv2 or any later version
-// Refer to the license.txt file included.
-
-#include <tuple>
-
-#include "common/common_types.h"
-#include "common/logging/log.h"
-#include "core/hle/ipc.h"
-#include "core/hle/ipc_helpers.h"
-#include "core/hle/kernel/client_port.h"
-#include "core/hle/kernel/client_session.h"
-#include "core/hle/kernel/errors.h"
-#include "core/hle/kernel/hle_ipc.h"
-#include "core/hle/kernel/semaphore.h"
-#include "core/hle/kernel/server_port.h"
-#include "core/hle/kernel/server_session.h"
-#include "core/hle/service/sm/sm.h"
-#include "core/hle/service/sm/srv.h"
-
-namespace Service {
-namespace SM {
-
-constexpr int MAX_PENDING_NOTIFICATIONS = 16;
-
-/**
- * SRV::RegisterClient service function
- * Inputs:
- * 0: 0x00010002
- * 1: ProcessId Header (must be 0x20)
- * Outputs:
- * 0: 0x00010040
- * 1: ResultCode
- */
-void SRV::RegisterClient(Kernel::HLERequestContext& ctx) {
- IPC::RequestParser rp(ctx, 0x1, 0, 2);
-
- u32 pid_descriptor = rp.Pop<u32>();
- if (pid_descriptor != IPC::CallingPidDesc()) {
- IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
- rb.Push(IPC::ERR_INVALID_BUFFER_DESCRIPTOR);
- return;
- }
- u32 caller_pid = rp.Pop<u32>();
-
- IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
- rb.Push(RESULT_SUCCESS);
- LOG_WARNING(Service_SRV, "(STUBBED) called");
-}
-
-/**
- * SRV::EnableNotification service function
- * Inputs:
- * 0: 0x00020000
- * Outputs:
- * 0: 0x00020042
- * 1: ResultCode
- * 2: Translation descriptor: 0x20
- * 3: Handle to semaphore signaled on process notification
- */
-void SRV::EnableNotification(Kernel::HLERequestContext& ctx) {
- IPC::RequestParser rp(ctx, 0x2, 0, 0);
-
- notification_semaphore =
- Kernel::Semaphore::Create(0, MAX_PENDING_NOTIFICATIONS, 0, "SRV:Notification").Unwrap();
-
- IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
- rb.Push(RESULT_SUCCESS);
- rb.PushObjects(notification_semaphore);
- LOG_WARNING(Service_SRV, "(STUBBED) called");
-}
-
-/**
- * SRV::GetServiceHandle service function
- * Inputs:
- * 0: 0x00050100
- * 1-2: 8-byte UTF-8 service name
- * 3: Name length
- * 4: Flags (bit0: if not set, return port-handle if session-handle unavailable)
- * Outputs:
- * 1: ResultCode
- * 3: Service handle
- */
-void SRV::GetServiceHandle(Kernel::HLERequestContext& ctx) {
- IPC::RequestParser rp(ctx, 0x5, 4, 0);
- auto name_buf = rp.PopRaw<std::array<char, 8>>();
- size_t name_len = rp.Pop<u32>();
- u32 flags = rp.Pop<u32>();
-
- bool return_port_on_failure = (flags & 1) == 0;
-
- if (name_len > Service::kMaxPortSize) {
- IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
- rb.Push(ERR_INVALID_NAME_SIZE);
- LOG_ERROR(Service_SRV, "called name_len=0x%X -> ERR_INVALID_NAME_SIZE", name_len);
- return;
- }
- std::string name(name_buf.data(), name_len);
-
- // TODO(yuriks): Permission checks go here
-
- auto client_port = service_manager->GetServicePort(name);
- if (client_port.Failed()) {
- IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
- rb.Push(client_port.Code());
- LOG_ERROR(Service_SRV, "called service=%s -> error 0x%08X", name.c_str(),
- client_port.Code().raw);
- return;
- }
-
- auto session = client_port.Unwrap()->Connect();
- if (session.Succeeded()) {
- LOG_DEBUG(Service_SRV, "called service=%s -> session=%u", name.c_str(),
- (*session)->GetObjectId());
- IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
- rb.Push(session.Code());
- rb.PushObjects(std::move(session).Unwrap());
- } else if (session.Code() == Kernel::ERR_MAX_CONNECTIONS_REACHED && return_port_on_failure) {
- LOG_WARNING(Service_SRV, "called service=%s -> ERR_MAX_CONNECTIONS_REACHED, *port*=%u",
- name.c_str(), (*client_port)->GetObjectId());
- IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
- rb.Push(ERR_MAX_CONNECTIONS_REACHED);
- rb.PushObjects(std::move(client_port).Unwrap());
- } else {
- LOG_ERROR(Service_SRV, "called service=%s -> error 0x%08X", name.c_str(), session.Code());
- IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
- rb.Push(session.Code());
- }
-}
-
-/**
- * SRV::Subscribe service function
- * Inputs:
- * 0: 0x00090040
- * 1: Notification ID
- * Outputs:
- * 0: 0x00090040
- * 1: ResultCode
- */
-void SRV::Subscribe(Kernel::HLERequestContext& ctx) {
- IPC::RequestParser rp(ctx, 0x9, 1, 0);
- u32 notification_id = rp.Pop<u32>();
-
- IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
- rb.Push(RESULT_SUCCESS);
- LOG_WARNING(Service_SRV, "(STUBBED) called, notification_id=0x%X", notification_id);
-}
-
-/**
- * SRV::Unsubscribe service function
- * Inputs:
- * 0: 0x000A0040
- * 1: Notification ID
- * Outputs:
- * 0: 0x000A0040
- * 1: ResultCode
- */
-void SRV::Unsubscribe(Kernel::HLERequestContext& ctx) {
- IPC::RequestParser rp(ctx, 0xA, 1, 0);
- u32 notification_id = rp.Pop<u32>();
-
- IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
- rb.Push(RESULT_SUCCESS);
- LOG_WARNING(Service_SRV, "(STUBBED) called, notification_id=0x%X", notification_id);
-}
-
-/**
- * SRV::PublishToSubscriber service function
- * Inputs:
- * 0: 0x000C0080
- * 1: Notification ID
- * 2: Flags (bit0: only fire if not fired, bit1: report errors)
- * Outputs:
- * 0: 0x000C0040
- * 1: ResultCode
- */
-void SRV::PublishToSubscriber(Kernel::HLERequestContext& ctx) {
- IPC::RequestParser rp(ctx, 0xC, 2, 0);
- u32 notification_id = rp.Pop<u32>();
- u8 flags = rp.Pop<u8>();
-
- IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
- rb.Push(RESULT_SUCCESS);
- LOG_WARNING(Service_SRV, "(STUBBED) called, notification_id=0x%X, flags=%u", notification_id,
- flags);
-}
-
-void SRV::RegisterService(Kernel::HLERequestContext& ctx) {
- IPC::RequestParser rp(ctx, 0x3, 4, 0);
-
- auto name_buf = rp.PopRaw<std::array<char, 8>>();
- size_t name_len = rp.Pop<u32>();
- u32 max_sessions = rp.Pop<u32>();
-
- std::string name(name_buf.data(), std::min(name_len, name_buf.size()));
-
- auto port = service_manager->RegisterService(name, max_sessions);
-
- if (port.Failed()) {
- IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
- rb.Push(port.Code());
- LOG_ERROR(Service_SRV, "called service=%s -> error 0x%08X", name.c_str(), port.Code().raw);
- return;
- }
-
- IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
- rb.Push(RESULT_SUCCESS);
- rb.PushObjects(port.Unwrap());
-}
-
-SRV::SRV(std::shared_ptr<ServiceManager> service_manager)
- : ServiceFramework("srv:", 4), service_manager(std::move(service_manager)) {
- static const FunctionInfo functions[] = {
- {0x00010002, &SRV::RegisterClient, "RegisterClient"},
- {0x00020000, &SRV::EnableNotification, "EnableNotification"},
- {0x00030100, &SRV::RegisterService, "RegisterService"},
- {0x000400C0, nullptr, "UnregisterService"},
- {0x00050100, &SRV::GetServiceHandle, "GetServiceHandle"},
- {0x000600C2, nullptr, "RegisterPort"},
- {0x000700C0, nullptr, "UnregisterPort"},
- {0x00080100, nullptr, "GetPort"},
- {0x00090040, &SRV::Subscribe, "Subscribe"},
- {0x000A0040, &SRV::Unsubscribe, "Unsubscribe"},
- {0x000B0000, nullptr, "ReceiveNotification"},
- {0x000C0080, &SRV::PublishToSubscriber, "PublishToSubscriber"},
- {0x000D0040, nullptr, "PublishAndGetSubscriber"},
- {0x000E00C0, nullptr, "IsServiceRegistered"},
- };
- RegisterHandlers(functions);
-}
-
-SRV::~SRV() = default;
-
-} // namespace SM
-} // namespace Service
diff --git a/src/core/hle/service/sm/srv.h b/src/core/hle/service/sm/srv.h
deleted file mode 100644
index aad839563..000000000
--- a/src/core/hle/service/sm/srv.h
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright 2014 Citra Emulator Project
-// Licensed under GPLv2 or any later version
-// Refer to the license.txt file included.
-
-#pragma once
-
-#include "core/hle/kernel/kernel.h"
-#include "core/hle/service/service.h"
-
-namespace Kernel {
-class HLERequestContext;
-class Semaphore;
-}
-
-namespace Service {
-namespace SM {
-
-/// Interface to "srv:" service
-class SRV final : public ServiceFramework<SRV> {
-public:
- explicit SRV(std::shared_ptr<ServiceManager> service_manager);
- ~SRV();
-
-private:
- void RegisterClient(Kernel::HLERequestContext& ctx);
- void EnableNotification(Kernel::HLERequestContext& ctx);
- void GetServiceHandle(Kernel::HLERequestContext& ctx);
- void Subscribe(Kernel::HLERequestContext& ctx);
- void Unsubscribe(Kernel::HLERequestContext& ctx);
- void PublishToSubscriber(Kernel::HLERequestContext& ctx);
- void RegisterService(Kernel::HLERequestContext& ctx);
-
- std::shared_ptr<ServiceManager> service_manager;
- Kernel::SharedPtr<Kernel::Semaphore> notification_semaphore;
-};
-
-} // namespace SM
-} // namespace Service