diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/service/service.cpp | 5 | ||||
| -rw-r--r-- | src/core/hle/service/sm/sm.cpp | 14 | ||||
| -rw-r--r-- | src/core/hle/service/sm/sm.h | 10 | ||||
| -rw-r--r-- | src/core/hle/service/sm/srv.cpp | 71 | ||||
| -rw-r--r-- | src/core/hle/service/sm/srv.h | 26 |
5 files changed, 75 insertions, 51 deletions
diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index f184736e0..d34968428 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp | |||
| @@ -206,8 +206,9 @@ void AddService(Interface* interface_) { | |||
| 206 | 206 | ||
| 207 | /// Initialize ServiceManager | 207 | /// Initialize ServiceManager |
| 208 | void Init() { | 208 | void Init() { |
| 209 | SM::g_service_manager = std::make_unique<SM::ServiceManager>(); | 209 | SM::g_service_manager = std::make_shared<SM::ServiceManager>(); |
| 210 | AddNamedPort(new SM::SRV); | 210 | SM::ServiceManager::InstallInterfaces(SM::g_service_manager); |
| 211 | |||
| 211 | AddNamedPort(new ERR::ERR_F); | 212 | AddNamedPort(new ERR::ERR_F); |
| 212 | 213 | ||
| 213 | FS::ArchiveInit(); | 214 | FS::ArchiveInit(); |
diff --git a/src/core/hle/service/sm/sm.cpp b/src/core/hle/service/sm/sm.cpp index 361f7a0a9..5e7fc68f9 100644 --- a/src/core/hle/service/sm/sm.cpp +++ b/src/core/hle/service/sm/sm.cpp | |||
| @@ -3,11 +3,13 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <tuple> | 5 | #include <tuple> |
| 6 | #include "common/assert.h" | ||
| 6 | #include "core/hle/kernel/client_port.h" | 7 | #include "core/hle/kernel/client_port.h" |
| 7 | #include "core/hle/kernel/client_session.h" | 8 | #include "core/hle/kernel/client_session.h" |
| 8 | #include "core/hle/kernel/server_port.h" | 9 | #include "core/hle/kernel/server_port.h" |
| 9 | #include "core/hle/result.h" | 10 | #include "core/hle/result.h" |
| 10 | #include "core/hle/service/sm/sm.h" | 11 | #include "core/hle/service/sm/sm.h" |
| 12 | #include "core/hle/service/sm/srv.h" | ||
| 11 | 13 | ||
| 12 | namespace Service { | 14 | namespace Service { |
| 13 | namespace SM { | 15 | namespace SM { |
| @@ -22,6 +24,14 @@ static ResultCode ValidateServiceName(const std::string& name) { | |||
| 22 | return RESULT_SUCCESS; | 24 | return RESULT_SUCCESS; |
| 23 | } | 25 | } |
| 24 | 26 | ||
| 27 | void ServiceManager::InstallInterfaces(std::shared_ptr<ServiceManager> self) { | ||
| 28 | ASSERT(self->srv_interface.expired()); | ||
| 29 | |||
| 30 | auto srv = std::make_shared<SRV>(self); | ||
| 31 | srv->InstallAsNamedPort(); | ||
| 32 | self->srv_interface = srv; | ||
| 33 | } | ||
| 34 | |||
| 25 | ResultVal<Kernel::SharedPtr<Kernel::ServerPort>> ServiceManager::RegisterService( | 35 | ResultVal<Kernel::SharedPtr<Kernel::ServerPort>> ServiceManager::RegisterService( |
| 26 | std::string name, unsigned int max_sessions) { | 36 | std::string name, unsigned int max_sessions) { |
| 27 | 37 | ||
| @@ -30,7 +40,7 @@ ResultVal<Kernel::SharedPtr<Kernel::ServerPort>> ServiceManager::RegisterService | |||
| 30 | Kernel::SharedPtr<Kernel::ClientPort> client_port; | 40 | Kernel::SharedPtr<Kernel::ClientPort> client_port; |
| 31 | std::tie(server_port, client_port) = Kernel::ServerPort::CreatePortPair(max_sessions, name); | 41 | std::tie(server_port, client_port) = Kernel::ServerPort::CreatePortPair(max_sessions, name); |
| 32 | 42 | ||
| 33 | registered_services.emplace(name, std::move(client_port)); | 43 | registered_services.emplace(std::move(name), std::move(client_port)); |
| 34 | return MakeResult<Kernel::SharedPtr<Kernel::ServerPort>>(std::move(server_port)); | 44 | return MakeResult<Kernel::SharedPtr<Kernel::ServerPort>>(std::move(server_port)); |
| 35 | } | 45 | } |
| 36 | 46 | ||
| @@ -53,7 +63,7 @@ ResultVal<Kernel::SharedPtr<Kernel::ClientSession>> ServiceManager::ConnectToSer | |||
| 53 | return client_port->Connect(); | 63 | return client_port->Connect(); |
| 54 | } | 64 | } |
| 55 | 65 | ||
| 56 | std::unique_ptr<ServiceManager> g_service_manager; | 66 | std::shared_ptr<ServiceManager> g_service_manager; |
| 57 | 67 | ||
| 58 | } // namespace SM | 68 | } // namespace SM |
| 59 | } // namespace Service | 69 | } // namespace Service |
diff --git a/src/core/hle/service/sm/sm.h b/src/core/hle/service/sm/sm.h index 5fac5455c..8f0dbf2db 100644 --- a/src/core/hle/service/sm/sm.h +++ b/src/core/hle/service/sm/sm.h | |||
| @@ -20,6 +20,8 @@ class SessionRequestHandler; | |||
| 20 | namespace Service { | 20 | namespace Service { |
| 21 | namespace SM { | 21 | namespace SM { |
| 22 | 22 | ||
| 23 | class SRV; | ||
| 24 | |||
| 23 | constexpr ResultCode ERR_SERVICE_NOT_REGISTERED(1, ErrorModule::SRV, ErrorSummary::WouldBlock, | 25 | constexpr ResultCode ERR_SERVICE_NOT_REGISTERED(1, ErrorModule::SRV, ErrorSummary::WouldBlock, |
| 24 | ErrorLevel::Temporary); // 0xD0406401 | 26 | ErrorLevel::Temporary); // 0xD0406401 |
| 25 | constexpr ResultCode ERR_MAX_CONNECTIONS_REACHED(2, ErrorModule::SRV, ErrorSummary::WouldBlock, | 27 | constexpr ResultCode ERR_MAX_CONNECTIONS_REACHED(2, ErrorModule::SRV, ErrorSummary::WouldBlock, |
| @@ -33,17 +35,21 @@ constexpr ResultCode ERR_NAME_CONTAINS_NUL(7, ErrorModule::SRV, ErrorSummary::Wr | |||
| 33 | 35 | ||
| 34 | class ServiceManager { | 36 | class ServiceManager { |
| 35 | public: | 37 | public: |
| 38 | static void InstallInterfaces(std::shared_ptr<ServiceManager> self); | ||
| 39 | |||
| 36 | ResultVal<Kernel::SharedPtr<Kernel::ServerPort>> RegisterService(std::string name, | 40 | ResultVal<Kernel::SharedPtr<Kernel::ServerPort>> RegisterService(std::string name, |
| 37 | unsigned int max_sessions); | 41 | unsigned int max_sessions); |
| 38 | ResultVal<Kernel::SharedPtr<Kernel::ClientPort>> GetServicePort(const std::string& name); | 42 | ResultVal<Kernel::SharedPtr<Kernel::ClientPort>> GetServicePort(const std::string& name); |
| 39 | ResultVal<Kernel::SharedPtr<Kernel::ClientSession>> ConnectToService(const std::string& name); | 43 | ResultVal<Kernel::SharedPtr<Kernel::ClientSession>> ConnectToService(const std::string& name); |
| 40 | 44 | ||
| 41 | private: | 45 | private: |
| 42 | /// Map of services registered with the "srv:" service, retrieved using GetServiceHandle. | 46 | std::weak_ptr<SRV> srv_interface; |
| 47 | |||
| 48 | /// Map of registered services, retrieved using GetServicePort or ConnectToService. | ||
| 43 | std::unordered_map<std::string, Kernel::SharedPtr<Kernel::ClientPort>> registered_services; | 49 | std::unordered_map<std::string, Kernel::SharedPtr<Kernel::ClientPort>> registered_services; |
| 44 | }; | 50 | }; |
| 45 | 51 | ||
| 46 | extern std::unique_ptr<ServiceManager> g_service_manager; | 52 | extern std::shared_ptr<ServiceManager> g_service_manager; |
| 47 | 53 | ||
| 48 | } // namespace SM | 54 | } // namespace SM |
| 49 | } // namespace Service | 55 | } // namespace Service |
diff --git a/src/core/hle/service/sm/srv.cpp b/src/core/hle/service/sm/srv.cpp index 063b1b0fc..b8b62b068 100644 --- a/src/core/hle/service/sm/srv.cpp +++ b/src/core/hle/service/sm/srv.cpp | |||
| @@ -20,8 +20,6 @@ namespace SM { | |||
| 20 | 20 | ||
| 21 | constexpr int MAX_PENDING_NOTIFICATIONS = 16; | 21 | constexpr int MAX_PENDING_NOTIFICATIONS = 16; |
| 22 | 22 | ||
| 23 | static Kernel::SharedPtr<Kernel::Semaphore> notification_semaphore; | ||
| 24 | |||
| 25 | /** | 23 | /** |
| 26 | * SRV::RegisterClient service function | 24 | * SRV::RegisterClient service function |
| 27 | * Inputs: | 25 | * Inputs: |
| @@ -31,8 +29,8 @@ static Kernel::SharedPtr<Kernel::Semaphore> notification_semaphore; | |||
| 31 | * 0: 0x00010040 | 29 | * 0: 0x00010040 |
| 32 | * 1: ResultCode | 30 | * 1: ResultCode |
| 33 | */ | 31 | */ |
| 34 | static void RegisterClient(Interface* self) { | 32 | void SRV::RegisterClient(Kernel::HLERequestContext& ctx) { |
| 35 | u32* cmd_buff = Kernel::GetCommandBuffer(); | 33 | u32* cmd_buff = ctx.CommandBuffer(); |
| 36 | 34 | ||
| 37 | if (cmd_buff[1] != IPC::CallingPidDesc()) { | 35 | if (cmd_buff[1] != IPC::CallingPidDesc()) { |
| 38 | cmd_buff[0] = IPC::MakeHeader(0x0, 0x1, 0); // 0x40 | 36 | cmd_buff[0] = IPC::MakeHeader(0x0, 0x1, 0); // 0x40 |
| @@ -54,8 +52,8 @@ static void RegisterClient(Interface* self) { | |||
| 54 | * 2: Translation descriptor: 0x20 | 52 | * 2: Translation descriptor: 0x20 |
| 55 | * 3: Handle to semaphore signaled on process notification | 53 | * 3: Handle to semaphore signaled on process notification |
| 56 | */ | 54 | */ |
| 57 | static void EnableNotification(Interface* self) { | 55 | void SRV::EnableNotification(Kernel::HLERequestContext& ctx) { |
| 58 | u32* cmd_buff = Kernel::GetCommandBuffer(); | 56 | u32* cmd_buff = ctx.CommandBuffer(); |
| 59 | 57 | ||
| 60 | notification_semaphore = | 58 | notification_semaphore = |
| 61 | Kernel::Semaphore::Create(0, MAX_PENDING_NOTIFICATIONS, "SRV:Notification").Unwrap(); | 59 | Kernel::Semaphore::Create(0, MAX_PENDING_NOTIFICATIONS, "SRV:Notification").Unwrap(); |
| @@ -78,9 +76,9 @@ static void EnableNotification(Interface* self) { | |||
| 78 | * 1: ResultCode | 76 | * 1: ResultCode |
| 79 | * 3: Service handle | 77 | * 3: Service handle |
| 80 | */ | 78 | */ |
| 81 | static void GetServiceHandle(Interface* self) { | 79 | void SRV::GetServiceHandle(Kernel::HLERequestContext& ctx) { |
| 82 | ResultCode res = RESULT_SUCCESS; | 80 | ResultCode res = RESULT_SUCCESS; |
| 83 | u32* cmd_buff = Kernel::GetCommandBuffer(); | 81 | u32* cmd_buff = ctx.CommandBuffer(); |
| 84 | 82 | ||
| 85 | size_t name_len = cmd_buff[3]; | 83 | size_t name_len = cmd_buff[3]; |
| 86 | if (name_len > Service::kMaxPortSize) { | 84 | if (name_len > Service::kMaxPortSize) { |
| @@ -94,7 +92,7 @@ static void GetServiceHandle(Interface* self) { | |||
| 94 | 92 | ||
| 95 | // TODO(yuriks): Permission checks go here | 93 | // TODO(yuriks): Permission checks go here |
| 96 | 94 | ||
| 97 | auto client_port = g_service_manager->GetServicePort(name); | 95 | auto client_port = service_manager->GetServicePort(name); |
| 98 | if (client_port.Failed()) { | 96 | if (client_port.Failed()) { |
| 99 | cmd_buff[1] = client_port.Code().raw; | 97 | cmd_buff[1] = client_port.Code().raw; |
| 100 | LOG_ERROR(Service_SRV, "called service=%s, failed with code=0x%08X", name.c_str(), | 98 | LOG_ERROR(Service_SRV, "called service=%s, failed with code=0x%08X", name.c_str(), |
| @@ -128,8 +126,8 @@ static void GetServiceHandle(Interface* self) { | |||
| 128 | * 0: 0x00090040 | 126 | * 0: 0x00090040 |
| 129 | * 1: ResultCode | 127 | * 1: ResultCode |
| 130 | */ | 128 | */ |
| 131 | static void Subscribe(Interface* self) { | 129 | void SRV::Subscribe(Kernel::HLERequestContext& ctx) { |
| 132 | u32* cmd_buff = Kernel::GetCommandBuffer(); | 130 | u32* cmd_buff = ctx.CommandBuffer(); |
| 133 | 131 | ||
| 134 | u32 notification_id = cmd_buff[1]; | 132 | u32 notification_id = cmd_buff[1]; |
| 135 | 133 | ||
| @@ -147,8 +145,8 @@ static void Subscribe(Interface* self) { | |||
| 147 | * 0: 0x000A0040 | 145 | * 0: 0x000A0040 |
| 148 | * 1: ResultCode | 146 | * 1: ResultCode |
| 149 | */ | 147 | */ |
| 150 | static void Unsubscribe(Interface* self) { | 148 | void SRV::Unsubscribe(Kernel::HLERequestContext& ctx) { |
| 151 | u32* cmd_buff = Kernel::GetCommandBuffer(); | 149 | u32* cmd_buff = ctx.CommandBuffer(); |
| 152 | 150 | ||
| 153 | u32 notification_id = cmd_buff[1]; | 151 | u32 notification_id = cmd_buff[1]; |
| 154 | 152 | ||
| @@ -167,8 +165,8 @@ static void Unsubscribe(Interface* self) { | |||
| 167 | * 0: 0x000C0040 | 165 | * 0: 0x000C0040 |
| 168 | * 1: ResultCode | 166 | * 1: ResultCode |
| 169 | */ | 167 | */ |
| 170 | static void PublishToSubscriber(Interface* self) { | 168 | void SRV::PublishToSubscriber(Kernel::HLERequestContext& ctx) { |
| 171 | u32* cmd_buff = Kernel::GetCommandBuffer(); | 169 | u32* cmd_buff = ctx.CommandBuffer(); |
| 172 | 170 | ||
| 173 | u32 notification_id = cmd_buff[1]; | 171 | u32 notification_id = cmd_buff[1]; |
| 174 | u8 flags = cmd_buff[2] & 0xFF; | 172 | u8 flags = cmd_buff[2] & 0xFF; |
| @@ -179,31 +177,28 @@ static void PublishToSubscriber(Interface* self) { | |||
| 179 | flags); | 177 | flags); |
| 180 | } | 178 | } |
| 181 | 179 | ||
| 182 | const Interface::FunctionInfo FunctionTable[] = { | 180 | SRV::SRV(std::shared_ptr<ServiceManager> service_manager) |
| 183 | {0x00010002, RegisterClient, "RegisterClient"}, | 181 | : ServiceFramework("srv:", 4), service_manager(std::move(service_manager)) { |
| 184 | {0x00020000, EnableNotification, "EnableNotification"}, | 182 | static const FunctionInfo functions[] = { |
| 185 | {0x00030100, nullptr, "RegisterService"}, | 183 | {0x00010002, &SRV::RegisterClient, "RegisterClient"}, |
| 186 | {0x000400C0, nullptr, "UnregisterService"}, | 184 | {0x00020000, &SRV::EnableNotification, "EnableNotification"}, |
| 187 | {0x00050100, GetServiceHandle, "GetServiceHandle"}, | 185 | {0x00030100, nullptr, "RegisterService"}, |
| 188 | {0x000600C2, nullptr, "RegisterPort"}, | 186 | {0x000400C0, nullptr, "UnregisterService"}, |
| 189 | {0x000700C0, nullptr, "UnregisterPort"}, | 187 | {0x00050100, &SRV::GetServiceHandle, "GetServiceHandle"}, |
| 190 | {0x00080100, nullptr, "GetPort"}, | 188 | {0x000600C2, nullptr, "RegisterPort"}, |
| 191 | {0x00090040, Subscribe, "Subscribe"}, | 189 | {0x000700C0, nullptr, "UnregisterPort"}, |
| 192 | {0x000A0040, Unsubscribe, "Unsubscribe"}, | 190 | {0x00080100, nullptr, "GetPort"}, |
| 193 | {0x000B0000, nullptr, "ReceiveNotification"}, | 191 | {0x00090040, &SRV::Subscribe, "Subscribe"}, |
| 194 | {0x000C0080, PublishToSubscriber, "PublishToSubscriber"}, | 192 | {0x000A0040, &SRV::Unsubscribe, "Unsubscribe"}, |
| 195 | {0x000D0040, nullptr, "PublishAndGetSubscriber"}, | 193 | {0x000B0000, nullptr, "ReceiveNotification"}, |
| 196 | {0x000E00C0, nullptr, "IsServiceRegistered"}, | 194 | {0x000C0080, &SRV::PublishToSubscriber, "PublishToSubscriber"}, |
| 197 | }; | 195 | {0x000D0040, nullptr, "PublishAndGetSubscriber"}, |
| 198 | 196 | {0x000E00C0, nullptr, "IsServiceRegistered"}, | |
| 199 | SRV::SRV() { | 197 | }; |
| 200 | Register(FunctionTable); | 198 | RegisterHandlers(functions); |
| 201 | notification_semaphore = nullptr; | ||
| 202 | } | 199 | } |
| 203 | 200 | ||
| 204 | SRV::~SRV() { | 201 | SRV::~SRV() = default; |
| 205 | notification_semaphore = nullptr; | ||
| 206 | } | ||
| 207 | 202 | ||
| 208 | } // namespace SM | 203 | } // namespace SM |
| 209 | } // namespace Service | 204 | } // namespace Service |
diff --git a/src/core/hle/service/sm/srv.h b/src/core/hle/service/sm/srv.h index 4196ca1e2..75cca5184 100644 --- a/src/core/hle/service/sm/srv.h +++ b/src/core/hle/service/sm/srv.h | |||
| @@ -4,21 +4,33 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <string> | 7 | #include "core/hle/kernel/kernel.h" |
| 8 | #include "core/hle/service/service.h" | 8 | #include "core/hle/service/service.h" |
| 9 | 9 | ||
| 10 | namespace Kernel { | ||
| 11 | class HLERequestContext; | ||
| 12 | class Semaphore; | ||
| 13 | } | ||
| 14 | |||
| 10 | namespace Service { | 15 | namespace Service { |
| 11 | namespace SM { | 16 | namespace SM { |
| 12 | 17 | ||
| 13 | /// Interface to "srv:" service | 18 | /// Interface to "srv:" service |
| 14 | class SRV final : public Interface { | 19 | class SRV final : public ServiceFramework<SRV> { |
| 15 | public: | 20 | public: |
| 16 | SRV(); | 21 | explicit SRV(std::shared_ptr<ServiceManager> service_manager); |
| 17 | ~SRV() override; | 22 | ~SRV(); |
| 23 | |||
| 24 | private: | ||
| 25 | void RegisterClient(Kernel::HLERequestContext& ctx); | ||
| 26 | void EnableNotification(Kernel::HLERequestContext& ctx); | ||
| 27 | void GetServiceHandle(Kernel::HLERequestContext& ctx); | ||
| 28 | void Subscribe(Kernel::HLERequestContext& ctx); | ||
| 29 | void Unsubscribe(Kernel::HLERequestContext& ctx); | ||
| 30 | void PublishToSubscriber(Kernel::HLERequestContext& ctx); | ||
| 18 | 31 | ||
| 19 | std::string GetPortName() const override { | 32 | std::shared_ptr<ServiceManager> service_manager; |
| 20 | return "srv:"; | 33 | Kernel::SharedPtr<Kernel::Semaphore> notification_semaphore; |
| 21 | } | ||
| 22 | }; | 34 | }; |
| 23 | 35 | ||
| 24 | } // namespace SM | 36 | } // namespace SM |