kern: build with -Wextra

This commit is contained in:
Michael Scire 2020-08-17 14:20:24 -07:00
parent d3014f6ed9
commit 73798cb812
32 changed files with 100 additions and 30 deletions

View file

@ -7,7 +7,7 @@ include $(dir $(abspath $(lastword $(MAKEFILE_LIST))))/../common.mk
# options for code generation
#---------------------------------------------------------------------------------
export DEFINES := $(ATMOSPHERE_DEFINES) -DATMOSPHERE_IS_MESOSPHERE
export SETTINGS := $(ATMOSPHERE_SETTINGS) -O2 -mgeneral-regs-only -ffixed-x18 -Werror -fno-non-call-exceptions
export SETTINGS := $(ATMOSPHERE_SETTINGS) -O2 -mgeneral-regs-only -ffixed-x18 -Wextra -Werror -fno-non-call-exceptions
export CFLAGS := $(ATMOSPHERE_CFLAGS) $(SETTINGS) $(DEFINES) $(INCLUDE)
export CXXFLAGS := $(CFLAGS) $(ATMOSPHERE_CXXFLAGS) -fno-use-cxa-atexit
export ASFLAGS := $(ATMOSPHERE_ASFLAGS) $(SETTINGS) $(DEFINES)

View file

@ -9,7 +9,7 @@ include $(dir $(abspath $(lastword $(MAKEFILE_LIST))))/../config/common.mk
PRECOMPILED_HEADERS := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))/include/mesosphere.hpp
DEFINES := $(ATMOSPHERE_DEFINES) -DATMOSPHERE_IS_MESOSPHERE
SETTINGS := $(ATMOSPHERE_SETTINGS) -O2 -mgeneral-regs-only -ffixed-x18 -Werror -fno-non-call-exceptions
SETTINGS := $(ATMOSPHERE_SETTINGS) -O2 -mgeneral-regs-only -ffixed-x18 -Wextra -Werror -fno-non-call-exceptions
CFLAGS := $(ATMOSPHERE_CFLAGS) $(SETTINGS) $(DEFINES) $(INCLUDE)
CXXFLAGS := $(CFLAGS) $(ATMOSPHERE_CXXFLAGS) -fno-use-cxa-atexit -flto
ASFLAGS := $(ATMOSPHERE_ASFLAGS) $(SETTINGS)

View file

