From 9be8b32311dfc3c1263c2d8ca76839944f6029c6 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Sat, 10 Apr 2021 15:32:48 -0700 Subject: [PATCH] tipc/sm: various fixes for issues --- .../include/stratosphere/ncm/ncm_program_id.hpp | 5 +---- .../include/stratosphere/sm/sm_types.hpp | 4 +++- .../tipc/impl/tipc_impl_command_serialization.hpp | 10 +++++----- .../include/stratosphere/tipc/tipc_object_manager.hpp | 2 -- .../os_waitable_manager_target_impl.os.horizon.cpp | 3 ++- stratosphere/sm/source/sm_user_service_cmif_shim.inc | 2 +- 6 files changed, 12 insertions(+), 14 deletions(-) diff --git a/libraries/libstratosphere/include/stratosphere/ncm/ncm_program_id.hpp b/libraries/libstratosphere/include/stratosphere/ncm/ncm_program_id.hpp index 20923ef52..746a5ea0d 100644 --- a/libraries/libstratosphere/include/stratosphere/ncm/ncm_program_id.hpp +++ b/libraries/libstratosphere/include/stratosphere/ncm/ncm_program_id.hpp @@ -21,8 +21,6 @@ namespace ams::ncm { struct ProgramId { u64 value; - static const ProgramId Invalid; - inline explicit operator svc::ProgramId() const { static_assert(sizeof(value) == sizeof(svc::ProgramId)); return { this->value }; @@ -53,7 +51,6 @@ namespace ams::ncm { return lhs.value >= rhs.value; } - inline constexpr const ProgramId ProgramId::Invalid = {}; - inline constexpr const ProgramId InvalidProgramId = ProgramId::Invalid; + inline constexpr const ProgramId InvalidProgramId = {}; } diff --git a/libraries/libstratosphere/include/stratosphere/sm/sm_types.hpp b/libraries/libstratosphere/include/stratosphere/sm/sm_types.hpp index e02253a6b..92e83f414 100644 --- a/libraries/libstratosphere/include/stratosphere/sm/sm_types.hpp +++ b/libraries/libstratosphere/include/stratosphere/sm/sm_types.hpp @@ -44,7 +44,9 @@ namespace ams::sm { return Encode(name, std::strlen(name)); } }; - static constexpr ServiceName InvalidServiceName = ServiceName::Encode(""); + + static constexpr inline ServiceName InvalidServiceName = ServiceName::Encode(""); + static_assert(alignof(ServiceName) == 1, "ServiceName definition!"); inline bool operator==(const ServiceName &lhs, const ServiceName &rhs) { diff --git a/libraries/libstratosphere/include/stratosphere/tipc/impl/tipc_impl_command_serialization.hpp b/libraries/libstratosphere/include/stratosphere/tipc/impl/tipc_impl_command_serialization.hpp index d0ad2e73f..439824a4a 100644 --- a/libraries/libstratosphere/include/stratosphere/tipc/impl/tipc_impl_command_serialization.hpp +++ b/libraries/libstratosphere/include/stratosphere/tipc/impl/tipc_impl_command_serialization.hpp @@ -314,8 +314,8 @@ namespace ams::tipc::impl { static constexpr svc::ipc::MessageBuffer::SpecialHeader OutSpecialHeader{false, NumOutCopyHandles, NumOutMoveHandles, HasOutSpecialHeader}; static constexpr auto OutMessageHandleIndex = svc::ipc::MessageBuffer::GetSpecialDataIndex(OutMessageHeader, OutSpecialHeader); - static constexpr auto OutMessageRawDataIndex = svc::ipc::MessageBuffer::GetRawDataIndex(OutMessageHeader, OutSpecialHeader); - static constexpr auto OutMessageResultIndex = OutMessageRawDataIndex + OutDataSize / sizeof(u32); + static constexpr auto OutMessageResultIndex = svc::ipc::MessageBuffer::GetRawDataIndex(OutMessageHeader, OutSpecialHeader); + static constexpr auto OutMessageRawDataIndex = OutMessageResultIndex + 1; /* Construction of argument serialization structs. */ private: @@ -580,11 +580,11 @@ namespace ams::tipc::impl { /* Set output handles. */ out_handles_holder.CopyTo(message_buffer); - /* Set output data. */ - out_raw_holder.CopyTo(message_buffer); - /* Set output result. */ message_buffer.Set(CommandMeta::OutMessageResultIndex, result.GetValue()); + + /* Set output data. */ + out_raw_holder.CopyTo(message_buffer); } }; diff --git a/libraries/libstratosphere/include/stratosphere/tipc/tipc_object_manager.hpp b/libraries/libstratosphere/include/stratosphere/tipc/tipc_object_manager.hpp index 91a60057d..c395fa7bd 100644 --- a/libraries/libstratosphere/include/stratosphere/tipc/tipc_object_manager.hpp +++ b/libraries/libstratosphere/include/stratosphere/tipc/tipc_object_manager.hpp @@ -131,11 +131,9 @@ namespace ams::tipc { R_TRY_CATCH(svc::ReplyAndReceive(std::addressof(dummy), nullptr, 0, reply_target, 0)) { R_CATCH(svc::ResultTimedOut) { /* Timing out is acceptable. */ - return R_CURRENT_RESULT; } R_CATCH(svc::ResultSessionClosed) { /* It's okay if we couldn't reply to a closed session. */ - return R_CURRENT_RESULT; } } R_END_TRY_CATCH_WITH_ABORT_UNLESS; diff --git a/libraries/libstratosphere/source/os/impl/os_waitable_manager_target_impl.os.horizon.cpp b/libraries/libstratosphere/source/os/impl/os_waitable_manager_target_impl.os.horizon.cpp index 9012d23cd..e567cf444 100644 --- a/libraries/libstratosphere/source/os/impl/os_waitable_manager_target_impl.os.horizon.cpp +++ b/libraries/libstratosphere/source/os/impl/os_waitable_manager_target_impl.os.horizon.cpp @@ -42,7 +42,7 @@ namespace ams::os::impl { s32 index = WaitableManagerImpl::WaitInvalid; static_assert(WaitableManagerImpl::WaitInvalid != -1); - R_TRY_CATCH(svc::ReplyAndReceive(std::addressof(index), arr, num, ns, reply_target)) { + R_TRY_CATCH(svc::ReplyAndReceive(std::addressof(index), arr, num, reply_target, ns)) { R_CATCH(svc::ResultTimedOut) { *out_index = WaitableManagerImpl::WaitTimedOut; return R_CURRENT_RESULT; } R_CATCH(svc::ResultCancelled) { *out_index = WaitableManagerImpl::WaitCancelled; return R_CURRENT_RESULT; } R_CATCH(svc::ResultSessionClosed) { @@ -60,6 +60,7 @@ namespace ams::os::impl { } } R_END_TRY_CATCH_WITH_ABORT_UNLESS; + *out_index = index; return ResultSuccess(); } diff --git a/stratosphere/sm/source/sm_user_service_cmif_shim.inc b/stratosphere/sm/source/sm_user_service_cmif_shim.inc index 92a4911b8..9dcc32626 100644 --- a/stratosphere/sm/source/sm_user_service_cmif_shim.inc +++ b/stratosphere/sm/source/sm_user_service_cmif_shim.inc @@ -182,7 +182,7 @@ namespace ams::sm { u32 max_sessions; std::memcpy(std::addressof(max_sessions), raw_message_buffer + 0x2C, sizeof(max_sessions)); - if (command_id == 4) { + if (command_id == 2) { /* Invoke the handler for RegisterService. */ tipc::MoveHandle out_handle; const Result result = this->RegisterService(std::addressof(out_handle), service_name, max_sessions, is_light);