summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar bunnei2019-11-24 20:15:51 -0500
committerGravatar GitHub2019-11-24 20:15:51 -0500
commit9046d4a5485452802b756869b7d27056ba9ea9d7 (patch)
tree2d704d912e9054fb232b73ad69f1bc3966ed97a5 /src
parentMerge pull request #3098 from ReinUsesLisp/shader-invalidations (diff)
downloadyuzu-9046d4a5485452802b756869b7d27056ba9ea9d7.tar.gz
yuzu-9046d4a5485452802b756869b7d27056ba9ea9d7.tar.xz
yuzu-9046d4a5485452802b756869b7d27056ba9ea9d7.zip
kernel: Replace usage of boost::intrusive_ptr with std::shared_ptr for kernel objects. (#3154)
* kernel: Replace usage of boost::intrusive_ptr with std::shared_ptr for kernel objects. - See https://github.com/citra-emu/citra/pull/4710 for details.
Diffstat (limited to 'src')
-rw-r--r--src/audio_core/audio_renderer.cpp2
-rw-r--r--src/audio_core/audio_renderer.h5
-rw-r--r--src/core/core.h1
-rw-r--r--src/core/hle/ipc_helpers.h16
-rw-r--r--src/core/hle/kernel/address_arbiter.cpp18
-rw-r--r--src/core/hle/kernel/address_arbiter.h2
-rw-r--r--src/core/hle/kernel/client_port.cpp7
-rw-r--r--src/core/hle/kernel/client_port.h12
-rw-r--r--src/core/hle/kernel/client_session.cpp15
-rw-r--r--src/core/hle/kernel/client_session.h8
-rw-r--r--src/core/hle/kernel/handle_table.cpp10
-rw-r--r--src/core/hle/kernel/handle_table.h8
-rw-r--r--src/core/hle/kernel/hle_ipc.cpp20
-rw-r--r--src/core/hle/kernel/hle_ipc.h38
-rw-r--r--src/core/hle/kernel/kernel.cpp19
-rw-r--r--src/core/hle/kernel/kernel.h13
-rw-r--r--src/core/hle/kernel/mutex.cpp22
-rw-r--r--src/core/hle/kernel/object.h30
-rw-r--r--src/core/hle/kernel/process.cpp33
-rw-r--r--src/core/hle/kernel/process.h21
-rw-r--r--src/core/hle/kernel/resource_limit.cpp4
-rw-r--r--src/core/hle/kernel/resource_limit.h8
-rw-r--r--src/core/hle/kernel/scheduler.cpp10
-rw-r--r--src/core/hle/kernel/scheduler.h12
-rw-r--r--src/core/hle/kernel/server_port.cpp8
-rw-r--r--src/core/hle/kernel/server_port.h14
-rw-r--r--src/core/hle/kernel/server_session.cpp15
-rw-r--r--src/core/hle/kernel/server_session.h20
-rw-r--r--src/core/hle/kernel/session.h6
-rw-r--r--src/core/hle/kernel/shared_memory.cpp15
-rw-r--r--src/core/hle/kernel/shared_memory.h19
-rw-r--r--src/core/hle/kernel/svc.cpp52
-rw-r--r--src/core/hle/kernel/thread.cpp39
-rw-r--r--src/core/hle/kernel/thread.h39
-rw-r--r--src/core/hle/kernel/transfer_memory.cpp6
-rw-r--r--src/core/hle/kernel/transfer_memory.h10
-rw-r--r--src/core/hle/kernel/wait_object.cpp17
-rw-r--r--src/core/hle/kernel/wait_object.h16
-rw-r--r--src/core/hle/kernel/writable_event.cpp6
-rw-r--r--src/core/hle/kernel/writable_event.h8
-rw-r--r--src/core/hle/service/am/am.cpp5
-rw-r--r--src/core/hle/service/am/am.h4
-rw-r--r--src/core/hle/service/am/applets/applets.cpp6
-rw-r--r--src/core/hle/service/am/applets/applets.h6
-rw-r--r--src/core/hle/service/bcat/backend/backend.cpp2
-rw-r--r--src/core/hle/service/bcat/backend/backend.h2
-rw-r--r--src/core/hle/service/bcat/module.cpp4
-rw-r--r--src/core/hle/service/hid/controllers/npad.cpp3
-rw-r--r--src/core/hle/service/hid/controllers/npad.h2
-rw-r--r--src/core/hle/service/hid/hid.h2
-rw-r--r--src/core/hle/service/hid/irs.h2
-rw-r--r--src/core/hle/service/nfp/nfp.cpp2
-rw-r--r--src/core/hle/service/nfp/nfp.h2
-rw-r--r--src/core/hle/service/ns/pl_u.cpp2
-rw-r--r--src/core/hle/service/nvdrv/interface.cpp2
-rw-r--r--src/core/hle/service/nvdrv/nvdrv.cpp4
-rw-r--r--src/core/hle/service/nvdrv/nvdrv.h4
-rw-r--r--src/core/hle/service/nvflinger/buffer_queue.cpp4
-rw-r--r--src/core/hle/service/nvflinger/buffer_queue.h4
-rw-r--r--src/core/hle/service/nvflinger/nvflinger.cpp2
-rw-r--r--src/core/hle/service/nvflinger/nvflinger.h2
-rw-r--r--src/core/hle/service/pm/pm.cpp12
-rw-r--r--src/core/hle/service/service.cpp2
-rw-r--r--src/core/hle/service/service.h2
-rw-r--r--src/core/hle/service/sm/controller.cpp2
-rw-r--r--src/core/hle/service/sm/sm.cpp6
-rw-r--r--src/core/hle/service/sm/sm.h10
-rw-r--r--src/core/hle/service/time/time_sharedmemory.cpp2
-rw-r--r--src/core/hle/service/time/time_sharedmemory.h4
-rw-r--r--src/core/hle/service/vi/display/vi_display.cpp2
-rw-r--r--src/core/hle/service/vi/display/vi_display.h2
-rw-r--r--src/core/hle/service/vi/vi.cpp2
-rw-r--r--src/yuzu/debugger/wait_tree.cpp8
-rw-r--r--src/yuzu/debugger/wait_tree.h11
74 files changed, 377 insertions, 378 deletions
diff --git a/src/audio_core/audio_renderer.cpp b/src/audio_core/audio_renderer.cpp
index e6f38d600..6b0167acd 100644
--- a/src/audio_core/audio_renderer.cpp
+++ b/src/audio_core/audio_renderer.cpp
@@ -73,7 +73,7 @@ private:
73 EffectInStatus info{}; 73 EffectInStatus info{};
74}; 74};
75AudioRenderer::AudioRenderer(Core::Timing::CoreTiming& core_timing, AudioRendererParameter params, 75AudioRenderer::AudioRenderer(Core::Timing::CoreTiming& core_timing, AudioRendererParameter params,
76 Kernel::SharedPtr<Kernel::WritableEvent> buffer_event, 76 std::shared_ptr<Kernel::WritableEvent> buffer_event,
77 std::size_t instance_number) 77 std::size_t instance_number)
78 : worker_params{params}, buffer_event{buffer_event}, voices(params.voice_count), 78 : worker_params{params}, buffer_event{buffer_event}, voices(params.voice_count),
79 effects(params.effect_count) { 79 effects(params.effect_count) {
diff --git a/src/audio_core/audio_renderer.h b/src/audio_core/audio_renderer.h
index 4f14b91cd..abed224bb 100644
--- a/src/audio_core/audio_renderer.h
+++ b/src/audio_core/audio_renderer.h
@@ -218,8 +218,7 @@ static_assert(sizeof(UpdateDataHeader) == 0x40, "UpdateDataHeader has wrong size
218class AudioRenderer { 218class AudioRenderer {
219public: 219public:
220 AudioRenderer(Core::Timing::CoreTiming& core_timing, AudioRendererParameter params, 220 AudioRenderer(Core::Timing::CoreTiming& core_timing, AudioRendererParameter params,
221 Kernel::SharedPtr<Kernel::WritableEvent> buffer_event, 221 std::shared_ptr<Kernel::WritableEvent> buffer_event, std::size_t instance_number);
222 std::size_t instance_number);
223 ~AudioRenderer(); 222 ~AudioRenderer();
224 223
225 std::vector<u8> UpdateAudioRenderer(const std::vector<u8>& input_params); 224 std::vector<u8> UpdateAudioRenderer(const std::vector<u8>& input_params);
@@ -235,7 +234,7 @@ private:
235 class VoiceState; 234 class VoiceState;
236 235
237 AudioRendererParameter worker_params; 236 AudioRendererParameter worker_params;
238 Kernel::SharedPtr<Kernel::WritableEvent> buffer_event; 237 std::shared_ptr<Kernel::WritableEvent> buffer_event;
239 std::vector<VoiceState> voices; 238 std::vector<VoiceState> voices;
240 std::vector<EffectState> effects; 239 std::vector<EffectState> effects;
241 std::unique_ptr<AudioOut> audio_out; 240 std::unique_ptr<AudioOut> audio_out;
diff --git a/src/core/core.h b/src/core/core.h
index 984074ce3..f9b1a2866 100644
--- a/src/core/core.h
+++ b/src/core/core.h
@@ -7,6 +7,7 @@
7#include <cstddef> 7#include <cstddef>
8#include <memory> 8#include <memory>
9#include <string> 9#include <string>
10#include <vector>
10 11
11#include "common/common_types.h" 12#include "common/common_types.h"
12#include "core/file_sys/vfs_types.h" 13#include "core/file_sys/vfs_types.h"
diff --git a/src/core/hle/ipc_helpers.h b/src/core/hle/ipc_helpers.h
index 5bb139483..b9f9ae1fa 100644
--- a/src/core/hle/ipc_helpers.h
+++ b/src/core/hle/ipc_helpers.h
@@ -203,10 +203,10 @@ public:
203 void PushRaw(const T& value); 203 void PushRaw(const T& value);
204 204
205 template <typename... O> 205 template <typename... O>
206 void PushMoveObjects(Kernel::SharedPtr<O>... pointers); 206 void PushMoveObjects(std::shared_ptr<O>... pointers);
207 207
208 template <typename... O> 208 template <typename... O>
209 void PushCopyObjects(Kernel::SharedPtr<O>... pointers); 209 void PushCopyObjects(std::shared_ptr<O>... pointers);
210 210
211private: 211private:
212 u32 normal_params_size{}; 212 u32 normal_params_size{};
@@ -298,7 +298,7 @@ void ResponseBuilder::Push(const First& first_value, const Other&... other_value
298} 298}
299 299
300template <typename... O> 300template <typename... O>
301inline void ResponseBuilder::PushCopyObjects(Kernel::SharedPtr<O>... pointers) { 301inline void ResponseBuilder::PushCopyObjects(std::shared_ptr<O>... pointers) {
302 auto objects = {pointers...}; 302 auto objects = {pointers...};
303 for (auto& object : objects) { 303 for (auto& object : objects) {
304 context->AddCopyObject(std::move(object)); 304 context->AddCopyObject(std::move(object));
@@ -306,7 +306,7 @@ inline void ResponseBuilder::PushCopyObjects(Kernel::SharedPtr<O>... pointers) {
306} 306}
307 307
308template <typename... O> 308template <typename... O>
309inline void ResponseBuilder::PushMoveObjects(Kernel::SharedPtr<O>... pointers) { 309inline void ResponseBuilder::PushMoveObjects(std::shared_ptr<O>... pointers) {
310 auto objects = {pointers...}; 310 auto objects = {pointers...};
311 for (auto& object : objects) { 311 for (auto& object : objects) {
312 context->AddMoveObject(std::move(object)); 312 context->AddMoveObject(std::move(object));
@@ -357,10 +357,10 @@ public:
357 T PopRaw(); 357 T PopRaw();
358 358
359 template <typename T> 359 template <typename T>
360 Kernel::SharedPtr<T> GetMoveObject(std::size_t index); 360 std::shared_ptr<T> GetMoveObject(std::size_t index);
361 361
362 template <typename T> 362 template <typename T>
363 Kernel::SharedPtr<T> GetCopyObject(std::size_t index); 363 std::shared_ptr<T> GetCopyObject(std::size_t index);
364 364
365 template <class T> 365 template <class T>
366 std::shared_ptr<T> PopIpcInterface() { 366 std::shared_ptr<T> PopIpcInterface() {
@@ -465,12 +465,12 @@ void RequestParser::Pop(First& first_value, Other&... other_values) {
465} 465}
466 466
467template <typename T> 467template <typename T>
468Kernel::SharedPtr<T> RequestParser::GetMoveObject(std::size_t index) { 468std::shared_ptr<T> RequestParser::GetMoveObject(std::size_t index) {
469 return context->GetMoveObject<T>(index); 469 return context->GetMoveObject<T>(index);
470} 470}
471 471
472template <typename T> 472template <typename T>
473Kernel::SharedPtr<T> RequestParser::GetCopyObject(std::size_t index) { 473std::shared_ptr<T> RequestParser::GetCopyObject(std::size_t index) {
474 return context->GetCopyObject<T>(index); 474 return context->GetCopyObject<T>(index);
475} 475}
476 476
diff --git a/src/core/hle/kernel/address_arbiter.cpp b/src/core/hle/kernel/address_arbiter.cpp
index de0a9064e..4859954cb 100644
--- a/src/core/hle/kernel/address_arbiter.cpp
+++ b/src/core/hle/kernel/address_arbiter.cpp
@@ -21,7 +21,7 @@
21namespace Kernel { 21namespace Kernel {
22namespace { 22namespace {
23// Wake up num_to_wake (or all) threads in a vector. 23// Wake up num_to_wake (or all) threads in a vector.
24void WakeThreads(const std::vector<SharedPtr<Thread>>& waiting_threads, s32 num_to_wake) { 24void WakeThreads(const std::vector<std::shared_ptr<Thread>>& waiting_threads, s32 num_to_wake) {
25 auto& system = Core::System::GetInstance(); 25 auto& system = Core::System::GetInstance();
26 // Only process up to 'target' threads, unless 'target' is <= 0, in which case process 26 // Only process up to 'target' threads, unless 'target' is <= 0, in which case process
27 // them all. 27 // them all.
@@ -59,7 +59,8 @@ ResultCode AddressArbiter::SignalToAddress(VAddr address, SignalType type, s32 v
59} 59}
60 60
61ResultCode AddressArbiter::SignalToAddressOnly(VAddr address, s32 num_to_wake) { 61ResultCode AddressArbiter::SignalToAddressOnly(VAddr address, s32 num_to_wake) {
62 const std::vector<SharedPtr<Thread>> waiting_threads = GetThreadsWaitingOnAddress(address); 62 const std::vector<std::shared_ptr<Thread>> waiting_threads =
63 GetThreadsWaitingOnAddress(address);
63 WakeThreads(waiting_threads, num_to_wake); 64 WakeThreads(waiting_threads, num_to_wake);
64 return RESULT_SUCCESS; 65 return RESULT_SUCCESS;
65} 66}
@@ -87,7 +88,8 @@ ResultCode AddressArbiter::ModifyByWaitingCountAndSignalToAddressIfEqual(VAddr a
87 } 88 }
88 89
89 // Get threads waiting on the address. 90 // Get threads waiting on the address.
90 const std::vector<SharedPtr<Thread>> waiting_threads = GetThreadsWaitingOnAddress(address); 91 const std::vector<std::shared_ptr<Thread>> waiting_threads =
92 GetThreadsWaitingOnAddress(address);
91 93
92 // Determine the modified value depending on the waiting count. 94 // Determine the modified value depending on the waiting count.
93 s32 updated_value; 95 s32 updated_value;
@@ -172,21 +174,21 @@ ResultCode AddressArbiter::WaitForAddressIfEqual(VAddr address, s32 value, s64 t
172} 174}
173 175
174ResultCode AddressArbiter::WaitForAddressImpl(VAddr address, s64 timeout) { 176ResultCode AddressArbiter::WaitForAddressImpl(VAddr address, s64 timeout) {
175 SharedPtr<Thread> current_thread = system.CurrentScheduler().GetCurrentThread(); 177 Thread* current_thread = system.CurrentScheduler().GetCurrentThread();
176 current_thread->SetArbiterWaitAddress(address); 178 current_thread->SetArbiterWaitAddress(address);
177 current_thread->SetStatus(ThreadStatus::WaitArb); 179 current_thread->SetStatus(ThreadStatus::WaitArb);
178 current_thread->InvalidateWakeupCallback(); 180 current_thread->InvalidateWakeupCallback();
179
180 current_thread->WakeAfterDelay(timeout); 181 current_thread->WakeAfterDelay(timeout);
181 182
182 system.PrepareReschedule(current_thread->GetProcessorID()); 183 system.PrepareReschedule(current_thread->GetProcessorID());
183 return RESULT_TIMEOUT; 184 return RESULT_TIMEOUT;
184} 185}
185 186
186std::vector<SharedPtr<Thread>> AddressArbiter::GetThreadsWaitingOnAddress(VAddr address) const { 187std::vector<std::shared_ptr<Thread>> AddressArbiter::GetThreadsWaitingOnAddress(
188 VAddr address) const {
187 189
188 // Retrieve all threads that are waiting for this address. 190 // Retrieve all threads that are waiting for this address.
189 std::vector<SharedPtr<Thread>> threads; 191 std::vector<std::shared_ptr<Thread>> threads;
190 const auto& scheduler = system.GlobalScheduler(); 192 const auto& scheduler = system.GlobalScheduler();
191 const auto& thread_list = scheduler.GetThreadList(); 193 const auto& thread_list = scheduler.GetThreadList();
192 194
@@ -198,7 +200,7 @@ std::vector<SharedPtr<Thread>> AddressArbiter::GetThreadsWaitingOnAddress(VAddr
198 200
199 // Sort them by priority, such that the highest priority ones come first. 201 // Sort them by priority, such that the highest priority ones come first.
200 std::sort(threads.begin(), threads.end(), 202 std::sort(threads.begin(), threads.end(),
201 [](const SharedPtr<Thread>& lhs, const SharedPtr<Thread>& rhs) { 203 [](const std::shared_ptr<Thread>& lhs, const std::shared_ptr<Thread>& rhs) {
202 return lhs->GetPriority() < rhs->GetPriority(); 204 return lhs->GetPriority() < rhs->GetPriority();
203 }); 205 });
204 206
diff --git a/src/core/hle/kernel/address_arbiter.h b/src/core/hle/kernel/address_arbiter.h
index ed0d0e69f..608918de5 100644
--- a/src/core/hle/kernel/address_arbiter.h
+++ b/src/core/hle/kernel/address_arbiter.h
@@ -72,7 +72,7 @@ private:
72 ResultCode WaitForAddressImpl(VAddr address, s64 timeout); 72 ResultCode WaitForAddressImpl(VAddr address, s64 timeout);
73 73
74 // Gets the threads waiting on an address. 74 // Gets the threads waiting on an address.
75 std::vector<SharedPtr<Thread>> GetThreadsWaitingOnAddress(VAddr address) const; 75 std::vector<std::shared_ptr<Thread>> GetThreadsWaitingOnAddress(VAddr address) const;
76 76
77 Core::System& system; 77 Core::System& system;
78}; 78};
diff --git a/src/core/hle/kernel/client_port.cpp b/src/core/hle/kernel/client_port.cpp
index 744b1697d..4637b6017 100644
--- a/src/core/hle/kernel/client_port.cpp
+++ b/src/core/hle/kernel/client_port.cpp
@@ -15,11 +15,11 @@ namespace Kernel {
15ClientPort::ClientPort(KernelCore& kernel) : Object{kernel} {} 15ClientPort::ClientPort(KernelCore& kernel) : Object{kernel} {}
16ClientPort::~ClientPort() = default; 16ClientPort::~ClientPort() = default;
17 17
18SharedPtr<ServerPort> ClientPort::GetServerPort() const { 18std::shared_ptr<ServerPort> ClientPort::GetServerPort() const {
19 return server_port; 19 return server_port;
20} 20}
21 21
22ResultVal<SharedPtr<ClientSession>> ClientPort::Connect() { 22ResultVal<std::shared_ptr<ClientSession>> ClientPort::Connect() {
23 // Note: Threads do not wait for the server endpoint to call 23 // Note: Threads do not wait for the server endpoint to call
24 // AcceptSession before returning from this call. 24 // AcceptSession before returning from this call.
25 25
@@ -29,7 +29,8 @@ ResultVal<SharedPtr<ClientSession>> ClientPort::Connect() {
29 active_sessions++; 29 active_sessions++;
30 30
31 // Create a new session pair, let the created sessions inherit the parent port's HLE handler. 31 // Create a new session pair, let the created sessions inherit the parent port's HLE handler.
32 auto [server, client] = ServerSession::CreateSessionPair(kernel, server_port->GetName(), this); 32 auto [server, client] =
33 ServerSession::CreateSessionPair(kernel, server_port->GetName(), SharedFrom(this));
33 34
34 if (server_port->HasHLEHandler()) { 35 if (server_port->HasHLEHandler()) {
35 server_port->GetHLEHandler()->ClientConnected(server); 36 server_port->GetHLEHandler()->ClientConnected(server);
diff --git a/src/core/hle/kernel/client_port.h b/src/core/hle/kernel/client_port.h
index 4921ad4f0..715edd18c 100644
--- a/src/core/hle/kernel/client_port.h
+++ b/src/core/hle/kernel/client_port.h
@@ -17,6 +17,9 @@ class ServerPort;
17 17
18class ClientPort final : public Object { 18class ClientPort final : public Object {
19public: 19public:
20 explicit ClientPort(KernelCore& kernel);
21 ~ClientPort() override;
22
20 friend class ServerPort; 23 friend class ServerPort;
21 std::string GetTypeName() const override { 24 std::string GetTypeName() const override {
22 return "ClientPort"; 25 return "ClientPort";
@@ -30,7 +33,7 @@ public:
30 return HANDLE_TYPE; 33 return HANDLE_TYPE;
31 } 34 }
32 35
33 SharedPtr<ServerPort> GetServerPort() const; 36 std::shared_ptr<ServerPort> GetServerPort() const;
34 37
35 /** 38 /**
36 * Creates a new Session pair, adds the created ServerSession to the associated ServerPort's 39 * Creates a new Session pair, adds the created ServerSession to the associated ServerPort's
@@ -38,7 +41,7 @@ public:
38 * waiting on it to awake. 41 * waiting on it to awake.
39 * @returns ClientSession The client endpoint of the created Session pair, or error code. 42 * @returns ClientSession The client endpoint of the created Session pair, or error code.
40 */ 43 */
41 ResultVal<SharedPtr<ClientSession>> Connect(); 44 ResultVal<std::shared_ptr<ClientSession>> Connect();
42 45
43 /** 46 /**
44 * Signifies that a previously active connection has been closed, 47 * Signifies that a previously active connection has been closed,
@@ -47,10 +50,7 @@ public:
47 void ConnectionClosed(); 50 void ConnectionClosed();
48 51
49private: 52private:
50 explicit ClientPort(KernelCore& kernel); 53 std::shared_ptr<ServerPort> server_port; ///< ServerPort associated with this client port.
51 ~ClientPort() override;
52
53 SharedPtr<ServerPort> server_port; ///< ServerPort associated with this client port.
54 u32 max_sessions = 0; ///< Maximum number of simultaneous sessions the port can have 54 u32 max_sessions = 0; ///< Maximum number of simultaneous sessions the port can have
55 u32 active_sessions = 0; ///< Number of currently open sessions to this port 55 u32 active_sessions = 0; ///< Number of currently open sessions to this port
56 std::string name; ///< Name of client port (optional) 56 std::string name; ///< Name of client port (optional)
diff --git a/src/core/hle/kernel/client_session.cpp b/src/core/hle/kernel/client_session.cpp
index c17baa50a..bc59d3306 100644
--- a/src/core/hle/kernel/client_session.cpp
+++ b/src/core/hle/kernel/client_session.cpp
@@ -16,25 +16,20 @@ ClientSession::ClientSession(KernelCore& kernel) : Object{kernel} {}
16ClientSession::~ClientSession() { 16ClientSession::~ClientSession() {
17 // This destructor will be called automatically when the last ClientSession handle is closed by 17 // This destructor will be called automatically when the last ClientSession handle is closed by
18 // the emulated application. 18 // the emulated application.
19 19 if (parent->server) {
20 // A local reference to the ServerSession is necessary to guarantee it 20 parent->server->ClientDisconnected();
21 // will be kept alive until after ClientDisconnected() returns.
22 SharedPtr<ServerSession> server = parent->server;
23 if (server) {
24 server->ClientDisconnected();
25 } 21 }
26 22
27 parent->client = nullptr; 23 parent->client = nullptr;
28} 24}
29 25
30ResultCode ClientSession::SendSyncRequest(SharedPtr<Thread> thread) { 26ResultCode ClientSession::SendSyncRequest(Thread* thread) {
31 // Keep ServerSession alive until we're done working with it. 27 // Keep ServerSession alive until we're done working with it.
32 SharedPtr<ServerSession> server = parent->server; 28 if (parent->server == nullptr)
33 if (server == nullptr)
34 return ERR_SESSION_CLOSED_BY_REMOTE; 29 return ERR_SESSION_CLOSED_BY_REMOTE;
35 30
36 // Signal the server session that new data is available 31 // Signal the server session that new data is available
37 return server->HandleSyncRequest(std::move(thread)); 32 return parent->server->HandleSyncRequest(SharedFrom(thread));
38} 33}
39 34
40} // namespace Kernel 35} // namespace Kernel
diff --git a/src/core/hle/kernel/client_session.h b/src/core/hle/kernel/client_session.h
index 09cdff588..5ae41db29 100644
--- a/src/core/hle/kernel/client_session.h
+++ b/src/core/hle/kernel/client_session.h
@@ -19,6 +19,9 @@ class Thread;
19 19
20class ClientSession final : public Object { 20class ClientSession final : public Object {
21public: 21public:
22 explicit ClientSession(KernelCore& kernel);
23 ~ClientSession() override;
24
22 friend class ServerSession; 25 friend class ServerSession;
23 26
24 std::string GetTypeName() const override { 27 std::string GetTypeName() const override {
@@ -34,12 +37,9 @@ public:
34 return HANDLE_TYPE; 37 return HANDLE_TYPE;
35 } 38 }
36 39
37 ResultCode SendSyncRequest(SharedPtr<Thread> thread); 40 ResultCode SendSyncRequest(Thread* thread);
38 41
39private: 42private:
40 explicit ClientSession(KernelCore& kernel);
41 ~ClientSession() override;
42
43 /// The parent session, which links to the server endpoint. 43 /// The parent session, which links to the server endpoint.
44 std::shared_ptr<Session> parent; 44 std::shared_ptr<Session> parent;
45 45
diff --git a/src/core/hle/kernel/handle_table.cpp b/src/core/hle/kernel/handle_table.cpp
index 2cc5d536b..e441a27fc 100644
--- a/src/core/hle/kernel/handle_table.cpp
+++ b/src/core/hle/kernel/handle_table.cpp
@@ -44,7 +44,7 @@ ResultCode HandleTable::SetSize(s32 handle_table_size) {
44 return RESULT_SUCCESS; 44 return RESULT_SUCCESS;
45} 45}
46 46
47ResultVal<Handle> HandleTable::Create(SharedPtr<Object> obj) { 47ResultVal<Handle> HandleTable::Create(std::shared_ptr<Object> obj) {
48 DEBUG_ASSERT(obj != nullptr); 48 DEBUG_ASSERT(obj != nullptr);
49 49
50 const u16 slot = next_free_slot; 50 const u16 slot = next_free_slot;
@@ -70,7 +70,7 @@ ResultVal<Handle> HandleTable::Create(SharedPtr<Object> obj) {
70} 70}
71 71
72ResultVal<Handle> HandleTable::Duplicate(Handle handle) { 72ResultVal<Handle> HandleTable::Duplicate(Handle handle) {
73 SharedPtr<Object> object = GetGeneric(handle); 73 std::shared_ptr<Object> object = GetGeneric(handle);
74 if (object == nullptr) { 74 if (object == nullptr) {
75 LOG_ERROR(Kernel, "Tried to duplicate invalid handle: {:08X}", handle); 75 LOG_ERROR(Kernel, "Tried to duplicate invalid handle: {:08X}", handle);
76 return ERR_INVALID_HANDLE; 76 return ERR_INVALID_HANDLE;
@@ -99,11 +99,11 @@ bool HandleTable::IsValid(Handle handle) const {
99 return slot < table_size && objects[slot] != nullptr && generations[slot] == generation; 99 return slot < table_size && objects[slot] != nullptr && generations[slot] == generation;
100} 100}
101 101
102SharedPtr<Object> HandleTable::GetGeneric(Handle handle) const { 102std::shared_ptr<Object> HandleTable::GetGeneric(Handle handle) const {
103 if (handle == CurrentThread) { 103 if (handle == CurrentThread) {
104 return GetCurrentThread(); 104 return SharedFrom(GetCurrentThread());
105 } else if (handle == CurrentProcess) { 105 } else if (handle == CurrentProcess) {
106 return Core::System::GetInstance().CurrentProcess(); 106 return SharedFrom(Core::System::GetInstance().CurrentProcess());
107 } 107 }
108 108
109 if (!IsValid(handle)) { 109 if (!IsValid(handle)) {
diff --git a/src/core/hle/kernel/handle_table.h b/src/core/hle/kernel/handle_table.h
index 44901391b..9fcb4cc15 100644
--- a/src/core/hle/kernel/handle_table.h
+++ b/src/core/hle/kernel/handle_table.h
@@ -68,7 +68,7 @@ public:
68 * @return The created Handle or one of the following errors: 68 * @return The created Handle or one of the following errors:
69 * - `ERR_HANDLE_TABLE_FULL`: the maximum number of handles has been exceeded. 69 * - `ERR_HANDLE_TABLE_FULL`: the maximum number of handles has been exceeded.
70 */ 70 */
71 ResultVal<Handle> Create(SharedPtr<Object> obj); 71 ResultVal<Handle> Create(std::shared_ptr<Object> obj);
72 72
73 /** 73 /**
74 * Returns a new handle that points to the same object as the passed in handle. 74 * Returns a new handle that points to the same object as the passed in handle.
@@ -92,7 +92,7 @@ public:
92 * Looks up a handle. 92 * Looks up a handle.
93 * @return Pointer to the looked-up object, or `nullptr` if the handle is not valid. 93 * @return Pointer to the looked-up object, or `nullptr` if the handle is not valid.
94 */ 94 */
95 SharedPtr<Object> GetGeneric(Handle handle) const; 95 std::shared_ptr<Object> GetGeneric(Handle handle) const;
96 96
97 /** 97 /**
98 * Looks up a handle while verifying its type. 98 * Looks up a handle while verifying its type.
@@ -100,7 +100,7 @@ public:
100 * type differs from the requested one. 100 * type differs from the requested one.
101 */ 101 */
102 template <class T> 102 template <class T>
103 SharedPtr<T> Get(Handle handle) const { 103 std::shared_ptr<T> Get(Handle handle) const {
104 return DynamicObjectCast<T>(GetGeneric(handle)); 104 return DynamicObjectCast<T>(GetGeneric(handle));
105 } 105 }
106 106
@@ -109,7 +109,7 @@ public:
109 109
110private: 110private:
111 /// Stores the Object referenced by the handle or null if the slot is empty. 111 /// Stores the Object referenced by the handle or null if the slot is empty.
112 std::array<SharedPtr<Object>, MAX_COUNT> objects; 112 std::array<std::shared_ptr<Object>, MAX_COUNT> objects;
113 113
114 /** 114 /**
115 * The value of `next_generation` when the handle was created, used to check for validity. For 115 * The value of `next_generation` when the handle was created, used to check for validity. For
diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp
index a7b5849b0..be24cef06 100644
--- a/src/core/hle/kernel/hle_ipc.cpp
+++ b/src/core/hle/kernel/hle_ipc.cpp
@@ -32,23 +32,25 @@ SessionRequestHandler::SessionRequestHandler() = default;
32 32
33SessionRequestHandler::~SessionRequestHandler() = default; 33SessionRequestHandler::~SessionRequestHandler() = default;
34 34
35void SessionRequestHandler::ClientConnected(SharedPtr<ServerSession> server_session) { 35void SessionRequestHandler::ClientConnected(std::shared_ptr<ServerSession> server_session) {
36 server_session->SetHleHandler(shared_from_this()); 36 server_session->SetHleHandler(shared_from_this());
37 connected_sessions.push_back(std::move(server_session)); 37 connected_sessions.push_back(std::move(server_session));
38} 38}
39 39
40void SessionRequestHandler::ClientDisconnected(const SharedPtr<ServerSession>& server_session) { 40void SessionRequestHandler::ClientDisconnected(
41 const std::shared_ptr<ServerSession>& server_session) {
41 server_session->SetHleHandler(nullptr); 42 server_session->SetHleHandler(nullptr);
42 boost::range::remove_erase(connected_sessions, server_session); 43 boost::range::remove_erase(connected_sessions, server_session);
43} 44}
44 45
45SharedPtr<WritableEvent> HLERequestContext::SleepClientThread( 46std::shared_ptr<WritableEvent> HLERequestContext::SleepClientThread(
46 const std::string& reason, u64 timeout, WakeupCallback&& callback, 47 const std::string& reason, u64 timeout, WakeupCallback&& callback,
47 SharedPtr<WritableEvent> writable_event) { 48 std::shared_ptr<WritableEvent> writable_event) {
48 // Put the client thread to sleep until the wait event is signaled or the timeout expires. 49 // Put the client thread to sleep until the wait event is signaled or the timeout expires.
49 thread->SetWakeupCallback([context = *this, callback]( 50 thread->SetWakeupCallback([context = *this, callback](ThreadWakeupReason reason,
50 ThreadWakeupReason reason, SharedPtr<Thread> thread, 51 std::shared_ptr<Thread> thread,
51 SharedPtr<WaitObject> object, std::size_t index) mutable -> bool { 52 std::shared_ptr<WaitObject> object,
53 std::size_t index) mutable -> bool {
52 ASSERT(thread->GetStatus() == ThreadStatus::WaitHLEEvent); 54 ASSERT(thread->GetStatus() == ThreadStatus::WaitHLEEvent);
53 callback(thread, context, reason); 55 callback(thread, context, reason);
54 context.WriteToOutgoingCommandBuffer(*thread); 56 context.WriteToOutgoingCommandBuffer(*thread);
@@ -75,8 +77,8 @@ SharedPtr<WritableEvent> HLERequestContext::SleepClientThread(
75 return writable_event; 77 return writable_event;
76} 78}
77 79
78HLERequestContext::HLERequestContext(SharedPtr<Kernel::ServerSession> server_session, 80HLERequestContext::HLERequestContext(std::shared_ptr<Kernel::ServerSession> server_session,
79 SharedPtr<Thread> thread) 81 std::shared_ptr<Thread> thread)
80 : server_session(std::move(server_session)), thread(std::move(thread)) { 82 : server_session(std::move(server_session)), thread(std::move(thread)) {
81 cmd_buf[0] = 0; 83 cmd_buf[0] = 0;
82} 84}
diff --git a/src/core/hle/kernel/hle_ipc.h b/src/core/hle/kernel/hle_ipc.h
index ccf5e56aa..dab37ba0d 100644
--- a/src/core/hle/kernel/hle_ipc.h
+++ b/src/core/hle/kernel/hle_ipc.h
@@ -5,6 +5,7 @@
5#pragma once 5#pragma once
6 6
7#include <array> 7#include <array>
8#include <functional>
8#include <memory> 9#include <memory>
9#include <optional> 10#include <optional>
10#include <string> 11#include <string>
@@ -60,20 +61,20 @@ public:
60 * associated ServerSession alive for the duration of the connection. 61 * associated ServerSession alive for the duration of the connection.
61 * @param server_session Owning pointer to the ServerSession associated with the connection. 62 * @param server_session Owning pointer to the ServerSession associated with the connection.
62 */ 63 */
63 void ClientConnected(SharedPtr<ServerSession> server_session); 64 void ClientConnected(std::shared_ptr<ServerSession> server_session);
64 65
65 /** 66 /**
66 * Signals that a client has just disconnected from this HLE handler and releases the 67 * Signals that a client has just disconnected from this HLE handler and releases the
67 * associated ServerSession. 68 * associated ServerSession.
68 * @param server_session ServerSession associated with the connection. 69 * @param server_session ServerSession associated with the connection.
69 */ 70 */
70 void ClientDisconnected(const SharedPtr<ServerSession>& server_session); 71 void ClientDisconnected(const std::shared_ptr<ServerSession>& server_session);
71 72
72protected: 73protected:
73 /// List of sessions that are connected to this handler. 74 /// List of sessions that are connected to this handler.
74 /// A ServerSession whose server endpoint is an HLE implementation is kept alive by this list 75 /// A ServerSession whose server endpoint is an HLE implementation is kept alive by this list
75 /// for the duration of the connection. 76 /// for the duration of the connection.
76 std::vector<SharedPtr<ServerSession>> connected_sessions; 77 std::vector<std::shared_ptr<ServerSession>> connected_sessions;
77}; 78};
78 79
79/** 80/**
@@ -97,7 +98,8 @@ protected:
97 */ 98 */
98class HLERequestContext { 99class HLERequestContext {
99public: 100public:
100 explicit HLERequestContext(SharedPtr<ServerSession> session, SharedPtr<Thread> thread); 101 explicit HLERequestContext(std::shared_ptr<ServerSession> session,
102 std::shared_ptr<Thread> thread);
101 ~HLERequestContext(); 103 ~HLERequestContext();
102 104
103 /// Returns a pointer to the IPC command buffer for this request. 105 /// Returns a pointer to the IPC command buffer for this request.
@@ -109,12 +111,12 @@ public:
109 * Returns the session through which this request was made. This can be used as a map key to 111 * Returns the session through which this request was made. This can be used as a map key to
110 * access per-client data on services. 112 * access per-client data on services.
111 */ 113 */
112 const SharedPtr<Kernel::ServerSession>& Session() const { 114 const std::shared_ptr<Kernel::ServerSession>& Session() const {
113 return server_session; 115 return server_session;
114 } 116 }
115 117
116 using WakeupCallback = std::function<void(SharedPtr<Thread> thread, HLERequestContext& context, 118 using WakeupCallback = std::function<void(
117 ThreadWakeupReason reason)>; 119 std::shared_ptr<Thread> thread, HLERequestContext& context, ThreadWakeupReason reason)>;
118 120
119 /** 121 /**
120 * Puts the specified guest thread to sleep until the returned event is signaled or until the 122 * Puts the specified guest thread to sleep until the returned event is signaled or until the
@@ -129,9 +131,9 @@ public:
129 * created. 131 * created.
130 * @returns Event that when signaled will resume the thread and call the callback function. 132 * @returns Event that when signaled will resume the thread and call the callback function.
131 */ 133 */
132 SharedPtr<WritableEvent> SleepClientThread(const std::string& reason, u64 timeout, 134 std::shared_ptr<WritableEvent> SleepClientThread(
133 WakeupCallback&& callback, 135 const std::string& reason, u64 timeout, WakeupCallback&& callback,
134 SharedPtr<WritableEvent> writable_event = nullptr); 136 std::shared_ptr<WritableEvent> writable_event = nullptr);
135 137
136 /// Populates this context with data from the requesting process/thread. 138 /// Populates this context with data from the requesting process/thread.
137 ResultCode PopulateFromIncomingCommandBuffer(const HandleTable& handle_table, 139 ResultCode PopulateFromIncomingCommandBuffer(const HandleTable& handle_table,
@@ -209,20 +211,20 @@ public:
209 std::size_t GetWriteBufferSize(int buffer_index = 0) const; 211 std::size_t GetWriteBufferSize(int buffer_index = 0) const;
210 212
211 template <typename T> 213 template <typename T>
212 SharedPtr<T> GetCopyObject(std::size_t index) { 214 std::shared_ptr<T> GetCopyObject(std::size_t index) {
213 return DynamicObjectCast<T>(copy_objects.at(index)); 215 return DynamicObjectCast<T>(copy_objects.at(index));
214 } 216 }
215 217
216 template <typename T> 218 template <typename T>
217 SharedPtr<T> GetMoveObject(std::size_t index) { 219 std::shared_ptr<T> GetMoveObject(std::size_t index) {
218 return DynamicObjectCast<T>(move_objects.at(index)); 220 return DynamicObjectCast<T>(move_objects.at(index));
219 } 221 }
220 222
221 void AddMoveObject(SharedPtr<Object> object) { 223 void AddMoveObject(std::shared_ptr<Object> object) {
222 move_objects.emplace_back(std::move(object)); 224 move_objects.emplace_back(std::move(object));
223 } 225 }
224 226
225 void AddCopyObject(SharedPtr<Object> object) { 227 void AddCopyObject(std::shared_ptr<Object> object) {
226 copy_objects.emplace_back(std::move(object)); 228 copy_objects.emplace_back(std::move(object));
227 } 229 }
228 230
@@ -266,11 +268,11 @@ private:
266 void ParseCommandBuffer(const HandleTable& handle_table, u32_le* src_cmdbuf, bool incoming); 268 void ParseCommandBuffer(const HandleTable& handle_table, u32_le* src_cmdbuf, bool incoming);
267 269
268 std::array<u32, IPC::COMMAND_BUFFER_LENGTH> cmd_buf; 270 std::array<u32, IPC::COMMAND_BUFFER_LENGTH> cmd_buf;
269 SharedPtr<Kernel::ServerSession> server_session; 271 std::shared_ptr<Kernel::ServerSession> server_session;
270 SharedPtr<Thread> thread; 272 std::shared_ptr<Thread> thread;
271 // TODO(yuriks): Check common usage of this and optimize size accordingly 273 // TODO(yuriks): Check common usage of this and optimize size accordingly
272 boost::container::small_vector<SharedPtr<Object>, 8> move_objects; 274 boost::container::small_vector<std::shared_ptr<Object>, 8> move_objects;
273 boost::container::small_vector<SharedPtr<Object>, 8> copy_objects; 275 boost::container::small_vector<std::shared_ptr<Object>, 8> copy_objects;
274 boost::container::small_vector<std::shared_ptr<SessionRequestHandler>, 8> domain_objects; 276 boost::container::small_vector<std::shared_ptr<SessionRequestHandler>, 8> domain_objects;
275 277
276 std::optional<IPC::CommandHeader> command_header; 278 std::optional<IPC::CommandHeader> command_header;
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp
index 9d3b309b3..63ad07950 100644
--- a/src/core/hle/kernel/kernel.cpp
+++ b/src/core/hle/kernel/kernel.cpp
@@ -40,7 +40,7 @@ static void ThreadWakeupCallback(u64 thread_handle, [[maybe_unused]] s64 cycles_
40 // Lock the global kernel mutex when we enter the kernel HLE. 40 // Lock the global kernel mutex when we enter the kernel HLE.
41 std::lock_guard lock{HLE::g_hle_lock}; 41 std::lock_guard lock{HLE::g_hle_lock};
42 42
43 SharedPtr<Thread> thread = 43 std::shared_ptr<Thread> thread =
44 system.Kernel().RetrieveThreadFromWakeupCallbackHandleTable(proper_handle); 44 system.Kernel().RetrieveThreadFromWakeupCallbackHandleTable(proper_handle);
45 if (thread == nullptr) { 45 if (thread == nullptr) {
46 LOG_CRITICAL(Kernel, "Callback fired for invalid thread {:08X}", proper_handle); 46 LOG_CRITICAL(Kernel, "Callback fired for invalid thread {:08X}", proper_handle);
@@ -53,7 +53,7 @@ static void ThreadWakeupCallback(u64 thread_handle, [[maybe_unused]] s64 cycles_
53 thread->GetStatus() == ThreadStatus::WaitHLEEvent) { 53 thread->GetStatus() == ThreadStatus::WaitHLEEvent) {
54 // Remove the thread from each of its waiting objects' waitlists 54 // Remove the thread from each of its waiting objects' waitlists
55 for (const auto& object : thread->GetWaitObjects()) { 55 for (const auto& object : thread->GetWaitObjects()) {
56 object->RemoveWaitingThread(thread.get()); 56 object->RemoveWaitingThread(thread);
57 } 57 }
58 thread->ClearWaitObjects(); 58 thread->ClearWaitObjects();
59 59
@@ -160,11 +160,11 @@ struct KernelCore::Impl {
160 std::atomic<u64> next_thread_id{1}; 160 std::atomic<u64> next_thread_id{1};
161 161
162 // Lists all processes that exist in the current session. 162 // Lists all processes that exist in the current session.
163 std::vector<SharedPtr<Process>> process_list; 163 std::vector<std::shared_ptr<Process>> process_list;
164 Process* current_process = nullptr; 164 Process* current_process = nullptr;
165 Kernel::GlobalScheduler global_scheduler; 165 Kernel::GlobalScheduler global_scheduler;
166 166
167 SharedPtr<ResourceLimit> system_resource_limit; 167 std::shared_ptr<ResourceLimit> system_resource_limit;
168 168
169 Core::Timing::EventType* thread_wakeup_event_type = nullptr; 169 Core::Timing::EventType* thread_wakeup_event_type = nullptr;
170 Core::Timing::EventType* preemption_event = nullptr; 170 Core::Timing::EventType* preemption_event = nullptr;
@@ -193,15 +193,16 @@ void KernelCore::Shutdown() {
193 impl->Shutdown(); 193 impl->Shutdown();
194} 194}
195 195
196SharedPtr<ResourceLimit> KernelCore::GetSystemResourceLimit() const { 196std::shared_ptr<ResourceLimit> KernelCore::GetSystemResourceLimit() const {
197 return impl->system_resource_limit; 197 return impl->system_resource_limit;
198} 198}
199 199
200SharedPtr<Thread> KernelCore::RetrieveThreadFromWakeupCallbackHandleTable(Handle handle) const { 200std::shared_ptr<Thread> KernelCore::RetrieveThreadFromWakeupCallbackHandleTable(
201 Handle handle) const {
201 return impl->thread_wakeup_callback_handle_table.Get<Thread>(handle); 202 return impl->thread_wakeup_callback_handle_table.Get<Thread>(handle);
202} 203}
203 204
204void KernelCore::AppendNewProcess(SharedPtr<Process> process) { 205void KernelCore::AppendNewProcess(std::shared_ptr<Process> process) {
205 impl->process_list.push_back(std::move(process)); 206 impl->process_list.push_back(std::move(process));
206} 207}
207 208
@@ -223,7 +224,7 @@ const Process* KernelCore::CurrentProcess() const {
223 return impl->current_process; 224 return impl->current_process;
224} 225}
225 226
226const std::vector<SharedPtr<Process>>& KernelCore::GetProcessList() const { 227const std::vector<std::shared_ptr<Process>>& KernelCore::GetProcessList() const {
227 return impl->process_list; 228 return impl->process_list;
228} 229}
229 230
@@ -235,7 +236,7 @@ const Kernel::GlobalScheduler& KernelCore::GlobalScheduler() const {
235 return impl->global_scheduler; 236 return impl->global_scheduler;
236} 237}
237 238
238void KernelCore::AddNamedPort(std::string name, SharedPtr<ClientPort> port) { 239void KernelCore::AddNamedPort(std::string name, std::shared_ptr<ClientPort> port) {
239 impl->named_ports.emplace(std::move(name), std::move(port)); 240 impl->named_ports.emplace(std::move(name), std::move(port));
240} 241}
241 242
diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h
index c4397fc77..c74b9078f 100644
--- a/src/core/hle/kernel/kernel.h
+++ b/src/core/hle/kernel/kernel.h
@@ -6,6 +6,7 @@
6 6
7#include <string> 7#include <string>
8#include <unordered_map> 8#include <unordered_map>
9#include <vector>
9#include "core/hle/kernel/object.h" 10#include "core/hle/kernel/object.h"
10 11
11namespace Core { 12namespace Core {
@@ -30,7 +31,7 @@ class Thread;
30/// Represents a single instance of the kernel. 31/// Represents a single instance of the kernel.
31class KernelCore { 32class KernelCore {
32private: 33private:
33 using NamedPortTable = std::unordered_map<std::string, SharedPtr<ClientPort>>; 34 using NamedPortTable = std::unordered_map<std::string, std::shared_ptr<ClientPort>>;
34 35
35public: 36public:
36 /// Constructs an instance of the kernel using the given System 37 /// Constructs an instance of the kernel using the given System
@@ -56,13 +57,13 @@ public:
56 void Shutdown(); 57 void Shutdown();
57 58
58 /// Retrieves a shared pointer to the system resource limit instance. 59 /// Retrieves a shared pointer to the system resource limit instance.
59 SharedPtr<ResourceLimit> GetSystemResourceLimit() const; 60 std::shared_ptr<ResourceLimit> GetSystemResourceLimit() const;
60 61
61 /// Retrieves a shared pointer to a Thread instance within the thread wakeup handle table. 62 /// Retrieves a shared pointer to a Thread instance within the thread wakeup handle table.
62 SharedPtr<Thread> RetrieveThreadFromWakeupCallbackHandleTable(Handle handle) const; 63 std::shared_ptr<Thread> RetrieveThreadFromWakeupCallbackHandleTable(Handle handle) const;
63 64
64 /// Adds the given shared pointer to an internal list of active processes. 65 /// Adds the given shared pointer to an internal list of active processes.
65 void AppendNewProcess(SharedPtr<Process> process); 66 void AppendNewProcess(std::shared_ptr<Process> process);
66 67
67 /// Makes the given process the new current process. 68 /// Makes the given process the new current process.
68 void MakeCurrentProcess(Process* process); 69 void MakeCurrentProcess(Process* process);
@@ -74,7 +75,7 @@ public:
74 const Process* CurrentProcess() const; 75 const Process* CurrentProcess() const;
75 76
76 /// Retrieves the list of processes. 77 /// Retrieves the list of processes.
77 const std::vector<SharedPtr<Process>>& GetProcessList() const; 78 const std::vector<std::shared_ptr<Process>>& GetProcessList() const;
78 79
79 /// Gets the sole instance of the global scheduler 80 /// Gets the sole instance of the global scheduler
80 Kernel::GlobalScheduler& GlobalScheduler(); 81 Kernel::GlobalScheduler& GlobalScheduler();
@@ -83,7 +84,7 @@ public:
83 const Kernel::GlobalScheduler& GlobalScheduler() const; 84 const Kernel::GlobalScheduler& GlobalScheduler() const;
84 85
85 /// Adds a port to the named port table 86 /// Adds a port to the named port table
86 void AddNamedPort(std::string name, SharedPtr<ClientPort> port); 87 void AddNamedPort(std::string name, std::shared_ptr<ClientPort> port);
87 88
88 /// Finds a port within the named port table with the given name. 89 /// Finds a port within the named port table with the given name.
89 NamedPortTable::iterator FindNamedPort(const std::string& name); 90 NamedPortTable::iterator FindNamedPort(const std::string& name);
diff --git a/src/core/hle/kernel/mutex.cpp b/src/core/hle/kernel/mutex.cpp
index 663d0f4b6..8493d0f78 100644
--- a/src/core/hle/kernel/mutex.cpp
+++ b/src/core/hle/kernel/mutex.cpp
@@ -22,10 +22,10 @@ namespace Kernel {
22 22
23/// Returns the number of threads that are waiting for a mutex, and the highest priority one among 23/// Returns the number of threads that are waiting for a mutex, and the highest priority one among
24/// those. 24/// those.
25static std::pair<SharedPtr<Thread>, u32> GetHighestPriorityMutexWaitingThread( 25static std::pair<std::shared_ptr<Thread>, u32> GetHighestPriorityMutexWaitingThread(
26 const SharedPtr<Thread>& current_thread, VAddr mutex_addr) { 26 const std::shared_ptr<Thread>& current_thread, VAddr mutex_addr) {
27 27
28 SharedPtr<Thread> highest_priority_thread; 28 std::shared_ptr<Thread> highest_priority_thread;
29 u32 num_waiters = 0; 29 u32 num_waiters = 0;
30 30
31 for (const auto& thread : current_thread->GetMutexWaitingThreads()) { 31 for (const auto& thread : current_thread->GetMutexWaitingThreads()) {
@@ -45,14 +45,14 @@ static std::pair<SharedPtr<Thread>, u32> GetHighestPriorityMutexWaitingThread(
45} 45}
46 46
47/// Update the mutex owner field of all threads waiting on the mutex to point to the new owner. 47/// Update the mutex owner field of all threads waiting on the mutex to point to the new owner.
48static void TransferMutexOwnership(VAddr mutex_addr, SharedPtr<Thread> current_thread, 48static void TransferMutexOwnership(VAddr mutex_addr, std::shared_ptr<Thread> current_thread,
49 SharedPtr<Thread> new_owner) { 49 std::shared_ptr<Thread> new_owner) {
50 const auto threads = current_thread->GetMutexWaitingThreads(); 50 const auto threads = current_thread->GetMutexWaitingThreads();
51 for (const auto& thread : threads) { 51 for (const auto& thread : threads) {
52 if (thread->GetMutexWaitAddress() != mutex_addr) 52 if (thread->GetMutexWaitAddress() != mutex_addr)
53 continue; 53 continue;
54 54
55 ASSERT(thread->GetLockOwner() == current_thread); 55 ASSERT(thread->GetLockOwner() == current_thread.get());
56 current_thread->RemoveMutexWaiter(thread); 56 current_thread->RemoveMutexWaiter(thread);
57 if (new_owner != thread) 57 if (new_owner != thread)
58 new_owner->AddMutexWaiter(thread); 58 new_owner->AddMutexWaiter(thread);
@@ -70,9 +70,10 @@ ResultCode Mutex::TryAcquire(VAddr address, Handle holding_thread_handle,
70 } 70 }
71 71
72 const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); 72 const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable();
73 Thread* const current_thread = system.CurrentScheduler().GetCurrentThread(); 73 std::shared_ptr<Thread> current_thread =
74 SharedPtr<Thread> holding_thread = handle_table.Get<Thread>(holding_thread_handle); 74 SharedFrom(system.CurrentScheduler().GetCurrentThread());
75 SharedPtr<Thread> requesting_thread = handle_table.Get<Thread>(requesting_thread_handle); 75 std::shared_ptr<Thread> holding_thread = handle_table.Get<Thread>(holding_thread_handle);
76 std::shared_ptr<Thread> requesting_thread = handle_table.Get<Thread>(requesting_thread_handle);
76 77
77 // TODO(Subv): It is currently unknown if it is possible to lock a mutex in behalf of another 78 // TODO(Subv): It is currently unknown if it is possible to lock a mutex in behalf of another
78 // thread. 79 // thread.
@@ -110,7 +111,8 @@ ResultCode Mutex::Release(VAddr address) {
110 return ERR_INVALID_ADDRESS; 111 return ERR_INVALID_ADDRESS;
111 } 112 }
112 113
113 auto* const current_thread = system.CurrentScheduler().GetCurrentThread(); 114 std::shared_ptr<Thread> current_thread =
115 SharedFrom(system.CurrentScheduler().GetCurrentThread());
114 auto [thread, num_waiters] = GetHighestPriorityMutexWaitingThread(current_thread, address); 116 auto [thread, num_waiters] = GetHighestPriorityMutexWaitingThread(current_thread, address);
115 117
116 // There are no more threads waiting for the mutex, release it completely. 118 // There are no more threads waiting for the mutex, release it completely.
diff --git a/src/core/hle/kernel/object.h b/src/core/hle/kernel/object.h
index a6faeb83b..bbbb4e7cc 100644
--- a/src/core/hle/kernel/object.h
+++ b/src/core/hle/kernel/object.h
@@ -5,10 +5,9 @@
5#pragma once 5#pragma once
6 6
7#include <atomic> 7#include <atomic>
8#include <memory>
8#include <string> 9#include <string>
9 10
10#include <boost/smart_ptr/intrusive_ptr.hpp>
11
12#include "common/common_types.h" 11#include "common/common_types.h"
13 12
14namespace Kernel { 13namespace Kernel {
@@ -32,7 +31,7 @@ enum class HandleType : u32 {
32 ServerSession, 31 ServerSession,
33}; 32};
34 33
35class Object : NonCopyable { 34class Object : NonCopyable, public std::enable_shared_from_this<Object> {
36public: 35public:
37 explicit Object(KernelCore& kernel); 36 explicit Object(KernelCore& kernel);
38 virtual ~Object(); 37 virtual ~Object();
@@ -61,35 +60,24 @@ protected:
61 KernelCore& kernel; 60 KernelCore& kernel;
62 61
63private: 62private:
64 friend void intrusive_ptr_add_ref(Object*);
65 friend void intrusive_ptr_release(Object*);
66
67 std::atomic<u32> ref_count{0};
68 std::atomic<u32> object_id{0}; 63 std::atomic<u32> object_id{0};
69}; 64};
70 65
71// Special functions used by boost::instrusive_ptr to do automatic ref-counting
72inline void intrusive_ptr_add_ref(Object* object) {
73 object->ref_count.fetch_add(1, std::memory_order_relaxed);
74}
75
76inline void intrusive_ptr_release(Object* object) {
77 if (object->ref_count.fetch_sub(1, std::memory_order_acq_rel) == 1) {
78 delete object;
79 }
80}
81
82template <typename T> 66template <typename T>
83using SharedPtr = boost::intrusive_ptr<T>; 67std::shared_ptr<T> SharedFrom(T* raw) {
68 if (raw == nullptr)
69 return nullptr;
70 return std::static_pointer_cast<T>(raw->shared_from_this());
71}
84 72
85/** 73/**
86 * Attempts to downcast the given Object pointer to a pointer to T. 74 * Attempts to downcast the given Object pointer to a pointer to T.
87 * @return Derived pointer to the object, or `nullptr` if `object` isn't of type T. 75 * @return Derived pointer to the object, or `nullptr` if `object` isn't of type T.
88 */ 76 */
89template <typename T> 77template <typename T>
90inline SharedPtr<T> DynamicObjectCast(SharedPtr<Object> object) { 78inline std::shared_ptr<T> DynamicObjectCast(std::shared_ptr<Object> object) {
91 if (object != nullptr && object->GetHandleType() == T::HANDLE_TYPE) { 79 if (object != nullptr && object->GetHandleType() == T::HANDLE_TYPE) {
92 return boost::static_pointer_cast<T>(object); 80 return std::static_pointer_cast<T>(object);
93 } 81 }
94 return nullptr; 82 return nullptr;
95} 83}
diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp
index a4e0dd385..12ea4ebe3 100644
--- a/src/core/hle/kernel/process.cpp
+++ b/src/core/hle/kernel/process.cpp
@@ -38,7 +38,7 @@ void SetupMainThread(Process& owner_process, KernelCore& kernel, u32 priority) {
38 auto thread_res = Thread::Create(kernel, "main", entry_point, priority, 0, 38 auto thread_res = Thread::Create(kernel, "main", entry_point, priority, 0,
39 owner_process.GetIdealCore(), stack_top, owner_process); 39 owner_process.GetIdealCore(), stack_top, owner_process);
40 40
41 SharedPtr<Thread> thread = std::move(thread_res).Unwrap(); 41 std::shared_ptr<Thread> thread = std::move(thread_res).Unwrap();
42 42
43 // Register 1 must be a handle to the main thread 43 // Register 1 must be a handle to the main thread
44 const Handle thread_handle = owner_process.GetHandleTable().Create(thread).Unwrap(); 44 const Handle thread_handle = owner_process.GetHandleTable().Create(thread).Unwrap();
@@ -100,10 +100,10 @@ private:
100 std::bitset<num_slot_entries> is_slot_used; 100 std::bitset<num_slot_entries> is_slot_used;
101}; 101};
102 102
103SharedPtr<Process> Process::Create(Core::System& system, std::string name, ProcessType type) { 103std::shared_ptr<Process> Process::Create(Core::System& system, std::string name, ProcessType type) {
104 auto& kernel = system.Kernel(); 104 auto& kernel = system.Kernel();
105 105
106 SharedPtr<Process> process(new Process(system)); 106 std::shared_ptr<Process> process = std::make_shared<Process>(system);
107 process->name = std::move(name); 107 process->name = std::move(name);
108 process->resource_limit = kernel.GetSystemResourceLimit(); 108 process->resource_limit = kernel.GetSystemResourceLimit();
109 process->status = ProcessStatus::Created; 109 process->status = ProcessStatus::Created;
@@ -121,7 +121,7 @@ SharedPtr<Process> Process::Create(Core::System& system, std::string name, Proce
121 return process; 121 return process;
122} 122}
123 123
124SharedPtr<ResourceLimit> Process::GetResourceLimit() const { 124std::shared_ptr<ResourceLimit> Process::GetResourceLimit() const {
125 return resource_limit; 125 return resource_limit;
126} 126}
127 127
@@ -142,12 +142,12 @@ u64 Process::GetTotalPhysicalMemoryUsedWithoutSystemResource() const {
142 return GetTotalPhysicalMemoryUsed() - GetSystemResourceUsage(); 142 return GetTotalPhysicalMemoryUsed() - GetSystemResourceUsage();
143} 143}
144 144
145void Process::InsertConditionVariableThread(SharedPtr<Thread> thread) { 145void Process::InsertConditionVariableThread(std::shared_ptr<Thread> thread) {
146 VAddr cond_var_addr = thread->GetCondVarWaitAddress(); 146 VAddr cond_var_addr = thread->GetCondVarWaitAddress();
147 std::list<SharedPtr<Thread>>& thread_list = cond_var_threads[cond_var_addr]; 147 std::list<std::shared_ptr<Thread>>& thread_list = cond_var_threads[cond_var_addr];
148 auto it = thread_list.begin(); 148 auto it = thread_list.begin();
149 while (it != thread_list.end()) { 149 while (it != thread_list.end()) {
150 const SharedPtr<Thread> current_thread = *it; 150 const std::shared_ptr<Thread> current_thread = *it;
151 if (current_thread->GetPriority() > thread->GetPriority()) { 151 if (current_thread->GetPriority() > thread->GetPriority()) {
152 thread_list.insert(it, thread); 152 thread_list.insert(it, thread);
153 return; 153 return;
@@ -157,12 +157,12 @@ void Process::InsertConditionVariableThread(SharedPtr<Thread> thread) {
157 thread_list.push_back(thread); 157 thread_list.push_back(thread);
158} 158}
159 159
160void Process::RemoveConditionVariableThread(SharedPtr<Thread> thread) { 160void Process::RemoveConditionVariableThread(std::shared_ptr<Thread> thread) {
161 VAddr cond_var_addr = thread->GetCondVarWaitAddress(); 161 VAddr cond_var_addr = thread->GetCondVarWaitAddress();
162 std::list<SharedPtr<Thread>>& thread_list = cond_var_threads[cond_var_addr]; 162 std::list<std::shared_ptr<Thread>>& thread_list = cond_var_threads[cond_var_addr];
163 auto it = thread_list.begin(); 163 auto it = thread_list.begin();
164 while (it != thread_list.end()) { 164 while (it != thread_list.end()) {
165 const SharedPtr<Thread> current_thread = *it; 165 const std::shared_ptr<Thread> current_thread = *it;
166 if (current_thread.get() == thread.get()) { 166 if (current_thread.get() == thread.get()) {
167 thread_list.erase(it); 167 thread_list.erase(it);
168 return; 168 return;
@@ -172,12 +172,13 @@ void Process::RemoveConditionVariableThread(SharedPtr<Thread> thread) {
172 UNREACHABLE(); 172 UNREACHABLE();
173} 173}
174 174
175std::vector<SharedPtr<Thread>> Process::GetConditionVariableThreads(const VAddr cond_var_addr) { 175std::vector<std::shared_ptr<Thread>> Process::GetConditionVariableThreads(
176 std::vector<SharedPtr<Thread>> result{}; 176 const VAddr cond_var_addr) {
177 std::list<SharedPtr<Thread>>& thread_list = cond_var_threads[cond_var_addr]; 177 std::vector<std::shared_ptr<Thread>> result{};
178 std::list<std::shared_ptr<Thread>>& thread_list = cond_var_threads[cond_var_addr];
178 auto it = thread_list.begin(); 179 auto it = thread_list.begin();
179 while (it != thread_list.end()) { 180 while (it != thread_list.end()) {
180 SharedPtr<Thread> current_thread = *it; 181 std::shared_ptr<Thread> current_thread = *it;
181 result.push_back(current_thread); 182 result.push_back(current_thread);
182 ++it; 183 ++it;
183 } 184 }
@@ -239,12 +240,12 @@ void Process::Run(s32 main_thread_priority, u64 stack_size) {
239void Process::PrepareForTermination() { 240void Process::PrepareForTermination() {
240 ChangeStatus(ProcessStatus::Exiting); 241 ChangeStatus(ProcessStatus::Exiting);
241 242
242 const auto stop_threads = [this](const std::vector<SharedPtr<Thread>>& thread_list) { 243 const auto stop_threads = [this](const std::vector<std::shared_ptr<Thread>>& thread_list) {
243 for (auto& thread : thread_list) { 244 for (auto& thread : thread_list) {
244 if (thread->GetOwnerProcess() != this) 245 if (thread->GetOwnerProcess() != this)
245 continue; 246 continue;
246 247
247 if (thread == system.CurrentScheduler().GetCurrentThread()) 248 if (thread.get() == system.CurrentScheduler().GetCurrentThread())
248 continue; 249 continue;
249 250
250 // TODO(Subv): When are the other running/ready threads terminated? 251 // TODO(Subv): When are the other running/ready threads terminated?
diff --git a/src/core/hle/kernel/process.h b/src/core/hle/kernel/process.h
index e2eda26b9..3483fa19d 100644
--- a/src/core/hle/kernel/process.h
+++ b/src/core/hle/kernel/process.h
@@ -62,6 +62,9 @@ enum class ProcessStatus {
62 62
63class Process final : public WaitObject { 63class Process final : public WaitObject {
64public: 64public:
65 explicit Process(Core::System& system);
66 ~Process() override;
67
65 enum : u64 { 68 enum : u64 {
66 /// Lowest allowed process ID for a kernel initial process. 69 /// Lowest allowed process ID for a kernel initial process.
67 InitialKIPIDMin = 1, 70 InitialKIPIDMin = 1,
@@ -82,7 +85,8 @@ public:
82 85
83 static constexpr std::size_t RANDOM_ENTROPY_SIZE = 4; 86 static constexpr std::size_t RANDOM_ENTROPY_SIZE = 4;
84 87
85 static SharedPtr<Process> Create(Core::System& system, std::string name, ProcessType type); 88 static std::shared_ptr<Process> Create(Core::System& system, std::string name,
89 ProcessType type);
86 90
87 std::string GetTypeName() const override { 91 std::string GetTypeName() const override {
88 return "Process"; 92 return "Process";
@@ -157,7 +161,7 @@ public:
157 } 161 }
158 162
159 /// Gets the resource limit descriptor for this process 163 /// Gets the resource limit descriptor for this process
160 SharedPtr<ResourceLimit> GetResourceLimit() const; 164 std::shared_ptr<ResourceLimit> GetResourceLimit() const;
161 165
162 /// Gets the ideal CPU core ID for this process 166 /// Gets the ideal CPU core ID for this process
163 u8 GetIdealCore() const { 167 u8 GetIdealCore() const {
@@ -234,13 +238,13 @@ public:
234 } 238 }
235 239
236 /// Insert a thread into the condition variable wait container 240 /// Insert a thread into the condition variable wait container
237 void InsertConditionVariableThread(SharedPtr<Thread> thread); 241 void InsertConditionVariableThread(std::shared_ptr<Thread> thread);
238 242
239 /// Remove a thread from the condition variable wait container 243 /// Remove a thread from the condition variable wait container
240 void RemoveConditionVariableThread(SharedPtr<Thread> thread); 244 void RemoveConditionVariableThread(std::shared_ptr<Thread> thread);
241 245
242 /// Obtain all condition variable threads waiting for some address 246 /// Obtain all condition variable threads waiting for some address
243 std::vector<SharedPtr<Thread>> GetConditionVariableThreads(VAddr cond_var_addr); 247 std::vector<std::shared_ptr<Thread>> GetConditionVariableThreads(VAddr cond_var_addr);
244 248
245 /// Registers a thread as being created under this process, 249 /// Registers a thread as being created under this process,
246 /// adding it to this process' thread list. 250 /// adding it to this process' thread list.
@@ -297,9 +301,6 @@ public:
297 void FreeTLSRegion(VAddr tls_address); 301 void FreeTLSRegion(VAddr tls_address);
298 302
299private: 303private:
300 explicit Process(Core::System& system);
301 ~Process() override;
302
303 /// Checks if the specified thread should wait until this process is available. 304 /// Checks if the specified thread should wait until this process is available.
304 bool ShouldWait(const Thread* thread) const override; 305 bool ShouldWait(const Thread* thread) const override;
305 306
@@ -338,7 +339,7 @@ private:
338 u32 system_resource_size = 0; 339 u32 system_resource_size = 0;
339 340
340 /// Resource limit descriptor for this process 341 /// Resource limit descriptor for this process
341 SharedPtr<ResourceLimit> resource_limit; 342 std::shared_ptr<ResourceLimit> resource_limit;
342 343
343 /// The ideal CPU core for this process, threads are scheduled on this core by default. 344 /// The ideal CPU core for this process, threads are scheduled on this core by default.
344 u8 ideal_core = 0; 345 u8 ideal_core = 0;
@@ -386,7 +387,7 @@ private:
386 std::list<const Thread*> thread_list; 387 std::list<const Thread*> thread_list;
387 388
388 /// List of threads waiting for a condition variable 389 /// List of threads waiting for a condition variable
389 std::unordered_map<VAddr, std::list<SharedPtr<Thread>>> cond_var_threads; 390 std::unordered_map<VAddr, std::list<std::shared_ptr<Thread>>> cond_var_threads;
390 391
391 /// System context 392 /// System context
392 Core::System& system; 393 Core::System& system;
diff --git a/src/core/hle/kernel/resource_limit.cpp b/src/core/hle/kernel/resource_limit.cpp
index 173f69915..b53423462 100644
--- a/src/core/hle/kernel/resource_limit.cpp
+++ b/src/core/hle/kernel/resource_limit.cpp
@@ -16,8 +16,8 @@ constexpr std::size_t ResourceTypeToIndex(ResourceType type) {
16ResourceLimit::ResourceLimit(KernelCore& kernel) : Object{kernel} {} 16ResourceLimit::ResourceLimit(KernelCore& kernel) : Object{kernel} {}
17ResourceLimit::~ResourceLimit() = default; 17ResourceLimit::~ResourceLimit() = default;
18 18
19SharedPtr<ResourceLimit> ResourceLimit::Create(KernelCore& kernel) { 19std::shared_ptr<ResourceLimit> ResourceLimit::Create(KernelCore& kernel) {
20 return new ResourceLimit(kernel); 20 return std::make_shared<ResourceLimit>(kernel);
21} 21}
22 22
23s64 ResourceLimit::GetCurrentResourceValue(ResourceType resource) const { 23s64 ResourceLimit::GetCurrentResourceValue(ResourceType resource) const {
diff --git a/src/core/hle/kernel/resource_limit.h b/src/core/hle/kernel/resource_limit.h
index 2613a6bb5..b5534620d 100644
--- a/src/core/hle/kernel/resource_limit.h
+++ b/src/core/hle/kernel/resource_limit.h
@@ -31,8 +31,11 @@ constexpr bool IsValidResourceType(ResourceType type) {
31 31
32class ResourceLimit final : public Object { 32class ResourceLimit final : public Object {
33public: 33public:
34 explicit ResourceLimit(KernelCore& kernel);
35 ~ResourceLimit() override;
36
34 /// Creates a resource limit object. 37 /// Creates a resource limit object.
35 static SharedPtr<ResourceLimit> Create(KernelCore& kernel); 38 static std::shared_ptr<ResourceLimit> Create(KernelCore& kernel);
36 39
37 std::string GetTypeName() const override { 40 std::string GetTypeName() const override {
38 return "ResourceLimit"; 41 return "ResourceLimit";
@@ -76,9 +79,6 @@ public:
76 ResultCode SetLimitValue(ResourceType resource, s64 value); 79 ResultCode SetLimitValue(ResourceType resource, s64 value);
77 80
78private: 81private:
79 explicit ResourceLimit(KernelCore& kernel);
80 ~ResourceLimit() override;
81
82 // TODO(Subv): Increment resource limit current values in their respective Kernel::T::Create 82 // TODO(Subv): Increment resource limit current values in their respective Kernel::T::Create
83 // functions 83 // functions
84 // 84 //
diff --git a/src/core/hle/kernel/scheduler.cpp b/src/core/hle/kernel/scheduler.cpp
index 16e95381b..3f5192087 100644
--- a/src/core/hle/kernel/scheduler.cpp
+++ b/src/core/hle/kernel/scheduler.cpp
@@ -26,11 +26,11 @@ GlobalScheduler::GlobalScheduler(Core::System& system) : system{system} {}
26 26
27GlobalScheduler::~GlobalScheduler() = default; 27GlobalScheduler::~GlobalScheduler() = default;
28 28
29void GlobalScheduler::AddThread(SharedPtr<Thread> thread) { 29void GlobalScheduler::AddThread(std::shared_ptr<Thread> thread) {
30 thread_list.push_back(std::move(thread)); 30 thread_list.push_back(std::move(thread));
31} 31}
32 32
33void GlobalScheduler::RemoveThread(const Thread* thread) { 33void GlobalScheduler::RemoveThread(std::shared_ptr<Thread> thread) {
34 thread_list.erase(std::remove(thread_list.begin(), thread_list.end(), thread), 34 thread_list.erase(std::remove(thread_list.begin(), thread_list.end(), thread),
35 thread_list.end()); 35 thread_list.end());
36} 36}
@@ -42,11 +42,11 @@ void GlobalScheduler::UnloadThread(std::size_t core) {
42 42
43void GlobalScheduler::SelectThread(std::size_t core) { 43void GlobalScheduler::SelectThread(std::size_t core) {
44 const auto update_thread = [](Thread* thread, Scheduler& sched) { 44 const auto update_thread = [](Thread* thread, Scheduler& sched) {
45 if (thread != sched.selected_thread) { 45 if (thread != sched.selected_thread.get()) {
46 if (thread == nullptr) { 46 if (thread == nullptr) {
47 ++sched.idle_selection_count; 47 ++sched.idle_selection_count;
48 } 48 }
49 sched.selected_thread = thread; 49 sched.selected_thread = SharedFrom(thread);
50 } 50 }
51 sched.is_context_switch_pending = sched.selected_thread != sched.current_thread; 51 sched.is_context_switch_pending = sched.selected_thread != sched.current_thread;
52 std::atomic_thread_fence(std::memory_order_seq_cst); 52 std::atomic_thread_fence(std::memory_order_seq_cst);
@@ -446,7 +446,7 @@ void Scheduler::SwitchContext() {
446 446
447 // Cancel any outstanding wakeup events for this thread 447 // Cancel any outstanding wakeup events for this thread
448 new_thread->CancelWakeupTimer(); 448 new_thread->CancelWakeupTimer();
449 current_thread = new_thread; 449 current_thread = SharedFrom(new_thread);
450 new_thread->SetStatus(ThreadStatus::Running); 450 new_thread->SetStatus(ThreadStatus::Running);
451 new_thread->SetIsRunning(true); 451 new_thread->SetIsRunning(true);
452 452
diff --git a/src/core/hle/kernel/scheduler.h b/src/core/hle/kernel/scheduler.h
index 311849dfb..3c5c21346 100644
--- a/src/core/hle/kernel/scheduler.h
+++ b/src/core/hle/kernel/scheduler.h
@@ -28,13 +28,13 @@ public:
28 ~GlobalScheduler(); 28 ~GlobalScheduler();
29 29
30 /// Adds a new thread to the scheduler 30 /// Adds a new thread to the scheduler
31 void AddThread(SharedPtr<Thread> thread); 31 void AddThread(std::shared_ptr<Thread> thread);
32 32
33 /// Removes a thread from the scheduler 33 /// Removes a thread from the scheduler
34 void RemoveThread(const Thread* thread); 34 void RemoveThread(std::shared_ptr<Thread> thread);
35 35
36 /// Returns a list of all threads managed by the scheduler 36 /// Returns a list of all threads managed by the scheduler
37 const std::vector<SharedPtr<Thread>>& GetThreadList() const { 37 const std::vector<std::shared_ptr<Thread>>& GetThreadList() const {
38 return thread_list; 38 return thread_list;
39 } 39 }
40 40
@@ -157,7 +157,7 @@ private:
157 std::array<u32, NUM_CPU_CORES> preemption_priorities = {59, 59, 59, 62}; 157 std::array<u32, NUM_CPU_CORES> preemption_priorities = {59, 59, 59, 62};
158 158
159 /// Lists all thread ids that aren't deleted/etc. 159 /// Lists all thread ids that aren't deleted/etc.
160 std::vector<SharedPtr<Thread>> thread_list; 160 std::vector<std::shared_ptr<Thread>> thread_list;
161 Core::System& system; 161 Core::System& system;
162}; 162};
163 163
@@ -213,8 +213,8 @@ private:
213 */ 213 */
214 void UpdateLastContextSwitchTime(Thread* thread, Process* process); 214 void UpdateLastContextSwitchTime(Thread* thread, Process* process);
215 215
216 SharedPtr<Thread> current_thread = nullptr; 216 std::shared_ptr<Thread> current_thread = nullptr;
217 SharedPtr<Thread> selected_thread = nullptr; 217 std::shared_ptr<Thread> selected_thread = nullptr;
218 218
219 Core::System& system; 219 Core::System& system;
220 Core::ARM_Interface& cpu_core; 220 Core::ARM_Interface& cpu_core;
diff --git a/src/core/hle/kernel/server_port.cpp b/src/core/hle/kernel/server_port.cpp
index 02e7c60e6..a4ccfa35e 100644
--- a/src/core/hle/kernel/server_port.cpp
+++ b/src/core/hle/kernel/server_port.cpp
@@ -16,7 +16,7 @@ namespace Kernel {
16ServerPort::ServerPort(KernelCore& kernel) : WaitObject{kernel} {} 16ServerPort::ServerPort(KernelCore& kernel) : WaitObject{kernel} {}
17ServerPort::~ServerPort() = default; 17ServerPort::~ServerPort() = default;
18 18
19ResultVal<SharedPtr<ServerSession>> ServerPort::Accept() { 19ResultVal<std::shared_ptr<ServerSession>> ServerPort::Accept() {
20 if (pending_sessions.empty()) { 20 if (pending_sessions.empty()) {
21 return ERR_NOT_FOUND; 21 return ERR_NOT_FOUND;
22 } 22 }
@@ -26,7 +26,7 @@ ResultVal<SharedPtr<ServerSession>> ServerPort::Accept() {
26 return MakeResult(std::move(session)); 26 return MakeResult(std::move(session));
27} 27}
28 28
29void ServerPort::AppendPendingSession(SharedPtr<ServerSession> pending_session) { 29void ServerPort::AppendPendingSession(std::shared_ptr<ServerSession> pending_session) {
30 pending_sessions.push_back(std::move(pending_session)); 30 pending_sessions.push_back(std::move(pending_session));
31} 31}
32 32
@@ -41,8 +41,8 @@ void ServerPort::Acquire(Thread* thread) {
41 41
42ServerPort::PortPair ServerPort::CreatePortPair(KernelCore& kernel, u32 max_sessions, 42ServerPort::PortPair ServerPort::CreatePortPair(KernelCore& kernel, u32 max_sessions,
43 std::string name) { 43 std::string name) {
44 SharedPtr<ServerPort> server_port(new ServerPort(kernel)); 44 std::shared_ptr<ServerPort> server_port = std::make_shared<ServerPort>(kernel);
45 SharedPtr<ClientPort> client_port(new ClientPort(kernel)); 45 std::shared_ptr<ClientPort> client_port = std::make_shared<ClientPort>(kernel);
46 46
47 server_port->name = name + "_Server"; 47 server_port->name = name + "_Server";
48 client_port->name = name + "_Client"; 48 client_port->name = name + "_Client";
diff --git a/src/core/hle/kernel/server_port.h b/src/core/hle/kernel/server_port.h
index dc88a1ebd..8be8a75ea 100644
--- a/src/core/hle/kernel/server_port.h
+++ b/src/core/hle/kernel/server_port.h
@@ -22,8 +22,11 @@ class SessionRequestHandler;
22 22
23class ServerPort final : public WaitObject { 23class ServerPort final : public WaitObject {
24public: 24public:
25 explicit ServerPort(KernelCore& kernel);
26 ~ServerPort() override;
27
25 using HLEHandler = std::shared_ptr<SessionRequestHandler>; 28 using HLEHandler = std::shared_ptr<SessionRequestHandler>;
26 using PortPair = std::pair<SharedPtr<ServerPort>, SharedPtr<ClientPort>>; 29 using PortPair = std::pair<std::shared_ptr<ServerPort>, std::shared_ptr<ClientPort>>;
27 30
28 /** 31 /**
29 * Creates a pair of ServerPort and an associated ClientPort. 32 * Creates a pair of ServerPort and an associated ClientPort.
@@ -52,7 +55,7 @@ public:
52 * Accepts a pending incoming connection on this port. If there are no pending sessions, will 55 * Accepts a pending incoming connection on this port. If there are no pending sessions, will
53 * return ERR_NO_PENDING_SESSIONS. 56 * return ERR_NO_PENDING_SESSIONS.
54 */ 57 */
55 ResultVal<SharedPtr<ServerSession>> Accept(); 58 ResultVal<std::shared_ptr<ServerSession>> Accept();
56 59
57 /// Whether or not this server port has an HLE handler available. 60 /// Whether or not this server port has an HLE handler available.
58 bool HasHLEHandler() const { 61 bool HasHLEHandler() const {
@@ -74,17 +77,14 @@ public:
74 77
75 /// Appends a ServerSession to the collection of ServerSessions 78 /// Appends a ServerSession to the collection of ServerSessions
76 /// waiting to be accepted by this port. 79 /// waiting to be accepted by this port.
77 void AppendPendingSession(SharedPtr<ServerSession> pending_session); 80 void AppendPendingSession(std::shared_ptr<ServerSession> pending_session);
78 81
79 bool ShouldWait(const Thread* thread) const override; 82 bool ShouldWait(const Thread* thread) const override;
80 void Acquire(Thread* thread) override; 83 void Acquire(Thread* thread) override;
81 84
82private: 85private:
83 explicit ServerPort(KernelCore& kernel);
84 ~ServerPort() override;
85
86 /// ServerSessions waiting to be accepted by the port 86 /// ServerSessions waiting to be accepted by the port
87 std::vector<SharedPtr<ServerSession>> pending_sessions; 87 std::vector<std::shared_ptr<ServerSession>> pending_sessions;
88 88
89 /// This session's HLE request handler template (optional) 89 /// This session's HLE request handler template (optional)
90 /// ServerSessions created from this port inherit a reference to this handler. 90 /// ServerSessions created from this port inherit a reference to this handler.
diff --git a/src/core/hle/kernel/server_session.cpp b/src/core/hle/kernel/server_session.cpp
index 30b2bfb5a..2994fa0ac 100644
--- a/src/core/hle/kernel/server_session.cpp
+++ b/src/core/hle/kernel/server_session.cpp
@@ -35,8 +35,9 @@ ServerSession::~ServerSession() {
35 parent->server = nullptr; 35 parent->server = nullptr;
36} 36}
37 37
38ResultVal<SharedPtr<ServerSession>> ServerSession::Create(KernelCore& kernel, std::string name) { 38ResultVal<std::shared_ptr<ServerSession>> ServerSession::Create(KernelCore& kernel,
39 SharedPtr<ServerSession> server_session(new ServerSession(kernel)); 39 std::string name) {
40 std::shared_ptr<ServerSession> server_session = std::make_shared<ServerSession>(kernel);
40 41
41 server_session->name = std::move(name); 42 server_session->name = std::move(name);
42 server_session->parent = nullptr; 43 server_session->parent = nullptr;
@@ -69,7 +70,7 @@ void ServerSession::ClientDisconnected() {
69 if (handler) { 70 if (handler) {
70 // Note that after this returns, this server session's hle_handler is 71 // Note that after this returns, this server session's hle_handler is
71 // invalidated (set to null). 72 // invalidated (set to null).
72 handler->ClientDisconnected(this); 73 handler->ClientDisconnected(SharedFrom(this));
73 } 74 }
74 75
75 // Clean up the list of client threads with pending requests, they are unneeded now that the 76 // Clean up the list of client threads with pending requests, they are unneeded now that the
@@ -126,11 +127,11 @@ ResultCode ServerSession::HandleDomainSyncRequest(Kernel::HLERequestContext& con
126 return RESULT_SUCCESS; 127 return RESULT_SUCCESS;
127} 128}
128 129
129ResultCode ServerSession::HandleSyncRequest(SharedPtr<Thread> thread) { 130ResultCode ServerSession::HandleSyncRequest(std::shared_ptr<Thread> thread) {
130 // The ServerSession received a sync request, this means that there's new data available 131 // The ServerSession received a sync request, this means that there's new data available
131 // from its ClientSession, so wake up any threads that may be waiting on a svcReplyAndReceive or 132 // from its ClientSession, so wake up any threads that may be waiting on a svcReplyAndReceive or
132 // similar. 133 // similar.
133 Kernel::HLERequestContext context(this, thread); 134 Kernel::HLERequestContext context(SharedFrom(this), thread);
134 u32* cmd_buf = (u32*)Memory::GetPointer(thread->GetTLSAddress()); 135 u32* cmd_buf = (u32*)Memory::GetPointer(thread->GetTLSAddress());
135 context.PopulateFromIncomingCommandBuffer(kernel.CurrentProcess()->GetHandleTable(), cmd_buf); 136 context.PopulateFromIncomingCommandBuffer(kernel.CurrentProcess()->GetHandleTable(), cmd_buf);
136 137
@@ -186,9 +187,9 @@ ResultCode ServerSession::HandleSyncRequest(SharedPtr<Thread> thread) {
186 187
187ServerSession::SessionPair ServerSession::CreateSessionPair(KernelCore& kernel, 188ServerSession::SessionPair ServerSession::CreateSessionPair(KernelCore& kernel,
188 const std::string& name, 189 const std::string& name,
189 SharedPtr<ClientPort> port) { 190 std::shared_ptr<ClientPort> port) {
190 auto server_session = ServerSession::Create(kernel, name + "_Server").Unwrap(); 191 auto server_session = ServerSession::Create(kernel, name + "_Server").Unwrap();
191 SharedPtr<ClientSession> client_session(new ClientSession(kernel)); 192 std::shared_ptr<ClientSession> client_session = std::make_shared<ClientSession>(kernel);
192 client_session->name = name + "_Client"; 193 client_session->name = name + "_Client";
193 194
194 std::shared_ptr<Session> parent(new Session); 195 std::shared_ptr<Session> parent(new Session);
diff --git a/src/core/hle/kernel/server_session.h b/src/core/hle/kernel/server_session.h
index 738df30f8..8a65647b6 100644
--- a/src/core/hle/kernel/server_session.h
+++ b/src/core/hle/kernel/server_session.h
@@ -38,6 +38,9 @@ class Thread;
38 */ 38 */
39class ServerSession final : public WaitObject { 39class ServerSession final : public WaitObject {
40public: 40public:
41 explicit ServerSession(KernelCore& kernel);
42 ~ServerSession() override;
43
41 std::string GetTypeName() const override { 44 std::string GetTypeName() const override {
42 return "ServerSession"; 45 return "ServerSession";
43 } 46 }
@@ -59,7 +62,7 @@ public:
59 return parent.get(); 62 return parent.get();
60 } 63 }
61 64
62 using SessionPair = std::pair<SharedPtr<ServerSession>, SharedPtr<ClientSession>>; 65 using SessionPair = std::pair<std::shared_ptr<ServerSession>, std::shared_ptr<ClientSession>>;
63 66
64 /** 67 /**
65 * Creates a pair of ServerSession and an associated ClientSession. 68 * Creates a pair of ServerSession and an associated ClientSession.
@@ -69,7 +72,7 @@ public:
69 * @return The created session tuple 72 * @return The created session tuple
70 */ 73 */
71 static SessionPair CreateSessionPair(KernelCore& kernel, const std::string& name = "Unknown", 74 static SessionPair CreateSessionPair(KernelCore& kernel, const std::string& name = "Unknown",
72 SharedPtr<ClientPort> client_port = nullptr); 75 std::shared_ptr<ClientPort> client_port = nullptr);
73 76
74 /** 77 /**
75 * Sets the HLE handler for the session. This handler will be called to service IPC requests 78 * Sets the HLE handler for the session. This handler will be called to service IPC requests
@@ -85,7 +88,7 @@ public:
85 * @param thread Thread that initiated the request. 88 * @param thread Thread that initiated the request.
86 * @returns ResultCode from the operation. 89 * @returns ResultCode from the operation.
87 */ 90 */
88 ResultCode HandleSyncRequest(SharedPtr<Thread> thread); 91 ResultCode HandleSyncRequest(std::shared_ptr<Thread> thread);
89 92
90 bool ShouldWait(const Thread* thread) const override; 93 bool ShouldWait(const Thread* thread) const override;
91 94
@@ -118,9 +121,6 @@ public:
118 } 121 }
119 122
120private: 123private:
121 explicit ServerSession(KernelCore& kernel);
122 ~ServerSession() override;
123
124 /** 124 /**
125 * Creates a server session. The server session can have an optional HLE handler, 125 * Creates a server session. The server session can have an optional HLE handler,
126 * which will be invoked to handle the IPC requests that this session receives. 126 * which will be invoked to handle the IPC requests that this session receives.
@@ -128,8 +128,8 @@ private:
128 * @param name Optional name of the server session. 128 * @param name Optional name of the server session.
129 * @return The created server session 129 * @return The created server session
130 */ 130 */
131 static ResultVal<SharedPtr<ServerSession>> Create(KernelCore& kernel, 131 static ResultVal<std::shared_ptr<ServerSession>> Create(KernelCore& kernel,
132 std::string name = "Unknown"); 132 std::string name = "Unknown");
133 133
134 /// Handles a SyncRequest to a domain, forwarding the request to the proper object or closing an 134 /// Handles a SyncRequest to a domain, forwarding the request to the proper object or closing an
135 /// object handle. 135 /// object handle.
@@ -147,12 +147,12 @@ private:
147 /// List of threads that are pending a response after a sync request. This list is processed in 147 /// List of threads that are pending a response after a sync request. This list is processed in
148 /// a LIFO manner, thus, the last request will be dispatched first. 148 /// a LIFO manner, thus, the last request will be dispatched first.
149 /// TODO(Subv): Verify if this is indeed processed in LIFO using a hardware test. 149 /// TODO(Subv): Verify if this is indeed processed in LIFO using a hardware test.
150 std::vector<SharedPtr<Thread>> pending_requesting_threads; 150 std::vector<std::shared_ptr<Thread>> pending_requesting_threads;
151 151
152 /// Thread whose request is currently being handled. A request is considered "handled" when a 152 /// Thread whose request is currently being handled. A request is considered "handled" when a
153 /// response is sent via svcReplyAndReceive. 153 /// response is sent via svcReplyAndReceive.
154 /// TODO(Subv): Find a better name for this. 154 /// TODO(Subv): Find a better name for this.
155 SharedPtr<Thread> currently_handling; 155 std::shared_ptr<Thread> currently_handling;
156 156
157 /// When set to True, converts the session to a domain at the end of the command 157 /// When set to True, converts the session to a domain at the end of the command
158 bool convert_to_domain{}; 158 bool convert_to_domain{};
diff --git a/src/core/hle/kernel/session.h b/src/core/hle/kernel/session.h
index 7a551f5e4..ea956813b 100644
--- a/src/core/hle/kernel/session.h
+++ b/src/core/hle/kernel/session.h
@@ -20,8 +20,8 @@ class ServerSession;
20 */ 20 */
21class Session final { 21class Session final {
22public: 22public:
23 ClientSession* client = nullptr; ///< The client endpoint of the session. 23 ClientSession* client = nullptr; ///< The client endpoint of the session.
24 ServerSession* server = nullptr; ///< The server endpoint of the session. 24 ServerSession* server = nullptr; ///< The server endpoint of the session.
25 SharedPtr<ClientPort> port; ///< The port that this session is associated with (optional). 25 std::shared_ptr<ClientPort> port; ///< The port that this session is associated with (optional).
26}; 26};
27} // namespace Kernel 27} // namespace Kernel
diff --git a/src/core/hle/kernel/shared_memory.cpp b/src/core/hle/kernel/shared_memory.cpp
index a815c4eea..afb2e3fc2 100644
--- a/src/core/hle/kernel/shared_memory.cpp
+++ b/src/core/hle/kernel/shared_memory.cpp
@@ -15,11 +15,12 @@ namespace Kernel {
15SharedMemory::SharedMemory(KernelCore& kernel) : Object{kernel} {} 15SharedMemory::SharedMemory(KernelCore& kernel) : Object{kernel} {}
16SharedMemory::~SharedMemory() = default; 16SharedMemory::~SharedMemory() = default;
17 17
18SharedPtr<SharedMemory> SharedMemory::Create(KernelCore& kernel, Process* owner_process, u64 size, 18std::shared_ptr<SharedMemory> SharedMemory::Create(KernelCore& kernel, Process* owner_process,
19 MemoryPermission permissions, 19 u64 size, MemoryPermission permissions,
20 MemoryPermission other_permissions, VAddr address, 20 MemoryPermission other_permissions,
21 MemoryRegion region, std::string name) { 21 VAddr address, MemoryRegion region,
22 SharedPtr<SharedMemory> shared_memory(new SharedMemory(kernel)); 22 std::string name) {
23 std::shared_ptr<SharedMemory> shared_memory = std::make_shared<SharedMemory>(kernel);
23 24
24 shared_memory->owner_process = owner_process; 25 shared_memory->owner_process = owner_process;
25 shared_memory->name = std::move(name); 26 shared_memory->name = std::move(name);
@@ -58,10 +59,10 @@ SharedPtr<SharedMemory> SharedMemory::Create(KernelCore& kernel, Process* owner_
58 return shared_memory; 59 return shared_memory;
59} 60}
60 61
61SharedPtr<SharedMemory> SharedMemory::CreateForApplet( 62std::shared_ptr<SharedMemory> SharedMemory::CreateForApplet(
62 KernelCore& kernel, std::shared_ptr<Kernel::PhysicalMemory> heap_block, std::size_t offset, 63 KernelCore& kernel, std::shared_ptr<Kernel::PhysicalMemory> heap_block, std::size_t offset,
63 u64 size, MemoryPermission permissions, MemoryPermission other_permissions, std::string name) { 64 u64 size, MemoryPermission permissions, MemoryPermission other_permissions, std::string name) {
64 SharedPtr<SharedMemory> shared_memory(new SharedMemory(kernel)); 65 std::shared_ptr<SharedMemory> shared_memory = std::make_shared<SharedMemory>(kernel);
65 66
66 shared_memory->owner_process = nullptr; 67 shared_memory->owner_process = nullptr;
67 shared_memory->name = std::move(name); 68 shared_memory->name = std::move(name);
diff --git a/src/core/hle/kernel/shared_memory.h b/src/core/hle/kernel/shared_memory.h
index 01ca6dcd2..18400a5ad 100644
--- a/src/core/hle/kernel/shared_memory.h
+++ b/src/core/hle/kernel/shared_memory.h
@@ -33,6 +33,9 @@ enum class MemoryPermission : u32 {
33 33
34class SharedMemory final : public Object { 34class SharedMemory final : public Object {
35public: 35public:
36 explicit SharedMemory(KernelCore& kernel);
37 ~SharedMemory() override;
38
36 /** 39 /**
37 * Creates a shared memory object. 40 * Creates a shared memory object.
38 * @param kernel The kernel instance to create a shared memory instance under. 41 * @param kernel The kernel instance to create a shared memory instance under.
@@ -46,11 +49,12 @@ public:
46 * linear heap. 49 * linear heap.
47 * @param name Optional object name, used for debugging purposes. 50 * @param name Optional object name, used for debugging purposes.
48 */ 51 */
49 static SharedPtr<SharedMemory> Create(KernelCore& kernel, Process* owner_process, u64 size, 52 static std::shared_ptr<SharedMemory> Create(KernelCore& kernel, Process* owner_process,
50 MemoryPermission permissions, 53 u64 size, MemoryPermission permissions,
51 MemoryPermission other_permissions, VAddr address = 0, 54 MemoryPermission other_permissions,
52 MemoryRegion region = MemoryRegion::BASE, 55 VAddr address = 0,
53 std::string name = "Unknown"); 56 MemoryRegion region = MemoryRegion::BASE,
57 std::string name = "Unknown");
54 58
55 /** 59 /**
56 * Creates a shared memory object from a block of memory managed by an HLE applet. 60 * Creates a shared memory object from a block of memory managed by an HLE applet.
@@ -63,7 +67,7 @@ public:
63 * block. 67 * block.
64 * @param name Optional object name, used for debugging purposes. 68 * @param name Optional object name, used for debugging purposes.
65 */ 69 */
66 static SharedPtr<SharedMemory> CreateForApplet( 70 static std::shared_ptr<SharedMemory> CreateForApplet(
67 KernelCore& kernel, std::shared_ptr<Kernel::PhysicalMemory> heap_block, std::size_t offset, 71 KernelCore& kernel, std::shared_ptr<Kernel::PhysicalMemory> heap_block, std::size_t offset,
68 u64 size, MemoryPermission permissions, MemoryPermission other_permissions, 72 u64 size, MemoryPermission permissions, MemoryPermission other_permissions,
69 std::string name = "Unknown Applet"); 73 std::string name = "Unknown Applet");
@@ -130,9 +134,6 @@ public:
130 const u8* GetPointer(std::size_t offset = 0) const; 134 const u8* GetPointer(std::size_t offset = 0) const;
131 135
132private: 136private:
133 explicit SharedMemory(KernelCore& kernel);
134 ~SharedMemory() override;
135
136 /// Backing memory for this shared memory block. 137 /// Backing memory for this shared memory block.
137 std::shared_ptr<PhysicalMemory> backing_block; 138 std::shared_ptr<PhysicalMemory> backing_block;
138 /// Offset into the backing block for this shared memory. 139 /// Offset into the backing block for this shared memory.
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index 4c3b53a88..9928b3a26 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -359,7 +359,7 @@ static ResultCode ConnectToNamedPort(Core::System& system, Handle* out_handle,
359 359
360 auto client_port = it->second; 360 auto client_port = it->second;
361 361
362 SharedPtr<ClientSession> client_session; 362 std::shared_ptr<ClientSession> client_session;
363 CASCADE_RESULT(client_session, client_port->Connect()); 363 CASCADE_RESULT(client_session, client_port->Connect());
364 364
365 // Return the client session 365 // Return the client session
@@ -371,7 +371,7 @@ static ResultCode ConnectToNamedPort(Core::System& system, Handle* out_handle,
371/// Makes a blocking IPC call to an OS service. 371/// Makes a blocking IPC call to an OS service.
372static ResultCode SendSyncRequest(Core::System& system, Handle handle) { 372static ResultCode SendSyncRequest(Core::System& system, Handle handle) {
373 const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); 373 const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable();
374 SharedPtr<ClientSession> session = handle_table.Get<ClientSession>(handle); 374 std::shared_ptr<ClientSession> session = handle_table.Get<ClientSession>(handle);
375 if (!session) { 375 if (!session) {
376 LOG_ERROR(Kernel_SVC, "called with invalid handle=0x{:08X}", handle); 376 LOG_ERROR(Kernel_SVC, "called with invalid handle=0x{:08X}", handle);
377 return ERR_INVALID_HANDLE; 377 return ERR_INVALID_HANDLE;
@@ -391,7 +391,7 @@ static ResultCode GetThreadId(Core::System& system, u64* thread_id, Handle threa
391 LOG_TRACE(Kernel_SVC, "called thread=0x{:08X}", thread_handle); 391 LOG_TRACE(Kernel_SVC, "called thread=0x{:08X}", thread_handle);
392 392
393 const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); 393 const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable();
394 const SharedPtr<Thread> thread = handle_table.Get<Thread>(thread_handle); 394 const std::shared_ptr<Thread> thread = handle_table.Get<Thread>(thread_handle);
395 if (!thread) { 395 if (!thread) {
396 LOG_ERROR(Kernel_SVC, "Thread handle does not exist, handle=0x{:08X}", thread_handle); 396 LOG_ERROR(Kernel_SVC, "Thread handle does not exist, handle=0x{:08X}", thread_handle);
397 return ERR_INVALID_HANDLE; 397 return ERR_INVALID_HANDLE;
@@ -406,13 +406,13 @@ static ResultCode GetProcessId(Core::System& system, u64* process_id, Handle han
406 LOG_DEBUG(Kernel_SVC, "called handle=0x{:08X}", handle); 406 LOG_DEBUG(Kernel_SVC, "called handle=0x{:08X}", handle);
407 407
408 const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); 408 const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable();
409 const SharedPtr<Process> process = handle_table.Get<Process>(handle); 409 const std::shared_ptr<Process> process = handle_table.Get<Process>(handle);
410 if (process) { 410 if (process) {
411 *process_id = process->GetProcessID(); 411 *process_id = process->GetProcessID();
412 return RESULT_SUCCESS; 412 return RESULT_SUCCESS;
413 } 413 }
414 414
415 const SharedPtr<Thread> thread = handle_table.Get<Thread>(handle); 415 const std::shared_ptr<Thread> thread = handle_table.Get<Thread>(handle);
416 if (thread) { 416 if (thread) {
417 const Process* const owner_process = thread->GetOwnerProcess(); 417 const Process* const owner_process = thread->GetOwnerProcess();
418 if (!owner_process) { 418 if (!owner_process) {
@@ -431,8 +431,8 @@ static ResultCode GetProcessId(Core::System& system, u64* process_id, Handle han
431} 431}
432 432
433/// Default thread wakeup callback for WaitSynchronization 433/// Default thread wakeup callback for WaitSynchronization
434static bool DefaultThreadWakeupCallback(ThreadWakeupReason reason, SharedPtr<Thread> thread, 434static bool DefaultThreadWakeupCallback(ThreadWakeupReason reason, std::shared_ptr<Thread> thread,
435 SharedPtr<WaitObject> object, std::size_t index) { 435 std::shared_ptr<WaitObject> object, std::size_t index) {
436 ASSERT(thread->GetStatus() == ThreadStatus::WaitSynch); 436 ASSERT(thread->GetStatus() == ThreadStatus::WaitSynch);
437 437
438 if (reason == ThreadWakeupReason::Timeout) { 438 if (reason == ThreadWakeupReason::Timeout) {
@@ -512,7 +512,7 @@ static ResultCode WaitSynchronization(Core::System& system, Handle* index, VAddr
512 } 512 }
513 513
514 for (auto& object : objects) { 514 for (auto& object : objects) {
515 object->AddWaitingThread(thread); 515 object->AddWaitingThread(SharedFrom(thread));
516 } 516 }
517 517
518 thread->SetWaitObjects(std::move(objects)); 518 thread->SetWaitObjects(std::move(objects));
@@ -532,7 +532,7 @@ static ResultCode CancelSynchronization(Core::System& system, Handle thread_hand
532 LOG_TRACE(Kernel_SVC, "called thread=0x{:X}", thread_handle); 532 LOG_TRACE(Kernel_SVC, "called thread=0x{:X}", thread_handle);
533 533
534 const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); 534 const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable();
535 SharedPtr<Thread> thread = handle_table.Get<Thread>(thread_handle); 535 std::shared_ptr<Thread> thread = handle_table.Get<Thread>(thread_handle);
536 if (!thread) { 536 if (!thread) {
537 LOG_ERROR(Kernel_SVC, "Thread handle does not exist, thread_handle=0x{:08X}", 537 LOG_ERROR(Kernel_SVC, "Thread handle does not exist, thread_handle=0x{:08X}",
538 thread_handle); 538 thread_handle);
@@ -941,7 +941,7 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, u64 ha
941 const auto& core_timing = system.CoreTiming(); 941 const auto& core_timing = system.CoreTiming();
942 const auto& scheduler = system.CurrentScheduler(); 942 const auto& scheduler = system.CurrentScheduler();
943 const auto* const current_thread = scheduler.GetCurrentThread(); 943 const auto* const current_thread = scheduler.GetCurrentThread();
944 const bool same_thread = current_thread == thread; 944 const bool same_thread = current_thread == thread.get();
945 945
946 const u64 prev_ctx_ticks = scheduler.GetLastContextSwitchTicks(); 946 const u64 prev_ctx_ticks = scheduler.GetLastContextSwitchTicks();
947 u64 out_ticks = 0; 947 u64 out_ticks = 0;
@@ -1051,7 +1051,7 @@ static ResultCode SetThreadActivity(Core::System& system, Handle handle, u32 act
1051 } 1051 }
1052 1052
1053 const auto* current_process = system.Kernel().CurrentProcess(); 1053 const auto* current_process = system.Kernel().CurrentProcess();
1054 const SharedPtr<Thread> thread = current_process->GetHandleTable().Get<Thread>(handle); 1054 const std::shared_ptr<Thread> thread = current_process->GetHandleTable().Get<Thread>(handle);
1055 if (!thread) { 1055 if (!thread) {
1056 LOG_ERROR(Kernel_SVC, "Thread handle does not exist, handle=0x{:08X}", handle); 1056 LOG_ERROR(Kernel_SVC, "Thread handle does not exist, handle=0x{:08X}", handle);
1057 return ERR_INVALID_HANDLE; 1057 return ERR_INVALID_HANDLE;
@@ -1067,7 +1067,7 @@ static ResultCode SetThreadActivity(Core::System& system, Handle handle, u32 act
1067 return ERR_INVALID_HANDLE; 1067 return ERR_INVALID_HANDLE;
1068 } 1068 }
1069 1069
1070 if (thread == system.CurrentScheduler().GetCurrentThread()) { 1070 if (thread.get() == system.CurrentScheduler().GetCurrentThread()) {
1071 LOG_ERROR(Kernel_SVC, "The thread handle specified is the current running thread"); 1071 LOG_ERROR(Kernel_SVC, "The thread handle specified is the current running thread");
1072 return ERR_BUSY; 1072 return ERR_BUSY;
1073 } 1073 }
@@ -1083,7 +1083,7 @@ static ResultCode GetThreadContext(Core::System& system, VAddr thread_context, H
1083 LOG_DEBUG(Kernel_SVC, "called, context=0x{:08X}, thread=0x{:X}", thread_context, handle); 1083 LOG_DEBUG(Kernel_SVC, "called, context=0x{:08X}, thread=0x{:X}", thread_context, handle);
1084 1084
1085 const auto* current_process = system.Kernel().CurrentProcess(); 1085 const auto* current_process = system.Kernel().CurrentProcess();
1086 const SharedPtr<Thread> thread = current_process->GetHandleTable().Get<Thread>(handle); 1086 const std::shared_ptr<Thread> thread = current_process->GetHandleTable().Get<Thread>(handle);
1087 if (!thread) { 1087 if (!thread) {
1088 LOG_ERROR(Kernel_SVC, "Thread handle does not exist, handle=0x{:08X}", handle); 1088 LOG_ERROR(Kernel_SVC, "Thread handle does not exist, handle=0x{:08X}", handle);
1089 return ERR_INVALID_HANDLE; 1089 return ERR_INVALID_HANDLE;
@@ -1099,7 +1099,7 @@ static ResultCode GetThreadContext(Core::System& system, VAddr thread_context, H
1099 return ERR_INVALID_HANDLE; 1099 return ERR_INVALID_HANDLE;
1100 } 1100 }
1101 1101
1102 if (thread == system.CurrentScheduler().GetCurrentThread()) { 1102 if (thread.get() == system.CurrentScheduler().GetCurrentThread()) {
1103 LOG_ERROR(Kernel_SVC, "The thread handle specified is the current running thread"); 1103 LOG_ERROR(Kernel_SVC, "The thread handle specified is the current running thread");
1104 return ERR_BUSY; 1104 return ERR_BUSY;
1105 } 1105 }
@@ -1124,7 +1124,7 @@ static ResultCode GetThreadPriority(Core::System& system, u32* priority, Handle
1124 LOG_TRACE(Kernel_SVC, "called"); 1124 LOG_TRACE(Kernel_SVC, "called");
1125 1125
1126 const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); 1126 const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable();
1127 const SharedPtr<Thread> thread = handle_table.Get<Thread>(handle); 1127 const std::shared_ptr<Thread> thread = handle_table.Get<Thread>(handle);
1128 if (!thread) { 1128 if (!thread) {
1129 LOG_ERROR(Kernel_SVC, "Thread handle does not exist, handle=0x{:08X}", handle); 1129 LOG_ERROR(Kernel_SVC, "Thread handle does not exist, handle=0x{:08X}", handle);
1130 return ERR_INVALID_HANDLE; 1130 return ERR_INVALID_HANDLE;
@@ -1148,7 +1148,7 @@ static ResultCode SetThreadPriority(Core::System& system, Handle handle, u32 pri
1148 1148
1149 const auto* const current_process = system.Kernel().CurrentProcess(); 1149 const auto* const current_process = system.Kernel().CurrentProcess();
1150 1150
1151 SharedPtr<Thread> thread = current_process->GetHandleTable().Get<Thread>(handle); 1151 std::shared_ptr<Thread> thread = current_process->GetHandleTable().Get<Thread>(handle);
1152 if (!thread) { 1152 if (!thread) {
1153 LOG_ERROR(Kernel_SVC, "Thread handle does not exist, handle=0x{:08X}", handle); 1153 LOG_ERROR(Kernel_SVC, "Thread handle does not exist, handle=0x{:08X}", handle);
1154 return ERR_INVALID_HANDLE; 1154 return ERR_INVALID_HANDLE;
@@ -1268,7 +1268,7 @@ static ResultCode QueryProcessMemory(Core::System& system, VAddr memory_info_add
1268 VAddr address) { 1268 VAddr address) {
1269 LOG_TRACE(Kernel_SVC, "called process=0x{:08X} address={:X}", process_handle, address); 1269 LOG_TRACE(Kernel_SVC, "called process=0x{:08X} address={:X}", process_handle, address);
1270 const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); 1270 const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable();
1271 SharedPtr<Process> process = handle_table.Get<Process>(process_handle); 1271 std::shared_ptr<Process> process = handle_table.Get<Process>(process_handle);
1272 if (!process) { 1272 if (!process) {
1273 LOG_ERROR(Kernel_SVC, "Process handle does not exist, process_handle=0x{:08X}", 1273 LOG_ERROR(Kernel_SVC, "Process handle does not exist, process_handle=0x{:08X}",
1274 process_handle); 1274 process_handle);
@@ -1496,7 +1496,7 @@ static ResultCode CreateThread(Core::System& system, Handle* out_handle, VAddr e
1496 } 1496 }
1497 1497
1498 auto& kernel = system.Kernel(); 1498 auto& kernel = system.Kernel();
1499 CASCADE_RESULT(SharedPtr<Thread> thread, 1499 CASCADE_RESULT(std::shared_ptr<Thread> thread,
1500 Thread::Create(kernel, "", entry_point, priority, arg, processor_id, stack_top, 1500 Thread::Create(kernel, "", entry_point, priority, arg, processor_id, stack_top,
1501 *current_process)); 1501 *current_process));
1502 1502
@@ -1522,7 +1522,7 @@ static ResultCode StartThread(Core::System& system, Handle thread_handle) {
1522 LOG_DEBUG(Kernel_SVC, "called thread=0x{:08X}", thread_handle); 1522 LOG_DEBUG(Kernel_SVC, "called thread=0x{:08X}", thread_handle);
1523 1523
1524 const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); 1524 const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable();
1525 const SharedPtr<Thread> thread = handle_table.Get<Thread>(thread_handle); 1525 const std::shared_ptr<Thread> thread = handle_table.Get<Thread>(thread_handle);
1526 if (!thread) { 1526 if (!thread) {
1527 LOG_ERROR(Kernel_SVC, "Thread handle does not exist, thread_handle=0x{:08X}", 1527 LOG_ERROR(Kernel_SVC, "Thread handle does not exist, thread_handle=0x{:08X}",
1528 thread_handle); 1528 thread_handle);
@@ -1546,7 +1546,7 @@ static void ExitThread(Core::System& system) {
1546 1546
1547 auto* const current_thread = system.CurrentScheduler().GetCurrentThread(); 1547 auto* const current_thread = system.CurrentScheduler().GetCurrentThread();
1548 current_thread->Stop(); 1548 current_thread->Stop();
1549 system.GlobalScheduler().RemoveThread(current_thread); 1549 system.GlobalScheduler().RemoveThread(SharedFrom(current_thread));
1550 system.PrepareReschedule(); 1550 system.PrepareReschedule();
1551} 1551}
1552 1552
@@ -1618,7 +1618,7 @@ static ResultCode WaitProcessWideKeyAtomic(Core::System& system, VAddr mutex_add
1618 1618
1619 auto* const current_process = system.Kernel().CurrentProcess(); 1619 auto* const current_process = system.Kernel().CurrentProcess();
1620 const auto& handle_table = current_process->GetHandleTable(); 1620 const auto& handle_table = current_process->GetHandleTable();
1621 SharedPtr<Thread> thread = handle_table.Get<Thread>(thread_handle); 1621 std::shared_ptr<Thread> thread = handle_table.Get<Thread>(thread_handle);
1622 ASSERT(thread); 1622 ASSERT(thread);
1623 1623
1624 const auto release_result = current_process->GetMutex().Release(mutex_addr); 1624 const auto release_result = current_process->GetMutex().Release(mutex_addr);
@@ -1626,13 +1626,13 @@ static ResultCode WaitProcessWideKeyAtomic(Core::System& system, VAddr mutex_add
1626 return release_result; 1626 return release_result;
1627 } 1627 }
1628 1628
1629 SharedPtr<Thread> current_thread = system.CurrentScheduler().GetCurrentThread(); 1629 Thread* current_thread = system.CurrentScheduler().GetCurrentThread();
1630 current_thread->SetCondVarWaitAddress(condition_variable_addr); 1630 current_thread->SetCondVarWaitAddress(condition_variable_addr);
1631 current_thread->SetMutexWaitAddress(mutex_addr); 1631 current_thread->SetMutexWaitAddress(mutex_addr);
1632 current_thread->SetWaitHandle(thread_handle); 1632 current_thread->SetWaitHandle(thread_handle);
1633 current_thread->SetStatus(ThreadStatus::WaitCondVar); 1633 current_thread->SetStatus(ThreadStatus::WaitCondVar);
1634 current_thread->InvalidateWakeupCallback(); 1634 current_thread->InvalidateWakeupCallback();
1635 current_process->InsertConditionVariableThread(current_thread); 1635 current_process->InsertConditionVariableThread(SharedFrom(current_thread));
1636 1636
1637 current_thread->WakeAfterDelay(nano_seconds); 1637 current_thread->WakeAfterDelay(nano_seconds);
1638 1638
@@ -1652,7 +1652,7 @@ static ResultCode SignalProcessWideKey(Core::System& system, VAddr condition_var
1652 1652
1653 // Retrieve a list of all threads that are waiting for this condition variable. 1653 // Retrieve a list of all threads that are waiting for this condition variable.
1654 auto* const current_process = system.Kernel().CurrentProcess(); 1654 auto* const current_process = system.Kernel().CurrentProcess();
1655 std::vector<SharedPtr<Thread>> waiting_threads = 1655 std::vector<std::shared_ptr<Thread>> waiting_threads =
1656 current_process->GetConditionVariableThreads(condition_variable_addr); 1656 current_process->GetConditionVariableThreads(condition_variable_addr);
1657 1657
1658 // Only process up to 'target' threads, unless 'target' is less equal 0, in which case process 1658 // Only process up to 'target' threads, unless 'target' is less equal 0, in which case process
@@ -1969,7 +1969,7 @@ static ResultCode GetThreadCoreMask(Core::System& system, Handle thread_handle,
1969 LOG_TRACE(Kernel_SVC, "called, handle=0x{:08X}", thread_handle); 1969 LOG_TRACE(Kernel_SVC, "called, handle=0x{:08X}", thread_handle);
1970 1970
1971 const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); 1971 const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable();
1972 const SharedPtr<Thread> thread = handle_table.Get<Thread>(thread_handle); 1972 const std::shared_ptr<Thread> thread = handle_table.Get<Thread>(thread_handle);
1973 if (!thread) { 1973 if (!thread) {
1974 LOG_ERROR(Kernel_SVC, "Thread handle does not exist, thread_handle=0x{:08X}", 1974 LOG_ERROR(Kernel_SVC, "Thread handle does not exist, thread_handle=0x{:08X}",
1975 thread_handle); 1975 thread_handle);
@@ -2028,7 +2028,7 @@ static ResultCode SetThreadCoreMask(Core::System& system, Handle thread_handle,
2028 } 2028 }
2029 2029
2030 const auto& handle_table = current_process->GetHandleTable(); 2030 const auto& handle_table = current_process->GetHandleTable();
2031 const SharedPtr<Thread> thread = handle_table.Get<Thread>(thread_handle); 2031 const std::shared_ptr<Thread> thread = handle_table.Get<Thread>(thread_handle);
2032 if (!thread) { 2032 if (!thread) {
2033 LOG_ERROR(Kernel_SVC, "Thread handle does not exist, thread_handle=0x{:08X}", 2033 LOG_ERROR(Kernel_SVC, "Thread handle does not exist, thread_handle=0x{:08X}",
2034 thread_handle); 2034 thread_handle);
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp
index 7166e9b07..735019d96 100644
--- a/src/core/hle/kernel/thread.cpp
+++ b/src/core/hle/kernel/thread.cpp
@@ -50,7 +50,7 @@ void Thread::Stop() {
50 50
51 // Clean up any dangling references in objects that this thread was waiting for 51 // Clean up any dangling references in objects that this thread was waiting for
52 for (auto& wait_object : wait_objects) { 52 for (auto& wait_object : wait_objects) {
53 wait_object->RemoveWaitingThread(this); 53 wait_object->RemoveWaitingThread(SharedFrom(this));
54 } 54 }
55 wait_objects.clear(); 55 wait_objects.clear();
56 56
@@ -147,9 +147,10 @@ static void ResetThreadContext(Core::ARM_Interface::ThreadContext& context, VAdd
147 context.fpcr = 0x03C00000; 147 context.fpcr = 0x03C00000;
148} 148}
149 149
150ResultVal<SharedPtr<Thread>> Thread::Create(KernelCore& kernel, std::string name, VAddr entry_point, 150ResultVal<std::shared_ptr<Thread>> Thread::Create(KernelCore& kernel, std::string name,
151 u32 priority, u64 arg, s32 processor_id, 151 VAddr entry_point, u32 priority, u64 arg,
152 VAddr stack_top, Process& owner_process) { 152 s32 processor_id, VAddr stack_top,
153 Process& owner_process) {
153 // Check if priority is in ranged. Lowest priority -> highest priority id. 154 // Check if priority is in ranged. Lowest priority -> highest priority id.
154 if (priority > THREADPRIO_LOWEST) { 155 if (priority > THREADPRIO_LOWEST) {
155 LOG_ERROR(Kernel_SVC, "Invalid thread priority: {}", priority); 156 LOG_ERROR(Kernel_SVC, "Invalid thread priority: {}", priority);
@@ -168,7 +169,7 @@ ResultVal<SharedPtr<Thread>> Thread::Create(KernelCore& kernel, std::string name
168 } 169 }
169 170
170 auto& system = Core::System::GetInstance(); 171 auto& system = Core::System::GetInstance();
171 SharedPtr<Thread> thread(new Thread(kernel)); 172 std::shared_ptr<Thread> thread = std::make_shared<Thread>(kernel);
172 173
173 thread->thread_id = kernel.CreateNewThreadID(); 174 thread->thread_id = kernel.CreateNewThreadID();
174 thread->status = ThreadStatus::Dormant; 175 thread->status = ThreadStatus::Dormant;
@@ -197,7 +198,7 @@ ResultVal<SharedPtr<Thread>> Thread::Create(KernelCore& kernel, std::string name
197 // to initialize the context 198 // to initialize the context
198 ResetThreadContext(thread->context, stack_top, entry_point, arg); 199 ResetThreadContext(thread->context, stack_top, entry_point, arg);
199 200
200 return MakeResult<SharedPtr<Thread>>(std::move(thread)); 201 return MakeResult<std::shared_ptr<Thread>>(std::move(thread));
201} 202}
202 203
203void Thread::SetPriority(u32 priority) { 204void Thread::SetPriority(u32 priority) {
@@ -215,7 +216,7 @@ void Thread::SetWaitSynchronizationOutput(s32 output) {
215 context.cpu_registers[1] = output; 216 context.cpu_registers[1] = output;
216} 217}
217 218
218s32 Thread::GetWaitObjectIndex(const WaitObject* object) const { 219s32 Thread::GetWaitObjectIndex(std::shared_ptr<WaitObject> object) const {
219 ASSERT_MSG(!wait_objects.empty(), "Thread is not waiting for anything"); 220 ASSERT_MSG(!wait_objects.empty(), "Thread is not waiting for anything");
220 const auto match = std::find(wait_objects.rbegin(), wait_objects.rend(), object); 221 const auto match = std::find(wait_objects.rbegin(), wait_objects.rend(), object);
221 return static_cast<s32>(std::distance(match, wait_objects.rend()) - 1); 222 return static_cast<s32>(std::distance(match, wait_objects.rend()) - 1);
@@ -255,8 +256,8 @@ void Thread::SetStatus(ThreadStatus new_status) {
255 status = new_status; 256 status = new_status;
256} 257}
257 258
258void Thread::AddMutexWaiter(SharedPtr<Thread> thread) { 259void Thread::AddMutexWaiter(std::shared_ptr<Thread> thread) {
259 if (thread->lock_owner == this) { 260 if (thread->lock_owner.get() == this) {
260 // If the thread is already waiting for this thread to release the mutex, ensure that the 261 // If the thread is already waiting for this thread to release the mutex, ensure that the
261 // waiters list is consistent and return without doing anything. 262 // waiters list is consistent and return without doing anything.
262 const auto iter = std::find(wait_mutex_threads.begin(), wait_mutex_threads.end(), thread); 263 const auto iter = std::find(wait_mutex_threads.begin(), wait_mutex_threads.end(), thread);
@@ -276,13 +277,13 @@ void Thread::AddMutexWaiter(SharedPtr<Thread> thread) {
276 wait_mutex_threads.begin(), wait_mutex_threads.end(), 277 wait_mutex_threads.begin(), wait_mutex_threads.end(),
277 [&thread](const auto& entry) { return entry->GetPriority() > thread->GetPriority(); }); 278 [&thread](const auto& entry) { return entry->GetPriority() > thread->GetPriority(); });
278 wait_mutex_threads.insert(insertion_point, thread); 279 wait_mutex_threads.insert(insertion_point, thread);
279 thread->lock_owner = this; 280 thread->lock_owner = SharedFrom(this);
280 281
281 UpdatePriority(); 282 UpdatePriority();
282} 283}
283 284
284void Thread::RemoveMutexWaiter(SharedPtr<Thread> thread) { 285void Thread::RemoveMutexWaiter(std::shared_ptr<Thread> thread) {
285 ASSERT(thread->lock_owner == this); 286 ASSERT(thread->lock_owner.get() == this);
286 287
287 // Ensure that the thread is in the list of mutex waiters 288 // Ensure that the thread is in the list of mutex waiters
288 const auto iter = std::find(wait_mutex_threads.begin(), wait_mutex_threads.end(), thread); 289 const auto iter = std::find(wait_mutex_threads.begin(), wait_mutex_threads.end(), thread);
@@ -310,13 +311,13 @@ void Thread::UpdatePriority() {
310 } 311 }
311 312
312 if (GetStatus() == ThreadStatus::WaitCondVar) { 313 if (GetStatus() == ThreadStatus::WaitCondVar) {
313 owner_process->RemoveConditionVariableThread(this); 314 owner_process->RemoveConditionVariableThread(SharedFrom(this));
314 } 315 }
315 316
316 SetCurrentPriority(new_priority); 317 SetCurrentPriority(new_priority);
317 318
318 if (GetStatus() == ThreadStatus::WaitCondVar) { 319 if (GetStatus() == ThreadStatus::WaitCondVar) {
319 owner_process->InsertConditionVariableThread(this); 320 owner_process->InsertConditionVariableThread(SharedFrom(this));
320 } 321 }
321 322
322 if (!lock_owner) { 323 if (!lock_owner) {
@@ -325,8 +326,8 @@ void Thread::UpdatePriority() {
325 326
326 // Ensure that the thread is within the correct location in the waiting list. 327 // Ensure that the thread is within the correct location in the waiting list.
327 auto old_owner = lock_owner; 328 auto old_owner = lock_owner;
328 lock_owner->RemoveMutexWaiter(this); 329 lock_owner->RemoveMutexWaiter(SharedFrom(this));
329 old_owner->AddMutexWaiter(this); 330 old_owner->AddMutexWaiter(SharedFrom(this));
330 331
331 // Recursively update the priority of the thread that depends on the priority of this one. 332 // Recursively update the priority of the thread that depends on the priority of this one.
332 lock_owner->UpdatePriority(); 333 lock_owner->UpdatePriority();
@@ -339,11 +340,11 @@ void Thread::ChangeCore(u32 core, u64 mask) {
339bool Thread::AllWaitObjectsReady() const { 340bool Thread::AllWaitObjectsReady() const {
340 return std::none_of( 341 return std::none_of(
341 wait_objects.begin(), wait_objects.end(), 342 wait_objects.begin(), wait_objects.end(),
342 [this](const SharedPtr<WaitObject>& object) { return object->ShouldWait(this); }); 343 [this](const std::shared_ptr<WaitObject>& object) { return object->ShouldWait(this); });
343} 344}
344 345
345bool Thread::InvokeWakeupCallback(ThreadWakeupReason reason, SharedPtr<Thread> thread, 346bool Thread::InvokeWakeupCallback(ThreadWakeupReason reason, std::shared_ptr<Thread> thread,
346 SharedPtr<WaitObject> object, std::size_t index) { 347 std::shared_ptr<WaitObject> object, std::size_t index) {
347 ASSERT(wakeup_callback); 348 ASSERT(wakeup_callback);
348 return wakeup_callback(reason, std::move(thread), std::move(object), index); 349 return wakeup_callback(reason, std::move(thread), std::move(object), index);
349} 350}
diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h
index 25a6ed234..3bcf9e137 100644
--- a/src/core/hle/kernel/thread.h
+++ b/src/core/hle/kernel/thread.h
@@ -97,14 +97,18 @@ enum class ThreadSchedMasks : u32 {
97 97
98class Thread final : public WaitObject { 98class Thread final : public WaitObject {
99public: 99public:
100 using MutexWaitingThreads = std::vector<SharedPtr<Thread>>; 100 explicit Thread(KernelCore& kernel);
101 ~Thread() override;
102
103 using MutexWaitingThreads = std::vector<std::shared_ptr<Thread>>;
101 104
102 using ThreadContext = Core::ARM_Interface::ThreadContext; 105 using ThreadContext = Core::ARM_Interface::ThreadContext;
103 106
104 using ThreadWaitObjects = std::vector<SharedPtr<WaitObject>>; 107 using ThreadWaitObjects = std::vector<std::shared_ptr<WaitObject>>;
105 108
106 using WakeupCallback = std::function<bool(ThreadWakeupReason reason, SharedPtr<Thread> thread, 109 using WakeupCallback =
107 SharedPtr<WaitObject> object, std::size_t index)>; 110 std::function<bool(ThreadWakeupReason reason, std::shared_ptr<Thread> thread,
111 std::shared_ptr<WaitObject> object, std::size_t index)>;
108 112
109 /** 113 /**
110 * Creates and returns a new thread. The new thread is immediately scheduled 114 * Creates and returns a new thread. The new thread is immediately scheduled
@@ -118,10 +122,10 @@ public:
118 * @param owner_process The parent process for the thread 122 * @param owner_process The parent process for the thread
119 * @return A shared pointer to the newly created thread 123 * @return A shared pointer to the newly created thread
120 */ 124 */
121 static ResultVal<SharedPtr<Thread>> Create(KernelCore& kernel, std::string name, 125 static ResultVal<std::shared_ptr<Thread>> Create(KernelCore& kernel, std::string name,
122 VAddr entry_point, u32 priority, u64 arg, 126 VAddr entry_point, u32 priority, u64 arg,
123 s32 processor_id, VAddr stack_top, 127 s32 processor_id, VAddr stack_top,
124 Process& owner_process); 128 Process& owner_process);
125 129
126 std::string GetName() const override { 130 std::string GetName() const override {
127 return name; 131 return name;
@@ -166,10 +170,10 @@ public:
166 void SetPriority(u32 priority); 170 void SetPriority(u32 priority);
167 171
168 /// Adds a thread to the list of threads that are waiting for a lock held by this thread. 172 /// Adds a thread to the list of threads that are waiting for a lock held by this thread.
169 void AddMutexWaiter(SharedPtr<Thread> thread); 173 void AddMutexWaiter(std::shared_ptr<Thread> thread);
170 174
171 /// Removes a thread from the list of threads that are waiting for a lock held by this thread. 175 /// Removes a thread from the list of threads that are waiting for a lock held by this thread.
172 void RemoveMutexWaiter(SharedPtr<Thread> thread); 176 void RemoveMutexWaiter(std::shared_ptr<Thread> thread);
173 177
174 /// Recalculates the current priority taking into account priority inheritance. 178 /// Recalculates the current priority taking into account priority inheritance.
175 void UpdatePriority(); 179 void UpdatePriority();
@@ -229,7 +233,7 @@ public:
229 * 233 *
230 * @param object Object to query the index of. 234 * @param object Object to query the index of.
231 */ 235 */
232 s32 GetWaitObjectIndex(const WaitObject* object) const; 236 s32 GetWaitObjectIndex(std::shared_ptr<WaitObject> object) const;
233 237
234 /** 238 /**
235 * Stops a thread, invalidating it from further use 239 * Stops a thread, invalidating it from further use
@@ -320,7 +324,7 @@ public:
320 324
321 void ClearWaitObjects() { 325 void ClearWaitObjects() {
322 for (const auto& waiting_object : wait_objects) { 326 for (const auto& waiting_object : wait_objects) {
323 waiting_object->RemoveWaitingThread(this); 327 waiting_object->RemoveWaitingThread(SharedFrom(this));
324 } 328 }
325 wait_objects.clear(); 329 wait_objects.clear();
326 } 330 }
@@ -336,7 +340,7 @@ public:
336 return lock_owner.get(); 340 return lock_owner.get();
337 } 341 }
338 342
339 void SetLockOwner(SharedPtr<Thread> owner) { 343 void SetLockOwner(std::shared_ptr<Thread> owner) {
340 lock_owner = std::move(owner); 344 lock_owner = std::move(owner);
341 } 345 }
342 346
@@ -390,8 +394,8 @@ public:
390 * @pre A valid wakeup callback has been set. Violating this precondition 394 * @pre A valid wakeup callback has been set. Violating this precondition
391 * will cause an assertion to trigger. 395 * will cause an assertion to trigger.
392 */ 396 */
393 bool InvokeWakeupCallback(ThreadWakeupReason reason, SharedPtr<Thread> thread, 397 bool InvokeWakeupCallback(ThreadWakeupReason reason, std::shared_ptr<Thread> thread,
394 SharedPtr<WaitObject> object, std::size_t index); 398 std::shared_ptr<WaitObject> object, std::size_t index);
395 399
396 u32 GetIdealCore() const { 400 u32 GetIdealCore() const {
397 return ideal_core; 401 return ideal_core;
@@ -449,9 +453,6 @@ public:
449 } 453 }
450 454
451private: 455private:
452 explicit Thread(KernelCore& kernel);
453 ~Thread() override;
454
455 void SetSchedulingStatus(ThreadSchedStatus new_status); 456 void SetSchedulingStatus(ThreadSchedStatus new_status);
456 void SetCurrentPriority(u32 new_priority); 457 void SetCurrentPriority(u32 new_priority);
457 ResultCode SetCoreAndAffinityMask(s32 new_core, u64 new_affinity_mask); 458 ResultCode SetCoreAndAffinityMask(s32 new_core, u64 new_affinity_mask);
@@ -499,7 +500,7 @@ private:
499 MutexWaitingThreads wait_mutex_threads; 500 MutexWaitingThreads wait_mutex_threads;
500 501
501 /// Thread that owns the lock that this thread is waiting for. 502 /// Thread that owns the lock that this thread is waiting for.
502 SharedPtr<Thread> lock_owner; 503 std::shared_ptr<Thread> lock_owner;
503 504
504 /// If waiting on a ConditionVariable, this is the ConditionVariable address 505 /// If waiting on a ConditionVariable, this is the ConditionVariable address
505 VAddr condvar_wait_address = 0; 506 VAddr condvar_wait_address = 0;
diff --git a/src/core/hle/kernel/transfer_memory.cpp b/src/core/hle/kernel/transfer_memory.cpp
index 1113c815e..f0e73f57b 100644
--- a/src/core/hle/kernel/transfer_memory.cpp
+++ b/src/core/hle/kernel/transfer_memory.cpp
@@ -14,9 +14,9 @@ namespace Kernel {
14TransferMemory::TransferMemory(KernelCore& kernel) : Object{kernel} {} 14TransferMemory::TransferMemory(KernelCore& kernel) : Object{kernel} {}
15TransferMemory::~TransferMemory() = default; 15TransferMemory::~TransferMemory() = default;
16 16
17SharedPtr<TransferMemory> TransferMemory::Create(KernelCore& kernel, VAddr base_address, u64 size, 17std::shared_ptr<TransferMemory> TransferMemory::Create(KernelCore& kernel, VAddr base_address,
18 MemoryPermission permissions) { 18 u64 size, MemoryPermission permissions) {
19 SharedPtr<TransferMemory> transfer_memory{new TransferMemory(kernel)}; 19 std::shared_ptr<TransferMemory> transfer_memory{std::make_shared<TransferMemory>(kernel)};
20 20
21 transfer_memory->base_address = base_address; 21 transfer_memory->base_address = base_address;
22 transfer_memory->memory_size = size; 22 transfer_memory->memory_size = size;
diff --git a/src/core/hle/kernel/transfer_memory.h b/src/core/hle/kernel/transfer_memory.h
index 6be9dc094..556e6c62b 100644
--- a/src/core/hle/kernel/transfer_memory.h
+++ b/src/core/hle/kernel/transfer_memory.h
@@ -27,10 +27,13 @@ enum class MemoryPermission : u32;
27/// 27///
28class TransferMemory final : public Object { 28class TransferMemory final : public Object {
29public: 29public:
30 explicit TransferMemory(KernelCore& kernel);
31 ~TransferMemory() override;
32
30 static constexpr HandleType HANDLE_TYPE = HandleType::TransferMemory; 33 static constexpr HandleType HANDLE_TYPE = HandleType::TransferMemory;
31 34
32 static SharedPtr<TransferMemory> Create(KernelCore& kernel, VAddr base_address, u64 size, 35 static std::shared_ptr<TransferMemory> Create(KernelCore& kernel, VAddr base_address, u64 size,
33 MemoryPermission permissions); 36 MemoryPermission permissions);
34 37
35 TransferMemory(const TransferMemory&) = delete; 38 TransferMemory(const TransferMemory&) = delete;
36 TransferMemory& operator=(const TransferMemory&) = delete; 39 TransferMemory& operator=(const TransferMemory&) = delete;
@@ -79,9 +82,6 @@ public:
79 ResultCode UnmapMemory(VAddr address, u64 size); 82 ResultCode UnmapMemory(VAddr address, u64 size);
80 83
81private: 84private:
82 explicit TransferMemory(KernelCore& kernel);
83 ~TransferMemory() override;
84
85 /// Memory block backing this instance. 85 /// Memory block backing this instance.
86 std::shared_ptr<PhysicalMemory> backing_block; 86 std::shared_ptr<PhysicalMemory> backing_block;
87 87
diff --git a/src/core/hle/kernel/wait_object.cpp b/src/core/hle/kernel/wait_object.cpp
index c00cef062..745f2c4e8 100644
--- a/src/core/hle/kernel/wait_object.cpp
+++ b/src/core/hle/kernel/wait_object.cpp
@@ -18,13 +18,13 @@ namespace Kernel {
18WaitObject::WaitObject(KernelCore& kernel) : Object{kernel} {} 18WaitObject::WaitObject(KernelCore& kernel) : Object{kernel} {}
19WaitObject::~WaitObject() = default; 19WaitObject::~WaitObject() = default;
20 20
21void WaitObject::AddWaitingThread(SharedPtr<Thread> thread) { 21void WaitObject::AddWaitingThread(std::shared_ptr<Thread> thread) {
22 auto itr = std::find(waiting_threads.begin(), waiting_threads.end(), thread); 22 auto itr = std::find(waiting_threads.begin(), waiting_threads.end(), thread);
23 if (itr == waiting_threads.end()) 23 if (itr == waiting_threads.end())
24 waiting_threads.push_back(std::move(thread)); 24 waiting_threads.push_back(std::move(thread));
25} 25}
26 26
27void WaitObject::RemoveWaitingThread(Thread* thread) { 27void WaitObject::RemoveWaitingThread(std::shared_ptr<Thread> thread) {
28 auto itr = std::find(waiting_threads.begin(), waiting_threads.end(), thread); 28 auto itr = std::find(waiting_threads.begin(), waiting_threads.end(), thread);
29 // If a thread passed multiple handles to the same object, 29 // If a thread passed multiple handles to the same object,
30 // the kernel might attempt to remove the thread from the object's 30 // the kernel might attempt to remove the thread from the object's
@@ -33,7 +33,7 @@ void WaitObject::RemoveWaitingThread(Thread* thread) {
33 waiting_threads.erase(itr); 33 waiting_threads.erase(itr);
34} 34}
35 35
36SharedPtr<Thread> WaitObject::GetHighestPriorityReadyThread() const { 36std::shared_ptr<Thread> WaitObject::GetHighestPriorityReadyThread() const {
37 Thread* candidate = nullptr; 37 Thread* candidate = nullptr;
38 u32 candidate_priority = THREADPRIO_LOWEST + 1; 38 u32 candidate_priority = THREADPRIO_LOWEST + 1;
39 39
@@ -64,10 +64,10 @@ SharedPtr<Thread> WaitObject::GetHighestPriorityReadyThread() const {
64 } 64 }
65 } 65 }
66 66
67 return candidate; 67 return SharedFrom(candidate);
68} 68}
69 69
70void WaitObject::WakeupWaitingThread(SharedPtr<Thread> thread) { 70void WaitObject::WakeupWaitingThread(std::shared_ptr<Thread> thread) {
71 ASSERT(!ShouldWait(thread.get())); 71 ASSERT(!ShouldWait(thread.get()));
72 72
73 if (!thread) { 73 if (!thread) {
@@ -83,7 +83,7 @@ void WaitObject::WakeupWaitingThread(SharedPtr<Thread> thread) {
83 Acquire(thread.get()); 83 Acquire(thread.get());
84 } 84 }
85 85
86 const std::size_t index = thread->GetWaitObjectIndex(this); 86 const std::size_t index = thread->GetWaitObjectIndex(SharedFrom(this));
87 87
88 thread->ClearWaitObjects(); 88 thread->ClearWaitObjects();
89 89
@@ -91,7 +91,8 @@ void WaitObject::WakeupWaitingThread(SharedPtr<Thread> thread) {
91 91
92 bool resume = true; 92 bool resume = true;
93 if (thread->HasWakeupCallback()) { 93 if (thread->HasWakeupCallback()) {
94 resume = thread->InvokeWakeupCallback(ThreadWakeupReason::Signal, thread, this, index); 94 resume = thread->InvokeWakeupCallback(ThreadWakeupReason::Signal, thread, SharedFrom(this),
95 index);
95 } 96 }
96 if (resume) { 97 if (resume) {
97 thread->ResumeFromWait(); 98 thread->ResumeFromWait();
@@ -105,7 +106,7 @@ void WaitObject::WakeupAllWaitingThreads() {
105 } 106 }
106} 107}
107 108
108const std::vector<SharedPtr<Thread>>& WaitObject::GetWaitingThreads() const { 109const std::vector<std::shared_ptr<Thread>>& WaitObject::GetWaitingThreads() const {
109 return waiting_threads; 110 return waiting_threads;
110} 111}
111 112
diff --git a/src/core/hle/kernel/wait_object.h b/src/core/hle/kernel/wait_object.h
index 3271a30a7..f9d596db9 100644
--- a/src/core/hle/kernel/wait_object.h
+++ b/src/core/hle/kernel/wait_object.h
@@ -33,13 +33,13 @@ public:
33 * Add a thread to wait on this object 33 * Add a thread to wait on this object
34 * @param thread Pointer to thread to add 34 * @param thread Pointer to thread to add
35 */ 35 */
36 void AddWaitingThread(SharedPtr<Thread> thread); 36 void AddWaitingThread(std::shared_ptr<Thread> thread);
37 37
38 /** 38 /**
39 * Removes a thread from waiting on this object (e.g. if it was resumed already) 39 * Removes a thread from waiting on this object (e.g. if it was resumed already)
40 * @param thread Pointer to thread to remove 40 * @param thread Pointer to thread to remove
41 */ 41 */
42 void RemoveWaitingThread(Thread* thread); 42 void RemoveWaitingThread(std::shared_ptr<Thread> thread);
43 43
44 /** 44 /**
45 * Wake up all threads waiting on this object that can be awoken, in priority order, 45 * Wake up all threads waiting on this object that can be awoken, in priority order,
@@ -51,24 +51,24 @@ public:
51 * Wakes up a single thread waiting on this object. 51 * Wakes up a single thread waiting on this object.
52 * @param thread Thread that is waiting on this object to wakeup. 52 * @param thread Thread that is waiting on this object to wakeup.
53 */ 53 */
54 void WakeupWaitingThread(SharedPtr<Thread> thread); 54 void WakeupWaitingThread(std::shared_ptr<Thread> thread);
55 55
56 /// Obtains the highest priority thread that is ready to run from this object's waiting list. 56 /// Obtains the highest priority thread that is ready to run from this object's waiting list.
57 SharedPtr<Thread> GetHighestPriorityReadyThread() const; 57 std::shared_ptr<Thread> GetHighestPriorityReadyThread() const;
58 58
59 /// Get a const reference to the waiting threads list for debug use 59 /// Get a const reference to the waiting threads list for debug use
60 const std::vector<SharedPtr<Thread>>& GetWaitingThreads() const; 60 const std::vector<std::shared_ptr<Thread>>& GetWaitingThreads() const;
61 61
62private: 62private:
63 /// Threads waiting for this object to become available 63 /// Threads waiting for this object to become available
64 std::vector<SharedPtr<Thread>> waiting_threads; 64 std::vector<std::shared_ptr<Thread>> waiting_threads;
65}; 65};
66 66
67// Specialization of DynamicObjectCast for WaitObjects 67// Specialization of DynamicObjectCast for WaitObjects
68template <> 68template <>
69inline SharedPtr<WaitObject> DynamicObjectCast<WaitObject>(SharedPtr<Object> object) { 69inline std::shared_ptr<WaitObject> DynamicObjectCast<WaitObject>(std::shared_ptr<Object> object) {
70 if (object != nullptr && object->IsWaitable()) { 70 if (object != nullptr && object->IsWaitable()) {
71 return boost::static_pointer_cast<WaitObject>(object); 71 return std::static_pointer_cast<WaitObject>(object);
72 } 72 }
73 return nullptr; 73 return nullptr;
74} 74}
diff --git a/src/core/hle/kernel/writable_event.cpp b/src/core/hle/kernel/writable_event.cpp
index c783a34ee..c9332e3e1 100644
--- a/src/core/hle/kernel/writable_event.cpp
+++ b/src/core/hle/kernel/writable_event.cpp
@@ -16,8 +16,8 @@ WritableEvent::WritableEvent(KernelCore& kernel) : Object{kernel} {}
16WritableEvent::~WritableEvent() = default; 16WritableEvent::~WritableEvent() = default;
17 17
18EventPair WritableEvent::CreateEventPair(KernelCore& kernel, std::string name) { 18EventPair WritableEvent::CreateEventPair(KernelCore& kernel, std::string name) {
19 SharedPtr<WritableEvent> writable_event(new WritableEvent(kernel)); 19 std::shared_ptr<WritableEvent> writable_event(new WritableEvent(kernel));
20 SharedPtr<ReadableEvent> readable_event(new ReadableEvent(kernel)); 20 std::shared_ptr<ReadableEvent> readable_event(new ReadableEvent(kernel));
21 21
22 writable_event->name = name + ":Writable"; 22 writable_event->name = name + ":Writable";
23 writable_event->readable = readable_event; 23 writable_event->readable = readable_event;
@@ -27,7 +27,7 @@ EventPair WritableEvent::CreateEventPair(KernelCore& kernel, std::string name) {
27 return {std::move(readable_event), std::move(writable_event)}; 27 return {std::move(readable_event), std::move(writable_event)};
28} 28}
29 29
30SharedPtr<ReadableEvent> WritableEvent::GetReadableEvent() const { 30std::shared_ptr<ReadableEvent> WritableEvent::GetReadableEvent() const {
31 return readable; 31 return readable;
32} 32}
33 33
diff --git a/src/core/hle/kernel/writable_event.h b/src/core/hle/kernel/writable_event.h
index f46cf1dd8..afe97f3a9 100644
--- a/src/core/hle/kernel/writable_event.h
+++ b/src/core/hle/kernel/writable_event.h
@@ -13,8 +13,8 @@ class ReadableEvent;
13class WritableEvent; 13class WritableEvent;
14 14
15struct EventPair { 15struct EventPair {
16 SharedPtr<ReadableEvent> readable; 16 std::shared_ptr<ReadableEvent> readable;
17 SharedPtr<WritableEvent> writable; 17 std::shared_ptr<WritableEvent> writable;
18}; 18};
19 19
20class WritableEvent final : public Object { 20class WritableEvent final : public Object {
@@ -40,7 +40,7 @@ public:
40 return HANDLE_TYPE; 40 return HANDLE_TYPE;
41 } 41 }
42 42
43 SharedPtr<ReadableEvent> GetReadableEvent() const; 43 std::shared_ptr<ReadableEvent> GetReadableEvent() const;
44 44
45 void Signal(); 45 void Signal();
46 void Clear(); 46 void Clear();
@@ -49,7 +49,7 @@ public:
49private: 49private:
50 explicit WritableEvent(KernelCore& kernel); 50 explicit WritableEvent(KernelCore& kernel);
51 51
52 SharedPtr<ReadableEvent> readable; 52 std::shared_ptr<ReadableEvent> readable;
53 53
54 std::string name; ///< Name of event (optional) 54 std::string name; ///< Name of event (optional)
55}; 55};
diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp
index 701f05019..3ebb92994 100644
--- a/src/core/hle/service/am/am.cpp
+++ b/src/core/hle/service/am/am.cpp
@@ -531,12 +531,11 @@ AppletMessageQueue::AppletMessageQueue(Kernel::KernelCore& kernel) {
531 531
532AppletMessageQueue::~AppletMessageQueue() = default; 532AppletMessageQueue::~AppletMessageQueue() = default;
533 533
534const Kernel::SharedPtr<Kernel::ReadableEvent>& AppletMessageQueue::GetMesssageRecieveEvent() 534const std::shared_ptr<Kernel::ReadableEvent>& AppletMessageQueue::GetMesssageRecieveEvent() const {
535 const {
536 return on_new_message.readable; 535 return on_new_message.readable;
537} 536}
538 537
539const Kernel::SharedPtr<Kernel::ReadableEvent>& AppletMessageQueue::GetOperationModeChangedEvent() 538const std::shared_ptr<Kernel::ReadableEvent>& AppletMessageQueue::GetOperationModeChangedEvent()
540 const { 539 const {
541 return on_operation_mode_changed.readable; 540 return on_operation_mode_changed.readable;
542} 541}
diff --git a/src/core/hle/service/am/am.h b/src/core/hle/service/am/am.h
index 06a65b5ed..448817be9 100644
--- a/src/core/hle/service/am/am.h
+++ b/src/core/hle/service/am/am.h
@@ -54,8 +54,8 @@ public:
54 explicit AppletMessageQueue(Kernel::KernelCore& kernel); 54 explicit AppletMessageQueue(Kernel::KernelCore& kernel);
55 ~AppletMessageQueue(); 55 ~AppletMessageQueue();
56 56
57 const Kernel::SharedPtr<Kernel::ReadableEvent>& GetMesssageRecieveEvent() const; 57 const std::shared_ptr<Kernel::ReadableEvent>& GetMesssageRecieveEvent() const;
58 const Kernel::SharedPtr<Kernel::ReadableEvent>& GetOperationModeChangedEvent() const; 58 const std::shared_ptr<Kernel::ReadableEvent>& GetOperationModeChangedEvent() const;
59 void PushMessage(AppletMessage msg); 59 void PushMessage(AppletMessage msg);
60 AppletMessage PopMessage(); 60 AppletMessage PopMessage();
61 std::size_t GetMessageCount() const; 61 std::size_t GetMessageCount() const;
diff --git a/src/core/hle/service/am/applets/applets.cpp b/src/core/hle/service/am/applets/applets.cpp
index 673ad1f7f..92f995f8f 100644
--- a/src/core/hle/service/am/applets/applets.cpp
+++ b/src/core/hle/service/am/applets/applets.cpp
@@ -108,15 +108,15 @@ void AppletDataBroker::SignalStateChanged() const {
108 state_changed_event.writable->Signal(); 108 state_changed_event.writable->Signal();
109} 109}
110 110
111Kernel::SharedPtr<Kernel::ReadableEvent> AppletDataBroker::GetNormalDataEvent() const { 111std::shared_ptr<Kernel::ReadableEvent> AppletDataBroker::GetNormalDataEvent() const {
112 return pop_out_data_event.readable; 112 return pop_out_data_event.readable;
113} 113}
114 114
115Kernel::SharedPtr<Kernel::ReadableEvent> AppletDataBroker::GetInteractiveDataEvent() const { 115std::shared_ptr<Kernel::ReadableEvent> AppletDataBroker::GetInteractiveDataEvent() const {
116 return pop_interactive_out_data_event.readable; 116 return pop_interactive_out_data_event.readable;
117} 117}
118 118
119Kernel::SharedPtr<Kernel::ReadableEvent> AppletDataBroker::GetStateChangedEvent() const { 119std::shared_ptr<Kernel::ReadableEvent> AppletDataBroker::GetStateChangedEvent() const {
120 return state_changed_event.readable; 120 return state_changed_event.readable;
121} 121}
122 122
diff --git a/src/core/hle/service/am/applets/applets.h b/src/core/hle/service/am/applets/applets.h
index 226be88b1..16e61fc6f 100644
--- a/src/core/hle/service/am/applets/applets.h
+++ b/src/core/hle/service/am/applets/applets.h
@@ -86,9 +86,9 @@ public:
86 86
87 void SignalStateChanged() const; 87 void SignalStateChanged() const;
88 88
89 Kernel::SharedPtr<Kernel::ReadableEvent> GetNormalDataEvent() const; 89 std::shared_ptr<Kernel::ReadableEvent> GetNormalDataEvent() const;
90 Kernel::SharedPtr<Kernel::ReadableEvent> GetInteractiveDataEvent() const; 90 std::shared_ptr<Kernel::ReadableEvent> GetInteractiveDataEvent() const;
91 Kernel::SharedPtr<Kernel::ReadableEvent> GetStateChangedEvent() const; 91 std::shared_ptr<Kernel::ReadableEvent> GetStateChangedEvent() const;
92 92
93private: 93private:
94 // Queues are named from applet's perspective 94 // Queues are named from applet's perspective
diff --git a/src/core/hle/service/bcat/backend/backend.cpp b/src/core/hle/service/bcat/backend/backend.cpp
index dec0849b8..6f5ea095a 100644
--- a/src/core/hle/service/bcat/backend/backend.cpp
+++ b/src/core/hle/service/bcat/backend/backend.cpp
@@ -16,7 +16,7 @@ ProgressServiceBackend::ProgressServiceBackend(Kernel::KernelCore& kernel,
16 kernel, std::string("ProgressServiceBackend:UpdateEvent:").append(event_name)); 16 kernel, std::string("ProgressServiceBackend:UpdateEvent:").append(event_name));
17} 17}
18 18
19Kernel::SharedPtr<Kernel::ReadableEvent> ProgressServiceBackend::GetEvent() const { 19std::shared_ptr<Kernel::ReadableEvent> ProgressServiceBackend::GetEvent() const {
20 return event.readable; 20 return event.readable;
21} 21}
22 22
diff --git a/src/core/hle/service/bcat/backend/backend.h b/src/core/hle/service/bcat/backend/backend.h
index ea4b16ad0..48bbbe66f 100644
--- a/src/core/hle/service/bcat/backend/backend.h
+++ b/src/core/hle/service/bcat/backend/backend.h
@@ -98,7 +98,7 @@ public:
98private: 98private:
99 explicit ProgressServiceBackend(Kernel::KernelCore& kernel, std::string_view event_name); 99 explicit ProgressServiceBackend(Kernel::KernelCore& kernel, std::string_view event_name);
100 100
101 Kernel::SharedPtr<Kernel::ReadableEvent> GetEvent() const; 101 std::shared_ptr<Kernel::ReadableEvent> GetEvent() const;
102 DeliveryCacheProgressImpl& GetImpl(); 102 DeliveryCacheProgressImpl& GetImpl();
103 103
104 void SignalUpdate() const; 104 void SignalUpdate() const;
diff --git a/src/core/hle/service/bcat/module.cpp b/src/core/hle/service/bcat/module.cpp
index 8a7304f86..920d7269b 100644
--- a/src/core/hle/service/bcat/module.cpp
+++ b/src/core/hle/service/bcat/module.cpp
@@ -87,7 +87,7 @@ struct DeliveryCacheDirectoryEntry {
87 87
88class IDeliveryCacheProgressService final : public ServiceFramework<IDeliveryCacheProgressService> { 88class IDeliveryCacheProgressService final : public ServiceFramework<IDeliveryCacheProgressService> {
89public: 89public:
90 IDeliveryCacheProgressService(Kernel::SharedPtr<Kernel::ReadableEvent> event, 90 IDeliveryCacheProgressService(std::shared_ptr<Kernel::ReadableEvent> event,
91 const DeliveryCacheProgressImpl& impl) 91 const DeliveryCacheProgressImpl& impl)
92 : ServiceFramework{"IDeliveryCacheProgressService"}, event(std::move(event)), impl(impl) { 92 : ServiceFramework{"IDeliveryCacheProgressService"}, event(std::move(event)), impl(impl) {
93 // clang-format off 93 // clang-format off
@@ -118,7 +118,7 @@ private:
118 rb.Push(RESULT_SUCCESS); 118 rb.Push(RESULT_SUCCESS);
119 } 119 }
120 120
121 Kernel::SharedPtr<Kernel::ReadableEvent> event; 121 std::shared_ptr<Kernel::ReadableEvent> event;
122 const DeliveryCacheProgressImpl& impl; 122 const DeliveryCacheProgressImpl& impl;
123}; 123};
124 124
diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp
index 79fff517e..4d952adc0 100644
--- a/src/core/hle/service/hid/controllers/npad.cpp
+++ b/src/core/hle/service/hid/controllers/npad.cpp
@@ -501,8 +501,7 @@ void Controller_NPad::VibrateController(const std::vector<u32>& controller_ids,
501 last_processed_vibration = vibrations.back(); 501 last_processed_vibration = vibrations.back();
502} 502}
503 503
504Kernel::SharedPtr<Kernel::ReadableEvent> Controller_NPad::GetStyleSetChangedEvent( 504std::shared_ptr<Kernel::ReadableEvent> Controller_NPad::GetStyleSetChangedEvent(u32 npad_id) const {
505 u32 npad_id) const {
506 // TODO(ogniK): Figure out the best time to signal this event. This event seems that it should 505 // TODO(ogniK): Figure out the best time to signal this event. This event seems that it should
507 // be signalled at least once, and signaled after a new controller is connected? 506 // be signalled at least once, and signaled after a new controller is connected?
508 const auto& styleset_event = styleset_changed_events[NPadIdToIndex(npad_id)]; 507 const auto& styleset_event = styleset_changed_events[NPadIdToIndex(npad_id)];
diff --git a/src/core/hle/service/hid/controllers/npad.h b/src/core/hle/service/hid/controllers/npad.h
index 16c4caa1f..931f03430 100644
--- a/src/core/hle/service/hid/controllers/npad.h
+++ b/src/core/hle/service/hid/controllers/npad.h
@@ -109,7 +109,7 @@ public:
109 void VibrateController(const std::vector<u32>& controller_ids, 109 void VibrateController(const std::vector<u32>& controller_ids,
110 const std::vector<Vibration>& vibrations); 110 const std::vector<Vibration>& vibrations);
111 111
112 Kernel::SharedPtr<Kernel::ReadableEvent> GetStyleSetChangedEvent(u32 npad_id) const; 112 std::shared_ptr<Kernel::ReadableEvent> GetStyleSetChangedEvent(u32 npad_id) const;
113 Vibration GetLastVibration() const; 113 Vibration GetLastVibration() const;
114 114
115 void AddNewController(NPadControllerType controller); 115 void AddNewController(NPadControllerType controller);
diff --git a/src/core/hle/service/hid/hid.h b/src/core/hle/service/hid/hid.h
index f08e036a3..923762fff 100644
--- a/src/core/hle/service/hid/hid.h
+++ b/src/core/hle/service/hid/hid.h
@@ -67,7 +67,7 @@ private:
67 void GetSharedMemoryHandle(Kernel::HLERequestContext& ctx); 67 void GetSharedMemoryHandle(Kernel::HLERequestContext& ctx);
68 void UpdateControllers(u64 userdata, s64 cycles_late); 68 void UpdateControllers(u64 userdata, s64 cycles_late);
69 69
70 Kernel::SharedPtr<Kernel::SharedMemory> shared_mem; 70 std::shared_ptr<Kernel::SharedMemory> shared_mem;
71 71
72 Core::Timing::EventType* pad_update_event; 72 Core::Timing::EventType* pad_update_event;
73 Core::System& system; 73 Core::System& system;
diff --git a/src/core/hle/service/hid/irs.h b/src/core/hle/service/hid/irs.h
index eb4e898dd..8918ad6ca 100644
--- a/src/core/hle/service/hid/irs.h
+++ b/src/core/hle/service/hid/irs.h
@@ -37,7 +37,7 @@ private:
37 void RunIrLedProcessor(Kernel::HLERequestContext& ctx); 37 void RunIrLedProcessor(Kernel::HLERequestContext& ctx);
38 void StopImageProcessorAsync(Kernel::HLERequestContext& ctx); 38 void StopImageProcessorAsync(Kernel::HLERequestContext& ctx);
39 void ActivateIrsensorWithFunctionLevel(Kernel::HLERequestContext& ctx); 39 void ActivateIrsensorWithFunctionLevel(Kernel::HLERequestContext& ctx);
40 Kernel::SharedPtr<Kernel::SharedMemory> shared_mem; 40 std::shared_ptr<Kernel::SharedMemory> shared_mem;
41 const u32 device_handle{0xABCD}; 41 const u32 device_handle{0xABCD};
42 Core::System& system; 42 Core::System& system;
43}; 43};
diff --git a/src/core/hle/service/nfp/nfp.cpp b/src/core/hle/service/nfp/nfp.cpp
index 3bf753dee..ec0367978 100644
--- a/src/core/hle/service/nfp/nfp.cpp
+++ b/src/core/hle/service/nfp/nfp.cpp
@@ -342,7 +342,7 @@ bool Module::Interface::LoadAmiibo(const std::vector<u8>& buffer) {
342 return true; 342 return true;
343} 343}
344 344
345const Kernel::SharedPtr<Kernel::ReadableEvent>& Module::Interface::GetNFCEvent() const { 345const std::shared_ptr<Kernel::ReadableEvent>& Module::Interface::GetNFCEvent() const {
346 return nfc_tag_load.readable; 346 return nfc_tag_load.readable;
347} 347}
348 348
diff --git a/src/core/hle/service/nfp/nfp.h b/src/core/hle/service/nfp/nfp.h
index 9718ef745..200013795 100644
--- a/src/core/hle/service/nfp/nfp.h
+++ b/src/core/hle/service/nfp/nfp.h
@@ -34,7 +34,7 @@ public:
34 34
35 void CreateUserInterface(Kernel::HLERequestContext& ctx); 35 void CreateUserInterface(Kernel::HLERequestContext& ctx);
36 bool LoadAmiibo(const std::vector<u8>& buffer); 36 bool LoadAmiibo(const std::vector<u8>& buffer);
37 const Kernel::SharedPtr<Kernel::ReadableEvent>& GetNFCEvent() const; 37 const std::shared_ptr<Kernel::ReadableEvent>& GetNFCEvent() const;
38 const AmiiboFile& GetAmiiboBuffer() const; 38 const AmiiboFile& GetAmiiboBuffer() const;
39 39
40 private: 40 private:
diff --git a/src/core/hle/service/ns/pl_u.cpp b/src/core/hle/service/ns/pl_u.cpp
index db433305f..8dc103bf0 100644
--- a/src/core/hle/service/ns/pl_u.cpp
+++ b/src/core/hle/service/ns/pl_u.cpp
@@ -141,7 +141,7 @@ struct PL_U::Impl {
141 } 141 }
142 142
143 /// Handle to shared memory region designated for a shared font 143 /// Handle to shared memory region designated for a shared font
144 Kernel::SharedPtr<Kernel::SharedMemory> shared_font_mem; 144 std::shared_ptr<Kernel::SharedMemory> shared_font_mem;
145 145
146 /// Backing memory for the shared font data 146 /// Backing memory for the shared font data
147 std::shared_ptr<Kernel::PhysicalMemory> shared_font; 147 std::shared_ptr<Kernel::PhysicalMemory> shared_font;
diff --git a/src/core/hle/service/nvdrv/interface.cpp b/src/core/hle/service/nvdrv/interface.cpp
index 68d139cfb..c8ea6c661 100644
--- a/src/core/hle/service/nvdrv/interface.cpp
+++ b/src/core/hle/service/nvdrv/interface.cpp
@@ -61,7 +61,7 @@ void NVDRV::IoctlBase(Kernel::HLERequestContext& ctx, IoctlVersion version) {
61 if (ctrl.must_delay) { 61 if (ctrl.must_delay) {
62 ctrl.fresh_call = false; 62 ctrl.fresh_call = false;
63 ctx.SleepClientThread("NVServices::DelayedResponse", ctrl.timeout, 63 ctx.SleepClientThread("NVServices::DelayedResponse", ctrl.timeout,
64 [=](Kernel::SharedPtr<Kernel::Thread> thread, 64 [=](std::shared_ptr<Kernel::Thread> thread,
65 Kernel::HLERequestContext& ctx, 65 Kernel::HLERequestContext& ctx,
66 Kernel::ThreadWakeupReason reason) { 66 Kernel::ThreadWakeupReason reason) {
67 IoctlCtrl ctrl2{ctrl}; 67 IoctlCtrl ctrl2{ctrl};
diff --git a/src/core/hle/service/nvdrv/nvdrv.cpp b/src/core/hle/service/nvdrv/nvdrv.cpp
index cc9cd3fd1..197c77db0 100644
--- a/src/core/hle/service/nvdrv/nvdrv.cpp
+++ b/src/core/hle/service/nvdrv/nvdrv.cpp
@@ -100,11 +100,11 @@ void Module::SignalSyncpt(const u32 syncpoint_id, const u32 value) {
100 } 100 }
101} 101}
102 102
103Kernel::SharedPtr<Kernel::ReadableEvent> Module::GetEvent(const u32 event_id) const { 103std::shared_ptr<Kernel::ReadableEvent> Module::GetEvent(const u32 event_id) const {
104 return events_interface.events[event_id].readable; 104 return events_interface.events[event_id].readable;
105} 105}
106 106
107Kernel::SharedPtr<Kernel::WritableEvent> Module::GetEventWriteable(const u32 event_id) const { 107std::shared_ptr<Kernel::WritableEvent> Module::GetEventWriteable(const u32 event_id) const {
108 return events_interface.events[event_id].writable; 108 return events_interface.events[event_id].writable;
109} 109}
110 110
diff --git a/src/core/hle/service/nvdrv/nvdrv.h b/src/core/hle/service/nvdrv/nvdrv.h
index f8bb28969..d7a1bef91 100644
--- a/src/core/hle/service/nvdrv/nvdrv.h
+++ b/src/core/hle/service/nvdrv/nvdrv.h
@@ -114,9 +114,9 @@ public:
114 114
115 void SignalSyncpt(const u32 syncpoint_id, const u32 value); 115 void SignalSyncpt(const u32 syncpoint_id, const u32 value);
116 116
117 Kernel::SharedPtr<Kernel::ReadableEvent> GetEvent(u32 event_id) const; 117 std::shared_ptr<Kernel::ReadableEvent> GetEvent(u32 event_id) const;
118 118
119 Kernel::SharedPtr<Kernel::WritableEvent> GetEventWriteable(u32 event_id) const; 119 std::shared_ptr<Kernel::WritableEvent> GetEventWriteable(u32 event_id) const;
120 120
121private: 121private:
122 /// Id to use for the next open file descriptor. 122 /// Id to use for the next open file descriptor.
diff --git a/src/core/hle/service/nvflinger/buffer_queue.cpp b/src/core/hle/service/nvflinger/buffer_queue.cpp
index 1af11e80c..32b6f4b27 100644
--- a/src/core/hle/service/nvflinger/buffer_queue.cpp
+++ b/src/core/hle/service/nvflinger/buffer_queue.cpp
@@ -117,11 +117,11 @@ u32 BufferQueue::Query(QueryType type) {
117 return 0; 117 return 0;
118} 118}
119 119
120Kernel::SharedPtr<Kernel::WritableEvent> BufferQueue::GetWritableBufferWaitEvent() const { 120std::shared_ptr<Kernel::WritableEvent> BufferQueue::GetWritableBufferWaitEvent() const {
121 return buffer_wait_event.writable; 121 return buffer_wait_event.writable;
122} 122}
123 123
124Kernel::SharedPtr<Kernel::ReadableEvent> BufferQueue::GetBufferWaitEvent() const { 124std::shared_ptr<Kernel::ReadableEvent> BufferQueue::GetBufferWaitEvent() const {
125 return buffer_wait_event.readable; 125 return buffer_wait_event.readable;
126} 126}
127 127
diff --git a/src/core/hle/service/nvflinger/buffer_queue.h b/src/core/hle/service/nvflinger/buffer_queue.h
index 8f9b18547..f4bbfd945 100644
--- a/src/core/hle/service/nvflinger/buffer_queue.h
+++ b/src/core/hle/service/nvflinger/buffer_queue.h
@@ -93,9 +93,9 @@ public:
93 return id; 93 return id;
94 } 94 }
95 95
96 Kernel::SharedPtr<Kernel::WritableEvent> GetWritableBufferWaitEvent() const; 96 std::shared_ptr<Kernel::WritableEvent> GetWritableBufferWaitEvent() const;
97 97
98 Kernel::SharedPtr<Kernel::ReadableEvent> GetBufferWaitEvent() const; 98 std::shared_ptr<Kernel::ReadableEvent> GetBufferWaitEvent() const;
99 99
100private: 100private:
101 u32 id; 101 u32 id;
diff --git a/src/core/hle/service/nvflinger/nvflinger.cpp b/src/core/hle/service/nvflinger/nvflinger.cpp
index cc9522aad..cd07ab362 100644
--- a/src/core/hle/service/nvflinger/nvflinger.cpp
+++ b/src/core/hle/service/nvflinger/nvflinger.cpp
@@ -98,7 +98,7 @@ std::optional<u32> NVFlinger::FindBufferQueueId(u64 display_id, u64 layer_id) co
98 return layer->GetBufferQueue().GetId(); 98 return layer->GetBufferQueue().GetId();
99} 99}
100 100
101Kernel::SharedPtr<Kernel::ReadableEvent> NVFlinger::FindVsyncEvent(u64 display_id) const { 101std::shared_ptr<Kernel::ReadableEvent> NVFlinger::FindVsyncEvent(u64 display_id) const {
102 auto* const display = FindDisplay(display_id); 102 auto* const display = FindDisplay(display_id);
103 103
104 if (display == nullptr) { 104 if (display == nullptr) {
diff --git a/src/core/hle/service/nvflinger/nvflinger.h b/src/core/hle/service/nvflinger/nvflinger.h
index 5d7e3bfb8..9cc41f2e6 100644
--- a/src/core/hle/service/nvflinger/nvflinger.h
+++ b/src/core/hle/service/nvflinger/nvflinger.h
@@ -62,7 +62,7 @@ public:
62 /// Gets the vsync event for the specified display. 62 /// Gets the vsync event for the specified display.
63 /// 63 ///
64 /// If an invalid display ID is provided, then nullptr is returned. 64 /// If an invalid display ID is provided, then nullptr is returned.
65 Kernel::SharedPtr<Kernel::ReadableEvent> FindVsyncEvent(u64 display_id) const; 65 std::shared_ptr<Kernel::ReadableEvent> FindVsyncEvent(u64 display_id) const;
66 66
67 /// Obtains a buffer queue identified by the ID. 67 /// Obtains a buffer queue identified by the ID.
68 BufferQueue& FindBufferQueue(u32 id); 68 BufferQueue& FindBufferQueue(u32 id);
diff --git a/src/core/hle/service/pm/pm.cpp b/src/core/hle/service/pm/pm.cpp
index fe6b5f798..38b569da2 100644
--- a/src/core/hle/service/pm/pm.cpp
+++ b/src/core/hle/service/pm/pm.cpp
@@ -16,9 +16,9 @@ constexpr ResultCode ERROR_PROCESS_NOT_FOUND{ErrorModule::PM, 1};
16 16
17constexpr u64 NO_PROCESS_FOUND_PID{0}; 17constexpr u64 NO_PROCESS_FOUND_PID{0};
18 18
19std::optional<Kernel::SharedPtr<Kernel::Process>> SearchProcessList( 19std::optional<std::shared_ptr<Kernel::Process>> SearchProcessList(
20 const std::vector<Kernel::SharedPtr<Kernel::Process>>& process_list, 20 const std::vector<std::shared_ptr<Kernel::Process>>& process_list,
21 std::function<bool(const Kernel::SharedPtr<Kernel::Process>&)> predicate) { 21 std::function<bool(const std::shared_ptr<Kernel::Process>&)> predicate) {
22 const auto iter = std::find_if(process_list.begin(), process_list.end(), predicate); 22 const auto iter = std::find_if(process_list.begin(), process_list.end(), predicate);
23 23
24 if (iter == process_list.end()) { 24 if (iter == process_list.end()) {
@@ -29,7 +29,7 @@ std::optional<Kernel::SharedPtr<Kernel::Process>> SearchProcessList(
29} 29}
30 30
31void GetApplicationPidGeneric(Kernel::HLERequestContext& ctx, 31void GetApplicationPidGeneric(Kernel::HLERequestContext& ctx,
32 const std::vector<Kernel::SharedPtr<Kernel::Process>>& process_list) { 32 const std::vector<std::shared_ptr<Kernel::Process>>& process_list) {
33 const auto process = SearchProcessList(process_list, [](const auto& process) { 33 const auto process = SearchProcessList(process_list, [](const auto& process) {
34 return process->GetProcessID() == Kernel::Process::ProcessIDMin; 34 return process->GetProcessID() == Kernel::Process::ProcessIDMin;
35 }); 35 });
@@ -124,7 +124,7 @@ private:
124 124
125class Info final : public ServiceFramework<Info> { 125class Info final : public ServiceFramework<Info> {
126public: 126public:
127 explicit Info(const std::vector<Kernel::SharedPtr<Kernel::Process>>& process_list) 127 explicit Info(const std::vector<std::shared_ptr<Kernel::Process>>& process_list)
128 : ServiceFramework{"pm:info"}, process_list(process_list) { 128 : ServiceFramework{"pm:info"}, process_list(process_list) {
129 static const FunctionInfo functions[] = { 129 static const FunctionInfo functions[] = {
130 {0, &Info::GetTitleId, "GetTitleId"}, 130 {0, &Info::GetTitleId, "GetTitleId"},
@@ -154,7 +154,7 @@ private:
154 rb.Push((*process)->GetTitleID()); 154 rb.Push((*process)->GetTitleID());
155 } 155 }
156 156
157 const std::vector<Kernel::SharedPtr<Kernel::Process>>& process_list; 157 const std::vector<std::shared_ptr<Kernel::Process>>& process_list;
158}; 158};
159 159
160class Shell final : public ServiceFramework<Shell> { 160class Shell final : public ServiceFramework<Shell> {
diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp
index 7c5302017..5698f429f 100644
--- a/src/core/hle/service/service.cpp
+++ b/src/core/hle/service/service.cpp
@@ -116,7 +116,7 @@ void ServiceFrameworkBase::InstallAsNamedPort() {
116 port_installed = true; 116 port_installed = true;
117} 117}
118 118
119Kernel::SharedPtr<Kernel::ClientPort> ServiceFrameworkBase::CreatePort() { 119std::shared_ptr<Kernel::ClientPort> ServiceFrameworkBase::CreatePort() {
120 ASSERT(!port_installed); 120 ASSERT(!port_installed);
121 121
122 auto& kernel = Core::System::GetInstance().Kernel(); 122 auto& kernel = Core::System::GetInstance().Kernel();
diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.h
index aef964861..022d885b6 100644
--- a/src/core/hle/service/service.h
+++ b/src/core/hle/service/service.h
@@ -65,7 +65,7 @@ public:
65 /// Creates a port pair and registers it on the kernel's global port registry. 65 /// Creates a port pair and registers it on the kernel's global port registry.
66 void InstallAsNamedPort(); 66 void InstallAsNamedPort();
67 /// Creates and returns an unregistered port for the service. 67 /// Creates and returns an unregistered port for the service.
68 Kernel::SharedPtr<Kernel::ClientPort> CreatePort(); 68 std::shared_ptr<Kernel::ClientPort> CreatePort();
69 69
70 void InvokeRequest(Kernel::HLERequestContext& ctx); 70 void InvokeRequest(Kernel::HLERequestContext& ctx);
71 71
diff --git a/src/core/hle/service/sm/controller.cpp b/src/core/hle/service/sm/controller.cpp
index e9ee73710..af2fadcef 100644
--- a/src/core/hle/service/sm/controller.cpp
+++ b/src/core/hle/service/sm/controller.cpp
@@ -30,7 +30,7 @@ void Controller::DuplicateSession(Kernel::HLERequestContext& ctx) {
30 30
31 IPC::ResponseBuilder rb{ctx, 2, 0, 1, IPC::ResponseBuilder::Flags::AlwaysMoveHandles}; 31 IPC::ResponseBuilder rb{ctx, 2, 0, 1, IPC::ResponseBuilder::Flags::AlwaysMoveHandles};
32 rb.Push(RESULT_SUCCESS); 32 rb.Push(RESULT_SUCCESS);
33 Kernel::SharedPtr<Kernel::ClientSession> session{ctx.Session()->GetParent()->client}; 33 std::shared_ptr<Kernel::ClientSession> session{ctx.Session()->GetParent()->client};
34 rb.PushMoveObjects(session); 34 rb.PushMoveObjects(session);
35 35
36 LOG_DEBUG(Service, "session={}", session->GetObjectId()); 36 LOG_DEBUG(Service, "session={}", session->GetObjectId());
diff --git a/src/core/hle/service/sm/sm.cpp b/src/core/hle/service/sm/sm.cpp
index 142929124..a0a7206bb 100644
--- a/src/core/hle/service/sm/sm.cpp
+++ b/src/core/hle/service/sm/sm.cpp
@@ -45,7 +45,7 @@ void ServiceManager::InstallInterfaces(std::shared_ptr<ServiceManager> self) {
45 self->controller_interface = std::make_unique<Controller>(); 45 self->controller_interface = std::make_unique<Controller>();
46} 46}
47 47
48ResultVal<Kernel::SharedPtr<Kernel::ServerPort>> ServiceManager::RegisterService( 48ResultVal<std::shared_ptr<Kernel::ServerPort>> ServiceManager::RegisterService(
49 std::string name, unsigned int max_sessions) { 49 std::string name, unsigned int max_sessions) {
50 50
51 CASCADE_CODE(ValidateServiceName(name)); 51 CASCADE_CODE(ValidateServiceName(name));
@@ -72,7 +72,7 @@ ResultCode ServiceManager::UnregisterService(const std::string& name) {
72 return RESULT_SUCCESS; 72 return RESULT_SUCCESS;
73} 73}
74 74
75ResultVal<Kernel::SharedPtr<Kernel::ClientPort>> ServiceManager::GetServicePort( 75ResultVal<std::shared_ptr<Kernel::ClientPort>> ServiceManager::GetServicePort(
76 const std::string& name) { 76 const std::string& name) {
77 77
78 CASCADE_CODE(ValidateServiceName(name)); 78 CASCADE_CODE(ValidateServiceName(name));
@@ -84,7 +84,7 @@ ResultVal<Kernel::SharedPtr<Kernel::ClientPort>> ServiceManager::GetServicePort(
84 return MakeResult(it->second); 84 return MakeResult(it->second);
85} 85}
86 86
87ResultVal<Kernel::SharedPtr<Kernel::ClientSession>> ServiceManager::ConnectToService( 87ResultVal<std::shared_ptr<Kernel::ClientSession>> ServiceManager::ConnectToService(
88 const std::string& name) { 88 const std::string& name) {
89 89
90 CASCADE_RESULT(auto client_port, GetServicePort(name)); 90 CASCADE_RESULT(auto client_port, GetServicePort(name));
diff --git a/src/core/hle/service/sm/sm.h b/src/core/hle/service/sm/sm.h
index b9d6381b4..3de22268b 100644
--- a/src/core/hle/service/sm/sm.h
+++ b/src/core/hle/service/sm/sm.h
@@ -48,11 +48,11 @@ public:
48 ServiceManager(); 48 ServiceManager();
49 ~ServiceManager(); 49 ~ServiceManager();
50 50
51 ResultVal<Kernel::SharedPtr<Kernel::ServerPort>> RegisterService(std::string name, 51 ResultVal<std::shared_ptr<Kernel::ServerPort>> RegisterService(std::string name,
52 unsigned int max_sessions); 52 unsigned int max_sessions);
53 ResultCode UnregisterService(const std::string& name); 53 ResultCode UnregisterService(const std::string& name);
54 ResultVal<Kernel::SharedPtr<Kernel::ClientPort>> GetServicePort(const std::string& name); 54 ResultVal<std::shared_ptr<Kernel::ClientPort>> GetServicePort(const std::string& name);
55 ResultVal<Kernel::SharedPtr<Kernel::ClientSession>> ConnectToService(const std::string& name); 55 ResultVal<std::shared_ptr<Kernel::ClientSession>> ConnectToService(const std::string& name);
56 56
57 template <typename T> 57 template <typename T>
58 std::shared_ptr<T> GetService(const std::string& service_name) const { 58 std::shared_ptr<T> GetService(const std::string& service_name) const {
@@ -77,7 +77,7 @@ private:
77 std::unique_ptr<Controller> controller_interface; 77 std::unique_ptr<Controller> controller_interface;
78 78
79 /// Map of registered services, retrieved using GetServicePort or ConnectToService. 79 /// Map of registered services, retrieved using GetServicePort or ConnectToService.
80 std::unordered_map<std::string, Kernel::SharedPtr<Kernel::ClientPort>> registered_services; 80 std::unordered_map<std::string, std::shared_ptr<Kernel::ClientPort>> registered_services;
81}; 81};
82 82
83} // namespace Service::SM 83} // namespace Service::SM
diff --git a/src/core/hle/service/time/time_sharedmemory.cpp b/src/core/hle/service/time/time_sharedmemory.cpp
index bfc81b83c..4035f5072 100644
--- a/src/core/hle/service/time/time_sharedmemory.cpp
+++ b/src/core/hle/service/time/time_sharedmemory.cpp
@@ -21,7 +21,7 @@ SharedMemory::SharedMemory(Core::System& system) : system(system) {
21 21
22SharedMemory::~SharedMemory() = default; 22SharedMemory::~SharedMemory() = default;
23 23
24Kernel::SharedPtr<Kernel::SharedMemory> SharedMemory::GetSharedMemoryHolder() const { 24std::shared_ptr<Kernel::SharedMemory> SharedMemory::GetSharedMemoryHolder() const {
25 return shared_memory_holder; 25 return shared_memory_holder;
26} 26}
27 27
diff --git a/src/core/hle/service/time/time_sharedmemory.h b/src/core/hle/service/time/time_sharedmemory.h
index cb8253541..904a96430 100644
--- a/src/core/hle/service/time/time_sharedmemory.h
+++ b/src/core/hle/service/time/time_sharedmemory.h
@@ -15,7 +15,7 @@ public:
15 ~SharedMemory(); 15 ~SharedMemory();
16 16
17 // Return the shared memory handle 17 // Return the shared memory handle
18 Kernel::SharedPtr<Kernel::SharedMemory> GetSharedMemoryHolder() const; 18 std::shared_ptr<Kernel::SharedMemory> GetSharedMemoryHolder() const;
19 19
20 // Set memory barriers in shared memory and update them 20 // Set memory barriers in shared memory and update them
21 void SetStandardSteadyClockTimepoint(const SteadyClockTimePoint& timepoint); 21 void SetStandardSteadyClockTimepoint(const SteadyClockTimePoint& timepoint);
@@ -66,7 +66,7 @@ public:
66 static_assert(sizeof(Format) == 0xd8, "Format is an invalid size"); 66 static_assert(sizeof(Format) == 0xd8, "Format is an invalid size");
67 67
68private: 68private:
69 Kernel::SharedPtr<Kernel::SharedMemory> shared_memory_holder{}; 69 std::shared_ptr<Kernel::SharedMemory> shared_memory_holder{};
70 Core::System& system; 70 Core::System& system;
71 Format shared_memory_format{}; 71 Format shared_memory_format{};
72}; 72};
diff --git a/src/core/hle/service/vi/display/vi_display.cpp b/src/core/hle/service/vi/display/vi_display.cpp
index 07033fb98..cd18c1610 100644
--- a/src/core/hle/service/vi/display/vi_display.cpp
+++ b/src/core/hle/service/vi/display/vi_display.cpp
@@ -31,7 +31,7 @@ const Layer& Display::GetLayer(std::size_t index) const {
31 return layers.at(index); 31 return layers.at(index);
32} 32}
33 33
34Kernel::SharedPtr<Kernel::ReadableEvent> Display::GetVSyncEvent() const { 34std::shared_ptr<Kernel::ReadableEvent> Display::GetVSyncEvent() const {
35 return vsync_event.readable; 35 return vsync_event.readable;
36} 36}
37 37
diff --git a/src/core/hle/service/vi/display/vi_display.h b/src/core/hle/service/vi/display/vi_display.h
index f56b5badc..8bb966a85 100644
--- a/src/core/hle/service/vi/display/vi_display.h
+++ b/src/core/hle/service/vi/display/vi_display.h
@@ -57,7 +57,7 @@ public:
57 const Layer& GetLayer(std::size_t index) const; 57 const Layer& GetLayer(std::size_t index) const;
58 58
59 /// Gets the readable vsync event. 59 /// Gets the readable vsync event.
60 Kernel::SharedPtr<Kernel::ReadableEvent> GetVSyncEvent() const; 60 std::shared_ptr<Kernel::ReadableEvent> GetVSyncEvent() const;
61 61
62 /// Signals the internal vsync event. 62 /// Signals the internal vsync event.
63 void SignalVSyncEvent(); 63 void SignalVSyncEvent();
diff --git a/src/core/hle/service/vi/vi.cpp b/src/core/hle/service/vi/vi.cpp
index abfc3a801..4cab49071 100644
--- a/src/core/hle/service/vi/vi.cpp
+++ b/src/core/hle/service/vi/vi.cpp
@@ -542,7 +542,7 @@ private:
542 // Wait the current thread until a buffer becomes available 542 // Wait the current thread until a buffer becomes available
543 ctx.SleepClientThread( 543 ctx.SleepClientThread(
544 "IHOSBinderDriver::DequeueBuffer", UINT64_MAX, 544 "IHOSBinderDriver::DequeueBuffer", UINT64_MAX,
545 [=](Kernel::SharedPtr<Kernel::Thread> thread, Kernel::HLERequestContext& ctx, 545 [=](std::shared_ptr<Kernel::Thread> thread, Kernel::HLERequestContext& ctx,
546 Kernel::ThreadWakeupReason reason) { 546 Kernel::ThreadWakeupReason reason) {
547 // Repeat TransactParcel DequeueBuffer when a buffer is available 547 // Repeat TransactParcel DequeueBuffer when a buffer is available
548 auto& buffer_queue = nv_flinger->FindBufferQueue(id); 548 auto& buffer_queue = nv_flinger->FindBufferQueue(id);
diff --git a/src/yuzu/debugger/wait_tree.cpp b/src/yuzu/debugger/wait_tree.cpp
index 188f798c0..535b3ce90 100644
--- a/src/yuzu/debugger/wait_tree.cpp
+++ b/src/yuzu/debugger/wait_tree.cpp
@@ -57,7 +57,7 @@ std::size_t WaitTreeItem::Row() const {
57std::vector<std::unique_ptr<WaitTreeThread>> WaitTreeItem::MakeThreadItemList() { 57std::vector<std::unique_ptr<WaitTreeThread>> WaitTreeItem::MakeThreadItemList() {
58 std::vector<std::unique_ptr<WaitTreeThread>> item_list; 58 std::vector<std::unique_ptr<WaitTreeThread>> item_list;
59 std::size_t row = 0; 59 std::size_t row = 0;
60 auto add_threads = [&](const std::vector<Kernel::SharedPtr<Kernel::Thread>>& threads) { 60 auto add_threads = [&](const std::vector<std::shared_ptr<Kernel::Thread>>& threads) {
61 for (std::size_t i = 0; i < threads.size(); ++i) { 61 for (std::size_t i = 0; i < threads.size(); ++i) {
62 item_list.push_back(std::make_unique<WaitTreeThread>(*threads[i])); 62 item_list.push_back(std::make_unique<WaitTreeThread>(*threads[i]));
63 item_list.back()->row = row; 63 item_list.back()->row = row;
@@ -172,8 +172,8 @@ std::vector<std::unique_ptr<WaitTreeItem>> WaitTreeWaitObject::GetChildren() con
172 return list; 172 return list;
173} 173}
174 174
175WaitTreeObjectList::WaitTreeObjectList( 175WaitTreeObjectList::WaitTreeObjectList(const std::vector<std::shared_ptr<Kernel::WaitObject>>& list,
176 const std::vector<Kernel::SharedPtr<Kernel::WaitObject>>& list, bool w_all) 176 bool w_all)
177 : object_list(list), wait_all(w_all) {} 177 : object_list(list), wait_all(w_all) {}
178 178
179WaitTreeObjectList::~WaitTreeObjectList() = default; 179WaitTreeObjectList::~WaitTreeObjectList() = default;
@@ -325,7 +325,7 @@ std::vector<std::unique_ptr<WaitTreeItem>> WaitTreeThread::GetChildren() const {
325WaitTreeEvent::WaitTreeEvent(const Kernel::ReadableEvent& object) : WaitTreeWaitObject(object) {} 325WaitTreeEvent::WaitTreeEvent(const Kernel::ReadableEvent& object) : WaitTreeWaitObject(object) {}
326WaitTreeEvent::~WaitTreeEvent() = default; 326WaitTreeEvent::~WaitTreeEvent() = default;
327 327
328WaitTreeThreadList::WaitTreeThreadList(const std::vector<Kernel::SharedPtr<Kernel::Thread>>& list) 328WaitTreeThreadList::WaitTreeThreadList(const std::vector<std::shared_ptr<Kernel::Thread>>& list)
329 : thread_list(list) {} 329 : thread_list(list) {}
330WaitTreeThreadList::~WaitTreeThreadList() = default; 330WaitTreeThreadList::~WaitTreeThreadList() = default;
331 331
diff --git a/src/yuzu/debugger/wait_tree.h b/src/yuzu/debugger/wait_tree.h
index f2b13be24..631274a5f 100644
--- a/src/yuzu/debugger/wait_tree.h
+++ b/src/yuzu/debugger/wait_tree.h
@@ -83,7 +83,7 @@ private:
83 VAddr mutex_address; 83 VAddr mutex_address;
84 u32 mutex_value; 84 u32 mutex_value;
85 Kernel::Handle owner_handle; 85 Kernel::Handle owner_handle;
86 Kernel::SharedPtr<Kernel::Thread> owner; 86 std::shared_ptr<Kernel::Thread> owner;
87}; 87};
88 88
89class WaitTreeCallstack : public WaitTreeExpandableItem { 89class WaitTreeCallstack : public WaitTreeExpandableItem {
@@ -116,15 +116,14 @@ protected:
116class WaitTreeObjectList : public WaitTreeExpandableItem { 116class WaitTreeObjectList : public WaitTreeExpandableItem {
117 Q_OBJECT 117 Q_OBJECT
118public: 118public:
119 WaitTreeObjectList(const std::vector<Kernel::SharedPtr<Kernel::WaitObject>>& list, 119 WaitTreeObjectList(const std::vector<std::shared_ptr<Kernel::WaitObject>>& list, bool wait_all);
120 bool wait_all);
121 ~WaitTreeObjectList() override; 120 ~WaitTreeObjectList() override;
122 121
123 QString GetText() const override; 122 QString GetText() const override;
124 std::vector<std::unique_ptr<WaitTreeItem>> GetChildren() const override; 123 std::vector<std::unique_ptr<WaitTreeItem>> GetChildren() const override;
125 124
126private: 125private:
127 const std::vector<Kernel::SharedPtr<Kernel::WaitObject>>& object_list; 126 const std::vector<std::shared_ptr<Kernel::WaitObject>>& object_list;
128 bool wait_all; 127 bool wait_all;
129}; 128};
130 129
@@ -149,14 +148,14 @@ public:
149class WaitTreeThreadList : public WaitTreeExpandableItem { 148class WaitTreeThreadList : public WaitTreeExpandableItem {
150 Q_OBJECT 149 Q_OBJECT
151public: 150public:
152 explicit WaitTreeThreadList(const std::vector<Kernel::SharedPtr<Kernel::Thread>>& list); 151 explicit WaitTreeThreadList(const std::vector<std::shared_ptr<Kernel::Thread>>& list);
153 ~WaitTreeThreadList() override; 152 ~WaitTreeThreadList() override;
154 153
155 QString GetText() const override; 154 QString GetText() const override;
156 std::vector<std::unique_ptr<WaitTreeItem>> GetChildren() const override; 155 std::vector<std::unique_ptr<WaitTreeItem>> GetChildren() const override;
157 156
158private: 157private:
159 const std::vector<Kernel::SharedPtr<Kernel::Thread>>& thread_list; 158 const std::vector<std::shared_ptr<Kernel::Thread>>& thread_list;
160}; 159};
161 160
162class WaitTreeModel : public QAbstractItemModel { 161class WaitTreeModel : public QAbstractItemModel {