summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/kernel/hle_ipc.cpp4
-rw-r--r--src/core/hle/kernel/k_client_port.cpp5
-rw-r--r--src/core/hle/kernel/k_server_session.h11
-rw-r--r--src/core/hle/service/service.h10
-rw-r--r--src/core/hle/service/sm/sm.cpp8
5 files changed, 21 insertions, 17 deletions
diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp
index 45aced99f..28ed6265a 100644
--- a/src/core/hle/kernel/hle_ipc.cpp
+++ b/src/core/hle/kernel/hle_ipc.cpp
@@ -57,11 +57,11 @@ bool SessionRequestManager::HasSessionRequestHandler(const HLERequestContext& co
57} 57}
58 58
59void SessionRequestHandler::ClientConnected(KServerSession* session) { 59void SessionRequestHandler::ClientConnected(KServerSession* session) {
60 session->SetSessionHandler(shared_from_this()); 60 session->ClientConnected(shared_from_this());
61} 61}
62 62
63void SessionRequestHandler::ClientDisconnected(KServerSession* session) { 63void SessionRequestHandler::ClientDisconnected(KServerSession* session) {
64 session->SetSessionHandler(nullptr); 64 session->ClientDisconnected();
65} 65}
66 66
67HLERequestContext::HLERequestContext(KernelCore& kernel_, Core::Memory::Memory& memory_, 67HLERequestContext::HLERequestContext(KernelCore& kernel_, Core::Memory::Memory& memory_,
diff --git a/src/core/hle/kernel/k_client_port.cpp b/src/core/hle/kernel/k_client_port.cpp
index 50606bd91..ef168fe87 100644
--- a/src/core/hle/kernel/k_client_port.cpp
+++ b/src/core/hle/kernel/k_client_port.cpp
@@ -28,6 +28,9 @@ void KClientPort::Initialize(KPort* parent_port_, s32 max_sessions_, std::string
28void KClientPort::OnSessionFinalized() { 28void KClientPort::OnSessionFinalized() {
29 KScopedSchedulerLock sl{kernel}; 29 KScopedSchedulerLock sl{kernel};
30 30
31 // This might happen if a session was improperly used with this port.
32 ASSERT_MSG(num_sessions > 0, "num_sessions is invalid");
33
31 const auto prev = num_sessions--; 34 const auto prev = num_sessions--;
32 if (prev == max_sessions) { 35 if (prev == max_sessions) {
33 this->NotifyAvailable(); 36 this->NotifyAvailable();
@@ -66,7 +69,7 @@ ResultCode KClientPort::CreateSession(KClientSession** out,
66 // Update the session counts. 69 // Update the session counts.
67 { 70 {
68 // Atomically increment the number of sessions. 71 // Atomically increment the number of sessions.
69 s32 new_sessions; 72 s32 new_sessions{};
70 { 73 {
71 const auto max = max_sessions; 74 const auto max = max_sessions;
72 auto cur_sessions = num_sessions.load(std::memory_order_acquire); 75 auto cur_sessions = num_sessions.load(std::memory_order_acquire);
diff --git a/src/core/hle/kernel/k_server_session.h b/src/core/hle/kernel/k_server_session.h
index 9efd400bc..d44bc9d4f 100644
--- a/src/core/hle/kernel/k_server_session.h
+++ b/src/core/hle/kernel/k_server_session.h
@@ -62,15 +62,14 @@ public:
62 62
63 void OnClientClosed(); 63 void OnClientClosed();
64 64
65 /** 65 void ClientConnected(SessionRequestHandlerPtr handler) {
66 * Sets the HLE handler for the session. This handler will be called to service IPC requests
67 * instead of the regular IPC machinery. (The regular IPC machinery is currently not
68 * implemented.)
69 */
70 void SetSessionHandler(SessionRequestHandlerPtr handler) {
71 manager->SetSessionHandler(std::move(handler)); 66 manager->SetSessionHandler(std::move(handler));
72 } 67 }
73 68
69 void ClientDisconnected() {
70 manager = nullptr;
71 }
72
74 /** 73 /**
75 * Handle a sync request from the emulated application. 74 * Handle a sync request from the emulated application.
76 * 75 *
diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.h
index 7f133a7cb..e078ac176 100644
--- a/src/core/hle/service/service.h
+++ b/src/core/hle/service/service.h
@@ -40,9 +40,11 @@ namespace SM {
40class ServiceManager; 40class ServiceManager;
41} 41}
42 42
43static const int kMaxPortSize = 8; ///< Maximum size of a port name (8 characters) 43/// Default number of maximum connections to a server session.
44/// Arbitrary default number of maximum connections to an HLE service. 44static constexpr u32 ServerSessionCountMax = 0x40;
45static const u32 DefaultMaxSessions = 0x10000; 45static_assert(ServerSessionCountMax == 0x40,
46 "ServerSessionCountMax isn't 0x40 somehow, this assert is a reminder that this will "
47 "break lots of things");
46 48
47/** 49/**
48 * This is an non-templated base of ServiceFramework to reduce code bloat and compilation times, it 50 * This is an non-templated base of ServiceFramework to reduce code bloat and compilation times, it
@@ -178,7 +180,7 @@ protected:
178 * connected to this service at the same time. 180 * connected to this service at the same time.
179 */ 181 */
180 explicit ServiceFramework(Core::System& system_, const char* service_name_, 182 explicit ServiceFramework(Core::System& system_, const char* service_name_,
181 u32 max_sessions_ = DefaultMaxSessions) 183 u32 max_sessions_ = ServerSessionCountMax)
182 : ServiceFrameworkBase(system_, service_name_, max_sessions_, Invoker) {} 184 : ServiceFrameworkBase(system_, service_name_, max_sessions_, Invoker) {}
183 185
184 /// Registers handlers in the service. 186 /// Registers handlers in the service.
diff --git a/src/core/hle/service/sm/sm.cpp b/src/core/hle/service/sm/sm.cpp
index bffa9ffcb..a1e1a7d76 100644
--- a/src/core/hle/service/sm/sm.cpp
+++ b/src/core/hle/service/sm/sm.cpp
@@ -164,18 +164,18 @@ ResultVal<Kernel::KClientSession*> SM::GetServiceImpl(Kernel::HLERequestContext&
164 R_UNLESS(session_reservation.Succeeded(), Kernel::ResultLimitReached); 164 R_UNLESS(session_reservation.Succeeded(), Kernel::ResultLimitReached);
165 165
166 // Create a new session. 166 // Create a new session.
167 auto* session = Kernel::KSession::Create(kernel); 167 Kernel::KClientSession* session{};
168 session->Initialize(&port->GetClientPort(), std::move(name)); 168 port->GetClientPort().CreateSession(std::addressof(session));
169 169
170 // Commit the session reservation. 170 // Commit the session reservation.
171 session_reservation.Commit(); 171 session_reservation.Commit();
172 172
173 // Enqueue the session with the named port. 173 // Enqueue the session with the named port.
174 port->EnqueueSession(&session->GetServerSession()); 174 port->EnqueueSession(&session->GetParent()->GetServerSession());
175 175
176 LOG_DEBUG(Service_SM, "called service={} -> session={}", name, session->GetId()); 176 LOG_DEBUG(Service_SM, "called service={} -> session={}", name, session->GetId());
177 177
178 return MakeResult(&session->GetClientSession()); 178 return MakeResult(session);
179} 179}
180 180
181void SM::RegisterService(Kernel::HLERequestContext& ctx) { 181void SM::RegisterService(Kernel::HLERequestContext& ctx) {