diff options
| author | 2017-12-29 00:36:22 -0500 | |
|---|---|---|
| committer | 2017-12-29 00:36:22 -0500 | |
| commit | dcdaac8a0b5ae5b8d251c3713d3024287b0720b1 (patch) | |
| tree | 35cb5631e4d00d1582aa238cf93abdc73b6afa8a /src/core/hle/kernel | |
| parent | ap, aoc_u: Minor cleanup. (diff) | |
| download | yuzu-dcdaac8a0b5ae5b8d251c3713d3024287b0720b1.tar.gz yuzu-dcdaac8a0b5ae5b8d251c3713d3024287b0720b1.tar.xz yuzu-dcdaac8a0b5ae5b8d251c3713d3024287b0720b1.zip | |
kernel: Fix implementation of ConvertSessionToDomain.
Diffstat (limited to 'src/core/hle/kernel')
| -rw-r--r-- | src/core/hle/kernel/handle_table.cpp | 10 | ||||
| -rw-r--r-- | src/core/hle/kernel/handle_table.h | 7 | ||||
| -rw-r--r-- | src/core/hle/kernel/hle_ipc.cpp | 30 | ||||
| -rw-r--r-- | src/core/hle/kernel/hle_ipc.h | 29 | ||||
| -rw-r--r-- | src/core/hle/kernel/server_session.cpp | 11 | ||||
| -rw-r--r-- | src/core/hle/kernel/server_session.h | 10 |
6 files changed, 67 insertions, 30 deletions
diff --git a/src/core/hle/kernel/handle_table.cpp b/src/core/hle/kernel/handle_table.cpp index c7322d883..12506e64c 100644 --- a/src/core/hle/kernel/handle_table.cpp +++ b/src/core/hle/kernel/handle_table.cpp | |||
| @@ -5,10 +5,12 @@ | |||
| 5 | #include <utility> | 5 | #include <utility> |
| 6 | #include "common/assert.h" | 6 | #include "common/assert.h" |
| 7 | #include "common/logging/log.h" | 7 | #include "common/logging/log.h" |
| 8 | #include "core/hle/kernel/client_session.h" | ||
| 8 | #include "core/hle/kernel/errors.h" | 9 | #include "core/hle/kernel/errors.h" |
| 9 | #include "core/hle/kernel/handle_table.h" | 10 | #include "core/hle/kernel/handle_table.h" |
| 10 | #include "core/hle/kernel/kernel.h" | 11 | #include "core/hle/kernel/kernel.h" |
| 11 | #include "core/hle/kernel/process.h" | 12 | #include "core/hle/kernel/process.h" |
| 13 | #include "core/hle/kernel/session.h" | ||
| 12 | #include "core/hle/kernel/thread.h" | 14 | #include "core/hle/kernel/thread.h" |
| 13 | 15 | ||
| 14 | namespace Kernel { | 16 | namespace Kernel { |
| @@ -53,6 +55,14 @@ ResultVal<Handle> HandleTable::Duplicate(Handle handle) { | |||
| 53 | return Create(std::move(object)); | 55 | return Create(std::move(object)); |
| 54 | } | 56 | } |
| 55 | 57 | ||
| 58 | void HandleTable::ConvertSessionToDomain(const Session& session, SharedPtr<Object> domain) { | ||
| 59 | for (auto& object : objects) { | ||
| 60 | if (DynamicObjectCast<ClientSession>(object) == session.client) { | ||
| 61 | object = domain; | ||
| 62 | } | ||
| 63 | } | ||
| 64 | } | ||
| 65 | |||
| 56 | ResultCode HandleTable::Close(Handle handle) { | 66 | ResultCode HandleTable::Close(Handle handle) { |
| 57 | if (!IsValid(handle)) | 67 | if (!IsValid(handle)) |
| 58 | return ERR_INVALID_HANDLE; | 68 | return ERR_INVALID_HANDLE; |
diff --git a/src/core/hle/kernel/handle_table.h b/src/core/hle/kernel/handle_table.h index d6aaefbf7..dba5573a8 100644 --- a/src/core/hle/kernel/handle_table.h +++ b/src/core/hle/kernel/handle_table.h | |||
| @@ -17,6 +17,8 @@ enum KernelHandle : Handle { | |||
| 17 | CurrentProcess = 0xFFFF8001, | 17 | CurrentProcess = 0xFFFF8001, |
| 18 | }; | 18 | }; |
| 19 | 19 | ||
| 20 | class Session; | ||
| 21 | |||
| 20 | /** | 22 | /** |
| 21 | * This class allows the creation of Handles, which are references to objects that can be tested | 23 | * This class allows the creation of Handles, which are references to objects that can be tested |
| 22 | * for validity and looked up. Here they are used to pass references to kernel objects to/from the | 24 | * for validity and looked up. Here they are used to pass references to kernel objects to/from the |
| @@ -60,6 +62,11 @@ public: | |||
| 60 | ResultVal<Handle> Duplicate(Handle handle); | 62 | ResultVal<Handle> Duplicate(Handle handle); |
| 61 | 63 | ||
| 62 | /** | 64 | /** |
| 65 | * Convert all handles of the specified Session to the specified Domain. | ||
| 66 | */ | ||
| 67 | void ConvertSessionToDomain(const Session& session, SharedPtr<Object> domain); | ||
| 68 | |||
| 69 | /** | ||
| 63 | * Closes a handle, removing it from the table and decreasing the object's ref-count. | 70 | * Closes a handle, removing it from the table and decreasing the object's ref-count. |
| 64 | * @return `RESULT_SUCCESS` or one of the following errors: | 71 | * @return `RESULT_SUCCESS` or one of the following errors: |
| 65 | * - `ERR_INVALID_HANDLE`: an invalid handle was passed in. | 72 | * - `ERR_INVALID_HANDLE`: an invalid handle was passed in. |
diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp index 427642cab..85dd80159 100644 --- a/src/core/hle/kernel/hle_ipc.cpp +++ b/src/core/hle/kernel/hle_ipc.cpp | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | #include "common/common_funcs.h" | 7 | #include "common/common_funcs.h" |
| 8 | #include "common/common_types.h" | 8 | #include "common/common_types.h" |
| 9 | #include "core/hle/ipc_helpers.h" | 9 | #include "core/hle/ipc_helpers.h" |
| 10 | #include "core/hle/kernel/domain.h" | ||
| 10 | #include "core/hle/kernel/handle_table.h" | 11 | #include "core/hle/kernel/handle_table.h" |
| 11 | #include "core/hle/kernel/hle_ipc.h" | 12 | #include "core/hle/kernel/hle_ipc.h" |
| 12 | #include "core/hle/kernel/kernel.h" | 13 | #include "core/hle/kernel/kernel.h" |
| @@ -25,8 +26,12 @@ void SessionRequestHandler::ClientDisconnected(SharedPtr<ServerSession> server_s | |||
| 25 | boost::range::remove_erase(connected_sessions, server_session); | 26 | boost::range::remove_erase(connected_sessions, server_session); |
| 26 | } | 27 | } |
| 27 | 28 | ||
| 28 | HLERequestContext::HLERequestContext(SharedPtr<ServerSession> session) | 29 | HLERequestContext::HLERequestContext(SharedPtr<Kernel::Domain> domain) : domain(std::move(domain)) { |
| 29 | : session(std::move(session)) { | 30 | cmd_buf[0] = 0; |
| 31 | } | ||
| 32 | |||
| 33 | HLERequestContext::HLERequestContext(SharedPtr<Kernel::ServerSession> server_session) | ||
| 34 | : server_session(std::move(server_session)) { | ||
| 30 | cmd_buf[0] = 0; | 35 | cmd_buf[0] = 0; |
| 31 | } | 36 | } |
| 32 | 37 | ||
| @@ -66,16 +71,16 @@ void HLERequestContext::ParseCommandBuffer(u32_le* src_cmdbuf, bool incoming) { | |||
| 66 | rp.Skip(handle_descriptor_header->num_handles_to_move, false); | 71 | rp.Skip(handle_descriptor_header->num_handles_to_move, false); |
| 67 | } | 72 | } |
| 68 | 73 | ||
| 69 | for (int i = 0; i < command_header->num_buf_x_descriptors; ++i) { | 74 | for (unsigned i = 0; i < command_header->num_buf_x_descriptors; ++i) { |
| 70 | buffer_x_desciptors.push_back(rp.PopRaw<IPC::BufferDescriptorX>()); | 75 | buffer_x_desciptors.push_back(rp.PopRaw<IPC::BufferDescriptorX>()); |
| 71 | } | 76 | } |
| 72 | for (int i = 0; i < command_header->num_buf_a_descriptors; ++i) { | 77 | for (unsigned i = 0; i < command_header->num_buf_a_descriptors; ++i) { |
| 73 | buffer_a_desciptors.push_back(rp.PopRaw<IPC::BufferDescriptorABW>()); | 78 | buffer_a_desciptors.push_back(rp.PopRaw<IPC::BufferDescriptorABW>()); |
| 74 | } | 79 | } |
| 75 | for (int i = 0; i < command_header->num_buf_b_descriptors; ++i) { | 80 | for (unsigned i = 0; i < command_header->num_buf_b_descriptors; ++i) { |
| 76 | buffer_b_desciptors.push_back(rp.PopRaw<IPC::BufferDescriptorABW>()); | 81 | buffer_b_desciptors.push_back(rp.PopRaw<IPC::BufferDescriptorABW>()); |
| 77 | } | 82 | } |
| 78 | for (int i = 0; i < command_header->num_buf_w_descriptors; ++i) { | 83 | for (unsigned i = 0; i < command_header->num_buf_w_descriptors; ++i) { |
| 79 | buffer_w_desciptors.push_back(rp.PopRaw<IPC::BufferDescriptorABW>()); | 84 | buffer_w_desciptors.push_back(rp.PopRaw<IPC::BufferDescriptorABW>()); |
| 80 | } | 85 | } |
| 81 | if (command_header->buf_c_descriptor_flags != | 86 | if (command_header->buf_c_descriptor_flags != |
| @@ -85,6 +90,12 @@ void HLERequestContext::ParseCommandBuffer(u32_le* src_cmdbuf, bool incoming) { | |||
| 85 | 90 | ||
| 86 | // Padding to align to 16 bytes | 91 | // Padding to align to 16 bytes |
| 87 | rp.AlignWithPadding(); | 92 | rp.AlignWithPadding(); |
| 93 | |||
| 94 | if (IsDomain() && (command_header->type == IPC::CommandType::Request || !incoming)) { | ||
| 95 | // If this is an incoming message, only CommandType "Request" has a domain header | ||
| 96 | // All outgoing domain messages have the domain header | ||
| 97 | domain_message_header = | ||
| 98 | std::make_unique<IPC::DomainMessageHeader>(rp.PopRaw<IPC::DomainMessageHeader>()); | ||
| 88 | } | 99 | } |
| 89 | 100 | ||
| 90 | data_payload_header = | 101 | data_payload_header = |
| @@ -106,13 +117,6 @@ ResultCode HLERequestContext::PopulateFromIncomingCommandBuffer(u32_le* src_cmdb | |||
| 106 | ParseCommandBuffer(src_cmdbuf, true); | 117 | ParseCommandBuffer(src_cmdbuf, true); |
| 107 | size_t untranslated_size = data_payload_offset + command_header->data_size; | 118 | size_t untranslated_size = data_payload_offset + command_header->data_size; |
| 108 | std::copy_n(src_cmdbuf, untranslated_size, cmd_buf.begin()); | 119 | std::copy_n(src_cmdbuf, untranslated_size, cmd_buf.begin()); |
| 109 | |||
| 110 | if (command_header->enable_handle_descriptor) { | ||
| 111 | if (handle_descriptor_header->num_handles_to_copy || | ||
| 112 | handle_descriptor_header->num_handles_to_move) { | ||
| 113 | UNIMPLEMENTED(); | ||
| 114 | } | ||
| 115 | } | ||
| 116 | return RESULT_SUCCESS; | 120 | return RESULT_SUCCESS; |
| 117 | } | 121 | } |
| 118 | 122 | ||
diff --git a/src/core/hle/kernel/hle_ipc.h b/src/core/hle/kernel/hle_ipc.h index bf8cfc2a3..7de13b36b 100644 --- a/src/core/hle/kernel/hle_ipc.h +++ b/src/core/hle/kernel/hle_ipc.h | |||
| @@ -20,7 +20,9 @@ class ServiceFrameworkBase; | |||
| 20 | 20 | ||
| 21 | namespace Kernel { | 21 | namespace Kernel { |
| 22 | 22 | ||
| 23 | class Domain; | ||
| 23 | class HandleTable; | 24 | class HandleTable; |
| 25 | class HLERequestContext; | ||
| 24 | class Process; | 26 | class Process; |
| 25 | 27 | ||
| 26 | /** | 28 | /** |
| @@ -40,7 +42,7 @@ public: | |||
| 40 | * this request (ServerSession, Originator thread, Translated command buffer, etc). | 42 | * this request (ServerSession, Originator thread, Translated command buffer, etc). |
| 41 | * @returns ResultCode the result code of the translate operation. | 43 | * @returns ResultCode the result code of the translate operation. |
| 42 | */ | 44 | */ |
| 43 | virtual ResultCode HandleSyncRequest(SharedPtr<ServerSession> server_session) = 0; | 45 | virtual ResultCode HandleSyncRequest(Kernel::HLERequestContext& context) = 0; |
| 44 | 46 | ||
| 45 | /** | 47 | /** |
| 46 | * Signals that a client has just connected to this HLE handler and keeps the | 48 | * Signals that a client has just connected to this HLE handler and keeps the |
| @@ -84,7 +86,8 @@ protected: | |||
| 84 | */ | 86 | */ |
| 85 | class HLERequestContext { | 87 | class HLERequestContext { |
| 86 | public: | 88 | public: |
| 87 | HLERequestContext(SharedPtr<ServerSession> session); | 89 | HLERequestContext(SharedPtr<Kernel::Domain> domain); |
| 90 | HLERequestContext(SharedPtr<Kernel::ServerSession> session); | ||
| 88 | ~HLERequestContext(); | 91 | ~HLERequestContext(); |
| 89 | 92 | ||
| 90 | /// Returns a pointer to the IPC command buffer for this request. | 93 | /// Returns a pointer to the IPC command buffer for this request. |
| @@ -93,11 +96,18 @@ public: | |||
| 93 | } | 96 | } |
| 94 | 97 | ||
| 95 | /** | 98 | /** |
| 99 | * Returns the domain through which this request was made. | ||
| 100 | */ | ||
| 101 | const SharedPtr<Kernel::Domain>& Domain() const { | ||
| 102 | return domain; | ||
| 103 | } | ||
| 104 | |||
| 105 | /** | ||
| 96 | * Returns the session through which this request was made. This can be used as a map key to | 106 | * Returns the session through which this request was made. This can be used as a map key to |
| 97 | * access per-client data on services. | 107 | * access per-client data on services. |
| 98 | */ | 108 | */ |
| 99 | SharedPtr<ServerSession> Session() const { | 109 | const SharedPtr<Kernel::ServerSession>& ServerSession() const { |
| 100 | return session; | 110 | return server_session; |
| 101 | } | 111 | } |
| 102 | 112 | ||
| 103 | /** | 113 | /** |
| @@ -144,9 +154,18 @@ public: | |||
| 144 | return buffer_x_desciptors; | 154 | return buffer_x_desciptors; |
| 145 | } | 155 | } |
| 146 | 156 | ||
| 157 | const std::unique_ptr<IPC::DomainMessageHeader>& GetDomainMessageHeader() const { | ||
| 158 | return domain_message_header; | ||
| 159 | } | ||
| 160 | |||
| 161 | bool IsDomain() const { | ||
| 162 | return domain != nullptr; | ||
| 163 | } | ||
| 164 | |||
| 147 | private: | 165 | private: |
| 148 | std::array<u32, IPC::COMMAND_BUFFER_LENGTH> cmd_buf; | 166 | std::array<u32, IPC::COMMAND_BUFFER_LENGTH> cmd_buf; |
| 149 | SharedPtr<ServerSession> session; | 167 | SharedPtr<Kernel::Domain> domain; |
| 168 | SharedPtr<Kernel::ServerSession> server_session; | ||
| 150 | // TODO(yuriks): Check common usage of this and optimize size accordingly | 169 | // TODO(yuriks): Check common usage of this and optimize size accordingly |
| 151 | boost::container::small_vector<SharedPtr<Object>, 8> request_handles; | 170 | boost::container::small_vector<SharedPtr<Object>, 8> request_handles; |
| 152 | 171 | ||
diff --git a/src/core/hle/kernel/server_session.cpp b/src/core/hle/kernel/server_session.cpp index 68e5cc2b7..09d02a691 100644 --- a/src/core/hle/kernel/server_session.cpp +++ b/src/core/hle/kernel/server_session.cpp | |||
| @@ -6,7 +6,9 @@ | |||
| 6 | 6 | ||
| 7 | #include "core/hle/kernel/client_port.h" | 7 | #include "core/hle/kernel/client_port.h" |
| 8 | #include "core/hle/kernel/client_session.h" | 8 | #include "core/hle/kernel/client_session.h" |
| 9 | #include "core/hle/kernel/handle_table.h" | ||
| 9 | #include "core/hle/kernel/hle_ipc.h" | 10 | #include "core/hle/kernel/hle_ipc.h" |
| 11 | #include "core/hle/kernel/process.h" | ||
| 10 | #include "core/hle/kernel/server_session.h" | 12 | #include "core/hle/kernel/server_session.h" |
| 11 | #include "core/hle/kernel/session.h" | 13 | #include "core/hle/kernel/session.h" |
| 12 | #include "core/hle/kernel/thread.h" | 14 | #include "core/hle/kernel/thread.h" |
| @@ -66,8 +68,13 @@ ResultCode ServerSession::HandleSyncRequest(SharedPtr<Thread> thread) { | |||
| 66 | ResultCode translate_result = TranslateHLERequest(this); | 68 | ResultCode translate_result = TranslateHLERequest(this); |
| 67 | if (translate_result.IsError()) | 69 | if (translate_result.IsError()) |
| 68 | return translate_result; | 70 | return translate_result; |
| 69 | result = hle_handler->HandleSyncRequest(SharedPtr<ServerSession>(this)); | 71 | |
| 70 | // TODO(Subv): Translate the response command buffer. | 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); | ||
| 71 | } else { | 78 | } else { |
| 72 | // Add the thread to the list of threads that have issued a sync request with this | 79 | // Add the thread to the list of threads that have issued a sync request with this |
| 73 | // server. | 80 | // server. |
diff --git a/src/core/hle/kernel/server_session.h b/src/core/hle/kernel/server_session.h index 78db5510d..f4360ddf3 100644 --- a/src/core/hle/kernel/server_session.h +++ b/src/core/hle/kernel/server_session.h | |||
| @@ -91,14 +91,6 @@ public: | |||
| 91 | /// TODO(Subv): Find a better name for this. | 91 | /// TODO(Subv): Find a better name for this. |
| 92 | SharedPtr<Thread> currently_handling; | 92 | SharedPtr<Thread> currently_handling; |
| 93 | 93 | ||
| 94 | void ConvertToDomain() { | ||
| 95 | is_domain = true; | ||
| 96 | } | ||
| 97 | |||
| 98 | bool IsDomain() const { | ||
| 99 | return is_domain; | ||
| 100 | } | ||
| 101 | |||
| 102 | private: | 94 | private: |
| 103 | ServerSession(); | 95 | ServerSession(); |
| 104 | ~ServerSession() override; | 96 | ~ServerSession() override; |
| @@ -110,8 +102,6 @@ private: | |||
| 110 | * @return The created server session | 102 | * @return The created server session |
| 111 | */ | 103 | */ |
| 112 | static ResultVal<SharedPtr<ServerSession>> Create(std::string name = "Unknown"); | 104 | static ResultVal<SharedPtr<ServerSession>> Create(std::string name = "Unknown"); |
| 113 | |||
| 114 | bool is_domain{}; | ||
| 115 | }; | 105 | }; |
| 116 | 106 | ||
| 117 | /** | 107 | /** |