From d666e01cdf2cbeb0ab55b69c8c4558e5fb6c3d2c Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Thu, 8 Jun 2017 00:33:24 -0700 Subject: [PATCH 1/2] Kernel: Ensure objects are kept alive during ClientSession disconnection Fixes #2760 --- src/core/hle/kernel/client_session.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/core/hle/kernel/client_session.cpp b/src/core/hle/kernel/client_session.cpp index 6bc49ff64f..5ac427bdb1 100644 --- a/src/core/hle/kernel/client_session.cpp +++ b/src/core/hle/kernel/client_session.cpp @@ -16,9 +16,13 @@ ClientSession::~ClientSession() { // This destructor will be called automatically when the last ClientSession handle is closed by // the emulated application. - if (parent->server) { - if (parent->server->hle_handler) - parent->server->hle_handler->ClientDisconnected(parent->server); + // Local references to ServerSession and SessionRequestHandler are necessary to guarantee they + // will be kept alive until after ClientDisconnected() returns. + SharedPtr server = parent->server; + if (server) { + std::shared_ptr hle_handler = server->hle_handler; + if (hle_handler) + hle_handler->ClientDisconnected(server); // TODO(Subv): Force a wake up of all the ServerSession's waiting threads and set // their WaitSynchronization result to 0xC920181A. @@ -28,11 +32,13 @@ ClientSession::~ClientSession() { } ResultCode ClientSession::SendSyncRequest() { - // Signal the server session that new data is available - if (parent->server) - return parent->server->HandleSyncRequest(); + // Keep ServerSession alive until we're done working with it. + SharedPtr server = parent->server; + if (server == nullptr) + return ERR_SESSION_CLOSED_BY_REMOTE; - return ERR_SESSION_CLOSED_BY_REMOTE; + // Signal the server session that new data is available + return server->HandleSyncRequest(); } } // namespace From 838faf147e03d68c63ffb8b37b6785196e06c205 Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Thu, 8 Jun 2017 00:33:57 -0700 Subject: [PATCH 2/2] Session: Remove/add some forward declarations --- src/citra_qt/debugger/wait_tree.h | 1 - src/core/hle/kernel/client_session.cpp | 1 + src/core/hle/kernel/server_session.h | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/citra_qt/debugger/wait_tree.h b/src/citra_qt/debugger/wait_tree.h index 06ef58ea7d..2b38712b91 100644 --- a/src/citra_qt/debugger/wait_tree.h +++ b/src/citra_qt/debugger/wait_tree.h @@ -18,7 +18,6 @@ class WaitObject; class Event; class Mutex; class Semaphore; -class Session; class Thread; class Timer; } diff --git a/src/core/hle/kernel/client_session.cpp b/src/core/hle/kernel/client_session.cpp index 5ac427bdb1..fef97af1f7 100644 --- a/src/core/hle/kernel/client_session.cpp +++ b/src/core/hle/kernel/client_session.cpp @@ -8,6 +8,7 @@ #include "core/hle/kernel/errors.h" #include "core/hle/kernel/hle_ipc.h" #include "core/hle/kernel/server_session.h" +#include "core/hle/kernel/session.h" namespace Kernel { diff --git a/src/core/hle/kernel/server_session.h b/src/core/hle/kernel/server_session.h index 28f365b9e7..5365605daf 100644 --- a/src/core/hle/kernel/server_session.h +++ b/src/core/hle/kernel/server_session.h @@ -9,7 +9,6 @@ #include "common/assert.h" #include "common/common_types.h" #include "core/hle/kernel/kernel.h" -#include "core/hle/kernel/session.h" #include "core/hle/kernel/wait_object.h" #include "core/hle/result.h" #include "core/memory.h" @@ -19,6 +18,7 @@ namespace Kernel { class ClientSession; class ClientPort; class ServerSession; +class Session; class SessionRequestHandler; class Thread;