Results: Implement namespaced, type-safe results.

Because I was working on multiple things at once, this commit also:
- Adds wrappers for/linker flags to wrap CXX exceptions to make them
  abort. This saves ~0x8000 of memory in every system module.
- Broadly replaces lines of the pattern if (cond) { return ResultX; }
  with R_UNLESS(!cond, ResultX());.
- Reworks the R_TRY_CATCH macros (and the result macros in general).
This commit is contained in:
Michael Scire
2019-10-24 01:40:44 -07:00
committed by SciresM
parent 15773e4755
commit 4059dc6187
169 changed files with 2172 additions and 1868 deletions

View File

@@ -34,11 +34,11 @@ namespace sts::sf::cmif {
Result ServerDomainManager::Domain::ReserveIds(DomainObjectId *out_ids, size_t count) {
for (size_t i = 0; i < count; i++) {
Entry *entry = this->manager->entry_manager.AllocateEntry();
R_UNLESS(entry != nullptr, ResultServiceFrameworkOutOfDomainEntries);
R_UNLESS(entry != nullptr, sf::cmif::ResultOutOfDomainEntries());
STS_ASSERT(entry->owner == nullptr);
out_ids[i] = this->manager->entry_manager.GetId(entry);
}
return ResultSuccess;
return ResultSuccess();
}
void ServerDomainManager::Domain::ReserveSpecificIds(const DomainObjectId *ids, size_t count) {

View File

@@ -28,7 +28,7 @@ namespace sts::sf::cmif {
Result DomainServiceObjectDispatchTable::ProcessMessageImpl(ServiceDispatchContext &ctx, ServerDomainBase *domain, const cmif::PointerAndSize &in_raw_data) const {
const CmifDomainInHeader *in_header = reinterpret_cast<const CmifDomainInHeader *>(in_raw_data.GetPointer());
R_UNLESS(in_raw_data.GetSize() >= sizeof(*in_header), ResultServiceFrameworkInvalidCmifHeaderSize);
R_UNLESS(in_raw_data.GetSize() >= sizeof(*in_header), sf::cmif::ResultInvalidHeaderSize());
const cmif::PointerAndSize in_domain_raw_data = cmif::PointerAndSize(in_raw_data.GetAddress() + sizeof(*in_header), in_raw_data.GetSize() - sizeof(*in_header));
const DomainObjectId target_object_id = DomainObjectId{in_header->object_id};
@@ -36,11 +36,11 @@ namespace sts::sf::cmif {
case CmifDomainRequestType_SendMessage:
{
auto target_object = domain->GetObject(target_object_id);
R_UNLESS(static_cast<bool>(target_object), ResultServiceFrameworkTargetNotFound);
R_UNLESS(in_header->data_size + in_header->num_in_objects * sizeof(DomainObjectId) <= in_domain_raw_data.GetSize(), ResultServiceFrameworkInvalidCmifHeaderSize);
R_UNLESS(static_cast<bool>(target_object), sf::cmif::ResultTargetNotFound());
R_UNLESS(in_header->data_size + in_header->num_in_objects * sizeof(DomainObjectId) <= in_domain_raw_data.GetSize(), sf::cmif::ResultInvalidHeaderSize());
const cmif::PointerAndSize in_message_raw_data = cmif::PointerAndSize(in_domain_raw_data.GetAddress(), in_header->data_size);
DomainObjectId in_object_ids[8];
R_UNLESS(in_header->num_in_objects <= util::size(in_object_ids), ResultServiceFrameworkInvalidCmifNumInObjects);
R_UNLESS(in_header->num_in_objects <= util::size(in_object_ids), sf::cmif::ResultInvalidNumInObjects());
std::memcpy(in_object_ids, reinterpret_cast<DomainObjectId *>(in_message_raw_data.GetAddress() + in_message_raw_data.GetSize()), sizeof(DomainObjectId) * in_header->num_in_objects);
DomainServiceObjectProcessor domain_processor(domain, in_object_ids, in_header->num_in_objects);
if (ctx.processor == nullptr) {
@@ -54,15 +54,15 @@ namespace sts::sf::cmif {
case CmifDomainRequestType_Close:
/* TODO: N doesn't error check here. Should we? */
domain->UnregisterObject(target_object_id);
return ResultSuccess;
return ResultSuccess();
default:
return ResultServiceFrameworkInvalidCmifInHeader;
return sf::cmif::ResultInvalidInHeader();
}
}
Result DomainServiceObjectDispatchTable::ProcessMessageForMitmImpl(ServiceDispatchContext &ctx, ServerDomainBase *domain, const cmif::PointerAndSize &in_raw_data) const {
const CmifDomainInHeader *in_header = reinterpret_cast<const CmifDomainInHeader *>(in_raw_data.GetPointer());
R_UNLESS(in_raw_data.GetSize() >= sizeof(*in_header), ResultServiceFrameworkInvalidCmifHeaderSize);
R_UNLESS(in_raw_data.GetSize() >= sizeof(*in_header), sf::cmif::ResultInvalidHeaderSize());
const cmif::PointerAndSize in_domain_raw_data = cmif::PointerAndSize(in_raw_data.GetAddress() + sizeof(*in_header), in_raw_data.GetSize() - sizeof(*in_header));
const DomainObjectId target_object_id = DomainObjectId{in_header->object_id};
@@ -76,10 +76,10 @@ namespace sts::sf::cmif {
return ctx.session->ForwardRequest(ctx);
}
R_UNLESS(in_header->data_size + in_header->num_in_objects * sizeof(DomainObjectId) <= in_domain_raw_data.GetSize(), ResultServiceFrameworkInvalidCmifHeaderSize);
R_UNLESS(in_header->data_size + in_header->num_in_objects * sizeof(DomainObjectId) <= in_domain_raw_data.GetSize(), sf::cmif::ResultInvalidHeaderSize());
const cmif::PointerAndSize in_message_raw_data = cmif::PointerAndSize(in_domain_raw_data.GetAddress(), in_header->data_size);
DomainObjectId in_object_ids[8];
R_UNLESS(in_header->num_in_objects <= util::size(in_object_ids), ResultServiceFrameworkInvalidCmifNumInObjects);
R_UNLESS(in_header->num_in_objects <= util::size(in_object_ids), sf::cmif::ResultInvalidNumInObjects());
std::memcpy(in_object_ids, reinterpret_cast<DomainObjectId *>(in_message_raw_data.GetAddress() + in_message_raw_data.GetSize()), sizeof(DomainObjectId) * in_header->num_in_objects);
DomainServiceObjectProcessor domain_processor(domain, in_object_ids, in_header->num_in_objects);
if (ctx.processor == nullptr) {
@@ -101,16 +101,16 @@ namespace sts::sf::cmif {
/* 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. */
domain->UnregisterObject(target_object_id);
return ResultSuccess;
return ResultSuccess();
}
default:
return ResultServiceFrameworkInvalidCmifInHeader;
return sf::cmif::ResultInvalidInHeader();
}
}
Result DomainServiceObjectProcessor::PrepareForProcess(const ServiceDispatchContext &ctx, const ServerMessageRuntimeMetadata runtime_metadata) const {
/* Validate in object count. */
R_UNLESS(this->impl_metadata.GetInObjectCount() == this->GetInObjectCount(), ResultServiceFrameworkInvalidCmifNumInObjects);
R_UNLESS(this->impl_metadata.GetInObjectCount() == this->GetInObjectCount(), sf::cmif::ResultInvalidNumInObjects());
/* Nintendo reserves domain object IDs here. We do this later, to support mitm semantics. */
@@ -122,7 +122,7 @@ namespace sts::sf::cmif {
for (size_t i = 0; i < this->GetInObjectCount(); i++) {
in_objects[i] = this->domain->GetObject(this->in_object_ids[i]);
}
return ResultSuccess;
return ResultSuccess();
}
HipcRequest DomainServiceObjectProcessor::PrepareForReply(const cmif::ServiceDispatchContext &ctx, PointerAndSize &out_raw_data, const ServerMessageRuntimeMetadata runtime_metadata) {

View File

@@ -24,8 +24,8 @@ namespace sts::sf::cmif {
/* Parse the CMIF in header. */
const CmifInHeader *in_header = reinterpret_cast<const CmifInHeader *>(in_raw_data.GetPointer());
R_UNLESS(in_raw_data.GetSize() >= sizeof(*in_header), ResultServiceFrameworkInvalidCmifHeaderSize);
R_UNLESS(in_header->magic == CMIF_IN_HEADER_MAGIC && in_header->version <= max_cmif_version, ResultServiceFrameworkInvalidCmifInHeader);
R_UNLESS(in_raw_data.GetSize() >= sizeof(*in_header), sf::cmif::ResultInvalidHeaderSize());
R_UNLESS(in_header->magic == CMIF_IN_HEADER_MAGIC && in_header->version <= max_cmif_version, sf::cmif::ResultInvalidInHeader());
const cmif::PointerAndSize in_message_raw_data = cmif::PointerAndSize(in_raw_data.GetAddress() + sizeof(*in_header), in_raw_data.GetSize() - sizeof(*in_header));
const u32 cmd_id = in_header->command_id;
@@ -37,7 +37,7 @@ namespace sts::sf::cmif {
break;
}
}
R_UNLESS(cmd_handler != nullptr, ResultServiceFrameworkUnknownCmifCommandId);
R_UNLESS(cmd_handler != nullptr, sf::cmif::ResultUnknownCommandId());
/* Invoke handler. */
CmifOutHeader *out_header = nullptr;
@@ -45,16 +45,16 @@ namespace sts::sf::cmif {
/* Forward forwardable results, otherwise ensure we can send result to user. */
R_TRY_CATCH(command_result) {
R_CATCH(ResultServiceFrameworkRequestDeferredByUser) { return ResultServiceFrameworkRequestDeferredByUser; }
R_CATCH(sf::impl::ResultRequestContextChanged) { return R_CURRENT_RESULT; }
R_CATCH_ALL() { STS_ASSERT(out_header != nullptr); }
} R_END_TRY_CATCH;
/* Write output header to raw data. */
if (out_header != nullptr) {
*out_header = CmifOutHeader{CMIF_OUT_HEADER_MAGIC, 0, command_result, 0};
*out_header = CmifOutHeader{CMIF_OUT_HEADER_MAGIC, 0, command_result.GetValue(), 0};
}
return ResultSuccess;
return ResultSuccess();
}
Result impl::ServiceDispatchTableBase::ProcessMessageForMitmImpl(ServiceDispatchContext &ctx, const cmif::PointerAndSize &in_raw_data, const ServiceCommandMeta *entries, const size_t entry_count) const {
@@ -64,8 +64,8 @@ namespace sts::sf::cmif {
/* Parse the CMIF in header. */
const CmifInHeader *in_header = reinterpret_cast<const CmifInHeader *>(in_raw_data.GetPointer());
R_UNLESS(in_raw_data.GetSize() >= sizeof(*in_header), ResultServiceFrameworkInvalidCmifHeaderSize);
R_UNLESS(in_header->magic == CMIF_IN_HEADER_MAGIC && in_header->version <= max_cmif_version, ResultServiceFrameworkInvalidCmifInHeader);
R_UNLESS(in_raw_data.GetSize() >= sizeof(*in_header), sf::cmif::ResultInvalidHeaderSize());
R_UNLESS(in_header->magic == CMIF_IN_HEADER_MAGIC && in_header->version <= max_cmif_version, sf::cmif::ResultInvalidInHeader());
const cmif::PointerAndSize in_message_raw_data = cmif::PointerAndSize(in_raw_data.GetAddress() + sizeof(*in_header), in_raw_data.GetSize() - sizeof(*in_header));
const u32 cmd_id = in_header->command_id;
@@ -89,19 +89,19 @@ namespace sts::sf::cmif {
/* Forward forwardable results, otherwise ensure we can send result to user. */
R_TRY_CATCH(command_result) {
R_CATCH(ResultServiceFrameworkRequestDeferredByUser) { return ResultServiceFrameworkRequestDeferredByUser; }
R_CATCH(ResultAtmosphereMitmShouldForwardToSession) {
R_CATCH(ams::mitm::ResultShouldForwardToSession) {
return ctx.session->ForwardRequest(ctx);
}
R_CATCH(sf::impl::ResultRequestContextChanged) { return R_CURRENT_RESULT; }
R_CATCH_ALL() { STS_ASSERT(out_header != nullptr); }
} R_END_TRY_CATCH;
/* Write output header to raw data. */
if (out_header != nullptr) {
*out_header = CmifOutHeader{CMIF_OUT_HEADER_MAGIC, 0, command_result, 0};
*out_header = CmifOutHeader{CMIF_OUT_HEADER_MAGIC, 0, command_result.GetValue(), 0};
}
return ResultSuccess;
return ResultSuccess();
}
}

View File

@@ -43,34 +43,34 @@ namespace sts::sf::hipc {
Result Receive(ReceiveResult *out_recv_result, Handle session_handle, const cmif::PointerAndSize &message_buffer) {
R_TRY_CATCH(ReceiveImpl(session_handle, message_buffer.GetPointer(), message_buffer.GetSize())) {
R_CATCH(ResultKernelConnectionClosed) {
R_CATCH(svc::ResultSessionClosed) {
*out_recv_result = ReceiveResult::Closed;
return ResultSuccess;
return ResultSuccess();
}
R_CATCH(ResultKernelReceiveListBroken) {
R_CATCH(svc::ResultReceiveListBroken) {
*out_recv_result = ReceiveResult::NeedsRetry;
return ResultSuccess;
return ResultSuccess();
}
} R_END_TRY_CATCH;
*out_recv_result = ReceiveResult::Success;
return ResultSuccess;
return ResultSuccess();
}
Result Receive(bool *out_closed, Handle session_handle, const cmif::PointerAndSize &message_buffer) {
R_TRY_CATCH(ReceiveImpl(session_handle, message_buffer.GetPointer(), message_buffer.GetSize())) {
R_CATCH(ResultKernelConnectionClosed) {
R_CATCH(svc::ResultSessionClosed) {
*out_closed = true;
return ResultSuccess;
return ResultSuccess();
}
} R_END_TRY_CATCH;
*out_closed = false;
return ResultSuccess;
return ResultSuccess();
}
Result Reply(Handle session_handle, const cmif::PointerAndSize &message_buffer) {
R_TRY_CATCH(ReplyImpl(session_handle, message_buffer.GetPointer(), message_buffer.GetSize())) {
R_CATCH(ResultKernelTimedOut) { return ResultSuccess; }
R_CATCH(ResultKernelConnectionClosed) { return ResultSuccess; }
R_CONVERT(svc::ResultTimedOut, ResultSuccess())
R_CONVERT(svc::ResultSessionClosed, ResultSuccess())
} R_END_TRY_CATCH;
/* ReplyImpl should *always* return an error. */
STS_ASSERT(false);
@@ -78,9 +78,9 @@ namespace sts::sf::hipc {
Result CreateSession(Handle *out_server_handle, Handle *out_client_handle) {
R_TRY_CATCH(svcCreateSession(out_server_handle, out_client_handle, 0, 0)) {
R_CATCH(ResultKernelResourceExhausted) { return ResultHipcOutOfSessions; }
R_CONVERT(svc::ResultOutOfResource, sf::hipc::ResultOutOfSessions());
} R_END_TRY_CATCH;
return ResultSuccess;
return ResultSuccess();
}
}

View File

@@ -36,7 +36,7 @@ namespace sts::sf::hipc {
Result CloneCurrentObjectImpl(Handle *out_client_handle, ServerSessionManager *tagged_manager) {
/* Clone the object. */
cmif::ServiceObjectHolder &&clone = this->session->srv_obj_holder.Clone();
R_UNLESS(clone, ResultHipcDomainObjectNotFound);
R_UNLESS(clone, sf::hipc::ResultDomainObjectNotFound());
/* Create new session handles. */
Handle server_handle;
@@ -52,7 +52,7 @@ namespace sts::sf::hipc {
R_ASSERT(tagged_manager->RegisterMitmSession(server_handle, std::move(clone), std::move(new_forward_service)));
}
return ResultSuccess;
return ResultSuccess();
}
public:
explicit HipcManager(ServerDomainSessionManager *m, ServerSession *s) : manager(m), session(s), is_mitm_session(s->forward_service != nullptr) {
@@ -62,7 +62,8 @@ namespace sts::sf::hipc {
Result ConvertCurrentObjectToDomain(sf::Out<cmif::DomainObjectId> out) {
/* Allocate a domain. */
auto domain = this->manager->AllocateDomainServiceObject();
R_UNLESS(domain, ResultHipcOutOfDomains);
R_UNLESS(domain, sf::hipc::ResultOutOfDomains());
auto domain_guard = SCOPE_GUARD { this->manager->FreeDomainServiceObject(domain); };
cmif::DomainObjectId object_id = cmif::InvalidDomainObjectId;
@@ -71,9 +72,7 @@ namespace sts::sf::hipc {
if (this->is_mitm_session) {
/* If we're a mitm session, we need to convert the remote session to domain. */
STS_ASSERT(session->forward_service->own_handle);
R_TRY_CLEANUP(serviceConvertToDomain(session->forward_service.get()), {
this->manager->FreeDomainServiceObject(domain);
});
R_TRY(serviceConvertToDomain(session->forward_service.get()));
/* The object ID reservation cannot fail here, as that would cause desynchronization from target domain. */
object_id = cmif::DomainObjectId{session->forward_service->object_id};
@@ -99,22 +98,23 @@ namespace sts::sf::hipc {
STS_ASSERT(static_cast<bool>(new_holder));
/* We succeeded! */
domain_guard.Cancel();
domain->RegisterObject(object_id, std::move(session->srv_obj_holder));
session->srv_obj_holder = std::move(new_holder);
out.SetValue(object_id);
return ResultSuccess;
return ResultSuccess();
}
Result CopyFromCurrentDomain(sf::OutMoveHandle out, cmif::DomainObjectId object_id) {
/* Get domain. */
auto domain = this->session->srv_obj_holder.GetServiceObject<cmif::DomainServiceObject>();
R_UNLESS(domain != nullptr, ResultHipcTargetNotDomain);
R_UNLESS(domain != nullptr, sf::hipc::ResultTargetNotDomain());
/* Get domain object. */
auto &&object = domain->GetObject(object_id);
if (!object) {
R_UNLESS(this->is_mitm_session, ResultHipcDomainObjectNotFound);
R_UNLESS(this->is_mitm_session, sf::hipc::ResultDomainObjectNotFound());
return cmifCopyFromCurrentDomain(this->session->forward_service->session, object_id.value, out.GetHandlePointer());
}
@@ -140,7 +140,7 @@ namespace sts::sf::hipc {
R_ASSERT(this->manager->RegisterMitmSession(server_handle, std::move(object), std::move(new_forward_service)));
}
return ResultSuccess;
return ResultSuccess();
}
Result CloneCurrentObject(sf::OutMoveHandle out) {

View File

@@ -124,7 +124,12 @@ namespace sts::sf::hipc {
std::memcpy(tls_message.GetPointer(), saved_message.GetPointer(), tls_message.GetSize());
}
return this->ProcessRequest(session, tls_message);
/* Treat a meta "Context Invalidated" message as a success. */
R_TRY_CATCH(this->ProcessRequest(session, tls_message)) {
R_CONVERT(sf::impl::ResultRequestInvalidated, ResultSuccess());
} R_END_TRY_CATCH;
return ResultSuccess();
}
void ServerManagerBase::ProcessDeferredSessions() {
@@ -135,12 +140,16 @@ namespace sts::sf::hipc {
while (it != this->deferred_session_list.end()) {
ServerSession *session = static_cast<ServerSession *>(&*it);
R_TRY_CATCH(this->ProcessForSession(session)) {
R_CATCH(ResultServiceFrameworkRequestDeferredByUser) {
R_CATCH(sf::ResultRequestDeferred) {
/* Session is still deferred, so let's continue. */
it++;
continue;
}
/* TODO: N has a result that undefers without success. */
R_CATCH(sf::impl::ResultRequestInvalidated) {
/* Session is no longer deferred! */
it = this->deferred_session_list.erase(it);
continue;
}
} R_END_TRY_CATCH_WITH_ASSERT;
/* We succeeded! Remove from deferred list. */
@@ -159,17 +168,17 @@ namespace sts::sf::hipc {
case UserDataTag::Session:
/* Try to process for session. */
R_TRY_CATCH(this->ProcessForSession(holder)) {
R_CATCH(ResultServiceFrameworkRequestDeferredByUser) {
R_CATCH(sf::ResultRequestDeferred) {
/* The session was deferred, so push it onto the deferred session list. */
std::scoped_lock lk(this->deferred_session_mutex);
this->deferred_session_list.push_back(*static_cast<ServerSession *>(holder));
return ResultSuccess;
return ResultSuccess();
}
} R_END_TRY_CATCH;
/* We successfully invoked a command...so let's see if anything can be undeferred. */
this->ProcessDeferredSessions();
return ResultSuccess;
return ResultSuccess();
break;
STS_UNREACHABLE_DEFAULT_CASE();
}

View File

@@ -65,7 +65,7 @@ namespace sts::sf::hipc {
}
}
return ResultSuccess;
return ResultSuccess();
}
void ServerSessionManager::DestroySession(ServerSession *session) {
@@ -89,7 +89,7 @@ namespace sts::sf::hipc {
session_memory->saved_message = this->GetSessionSavedMessageBuffer(session_memory);
/* Register to wait list. */
this->RegisterSessionToWaitList(session_memory);
return ResultSuccess;
return ResultSuccess();
}
Result ServerSessionManager::AcceptSessionImpl(ServerSession *session_memory, Handle port_handle, cmif::ServiceObjectHolder &&obj) {
@@ -105,7 +105,7 @@ namespace sts::sf::hipc {
/* Register session. */
R_TRY(this->RegisterSessionImpl(session_memory, session_handle, std::forward<cmif::ServiceObjectHolder>(obj)));
succeeded = true;
return ResultSuccess;
return ResultSuccess();
}
Result ServerSessionManager::RegisterMitmSessionImpl(ServerSession *session_memory, Handle mitm_session_handle, cmif::ServiceObjectHolder &&obj, std::shared_ptr<::Service> &&fsrv) {
@@ -119,7 +119,7 @@ namespace sts::sf::hipc {
session_memory->pointer_buffer = cmif::PointerAndSize(session_memory->pointer_buffer.GetAddress(), session_memory->forward_service->pointer_buffer_size);
/* Register to wait list. */
this->RegisterSessionToWaitList(session_memory);
return ResultSuccess;
return ResultSuccess();
}
Result ServerSessionManager::AcceptMitmSessionImpl(ServerSession *session_memory, Handle mitm_port_handle, cmif::ServiceObjectHolder &&obj, std::shared_ptr<::Service> &&fsrv) {
@@ -135,7 +135,7 @@ namespace sts::sf::hipc {
/* Register session. */
R_TRY(this->RegisterMitmSessionImpl(session_memory, mitm_session_handle, std::forward<cmif::ServiceObjectHolder>(obj), std::forward<std::shared_ptr<::Service>>(fsrv)));
succeeded = true;
return ResultSuccess;
return ResultSuccess();
}
Result ServerSessionManager::RegisterSession(Handle session_handle, cmif::ServiceObjectHolder &&obj) {
@@ -182,10 +182,10 @@ namespace sts::sf::hipc {
switch (recv_result) {
case hipc::ReceiveResult::Success:
session->is_closed = false;
return ResultSuccess;
return ResultSuccess();
case hipc::ReceiveResult::Closed:
session->is_closed = true;
return ResultSuccess;
return ResultSuccess();
case hipc::ReceiveResult::NeedsRetry:
continue;
STS_UNREACHABLE_DEFAULT_CASE();
@@ -206,29 +206,31 @@ namespace sts::sf::hipc {
Result ServerSessionManager::ProcessRequest(ServerSession *session, const cmif::PointerAndSize &message) {
if (session->is_closed) {
this->CloseSessionImpl(session);
return ResultSuccess;
return ResultSuccess();
}
switch (GetCmifCommandType(message)) {
case CmifCommandType_Close:
{
this->CloseSessionImpl(session);
return ResultSuccess;
return ResultSuccess();
}
default:
{
R_TRY_CATCH(this->ProcessRequestImpl(session, message, message)) {
R_CATCH(ResultServiceFrameworkRequestDeferredByUser) { /* TODO: Properly include entire range Nintendo does */
return ResultServiceFrameworkRequestDeferredByUser;
R_CATCH(sf::impl::ResultRequestContextChanged) {
/* A meta message changing the request context has been sent. */
return R_CURRENT_RESULT;
}
R_CATCH_ALL() {
/* All other results indicate something went very wrong. */
this->CloseSessionImpl(session);
return ResultSuccess;
return ResultSuccess();
}
} R_END_TRY_CATCH;
/* We succeeded, so we can process future messages on this session. */
this->RegisterSessionToWaitList(session);
return ResultSuccess;
return ResultSuccess();
}
}
}
@@ -244,13 +246,13 @@ namespace sts::sf::hipc {
case CmifCommandType_ControlWithContext:
return this->DispatchManagerRequest(session, in_message, out_message);
default:
return ResultHipcUnknownCommandType;
return sf::hipc::ResultUnknownCommandType();
}
}
Result ServerSessionManager::DispatchManagerRequest(ServerSession *session, const cmif::PointerAndSize &in_message, const cmif::PointerAndSize &out_message) {
/* This will get overridden by ... WithDomain class. */
return ResultServiceFrameworkNotSupported;
return sf::ResultNotSupported();
}
Result ServerSessionManager::DispatchRequest(cmif::ServiceObjectHolder &&obj_holder, ServerSession *session, const cmif::PointerAndSize &in_message, const cmif::PointerAndSize &out_message) {
@@ -273,10 +275,10 @@ namespace sts::sf::hipc {
const uintptr_t in_raw_addr = reinterpret_cast<uintptr_t>(dispatch_ctx.request.data.data_words);
const size_t in_raw_size = dispatch_ctx.request.meta.num_data_words * sizeof(u32);
/* Note: Nintendo does not validate this size before subtracting 0x10 from it. This is not exploitable. */
R_UNLESS(in_raw_size >= 0x10, ResultHipcInvalidRequestSize);
R_UNLESS(in_raw_addr + in_raw_size <= in_message_buffer_end, ResultHipcInvalidRequestSize);
R_UNLESS(in_raw_size >= 0x10, sf::hipc::ResultInvalidRequestSize());
R_UNLESS(in_raw_addr + in_raw_size <= in_message_buffer_end, sf::hipc::ResultInvalidRequestSize());
const uintptr_t recv_list_end = reinterpret_cast<uintptr_t>(dispatch_ctx.request.data.recv_list + dispatch_ctx.request.meta.num_recv_statics);
R_UNLESS(recv_list_end <= in_message_buffer_end, ResultHipcInvalidRequestSize);
R_UNLESS(recv_list_end <= in_message_buffer_end, sf::hipc::ResultInvalidRequestSize());
/* CMIF has 0x10 of padding in raw data, and requires 0x10 alignment. */
const cmif::PointerAndSize in_raw_data(util::AlignUp(in_raw_addr, 0x10), in_raw_size - 0x10);
@@ -294,7 +296,7 @@ namespace sts::sf::hipc {
R_TRY(hipc::Reply(session->session_handle, out_message));
}
return ResultSuccess;
return ResultSuccess();
}