mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-05-17 08:34:23 -04:00
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:
parent
375ba615be
commit
96f95b9f95
109 changed files with 1355 additions and 1380 deletions
|
@ -43,21 +43,17 @@ namespace ams::kern::svc {
|
|||
/* Try to allocate a session from unused slab memory. */
|
||||
session = T::CreateFromUnusedSlabMemory();
|
||||
R_UNLESS(session != nullptr, svc::ResultLimitReached());
|
||||
ON_RESULT_FAILURE { session->Close(); };
|
||||
|
||||
/* If we're creating a KSession, we want to add two KSessionRequests to the heap, to prevent request exhaustion. */
|
||||
/* NOTE: Nintendo checks if session->DynamicCast<KSession *>() != nullptr, but there's no reason to not do this statically. */
|
||||
if constexpr (std::same_as<T, KSession>) {
|
||||
/* Ensure that if we fail to allocate our session requests, we close the session we created. */
|
||||
auto session_guard = SCOPE_GUARD { session->Close(); };
|
||||
{
|
||||
for (size_t i = 0; i < 2; ++i) {
|
||||
KSessionRequest *request = KSessionRequest::CreateFromUnusedSlabMemory();
|
||||
R_UNLESS(request != nullptr, svc::ResultLimitReached());
|
||||
for (size_t i = 0; i < 2; ++i) {
|
||||
KSessionRequest *request = KSessionRequest::CreateFromUnusedSlabMemory();
|
||||
R_UNLESS(request != nullptr, svc::ResultLimitReached());
|
||||
|
||||
request->Close();
|
||||
}
|
||||
request->Close();
|
||||
}
|
||||
session_guard.Cancel();
|
||||
}
|
||||
|
||||
/* We successfully allocated a session, so add the object we allocated to the resource limit. */
|
||||
|
@ -86,21 +82,17 @@ namespace ams::kern::svc {
|
|||
R_TRY(handle_table.Add(out_server, std::addressof(session->GetServerSession())));
|
||||
|
||||
/* Ensure that we maintaing a clean handle state on exit. */
|
||||
auto handle_guard = SCOPE_GUARD { handle_table.Remove(*out_server); };
|
||||
ON_RESULT_FAILURE { handle_table.Remove(*out_server); };
|
||||
|
||||
/* Add the client session to the handle table. */
|
||||
R_TRY(handle_table.Add(out_client, std::addressof(session->GetClientSession())));
|
||||
|
||||
/* We succeeded! */
|
||||
handle_guard.Cancel();
|
||||
return ResultSuccess();
|
||||
R_RETURN(handle_table.Add(out_client, std::addressof(session->GetClientSession())));
|
||||
}
|
||||
|
||||
Result CreateSession(ams::svc::Handle *out_server, ams::svc::Handle *out_client, bool is_light, uintptr_t name) {
|
||||
if (is_light) {
|
||||
return CreateSession<KLightSession>(out_server, out_client, name);
|
||||
R_RETURN(CreateSession<KLightSession>(out_server, out_client, name));
|
||||
} else {
|
||||
return CreateSession<KSession>(out_server, out_client, name);
|
||||
R_RETURN(CreateSession<KSession>(out_server, out_client, name));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -114,7 +106,7 @@ namespace ams::kern::svc {
|
|||
|
||||
/* Reserve an entry for the new session. */
|
||||
R_TRY(handle_table.Reserve(out));
|
||||
auto handle_guard = SCOPE_GUARD { handle_table.Unreserve(*out); };
|
||||
ON_RESULT_FAILURE { handle_table.Unreserve(*out); };
|
||||
|
||||
/* Accept the session. */
|
||||
KAutoObject *session;
|
||||
|
@ -129,10 +121,9 @@ namespace ams::kern::svc {
|
|||
|
||||
/* Register the session. */
|
||||
handle_table.Register(*out, session);
|
||||
handle_guard.Cancel();
|
||||
session->Close();
|
||||
|
||||
return ResultSuccess();
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -140,21 +131,21 @@ namespace ams::kern::svc {
|
|||
/* ============================= 64 ABI ============================= */
|
||||
|
||||
Result CreateSession64(ams::svc::Handle *out_server_session_handle, ams::svc::Handle *out_client_session_handle, bool is_light, ams::svc::Address name) {
|
||||
return CreateSession(out_server_session_handle, out_client_session_handle, is_light, name);
|
||||
R_RETURN(CreateSession(out_server_session_handle, out_client_session_handle, is_light, name));
|
||||
}
|
||||
|
||||
Result AcceptSession64(ams::svc::Handle *out_handle, ams::svc::Handle port) {
|
||||
return AcceptSession(out_handle, port);
|
||||
R_RETURN(AcceptSession(out_handle, port));
|
||||
}
|
||||
|
||||
/* ============================= 64From32 ABI ============================= */
|
||||
|
||||
Result CreateSession64From32(ams::svc::Handle *out_server_session_handle, ams::svc::Handle *out_client_session_handle, bool is_light, ams::svc::Address name) {
|
||||
return CreateSession(out_server_session_handle, out_client_session_handle, is_light, name);
|
||||
R_RETURN(CreateSession(out_server_session_handle, out_client_session_handle, is_light, name));
|
||||
}
|
||||
|
||||
Result AcceptSession64From32(ams::svc::Handle *out_handle, ams::svc::Handle port) {
|
||||
return AcceptSession(out_handle, port);
|
||||
R_RETURN(AcceptSession(out_handle, port));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue