From d0041a33acf2f8cf750c193ec16b3d050bdfbc25 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Mon, 4 Oct 2021 17:12:32 -0700 Subject: [PATCH] strat: prefer os::NativeHandle to Handle/svc::Handle where sensible --- .../dd/dd_device_address_space_api.hpp | 4 +- .../dd/dd_device_address_space_common.hpp | 1 + .../dd/dd_device_address_space_types.hpp | 2 +- .../include/stratosphere/ldr/ldr_pm_api.hpp | 2 +- .../include/stratosphere/map/map_types.hpp | 4 +- .../stratosphere/osdbg/osdbg_thread_api.hpp | 2 +- .../stratosphere/osdbg/osdbg_thread_types.hpp | 2 +- .../sf/cmif/sf_cmif_service_dispatch.hpp | 2 +- .../sf/hipc/sf_hipc_server_manager.hpp | 16 ++--- .../include/stratosphere/sm/sm_api.hpp | 2 +- .../include/stratosphere/sm/sm_mitm_api.hpp | 2 +- .../stratosphere/tipc/tipc_object_holder.hpp | 14 ++-- .../stratosphere/tipc/tipc_object_manager.hpp | 12 ++-- .../stratosphere/tipc/tipc_server_manager.hpp | 32 ++++----- .../source/dd/dd_device_address_space.cpp | 6 +- .../source/htc/server/htc_htcmisc_impl.cpp | 2 +- .../source/htc/server/htc_htcmisc_impl.hpp | 2 +- .../source/htc/server/rpc/htc_rpc_client.hpp | 2 +- .../source/htcs/impl/htcs_manager.cpp | 14 ++-- .../source/htcs/impl/htcs_manager.hpp | 14 ++-- .../source/htcs/impl/htcs_manager_impl.cpp | 18 ++--- .../source/htcs/impl/htcs_manager_impl.hpp | 14 ++-- .../source/htcs/impl/htcs_service.cpp | 12 ++-- .../source/htcs/impl/htcs_service.hpp | 12 ++-- .../libstratosphere/source/ldr/ldr_pm_api.cpp | 2 +- .../source/osdbg/osdbg_thread.cpp | 2 +- .../source/pgl/srv/pgl_srv_api.cpp | 2 +- .../source/pgl/srv/pgl_srv_tipc_utils.hpp | 2 +- .../source/sf/hipc/sf_hipc_mitm_query_api.cpp | 2 +- .../source/sf/hipc/sf_hipc_mitm_query_api.hpp | 2 +- .../sf_hipc_server_domain_session_manager.cpp | 10 +-- .../source/sf/hipc/sf_hipc_server_manager.cpp | 4 +- .../libstratosphere/source/sm/sm_api.cpp | 2 +- .../libstratosphere/source/sm/sm_mitm_api.cpp | 2 +- .../libstratosphere/source/spl/spl_api.cpp | 6 +- .../include/vapours/svc/svc_common.hpp | 5 +- .../dmnt.gen2/source/dmnt2_debug_process.hpp | 4 +- .../dmnt/source/cheat/impl/dmnt_cheat_api.cpp | 20 +++--- .../dmnt/source/cheat/impl/dmnt_cheat_api.hpp | 2 +- .../impl/dmnt_cheat_debug_events_manager.cpp | 4 +- .../impl/dmnt_cheat_debug_events_manager.hpp | 2 +- stratosphere/fatal/source/fatal_config.cpp | 2 +- .../pm/source/impl/pm_resource_manager.cpp | 10 +-- .../pm/source/impl/pm_resource_manager.hpp | 8 ++- stratosphere/pm/source/pm_info_service.cpp | 3 +- .../sm/source/impl/sm_service_manager.cpp | 72 +++++++++---------- .../sm/source/impl/sm_service_manager.hpp | 10 +-- stratosphere/sm/source/sm_tipc_server.cpp | 2 +- stratosphere/spl/source/spl_api_impl.cpp | 8 +-- stratosphere/spl/source/spl_api_impl.hpp | 2 +- 50 files changed, 193 insertions(+), 190 deletions(-) diff --git a/libraries/libstratosphere/include/stratosphere/dd/dd_device_address_space_api.hpp b/libraries/libstratosphere/include/stratosphere/dd/dd_device_address_space_api.hpp index 58f53bfcf..814c66c04 100644 --- a/libraries/libstratosphere/include/stratosphere/dd/dd_device_address_space_api.hpp +++ b/libraries/libstratosphere/include/stratosphere/dd/dd_device_address_space_api.hpp @@ -25,9 +25,9 @@ namespace ams::dd { Result CreateDeviceAddressSpace(DeviceAddressSpaceType *das, u64 size); void DestroyDeviceAddressSpace(DeviceAddressSpaceType *das); - void AttachDeviceAddressSpaceHandle(DeviceAddressSpaceType *das, Handle handle, bool managed); + void AttachDeviceAddressSpaceHandle(DeviceAddressSpaceType *das, DeviceAddressSpaceHandle handle, bool managed); - Handle GetDeviceAddressSpaceHandle(DeviceAddressSpaceType *das); + DeviceAddressSpaceHandle GetDeviceAddressSpaceHandle(DeviceAddressSpaceType *das); Result MapDeviceAddressSpaceAligned(DeviceAddressSpaceType *das, ProcessHandle process_handle, u64 process_address, size_t size, DeviceVirtualAddress device_address, MemoryPermission device_perm); Result MapDeviceAddressSpaceNotAligned(DeviceAddressSpaceType *das, ProcessHandle process_handle, u64 process_address, size_t size, DeviceVirtualAddress device_address, MemoryPermission device_perm); diff --git a/libraries/libstratosphere/include/stratosphere/dd/dd_device_address_space_common.hpp b/libraries/libstratosphere/include/stratosphere/dd/dd_device_address_space_common.hpp index ec174b998..6b3226715 100644 --- a/libraries/libstratosphere/include/stratosphere/dd/dd_device_address_space_common.hpp +++ b/libraries/libstratosphere/include/stratosphere/dd/dd_device_address_space_common.hpp @@ -20,6 +20,7 @@ namespace ams::dd { using DeviceName = ::ams::svc::DeviceName; + using enum ::ams::svc::DeviceName; constexpr inline u64 DeviceAddressSpaceMemoryRegionAlignment = 4_KB; diff --git a/libraries/libstratosphere/include/stratosphere/dd/dd_device_address_space_types.hpp b/libraries/libstratosphere/include/stratosphere/dd/dd_device_address_space_types.hpp index fe5e5d8e3..40887f18b 100644 --- a/libraries/libstratosphere/include/stratosphere/dd/dd_device_address_space_types.hpp +++ b/libraries/libstratosphere/include/stratosphere/dd/dd_device_address_space_types.hpp @@ -21,7 +21,7 @@ namespace ams::dd { using DeviceVirtualAddress = u64; - using DeviceAddressSpaceHandle = ::Handle; + using DeviceAddressSpaceHandle = os::NativeHandle; struct DeviceAddressSpaceType { enum State { diff --git a/libraries/libstratosphere/include/stratosphere/ldr/ldr_pm_api.hpp b/libraries/libstratosphere/include/stratosphere/ldr/ldr_pm_api.hpp index 6bf6efc10..dd5d34b9a 100644 --- a/libraries/libstratosphere/include/stratosphere/ldr/ldr_pm_api.hpp +++ b/libraries/libstratosphere/include/stratosphere/ldr/ldr_pm_api.hpp @@ -20,7 +20,7 @@ namespace ams::ldr::pm { /* Process Manager API. */ - Result CreateProcess(Handle *out, PinId pin_id, u32 flags, Handle reslimit); + Result CreateProcess(os::NativeHandle *out, PinId pin_id, u32 flags, os::NativeHandle reslimit); Result GetProgramInfo(ProgramInfo *out, const ncm::ProgramLocation &loc); Result PinProgram(PinId *out, const ncm::ProgramLocation &loc); Result UnpinProgram(PinId pin_id); diff --git a/libraries/libstratosphere/include/stratosphere/map/map_types.hpp b/libraries/libstratosphere/include/stratosphere/map/map_types.hpp index 214dfee9b..9dc92788f 100644 --- a/libraries/libstratosphere/include/stratosphere/map/map_types.hpp +++ b/libraries/libstratosphere/include/stratosphere/map/map_types.hpp @@ -73,7 +73,7 @@ namespace ams::map { class MappedCodeMemory { private: - Handle process_handle; + os::NativeHandle process_handle; Result result; uintptr_t dst_address; uintptr_t src_address; @@ -83,7 +83,7 @@ namespace ams::map { /* ... */ } - MappedCodeMemory(Handle p_h, uintptr_t dst, uintptr_t src, size_t sz) : process_handle(p_h), dst_address(dst), src_address(src), size(sz) { + MappedCodeMemory(os::NativeHandle p_h, uintptr_t dst, uintptr_t src, size_t sz) : process_handle(p_h), dst_address(dst), src_address(src), size(sz) { this->result = svc::MapProcessCodeMemory(this->process_handle, this->dst_address, this->src_address, this->size); } diff --git a/libraries/libstratosphere/include/stratosphere/osdbg/osdbg_thread_api.hpp b/libraries/libstratosphere/include/stratosphere/osdbg/osdbg_thread_api.hpp index 5224bf818..316107b73 100644 --- a/libraries/libstratosphere/include/stratosphere/osdbg/osdbg_thread_api.hpp +++ b/libraries/libstratosphere/include/stratosphere/osdbg/osdbg_thread_api.hpp @@ -21,7 +21,7 @@ namespace ams::osdbg { struct ThreadInfo; - Result InitializeThreadInfo(ThreadInfo *thread_info, svc::Handle debug_handle, const svc::DebugInfoCreateProcess *create_process, const svc::DebugInfoCreateThread *create_thread); + Result InitializeThreadInfo(ThreadInfo *thread_info, os::NativeHandle debug_handle, const svc::DebugInfoCreateProcess *create_process, const svc::DebugInfoCreateThread *create_thread); Result UpdateThreadInfo(ThreadInfo *thread_info); Result GetThreadName(char *dst, const ThreadInfo *thread_info); diff --git a/libraries/libstratosphere/include/stratosphere/osdbg/osdbg_thread_types.hpp b/libraries/libstratosphere/include/stratosphere/osdbg/osdbg_thread_types.hpp index 3da8c8062..c4ac6f02d 100644 --- a/libraries/libstratosphere/include/stratosphere/osdbg/osdbg_thread_types.hpp +++ b/libraries/libstratosphere/include/stratosphere/osdbg/osdbg_thread_types.hpp @@ -40,7 +40,7 @@ namespace ams::osdbg { uintptr_t _function; uintptr_t _name_pointer; impl::ThreadTypeCommon *_thread_type; - svc::Handle _debug_handle; + os::NativeHandle _debug_handle; ThreadTypeType _thread_type_type; svc::DebugInfoCreateProcess _debug_info_create_process; svc::DebugInfoCreateThread _debug_info_create_thread; diff --git a/libraries/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_service_dispatch.hpp b/libraries/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_service_dispatch.hpp index 3f6c9d9bf..7161174c5 100644 --- a/libraries/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_service_dispatch.hpp +++ b/libraries/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_service_dispatch.hpp @@ -31,7 +31,7 @@ namespace ams::sf::cmif { class ServerMessageProcessor; struct HandlesToClose { - Handle handles[8]; + os::NativeHandle handles[8]; size_t num_handles; }; diff --git a/libraries/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_manager.hpp b/libraries/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_manager.hpp index 352589f1d..5ed4b95ec 100644 --- a/libraries/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_manager.hpp +++ b/libraries/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_manager.hpp @@ -55,7 +55,7 @@ namespace ams::sf::hipc { NON_MOVEABLE(Server); private: cmif::ServiceObjectHolder static_object; - ::Handle port_handle; + os::NativeHandle port_handle; sm::ServiceName service_name; int index; bool service_managed; @@ -95,7 +95,7 @@ namespace ams::sf::hipc { Result ProcessForMitmServer(os::MultiWaitHolderType *holder); Result ProcessForSession(os::MultiWaitHolderType *holder); - void RegisterServerImpl(Server *server, Handle port_handle, bool is_mitm_server) { + void RegisterServerImpl(Server *server, os::NativeHandle port_handle, bool is_mitm_server) { server->port_handle = port_handle; hipc::AttachMultiWaitHolderForAccept(server, port_handle); @@ -111,7 +111,7 @@ namespace ams::sf::hipc { os::LinkMultiWaitHolder(std::addressof(this->multi_wait), server); } - void RegisterServerImpl(int index, cmif::ServiceObjectHolder &&static_holder, Handle port_handle, bool is_mitm_server) { + void RegisterServerImpl(int index, cmif::ServiceObjectHolder &&static_holder, os::NativeHandle port_handle, bool is_mitm_server) { /* Allocate server memory. */ auto *server = this->AllocateServer(); AMS_ABORT_UNLESS(server != nullptr); @@ -128,7 +128,7 @@ namespace ams::sf::hipc { Result RegisterServerImpl(int index, cmif::ServiceObjectHolder &&static_holder, sm::ServiceName service_name, size_t max_sessions) { /* Register service. */ - Handle port_handle; + os::NativeHandle port_handle; R_TRY(sm::RegisterService(&port_handle, service_name, max_sessions, false)); /* Allocate server memory. */ @@ -151,7 +151,7 @@ namespace ams::sf::hipc { template Result RegisterMitmServerImpl(int index, cmif::ServiceObjectHolder &&static_holder, sm::ServiceName service_name) { /* Install mitm service. */ - Handle port_handle; + os::NativeHandle port_handle; R_TRY(this->InstallMitmServerImpl(&port_handle, service_name, &Interface::ShouldMitm)); /* Allocate server memory. */ @@ -171,7 +171,7 @@ namespace ams::sf::hipc { return ResultSuccess(); } - Result InstallMitmServerImpl(Handle *out_port_handle, sm::ServiceName service_name, MitmQueryFunction query_func); + Result InstallMitmServerImpl(os::NativeHandle *out_port_handle, sm::ServiceName service_name, MitmQueryFunction query_func); protected: virtual Server *AllocateServer() = 0; virtual void DestroyServer(Server *server) = 0; @@ -205,7 +205,7 @@ namespace ams::sf::hipc { } template - void RegisterObjectForServer(SharedPointer static_object, Handle port_handle) { + void RegisterObjectForServer(SharedPointer static_object, os::NativeHandle port_handle) { this->RegisterServerImpl(0, cmif::ServiceObjectHolder(std::move(static_object)), port_handle, false); } @@ -214,7 +214,7 @@ namespace ams::sf::hipc { return this->RegisterServerImpl(0, cmif::ServiceObjectHolder(std::move(static_object)), service_name, max_sessions); } - void RegisterServer(int port_index, Handle port_handle) { + void RegisterServer(int port_index, os::NativeHandle port_handle) { this->RegisterServerImpl(port_index, cmif::ServiceObjectHolder(), port_handle, false); } diff --git a/libraries/libstratosphere/include/stratosphere/sm/sm_api.hpp b/libraries/libstratosphere/include/stratosphere/sm/sm_api.hpp index f2202b223..eac646c7d 100644 --- a/libraries/libstratosphere/include/stratosphere/sm/sm_api.hpp +++ b/libraries/libstratosphere/include/stratosphere/sm/sm_api.hpp @@ -26,7 +26,7 @@ namespace ams::sm { /* Ordinary SM API. */ Result GetService(Service *out, ServiceName name); - Result RegisterService(Handle *out, ServiceName name, size_t max_sessions, bool is_light); + Result RegisterService(os::NativeHandle *out, ServiceName name, size_t max_sessions, bool is_light); Result UnregisterService(ServiceName name); /* Atmosphere extensions. */ diff --git a/libraries/libstratosphere/include/stratosphere/sm/sm_mitm_api.hpp b/libraries/libstratosphere/include/stratosphere/sm/sm_mitm_api.hpp index 20163c006..22b07cfd3 100644 --- a/libraries/libstratosphere/include/stratosphere/sm/sm_mitm_api.hpp +++ b/libraries/libstratosphere/include/stratosphere/sm/sm_mitm_api.hpp @@ -21,7 +21,7 @@ namespace ams::sm::mitm { /* Mitm API. */ - Result InstallMitm(Handle *out_port, Handle *out_query, ServiceName name); + Result InstallMitm(os::NativeHandle *out_port, os::NativeHandle *out_query, ServiceName name); Result UninstallMitm(ServiceName name); Result DeclareFutureMitm(ServiceName name); Result ClearFutureMitm(ServiceName name); diff --git a/libraries/libstratosphere/include/stratosphere/tipc/tipc_object_holder.hpp b/libraries/libstratosphere/include/stratosphere/tipc/tipc_object_holder.hpp index 45ffd0a67..9e3ebdb9f 100644 --- a/libraries/libstratosphere/include/stratosphere/tipc/tipc_object_holder.hpp +++ b/libraries/libstratosphere/include/stratosphere/tipc/tipc_object_holder.hpp @@ -28,12 +28,12 @@ namespace ams::tipc { ObjectType_Session = 2, }; private: - svc::Handle m_handle; + os::NativeHandle m_handle; ObjectType m_type; bool m_managed; tipc::ServiceObjectBase *m_object; private: - void InitializeImpl(ObjectType type, svc::Handle handle, bool managed, tipc::ServiceObjectBase *object) { + void InitializeImpl(ObjectType type, os::NativeHandle handle, bool managed, tipc::ServiceObjectBase *object) { /* Validate that the object isn't already constructed. */ AMS_ASSERT(m_type == ObjectType_Invalid); @@ -44,16 +44,16 @@ namespace ams::tipc { m_object = object; } public: - constexpr inline ObjectHolder() : m_handle(svc::InvalidHandle), m_type(ObjectType_Invalid), m_managed(false), m_object(nullptr) { /* ... */ } + constexpr inline ObjectHolder() : m_handle(os::InvalidNativeHandle), m_type(ObjectType_Invalid), m_managed(false), m_object(nullptr) { /* ... */ } - void InitializeAsPort(svc::Handle handle) { + void InitializeAsPort(os::NativeHandle handle) { /* NOTE: Nintendo sets ports as managed, but this will cause a nullptr-deref if one is ever closed. */ /* This is theoretically a non-issue, as ports can't be closed, but we will set ours as unmanaged, */ /* just in case. */ this->InitializeImpl(ObjectType_Port, handle, false, nullptr); } - void InitializeAsSession(svc::Handle handle, bool managed, tipc::ServiceObjectBase *object) { + void InitializeAsSession(os::NativeHandle handle, bool managed, tipc::ServiceObjectBase *object) { this->InitializeImpl(ObjectType_Session, handle, managed, object); } @@ -69,13 +69,13 @@ namespace ams::tipc { } /* Reset all fields. */ - m_handle = svc::InvalidHandle; + m_handle = os::InvalidNativeHandle; m_type = ObjectType_Invalid; m_managed = false; m_object = nullptr; } - constexpr svc::Handle GetHandle() const { + constexpr os::NativeHandle GetHandle() const { return m_handle; } diff --git a/libraries/libstratosphere/include/stratosphere/tipc/tipc_object_manager.hpp b/libraries/libstratosphere/include/stratosphere/tipc/tipc_object_manager.hpp index 350c519ef..221e09a64 100644 --- a/libraries/libstratosphere/include/stratosphere/tipc/tipc_object_manager.hpp +++ b/libraries/libstratosphere/include/stratosphere/tipc/tipc_object_manager.hpp @@ -37,7 +37,7 @@ namespace ams::tipc { Entry *m_entries_end{}; os::MultiWaitType *m_multi_wait{}; private: - Entry *FindEntry(svc::Handle handle) { + Entry *FindEntry(os::NativeHandle handle) { for (Entry *cur = m_entries_start; cur != m_entries_end; ++cur) { if (GetReference(cur->object).GetHandle() == handle) { return cur; @@ -76,7 +76,7 @@ namespace ams::tipc { std::scoped_lock lk(m_mutex); /* Find an empty entry. */ - auto *entry = this->FindEntry(svc::InvalidHandle); + auto *entry = this->FindEntry(os::InvalidNativeHandle); AMS_ABORT_UNLESS(entry != nullptr); /* Set the entry's object. */ @@ -87,7 +87,7 @@ namespace ams::tipc { os::LinkMultiWaitHolder(m_multi_wait, std::addressof(entry->multi_wait_holder)); } - void CloseObject(svc::Handle handle) { + void CloseObject(os::NativeHandle handle) { /* Lock ourselves. */ std::scoped_lock lk(m_mutex); @@ -103,14 +103,14 @@ namespace ams::tipc { GetReference(entry->object).Destroy(); } - Result ReplyAndReceive(os::MultiWaitHolderType **out_holder, ObjectHolder *out_object, svc::Handle reply_target, os::MultiWaitType *multi_wait) { + Result ReplyAndReceive(os::MultiWaitHolderType **out_holder, ObjectHolder *out_object, os::NativeHandle reply_target, os::MultiWaitType *multi_wait) { /* Declare signaled holder for processing ahead of time. */ os::MultiWaitHolderType *signaled_holder; /* Reply and receive until we get a newly signaled target. */ Result result = os::SdkReplyAndReceive(out_holder, reply_target, multi_wait); for (signaled_holder = *out_holder; signaled_holder == nullptr; signaled_holder = *out_holder) { - result = os::SdkReplyAndReceive(out_holder, svc::InvalidHandle, multi_wait); + result = os::SdkReplyAndReceive(out_holder, os::InvalidNativeHandle, multi_wait); } /* Find the entry matching the signaled holder. */ @@ -125,7 +125,7 @@ namespace ams::tipc { } } - Result Reply(svc::Handle reply_target) { + Result Reply(os::NativeHandle reply_target) { /* Perform the reply. */ s32 dummy; R_TRY_CATCH(svc::ReplyAndReceive(std::addressof(dummy), nullptr, 0, reply_target, 0)) { diff --git a/libraries/libstratosphere/include/stratosphere/tipc/tipc_server_manager.hpp b/libraries/libstratosphere/include/stratosphere/tipc/tipc_server_manager.hpp index c67c1340a..6f5f897b1 100644 --- a/libraries/libstratosphere/include/stratosphere/tipc/tipc_server_manager.hpp +++ b/libraries/libstratosphere/include/stratosphere/tipc/tipc_server_manager.hpp @@ -141,7 +141,7 @@ namespace ams::tipc { m_object_manager = manager; } - void RegisterPort(s32 index, svc::Handle port_handle) { + void RegisterPort(s32 index, os::NativeHandle port_handle) { /* Set our port number. */ this->m_port_number = index; @@ -168,11 +168,11 @@ namespace ams::tipc { return m_object_manager->Reply(object.GetHandle()); } - Result ReplyAndReceive(os::MultiWaitHolderType **out_holder, ObjectHolder *out_object, svc::Handle reply_target) { + Result ReplyAndReceive(os::MultiWaitHolderType **out_holder, ObjectHolder *out_object, os::NativeHandle reply_target) { return m_object_manager->ReplyAndReceive(out_holder, out_object, reply_target, std::addressof(m_multi_wait)); } - void AddSession(svc::Handle session_handle, tipc::ServiceObjectBase *service_object) { + void AddSession(os::NativeHandle session_handle, tipc::ServiceObjectBase *service_object) { /* Create an object holder for the session. */ tipc::ObjectHolder object; @@ -195,7 +195,7 @@ namespace ams::tipc { case MessageType_AddSession: { /* Get the handle from where it's packed into the message type. */ - const svc::Handle session_handle = static_cast(message_type >> BITSIZEOF(u32)); + const os::NativeHandle session_handle = static_cast(message_type >> BITSIZEOF(u32)); /* Allocate a service object for the port. */ auto *service_object = m_server_manager->AllocateObject(static_cast(message_data)); @@ -292,7 +292,7 @@ namespace ams::tipc { os::SendMessageQueue(std::addressof(m_message_queue), ConvertKeyToMessage(key)); } - void TriggerAddSession(svc::Handle session_handle, size_t port_index) { + void TriggerAddSession(os::NativeHandle session_handle, size_t port_index) { /* Acquire exclusive server manager access. */ std::scoped_lock lk(m_server_manager->GetMutex()); @@ -409,14 +409,14 @@ namespace ams::tipc { } template - void RegisterPort(svc::Handle port_handle) { + void RegisterPort(os::NativeHandle port_handle) { this->GetPortManager().RegisterPort(static_cast(Ix), port_handle); } template void RegisterPort(sm::ServiceName service_name, size_t max_sessions) { /* Register service. */ - svc::Handle port_handle = svc::InvalidHandle; + os::NativeHandle port_handle; R_ABORT_UNLESS(sm::RegisterService(std::addressof(port_handle), service_name, max_sessions, false)); /* Register the port handle. */ @@ -463,13 +463,13 @@ namespace ams::tipc { }(std::make_index_sequence()); } - Result AddSession(svc::Handle *out, tipc::ServiceObjectBase *object) { + Result AddSession(os::NativeHandle *out, tipc::ServiceObjectBase *object) { /* Acquire exclusive access to ourselves. */ std::scoped_lock lk(m_mutex); /* Create a handle for the session. */ svc::Handle session_handle; - R_TRY(svc::CreateSession(std::addressof(session_handle), out, false, 0)); + R_TRY(svc::CreateSession(std::addressof(session_handle), static_cast(out), false, 0)); /* Select the best port manager. */ PortManagerBase *best_manager = nullptr; @@ -514,7 +514,7 @@ namespace ams::tipc { std::memset(svc::ipc::GetMessageBuffer(), 0, svc::ipc::MessageBufferSize); /* Process requests forever. */ - svc::Handle reply_target = svc::InvalidHandle; + os::NativeHandle reply_target = os::InvalidNativeHandle; while (true) { /* Reply to our pending request, and receive a new one. */ os::MultiWaitHolderType *signaled_holder = nullptr; @@ -525,7 +525,7 @@ namespace ams::tipc { port_manager.CloseSession(signaled_object); /* We have nothing to reply to. */ - reply_target = svc::InvalidHandle; + reply_target = os::InvalidNativeHandle; continue; } } R_END_TRY_CATCH; @@ -542,7 +542,7 @@ namespace ams::tipc { } /* We have nothing to reply to. */ - reply_target = svc::InvalidHandle; + reply_target = os::InvalidNativeHandle; } break; case ObjectHolder::ObjectType_Session: @@ -557,7 +557,7 @@ namespace ams::tipc { port_manager.ProcessRegisterRetry(signaled_object); /* We have nothing to reply to. */ - reply_target = svc::InvalidHandle; + reply_target = os::InvalidNativeHandle; } else { /* We're done processing, so we should reply. */ reply_target = signaled_object.GetHandle(); @@ -571,7 +571,7 @@ namespace ams::tipc { port_manager.CloseSessionIfNecessary(signaled_object, !tipc::ResultSessionClosed::Includes(process_result)); /* We have nothing to reply to. */ - reply_target = svc::InvalidHandle; + reply_target = os::InvalidNativeHandle; } } break; @@ -582,12 +582,12 @@ namespace ams::tipc { port_manager.ProcessMessages(); /* We have nothing to reply to. */ - reply_target = svc::InvalidHandle; + reply_target = os::InvalidNativeHandle; } } } - void TriggerAddSession(svc::Handle session_handle, size_t port_index) { + void TriggerAddSession(os::NativeHandle session_handle, size_t port_index) { /* Acquire exclusive access to ourselves. */ std::scoped_lock lk(m_mutex); diff --git a/libraries/libstratosphere/source/dd/dd_device_address_space.cpp b/libraries/libstratosphere/source/dd/dd_device_address_space.cpp index ac25e13dd..49c0ecbae 100644 --- a/libraries/libstratosphere/source/dd/dd_device_address_space.cpp +++ b/libraries/libstratosphere/source/dd/dd_device_address_space.cpp @@ -59,16 +59,16 @@ namespace ams::dd { das->state = DeviceAddressSpaceType::State_NotInitialized; } - void AttachDeviceAddressSpaceHandle(DeviceAddressSpaceType *das, Handle handle, bool managed) { + void AttachDeviceAddressSpaceHandle(DeviceAddressSpaceType *das, DeviceAddressSpaceHandle handle, bool managed) { /* Check pre-conditions. */ - AMS_ASSERT(handle != svc::InvalidHandle); + AMS_ASSERT(handle != os::InvalidNativeHandle); das->device_handle = handle; das->is_handle_managed = managed; das->state = DeviceAddressSpaceType::State_Initialized; } - Handle GetDeviceAddressSpaceHandle(DeviceAddressSpaceType *das) { + DeviceAddressSpaceHandle GetDeviceAddressSpaceHandle(DeviceAddressSpaceType *das) { /* Check pre-conditions. */ AMS_ASSERT(das->state == DeviceAddressSpaceType::State_Initialized); diff --git a/libraries/libstratosphere/source/htc/server/htc_htcmisc_impl.cpp b/libraries/libstratosphere/source/htc/server/htc_htcmisc_impl.cpp index 9443994a8..07f89cbaa 100644 --- a/libraries/libstratosphere/source/htc/server/htc_htcmisc_impl.cpp +++ b/libraries/libstratosphere/source/htc/server/htc_htcmisc_impl.cpp @@ -108,7 +108,7 @@ namespace ams::htc::server { return ResultSuccess(); } - Result HtcmiscImpl::RunOnHostBegin(u32 *out_task_id, Handle *out_event, const char *args, size_t args_size) { + Result HtcmiscImpl::RunOnHostBegin(u32 *out_task_id, os::NativeHandle *out_event, const char *args, size_t args_size) { /* Begin the task. */ u32 task_id; R_TRY(m_rpc_client.Begin(std::addressof(task_id), args, args_size)); diff --git a/libraries/libstratosphere/source/htc/server/htc_htcmisc_impl.hpp b/libraries/libstratosphere/source/htc/server/htc_htcmisc_impl.hpp index 538952a82..8ed96d5df 100644 --- a/libraries/libstratosphere/source/htc/server/htc_htcmisc_impl.hpp +++ b/libraries/libstratosphere/source/htc/server/htc_htcmisc_impl.hpp @@ -63,7 +63,7 @@ namespace ams::htc::server { Result GetEnvironmentVariable(size_t *out_size, char *dst, size_t dst_size, const char *name, size_t name_size); Result GetEnvironmentVariableLength(size_t *out_size, const char *name, size_t name_size); - Result RunOnHostBegin(u32 *out_task_id, Handle *out_event, const char *args, size_t args_size); + Result RunOnHostBegin(u32 *out_task_id, os::NativeHandle *out_event, const char *args, size_t args_size); Result RunOnHostEnd(s32 *out_result, u32 task_id); }; diff --git a/libraries/libstratosphere/source/htc/server/rpc/htc_rpc_client.hpp b/libraries/libstratosphere/source/htc/server/rpc/htc_rpc_client.hpp index f74d4b447..ea5b7066c 100644 --- a/libraries/libstratosphere/source/htc/server/rpc/htc_rpc_client.hpp +++ b/libraries/libstratosphere/source/htc/server/rpc/htc_rpc_client.hpp @@ -199,7 +199,7 @@ namespace ams::htc::server::rpc { os::WaitEvent(m_task_table.Get(task_id)->GetEvent()); } - Handle DetachReadableHandle(u32 task_id) { + os::NativeHandle DetachReadableHandle(u32 task_id) { return os::DetachReadableHandleOfSystemEvent(m_task_table.Get(task_id)->GetSystemEvent()); } diff --git a/libraries/libstratosphere/source/htcs/impl/htcs_manager.cpp b/libraries/libstratosphere/source/htcs/impl/htcs_manager.cpp index b411eace9..2300ae9ea 100644 --- a/libraries/libstratosphere/source/htcs/impl/htcs_manager.cpp +++ b/libraries/libstratosphere/source/htcs/impl/htcs_manager.cpp @@ -204,7 +204,7 @@ namespace ams::htcs::impl { } } - Result HtcsManager::AcceptStart(u32 *out_task_id, Handle *out_handle, s32 desc) { + Result HtcsManager::AcceptStart(u32 *out_task_id, os::NativeHandle *out_handle, s32 desc) { return m_impl->AcceptStart(out_task_id, out_handle, desc); } @@ -227,7 +227,7 @@ namespace ams::htcs::impl { } } - Result HtcsManager::RecvStart(u32 *out_task_id, Handle *out_handle, s64 size, s32 desc, s32 flags) { + Result HtcsManager::RecvStart(u32 *out_task_id, os::NativeHandle *out_handle, s64 size, s32 desc, s32 flags) { return m_impl->RecvStart(out_task_id, out_handle, size, desc, flags); } @@ -255,11 +255,11 @@ namespace ams::htcs::impl { } } - Result HtcsManager::SendStart(u32 *out_task_id, Handle *out_handle, const char *buffer, s64 size, s32 desc, s32 flags) { + Result HtcsManager::SendStart(u32 *out_task_id, os::NativeHandle *out_handle, const char *buffer, s64 size, s32 desc, s32 flags) { return m_impl->SendStart(out_task_id, out_handle, buffer, size, desc, flags); } - Result HtcsManager::SendLargeStart(u32 *out_task_id, Handle *out_handle, const char **buffers, const s64 *sizes, s32 count, s32 desc, s32 flags) { + Result HtcsManager::SendLargeStart(u32 *out_task_id, os::NativeHandle *out_handle, const char **buffers, const s64 *sizes, s32 count, s32 desc, s32 flags) { return m_impl->SendLargeStart(out_task_id, out_handle, buffers, sizes, count, desc, flags); } @@ -287,7 +287,7 @@ namespace ams::htcs::impl { } } - Result HtcsManager::StartSend(u32 *out_task_id, Handle *out_handle, s32 desc, s64 size, s32 flags) { + Result HtcsManager::StartSend(u32 *out_task_id, os::NativeHandle *out_handle, s32 desc, s64 size, s32 flags) { return m_impl->StartSend(out_task_id, out_handle, desc, size, flags); } @@ -328,7 +328,7 @@ namespace ams::htcs::impl { } } - Result HtcsManager::StartRecv(u32 *out_task_id, Handle *out_handle, s64 size, s32 desc, s32 flags) { + Result HtcsManager::StartRecv(u32 *out_task_id, os::NativeHandle *out_handle, s64 size, s32 desc, s32 flags) { return m_impl->StartRecv(out_task_id, out_handle, size, desc, flags); } @@ -356,7 +356,7 @@ namespace ams::htcs::impl { } } - Result HtcsManager::StartSelect(u32 *out_task_id, Handle *out_handle, Span read_handles, Span write_handles, Span exception_handles, s64 tv_sec, s64 tv_usec) { + Result HtcsManager::StartSelect(u32 *out_task_id, os::NativeHandle *out_handle, Span read_handles, Span write_handles, Span exception_handles, s64 tv_sec, s64 tv_usec) { /* Invoke our implementation. */ R_TRY_CATCH(m_impl->StartSelect(out_task_id, out_handle, read_handles, write_handles, exception_handles, tv_sec, tv_usec)) { R_CONVERT(htc::ResultTaskCancelled, tma::ResultUnknown()) diff --git a/libraries/libstratosphere/source/htcs/impl/htcs_manager.hpp b/libraries/libstratosphere/source/htcs/impl/htcs_manager.hpp index 6f068e536..dc34c8d0c 100644 --- a/libraries/libstratosphere/source/htcs/impl/htcs_manager.hpp +++ b/libraries/libstratosphere/source/htcs/impl/htcs_manager.hpp @@ -43,24 +43,24 @@ namespace ams::htcs::impl { void Shutdown(s32 *out_err, s32 *out_res, s32 how, s32 desc); void Fcntl(s32 *out_err, s32 *out_res, s32 command, s32 value, s32 desc); - Result AcceptStart(u32 *out_task_id, Handle *out_handle, s32 desc); + Result AcceptStart(u32 *out_task_id, os::NativeHandle *out_handle, s32 desc); void AcceptResults(s32 *out_err, s32 *out_desc, SockAddrHtcs *out_address, u32 task_id, s32 desc); - Result RecvStart(u32 *out_task_id, Handle *out_handle, s64 size, s32 desc, s32 flags); + Result RecvStart(u32 *out_task_id, os::NativeHandle *out_handle, s64 size, s32 desc, s32 flags); void RecvResults(s32 *out_err, s64 *out_size, char *buffer, s64 buffer_size, u32 task_id, s32 desc); - Result SendStart(u32 *out_task_id, Handle *out_handle, const char *buffer, s64 size, s32 desc, s32 flags); - Result SendLargeStart(u32 *out_task_id, Handle *out_handle, const char **buffers, const s64 *sizes, s32 count, s32 desc, s32 flags); + Result SendStart(u32 *out_task_id, os::NativeHandle *out_handle, const char *buffer, s64 size, s32 desc, s32 flags); + Result SendLargeStart(u32 *out_task_id, os::NativeHandle *out_handle, const char **buffers, const s64 *sizes, s32 count, s32 desc, s32 flags); void SendResults(s32 *out_err, s64 *out_size, u32 task_id, s32 desc); - Result StartSend(u32 *out_task_id, Handle *out_handle, s32 desc, s64 size, s32 flags); + Result StartSend(u32 *out_task_id, os::NativeHandle *out_handle, s32 desc, s64 size, s32 flags); Result ContinueSend(s64 *out_size, const char *buffer, s64 buffer_size, u32 task_id, s32 desc); void EndSend(s32 *out_err, s64 *out_size, u32 task_id, s32 desc); - Result StartRecv(u32 *out_task_id, Handle *out_handle, s64 size, s32 desc, s32 flags); + Result StartRecv(u32 *out_task_id, os::NativeHandle *out_handle, s64 size, s32 desc, s32 flags); void EndRecv(s32 *out_err, s64 *out_size, char *buffer, s64 buffer_size, u32 task_id, s32 desc); - Result StartSelect(u32 *out_task_id, Handle *out_handle, Span read_handles, Span write_handles, Span exception_handles, s64 tv_sec, s64 tv_usec); + Result StartSelect(u32 *out_task_id, os::NativeHandle *out_handle, Span read_handles, Span write_handles, Span exception_handles, s64 tv_sec, s64 tv_usec); Result EndSelect(s32 *out_err, s32 *out_count, Span read_handles, Span write_handles, Span exception_handles, u32 task_id); }; diff --git a/libraries/libstratosphere/source/htcs/impl/htcs_manager_impl.cpp b/libraries/libstratosphere/source/htcs/impl/htcs_manager_impl.cpp index 6d78c3bf4..b836c2c1e 100644 --- a/libraries/libstratosphere/source/htcs/impl/htcs_manager_impl.cpp +++ b/libraries/libstratosphere/source/htcs/impl/htcs_manager_impl.cpp @@ -82,7 +82,7 @@ namespace ams::htcs::impl { return m_service.Fcntl(out_err, out_res, desc, command, value); } - Result HtcsManagerImpl::AcceptStart(u32 *out_task_id, Handle *out_handle, s32 desc) { + Result HtcsManagerImpl::AcceptStart(u32 *out_task_id, os::NativeHandle *out_handle, s32 desc) { return m_service.AcceptStart(out_task_id, out_handle, desc); } @@ -90,7 +90,7 @@ namespace ams::htcs::impl { return m_service.AcceptResults(out_err, out_desc, out_address, task_id, desc); } - Result HtcsManagerImpl::RecvStart(u32 *out_task_id, Handle *out_handle, s64 size, s32 desc, s32 flags) { + Result HtcsManagerImpl::RecvStart(u32 *out_task_id, os::NativeHandle *out_handle, s64 size, s32 desc, s32 flags) { return m_service.ReceiveSmallStart(out_task_id, out_handle, size, desc, flags); } @@ -98,10 +98,10 @@ namespace ams::htcs::impl { return m_service.ReceiveSmallResults(out_err, out_size, buffer, buffer_size, task_id, desc); } - Result HtcsManagerImpl::SendStart(u32 *out_task_id, Handle *out_handle, const char *buffer, s64 size, s32 desc, s32 flags) { + Result HtcsManagerImpl::SendStart(u32 *out_task_id, os::NativeHandle *out_handle, const char *buffer, s64 size, s32 desc, s32 flags) { /* Start the send. */ u32 task_id; - Handle handle; + os::NativeHandle handle; R_TRY(m_service.SendSmallStart(std::addressof(task_id), std::addressof(handle), desc, size, flags)); /* Continue the send. */ @@ -126,7 +126,7 @@ namespace ams::htcs::impl { return ResultSuccess(); } - Result HtcsManagerImpl::SendLargeStart(u32 *out_task_id, Handle *out_handle, const char **buffers, const s64 *sizes, s32 count, s32 desc, s32 flags) { + Result HtcsManagerImpl::SendLargeStart(u32 *out_task_id, os::NativeHandle *out_handle, const char **buffers, const s64 *sizes, s32 count, s32 desc, s32 flags) { /* NOTE: Nintendo aborts here, too. */ AMS_ABORT("HtcsManagerImpl::SendLargeStart is not implemented"); } @@ -135,7 +135,7 @@ namespace ams::htcs::impl { return m_service.SendSmallResults(out_err, out_size, task_id, desc); } - Result HtcsManagerImpl::StartSend(u32 *out_task_id, Handle *out_handle, s32 desc, s64 size, s32 flags) { + Result HtcsManagerImpl::StartSend(u32 *out_task_id, os::NativeHandle *out_handle, s32 desc, s64 size, s32 flags) { return m_service.SendStart(out_task_id, out_handle, desc, size, flags); } @@ -147,7 +147,7 @@ namespace ams::htcs::impl { return m_service.SendResults(out_err, out_size, task_id, desc); } - Result HtcsManagerImpl::StartRecv(u32 *out_task_id, Handle *out_handle, s64 size, s32 desc, s32 flags) { + Result HtcsManagerImpl::StartRecv(u32 *out_task_id, os::NativeHandle *out_handle, s64 size, s32 desc, s32 flags) { return m_service.ReceiveStart(out_task_id, out_handle, size, desc, flags); } @@ -155,10 +155,10 @@ namespace ams::htcs::impl { return m_service.ReceiveResults(out_err, out_size, buffer, buffer_size, task_id, desc); } - Result HtcsManagerImpl::StartSelect(u32 *out_task_id, Handle *out_handle, Span read_handles, Span write_handles, Span exception_handles, s64 tv_sec, s64 tv_usec) { + Result HtcsManagerImpl::StartSelect(u32 *out_task_id, os::NativeHandle *out_handle, Span read_handles, Span write_handles, Span exception_handles, s64 tv_sec, s64 tv_usec) { /* Start the select. */ u32 task_id; - Handle handle; + os::NativeHandle handle; const Result result = m_service.SelectStart(std::addressof(task_id), std::addressof(handle), read_handles, write_handles, exception_handles, tv_sec, tv_usec); /* Ensure our state ends up clean. */ diff --git a/libraries/libstratosphere/source/htcs/impl/htcs_manager_impl.hpp b/libraries/libstratosphere/source/htcs/impl/htcs_manager_impl.hpp index e5aa1036c..ba6917b8c 100644 --- a/libraries/libstratosphere/source/htcs/impl/htcs_manager_impl.hpp +++ b/libraries/libstratosphere/source/htcs/impl/htcs_manager_impl.hpp @@ -52,24 +52,24 @@ namespace ams::htcs::impl { Result Shutdown(s32 *out_err, s32 desc, s32 how); Result Fcntl(s32 *out_err, s32 *out_res, s32 desc, s32 command, s32 value); - Result AcceptStart(u32 *out_task_id, Handle *out_handle, s32 desc); + Result AcceptStart(u32 *out_task_id, os::NativeHandle *out_handle, s32 desc); Result AcceptResults(s32 *out_err, s32 *out_desc, SockAddrHtcs *out_address, u32 task_id, s32 desc); - Result RecvStart(u32 *out_task_id, Handle *out_handle, s64 size, s32 desc, s32 flags); + Result RecvStart(u32 *out_task_id, os::NativeHandle *out_handle, s64 size, s32 desc, s32 flags); Result RecvResults(s32 *out_err, s64 *out_size, char *buffer, s64 buffer_size, u32 task_id, s32 desc); - Result SendStart(u32 *out_task_id, Handle *out_handle, const char *buffer, s64 size, s32 desc, s32 flags); - Result SendLargeStart(u32 *out_task_id, Handle *out_handle, const char **buffers, const s64 *sizes, s32 count, s32 desc, s32 flags); + Result SendStart(u32 *out_task_id, os::NativeHandle *out_handle, const char *buffer, s64 size, s32 desc, s32 flags); + Result SendLargeStart(u32 *out_task_id, os::NativeHandle *out_handle, const char **buffers, const s64 *sizes, s32 count, s32 desc, s32 flags); Result SendResults(s32 *out_err, s64 *out_size, u32 task_id, s32 desc); - Result StartSend(u32 *out_task_id, Handle *out_handle, s32 desc, s64 size, s32 flags); + Result StartSend(u32 *out_task_id, os::NativeHandle *out_handle, s32 desc, s64 size, s32 flags); Result ContinueSend(s64 *out_size, const char *buffer, s64 buffer_size, u32 task_id, s32 desc); Result EndSend(s32 *out_err, s64 *out_size, u32 task_id, s32 desc); - Result StartRecv(u32 *out_task_id, Handle *out_handle, s64 size, s32 desc, s32 flags); + Result StartRecv(u32 *out_task_id, os::NativeHandle *out_handle, s64 size, s32 desc, s32 flags); Result EndRecv(s32 *out_err, s64 *out_size, char *buffer, s64 buffer_size, u32 task_id, s32 desc); - Result StartSelect(u32 *out_task_id, Handle *out_handle, Span read_handles, Span write_handles, Span exception_handles, s64 tv_sec, s64 tv_usec); + Result StartSelect(u32 *out_task_id, os::NativeHandle *out_handle, Span read_handles, Span write_handles, Span exception_handles, s64 tv_sec, s64 tv_usec); Result EndSelect(s32 *out_err, bool *out_empty, Span read_handles, Span write_handles, Span exception_handles, u32 task_id); }; diff --git a/libraries/libstratosphere/source/htcs/impl/htcs_service.cpp b/libraries/libstratosphere/source/htcs/impl/htcs_service.cpp index d5614e9cf..3a00947b4 100644 --- a/libraries/libstratosphere/source/htcs/impl/htcs_service.cpp +++ b/libraries/libstratosphere/source/htcs/impl/htcs_service.cpp @@ -196,7 +196,7 @@ namespace ams::htcs::impl { return ResultSuccess(); } - Result HtcsService::AcceptStart(u32 *out_task_id, Handle *out_handle, s32 desc) { + Result HtcsService::AcceptStart(u32 *out_task_id, os::NativeHandle *out_handle, s32 desc) { /* Begin the task. */ u32 task_id; R_TRY(m_rpc_client->Begin(std::addressof(task_id), desc)); @@ -220,7 +220,7 @@ namespace ams::htcs::impl { return ResultSuccess(); } - Result HtcsService::ReceiveSmallStart(u32 *out_task_id, Handle *out_handle, s64 size, s32 desc, s32 flags) { + Result HtcsService::ReceiveSmallStart(u32 *out_task_id, os::NativeHandle *out_handle, s64 size, s32 desc, s32 flags) { /* Begin the task. */ u32 task_id; R_TRY(m_rpc_client->Begin(std::addressof(task_id), desc, size, static_cast(flags))); @@ -245,7 +245,7 @@ namespace ams::htcs::impl { return ResultSuccess(); } - Result HtcsService::SendSmallStart(u32 *out_task_id, Handle *out_handle, s32 desc, s64 size, s32 flags) { + Result HtcsService::SendSmallStart(u32 *out_task_id, os::NativeHandle *out_handle, s32 desc, s64 size, s32 flags) { /* Begin the task. */ u32 task_id; R_TRY(m_rpc_client->Begin(std::addressof(task_id), desc, size, static_cast(flags))); @@ -279,7 +279,7 @@ namespace ams::htcs::impl { return ResultSuccess(); } - Result HtcsService::SendStart(u32 *out_task_id, Handle *out_handle, s32 desc, s64 size, s32 flags) { + Result HtcsService::SendStart(u32 *out_task_id, os::NativeHandle *out_handle, s32 desc, s64 size, s32 flags) { /* Begin the task. */ u32 task_id; R_TRY(m_rpc_client->Begin(std::addressof(task_id), desc, size, static_cast(flags))); @@ -325,7 +325,7 @@ namespace ams::htcs::impl { return ResultSuccess(); } - Result HtcsService::ReceiveStart(u32 *out_task_id, Handle *out_handle, s64 size, s32 desc, s32 flags) { + Result HtcsService::ReceiveStart(u32 *out_task_id, os::NativeHandle *out_handle, s64 size, s32 desc, s32 flags) { /* Begin the task. */ u32 task_id; R_TRY(m_rpc_client->Begin(std::addressof(task_id), desc, size, static_cast(flags))); @@ -377,7 +377,7 @@ namespace ams::htcs::impl { return ResultSuccess(); } - Result HtcsService::SelectStart(u32 *out_task_id, Handle *out_handle, Span read_handles, Span write_handles, Span exception_handles, s64 tv_sec, s64 tv_usec) { + Result HtcsService::SelectStart(u32 *out_task_id, os::NativeHandle *out_handle, Span read_handles, Span write_handles, Span exception_handles, s64 tv_sec, s64 tv_usec) { /* Begin the task. */ u32 task_id; R_TRY(m_rpc_client->Begin(std::addressof(task_id), read_handles, write_handles, exception_handles, tv_sec, tv_usec)); diff --git a/libraries/libstratosphere/source/htcs/impl/htcs_service.hpp b/libraries/libstratosphere/source/htcs/impl/htcs_service.hpp index d379c3dc4..bb7700fa7 100644 --- a/libraries/libstratosphere/source/htcs/impl/htcs_service.hpp +++ b/libraries/libstratosphere/source/htcs/impl/htcs_service.hpp @@ -41,24 +41,24 @@ namespace ams::htcs::impl { Result Shutdown(s32 *out_err, s32 desc, s32 how); Result Fcntl(s32 *out_err, s32 *out_res, s32 desc, s32 command, s32 value); - Result AcceptStart(u32 *out_task_id, Handle *out_handle, s32 desc); + Result AcceptStart(u32 *out_task_id, os::NativeHandle *out_handle, s32 desc); Result AcceptResults(s32 *out_err, s32 *out_desc, SockAddrHtcs *out_address, u32 task_id, s32 desc); - Result ReceiveSmallStart(u32 *out_task_id, Handle *out_handle, s64 size, s32 desc, s32 flags); + Result ReceiveSmallStart(u32 *out_task_id, os::NativeHandle *out_handle, s64 size, s32 desc, s32 flags); Result ReceiveSmallResults(s32 *out_err, s64 *out_size, char *buffer, s64 buffer_size, u32 task_id, s32 desc); - Result SendSmallStart(u32 *out_task_id, Handle *out_handle, s32 desc, s64 size, s32 flags); + Result SendSmallStart(u32 *out_task_id, os::NativeHandle *out_handle, s32 desc, s64 size, s32 flags); Result SendSmallContinue(s64 *out_size, const char *buffer, s64 buffer_size, u32 task_id, s32 desc); Result SendSmallResults(s32 *out_err, s64 *out_size, u32 task_id, s32 desc); - Result SendStart(u32 *out_task_id, Handle *out_handle, s32 desc, s64 size, s32 flags); + Result SendStart(u32 *out_task_id, os::NativeHandle *out_handle, s32 desc, s64 size, s32 flags); Result SendContinue(s64 *out_size, const char *buffer, s64 buffer_size, u32 task_id, s32 desc); Result SendResults(s32 *out_err, s64 *out_size, u32 task_id, s32 desc); - Result ReceiveStart(u32 *out_task_id, Handle *out_handle, s64 size, s32 desc, s32 flags); + Result ReceiveStart(u32 *out_task_id, os::NativeHandle *out_handle, s64 size, s32 desc, s32 flags); Result ReceiveResults(s32 *out_err, s64 *out_size, char *buffer, s64 buffer_size, u32 task_id, s32 desc); - Result SelectStart(u32 *out_task_id, Handle *out_handle, Span read_handles, Span write_handles, Span exception_handles, s64 tv_sec, s64 tv_usec); + Result SelectStart(u32 *out_task_id, os::NativeHandle *out_handle, Span read_handles, Span write_handles, Span exception_handles, s64 tv_sec, s64 tv_usec); Result SelectEnd(s32 *out_err, bool *out_empty, Span read_handles, Span write_handles, Span exception_handles, u32 task_id); private: void WaitTask(u32 task_id); diff --git a/libraries/libstratosphere/source/ldr/ldr_pm_api.cpp b/libraries/libstratosphere/source/ldr/ldr_pm_api.cpp index 6b5af5c2f..1a4856e4c 100644 --- a/libraries/libstratosphere/source/ldr/ldr_pm_api.cpp +++ b/libraries/libstratosphere/source/ldr/ldr_pm_api.cpp @@ -19,7 +19,7 @@ namespace ams::ldr::pm { /* Information API. */ - Result CreateProcess(Handle *out, PinId pin_id, u32 flags, Handle reslimit) { + Result CreateProcess(os::NativeHandle *out, PinId pin_id, u32 flags, Handle reslimit) { return ldrPmCreateProcess(pin_id.value, flags, reslimit, out); } diff --git a/libraries/libstratosphere/source/osdbg/osdbg_thread.cpp b/libraries/libstratosphere/source/osdbg/osdbg_thread.cpp index 18eb7b285..6eb28015e 100644 --- a/libraries/libstratosphere/source/osdbg/osdbg_thread.cpp +++ b/libraries/libstratosphere/source/osdbg/osdbg_thread.cpp @@ -23,7 +23,7 @@ namespace ams::osdbg { - Result InitializeThreadInfo(ThreadInfo *thread_info, svc::Handle debug_handle, const svc::DebugInfoCreateProcess *create_process, const svc::DebugInfoCreateThread *create_thread) { + Result InitializeThreadInfo(ThreadInfo *thread_info, os::NativeHandle debug_handle, const svc::DebugInfoCreateProcess *create_process, const svc::DebugInfoCreateThread *create_thread) { /* Set basic fields. */ thread_info->_thread_type = nullptr; thread_info->_thread_type_type = ThreadTypeType_Unknown; diff --git a/libraries/libstratosphere/source/pgl/srv/pgl_srv_api.cpp b/libraries/libstratosphere/source/pgl/srv/pgl_srv_api.cpp index 4fdbf3ce9..d4dc7461e 100644 --- a/libraries/libstratosphere/source/pgl/srv/pgl_srv_api.cpp +++ b/libraries/libstratosphere/source/pgl/srv/pgl_srv_api.cpp @@ -172,7 +172,7 @@ namespace ams::pgl::srv { LoopProcessServer(); } - Result AllocateShellEventObserverForTipc(svc::Handle *out) { + Result AllocateShellEventObserverForTipc(os::NativeHandle *out) { /* Get the shell event observer allocator. */ auto &allocator = GetGlobalsForTipc().observer_allocator; diff --git a/libraries/libstratosphere/source/pgl/srv/pgl_srv_tipc_utils.hpp b/libraries/libstratosphere/source/pgl/srv/pgl_srv_tipc_utils.hpp index 581573eaa..c4ec6fc83 100644 --- a/libraries/libstratosphere/source/pgl/srv/pgl_srv_tipc_utils.hpp +++ b/libraries/libstratosphere/source/pgl/srv/pgl_srv_tipc_utils.hpp @@ -18,6 +18,6 @@ namespace ams::pgl::srv { - Result AllocateShellEventObserverForTipc(svc::Handle *out); + Result AllocateShellEventObserverForTipc(os::NativeHandle *out); } diff --git a/libraries/libstratosphere/source/sf/hipc/sf_hipc_mitm_query_api.cpp b/libraries/libstratosphere/source/sf/hipc/sf_hipc_mitm_query_api.cpp index bc4c53735..d5a829cb1 100644 --- a/libraries/libstratosphere/source/sf/hipc/sf_hipc_mitm_query_api.cpp +++ b/libraries/libstratosphere/source/sf/hipc/sf_hipc_mitm_query_api.cpp @@ -54,7 +54,7 @@ namespace ams::sf::hipc::impl { } - void RegisterMitmQueryHandle(Handle query_handle, ServerManagerBase::MitmQueryFunction query_func) { + void RegisterMitmQueryHandle(os::NativeHandle query_handle, ServerManagerBase::MitmQueryFunction query_func) { std::scoped_lock lk(g_query_server_lock); if (AMS_UNLIKELY(!g_constructed_server)) { diff --git a/libraries/libstratosphere/source/sf/hipc/sf_hipc_mitm_query_api.hpp b/libraries/libstratosphere/source/sf/hipc/sf_hipc_mitm_query_api.hpp index af041c6c1..0cd1518d4 100644 --- a/libraries/libstratosphere/source/sf/hipc/sf_hipc_mitm_query_api.hpp +++ b/libraries/libstratosphere/source/sf/hipc/sf_hipc_mitm_query_api.hpp @@ -18,6 +18,6 @@ namespace ams::sf::hipc::impl { - void RegisterMitmQueryHandle(Handle query_handle, ServerManagerBase::MitmQueryFunction query_func); + void RegisterMitmQueryHandle(os::NativeHandle query_handle, ServerManagerBase::MitmQueryFunction query_func); } diff --git a/libraries/libstratosphere/source/sf/hipc/sf_hipc_server_domain_session_manager.cpp b/libraries/libstratosphere/source/sf/hipc/sf_hipc_server_domain_session_manager.cpp index bb75e8a67..01086e150 100644 --- a/libraries/libstratosphere/source/sf/hipc/sf_hipc_server_domain_session_manager.cpp +++ b/libraries/libstratosphere/source/sf/hipc/sf_hipc_server_domain_session_manager.cpp @@ -34,13 +34,13 @@ namespace ams::sf::hipc { ServerSession *session; bool is_mitm_session; private: - Result CloneCurrentObjectImpl(Handle *out_client_handle, ServerSessionManager *tagged_manager) { + Result CloneCurrentObjectImpl(os::NativeHandle *out_client_handle, ServerSessionManager *tagged_manager) { /* Clone the object. */ cmif::ServiceObjectHolder &&clone = this->session->srv_obj_holder.Clone(); R_UNLESS(clone, sf::hipc::ResultDomainObjectNotFound()); /* Create new session handles. */ - Handle server_handle; + os::NativeHandle server_handle; R_ABORT_UNLESS(hipc::CreateSession(&server_handle, out_client_handle)); /* Register with manager. */ @@ -118,18 +118,18 @@ namespace ams::sf::hipc { if (!this->is_mitm_session || object_id.value != serviceGetObjectId(this->session->forward_service.get())) { /* Create new session handles. */ - Handle server_handle; + os::NativeHandle server_handle; R_ABORT_UNLESS(hipc::CreateSession(&server_handle, out.GetHandlePointer())); /* Register. */ R_ABORT_UNLESS(this->manager->RegisterSession(server_handle, std::move(object))); } else { /* Copy from the target domain. */ - Handle new_forward_target; + os::NativeHandle new_forward_target; R_TRY(cmifCopyFromCurrentDomain(this->session->forward_service->session, object_id.value, &new_forward_target)); /* Create new session handles. */ - Handle server_handle; + os::NativeHandle server_handle; R_ABORT_UNLESS(hipc::CreateSession(&server_handle, out.GetHandlePointer())); /* Register. */ diff --git a/libraries/libstratosphere/source/sf/hipc/sf_hipc_server_manager.cpp b/libraries/libstratosphere/source/sf/hipc/sf_hipc_server_manager.cpp index a8827c632..f5823ba5a 100644 --- a/libraries/libstratosphere/source/sf/hipc/sf_hipc_server_manager.cpp +++ b/libraries/libstratosphere/source/sf/hipc/sf_hipc_server_manager.cpp @@ -18,9 +18,9 @@ namespace ams::sf::hipc { - Result ServerManagerBase::InstallMitmServerImpl(Handle *out_port_handle, sm::ServiceName service_name, ServerManagerBase::MitmQueryFunction query_func) { + Result ServerManagerBase::InstallMitmServerImpl(os::NativeHandle *out_port_handle, sm::ServiceName service_name, ServerManagerBase::MitmQueryFunction query_func) { /* Install the Mitm. */ - Handle query_handle; + os::NativeHandle query_handle; R_TRY(sm::mitm::InstallMitm(out_port_handle, &query_handle, service_name)); /* Register the query handle. */ diff --git a/libraries/libstratosphere/source/sm/sm_api.cpp b/libraries/libstratosphere/source/sm/sm_api.cpp index 4c46bb210..bd3b66f29 100644 --- a/libraries/libstratosphere/source/sm/sm_api.cpp +++ b/libraries/libstratosphere/source/sm/sm_api.cpp @@ -49,7 +49,7 @@ namespace ams::sm { return smGetServiceWrapper(out, impl::ConvertName(name)); } - Result RegisterService(Handle *out, ServiceName name, size_t max_sessions, bool is_light) { + Result RegisterService(os::NativeHandle *out, ServiceName name, size_t max_sessions, bool is_light) { return smRegisterService(out, impl::ConvertName(name), is_light, static_cast(max_sessions)); } diff --git a/libraries/libstratosphere/source/sm/sm_mitm_api.cpp b/libraries/libstratosphere/source/sm/sm_mitm_api.cpp index 34c56abef..82e392f1d 100644 --- a/libraries/libstratosphere/source/sm/sm_mitm_api.cpp +++ b/libraries/libstratosphere/source/sm/sm_mitm_api.cpp @@ -19,7 +19,7 @@ namespace ams::sm::mitm { /* Mitm API. */ - Result InstallMitm(Handle *out_port, Handle *out_query, ServiceName name) { + Result InstallMitm(os::NativeHandle *out_port, os::NativeHandle *out_query, ServiceName name) { return impl::DoWithPerThreadSession([&](TipcService *fwd) { return smAtmosphereMitmInstall(fwd, out_port, out_query, impl::ConvertName(name)); }); diff --git a/libraries/libstratosphere/source/spl/spl_api.cpp b/libraries/libstratosphere/source/spl/spl_api.cpp index 2db30a038..8528eeed9 100644 --- a/libraries/libstratosphere/source/spl/spl_api.cpp +++ b/libraries/libstratosphere/source/spl/spl_api.cpp @@ -41,7 +41,7 @@ namespace ams::spl { return serviceDispatchIn(splCryptoGetServiceSession(), 22, slot); } - Result GetAesKeySlotAvailableEventImpl(Handle *out) { + Result GetAesKeySlotAvailableEventImpl(os::NativeHandle *out) { return serviceDispatch(splCryptoGetServiceSession(), 23, .out_handle_attrs = { SfOutHandleAttr_HipcCopy }, .out_handles = out, @@ -49,8 +49,8 @@ namespace ams::spl { } void GetAesKeySlotAvailableEvent(os::SystemEvent *out) { - /* Get libnx event. */ - Handle handle = svc::InvalidHandle; + /* Get event handle. */ + os::NativeHandle handle; R_ABORT_UNLESS(GetAesKeySlotAvailableEventImpl(std::addressof(handle))); /* Attach to event. */ diff --git a/libraries/libvapours/include/vapours/svc/svc_common.hpp b/libraries/libvapours/include/vapours/svc/svc_common.hpp index 832fbb35b..0227e9bfc 100644 --- a/libraries/libvapours/include/vapours/svc/svc_common.hpp +++ b/libraries/libvapours/include/vapours/svc/svc_common.hpp @@ -22,10 +22,9 @@ namespace ams::svc { /* TODO: C++ style handle? */ -#ifdef ATMOSPHERE_IS_STRATOSPHERE - using Handle = ::Handle; -#else using Handle = u32; +#if defined(ATMOSPHERE_IS_STRATOSPHERE) + static_assert(std::same_as<::ams::svc::Handle, ::Handle>); #endif enum { diff --git a/stratosphere/dmnt.gen2/source/dmnt2_debug_process.hpp b/stratosphere/dmnt.gen2/source/dmnt2_debug_process.hpp index 86066f59d..d991420b0 100644 --- a/stratosphere/dmnt.gen2/source/dmnt2_debug_process.hpp +++ b/stratosphere/dmnt.gen2/source/dmnt2_debug_process.hpp @@ -40,7 +40,7 @@ namespace ams::dmnt { ContinueMode_Step, }; private: - svc::Handle m_debug_handle{svc::InvalidHandle}; + os::NativeHandle m_debug_handle{os::InvalidNativeHandle}; s32 m_thread_count{0}; bool m_is_valid{false}; bool m_is_64_bit{false}; @@ -73,7 +73,7 @@ namespace ams::dmnt { } ~DebugProcess() { this->Detach(); } - svc::Handle GetHandle() const { return m_debug_handle; } + os::NativeHandle GetHandle() const { return m_debug_handle; } bool IsValid() const { return m_is_valid; } bool Is64Bit() const { return m_is_64_bit; } bool Is64BitAddressSpace() const { return m_is_64_bit_address_space; } diff --git a/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_api.cpp b/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_api.cpp index 34c2bcc53..367bcc64c 100644 --- a/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_api.cpp +++ b/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_api.cpp @@ -88,7 +88,7 @@ namespace ams::dmnt::cheat::impl { os::Event debug_events_event; /* Autoclear. */ os::ThreadType detect_thread, debug_events_thread; os::SystemEvent cheat_process_event; - Handle cheat_process_debug_handle = svc::InvalidHandle; + os::NativeHandle cheat_process_debug_handle = os::InvalidNativeHandle; CheatProcessMetadata cheat_process_metadata = {}; os::ThreadType vm_thread; @@ -175,7 +175,7 @@ namespace ams::dmnt::cheat::impl { } void CloseActiveCheatProcess() { - if (this->cheat_process_debug_handle != svc::InvalidHandle) { + if (this->cheat_process_debug_handle != os::InvalidNativeHandle) { /* We don't need to do any unsafe brekaing. */ this->broken_unsafe = false; this->unsafe_break_event.Signal(); @@ -185,7 +185,7 @@ namespace ams::dmnt::cheat::impl { /* Close resources. */ R_ABORT_UNLESS(svc::CloseHandle(this->cheat_process_debug_handle)); - this->cheat_process_debug_handle = svc::InvalidHandle; + this->cheat_process_debug_handle = os::InvalidNativeHandle; /* Save cheat toggles. */ if (this->always_save_cheat_toggles || this->should_save_cheat_toggles) { @@ -218,7 +218,7 @@ namespace ams::dmnt::cheat::impl { bool HasActiveCheatProcess() { /* Note: This function *MUST* be called only with the cheat lock held. */ os::ProcessId pid; - bool has_cheat_process = this->cheat_process_debug_handle != svc::InvalidHandle; + bool has_cheat_process = this->cheat_process_debug_handle != os::InvalidNativeHandle; has_cheat_process &= R_SUCCEEDED(os::GetProcessId(&pid, this->cheat_process_debug_handle)); has_cheat_process &= R_SUCCEEDED(pm::dmnt::GetApplicationProcessId(&pid)); has_cheat_process &= (pid == this->cheat_process_metadata.process_id); @@ -235,12 +235,12 @@ namespace ams::dmnt::cheat::impl { return ResultSuccess(); } - Handle GetCheatProcessHandle() const { + os::NativeHandle GetCheatProcessHandle() const { return this->cheat_process_debug_handle; } - Handle HookToCreateApplicationProcess() const { - Handle h = svc::InvalidHandle; + os::NativeHandle HookToCreateApplicationProcess() const { + os::NativeHandle h; R_ABORT_UNLESS(pm::dmnt::HookToCreateApplicationProcess(&h)); return h; } @@ -284,7 +284,7 @@ namespace ams::dmnt::cheat::impl { return this->HasActiveCheatProcess(); } - Handle GetCheatProcessEventHandle() const { + os::NativeHandle GetCheatProcessEventHandle() const { return this->cheat_process_event.GetReadableHandle(); } @@ -704,7 +704,7 @@ namespace ams::dmnt::cheat::impl { this_ptr->cheat_lock.Unlock(); this_ptr->unsafe_break_event.Wait(); this_ptr->cheat_lock.Lock(); - if (this_ptr->GetCheatProcessHandle() != svc::InvalidHandle) { + if (this_ptr->GetCheatProcessHandle() != os::InvalidNativeHandle) { continue; } else { break; @@ -1193,7 +1193,7 @@ namespace ams::dmnt::cheat::impl { return GetReference(g_cheat_process_manager).GetHasActiveCheatProcess(); } - Handle GetCheatProcessEventHandle() { + os::NativeHandle GetCheatProcessEventHandle() { return GetReference(g_cheat_process_manager).GetCheatProcessEventHandle(); } diff --git a/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_api.hpp b/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_api.hpp index 3dfc3e1b7..663cef4ea 100644 --- a/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_api.hpp +++ b/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_api.hpp @@ -21,7 +21,7 @@ namespace ams::dmnt::cheat::impl { void InitializeCheatManager(); bool GetHasActiveCheatProcess(); - Handle GetCheatProcessEventHandle(); + os::NativeHandle GetCheatProcessEventHandle(); Result GetCheatProcessMetadata(CheatProcessMetadata *out); Result ForceOpenCheatProcess(); Result PauseCheatProcess(); diff --git a/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_debug_events_manager.cpp b/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_debug_events_manager.cpp index b724601d6..0493fcb1e 100644 --- a/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_debug_events_manager.cpp +++ b/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_debug_events_manager.cpp @@ -126,7 +126,7 @@ namespace ams::dmnt::cheat::impl { } } - Result ContinueCheatProcess(Handle cheat_dbg_hnd) { + Result ContinueCheatProcess(os::NativeHandle cheat_dbg_hnd) { /* Loop getting all debug events. */ svc::DebugEventInfo d; size_t target_core = NumCores - 1; @@ -151,7 +151,7 @@ namespace ams::dmnt::cheat::impl { util::ConstructAt(g_events_manager); } - Result ContinueCheatProcess(Handle cheat_dbg_hnd) { + Result ContinueCheatProcess(os::NativeHandle cheat_dbg_hnd) { return GetReference(g_events_manager).ContinueCheatProcess(cheat_dbg_hnd); } diff --git a/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_debug_events_manager.hpp b/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_debug_events_manager.hpp index d8378072d..58fc90ca4 100644 --- a/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_debug_events_manager.hpp +++ b/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_debug_events_manager.hpp @@ -20,6 +20,6 @@ namespace ams::dmnt::cheat::impl { void InitializeDebugEventsManager(); - Result ContinueCheatProcess(Handle cheat_dbg_hnd); + Result ContinueCheatProcess(os::NativeHandle cheat_dbg_hnd); } diff --git a/stratosphere/fatal/source/fatal_config.cpp b/stratosphere/fatal/source/fatal_config.cpp index f40e22e8b..c07b84ec4 100644 --- a/stratosphere/fatal/source/fatal_config.cpp +++ b/stratosphere/fatal/source/fatal_config.cpp @@ -24,7 +24,7 @@ namespace ams::fatal::srv { FatalConfig g_config; /* Event creator. */ - Handle GetFatalDirtyEventReadableHandle() { + os::NativeHandle GetFatalDirtyEventReadableHandle() { Event evt; R_ABORT_UNLESS(setsysAcquireFatalDirtyFlagEventHandle(&evt)); return evt.revent; diff --git a/stratosphere/pm/source/impl/pm_resource_manager.cpp b/stratosphere/pm/source/impl/pm_resource_manager.cpp index 095560e1e..7b9794eac 100644 --- a/stratosphere/pm/source/impl/pm_resource_manager.cpp +++ b/stratosphere/pm/source/impl/pm_resource_manager.cpp @@ -37,7 +37,7 @@ namespace ams::pm::resource { /* Globals. */ constinit os::SdkMutex g_resource_limit_lock; - constinit Handle g_resource_limit_handles[ResourceLimitGroup_Count]; + constinit os::NativeHandle g_resource_limit_handles[ResourceLimitGroup_Count]; constinit spl::MemoryArrangement g_memory_arrangement = spl::MemoryArrangement_Standard; constinit u64 g_system_memory_boost_size = 0; constinit u64 g_extra_application_threads_available = 0; @@ -136,7 +136,7 @@ namespace ams::pm::resource { } void WaitResourceAvailable(ResourceLimitGroup group) { - const Handle reslimit_hnd = GetResourceLimitHandle(group); + const auto reslimit_hnd = GetResourceLimitHandle(group); for (size_t i = 0; i < svc::LimitableResource_Count; i++) { const auto resource = LimitableResources[i]; @@ -336,11 +336,11 @@ namespace ams::pm::resource { return ResultSuccess(); } - Handle GetResourceLimitHandle(ResourceLimitGroup group) { + os::NativeHandle GetResourceLimitHandle(ResourceLimitGroup group) { return g_resource_limit_handles[group]; } - Handle GetResourceLimitHandle(const ldr::ProgramInfo *info) { + os::NativeHandle GetResourceLimitHandle(const ldr::ProgramInfo *info) { return GetResourceLimitHandle(GetResourceLimitGroup(info)); } @@ -358,7 +358,7 @@ namespace ams::pm::resource { AMS_ABORT_UNLESS(group < ResourceLimitGroup_Count); AMS_ABORT_UNLESS(resource < svc::LimitableResource_Count); - const Handle reslimit_hnd = GetResourceLimitHandle(group); + const auto reslimit_hnd = GetResourceLimitHandle(group); R_TRY(svc::GetResourceLimitCurrentValue(out_cur, reslimit_hnd, resource)); R_TRY(svc::GetResourceLimitLimitValue(out_lim, reslimit_hnd, resource)); diff --git a/stratosphere/pm/source/impl/pm_resource_manager.hpp b/stratosphere/pm/source/impl/pm_resource_manager.hpp index d5527e2cd..d9bef4d5d 100644 --- a/stratosphere/pm/source/impl/pm_resource_manager.hpp +++ b/stratosphere/pm/source/impl/pm_resource_manager.hpp @@ -22,9 +22,11 @@ namespace ams::pm::resource { Result InitializeResourceManager(); Result BoostSystemMemoryResourceLimit(u64 boost_size); Result BoostApplicationThreadResourceLimit(); - Handle GetResourceLimitHandle(ResourceLimitGroup group); - Handle GetResourceLimitHandle(const ldr::ProgramInfo *info); - void WaitResourceAvailable(const ldr::ProgramInfo *info); + + os::NativeHandle GetResourceLimitHandle(ResourceLimitGroup group); + os::NativeHandle GetResourceLimitHandle(const ldr::ProgramInfo *info); + + void WaitResourceAvailable(const ldr::ProgramInfo *info); Result GetResourceLimitValues(s64 *out_cur, s64 *out_lim, ResourceLimitGroup group, svc::LimitableResource resource); diff --git a/stratosphere/pm/source/pm_info_service.cpp b/stratosphere/pm/source/pm_info_service.cpp index 49ec655b2..b342768e6 100644 --- a/stratosphere/pm/source/pm_info_service.cpp +++ b/stratosphere/pm/source/pm_info_service.cpp @@ -43,7 +43,8 @@ namespace ams::pm { } Result InformationService::AtmosphereGetProcessInfo(sf::Out out_loc, sf::Out out_status, os::ProcessId process_id) { - Handle dummy_handle; + /* NOTE: We don't need to worry about closing this handle, because it's an in-process copy, not a newly allocated handle. */ + os::NativeHandle dummy_handle; return impl::AtmosphereGetProcessInfo(&dummy_handle, out_loc.GetPointer(), out_status.GetPointer(), process_id); } diff --git a/stratosphere/sm/source/impl/sm_service_manager.cpp b/stratosphere/sm/source/impl/sm_service_manager.cpp index e51d1603f..5e088f8c5 100644 --- a/stratosphere/sm/source/impl/sm_service_manager.cpp +++ b/stratosphere/sm/source/impl/sm_service_manager.cpp @@ -53,10 +53,10 @@ namespace ams::sm::impl { os::ProcessId owner_process_id; os::ProcessId mitm_process_id; os::ProcessId mitm_waiting_ack_process_id; - svc::Handle mitm_port_h; - svc::Handle mitm_query_h; - svc::Handle port_h; - svc::Handle mitm_fwd_sess_h; + os::NativeHandle mitm_port_h; + os::NativeHandle mitm_query_h; + os::NativeHandle port_h; + os::NativeHandle mitm_fwd_sess_h; s32 max_sessions; bool is_light; bool mitm_waiting_ack; @@ -67,10 +67,10 @@ namespace ams::sm::impl { .owner_process_id = os::InvalidProcessId, .mitm_process_id = os::InvalidProcessId, .mitm_waiting_ack_process_id = os::InvalidProcessId, - .mitm_port_h = svc::InvalidHandle, - .mitm_query_h = svc::InvalidHandle, - .port_h = svc::InvalidHandle, - .mitm_fwd_sess_h = svc::InvalidHandle, + .mitm_port_h = os::InvalidNativeHandle, + .mitm_query_h = os::InvalidNativeHandle, + .port_h = os::InvalidNativeHandle, + .mitm_fwd_sess_h = os::InvalidNativeHandle, .max_sessions = 0, .is_light = false, .mitm_waiting_ack = false, @@ -361,7 +361,7 @@ namespace ams::sm::impl { program_id == ncm::SystemProgramId::Creport; } - Result GetMitmServiceHandleImpl(svc::Handle *out, ServiceInfo *service_info, const MitmProcessInfo &client_info) { + Result GetMitmServiceHandleImpl(os::NativeHandle *out, ServiceInfo *service_info, const MitmProcessInfo &client_info) { /* Send command to query if we should mitm. */ bool should_mitm; { @@ -376,15 +376,15 @@ namespace ams::sm::impl { /* Create both handles. */ { /* Get the forward handle. */ - svc::Handle fwd_hnd; + os::NativeHandle fwd_hnd; R_TRY(svc::ConnectToPort(std::addressof(fwd_hnd), service_info->port_h)); /* Ensure that the forward handle is closed, if we fail to get the mitm handle. */ - auto fwd_guard = SCOPE_GUARD { R_ABORT_UNLESS(svc::CloseHandle(fwd_hnd)); }; + auto fwd_guard = SCOPE_GUARD { os::CloseNativeHandle(fwd_hnd); }; /* Get the mitm handle. */ /* This should be guaranteed to succeed, since we got a forward handle. */ - svc::Handle hnd; + os::NativeHandle hnd; R_ABORT_UNLESS(svc::ConnectToPort(std::addressof(hnd), service_info->mitm_port_h)); /* We got both handles, so we no longer need to clean up the forward handle. */ @@ -401,9 +401,9 @@ namespace ams::sm::impl { return ResultSuccess(); } - Result GetServiceHandleImpl(svc::Handle *out, ServiceInfo *service_info, os::ProcessId process_id) { + Result GetServiceHandleImpl(os::NativeHandle *out, ServiceInfo *service_info, os::ProcessId process_id) { /* Clear handle output. */ - *out = svc::InvalidHandle; + *out = os::InvalidNativeHandle; /* Check if we should return a mitm handle. */ if (IsValidProcessId(service_info->mitm_process_id) && service_info->mitm_process_id != process_id) { @@ -420,7 +420,7 @@ namespace ams::sm::impl { return svc::ConnectToPort(out, service_info->port_h); } - Result RegisterServiceImpl(svc::Handle *out, os::ProcessId process_id, ServiceName service, size_t max_sessions, bool is_light) { + Result RegisterServiceImpl(os::NativeHandle *out, os::ProcessId process_id, ServiceName service, size_t max_sessions, bool is_light) { /* Validate service name. */ R_TRY(ValidateServiceName(service)); @@ -432,8 +432,8 @@ namespace ams::sm::impl { R_UNLESS(free_service != nullptr, sm::ResultOutOfServices()); /* Create the new service. */ - *out = svc::InvalidHandle; - svc::Handle server_hnd = svc::InvalidHandle; + *out = os::InvalidNativeHandle; + os::NativeHandle server_hnd = os::InvalidNativeHandle; R_TRY(svc::CreatePort(out, std::addressof(server_hnd), max_sessions, is_light, reinterpret_cast(free_service->name.name))); /* Save info. */ @@ -451,10 +451,10 @@ namespace ams::sm::impl { void UnregisterServiceImpl(ServiceInfo *service_info) { /* Close all valid handles. */ - if (service_info->port_h != svc::InvalidHandle) { R_ABORT_UNLESS(svc::CloseHandle(service_info->port_h)); } - if (service_info->mitm_port_h != svc::InvalidHandle) { R_ABORT_UNLESS(svc::CloseHandle(service_info->mitm_port_h)); } - if (service_info->mitm_query_h != svc::InvalidHandle) { R_ABORT_UNLESS(svc::CloseHandle(service_info->mitm_query_h)); } - if (service_info->mitm_fwd_sess_h != svc::InvalidHandle) { R_ABORT_UNLESS(svc::CloseHandle(service_info->mitm_fwd_sess_h)); } + os::CloseNativeHandle(service_info->port_h); + os::CloseNativeHandle(service_info->mitm_port_h); + os::CloseNativeHandle(service_info->mitm_query_h); + os::CloseNativeHandle(service_info->mitm_fwd_sess_h); /* Reset the info's state. */ *service_info = InvalidServiceInfo; @@ -547,7 +547,7 @@ namespace ams::sm::impl { return StartRegisterRetry(service); } - Result GetServiceHandle(svc::Handle *out, os::ProcessId process_id, ServiceName service) { + Result GetServiceHandle(os::NativeHandle *out, os::ProcessId process_id, ServiceName service) { /* Acquire exclusive access to global state. */ std::scoped_lock lk(g_mutex); @@ -583,7 +583,7 @@ namespace ams::sm::impl { return ResultSuccess(); } - Result RegisterService(svc::Handle *out, os::ProcessId process_id, ServiceName service, size_t max_sessions, bool is_light) { + Result RegisterService(os::NativeHandle *out, os::ProcessId process_id, ServiceName service, size_t max_sessions, bool is_light) { /* Acquire exclusive access to global state. */ std::scoped_lock lk(g_mutex); @@ -604,7 +604,7 @@ namespace ams::sm::impl { return RegisterServiceImpl(out, process_id, service, max_sessions, is_light); } - Result RegisterServiceForSelf(svc::Handle *out, ServiceName service, size_t max_sessions) { + Result RegisterServiceForSelf(os::NativeHandle *out, ServiceName service, size_t max_sessions) { /* Acquire exclusive access to global state. */ std::scoped_lock lk(g_mutex); @@ -665,7 +665,7 @@ namespace ams::sm::impl { return StartRegisterRetry(service); } - Result InstallMitm(svc::Handle *out, svc::Handle *out_query, os::ProcessId process_id, ServiceName service) { + Result InstallMitm(os::NativeHandle *out, os::NativeHandle *out_query, os::ProcessId process_id, ServiceName service) { /* Acquire exclusive access to global state. */ std::scoped_lock lk(g_mutex); @@ -689,8 +689,8 @@ namespace ams::sm::impl { R_UNLESS(!IsValidProcessId(service_info->mitm_process_id), sm::ResultAlreadyRegistered()); /* Always clear output. */ - *out = svc::InvalidHandle; - *out_query = svc::InvalidHandle; + *out = os::InvalidNativeHandle; + *out_query = os::InvalidNativeHandle; /* If we don't have a future mitm declaration, add one. */ /* Client will clear this when ready to process. */ @@ -704,14 +704,14 @@ namespace ams::sm::impl { /* Create mitm handles. */ { /* Get the port handles. */ - svc::Handle hnd, port_hnd; + os::NativeHandle hnd, port_hnd; R_TRY(svc::CreatePort(std::addressof(hnd), std::addressof(port_hnd), service_info->max_sessions, service_info->is_light, reinterpret_cast(service_info->name.name))); /* Ensure that we clean up the port handles, if something goes wrong creating the query sessions. */ - auto port_guard = SCOPE_GUARD { R_ABORT_UNLESS(svc::CloseHandle(hnd)); R_ABORT_UNLESS(svc::CloseHandle(port_hnd)); }; + auto port_guard = SCOPE_GUARD { os::CloseNativeHandle(hnd); os::CloseNativeHandle(port_hnd); }; /* Create the session for our query service. */ - svc::Handle qry_hnd, mitm_qry_hnd; + os::NativeHandle qry_hnd, mitm_qry_hnd; R_TRY(svc::CreateSession(std::addressof(qry_hnd), std::addressof(mitm_qry_hnd), false, 0)); /* We created the query service session, so we no longer need to clean up the port handles. */ @@ -755,12 +755,12 @@ namespace ams::sm::impl { /* Uninstall the mitm. */ { /* Close mitm handles. */ - R_ABORT_UNLESS(svc::CloseHandle(service_info->mitm_port_h)); - R_ABORT_UNLESS(svc::CloseHandle(service_info->mitm_query_h)); + os::CloseNativeHandle(service_info->mitm_port_h); + os::CloseNativeHandle(service_info->mitm_query_h); /* Reset mitm members. */ - service_info->mitm_port_h = svc::InvalidHandle; - service_info->mitm_query_h = svc::InvalidHandle; + service_info->mitm_port_h = os::InvalidNativeHandle; + service_info->mitm_query_h = os::InvalidNativeHandle; service_info->mitm_process_id = os::InvalidProcessId; } @@ -824,7 +824,7 @@ namespace ams::sm::impl { return ResultSuccess(); } - Result AcknowledgeMitmSession(MitmProcessInfo *out_info, svc::Handle *out_hnd, os::ProcessId process_id, ServiceName service) { + Result AcknowledgeMitmSession(MitmProcessInfo *out_info, os::NativeHandle *out_hnd, os::ProcessId process_id, ServiceName service) { /* Acquire exclusive access to global state. */ std::scoped_lock lk(g_mutex); @@ -852,7 +852,7 @@ namespace ams::sm::impl { /* Set the output handle. */ *out_hnd = service_info->mitm_fwd_sess_h; - service_info->mitm_fwd_sess_h = svc::InvalidHandle; + service_info->mitm_fwd_sess_h = os::InvalidNativeHandle; /* Clear acknowledgement-related fields. */ service_info->mitm_waiting_ack = false; diff --git a/stratosphere/sm/source/impl/sm_service_manager.hpp b/stratosphere/sm/source/impl/sm_service_manager.hpp index a65ca3cec..4a4ae9ee7 100644 --- a/stratosphere/sm/source/impl/sm_service_manager.hpp +++ b/stratosphere/sm/source/impl/sm_service_manager.hpp @@ -29,19 +29,19 @@ namespace ams::sm::impl { /* Service management. */ Result HasService(bool *out, ServiceName service); Result WaitService(ServiceName service); - Result GetServiceHandle(svc::Handle *out, os::ProcessId process_id, ServiceName service); - Result RegisterService(svc::Handle *out, os::ProcessId process_id, ServiceName service, size_t max_sessions, bool is_light); - Result RegisterServiceForSelf(svc::Handle *out, ServiceName service, size_t max_sessions); + Result GetServiceHandle(os::NativeHandle *out, os::ProcessId process_id, ServiceName service); + Result RegisterService(os::NativeHandle *out, os::ProcessId process_id, ServiceName service, size_t max_sessions, bool is_light); + Result RegisterServiceForSelf(os::NativeHandle *out, ServiceName service, size_t max_sessions); Result UnregisterService(os::ProcessId process_id, ServiceName service); /* Mitm extensions. */ Result HasMitm(bool *out, ServiceName service); Result WaitMitm(ServiceName service); - Result InstallMitm(svc::Handle *out, svc::Handle *out_query, os::ProcessId process_id, ServiceName service); + Result InstallMitm(os::NativeHandle *out, os::NativeHandle *out_query, os::ProcessId process_id, ServiceName service); Result UninstallMitm(os::ProcessId process_id, ServiceName service); Result DeclareFutureMitm(os::ProcessId process_id, ServiceName service); Result ClearFutureMitm(os::ProcessId process_id, ServiceName service); - Result AcknowledgeMitmSession(MitmProcessInfo *out_info, svc::Handle *out_hnd, os::ProcessId process_id, ServiceName service); + Result AcknowledgeMitmSession(MitmProcessInfo *out_info, os::NativeHandle *out_hnd, os::ProcessId process_id, ServiceName service); /* Deferral extension (works around FS bug). */ Result EndInitialDefers(); diff --git a/stratosphere/sm/source/sm_tipc_server.cpp b/stratosphere/sm/source/sm_tipc_server.cpp index 5e20290f3..ab22cba67 100644 --- a/stratosphere/sm/source/sm_tipc_server.cpp +++ b/stratosphere/sm/source/sm_tipc_server.cpp @@ -143,7 +143,7 @@ namespace ams::sm { g_server_manager.Initialize(); /* Create the handles for our ports. */ - svc::Handle user_port_handle = svc::InvalidHandle, manager_port_handle = svc::InvalidHandle; + os::NativeHandle user_port_handle, manager_port_handle; { /* Create the user port handle. */ R_ABORT_UNLESS(svc::ManageNamedPort(std::addressof(user_port_handle), "sm:", MaxSessionsUser)); diff --git a/stratosphere/spl/source/spl_api_impl.cpp b/stratosphere/spl/source/spl_api_impl.cpp index e912b29f0..e349dfcca 100644 --- a/stratosphere/spl/source/spl_api_impl.cpp +++ b/stratosphere/spl/source/spl_api_impl.cpp @@ -222,13 +222,13 @@ namespace ams::spl::impl { class DeviceAddressSpaceMapHelper { private: - Handle das_hnd; + os::NativeHandle das_hnd; u64 dst_addr; u64 src_addr; size_t size; svc::MemoryPermission perm; public: - DeviceAddressSpaceMapHelper(Handle h, u64 dst, u64 src, size_t sz, svc::MemoryPermission p) : das_hnd(h), dst_addr(dst), src_addr(src), size(sz), perm(p) { + DeviceAddressSpaceMapHelper(os::NativeHandle h, u64 dst, u64 src, size_t sz, svc::MemoryPermission p) : das_hnd(h), dst_addr(dst), src_addr(src), size(sz), perm(p) { R_ABORT_UNLESS(svc::MapDeviceAddressSpaceAligned(this->das_hnd, dd::GetCurrentProcessHandle(), this->src_addr, this->size, this->dst_addr, this->perm)); } ~DeviceAddressSpaceMapHelper() { @@ -241,7 +241,7 @@ namespace ams::spl::impl { constinit os::InterruptEventType g_se_event; constinit os::SystemEventType g_se_keyslot_available_event; - constinit Handle g_se_das_hnd; + constinit os::NativeHandle g_se_das_hnd = os::InvalidNativeHandle; constinit u32 g_se_mapped_work_buffer_addr; alignas(os::MemoryPageSize) constinit u8 g_work_buffer[2 * WorkBufferSizeMax]; @@ -937,7 +937,7 @@ namespace ams::spl::impl { return ResultSuccess(); } - Handle GetAesKeySlotAvailableEventHandle() { + os::NativeHandle GetAesKeySlotAvailableEventHandle() { return os::GetReadableHandleOfSystemEvent(std::addressof(g_se_keyslot_available_event)); } diff --git a/stratosphere/spl/source/spl_api_impl.hpp b/stratosphere/spl/source/spl_api_impl.hpp index 2d56eaa15..a3fdba5c1 100644 --- a/stratosphere/spl/source/spl_api_impl.hpp +++ b/stratosphere/spl/source/spl_api_impl.hpp @@ -68,6 +68,6 @@ namespace ams::spl::impl { /* Helper. */ Result DeallocateAllAesKeySlots(const void *owner); - Handle GetAesKeySlotAvailableEventHandle(); + os::NativeHandle GetAesKeySlotAvailableEventHandle(); }