summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hle/kernel')
-rw-r--r--src/core/hle/kernel/client_session.cpp10
-rw-r--r--src/core/hle/kernel/client_session.h4
-rw-r--r--src/core/hle/kernel/server_session.cpp22
-rw-r--r--src/core/hle/kernel/server_session.h14
4 files changed, 39 insertions, 11 deletions
diff --git a/src/core/hle/kernel/client_session.cpp b/src/core/hle/kernel/client_session.cpp
index fef97af1f..646a5cc64 100644
--- a/src/core/hle/kernel/client_session.cpp
+++ b/src/core/hle/kernel/client_session.cpp
@@ -9,6 +9,7 @@
9#include "core/hle/kernel/hle_ipc.h" 9#include "core/hle/kernel/hle_ipc.h"
10#include "core/hle/kernel/server_session.h" 10#include "core/hle/kernel/server_session.h"
11#include "core/hle/kernel/session.h" 11#include "core/hle/kernel/session.h"
12#include "core/hle/kernel/thread.h"
12 13
13namespace Kernel { 14namespace Kernel {
14 15
@@ -27,19 +28,24 @@ ClientSession::~ClientSession() {
27 28
28 // TODO(Subv): Force a wake up of all the ServerSession's waiting threads and set 29 // TODO(Subv): Force a wake up of all the ServerSession's waiting threads and set
29 // their WaitSynchronization result to 0xC920181A. 30 // their WaitSynchronization result to 0xC920181A.
31
32 // Clean up the list of client threads with pending requests, they are unneeded now that the
33 // client endpoint is closed.
34 server->pending_requesting_threads.clear();
35 server->currently_handling = nullptr;
30 } 36 }
31 37
32 parent->client = nullptr; 38 parent->client = nullptr;
33} 39}
34 40
35ResultCode ClientSession::SendSyncRequest() { 41ResultCode ClientSession::SendSyncRequest(SharedPtr<Thread> thread) {
36 // Keep ServerSession alive until we're done working with it. 42 // Keep ServerSession alive until we're done working with it.
37 SharedPtr<ServerSession> server = parent->server; 43 SharedPtr<ServerSession> server = parent->server;
38 if (server == nullptr) 44 if (server == nullptr)
39 return ERR_SESSION_CLOSED_BY_REMOTE; 45 return ERR_SESSION_CLOSED_BY_REMOTE;
40 46
41 // Signal the server session that new data is available 47 // Signal the server session that new data is available
42 return server->HandleSyncRequest(); 48 return server->HandleSyncRequest(std::move(thread));
43} 49}
44 50
45} // namespace 51} // namespace
diff --git a/src/core/hle/kernel/client_session.h b/src/core/hle/kernel/client_session.h
index 2de379c09..daf521529 100644
--- a/src/core/hle/kernel/client_session.h
+++ b/src/core/hle/kernel/client_session.h
@@ -14,6 +14,7 @@ namespace Kernel {
14 14
15class ServerSession; 15class ServerSession;
16class Session; 16class Session;
17class Thread;
17 18
18class ClientSession final : public Object { 19class ClientSession final : public Object {
19public: 20public:
@@ -34,9 +35,10 @@ public:
34 35
35 /** 36 /**
36 * Sends an SyncRequest from the current emulated thread. 37 * Sends an SyncRequest from the current emulated thread.
38 * @param thread Thread that initiated the request.
37 * @return ResultCode of the operation. 39 * @return ResultCode of the operation.
38 */ 40 */
39 ResultCode SendSyncRequest(); 41 ResultCode SendSyncRequest(SharedPtr<Thread> thread);
40 42
41 std::string name; ///< Name of client port (optional) 43 std::string name; ///< Name of client port (optional)
42 44
diff --git a/src/core/hle/kernel/server_session.cpp b/src/core/hle/kernel/server_session.cpp
index d197137c3..337896abf 100644
--- a/src/core/hle/kernel/server_session.cpp
+++ b/src/core/hle/kernel/server_session.cpp
@@ -32,22 +32,29 @@ ResultVal<SharedPtr<ServerSession>> ServerSession::Create(std::string name) {
32 SharedPtr<ServerSession> server_session(new ServerSession); 32 SharedPtr<ServerSession> server_session(new ServerSession);
33 33
34 server_session->name = std::move(name); 34 server_session->name = std::move(name);
35 server_session->signaled = false;
36 server_session->parent = nullptr; 35 server_session->parent = nullptr;
37 36
38 return MakeResult(std::move(server_session)); 37 return MakeResult(std::move(server_session));
39} 38}
40 39
41bool ServerSession::ShouldWait(Thread* thread) const { 40bool ServerSession::ShouldWait(Thread* thread) const {
42 return !signaled; 41 // Closed sessions should never wait, an error will be returned from svcReplyAndReceive.
42 if (parent->client == nullptr)
43 return false;
44 // Wait if we have no pending requests, or if we're currently handling a request.
45 return pending_requesting_threads.empty() || currently_handling != nullptr;
43} 46}
44 47
45void ServerSession::Acquire(Thread* thread) { 48void ServerSession::Acquire(Thread* thread) {
46 ASSERT_MSG(!ShouldWait(thread), "object unavailable!"); 49 ASSERT_MSG(!ShouldWait(thread), "object unavailable!");
47 signaled = false; 50 // We are now handling a request, pop it from the stack.
51 // TODO(Subv): What happens if the client endpoint is closed before any requests are made?
52 ASSERT(!pending_requesting_threads.empty());
53 currently_handling = pending_requesting_threads.back();
54 pending_requesting_threads.pop_back();
48} 55}
49 56
50ResultCode ServerSession::HandleSyncRequest() { 57ResultCode ServerSession::HandleSyncRequest(SharedPtr<Thread> thread) {
51 // The ServerSession received a sync request, this means that there's new data available 58 // The ServerSession received a sync request, this means that there's new data available
52 // from its ClientSession, so wake up any threads that may be waiting on a svcReplyAndReceive or 59 // from its ClientSession, so wake up any threads that may be waiting on a svcReplyAndReceive or
53 // similar. 60 // similar.
@@ -60,11 +67,14 @@ ResultCode ServerSession::HandleSyncRequest() {
60 return result; 67 return result;
61 hle_handler->HandleSyncRequest(SharedPtr<ServerSession>(this)); 68 hle_handler->HandleSyncRequest(SharedPtr<ServerSession>(this));
62 // TODO(Subv): Translate the response command buffer. 69 // TODO(Subv): Translate the response command buffer.
70 } else {
71 // Add the thread to the list of threads that have issued a sync request with this
72 // server.
73 pending_requesting_threads.push_back(std::move(thread));
63 } 74 }
64 75
65 // If this ServerSession does not have an HLE implementation, just wake up the threads waiting 76 // If this ServerSession does not have an HLE implementation, just wake up the threads waiting
66 // on it. 77 // on it.
67 signaled = true;
68 WakeupAllWaitingThreads(); 78 WakeupAllWaitingThreads();
69 return RESULT_SUCCESS; 79 return RESULT_SUCCESS;
70} 80}
@@ -90,4 +100,4 @@ ResultCode TranslateHLERequest(ServerSession* server_session) {
90 // TODO(Subv): Implement this function once multiple concurrent processes are supported. 100 // TODO(Subv): Implement this function once multiple concurrent processes are supported.
91 return RESULT_SUCCESS; 101 return RESULT_SUCCESS;
92} 102}
93} 103} // namespace Kernel
diff --git a/src/core/hle/kernel/server_session.h b/src/core/hle/kernel/server_session.h
index 5365605da..f4360ddf3 100644
--- a/src/core/hle/kernel/server_session.h
+++ b/src/core/hle/kernel/server_session.h
@@ -67,20 +67,30 @@ public:
67 67
68 /** 68 /**
69 * Handle a sync request from the emulated application. 69 * Handle a sync request from the emulated application.
70 * @param thread Thread that initiated the request.
70 * @returns ResultCode from the operation. 71 * @returns ResultCode from the operation.
71 */ 72 */
72 ResultCode HandleSyncRequest(); 73 ResultCode HandleSyncRequest(SharedPtr<Thread> thread);
73 74
74 bool ShouldWait(Thread* thread) const override; 75 bool ShouldWait(Thread* thread) const override;
75 76
76 void Acquire(Thread* thread) override; 77 void Acquire(Thread* thread) override;
77 78
78 std::string name; ///< The name of this session (optional) 79 std::string name; ///< The name of this session (optional)
79 bool signaled; ///< Whether there's new data available to this ServerSession
80 std::shared_ptr<Session> parent; ///< The parent session, which links to the client endpoint. 80 std::shared_ptr<Session> parent; ///< The parent session, which links to the client endpoint.
81 std::shared_ptr<SessionRequestHandler> 81 std::shared_ptr<SessionRequestHandler>
82 hle_handler; ///< This session's HLE request handler (optional) 82 hle_handler; ///< This session's HLE request handler (optional)
83 83
84 /// List of threads that are pending a response after a sync request. This list is processed in
85 /// a LIFO manner, thus, the last request will be dispatched first.
86 /// TODO(Subv): Verify if this is indeed processed in LIFO using a hardware test.
87 std::vector<SharedPtr<Thread>> pending_requesting_threads;
88
89 /// Thread whose request is currently being handled. A request is considered "handled" when a
90 /// response is sent via svcReplyAndReceive.
91 /// TODO(Subv): Find a better name for this.
92 SharedPtr<Thread> currently_handling;
93
84private: 94private:
85 ServerSession(); 95 ServerSession();
86 ~ServerSession() override; 96 ~ServerSession() override;