Integrate new result macros. (#1780)

* result: try out some experimental shenanigans

* result: sketch out some more shenanigans

* result: see what it looks like to convert kernel to use result conds instead of guards

* make rest of kernel use experimental new macro-ing
This commit is contained in:
SciresM 2022-02-14 14:45:32 -08:00 committed by GitHub
parent 375ba615be
commit 96f95b9f95
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
109 changed files with 1355 additions and 1380 deletions

View file

@ -239,7 +239,7 @@ namespace ams::sm::impl {
access_control = access_control.GetNextEntry();
}
return sm::ResultNotAllowed();
R_THROW(sm::ResultNotAllowed());
}
Result ValidateAccessControl(AccessControlEntry restriction, AccessControlEntry access) {
@ -249,7 +249,7 @@ namespace ams::sm::impl {
access = access.GetNextEntry();
}
return ResultSuccess();
R_SUCCEED();
}
Result ValidateServiceName(ServiceName service) {
@ -269,7 +269,7 @@ namespace ams::sm::impl {
R_UNLESS(service.name[name_len++] == 0, sm::ResultInvalidServiceName());
}
return ResultSuccess();
R_SUCCEED();
}
bool ShouldDeferForInit(ServiceName service) {
@ -355,11 +355,11 @@ namespace ams::sm::impl {
for (auto &future_mitm : g_future_mitm_list) {
if (future_mitm == InvalidServiceName) {
future_mitm = service;
return ResultSuccess();
R_SUCCEED();
}
}
return sm::ResultOutOfServices();
R_THROW(sm::ResultOutOfServices());
}
bool HasFutureMitmDeclaration(ServiceName service) {
@ -414,7 +414,7 @@ namespace ams::sm::impl {
/* Set the output handles. */
*out_server = server_port;
*out_client = client_port;
return ResultSuccess();
R_SUCCEED();
}
Result ConnectToPortImpl(os::NativeHandle *out, os::NativeHandle port) {
@ -424,7 +424,7 @@ namespace ams::sm::impl {
/* Set the output handle. */
*out = session;
return ResultSuccess();
R_SUCCEED();
}
Result GetMitmServiceHandleImpl(os::NativeHandle *out, ServiceInfo *service_info, const MitmProcessInfo &client_info) {
@ -456,7 +456,7 @@ namespace ams::sm::impl {
mitm_info->waiting_ack_process_id = client_info.process_id;
mitm_info->waiting_ack = true;
return ResultSuccess();
R_SUCCEED();
}
Result GetServiceHandleImpl(os::NativeHandle *out, ServiceInfo *service_info, os::ProcessId process_id) {
@ -470,12 +470,12 @@ namespace ams::sm::impl {
GetMitmProcessInfo(std::addressof(client_info), process_id);
if (!IsMitmDisallowed(client_info.program_id)) {
/* Get a mitm service handle. */
return GetMitmServiceHandleImpl(out, service_info, client_info);
R_RETURN(GetMitmServiceHandleImpl(out, service_info, client_info));
}
}
/* We're not returning a mitm handle, so just return a normal port handle. */
return ConnectToPortImpl(out, service_info->port_h);
R_RETURN(ConnectToPortImpl(out, service_info->port_h));
}
Result RegisterServiceImpl(os::NativeHandle *out, os::ProcessId process_id, ServiceName service, size_t max_sessions, bool is_light) {
@ -501,7 +501,7 @@ namespace ams::sm::impl {
/* This might undefer some requests. */
TriggerResume(service);
return ResultSuccess();
R_SUCCEED();
}
void UnregisterServiceImpl(ServiceInfo *service_info) {
@ -567,7 +567,7 @@ namespace ams::sm::impl {
proc->access_control_size = aci_sac_size;
std::memcpy(proc->access_control, aci_sac, proc->access_control_size);
return ResultSuccess();
R_SUCCEED();
}
Result UnregisterProcess(os::ProcessId process_id) {
@ -581,7 +581,7 @@ namespace ams::sm::impl {
/* Free the process. */
*proc = InvalidProcessInfo;
return ResultSuccess();
R_SUCCEED();
}
/* Service management. */
@ -593,7 +593,7 @@ namespace ams::sm::impl {
R_TRY(ValidateServiceName(service));
*out = HasServiceInfo(service);
return ResultSuccess();
R_SUCCEED();
}
Result WaitService(ServiceName service) {
@ -607,7 +607,7 @@ namespace ams::sm::impl {
/* If we don't, we want to wait until the service is registered. */
R_UNLESS(has_service, tipc::ResultRequestDeferred());
return ResultSuccess();
R_SUCCEED();
}
Result GetServiceHandle(os::NativeHandle *out, os::ProcessId process_id, ServiceName service) {
@ -639,7 +639,7 @@ namespace ams::sm::impl {
R_CONVERT(svc::ResultOutOfSessions, sm::ResultOutOfSessions())
} R_END_TRY_CATCH;
return ResultSuccess();
R_SUCCEED();
}
Result RegisterService(os::NativeHandle *out, os::ProcessId process_id, ServiceName service, size_t max_sessions, bool is_light) {
@ -660,14 +660,14 @@ namespace ams::sm::impl {
/* Check that the service isn't already registered. */
R_UNLESS(!HasServiceInfo(service), sm::ResultAlreadyRegistered());
return RegisterServiceImpl(out, process_id, service, max_sessions, is_light);
R_RETURN(RegisterServiceImpl(out, process_id, service, max_sessions, is_light));
}
Result RegisterServiceForSelf(os::NativeHandle *out, ServiceName service, size_t max_sessions) {
/* Acquire exclusive access to global state. */
std::scoped_lock lk(g_mutex);
return RegisterServiceImpl(out, os::GetCurrentProcessId(), service, max_sessions, false);
R_RETURN(RegisterServiceImpl(out, os::GetCurrentProcessId(), service, max_sessions, false));
}
Result UnregisterService(os::ProcessId process_id, ServiceName service) {
@ -692,7 +692,7 @@ namespace ams::sm::impl {
/* Unregister the service. */
UnregisterServiceImpl(service_info);
return ResultSuccess();
R_SUCCEED();
}
/* Mitm extensions. */
@ -706,7 +706,7 @@ namespace ams::sm::impl {
/* Get whether we have a mitm. */
*out = HasMitm(service);
return ResultSuccess();
R_SUCCEED();
}
Result WaitMitm(ServiceName service) {
@ -720,7 +720,7 @@ namespace ams::sm::impl {
/* If we don't, we want to wait until the mitm is installed. */
R_UNLESS(has_mitm, tipc::ResultRequestDeferred());
return ResultSuccess();
R_SUCCEED();
}
Result InstallMitm(os::NativeHandle *out, os::NativeHandle *out_query, os::ProcessId process_id, ServiceName service) {
@ -757,7 +757,8 @@ namespace ams::sm::impl {
R_TRY(AddFutureMitmDeclaration(service));
}
auto future_guard = SCOPE_GUARD { if (!has_existing_future_declaration) { ClearFutureMitmDeclaration(service); } };
/* If we fail past this point, clean up the future mitm declaration we just added. */
ON_RESULT_FAILURE { if (!has_existing_future_declaration) { ClearFutureMitmDeclaration(service); } };
/* Create mitm handles. */
{
@ -766,15 +767,12 @@ namespace ams::sm::impl {
R_TRY(CreatePortImpl(std::addressof(hnd), std::addressof(port_hnd), service_info->max_sessions, service_info->is_light, service_info->name));
/* Ensure that we clean up the port handles, if something goes wrong creating the query sessions. */
auto port_guard = SCOPE_GUARD { os::CloseNativeHandle(hnd); os::CloseNativeHandle(port_hnd); };
ON_RESULT_FAILURE { os::CloseNativeHandle(hnd); os::CloseNativeHandle(port_hnd); };
/* Create the session for our query service. */
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. */
port_guard.Cancel();
/* Setup the mitm info. */
mitm_info->process_id = process_id;
mitm_info->port_h = port_hnd;
@ -791,8 +789,7 @@ namespace ams::sm::impl {
TriggerResume(service);
}
future_guard.Cancel();
return ResultSuccess();
R_SUCCEED();
}
Result UninstallMitm(os::ProcessId process_id, ServiceName service) {
@ -833,7 +830,7 @@ namespace ams::sm::impl {
service_info->mitm_index = MitmCountMax;
}
return ResultSuccess();
R_SUCCEED();
}
Result DeclareFutureMitm(os::ProcessId process_id, ServiceName service) {
@ -857,7 +854,7 @@ namespace ams::sm::impl {
/* Try to forward declare it. */
R_TRY(AddFutureMitmDeclaration(service));
return ResultSuccess();
R_SUCCEED();
}
Result ClearFutureMitm(os::ProcessId process_id, ServiceName service) {
@ -889,7 +886,7 @@ namespace ams::sm::impl {
/* Clear the forward declaration. */
ClearFutureMitmDeclaration(service);
return ResultSuccess();
R_SUCCEED();
}
Result AcknowledgeMitmSession(MitmProcessInfo *out_info, os::NativeHandle *out_hnd, os::ProcessId process_id, ServiceName service) {
@ -934,7 +931,7 @@ namespace ams::sm::impl {
/* Undefer requests to the session. */
TriggerResume(service);
return ResultSuccess();
R_SUCCEED();
}
/* Deferral extension (works around FS bug). */
@ -954,7 +951,7 @@ namespace ams::sm::impl {
TriggerResume(service_name);
}
return ResultSuccess();
R_SUCCEED();
}
}

View file

@ -23,11 +23,11 @@ namespace ams::sm {
class ManagerService {
public:
Result RegisterProcess(os::ProcessId process_id, const tipc::InBuffer acid_sac, const tipc::InBuffer aci_sac) {
return impl::RegisterProcess(process_id, ncm::InvalidProgramId, cfg::OverrideStatus{}, acid_sac.GetPointer(), acid_sac.GetSize(), aci_sac.GetPointer(), aci_sac.GetSize());
R_RETURN(impl::RegisterProcess(process_id, ncm::InvalidProgramId, cfg::OverrideStatus{}, acid_sac.GetPointer(), acid_sac.GetSize(), aci_sac.GetPointer(), aci_sac.GetSize()));
}
Result UnregisterProcess(os::ProcessId process_id) {
return impl::UnregisterProcess(process_id);
R_RETURN(impl::UnregisterProcess(process_id));
}
void AtmosphereEndInitDefers() {
@ -40,7 +40,7 @@ namespace ams::sm {
Result AtmosphereRegisterProcess(os::ProcessId process_id, ncm::ProgramId program_id, cfg::OverrideStatus override_status, const tipc::InBuffer acid_sac, const tipc::InBuffer aci_sac) {
/* This takes in a program id and override status, unlike RegisterProcess. */
return impl::RegisterProcess(process_id, program_id, override_status, acid_sac.GetPointer(), acid_sac.GetSize(), aci_sac.GetPointer(), aci_sac.GetSize());
R_RETURN(impl::RegisterProcess(process_id, program_id, override_status, acid_sac.GetPointer(), acid_sac.GetSize(), aci_sac.GetPointer(), aci_sac.GetSize()));
}
};
static_assert(sm::impl::IsIManagerInterface<ManagerService>);

View file

@ -78,7 +78,7 @@ namespace ams::sm {
/* We do not have a pointer buffer, and so our pointer buffer size is zero. */
/* Return the relevant hardcoded response. */
std::memcpy(message_buffer.GetBufferForDebug(), CmifResponseToQueryPointerBufferSize, sizeof(CmifResponseToQueryPointerBufferSize));
return ResultSuccess();
R_SUCCEED();
}
/* We only support request (with context), from this point forwards. */
@ -124,7 +124,7 @@ namespace ams::sm {
/* Invoke the handler for DetachClient. */
R_ABORT_UNLESS(this->DetachClient(tipc::ClientProcessId{ client_process_id }));
} else {
return tipc::ResultInvalidMethod();
R_THROW(tipc::ResultInvalidMethod());
}
/* Serialize output. */
@ -158,7 +158,7 @@ namespace ams::sm {
std::memcpy(out_message_buffer + 0x00, CmifResponseToUnregisterService, sizeof(CmifResponseToUnregisterService));
std::memcpy(out_message_buffer + 0x18, std::addressof(result), sizeof(result));
} else {
return tipc::ResultInvalidMethod();
R_THROW(tipc::ResultInvalidMethod());
}
} else if (std::memcmp(raw_message_buffer, CmifExpectedRequestHeaderForRegisterService, sizeof(CmifExpectedRequestHeaderForRegisterService)) == 0) {
/* Get the command id. */
@ -186,13 +186,13 @@ namespace ams::sm {
std::memcpy(out_message_buffer + 0x0C, std::addressof(out_handle), sizeof(out_handle));
std::memcpy(out_message_buffer + 0x18, std::addressof(result), sizeof(result));
} else {
return tipc::ResultInvalidMethod();
R_THROW(tipc::ResultInvalidMethod());
}
} else {
return tipc::ResultInvalidMethod();
R_THROW(tipc::ResultInvalidMethod());
}
return ResultSuccess();
R_SUCCEED();
}
}

View file

@ -36,83 +36,96 @@ namespace ams::sm {
Result RegisterClient(const tipc::ClientProcessId client_process_id) {
m_process_id = client_process_id.value;
m_initialized = true;
return ResultSuccess();
R_SUCCEED();
}
Result GetServiceHandle(tipc::OutMoveHandle out_h, ServiceName service) {
R_UNLESS(m_initialized, sm::ResultInvalidClient());
return this->RegisterRetryIfDeferred(service, [&]() ALWAYS_INLINE_LAMBDA -> Result {
return impl::GetServiceHandle(out_h.GetPointer(), m_process_id, service);
});
TIPC_REGISTER_RETRY_ON_RESULT_REQUEST_DEFERRED(service);
R_RETURN(impl::GetServiceHandle(out_h.GetPointer(), m_process_id, service));
}
Result RegisterService(tipc::OutMoveHandle out_h, ServiceName service, u32 max_sessions, bool is_light) {
R_UNLESS(m_initialized, sm::ResultInvalidClient());
return impl::RegisterService(out_h.GetPointer(), m_process_id, service, max_sessions, is_light);
R_RETURN(impl::RegisterService(out_h.GetPointer(), m_process_id, service, max_sessions, is_light));
}
Result UnregisterService(ServiceName service) {
R_UNLESS(m_initialized, sm::ResultInvalidClient());
return impl::UnregisterService(m_process_id, service);
R_RETURN(impl::UnregisterService(m_process_id, service));
}
Result DetachClient(const tipc::ClientProcessId client_process_id) {
AMS_UNUSED(client_process_id);
m_initialized = false;
return ResultSuccess();
R_SUCCEED();
}
/* Atmosphere commands. */
Result AtmosphereInstallMitm(tipc::OutMoveHandle srv_h, tipc::OutMoveHandle qry_h, ServiceName service) {
R_UNLESS(m_initialized, sm::ResultInvalidClient());
return this->RegisterRetryIfDeferred(service, [&]() ALWAYS_INLINE_LAMBDA -> Result {
return impl::InstallMitm(srv_h.GetPointer(), qry_h.GetPointer(), m_process_id, service);
});
TIPC_REGISTER_RETRY_ON_RESULT_REQUEST_DEFERRED(service);
R_RETURN(impl::InstallMitm(srv_h.GetPointer(), qry_h.GetPointer(), m_process_id, service));
}
Result AtmosphereUninstallMitm(ServiceName service) {
R_UNLESS(m_initialized, sm::ResultInvalidClient());
return impl::UninstallMitm(m_process_id, service);
R_RETURN(impl::UninstallMitm(m_process_id, service));
}
Result AtmosphereAcknowledgeMitmSession(tipc::Out<MitmProcessInfo> client_info, tipc::OutMoveHandle fwd_h, ServiceName service) {
R_UNLESS(m_initialized, sm::ResultInvalidClient());
return impl::AcknowledgeMitmSession(client_info.GetPointer(), fwd_h.GetPointer(), m_process_id, service);
R_RETURN(impl::AcknowledgeMitmSession(client_info.GetPointer(), fwd_h.GetPointer(), m_process_id, service));
}
Result AtmosphereHasMitm(tipc::Out<bool> out, ServiceName service) {
R_UNLESS(m_initialized, sm::ResultInvalidClient());
return impl::HasMitm(out.GetPointer(), service);
R_RETURN(impl::HasMitm(out.GetPointer(), service));
}
Result AtmosphereWaitMitm(ServiceName service) {
R_UNLESS(m_initialized, sm::ResultInvalidClient());
return this->RegisterRetryIfDeferred(service, [&]() ALWAYS_INLINE_LAMBDA -> Result {
return impl::WaitMitm(service);
});
TIPC_REGISTER_RETRY_ON_RESULT_REQUEST_DEFERRED(service);
R_RETURN(impl::WaitMitm(service));
}
Result AtmosphereDeclareFutureMitm(ServiceName service) {
R_UNLESS(m_initialized, sm::ResultInvalidClient());
return impl::DeclareFutureMitm(m_process_id, service);
R_RETURN(impl::DeclareFutureMitm(m_process_id, service));
}
Result AtmosphereClearFutureMitm(ServiceName service) {
R_UNLESS(m_initialized, sm::ResultInvalidClient());
return impl::ClearFutureMitm(m_process_id, service);
R_RETURN(impl::ClearFutureMitm(m_process_id, service));
}
Result AtmosphereHasService(tipc::Out<bool> out, ServiceName service) {
R_UNLESS(m_initialized, sm::ResultInvalidClient());
return impl::HasService(out.GetPointer(), service);
R_RETURN(impl::HasService(out.GetPointer(), service));
}
Result AtmosphereWaitService(ServiceName service) {
R_UNLESS(m_initialized, sm::ResultInvalidClient());
return this->RegisterRetryIfDeferred(service, [&]() ALWAYS_INLINE_LAMBDA -> Result {
return impl::WaitService(service);
});
TIPC_REGISTER_RETRY_ON_RESULT_REQUEST_DEFERRED(service);
R_RETURN(impl::WaitService(service));
}
public:
/* Backwards compatibility layer for cmif. */