strat: build sysmodules with -Wextra/-Werror

This commit is contained in:
Michael Scire 2021-10-06 23:22:54 -07:00
parent 843dc8e521
commit 8a8631ebcb
11 changed files with 57 additions and 63 deletions

View File

@ -16,7 +16,7 @@ include $(DEVKITPRO)/libnx/switch_rules
# options for code generation # options for code generation
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
export DEFINES = $(ATMOSPHERE_DEFINES) -DATMOSPHERE_IS_STRATOSPHERE -D_GNU_SOURCE 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 CFLAGS = $(ATMOSPHERE_CFLAGS) $(SETTINGS) $(DEFINES) $(INCLUDE)
export CXXFLAGS = $(CFLAGS) $(ATMOSPHERE_CXXFLAGS) export CXXFLAGS = $(CFLAGS) $(ATMOSPHERE_CXXFLAGS)
export ASFLAGS = $(ATMOSPHERE_ASFLAGS) $(SETTINGS) $(DEFINES) export ASFLAGS = $(ATMOSPHERE_ASFLAGS) $(SETTINGS) $(DEFINES)

View File

@ -132,7 +132,7 @@ namespace ams::fs::impl {
/* Access log invocation lambdas. */ /* Access log invocation lambdas. */
#define AMS_FS_IMPL_ACCESS_LOG_IMPL(__EXPR__, __HANDLE__, __ENABLED__, __NAME__, ...) \ #define AMS_FS_IMPL_ACCESS_LOG_IMPL(__EXPR__, __HANDLE__, __ENABLED__, __NAME__, ...) \
[&](const char *name) { \ [&](const char *name) -> Result { \
if (!(__ENABLED__)) { \ if (!(__ENABLED__)) { \
return (__EXPR__); \ return (__EXPR__); \
} else { \ } else { \
@ -145,7 +145,7 @@ namespace ams::fs::impl {
}(__NAME__) }(__NAME__)
#define AMS_FS_IMPL_ACCESS_LOG_WITH_PRIORITY_IMPL(__EXPR__, __PRIORITY__, __HANDLE__, __ENABLED__, __NAME__, ...) \ #define AMS_FS_IMPL_ACCESS_LOG_WITH_PRIORITY_IMPL(__EXPR__, __PRIORITY__, __HANDLE__, __ENABLED__, __NAME__, ...) \
[&](const char *name) { \ [&](const char *name) -> Result { \
if (!(__ENABLED__)) { \ if (!(__ENABLED__)) { \
return (__EXPR__); \ return (__EXPR__); \
} else { \ } else { \
@ -158,7 +158,7 @@ namespace ams::fs::impl {
}(__NAME__) }(__NAME__)
#define AMS_FS_IMPL_ACCESS_LOG_EXPLICIT_IMPL(__RESULT__, __START__, __END__, __HANDLE__, __ENABLED__, __NAME__, ...) \ #define AMS_FS_IMPL_ACCESS_LOG_EXPLICIT_IMPL(__RESULT__, __START__, __END__, __HANDLE__, __ENABLED__, __NAME__, ...) \
[&](const char *name) { \ [&](const char *name) -> Result { \
if (!(__ENABLED__)) { \ if (!(__ENABLED__)) { \
return __RESULT__; \ return __RESULT__; \
} else { \ } else { \
@ -169,7 +169,7 @@ namespace ams::fs::impl {
}(__NAME__) }(__NAME__)
#define AMS_FS_IMPL_ACCESS_LOG_UNLESS_R_SUCCEEDED_IMPL(__EXPR__, __ENABLED__, __NAME__, ...) \ #define AMS_FS_IMPL_ACCESS_LOG_UNLESS_R_SUCCEEDED_IMPL(__EXPR__, __ENABLED__, __NAME__, ...) \
[&](const char *name) { \ [&](const char *name) -> Result { \
if (!(__ENABLED__)) { \ if (!(__ENABLED__)) { \
return (__EXPR__); \ return (__EXPR__); \
} else { \ } else { \

View File

@ -244,22 +244,22 @@ namespace ams::fs {
namespace { namespace {
Result CommitImpl(const char *path, const char *func_name) { Result CommitImpl(const char *mount_name, const char *func_name) {
impl::FileSystemAccessor *accessor; 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)); 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(); return ResultSuccess();
} }
} }
Result Commit(const char *path) { Result Commit(const char *mount_name) {
return CommitImpl(path, AMS_CURRENT_FUNCTION_NAME); return CommitImpl(mount_name, AMS_CURRENT_FUNCTION_NAME);
} }
Result CommitSaveData(const char *path) { Result CommitSaveData(const char *mount_name) {
return CommitImpl(path, AMS_CURRENT_FUNCTION_NAME); return CommitImpl(mount_name, AMS_CURRENT_FUNCTION_NAME);
} }
} }

View File

@ -31,7 +31,7 @@ namespace ams::fs::impl {
} }
Result Find(FileSystemAccessor **out, const char *name) { 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) { void Unregister(const char *name) {

View File

@ -31,7 +31,7 @@ namespace ams::htc::server {
Result HtcServiceObject::GetEnvironmentVariable(sf::Out<s32> out_size, const sf::OutBuffer &out, const sf::InBuffer &name) { Result HtcServiceObject::GetEnvironmentVariable(sf::Out<s32> out_size, const sf::OutBuffer &out, const sf::InBuffer &name) {
/* Get the variable. */ /* Get the variable. */
size_t var_size; size_t var_size = std::numeric_limits<size_t>::max();
R_TRY(m_misc_impl.GetEnvironmentVariable(std::addressof(var_size), reinterpret_cast<char *>(out.GetPointer()), out.GetSize(), reinterpret_cast<const char *>(name.GetPointer()), name.GetSize())); R_TRY(m_misc_impl.GetEnvironmentVariable(std::addressof(var_size), reinterpret_cast<char *>(out.GetPointer()), out.GetSize(), reinterpret_cast<const char *>(name.GetPointer()), name.GetSize()));
/* Check the output size. */ /* Check the output size. */
@ -44,7 +44,7 @@ namespace ams::htc::server {
Result HtcServiceObject::GetEnvironmentVariableLength(sf::Out<s32> out_size, const sf::InBuffer &name) { Result HtcServiceObject::GetEnvironmentVariableLength(sf::Out<s32> out_size, const sf::InBuffer &name) {
/* Get the variable. */ /* Get the variable. */
size_t var_size; size_t var_size = std::numeric_limits<size_t>::max();
R_TRY(m_misc_impl.GetEnvironmentVariableLength(std::addressof(var_size), reinterpret_cast<const char *>(name.GetPointer()), name.GetSize())); R_TRY(m_misc_impl.GetEnvironmentVariableLength(std::addressof(var_size), reinterpret_cast<const char *>(name.GetPointer()), name.GetSize()));
/* Check the output size. */ /* Check the output size. */

View File

@ -94,8 +94,20 @@ namespace ams::htc::server::rpc {
Result ReceiveBody(char *dst, size_t size); Result ReceiveBody(char *dst, size_t size);
Result SendRequest(const char *src, size_t size); Result SendRequest(const char *src, size_t size);
private: private:
template<typename T, size_t... Ix> requires IsRpcTask<T> s32 GetTaskHandle(u32 task_id);
ALWAYS_INLINE Result BeginImpl(std::index_sequence<Ix...>, u32 *out_task_id, RpcTaskArgumentType<T, Ix>... args) { public:
void Wait(u32 task_id) {
os::WaitEvent(m_task_table.Get<Task>(task_id)->GetEvent());
}
os::NativeHandle DetachReadableHandle(u32 task_id) {
return os::DetachReadableHandleOfSystemEvent(m_task_table.Get<Task>(task_id)->GetSystemEvent());
}
void CancelBySocket(s32 handle);
template<typename T, typename... Args> requires (IsRpcTask<T> && sizeof...(Args) == std::tuple_size<RpcTaskArgumentsType<T>>::value)
Result Begin(u32 *out_task_id, Args &&... args) {
/* Lock ourselves. */ /* Lock ourselves. */
std::scoped_lock lk(m_mutex); std::scoped_lock lk(m_mutex);
@ -117,7 +129,7 @@ namespace ams::htc::server::rpc {
}; };
/* Set the task arguments. */ /* Set the task arguments. */
R_TRY(task->SetArguments(args...)); R_TRY(task->SetArguments(std::forward<Args>(args)...));
/* Clear the task's events. */ /* Clear the task's events. */
os::ClearEvent(std::addressof(m_receive_buffer_available_events[task_id])); os::ClearEvent(std::addressof(m_receive_buffer_available_events[task_id]));
@ -138,8 +150,8 @@ namespace ams::htc::server::rpc {
return ResultSuccess(); return ResultSuccess();
} }
template<typename T, size_t... Ix> requires IsRpcTask<T> template<typename T, typename... Args> requires (IsRpcTask<T> && sizeof...(Args) == std::tuple_size<RpcTaskResultsType<T>>::value)
ALWAYS_INLINE Result GetResultImpl(std::index_sequence<Ix...>, u32 task_id, RpcTaskResultType<T, Ix>... args) { Result GetResult(u32 task_id, Args &&... args) {
/* Lock ourselves. */ /* Lock ourselves. */
std::scoped_lock lk(m_mutex); std::scoped_lock lk(m_mutex);
@ -151,13 +163,13 @@ namespace ams::htc::server::rpc {
R_UNLESS(task->GetTaskState() == RpcTaskState::Completed, htc::ResultTaskNotCompleted()); R_UNLESS(task->GetTaskState() == RpcTaskState::Completed, htc::ResultTaskNotCompleted());
/* Get the task's result. */ /* Get the task's result. */
R_TRY(task->GetResult(args...)); R_TRY(task->GetResult(std::forward<Args>(args)...));
return ResultSuccess(); return ResultSuccess();
} }
template<typename T, size_t... Ix> requires IsRpcTask<T> template<typename T, typename... Args> requires (IsRpcTask<T> && sizeof...(Args) == std::tuple_size<RpcTaskResultsType<T>>::value)
ALWAYS_INLINE Result EndImpl(std::index_sequence<Ix...>, u32 task_id, RpcTaskResultType<T, Ix>... args) { Result End(u32 task_id, Args &&... args) {
/* Lock ourselves. */ /* Lock ourselves. */
std::scoped_lock lk(m_mutex); std::scoped_lock lk(m_mutex);
@ -188,38 +200,11 @@ namespace ams::htc::server::rpc {
} }
/* Get the task's result. */ /* Get the task's result. */
R_TRY(task->GetResult(args...)); R_TRY(task->GetResult(std::forward<Args>(args)...));
return ResultSuccess(); return ResultSuccess();
} }
s32 GetTaskHandle(u32 task_id);
public:
void Wait(u32 task_id) {
os::WaitEvent(m_task_table.Get<Task>(task_id)->GetEvent());
}
os::NativeHandle DetachReadableHandle(u32 task_id) {
return os::DetachReadableHandleOfSystemEvent(m_task_table.Get<Task>(task_id)->GetSystemEvent());
}
void CancelBySocket(s32 handle);
template<typename T, typename... Args> requires (IsRpcTask<T> && sizeof...(Args) == std::tuple_size<RpcTaskArgumentsType<T>>::value)
Result Begin(u32 *out_task_id, Args &&... args) {
return this->BeginImpl<T>(std::make_index_sequence<std::tuple_size<RpcTaskArgumentsType<T>>::value>(), out_task_id, std::forward<Args>(args)...);
}
template<typename T, typename... Args> requires (IsRpcTask<T> && sizeof...(Args) == std::tuple_size<RpcTaskResultsType<T>>::value)
Result GetResult(u32 task_id, Args &&... args) {
return this->GetResultImpl<T>(std::make_index_sequence<std::tuple_size<RpcTaskResultsType<T>>::value>(), task_id, std::forward<Args>(args)...);
}
template<typename T, typename... Args> requires (IsRpcTask<T> && sizeof...(Args) == std::tuple_size<RpcTaskResultsType<T>>::value)
Result End(u32 task_id, Args &&... args) {
return this->EndImpl<T>(std::make_index_sequence<std::tuple_size<RpcTaskResultsType<T>>::value>(), task_id, std::forward<Args>(args)...);
}
template<typename T> requires IsRpcTask<T> template<typename T> requires IsRpcTask<T>
Result VerifyTaskIdWithHandle(u32 task_id, s32 handle) { Result VerifyTaskIdWithHandle(u32 task_id, s32 handle) {
/* Lock ourselves. */ /* Lock ourselves. */

View File

@ -159,20 +159,22 @@ namespace ams::htcs::impl {
Result HtcsManagerImpl::StartSelect(u32 *out_task_id, os::NativeHandle *out_handle, Span<const int> read_handles, Span<const int> write_handles, Span<const int> exception_handles, s64 tv_sec, s64 tv_usec) { Result HtcsManagerImpl::StartSelect(u32 *out_task_id, os::NativeHandle *out_handle, Span<const int> read_handles, Span<const int> write_handles, Span<const int> exception_handles, s64 tv_sec, s64 tv_usec) {
/* Start the select. */ /* Start the select. */
u32 task_id; 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); 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. */ /* Ensure our state ends up clean. */
if (htcs::ResultCancelled::Includes(result)) { if (htcs::ResultCancelled::Includes(result)) {
os::SystemEventType event;
os::AttachReadableHandleToSystemEvent(std::addressof(event), handle, true, os::EventClearMode_ManualClear);
s32 err; s32 err;
bool empty; bool empty;
m_service.SelectEnd(std::addressof(err), std::addressof(empty), Span<int>{}, Span<int>{}, Span<int>{}, task_id); m_service.SelectEnd(std::addressof(err), std::addressof(empty), Span<int>{}, Span<int>{}, Span<int>{}, task_id);
os::DestroySystemEvent(std::addressof(event)); if (handle != os::InvalidNativeHandle) {
} else { 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_task_id = task_id;
*out_handle = handle; *out_handle = handle;
} }

View File

@ -275,6 +275,7 @@ namespace ams::htcs::impl {
Result HtcsService::SendSmallResults(s32 *out_err, s64 *out_size, u32 task_id, s32 desc) { Result HtcsService::SendSmallResults(s32 *out_err, s64 *out_size, u32 task_id, s32 desc) {
AMS_UNUSED(desc); AMS_UNUSED(desc);
/* Finish the task. */ /* Finish the task. */
htcs::SocketError err; htcs::SocketError err;
R_TRY(m_rpc_client->End<rpc::SendSmallTask>(task_id, std::addressof(err), out_size)); R_TRY(m_rpc_client->End<rpc::SendSmallTask>(task_id, std::addressof(err), out_size));
@ -387,13 +388,13 @@ namespace ams::htcs::impl {
u32 task_id; u32 task_id;
R_TRY(m_rpc_client->Begin<rpc::SelectTask>(std::addressof(task_id), read_handles, write_handles, exception_handles, tv_sec, tv_usec)); R_TRY(m_rpc_client->Begin<rpc::SelectTask>(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<rpc::SelectTask>(task_id), htcs::ResultCancelled());
/* Detach the task. */ /* Detach the task. */
*out_task_id = task_id; *out_task_id = task_id;
*out_handle = m_rpc_client->DetachReadableHandle(task_id); *out_handle = m_rpc_client->DetachReadableHandle(task_id);
/* Check that the task isn't cancelled. */
R_UNLESS(!m_rpc_client->IsCancelled<rpc::SelectTask>(task_id), htcs::ResultCancelled());
return ResultSuccess(); return ResultSuccess();
} }

View File

@ -131,7 +131,7 @@ namespace ams::htcs::server {
auto *manager = impl::HtcsManagerHolder::GetHtcsManager(); auto *manager = impl::HtcsManagerHolder::GetHtcsManager();
/* Get the accept results. */ /* Get the accept results. */
s32 desc; s32 desc = -1;
manager->AcceptResults(out_err.GetPointer(), std::addressof(desc), out_address.GetPointer(), task_id, m_desc); manager->AcceptResults(out_err.GetPointer(), std::addressof(desc), out_address.GetPointer(), task_id, m_desc);
/* If an error occurred, we're done. */ /* If an error occurred, we're done. */

View File

@ -36,10 +36,12 @@ namespace ams::i2c {
auto &header1 = cmd_list[this->current_index++]; auto &header1 = cmd_list[this->current_index++];
/* Set the header. */ /* Set the header. */
header0 = {};
header0.Set<impl::CommonCommandFormat::CommandId>(impl::CommandId_Receive); header0.Set<impl::CommonCommandFormat::CommandId>(impl::CommandId_Receive);
header0.Set<impl::ReceiveCommandFormat::StopCondition>((option & TransactionOption_StopCondition) != 0); header0.Set<impl::ReceiveCommandFormat::StopCondition>((option & TransactionOption_StopCondition) != 0);
header0.Set<impl::ReceiveCommandFormat::StartCondition>((option & TransactionOption_StartCondition) != 0); header0.Set<impl::ReceiveCommandFormat::StartCondition>((option & TransactionOption_StartCondition) != 0);
header1 = {};
header1.Set<impl::ReceiveCommandFormat::Size>(size); header1.Set<impl::ReceiveCommandFormat::Size>(size);
return ResultSuccess(); return ResultSuccess();
@ -58,10 +60,12 @@ namespace ams::i2c {
auto &header1 = cmd_list[this->current_index++]; auto &header1 = cmd_list[this->current_index++];
/* Set the header. */ /* Set the header. */
header0 = {};
header0.Set<impl::CommonCommandFormat::CommandId>(impl::CommandId_Send); header0.Set<impl::CommonCommandFormat::CommandId>(impl::CommandId_Send);
header0.Set<impl::SendCommandFormat::StopCondition>((option & TransactionOption_StopCondition) != 0); header0.Set<impl::SendCommandFormat::StopCondition>((option & TransactionOption_StopCondition) != 0);
header0.Set<impl::SendCommandFormat::StartCondition>((option & TransactionOption_StartCondition) != 0); header0.Set<impl::SendCommandFormat::StartCondition>((option & TransactionOption_StartCondition) != 0);
header1 = {};
header1.Set<impl::SendCommandFormat::Size>(size); header1.Set<impl::SendCommandFormat::Size>(size);
/* Copy the data we're sending. */ /* Copy the data we're sending. */
@ -84,9 +88,11 @@ namespace ams::i2c {
auto &header1 = cmd_list[this->current_index++]; auto &header1 = cmd_list[this->current_index++];
/* Set the header. */ /* Set the header. */
header0 = {};
header0.Set<impl::CommonCommandFormat::CommandId>(impl::CommandId_Extension); header0.Set<impl::CommonCommandFormat::CommandId>(impl::CommandId_Extension);
header0.Set<impl::CommonCommandFormat::SubCommandId>(impl::SubCommandId_Sleep); header0.Set<impl::CommonCommandFormat::SubCommandId>(impl::SubCommandId_Sleep);
header1 = {};
header1.Set<impl::SleepCommandFormat::MicroSeconds>(us); header1.Set<impl::SleepCommandFormat::MicroSeconds>(us);
return ResultSuccess(); return ResultSuccess();

View File

@ -52,7 +52,7 @@ namespace ams::mem::impl::heap {
this->use_virtual_memory = false; this->use_virtual_memory = false;
} else { } else {
/* We were not provided with a region to use as backing. */ /* 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) { if (auto err = AllocateVirtualMemory(std::addressof(mem), size); err != 0) {
return err; return err;
} }