diff --git a/src/citra_qt/debugger/wait_tree.cpp b/src/citra_qt/debugger/wait_tree.cpp index 15dc90ba07..7a208882cb 100644 --- a/src/citra_qt/debugger/wait_tree.cpp +++ b/src/citra_qt/debugger/wait_tree.cpp @@ -123,8 +123,8 @@ QString WaitTreeWaitObject::GetResetTypeQString(Kernel::ResetType reset_type) { return {}; } -WaitTreeObjectList::WaitTreeObjectList( - const std::vector>& list, bool w_all) +WaitTreeObjectList::WaitTreeObjectList(const std::vector>& list, + bool w_all) : object_list(list), wait_all(w_all) {} QString WaitTreeObjectList::GetText() const { @@ -311,7 +311,7 @@ std::vector> WaitTreeTimer::GetChildren() const { } WaitTreeMutexList::WaitTreeMutexList( - const boost::container::flat_set>& list) + const boost::container::flat_set>& list) : mutex_list(list) {} QString WaitTreeMutexList::GetText() const { @@ -325,7 +325,7 @@ std::vector> WaitTreeMutexList::GetChildren() cons return list; } -WaitTreeThreadList::WaitTreeThreadList(const std::vector>& list) +WaitTreeThreadList::WaitTreeThreadList(const std::vector>& list) : thread_list(list) {} QString WaitTreeThreadList::GetText() const { diff --git a/src/citra_qt/debugger/wait_tree.h b/src/citra_qt/debugger/wait_tree.h index 469072a301..8c8688c28d 100644 --- a/src/citra_qt/debugger/wait_tree.h +++ b/src/citra_qt/debugger/wait_tree.h @@ -82,13 +82,12 @@ protected: class WaitTreeObjectList : public WaitTreeExpandableItem { Q_OBJECT public: - WaitTreeObjectList(const std::vector>& list, - bool wait_all); + WaitTreeObjectList(const std::vector>& list, bool wait_all); QString GetText() const override; std::vector> GetChildren() const override; private: - const std::vector>& object_list; + const std::vector>& object_list; bool wait_all; }; @@ -133,24 +132,24 @@ class WaitTreeMutexList : public WaitTreeExpandableItem { Q_OBJECT public: explicit WaitTreeMutexList( - const boost::container::flat_set>& list); + const boost::container::flat_set>& list); QString GetText() const override; std::vector> GetChildren() const override; private: - const boost::container::flat_set>& mutex_list; + const boost::container::flat_set>& mutex_list; }; class WaitTreeThreadList : public WaitTreeExpandableItem { Q_OBJECT public: - explicit WaitTreeThreadList(const std::vector>& list); + explicit WaitTreeThreadList(const std::vector>& list); QString GetText() const override; std::vector> GetChildren() const override; private: - const std::vector>& thread_list; + const std::vector>& thread_list; }; class WaitTreeModel : public QAbstractItemModel { diff --git a/src/core/core.cpp b/src/core/core.cpp index e3b320e3b9..a72c8a1e93 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -125,7 +125,7 @@ System::ResultStatus System::Load(EmuWindow& emu_window, const std::string& file return init_result; } - Kernel::SharedPtr process; + std::shared_ptr process; const Loader::ResultStatus load_result{app_loader->Load(process)}; kernel->SetCurrentProcess(process); if (Loader::ResultStatus::Success != load_result) { diff --git a/src/core/hle/applets/erreula.h b/src/core/hle/applets/erreula.h index 627b0f0d84..c879c5e050 100644 --- a/src/core/hle/applets/erreula.h +++ b/src/core/hle/applets/erreula.h @@ -22,7 +22,7 @@ private: /// This SharedMemory will be created when we receive the LibAppJustStarted message. /// It holds the framebuffer info retrieved by the application with /// GSPGPU::ImportDisplayCaptureInfo - Kernel::SharedPtr framebuffer_memory; + std::shared_ptr framebuffer_memory; }; } // namespace HLE::Applets diff --git a/src/core/hle/applets/mii_selector.h b/src/core/hle/applets/mii_selector.h index fb853baafc..c4a7dae190 100644 --- a/src/core/hle/applets/mii_selector.h +++ b/src/core/hle/applets/mii_selector.h @@ -4,10 +4,10 @@ #pragma once +#include #include "common/common_funcs.h" #include "common/common_types.h" #include "core/hle/applets/applet.h" -#include "core/hle/kernel/kernel.h" #include "core/hle/kernel/shared_memory.h" #include "core/hle/result.h" #include "core/hle/service/apt/apt.h" @@ -121,7 +121,7 @@ private: /// This SharedMemory will be created when we receive the LibAppJustStarted message. /// It holds the framebuffer info retrieved by the application with /// GSPGPU::ImportDisplayCaptureInfo - Kernel::SharedPtr framebuffer_memory; + std::shared_ptr framebuffer_memory; MiiConfig config; }; diff --git a/src/core/hle/applets/mint.h b/src/core/hle/applets/mint.h index 08d2adb674..cb250f1fa0 100644 --- a/src/core/hle/applets/mint.h +++ b/src/core/hle/applets/mint.h @@ -22,7 +22,7 @@ private: /// This SharedMemory will be created when we receive the Request message. /// It holds the framebuffer info retrieved by the application with /// GSPGPU::ImportDisplayCaptureInfo - Kernel::SharedPtr framebuffer_memory; + std::shared_ptr framebuffer_memory; }; } // namespace HLE::Applets diff --git a/src/core/hle/applets/swkbd.cpp b/src/core/hle/applets/swkbd.cpp index cdceccb1a4..3f209e9f4f 100644 --- a/src/core/hle/applets/swkbd.cpp +++ b/src/core/hle/applets/swkbd.cpp @@ -60,8 +60,7 @@ ResultCode SoftwareKeyboard::StartImpl(Service::APT::AppletStartupParameter cons "The size of the parameter (SoftwareKeyboardConfig) is wrong"); memcpy(&config, parameter.buffer.data(), parameter.buffer.size()); - text_memory = - boost::static_pointer_cast(parameter.object); + text_memory = std::static_pointer_cast(parameter.object); // TODO(Subv): Verify if this is the correct behavior memset(text_memory->GetPointer(), 0, text_memory->GetSize()); diff --git a/src/core/hle/applets/swkbd.h b/src/core/hle/applets/swkbd.h index 88a4d4ed59..b63871b2fb 100644 --- a/src/core/hle/applets/swkbd.h +++ b/src/core/hle/applets/swkbd.h @@ -4,11 +4,11 @@ #pragma once +#include #include "common/common_funcs.h" #include "common/common_types.h" #include "core/frontend/applets/swkbd.h" #include "core/hle/applets/applet.h" -#include "core/hle/kernel/kernel.h" #include "core/hle/kernel/shared_memory.h" #include "core/hle/result.h" #include "core/hle/service/apt/apt.h" @@ -199,10 +199,10 @@ private: /// This SharedMemory will be created when we receive the LibAppJustStarted message. /// It holds the framebuffer info retrieved by the application with /// GSPGPU::ImportDisplayCaptureInfo - Kernel::SharedPtr framebuffer_memory; + std::shared_ptr framebuffer_memory; /// SharedMemory where the output text will be stored - Kernel::SharedPtr text_memory; + std::shared_ptr text_memory; /// Configuration of this instance of the SoftwareKeyboard, as received from the application SoftwareKeyboardConfig config; diff --git a/src/core/hle/ipc_helpers.h b/src/core/hle/ipc_helpers.h index a9304f6e2d..01282a69b0 100644 --- a/src/core/hle/ipc_helpers.h +++ b/src/core/hle/ipc_helpers.h @@ -5,13 +5,13 @@ #pragma once #include +#include #include #include #include #include #include "core/hle/ipc.h" #include "core/hle/kernel/hle_ipc.h" -#include "core/hle/kernel/kernel.h" namespace IPC { @@ -88,10 +88,10 @@ public: // TODO : ensure that translate params are added after all regular params template - void PushCopyObjects(Kernel::SharedPtr... pointers); + void PushCopyObjects(std::shared_ptr... pointers); template - void PushMoveObjects(Kernel::SharedPtr... pointers); + void PushMoveObjects(std::shared_ptr... pointers); void PushStaticBuffer(const std::vector& buffer, u8 buffer_id); @@ -170,12 +170,12 @@ inline void RequestBuilder::PushMoveHLEHandles(H... handles) { } template -inline void RequestBuilder::PushCopyObjects(Kernel::SharedPtr... pointers) { +inline void RequestBuilder::PushCopyObjects(std::shared_ptr... pointers) { PushCopyHLEHandles(context->AddOutgoingHandle(std::move(pointers))...); } template -inline void RequestBuilder::PushMoveObjects(Kernel::SharedPtr... pointers) { +inline void RequestBuilder::PushMoveObjects(std::shared_ptr... pointers) { PushMoveHLEHandles(context->AddOutgoingHandle(std::move(pointers))...); } @@ -233,11 +233,11 @@ public: } /// Equivalent to calling `PopGenericObjects<1>()[0]`. - Kernel::SharedPtr PopGenericObject(); + std::shared_ptr PopGenericObject(); /// Equivalent to calling `std::get<0>(PopObjects())`. template - Kernel::SharedPtr PopObject(); + std::shared_ptr PopObject(); /** * Pop a descriptor containing `N` handles and resolves them to Kernel::Object pointers. If a @@ -247,7 +247,7 @@ public: * call to read 2 single-handle descriptors. */ template - std::array, N> PopGenericObjects(); + std::array, N> PopGenericObjects(); /** * Resolves handles to Kernel::Objects as in PopGenericsObjects(), but then also casts them to @@ -255,11 +255,11 @@ public: * not match, null is returned instead. */ template - std::tuple...> PopObjects(); + std::tuple...> PopObjects(); /// Convenience wrapper around PopObjects() which assigns the handles to the passed references. template - void PopObjects(Kernel::SharedPtr&... pointers) { + void PopObjects(std::shared_ptr&... pointers) { std::tie(pointers...) = PopObjects(); } @@ -377,20 +377,20 @@ std::array RequestParser::PopHLEHandles() { return handles; } -inline Kernel::SharedPtr RequestParser::PopGenericObject() { +inline std::shared_ptr RequestParser::PopGenericObject() { auto [handle] = PopHLEHandles<1>(); return context->GetIncomingHandle(handle); } template -Kernel::SharedPtr RequestParser::PopObject() { +std::shared_ptr RequestParser::PopObject() { return Kernel::DynamicObjectCast(PopGenericObject()); } template -inline std::array, N> RequestParser::PopGenericObjects() { +inline std::array, N> RequestParser::PopGenericObjects() { std::array handles = PopHLEHandles(); - std::array, N> pointers; + std::array, N> pointers; for (int i = 0; i < N; ++i) { pointers[i] = context->GetIncomingHandle(handles[i]); } @@ -399,15 +399,15 @@ inline std::array, N> RequestParser::PopGeneri namespace detail { template -std::tuple...> PopObjectsHelper( - std::array, sizeof...(T)>&& pointers, +std::tuple...> PopObjectsHelper( + std::array, sizeof...(T)>&& pointers, std::index_sequence) { return std::make_tuple(Kernel::DynamicObjectCast(std::move(pointers[I]))...); } } // namespace detail template -inline std::tuple...> RequestParser::PopObjects() { +inline std::tuple...> RequestParser::PopObjects() { return detail::PopObjectsHelper(PopGenericObjects(), std::index_sequence_for{}); } diff --git a/src/core/hle/kernel/address_arbiter.cpp b/src/core/hle/kernel/address_arbiter.cpp index cc54045707..e52c0f2720 100644 --- a/src/core/hle/kernel/address_arbiter.cpp +++ b/src/core/hle/kernel/address_arbiter.cpp @@ -16,7 +16,7 @@ namespace Kernel { -void AddressArbiter::WaitThread(SharedPtr thread, VAddr wait_address) { +void AddressArbiter::WaitThread(std::shared_ptr thread, VAddr wait_address) { thread->wait_address = wait_address; thread->status = ThreadStatus::WaitArb; waiting_threads.emplace_back(std::move(thread)); @@ -38,7 +38,7 @@ void AddressArbiter::ResumeAllThreads(VAddr address) { waiting_threads.erase(itr, waiting_threads.end()); } -SharedPtr AddressArbiter::ResumeHighestPriorityThread(VAddr address) { +std::shared_ptr AddressArbiter::ResumeHighestPriorityThread(VAddr address) { // Determine which threads are waiting on this address, those should be considered for wakeup. auto matches_start = std::stable_partition( waiting_threads.begin(), waiting_threads.end(), [address](const auto& thread) { @@ -68,19 +68,19 @@ SharedPtr AddressArbiter::ResumeHighestPriorityThread(VAddr address) { AddressArbiter::AddressArbiter(KernelSystem& kernel) : Object(kernel), kernel(kernel) {} AddressArbiter::~AddressArbiter() {} -SharedPtr KernelSystem::CreateAddressArbiter(std::string name) { - SharedPtr address_arbiter(new AddressArbiter(*this)); +std::shared_ptr KernelSystem::CreateAddressArbiter(std::string name) { + auto address_arbiter{std::make_shared(*this)}; address_arbiter->name = std::move(name); return address_arbiter; } -ResultCode AddressArbiter::ArbitrateAddress(SharedPtr thread, ArbitrationType type, +ResultCode AddressArbiter::ArbitrateAddress(std::shared_ptr thread, ArbitrationType type, VAddr address, s32 value, u64 nanoseconds) { - auto timeout_callback = [this](ThreadWakeupReason reason, SharedPtr thread, - SharedPtr object) { + auto timeout_callback = [this](ThreadWakeupReason reason, std::shared_ptr thread, + std::shared_ptr object) { ASSERT(reason == ThreadWakeupReason::Timeout); // Remove the newly-awakened thread from the Arbiter's waiting list. waiting_threads.erase(std::remove(waiting_threads.begin(), waiting_threads.end(), thread), diff --git a/src/core/hle/kernel/address_arbiter.h b/src/core/hle/kernel/address_arbiter.h index ac01749f70..8d154b6db6 100644 --- a/src/core/hle/kernel/address_arbiter.h +++ b/src/core/hle/kernel/address_arbiter.h @@ -4,6 +4,7 @@ #pragma once +#include #include #include "common/common_types.h" #include "core/hle/kernel/object.h" @@ -31,6 +32,9 @@ enum class ArbitrationType : u32 { class AddressArbiter final : public Object { public: + explicit AddressArbiter(KernelSystem& kernel); + ~AddressArbiter() override; + std::string GetTypeName() const override { return "Arbiter"; } @@ -45,29 +49,24 @@ public: std::string name; ///< Name of address arbiter object (optional) - ResultCode ArbitrateAddress(SharedPtr thread, ArbitrationType type, VAddr address, + ResultCode ArbitrateAddress(std::shared_ptr thread, ArbitrationType type, VAddr address, s32 value, u64 nanoseconds); private: - explicit AddressArbiter(KernelSystem& kernel); - ~AddressArbiter() override; - KernelSystem& kernel; /// Puts the thread to wait on the specified arbitration address under this address arbiter. - void WaitThread(SharedPtr thread, VAddr wait_address); + void WaitThread(std::shared_ptr thread, VAddr wait_address); /// Resume all threads found to be waiting on the address under this address arbiter void ResumeAllThreads(VAddr address); /// Resume one thread found to be waiting on the address under this address arbiter and return /// the resumed thread. - SharedPtr ResumeHighestPriorityThread(VAddr address); + std::shared_ptr ResumeHighestPriorityThread(VAddr address); /// Threads waiting for the address arbiter to be signaled. - std::vector> waiting_threads; - - friend class KernelSystem; + std::vector> waiting_threads; }; } // namespace Kernel diff --git a/src/core/hle/kernel/client_port.cpp b/src/core/hle/kernel/client_port.cpp index 02c5d08fdf..0a4ca3b0a1 100644 --- a/src/core/hle/kernel/client_port.cpp +++ b/src/core/hle/kernel/client_port.cpp @@ -16,7 +16,7 @@ namespace Kernel { ClientPort::ClientPort(KernelSystem& kernel) : kernel(kernel), Object(kernel) {} ClientPort::~ClientPort() = default; -ResultVal> ClientPort::Connect() { +ResultVal> ClientPort::Connect() { // Note: Threads do not wait for the server endpoint to call // AcceptSession before returning from this call. @@ -26,17 +26,18 @@ ResultVal> ClientPort::Connect() { active_sessions++; // Create a new session pair, let the created sessions inherit the parent port's HLE handler. - auto sessions = kernel.CreateSessionPair(server_port->GetName(), this); + auto sessions = kernel.CreateSessionPair(server_port->GetName(), SharedFrom(this)); if (server_port->hle_handler) - server_port->hle_handler->ClientConnected(std::get>(sessions)); + server_port->hle_handler->ClientConnected( + std::get>(sessions)); else - server_port->pending_sessions.push_back(std::get>(sessions)); + server_port->pending_sessions.push_back(std::get>(sessions)); // Wake the threads waiting on the ServerPort server_port->WakeupAllWaitingThreads(); - return MakeResult(std::get>(sessions)); + return MakeResult(std::get>(sessions)); } void ClientPort::ConnectionClosed() { diff --git a/src/core/hle/kernel/client_port.h b/src/core/hle/kernel/client_port.h index 149ca77a1f..75264a0a68 100644 --- a/src/core/hle/kernel/client_port.h +++ b/src/core/hle/kernel/client_port.h @@ -4,6 +4,7 @@ #pragma once +#include #include #include "common/common_types.h" #include "core/hle/kernel/object.h" @@ -16,6 +17,9 @@ class ClientSession; class ClientPort final : public Object { public: + explicit ClientPort(KernelSystem& kernel); + ~ClientPort() override; + friend class ServerPort; std::string GetTypeName() const override { return "ClientPort"; @@ -29,7 +33,7 @@ public: return HANDLE_TYPE; } - SharedPtr GetServerPort() const { + std::shared_ptr GetServerPort() const { return server_port; } @@ -39,7 +43,7 @@ public: * waiting on it to awake. * @returns ClientSession The client endpoint of the created Session pair, or error code. */ - ResultVal> Connect(); + ResultVal> Connect(); /** * Signifies that a previously active connection has been closed, @@ -48,11 +52,8 @@ public: void ConnectionClosed(); private: - explicit ClientPort(KernelSystem& kernel); - ~ClientPort() override; - KernelSystem& kernel; - SharedPtr server_port; ///< ServerPort associated with this client port. + std::shared_ptr server_port; ///< ServerPort associated with this client port. u32 max_sessions = 0; ///< Maximum number of simultaneous sessions the port can have u32 active_sessions = 0; ///< Number of currently open sessions to this port 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 ef1b901952..3e76f1a4ef 100644 --- a/src/core/hle/kernel/client_session.cpp +++ b/src/core/hle/kernel/client_session.cpp @@ -20,7 +20,7 @@ ClientSession::~ClientSession() { // Local references to ServerSession and SessionRequestHandler are necessary to guarantee they // will be kept alive until after ClientDisconnected() returns. - SharedPtr server = parent->server; + std::shared_ptr server = SharedFrom(parent->server); if (server) { std::shared_ptr hle_handler = server->hle_handler; if (hle_handler) @@ -42,9 +42,9 @@ ClientSession::~ClientSession() { } } -ResultCode ClientSession::SendSyncRequest(SharedPtr thread) { +ResultCode ClientSession::SendSyncRequest(std::shared_ptr thread) { // Keep ServerSession alive until we're done working with it. - SharedPtr server = parent->server; + std::shared_ptr server = SharedFrom(parent->server); if (server == nullptr) return ERR_SESSION_CLOSED_BY_REMOTE; diff --git a/src/core/hle/kernel/client_session.h b/src/core/hle/kernel/client_session.h index 5d5a2d9cdf..c193fb0a71 100644 --- a/src/core/hle/kernel/client_session.h +++ b/src/core/hle/kernel/client_session.h @@ -17,6 +17,9 @@ class Thread; class ClientSession final : public Object { public: + explicit ClientSession(KernelSystem& kernel); + ~ClientSession() override; + friend class KernelSystem; std::string GetTypeName() const override { @@ -37,16 +40,12 @@ public: * @param thread Thread that initiated the request. * @return ResultCode of the operation. */ - ResultCode SendSyncRequest(SharedPtr thread); + ResultCode SendSyncRequest(std::shared_ptr thread); std::string name; ///< Name of client port (optional) /// The parent session, which links to the server endpoint. std::shared_ptr parent; - -private: - explicit ClientSession(KernelSystem& kernel); - ~ClientSession() override; }; } // namespace Kernel diff --git a/src/core/hle/kernel/event.cpp b/src/core/hle/kernel/event.cpp index ce5f3d6ec5..403e260094 100644 --- a/src/core/hle/kernel/event.cpp +++ b/src/core/hle/kernel/event.cpp @@ -15,8 +15,8 @@ namespace Kernel { Event::Event(KernelSystem& kernel) : WaitObject(kernel) {} Event::~Event() {} -SharedPtr KernelSystem::CreateEvent(ResetType reset_type, std::string name) { - SharedPtr evt(new Event(*this)); +std::shared_ptr KernelSystem::CreateEvent(ResetType reset_type, std::string name) { + auto evt{std::make_shared(*this)}; evt->signaled = false; evt->reset_type = reset_type; diff --git a/src/core/hle/kernel/event.h b/src/core/hle/kernel/event.h index 09c21587d2..a7737edf54 100644 --- a/src/core/hle/kernel/event.h +++ b/src/core/hle/kernel/event.h @@ -12,6 +12,9 @@ namespace Kernel { class Event final : public WaitObject { public: + explicit Event(KernelSystem& kernel); + ~Event() override; + std::string GetTypeName() const override { return "Event"; } @@ -40,9 +43,6 @@ public: void Clear(); private: - explicit Event(KernelSystem& kernel); - ~Event() override; - ResetType reset_type; ///< Current ResetType bool signaled; ///< Whether the event has already been signaled diff --git a/src/core/hle/kernel/handle_table.cpp b/src/core/hle/kernel/handle_table.cpp index 2784ca8b0e..71e18eb7ce 100644 --- a/src/core/hle/kernel/handle_table.cpp +++ b/src/core/hle/kernel/handle_table.cpp @@ -28,7 +28,7 @@ HandleTable::HandleTable(KernelSystem& kernel) : kernel(kernel) { HandleTable::~HandleTable() = default; -ResultVal HandleTable::Create(SharedPtr obj) { +ResultVal HandleTable::Create(std::shared_ptr obj) { DEBUG_ASSERT(obj != nullptr); u16 slot = next_free_slot; @@ -53,7 +53,7 @@ ResultVal HandleTable::Create(SharedPtr obj) { } ResultVal HandleTable::Duplicate(Handle handle) { - SharedPtr object = GetGeneric(handle); + std::shared_ptr object = GetGeneric(handle); if (object == nullptr) { LOG_ERROR(Kernel, "Tried to duplicate invalid handle: {:08X}", handle); return ERR_INVALID_HANDLE; @@ -81,9 +81,9 @@ bool HandleTable::IsValid(Handle handle) const { return slot < MAX_COUNT && objects[slot] != nullptr && generations[slot] == generation; } -SharedPtr HandleTable::GetGeneric(Handle handle) const { +std::shared_ptr HandleTable::GetGeneric(Handle handle) const { if (handle == CurrentThread) { - return kernel.GetThreadManager().GetCurrentThread(); + return SharedFrom(kernel.GetThreadManager().GetCurrentThread()); } else if (handle == CurrentProcess) { return kernel.GetCurrentProcess(); } diff --git a/src/core/hle/kernel/handle_table.h b/src/core/hle/kernel/handle_table.h index 59588d2254..bd5a5df6af 100644 --- a/src/core/hle/kernel/handle_table.h +++ b/src/core/hle/kernel/handle_table.h @@ -6,6 +6,7 @@ #include #include +#include #include "common/common_types.h" #include "core/hle/kernel/object.h" #include "core/hle/result.h" @@ -50,7 +51,7 @@ public: * @return The created Handle or one of the following errors: * - `ERR_OUT_OF_HANDLES`: the maximum number of handles has been exceeded. */ - ResultVal Create(SharedPtr obj); + ResultVal Create(std::shared_ptr obj); /** * Returns a new handle that points to the same object as the passed in handle. @@ -74,7 +75,7 @@ public: * Looks up a handle. * @return Pointer to the looked-up object, or `nullptr` if the handle is not valid. */ - SharedPtr GetGeneric(Handle handle) const; + std::shared_ptr GetGeneric(Handle handle) const; /** * Looks up a handle while verifying its type. @@ -82,7 +83,7 @@ public: * type differs from the requested one. */ template - SharedPtr Get(Handle handle) const { + std::shared_ptr Get(Handle handle) const { return DynamicObjectCast(GetGeneric(handle)); } @@ -97,7 +98,7 @@ private: static const std::size_t MAX_COUNT = 4096; /// Stores the Object referenced by the handle or null if the slot is empty. - std::array, MAX_COUNT> objects; + std::array, MAX_COUNT> objects; /** * 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 618a9d2109..a78a64bbf8 100644 --- a/src/core/hle/kernel/hle_ipc.cpp +++ b/src/core/hle/kernel/hle_ipc.cpp @@ -15,16 +15,16 @@ namespace Kernel { -SessionRequestHandler::SessionInfo::SessionInfo(SharedPtr session, +SessionRequestHandler::SessionInfo::SessionInfo(std::shared_ptr session, std::unique_ptr data) : session(std::move(session)), data(std::move(data)) {} -void SessionRequestHandler::ClientConnected(SharedPtr server_session) { +void SessionRequestHandler::ClientConnected(std::shared_ptr server_session) { server_session->SetHleHandler(shared_from_this()); connected_sessions.emplace_back(std::move(server_session), MakeSessionData()); } -void SessionRequestHandler::ClientDisconnected(SharedPtr server_session) { +void SessionRequestHandler::ClientDisconnected(std::shared_ptr server_session) { server_session->SetHleHandler(nullptr); connected_sessions.erase( std::remove_if(connected_sessions.begin(), connected_sessions.end(), @@ -32,14 +32,14 @@ void SessionRequestHandler::ClientDisconnected(SharedPtr server_s connected_sessions.end()); } -SharedPtr HLERequestContext::SleepClientThread(SharedPtr thread, - const std::string& reason, - std::chrono::nanoseconds timeout, - WakeupCallback&& callback) { +std::shared_ptr HLERequestContext::SleepClientThread(std::shared_ptr thread, + const std::string& reason, + std::chrono::nanoseconds timeout, + WakeupCallback&& callback) { // Put the client thread to sleep until the wait event is signaled or the timeout expires. - thread->wakeup_callback = [context = *this, callback](ThreadWakeupReason reason, - SharedPtr thread, - SharedPtr object) mutable { + thread->wakeup_callback = [context = *this, + callback](ThreadWakeupReason reason, std::shared_ptr thread, + std::shared_ptr object) mutable { ASSERT(thread->status == ThreadStatus::WaitHleEvent); callback(thread, context, reason); @@ -68,19 +68,19 @@ SharedPtr HLERequestContext::SleepClientThread(SharedPtr thread, return event; } -HLERequestContext::HLERequestContext(KernelSystem& kernel, SharedPtr session) +HLERequestContext::HLERequestContext(KernelSystem& kernel, std::shared_ptr session) : kernel(kernel), session(std::move(session)) { cmd_buf[0] = 0; } HLERequestContext::~HLERequestContext() = default; -SharedPtr HLERequestContext::GetIncomingHandle(u32 id_from_cmdbuf) const { +std::shared_ptr HLERequestContext::GetIncomingHandle(u32 id_from_cmdbuf) const { ASSERT(id_from_cmdbuf < request_handles.size()); return request_handles[id_from_cmdbuf]; } -u32 HLERequestContext::AddOutgoingHandle(SharedPtr object) { +u32 HLERequestContext::AddOutgoingHandle(std::shared_ptr object) { request_handles.push_back(std::move(object)); return static_cast(request_handles.size() - 1); } @@ -119,7 +119,7 @@ ResultCode HLERequestContext::PopulateFromIncomingCommandBuffer(const u32_le* sr ASSERT(i + num_handles <= command_size); // TODO(yuriks): Return error for (u32 j = 0; j < num_handles; ++j) { Handle handle = src_cmdbuf[i]; - SharedPtr object = nullptr; + std::shared_ptr object = nullptr; if (handle != 0) { object = src_process.handle_table.GetGeneric(handle); ASSERT(object != nullptr); // TODO(yuriks): Return error @@ -185,7 +185,7 @@ ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(u32_le* dst_cmdbuf, u32 num_handles = IPC::HandleNumberFromDesc(descriptor); ASSERT(i + num_handles <= command_size); for (u32 j = 0; j < num_handles; ++j) { - SharedPtr object = GetIncomingHandle(cmd_buf[i]); + std::shared_ptr object = GetIncomingHandle(cmd_buf[i]); Handle handle = 0; if (object != nullptr) { // TODO(yuriks): Figure out the proper error handling for if this fails diff --git a/src/core/hle/kernel/hle_ipc.h b/src/core/hle/kernel/hle_ipc.h index 78c459a9e0..655165f8cf 100644 --- a/src/core/hle/kernel/hle_ipc.h +++ b/src/core/hle/kernel/hle_ipc.h @@ -55,14 +55,14 @@ public: * associated ServerSession alive for the duration of the connection. * @param server_session Owning pointer to the ServerSession associated with the connection. */ - virtual void ClientConnected(SharedPtr server_session); + virtual void ClientConnected(std::shared_ptr server_session); /** * Signals that a client has just disconnected from this HLE handler and releases the * associated ServerSession. * @param server_session ServerSession associated with the connection. */ - virtual void ClientDisconnected(SharedPtr server_session); + virtual void ClientDisconnected(std::shared_ptr server_session); /// Empty placeholder structure for services with no per-session data. The session data classes /// in each service must inherit from this. @@ -76,7 +76,7 @@ protected: /// Returns the session data associated with the server session. template - T* GetSessionData(SharedPtr session) { + T* GetSessionData(std::shared_ptr session) { static_assert(std::is_base_of(), "T is not a subclass of SessionDataBase"); auto itr = std::find_if(connected_sessions.begin(), connected_sessions.end(), @@ -86,9 +86,9 @@ protected: } struct SessionInfo { - SessionInfo(SharedPtr session, std::unique_ptr data); + SessionInfo(std::shared_ptr session, std::unique_ptr data); - SharedPtr session; + std::shared_ptr session; std::unique_ptr data; }; /// List of sessions that are connected to this handler. A ServerSession whose server endpoint @@ -158,7 +158,7 @@ private: */ class HLERequestContext { public: - HLERequestContext(KernelSystem& kernel, SharedPtr session); + HLERequestContext(KernelSystem& kernel, std::shared_ptr session); ~HLERequestContext(); /// Returns a pointer to the IPC command buffer for this request. @@ -170,12 +170,12 @@ public: * Returns the session through which this request was made. This can be used as a map key to * access per-client data on services. */ - SharedPtr Session() const { + std::shared_ptr Session() const { return session; } - using WakeupCallback = std::function thread, HLERequestContext& context, - ThreadWakeupReason reason)>; + using WakeupCallback = std::function thread, HLERequestContext& context, ThreadWakeupReason reason)>; /** * Puts the specified guest thread to sleep until the returned event is signaled or until the @@ -189,20 +189,22 @@ public: * was called. * @returns Event that when signaled will resume the thread and call the callback function. */ - SharedPtr SleepClientThread(SharedPtr thread, const std::string& reason, - std::chrono::nanoseconds timeout, WakeupCallback&& callback); + std::shared_ptr SleepClientThread(std::shared_ptr thread, + const std::string& reason, + std::chrono::nanoseconds timeout, + WakeupCallback&& callback); /** * Resolves a object id from the request command buffer into a pointer to an object. See the * "HLE handle protocol" section in the class documentation for more details. */ - SharedPtr GetIncomingHandle(u32 id_from_cmdbuf) const; + std::shared_ptr GetIncomingHandle(u32 id_from_cmdbuf) const; /** * Adds an outgoing object to the response, returning the id which should be used to reference * it. See the "HLE handle protocol" section in the class documentation for more details. */ - u32 AddOutgoingHandle(SharedPtr object); + u32 AddOutgoingHandle(std::shared_ptr object); /** * Discards all Objects from the context, invalidating all ids. This may be called after reading @@ -237,9 +239,9 @@ public: private: KernelSystem& kernel; std::array cmd_buf; - SharedPtr session; + std::shared_ptr session; // TODO(yuriks): Check common usage of this and optimize size accordingly - boost::container::small_vector, 8> request_handles; + boost::container::small_vector, 8> request_handles; // The static buffers will be created when the IPC request is translated. std::array, IPC::MAX_STATIC_BUFFERS> static_buffers; // The mapped buffers will be created when the IPC request is translated diff --git a/src/core/hle/kernel/ipc.cpp b/src/core/hle/kernel/ipc.cpp index 25676ee560..eeb8898343 100644 --- a/src/core/hle/kernel/ipc.cpp +++ b/src/core/hle/kernel/ipc.cpp @@ -16,8 +16,8 @@ namespace Kernel { -ResultCode TranslateCommandBuffer(Memory::MemorySystem& memory, SharedPtr src_thread, - SharedPtr dst_thread, VAddr src_address, +ResultCode TranslateCommandBuffer(Memory::MemorySystem& memory, std::shared_ptr src_thread, + std::shared_ptr dst_thread, VAddr src_address, VAddr dst_address, std::vector& mapped_buffer_context, bool reply) { @@ -55,14 +55,14 @@ ResultCode TranslateCommandBuffer(Memory::MemorySystem& memory, SharedPtr object = nullptr; + std::shared_ptr object = nullptr; // Perform pseudo-handle detection here because by the time this function is called, // the current thread and process are no longer the ones which created this IPC // request, but the ones that are handling it. if (handle == CurrentThread) { object = src_thread; } else if (handle == CurrentProcess) { - object = src_process; + object = SharedFrom(src_process); } else if (handle != 0) { object = src_process->handle_table.GetGeneric(handle); if (descriptor == IPC::DescriptorType::MoveHandle) { diff --git a/src/core/hle/kernel/ipc.h b/src/core/hle/kernel/ipc.h index 55488bc72a..d84028767c 100644 --- a/src/core/hle/kernel/ipc.h +++ b/src/core/hle/kernel/ipc.h @@ -27,8 +27,8 @@ struct MappedBufferContext { }; /// Performs IPC command buffer translation from one process to another. -ResultCode TranslateCommandBuffer(Memory::MemorySystem& memory, SharedPtr src_thread, - SharedPtr dst_thread, VAddr src_address, +ResultCode TranslateCommandBuffer(Memory::MemorySystem& memory, std::shared_ptr src_thread, + std::shared_ptr dst_thread, VAddr src_address, VAddr dst_address, std::vector& mapped_buffer_context, bool reply); diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index e5bb44f0ae..61734933b6 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp @@ -42,11 +42,11 @@ u32 KernelSystem::GenerateObjectID() { return next_object_id++; } -SharedPtr KernelSystem::GetCurrentProcess() const { +std::shared_ptr KernelSystem::GetCurrentProcess() const { return current_process; } -void KernelSystem::SetCurrentProcess(SharedPtr process) { +void KernelSystem::SetCurrentProcess(std::shared_ptr process) { current_process = std::move(process); } @@ -74,7 +74,7 @@ const SharedPage::Handler& KernelSystem::GetSharedPageHandler() const { return *shared_page_handler; } -void KernelSystem::AddNamedPort(std::string name, SharedPtr port) { +void KernelSystem::AddNamedPort(std::string name, std::shared_ptr port) { named_ports.emplace(std::move(name), std::move(port)); } diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h index 0fe29af927..9c32d90602 100644 --- a/src/core/hle/kernel/kernel.h +++ b/src/core/hle/kernel/kernel.h @@ -11,7 +11,6 @@ #include #include #include -#include #include "common/common_types.h" #include "core/hle/kernel/memory.h" #include "core/hle/result.h" @@ -78,9 +77,6 @@ enum class MemoryRegion : u16 { BASE = 3, }; -template -using SharedPtr = boost::intrusive_ptr; - class KernelSystem { public: explicit KernelSystem(Memory::MemorySystem& memory, Core::Timing& timing, @@ -93,14 +89,14 @@ public: * @param name Optional name used for debugging. * @returns The created AddressArbiter. */ - SharedPtr CreateAddressArbiter(std::string name = "Unknown"); + std::shared_ptr CreateAddressArbiter(std::string name = "Unknown"); /** * Creates an event * @param reset_type ResetType describing how to create event * @param name Optional name of event */ - SharedPtr CreateEvent(ResetType reset_type, std::string name = "Unknown"); + std::shared_ptr CreateEvent(ResetType reset_type, std::string name = "Unknown"); /** * Creates a mutex. @@ -108,11 +104,11 @@ public: * @param name Optional name of mutex * @return Pointer to new Mutex object */ - SharedPtr CreateMutex(bool initial_locked, std::string name = "Unknown"); + std::shared_ptr CreateMutex(bool initial_locked, std::string name = "Unknown"); - SharedPtr CreateCodeSet(std::string name, u64 program_id); + std::shared_ptr CreateCodeSet(std::string name, u64 program_id); - SharedPtr CreateProcess(SharedPtr code_set); + std::shared_ptr CreateProcess(std::shared_ptr code_set); /** * Creates and returns a new thread. The new thread is immediately scheduled @@ -125,9 +121,9 @@ public: * @param owner_process The parent process for the thread * @return A shared pointer to the newly created thread */ - ResultVal> CreateThread(std::string name, VAddr entry_point, u32 priority, - u32 arg, s32 processor_id, VAddr stack_top, - Process& owner_process); + ResultVal> CreateThread(std::string name, VAddr entry_point, + u32 priority, u32 arg, s32 processor_id, + VAddr stack_top, Process& owner_process); /** * Creates a semaphore. @@ -136,8 +132,8 @@ public: * @param name Optional name of semaphore * @return The created semaphore */ - ResultVal> CreateSemaphore(s32 initial_count, s32 max_count, - std::string name = "Unknown"); + ResultVal> CreateSemaphore(s32 initial_count, s32 max_count, + std::string name = "Unknown"); /** * Creates a timer @@ -145,7 +141,7 @@ public: * @param name Optional name of timer * @return The created Timer */ - SharedPtr CreateTimer(ResetType reset_type, std::string name = "Unknown"); + std::shared_ptr CreateTimer(ResetType reset_type, std::string name = "Unknown"); /** * Creates a pair of ServerPort and an associated ClientPort. @@ -154,7 +150,7 @@ public: * @param name Optional name of the ports * @return The created port tuple */ - std::tuple, SharedPtr> CreatePortPair( + std::tuple, std::shared_ptr> CreatePortPair( u32 max_sessions, std::string name = "UnknownPort"); /** @@ -163,8 +159,8 @@ public: * @param client_port Optional The ClientPort that spawned this session. * @return The created session tuple */ - std::tuple, SharedPtr> CreateSessionPair( - const std::string& name = "Unknown", SharedPtr client_port = nullptr); + std::tuple, std::shared_ptr> CreateSessionPair( + const std::string& name = "Unknown", std::shared_ptr client_port = nullptr); ResourceLimitList& ResourceLimit(); const ResourceLimitList& ResourceLimit() const; @@ -181,12 +177,10 @@ public: * linear heap. * @param name Optional object name, used for debugging purposes. */ - ResultVal> CreateSharedMemory(Process* owner_process, u32 size, - MemoryPermission permissions, - MemoryPermission other_permissions, - VAddr address = 0, - MemoryRegion region = MemoryRegion::BASE, - std::string name = "Unknown"); + ResultVal> CreateSharedMemory( + Process* owner_process, u32 size, MemoryPermission permissions, + MemoryPermission other_permissions, VAddr address = 0, + MemoryRegion region = MemoryRegion::BASE, std::string name = "Unknown"); /** * Creates a shared memory object from a block of memory managed by an HLE applet. @@ -197,18 +191,18 @@ public: * block. * @param name Optional object name, used for debugging purposes. */ - SharedPtr CreateSharedMemoryForApplet(u32 offset, u32 size, - MemoryPermission permissions, - MemoryPermission other_permissions, - std::string name = "Unknown Applet"); + std::shared_ptr CreateSharedMemoryForApplet(u32 offset, u32 size, + MemoryPermission permissions, + MemoryPermission other_permissions, + std::string name = "Unknown Applet"); u32 GenerateObjectID(); /// Retrieves a process from the current list of processes. - SharedPtr GetProcessById(u32 process_id) const; + std::shared_ptr GetProcessById(u32 process_id) const; - SharedPtr GetCurrentProcess() const; - void SetCurrentProcess(SharedPtr process); + std::shared_ptr GetCurrentProcess() const; + void SetCurrentProcess(std::shared_ptr process); ThreadManager& GetThreadManager(); const ThreadManager& GetThreadManager() const; @@ -228,14 +222,14 @@ public: std::array memory_regions; /// Adds a port to the named port table - void AddNamedPort(std::string name, SharedPtr port); + void AddNamedPort(std::string name, std::shared_ptr port); void PrepareReschedule() { prepare_reschedule_callback(); } /// Map of named ports managed by the kernel, which can be retrieved using the ConnectToPort - std::unordered_map> named_ports; + std::unordered_map> named_ports; Memory::MemorySystem& memory; @@ -263,9 +257,9 @@ private: u32 next_process_id = 10; // Lists all processes that exist in the current session. - std::vector> process_list; + std::vector> process_list; - SharedPtr current_process; + std::shared_ptr current_process; std::unique_ptr thread_manager; diff --git a/src/core/hle/kernel/mutex.cpp b/src/core/hle/kernel/mutex.cpp index 9bc0505f5c..7c2c52c9fd 100644 --- a/src/core/hle/kernel/mutex.cpp +++ b/src/core/hle/kernel/mutex.cpp @@ -27,8 +27,8 @@ void ReleaseThreadMutexes(Thread* thread) { Mutex::Mutex(KernelSystem& kernel) : WaitObject(kernel), kernel(kernel) {} Mutex::~Mutex() {} -SharedPtr KernelSystem::CreateMutex(bool initial_locked, std::string name) { - SharedPtr mutex(new Mutex(*this)); +std::shared_ptr KernelSystem::CreateMutex(bool initial_locked, std::string name) { + auto mutex{std::make_shared(*this)}; mutex->lock_count = 0; mutex->name = std::move(name); @@ -42,7 +42,7 @@ SharedPtr KernelSystem::CreateMutex(bool initial_locked, std::string name } bool Mutex::ShouldWait(Thread* thread) const { - return lock_count > 0 && thread != holding_thread; + return lock_count > 0 && thread != holding_thread.get(); } void Mutex::Acquire(Thread* thread) { @@ -51,8 +51,8 @@ void Mutex::Acquire(Thread* thread) { // Actually "acquire" the mutex only if we don't already have it if (lock_count == 0) { priority = thread->current_priority; - thread->held_mutexes.insert(this); - holding_thread = thread; + thread->held_mutexes.insert(SharedFrom(this)); + holding_thread = SharedFrom(thread); thread->UpdatePriority(); kernel.PrepareReschedule(); } @@ -62,7 +62,7 @@ void Mutex::Acquire(Thread* thread) { ResultCode Mutex::Release(Thread* thread) { // We can only release the mutex if it's held by the calling thread. - if (thread != holding_thread) { + if (thread != holding_thread.get()) { if (holding_thread) { LOG_ERROR( Kernel, @@ -83,7 +83,7 @@ ResultCode Mutex::Release(Thread* thread) { // Yield to the next thread only if we've fully released the mutex if (lock_count == 0) { - holding_thread->held_mutexes.erase(this); + holding_thread->held_mutexes.erase(SharedFrom(this)); holding_thread->UpdatePriority(); holding_thread = nullptr; WakeupAllWaitingThreads(); @@ -93,15 +93,15 @@ ResultCode Mutex::Release(Thread* thread) { return RESULT_SUCCESS; } -void Mutex::AddWaitingThread(SharedPtr thread) { +void Mutex::AddWaitingThread(std::shared_ptr thread) { WaitObject::AddWaitingThread(thread); - thread->pending_mutexes.insert(this); + thread->pending_mutexes.insert(SharedFrom(this)); UpdatePriority(); } void Mutex::RemoveWaitingThread(Thread* thread) { WaitObject::RemoveWaitingThread(thread); - thread->pending_mutexes.erase(this); + thread->pending_mutexes.erase(SharedFrom(this)); UpdatePriority(); } diff --git a/src/core/hle/kernel/mutex.h b/src/core/hle/kernel/mutex.h index aff2f39862..8cfbfa5403 100644 --- a/src/core/hle/kernel/mutex.h +++ b/src/core/hle/kernel/mutex.h @@ -4,6 +4,7 @@ #pragma once +#include #include #include "common/common_types.h" #include "core/hle/kernel/kernel.h" @@ -16,6 +17,9 @@ class Thread; class Mutex final : public WaitObject { public: + explicit Mutex(KernelSystem& kernel); + ~Mutex() override; + std::string GetTypeName() const override { return "Mutex"; } @@ -28,10 +32,10 @@ public: return HANDLE_TYPE; } - int lock_count; ///< Number of times the mutex has been acquired - u32 priority; ///< The priority of the mutex, used for priority inheritance. - std::string name; ///< Name of mutex (optional) - SharedPtr holding_thread; ///< Thread that has acquired the mutex + int lock_count; ///< Number of times the mutex has been acquired + u32 priority; ///< The priority of the mutex, used for priority inheritance. + std::string name; ///< Name of mutex (optional) + std::shared_ptr holding_thread; ///< Thread that has acquired the mutex /** * Elevate the mutex priority to the best priority @@ -42,7 +46,7 @@ public: bool ShouldWait(Thread* thread) const override; void Acquire(Thread* thread) override; - void AddWaitingThread(SharedPtr thread) override; + void AddWaitingThread(std::shared_ptr thread) override; void RemoveWaitingThread(Thread* thread) override; /** @@ -53,10 +57,6 @@ public: ResultCode Release(Thread* thread); private: - explicit Mutex(KernelSystem& kernel); - ~Mutex() override; - - friend class KernelSystem; KernelSystem& kernel; }; diff --git a/src/core/hle/kernel/object.h b/src/core/hle/kernel/object.h index f1fd032957..9547a83ed2 100644 --- a/src/core/hle/kernel/object.h +++ b/src/core/hle/kernel/object.h @@ -5,6 +5,7 @@ #pragma once #include +#include #include #include "common/common_types.h" #include "core/hle/kernel/kernel.h" @@ -37,7 +38,7 @@ enum { DEFAULT_STACK_SIZE = 0x4000, }; -class Object : NonCopyable { +class Object : NonCopyable, public std::enable_shared_from_this { public: explicit Object(KernelSystem& kernel); virtual ~Object(); @@ -62,22 +63,15 @@ public: bool IsWaitable() const; private: - friend void intrusive_ptr_add_ref(Object*); - friend void intrusive_ptr_release(Object*); - - std::atomic ref_count{0}; std::atomic object_id; }; -// Special functions used by boost::instrusive_ptr to do automatic ref-counting -inline void intrusive_ptr_add_ref(Object* object) { - object->ref_count.fetch_add(1, std::memory_order_relaxed); -} +template +std::shared_ptr SharedFrom(T* raw) { + if (raw == nullptr) + return nullptr; -inline void intrusive_ptr_release(Object* object) { - if (object->ref_count.fetch_sub(1, std::memory_order_acq_rel) == 1) { - delete object; - } + return std::static_pointer_cast(raw->shared_from_this()); } /** @@ -85,9 +79,9 @@ inline void intrusive_ptr_release(Object* object) { * @return Derived pointer to the object, or `nullptr` if `object` isn't of type T. */ template -inline SharedPtr DynamicObjectCast(SharedPtr object) { +inline std::shared_ptr DynamicObjectCast(std::shared_ptr object) { if (object != nullptr && object->GetHandleType() == T::HANDLE_TYPE) { - return boost::static_pointer_cast(object); + return std::static_pointer_cast(object); } return nullptr; } diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp index b04af46646..6b1fabcbce 100644 --- a/src/core/hle/kernel/process.cpp +++ b/src/core/hle/kernel/process.cpp @@ -17,8 +17,8 @@ namespace Kernel { -SharedPtr KernelSystem::CreateCodeSet(std::string name, u64 program_id) { - SharedPtr codeset(new CodeSet(*this)); +std::shared_ptr KernelSystem::CreateCodeSet(std::string name, u64 program_id) { + auto codeset{std::make_shared(*this)}; codeset->name = std::move(name); codeset->program_id = program_id; @@ -29,8 +29,8 @@ SharedPtr KernelSystem::CreateCodeSet(std::string name, u64 program_id) CodeSet::CodeSet(KernelSystem& kernel) : Object(kernel) {} CodeSet::~CodeSet() {} -SharedPtr KernelSystem::CreateProcess(SharedPtr code_set) { - SharedPtr process(new Process(*this)); +std::shared_ptr KernelSystem::CreateProcess(std::shared_ptr code_set) { + auto process{std::make_shared(*this)}; process->codeset = std::move(code_set); process->flags.raw = 0; @@ -142,7 +142,7 @@ void Process::Run(s32 main_thread_priority, u32 stack_size) { status = ProcessStatus::Running; vm_manager.LogLayout(Log::Level::Debug); - Kernel::SetupMainThread(kernel, codeset->entrypoint, main_thread_priority, this); + Kernel::SetupMainThread(kernel, codeset->entrypoint, main_thread_priority, SharedFrom(this)); } VAddr Process::GetLinearHeapAreaAddress() const { @@ -416,10 +416,10 @@ Kernel::Process::~Process() { kernel.memory.UnregisterPageTable(&vm_manager.page_table); } -SharedPtr KernelSystem::GetProcessById(u32 process_id) const { +std::shared_ptr KernelSystem::GetProcessById(u32 process_id) const { auto itr = std::find_if( process_list.begin(), process_list.end(), - [&](const SharedPtr& process) { return process->process_id == process_id; }); + [&](const std::shared_ptr& process) { return process->process_id == process_id; }); if (itr == process_list.end()) return nullptr; diff --git a/src/core/hle/kernel/process.h b/src/core/hle/kernel/process.h index 0ef9e42781..6b595336c6 100644 --- a/src/core/hle/kernel/process.h +++ b/src/core/hle/kernel/process.h @@ -52,6 +52,9 @@ struct MemoryRegionInfo; class CodeSet final : public Object { public: + explicit CodeSet(KernelSystem& kernel); + ~CodeSet() override; + struct Segment { std::size_t offset = 0; VAddr addr = 0; @@ -103,16 +106,13 @@ public: std::string name; /// Title ID corresponding to the process u64 program_id; - -private: - explicit CodeSet(KernelSystem& kernel); - ~CodeSet() override; - - friend class KernelSystem; }; class Process final : public Object { public: + explicit Process(Kernel::KernelSystem& kernel); + ~Process() override; + std::string GetTypeName() const override { return "Process"; } @@ -127,9 +127,9 @@ public: HandleTable handle_table; - SharedPtr codeset; + std::shared_ptr codeset; /// Resource limit descriptor for this process - SharedPtr resource_limit; + std::shared_ptr resource_limit; /// The process may only call SVCs which have the corresponding bit set. std::bitset<0x80> svc_access_mask; @@ -194,10 +194,6 @@ public: bool privileged = false); private: - explicit Process(Kernel::KernelSystem& kernel); - ~Process() override; - - friend class KernelSystem; KernelSystem& kernel; }; } // namespace Kernel diff --git a/src/core/hle/kernel/resource_limit.cpp b/src/core/hle/kernel/resource_limit.cpp index 3498acb23c..8691c142ec 100644 --- a/src/core/hle/kernel/resource_limit.cpp +++ b/src/core/hle/kernel/resource_limit.cpp @@ -12,14 +12,14 @@ namespace Kernel { ResourceLimit::ResourceLimit(KernelSystem& kernel) : Object(kernel) {} ResourceLimit::~ResourceLimit() {} -SharedPtr ResourceLimit::Create(KernelSystem& kernel, std::string name) { - SharedPtr resource_limit(new ResourceLimit(kernel)); +std::shared_ptr ResourceLimit::Create(KernelSystem& kernel, std::string name) { + auto resource_limit{std::make_shared(kernel)}; resource_limit->name = std::move(name); return resource_limit; } -SharedPtr ResourceLimitList::GetForCategory(ResourceLimitCategory category) { +std::shared_ptr ResourceLimitList::GetForCategory(ResourceLimitCategory category) { switch (category) { case ResourceLimitCategory::APPLICATION: case ResourceLimitCategory::SYS_APPLET: @@ -91,7 +91,7 @@ u32 ResourceLimit::GetMaxResourceValue(u32 resource) const { ResourceLimitList::ResourceLimitList(KernelSystem& kernel) { // Create the four resource limits that the system uses // Create the APPLICATION resource limit - SharedPtr resource_limit = ResourceLimit::Create(kernel, "Applications"); + std::shared_ptr resource_limit = ResourceLimit::Create(kernel, "Applications"); resource_limit->max_priority = 0x18; resource_limit->max_commit = 0x4000000; resource_limit->max_threads = 0x20; diff --git a/src/core/hle/kernel/resource_limit.h b/src/core/hle/kernel/resource_limit.h index 3b8b79d0c5..582cca43d6 100644 --- a/src/core/hle/kernel/resource_limit.h +++ b/src/core/hle/kernel/resource_limit.h @@ -5,6 +5,7 @@ #pragma once #include +#include #include "common/common_types.h" #include "core/hle/kernel/object.h" @@ -32,10 +33,14 @@ enum ResourceTypes { class ResourceLimit final : public Object { public: + explicit ResourceLimit(KernelSystem& kernel); + ~ResourceLimit() override; + /** * Creates a resource limit object. */ - static SharedPtr Create(KernelSystem& kernel, std::string name = "Unknown"); + static std::shared_ptr Create(KernelSystem& kernel, + std::string name = "Unknown"); std::string GetTypeName() const override { return "ResourceLimit"; @@ -105,10 +110,6 @@ public: /// Current CPU time that the processes in this category are utilizing s32 current_cpu_time = 0; - -private: - explicit ResourceLimit(KernelSystem& kernel); - ~ResourceLimit() override; }; class ResourceLimitList { @@ -121,10 +122,10 @@ public: * @param category The resource limit category * @returns The resource limit associated with the category */ - SharedPtr GetForCategory(ResourceLimitCategory category); + std::shared_ptr GetForCategory(ResourceLimitCategory category); private: - std::array, 4> resource_limits; + std::array, 4> resource_limits; }; } // namespace Kernel diff --git a/src/core/hle/kernel/semaphore.cpp b/src/core/hle/kernel/semaphore.cpp index 8193f848df..04dd369231 100644 --- a/src/core/hle/kernel/semaphore.cpp +++ b/src/core/hle/kernel/semaphore.cpp @@ -13,13 +13,14 @@ namespace Kernel { Semaphore::Semaphore(KernelSystem& kernel) : WaitObject(kernel) {} Semaphore::~Semaphore() {} -ResultVal> KernelSystem::CreateSemaphore(s32 initial_count, s32 max_count, - std::string name) { +ResultVal> KernelSystem::CreateSemaphore(s32 initial_count, + s32 max_count, + std::string name) { if (initial_count > max_count) return ERR_INVALID_COMBINATION_KERNEL; - SharedPtr semaphore(new Semaphore(*this)); + auto semaphore{std::make_shared(*this)}; // When the semaphore is created, some slots are reserved for other threads, // and the rest is reserved for the caller thread @@ -27,7 +28,7 @@ ResultVal> KernelSystem::CreateSemaphore(s32 initial_count, semaphore->available_count = initial_count; semaphore->name = std::move(name); - return MakeResult>(std::move(semaphore)); + return MakeResult>(std::move(semaphore)); } bool Semaphore::ShouldWait(Thread* thread) const { diff --git a/src/core/hle/kernel/semaphore.h b/src/core/hle/kernel/semaphore.h index 7303ee7d19..31c9fa8b5d 100644 --- a/src/core/hle/kernel/semaphore.h +++ b/src/core/hle/kernel/semaphore.h @@ -15,6 +15,9 @@ namespace Kernel { class Semaphore final : public WaitObject { public: + explicit Semaphore(KernelSystem& kernel); + ~Semaphore() override; + std::string GetTypeName() const override { return "Semaphore"; } @@ -40,12 +43,6 @@ public: * @return The number of free slots the semaphore had before this call */ ResultVal Release(s32 release_count); - -private: - explicit Semaphore(KernelSystem& kernel); - ~Semaphore() override; - - friend class KernelSystem; }; } // namespace Kernel diff --git a/src/core/hle/kernel/server_port.cpp b/src/core/hle/kernel/server_port.cpp index e17e699a49..f4b54451c9 100644 --- a/src/core/hle/kernel/server_port.cpp +++ b/src/core/hle/kernel/server_port.cpp @@ -16,7 +16,7 @@ namespace Kernel { ServerPort::ServerPort(KernelSystem& kernel) : WaitObject(kernel) {} ServerPort::~ServerPort() {} -ResultVal> ServerPort::Accept() { +ResultVal> ServerPort::Accept() { if (pending_sessions.empty()) { return ERR_NO_PENDING_SESSIONS; } @@ -35,11 +35,11 @@ void ServerPort::Acquire(Thread* thread) { ASSERT_MSG(!ShouldWait(thread), "object unavailable!"); } -std::tuple, SharedPtr> KernelSystem::CreatePortPair( +std::tuple, std::shared_ptr> KernelSystem::CreatePortPair( u32 max_sessions, std::string name) { - SharedPtr server_port(new ServerPort(*this)); - SharedPtr client_port(new ClientPort(*this)); + auto server_port{std::make_shared(*this)}; + auto client_port{std::make_shared(*this)}; server_port->name = name + "_Server"; client_port->name = name + "_Client"; diff --git a/src/core/hle/kernel/server_port.h b/src/core/hle/kernel/server_port.h index ee09efba10..eb6c1e0aaa 100644 --- a/src/core/hle/kernel/server_port.h +++ b/src/core/hle/kernel/server_port.h @@ -20,6 +20,9 @@ class SessionRequestHandler; class ServerPort final : public WaitObject { public: + explicit ServerPort(KernelSystem& kernel); + ~ServerPort() override; + std::string GetTypeName() const override { return "ServerPort"; } @@ -36,7 +39,7 @@ public: * Accepts a pending incoming connection on this port. If there are no pending sessions, will * return ERR_NO_PENDING_SESSIONS. */ - ResultVal> Accept(); + ResultVal> Accept(); /** * Sets the HLE handler template for the port. ServerSessions crated by connecting to this port @@ -49,7 +52,7 @@ public: std::string name; ///< Name of port (optional) /// ServerSessions waiting to be accepted by the port - std::vector> pending_sessions; + std::vector> pending_sessions; /// This session's HLE request handler template (optional) /// ServerSessions created from this port inherit a reference to this handler. @@ -57,12 +60,6 @@ public: bool ShouldWait(Thread* thread) const override; void Acquire(Thread* thread) override; - -private: - explicit ServerPort(KernelSystem& kernel); - ~ServerPort() override; - - friend class KernelSystem; }; } // namespace Kernel diff --git a/src/core/hle/kernel/server_session.cpp b/src/core/hle/kernel/server_session.cpp index dd940b7245..2989fa3f94 100644 --- a/src/core/hle/kernel/server_session.cpp +++ b/src/core/hle/kernel/server_session.cpp @@ -28,8 +28,9 @@ ServerSession::~ServerSession() { parent->server = nullptr; } -ResultVal> ServerSession::Create(KernelSystem& kernel, std::string name) { - SharedPtr server_session(new ServerSession(kernel)); +ResultVal> ServerSession::Create(KernelSystem& kernel, + std::string name) { + auto server_session{std::make_shared(kernel)}; server_session->name = std::move(name); server_session->parent = nullptr; @@ -59,7 +60,7 @@ void ServerSession::Acquire(Thread* thread) { pending_requesting_threads.pop_back(); } -ResultCode ServerSession::HandleSyncRequest(SharedPtr thread) { +ResultCode ServerSession::HandleSyncRequest(std::shared_ptr thread) { // The ServerSession received a sync request, this means that there's new data available // from its ClientSession, so wake up any threads that may be waiting on a svcReplyAndReceive or // similar. @@ -71,7 +72,7 @@ ResultCode ServerSession::HandleSyncRequest(SharedPtr thread) { kernel.memory.ReadBlock(*current_process, thread->GetCommandBufferAddress(), cmd_buf.data(), cmd_buf.size() * sizeof(u32)); - Kernel::HLERequestContext context(kernel, this); + Kernel::HLERequestContext context(kernel, SharedFrom(this)); context.PopulateFromIncomingCommandBuffer(cmd_buf.data(), *current_process); hle_handler->HandleSyncRequest(context); @@ -119,10 +120,10 @@ ResultCode ServerSession::HandleSyncRequest(SharedPtr thread) { return RESULT_SUCCESS; } -std::tuple, SharedPtr> KernelSystem::CreateSessionPair( - const std::string& name, SharedPtr port) { +std::tuple, std::shared_ptr> +KernelSystem::CreateSessionPair(const std::string& name, std::shared_ptr port) { auto server_session = ServerSession::Create(*this, name + "_Server").Unwrap(); - SharedPtr client_session(new ClientSession(*this)); + auto client_session{std::make_shared(*this)}; client_session->name = name + "_Client"; std::shared_ptr parent(new Session); diff --git a/src/core/hle/kernel/server_session.h b/src/core/hle/kernel/server_session.h index 8fe9a6552a..f1f36f392f 100644 --- a/src/core/hle/kernel/server_session.h +++ b/src/core/hle/kernel/server_session.h @@ -37,6 +37,9 @@ class Thread; */ class ServerSession final : public WaitObject { public: + ~ServerSession() override; + explicit ServerSession(KernelSystem& kernel); + std::string GetName() const override { return name; } @@ -63,7 +66,7 @@ public: * @param thread Thread that initiated the request. * @returns ResultCode from the operation. */ - ResultCode HandleSyncRequest(SharedPtr thread); + ResultCode HandleSyncRequest(std::shared_ptr thread); bool ShouldWait(Thread* thread) const override; @@ -77,20 +80,17 @@ public: /// List of threads that are pending a response after a sync request. This list is processed in /// a LIFO manner, thus, the last request will be dispatched first. /// TODO(Subv): Verify if this is indeed processed in LIFO using a hardware test. - std::vector> pending_requesting_threads; + std::vector> pending_requesting_threads; /// Thread whose request is currently being handled. A request is considered "handled" when a /// response is sent via svcReplyAndReceive. /// TODO(Subv): Find a better name for this. - SharedPtr currently_handling; + std::shared_ptr currently_handling; /// A temporary list holding mapped buffer info from IPC request, used for during IPC reply std::vector mapped_buffer_context; private: - explicit ServerSession(KernelSystem& kernel); - ~ServerSession() override; - /** * Creates a server session. The server session can have an optional HLE handler, * which will be invoked to handle the IPC requests that this session receives. @@ -98,8 +98,8 @@ private: * @param name Optional name of the server session. * @return The created server session */ - static ResultVal> Create(KernelSystem& kernel, - std::string name = "Unknown"); + static ResultVal> Create(KernelSystem& kernel, + std::string name = "Unknown"); friend class KernelSystem; KernelSystem& kernel; diff --git a/src/core/hle/kernel/session.h b/src/core/hle/kernel/session.h index 8df6c3e4ce..17bb4d6c67 100644 --- a/src/core/hle/kernel/session.h +++ b/src/core/hle/kernel/session.h @@ -4,6 +4,7 @@ #pragma once +#include #include "core/hle/kernel/object.h" namespace Kernel { @@ -20,8 +21,8 @@ class ServerSession; */ class Session final { public: - ClientSession* client = nullptr; ///< The client endpoint of the session. - ServerSession* server = nullptr; ///< The server endpoint of the session. - SharedPtr port; ///< The port that this session is associated with (optional). + ClientSession* client = nullptr; ///< The client endpoint of the session. + ServerSession* server = nullptr; ///< The server endpoint of the session. + std::shared_ptr port; ///< The port that this session is associated with (optional). }; } // namespace Kernel diff --git a/src/core/hle/kernel/shared_memory.cpp b/src/core/hle/kernel/shared_memory.cpp index 3e1e6d9f54..4cd3055085 100644 --- a/src/core/hle/kernel/shared_memory.cpp +++ b/src/core/hle/kernel/shared_memory.cpp @@ -24,10 +24,10 @@ SharedMemory::~SharedMemory() { } } -ResultVal> KernelSystem::CreateSharedMemory( +ResultVal> KernelSystem::CreateSharedMemory( Process* owner_process, u32 size, MemoryPermission permissions, MemoryPermission other_permissions, VAddr address, MemoryRegion region, std::string name) { - SharedPtr shared_memory(new SharedMemory(*this)); + auto shared_memory{std::make_shared(*this)}; shared_memory->owner_process = owner_process; shared_memory->name = std::move(name); @@ -69,10 +69,10 @@ ResultVal> KernelSystem::CreateSharedMemory( return MakeResult(shared_memory); } -SharedPtr KernelSystem::CreateSharedMemoryForApplet( +std::shared_ptr KernelSystem::CreateSharedMemoryForApplet( u32 offset, u32 size, MemoryPermission permissions, MemoryPermission other_permissions, std::string name) { - SharedPtr shared_memory(new SharedMemory(*this)); + auto shared_memory{std::make_shared(*this)}; // Allocate memory in heap MemoryRegionInfo* memory_region = GetMemoryRegion(MemoryRegion::SYSTEM); diff --git a/src/core/hle/kernel/shared_memory.h b/src/core/hle/kernel/shared_memory.h index afc0b3bb13..d4eeec6699 100644 --- a/src/core/hle/kernel/shared_memory.h +++ b/src/core/hle/kernel/shared_memory.h @@ -15,6 +15,9 @@ namespace Kernel { class SharedMemory final : public Object { public: + explicit SharedMemory(KernelSystem& kernel); + ~SharedMemory() override; + std::string GetTypeName() const override { return "SharedMemory"; } @@ -79,9 +82,6 @@ public: const u8* GetPointer(u32 offset = 0) const; private: - explicit SharedMemory(KernelSystem& kernel); - ~SharedMemory() override; - /// Offset in FCRAM of the shared memory block in the linear heap if no address was specified /// during creation. PAddr linear_heap_phys_offset = 0; diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 892aa0dc18..3a5b60654f 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp @@ -271,7 +271,7 @@ ResultCode SVC::ControlMemory(u32* out_addr, u32 addr0, u32 addr1, u32 size, u32 } void SVC::ExitProcess() { - SharedPtr current_process = kernel.GetCurrentProcess(); + std::shared_ptr current_process = kernel.GetCurrentProcess(); LOG_INFO(Kernel_SVC, "Process {} exiting", current_process->process_id); ASSERT_MSG(current_process->status == ProcessStatus::Running, "Process has already exited"); @@ -281,10 +281,10 @@ void SVC::ExitProcess() { // Stop all the process threads that are currently waiting for objects. auto& thread_list = kernel.GetThreadManager().GetThreadList(); for (auto& thread : thread_list) { - if (thread->owner_process != current_process) + if (thread->owner_process != current_process.get()) continue; - if (thread == kernel.GetThreadManager().GetCurrentThread()) + if (thread.get() == kernel.GetThreadManager().GetCurrentThread()) continue; // TODO(Subv): When are the other running/ready threads terminated? @@ -308,7 +308,7 @@ ResultCode SVC::MapMemoryBlock(Handle handle, u32 addr, u32 permissions, u32 oth "otherpermission={}", handle, addr, permissions, other_permissions); - SharedPtr shared_memory = + std::shared_ptr shared_memory = kernel.GetCurrentProcess()->handle_table.Get(handle); if (shared_memory == nullptr) return ERR_INVALID_HANDLE; @@ -337,8 +337,9 @@ ResultCode SVC::UnmapMemoryBlock(Handle handle, u32 addr) { // TODO(Subv): Return E0A01BF5 if the address is not in the application's heap - SharedPtr current_process = kernel.GetCurrentProcess(); - SharedPtr shared_memory = current_process->handle_table.Get(handle); + std::shared_ptr current_process = kernel.GetCurrentProcess(); + std::shared_ptr shared_memory = + current_process->handle_table.Get(handle); if (shared_memory == nullptr) return ERR_INVALID_HANDLE; @@ -366,7 +367,7 @@ ResultCode SVC::ConnectToPort(Handle* out_handle, VAddr port_name_address) { auto client_port = it->second; - SharedPtr client_session; + std::shared_ptr client_session; CASCADE_RESULT(client_session, client_port->Connect()); // Return the client session @@ -376,7 +377,7 @@ ResultCode SVC::ConnectToPort(Handle* out_handle, VAddr port_name_address) { /// Makes a blocking IPC call to an OS service. ResultCode SVC::SendSyncRequest(Handle handle) { - SharedPtr session = + std::shared_ptr session = kernel.GetCurrentProcess()->handle_table.Get(handle); if (session == nullptr) { return ERR_INVALID_HANDLE; @@ -386,7 +387,7 @@ ResultCode SVC::SendSyncRequest(Handle handle) { system.PrepareReschedule(); - return session->SendSyncRequest(kernel.GetThreadManager().GetCurrentThread()); + return session->SendSyncRequest(SharedFrom(kernel.GetThreadManager().GetCurrentThread())); } /// Close a handle @@ -412,14 +413,14 @@ ResultCode SVC::WaitSynchronization1(Handle handle, s64 nano_seconds) { return RESULT_TIMEOUT; thread->wait_objects = {object}; - object->AddWaitingThread(thread); + object->AddWaitingThread(SharedFrom(thread)); thread->status = ThreadStatus::WaitSynchAny; // Create an event to wake the thread up after the specified nanosecond delay has passed thread->WakeAfterDelay(nano_seconds); - thread->wakeup_callback = [](ThreadWakeupReason reason, SharedPtr thread, - SharedPtr object) { + thread->wakeup_callback = [](ThreadWakeupReason reason, std::shared_ptr thread, + std::shared_ptr object) { ASSERT(thread->status == ThreadStatus::WaitSynchAny); if (reason == ThreadWakeupReason::Timeout) { @@ -463,7 +464,7 @@ ResultCode SVC::WaitSynchronizationN(s32* out, VAddr handles_address, s32 handle if (handle_count < 0) return ERR_OUT_OF_RANGE; - using ObjectPtr = SharedPtr; + using ObjectPtr = std::shared_ptr; std::vector objects(handle_count); for (int i = 0; i < handle_count; ++i) { @@ -499,7 +500,7 @@ ResultCode SVC::WaitSynchronizationN(s32* out, VAddr handles_address, s32 handle // Add the thread to each of the objects' waiting threads. for (auto& object : objects) { - object->AddWaitingThread(thread); + object->AddWaitingThread(SharedFrom(thread)); } thread->wait_objects = std::move(objects); @@ -507,8 +508,8 @@ ResultCode SVC::WaitSynchronizationN(s32* out, VAddr handles_address, s32 handle // Create an event to wake the thread up after the specified nanosecond delay has passed thread->WakeAfterDelay(nano_seconds); - thread->wakeup_callback = [](ThreadWakeupReason reason, SharedPtr thread, - SharedPtr object) { + thread->wakeup_callback = [](ThreadWakeupReason reason, std::shared_ptr thread, + std::shared_ptr object) { ASSERT(thread->status == ThreadStatus::WaitSynchAll); if (reason == ThreadWakeupReason::Timeout) { @@ -556,7 +557,7 @@ ResultCode SVC::WaitSynchronizationN(s32* out, VAddr handles_address, s32 handle // Add the thread to each of the objects' waiting threads. for (std::size_t i = 0; i < objects.size(); ++i) { WaitObject* object = objects[i].get(); - object->AddWaitingThread(thread); + object->AddWaitingThread(SharedFrom(thread)); } thread->wait_objects = std::move(objects); @@ -567,8 +568,8 @@ ResultCode SVC::WaitSynchronizationN(s32* out, VAddr handles_address, s32 handle // Create an event to wake the thread up after the specified nanosecond delay has passed thread->WakeAfterDelay(nano_seconds); - thread->wakeup_callback = [](ThreadWakeupReason reason, SharedPtr thread, - SharedPtr object) { + thread->wakeup_callback = [](ThreadWakeupReason reason, std::shared_ptr thread, + std::shared_ptr object) { ASSERT(thread->status == ThreadStatus::WaitSynchAny); if (reason == ThreadWakeupReason::Timeout) { @@ -593,8 +594,8 @@ ResultCode SVC::WaitSynchronizationN(s32* out, VAddr handles_address, s32 handle } static ResultCode ReceiveIPCRequest(Memory::MemorySystem& memory, - SharedPtr server_session, - SharedPtr thread) { + std::shared_ptr server_session, + std::shared_ptr thread) { if (server_session->parent->client == nullptr) { return ERR_SESSION_CLOSED_BY_REMOTE; } @@ -631,10 +632,10 @@ ResultCode SVC::ReplyAndReceive(s32* index, VAddr handles_address, s32 handle_co if (handle_count < 0) return ERR_OUT_OF_RANGE; - using ObjectPtr = SharedPtr; + using ObjectPtr = std::shared_ptr; std::vector objects(handle_count); - SharedPtr current_process = kernel.GetCurrentProcess(); + std::shared_ptr current_process = kernel.GetCurrentProcess(); for (int i = 0; i < handle_count; ++i) { Handle handle = memory.Read32(handles_address + i * sizeof(Handle)); @@ -670,8 +671,8 @@ ResultCode SVC::ReplyAndReceive(s32* index, VAddr handles_address, s32 handle_co VAddr target_address = request_thread->GetCommandBufferAddress(); ResultCode translation_result = - TranslateCommandBuffer(memory, thread, request_thread, source_address, target_address, - session->mapped_buffer_context, true); + TranslateCommandBuffer(memory, SharedFrom(thread), request_thread, source_address, + target_address, session->mapped_buffer_context, true); // Note: The real kernel seems to always panic if the Server->Client buffer translation // fails for whatever reason. @@ -706,7 +707,7 @@ ResultCode SVC::ReplyAndReceive(s32* index, VAddr handles_address, s32 handle_co return RESULT_SUCCESS; auto server_session = static_cast(object); - return ReceiveIPCRequest(memory, server_session, thread); + return ReceiveIPCRequest(memory, SharedFrom(server_session), SharedFrom(thread)); } // No objects were ready to be acquired, prepare to suspend the thread. @@ -717,14 +718,14 @@ ResultCode SVC::ReplyAndReceive(s32* index, VAddr handles_address, s32 handle_co // Add the thread to each of the objects' waiting threads. for (std::size_t i = 0; i < objects.size(); ++i) { WaitObject* object = objects[i].get(); - object->AddWaitingThread(thread); + object->AddWaitingThread(SharedFrom(thread)); } thread->wait_objects = std::move(objects); thread->wakeup_callback = [& memory = this->memory](ThreadWakeupReason reason, - SharedPtr thread, - SharedPtr object) { + std::shared_ptr thread, + std::shared_ptr object) { ASSERT(thread->status == ThreadStatus::WaitSynchAny); ASSERT(reason == ThreadWakeupReason::Signal); @@ -750,7 +751,7 @@ ResultCode SVC::ReplyAndReceive(s32* index, VAddr handles_address, s32 handle_co /// Create an address arbiter (to allocate access to shared resources) ResultCode SVC::CreateAddressArbiter(Handle* out_handle) { - SharedPtr arbiter = kernel.CreateAddressArbiter(); + std::shared_ptr arbiter = kernel.CreateAddressArbiter(); CASCADE_RESULT(*out_handle, kernel.GetCurrentProcess()->handle_table.Create(std::move(arbiter))); LOG_TRACE(Kernel_SVC, "returned handle=0x{:08X}", *out_handle); @@ -762,13 +763,13 @@ ResultCode SVC::ArbitrateAddress(Handle handle, u32 address, u32 type, u32 value LOG_TRACE(Kernel_SVC, "called handle=0x{:08X}, address=0x{:08X}, type=0x{:08X}, value=0x{:08X}", handle, address, type, value); - SharedPtr arbiter = + std::shared_ptr arbiter = kernel.GetCurrentProcess()->handle_table.Get(handle); if (arbiter == nullptr) return ERR_INVALID_HANDLE; auto res = - arbiter->ArbitrateAddress(kernel.GetThreadManager().GetCurrentThread(), + arbiter->ArbitrateAddress(SharedFrom(kernel.GetThreadManager().GetCurrentThread()), static_cast(type), address, value, nanoseconds); // TODO(Subv): Identify in which specific cases this call should cause a reschedule. @@ -812,8 +813,8 @@ void SVC::OutputDebugString(VAddr address, s32 len) { ResultCode SVC::GetResourceLimit(Handle* resource_limit, Handle process_handle) { LOG_TRACE(Kernel_SVC, "called process=0x{:08X}", process_handle); - SharedPtr current_process = kernel.GetCurrentProcess(); - SharedPtr process = current_process->handle_table.Get(process_handle); + std::shared_ptr current_process = kernel.GetCurrentProcess(); + std::shared_ptr process = current_process->handle_table.Get(process_handle); if (process == nullptr) return ERR_INVALID_HANDLE; @@ -828,7 +829,7 @@ ResultCode SVC::GetResourceLimitCurrentValues(VAddr values, Handle resource_limi LOG_TRACE(Kernel_SVC, "called resource_limit={:08X}, names={:08X}, name_count={}", resource_limit_handle, names, name_count); - SharedPtr resource_limit = + std::shared_ptr resource_limit = kernel.GetCurrentProcess()->handle_table.Get(resource_limit_handle); if (resource_limit == nullptr) return ERR_INVALID_HANDLE; @@ -848,7 +849,7 @@ ResultCode SVC::GetResourceLimitLimitValues(VAddr values, Handle resource_limit_ LOG_TRACE(Kernel_SVC, "called resource_limit={:08X}, names={:08X}, name_count={}", resource_limit_handle, names, name_count); - SharedPtr resource_limit = + std::shared_ptr resource_limit = kernel.GetCurrentProcess()->handle_table.Get(resource_limit_handle); if (resource_limit == nullptr) return ERR_INVALID_HANDLE; @@ -871,9 +872,9 @@ ResultCode SVC::CreateThread(Handle* out_handle, u32 entry_point, u32 arg, VAddr return ERR_OUT_OF_RANGE; } - SharedPtr current_process = kernel.GetCurrentProcess(); + std::shared_ptr current_process = kernel.GetCurrentProcess(); - SharedPtr& resource_limit = current_process->resource_limit; + std::shared_ptr& resource_limit = current_process->resource_limit; if (resource_limit->GetMaxResourceValue(ResourceTypes::PRIORITY) > priority) { return ERR_NOT_AUTHORIZED; } @@ -901,7 +902,7 @@ ResultCode SVC::CreateThread(Handle* out_handle, u32 entry_point, u32 arg, VAddr break; } - CASCADE_RESULT(SharedPtr thread, + CASCADE_RESULT(std::shared_ptr thread, kernel.CreateThread(name, entry_point, priority, arg, processor_id, stack_top, *current_process)); @@ -930,7 +931,8 @@ void SVC::ExitThread() { /// Gets the priority for the specified thread ResultCode SVC::GetThreadPriority(u32* priority, Handle handle) { - const SharedPtr thread = kernel.GetCurrentProcess()->handle_table.Get(handle); + const std::shared_ptr thread = + kernel.GetCurrentProcess()->handle_table.Get(handle); if (thread == nullptr) return ERR_INVALID_HANDLE; @@ -944,13 +946,13 @@ ResultCode SVC::SetThreadPriority(Handle handle, u32 priority) { return ERR_OUT_OF_RANGE; } - SharedPtr thread = kernel.GetCurrentProcess()->handle_table.Get(handle); + std::shared_ptr thread = kernel.GetCurrentProcess()->handle_table.Get(handle); if (thread == nullptr) return ERR_INVALID_HANDLE; // Note: The kernel uses the current process's resource limit instead of // the one from the thread owner's resource limit. - SharedPtr& resource_limit = kernel.GetCurrentProcess()->resource_limit; + std::shared_ptr& resource_limit = kernel.GetCurrentProcess()->resource_limit; if (resource_limit->GetMaxResourceValue(ResourceTypes::PRIORITY) > priority) { return ERR_NOT_AUTHORIZED; } @@ -968,7 +970,7 @@ ResultCode SVC::SetThreadPriority(Handle handle, u32 priority) { /// Create a mutex ResultCode SVC::CreateMutex(Handle* out_handle, u32 initial_locked) { - SharedPtr mutex = kernel.CreateMutex(initial_locked != 0); + std::shared_ptr mutex = kernel.CreateMutex(initial_locked != 0); mutex->name = fmt::format("mutex-{:08x}", system.CPU().GetReg(14)); CASCADE_RESULT(*out_handle, kernel.GetCurrentProcess()->handle_table.Create(std::move(mutex))); @@ -982,7 +984,7 @@ ResultCode SVC::CreateMutex(Handle* out_handle, u32 initial_locked) { ResultCode SVC::ReleaseMutex(Handle handle) { LOG_TRACE(Kernel_SVC, "called handle=0x{:08X}", handle); - SharedPtr mutex = kernel.GetCurrentProcess()->handle_table.Get(handle); + std::shared_ptr mutex = kernel.GetCurrentProcess()->handle_table.Get(handle); if (mutex == nullptr) return ERR_INVALID_HANDLE; @@ -993,7 +995,7 @@ ResultCode SVC::ReleaseMutex(Handle handle) { ResultCode SVC::GetProcessId(u32* process_id, Handle process_handle) { LOG_TRACE(Kernel_SVC, "called process=0x{:08X}", process_handle); - const SharedPtr process = + const std::shared_ptr process = kernel.GetCurrentProcess()->handle_table.Get(process_handle); if (process == nullptr) return ERR_INVALID_HANDLE; @@ -1006,12 +1008,12 @@ ResultCode SVC::GetProcessId(u32* process_id, Handle process_handle) { ResultCode SVC::GetProcessIdOfThread(u32* process_id, Handle thread_handle) { LOG_TRACE(Kernel_SVC, "called thread=0x{:08X}", thread_handle); - const SharedPtr thread = + const std::shared_ptr thread = kernel.GetCurrentProcess()->handle_table.Get(thread_handle); if (thread == nullptr) return ERR_INVALID_HANDLE; - const SharedPtr process = thread->owner_process; + const std::shared_ptr process = SharedFrom(thread->owner_process); ASSERT_MSG(process != nullptr, "Invalid parent process for thread={:#010X}", thread_handle); @@ -1023,7 +1025,8 @@ ResultCode SVC::GetProcessIdOfThread(u32* process_id, Handle thread_handle) { ResultCode SVC::GetThreadId(u32* thread_id, Handle handle) { LOG_TRACE(Kernel_SVC, "called thread=0x{:08X}", handle); - const SharedPtr thread = kernel.GetCurrentProcess()->handle_table.Get(handle); + const std::shared_ptr thread = + kernel.GetCurrentProcess()->handle_table.Get(handle); if (thread == nullptr) return ERR_INVALID_HANDLE; @@ -1033,7 +1036,7 @@ ResultCode SVC::GetThreadId(u32* thread_id, Handle handle) { /// Creates a semaphore ResultCode SVC::CreateSemaphore(Handle* out_handle, s32 initial_count, s32 max_count) { - CASCADE_RESULT(SharedPtr semaphore, + CASCADE_RESULT(std::shared_ptr semaphore, kernel.CreateSemaphore(initial_count, max_count)); semaphore->name = fmt::format("semaphore-{:08x}", system.CPU().GetReg(14)); CASCADE_RESULT(*out_handle, @@ -1048,7 +1051,7 @@ ResultCode SVC::CreateSemaphore(Handle* out_handle, s32 initial_count, s32 max_c ResultCode SVC::ReleaseSemaphore(s32* count, Handle handle, s32 release_count) { LOG_TRACE(Kernel_SVC, "called release_count={}, handle=0x{:08X}", release_count, handle); - SharedPtr semaphore = + std::shared_ptr semaphore = kernel.GetCurrentProcess()->handle_table.Get(handle); if (semaphore == nullptr) return ERR_INVALID_HANDLE; @@ -1061,7 +1064,7 @@ ResultCode SVC::ReleaseSemaphore(s32* count, Handle handle, s32 release_count) { /// Query process memory ResultCode SVC::QueryProcessMemory(MemoryInfo* memory_info, PageInfo* page_info, Handle process_handle, u32 addr) { - SharedPtr process = + std::shared_ptr process = kernel.GetCurrentProcess()->handle_table.Get(process_handle); if (process == nullptr) return ERR_INVALID_HANDLE; @@ -1105,8 +1108,8 @@ ResultCode SVC::QueryMemory(MemoryInfo* memory_info, PageInfo* page_info, u32 ad /// Create an event ResultCode SVC::CreateEvent(Handle* out_handle, u32 reset_type) { - SharedPtr evt = kernel.CreateEvent(static_cast(reset_type), - fmt::format("event-{:08x}", system.CPU().GetReg(14))); + std::shared_ptr evt = kernel.CreateEvent( + static_cast(reset_type), fmt::format("event-{:08x}", system.CPU().GetReg(14))); CASCADE_RESULT(*out_handle, kernel.GetCurrentProcess()->handle_table.Create(std::move(evt))); LOG_TRACE(Kernel_SVC, "called reset_type=0x{:08X} : created handle=0x{:08X}", reset_type, @@ -1125,7 +1128,7 @@ ResultCode SVC::DuplicateHandle(Handle* out, Handle handle) { ResultCode SVC::SignalEvent(Handle handle) { LOG_TRACE(Kernel_SVC, "called event=0x{:08X}", handle); - SharedPtr evt = kernel.GetCurrentProcess()->handle_table.Get(handle); + std::shared_ptr evt = kernel.GetCurrentProcess()->handle_table.Get(handle); if (evt == nullptr) return ERR_INVALID_HANDLE; @@ -1138,7 +1141,7 @@ ResultCode SVC::SignalEvent(Handle handle) { ResultCode SVC::ClearEvent(Handle handle) { LOG_TRACE(Kernel_SVC, "called event=0x{:08X}", handle); - SharedPtr evt = kernel.GetCurrentProcess()->handle_table.Get(handle); + std::shared_ptr evt = kernel.GetCurrentProcess()->handle_table.Get(handle); if (evt == nullptr) return ERR_INVALID_HANDLE; @@ -1148,7 +1151,7 @@ ResultCode SVC::ClearEvent(Handle handle) { /// Creates a timer ResultCode SVC::CreateTimer(Handle* out_handle, u32 reset_type) { - SharedPtr timer = kernel.CreateTimer( + std::shared_ptr timer = kernel.CreateTimer( static_cast(reset_type), fmt ::format("timer-{:08x}", system.CPU().GetReg(14))); CASCADE_RESULT(*out_handle, kernel.GetCurrentProcess()->handle_table.Create(std::move(timer))); @@ -1161,7 +1164,7 @@ ResultCode SVC::CreateTimer(Handle* out_handle, u32 reset_type) { ResultCode SVC::ClearTimer(Handle handle) { LOG_TRACE(Kernel_SVC, "called timer=0x{:08X}", handle); - SharedPtr timer = kernel.GetCurrentProcess()->handle_table.Get(handle); + std::shared_ptr timer = kernel.GetCurrentProcess()->handle_table.Get(handle); if (timer == nullptr) return ERR_INVALID_HANDLE; @@ -1177,7 +1180,7 @@ ResultCode SVC::SetTimer(Handle handle, s64 initial, s64 interval) { return ERR_OUT_OF_RANGE_KERNEL; } - SharedPtr timer = kernel.GetCurrentProcess()->handle_table.Get(handle); + std::shared_ptr timer = kernel.GetCurrentProcess()->handle_table.Get(handle); if (timer == nullptr) return ERR_INVALID_HANDLE; @@ -1190,7 +1193,7 @@ ResultCode SVC::SetTimer(Handle handle, s64 initial, s64 interval) { ResultCode SVC::CancelTimer(Handle handle) { LOG_TRACE(Kernel_SVC, "called timer=0x{:08X}", handle); - SharedPtr timer = kernel.GetCurrentProcess()->handle_table.Get(handle); + std::shared_ptr timer = kernel.GetCurrentProcess()->handle_table.Get(handle); if (timer == nullptr) return ERR_INVALID_HANDLE; @@ -1234,7 +1237,7 @@ ResultCode SVC::CreateMemoryBlock(Handle* out_handle, u32 addr, u32 size, u32 my if (size % Memory::PAGE_SIZE != 0) return ERR_MISALIGNED_SIZE; - SharedPtr shared_memory = nullptr; + std::shared_ptr shared_memory = nullptr; auto VerifyPermissions = [](MemoryPermission permission) { // SharedMemory blocks can not be created with Execute permissions @@ -1262,7 +1265,7 @@ ResultCode SVC::CreateMemoryBlock(Handle* out_handle, u32 addr, u32 size, u32 my return ERR_INVALID_ADDRESS; } - SharedPtr current_process = kernel.GetCurrentProcess(); + std::shared_ptr current_process = kernel.GetCurrentProcess(); // When trying to create a memory block with address = 0, // if the process has the Shared Device Memory flag in the exheader, @@ -1287,23 +1290,23 @@ ResultCode SVC::CreatePort(Handle* server_port, Handle* client_port, VAddr name_ // TODO(Subv): Implement named ports. ASSERT_MSG(name_address == 0, "Named ports are currently unimplemented"); - SharedPtr current_process = kernel.GetCurrentProcess(); + std::shared_ptr current_process = kernel.GetCurrentProcess(); auto ports = kernel.CreatePortPair(max_sessions); CASCADE_RESULT(*client_port, current_process->handle_table.Create( - std::move(std::get>(ports)))); + std::move(std::get>(ports)))); // Note: The 3DS kernel also leaks the client port handle if the server port handle fails to be // created. CASCADE_RESULT(*server_port, current_process->handle_table.Create( - std::move(std::get>(ports)))); + std::move(std::get>(ports)))); LOG_TRACE(Kernel_SVC, "called max_sessions={}", max_sessions); return RESULT_SUCCESS; } ResultCode SVC::CreateSessionToPort(Handle* out_client_session, Handle client_port_handle) { - SharedPtr current_process = kernel.GetCurrentProcess(); - SharedPtr client_port = + std::shared_ptr current_process = kernel.GetCurrentProcess(); + std::shared_ptr client_port = current_process->handle_table.Get(client_port_handle); if (client_port == nullptr) return ERR_INVALID_HANDLE; @@ -1316,12 +1319,12 @@ ResultCode SVC::CreateSessionToPort(Handle* out_client_session, Handle client_po ResultCode SVC::CreateSession(Handle* server_session, Handle* client_session) { auto sessions = kernel.CreateSessionPair(); - SharedPtr current_process = kernel.GetCurrentProcess(); + std::shared_ptr current_process = kernel.GetCurrentProcess(); - auto& server = std::get>(sessions); + auto& server = std::get>(sessions); CASCADE_RESULT(*server_session, current_process->handle_table.Create(std::move(server))); - auto& client = std::get>(sessions); + auto& client = std::get>(sessions); CASCADE_RESULT(*client_session, current_process->handle_table.Create(std::move(client))); LOG_TRACE(Kernel_SVC, "called"); @@ -1329,8 +1332,8 @@ ResultCode SVC::CreateSession(Handle* server_session, Handle* client_session) { } ResultCode SVC::AcceptSession(Handle* out_server_session, Handle server_port_handle) { - SharedPtr current_process = kernel.GetCurrentProcess(); - SharedPtr server_port = + std::shared_ptr current_process = kernel.GetCurrentProcess(); + std::shared_ptr server_port = current_process->handle_table.Get(server_port_handle); if (server_port == nullptr) return ERR_INVALID_HANDLE; @@ -1386,7 +1389,7 @@ ResultCode SVC::GetSystemInfo(s64* out, u32 type, s32 param) { ResultCode SVC::GetProcessInfo(s64* out, Handle process_handle, u32 type) { LOG_TRACE(Kernel_SVC, "called process=0x{:08X} type={}", process_handle, type); - SharedPtr process = + std::shared_ptr process = kernel.GetCurrentProcess()->handle_table.Get(process_handle); if (process == nullptr) return ERR_INVALID_HANDLE; diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index c3ad3d054e..819ccd53ac 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp @@ -105,13 +105,13 @@ void ThreadManager::SwitchContext(Thread* new_thread) { auto previous_process = kernel.GetCurrentProcess(); - current_thread = new_thread; + current_thread = SharedFrom(new_thread); ready_queue.remove(new_thread->current_priority, new_thread); new_thread->status = ThreadStatus::Running; - if (previous_process != current_thread->owner_process) { - kernel.SetCurrentProcess(current_thread->owner_process); + if (previous_process.get() != current_thread->owner_process) { + kernel.SetCurrentProcess(SharedFrom(current_thread->owner_process)); kernel.memory.SetCurrentPageTable( ¤t_thread->owner_process->vm_manager.page_table); } @@ -152,12 +152,13 @@ void ThreadManager::WaitCurrentThread_Sleep() { void ThreadManager::ExitCurrentThread() { Thread* thread = GetCurrentThread(); thread->Stop(); - thread_list.erase(std::remove(thread_list.begin(), thread_list.end(), thread), + thread_list.erase(std::remove_if(thread_list.begin(), thread_list.end(), + [thread](const auto& p) { return p.get() == thread; }), thread_list.end()); } void ThreadManager::ThreadWakeupCallback(u64 thread_id, s64 cycles_late) { - SharedPtr thread = wakeup_callback_table.at(thread_id); + std::shared_ptr thread = SharedFrom(wakeup_callback_table.at(thread_id)); if (thread == nullptr) { LOG_CRITICAL(Kernel, "Callback fired for invalid thread {:08X}", thread_id); return; @@ -286,9 +287,10 @@ static void ResetThreadContext(const std::unique_ptrSetCpsr(USER32MODE | ((entry_point & 1) << 5)); // Usermode and THUMB mode } -ResultVal> KernelSystem::CreateThread(std::string name, VAddr entry_point, - u32 priority, u32 arg, s32 processor_id, - VAddr stack_top, Process& owner_process) { +ResultVal> KernelSystem::CreateThread(std::string name, VAddr entry_point, + u32 priority, u32 arg, + s32 processor_id, VAddr stack_top, + Process& owner_process) { // Check if priority is in ranged. Lowest priority -> highest priority id. if (priority > ThreadPrioLowest) { LOG_ERROR(Kernel_SVC, "Invalid thread priority: {}", priority); @@ -309,7 +311,7 @@ ResultVal> KernelSystem::CreateThread(std::string name, VAddr ErrorSummary::InvalidArgument, ErrorLevel::Permanent); } - SharedPtr thread(new Thread(*this)); + auto thread{std::make_shared(*this)}; thread_manager->thread_list.push_back(thread); thread_manager->ready_queue.prepare(priority); @@ -372,7 +374,7 @@ ResultVal> KernelSystem::CreateThread(std::string name, VAddr thread_manager->ready_queue.push_back(thread->current_priority, thread.get()); thread->status = ThreadStatus::Ready; - return MakeResult>(std::move(thread)); + return MakeResult>(std::move(thread)); } void Thread::SetPriority(u32 priority) { @@ -405,14 +407,14 @@ void Thread::BoostPriority(u32 priority) { current_priority = priority; } -SharedPtr SetupMainThread(KernelSystem& kernel, u32 entry_point, u32 priority, - SharedPtr owner_process) { +std::shared_ptr SetupMainThread(KernelSystem& kernel, u32 entry_point, u32 priority, + std::shared_ptr owner_process) { // Initialize new "main" thread auto thread_res = kernel.CreateThread("main", entry_point, priority, 0, owner_process->ideal_processor, Memory::HEAP_VADDR_END, *owner_process); - SharedPtr thread = std::move(thread_res).Unwrap(); + std::shared_ptr thread = std::move(thread_res).Unwrap(); thread->context->SetFpscr(FPSCR_DEFAULT_NAN | FPSCR_FLUSH_TO_ZERO | FPSCR_ROUND_TOZERO | FPSCR_IXC); // 0x03C00010 @@ -450,7 +452,8 @@ void Thread::SetWaitSynchronizationOutput(s32 output) { s32 Thread::GetWaitObjectIndex(WaitObject* object) const { ASSERT_MSG(!wait_objects.empty(), "Thread is not waiting for anything"); - auto match = std::find(wait_objects.rbegin(), wait_objects.rend(), object); + auto match = std::find_if(wait_objects.rbegin(), wait_objects.rend(), + [object](const auto& p) { return p.get() == object; }); return static_cast(std::distance(match, wait_objects.rend()) - 1); } @@ -473,7 +476,7 @@ ThreadManager::~ThreadManager() { } } -const std::vector>& ThreadManager::GetThreadList() { +const std::vector>& ThreadManager::GetThreadList() { return thread_list; } diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h index 8f5da92c7d..7ab90ccc43 100644 --- a/src/core/hle/kernel/thread.h +++ b/src/core/hle/kernel/thread.h @@ -4,6 +4,7 @@ #pragma once +#include #include #include #include @@ -99,7 +100,7 @@ public: /** * Get a const reference to the thread list for debug use */ - const std::vector>& GetThreadList(); + const std::vector>& GetThreadList(); void SetCPU(ARM_Interface& cpu) { this->cpu = &cpu; @@ -133,7 +134,7 @@ private: ARM_Interface* cpu; u32 next_thread_id = 1; - SharedPtr current_thread; + std::shared_ptr current_thread; Common::ThreadQueueList ready_queue; std::unordered_map wakeup_callback_table; @@ -141,7 +142,7 @@ private: Core::TimingEventType* ThreadWakeupEventType = nullptr; // Lists all threadsthat aren't deleted. - std::vector> thread_list; + std::vector> thread_list; friend class Thread; friend class KernelSystem; @@ -149,6 +150,9 @@ private: class Thread final : public WaitObject { public: + explicit Thread(KernelSystem&); + ~Thread() override; + std::string GetName() const override { return name; } @@ -278,35 +282,30 @@ public: VAddr tls_address; ///< Virtual address of the Thread Local Storage of the thread /// Mutexes currently held by this thread, which will be released when it exits. - boost::container::flat_set> held_mutexes; + boost::container::flat_set> held_mutexes; /// Mutexes that this thread is currently waiting for. - boost::container::flat_set> pending_mutexes; + boost::container::flat_set> pending_mutexes; Process* owner_process; ///< Process that owns this thread /// Objects that the thread is waiting on, in the same order as they were // passed to WaitSynchronization1/N. - std::vector> wait_objects; + std::vector> wait_objects; VAddr wait_address; ///< If waiting on an AddressArbiter, this is the arbitration address std::string name; - using WakeupCallback = void(ThreadWakeupReason reason, SharedPtr thread, - SharedPtr object); + using WakeupCallback = void(ThreadWakeupReason reason, std::shared_ptr thread, + std::shared_ptr object); // Callback that will be invoked when the thread is resumed from a waiting state. If the thread // was waiting via WaitSynchronizationN then the object will be the last object that became // available. In case of a timeout, the object will be nullptr. std::function wakeup_callback; private: - explicit Thread(KernelSystem&); - ~Thread() override; - ThreadManager& thread_manager; - - friend class KernelSystem; }; /** @@ -317,7 +316,7 @@ private: * @param owner_process The parent process for the main thread * @return A shared pointer to the main thread */ -SharedPtr SetupMainThread(KernelSystem& kernel, u32 entry_point, u32 priority, - SharedPtr owner_process); +std::shared_ptr SetupMainThread(KernelSystem& kernel, u32 entry_point, u32 priority, + std::shared_ptr owner_process); } // namespace Kernel diff --git a/src/core/hle/kernel/timer.cpp b/src/core/hle/kernel/timer.cpp index 08f21479f5..bac1ca848f 100644 --- a/src/core/hle/kernel/timer.cpp +++ b/src/core/hle/kernel/timer.cpp @@ -21,8 +21,8 @@ Timer::~Timer() { timer_manager.timer_callback_table.erase(callback_id); } -SharedPtr KernelSystem::CreateTimer(ResetType reset_type, std::string name) { - SharedPtr timer(new Timer(*this)); +std::shared_ptr KernelSystem::CreateTimer(ResetType reset_type, std::string name) { + auto timer{std::make_shared(*this)}; timer->reset_type = reset_type; timer->signaled = false; @@ -94,7 +94,7 @@ void Timer::Signal(s64 cycles_late) { /// The timer callback event, called when a timer is fired void TimerManager::TimerCallback(u64 callback_id, s64 cycles_late) { - SharedPtr timer = timer_callback_table.at(callback_id); + std::shared_ptr timer = SharedFrom(timer_callback_table.at(callback_id)); if (timer == nullptr) { LOG_CRITICAL(Kernel, "Callback fired for invalid timer {:016x}", callback_id); diff --git a/src/core/hle/kernel/timer.h b/src/core/hle/kernel/timer.h index be11ab16c9..91825e7af9 100644 --- a/src/core/hle/kernel/timer.h +++ b/src/core/hle/kernel/timer.h @@ -37,6 +37,9 @@ private: class Timer final : public WaitObject { public: + explicit Timer(KernelSystem& kernel); + ~Timer() override; + std::string GetTypeName() const override { return "Timer"; } @@ -85,9 +88,6 @@ public: void Signal(s64 cycles_late); private: - explicit Timer(KernelSystem& kernel); - ~Timer() override; - ResetType reset_type; ///< The ResetType of this timer u64 initial_delay; ///< The delay until the timer fires for the first time diff --git a/src/core/hle/kernel/wait_object.cpp b/src/core/hle/kernel/wait_object.cpp index a63cf4c336..b2835ffbdc 100644 --- a/src/core/hle/kernel/wait_object.cpp +++ b/src/core/hle/kernel/wait_object.cpp @@ -16,14 +16,15 @@ namespace Kernel { -void WaitObject::AddWaitingThread(SharedPtr thread) { +void WaitObject::AddWaitingThread(std::shared_ptr thread) { auto itr = std::find(waiting_threads.begin(), waiting_threads.end(), thread); if (itr == waiting_threads.end()) waiting_threads.push_back(std::move(thread)); } void WaitObject::RemoveWaitingThread(Thread* thread) { - auto itr = std::find(waiting_threads.begin(), waiting_threads.end(), thread); + auto itr = std::find_if(waiting_threads.begin(), waiting_threads.end(), + [thread](const auto& p) { return p.get() == thread; }); // If a thread passed multiple handles to the same object, // the kernel might attempt to remove the thread from the object's // waiting threads list multiple times. @@ -31,7 +32,7 @@ void WaitObject::RemoveWaitingThread(Thread* thread) { waiting_threads.erase(itr); } -SharedPtr WaitObject::GetHighestPriorityReadyThread() { +std::shared_ptr WaitObject::GetHighestPriorityReadyThread() { Thread* candidate = nullptr; u32 candidate_priority = ThreadPrioLowest + 1; @@ -53,7 +54,7 @@ SharedPtr WaitObject::GetHighestPriorityReadyThread() { bool ready_to_run = true; if (thread->status == ThreadStatus::WaitSynchAll) { ready_to_run = std::none_of(thread->wait_objects.begin(), thread->wait_objects.end(), - [&thread](const SharedPtr& object) { + [&thread](const std::shared_ptr& object) { return object->ShouldWait(thread.get()); }); } @@ -64,7 +65,7 @@ SharedPtr WaitObject::GetHighestPriorityReadyThread() { } } - return candidate; + return SharedFrom(candidate); } void WaitObject::WakeupAllWaitingThreads() { @@ -79,7 +80,7 @@ void WaitObject::WakeupAllWaitingThreads() { // Invoke the wakeup callback before clearing the wait objects if (thread->wakeup_callback) - thread->wakeup_callback(ThreadWakeupReason::Signal, thread, this); + thread->wakeup_callback(ThreadWakeupReason::Signal, thread, SharedFrom(this)); for (auto& object : thread->wait_objects) object->RemoveWaitingThread(thread.get()); @@ -92,7 +93,7 @@ void WaitObject::WakeupAllWaitingThreads() { hle_notifier(); } -const std::vector>& WaitObject::GetWaitingThreads() const { +const std::vector>& WaitObject::GetWaitingThreads() const { return waiting_threads; } diff --git a/src/core/hle/kernel/wait_object.h b/src/core/hle/kernel/wait_object.h index 693ae21866..5c2f38be8e 100644 --- a/src/core/hle/kernel/wait_object.h +++ b/src/core/hle/kernel/wait_object.h @@ -5,6 +5,7 @@ #pragma once #include +#include #include #include #include "common/common_types.h" @@ -33,7 +34,7 @@ public: * Add a thread to wait on this object * @param thread Pointer to thread to add */ - virtual void AddWaitingThread(SharedPtr thread); + virtual void AddWaitingThread(std::shared_ptr thread); /** * Removes a thread from waiting on this object (e.g. if it was resumed already) @@ -48,17 +49,17 @@ public: virtual void WakeupAllWaitingThreads(); /// Obtains the highest priority thread that is ready to run from this object's waiting list. - SharedPtr GetHighestPriorityReadyThread(); + std::shared_ptr GetHighestPriorityReadyThread(); /// Get a const reference to the waiting threads list for debug use - const std::vector>& GetWaitingThreads() const; + const std::vector>& GetWaitingThreads() const; /// Sets a callback which is called when the object becomes available void SetHLENotifier(std::function callback); private: /// Threads waiting for this object to become available - std::vector> waiting_threads; + std::vector> waiting_threads; /// Function to call when this object becomes available std::function hle_notifier; @@ -66,9 +67,9 @@ private: // Specialization of DynamicObjectCast for WaitObjects template <> -inline SharedPtr DynamicObjectCast(SharedPtr object) { +inline std::shared_ptr DynamicObjectCast(std::shared_ptr object) { if (object != nullptr && object->IsWaitable()) { - return boost::static_pointer_cast(object); + return std::static_pointer_cast(object); } return nullptr; } diff --git a/src/core/hle/service/ac/ac.h b/src/core/hle/service/ac/ac.h index 6721ec8dee..f3554c876d 100644 --- a/src/core/hle/service/ac/ac.h +++ b/src/core/hle/service/ac/ac.h @@ -6,7 +6,6 @@ #include #include -#include "core/hle/kernel/kernel.h" #include "core/hle/service/service.h" namespace Core { @@ -151,9 +150,9 @@ protected: bool ac_connected = false; - Kernel::SharedPtr close_event; - Kernel::SharedPtr connect_event; - Kernel::SharedPtr disconnect_event; + std::shared_ptr close_event; + std::shared_ptr connect_event; + std::shared_ptr disconnect_event; }; void InstallInterfaces(Core::System& system); diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index 972c826a99..af46a2c566 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp @@ -1138,7 +1138,7 @@ private: }; ResultVal> GetFileFromSession( - Kernel::SharedPtr file_session) { + std::shared_ptr file_session) { // Step up the chain from ClientSession->ServerSession and then // cast to File. For AM on 3DS, invalid handles actually hang the system. @@ -1147,7 +1147,8 @@ ResultVal> GetFileFromSession( return Kernel::ERR_INVALID_HANDLE; } - Kernel::SharedPtr server = file_session->parent->server; + std::shared_ptr server = + Kernel::SharedFrom(file_session->parent->server); if (server == nullptr) { LOG_WARNING(Service_AM, "File handle ServerSession disconnected!"); return Kernel::ERR_SESSION_CLOSED_BY_REMOTE; diff --git a/src/core/hle/service/am/am.h b/src/core/hle/service/am/am.h index e00e16abd0..0912dde409 100644 --- a/src/core/hle/service/am/am.h +++ b/src/core/hle/service/am/am.h @@ -576,7 +576,7 @@ private: Core::System& system; bool cia_installing = false; std::array, 3> am_title_list; - Kernel::SharedPtr system_updater_mutex; + std::shared_ptr system_updater_mutex; }; void InstallInterfaces(Core::System& system); diff --git a/src/core/hle/service/apt/applet_manager.cpp b/src/core/hle/service/apt/applet_manager.cpp index 8d7d671da8..307a9f0a77 100644 --- a/src/core/hle/service/apt/applet_manager.cpp +++ b/src/core/hle/service/apt/applet_manager.cpp @@ -384,7 +384,7 @@ ResultCode AppletManager::FinishPreloadingLibraryApplet(AppletId applet_id) { } ResultCode AppletManager::StartLibraryApplet(AppletId applet_id, - Kernel::SharedPtr object, + std::shared_ptr object, const std::vector& buffer) { MessageParameter param; param.destination_id = applet_id; @@ -424,7 +424,7 @@ ResultCode AppletManager::PrepareToCloseLibraryApplet(bool not_pause, bool exiti return RESULT_SUCCESS; } -ResultCode AppletManager::CloseLibraryApplet(Kernel::SharedPtr object, +ResultCode AppletManager::CloseLibraryApplet(std::shared_ptr object, std::vector buffer) { auto& slot = applet_slots[static_cast(AppletSlot::LibraryApplet)]; diff --git a/src/core/hle/service/apt/applet_manager.h b/src/core/hle/service/apt/applet_manager.h index 18c5de7004..6bc880bd46 100644 --- a/src/core/hle/service/apt/applet_manager.h +++ b/src/core/hle/service/apt/applet_manager.h @@ -5,6 +5,7 @@ #pragma once #include +#include #include #include #include "core/hle/kernel/event.h" @@ -81,13 +82,13 @@ struct MessageParameter { AppletId sender_id = AppletId::None; AppletId destination_id = AppletId::None; SignalType signal = SignalType::None; - Kernel::SharedPtr object = nullptr; + std::shared_ptr object = nullptr; std::vector buffer; }; /// Holds information about the parameters used in StartLibraryApplet struct AppletStartupParameter { - Kernel::SharedPtr object = nullptr; + std::shared_ptr object = nullptr; std::vector buffer; }; @@ -125,8 +126,8 @@ public: AppletId receiver_appid); struct InitializeResult { - Kernel::SharedPtr notification_event; - Kernel::SharedPtr parameter_event; + std::shared_ptr notification_event; + std::shared_ptr parameter_event; }; ResultVal Initialize(AppletId app_id, AppletAttributes attributes); @@ -135,10 +136,10 @@ public: ResultCode PrepareToStartLibraryApplet(AppletId applet_id); ResultCode PreloadLibraryApplet(AppletId applet_id); ResultCode FinishPreloadingLibraryApplet(AppletId applet_id); - ResultCode StartLibraryApplet(AppletId applet_id, Kernel::SharedPtr object, + ResultCode StartLibraryApplet(AppletId applet_id, std::shared_ptr object, const std::vector& buffer); ResultCode PrepareToCloseLibraryApplet(bool not_pause, bool exiting, bool jump_home); - ResultCode CloseLibraryApplet(Kernel::SharedPtr object, std::vector buffer); + ResultCode CloseLibraryApplet(std::shared_ptr object, std::vector buffer); ResultCode PrepareToDoApplicationJump(u64 title_id, FS::MediaType media_type, ApplicationJumpFlags flags); @@ -189,8 +190,8 @@ private: bool registered; bool loaded; AppletAttributes attributes; - Kernel::SharedPtr notification_event; - Kernel::SharedPtr parameter_event; + std::shared_ptr notification_event; + std::shared_ptr parameter_event; void Reset() { applet_id = AppletId::None; diff --git a/src/core/hle/service/apt/apt.cpp b/src/core/hle/service/apt/apt.cpp index 4d4904f536..494624dc75 100644 --- a/src/core/hle/service/apt/apt.cpp +++ b/src/core/hle/service/apt/apt.cpp @@ -308,7 +308,7 @@ void Module::Interface::SendParameter(Kernel::HLERequestContext& ctx) { AppletId dst_app_id = rp.PopEnum(); SignalType signal_type = rp.PopEnum(); u32 buffer_size = rp.Pop(); - Kernel::SharedPtr object = rp.PopGenericObject(); + std::shared_ptr object = rp.PopGenericObject(); std::vector buffer = rp.PopStaticBuffer(); LOG_DEBUG(Service_APT, @@ -586,7 +586,7 @@ void Module::Interface::StartLibraryApplet(Kernel::HLERequestContext& ctx) { AppletId applet_id = rp.PopEnum(); std::size_t buffer_size = rp.Pop(); - Kernel::SharedPtr object = rp.PopGenericObject(); + std::shared_ptr object = rp.PopGenericObject(); std::vector buffer = rp.PopStaticBuffer(); LOG_DEBUG(Service_APT, "called, applet_id={:08X}", static_cast(applet_id)); @@ -598,7 +598,7 @@ void Module::Interface::StartLibraryApplet(Kernel::HLERequestContext& ctx) { void Module::Interface::CloseApplication(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp(ctx, 0x27, 1, 4); u32 parameters_size = rp.Pop(); - Kernel::SharedPtr object = rp.PopGenericObject(); + std::shared_ptr object = rp.PopGenericObject(); std::vector buffer = rp.PopStaticBuffer(); LOG_DEBUG(Service_APT, "called"); diff --git a/src/core/hle/service/apt/apt.h b/src/core/hle/service/apt/apt.h index 23b299e8da..3755be43f9 100644 --- a/src/core/hle/service/apt/apt.h +++ b/src/core/hle/service/apt/apt.h @@ -4,11 +4,11 @@ #pragma once +#include #include #include "common/common_funcs.h" #include "common/common_types.h" #include "common/swap.h" -#include "core/hle/kernel/kernel.h" #include "core/hle/service/service.h" namespace Core { @@ -603,11 +603,11 @@ private: Core::System& system; /// Handle to shared memory region designated to for shared system font - Kernel::SharedPtr shared_font_mem; + std::shared_ptr shared_font_mem; bool shared_font_loaded = false; bool shared_font_relocated = false; - Kernel::SharedPtr lock; + std::shared_ptr lock; u32 cpu_percent = 0; ///< CPU time available to the running application diff --git a/src/core/hle/service/apt/bcfnt/bcfnt.cpp b/src/core/hle/service/apt/bcfnt/bcfnt.cpp index c51caaace9..14916cc23f 100644 --- a/src/core/hle/service/apt/bcfnt/bcfnt.cpp +++ b/src/core/hle/service/apt/bcfnt/bcfnt.cpp @@ -7,7 +7,7 @@ namespace Service::APT::BCFNT { -void RelocateSharedFont(Kernel::SharedPtr shared_font, VAddr new_address) { +void RelocateSharedFont(std::shared_ptr shared_font, VAddr new_address) { static const u32 SharedFontStartOffset = 0x80; const u8* cfnt_ptr = shared_font->GetPointer(SharedFontStartOffset); diff --git a/src/core/hle/service/apt/bcfnt/bcfnt.h b/src/core/hle/service/apt/bcfnt/bcfnt.h index 1c3bd34959..cf847cce3d 100644 --- a/src/core/hle/service/apt/bcfnt/bcfnt.h +++ b/src/core/hle/service/apt/bcfnt/bcfnt.h @@ -4,6 +4,7 @@ #pragma once +#include #include "common/swap.h" #include "core/hle/kernel/shared_memory.h" #include "core/hle/service/service.h" @@ -83,6 +84,6 @@ struct CWDH { * @param shared_font SharedMemory object that contains the Shared Font * @param new_address New base for the offsets in the structure. */ -void RelocateSharedFont(Kernel::SharedPtr shared_font, VAddr new_address); +void RelocateSharedFont(std::shared_ptr shared_font, VAddr new_address); } // namespace Service::APT::BCFNT diff --git a/src/core/hle/service/boss/boss.cpp b/src/core/hle/service/boss/boss.cpp index 63df574270..d22e94cf19 100644 --- a/src/core/hle/service/boss/boss.cpp +++ b/src/core/hle/service/boss/boss.cpp @@ -282,7 +282,7 @@ void Module::Interface::SendProperty(Kernel::HLERequestContext& ctx) { void Module::Interface::SendPropertyHandle(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp(ctx, 0x15, 1, 2); const u16 property_id = rp.Pop(); - const Kernel::SharedPtr object = rp.PopGenericObject(); + const std::shared_ptr object = rp.PopGenericObject(); IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); rb.Push(RESULT_SUCCESS); diff --git a/src/core/hle/service/boss/boss.h b/src/core/hle/service/boss/boss.h index 15a41746e6..e0cb39b372 100644 --- a/src/core/hle/service/boss/boss.h +++ b/src/core/hle/service/boss/boss.h @@ -4,6 +4,7 @@ #pragma once +#include #include "core/hle/kernel/event.h" #include "core/hle/service/service.h" @@ -961,7 +962,7 @@ public: }; private: - Kernel::SharedPtr task_finish_event; + std::shared_ptr task_finish_event; }; void InstallInterfaces(Core::System& system); diff --git a/src/core/hle/service/cam/cam.h b/src/core/hle/service/cam/cam.h index 735d192fb7..9f3d819901 100644 --- a/src/core/hle/service/cam/cam.h +++ b/src/core/hle/service/cam/cam.h @@ -769,9 +769,9 @@ private: u16 transfer_bytes{256}; - Kernel::SharedPtr completion_event; - Kernel::SharedPtr buffer_error_interrupt_event; - Kernel::SharedPtr vsync_interrupt_event; + std::shared_ptr completion_event; + std::shared_ptr buffer_error_interrupt_event; + std::shared_ptr vsync_interrupt_event; std::future> capture_result; // will hold the received frame. Kernel::Process* dest_process{nullptr}; diff --git a/src/core/hle/service/cecd/cecd.h b/src/core/hle/service/cecd/cecd.h index d8023f5cf4..004ef33e70 100644 --- a/src/core/hle/service/cecd/cecd.h +++ b/src/core/hle/service/cecd/cecd.h @@ -4,6 +4,7 @@ #pragma once +#include #include "common/bit_field.h" #include "common/common_funcs.h" #include "core/hle/kernel/event.h" @@ -608,8 +609,8 @@ private: std::unique_ptr cecd_system_save_data_archive; - Kernel::SharedPtr cecinfo_event; - Kernel::SharedPtr change_state_event; + std::shared_ptr cecinfo_event; + std::shared_ptr change_state_event; Core::System& system; }; diff --git a/src/core/hle/service/csnd/csnd_snd.h b/src/core/hle/service/csnd/csnd_snd.h index 94b1bf3bb1..1d01b31174 100644 --- a/src/core/hle/service/csnd/csnd_snd.h +++ b/src/core/hle/service/csnd/csnd_snd.h @@ -4,6 +4,7 @@ #pragma once +#include #include "core/hle/kernel/mutex.h" #include "core/hle/kernel/shared_memory.h" #include "core/hle/service/service.h" @@ -176,8 +177,8 @@ private: Core::System& system; - Kernel::SharedPtr mutex = nullptr; - Kernel::SharedPtr shared_memory = nullptr; + std::shared_ptr mutex = nullptr; + std::shared_ptr shared_memory = nullptr; static constexpr u32 MaxCaptureUnits = 2; std::array capture_units = {false, false}; diff --git a/src/core/hle/service/dsp/dsp_dsp.cpp b/src/core/hle/service/dsp/dsp_dsp.cpp index 4745017619..37682edcc3 100644 --- a/src/core/hle/service/dsp/dsp_dsp.cpp +++ b/src/core/hle/service/dsp/dsp_dsp.cpp @@ -308,7 +308,7 @@ void DSP_DSP::SignalInterrupt(InterruptType type, DspPipe pipe) { event->Signal(); } -Kernel::SharedPtr& DSP_DSP::GetInterruptEvent(InterruptType type, DspPipe pipe) { +std::shared_ptr& DSP_DSP::GetInterruptEvent(InterruptType type, DspPipe pipe) { switch (type) { case InterruptType::Zero: return interrupt_zero; diff --git a/src/core/hle/service/dsp/dsp_dsp.h b/src/core/hle/service/dsp/dsp_dsp.h index 5bf00334b5..ef1f0b76df 100644 --- a/src/core/hle/service/dsp/dsp_dsp.h +++ b/src/core/hle/service/dsp/dsp_dsp.h @@ -4,6 +4,7 @@ #pragma once +#include #include "audio_core/dsp_interface.h" #include "core/hle/kernel/event.h" #include "core/hle/result.h" @@ -249,21 +250,20 @@ private: void ForceHeadphoneOut(Kernel::HLERequestContext& ctx); /// Returns the Interrupt Event for a given pipe - Kernel::SharedPtr& GetInterruptEvent(InterruptType type, - AudioCore::DspPipe pipe); + std::shared_ptr& GetInterruptEvent(InterruptType type, AudioCore::DspPipe pipe); /// Checks if we are trying to register more than 6 events bool HasTooManyEventsRegistered() const; Core::System& system; - Kernel::SharedPtr semaphore_event; + std::shared_ptr semaphore_event; u16 preset_semaphore = 0; - Kernel::SharedPtr interrupt_zero = nullptr; /// Currently unknown purpose - Kernel::SharedPtr interrupt_one = nullptr; /// Currently unknown purpose + std::shared_ptr interrupt_zero = nullptr; /// Currently unknown purpose + std::shared_ptr interrupt_one = nullptr; /// Currently unknown purpose /// Each DSP pipe has an associated interrupt - std::array, AudioCore::num_dsp_pipe> pipes = {{}}; + std::array, AudioCore::num_dsp_pipe> pipes = {{}}; }; void InstallInterfaces(Core::System& system); diff --git a/src/core/hle/service/fs/directory.h b/src/core/hle/service/fs/directory.h index 2f4529ca07..890b266488 100644 --- a/src/core/hle/service/fs/directory.h +++ b/src/core/hle/service/fs/directory.h @@ -4,8 +4,8 @@ #pragma once +#include #include "core/file_sys/archive_backend.h" -#include "core/hle/kernel/kernel.h" #include "core/hle/service/service.h" namespace Service::FS { diff --git a/src/core/hle/service/fs/file.cpp b/src/core/hle/service/fs/file.cpp index 0edd93644b..9efd88dd3f 100644 --- a/src/core/hle/service/fs/file.cpp +++ b/src/core/hle/service/fs/file.cpp @@ -71,12 +71,13 @@ void File::Read(Kernel::HLERequestContext& ctx) { rb.PushMappedBuffer(buffer); std::chrono::nanoseconds read_timeout_ns{backend->GetReadDelayNs(length)}; - ctx.SleepClientThread( - system.Kernel().GetThreadManager().GetCurrentThread(), "file::read", read_timeout_ns, - [](Kernel::SharedPtr /*thread*/, Kernel::HLERequestContext& /*ctx*/, - Kernel::ThreadWakeupReason /*reason*/) { - // Nothing to do here - }); + ctx.SleepClientThread(Kernel::SharedFrom(system.Kernel().GetThreadManager().GetCurrentThread()), + "file::read", read_timeout_ns, + [](std::shared_ptr /*thread*/, + Kernel::HLERequestContext& /*ctx*/, + Kernel::ThreadWakeupReason /*reason*/) { + // Nothing to do here + }); } void File::Write(Kernel::HLERequestContext& ctx) { @@ -195,11 +196,10 @@ void File::OpenLinkFile(Kernel::HLERequestContext& ctx) { LOG_WARNING(Service_FS, "(STUBBED) File command OpenLinkFile {}", GetName()); using Kernel::ClientSession; using Kernel::ServerSession; - using Kernel::SharedPtr; IPC::RequestParser rp(ctx, 0x080C, 0, 0); IPC::RequestBuilder rb = rp.MakeBuilder(1, 2); auto sessions = system.Kernel().CreateSessionPair(GetName()); - auto server = std::get>(sessions); + auto server = std::get>(sessions); ClientConnected(server); FileSessionSlot* slot = GetSessionData(server); @@ -211,7 +211,7 @@ void File::OpenLinkFile(Kernel::HLERequestContext& ctx) { slot->subfile = false; rb.Push(RESULT_SUCCESS); - rb.PushMoveObjects(std::get>(sessions)); + rb.PushMoveObjects(std::get>(sessions)); } void File::OpenSubFile(Kernel::HLERequestContext& ctx) { @@ -245,9 +245,8 @@ void File::OpenSubFile(Kernel::HLERequestContext& ctx) { using Kernel::ClientSession; using Kernel::ServerSession; - using Kernel::SharedPtr; auto sessions = system.Kernel().CreateSessionPair(GetName()); - auto server = std::get>(sessions); + auto server = std::get>(sessions); ClientConnected(server); FileSessionSlot* slot = GetSessionData(server); @@ -257,12 +256,12 @@ void File::OpenSubFile(Kernel::HLERequestContext& ctx) { slot->subfile = true; rb.Push(RESULT_SUCCESS); - rb.PushMoveObjects(std::get>(sessions)); + rb.PushMoveObjects(std::get>(sessions)); } -Kernel::SharedPtr File::Connect() { +std::shared_ptr File::Connect() { auto sessions = system.Kernel().CreateSessionPair(GetName()); - auto server = std::get>(sessions); + auto server = std::get>(sessions); ClientConnected(server); FileSessionSlot* slot = GetSessionData(server); @@ -271,16 +270,16 @@ Kernel::SharedPtr File::Connect() { slot->size = backend->GetSize(); slot->subfile = false; - return std::get>(sessions); + return std::get>(sessions); } -std::size_t File::GetSessionFileOffset(Kernel::SharedPtr session) { +std::size_t File::GetSessionFileOffset(std::shared_ptr session) { const FileSessionSlot* slot = GetSessionData(session); ASSERT(slot); return slot->offset; } -std::size_t File::GetSessionFileSize(Kernel::SharedPtr session) { +std::size_t File::GetSessionFileSize(std::shared_ptr session) { const FileSessionSlot* slot = GetSessionData(session); ASSERT(slot); return slot->size; diff --git a/src/core/hle/service/fs/file.h b/src/core/hle/service/fs/file.h index b946491b8d..062fcd5e71 100644 --- a/src/core/hle/service/fs/file.h +++ b/src/core/hle/service/fs/file.h @@ -4,8 +4,8 @@ #pragma once +#include #include "core/file_sys/archive_backend.h" -#include "core/hle/kernel/kernel.h" #include "core/hle/service/service.h" namespace Core { @@ -37,15 +37,15 @@ public: std::unique_ptr backend; ///< File backend interface /// Creates a new session to this File and returns the ClientSession part of the connection. - Kernel::SharedPtr Connect(); + std::shared_ptr Connect(); // Returns the start offset of an open file represented by the input session, opened with // OpenSubFile. - std::size_t GetSessionFileOffset(Kernel::SharedPtr session); + std::size_t GetSessionFileOffset(std::shared_ptr session); // Returns the size of an open file represented by the input session, opened with // OpenSubFile. - std::size_t GetSessionFileSize(Kernel::SharedPtr session); + std::size_t GetSessionFileSize(std::shared_ptr session); private: void Read(Kernel::HLERequestContext& ctx); diff --git a/src/core/hle/service/fs/fs_user.cpp b/src/core/hle/service/fs/fs_user.cpp index 51bc18374d..ec1e1b8519 100644 --- a/src/core/hle/service/fs/fs_user.cpp +++ b/src/core/hle/service/fs/fs_user.cpp @@ -30,7 +30,6 @@ using Kernel::ClientSession; using Kernel::ServerSession; -using Kernel::SharedPtr; namespace Service::FS { @@ -72,12 +71,13 @@ void FS_USER::OpenFile(Kernel::HLERequestContext& ctx) { LOG_ERROR(Service_FS, "failed to get a handle for file {}", file_path.DebugStr()); } - ctx.SleepClientThread( - system.Kernel().GetThreadManager().GetCurrentThread(), "fs_user::open", open_timeout_ns, - [](Kernel::SharedPtr /*thread*/, Kernel::HLERequestContext& /*ctx*/, - Kernel::ThreadWakeupReason /*reason*/) { - // Nothing to do here - }); + ctx.SleepClientThread(Kernel::SharedFrom(system.Kernel().GetThreadManager().GetCurrentThread()), + "fs_user::open", open_timeout_ns, + [](std::shared_ptr /*thread*/, + Kernel::HLERequestContext& /*ctx*/, + Kernel::ThreadWakeupReason /*reason*/) { + // Nothing to do here + }); } void FS_USER::OpenFileDirectly(Kernel::HLERequestContext& ctx) { @@ -130,9 +130,9 @@ void FS_USER::OpenFileDirectly(Kernel::HLERequestContext& ctx) { file_path.DebugStr(), mode.hex, attributes); } - ctx.SleepClientThread(system.Kernel().GetThreadManager().GetCurrentThread(), + ctx.SleepClientThread(Kernel::SharedFrom(system.Kernel().GetThreadManager().GetCurrentThread()), "fs_user::open_directly", open_timeout_ns, - [](Kernel::SharedPtr /*thread*/, + [](std::shared_ptr /*thread*/, Kernel::HLERequestContext& /*ctx*/, Kernel::ThreadWakeupReason /*reason*/) { // Nothing to do here @@ -309,8 +309,8 @@ void FS_USER::OpenDirectory(Kernel::HLERequestContext& ctx) { if (dir_res.Succeeded()) { std::shared_ptr directory = *dir_res; auto sessions = system.Kernel().CreateSessionPair(directory->GetName()); - directory->ClientConnected(std::get>(sessions)); - rb.PushMoveObjects(std::get>(sessions)); + directory->ClientConnected(std::get>(sessions)); + rb.PushMoveObjects(std::get>(sessions)); } else { LOG_ERROR(Service_FS, "failed to get a handle for directory type={} size={} data={}", static_cast(dirname_type), dirname_size, dir_path.DebugStr()); diff --git a/src/core/hle/service/gsp/gsp_gpu.cpp b/src/core/hle/service/gsp/gsp_gpu.cpp index 50bb30bb95..129139014b 100644 --- a/src/core/hle/service/gsp/gsp_gpu.cpp +++ b/src/core/hle/service/gsp/gsp_gpu.cpp @@ -88,7 +88,7 @@ static u32 GetUnusedThreadId() { } /// Gets a pointer to a thread command buffer in GSP shared memory -static inline u8* GetCommandBuffer(Kernel::SharedPtr shared_memory, +static inline u8* GetCommandBuffer(std::shared_ptr shared_memory, u32 thread_id) { return shared_memory->GetPointer(0x800 + (thread_id * sizeof(CommandBuffer))); } @@ -104,12 +104,12 @@ FrameBufferUpdate* GSP_GPU::GetFrameBufferInfo(u32 thread_id, u32 screen_index) /// Gets a pointer to the interrupt relay queue for a given thread index static inline InterruptRelayQueue* GetInterruptRelayQueue( - Kernel::SharedPtr shared_memory, u32 thread_id) { + std::shared_ptr shared_memory, u32 thread_id) { u8* ptr = shared_memory->GetPointer(sizeof(InterruptRelayQueue) * thread_id); return reinterpret_cast(ptr); } -void GSP_GPU::ClientDisconnected(Kernel::SharedPtr server_session) { +void GSP_GPU::ClientDisconnected(std::shared_ptr server_session) { SessionData* session_data = GetSessionData(server_session); if (active_thread_id == session_data->thread_id) ReleaseRight(session_data); diff --git a/src/core/hle/service/gsp/gsp_gpu.h b/src/core/hle/service/gsp/gsp_gpu.h index 593d05ea2b..b1ab6807f5 100644 --- a/src/core/hle/service/gsp/gsp_gpu.h +++ b/src/core/hle/service/gsp/gsp_gpu.h @@ -5,6 +5,7 @@ #pragma once #include +#include #include #include "common/bit_field.h" #include "common/common_types.h" @@ -187,7 +188,7 @@ struct SessionData : public Kernel::SessionRequestHandler::SessionDataBase { ~SessionData(); /// Event triggered when GSP interrupt has been signalled - Kernel::SharedPtr interrupt_event; + std::shared_ptr interrupt_event; /// Thread index into interrupt relay queue u32 thread_id; /// Whether RegisterInterruptRelayQueue was called for this session @@ -199,7 +200,7 @@ public: explicit GSP_GPU(Core::System& system); ~GSP_GPU() = default; - void ClientDisconnected(Kernel::SharedPtr server_session) override; + void ClientDisconnected(std::shared_ptr server_session) override; /** * Signals that the specified interrupt type has occurred to userland code @@ -406,7 +407,7 @@ private: Core::System& system; /// GSP shared memory - Kernel::SharedPtr shared_memory; + std::shared_ptr shared_memory; /// Thread id that currently has GPU rights or -1 if none. int active_thread_id = -1; diff --git a/src/core/hle/service/hid/hid.h b/src/core/hle/service/hid/hid.h index 2aba49b3a2..8d217f8356 100644 --- a/src/core/hle/service/hid/hid.h +++ b/src/core/hle/service/hid/hid.h @@ -14,7 +14,6 @@ #include "common/common_funcs.h" #include "common/common_types.h" #include "core/frontend/input.h" -#include "core/hle/kernel/kernel.h" #include "core/hle/service/service.h" #include "core/settings.h" @@ -312,14 +311,14 @@ private: Core::System& system; // Handle to shared memory region designated to HID_User service - Kernel::SharedPtr shared_mem; + std::shared_ptr shared_mem; // Event handles - Kernel::SharedPtr event_pad_or_touch_1; - Kernel::SharedPtr event_pad_or_touch_2; - Kernel::SharedPtr event_accelerometer; - Kernel::SharedPtr event_gyroscope; - Kernel::SharedPtr event_debug_pad; + std::shared_ptr event_pad_or_touch_1; + std::shared_ptr event_pad_or_touch_2; + std::shared_ptr event_accelerometer; + std::shared_ptr event_gyroscope; + std::shared_ptr event_debug_pad; // The HID module of a 3DS does not store the PadState. // Storing this here was necessary for emulation specific tasks like cheats or scripting. diff --git a/src/core/hle/service/http_c.h b/src/core/hle/service/http_c.h index daf998ecf4..3ae540400a 100644 --- a/src/core/hle/service/http_c.h +++ b/src/core/hle/service/http_c.h @@ -265,7 +265,7 @@ private: void DecryptClCertA(); - Kernel::SharedPtr shared_memory = nullptr; + std::shared_ptr shared_memory = nullptr; /// The next number to use when a new HTTP session is initalized. u32 session_counter = 0; diff --git a/src/core/hle/service/ir/ir_rst.h b/src/core/hle/service/ir/ir_rst.h index df7f768e44..84ad70dfcb 100644 --- a/src/core/hle/service/ir/ir_rst.h +++ b/src/core/hle/service/ir/ir_rst.h @@ -10,7 +10,6 @@ #include "common/common_types.h" #include "common/swap.h" #include "core/frontend/input.h" -#include "core/hle/kernel/kernel.h" #include "core/hle/service/service.h" namespace Kernel { @@ -78,8 +77,8 @@ private: void UpdateCallback(u64 userdata, s64 cycles_late); Core::System& system; - Kernel::SharedPtr update_event; - Kernel::SharedPtr shared_memory; + std::shared_ptr update_event; + std::shared_ptr shared_memory; u32 next_pad_index{0}; Core::TimingEventType* update_callback_id; std::unique_ptr zl_button; diff --git a/src/core/hle/service/ir/ir_user.cpp b/src/core/hle/service/ir/ir_user.cpp index f72834deae..d392c1983d 100644 --- a/src/core/hle/service/ir/ir_user.cpp +++ b/src/core/hle/service/ir/ir_user.cpp @@ -66,7 +66,7 @@ static_assert(sizeof(SharedMemoryHeader) == 16, "SharedMemoryHeader has wrong si */ class BufferManager { public: - BufferManager(Kernel::SharedPtr shared_memory_, u32 info_offset_, + BufferManager(std::shared_ptr shared_memory_, u32 info_offset_, u32 buffer_offset_, u32 max_packet_count_, u32 buffer_size) : shared_memory(shared_memory_), info_offset(info_offset_), buffer_offset(buffer_offset_), max_packet_count(max_packet_count_), @@ -174,7 +174,7 @@ private: } BufferInfo info{0, 0, 0, 0}; - Kernel::SharedPtr shared_memory; + std::shared_ptr shared_memory; u32 info_offset; u32 buffer_offset; u32 max_packet_count; diff --git a/src/core/hle/service/ir/ir_user.h b/src/core/hle/service/ir/ir_user.h index 71d5e16303..54a4f3e087 100644 --- a/src/core/hle/service/ir/ir_user.h +++ b/src/core/hle/service/ir/ir_user.h @@ -162,8 +162,8 @@ private: void PutToReceive(const std::vector& payload); - Kernel::SharedPtr conn_status_event, send_event, receive_event; - Kernel::SharedPtr shared_memory; + std::shared_ptr conn_status_event, send_event, receive_event; + std::shared_ptr shared_memory; IRDevice* connected_device{nullptr}; std::unique_ptr receive_buffer; std::unique_ptr extra_hid; diff --git a/src/core/hle/service/mic_u.cpp b/src/core/hle/service/mic_u.cpp index 779b520b85..42b3e67633 100644 --- a/src/core/hle/service/mic_u.cpp +++ b/src/core/hle/service/mic_u.cpp @@ -354,9 +354,9 @@ struct MIC_U::Impl { } std::atomic change_mic_impl_requested = false; - Kernel::SharedPtr buffer_full_event; + std::shared_ptr buffer_full_event; Core::TimingEventType* buffer_write_event = nullptr; - Kernel::SharedPtr shared_memory; + std::shared_ptr shared_memory; u32 client_version = 0; bool allow_shell_closed = false; bool clamp = false; diff --git a/src/core/hle/service/nfc/nfc.h b/src/core/hle/service/nfc/nfc.h index afa05d60e0..7f7af05176 100644 --- a/src/core/hle/service/nfc/nfc.h +++ b/src/core/hle/service/nfc/nfc.h @@ -7,7 +7,6 @@ #include #include #include "common/common_types.h" -#include "core/hle/kernel/kernel.h" #include "core/hle/service/service.h" namespace Core { @@ -232,8 +231,8 @@ public: }; private: - Kernel::SharedPtr tag_in_range_event; - Kernel::SharedPtr tag_out_of_range_event; + std::shared_ptr tag_in_range_event; + std::shared_ptr tag_out_of_range_event; std::atomic nfc_tag_state = TagState::NotInitialized; CommunicationStatus nfc_status = CommunicationStatus::NfcInitialized; diff --git a/src/core/hle/service/nim/nim_u.h b/src/core/hle/service/nim/nim_u.h index 0f4338f16e..367ee6ea85 100644 --- a/src/core/hle/service/nim/nim_u.h +++ b/src/core/hle/service/nim/nim_u.h @@ -4,6 +4,7 @@ #pragma once +#include #include "core/hle/service/service.h" namespace Core { @@ -39,7 +40,7 @@ private: */ void CheckSysUpdateAvailable(Kernel::HLERequestContext& ctx); - Kernel::SharedPtr nim_system_update_event; + std::shared_ptr nim_system_update_event; }; } // namespace Service::NIM diff --git a/src/core/hle/service/ns/ns.cpp b/src/core/hle/service/ns/ns.cpp index c0fac1d552..ba0fd793dc 100644 --- a/src/core/hle/service/ns/ns.cpp +++ b/src/core/hle/service/ns/ns.cpp @@ -11,7 +11,7 @@ namespace Service::NS { -Kernel::SharedPtr LaunchTitle(FS::MediaType media_type, u64 title_id) { +std::shared_ptr LaunchTitle(FS::MediaType media_type, u64 title_id) { std::string path = AM::GetTitleContentPath(media_type, title_id); auto loader = Loader::GetLoader(path); @@ -20,7 +20,7 @@ Kernel::SharedPtr LaunchTitle(FS::MediaType media_type, u64 tit return nullptr; } - Kernel::SharedPtr process; + std::shared_ptr process; Loader::ResultStatus result = loader->Load(process); if (result != Loader::ResultStatus::Success) { diff --git a/src/core/hle/service/ns/ns.h b/src/core/hle/service/ns/ns.h index f6328dc3aa..25aec246ec 100644 --- a/src/core/hle/service/ns/ns.h +++ b/src/core/hle/service/ns/ns.h @@ -4,6 +4,7 @@ #pragma once +#include #include "core/hle/kernel/process.h" #include "core/hle/service/fs/archive.h" #include "core/hle/service/service.h" @@ -15,7 +16,7 @@ class System; namespace Service::NS { /// Loads and launches the title identified by title_id in the specified media type. -Kernel::SharedPtr LaunchTitle(FS::MediaType media_type, u64 title_id); +std::shared_ptr LaunchTitle(FS::MediaType media_type, u64 title_id); /// Registers all NS services with the specified service manager. void InstallInterfaces(Core::System& system); diff --git a/src/core/hle/service/ns/ns_s.h b/src/core/hle/service/ns/ns_s.h index cc8cdb57ac..d6c42b0fde 100644 --- a/src/core/hle/service/ns/ns_s.h +++ b/src/core/hle/service/ns/ns_s.h @@ -4,7 +4,6 @@ #pragma once -#include "core/hle/kernel/kernel.h" #include "core/hle/service/service.h" namespace Service::NS { diff --git a/src/core/hle/service/nwm/nwm_uds.cpp b/src/core/hle/service/nwm/nwm_uds.cpp index fd8169276a..d8bad3686a 100644 --- a/src/core/hle/service/nwm/nwm_uds.cpp +++ b/src/core/hle/service/nwm/nwm_uds.cpp @@ -568,7 +568,7 @@ void NWM_UDS::RecvBeaconBroadcastData(Kernel::HLERequestContext& ctx) { // 'Official user processes create a new event handle which is then passed to this command. // However, those user processes don't save that handle anywhere afterwards.' // So we don't save/use that event too. - Kernel::SharedPtr input_event = rp.PopObject(); + std::shared_ptr input_event = rp.PopObject(); Kernel::MappedBuffer out_buffer = rp.PopMappedBuffer(); ASSERT(out_buffer.GetSize() == out_buffer_size); @@ -615,9 +615,9 @@ void NWM_UDS::RecvBeaconBroadcastData(Kernel::HLERequestContext& ctx) { out_buffer_size, wlan_comm_id, id, unk1, unk2, cur_buffer_size); } -ResultVal> NWM_UDS::Initialize( +ResultVal> NWM_UDS::Initialize( u32 sharedmem_size, const NodeInfo& node, u16 version, - Kernel::SharedPtr sharedmem) { + std::shared_ptr sharedmem) { current_node = node; initialized = true; @@ -1179,9 +1179,9 @@ void NWM_UDS::ConnectToNetwork(Kernel::HLERequestContext& ctx, u16 command_id, static constexpr std::chrono::nanoseconds UDSConnectionTimeout{300000000}; connection_event = ctx.SleepClientThread( - system.Kernel().GetThreadManager().GetCurrentThread(), "uds::ConnectToNetwork", - UDSConnectionTimeout, - [command_id](Kernel::SharedPtr thread, Kernel::HLERequestContext& ctx, + Kernel::SharedFrom(system.Kernel().GetThreadManager().GetCurrentThread()), + "uds::ConnectToNetwork", UDSConnectionTimeout, + [command_id](std::shared_ptr thread, Kernel::HLERequestContext& ctx, Kernel::ThreadWakeupReason reason) { // TODO(B3N30): Add error handling for host full and timeout IPC::RequestBuilder rb(ctx, command_id, 1, 0); diff --git a/src/core/hle/service/nwm/nwm_uds.h b/src/core/hle/service/nwm/nwm_uds.h index b28b578a7a..52ca386635 100644 --- a/src/core/hle/service/nwm/nwm_uds.h +++ b/src/core/hle/service/nwm/nwm_uds.h @@ -10,13 +10,13 @@ #include #include #include +#include #include #include #include #include #include "common/common_types.h" #include "common/swap.h" -#include "core/hle/kernel/kernel.h" #include "core/hle/service/service.h" #include "network/network.h" @@ -416,9 +416,9 @@ private: template void DecryptBeaconData(Kernel::HLERequestContext& ctx); - ResultVal> Initialize( + ResultVal> Initialize( u32 sharedmem_size, const NodeInfo& node, u16 version, - Kernel::SharedPtr sharedmem); + std::shared_ptr sharedmem); ResultCode BeginHostingNetwork(const u8* network_info_buffer, std::size_t network_info_size, std::vector passphrase); @@ -477,11 +477,11 @@ private: boost::optional GetNodeMacAddress(u16 dest_node_id, u8 flags); // Event that is signaled every time the connection status changes. - Kernel::SharedPtr connection_status_event; + std::shared_ptr connection_status_event; // Shared memory provided by the application to store the receive buffer. // This is not currently used. - Kernel::SharedPtr recv_buffer_memory; + std::shared_ptr recv_buffer_memory; // Connection status of this 3DS. ConnectionStatus connection_status{}; @@ -503,7 +503,7 @@ private: u8 channel; ///< Channel that this bind node was bound to. u16 network_node_id; ///< Node id this bind node is associated with, only packets from this /// network node will be received. - Kernel::SharedPtr event; ///< Receive event for this bind node. + std::shared_ptr event; ///< Receive event for this bind node. std::deque> received_packets; ///< List of packets received on this channel. }; @@ -535,7 +535,7 @@ private: // network thread. std::mutex connection_status_mutex; - Kernel::SharedPtr connection_event; + std::shared_ptr connection_event; // Mutex to synchronize access to the list of received beacons between the emulation thread and // the network thread. diff --git a/src/core/hle/service/pxi/dev.h b/src/core/hle/service/pxi/dev.h index d79fa49baa..115dc23084 100644 --- a/src/core/hle/service/pxi/dev.h +++ b/src/core/hle/service/pxi/dev.h @@ -4,7 +4,6 @@ #pragma once -#include "core/hle/kernel/kernel.h" #include "core/hle/service/service.h" namespace Service::PXI { diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index 19333fd01a..a4ccf429e0 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp @@ -197,7 +197,7 @@ static bool AttemptLLE(const ServiceModuleInfo& service_module) { service_module.name); return false; } - Kernel::SharedPtr process; + std::shared_ptr process; loader->Load(process); LOG_DEBUG(Service, "Service module \"{}\" has been successfully loaded.", service_module.name); return true; diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.h index c44249000f..4aa60eb41f 100644 --- a/src/core/hle/service/service.h +++ b/src/core/hle/service/service.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include "common/common_types.h" @@ -159,7 +160,7 @@ protected: return std::make_unique(); } - SessionData* GetSessionData(Kernel::SharedPtr server_session) { + SessionData* GetSessionData(std::shared_ptr server_session) { return ServiceFrameworkBase::GetSessionData(server_session); } diff --git a/src/core/hle/service/sm/sm.cpp b/src/core/hle/service/sm/sm.cpp index 9520be4ad9..e37c72cc15 100644 --- a/src/core/hle/service/sm/sm.cpp +++ b/src/core/hle/service/sm/sm.cpp @@ -32,7 +32,7 @@ void ServiceManager::InstallInterfaces(Core::System& system) { system.ServiceManager().srv_interface = srv; } -ResultVal> ServiceManager::RegisterService( +ResultVal> ServiceManager::RegisterService( std::string name, unsigned int max_sessions) { CASCADE_CODE(ValidateServiceName(name)); @@ -46,7 +46,7 @@ ResultVal> ServiceManager::RegisterService return MakeResult(std::move(server_port)); } -ResultVal> ServiceManager::GetServicePort( +ResultVal> ServiceManager::GetServicePort( const std::string& name) { CASCADE_CODE(ValidateServiceName(name)); @@ -58,7 +58,7 @@ ResultVal> ServiceManager::GetServicePort( return MakeResult(it->second); } -ResultVal> ServiceManager::ConnectToService( +ResultVal> ServiceManager::ConnectToService( const std::string& name) { 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 f3cf407563..dc26d88148 100644 --- a/src/core/hle/service/sm/sm.h +++ b/src/core/hle/service/sm/sm.h @@ -47,10 +47,10 @@ public: explicit ServiceManager(Core::System& system); - ResultVal> RegisterService(std::string name, - unsigned int max_sessions); - ResultVal> GetServicePort(const std::string& name); - ResultVal> ConnectToService(const std::string& name); + ResultVal> RegisterService(std::string name, + unsigned int max_sessions); + ResultVal> GetServicePort(const std::string& name); + ResultVal> ConnectToService(const std::string& name); template std::shared_ptr GetService(const std::string& service_name) const { @@ -73,7 +73,7 @@ private: std::weak_ptr srv_interface; /// Map of registered services, retrieved using GetServicePort or ConnectToService. - std::unordered_map> registered_services; + std::unordered_map> registered_services; }; } // namespace Service::SM diff --git a/src/core/hle/service/sm/srv.cpp b/src/core/hle/service/sm/srv.cpp index dc7e8297e8..ab6585b6b5 100644 --- a/src/core/hle/service/sm/srv.cpp +++ b/src/core/hle/service/sm/srv.cpp @@ -100,7 +100,7 @@ void SRV::GetServiceHandle(Kernel::HLERequestContext& ctx) { // TODO(yuriks): Permission checks go here - auto get_handle = [name, this](Kernel::SharedPtr thread, + auto get_handle = [name, this](std::shared_ptr thread, Kernel::HLERequestContext& ctx, Kernel::ThreadWakeupReason reason) { LOG_ERROR(Service_SRV, "called service={} wakeup", name); @@ -127,9 +127,9 @@ void SRV::GetServiceHandle(Kernel::HLERequestContext& ctx) { if (client_port.Failed()) { if (wait_until_available && client_port.Code() == ERR_SERVICE_NOT_REGISTERED) { LOG_INFO(Service_SRV, "called service={} delayed", name); - Kernel::SharedPtr get_service_handle_event = - ctx.SleepClientThread(system.Kernel().GetThreadManager().GetCurrentThread(), - "GetServiceHandle", std::chrono::nanoseconds(-1), get_handle); + std::shared_ptr get_service_handle_event = ctx.SleepClientThread( + Kernel::SharedFrom(system.Kernel().GetThreadManager().GetCurrentThread()), + "GetServiceHandle", std::chrono::nanoseconds(-1), get_handle); get_service_handle_delayed_map[name] = std::move(get_service_handle_event); return; } else { diff --git a/src/core/hle/service/sm/srv.h b/src/core/hle/service/sm/srv.h index 02d72ec49d..2382f48425 100644 --- a/src/core/hle/service/sm/srv.h +++ b/src/core/hle/service/sm/srv.h @@ -4,8 +4,8 @@ #pragma once +#include #include -#include "core/hle/kernel/kernel.h" #include "core/hle/service/service.h" namespace Core { @@ -35,9 +35,8 @@ private: void RegisterService(Kernel::HLERequestContext& ctx); Core::System& system; - Kernel::SharedPtr notification_semaphore; - std::unordered_map> - get_service_handle_delayed_map; + std::shared_ptr notification_semaphore; + std::unordered_map> get_service_handle_delayed_map; }; } // namespace Service::SM diff --git a/src/core/hle/service/y2r_u.h b/src/core/hle/service/y2r_u.h index 6e6a352e58..332d3b240f 100644 --- a/src/core/hle/service/y2r_u.h +++ b/src/core/hle/service/y2r_u.h @@ -8,7 +8,6 @@ #include #include #include "common/common_types.h" -#include "core/hle/kernel/kernel.h" #include "core/hle/result.h" #include "core/hle/service/service.h" @@ -296,7 +295,7 @@ private: Core::System& system; - Kernel::SharedPtr completion_event; + std::shared_ptr completion_event; ConversionConfiguration conversion{}; DitheringWeightParams dithering_weight_params{}; bool temporal_dithering_enabled = false; diff --git a/src/core/loader/3dsx.cpp b/src/core/loader/3dsx.cpp index 1b3905b02e..20dbc276f1 100644 --- a/src/core/loader/3dsx.cpp +++ b/src/core/loader/3dsx.cpp @@ -92,10 +92,9 @@ static u32 TranslateAddr(u32 addr, const THREEloadinfo* loadinfo, u32* offsets) } using Kernel::CodeSet; -using Kernel::SharedPtr; static THREEDSX_Error Load3DSXFile(FileUtil::IOFile& file, u32 base_addr, - SharedPtr* out_codeset) { + std::shared_ptr* out_codeset) { if (!file.IsOpen()) return ERROR_FILE; @@ -217,7 +216,7 @@ static THREEDSX_Error Load3DSXFile(FileUtil::IOFile& file, u32 base_addr, } // Create the CodeSet - SharedPtr code_set = Core::System::GetInstance().Kernel().CreateCodeSet("", 0); + std::shared_ptr code_set = Core::System::GetInstance().Kernel().CreateCodeSet("", 0); code_set->CodeSegment().offset = loadinfo.seg_ptrs[0] - program_image.data(); code_set->CodeSegment().addr = loadinfo.seg_addrs[0]; @@ -255,14 +254,14 @@ FileType AppLoader_THREEDSX::IdentifyType(FileUtil::IOFile& file) { return FileType::Error; } -ResultStatus AppLoader_THREEDSX::Load(Kernel::SharedPtr& process) { +ResultStatus AppLoader_THREEDSX::Load(std::shared_ptr& process) { if (is_loaded) return ResultStatus::ErrorAlreadyLoaded; if (!file.IsOpen()) return ResultStatus::Error; - SharedPtr codeset; + std::shared_ptr codeset; if (Load3DSXFile(file, Memory::PROCESS_IMAGE_VADDR, &codeset) != ERROR_NONE) return ResultStatus::Error; codeset->name = filename; diff --git a/src/core/loader/3dsx.h b/src/core/loader/3dsx.h index 237d283508..4d56a06246 100644 --- a/src/core/loader/3dsx.h +++ b/src/core/loader/3dsx.h @@ -4,6 +4,7 @@ #pragma once +#include #include #include "common/common_types.h" #include "core/loader/loader.h" @@ -31,7 +32,7 @@ public: return IdentifyType(file); } - ResultStatus Load(Kernel::SharedPtr& process) override; + ResultStatus Load(std::shared_ptr& process) override; ResultStatus ReadIcon(std::vector& buffer) override; diff --git a/src/core/loader/elf.cpp b/src/core/loader/elf.cpp index 26470ff9d5..417c309a27 100644 --- a/src/core/loader/elf.cpp +++ b/src/core/loader/elf.cpp @@ -15,7 +15,6 @@ #include "core/memory.h" using Kernel::CodeSet; -using Kernel::SharedPtr; //////////////////////////////////////////////////////////////////////////////////////////////////// // ELF Header Constants @@ -209,7 +208,7 @@ public: u32 GetFlags() const { return (u32)(header->e_flags); } - SharedPtr LoadInto(u32 vaddr); + std::shared_ptr LoadInto(u32 vaddr); int GetNumSegments() const { return (int)(header->e_phnum); @@ -272,7 +271,7 @@ const char* ElfReader::GetSectionName(int section) const { return nullptr; } -SharedPtr ElfReader::LoadInto(u32 vaddr) { +std::shared_ptr ElfReader::LoadInto(u32 vaddr) { LOG_DEBUG(Loader, "String section: {}", header->e_shstrndx); // Should we relocate? @@ -300,7 +299,7 @@ SharedPtr ElfReader::LoadInto(u32 vaddr) { std::vector program_image(total_image_size); std::size_t current_image_position = 0; - SharedPtr codeset = Core::System::GetInstance().Kernel().CreateCodeSet("", 0); + std::shared_ptr codeset = Core::System::GetInstance().Kernel().CreateCodeSet("", 0); for (unsigned int i = 0; i < header->e_phnum; ++i) { Elf32_Phdr* p = &segments[i]; @@ -377,7 +376,7 @@ FileType AppLoader_ELF::IdentifyType(FileUtil::IOFile& file) { return FileType::Error; } -ResultStatus AppLoader_ELF::Load(Kernel::SharedPtr& process) { +ResultStatus AppLoader_ELF::Load(std::shared_ptr& process) { if (is_loaded) return ResultStatus::ErrorAlreadyLoaded; @@ -393,7 +392,7 @@ ResultStatus AppLoader_ELF::Load(Kernel::SharedPtr& process) { return ResultStatus::Error; ElfReader elf_reader(&buffer[0]); - SharedPtr codeset = elf_reader.LoadInto(Memory::PROCESS_IMAGE_VADDR); + std::shared_ptr codeset = elf_reader.LoadInto(Memory::PROCESS_IMAGE_VADDR); codeset->name = filename; process = Core::System::GetInstance().Kernel().CreateProcess(std::move(codeset)); diff --git a/src/core/loader/elf.h b/src/core/loader/elf.h index 113da59179..a43edff413 100644 --- a/src/core/loader/elf.h +++ b/src/core/loader/elf.h @@ -4,6 +4,7 @@ #pragma once +#include #include #include "common/common_types.h" #include "core/loader/loader.h" @@ -30,7 +31,7 @@ public: return IdentifyType(file); } - ResultStatus Load(Kernel::SharedPtr& process) override; + ResultStatus Load(std::shared_ptr& process) override; private: std::string filename; diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h index 1689bc9996..1a8e158234 100644 --- a/src/core/loader/loader.h +++ b/src/core/loader/loader.h @@ -99,7 +99,7 @@ public: * @param process The newly created process. * @return The status result of the operation. */ - virtual ResultStatus Load(Kernel::SharedPtr& process) = 0; + virtual ResultStatus Load(std::shared_ptr& process) = 0; /** * Loads the system mode that this application needs. diff --git a/src/core/loader/ncch.cpp b/src/core/loader/ncch.cpp index 34f49663a7..87aca79acd 100644 --- a/src/core/loader/ncch.cpp +++ b/src/core/loader/ncch.cpp @@ -61,9 +61,8 @@ std::pair, ResultStatus> AppLoader_NCCH::LoadKernelSystemMode ResultStatus::Success); } -ResultStatus AppLoader_NCCH::LoadExec(Kernel::SharedPtr& process) { +ResultStatus AppLoader_NCCH::LoadExec(std::shared_ptr& process) { using Kernel::CodeSet; - using Kernel::SharedPtr; if (!is_loaded) return ResultStatus::ErrorNotLoaded; @@ -75,7 +74,7 @@ ResultStatus AppLoader_NCCH::LoadExec(Kernel::SharedPtr& proces std::string process_name = Common::StringFromFixedZeroTerminatedBuffer( (const char*)overlay_ncch->exheader_header.codeset_info.name, 8); - SharedPtr codeset = + std::shared_ptr codeset = Core::System::GetInstance().Kernel().CreateCodeSet(process_name, program_id); codeset->CodeSegment().offset = 0; @@ -151,7 +150,7 @@ void AppLoader_NCCH::ParseRegionLockoutInfo() { } } -ResultStatus AppLoader_NCCH::Load(Kernel::SharedPtr& process) { +ResultStatus AppLoader_NCCH::Load(std::shared_ptr& process) { u64_le ncch_program_id; if (is_loaded) diff --git a/src/core/loader/ncch.h b/src/core/loader/ncch.h index cc9ef19142..d45ae8781b 100644 --- a/src/core/loader/ncch.h +++ b/src/core/loader/ncch.h @@ -33,7 +33,7 @@ public: return IdentifyType(file); } - ResultStatus Load(Kernel::SharedPtr& process) override; + ResultStatus Load(std::shared_ptr& process) override; /** * Loads the Exheader and returns the system mode for this application. @@ -65,7 +65,7 @@ private: * @param process The newly created process * @return ResultStatus result of function */ - ResultStatus LoadExec(Kernel::SharedPtr& process); + ResultStatus LoadExec(std::shared_ptr& process); /// Reads the region lockout info in the SMDH and send it to CFG service void ParseRegionLockoutInfo(); diff --git a/src/tests/core/hle/kernel/hle_ipc.cpp b/src/tests/core/hle/kernel/hle_ipc.cpp index d30897e2d1..455f50883a 100644 --- a/src/tests/core/hle/kernel/hle_ipc.cpp +++ b/src/tests/core/hle/kernel/hle_ipc.cpp @@ -16,7 +16,7 @@ namespace Kernel { -static SharedPtr MakeObject(Kernel::KernelSystem& kernel) { +static std::shared_ptr MakeObject(Kernel::KernelSystem& kernel) { return kernel.CreateEvent(ResetType::OneShot); } @@ -24,7 +24,7 @@ TEST_CASE("HLERequestContext::PopulateFromIncomingCommandBuffer", "[core][kernel Core::Timing timing; Memory::MemorySystem memory; Kernel::KernelSystem kernel(memory, timing, [] {}, 0); - auto session = std::get>(kernel.CreateSessionPair()); + auto session = std::get>(kernel.CreateSessionPair()); HLERequestContext context(kernel, std::move(session)); auto process = kernel.CreateProcess(kernel.CreateCodeSet("", 0)); @@ -236,7 +236,7 @@ TEST_CASE("HLERequestContext::WriteToOutgoingCommandBuffer", "[core][kernel]") { Core::Timing timing; Memory::MemorySystem memory; Kernel::KernelSystem kernel(memory, timing, [] {}, 0); - auto session = std::get>(kernel.CreateSessionPair()); + auto session = std::get>(kernel.CreateSessionPair()); HLERequestContext context(kernel, std::move(session)); auto process = kernel.CreateProcess(kernel.CreateCodeSet("", 0));