From 8a8631ebcb2837ade2fa2e6a5209bada4d4a8e52 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Wed, 6 Oct 2021 23:22:54 -0700 Subject: [PATCH] strat: build sysmodules with -Wextra/-Werror --- config/templates/stratosphere.mk | 2 +- .../fs/impl/fs_access_log_impl.hpp | 8 +-- .../source/fs/fsa/fs_user_filesystem.cpp | 16 +++--- .../source/fs/fsa/fs_user_mount_table.cpp | 2 +- .../htc/server/htc_htc_service_object.cpp | 4 +- .../source/htc/server/rpc/htc_rpc_client.hpp | 57 +++++++------------ .../source/htcs/impl/htcs_manager_impl.cpp | 14 +++-- .../source/htcs/impl/htcs_service.cpp | 7 ++- .../server/htcs_socket_service_object.cpp | 2 +- .../source/i2c/i2c_command_list_formatter.cpp | 6 ++ .../impl/heap/mem_impl_heap_central_heap.cpp | 2 +- 11 files changed, 57 insertions(+), 63 deletions(-) diff --git a/config/templates/stratosphere.mk b/config/templates/stratosphere.mk index fe796490..aff1007b 100644 --- a/config/templates/stratosphere.mk +++ b/config/templates/stratosphere.mk @@ -16,7 +16,7 @@ include $(DEVKITPRO)/libnx/switch_rules # options for code generation #--------------------------------------------------------------------------------- export DEFINES = $(ATMOSPHERE_DEFINES) -DATMOSPHERE_IS_STRATOSPHERE -D_GNU_SOURCE -export SETTINGS = $(ATMOSPHERE_SETTINGS) -O2 +export SETTINGS = $(ATMOSPHERE_SETTINGS) -O2 -Wextra -Werror -Wno-missing-field-initializers export CFLAGS = $(ATMOSPHERE_CFLAGS) $(SETTINGS) $(DEFINES) $(INCLUDE) export CXXFLAGS = $(CFLAGS) $(ATMOSPHERE_CXXFLAGS) export ASFLAGS = $(ATMOSPHERE_ASFLAGS) $(SETTINGS) $(DEFINES) diff --git a/libstratosphere/include/stratosphere/fs/impl/fs_access_log_impl.hpp b/libstratosphere/include/stratosphere/fs/impl/fs_access_log_impl.hpp index e6625b08..38eb78f2 100644 --- a/libstratosphere/include/stratosphere/fs/impl/fs_access_log_impl.hpp +++ b/libstratosphere/include/stratosphere/fs/impl/fs_access_log_impl.hpp @@ -132,7 +132,7 @@ namespace ams::fs::impl { /* Access log invocation lambdas. */ #define AMS_FS_IMPL_ACCESS_LOG_IMPL(__EXPR__, __HANDLE__, __ENABLED__, __NAME__, ...) \ - [&](const char *name) { \ + [&](const char *name) -> Result { \ if (!(__ENABLED__)) { \ return (__EXPR__); \ } else { \ @@ -145,7 +145,7 @@ namespace ams::fs::impl { }(__NAME__) #define AMS_FS_IMPL_ACCESS_LOG_WITH_PRIORITY_IMPL(__EXPR__, __PRIORITY__, __HANDLE__, __ENABLED__, __NAME__, ...) \ - [&](const char *name) { \ + [&](const char *name) -> Result { \ if (!(__ENABLED__)) { \ return (__EXPR__); \ } else { \ @@ -158,7 +158,7 @@ namespace ams::fs::impl { }(__NAME__) #define AMS_FS_IMPL_ACCESS_LOG_EXPLICIT_IMPL(__RESULT__, __START__, __END__, __HANDLE__, __ENABLED__, __NAME__, ...) \ - [&](const char *name) { \ + [&](const char *name) -> Result { \ if (!(__ENABLED__)) { \ return __RESULT__; \ } else { \ @@ -169,7 +169,7 @@ namespace ams::fs::impl { }(__NAME__) #define AMS_FS_IMPL_ACCESS_LOG_UNLESS_R_SUCCEEDED_IMPL(__EXPR__, __ENABLED__, __NAME__, ...) \ - [&](const char *name) { \ + [&](const char *name) -> Result { \ if (!(__ENABLED__)) { \ return (__EXPR__); \ } else { \ diff --git a/libstratosphere/source/fs/fsa/fs_user_filesystem.cpp b/libstratosphere/source/fs/fsa/fs_user_filesystem.cpp index d2b7489d..6a4e0267 100644 --- a/libstratosphere/source/fs/fsa/fs_user_filesystem.cpp +++ b/libstratosphere/source/fs/fsa/fs_user_filesystem.cpp @@ -244,22 +244,22 @@ namespace ams::fs { namespace { - Result CommitImpl(const char *path, const char *func_name) { - impl::FileSystemAccessor *accessor; - AMS_FS_R_TRY(AMS_FS_IMPL_ACCESS_LOG_UNLESS_R_SUCCEEDED(impl::Find(std::addressof(accessor), path), AMS_FS_IMPL_ACCESS_LOG_FORMAT_PATH, path)); + Result CommitImpl(const char *mount_name, const char *func_name) { + impl::FileSystemAccessor *accessor{}; + AMS_FS_R_TRY(AMS_FS_IMPL_ACCESS_LOG_UNLESS_R_SUCCEEDED(impl::Find(std::addressof(accessor), mount_name), AMS_FS_IMPL_ACCESS_LOG_FORMAT_MOUNT, mount_name)); - AMS_FS_R_TRY(AMS_FS_IMPL_ACCESS_LOG_FILESYSTEM_WITH_NAME(accessor->Commit(), nullptr, accessor, func_name, AMS_FS_IMPL_ACCESS_LOG_FORMAT_MOUNT, path)); + AMS_FS_R_TRY(AMS_FS_IMPL_ACCESS_LOG_FILESYSTEM_WITH_NAME(accessor->Commit(), nullptr, accessor, func_name, AMS_FS_IMPL_ACCESS_LOG_FORMAT_MOUNT, mount_name)); return ResultSuccess(); } } - Result Commit(const char *path) { - return CommitImpl(path, AMS_CURRENT_FUNCTION_NAME); + Result Commit(const char *mount_name) { + return CommitImpl(mount_name, AMS_CURRENT_FUNCTION_NAME); } - Result CommitSaveData(const char *path) { - return CommitImpl(path, AMS_CURRENT_FUNCTION_NAME); + Result CommitSaveData(const char *mount_name) { + return CommitImpl(mount_name, AMS_CURRENT_FUNCTION_NAME); } } diff --git a/libstratosphere/source/fs/fsa/fs_user_mount_table.cpp b/libstratosphere/source/fs/fsa/fs_user_mount_table.cpp index 58a6ed96..88813fc3 100644 --- a/libstratosphere/source/fs/fsa/fs_user_mount_table.cpp +++ b/libstratosphere/source/fs/fsa/fs_user_mount_table.cpp @@ -31,7 +31,7 @@ namespace ams::fs::impl { } Result Find(FileSystemAccessor **out, const char *name) { - return g_mount_table.Find(out, name); + return g_mount_table.Find(out, name); } void Unregister(const char *name) { diff --git a/libstratosphere/source/htc/server/htc_htc_service_object.cpp b/libstratosphere/source/htc/server/htc_htc_service_object.cpp index 6d22f274..6664724a 100644 --- a/libstratosphere/source/htc/server/htc_htc_service_object.cpp +++ b/libstratosphere/source/htc/server/htc_htc_service_object.cpp @@ -31,7 +31,7 @@ namespace ams::htc::server { Result HtcServiceObject::GetEnvironmentVariable(sf::Out out_size, const sf::OutBuffer &out, const sf::InBuffer &name) { /* Get the variable. */ - size_t var_size; + size_t var_size = std::numeric_limits::max(); R_TRY(m_misc_impl.GetEnvironmentVariable(std::addressof(var_size), reinterpret_cast(out.GetPointer()), out.GetSize(), reinterpret_cast(name.GetPointer()), name.GetSize())); /* Check the output size. */ @@ -44,7 +44,7 @@ namespace ams::htc::server { Result HtcServiceObject::GetEnvironmentVariableLength(sf::Out out_size, const sf::InBuffer &name) { /* Get the variable. */ - size_t var_size; + size_t var_size = std::numeric_limits::max(); R_TRY(m_misc_impl.GetEnvironmentVariableLength(std::addressof(var_size), reinterpret_cast(name.GetPointer()), name.GetSize())); /* Check the output size. */ diff --git a/libstratosphere/source/htc/server/rpc/htc_rpc_client.hpp b/libstratosphere/source/htc/server/rpc/htc_rpc_client.hpp index 7adf7da5..dd9fafdf 100644 --- a/libstratosphere/source/htc/server/rpc/htc_rpc_client.hpp +++ b/libstratosphere/source/htc/server/rpc/htc_rpc_client.hpp @@ -94,8 +94,20 @@ namespace ams::htc::server::rpc { Result ReceiveBody(char *dst, size_t size); Result SendRequest(const char *src, size_t size); private: - template requires IsRpcTask - ALWAYS_INLINE Result BeginImpl(std::index_sequence, u32 *out_task_id, RpcTaskArgumentType... args) { + s32 GetTaskHandle(u32 task_id); + public: + void Wait(u32 task_id) { + os::WaitEvent(m_task_table.Get(task_id)->GetEvent()); + } + + os::NativeHandle DetachReadableHandle(u32 task_id) { + return os::DetachReadableHandleOfSystemEvent(m_task_table.Get(task_id)->GetSystemEvent()); + } + + void CancelBySocket(s32 handle); + + template requires (IsRpcTask && sizeof...(Args) == std::tuple_size>::value) + Result Begin(u32 *out_task_id, Args &&... args) { /* Lock ourselves. */ std::scoped_lock lk(m_mutex); @@ -117,7 +129,7 @@ namespace ams::htc::server::rpc { }; /* Set the task arguments. */ - R_TRY(task->SetArguments(args...)); + R_TRY(task->SetArguments(std::forward(args)...)); /* Clear the task's events. */ os::ClearEvent(std::addressof(m_receive_buffer_available_events[task_id])); @@ -138,8 +150,8 @@ namespace ams::htc::server::rpc { return ResultSuccess(); } - template requires IsRpcTask - ALWAYS_INLINE Result GetResultImpl(std::index_sequence, u32 task_id, RpcTaskResultType... args) { + template requires (IsRpcTask && sizeof...(Args) == std::tuple_size>::value) + Result GetResult(u32 task_id, Args &&... args) { /* Lock ourselves. */ std::scoped_lock lk(m_mutex); @@ -151,13 +163,13 @@ namespace ams::htc::server::rpc { R_UNLESS(task->GetTaskState() == RpcTaskState::Completed, htc::ResultTaskNotCompleted()); /* Get the task's result. */ - R_TRY(task->GetResult(args...)); + R_TRY(task->GetResult(std::forward(args)...)); return ResultSuccess(); } - template requires IsRpcTask - ALWAYS_INLINE Result EndImpl(std::index_sequence, u32 task_id, RpcTaskResultType... args) { + template requires (IsRpcTask && sizeof...(Args) == std::tuple_size>::value) + Result End(u32 task_id, Args &&... args) { /* Lock ourselves. */ std::scoped_lock lk(m_mutex); @@ -188,38 +200,11 @@ namespace ams::htc::server::rpc { } /* Get the task's result. */ - R_TRY(task->GetResult(args...)); + R_TRY(task->GetResult(std::forward(args)...)); return ResultSuccess(); } - s32 GetTaskHandle(u32 task_id); - public: - void Wait(u32 task_id) { - os::WaitEvent(m_task_table.Get(task_id)->GetEvent()); - } - - os::NativeHandle DetachReadableHandle(u32 task_id) { - return os::DetachReadableHandleOfSystemEvent(m_task_table.Get(task_id)->GetSystemEvent()); - } - - void CancelBySocket(s32 handle); - - template requires (IsRpcTask && sizeof...(Args) == std::tuple_size>::value) - Result Begin(u32 *out_task_id, Args &&... args) { - return this->BeginImpl(std::make_index_sequence>::value>(), out_task_id, std::forward(args)...); - } - - template requires (IsRpcTask && sizeof...(Args) == std::tuple_size>::value) - Result GetResult(u32 task_id, Args &&... args) { - return this->GetResultImpl(std::make_index_sequence>::value>(), task_id, std::forward(args)...); - } - - template requires (IsRpcTask && sizeof...(Args) == std::tuple_size>::value) - Result End(u32 task_id, Args &&... args) { - return this->EndImpl(std::make_index_sequence>::value>(), task_id, std::forward(args)...); - } - template requires IsRpcTask Result VerifyTaskIdWithHandle(u32 task_id, s32 handle) { /* Lock ourselves. */ diff --git a/libstratosphere/source/htcs/impl/htcs_manager_impl.cpp b/libstratosphere/source/htcs/impl/htcs_manager_impl.cpp index df955813..3a60aec9 100644 --- a/libstratosphere/source/htcs/impl/htcs_manager_impl.cpp +++ b/libstratosphere/source/htcs/impl/htcs_manager_impl.cpp @@ -159,20 +159,22 @@ namespace ams::htcs::impl { Result HtcsManagerImpl::StartSelect(u32 *out_task_id, os::NativeHandle *out_handle, Span read_handles, Span write_handles, Span exception_handles, s64 tv_sec, s64 tv_usec) { /* Start the select. */ u32 task_id; - os::NativeHandle handle; + os::NativeHandle handle = os::InvalidNativeHandle; const Result result = m_service.SelectStart(std::addressof(task_id), std::addressof(handle), read_handles, write_handles, exception_handles, tv_sec, tv_usec); /* Ensure our state ends up clean. */ if (htcs::ResultCancelled::Includes(result)) { - os::SystemEventType event; - os::AttachReadableHandleToSystemEvent(std::addressof(event), handle, true, os::EventClearMode_ManualClear); - s32 err; bool empty; m_service.SelectEnd(std::addressof(err), std::addressof(empty), Span{}, Span{}, Span{}, task_id); - os::DestroySystemEvent(std::addressof(event)); - } else { + if (handle != os::InvalidNativeHandle) { + os::SystemEventType event; + os::AttachReadableHandleToSystemEvent(std::addressof(event), handle, true, os::EventClearMode_ManualClear); + + os::DestroySystemEvent(std::addressof(event)); + } + } else if (R_SUCCEEDED(result)) { *out_task_id = task_id; *out_handle = handle; } diff --git a/libstratosphere/source/htcs/impl/htcs_service.cpp b/libstratosphere/source/htcs/impl/htcs_service.cpp index 28e3648a..fb1ec8ee 100644 --- a/libstratosphere/source/htcs/impl/htcs_service.cpp +++ b/libstratosphere/source/htcs/impl/htcs_service.cpp @@ -275,6 +275,7 @@ namespace ams::htcs::impl { Result HtcsService::SendSmallResults(s32 *out_err, s64 *out_size, u32 task_id, s32 desc) { AMS_UNUSED(desc); + /* Finish the task. */ htcs::SocketError err; R_TRY(m_rpc_client->End(task_id, std::addressof(err), out_size)); @@ -387,13 +388,13 @@ namespace ams::htcs::impl { u32 task_id; R_TRY(m_rpc_client->Begin(std::addressof(task_id), read_handles, write_handles, exception_handles, tv_sec, tv_usec)); - /* Check that the task isn't cancelled. */ - R_UNLESS(!m_rpc_client->IsCancelled(task_id), htcs::ResultCancelled()); - /* Detach the task. */ *out_task_id = task_id; *out_handle = m_rpc_client->DetachReadableHandle(task_id); + /* Check that the task isn't cancelled. */ + R_UNLESS(!m_rpc_client->IsCancelled(task_id), htcs::ResultCancelled()); + return ResultSuccess(); } diff --git a/libstratosphere/source/htcs/server/htcs_socket_service_object.cpp b/libstratosphere/source/htcs/server/htcs_socket_service_object.cpp index 8645ccd8..79948a7c 100644 --- a/libstratosphere/source/htcs/server/htcs_socket_service_object.cpp +++ b/libstratosphere/source/htcs/server/htcs_socket_service_object.cpp @@ -131,7 +131,7 @@ namespace ams::htcs::server { auto *manager = impl::HtcsManagerHolder::GetHtcsManager(); /* Get the accept results. */ - s32 desc; + s32 desc = -1; manager->AcceptResults(out_err.GetPointer(), std::addressof(desc), out_address.GetPointer(), task_id, m_desc); /* If an error occurred, we're done. */ diff --git a/libstratosphere/source/i2c/i2c_command_list_formatter.cpp b/libstratosphere/source/i2c/i2c_command_list_formatter.cpp index 4c1b45eb..ee965d37 100644 --- a/libstratosphere/source/i2c/i2c_command_list_formatter.cpp +++ b/libstratosphere/source/i2c/i2c_command_list_formatter.cpp @@ -36,10 +36,12 @@ namespace ams::i2c { auto &header1 = cmd_list[this->current_index++]; /* Set the header. */ + header0 = {}; header0.Set(impl::CommandId_Receive); header0.Set((option & TransactionOption_StopCondition) != 0); header0.Set((option & TransactionOption_StartCondition) != 0); + header1 = {}; header1.Set(size); return ResultSuccess(); @@ -58,10 +60,12 @@ namespace ams::i2c { auto &header1 = cmd_list[this->current_index++]; /* Set the header. */ + header0 = {}; header0.Set(impl::CommandId_Send); header0.Set((option & TransactionOption_StopCondition) != 0); header0.Set((option & TransactionOption_StartCondition) != 0); + header1 = {}; header1.Set(size); /* Copy the data we're sending. */ @@ -84,9 +88,11 @@ namespace ams::i2c { auto &header1 = cmd_list[this->current_index++]; /* Set the header. */ + header0 = {}; header0.Set(impl::CommandId_Extension); header0.Set(impl::SubCommandId_Sleep); + header1 = {}; header1.Set(us); return ResultSuccess(); diff --git a/libstratosphere/source/mem/impl/heap/mem_impl_heap_central_heap.cpp b/libstratosphere/source/mem/impl/heap/mem_impl_heap_central_heap.cpp index 6bc297b2..f9ef0d31 100644 --- a/libstratosphere/source/mem/impl/heap/mem_impl_heap_central_heap.cpp +++ b/libstratosphere/source/mem/impl/heap/mem_impl_heap_central_heap.cpp @@ -52,7 +52,7 @@ namespace ams::mem::impl::heap { this->use_virtual_memory = false; } else { /* We were not provided with a region to use as backing. */ - void *mem; + void *mem = nullptr; if (auto err = AllocateVirtualMemory(std::addressof(mem), size); err != 0) { return err; }