diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/kernel/hle_ipc.cpp | 135 | ||||
| -rw-r--r-- | src/core/hle/kernel/hle_ipc.h | 3 |
2 files changed, 57 insertions, 81 deletions
diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp index d6929d2c0..edb3f8d98 100644 --- a/src/core/hle/kernel/hle_ipc.cpp +++ b/src/core/hle/kernel/hle_ipc.cpp | |||
| @@ -55,7 +55,7 @@ void HLERequestContext::ParseCommandBuffer(const KHandleTable& handle_table, u32 | |||
| 55 | IPC::RequestParser rp(src_cmdbuf); | 55 | IPC::RequestParser rp(src_cmdbuf); |
| 56 | command_header = rp.PopRaw<IPC::CommandHeader>(); | 56 | command_header = rp.PopRaw<IPC::CommandHeader>(); |
| 57 | 57 | ||
| 58 | if (command_header->type == IPC::CommandType::Close) { | 58 | if (command_header->IsCloseCommand()) { |
| 59 | // Close does not populate the rest of the IPC header | 59 | // Close does not populate the rest of the IPC header |
| 60 | return; | 60 | return; |
| 61 | } | 61 | } |
| @@ -101,37 +101,41 @@ void HLERequestContext::ParseCommandBuffer(const KHandleTable& handle_table, u32 | |||
| 101 | 101 | ||
| 102 | const auto buffer_c_offset = rp.GetCurrentOffset() + command_header->data_size; | 102 | const auto buffer_c_offset = rp.GetCurrentOffset() + command_header->data_size; |
| 103 | 103 | ||
| 104 | // Padding to align to 16 bytes | 104 | if (!command_header->IsTipc()) { |
| 105 | rp.AlignWithPadding(); | 105 | // Padding to align to 16 bytes |
| 106 | 106 | rp.AlignWithPadding(); | |
| 107 | if (Session()->IsDomain() && ((command_header->type == IPC::CommandType::Request || | 107 | |
| 108 | command_header->type == IPC::CommandType::RequestWithContext) || | 108 | if (Session()->IsDomain() && |
| 109 | !incoming)) { | 109 | ((command_header->type == IPC::CommandType::Request || |
| 110 | // If this is an incoming message, only CommandType "Request" has a domain header | 110 | command_header->type == IPC::CommandType::RequestWithContext) || |
| 111 | // All outgoing domain messages have the domain header, if only incoming has it | 111 | !incoming)) { |
| 112 | if (incoming || domain_message_header) { | 112 | // If this is an incoming message, only CommandType "Request" has a domain header |
| 113 | domain_message_header = rp.PopRaw<IPC::DomainMessageHeader>(); | 113 | // All outgoing domain messages have the domain header, if only incoming has it |
| 114 | } else { | 114 | if (incoming || domain_message_header) { |
| 115 | if (Session()->IsDomain()) { | 115 | domain_message_header = rp.PopRaw<IPC::DomainMessageHeader>(); |
| 116 | LOG_WARNING(IPC, "Domain request has no DomainMessageHeader!"); | 116 | } else { |
| 117 | if (Session()->IsDomain()) { | ||
| 118 | LOG_WARNING(IPC, "Domain request has no DomainMessageHeader!"); | ||
| 119 | } | ||
| 117 | } | 120 | } |
| 118 | } | 121 | } |
| 119 | } | ||
| 120 | 122 | ||
| 121 | data_payload_header = rp.PopRaw<IPC::DataPayloadHeader>(); | 123 | data_payload_header = rp.PopRaw<IPC::DataPayloadHeader>(); |
| 122 | 124 | ||
| 123 | data_payload_offset = rp.GetCurrentOffset(); | 125 | data_payload_offset = rp.GetCurrentOffset(); |
| 124 | 126 | ||
| 125 | if (domain_message_header && domain_message_header->command == | 127 | if (domain_message_header && |
| 126 | IPC::DomainMessageHeader::CommandType::CloseVirtualHandle) { | 128 | domain_message_header->command == |
| 127 | // CloseVirtualHandle command does not have SFC* or any data | 129 | IPC::DomainMessageHeader::CommandType::CloseVirtualHandle) { |
| 128 | return; | 130 | // CloseVirtualHandle command does not have SFC* or any data |
| 129 | } | 131 | return; |
| 132 | } | ||
| 130 | 133 | ||
| 131 | if (incoming) { | 134 | if (incoming) { |
| 132 | ASSERT(data_payload_header->magic == Common::MakeMagic('S', 'F', 'C', 'I')); | 135 | ASSERT(data_payload_header->magic == Common::MakeMagic('S', 'F', 'C', 'I')); |
| 133 | } else { | 136 | } else { |
| 134 | ASSERT(data_payload_header->magic == Common::MakeMagic('S', 'F', 'C', 'O')); | 137 | ASSERT(data_payload_header->magic == Common::MakeMagic('S', 'F', 'C', 'O')); |
| 138 | } | ||
| 135 | } | 139 | } |
| 136 | 140 | ||
| 137 | rp.SetCurrentOffset(buffer_c_offset); | 141 | rp.SetCurrentOffset(buffer_c_offset); |
| @@ -166,84 +170,55 @@ void HLERequestContext::ParseCommandBuffer(const KHandleTable& handle_table, u32 | |||
| 166 | ResultCode HLERequestContext::PopulateFromIncomingCommandBuffer(const KHandleTable& handle_table, | 170 | ResultCode HLERequestContext::PopulateFromIncomingCommandBuffer(const KHandleTable& handle_table, |
| 167 | u32_le* src_cmdbuf) { | 171 | u32_le* src_cmdbuf) { |
| 168 | ParseCommandBuffer(handle_table, src_cmdbuf, true); | 172 | ParseCommandBuffer(handle_table, src_cmdbuf, true); |
| 169 | if (command_header->type == IPC::CommandType::Close) { | 173 | |
| 174 | if (command_header->IsCloseCommand()) { | ||
| 170 | // Close does not populate the rest of the IPC header | 175 | // Close does not populate the rest of the IPC header |
| 171 | return RESULT_SUCCESS; | 176 | return RESULT_SUCCESS; |
| 172 | } | 177 | } |
| 173 | 178 | ||
| 174 | // The data_size already includes the payload header, the padding and the domain header. | 179 | std::copy_n(src_cmdbuf, IPC::COMMAND_BUFFER_LENGTH, cmd_buf.begin()); |
| 175 | std::size_t size = data_payload_offset + command_header->data_size - | 180 | |
| 176 | sizeof(IPC::DataPayloadHeader) / sizeof(u32) - 4; | ||
| 177 | if (domain_message_header) | ||
| 178 | size -= sizeof(IPC::DomainMessageHeader) / sizeof(u32); | ||
| 179 | std::copy_n(src_cmdbuf, size, cmd_buf.begin()); | ||
| 180 | return RESULT_SUCCESS; | 181 | return RESULT_SUCCESS; |
| 181 | } | 182 | } |
| 182 | 183 | ||
| 183 | ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(KThread& requesting_thread) { | 184 | ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(KThread& requesting_thread) { |
| 185 | auto current_offset = handles_offset; | ||
| 184 | auto& owner_process = *requesting_thread.GetOwnerProcess(); | 186 | auto& owner_process = *requesting_thread.GetOwnerProcess(); |
| 185 | auto& handle_table = owner_process.GetHandleTable(); | 187 | auto& handle_table = owner_process.GetHandleTable(); |
| 186 | 188 | ||
| 187 | std::array<u32, IPC::COMMAND_BUFFER_LENGTH> dst_cmdbuf; | 189 | for (auto& object : copy_objects) { |
| 188 | memory.ReadBlock(owner_process, requesting_thread.GetTLSAddress(), dst_cmdbuf.data(), | 190 | Handle handle{}; |
| 189 | dst_cmdbuf.size() * sizeof(u32)); | 191 | if (object) { |
| 190 | 192 | R_TRY(handle_table.Add(&handle, object)); | |
| 191 | // The header was already built in the internal command buffer. Attempt to parse it to verify | ||
| 192 | // the integrity and then copy it over to the target command buffer. | ||
| 193 | ParseCommandBuffer(handle_table, cmd_buf.data(), false); | ||
| 194 | |||
| 195 | // The data_size already includes the payload header, the padding and the domain header. | ||
| 196 | std::size_t size = data_payload_offset + command_header->data_size - | ||
| 197 | sizeof(IPC::DataPayloadHeader) / sizeof(u32) - 4; | ||
| 198 | if (domain_message_header) | ||
| 199 | size -= sizeof(IPC::DomainMessageHeader) / sizeof(u32); | ||
| 200 | |||
| 201 | std::copy_n(cmd_buf.begin(), size, dst_cmdbuf.data()); | ||
| 202 | |||
| 203 | if (command_header->enable_handle_descriptor) { | ||
| 204 | ASSERT_MSG(!move_objects.empty() || !copy_objects.empty(), | ||
| 205 | "Handle descriptor bit set but no handles to translate"); | ||
| 206 | // We write the translated handles at a specific offset in the command buffer, this space | ||
| 207 | // was already reserved when writing the header. | ||
| 208 | std::size_t current_offset = | ||
| 209 | (sizeof(IPC::CommandHeader) + sizeof(IPC::HandleDescriptorHeader)) / sizeof(u32); | ||
| 210 | ASSERT_MSG(!handle_descriptor_header->send_current_pid, "Sending PID is not implemented"); | ||
| 211 | |||
| 212 | ASSERT(copy_objects.size() == handle_descriptor_header->num_handles_to_copy); | ||
| 213 | ASSERT(move_objects.size() == handle_descriptor_header->num_handles_to_move); | ||
| 214 | |||
| 215 | // We don't make a distinction between copy and move handles when translating since HLE | ||
| 216 | // services don't deal with handles directly. However, the guest applications might check | ||
| 217 | // for specific values in each of these descriptors. | ||
| 218 | for (auto& object : copy_objects) { | ||
| 219 | ASSERT(object != nullptr); | ||
| 220 | R_TRY(handle_table.Add(&dst_cmdbuf[current_offset++], object)); | ||
| 221 | } | 193 | } |
| 194 | cmd_buf[current_offset++] = handle; | ||
| 195 | } | ||
| 196 | for (auto& object : move_objects) { | ||
| 197 | Handle handle{}; | ||
| 198 | if (object) { | ||
| 199 | R_TRY(handle_table.Add(&handle, object)); | ||
| 222 | 200 | ||
| 223 | for (auto& object : move_objects) { | 201 | // Close our reference to the object, as it is being moved to the caller. |
| 224 | ASSERT(object != nullptr); | 202 | object->Close(); |
| 225 | R_TRY(handle_table.Add(&dst_cmdbuf[current_offset++], object)); | ||
| 226 | } | 203 | } |
| 204 | cmd_buf[current_offset++] = handle; | ||
| 227 | } | 205 | } |
| 228 | 206 | ||
| 229 | // TODO(Subv): Translate the X/A/B/W buffers. | 207 | // Write the domain objects to the command buffer, these go after the raw untranslated data. |
| 230 | 208 | // TODO(Subv): This completely ignores C buffers. | |
| 231 | if (Session()->IsDomain() && domain_message_header) { | ||
| 232 | ASSERT(domain_message_header->num_objects == domain_objects.size()); | ||
| 233 | // Write the domain objects to the command buffer, these go after the raw untranslated data. | ||
| 234 | // TODO(Subv): This completely ignores C buffers. | ||
| 235 | std::size_t domain_offset = size - domain_message_header->num_objects; | ||
| 236 | 209 | ||
| 210 | if (Session()->IsDomain()) { | ||
| 211 | current_offset = domain_offset - static_cast<u32>(domain_objects.size()); | ||
| 237 | for (const auto& object : domain_objects) { | 212 | for (const auto& object : domain_objects) { |
| 238 | server_session->AppendDomainRequestHandler(object); | 213 | server_session->AppendDomainRequestHandler(object); |
| 239 | dst_cmdbuf[domain_offset++] = | 214 | cmd_buf[current_offset++] = |
| 240 | static_cast<u32_le>(server_session->NumDomainRequestHandlers()); | 215 | static_cast<u32_le>(server_session->NumDomainRequestHandlers()); |
| 241 | } | 216 | } |
| 242 | } | 217 | } |
| 243 | 218 | ||
| 244 | // Copy the translated command buffer back into the thread's command buffer area. | 219 | // Copy the translated command buffer back into the thread's command buffer area. |
| 245 | memory.WriteBlock(owner_process, requesting_thread.GetTLSAddress(), dst_cmdbuf.data(), | 220 | memory.WriteBlock(owner_process, requesting_thread.GetTLSAddress(), cmd_buf.data(), |
| 246 | dst_cmdbuf.size() * sizeof(u32)); | 221 | cmd_buf.size() * sizeof(u32)); |
| 247 | 222 | ||
| 248 | return RESULT_SUCCESS; | 223 | return RESULT_SUCCESS; |
| 249 | } | 224 | } |
diff --git a/src/core/hle/kernel/hle_ipc.h b/src/core/hle/kernel/hle_ipc.h index 07360629e..3e66e5542 100644 --- a/src/core/hle/kernel/hle_ipc.h +++ b/src/core/hle/kernel/hle_ipc.h | |||
| @@ -66,7 +66,8 @@ public: | |||
| 66 | * this request (ServerSession, Originator thread, Translated command buffer, etc). | 66 | * this request (ServerSession, Originator thread, Translated command buffer, etc). |
| 67 | * @returns ResultCode the result code of the translate operation. | 67 | * @returns ResultCode the result code of the translate operation. |
| 68 | */ | 68 | */ |
| 69 | virtual ResultCode HandleSyncRequest(Kernel::HLERequestContext& context) = 0; | 69 | virtual ResultCode HandleSyncRequest(Kernel::KServerSession& session, |
| 70 | Kernel::HLERequestContext& context) = 0; | ||
| 70 | 71 | ||
| 71 | /** | 72 | /** |
| 72 | * Signals that a client has just connected to this HLE handler and keeps the | 73 | * Signals that a client has just connected to this HLE handler and keeps the |