ams: mark ams::Result [[nodiscard]] (partially complete).

NOTE: This work is not yet fully complete; kernel is done, but
it was taking an exceedingly long time to get through libstratosphere.
Thus, I've temporarily added -Wno-error=unused-result for libstratosphere/stratosphere.

All warnings should be fixed to do the same thing Nintendo does as relevant, but this
is taking a phenomenally long time and is not actually the most important work to do,
so it can be put off for some time to prioritize other tasks for 21.0.0 support.
This commit is contained in:
Michael Scire
2025-11-11 16:13:25 -07:00
parent 0b9cf32cdc
commit 98e131fcd1
86 changed files with 444 additions and 455 deletions

View File

@@ -750,7 +750,9 @@ namespace ams::htcs::client {
if (index = this->Find(set->fds[i], std::addressof(error_code)); index >= 0) {
/* Get the primitive, if necessary. */
if (m_socket_list[index].m_primitive == InvalidPrimitive && m_socket_list[index].m_socket != nullptr) {
m_socket_list[index].m_socket->GetPrimitive(std::addressof(m_socket_list[index].m_primitive));
if (R_FAILED(m_socket_list[index].m_socket->GetPrimitive(std::addressof(m_socket_list[index].m_primitive)))) {
/* Nintendo doesn't do anything here? */
}
}
primitive = m_socket_list[index].m_primitive;
@@ -769,7 +771,9 @@ namespace ams::htcs::client {
/* Get the primitive. */
if (index = this->Find(set->fds[i], std::addressof(error_code)); index >= 0) {
m_socket_list[index].m_socket->GetPrimitive(std::addressof(m_socket_list[index].m_primitive));
if (R_FAILED(m_socket_list[index].m_socket->GetPrimitive(std::addressof(m_socket_list[index].m_primitive)))) {
/* Nintendo doesn't do anything here? */
}
primitive = m_socket_list[index].m_primitive;
}

View File

@@ -54,7 +54,7 @@ namespace ams::htcs {
R_ABORT_UNLESS(g_monitor->MonitorManager(process_id));
/* Allocate a tls slot for our last error. */
os::SdkAllocateTlsSlot(std::addressof(g_tls_slot), nullptr);
R_ABORT_UNLESS(os::SdkAllocateTlsSlot(std::addressof(g_tls_slot), nullptr));
/* Setup the virtual socket collection. */
AMS_ASSERT(buffer != nullptr);
@@ -185,7 +185,7 @@ namespace ams::htcs {
/* Get name. */
HtcsPeerName name;
g_manager->GetPeerNameAny(std::addressof(name));
static_cast<void>(g_manager->GetPeerNameAny(std::addressof(name)));
return name;
}
@@ -196,7 +196,7 @@ namespace ams::htcs {
/* Get name. */
HtcsPeerName name;
g_manager->GetDefaultHostName(std::addressof(name));
static_cast<void>(g_manager->GetDefaultHostName(std::addressof(name)));
return name;
}
@@ -472,7 +472,7 @@ namespace ams::htcs {
s32 close(sf::SharedPointer<tma::ISocket> socket, s32 &last_error) {
s32 res;
socket->Close(std::addressof(last_error), std::addressof(res));
static_cast<void>(socket->Close(std::addressof(last_error), std::addressof(res)));
return res;
}
@@ -484,13 +484,13 @@ namespace ams::htcs {
util::Strlcpy(null_terminated_address.port_name.name, address->port_name.name, PortNameBufferLength);
s32 res;
socket->Bind(std::addressof(last_error), std::addressof(res), null_terminated_address);
static_cast<void>(socket->Bind(std::addressof(last_error), std::addressof(res), null_terminated_address));
return res;
}
s32 listen(sf::SharedPointer<tma::ISocket> socket, s32 backlog_count, s32 &last_error) {
s32 res;
socket->Listen(std::addressof(last_error), std::addressof(res), backlog_count);
static_cast<void>(socket->Listen(std::addressof(last_error), std::addressof(res), backlog_count));
return res;
}
@@ -512,7 +512,7 @@ namespace ams::htcs {
os::WaitSystemEvent(std::addressof(event));
/* End the accept. */
socket->AcceptResults(std::addressof(last_error), std::addressof(res), address, task_id);
static_cast<void>(socket->AcceptResults(std::addressof(last_error), std::addressof(res), address, task_id));
} else {
/* Set error. */
last_error = HTCS_EINTR;
@@ -528,13 +528,13 @@ namespace ams::htcs {
s32 fcntl(sf::SharedPointer<tma::ISocket> socket, s32 command, s32 value, s32 &last_error) {
s32 res;
socket->Fcntl(std::addressof(last_error), std::addressof(res), command, value);
static_cast<void>(socket->Fcntl(std::addressof(last_error), std::addressof(res), command, value));
return res;
}
s32 shutdown(sf::SharedPointer<tma::ISocket> socket, s32 how, s32 &last_error) {
s32 res;
socket->Shutdown(std::addressof(last_error), std::addressof(res), how);
static_cast<void>(socket->Shutdown(std::addressof(last_error), std::addressof(res), how));
return res;
}
@@ -546,7 +546,7 @@ namespace ams::htcs {
util::Strlcpy(null_terminated_address.port_name.name, address->port_name.name, PortNameBufferLength);
s32 res;
socket->Connect(std::addressof(last_error), std::addressof(res), null_terminated_address);
static_cast<void>(socket->Connect(std::addressof(last_error), std::addressof(res), null_terminated_address));
return res;
}
@@ -579,7 +579,7 @@ namespace ams::htcs {
os::WaitSystemEvent(std::addressof(event));
/* End the select. */
g_manager->EndSelect(std::addressof(last_error), std::addressof(res), OutArray(read, num_read), OutArray(write, num_write), OutArray(except, num_except), task_id);
static_cast<void>(g_manager->EndSelect(std::addressof(last_error), std::addressof(res), OutArray(read, num_read), OutArray(write, num_write), OutArray(except, num_except), task_id));
} else {
/* Set error. */
last_error = HTCS_EINTR;
@@ -614,7 +614,7 @@ namespace ams::htcs {
os::WaitSystemEvent(std::addressof(event));
/* End the receive. */
socket->EndRecv(std::addressof(last_error), std::addressof(res), sf::OutAutoSelectBuffer(buffer, buffer_size), task_id);
static_cast<void>(socket->EndRecv(std::addressof(last_error), std::addressof(res), sf::OutAutoSelectBuffer(buffer, buffer_size), task_id));
} else {
/* Set error. */
last_error = HTCS_EINTR;
@@ -675,7 +675,7 @@ namespace ams::htcs {
}
/* End the send. */
socket->EndSend(std::addressof(last_error), std::addressof(res), task_id);
static_cast<void>(socket->EndSend(std::addressof(last_error), std::addressof(res), task_id));
} else {
/* Set error. */
last_error = HTCS_EINTR;
@@ -717,7 +717,7 @@ namespace ams::htcs {
os::WaitSystemEvent(std::addressof(event));
/* End the receive. */
socket->RecvResults(std::addressof(last_error), std::addressof(res), sf::OutAutoSelectBuffer(buffer, recv_size), task_id);
static_cast<void>(socket->RecvResults(std::addressof(last_error), std::addressof(res), sf::OutAutoSelectBuffer(buffer, recv_size), task_id));
} else {
/* Set error. */
last_error = HTCS_EINTR;
@@ -750,7 +750,7 @@ namespace ams::htcs {
os::WaitSystemEvent(std::addressof(event));
/* End the send. */
socket->SendResults(std::addressof(last_error), std::addressof(res), task_id);
static_cast<void>(socket->SendResults(std::addressof(last_error), std::addressof(res), task_id));
} else {
/* Set error. */
last_error = HTCS_EINTR;

View File

@@ -101,7 +101,7 @@ namespace ams::htcs::impl {
Result HtcsManagerImpl::SendStart(u32 *out_task_id, os::NativeHandle *out_handle, const char *buffer, s64 size, s32 desc, s32 flags) {
/* Start the send. */
u32 task_id{};
os::NativeHandle handle;
os::NativeHandle handle = os::InvalidNativeHandle;
R_TRY(m_service.SendSmallStart(std::addressof(task_id), std::addressof(handle), desc, size, flags));
/* Continue the send. */
@@ -113,14 +113,16 @@ namespace ams::htcs::impl {
R_SUCCEED();
} else {
os::SystemEventType event;
os::AttachReadableHandleToSystemEvent(std::addressof(event), handle, true, os::EventClearMode_ManualClear);
s32 err;
s64 rsize;
m_service.SendSmallResults(std::addressof(err), std::addressof(rsize), task_id, desc);
static_cast<void>(m_service.SendSmallResults(std::addressof(err), std::addressof(rsize), task_id, desc));
os::DestroySystemEvent(std::addressof(event));
if (handle != os::InvalidNativeHandle) {
os::SystemEventType event;
os::AttachReadableHandleToSystemEvent(std::addressof(event), handle, true, os::EventClearMode_ManualClear);
os::DestroySystemEvent(std::addressof(event));
}
R_RETURN(result);
}
@@ -166,7 +168,7 @@ namespace ams::htcs::impl {
if (htcs::ResultCancelled::Includes(result)) {
s32 err;
bool empty;
m_service.SelectEnd(std::addressof(err), std::addressof(empty), Span<int>{}, Span<int>{}, Span<int>{}, task_id);
static_cast<void>(m_service.SelectEnd(std::addressof(err), std::addressof(empty), Span<int>{}, Span<int>{}, Span<int>{}, task_id));
if (handle != os::InvalidNativeHandle) {
os::SystemEventType event;

View File

@@ -211,6 +211,9 @@ namespace ams::htcs::impl {
Result HtcsService::AcceptResults(s32 *out_err, s32 *out_desc, SockAddrHtcs *out_address, u32 task_id, s32 desc) {
AMS_UNUSED(out_address);
/* Wait for the task to complete. */
this->WaitTask(task_id);
/* Finish the task. */
htcs::SocketError err;
s32 ret_desc;
@@ -235,10 +238,14 @@ namespace ams::htcs::impl {
}
Result HtcsService::ReceiveSmallResults(s32 *out_err, s64 *out_size, char *buffer, s64 buffer_size, u32 task_id, s32 desc) {
AMS_UNUSED(desc);
/* Verify the task. */
R_TRY(m_rpc_client->VerifyTaskIdWithHandle<rpc::ReceiveSmallTask>(task_id, desc));
/* Continue the task. */
m_rpc_client->ReceiveContinue<rpc::ReceiveSmallTask>(task_id, buffer, buffer_size);
static_cast<void>(m_rpc_client->ReceiveContinue<rpc::ReceiveSmallTask>(task_id, buffer, buffer_size));
/* Wait for the task to complete. */
this->WaitTask(task_id);
/* Finish the task. */
htcs::SocketError err;
@@ -274,7 +281,11 @@ namespace ams::htcs::impl {
}
Result HtcsService::SendSmallResults(s32 *out_err, s64 *out_size, u32 task_id, s32 desc) {
AMS_UNUSED(desc);
/* Verify the task. */
R_TRY(m_rpc_client->VerifyTaskIdWithHandle<rpc::SendSmallTask>(task_id, desc));
/* Wait for the task to complete. */
this->WaitTask(task_id);
/* Finish the task. */
htcs::SocketError err;
@@ -322,6 +333,9 @@ namespace ams::htcs::impl {
/* Verify the task. */
R_TRY(m_rpc_client->VerifyTaskIdWithHandle<rpc::SendTask>(task_id, desc));
/* Wait for the task to complete. */
this->WaitTask(task_id);
/* Finish the task. */
htcs::SocketError err;
R_TRY(m_rpc_client->End<rpc::SendTask>(task_id, std::addressof(err), out_size));
@@ -347,6 +361,9 @@ namespace ams::htcs::impl {
/* Verify the task. */
R_TRY(m_rpc_client->VerifyTaskIdWithHandle<rpc::ReceiveTask>(task_id, desc));
/* Wait for the task to complete. */
this->WaitTask(task_id);
/* Get the result. */
htcs::SocketError err{};
s64 recv_size{};
@@ -399,6 +416,9 @@ namespace ams::htcs::impl {
}
Result HtcsService::SelectEnd(s32 *out_err, bool *out_empty, Span<int> read_handles, Span<int> write_handles, Span<int> exception_handles, u32 task_id) {
/* Wait for the task to complete. */
this->WaitTask(task_id);
/* Finish the task. */
htcs::SocketError err;
bool empty;