ams: globally prefer R_RETURN to return for ams::Result

This commit is contained in:
Michael Scire
2022-03-26 14:48:33 -07:00
parent dd78ede99f
commit bbf22b4c60
325 changed files with 1955 additions and 1993 deletions

View File

@@ -18,12 +18,12 @@
namespace ams::sf::cmif {
Result DomainServiceObjectDispatchTable::ProcessMessage(ServiceDispatchContext &ctx, const cmif::PointerAndSize &in_raw_data) const {
return this->ProcessMessageImpl(ctx, static_cast<DomainServiceObject *>(ctx.srv_obj)->GetServerDomain(), in_raw_data);
R_RETURN(this->ProcessMessageImpl(ctx, static_cast<DomainServiceObject *>(ctx.srv_obj)->GetServerDomain(), in_raw_data));
}
#if AMS_SF_MITM_SUPPORTED
Result DomainServiceObjectDispatchTable::ProcessMessageForMitm(ServiceDispatchContext &ctx, const cmif::PointerAndSize &in_raw_data) const {
return this->ProcessMessageForMitmImpl(ctx, static_cast<DomainServiceObject *>(ctx.srv_obj)->GetServerDomain(), in_raw_data);
R_RETURN(this->ProcessMessageForMitmImpl(ctx, static_cast<DomainServiceObject *>(ctx.srv_obj)->GetServerDomain(), in_raw_data));
}
#endif
@@ -50,14 +50,14 @@ namespace ams::sf::cmif {
ctx.processor->SetImplementationProcessor(std::addressof(domain_processor));
}
ctx.srv_obj = target_object.GetServiceObjectUnsafe();
return target_object.ProcessMessage(ctx, in_message_raw_data);
R_RETURN(target_object.ProcessMessage(ctx, in_message_raw_data));
}
case CmifDomainRequestType_Close:
/* TODO: N doesn't error check here. Should we? */
domain->UnregisterObject(target_object_id);
R_SUCCEED();
default:
return sf::cmif::ResultInvalidInHeader();
R_THROW(sf::cmif::ResultInvalidInHeader());
}
}
@@ -75,7 +75,7 @@ namespace ams::sf::cmif {
/* Mitm. If we don't have a target object, we should forward to let the server handle. */
if (!target_object) {
return ctx.session->ForwardRequest(ctx);
R_RETURN(ctx.session->ForwardRequest(ctx));
}
R_UNLESS(in_header->data_size + in_header->num_in_objects * sizeof(DomainObjectId) <= in_domain_raw_data.GetSize(), sf::cmif::ResultInvalidHeaderSize());
@@ -90,7 +90,7 @@ namespace ams::sf::cmif {
ctx.processor->SetImplementationProcessor(std::addressof(domain_processor));
}
ctx.srv_obj = target_object.GetServiceObjectUnsafe();
return target_object.ProcessMessage(ctx, in_message_raw_data);
R_RETURN(target_object.ProcessMessage(ctx, in_message_raw_data));
}
case CmifDomainRequestType_Close:
{
@@ -98,7 +98,7 @@ namespace ams::sf::cmif {
/* If the object is not in the domain, tell the server to close it. */
if (!target_object) {
return ctx.session->ForwardRequest(ctx);
R_RETURN(ctx.session->ForwardRequest(ctx));
}
/* If the object is in the domain, close our copy of it. Mitm objects are required to close their associated domain id, so this shouldn't cause desynch. */
@@ -106,7 +106,7 @@ namespace ams::sf::cmif {
R_SUCCEED();
}
default:
return sf::cmif::ResultInvalidInHeader();
R_THROW(sf::cmif::ResultInvalidInHeader());
}
}
#endif
@@ -118,7 +118,7 @@ namespace ams::sf::cmif {
/* Nintendo reserves domain object IDs here. We do this later, to support mitm semantics. */
/* Pass onwards. */
return m_impl_processor->PrepareForProcess(ctx, runtime_metadata);
R_RETURN(m_impl_processor->PrepareForProcess(ctx, runtime_metadata));
}
Result DomainServiceObjectProcessor::GetInObjects(ServiceObjectHolder *in_objects) const {

View File

@@ -105,13 +105,13 @@ namespace ams::sf::cmif {
/* Forward any meta-context change result. */
if (sf::impl::ResultRequestContextChanged::Includes(command_result)) {
return command_result;
R_RETURN(command_result);
}
/* Otherwise, ensure that we're able to write the output header. */
if (out_header == nullptr) {
AMS_ABORT_UNLESS(R_FAILED(command_result));
return command_result;
R_RETURN(command_result);
}
/* Write output header to raw data. */
@@ -138,7 +138,7 @@ namespace ams::sf::cmif {
/* If we didn't find a handler, forward the request. */
if (cmd_handler == nullptr) {
return ctx.session->ForwardRequest(ctx);
R_RETURN(ctx.session->ForwardRequest(ctx));
}
/* Invoke handler. */
@@ -147,18 +147,18 @@ namespace ams::sf::cmif {
/* If we should, forward the request to the forward session. */
if (sm::mitm::ResultShouldForwardToSession::Includes(command_result)) {
return ctx.session->ForwardRequest(ctx);
R_RETURN(ctx.session->ForwardRequest(ctx));
}
/* Forward any meta-context change result. */
if (sf::impl::ResultRequestContextChanged::Includes(command_result)) {
return command_result;
R_RETURN(command_result);
}
/* Otherwise, ensure that we're able to write the output header. */
if (out_header == nullptr) {
AMS_ABORT_UNLESS(R_FAILED(command_result));
return command_result;
R_RETURN(command_result);
}
/* Write output header to raw data. */

View File

@@ -23,9 +23,9 @@ namespace ams::sf::hipc {
s32 unused_index;
if (message_buf == hipc::GetMessageBufferOnTls()) {
/* Consider: AMS_ABORT_UNLESS(message_buf_size == TlsMessageBufferSize); */
return svc::ReplyAndReceive(&unused_index, &session_handle, 1, svc::InvalidHandle, std::numeric_limits<u64>::max());
R_RETURN(svc::ReplyAndReceive(&unused_index, &session_handle, 1, svc::InvalidHandle, std::numeric_limits<u64>::max()));
} else {
return svc::ReplyAndReceiveWithUserBuffer(&unused_index, reinterpret_cast<uintptr_t>(message_buf), message_buf_size, &session_handle, 1, svc::InvalidHandle, std::numeric_limits<u64>::max());
R_RETURN(svc::ReplyAndReceiveWithUserBuffer(&unused_index, reinterpret_cast<uintptr_t>(message_buf), message_buf_size, &session_handle, 1, svc::InvalidHandle, std::numeric_limits<u64>::max()));
}
}
@@ -33,9 +33,9 @@ namespace ams::sf::hipc {
s32 unused_index;
if (message_buf == hipc::GetMessageBufferOnTls()) {
/* Consider: AMS_ABORT_UNLESS(message_buf_size == TlsMessageBufferSize); */
return svc::ReplyAndReceive(&unused_index, &session_handle, 0, session_handle, 0);
R_RETURN(svc::ReplyAndReceive(&unused_index, &session_handle, 0, session_handle, 0));
} else {
return svc::ReplyAndReceiveWithUserBuffer(&unused_index, reinterpret_cast<uintptr_t>(message_buf), message_buf_size, &session_handle, 0, session_handle, 0);
R_RETURN(svc::ReplyAndReceiveWithUserBuffer(&unused_index, reinterpret_cast<uintptr_t>(message_buf), message_buf_size, &session_handle, 0, session_handle, 0));
}
}

View File

@@ -181,7 +181,7 @@ namespace ams::sf::hipc {
}
Result CloneCurrentObject(sf::OutMoveHandle out) {
return this->CloneCurrentObjectImpl(out, m_manager);
R_RETURN(this->CloneCurrentObjectImpl(out, m_manager));
}
void QueryPointerBufferSize(sf::Out<u16> out) {
@@ -189,7 +189,7 @@ namespace ams::sf::hipc {
}
Result CloneCurrentObjectEx(sf::OutMoveHandle out, u32 tag) {
return this->CloneCurrentObjectImpl(out, m_manager->GetSessionManagerByTag(tag));
R_RETURN(this->CloneCurrentObjectImpl(out, m_manager->GetSessionManagerByTag(tag)));
}
};
static_assert(IsIHipcManager<HipcManagerImpl>);
@@ -201,7 +201,7 @@ namespace ams::sf::hipc {
/* Note: This is safe, as no additional references to the hipc manager can ever be stored. */
/* The shared pointer to stack object is definitely gross, though. */
UnmanagedServiceObject<impl::IHipcManager, impl::HipcManagerImpl> hipc_manager(this, session);
return this->DispatchRequest(cmif::ServiceObjectHolder(hipc_manager.GetShared()), session, in_message, out_message);
R_RETURN(this->DispatchRequest(cmif::ServiceObjectHolder(hipc_manager.GetShared()), session, in_message, out_message));
}
}

View File

@@ -96,9 +96,9 @@ namespace ams::sf::hipc {
/* Create new session. */
if (server->m_static_object) {
return this->AcceptSession(server->m_port_handle, server->m_static_object.Clone());
R_RETURN(this->AcceptSession(server->m_port_handle, server->m_static_object.Clone()));
} else {
return this->OnNeedsToAccept(server->m_index, server);
R_RETURN(this->OnNeedsToAccept(server->m_index, server));
}
}
@@ -110,7 +110,7 @@ namespace ams::sf::hipc {
ON_SCOPE_EXIT { this->LinkToDeferredList(server); };
/* Create resources for new session. */
return this->OnNeedsToAccept(server->m_index, server);
R_RETURN(this->OnNeedsToAccept(server->m_index, server));
}
#endif
@@ -164,13 +164,13 @@ namespace ams::sf::hipc {
Result ServerManagerBase::Process(os::MultiWaitHolderType *holder) {
switch (static_cast<UserDataTag>(os::GetMultiWaitHolderUserData(holder))) {
case UserDataTag::Server:
return this->ProcessForServer(holder);
R_RETURN(this->ProcessForServer(holder));
case UserDataTag::Session:
return this->ProcessForSession(holder);
R_RETURN(this->ProcessForSession(holder));
#if AMS_SF_MITM_SUPPORTED
case UserDataTag::MitmServer:
AMS_ABORT_UNLESS(this->CanManageMitmServers());
return this->ProcessForMitmServer(holder);
R_RETURN(this->ProcessForMitmServer(holder));
#endif
AMS_UNREACHABLE_DEFAULT_CASE();
}

View File

@@ -164,26 +164,26 @@ namespace ams::sf::hipc {
Result ServerSessionManager::RegisterSession(os::NativeHandle session_handle, cmif::ServiceObjectHolder &&obj) {
/* We don't actually care about what happens to the session. It'll get linked. */
ServerSession *session_ptr = nullptr;
return this->RegisterSession(std::addressof(session_ptr), session_handle, std::forward<cmif::ServiceObjectHolder>(obj));
R_RETURN(this->RegisterSession(std::addressof(session_ptr), session_handle, std::forward<cmif::ServiceObjectHolder>(obj)));
}
Result ServerSessionManager::AcceptSession(os::NativeHandle port_handle, cmif::ServiceObjectHolder &&obj) {
/* We don't actually care about what happens to the session. It'll get linked. */
ServerSession *session_ptr = nullptr;
return this->AcceptSession(std::addressof(session_ptr), port_handle, std::forward<cmif::ServiceObjectHolder>(obj));
R_RETURN(this->AcceptSession(std::addressof(session_ptr), port_handle, std::forward<cmif::ServiceObjectHolder>(obj)));
}
#if AMS_SF_MITM_SUPPORTED
Result ServerSessionManager::RegisterMitmSession(os::NativeHandle mitm_session_handle, cmif::ServiceObjectHolder &&obj, std::shared_ptr<::Service> &&fsrv) {
/* We don't actually care about what happens to the session. It'll get linked. */
ServerSession *session_ptr = nullptr;
return this->RegisterMitmSession(std::addressof(session_ptr), mitm_session_handle, std::forward<cmif::ServiceObjectHolder>(obj), std::forward<std::shared_ptr<::Service>>(fsrv));
R_RETURN(this->RegisterMitmSession(std::addressof(session_ptr), mitm_session_handle, std::forward<cmif::ServiceObjectHolder>(obj), std::forward<std::shared_ptr<::Service>>(fsrv)));
}
Result ServerSessionManager::AcceptMitmSession(os::NativeHandle mitm_port_handle, cmif::ServiceObjectHolder &&obj, std::shared_ptr<::Service> &&fsrv) {
/* We don't actually care about what happens to the session. It'll get linked. */
ServerSession *session_ptr = nullptr;
return this->AcceptMitmSession(std::addressof(session_ptr), mitm_port_handle, std::forward<cmif::ServiceObjectHolder>(obj), std::forward<std::shared_ptr<::Service>>(fsrv));
R_RETURN(this->AcceptMitmSession(std::addressof(session_ptr), mitm_port_handle, std::forward<cmif::ServiceObjectHolder>(obj), std::forward<std::shared_ptr<::Service>>(fsrv)));
}
#endif
@@ -243,10 +243,7 @@ namespace ams::sf::hipc {
default:
{
R_TRY_CATCH(this->ProcessRequestImpl(session, message, message)) {
R_CATCH(sf::impl::ResultRequestContextChanged) {
/* A meta message changing the request context has been sent. */
return R_CURRENT_RESULT;
}
R_CATCH_RETHROW(sf::impl::ResultRequestContextChanged) /* A meta message changing the request context has been sent. */
R_CATCH_ALL() {
/* All other results indicate something went very wrong. */
this->CloseSessionImpl(session);
@@ -285,12 +282,12 @@ namespace ams::sf::hipc {
switch (cmif_command_type) {
case CmifCommandType_Request:
case CmifCommandType_RequestWithContext:
return this->DispatchRequest(session->m_srv_obj_holder.Clone(), session, in_message, out_message);
R_RETURN(this->DispatchRequest(session->m_srv_obj_holder.Clone(), session, in_message, out_message));
case CmifCommandType_Control:
case CmifCommandType_ControlWithContext:
return this->DispatchManagerRequest(session, in_message, out_message);
R_RETURN(this->DispatchManagerRequest(session, in_message, out_message));
default:
return sf::hipc::ResultUnknownCommandType();
R_THROW(sf::hipc::ResultUnknownCommandType());
}
}