summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel
diff options
context:
space:
mode:
authorGravatar bunnei2018-01-23 18:03:09 -0500
committerGravatar bunnei2018-01-24 22:18:56 -0500
commit27bad0598a3ddce0417388c3945368200150d413 (patch)
tree8afc27be2a01d80cc592a698632b2fbcae71d8a5 /src/core/hle/kernel
parenthle: Remove Domain and SyncObject kernel objects. (diff)
downloadyuzu-27bad0598a3ddce0417388c3945368200150d413.tar.gz
yuzu-27bad0598a3ddce0417388c3945368200150d413.tar.xz
yuzu-27bad0598a3ddce0417388c3945368200150d413.zip
hle: Integrate Domain handling into ServerSession.
Diffstat (limited to 'src/core/hle/kernel')
-rw-r--r--src/core/hle/kernel/client_session.h3
-rw-r--r--src/core/hle/kernel/hle_ipc.cpp10
-rw-r--r--src/core/hle/kernel/hle_ipc.h16
-rw-r--r--src/core/hle/kernel/server_session.cpp47
-rw-r--r--src/core/hle/kernel/server_session.h18
5 files changed, 66 insertions, 28 deletions
diff --git a/src/core/hle/kernel/client_session.h b/src/core/hle/kernel/client_session.h
index f2765cc1e..2258f95bc 100644
--- a/src/core/hle/kernel/client_session.h
+++ b/src/core/hle/kernel/client_session.h
@@ -7,6 +7,7 @@
7#include <memory> 7#include <memory>
8#include <string> 8#include <string>
9#include "common/common_types.h" 9#include "common/common_types.h"
10#include "core/hle/kernel/kernel.h"
10#include "core/hle/result.h" 11#include "core/hle/result.h"
11 12
12namespace Kernel { 13namespace Kernel {
@@ -32,7 +33,7 @@ public:
32 return HANDLE_TYPE; 33 return HANDLE_TYPE;
33 } 34 }
34 35
35 ResultCode SendSyncRequest(SharedPtr<Thread> thread) override; 36 ResultCode SendSyncRequest(SharedPtr<Thread> thread);
36 37
37 std::string name; ///< Name of client port (optional) 38 std::string name; ///< Name of client port (optional)
38 39
diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp
index 2cd6de12e..db104e8a2 100644
--- a/src/core/hle/kernel/hle_ipc.cpp
+++ b/src/core/hle/kernel/hle_ipc.cpp
@@ -25,10 +25,6 @@ void SessionRequestHandler::ClientDisconnected(SharedPtr<ServerSession> server_s
25 boost::range::remove_erase(connected_sessions, server_session); 25 boost::range::remove_erase(connected_sessions, server_session);
26} 26}
27 27
28HLERequestContext::HLERequestContext(SharedPtr<Kernel::Domain> domain) : domain(std::move(domain)) {
29 cmd_buf[0] = 0;
30}
31
32HLERequestContext::HLERequestContext(SharedPtr<Kernel::ServerSession> server_session) 28HLERequestContext::HLERequestContext(SharedPtr<Kernel::ServerSession> server_session)
33 : server_session(std::move(server_session)) { 29 : server_session(std::move(server_session)) {
34 cmd_buf[0] = 0; 30 cmd_buf[0] = 0;
@@ -86,7 +82,7 @@ void HLERequestContext::ParseCommandBuffer(u32_le* src_cmdbuf, bool incoming) {
86 // Padding to align to 16 bytes 82 // Padding to align to 16 bytes
87 rp.AlignWithPadding(); 83 rp.AlignWithPadding();
88 84
89 if (IsDomain() && (command_header->type == IPC::CommandType::Request || !incoming)) { 85 if (Session()->IsDomain() && (command_header->type == IPC::CommandType::Request || !incoming)) {
90 // If this is an incoming message, only CommandType "Request" has a domain header 86 // If this is an incoming message, only CommandType "Request" has a domain header
91 // All outgoing domain messages have the domain header 87 // All outgoing domain messages have the domain header
92 domain_message_header = 88 domain_message_header =
@@ -199,12 +195,12 @@ ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(u32_le* dst_cmdbuf, P
199 195
200 // TODO(Subv): Translate the X/A/B/W buffers. 196 // TODO(Subv): Translate the X/A/B/W buffers.
201 197
202 if (IsDomain()) { 198 if (Session()->IsDomain()) {
203 ASSERT(domain_message_header->num_objects == domain_objects.size()); 199 ASSERT(domain_message_header->num_objects == domain_objects.size());
204 // Write the domain objects to the command buffer, these go after the raw untranslated data. 200 // Write the domain objects to the command buffer, these go after the raw untranslated data.
205 // TODO(Subv): This completely ignores C buffers. 201 // TODO(Subv): This completely ignores C buffers.
206 size_t domain_offset = size - domain_message_header->num_objects; 202 size_t domain_offset = size - domain_message_header->num_objects;
207 auto& request_handlers = domain->request_handlers; 203 auto& request_handlers = server_session->domain_request_handlers;
208 204
209 for (auto& object : domain_objects) { 205 for (auto& object : domain_objects) {
210 request_handlers.emplace_back(object); 206 request_handlers.emplace_back(object);
diff --git a/src/core/hle/kernel/hle_ipc.h b/src/core/hle/kernel/hle_ipc.h
index 80fa48d7f..71e5609b8 100644
--- a/src/core/hle/kernel/hle_ipc.h
+++ b/src/core/hle/kernel/hle_ipc.h
@@ -86,7 +86,6 @@ protected:
86 */ 86 */
87class HLERequestContext { 87class HLERequestContext {
88public: 88public:
89 HLERequestContext(SharedPtr<Kernel::Domain> domain);
90 HLERequestContext(SharedPtr<Kernel::ServerSession> session); 89 HLERequestContext(SharedPtr<Kernel::ServerSession> session);
91 ~HLERequestContext(); 90 ~HLERequestContext();
92 91
@@ -96,17 +95,10 @@ public:
96 } 95 }
97 96
98 /** 97 /**
99 * Returns the domain through which this request was made.
100 */
101 const SharedPtr<Kernel::Domain>& Domain() const {
102 return domain;
103 }
104
105 /**
106 * Returns the session through which this request was made. This can be used as a map key to 98 * Returns the session through which this request was made. This can be used as a map key to
107 * access per-client data on services. 99 * access per-client data on services.
108 */ 100 */
109 const SharedPtr<Kernel::ServerSession>& ServerSession() const { 101 const SharedPtr<Kernel::ServerSession>& Session() const {
110 return server_session; 102 return server_session;
111 } 103 }
112 104
@@ -151,10 +143,6 @@ public:
151 return domain_message_header; 143 return domain_message_header;
152 } 144 }
153 145
154 bool IsDomain() const {
155 return domain != nullptr;
156 }
157
158 template <typename T> 146 template <typename T>
159 SharedPtr<T> GetCopyObject(size_t index) { 147 SharedPtr<T> GetCopyObject(size_t index) {
160 ASSERT(index < copy_objects.size()); 148 ASSERT(index < copy_objects.size());
@@ -189,7 +177,6 @@ public:
189 177
190private: 178private:
191 std::array<u32, IPC::COMMAND_BUFFER_LENGTH> cmd_buf; 179 std::array<u32, IPC::COMMAND_BUFFER_LENGTH> cmd_buf;
192 SharedPtr<Kernel::Domain> domain;
193 SharedPtr<Kernel::ServerSession> server_session; 180 SharedPtr<Kernel::ServerSession> server_session;
194 // TODO(yuriks): Check common usage of this and optimize size accordingly 181 // TODO(yuriks): Check common usage of this and optimize size accordingly
195 boost::container::small_vector<SharedPtr<Object>, 8> move_objects; 182 boost::container::small_vector<SharedPtr<Object>, 8> move_objects;
@@ -209,6 +196,7 @@ private:
209 unsigned data_payload_offset{}; 196 unsigned data_payload_offset{};
210 unsigned buffer_c_offset{}; 197 unsigned buffer_c_offset{};
211 u32_le command{}; 198 u32_le command{};
199 bool is_domain{};
212}; 200};
213 201
214} // namespace Kernel 202} // namespace Kernel
diff --git a/src/core/hle/kernel/server_session.cpp b/src/core/hle/kernel/server_session.cpp
index 09d02a691..b79bf7bab 100644
--- a/src/core/hle/kernel/server_session.cpp
+++ b/src/core/hle/kernel/server_session.cpp
@@ -4,6 +4,7 @@
4 4
5#include <tuple> 5#include <tuple>
6 6
7#include "core/hle/ipc_helpers.h"
7#include "core/hle/kernel/client_port.h" 8#include "core/hle/kernel/client_port.h"
8#include "core/hle/kernel/client_session.h" 9#include "core/hle/kernel/client_session.h"
9#include "core/hle/kernel/handle_table.h" 10#include "core/hle/kernel/handle_table.h"
@@ -61,6 +62,38 @@ ResultCode ServerSession::HandleSyncRequest(SharedPtr<Thread> thread) {
61 // from its ClientSession, so wake up any threads that may be waiting on a svcReplyAndReceive or 62 // from its ClientSession, so wake up any threads that may be waiting on a svcReplyAndReceive or
62 // similar. 63 // similar.
63 64
65 Kernel::HLERequestContext context(this);
66 u32* cmd_buf = (u32*)Memory::GetPointer(thread->GetTLSAddress());
67 context.PopulateFromIncomingCommandBuffer(cmd_buf, *Kernel::g_current_process,
68 Kernel::g_handle_table);
69
70 // If the session has been converted to a domain, handle the doomain request
71 if (IsDomain()) {
72 auto& domain_message_header = context.GetDomainMessageHeader();
73 if (domain_message_header) {
74 // If there is a DomainMessageHeader, then this is CommandType "Request"
75 const u32 object_id{context.GetDomainMessageHeader()->object_id};
76 switch (domain_message_header->command) {
77 case IPC::DomainMessageHeader::CommandType::SendMessage:
78 return domain_request_handlers[object_id - 1]->HandleSyncRequest(context);
79
80 case IPC::DomainMessageHeader::CommandType::CloseVirtualHandle: {
81 LOG_DEBUG(IPC, "CloseVirtualHandle, object_id=0x%08X", object_id);
82
83 domain_request_handlers[object_id - 1] = nullptr;
84
85 IPC::RequestBuilder rb{context, 2};
86 rb.Push(RESULT_SUCCESS);
87 return RESULT_SUCCESS;
88 }
89 }
90
91 LOG_CRITICAL(IPC, "Unknown domain command=%d", domain_message_header->command.Value());
92 UNIMPLEMENTED();
93 }
94 return domain_request_handlers.front()->HandleSyncRequest(context);
95 }
96
64 // If this ServerSession has an associated HLE handler, forward the request to it. 97 // If this ServerSession has an associated HLE handler, forward the request to it.
65 ResultCode result{RESULT_SUCCESS}; 98 ResultCode result{RESULT_SUCCESS};
66 if (hle_handler != nullptr) { 99 if (hle_handler != nullptr) {
@@ -69,11 +102,6 @@ ResultCode ServerSession::HandleSyncRequest(SharedPtr<Thread> thread) {
69 if (translate_result.IsError()) 102 if (translate_result.IsError())
70 return translate_result; 103 return translate_result;
71 104
72 Kernel::HLERequestContext context(this);
73 u32* cmd_buf = (u32*)Memory::GetPointer(Kernel::GetCurrentThread()->GetTLSAddress());
74 context.PopulateFromIncomingCommandBuffer(cmd_buf, *Kernel::g_current_process,
75 Kernel::g_handle_table);
76
77 result = hle_handler->HandleSyncRequest(context); 105 result = hle_handler->HandleSyncRequest(context);
78 } else { 106 } else {
79 // Add the thread to the list of threads that have issued a sync request with this 107 // Add the thread to the list of threads that have issued a sync request with this
@@ -84,6 +112,15 @@ ResultCode ServerSession::HandleSyncRequest(SharedPtr<Thread> thread) {
84 // If this ServerSession does not have an HLE implementation, just wake up the threads waiting 112 // If this ServerSession does not have an HLE implementation, just wake up the threads waiting
85 // on it. 113 // on it.
86 WakeupAllWaitingThreads(); 114 WakeupAllWaitingThreads();
115
116 // Handle scenario when ConvertToDomain command was issued, as we must do the conversion at the
117 // end of the command such that only commands following this one are handled as domains
118 if (convert_to_domain) {
119 ASSERT_MSG(domain_request_handlers.empty(), "already a domain");
120 domain_request_handlers.push_back(std::move(hle_handler));
121 convert_to_domain = false;
122 }
123
87 return result; 124 return result;
88} 125}
89 126
diff --git a/src/core/hle/kernel/server_session.h b/src/core/hle/kernel/server_session.h
index 6ff4ef8c1..144692106 100644
--- a/src/core/hle/kernel/server_session.h
+++ b/src/core/hle/kernel/server_session.h
@@ -79,7 +79,10 @@ public:
79 std::string name; ///< The name of this session (optional) 79 std::string name; ///< The name of this session (optional)
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 (applicable when not a domain)
83
84 /// This is the list of domain request handlers (after conversion to a domain)
85 std::vector<std::shared_ptr<SessionRequestHandler>> domain_request_handlers;
83 86
84 /// List of threads that are pending a response after a sync request. This list is processed in 87 /// 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. 88 /// a LIFO manner, thus, the last request will be dispatched first.
@@ -91,6 +94,16 @@ public:
91 /// TODO(Subv): Find a better name for this. 94 /// TODO(Subv): Find a better name for this.
92 SharedPtr<Thread> currently_handling; 95 SharedPtr<Thread> currently_handling;
93 96
97 /// Returns true if the session has been converted to a domain, otherwise False
98 bool IsDomain() const {
99 return !domain_request_handlers.empty();
100 }
101
102 /// Converts the session to a domain at the end of the current command
103 void ConvertToDomain() {
104 convert_to_domain = true;
105 }
106
94private: 107private:
95 ServerSession(); 108 ServerSession();
96 ~ServerSession() override; 109 ~ServerSession() override;
@@ -102,6 +115,9 @@ private:
102 * @return The created server session 115 * @return The created server session
103 */ 116 */
104 static ResultVal<SharedPtr<ServerSession>> Create(std::string name = "Unknown"); 117 static ResultVal<SharedPtr<ServerSession>> Create(std::string name = "Unknown");
118
119 /// When set to True, converts the session to a domain at the end of the command
120 bool convert_to_domain{};
105}; 121};
106 122
107/** 123/**