diff options
| author | 2023-12-26 11:46:11 -0500 | |
|---|---|---|
| committer | 2023-12-26 11:46:11 -0500 | |
| commit | de1e5584b32edcc5b43dd7b5757ee4b361f9f70c (patch) | |
| tree | a11721530b76fa281f0793ed8469fd9a847f5489 | |
| parent | Merge pull request #12471 from FearlessTobi/port-7146 (diff) | |
| parent | am/jit: reference memory instance from context (diff) | |
| download | yuzu-de1e5584b32edcc5b43dd7b5757ee4b361f9f70c.tar.gz yuzu-de1e5584b32edcc5b43dd7b5757ee4b361f9f70c.tar.xz yuzu-de1e5584b32edcc5b43dd7b5757ee4b361f9f70c.zip | |
Merge pull request #12465 from liamwhite/proper-handle-table
service: fetch objects from the client handle table
| -rw-r--r-- | src/core/hle/kernel/k_handle_table.h | 7 | ||||
| -rw-r--r-- | src/core/hle/kernel/k_process.h | 2 | ||||
| -rw-r--r-- | src/core/hle/kernel/k_server_session.cpp | 3 | ||||
| -rw-r--r-- | src/core/hle/service/am/am.cpp | 12 | ||||
| -rw-r--r-- | src/core/hle/service/audio/audren_u.cpp | 6 | ||||
| -rw-r--r-- | src/core/hle/service/audio/hwopus.cpp | 16 | ||||
| -rw-r--r-- | src/core/hle/service/hid/hid_server.cpp | 9 | ||||
| -rw-r--r-- | src/core/hle/service/hid/hidbus.cpp | 3 | ||||
| -rw-r--r-- | src/core/hle/service/hid/irs.cpp | 6 | ||||
| -rw-r--r-- | src/core/hle/service/hle_ipc.cpp | 20 | ||||
| -rw-r--r-- | src/core/hle/service/hle_ipc.h | 20 | ||||
| -rw-r--r-- | src/core/hle/service/jit/jit.cpp | 14 | ||||
| -rw-r--r-- | src/core/hle/service/ro/ro.cpp | 12 | ||||
| -rw-r--r-- | src/core/hle/service/service.cpp | 2 |
14 files changed, 55 insertions, 77 deletions
diff --git a/src/core/hle/kernel/k_handle_table.h b/src/core/hle/kernel/k_handle_table.h index 4e6dcd66b..1bf68e6b0 100644 --- a/src/core/hle/kernel/k_handle_table.h +++ b/src/core/hle/kernel/k_handle_table.h | |||
| @@ -30,7 +30,7 @@ public: | |||
| 30 | public: | 30 | public: |
| 31 | explicit KHandleTable(KernelCore& kernel) : m_kernel(kernel) {} | 31 | explicit KHandleTable(KernelCore& kernel) : m_kernel(kernel) {} |
| 32 | 32 | ||
| 33 | Result Initialize(KProcess* owner, s32 size) { | 33 | Result Initialize(s32 size) { |
| 34 | // Check that the table size is valid. | 34 | // Check that the table size is valid. |
| 35 | R_UNLESS(size <= static_cast<s32>(MaxTableSize), ResultOutOfMemory); | 35 | R_UNLESS(size <= static_cast<s32>(MaxTableSize), ResultOutOfMemory); |
| 36 | 36 | ||
| @@ -44,7 +44,6 @@ public: | |||
| 44 | m_next_linear_id = MinLinearId; | 44 | m_next_linear_id = MinLinearId; |
| 45 | m_count = 0; | 45 | m_count = 0; |
| 46 | m_free_head_index = -1; | 46 | m_free_head_index = -1; |
| 47 | m_owner = owner; | ||
| 48 | 47 | ||
| 49 | // Free all entries. | 48 | // Free all entries. |
| 50 | for (s32 i = 0; i < static_cast<s32>(m_table_size); ++i) { | 49 | for (s32 i = 0; i < static_cast<s32>(m_table_size); ++i) { |
| @@ -91,8 +90,7 @@ public: | |||
| 91 | // Handle pseudo-handles. | 90 | // Handle pseudo-handles. |
| 92 | if constexpr (std::derived_from<KProcess, T>) { | 91 | if constexpr (std::derived_from<KProcess, T>) { |
| 93 | if (handle == Svc::PseudoHandle::CurrentProcess) { | 92 | if (handle == Svc::PseudoHandle::CurrentProcess) { |
| 94 | // TODO: this should be the current process | 93 | auto* const cur_process = GetCurrentProcessPointer(m_kernel); |
| 95 | auto* const cur_process = m_owner; | ||
| 96 | ASSERT(cur_process != nullptr); | 94 | ASSERT(cur_process != nullptr); |
| 97 | return cur_process; | 95 | return cur_process; |
| 98 | } | 96 | } |
| @@ -302,7 +300,6 @@ private: | |||
| 302 | 300 | ||
| 303 | private: | 301 | private: |
| 304 | KernelCore& m_kernel; | 302 | KernelCore& m_kernel; |
| 305 | KProcess* m_owner{}; | ||
| 306 | std::array<EntryInfo, MaxTableSize> m_entry_infos{}; | 303 | std::array<EntryInfo, MaxTableSize> m_entry_infos{}; |
| 307 | std::array<KAutoObject*, MaxTableSize> m_objects{}; | 304 | std::array<KAutoObject*, MaxTableSize> m_objects{}; |
| 308 | mutable KSpinLock m_lock; | 305 | mutable KSpinLock m_lock; |
diff --git a/src/core/hle/kernel/k_process.h b/src/core/hle/kernel/k_process.h index b5c6867a1..53c0e3316 100644 --- a/src/core/hle/kernel/k_process.h +++ b/src/core/hle/kernel/k_process.h | |||
| @@ -552,7 +552,7 @@ private: | |||
| 552 | 552 | ||
| 553 | Result InitializeHandleTable(s32 size) { | 553 | Result InitializeHandleTable(s32 size) { |
| 554 | // Try to initialize the handle table. | 554 | // Try to initialize the handle table. |
| 555 | R_TRY(m_handle_table.Initialize(this, size)); | 555 | R_TRY(m_handle_table.Initialize(size)); |
| 556 | 556 | ||
| 557 | // We succeeded, so note that we did. | 557 | // We succeeded, so note that we did. |
| 558 | m_is_handle_table_initialized = true; | 558 | m_is_handle_table_initialized = true; |
diff --git a/src/core/hle/kernel/k_server_session.cpp b/src/core/hle/kernel/k_server_session.cpp index f6ca3dc48..adaabdd6d 100644 --- a/src/core/hle/kernel/k_server_session.cpp +++ b/src/core/hle/kernel/k_server_session.cpp | |||
| @@ -1147,8 +1147,7 @@ Result KServerSession::ReceiveRequest(uintptr_t server_message, uintptr_t server | |||
| 1147 | *out_context = | 1147 | *out_context = |
| 1148 | std::make_shared<Service::HLERequestContext>(m_kernel, memory, this, client_thread); | 1148 | std::make_shared<Service::HLERequestContext>(m_kernel, memory, this, client_thread); |
| 1149 | (*out_context)->SetSessionRequestManager(manager); | 1149 | (*out_context)->SetSessionRequestManager(manager); |
| 1150 | (*out_context) | 1150 | (*out_context)->PopulateFromIncomingCommandBuffer(cmd_buf); |
| 1151 | ->PopulateFromIncomingCommandBuffer(*client_thread->GetOwnerProcess(), cmd_buf); | ||
| 1152 | // We succeeded. | 1151 | // We succeeded. |
| 1153 | R_SUCCEED(); | 1152 | R_SUCCEED(); |
| 1154 | } else { | 1153 | } else { |
diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index a266d7c21..97eb56ff0 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp | |||
| @@ -1513,8 +1513,7 @@ void ILibraryAppletCreator::CreateTransferMemoryStorage(HLERequestContext& ctx) | |||
| 1513 | return; | 1513 | return; |
| 1514 | } | 1514 | } |
| 1515 | 1515 | ||
| 1516 | auto transfer_mem = | 1516 | auto transfer_mem = ctx.GetObjectFromHandle<Kernel::KTransferMemory>(handle); |
| 1517 | system.ApplicationProcess()->GetHandleTable().GetObject<Kernel::KTransferMemory>(handle); | ||
| 1518 | 1517 | ||
| 1519 | if (transfer_mem.IsNull()) { | 1518 | if (transfer_mem.IsNull()) { |
| 1520 | LOG_ERROR(Service_AM, "transfer_mem is a nullptr for handle={:08X}", handle); | 1519 | LOG_ERROR(Service_AM, "transfer_mem is a nullptr for handle={:08X}", handle); |
| @@ -1524,8 +1523,7 @@ void ILibraryAppletCreator::CreateTransferMemoryStorage(HLERequestContext& ctx) | |||
| 1524 | } | 1523 | } |
| 1525 | 1524 | ||
| 1526 | std::vector<u8> memory(transfer_mem->GetSize()); | 1525 | std::vector<u8> memory(transfer_mem->GetSize()); |
| 1527 | system.ApplicationMemory().ReadBlock(transfer_mem->GetSourceAddress(), memory.data(), | 1526 | ctx.GetMemory().ReadBlock(transfer_mem->GetSourceAddress(), memory.data(), memory.size()); |
| 1528 | memory.size()); | ||
| 1529 | 1527 | ||
| 1530 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; | 1528 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; |
| 1531 | rb.Push(ResultSuccess); | 1529 | rb.Push(ResultSuccess); |
| @@ -1547,8 +1545,7 @@ void ILibraryAppletCreator::CreateHandleStorage(HLERequestContext& ctx) { | |||
| 1547 | return; | 1545 | return; |
| 1548 | } | 1546 | } |
| 1549 | 1547 | ||
| 1550 | auto transfer_mem = | 1548 | auto transfer_mem = ctx.GetObjectFromHandle<Kernel::KTransferMemory>(handle); |
| 1551 | system.ApplicationProcess()->GetHandleTable().GetObject<Kernel::KTransferMemory>(handle); | ||
| 1552 | 1549 | ||
| 1553 | if (transfer_mem.IsNull()) { | 1550 | if (transfer_mem.IsNull()) { |
| 1554 | LOG_ERROR(Service_AM, "transfer_mem is a nullptr for handle={:08X}", handle); | 1551 | LOG_ERROR(Service_AM, "transfer_mem is a nullptr for handle={:08X}", handle); |
| @@ -1558,8 +1555,7 @@ void ILibraryAppletCreator::CreateHandleStorage(HLERequestContext& ctx) { | |||
| 1558 | } | 1555 | } |
| 1559 | 1556 | ||
| 1560 | std::vector<u8> memory(transfer_mem->GetSize()); | 1557 | std::vector<u8> memory(transfer_mem->GetSize()); |
| 1561 | system.ApplicationMemory().ReadBlock(transfer_mem->GetSourceAddress(), memory.data(), | 1558 | ctx.GetMemory().ReadBlock(transfer_mem->GetSourceAddress(), memory.data(), memory.size()); |
| 1562 | memory.size()); | ||
| 1563 | 1559 | ||
| 1564 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; | 1560 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; |
| 1565 | rb.Push(ResultSuccess); | 1561 | rb.Push(ResultSuccess); |
diff --git a/src/core/hle/service/audio/audren_u.cpp b/src/core/hle/service/audio/audren_u.cpp index 23e56c77a..bd4ca753b 100644 --- a/src/core/hle/service/audio/audren_u.cpp +++ b/src/core/hle/service/audio/audren_u.cpp | |||
| @@ -454,10 +454,8 @@ void AudRenU::OpenAudioRenderer(HLERequestContext& ctx) { | |||
| 454 | return; | 454 | return; |
| 455 | } | 455 | } |
| 456 | 456 | ||
| 457 | const auto& handle_table{system.ApplicationProcess()->GetHandleTable()}; | 457 | auto process{ctx.GetObjectFromHandle<Kernel::KProcess>(process_handle)}; |
| 458 | auto process{handle_table.GetObject<Kernel::KProcess>(process_handle)}; | 458 | auto transfer_memory{ctx.GetObjectFromHandle<Kernel::KTransferMemory>(transfer_memory_handle)}; |
| 459 | auto transfer_memory{ | ||
| 460 | process->GetHandleTable().GetObject<Kernel::KTransferMemory>(transfer_memory_handle)}; | ||
| 461 | 459 | ||
| 462 | const auto session_id{impl->GetSessionId()}; | 460 | const auto session_id{impl->GetSessionId()}; |
| 463 | if (session_id == -1) { | 461 | if (session_id == -1) { |
diff --git a/src/core/hle/service/audio/hwopus.cpp b/src/core/hle/service/audio/hwopus.cpp index 6a7bf9416..91f33aabd 100644 --- a/src/core/hle/service/audio/hwopus.cpp +++ b/src/core/hle/service/audio/hwopus.cpp | |||
| @@ -278,9 +278,7 @@ void HwOpus::OpenHardwareOpusDecoder(HLERequestContext& ctx) { | |||
| 278 | auto params = rp.PopRaw<OpusParameters>(); | 278 | auto params = rp.PopRaw<OpusParameters>(); |
| 279 | auto transfer_memory_size{rp.Pop<u32>()}; | 279 | auto transfer_memory_size{rp.Pop<u32>()}; |
| 280 | auto transfer_memory_handle{ctx.GetCopyHandle(0)}; | 280 | auto transfer_memory_handle{ctx.GetCopyHandle(0)}; |
| 281 | auto transfer_memory{ | 281 | auto transfer_memory{ctx.GetObjectFromHandle<Kernel::KTransferMemory>(transfer_memory_handle)}; |
| 282 | system.ApplicationProcess()->GetHandleTable().GetObject<Kernel::KTransferMemory>( | ||
| 283 | transfer_memory_handle)}; | ||
| 284 | 282 | ||
| 285 | LOG_DEBUG(Service_Audio, "sample_rate {} channel_count {} transfer_memory_size 0x{:X}", | 283 | LOG_DEBUG(Service_Audio, "sample_rate {} channel_count {} transfer_memory_size 0x{:X}", |
| 286 | params.sample_rate, params.channel_count, transfer_memory_size); | 284 | params.sample_rate, params.channel_count, transfer_memory_size); |
| @@ -323,9 +321,7 @@ void HwOpus::OpenHardwareOpusDecoderForMultiStream(HLERequestContext& ctx) { | |||
| 323 | 321 | ||
| 324 | auto transfer_memory_size{rp.Pop<u32>()}; | 322 | auto transfer_memory_size{rp.Pop<u32>()}; |
| 325 | auto transfer_memory_handle{ctx.GetCopyHandle(0)}; | 323 | auto transfer_memory_handle{ctx.GetCopyHandle(0)}; |
| 326 | auto transfer_memory{ | 324 | auto transfer_memory{ctx.GetObjectFromHandle<Kernel::KTransferMemory>(transfer_memory_handle)}; |
| 327 | system.ApplicationProcess()->GetHandleTable().GetObject<Kernel::KTransferMemory>( | ||
| 328 | transfer_memory_handle)}; | ||
| 329 | 325 | ||
| 330 | LOG_DEBUG(Service_Audio, | 326 | LOG_DEBUG(Service_Audio, |
| 331 | "sample_rate {} channel_count {} total_stream_count {} stereo_stream_count {} " | 327 | "sample_rate {} channel_count {} total_stream_count {} stereo_stream_count {} " |
| @@ -374,9 +370,7 @@ void HwOpus::OpenHardwareOpusDecoderEx(HLERequestContext& ctx) { | |||
| 374 | auto params = rp.PopRaw<OpusParametersEx>(); | 370 | auto params = rp.PopRaw<OpusParametersEx>(); |
| 375 | auto transfer_memory_size{rp.Pop<u32>()}; | 371 | auto transfer_memory_size{rp.Pop<u32>()}; |
| 376 | auto transfer_memory_handle{ctx.GetCopyHandle(0)}; | 372 | auto transfer_memory_handle{ctx.GetCopyHandle(0)}; |
| 377 | auto transfer_memory{ | 373 | auto transfer_memory{ctx.GetObjectFromHandle<Kernel::KTransferMemory>(transfer_memory_handle)}; |
| 378 | system.ApplicationProcess()->GetHandleTable().GetObject<Kernel::KTransferMemory>( | ||
| 379 | transfer_memory_handle)}; | ||
| 380 | 374 | ||
| 381 | LOG_DEBUG(Service_Audio, "sample_rate {} channel_count {} transfer_memory_size 0x{:X}", | 375 | LOG_DEBUG(Service_Audio, "sample_rate {} channel_count {} transfer_memory_size 0x{:X}", |
| 382 | params.sample_rate, params.channel_count, transfer_memory_size); | 376 | params.sample_rate, params.channel_count, transfer_memory_size); |
| @@ -414,9 +408,7 @@ void HwOpus::OpenHardwareOpusDecoderForMultiStreamEx(HLERequestContext& ctx) { | |||
| 414 | 408 | ||
| 415 | auto transfer_memory_size{rp.Pop<u32>()}; | 409 | auto transfer_memory_size{rp.Pop<u32>()}; |
| 416 | auto transfer_memory_handle{ctx.GetCopyHandle(0)}; | 410 | auto transfer_memory_handle{ctx.GetCopyHandle(0)}; |
| 417 | auto transfer_memory{ | 411 | auto transfer_memory{ctx.GetObjectFromHandle<Kernel::KTransferMemory>(transfer_memory_handle)}; |
| 418 | system.ApplicationProcess()->GetHandleTable().GetObject<Kernel::KTransferMemory>( | ||
| 419 | transfer_memory_handle)}; | ||
| 420 | 412 | ||
| 421 | LOG_DEBUG(Service_Audio, | 413 | LOG_DEBUG(Service_Audio, |
| 422 | "sample_rate {} channel_count {} total_stream_count {} stereo_stream_count {} " | 414 | "sample_rate {} channel_count {} total_stream_count {} stereo_stream_count {} " |
diff --git a/src/core/hle/service/hid/hid_server.cpp b/src/core/hle/service/hid/hid_server.cpp index 06a01c02c..3174672af 100644 --- a/src/core/hle/service/hid/hid_server.cpp +++ b/src/core/hle/service/hid/hid_server.cpp | |||
| @@ -1850,8 +1850,7 @@ void IHidServer::InitializeSevenSixAxisSensor(HLERequestContext& ctx) { | |||
| 1850 | ASSERT_MSG(t_mem_1_size == 0x1000, "t_mem_1_size is not 0x1000 bytes"); | 1850 | ASSERT_MSG(t_mem_1_size == 0x1000, "t_mem_1_size is not 0x1000 bytes"); |
| 1851 | ASSERT_MSG(t_mem_2_size == 0x7F000, "t_mem_2_size is not 0x7F000 bytes"); | 1851 | ASSERT_MSG(t_mem_2_size == 0x7F000, "t_mem_2_size is not 0x7F000 bytes"); |
| 1852 | 1852 | ||
| 1853 | auto t_mem_1 = system.ApplicationProcess()->GetHandleTable().GetObject<Kernel::KTransferMemory>( | 1853 | auto t_mem_1 = ctx.GetObjectFromHandle<Kernel::KTransferMemory>(t_mem_1_handle); |
| 1854 | t_mem_1_handle); | ||
| 1855 | 1854 | ||
| 1856 | if (t_mem_1.IsNull()) { | 1855 | if (t_mem_1.IsNull()) { |
| 1857 | LOG_ERROR(Service_HID, "t_mem_1 is a nullptr for handle=0x{:08X}", t_mem_1_handle); | 1856 | LOG_ERROR(Service_HID, "t_mem_1 is a nullptr for handle=0x{:08X}", t_mem_1_handle); |
| @@ -1860,8 +1859,7 @@ void IHidServer::InitializeSevenSixAxisSensor(HLERequestContext& ctx) { | |||
| 1860 | return; | 1859 | return; |
| 1861 | } | 1860 | } |
| 1862 | 1861 | ||
| 1863 | auto t_mem_2 = system.ApplicationProcess()->GetHandleTable().GetObject<Kernel::KTransferMemory>( | 1862 | auto t_mem_2 = ctx.GetObjectFromHandle<Kernel::KTransferMemory>(t_mem_2_handle); |
| 1864 | t_mem_2_handle); | ||
| 1865 | 1863 | ||
| 1866 | if (t_mem_2.IsNull()) { | 1864 | if (t_mem_2.IsNull()) { |
| 1867 | LOG_ERROR(Service_HID, "t_mem_2 is a nullptr for handle=0x{:08X}", t_mem_2_handle); | 1865 | LOG_ERROR(Service_HID, "t_mem_2 is a nullptr for handle=0x{:08X}", t_mem_2_handle); |
| @@ -2142,8 +2140,7 @@ void IHidServer::WritePalmaWaveEntry(HLERequestContext& ctx) { | |||
| 2142 | 2140 | ||
| 2143 | ASSERT_MSG(t_mem_size == 0x3000, "t_mem_size is not 0x3000 bytes"); | 2141 | ASSERT_MSG(t_mem_size == 0x3000, "t_mem_size is not 0x3000 bytes"); |
| 2144 | 2142 | ||
| 2145 | auto t_mem = system.ApplicationProcess()->GetHandleTable().GetObject<Kernel::KTransferMemory>( | 2143 | auto t_mem = ctx.GetObjectFromHandle<Kernel::KTransferMemory>(t_mem_handle); |
| 2146 | t_mem_handle); | ||
| 2147 | 2144 | ||
| 2148 | if (t_mem.IsNull()) { | 2145 | if (t_mem.IsNull()) { |
| 2149 | LOG_ERROR(Service_HID, "t_mem is a nullptr for handle=0x{:08X}", t_mem_handle); | 2146 | LOG_ERROR(Service_HID, "t_mem is a nullptr for handle=0x{:08X}", t_mem_handle); |
diff --git a/src/core/hle/service/hid/hidbus.cpp b/src/core/hle/service/hid/hidbus.cpp index 80aac221b..d12f9beb0 100644 --- a/src/core/hle/service/hid/hidbus.cpp +++ b/src/core/hle/service/hid/hidbus.cpp | |||
| @@ -448,8 +448,7 @@ void HidBus::EnableJoyPollingReceiveMode(HLERequestContext& ctx) { | |||
| 448 | 448 | ||
| 449 | ASSERT_MSG(t_mem_size == 0x1000, "t_mem_size is not 0x1000 bytes"); | 449 | ASSERT_MSG(t_mem_size == 0x1000, "t_mem_size is not 0x1000 bytes"); |
| 450 | 450 | ||
| 451 | auto t_mem = system.ApplicationProcess()->GetHandleTable().GetObject<Kernel::KTransferMemory>( | 451 | auto t_mem = ctx.GetObjectFromHandle<Kernel::KTransferMemory>(t_mem_handle); |
| 452 | t_mem_handle); | ||
| 453 | 452 | ||
| 454 | if (t_mem.IsNull()) { | 453 | if (t_mem.IsNull()) { |
| 455 | LOG_ERROR(Service_HID, "t_mem is a nullptr for handle=0x{:08X}", t_mem_handle); | 454 | LOG_ERROR(Service_HID, "t_mem is a nullptr for handle=0x{:08X}", t_mem_handle); |
diff --git a/src/core/hle/service/hid/irs.cpp b/src/core/hle/service/hid/irs.cpp index 39b9a4474..008debfd1 100644 --- a/src/core/hle/service/hid/irs.cpp +++ b/src/core/hle/service/hid/irs.cpp | |||
| @@ -197,8 +197,7 @@ void IRS::RunImageTransferProcessor(HLERequestContext& ctx) { | |||
| 197 | const auto parameters{rp.PopRaw<Parameters>()}; | 197 | const auto parameters{rp.PopRaw<Parameters>()}; |
| 198 | const auto t_mem_handle{ctx.GetCopyHandle(0)}; | 198 | const auto t_mem_handle{ctx.GetCopyHandle(0)}; |
| 199 | 199 | ||
| 200 | auto t_mem = system.ApplicationProcess()->GetHandleTable().GetObject<Kernel::KTransferMemory>( | 200 | auto t_mem = ctx.GetObjectFromHandle<Kernel::KTransferMemory>(t_mem_handle); |
| 201 | t_mem_handle); | ||
| 202 | 201 | ||
| 203 | if (t_mem.IsNull()) { | 202 | if (t_mem.IsNull()) { |
| 204 | LOG_ERROR(Service_IRS, "t_mem is a nullptr for handle=0x{:08X}", t_mem_handle); | 203 | LOG_ERROR(Service_IRS, "t_mem is a nullptr for handle=0x{:08X}", t_mem_handle); |
| @@ -444,8 +443,7 @@ void IRS::RunImageTransferExProcessor(HLERequestContext& ctx) { | |||
| 444 | const auto parameters{rp.PopRaw<Parameters>()}; | 443 | const auto parameters{rp.PopRaw<Parameters>()}; |
| 445 | const auto t_mem_handle{ctx.GetCopyHandle(0)}; | 444 | const auto t_mem_handle{ctx.GetCopyHandle(0)}; |
| 446 | 445 | ||
| 447 | auto t_mem = system.ApplicationProcess()->GetHandleTable().GetObject<Kernel::KTransferMemory>( | 446 | auto t_mem = ctx.GetObjectFromHandle<Kernel::KTransferMemory>(t_mem_handle); |
| 448 | t_mem_handle); | ||
| 449 | 447 | ||
| 450 | LOG_INFO(Service_IRS, | 448 | LOG_INFO(Service_IRS, |
| 451 | "called, npad_type={}, npad_id={}, transfer_memory_size={}, " | 449 | "called, npad_type={}, npad_id={}, transfer_memory_size={}, " |
diff --git a/src/core/hle/service/hle_ipc.cpp b/src/core/hle/service/hle_ipc.cpp index 38955932c..39df77e43 100644 --- a/src/core/hle/service/hle_ipc.cpp +++ b/src/core/hle/service/hle_ipc.cpp | |||
| @@ -146,10 +146,7 @@ HLERequestContext::HLERequestContext(Kernel::KernelCore& kernel_, Core::Memory:: | |||
| 146 | 146 | ||
| 147 | HLERequestContext::~HLERequestContext() = default; | 147 | HLERequestContext::~HLERequestContext() = default; |
| 148 | 148 | ||
| 149 | void HLERequestContext::ParseCommandBuffer(Kernel::KProcess& process, u32_le* src_cmdbuf, | 149 | void HLERequestContext::ParseCommandBuffer(u32_le* src_cmdbuf, bool incoming) { |
| 150 | bool incoming) { | ||
| 151 | client_handle_table = &process.GetHandleTable(); | ||
| 152 | |||
| 153 | IPC::RequestParser rp(src_cmdbuf); | 150 | IPC::RequestParser rp(src_cmdbuf); |
| 154 | command_header = rp.PopRaw<IPC::CommandHeader>(); | 151 | command_header = rp.PopRaw<IPC::CommandHeader>(); |
| 155 | 152 | ||
| @@ -162,7 +159,7 @@ void HLERequestContext::ParseCommandBuffer(Kernel::KProcess& process, u32_le* sr | |||
| 162 | if (command_header->enable_handle_descriptor) { | 159 | if (command_header->enable_handle_descriptor) { |
| 163 | handle_descriptor_header = rp.PopRaw<IPC::HandleDescriptorHeader>(); | 160 | handle_descriptor_header = rp.PopRaw<IPC::HandleDescriptorHeader>(); |
| 164 | if (handle_descriptor_header->send_current_pid) { | 161 | if (handle_descriptor_header->send_current_pid) { |
| 165 | pid = process.GetProcessId(); | 162 | pid = thread->GetOwnerProcess()->GetProcessId(); |
| 166 | rp.Skip(2, false); | 163 | rp.Skip(2, false); |
| 167 | } | 164 | } |
| 168 | if (incoming) { | 165 | if (incoming) { |
| @@ -270,9 +267,10 @@ void HLERequestContext::ParseCommandBuffer(Kernel::KProcess& process, u32_le* sr | |||
| 270 | rp.Skip(1, false); // The command is actually an u64, but we don't use the high part. | 267 | rp.Skip(1, false); // The command is actually an u64, but we don't use the high part. |
| 271 | } | 268 | } |
| 272 | 269 | ||
| 273 | Result HLERequestContext::PopulateFromIncomingCommandBuffer(Kernel::KProcess& process, | 270 | Result HLERequestContext::PopulateFromIncomingCommandBuffer(u32_le* src_cmdbuf) { |
| 274 | u32_le* src_cmdbuf) { | 271 | client_handle_table = &thread->GetOwnerProcess()->GetHandleTable(); |
| 275 | ParseCommandBuffer(process, src_cmdbuf, true); | 272 | |
| 273 | ParseCommandBuffer(src_cmdbuf, true); | ||
| 276 | 274 | ||
| 277 | if (command_header->IsCloseCommand()) { | 275 | if (command_header->IsCloseCommand()) { |
| 278 | // Close does not populate the rest of the IPC header | 276 | // Close does not populate the rest of the IPC header |
| @@ -284,9 +282,9 @@ Result HLERequestContext::PopulateFromIncomingCommandBuffer(Kernel::KProcess& pr | |||
| 284 | return ResultSuccess; | 282 | return ResultSuccess; |
| 285 | } | 283 | } |
| 286 | 284 | ||
| 287 | Result HLERequestContext::WriteToOutgoingCommandBuffer(Kernel::KThread& requesting_thread) { | 285 | Result HLERequestContext::WriteToOutgoingCommandBuffer() { |
| 288 | auto current_offset = handles_offset; | 286 | auto current_offset = handles_offset; |
| 289 | auto& owner_process = *requesting_thread.GetOwnerProcess(); | 287 | auto& owner_process = *thread->GetOwnerProcess(); |
| 290 | auto& handle_table = owner_process.GetHandleTable(); | 288 | auto& handle_table = owner_process.GetHandleTable(); |
| 291 | 289 | ||
| 292 | for (auto& object : outgoing_copy_objects) { | 290 | for (auto& object : outgoing_copy_objects) { |
| @@ -319,7 +317,7 @@ Result HLERequestContext::WriteToOutgoingCommandBuffer(Kernel::KThread& requesti | |||
| 319 | } | 317 | } |
| 320 | 318 | ||
| 321 | // Copy the translated command buffer back into the thread's command buffer area. | 319 | // Copy the translated command buffer back into the thread's command buffer area. |
| 322 | memory.WriteBlock(requesting_thread.GetTlsAddress(), cmd_buf.data(), write_size * sizeof(u32)); | 320 | memory.WriteBlock(thread->GetTlsAddress(), cmd_buf.data(), write_size * sizeof(u32)); |
| 323 | 321 | ||
| 324 | return ResultSuccess; | 322 | return ResultSuccess; |
| 325 | } | 323 | } |
diff --git a/src/core/hle/service/hle_ipc.h b/src/core/hle/service/hle_ipc.h index 18d464c63..40d86943e 100644 --- a/src/core/hle/service/hle_ipc.h +++ b/src/core/hle/service/hle_ipc.h | |||
| @@ -17,6 +17,7 @@ | |||
| 17 | #include "common/concepts.h" | 17 | #include "common/concepts.h" |
| 18 | #include "common/swap.h" | 18 | #include "common/swap.h" |
| 19 | #include "core/hle/ipc.h" | 19 | #include "core/hle/ipc.h" |
| 20 | #include "core/hle/kernel/k_handle_table.h" | ||
| 20 | #include "core/hle/kernel/svc_common.h" | 21 | #include "core/hle/kernel/svc_common.h" |
| 21 | 22 | ||
| 22 | union Result; | 23 | union Result; |
| @@ -196,10 +197,10 @@ public: | |||
| 196 | } | 197 | } |
| 197 | 198 | ||
| 198 | /// Populates this context with data from the requesting process/thread. | 199 | /// Populates this context with data from the requesting process/thread. |
| 199 | Result PopulateFromIncomingCommandBuffer(Kernel::KProcess& process, u32_le* src_cmdbuf); | 200 | Result PopulateFromIncomingCommandBuffer(u32_le* src_cmdbuf); |
| 200 | 201 | ||
| 201 | /// Writes data from this context back to the requesting process/thread. | 202 | /// Writes data from this context back to the requesting process/thread. |
| 202 | Result WriteToOutgoingCommandBuffer(Kernel::KThread& requesting_thread); | 203 | Result WriteToOutgoingCommandBuffer(); |
| 203 | 204 | ||
| 204 | [[nodiscard]] u32_le GetHipcCommand() const { | 205 | [[nodiscard]] u32_le GetHipcCommand() const { |
| 205 | return command; | 206 | return command; |
| @@ -359,8 +360,17 @@ public: | |||
| 359 | return *thread; | 360 | return *thread; |
| 360 | } | 361 | } |
| 361 | 362 | ||
| 362 | Kernel::KHandleTable& GetClientHandleTable() { | 363 | [[nodiscard]] Core::Memory::Memory& GetMemory() const { |
| 363 | return *client_handle_table; | 364 | return memory; |
| 365 | } | ||
| 366 | |||
| 367 | template <typename T> | ||
| 368 | Kernel::KScopedAutoObject<T> GetObjectFromHandle(u32 handle) { | ||
| 369 | auto obj = client_handle_table->GetObjectForIpc(handle, thread); | ||
| 370 | if (obj.IsNotNull()) { | ||
| 371 | return obj->DynamicCast<T*>(); | ||
| 372 | } | ||
| 373 | return nullptr; | ||
| 364 | } | 374 | } |
| 365 | 375 | ||
| 366 | [[nodiscard]] std::shared_ptr<SessionRequestManager> GetManager() const { | 376 | [[nodiscard]] std::shared_ptr<SessionRequestManager> GetManager() const { |
| @@ -378,7 +388,7 @@ public: | |||
| 378 | private: | 388 | private: |
| 379 | friend class IPC::ResponseBuilder; | 389 | friend class IPC::ResponseBuilder; |
| 380 | 390 | ||
| 381 | void ParseCommandBuffer(Kernel::KProcess& process, u32_le* src_cmdbuf, bool incoming); | 391 | void ParseCommandBuffer(u32_le* src_cmdbuf, bool incoming); |
| 382 | 392 | ||
| 383 | std::array<u32, IPC::COMMAND_BUFFER_LENGTH> cmd_buf; | 393 | std::array<u32, IPC::COMMAND_BUFFER_LENGTH> cmd_buf; |
| 384 | Kernel::KServerSession* server_session{}; | 394 | Kernel::KServerSession* server_session{}; |
diff --git a/src/core/hle/service/jit/jit.cpp b/src/core/hle/service/jit/jit.cpp index 65851fc05..a94d05e19 100644 --- a/src/core/hle/service/jit/jit.cpp +++ b/src/core/hle/service/jit/jit.cpp | |||
| @@ -26,7 +26,7 @@ public: | |||
| 26 | explicit IJitEnvironment(Core::System& system_, Kernel::KProcess& process_, CodeRange user_rx, | 26 | explicit IJitEnvironment(Core::System& system_, Kernel::KProcess& process_, CodeRange user_rx, |
| 27 | CodeRange user_ro) | 27 | CodeRange user_ro) |
| 28 | : ServiceFramework{system_, "IJitEnvironment"}, process{&process_}, | 28 | : ServiceFramework{system_, "IJitEnvironment"}, process{&process_}, |
| 29 | context{system_.ApplicationMemory()} { | 29 | context{process->GetMemory()} { |
| 30 | // clang-format off | 30 | // clang-format off |
| 31 | static const FunctionInfo functions[] = { | 31 | static const FunctionInfo functions[] = { |
| 32 | {0, &IJitEnvironment::GenerateCode, "GenerateCode"}, | 32 | {0, &IJitEnvironment::GenerateCode, "GenerateCode"}, |
| @@ -188,7 +188,7 @@ public: | |||
| 188 | return; | 188 | return; |
| 189 | } | 189 | } |
| 190 | 190 | ||
| 191 | auto tmem{process->GetHandleTable().GetObject<Kernel::KTransferMemory>(tmem_handle)}; | 191 | auto tmem{ctx.GetObjectFromHandle<Kernel::KTransferMemory>(tmem_handle)}; |
| 192 | if (tmem.IsNull()) { | 192 | if (tmem.IsNull()) { |
| 193 | LOG_ERROR(Service_JIT, "attempted to load plugin with invalid transfer memory handle"); | 193 | LOG_ERROR(Service_JIT, "attempted to load plugin with invalid transfer memory handle"); |
| 194 | IPC::ResponseBuilder rb{ctx, 2}; | 194 | IPC::ResponseBuilder rb{ctx, 2}; |
| @@ -356,11 +356,7 @@ public: | |||
| 356 | return; | 356 | return; |
| 357 | } | 357 | } |
| 358 | 358 | ||
| 359 | // Fetch using the handle table for the application process here, | 359 | auto process{ctx.GetObjectFromHandle<Kernel::KProcess>(process_handle)}; |
| 360 | // since we are not multiprocess yet. | ||
| 361 | const auto& handle_table{system.ApplicationProcess()->GetHandleTable()}; | ||
| 362 | |||
| 363 | auto process{handle_table.GetObject<Kernel::KProcess>(process_handle)}; | ||
| 364 | if (process.IsNull()) { | 360 | if (process.IsNull()) { |
| 365 | LOG_ERROR(Service_JIT, "process is null for handle=0x{:08X}", process_handle); | 361 | LOG_ERROR(Service_JIT, "process is null for handle=0x{:08X}", process_handle); |
| 366 | IPC::ResponseBuilder rb{ctx, 2}; | 362 | IPC::ResponseBuilder rb{ctx, 2}; |
| @@ -368,7 +364,7 @@ public: | |||
| 368 | return; | 364 | return; |
| 369 | } | 365 | } |
| 370 | 366 | ||
| 371 | auto rx_mem{handle_table.GetObject<Kernel::KCodeMemory>(rx_mem_handle)}; | 367 | auto rx_mem{ctx.GetObjectFromHandle<Kernel::KCodeMemory>(rx_mem_handle)}; |
| 372 | if (rx_mem.IsNull()) { | 368 | if (rx_mem.IsNull()) { |
| 373 | LOG_ERROR(Service_JIT, "rx_mem is null for handle=0x{:08X}", rx_mem_handle); | 369 | LOG_ERROR(Service_JIT, "rx_mem is null for handle=0x{:08X}", rx_mem_handle); |
| 374 | IPC::ResponseBuilder rb{ctx, 2}; | 370 | IPC::ResponseBuilder rb{ctx, 2}; |
| @@ -376,7 +372,7 @@ public: | |||
| 376 | return; | 372 | return; |
| 377 | } | 373 | } |
| 378 | 374 | ||
| 379 | auto ro_mem{handle_table.GetObject<Kernel::KCodeMemory>(ro_mem_handle)}; | 375 | auto ro_mem{ctx.GetObjectFromHandle<Kernel::KCodeMemory>(ro_mem_handle)}; |
| 380 | if (ro_mem.IsNull()) { | 376 | if (ro_mem.IsNull()) { |
| 381 | LOG_ERROR(Service_JIT, "ro_mem is null for handle=0x{:08X}", ro_mem_handle); | 377 | LOG_ERROR(Service_JIT, "ro_mem is null for handle=0x{:08X}", ro_mem_handle); |
| 382 | IPC::ResponseBuilder rb{ctx, 2}; | 378 | IPC::ResponseBuilder rb{ctx, 2}; |
diff --git a/src/core/hle/service/ro/ro.cpp b/src/core/hle/service/ro/ro.cpp index 17110d3f1..f0658bb5d 100644 --- a/src/core/hle/service/ro/ro.cpp +++ b/src/core/hle/service/ro/ro.cpp | |||
| @@ -651,10 +651,9 @@ private: | |||
| 651 | void RegisterProcessHandle(HLERequestContext& ctx) { | 651 | void RegisterProcessHandle(HLERequestContext& ctx) { |
| 652 | LOG_DEBUG(Service_LDR, "(called)"); | 652 | LOG_DEBUG(Service_LDR, "(called)"); |
| 653 | 653 | ||
| 654 | auto process_h = ctx.GetClientHandleTable().GetObject(ctx.GetCopyHandle(0)); | 654 | auto process = ctx.GetObjectFromHandle<Kernel::KProcess>(ctx.GetCopyHandle(0)); |
| 655 | auto client_pid = ctx.GetPID(); | 655 | auto client_pid = ctx.GetPID(); |
| 656 | auto result = interface.RegisterProcessHandle(client_pid, | 656 | auto result = interface.RegisterProcessHandle(client_pid, process.GetPointerUnsafe()); |
| 657 | process_h->DynamicCast<Kernel::KProcess*>()); | ||
| 658 | 657 | ||
| 659 | IPC::ResponseBuilder rb{ctx, 2}; | 658 | IPC::ResponseBuilder rb{ctx, 2}; |
| 660 | rb.Push(result); | 659 | rb.Push(result); |
| @@ -671,12 +670,11 @@ private: | |||
| 671 | 670 | ||
| 672 | IPC::RequestParser rp{ctx}; | 671 | IPC::RequestParser rp{ctx}; |
| 673 | auto params = rp.PopRaw<InputParameters>(); | 672 | auto params = rp.PopRaw<InputParameters>(); |
| 674 | auto process_h = ctx.GetClientHandleTable().GetObject(ctx.GetCopyHandle(0)); | 673 | auto process = ctx.GetObjectFromHandle<Kernel::KProcess>(ctx.GetCopyHandle(0)); |
| 675 | 674 | ||
| 676 | auto client_pid = ctx.GetPID(); | 675 | auto client_pid = ctx.GetPID(); |
| 677 | auto result = | 676 | auto result = interface.RegisterProcessModuleInfo( |
| 678 | interface.RegisterProcessModuleInfo(client_pid, params.nrr_address, params.nrr_size, | 677 | client_pid, params.nrr_address, params.nrr_size, process.GetPointerUnsafe()); |
| 679 | process_h->DynamicCast<Kernel::KProcess*>()); | ||
| 680 | 678 | ||
| 681 | IPC::ResponseBuilder rb{ctx, 2}; | 679 | IPC::ResponseBuilder rb{ctx, 2}; |
| 682 | rb.Push(result); | 680 | rb.Push(result); |
diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index 00531b021..39124c5fd 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp | |||
| @@ -203,7 +203,7 @@ Result ServiceFrameworkBase::HandleSyncRequest(Kernel::KServerSession& session, | |||
| 203 | // If emulation was shutdown, we are closing service threads, do not write the response back to | 203 | // If emulation was shutdown, we are closing service threads, do not write the response back to |
| 204 | // memory that may be shutting down as well. | 204 | // memory that may be shutting down as well. |
| 205 | if (system.IsPoweredOn()) { | 205 | if (system.IsPoweredOn()) { |
| 206 | ctx.WriteToOutgoingCommandBuffer(ctx.GetThread()); | 206 | ctx.WriteToOutgoingCommandBuffer(); |
| 207 | } | 207 | } |
| 208 | 208 | ||
| 209 | return result; | 209 | return result; |