@ -31,6 +31,9 @@ namespace ams::kern {
template<typename U>
constexpr ALWAYS_INLINE explicit KTypedAddress(U *ptr) : address(reinterpret_cast<uintptr_t>(ptr)) { /* ... */ }
/* Copy constructor. */
constexpr ALWAYS_INLINE KTypedAddress(const KTypedAddress &rhs) : address(rhs.address) { /* ... */ }
/* Assignment operator. */
constexpr ALWAYS_INLINE KTypedAddress operator=(KTypedAddress rhs) {
this->address = rhs.address;

View file

@ -19,17 +19,12 @@
namespace ams::kern {
template<typename... ArgTypes>
ALWAYS_INLINE void UnusedImpl(ArgTypes &&... args) {
(static_cast<void>(args), ...);
}
NORETURN NOINLINE void Panic(const char *file, int line, const char *format, ...) __attribute__((format(printf, 3, 4)));
NORETURN NOINLINE void Panic();
}
#define MESOSPHERE_UNUSED(...) ::ams::kern::UnusedImpl(__VA_ARGS__)
#define MESOSPHERE_UNUSED(...) AMS_UNUSED(__VA_ARGS__)
#ifdef MESOSPHERE_ENABLE_DEBUG_PRINT
#define MESOSPHERE_PANIC(...) do { ::ams::kern::Panic(__FILE__, __LINE__, ## __VA_ARGS__); } while(0)

View file

@ -37,6 +37,7 @@ namespace ams::kern::arch::arm64::cpu {
constexpr KThreadTerminationInterruptHandler() : KInterruptHandler() { /* ... */ }
virtual KInterruptTask *OnInterrupt(s32 interrupt_id) override {
MESOSPHERE_UNUSED(interrupt_id);
return nullptr;
}
};
@ -68,6 +69,8 @@ namespace ams::kern::arch::arm64::cpu {
/* Nintendo misuses this per their own API, but it's functional. */
virtual KInterruptTask *OnInterrupt(s32 interrupt_id) override {
MESOSPHERE_UNUSED(interrupt_id);
if (this->which < 0) {
this->counter = cpu::GetCycleCounter();
} else {
@ -145,6 +148,7 @@ namespace ams::kern::arch::arm64::cpu {
}
virtual KInterruptTask *OnInterrupt(s32 interrupt_id) override {
MESOSPHERE_UNUSED(interrupt_id);
this->ProcessOperation();
return nullptr;
}

View file

@ -24,6 +24,7 @@ namespace ams::kern::arch::arm64 {
constexpr KHardwareTimerInterruptTask() : KInterruptTask() { /* ... */ }
virtual KInterruptTask *OnInterrupt(s32 interrupt_id) override {
MESOSPHERE_UNUSED(interrupt_id);
return this;
}

View file

@ -160,6 +160,7 @@ namespace ams::kern::arch::arm64 {
void KPageTable::Initialize(s32 core_id) {
/* Nothing actually needed here. */
MESOSPHERE_UNUSED(core_id);
}
Result KPageTable::InitializeForKernel(void *table, KVirtualAddress start, KVirtualAddress end) {
@ -181,7 +182,8 @@ namespace ams::kern::arch::arm64 {
}
Result KPageTable::InitializeForProcess(u32 id, ams::svc::CreateProcessFlag as_type, bool enable_aslr, bool from_back, KMemoryManager::Pool pool, KProcessAddress code_address, size_t code_size, KMemoryBlockSlabManager *mem_block_slab_manager, KBlockInfoManager *block_info_manager, KPageTableManager *pt_manager) {
/* Convert the address space type to a width. */
/* The input ID isn't actually used. */
MESOSPHERE_UNUSED(id);
/* Get an ASID */
this->asid = g_asid_manager.Reserve();
@ -364,6 +366,9 @@ namespace ams::kern::arch::arm64 {
MESOSPHERE_ASSERT(util::IsAligned(GetInteger(phys_addr), L1BlockSize));
MESOSPHERE_ASSERT(util::IsAligned(num_pages * PageSize, L1BlockSize));
/* Allocation is never needed for L1 block mapping. */
MESOSPHERE_UNUSED(page_list, reuse_ll);
auto &impl = this->GetImpl();
/* Iterate, mapping each block. */

View file

@ -281,6 +281,7 @@ namespace ams::kern::arch::arm64 {
}
void KThreadContext::OnThreadTerminating(const KThread *thread) {
MESOSPHERE_UNUSED(thread);
/* ... */
}

View file

@ -498,6 +498,8 @@ namespace ams::kern {
R_TRY(PutUserString(user_str, len));
}
#else
MESOSPHERE_UNUSED(user_str, len);
#endif
return ResultSuccess();

View file

@ -62,7 +62,7 @@ namespace ams::kern {
/* Allocate memory for the process. */
auto &mm = Kernel::GetMemoryManager();
const auto pool = static_cast<KMemoryManager::Pool>(reader.UsesSecureMemory() ? KMemoryManager::Pool_System : KSystemControl::GetInitialProcessBinaryPool());
const auto pool = reader.UsesSecureMemory() ? KMemoryManager::Pool_System : static_cast<KMemoryManager::Pool>(KSystemControl::GetInitialProcessBinaryPool());
MESOSPHERE_R_ABORT_UNLESS(mm.Allocate(std::addressof(pg), params.code_num_pages, KMemoryManager::EncodeOption(pool, KMemoryManager::Direction_FromFront)));
{

View file

@ -157,6 +157,7 @@ namespace ams::kern {
case RegionType::OnMemoryBootImage:
case RegionType::DTB:
R_TRY(page_table->MapRegion(MemoryRegions[static_cast<u32>(type)], perm));
break;
default:
return svc::ResultNotFound();
}

View file

@ -86,6 +86,10 @@ namespace ams::kern {
/* Manager thread functions. */
void DpcManagerNormalThreadFunction(uintptr_t arg) {
/* Input argument goes unused. */
MESOSPHERE_UNUSED(arg);
/* Forever wait and service requests. */
while (true) {
KDpcTask::WaitForRequest();
KDpcTask::HandleRequest();
@ -93,6 +97,10 @@ namespace ams::kern {
}
void DpcManagerPreemptionThreadFunction(uintptr_t arg) {
/* Input argument goes unused. */
MESOSPHERE_UNUSED(arg);
/* Forever wait and service requests, rotating the scheduled queue every 10 ms. */
s64 timeout = KHardwareTimer::GetTick() + DpcManagerTimeout;
while (true) {
if (KDpcTask::TimedWaitForRequest(timeout)) {

View file

@ -128,7 +128,7 @@ namespace ams::kern {
KInterruptTask *KInterruptEventTask::OnInterrupt(s32 interrupt_id) {
MESOSPHERE_ASSERT_THIS();
MESOSPHERE_UNUSED(interrupt_id);
return this;
}

View file

@ -188,6 +188,10 @@ namespace ams::kern {
}
void SetupCoreLocalRegionMemoryRegions(KInitialPageTable &page_table, KInitialPageAllocator &page_allocator) {
/* NOTE: Nintendo passes page table here to use num_l1_entries; we don't use this at present. */
MESOSPHERE_UNUSED(page_table);
/* Get the virtual address of the core local reigon. */
const KVirtualAddress core_local_virt_start = GetCoreLocalRegionVirtualAddress();
MESOSPHERE_INIT_ABORT_UNLESS(KMemoryLayout::GetVirtualMemoryRegionTree().Insert(GetInteger(core_local_virt_start), CoreLocalRegionSize, KMemoryRegionType_CoreLocal));

View file

@ -203,7 +203,6 @@ namespace ams::kern {
}
/* Only succeed if we allocated as many pages as we wanted. */
MESOSPHERE_ASSERT(num_pages >= 0);
R_UNLESS(num_pages == 0, svc::ResultOutOfMemory());
/* We succeeded! */

View file

@ -2761,9 +2761,12 @@ namespace ams::kern {
lk1.emplace(lock_1);
}
/* Check memory state. */
/* Check memory state for source. */
R_TRY(src_page_table.CheckMemoryStateContiguous(src_addr, size, src_state_mask, src_state, src_test_perm, src_test_perm, src_attr_mask | KMemoryAttribute_Uncached, src_attr));
/* Destination state is intentionally unchecked. */
MESOSPHERE_UNUSED(dst_state_mask, dst_state, dst_test_perm, dst_attr_mask, dst_attr);
/* Get implementations. */
auto &src_impl = src_page_table.GetImpl();
auto &dst_impl = dst_page_table.GetImpl();

View file

@ -493,6 +493,9 @@ namespace ams::kern {
/* Lock ourselves, to prevent concurrent access. */
KScopedLightLock lk(this->state_lock);
/* Address and size parameters aren't used. */
MESOSPHERE_UNUSED(address, size);
/* Try to find an existing info for the memory. */
KSharedMemoryInfo *info = nullptr;
for (auto it = this->shared_memory_list.begin(); it != this->shared_memory_list.end(); ++it) {
@ -524,6 +527,9 @@ namespace ams::kern {
/* Lock ourselves, to prevent concurrent access. */
KScopedLightLock lk(this->state_lock);
/* Address and size parameters aren't used. */
MESOSPHERE_UNUSED(address, size);
/* Find an existing info for the memory. */
KSharedMemoryInfo *info = nullptr;
auto it = this->shared_memory_list.begin();

View file

@ -28,6 +28,7 @@ namespace ams::kern {
constexpr KSchedulerInterruptTask() : KInterruptTask() { /* ... */ }
virtual KInterruptTask *OnInterrupt(s32 interrupt_id) override {
MESOSPHERE_UNUSED(interrupt_id);
return GetDummyInterruptTask();
}

View file

@ -53,6 +53,10 @@ namespace ams::kern {
this->msg_buffer_end = dst_address + sizeof(u32) * out_offset;
this->msg_buffer_space_end = dst_address + msg_size;
/* NOTE: Nintendo calculates the receive list index here using the special header. */
/* We pre-calculate it in the caller, and pass it as a parameter. */
MESOSPHERE_UNUSED(dst_special_header);
const u32 *recv_list = dst_msg + dst_recv_list_idx;
const auto entry_count = GetEntryCount(dst_header);
@ -494,6 +498,9 @@ namespace ams::kern {
auto &dst_page_table = dst_process.GetPageTable();
auto &src_page_table = src_process.GetPageTable();
/* NOTE: Session is used only for debugging, and so may go unused. */
MESOSPHERE_UNUSED(session);
/* The receive list is initially not broken. */
recv_list_broken = false;
@ -711,7 +718,7 @@ namespace ams::kern {
return ResultSuccess();
}
ALWAYS_INLINE Result ProcessSendMessagePointerDescriptors(int &offset, int &pointer_key, KProcessPageTable &dst_page_table, KProcessPageTable &src_page_table, const ipc::MessageBuffer &dst_msg, const ipc::MessageBuffer &src_msg, const ReceiveList &dst_recv_list, bool dst_user) {
ALWAYS_INLINE Result ProcessSendMessagePointerDescriptors(int &offset, int &pointer_key, KProcessPageTable &dst_page_table, const ipc::MessageBuffer &dst_msg, const ipc::MessageBuffer &src_msg, const ReceiveList &dst_recv_list, bool dst_user) {
/* Get the offset at the start of processing. */
const int cur_offset = offset;
@ -758,6 +765,9 @@ namespace ams::kern {
auto &dst_page_table = dst_process.GetPageTable();
auto &src_page_table = src_process.GetPageTable();
/* NOTE: Session is used only for debugging, and so may go unused. */
MESOSPHERE_UNUSED(session);
/* Determine the message buffers. */
u32 *dst_msg_ptr, *src_msg_ptr;
bool dst_user, src_user;
@ -860,7 +870,7 @@ namespace ams::kern {
/* Process any pointer buffers. */
for (auto i = 0; i < src_header.GetPointerCount(); ++i) {
R_TRY(ProcessSendMessagePointerDescriptors(offset, pointer_key, dst_page_table, src_page_table, dst_msg, src_msg, dst_recv_list, dst_user && dst_header.GetReceiveListCount() == ipc::MessageBuffer::MessageHeader::ReceiveListCountType_ToMessageBuffer));
R_TRY(ProcessSendMessagePointerDescriptors(offset, pointer_key, dst_page_table, dst_msg, src_msg, dst_recv_list, dst_user && dst_header.GetReceiveListCount() == ipc::MessageBuffer::MessageHeader::ReceiveListCountType_ToMessageBuffer));
}
/* Clear any map alias buffers. */

View file

@ -99,6 +99,7 @@ namespace ams::kern {
Result KSharedMemory::Unmap(KProcessPageTable *table, KProcessAddress address, size_t size, KProcess *process) {
MESOSPHERE_ASSERT_THIS();
MESOSPHERE_UNUSED(process);
/* Validate the size. */
R_UNLESS(this->page_group.GetNumPages() == util::DivideUp(size, PageSize), svc::ResultInvalidSize());

View file

@ -126,6 +126,8 @@ namespace ams::kern {
MESOSPHERE_RELEASE_VLOG(format, vl);
MESOSPHERE_RELEASE_LOG("\n");
va_end(vl);
#else
MESOSPHERE_UNUSED(file, line, format);
#endif
StopSystem();

View file

@ -26,6 +26,10 @@ namespace ams::kern::svc {
{
/* TODO: Implement Kernel Debugging. */
}
#else
{
MESOSPHERE_UNUSED(kern_debug_type, arg0, arg1, arg2);
}
#endif
}
@ -47,6 +51,10 @@ namespace ams::kern::svc {
break;
}
}
#else
{
MESOSPHERE_UNUSED(kern_trace_state);
}
#endif
}

View file

@ -16,15 +16,6 @@
#pragma once
#include <vapours/common.hpp>
namespace ams::impl {
template<typename... ArgTypes>
constexpr ALWAYS_INLINE void UnusedImpl(ArgTypes... args) {
(static_cast<void>(args), ...);
}
}
namespace ams::diag {
NORETURN NOINLINE void AssertionFailureImpl(const char *file, int line, const char *func, const char *expr, u64 value, const char *format, ...) __attribute__((format(printf, 6, 7)));
@ -36,8 +27,6 @@ namespace ams::diag {
}
#define AMS_UNUSED(...) ::ams::impl::UnusedImpl(__VA_ARGS__)
#ifdef AMS_ENABLE_DEBUG_PRINT
#define AMS_CALL_ASSERT_FAIL_IMPL(cond, ...) ::ams::diag::AssertionFailureImpl(__FILE__, __LINE__, __PRETTY_FUNCTION__, cond, 0, ## __VA_ARGS__)
#define AMS_CALL_ABORT_IMPL(cond, ...) ::ams::diag::AbortImpl(__FILE__, __LINE__, __PRETTY_FUNCTION__, cond, 0, ## __VA_ARGS__)

View file

@ -66,4 +66,19 @@
#define AMS_CURRENT_FUNCTION_NAME __FUNCTION__
#if defined(__cplusplus)
namespace ams::impl {
template<typename... ArgTypes>
constexpr ALWAYS_INLINE void UnusedImpl(ArgTypes &&... args) {
(static_cast<void>(args), ...);
}
}
#endif
#define AMS_UNUSED(...) ::ams::impl::UnusedImpl(__VA_ARGS__)
#define AMS_INFINITE_LOOP() do { __asm__ __volatile__("" ::: "memory"); } while (1)

View file

@ -83,7 +83,7 @@ namespace ams {
constexpr Result(typename Base::BaseType v) : value(v) { static_assert(std::is_same<typename Base::BaseType, ::Result>::value); }
constexpr ALWAYS_INLINE operator ResultSuccess() const;
NX_CONSTEXPR bool CanAccept(Result result) { return true; }
NX_CONSTEXPR bool CanAccept(Result) { return true; }
constexpr ALWAYS_INLINE bool IsSuccess() const { return this->GetValue() == Base::SuccessValue; }
constexpr ALWAYS_INLINE bool IsFailure() const { return !this->IsSuccess(); }

View file

@ -353,7 +353,7 @@ namespace ams::svc::codegen::impl {
};
template<auto Allocator, typename FirstOperation, typename...OtherOperations>
static constexpr auto GetModifiedOperations(std::tuple<FirstOperation, OtherOperations...> ops) {
static constexpr auto GetModifiedOperations(std::tuple<FirstOperation, OtherOperations...>) {
constexpr size_t ModifyRegister = [] {
auto allocator = Allocator;
return allocator.AllocateFirstFree();
@ -535,7 +535,11 @@ namespace ams::svc::codegen::impl {
GenerateCodeForMetaCode<CodeGenerator, BeforeMetaCode>();
ON_SCOPE_EXIT { GenerateCodeForMetaCode<CodeGenerator, AfterMetaCode>(); };
/* Cast the generated function to the generic funciton pointer type. */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-function-type"
return reinterpret_cast<ReturnType (*)()>(Function)();
#pragma GCC diagnostic pop
}
#pragma GCC pop_options

View file

@ -139,7 +139,7 @@ namespace ams::svc::codegen::impl {
template<typename Operation>
static constexpr void GenerateCodeForPrepareForKernelProcedureToSvcInvocation(MetaCodeGenerator &mcg) {
static_assert(Operation::Kind == OperationKind::PackAndUnpack);
/* ... */
AMS_UNUSED(mcg);
}
template<typename Operation>

View file

@ -498,6 +498,7 @@ namespace ams::svc::ipc {
}
static constexpr ALWAYS_INLINE s32 GetSpecialDataIndex(const MessageHeader &hdr, const SpecialHeader &spc) {
AMS_UNUSED(hdr);
return (MessageHeader::GetDataSize() / sizeof(util::BitPack32)) + (spc.GetHeaderSize() / sizeof(util::BitPack32));
}

View file

@ -61,7 +61,7 @@ namespace ams {
private:
TimeSpanType ts;
public:
constexpr ALWAYS_INLINE TimeSpan(ZeroTag z = nullptr) : ts(TimeSpanType::FromNanoSeconds(0)) { /* ... */ }
constexpr ALWAYS_INLINE TimeSpan(ZeroTag z = nullptr) : ts(TimeSpanType::FromNanoSeconds(0)) { AMS_UNUSED(z); /* ... */ }
constexpr ALWAYS_INLINE TimeSpan(const TimeSpanType &t) : ts(t) { /* ... */ }
template<typename R, typename P>

View file

@ -267,12 +267,14 @@ namespace ams::util {
}
void splice(const_iterator pos, IntrusiveListImpl &o, const_iterator first) {
AMS_UNUSED(o);
const_iterator last(first);
std::advance(last, 1);
splice_impl(pos, first, last);
}
void splice(const_iterator pos, IntrusiveListImpl &o, const_iterator first, const_iterator last) {
AMS_UNUSED(o);
splice_impl(pos, first, last);
}

View file

@ -55,6 +55,7 @@ namespace ams::crypto::impl {
size_t XtsModeImpl::FinalizeEncryption(void *dst, size_t dst_size) {
AMS_ASSERT(this->state == State_Processing);
AMS_UNUSED(dst_size);
u8 *dst_u8 = static_cast<u8 *>(dst);
size_t processed = 0;
@ -80,6 +81,7 @@ namespace ams::crypto::impl {
size_t XtsModeImpl::FinalizeDecryption(void *dst, size_t dst_size) {
AMS_ASSERT(this->state == State_Processing);
AMS_UNUSED(dst_size);
u8 *dst_u8 = static_cast<u8 *>(dst);
size_t processed = 0;
@ -131,6 +133,8 @@ namespace ams::crypto::impl {
}
size_t XtsModeImpl::ProcessRemainingData(u8 *dst, const u8 *src, size_t size) {
AMS_UNUSED(dst);
std::memcpy(this->buffer, src, size);
this->num_buffered = size;

View file

@ -357,6 +357,7 @@ namespace ams::kern::init {
case ID: \
cpu::SetDbgWcr##ID##El1(__VA_ARGS__); \
cpu::SetDbgWvr##ID##El1(__VA_ARGS__); \
[[fallthrough]];
#define MESOSPHERE_INITIALIZE_BREAKPOINT_CASE(ID, ...) \
case ID: \