From 5f6d9f1915620a115d9580fbf5647222ef108ed0 Mon Sep 17 00:00:00 2001 From: Weiyi Wang Date: Fri, 1 Feb 2019 12:32:49 -0500 Subject: [PATCH] Kernel/IPC: use MemorySystem from parameter --- src/core/hle/kernel/ipc.cpp | 6 +++--- src/core/hle/kernel/ipc.h | 9 +++++++-- src/core/hle/kernel/svc.cpp | 16 +++++++++------- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/core/hle/kernel/ipc.cpp b/src/core/hle/kernel/ipc.cpp index 7eb16ba9e..25676ee56 100644 --- a/src/core/hle/kernel/ipc.cpp +++ b/src/core/hle/kernel/ipc.cpp @@ -16,11 +16,11 @@ namespace Kernel { -ResultCode TranslateCommandBuffer(SharedPtr src_thread, SharedPtr dst_thread, - VAddr src_address, VAddr dst_address, +ResultCode TranslateCommandBuffer(Memory::MemorySystem& memory, SharedPtr src_thread, + SharedPtr dst_thread, VAddr src_address, + VAddr dst_address, std::vector& mapped_buffer_context, bool reply) { - Memory::MemorySystem& memory = Core::System::GetInstance().Memory(); auto& src_process = src_thread->owner_process; auto& dst_process = dst_thread->owner_process; diff --git a/src/core/hle/kernel/ipc.h b/src/core/hle/kernel/ipc.h index 9f2d57a96..55488bc72 100644 --- a/src/core/hle/kernel/ipc.h +++ b/src/core/hle/kernel/ipc.h @@ -10,6 +10,10 @@ #include "core/hle/ipc.h" #include "core/hle/kernel/thread.h" +namespace Memory { +class MemorySystem; +} + namespace Kernel { struct MappedBufferContext { @@ -23,8 +27,9 @@ struct MappedBufferContext { }; /// Performs IPC command buffer translation from one process to another. -ResultCode TranslateCommandBuffer(SharedPtr src_thread, SharedPtr dst_thread, - VAddr src_address, VAddr dst_address, +ResultCode TranslateCommandBuffer(Memory::MemorySystem& memory, SharedPtr src_thread, + SharedPtr dst_thread, VAddr src_address, + VAddr dst_address, std::vector& mapped_buffer_context, bool reply); } // namespace Kernel diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index f28717570..892aa0dc1 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp @@ -592,7 +592,8 @@ ResultCode SVC::WaitSynchronizationN(s32* out, VAddr handles_address, s32 handle } } -static ResultCode ReceiveIPCRequest(SharedPtr server_session, +static ResultCode ReceiveIPCRequest(Memory::MemorySystem& memory, + SharedPtr server_session, SharedPtr thread) { if (server_session->parent->client == nullptr) { return ERR_SESSION_CLOSED_BY_REMOTE; @@ -602,7 +603,7 @@ static ResultCode ReceiveIPCRequest(SharedPtr server_session, VAddr source_address = server_session->currently_handling->GetCommandBufferAddress(); ResultCode translation_result = - TranslateCommandBuffer(server_session->currently_handling, thread, source_address, + TranslateCommandBuffer(memory, server_session->currently_handling, thread, source_address, target_address, server_session->mapped_buffer_context, false); // If a translation error occurred, immediately resume the client thread. @@ -669,7 +670,7 @@ ResultCode SVC::ReplyAndReceive(s32* index, VAddr handles_address, s32 handle_co VAddr target_address = request_thread->GetCommandBufferAddress(); ResultCode translation_result = - TranslateCommandBuffer(thread, request_thread, source_address, target_address, + TranslateCommandBuffer(memory, thread, request_thread, source_address, target_address, session->mapped_buffer_context, true); // Note: The real kernel seems to always panic if the Server->Client buffer translation @@ -705,7 +706,7 @@ ResultCode SVC::ReplyAndReceive(s32* index, VAddr handles_address, s32 handle_co return RESULT_SUCCESS; auto server_session = static_cast(object); - return ReceiveIPCRequest(server_session, thread); + return ReceiveIPCRequest(memory, server_session, thread); } // No objects were ready to be acquired, prepare to suspend the thread. @@ -721,8 +722,9 @@ ResultCode SVC::ReplyAndReceive(s32* index, VAddr handles_address, s32 handle_co thread->wait_objects = std::move(objects); - thread->wakeup_callback = [](ThreadWakeupReason reason, SharedPtr thread, - SharedPtr object) { + thread->wakeup_callback = [& memory = this->memory](ThreadWakeupReason reason, + SharedPtr thread, + SharedPtr object) { ASSERT(thread->status == ThreadStatus::WaitSynchAny); ASSERT(reason == ThreadWakeupReason::Signal); @@ -730,7 +732,7 @@ ResultCode SVC::ReplyAndReceive(s32* index, VAddr handles_address, s32 handle_co if (object->GetHandleType() == HandleType::ServerSession) { auto server_session = DynamicObjectCast(object); - result = ReceiveIPCRequest(server_session, thread); + result = ReceiveIPCRequest(memory, server_session, thread); } thread->SetWaitSynchronizationResult(result);