From 3bc19518202bdcfbda4caf2712e6a12f171ba064 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Tue, 11 Nov 2025 16:13:25 -0700 Subject: [PATCH] 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. --- fusee/program/source/fusee_setup_horizon.cpp | 5 +- libraries/config/templates/stratosphere.mk | 2 +- .../arch/arm64/kern_k_interrupt_manager.hpp | 12 +- .../arch/arm64/kern_k_page_table.hpp | 2 +- .../arch/arm64/kern_k_thread_context.hpp | 2 +- .../include/mesosphere/kern_k_debug_base.hpp | 6 +- .../include/mesosphere/kern_k_event.hpp | 4 +- .../mesosphere/kern_k_interrupt_event.hpp | 8 +- .../mesosphere/kern_k_page_table_base.hpp | 2 +- .../include/mesosphere/kern_k_process.hpp | 2 +- .../mesosphere/kern_k_readable_event.hpp | 10 +- .../include/mesosphere/kern_k_thread.hpp | 6 +- .../mesosphere/kern_k_thread_local_page.hpp | 2 +- .../source/arch/arm64/kern_cpu.cpp | 10 +- .../arch/arm64/kern_k_hardware_timer.cpp | 2 +- .../arch/arm64/kern_k_interrupt_manager.cpp | 71 +++++------ .../source/arch/arm64/kern_k_page_table.cpp | 8 +- .../arch/arm64/kern_k_thread_context.cpp | 6 +- .../nintendo/nx/kern_k_device_page_table.cpp | 19 ++- .../nintendo/nx/kern_k_sleep_manager.cpp | 2 +- .../source/kern_initial_process.cpp | 6 +- .../source/kern_k_code_memory.cpp | 2 +- .../source/kern_k_debug_base.cpp | 17 +-- .../source/kern_k_dpc_manager.cpp | 2 +- .../libmesosphere/source/kern_k_event.cpp | 16 +-- .../source/kern_k_page_table_base.cpp | 20 ++- .../libmesosphere/source/kern_k_process.cpp | 41 +++--- .../source/kern_k_readable_event.cpp | 4 +- .../libmesosphere/source/kern_k_scheduler.cpp | 2 +- .../source/kern_k_server_session.cpp | 18 +-- .../source/kern_k_system_resource.cpp | 2 +- .../libmesosphere/source/kern_k_thread.cpp | 16 +-- .../source/kern_k_thread_local_page.cpp | 5 +- .../source/kern_k_worker_task_manager.cpp | 2 +- .../libmesosphere/source/kern_kernel.cpp | 6 +- .../source/svc/kern_svc_cache.cpp | 4 +- .../source/svc/kern_svc_event.cpp | 9 +- .../libmesosphere/source/svc/kern_svc_ipc.cpp | 6 +- .../stratosphere/erpt/erpt_ids.autogen.hpp | 24 ++-- .../ncm/ncm_content_meta_extended_data.hpp | 4 +- libraries/libstratosphere/libstratosphere.mk | 2 +- .../source/cs/cs_target_io_server.cpp | 2 +- .../source/erpt/srv/erpt_srv_attachment.cpp | 4 +- .../source/erpt/srv/erpt_srv_cipher.hpp | 2 +- .../source/erpt/srv/erpt_srv_context.cpp | 7 +- .../source/erpt/srv/erpt_srv_context_impl.cpp | 2 +- .../erpt/srv/erpt_srv_forced_shutdown.cpp | 16 +-- .../source/erpt/srv/erpt_srv_journal.cpp | 2 +- .../srv/erpt_srv_journal_for_attachments.cpp | 15 ++- .../erpt/srv/erpt_srv_journal_for_reports.cpp | 13 +- .../source/erpt/srv/erpt_srv_main.cpp | 10 +- .../source/erpt/srv/erpt_srv_manager_impl.cpp | 3 +- .../source/erpt/srv/erpt_srv_manager_impl.hpp | 2 +- .../source/erpt/srv/erpt_srv_report.cpp | 4 +- .../source/erpt/srv/erpt_srv_reporter.cpp | 118 ++++++------------ .../source/erpt/srv/erpt_srv_stream.cpp | 16 ++- .../source/fs/fs_access_log.cpp | 4 +- .../libstratosphere/source/fs/fs_api.cpp | 4 +- .../source/fs/fsa/fs_filesystem_accessor.cpp | 2 +- .../source/fs/fsa/fs_user_directory.cpp | 2 +- .../source/fs/fsa/fs_user_file.cpp | 4 +- .../fssystem_block_cache_buffered_storage.cpp | 2 +- .../fssystem_crypto_configuration.cpp | 7 +- .../fssystem_file_system_proxy_api.cpp | 16 ++- .../htc/server/driver/htc_htclow_driver.cpp | 2 +- .../htc/server/rpc/htc_htcmisc_rpc_server.hpp | 2 +- .../source/htc/server/rpc/htc_rpc_client.hpp | 4 +- .../source/htcfs/htcfs_client_impl.cpp | 2 +- .../htcfs/htcfs_directory_service_object.cpp | 2 +- .../htcfs/htcfs_file_service_object.cpp | 2 +- .../htclow/driver/htclow_driver_manager.cpp | 6 +- .../htclow_socket_discovery_manager.cpp | 10 +- .../source/htclow/driver/htclow_usb_impl.cpp | 14 +-- .../source/htclow/htclow_channel.cpp | 6 +- .../source/htclow/htclow_worker.cpp | 12 +- .../source/htclow/mux/htclow_mux.cpp | 4 +- .../client/htcs_virtual_socket_collection.cpp | 8 +- .../source/htcs/htcs_socket.cpp | 30 ++--- .../source/htcs/impl/htcs_manager_impl.cpp | 16 +-- .../source/htcs/impl/htcs_service.cpp | 26 +++- .../vapours/results/results_common.hpp | 57 ++++----- .../sdmmc/impl/sdmmc_mmc_device_accessor.cpp | 4 +- .../impl/sdmmc_sd_card_device_accessor.cpp | 4 +- .../sdmmc_sd_host_standard_controller.cpp | 22 ++-- ...mmc_sdmmc_controller.board.nintendo_nx.cpp | 16 ++- utilities/erpt.py | 4 +- 86 files changed, 444 insertions(+), 455 deletions(-) diff --git a/fusee/program/source/fusee_setup_horizon.cpp b/fusee/program/source/fusee_setup_horizon.cpp index 8868eafc8..7ec68d4a3 100644 --- a/fusee/program/source/fusee_setup_horizon.cpp +++ b/fusee/program/source/fusee_setup_horizon.cpp @@ -411,8 +411,9 @@ namespace ams::nxboot { /* If we should, save the current warmboot firmware. */ UpdateWarmbootPath(expected_fuses); if (!IsFileExist(warmboot_path)) { - fs::CreateDirectory("sdmc:/warmboot_mariko"); - fs::CreateFile(warmboot_path, warmboot_src_size); + /* Try to create the directory/file, allowing them to fail (if already exist). */ + static_cast(fs::CreateDirectory("sdmc:/warmboot_mariko")); + static_cast(fs::CreateFile(warmboot_path, warmboot_src_size)); Result result; fs::FileHandle file; diff --git a/libraries/config/templates/stratosphere.mk b/libraries/config/templates/stratosphere.mk index 06fb362c9..6f37f2efa 100644 --- a/libraries/config/templates/stratosphere.mk +++ b/libraries/config/templates/stratosphere.mk @@ -26,7 +26,7 @@ ATMOSPHERE_OPTIMIZATION_FLAG := -O2 endif export DEFINES = $(ATMOSPHERE_DEFINES) -DATMOSPHERE_IS_STRATOSPHERE -D_GNU_SOURCE -export SETTINGS = $(ATMOSPHERE_SETTINGS) $(ATMOSPHERE_OPTIMIZATION_FLAG) -Wextra -Werror -Wno-missing-field-initializers +export SETTINGS = $(ATMOSPHERE_SETTINGS) $(ATMOSPHERE_OPTIMIZATION_FLAG) -Wextra -Werror -Wno-missing-field-initializers -Wno-error=unused-result export CFLAGS = $(ATMOSPHERE_CFLAGS) $(SETTINGS) $(DEFINES) $(INCLUDE) export CXXFLAGS = $(CFLAGS) $(ATMOSPHERE_CXXFLAGS) export ASFLAGS = $(ATMOSPHERE_ASFLAGS) $(SETTINGS) $(DEFINES) diff --git a/libraries/libmesosphere/include/mesosphere/arch/arm64/kern_k_interrupt_manager.hpp b/libraries/libmesosphere/include/mesosphere/arch/arm64/kern_k_interrupt_manager.hpp index 2a0c15604..0e99a0c67 100644 --- a/libraries/libmesosphere/include/mesosphere/arch/arm64/kern_k_interrupt_manager.hpp +++ b/libraries/libmesosphere/include/mesosphere/arch/arm64/kern_k_interrupt_manager.hpp @@ -83,9 +83,9 @@ namespace ams::kern::arch::arm64 { } NOINLINE Result BindHandler(KInterruptHandler *handler, s32 irq, s32 core_id, s32 priority, bool manual_clear, bool level); - NOINLINE Result UnbindHandler(s32 irq, s32 core); + NOINLINE void UnbindHandler(s32 irq, s32 core); - NOINLINE Result ClearInterrupt(s32 irq, s32 core_id); + NOINLINE void ClearInterrupt(s32 irq, s32 core_id); ALWAYS_INLINE void SendInterProcessorInterrupt(s32 irq, u64 core_mask) { m_interrupt_controller.SendInterProcessorInterrupt(irq, core_mask); @@ -99,10 +99,10 @@ namespace ams::kern::arch::arm64 { private: Result BindGlobal(KInterruptHandler *handler, s32 irq, s32 core_id, s32 priority, bool manual_clear, bool level); Result BindLocal(KInterruptHandler *handler, s32 irq, s32 priority, bool manual_clear); - Result UnbindGlobal(s32 irq); - Result UnbindLocal(s32 irq); - Result ClearGlobal(s32 irq); - Result ClearLocal(s32 irq); + void UnbindGlobal(s32 irq); + void UnbindLocal(s32 irq); + void ClearGlobal(s32 irq); + void ClearLocal(s32 irq); private: [[nodiscard]] static ALWAYS_INLINE u32 GetInterruptsEnabledState() { u64 intr_state; diff --git a/libraries/libmesosphere/include/mesosphere/arch/arm64/kern_k_page_table.hpp b/libraries/libmesosphere/include/mesosphere/arch/arm64/kern_k_page_table.hpp index 7bc1a96f1..b08fe1625 100644 --- a/libraries/libmesosphere/include/mesosphere/arch/arm64/kern_k_page_table.hpp +++ b/libraries/libmesosphere/include/mesosphere/arch/arm64/kern_k_page_table.hpp @@ -197,7 +197,7 @@ namespace ams::kern::arch::arm64 { cpu::SwitchProcess(s_ttbr0_entries[proc_idx + 1], proc_id); } - NOINLINE Result InitializeForKernel(void *table, KVirtualAddress start, KVirtualAddress end); + NOINLINE void InitializeForKernel(void *table, KVirtualAddress start, KVirtualAddress end); NOINLINE Result InitializeForProcess(ams::svc::CreateProcessFlag flags, bool from_back, KMemoryManager::Pool pool, KProcessAddress code_address, size_t code_size, KSystemResource *system_resource, KResourceLimit *resource_limit, size_t process_index); Result Finalize(); diff --git a/libraries/libmesosphere/include/mesosphere/arch/arm64/kern_k_thread_context.hpp b/libraries/libmesosphere/include/mesosphere/arch/arm64/kern_k_thread_context.hpp index 40cc1f860..c605614db 100644 --- a/libraries/libmesosphere/include/mesosphere/arch/arm64/kern_k_thread_context.hpp +++ b/libraries/libmesosphere/include/mesosphere/arch/arm64/kern_k_thread_context.hpp @@ -165,7 +165,7 @@ namespace ams::kern::arch::arm64 { constexpr explicit KThreadContext(util::ConstantInitializeTag) : m_callee_saved(), m_lr(), m_sp(), m_fpcr(), m_fpsr(), m_callee_saved_fpu(), m_locked() { /* ... */ } explicit KThreadContext() { /* ... */ } - Result Initialize(KVirtualAddress u_pc, KVirtualAddress k_sp, KVirtualAddress u_sp, uintptr_t arg, bool is_user, bool is_64_bit, bool is_main); + void Initialize(KVirtualAddress u_pc, KVirtualAddress k_sp, KVirtualAddress u_sp, uintptr_t arg, bool is_user, bool is_64_bit, bool is_main); void SetArguments(uintptr_t arg0, uintptr_t arg1); diff --git a/libraries/libmesosphere/include/mesosphere/kern_k_debug_base.hpp b/libraries/libmesosphere/include/mesosphere/kern_k_debug_base.hpp index 6978b9152..4b4fdd682 100644 --- a/libraries/libmesosphere/include/mesosphere/kern_k_debug_base.hpp +++ b/libraries/libmesosphere/include/mesosphere/kern_k_debug_base.hpp @@ -93,9 +93,9 @@ namespace ams::kern { static Result ProcessDebugEvent(ams::svc::DebugEvent event, const uintptr_t *params, size_t num_params); public: static Result OnDebugEvent(ams::svc::DebugEvent event, const uintptr_t *params, size_t num_params); - static Result OnExitProcess(KProcess *process); - static Result OnTerminateProcess(KProcess *process); - static Result OnExitThread(KThread *thread); + static void OnExitProcess(KProcess *process); + static void OnTerminateProcess(KProcess *process); + static void OnExitThread(KThread *thread); static KEventInfo *CreateDebugEvent(ams::svc::DebugEvent event, u64 thread_id, const uintptr_t *params, size_t num_params); }; diff --git a/libraries/libmesosphere/include/mesosphere/kern_k_event.hpp b/libraries/libmesosphere/include/mesosphere/kern_k_event.hpp index dd4a950d5..09eb380c3 100644 --- a/libraries/libmesosphere/include/mesosphere/kern_k_event.hpp +++ b/libraries/libmesosphere/include/mesosphere/kern_k_event.hpp @@ -50,8 +50,8 @@ namespace ams::kern { KReadableEvent &GetReadableEvent() { return m_readable_event; } - Result Signal(); - Result Clear(); + void Signal(); + void Clear(); ALWAYS_INLINE void OnReadableEventDestroyed() { m_readable_event_destroyed = true; } }; diff --git a/libraries/libmesosphere/include/mesosphere/kern_k_interrupt_event.hpp b/libraries/libmesosphere/include/mesosphere/kern_k_interrupt_event.hpp index ac32cdadf..180e8fcfe 100644 --- a/libraries/libmesosphere/include/mesosphere/kern_k_interrupt_event.hpp +++ b/libraries/libmesosphere/include/mesosphere/kern_k_interrupt_event.hpp @@ -38,13 +38,11 @@ namespace ams::kern { Result Reset(); - Result Clear() { + void Clear() { MESOSPHERE_ASSERT_THIS(); - /* Try to perform a reset, succeeding unconditionally. */ - this->Reset(); - - R_SUCCEED(); + /* Try to perform a reset, ignoring whether it succeeds. */ + static_cast(this->Reset()); } bool IsInitialized() const { return m_is_initialized; } diff --git a/libraries/libmesosphere/include/mesosphere/kern_k_page_table_base.hpp b/libraries/libmesosphere/include/mesosphere/kern_k_page_table_base.hpp index 7b2c722e1..9db423f1f 100644 --- a/libraries/libmesosphere/include/mesosphere/kern_k_page_table_base.hpp +++ b/libraries/libmesosphere/include/mesosphere/kern_k_page_table_base.hpp @@ -226,7 +226,7 @@ namespace ams::kern { explicit KPageTableBase() { /* ... */ } - NOINLINE Result InitializeForKernel(bool is_64_bit, void *table, KVirtualAddress start, KVirtualAddress end); + NOINLINE void InitializeForKernel(bool is_64_bit, void *table, KVirtualAddress start, KVirtualAddress end); NOINLINE Result InitializeForProcess(ams::svc::CreateProcessFlag flags, bool from_back, KMemoryManager::Pool pool, void *table, KProcessAddress start, KProcessAddress end, KProcessAddress code_address, size_t code_size, KSystemResource *system_resource, KResourceLimit *resource_limit); void Finalize(); diff --git a/libraries/libmesosphere/include/mesosphere/kern_k_process.hpp b/libraries/libmesosphere/include/mesosphere/kern_k_process.hpp index 849f73dab..63060f900 100644 --- a/libraries/libmesosphere/include/mesosphere/kern_k_process.hpp +++ b/libraries/libmesosphere/include/mesosphere/kern_k_process.hpp @@ -269,7 +269,7 @@ namespace ams::kern { void RemoveIoRegion(KIoRegion *io_region); Result CreateThreadLocalRegion(KProcessAddress *out); - Result DeleteThreadLocalRegion(KProcessAddress addr); + void DeleteThreadLocalRegion(KProcessAddress addr); void *GetThreadLocalRegionPointer(KProcessAddress addr); constexpr KProcessAddress GetProcessLocalRegionAddress() const { return m_plr_address; } diff --git a/libraries/libmesosphere/include/mesosphere/kern_k_readable_event.hpp b/libraries/libmesosphere/include/mesosphere/kern_k_readable_event.hpp index d5888f989..d5fb5bb40 100644 --- a/libraries/libmesosphere/include/mesosphere/kern_k_readable_event.hpp +++ b/libraries/libmesosphere/include/mesosphere/kern_k_readable_event.hpp @@ -35,16 +35,14 @@ namespace ams::kern { constexpr KEvent *GetParent() const { return m_parent; } - Result Signal(); + void Signal(); Result Reset(); - Result Clear() { + void Clear() { MESOSPHERE_ASSERT_THIS(); - /* Try to perform a reset, succeeding unconditionally. */ - this->Reset(); - - R_SUCCEED(); + /* Try to perform a reset, ignoring whether it succeeds. */ + static_cast(this->Reset()); } virtual bool IsSignaled() const override; diff --git a/libraries/libmesosphere/include/mesosphere/kern_k_thread.hpp b/libraries/libmesosphere/include/mesosphere/kern_k_thread.hpp index f86457b44..487f36439 100644 --- a/libraries/libmesosphere/include/mesosphere/kern_k_thread.hpp +++ b/libraries/libmesosphere/include/mesosphere/kern_k_thread.hpp @@ -523,7 +523,7 @@ namespace ams::kern { Result GetCoreMask(int32_t *out_ideal_core, u64 *out_affinity_mask); Result SetCoreMask(int32_t ideal_core, u64 affinity_mask); - Result GetPhysicalCoreMask(int32_t *out_ideal_core, u64 *out_affinity_mask); + void GetPhysicalCoreMask(int32_t *out_ideal_core, u64 *out_affinity_mask); constexpr ThreadState GetState() const { return static_cast(m_thread_state & ThreadState_Mask); } constexpr ThreadState GetRawState() const { return m_thread_state; } @@ -717,7 +717,7 @@ namespace ams::kern { } void SetBasePriority(s32 priority); - Result SetPriorityToIdle(); + void SetPriorityToIdle(); Result Run(); void Exit(); @@ -725,7 +725,7 @@ namespace ams::kern { Result Terminate(); ThreadState RequestTerminate(); - Result Sleep(s64 timeout); + void Sleep(s64 timeout); ALWAYS_INLINE void *GetStackTop() const { return reinterpret_cast(m_kernel_stack_top) - 1; } ALWAYS_INLINE void *GetKernelStackTop() const { return m_kernel_stack_top; } diff --git a/libraries/libmesosphere/include/mesosphere/kern_k_thread_local_page.hpp b/libraries/libmesosphere/include/mesosphere/kern_k_thread_local_page.hpp index 280b65904..1822b4c56 100644 --- a/libraries/libmesosphere/include/mesosphere/kern_k_thread_local_page.hpp +++ b/libraries/libmesosphere/include/mesosphere/kern_k_thread_local_page.hpp @@ -77,7 +77,7 @@ namespace ams::kern { } public: Result Initialize(KProcess *process); - Result Finalize(); + void Finalize(); KProcessAddress Reserve(); void Release(KProcessAddress addr); diff --git a/libraries/libmesosphere/source/arch/arm64/kern_cpu.cpp b/libraries/libmesosphere/source/arch/arm64/kern_cpu.cpp index 401a4d4d7..4839349da 100644 --- a/libraries/libmesosphere/source/arch/arm64/kern_cpu.cpp +++ b/libraries/libmesosphere/source/arch/arm64/kern_cpu.cpp @@ -215,7 +215,7 @@ namespace ams::kern::arch::arm64::cpu { KThread::Register(new_thread); /* Run the thread. */ - new_thread->Run(); + MESOSPHERE_R_ABORT_UNLESS(new_thread->Run()); } virtual KInterruptTask *OnInterrupt(s32 interrupt_id) override { @@ -508,16 +508,16 @@ namespace ams::kern::arch::arm64::cpu { g_cache_operation_handler.Initialize(core_id); /* Bind all handlers to the relevant interrupts. */ - Kernel::GetInterruptManager().BindHandler(std::addressof(g_cache_operation_handler), KInterruptName_CacheOperation, core_id, KInterruptController::PriorityLevel_High, false, false); - Kernel::GetInterruptManager().BindHandler(std::addressof(g_thread_termination_handler), KInterruptName_ThreadTerminate, core_id, KInterruptController::PriorityLevel_Scheduler, false, false); - Kernel::GetInterruptManager().BindHandler(std::addressof(g_core_barrier_handler), KInterruptName_CoreBarrier, core_id, KInterruptController::PriorityLevel_Scheduler, false, false); + MESOSPHERE_R_ABORT_UNLESS(Kernel::GetInterruptManager().BindHandler(std::addressof(g_cache_operation_handler), KInterruptName_CacheOperation, core_id, KInterruptController::PriorityLevel_High, false, false)); + MESOSPHERE_R_ABORT_UNLESS(Kernel::GetInterruptManager().BindHandler(std::addressof(g_thread_termination_handler), KInterruptName_ThreadTerminate, core_id, KInterruptController::PriorityLevel_Scheduler, false, false)); + MESOSPHERE_R_ABORT_UNLESS(Kernel::GetInterruptManager().BindHandler(std::addressof(g_core_barrier_handler), KInterruptName_CoreBarrier, core_id, KInterruptController::PriorityLevel_Scheduler, false, false)); /* If we should, enable user access to the performance counter registers. */ if (KTargetSystem::IsUserPmuAccessEnabled()) { SetPmUserEnrEl0(1ul); } /* If we should, enable the kernel performance counter interrupt handler. */ #if defined(MESOSPHERE_ENABLE_PERFORMANCE_COUNTER) - Kernel::GetInterruptManager().BindHandler(std::addressof(g_performance_counter_handler[core_id]), KInterruptName_PerformanceCounter, core_id, KInterruptController::PriorityLevel_Timer, false, false); + MESOSPHERE_R_ABORT_UNLESS(Kernel::GetInterruptManager().BindHandler(std::addressof(g_performance_counter_handler[core_id]), KInterruptName_PerformanceCounter, core_id, KInterruptController::PriorityLevel_Timer, false, false)); #endif } diff --git a/libraries/libmesosphere/source/arch/arm64/kern_k_hardware_timer.cpp b/libraries/libmesosphere/source/arch/arm64/kern_k_hardware_timer.cpp index 57e10774a..576ad03a4 100644 --- a/libraries/libmesosphere/source/arch/arm64/kern_k_hardware_timer.cpp +++ b/libraries/libmesosphere/source/arch/arm64/kern_k_hardware_timer.cpp @@ -25,7 +25,7 @@ namespace ams::kern::arch::arm64 { m_maximum_time = static_cast(std::min(std::numeric_limits::max(), cpu::CounterTimerPhysicalTimerCompareValueRegisterAccessor().GetCompareValue())); /* Bind the interrupt task for this core. */ - Kernel::GetInterruptManager().BindHandler(this, KInterruptName_NonSecurePhysicalTimer, GetCurrentCoreId(), KInterruptController::PriorityLevel_Timer, true, true); + MESOSPHERE_R_ABORT_UNLESS(Kernel::GetInterruptManager().BindHandler(this, KInterruptName_NonSecurePhysicalTimer, GetCurrentCoreId(), KInterruptController::PriorityLevel_Timer, true, true)); } void KHardwareTimer::Finalize() { diff --git a/libraries/libmesosphere/source/arch/arm64/kern_k_interrupt_manager.cpp b/libraries/libmesosphere/source/arch/arm64/kern_k_interrupt_manager.cpp index e4cf075dc..af8e607c1 100644 --- a/libraries/libmesosphere/source/arch/arm64/kern_k_interrupt_manager.cpp +++ b/libraries/libmesosphere/source/arch/arm64/kern_k_interrupt_manager.cpp @@ -126,7 +126,7 @@ namespace ams::kern::arch::arm64 { if (entry.handler != nullptr) { /* Set manual clear needed if relevant. */ if (entry.manually_cleared) { - m_interrupt_controller.SetPriorityLevel(irq, KInterruptController::PriorityLevel_Low); + m_interrupt_controller.Disable(irq); entry.needs_clear = true; } @@ -242,40 +242,40 @@ namespace ams::kern::arch::arm64 { } } - Result KInterruptManager::UnbindHandler(s32 irq, s32 core_id) { + void KInterruptManager::UnbindHandler(s32 irq, s32 core_id) { MESOSPHERE_UNUSED(core_id); - R_UNLESS(KInterruptController::IsGlobal(irq) || KInterruptController::IsLocal(irq), svc::ResultOutOfRange()); + MESOSPHERE_ASSERT(KInterruptController::IsGlobal(irq) || KInterruptController::IsLocal(irq)); if (KInterruptController::IsGlobal(irq)) { KScopedInterruptDisable di; KScopedSpinLock lk(this->GetGlobalInterruptLock()); - R_RETURN(this->UnbindGlobal(irq)); - } else { + return this->UnbindGlobal(irq); + } else if (KInterruptController::IsLocal(irq)) { MESOSPHERE_ASSERT(core_id == GetCurrentCoreId()); KScopedInterruptDisable di; - R_RETURN(this->UnbindLocal(irq)); + return this->UnbindLocal(irq); } } - Result KInterruptManager::ClearInterrupt(s32 irq, s32 core_id) { + void KInterruptManager::ClearInterrupt(s32 irq, s32 core_id) { MESOSPHERE_UNUSED(core_id); - R_UNLESS(KInterruptController::IsGlobal(irq) || KInterruptController::IsLocal(irq), svc::ResultOutOfRange()); + MESOSPHERE_ASSERT(KInterruptController::IsGlobal(irq) || KInterruptController::IsLocal(irq)); if (KInterruptController::IsGlobal(irq)) { KScopedInterruptDisable di; KScopedSpinLock lk(this->GetGlobalInterruptLock()); - R_RETURN(this->ClearGlobal(irq)); - } else { + return this->ClearGlobal(irq); + } else if (KInterruptController::IsLocal(irq)) { MESOSPHERE_ASSERT(core_id == GetCurrentCoreId()); KScopedInterruptDisable di; - R_RETURN(this->ClearLocal(irq)); + return this->ClearLocal(irq); } } @@ -332,7 +332,7 @@ namespace ams::kern::arch::arm64 { R_SUCCEED(); } - Result KInterruptManager::UnbindGlobal(s32 irq) { + void KInterruptManager::UnbindGlobal(s32 irq) { for (size_t core_id = 0; core_id < cpu::NumCores; core_id++) { m_interrupt_controller.ClearTarget(irq, static_cast(core_id)); } @@ -340,50 +340,35 @@ namespace ams::kern::arch::arm64 { m_interrupt_controller.Disable(irq); GetGlobalInterruptEntry(irq).handler = nullptr; - - R_SUCCEED(); } - Result KInterruptManager::UnbindLocal(s32 irq) { - auto &entry = this->GetLocalInterruptEntry(irq); - R_UNLESS(entry.handler != nullptr, svc::ResultInvalidState()); - + void KInterruptManager::UnbindLocal(s32 irq) { m_interrupt_controller.SetPriorityLevel(irq, KInterruptController::PriorityLevel_Low); m_interrupt_controller.Disable(irq); - entry.handler = nullptr; - - R_SUCCEED(); + this->GetLocalInterruptEntry(irq).handler = nullptr; } - Result KInterruptManager::ClearGlobal(s32 irq) { - /* We can't clear an entry with no handler. */ + void KInterruptManager::ClearGlobal(s32 irq) { + /* Get the entry. */ auto &entry = GetGlobalInterruptEntry(irq); - R_UNLESS(entry.handler != nullptr, svc::ResultInvalidState()); - /* If auto-cleared, we can succeed immediately. */ - R_SUCCEED_IF(!entry.manually_cleared); - R_SUCCEED_IF(!entry.needs_clear); - - /* Clear and enable. */ - entry.needs_clear = false; - m_interrupt_controller.Enable(irq); - R_SUCCEED(); + /* If not auto-cleared, clear and enable. */ + if (entry.manually_cleared && entry.needs_clear) { + entry.needs_clear = false; + m_interrupt_controller.Enable(irq); + } } - Result KInterruptManager::ClearLocal(s32 irq) { - /* We can't clear an entry with no handler. */ + void KInterruptManager::ClearLocal(s32 irq) { + /* Get the entry. */ auto &entry = this->GetLocalInterruptEntry(irq); - R_UNLESS(entry.handler != nullptr, svc::ResultInvalidState()); - /* If auto-cleared, we can succeed immediately. */ - R_SUCCEED_IF(!entry.manually_cleared); - R_SUCCEED_IF(!entry.needs_clear); - - /* Clear and set priority. */ - entry.needs_clear = false; - m_interrupt_controller.SetPriorityLevel(irq, entry.priority); - R_SUCCEED(); + /* If not auto-cleared, clear and enable. */ + if (entry.manually_cleared && entry.needs_clear) { + entry.needs_clear = false; + m_interrupt_controller.Enable(irq); + } } } diff --git a/libraries/libmesosphere/source/arch/arm64/kern_k_page_table.cpp b/libraries/libmesosphere/source/arch/arm64/kern_k_page_table.cpp index abc3b1076..4607272be 100644 --- a/libraries/libmesosphere/source/arch/arm64/kern_k_page_table.cpp +++ b/libraries/libmesosphere/source/arch/arm64/kern_k_page_table.cpp @@ -119,15 +119,13 @@ namespace ams::kern::arch::arm64 { MESOSPHERE_UNUSED(core_id); } - Result KPageTable::InitializeForKernel(void *table, KVirtualAddress start, KVirtualAddress end) { + void KPageTable::InitializeForKernel(void *table, KVirtualAddress start, KVirtualAddress end) { /* Initialize basic fields. */ m_asid = 0; m_manager = Kernel::GetSystemSystemResource().GetPageTableManagerPointer(); /* Initialize the base page table. */ - MESOSPHERE_R_ABORT_UNLESS(KPageTableBase::InitializeForKernel(true, table, start, end)); - - R_SUCCEED(); + KPageTableBase::InitializeForKernel(true, table, start, end); } Result KPageTable::InitializeForProcess(ams::svc::CreateProcessFlag flags, bool from_back, KMemoryManager::Pool pool, KProcessAddress code_address, size_t code_size, KSystemResource *system_resource, KResourceLimit *resource_limit, size_t process_index) { @@ -942,7 +940,7 @@ namespace ams::kern::arch::arm64 { /* If we should flush entries, do so. */ if ((apply_option & ApplyOption_FlushDataCache) != 0) { if (IsHeapPhysicalAddress(next_entry.phys_addr)) { - cpu::FlushDataCache(GetVoidPointer(GetHeapVirtualAddress(next_entry.phys_addr)), next_entry.block_size); + MESOSPHERE_R_ABORT_UNLESS(cpu::FlushDataCache(GetVoidPointer(GetHeapVirtualAddress(next_entry.phys_addr)), next_entry.block_size)); } } diff --git a/libraries/libmesosphere/source/arch/arm64/kern_k_thread_context.cpp b/libraries/libmesosphere/source/arch/arm64/kern_k_thread_context.cpp index 76e91cff7..db93121b2 100644 --- a/libraries/libmesosphere/source/arch/arm64/kern_k_thread_context.cpp +++ b/libraries/libmesosphere/source/arch/arm64/kern_k_thread_context.cpp @@ -37,7 +37,7 @@ namespace ams::kern::arch::arm64 { KScopedInterruptEnable ei; const uintptr_t params[2] = { GetCurrentThread().GetId(), GetInteger(GetCurrentThread().GetThreadLocalRegionAddress()) }; - KDebug::OnDebugEvent(ams::svc::DebugEvent_CreateThread, params, util::size(params)); + static_cast(KDebug::OnDebugEvent(ams::svc::DebugEvent_CreateThread, params, util::size(params))); } /* Handle any pending dpc. */ @@ -116,7 +116,7 @@ namespace ams::kern::arch::arm64 { } - Result KThreadContext::Initialize(KVirtualAddress u_pc, KVirtualAddress k_sp, KVirtualAddress u_sp, uintptr_t arg, bool is_user, bool is_64_bit, bool is_main) { + void KThreadContext::Initialize(KVirtualAddress u_pc, KVirtualAddress k_sp, KVirtualAddress u_sp, uintptr_t arg, bool is_user, bool is_64_bit, bool is_main) { MESOSPHERE_ASSERT(k_sp != Null); /* Ensure that the stack pointers are aligned. */ @@ -157,8 +157,6 @@ namespace ams::kern::arch::arm64 { /* Lock the context, if we're a main thread. */ m_locked = is_main; - - R_SUCCEED(); } void KThreadContext::SetArguments(uintptr_t arg0, uintptr_t arg1) { diff --git a/libraries/libmesosphere/source/board/nintendo/nx/kern_k_device_page_table.cpp b/libraries/libmesosphere/source/board/nintendo/nx/kern_k_device_page_table.cpp index 292c25750..f02bbee51 100644 --- a/libraries/libmesosphere/source/board/nintendo/nx/kern_k_device_page_table.cpp +++ b/libraries/libmesosphere/source/board/nintendo/nx/kern_k_device_page_table.cpp @@ -660,8 +660,7 @@ namespace ams::kern::board::nintendo::nx { ptm.Open(table_virt_addr, 1); /* Save the page. Note that it is a pre-condition that the page is cleared, when allocated from the system page table manager. */ - /* NOTE: Nintendo does not check the result of StoreDataCache. */ - cpu::StoreDataCache(GetVoidPointer(table_virt_addr), PageDirectorySize); + MESOSPHERE_R_ABORT_UNLESS(cpu::StoreDataCache(GetVoidPointer(table_virt_addr), PageDirectorySize)); g_reserved_table_phys_addr = table_phys_addr; /* Reserve an asid to correspond to no device. */ @@ -806,7 +805,7 @@ namespace ams::kern::board::nintendo::nx { MESOSPHERE_ASSERT(IsValidPhysicalAddress(GetPageTablePhysicalAddress(table_vaddr))); ptm.Open(table_vaddr, 1); - cpu::StoreDataCache(GetVoidPointer(table_vaddr), PageDirectorySize); + MESOSPHERE_R_ABORT_UNLESS(cpu::StoreDataCache(GetVoidPointer(table_vaddr), PageDirectorySize)); m_tables[i] = table_vaddr; } @@ -1042,7 +1041,7 @@ namespace ams::kern::board::nintendo::nx { if (l2_index == 0 && util::IsAligned(GetInteger(phys_addr), DeviceLargePageSize) && remaining >= DeviceLargePageSize) { /* Set the large page. */ l1[l1_index].SetLargePage(read, write, true, phys_addr); - cpu::StoreDataCache(std::addressof(l1[l1_index]), sizeof(PageDirectoryEntry)); + MESOSPHERE_R_ABORT_UNLESS(cpu::StoreDataCache(std::addressof(l1[l1_index]), sizeof(PageDirectoryEntry))); /* Synchronize. */ InvalidatePtc(GetPageTablePhysicalAddress(KVirtualAddress(std::addressof(l1[l1_index])))); @@ -1062,11 +1061,11 @@ namespace ams::kern::board::nintendo::nx { const KVirtualAddress table_vaddr = ptm.Allocate(); R_UNLESS(table_vaddr != Null, svc::ResultOutOfMemory()); MESOSPHERE_ASSERT(IsValidPhysicalAddress(GetPageTablePhysicalAddress(table_vaddr))); - cpu::StoreDataCache(GetVoidPointer(table_vaddr), PageTableSize); + MESOSPHERE_R_ABORT_UNLESS(cpu::StoreDataCache(GetVoidPointer(table_vaddr), PageTableSize)); /* Set the l1 table. */ l1[l1_index].SetTable(true, true, true, GetPageTablePhysicalAddress(table_vaddr)); - cpu::StoreDataCache(std::addressof(l1[l1_index]), sizeof(PageDirectoryEntry)); + MESOSPHERE_R_ABORT_UNLESS(cpu::StoreDataCache(std::addressof(l1[l1_index]), sizeof(PageDirectoryEntry))); /* Synchronize. */ InvalidatePtc(GetPageTablePhysicalAddress(KVirtualAddress(std::addressof(l1[l1_index])))); @@ -1093,7 +1092,7 @@ namespace ams::kern::board::nintendo::nx { /* Add a reference to the l2 page (from the l2 entry page). */ ptm.Open(KVirtualAddress(l2), 1); } - cpu::StoreDataCache(std::addressof(l2[l2_index]), map_count * sizeof(PageTableEntry)); + MESOSPHERE_R_ABORT_UNLESS(cpu::StoreDataCache(std::addressof(l2[l2_index]), map_count * sizeof(PageTableEntry))); /* Invalidate the page table cache. */ for (size_t i = util::AlignDown(l2_index, 4); i <= util::AlignDown(l2_index + map_count - 1, 4); i += 4) { @@ -1199,7 +1198,7 @@ namespace ams::kern::board::nintendo::nx { ++num_closed; } } - cpu::StoreDataCache(std::addressof(l2[l2_index]), map_count * sizeof(PageTableEntry)); + MESOSPHERE_R_ABORT_UNLESS(cpu::StoreDataCache(std::addressof(l2[l2_index]), map_count * sizeof(PageTableEntry))); /* Invalidate the page table cache. */ for (size_t i = util::AlignDown(l2_index, 4); i <= util::AlignDown(l2_index + map_count - 1, 4); i += 4) { @@ -1243,7 +1242,7 @@ namespace ams::kern::board::nintendo::nx { if (ptm.Close(KVirtualAddress(l2), num_closed)) { /* Invalidate the l1 entry. */ l1[l1_index].Invalidate(); - cpu::StoreDataCache(std::addressof(l1[l1_index]), sizeof(PageDirectoryEntry)); + MESOSPHERE_R_ABORT_UNLESS(cpu::StoreDataCache(std::addressof(l1[l1_index]), sizeof(PageDirectoryEntry))); /* Synchronize. */ InvalidatePtc(GetPageTablePhysicalAddress(KVirtualAddress(std::addressof(l1[l1_index])))); @@ -1266,7 +1265,7 @@ namespace ams::kern::board::nintendo::nx { /* Invalidate the entry. */ l1[l1_index].Invalidate(); - cpu::StoreDataCache(std::addressof(l1[l1_index]), sizeof(PageDirectoryEntry)); + MESOSPHERE_R_ABORT_UNLESS(cpu::StoreDataCache(std::addressof(l1[l1_index]), sizeof(PageDirectoryEntry))); /* Synchronize. */ InvalidatePtc(GetPageTablePhysicalAddress(KVirtualAddress(std::addressof(l1[l1_index])))); diff --git a/libraries/libmesosphere/source/board/nintendo/nx/kern_k_sleep_manager.cpp b/libraries/libmesosphere/source/board/nintendo/nx/kern_k_sleep_manager.cpp index 59e7770ea..7f8290c12 100644 --- a/libraries/libmesosphere/source/board/nintendo/nx/kern_k_sleep_manager.cpp +++ b/libraries/libmesosphere/source/board/nintendo/nx/kern_k_sleep_manager.cpp @@ -441,7 +441,7 @@ namespace ams::kern::board::nintendo::nx { KThread::Register(new_thread); /* Run the thread. */ - new_thread->Run(); + MESOSPHERE_R_ABORT_UNLESS(new_thread->Run()); } } diff --git a/libraries/libmesosphere/source/kern_initial_process.cpp b/libraries/libmesosphere/source/kern_initial_process.cpp index ab38d5774..60d8881c3 100644 --- a/libraries/libmesosphere/source/kern_initial_process.cpp +++ b/libraries/libmesosphere/source/kern_initial_process.cpp @@ -140,14 +140,12 @@ namespace ams::kern { /* Add the previously reserved pages. */ if (src_pool == dst_pool && binary_pages != 0) { - /* NOTE: Nintendo does not check the result of this operation. */ - pg.AddBlock(KMemoryLayout::GetLinearPhysicalAddress(data), binary_pages); + MESOSPHERE_R_ABORT_UNLESS(pg.AddBlock(KMemoryLayout::GetLinearPhysicalAddress(data), binary_pages)); } /* Add the previously unreserved pages. */ for (const auto &block : unreserve_pg) { - /* NOTE: Nintendo does not check the result of this operation. */ - pg.AddBlock(block.GetAddress(), block.GetNumPages()); + MESOSPHERE_R_ABORT_UNLESS(pg.AddBlock(block.GetAddress(), block.GetNumPages())); } } MESOSPHERE_ABORT_UNLESS(pg.GetNumPages() == static_cast(params.code_num_pages)); diff --git a/libraries/libmesosphere/source/kern_k_code_memory.cpp b/libraries/libmesosphere/source/kern_k_code_memory.cpp index 6a5a30ffa..14ac6c83f 100644 --- a/libraries/libmesosphere/source/kern_k_code_memory.cpp +++ b/libraries/libmesosphere/source/kern_k_code_memory.cpp @@ -37,7 +37,7 @@ namespace ams::kern { /* Clear and store cache. */ void * const block_address = GetVoidPointer(KMemoryLayout::GetLinearVirtualAddress(block.GetAddress())); std::memset(block_address, 0xFF, block.GetSize()); - cpu::StoreDataCache(block_address, block.GetSize()); + MESOSPHERE_R_ABORT_UNLESS(cpu::StoreDataCache(block_address, block.GetSize())); } /* Set remaining tracking members. */ diff --git a/libraries/libmesosphere/source/kern_k_debug_base.cpp b/libraries/libmesosphere/source/kern_k_debug_base.cpp index 635673cd2..88ec79185 100644 --- a/libraries/libmesosphere/source/kern_k_debug_base.cpp +++ b/libraries/libmesosphere/source/kern_k_debug_base.cpp @@ -416,7 +416,8 @@ namespace ams::kern { KProcess * const target = this->GetProcessUnsafe(); /* Terminate the process. */ - target->Terminate(); + /* NOTE: This result is seemingly-intentionally not checked by Nintendo. */ + static_cast(target->Terminate()); R_SUCCEED(); } @@ -1133,7 +1134,7 @@ namespace ams::kern { R_SUCCEED(); } - Result KDebugBase::OnExitProcess(KProcess *process) { + void KDebugBase::OnExitProcess(KProcess *process) { MESOSPHERE_ASSERT(process != nullptr); /* Check if we're attached to a debugger. */ @@ -1148,11 +1149,9 @@ namespace ams::kern { debug->NotifyAvailable(); } } - - R_SUCCEED(); } - Result KDebugBase::OnTerminateProcess(KProcess *process) { + void KDebugBase::OnTerminateProcess(KProcess *process) { MESOSPHERE_ASSERT(process != nullptr); /* Check if we're attached to a debugger. */ @@ -1167,21 +1166,17 @@ namespace ams::kern { debug->NotifyAvailable(); } } - - R_SUCCEED(); } - Result KDebugBase::OnExitThread(KThread *thread) { + void KDebugBase::OnExitThread(KThread *thread) { MESOSPHERE_ASSERT(thread != nullptr); /* Check if we're attached to a debugger. */ if (KProcess *process = thread->GetOwnerProcess(); process != nullptr && process->IsAttachedToDebugger()) { /* If we are, submit the event. */ const uintptr_t params[2] = { thread->GetId(), static_cast(thread->IsTerminationRequested() ? ams::svc::ThreadExitReason_TerminateThread : ams::svc::ThreadExitReason_ExitThread) }; - R_TRY(OnDebugEvent(ams::svc::DebugEvent_ExitThread, params, util::size(params))); + static_cast(OnDebugEvent(ams::svc::DebugEvent_ExitThread, params, util::size(params))); } - - R_SUCCEED(); } } diff --git a/libraries/libmesosphere/source/kern_k_dpc_manager.cpp b/libraries/libmesosphere/source/kern_k_dpc_manager.cpp index 9d2218e24..2b11ec408 100644 --- a/libraries/libmesosphere/source/kern_k_dpc_manager.cpp +++ b/libraries/libmesosphere/source/kern_k_dpc_manager.cpp @@ -167,7 +167,7 @@ namespace ams::kern { KThread::Register(new_thread); /* Run the thread. */ - new_thread->Run(); + MESOSPHERE_R_ABORT_UNLESS(new_thread->Run()); } void KDpcManager::HandleDpc() { diff --git a/libraries/libmesosphere/source/kern_k_event.cpp b/libraries/libmesosphere/source/kern_k_event.cpp index 5400557ec..7228155e6 100644 --- a/libraries/libmesosphere/source/kern_k_event.cpp +++ b/libraries/libmesosphere/source/kern_k_event.cpp @@ -38,20 +38,20 @@ namespace ams::kern { MESOSPHERE_ASSERT_THIS(); } - Result KEvent::Signal() { + void KEvent::Signal() { KScopedSchedulerLock sl; - R_SUCCEED_IF(m_readable_event_destroyed); - - R_RETURN(m_readable_event.Signal()); + if (!m_readable_event_destroyed) { + m_readable_event.Signal(); + } } - Result KEvent::Clear() { + void KEvent::Clear() { KScopedSchedulerLock sl; - R_SUCCEED_IF(m_readable_event_destroyed); - - R_RETURN(m_readable_event.Clear()); + if (!m_readable_event_destroyed) { + m_readable_event.Clear(); + } } void KEvent::PostDestroy(uintptr_t arg) { diff --git a/libraries/libmesosphere/source/kern_k_page_table_base.cpp b/libraries/libmesosphere/source/kern_k_page_table_base.cpp index ad42a62a4..ea44184fe 100644 --- a/libraries/libmesosphere/source/kern_k_page_table_base.cpp +++ b/libraries/libmesosphere/source/kern_k_page_table_base.cpp @@ -88,7 +88,7 @@ namespace ams::kern { } } - Result KPageTableBase::InitializeForKernel(bool is_64_bit, void *table, KVirtualAddress start, KVirtualAddress end) { + void KPageTableBase::InitializeForKernel(bool is_64_bit, void *table, KVirtualAddress start, KVirtualAddress end) { /* Initialize our members. */ m_address_space_width = (is_64_bit) ? BITSIZEOF(u64) : BITSIZEOF(u32); m_address_space_start = KProcessAddress(GetInteger(start)); @@ -130,7 +130,7 @@ namespace ams::kern { m_impl.InitializeForKernel(table, start, end); /* Initialize our memory block manager. */ - R_RETURN(m_memory_block_manager.Initialize(m_address_space_start, m_address_space_end, m_memory_block_slab_manager)); + MESOSPHERE_R_ABORT_UNLESS(m_memory_block_manager.Initialize(m_address_space_start, m_address_space_end, m_memory_block_slab_manager)); } Result KPageTableBase::InitializeForProcess(ams::svc::CreateProcessFlag flags, bool from_back, KMemoryManager::Pool pool, void *table, KProcessAddress start, KProcessAddress end, KProcessAddress code_address, size_t code_size, KSystemResource *system_resource, KResourceLimit *resource_limit) { @@ -1792,7 +1792,7 @@ namespace ams::kern { /* Ensure cache coherency, if we're setting pages as executable. */ if (is_x) { for (const auto &block : pg) { - cpu::StoreDataCache(GetVoidPointer(GetHeapVirtualAddress(block.GetAddress())), block.GetSize()); + MESOSPHERE_R_ABORT_UNLESS(cpu::StoreDataCache(GetVoidPointer(GetHeapVirtualAddress(block.GetAddress())), block.GetSize())); } cpu::InvalidateEntireInstructionCache(); } @@ -2665,8 +2665,7 @@ namespace ams::kern { /* Invalidate the block. */ if (cur_size > 0) { - /* NOTE: Nintendo does not check the result of invalidation. */ - cpu::InvalidateDataCache(GetVoidPointer(GetLinearMappedVirtualAddress(cur_addr)), cur_size); + MESOSPHERE_R_ABORT_UNLESS(cpu::InvalidateDataCache(GetVoidPointer(GetLinearMappedVirtualAddress(cur_addr)), cur_size)); } /* Advance. */ @@ -2689,8 +2688,7 @@ namespace ams::kern { /* Invalidate the last block. */ if (cur_size > 0) { - /* NOTE: Nintendo does not check the result of invalidation. */ - cpu::InvalidateDataCache(GetVoidPointer(GetLinearMappedVirtualAddress(cur_addr)), cur_size); + MESOSPHERE_R_ABORT_UNLESS(cpu::InvalidateDataCache(GetVoidPointer(GetLinearMappedVirtualAddress(cur_addr)), cur_size)); } R_SUCCEED(); @@ -2768,7 +2766,7 @@ namespace ams::kern { if (cur_size >= sizeof(u32)) { const size_t copy_size = util::AlignDown(cur_size, sizeof(u32)); const void * copy_src = GetVoidPointer(GetLinearMappedVirtualAddress(cur_addr)); - cpu::FlushDataCache(copy_src, copy_size); + MESOSPHERE_R_ABORT_UNLESS(cpu::FlushDataCache(copy_src, copy_size)); R_UNLESS(UserspaceAccess::CopyMemoryToUserAligned32Bit(buffer, copy_src, copy_size), svc::ResultInvalidPointer()); buffer = reinterpret_cast(reinterpret_cast(buffer) + copy_size); cur_addr += copy_size; @@ -2778,7 +2776,7 @@ namespace ams::kern { /* Copy remaining data. */ if (cur_size > 0) { const void * copy_src = GetVoidPointer(GetLinearMappedVirtualAddress(cur_addr)); - cpu::FlushDataCache(copy_src, cur_size); + MESOSPHERE_R_ABORT_UNLESS(cpu::FlushDataCache(copy_src, cur_size)); R_UNLESS(UserspaceAccess::CopyMemoryToUser(buffer, copy_src, cur_size), svc::ResultInvalidPointer()); } @@ -2853,7 +2851,7 @@ namespace ams::kern { if (cur_size >= sizeof(u32)) { const size_t copy_size = util::AlignDown(cur_size, sizeof(u32)); R_UNLESS(UserspaceAccess::CopyMemoryFromUserAligned32Bit(GetVoidPointer(GetLinearMappedVirtualAddress(cur_addr)), buffer, copy_size), svc::ResultInvalidCurrentMemory()); - cpu::StoreDataCache(GetVoidPointer(GetLinearMappedVirtualAddress(cur_addr)), copy_size); + MESOSPHERE_R_ABORT_UNLESS(cpu::StoreDataCache(GetVoidPointer(GetLinearMappedVirtualAddress(cur_addr)), copy_size)); buffer = reinterpret_cast(reinterpret_cast(buffer) + copy_size); cur_addr += copy_size; @@ -2863,7 +2861,7 @@ namespace ams::kern { /* Copy remaining data. */ if (cur_size > 0) { R_UNLESS(UserspaceAccess::CopyMemoryFromUser(GetVoidPointer(GetLinearMappedVirtualAddress(cur_addr)), buffer, cur_size), svc::ResultInvalidCurrentMemory()); - cpu::StoreDataCache(GetVoidPointer(GetLinearMappedVirtualAddress(cur_addr)), cur_size); + MESOSPHERE_R_ABORT_UNLESS(cpu::StoreDataCache(GetVoidPointer(GetLinearMappedVirtualAddress(cur_addr)), cur_size)); } R_SUCCEED(); diff --git a/libraries/libmesosphere/source/kern_k_process.cpp b/libraries/libmesosphere/source/kern_k_process.cpp index 08a79f5c0..0d1d4b6dc 100644 --- a/libraries/libmesosphere/source/kern_k_process.cpp +++ b/libraries/libmesosphere/source/kern_k_process.cpp @@ -404,7 +404,7 @@ namespace ams::kern { void KProcess::DoWorkerTaskImpl() { /* Terminate child threads. */ - TerminateChildren(this, nullptr); + MESOSPHERE_R_ABORT_UNLESS(TerminateChildren(this, nullptr)); /* Finalize the handle table, if we're not immortal. */ if (!m_is_immortal && m_is_handle_table_initialized) { @@ -420,7 +420,7 @@ namespace ams::kern { Result KProcess::StartTermination() { /* Finalize the handle table when we're done, if the process isn't immortal. */ - ON_SCOPE_EXIT { + ON_RESULT_SUCCESS { if (!m_is_immortal) { this->FinalizeHandleTable(); } @@ -471,7 +471,7 @@ namespace ams::kern { /* If we need to start termination, do so. */ if (needs_terminate) { - this->StartTermination(); + static_cast(this->StartTermination()); /* Note for debug that we're exiting the process. */ MESOSPHERE_LOG("KProcess::Exit() pid=%ld name=%-12s\n", m_process_id, m_name); @@ -507,23 +507,26 @@ namespace ams::kern { /* If we need to terminate, do so. */ if (needs_terminate) { - /* Start termination. */ - if (R_SUCCEEDED(this->StartTermination())) { - /* Note for debug that we're terminating the process. */ - MESOSPHERE_LOG("KProcess::Terminate() OK pid=%ld name=%-12s\n", m_process_id, m_name); - - /* Call the debug callback. */ - KDebug::OnTerminateProcess(this); - - /* Finish termination. */ - this->FinishTermination(); - } else { + /* If we fail to terminate, register as a worker task. */ + ON_RESULT_FAILURE { /* Note for debug that we're terminating the process. */ MESOSPHERE_LOG("KProcess::Terminate() FAIL pid=%ld name=%-12s\n", m_process_id, m_name); /* Register the process as a work task. */ KWorkerTaskManager::AddTask(KWorkerTaskManager::WorkerType_ExitProcess, this); - } + }; + + /* Start termination. */ + R_TRY(this->StartTermination()); + + /* Note for debug that we're terminating the process. */ + MESOSPHERE_LOG("KProcess::Terminate() OK pid=%ld name=%-12s\n", m_process_id, m_name); + + /* Call the debug callback. */ + KDebug::OnTerminateProcess(this); + + /* Finish termination. */ + this->FinishTermination(); } R_SUCCEED(); @@ -666,7 +669,7 @@ namespace ams::kern { R_SUCCEED(); } - Result KProcess::DeleteThreadLocalRegion(KProcessAddress addr) { + void KProcess::DeleteThreadLocalRegion(KProcessAddress addr) { KThreadLocalPage *page_to_free = nullptr; /* Release the region. */ @@ -678,7 +681,7 @@ namespace ams::kern { if (it == m_partially_used_tlp_tree.end()) { /* If we don't find it, it has to be in the fully used list. */ it = m_fully_used_tlp_tree.find_key(util::AlignDown(GetInteger(addr), PageSize)); - R_UNLESS(it != m_fully_used_tlp_tree.end(), svc::ResultInvalidAddress()); + MESOSPHERE_ABORT_UNLESS(it != m_fully_used_tlp_tree.end()); /* Release the region. */ it->Release(addr); @@ -710,8 +713,6 @@ namespace ams::kern { KThreadLocalPage::Free(page_to_free); } - - R_SUCCEED(); } void *KProcess::GetThreadLocalRegionPointer(KProcessAddress addr) { @@ -767,7 +768,7 @@ namespace ams::kern { MESOSPHERE_ASSERT(m_num_running_threads.Load() > 0); if (const auto prev = m_num_running_threads--; prev == 1) { - this->Terminate(); + static_cast(this->Terminate()); } } diff --git a/libraries/libmesosphere/source/kern_k_readable_event.cpp b/libraries/libmesosphere/source/kern_k_readable_event.cpp index 375e536fa..81703818f 100644 --- a/libraries/libmesosphere/source/kern_k_readable_event.cpp +++ b/libraries/libmesosphere/source/kern_k_readable_event.cpp @@ -46,7 +46,7 @@ namespace ams::kern { } } - Result KReadableEvent::Signal() { + void KReadableEvent::Signal() { MESOSPHERE_ASSERT_THIS(); KScopedSchedulerLock lk; @@ -55,8 +55,6 @@ namespace ams::kern { m_is_signaled = true; this->NotifyAvailable(); } - - R_SUCCEED(); } Result KReadableEvent::Reset() { diff --git a/libraries/libmesosphere/source/kern_k_scheduler.cpp b/libraries/libmesosphere/source/kern_k_scheduler.cpp index bf0e6c190..e39eab8c9 100644 --- a/libraries/libmesosphere/source/kern_k_scheduler.cpp +++ b/libraries/libmesosphere/source/kern_k_scheduler.cpp @@ -65,7 +65,7 @@ namespace ams::kern { } /* Bind interrupt handler. */ - Kernel::GetInterruptManager().BindHandler(GetSchedulerInterruptHandler(), KInterruptName_Scheduler, m_core_id, KInterruptController::PriorityLevel_Scheduler, false, false); + MESOSPHERE_R_ABORT_UNLESS(Kernel::GetInterruptManager().BindHandler(GetSchedulerInterruptHandler(), KInterruptName_Scheduler, m_core_id, KInterruptController::PriorityLevel_Scheduler, false, false)); /* Set the current thread. */ m_current_thread = GetCurrentThreadPointer(); diff --git a/libraries/libmesosphere/source/kern_k_server_session.cpp b/libraries/libmesosphere/source/kern_k_server_session.cpp index 7c8c4e91c..80d4b81cc 100644 --- a/libraries/libmesosphere/source/kern_k_server_session.cpp +++ b/libraries/libmesosphere/source/kern_k_server_session.cpp @@ -476,8 +476,8 @@ namespace ams::kern { /* Ensure that we clean up on failure. */ ON_RESULT_FAILURE { - dst_page_table.CleanupForIpcServer(dst_address, size, dst_state); - src_page_table.CleanupForIpcClient(src_address, size, dst_state); + static_cast(dst_page_table.CleanupForIpcServer(dst_address, size, dst_state)); + static_cast(src_page_table.CleanupForIpcClient(src_address, size, dst_state)); }; /* Push the appropriate mapping. */ @@ -582,7 +582,7 @@ namespace ams::kern { /* Set up a guard to make sure that we end up in a clean state on error. */ ON_RESULT_FAILURE { /* Cleanup mappings. */ - CleanupMap(request, std::addressof(dst_process), std::addressof(src_page_table)); + static_cast(CleanupMap(request, std::addressof(dst_process), std::addressof(src_page_table))); /* Cleanup special data. */ if (src_header.GetHasSpecialHeader()) { @@ -835,11 +835,11 @@ namespace ams::kern { CleanupSpecialData(dst_process, dst_msg_ptr, dst_buffer_size); } } else { - CleanupServerHandles(src_user ? src_message_buffer : 0, src_buffer_size, src_message_paddr); + static_cast(CleanupServerHandles(src_user ? src_message_buffer : 0, src_buffer_size, src_message_paddr)); } /* Cleanup mappings. */ - CleanupMap(request, std::addressof(src_process), std::addressof(dst_page_table)); + static_cast(CleanupMap(request, std::addressof(src_process), std::addressof(dst_page_table))); }; /* Ensure that the headers fit. */ @@ -1052,7 +1052,7 @@ namespace ams::kern { /* Unlock the client buffer. */ /* NOTE: Nintendo does not check the result of this. */ - client_pt.UnlockForIpcUserBuffer(client_message, client_buffer_size); + static_cast(client_pt.UnlockForIpcUserBuffer(client_message, client_buffer_size)); /* Signal the event. */ event->Signal(); @@ -1156,7 +1156,7 @@ namespace ams::kern { /* Unlock the client buffer. */ /* NOTE: Nintendo does not check the result of this. */ - client_page_table->UnlockForIpcUserBuffer(client_message, client_buffer_size); + static_cast(client_page_table->UnlockForIpcUserBuffer(client_message, client_buffer_size)); /* Signal the event. */ event->Signal(); @@ -1284,7 +1284,7 @@ namespace ams::kern { /* Unlock the client buffer. */ /* NOTE: Nintendo does not check the result of this. */ - client_page_table->UnlockForIpcUserBuffer(client_message, client_buffer_size); + static_cast(client_page_table->UnlockForIpcUserBuffer(client_message, client_buffer_size)); /* Signal the event. */ event->Signal(); @@ -1383,7 +1383,7 @@ namespace ams::kern { /* Unlock the buffer. */ /* NOTE: Nintendo does not check the result of this. */ - client_pt.UnlockForIpcUserBuffer(request->GetAddress(), request->GetSize()); + static_cast(client_pt.UnlockForIpcUserBuffer(request->GetAddress(), request->GetSize())); /* Signal the event. */ event->Signal(); diff --git a/libraries/libmesosphere/source/kern_k_system_resource.cpp b/libraries/libmesosphere/source/kern_k_system_resource.cpp index fc4876252..93815fe69 100644 --- a/libraries/libmesosphere/source/kern_k_system_resource.cpp +++ b/libraries/libmesosphere/source/kern_k_system_resource.cpp @@ -42,7 +42,7 @@ namespace ams::kern { R_UNLESS(m_resource_size > rc_size, svc::ResultOutOfMemory()); /* Initialize slab heaps. */ - m_dynamic_page_manager.Initialize(m_resource_address + rc_size, m_resource_size - rc_size, PageSize); + R_TRY(m_dynamic_page_manager.Initialize(m_resource_address + rc_size, m_resource_size - rc_size, PageSize)); m_page_table_heap.Initialize(std::addressof(m_dynamic_page_manager), 0, GetPointer(m_resource_address)); m_memory_block_heap.Initialize(std::addressof(m_dynamic_page_manager), 0); m_block_info_heap.Initialize(std::addressof(m_dynamic_page_manager), 0); diff --git a/libraries/libmesosphere/source/kern_k_thread.cpp b/libraries/libmesosphere/source/kern_k_thread.cpp index 74b39acd3..9cf5ea862 100644 --- a/libraries/libmesosphere/source/kern_k_thread.cpp +++ b/libraries/libmesosphere/source/kern_k_thread.cpp @@ -392,7 +392,7 @@ namespace ams::kern { /* If the thread has a local region, delete it. */ if (m_tls_address != Null) { - MESOSPHERE_R_ABORT_UNLESS(m_parent->DeleteThreadLocalRegion(m_tls_address)); + m_parent->DeleteThreadLocalRegion(m_tls_address); } /* Release any waiters. */ @@ -697,7 +697,7 @@ namespace ams::kern { R_SUCCEED(); } - Result KThread::GetPhysicalCoreMask(int32_t *out_ideal_core, u64 *out_affinity_mask) { + void KThread::GetPhysicalCoreMask(int32_t *out_ideal_core, u64 *out_affinity_mask) { MESOSPHERE_ASSERT_THIS(); { KScopedSchedulerLock sl; @@ -712,8 +712,6 @@ namespace ams::kern { *out_affinity_mask = m_original_physical_affinity_mask.GetAffinityMask(); } } - - R_SUCCEED(); } Result KThread::SetCoreMask(int32_t core_id, u64 v_affinity_mask) { @@ -852,7 +850,7 @@ namespace ams::kern { } } - Result KThread::SetPriorityToIdle() { + void KThread::SetPriorityToIdle() { MESOSPHERE_ASSERT_THIS(); KScopedSchedulerLock sl; @@ -862,8 +860,6 @@ namespace ams::kern { m_priority = IdleThreadPriority; m_base_priority = IdleThreadPriority; KScheduler::OnThreadPriorityChanged(this, old_priority); - - R_SUCCEED(); } void KThread::RequestSuspend(SuspendType type) { @@ -1407,7 +1403,7 @@ namespace ams::kern { return this->GetState(); } - Result KThread::Sleep(s64 timeout) { + void KThread::Sleep(s64 timeout) { MESOSPHERE_ASSERT_THIS(); MESOSPHERE_ASSERT(!KScheduler::IsSchedulerLockedByCurrentThread()); MESOSPHERE_ASSERT(this == GetCurrentThreadPointer()); @@ -1422,15 +1418,13 @@ namespace ams::kern { /* Check if the thread should terminate. */ if (this->IsTerminationRequested()) { slp.CancelSleep(); - R_THROW(svc::ResultTerminationRequested()); + return; } /* Wait for the sleep to end. */ wait_queue.SetHardwareTimer(timer); this->BeginWait(std::addressof(wait_queue)); } - - R_SUCCEED(); } void KThread::BeginWait(KThreadQueue *queue) { diff --git a/libraries/libmesosphere/source/kern_k_thread_local_page.cpp b/libraries/libmesosphere/source/kern_k_thread_local_page.cpp index e0358cc13..63445f906 100644 --- a/libraries/libmesosphere/source/kern_k_thread_local_page.cpp +++ b/libraries/libmesosphere/source/kern_k_thread_local_page.cpp @@ -32,7 +32,7 @@ namespace ams::kern { R_RETURN(m_owner->GetPageTable().MapPages(std::addressof(m_virt_addr), 1, PageSize, page_buf->GetPhysicalAddress(), KMemoryState_ThreadLocal, KMemoryPermission_UserReadWrite)); } - Result KThreadLocalPage::Finalize() { + void KThreadLocalPage::Finalize() { MESOSPHERE_ASSERT_THIS(); /* Get the physical address of the page. */ @@ -40,11 +40,10 @@ namespace ams::kern { MESOSPHERE_ABORT_UNLESS(m_owner->GetPageTable().GetPhysicalAddress(std::addressof(phys_addr), this->GetAddress())); /* Unmap the page. */ - R_TRY(m_owner->GetPageTable().UnmapPages(this->GetAddress(), 1, KMemoryState_ThreadLocal)); + MESOSPHERE_R_ABORT_UNLESS(m_owner->GetPageTable().UnmapPages(this->GetAddress(), 1, KMemoryState_ThreadLocal)); /* Free the page. */ KPageBuffer::FreeChecked(KPageBuffer::FromPhysicalAddress(phys_addr)); - R_SUCCEED(); } KProcessAddress KThreadLocalPage::Reserve() { diff --git a/libraries/libmesosphere/source/kern_k_worker_task_manager.cpp b/libraries/libmesosphere/source/kern_k_worker_task_manager.cpp index f639e7764..b246c980c 100644 --- a/libraries/libmesosphere/source/kern_k_worker_task_manager.cpp +++ b/libraries/libmesosphere/source/kern_k_worker_task_manager.cpp @@ -67,7 +67,7 @@ namespace ams::kern { KThread::Register(thread); /* Run the thread. */ - thread->Run(); + MESOSPHERE_R_ABORT_UNLESS(thread->Run()); } void KWorkerTaskManager::AddTask(WorkerType type, KWorkerTask *task) { diff --git a/libraries/libmesosphere/source/kern_kernel.cpp b/libraries/libmesosphere/source/kern_kernel.cpp index 9660d906d..a63cf3cdd 100644 --- a/libraries/libmesosphere/source/kern_kernel.cpp +++ b/libraries/libmesosphere/source/kern_kernel.cpp @@ -52,8 +52,8 @@ namespace ams::kern { void *idle_thread_stack = GetVoidPointer(KMemoryLayout::GetIdleStackTopAddress(core_id)); KAutoObject::Create(main_thread); KAutoObject::Create(idle_thread); - main_thread->Initialize(nullptr, 0, main_thread_stack, 0, KThread::MainThreadPriority, core_id, nullptr, KThread::ThreadType_Main); - idle_thread->Initialize(nullptr, 0, idle_thread_stack, 0, KThread::IdleThreadPriority, core_id, nullptr, KThread::ThreadType_Main); + MESOSPHERE_R_ABORT_UNLESS(main_thread->Initialize(nullptr, 0, main_thread_stack, 0, KThread::MainThreadPriority, core_id, nullptr, KThread::ThreadType_Main)); + MESOSPHERE_R_ABORT_UNLESS(idle_thread->Initialize(nullptr, 0, idle_thread_stack, 0, KThread::IdleThreadPriority, core_id, nullptr, KThread::ThreadType_Main)); /* Set the current thread to be the main thread, and we have no processes running yet. */ SetCurrentThread(main_thread); @@ -79,7 +79,7 @@ namespace ams::kern { KDynamicPageManager * const sys_dynamic_page_manager = KTargetSystem::IsDynamicResourceLimitsEnabled() ? std::addressof(g_resource_manager_page_manager) : nullptr; /* Initialize the resource managers' shared page manager. */ - g_resource_manager_page_manager.Initialize(address, size, std::max(PageSize, KPageBufferSlabHeap::BufferSize)); + MESOSPHERE_R_ABORT_UNLESS(g_resource_manager_page_manager.Initialize(address, size, std::max(PageSize, KPageBufferSlabHeap::BufferSize))); /* Initialize the KPageBuffer slab heap. */ KPageBuffer::InitializeSlabHeap(g_resource_manager_page_manager); diff --git a/libraries/libmesosphere/source/svc/kern_svc_cache.cpp b/libraries/libmesosphere/source/svc/kern_svc_cache.cpp index c6ffb5e4c..00f84781f 100644 --- a/libraries/libmesosphere/source/svc/kern_svc_cache.cpp +++ b/libraries/libmesosphere/source/svc/kern_svc_cache.cpp @@ -131,7 +131,7 @@ namespace ams::kern::svc { } else { class StoreCacheOperation : public CacheOperation { public: - virtual void Operate(void *address, size_t size) const override { cpu::StoreDataCache(address, size); } + virtual void Operate(void *address, size_t size) const override { MESOSPHERE_R_ABORT_UNLESS(cpu::StoreDataCache(address, size)); } } operation; R_RETURN(DoProcessCacheOperation(operation, page_table, address, size)); @@ -158,7 +158,7 @@ namespace ams::kern::svc { } else { class FlushCacheOperation : public CacheOperation { public: - virtual void Operate(void *address, size_t size) const override { cpu::FlushDataCache(address, size); } + virtual void Operate(void *address, size_t size) const override { MESOSPHERE_R_ABORT_UNLESS(cpu::FlushDataCache(address, size)); } } operation; R_RETURN(DoProcessCacheOperation(operation, page_table, address, size)); diff --git a/libraries/libmesosphere/source/svc/kern_svc_event.cpp b/libraries/libmesosphere/source/svc/kern_svc_event.cpp index 571347be9..a409d75ec 100644 --- a/libraries/libmesosphere/source/svc/kern_svc_event.cpp +++ b/libraries/libmesosphere/source/svc/kern_svc_event.cpp @@ -29,7 +29,8 @@ namespace ams::kern::svc { KScopedAutoObject event = handle_table.GetObject(event_handle); R_UNLESS(event.IsNotNull(), svc::ResultInvalidHandle()); - R_RETURN(event->Signal()); + event->Signal(); + R_SUCCEED(); } Result ClearEvent(ams::svc::Handle event_handle) { @@ -40,7 +41,7 @@ namespace ams::kern::svc { { KScopedAutoObject event = handle_table.GetObject(event_handle); if (event.IsNotNull()) { - R_RETURN(event->Clear()); + event->Clear(); } } @@ -49,9 +50,9 @@ namespace ams::kern::svc { KScopedAutoObject readable_event = handle_table.GetObject(event_handle); if (readable_event.IsNotNull()) { if (auto * const interrupt_event = readable_event->DynamicCast(); interrupt_event != nullptr) { - R_RETURN(interrupt_event->Clear()); + interrupt_event->Clear(); } else { - R_RETURN(readable_event->Clear()); + readable_event->Clear(); } } } diff --git a/libraries/libmesosphere/source/svc/kern_svc_ipc.cpp b/libraries/libmesosphere/source/svc/kern_svc_ipc.cpp index a67b581cb..e2013a1b3 100644 --- a/libraries/libmesosphere/source/svc/kern_svc_ipc.cpp +++ b/libraries/libmesosphere/source/svc/kern_svc_ipc.cpp @@ -148,7 +148,7 @@ namespace ams::kern::svc { { /* If we fail to send the message, unlock the message buffer. */ - ON_RESULT_FAILURE { page_table.UnlockForIpcUserBuffer(message, buffer_size); }; + ON_RESULT_FAILURE { static_cast(page_table.UnlockForIpcUserBuffer(message, buffer_size)); }; /* Send the request. */ MESOSPHERE_ASSERT(message != 0); @@ -220,7 +220,7 @@ namespace ams::kern::svc { /* Ensure that if we fail and aren't terminating that we unlock the user buffer. */ ON_RESULT_FAILURE_BESIDES(svc::ResultTerminationRequested) { - page_table.UnlockForIpcUserBuffer(message, buffer_size); + static_cast(page_table.UnlockForIpcUserBuffer(message, buffer_size)); }; /* Send the request. */ @@ -248,7 +248,7 @@ namespace ams::kern::svc { { /* If we fail to send the message, unlock the message buffer. */ - ON_RESULT_FAILURE { page_table.UnlockForIpcUserBuffer(message, buffer_size); }; + ON_RESULT_FAILURE { static_cast(page_table.UnlockForIpcUserBuffer(message, buffer_size)); }; /* Reply/Receive the request. */ MESOSPHERE_ASSERT(message != 0); diff --git a/libraries/libstratosphere/include/stratosphere/erpt/erpt_ids.autogen.hpp b/libraries/libstratosphere/include/stratosphere/erpt/erpt_ids.autogen.hpp index a6a6d5f55..8f599ec3d 100644 --- a/libraries/libstratosphere/include/stratosphere/erpt/erpt_ids.autogen.hpp +++ b/libraries/libstratosphere/include/stratosphere/erpt/erpt_ids.autogen.hpp @@ -165,8 +165,8 @@ HANDLER(NvHostErrInfo, 124 ) \ HANDLER(RunningUlaInfo, 125 ) \ HANDLER(InternalPanelInfo, 126 ) \ - HANDLER(ResourceLimitLimitInfo, 127 ) \ - HANDLER(ResourceLimitPeakInfo, 128 ) \ + HANDLER(ResourceLimitInfo, 127 ) \ + HANDLER(ResourceLimitPeakInfoDeprecated, 128 ) \ HANDLER(TouchScreenInfo, 129 ) \ HANDLER(AcpUserAccountSettingsInfo, 130 ) \ HANDLER(AudioDeviceInfo, 131 ) \ @@ -811,16 +811,16 @@ HANDLER(ErrorContext, 615, ErrorInfoAuto, FieldType_U8Array, FieldFlag_None ) \ HANDLER(ErrorContextSize, 616, ErrorInfoAuto, FieldType_NumericU64, FieldFlag_None ) \ HANDLER(ErrorContextTotalSize, 617, ErrorInfoAuto, FieldType_NumericU64, FieldFlag_None ) \ - HANDLER(SystemPhysicalMemoryLimit, 618, ResourceLimitLimitInfo, FieldType_NumericI64, FieldFlag_None ) \ - HANDLER(SystemThreadCountLimit, 619, ResourceLimitLimitInfo, FieldType_NumericI64, FieldFlag_None ) \ - HANDLER(SystemEventCountLimit, 620, ResourceLimitLimitInfo, FieldType_NumericI64, FieldFlag_None ) \ - HANDLER(SystemTransferMemoryCountLimit, 621, ResourceLimitLimitInfo, FieldType_NumericI64, FieldFlag_None ) \ - HANDLER(SystemSessionCountLimit, 622, ResourceLimitLimitInfo, FieldType_NumericI64, FieldFlag_None ) \ - HANDLER(SystemPhysicalMemoryPeak, 623, ResourceLimitPeakInfo, FieldType_NumericI64, FieldFlag_None ) \ - HANDLER(SystemThreadCountPeak, 624, ResourceLimitPeakInfo, FieldType_NumericI64, FieldFlag_None ) \ - HANDLER(SystemEventCountPeak, 625, ResourceLimitPeakInfo, FieldType_NumericI64, FieldFlag_None ) \ - HANDLER(SystemTransferMemoryCountPeak, 626, ResourceLimitPeakInfo, FieldType_NumericI64, FieldFlag_None ) \ - HANDLER(SystemSessionCountPeak, 627, ResourceLimitPeakInfo, FieldType_NumericI64, FieldFlag_None ) \ + HANDLER(SystemPhysicalMemoryLimit, 618, ResourceLimitInfo, FieldType_NumericI64, FieldFlag_None ) \ + HANDLER(SystemThreadCountLimit, 619, ResourceLimitInfo, FieldType_NumericI64, FieldFlag_None ) \ + HANDLER(SystemEventCountLimit, 620, ResourceLimitInfo, FieldType_NumericI64, FieldFlag_None ) \ + HANDLER(SystemTransferMemoryCountLimit, 621, ResourceLimitInfo, FieldType_NumericI64, FieldFlag_None ) \ + HANDLER(SystemSessionCountLimit, 622, ResourceLimitInfo, FieldType_NumericI64, FieldFlag_None ) \ + HANDLER(SystemPhysicalMemoryPeak, 623, ResourceLimitInfo, FieldType_NumericI64, FieldFlag_None ) \ + HANDLER(SystemThreadCountPeak, 624, ResourceLimitInfo, FieldType_NumericI64, FieldFlag_None ) \ + HANDLER(SystemEventCountPeak, 625, ResourceLimitInfo, FieldType_NumericI64, FieldFlag_None ) \ + HANDLER(SystemTransferMemoryCountPeak, 626, ResourceLimitInfo, FieldType_NumericI64, FieldFlag_None ) \ + HANDLER(SystemSessionCountPeak, 627, ResourceLimitInfo, FieldType_NumericI64, FieldFlag_None ) \ HANDLER(GpuCrashHash, 628, GpuCrashInfo, FieldType_U8Array, FieldFlag_None ) \ HANDLER(TouchScreenPanelGpioValue, 629, TouchScreenInfo, FieldType_NumericU8, FieldFlag_None ) \ HANDLER(BrowserCertificateHostName, 630, ErrorInfo, FieldType_String, FieldFlag_None ) \ diff --git a/libraries/libstratosphere/include/stratosphere/ncm/ncm_content_meta_extended_data.hpp b/libraries/libstratosphere/include/stratosphere/ncm/ncm_content_meta_extended_data.hpp index f8888e49f..fe83f64e1 100644 --- a/libraries/libstratosphere/include/stratosphere/ncm/ncm_content_meta_extended_data.hpp +++ b/libraries/libstratosphere/include/stratosphere/ncm/ncm_content_meta_extended_data.hpp @@ -422,7 +422,7 @@ namespace ams::ncm { public: void Reset() { if (m_accessor != nullptr) { - m_accessor->ReleasePin(m_pin_id); + static_cast(m_accessor->ReleasePin(m_pin_id)); m_accessor = nullptr; } } @@ -479,7 +479,7 @@ namespace ams::ncm { /* Mark the memory as in use. */ R_RETURN(m_mapper->MarkUsing(memory.id)); - ON_SCOPE_EXIT { this->ReleasePin(memory.id); }; + ON_SCOPE_EXIT { static_cast(this->ReleasePin(memory.id)); }; /* Copy out the struct. */ *out = *reinterpret_cast(memory.GetBuffer(offset, sizeof(T))); diff --git a/libraries/libstratosphere/libstratosphere.mk b/libraries/libstratosphere/libstratosphere.mk index 5c444caf6..9eb6bd244 100644 --- a/libraries/libstratosphere/libstratosphere.mk +++ b/libraries/libstratosphere/libstratosphere.mk @@ -34,7 +34,7 @@ ATMOSPHERE_OPTIMIZATION_FLAG := -O2 endif DEFINES := $(ATMOSPHERE_DEFINES) -DATMOSPHERE_IS_STRATOSPHERE -D_GNU_SOURCE -SETTINGS := $(ATMOSPHERE_SETTINGS) $(ATMOSPHERE_OPTIMIZATION_FLAG) -Wextra -Werror -Wno-missing-field-initializers -flto +SETTINGS := $(ATMOSPHERE_SETTINGS) $(ATMOSPHERE_OPTIMIZATION_FLAG) -Wextra -Werror -Wno-missing-field-initializers -flto -Wno-error=unused-result CFLAGS := $(ATMOSPHERE_CFLAGS) $(SETTINGS) $(DEFINES) $(INCLUDE) CXXFLAGS := $(CFLAGS) $(ATMOSPHERE_CXXFLAGS) ASFLAGS := $(ATMOSPHERE_ASFLAGS) $(SETTINGS) $(DEFINES) diff --git a/libraries/libstratosphere/source/cs/cs_target_io_server.cpp b/libraries/libstratosphere/source/cs/cs_target_io_server.cpp index 04566cc2d..c33b8b07d 100644 --- a/libraries/libstratosphere/source/cs/cs_target_io_server.cpp +++ b/libraries/libstratosphere/source/cs/cs_target_io_server.cpp @@ -20,7 +20,7 @@ namespace ams::cs { void InitializeTargetIoServer() { /* Launch target io server. */ os::ProcessId process_id; - scs::LaunchProgram(std::addressof(process_id), ncm::ProgramLocation::Make(ncm::SystemProgramId::DevServer, ncm::StorageId::None), nullptr, 0, 0); + static_cast(scs::LaunchProgram(std::addressof(process_id), ncm::ProgramLocation::Make(ncm::SystemProgramId::DevServer, ncm::StorageId::None), nullptr, 0, 0)); } } diff --git a/libraries/libstratosphere/source/erpt/srv/erpt_srv_attachment.cpp b/libraries/libstratosphere/source/erpt/srv/erpt_srv_attachment.cpp index 93685480b..5a996b674 100644 --- a/libraries/libstratosphere/source/erpt/srv/erpt_srv_attachment.cpp +++ b/libraries/libstratosphere/source/erpt/srv/erpt_srv_attachment.cpp @@ -35,7 +35,9 @@ namespace ams::erpt::srv { Attachment::~Attachment() { this->CloseStream(); if (m_record->RemoveReference()) { - this->DeleteStream(this->FileName().name); + if (R_FAILED(this->DeleteStream(this->FileName().name))) { + /* TODO: Log failure? */ + } delete m_record; } } diff --git a/libraries/libstratosphere/source/erpt/srv/erpt_srv_cipher.hpp b/libraries/libstratosphere/source/erpt/srv/erpt_srv_cipher.hpp index a71c3c6f5..9a7a91bf3 100644 --- a/libraries/libstratosphere/source/erpt/srv/erpt_srv_cipher.hpp +++ b/libraries/libstratosphere/source/erpt/srv/erpt_srv_cipher.hpp @@ -81,7 +81,7 @@ namespace ams::erpt::srv { oaep.Encrypt(cipher, sizeof(cipher), s_key, sizeof(s_key), salt, sizeof(salt)); } - Formatter::AddField(report, FieldId_CipherKey, cipher, sizeof(cipher)); + R_TRY(Formatter::AddField(report, FieldId_CipherKey, cipher, s_need_to_store_cipher ? sizeof(cipher) : 1)); std::memset(s_key, 0, sizeof(s_key)); R_RETURN(Formatter::End(report)); diff --git a/libraries/libstratosphere/source/erpt/srv/erpt_srv_context.cpp b/libraries/libstratosphere/source/erpt/srv/erpt_srv_context.cpp index 2d4c021a2..bfe031d7c 100644 --- a/libraries/libstratosphere/source/erpt/srv/erpt_srv_context.cpp +++ b/libraries/libstratosphere/source/erpt/srv/erpt_srv_context.cpp @@ -90,16 +90,15 @@ namespace ams::erpt::srv { Result Context::WriteContextsToReport(Report *report) { R_TRY(report->Open(ReportOpenType_Create)); + ON_SCOPE_EXIT { report->Close(); }; + R_TRY(Cipher::Begin(report, ContextRecord::GetRecordCount())); for (auto it = g_category_list.begin(); it != g_category_list.end(); it++) { R_TRY(it->AddCategoryToReport(report)); } - Cipher::End(report); - report->Close(); - - R_SUCCEED(); + R_RETURN(Cipher::End(report)); } Result Context::ClearContext(CategoryId cat) { diff --git a/libraries/libstratosphere/source/erpt/srv/erpt_srv_context_impl.cpp b/libraries/libstratosphere/source/erpt/srv/erpt_srv_context_impl.cpp index 77a39a5c5..fcfb8af80 100644 --- a/libraries/libstratosphere/source/erpt/srv/erpt_srv_context_impl.cpp +++ b/libraries/libstratosphere/source/erpt/srv/erpt_srv_context_impl.cpp @@ -211,7 +211,7 @@ namespace ams::erpt::srv { Result ContextImpl::InvalidateForcedShutdownDetection() { /* NOTE: Nintendo does not check the result here. */ - erpt::srv::InvalidateForcedShutdownDetection(); + static_cast(erpt::srv::InvalidateForcedShutdownDetection()); R_SUCCEED(); } diff --git a/libraries/libstratosphere/source/erpt/srv/erpt_srv_forced_shutdown.cpp b/libraries/libstratosphere/source/erpt/srv/erpt_srv_forced_shutdown.cpp index c41e04f36..26bb1b47f 100644 --- a/libraries/libstratosphere/source/erpt/srv/erpt_srv_forced_shutdown.cpp +++ b/libraries/libstratosphere/source/erpt/srv/erpt_srv_forced_shutdown.cpp @@ -228,27 +228,27 @@ namespace ams::erpt::srv { /* Check if the forced shutdown context exists; if it doesn't, we should create an empty one. */ if (!IsForceShutdownDetected()) { /* NOTE: Nintendo does not check result here. */ - CreateForcedShutdownContext(); + static_cast(CreateForcedShutdownContext()); return; } /* Load the forced shutdown context. */ /* NOTE: Nintendo does not check that this succeeds. */ - LoadForcedShutdownContext(); + static_cast(LoadForcedShutdownContext()); /* Create report for the forced shutdown. */ /* NOTE: Nintendo does not check that this succeeds. */ - CreateReportForForcedShutdown(); + static_cast(CreateReportForForcedShutdown()); /* Clear the forced shutdown categories. */ /* NOTE: Nintendo does not check that this succeeds. */ - Context::ClearContext(CategoryId_RunningApplicationInfo); - Context::ClearContext(CategoryId_RunningAppletInfo); - Context::ClearContext(CategoryId_FocusedAppletHistoryInfo); + static_cast(Context::ClearContext(CategoryId_RunningApplicationInfo)); + static_cast(Context::ClearContext(CategoryId_RunningAppletInfo)); + static_cast(Context::ClearContext(CategoryId_FocusedAppletHistoryInfo)); /* Save the forced shutdown context. */ /* NOTE: Nintendo does not check that this succeeds. */ - SaveForcedShutdownContext(); + static_cast(SaveForcedShutdownContext()); } void FinalizeForcedShutdownDetection() { @@ -265,7 +265,7 @@ namespace ams::erpt::srv { void SaveForcedShutdownContext() { /* NOTE: Nintendo does not check that saving the report succeeds. */ - SaveForcedShutdownContextImpl(); + static_cast(SaveForcedShutdownContextImpl()); } void SubmitContextForForcedShutdownDetection(const ContextEntry *entry, const u8 *data, u32 data_size) { diff --git a/libraries/libstratosphere/source/erpt/srv/erpt_srv_journal.cpp b/libraries/libstratosphere/source/erpt/srv/erpt_srv_journal.cpp index 84dd89f53..88a9a67bc 100644 --- a/libraries/libstratosphere/source/erpt/srv/erpt_srv_journal.cpp +++ b/libraries/libstratosphere/source/erpt/srv/erpt_srv_journal.cpp @@ -42,7 +42,7 @@ namespace ams::erpt::srv { /* Close and commit the stream. */ stream.CloseStream(); - stream.CommitStream(); + R_TRY(stream.CommitStream()); R_SUCCEED(); } diff --git a/libraries/libstratosphere/source/erpt/srv/erpt_srv_journal_for_attachments.cpp b/libraries/libstratosphere/source/erpt/srv/erpt_srv_journal_for_attachments.cpp index 402951380..77c958fbf 100644 --- a/libraries/libstratosphere/source/erpt/srv/erpt_srv_journal_for_attachments.cpp +++ b/libraries/libstratosphere/source/erpt/srv/erpt_srv_journal_for_attachments.cpp @@ -34,7 +34,9 @@ namespace ams::erpt::srv { auto *record = std::addressof(*it); it = s_attachment_list.erase(s_attachment_list.iterator_to(*record)); if (record->RemoveReference()) { - Stream::DeleteStream(Attachment::FileName(record->m_info.attachment_id).name); + if (R_FAILED(Stream::DeleteStream(Attachment::FileName(record->m_info.attachment_id).name))) { + /* TODO: Log failure? */ + } delete record; } } @@ -66,7 +68,9 @@ namespace ams::erpt::srv { /* Delete the object, if we should. */ if (record->RemoveReference()) { - Stream::DeleteStream(Attachment::FileName(record->m_info.attachment_id).name); + const auto delete_res = Stream::DeleteStream(Attachment::FileName(record->m_info.attachment_id).name); + R_ASSERT(delete_res); + AMS_UNUSED(delete_res); delete record; } } else { @@ -128,12 +132,13 @@ namespace ams::erpt::srv { } if (record->m_info.flags.Test() && JournalForReports::RetrieveRecord(record->m_info.owner_report_id) != nullptr) { - /* NOTE: Nintendo does not check the result of storing the new record... */ record_guard.Cancel(); - StoreRecord(record); + R_TRY(StoreRecord(record)); } else { /* If the attachment has no owner (or we deleted the report), delete the file associated with it. */ - Stream::DeleteStream(Attachment::FileName(record->m_info.attachment_id).name); + const auto delete_res = Stream::DeleteStream(Attachment::FileName(record->m_info.attachment_id).name); + R_ASSERT(delete_res); + AMS_UNUSED(delete_res); } } diff --git a/libraries/libstratosphere/source/erpt/srv/erpt_srv_journal_for_reports.cpp b/libraries/libstratosphere/source/erpt/srv/erpt_srv_journal_for_reports.cpp index 87c7f8d71..01f993511 100644 --- a/libraries/libstratosphere/source/erpt/srv/erpt_srv_journal_for_reports.cpp +++ b/libraries/libstratosphere/source/erpt/srv/erpt_srv_journal_for_reports.cpp @@ -29,7 +29,9 @@ namespace ams::erpt::srv { auto *record = std::addressof(*it); it = s_record_list.erase(s_record_list.iterator_to(*record)); if (record->RemoveReference()) { - Stream::DeleteStream(Report::FileName(record->m_info.id, false).name); + if (R_FAILED(Stream::DeleteStream(Report::FileName(record->m_info.id, false).name))) { + /* TODO: Log failure? */ + } delete record; } } @@ -65,12 +67,14 @@ namespace ams::erpt::srv { /* Delete any attachments. */ if (force_delete_attachments || record->m_info.flags.Test()) { - JournalForAttachments::DeleteAttachments(record->m_info.id); + static_cast(JournalForAttachments::DeleteAttachments(record->m_info.id)); } /* Delete the object, if we should. */ if (record->RemoveReference()) { - Stream::DeleteStream(Report::FileName(record->m_info.id, false).name); + const auto delete_res = Stream::DeleteStream(Report::FileName(record->m_info.id, false).name); + R_ASSERT(delete_res); + AMS_UNUSED(delete_res); delete record; } } @@ -164,8 +168,7 @@ namespace ams::erpt::srv { record_guard.Cancel(); - /* NOTE: Nintendo does not check the result of storing the new record... */ - StoreRecord(record); + R_TRY(StoreRecord(record)); } cleanup_guard.Cancel(); diff --git a/libraries/libstratosphere/source/erpt/srv/erpt_srv_main.cpp b/libraries/libstratosphere/source/erpt/srv/erpt_srv_main.cpp index 8fb682244..8447fbb4c 100644 --- a/libraries/libstratosphere/source/erpt/srv/erpt_srv_main.cpp +++ b/libraries/libstratosphere/source/erpt/srv/erpt_srv_main.cpp @@ -56,8 +56,8 @@ namespace ams::erpt::srv { fs::DisableAutoSaveDataCreation(); /* Extend the system save data. */ - /* NOTE: Nintendo does not check result of this. */ - ExtendSystemSaveData(); + /* NOTE: Nintendo used to not check the result of this; they do now, but . */ + static_cast(ExtendSystemSaveData()); R_TRY_CATCH(fs::MountSystemSaveData(ReportStoragePath, SystemSaveDataId)) { R_CATCH(fs::ResultTargetNotFound) { @@ -97,7 +97,7 @@ namespace ams::erpt::srv { } if (report_count >= MinimumReportCountForCleanup) { - fs::CleanDirectoryRecursively(ReportOnSdStorageRootDirectoryPath); + static_cast(fs::CleanDirectoryRecursively(ReportOnSdStorageRootDirectoryPath)); } } @@ -110,7 +110,9 @@ namespace ams::erpt::srv { AMS_ABORT_UNLESS(ctx != nullptr); } - Journal::Restore(); + if (R_FAILED(Journal::Restore())) { + /* TODO: Nintendo deletes system savedata when this fails. Should we?. */ + } Reporter::UpdatePowerOnTime(); Reporter::UpdateAwakeTime(); diff --git a/libraries/libstratosphere/source/erpt/srv/erpt_srv_manager_impl.cpp b/libraries/libstratosphere/source/erpt/srv/erpt_srv_manager_impl.cpp index 2130a5200..668610ba0 100644 --- a/libraries/libstratosphere/source/erpt/srv/erpt_srv_manager_impl.cpp +++ b/libraries/libstratosphere/source/erpt/srv/erpt_srv_manager_impl.cpp @@ -39,11 +39,10 @@ namespace ams::erpt::srv { m_system_event.Signal(); } - Result ManagerImpl::NotifyAll() { + void ManagerImpl::NotifyAll() { for (auto &manager : g_manager_list) { manager.NotifyOne(); } - R_SUCCEED(); } Result ManagerImpl::GetReportList(const ams::sf::OutBuffer &out_list, ReportType type_filter) { diff --git a/libraries/libstratosphere/source/erpt/srv/erpt_srv_manager_impl.hpp b/libraries/libstratosphere/source/erpt/srv/erpt_srv_manager_impl.hpp index 24046b29b..a4f55bb30 100644 --- a/libraries/libstratosphere/source/erpt/srv/erpt_srv_manager_impl.hpp +++ b/libraries/libstratosphere/source/erpt/srv/erpt_srv_manager_impl.hpp @@ -27,7 +27,7 @@ namespace ams::erpt::srv { private: void NotifyOne(); public: - static Result NotifyAll(); + static void NotifyAll(); public: Result GetReportList(const ams::sf::OutBuffer &out_list, ReportType type_filter); Result GetEvent(ams::sf::OutCopyHandle out); diff --git a/libraries/libstratosphere/source/erpt/srv/erpt_srv_report.cpp b/libraries/libstratosphere/source/erpt/srv/erpt_srv_report.cpp index 67f927819..ceec506b7 100644 --- a/libraries/libstratosphere/source/erpt/srv/erpt_srv_report.cpp +++ b/libraries/libstratosphere/source/erpt/srv/erpt_srv_report.cpp @@ -41,7 +41,9 @@ namespace ams::erpt::srv { Report::~Report() { this->CloseStream(); if (m_record->RemoveReference()) { - this->DeleteStream(this->FileName().name); + if (R_FAILED(this->DeleteStream(this->FileName().name))) { + /* TODO: Log failure? */ + } delete m_record; } } diff --git a/libraries/libstratosphere/source/erpt/srv/erpt_srv_reporter.cpp b/libraries/libstratosphere/source/erpt/srv/erpt_srv_reporter.cpp index a9a2871c6..f1c601698 100644 --- a/libraries/libstratosphere/source/erpt/srv/erpt_srv_reporter.cpp +++ b/libraries/libstratosphere/source/erpt/srv/erpt_srv_reporter.cpp @@ -124,29 +124,19 @@ namespace ams::erpt::srv { if (error_context_total_size == 0) { return; } - record->Add(FieldId_ErrorContextTotalSize, error_context_total_size); + static_cast(record->Add(FieldId_ErrorContextTotalSize, error_context_total_size)); /* Set the context. */ if (error_context_size == 0) { return; } - record->Add(FieldId_ErrorContextSize, error_context_size); - record->Add(FieldId_ErrorContext, error_context, error_context_size); + static_cast(record->Add(FieldId_ErrorContextSize, error_context_size)); + static_cast(record->Add(FieldId_ErrorContext, error_context, error_context_size)); } - constinit os::SdkMutex g_limit_mutex; - constinit bool g_submitted_limit = false; - - void SubmitResourceLimitLimitContext() { - std::scoped_lock lk(g_limit_mutex); - if (g_submitted_limit) { - return; - } - - ON_SCOPE_EXIT { g_submitted_limit = true; }; - + void SubmitResourceLimitContexts() { /* Create and populate the record. */ - auto record = std::make_unique(CategoryId_ResourceLimitLimitInfo); + auto record = std::make_unique(CategoryId_ResourceLimitInfo); if (record == nullptr) { return; } @@ -165,7 +155,15 @@ namespace ams::erpt::srv { if (R_FAILED(svc::GetResourceLimitLimitValue(std::addressof(limit_value), handle, svc::LimitableResource_##__RESOURCE__##Max))) { \ return; \ } \ - if (R_FAILED(record->Add(FieldId_System##__RESOURCE__##Limit, limit_value))) { \ + if (R_FAILED(record->Add(FieldId_System##__RESOURCE__##Limit, limit_value))) { \ + return; \ + } \ + \ + s64 peak_value; \ + if (R_FAILED(svc::GetResourceLimitPeakValue(std::addressof(peak_value), handle, svc::LimitableResource_##__RESOURCE__##Max))) { \ + return; \ + } \ + if (R_FAILED(record->Add(FieldId_System##__RESOURCE__##Peak, peak_value))) { \ return; \ } \ } while (0) @@ -178,51 +176,7 @@ namespace ams::erpt::srv { #undef ADD_RESOURCE - Context::SubmitContextRecord(std::move(record)); - - g_submitted_limit = true; - } - - void SubmitResourceLimitPeakContext() { - /* Create and populate the record. */ - auto record = std::make_unique(CategoryId_ResourceLimitPeakInfo); - if (record == nullptr) { - return; - } - - u64 reslimit_handle_value; - if (R_FAILED(svc::GetInfo(std::addressof(reslimit_handle_value), svc::InfoType_ResourceLimit, svc::InvalidHandle, 0))) { - return; - } - - const auto handle = static_cast(reslimit_handle_value); - ON_SCOPE_EXIT { R_ABORT_UNLESS(svc::CloseHandle(handle)); }; - - #define ADD_RESOURCE(__RESOURCE__) \ - do { \ - s64 peak_value; \ - if (R_FAILED(svc::GetResourceLimitPeakValue(std::addressof(peak_value), handle, svc::LimitableResource_##__RESOURCE__##Max))) { \ - return; \ - } \ - if (R_FAILED(record->Add(FieldId_System##__RESOURCE__##Peak, peak_value))) { \ - return; \ - } \ - } while (0) - - ADD_RESOURCE(PhysicalMemory); - ADD_RESOURCE(ThreadCount); - ADD_RESOURCE(EventCount); - ADD_RESOURCE(TransferMemoryCount); - ADD_RESOURCE(SessionCount); - - #undef ADD_RESOURCE - - Context::SubmitContextRecord(std::move(record)); - } - - void SubmitResourceLimitContexts() { - SubmitResourceLimitLimitContext(); - SubmitResourceLimitPeakContext(); + static_cast(Context::SubmitContextRecord(std::move(record))); } #else void SubmitErrorContext(ContextRecord *record, Result result) { @@ -262,11 +216,11 @@ namespace ams::erpt::srv { } if (!found_abort_flag) { - record->Add(FieldId_AbortFlag, false); + static_cast(record->Add(FieldId_AbortFlag, false)); } if (!found_syslog_flag) { - record->Add(FieldId_HasSyslogFlag, true); + static_cast(record->Add(FieldId_HasSyslogFlag, true)); } R_TRY(Context::SubmitContextRecord(std::move(record))); @@ -377,7 +331,7 @@ namespace ams::erpt::srv { auto report = std::make_unique(record.get(), redirect_new_reports); R_UNLESS(report != nullptr, erpt::ResultOutOfMemory()); - auto report_guard = SCOPE_GUARD { report->Delete(); }; + auto report_guard = SCOPE_GUARD { const auto delete_res = report->Delete(); R_ASSERT(delete_res); AMS_UNUSED(delete_res); }; R_TRY(Context::WriteContextsToReport(report.get())); R_TRY(report->GetSize(std::addressof(record->m_info.report_size))); @@ -429,9 +383,9 @@ namespace ams::erpt::srv { Result Reporter::CreateReport(ReportType type, Result ctx_result, std::unique_ptr record, const ReportMetaData *meta, const AttachmentId *attachments, u32 num_attachments, erpt::CreateReportOptionFlagSet flags, const ReportId *specified_report_id) { /* Clear the automatic categories, when we're done with our report. */ ON_SCOPE_EXIT { - Context::ClearContext(CategoryId_ErrorInfo); - Context::ClearContext(CategoryId_ErrorInfoAuto); - Context::ClearContext(CategoryId_ErrorInfoDefaults); + static_cast(Context::ClearContext(CategoryId_ErrorInfo)); + static_cast(Context::ClearContext(CategoryId_ErrorInfoAuto)); + static_cast(Context::ClearContext(CategoryId_ErrorInfoDefaults)); }; /* Get the context entry pointer. */ @@ -490,28 +444,28 @@ namespace ams::erpt::srv { R_ABORT_UNLESS(time::GetStandardSteadyClockCurrentTimePoint(std::addressof(steady_clock_current_timepoint))); /* Add automatic fields. */ - auto_record->Add(FieldId_OsVersion, s_os_version, util::Strnlen(s_os_version, sizeof(s_os_version))); - auto_record->Add(FieldId_PrivateOsVersion, s_private_os_version, util::Strnlen(s_private_os_version, sizeof(s_private_os_version))); - auto_record->Add(FieldId_SerialNumber, s_serial_number, util::Strnlen(s_serial_number, sizeof(s_serial_number))); - auto_record->Add(FieldId_ReportIdentifier, identifier_str, util::Strnlen(identifier_str, sizeof(identifier_str))); - auto_record->Add(FieldId_OccurrenceTimestamp, timestamp_user.value); - auto_record->Add(FieldId_OccurrenceTimestampNet, timestamp_network.value); - auto_record->Add(FieldId_ReportVisibilityFlag, type == ReportType_Visible); - auto_record->Add(FieldId_OccurrenceTick, occurrence_tick.GetInt64Value()); - auto_record->Add(FieldId_SteadyClockInternalOffset, steady_clock_internal_offset_seconds); - auto_record->Add(FieldId_SteadyClockCurrentTimePointValue, steady_clock_current_timepoint.value); - auto_record->Add(FieldId_ElapsedTimeSincePowerOn, (occurrence_tick - *s_power_on_time).ToTimeSpan().GetSeconds()); - auto_record->Add(FieldId_ElapsedTimeSinceLastAwake, (occurrence_tick - *s_awake_time).ToTimeSpan().GetSeconds()); + static_cast(auto_record->Add(FieldId_OsVersion, s_os_version, util::Strnlen(s_os_version, sizeof(s_os_version)))); + static_cast(auto_record->Add(FieldId_PrivateOsVersion, s_private_os_version, util::Strnlen(s_private_os_version, sizeof(s_private_os_version)))); + static_cast(auto_record->Add(FieldId_SerialNumber, s_serial_number, util::Strnlen(s_serial_number, sizeof(s_serial_number)))); + static_cast(auto_record->Add(FieldId_ReportIdentifier, identifier_str, util::Strnlen(identifier_str, sizeof(identifier_str)))); + static_cast(auto_record->Add(FieldId_OccurrenceTimestamp, timestamp_user.value)); + static_cast(auto_record->Add(FieldId_OccurrenceTimestampNet, timestamp_network.value)); + static_cast(auto_record->Add(FieldId_ReportVisibilityFlag, type == ReportType_Visible)); + static_cast(auto_record->Add(FieldId_OccurrenceTick, occurrence_tick.GetInt64Value())); + static_cast(auto_record->Add(FieldId_SteadyClockInternalOffset, steady_clock_internal_offset_seconds)); + static_cast(auto_record->Add(FieldId_SteadyClockCurrentTimePointValue, steady_clock_current_timepoint.value)); + static_cast(auto_record->Add(FieldId_ElapsedTimeSincePowerOn, (occurrence_tick - *s_power_on_time).ToTimeSpan().GetSeconds())); + static_cast(auto_record->Add(FieldId_ElapsedTimeSinceLastAwake, (occurrence_tick - *s_awake_time).ToTimeSpan().GetSeconds())); if (s_initial_launch_settings_completion_time) { s64 elapsed_seconds; if (R_SUCCEEDED(time::GetElapsedSecondsBetween(std::addressof(elapsed_seconds), *s_initial_launch_settings_completion_time, steady_clock_current_timepoint))) { - auto_record->Add(FieldId_ElapsedTimeSinceInitialLaunch, elapsed_seconds); + static_cast(auto_record->Add(FieldId_ElapsedTimeSinceInitialLaunch, elapsed_seconds)); } } if (s_application_launch_time) { - auto_record->Add(FieldId_ApplicationAliveTime, (occurrence_tick - *s_application_launch_time).ToTimeSpan().GetSeconds()); + static_cast(auto_record->Add(FieldId_ApplicationAliveTime, (occurrence_tick - *s_application_launch_time).ToTimeSpan().GetSeconds())); } /* Submit applet active duration information. */ @@ -535,7 +489,7 @@ namespace ams::erpt::srv { #if defined(ATMOSPHERE_OS_HORIZON) if (hos::GetVersion() >= hos::Version_17_0_0 && flags.Test()) { /* NOTE: Nintendo ignores the result of this call. */ - SubmitFsInfo(); + static_cast(SubmitFsInfo()); } #else AMS_UNUSED(flags); diff --git a/libraries/libstratosphere/source/erpt/srv/erpt_srv_stream.cpp b/libraries/libstratosphere/source/erpt/srv/erpt_srv_stream.cpp index 35c0db843..ef1906433 100644 --- a/libraries/libstratosphere/source/erpt/srv/erpt_srv_stream.cpp +++ b/libraries/libstratosphere/source/erpt/srv/erpt_srv_stream.cpp @@ -36,7 +36,10 @@ namespace ams::erpt::srv { std::scoped_lock lk(s_fs_commit_mutex); - fs::CommitSaveData(ReportStoragePath); + const auto commit_res = fs::CommitSaveData(ReportStoragePath); + R_ASSERT(commit_res); + AMS_UNUSED(commit_res); + R_SUCCEED(); } @@ -81,7 +84,7 @@ namespace ams::erpt::srv { } R_END_TRY_CATCH; break; } - fs::SetFileSize(m_file_handle, 0); + R_TRY(fs::SetFileSize(m_file_handle, 0)); } else { R_UNLESS(mode == StreamMode_Read, erpt::ResultInvalidArgument()); @@ -187,8 +190,13 @@ namespace ams::erpt::srv { if (m_initialized) { if (s_can_access_fs) { if (m_stream_mode == StreamMode_Write) { - this->Flush(); - fs::FlushFile(m_file_handle); + const auto self_flush_res = this->Flush(); + R_ASSERT(self_flush_res); + AMS_UNUSED(self_flush_res); + + const auto file_flush_res = fs::FlushFile(m_file_handle); + R_ASSERT(file_flush_res); + AMS_UNUSED(file_flush_res); } fs::CloseFile(m_file_handle); } diff --git a/libraries/libstratosphere/source/fs/fs_access_log.cpp b/libraries/libstratosphere/source/fs/fs_access_log.cpp index 157e1ca38..7c4ce1524 100644 --- a/libraries/libstratosphere/source/fs/fs_access_log.cpp +++ b/libraries/libstratosphere/source/fs/fs_access_log.cpp @@ -585,7 +585,7 @@ namespace ams::fs::impl { } /* Output. */ - OutputAccessLogToSdCardImpl(log_buffer.get(), log_buffer_size - 1); + static_cast(OutputAccessLogToSdCardImpl(log_buffer.get(), log_buffer_size - 1)); } } @@ -593,7 +593,7 @@ namespace ams::fs::impl { if ((g_global_access_log_mode & AccessLogMode_Log) != 0) { /* TODO: Support logging. */ } else if ((g_global_access_log_mode & AccessLogMode_SdCard) != 0) { - OutputAccessLogToSdCardImpl(log, size - 1); + static_cast(OutputAccessLogToSdCardImpl(log, size - 1)); } } diff --git a/libraries/libstratosphere/source/fs/fs_api.cpp b/libraries/libstratosphere/source/fs/fs_api.cpp index c548fc674..3e9d267e1 100644 --- a/libraries/libstratosphere/source/fs/fs_api.cpp +++ b/libraries/libstratosphere/source/fs/fs_api.cpp @@ -105,7 +105,9 @@ namespace ams::fs { AMS_ABORT_UNLESS(fsp_object != nullptr); /* Set the current process. */ - fsp_object->SetCurrentProcess({}); + const auto scp_res = fsp_object->SetCurrentProcess({}); + R_ASSERT(scp_res); + AMS_UNUSED(scp_res); } #else /* On non-horizon, use the system object. */ diff --git a/libraries/libstratosphere/source/fs/fsa/fs_filesystem_accessor.cpp b/libraries/libstratosphere/source/fs/fsa/fs_filesystem_accessor.cpp index 23357d660..690fd7cd2 100644 --- a/libraries/libstratosphere/source/fs/fsa/fs_filesystem_accessor.cpp +++ b/libraries/libstratosphere/source/fs/fsa/fs_filesystem_accessor.cpp @@ -107,7 +107,7 @@ namespace ams::fs::impl { size_t len; if (R_SUCCEEDED(PathFormatter::IsNormalized(std::addressof(normalized), std::addressof(len), p, m_path_flags)) && normalized) { /* We can use the input buffer directly. */ - out->SetShallowBuffer(p); + R_TRY(out->SetShallowBuffer(p)); } else { /* Initialize with appropriate slash replacement. */ if (m_path_flags.IsWindowsPathAllowed()) { diff --git a/libraries/libstratosphere/source/fs/fsa/fs_user_directory.cpp b/libraries/libstratosphere/source/fs/fsa/fs_user_directory.cpp index f5e8cbc46..ca7979867 100644 --- a/libraries/libstratosphere/source/fs/fsa/fs_user_directory.cpp +++ b/libraries/libstratosphere/source/fs/fsa/fs_user_directory.cpp @@ -38,7 +38,7 @@ namespace ams::fs { } void CloseDirectory(DirectoryHandle handle) { - AMS_FS_IMPL_ACCESS_LOG((delete Get(handle), ResultSuccess()), handle, AMS_FS_IMPL_ACCESS_LOG_FORMAT_NONE); + static_cast(AMS_FS_IMPL_ACCESS_LOG((delete Get(handle), ResultSuccess()), handle, AMS_FS_IMPL_ACCESS_LOG_FORMAT_NONE)); } } diff --git a/libraries/libstratosphere/source/fs/fsa/fs_user_file.cpp b/libraries/libstratosphere/source/fs/fsa/fs_user_file.cpp index 6b6ec66d5..9ecfe16ad 100644 --- a/libraries/libstratosphere/source/fs/fsa/fs_user_file.cpp +++ b/libraries/libstratosphere/source/fs/fsa/fs_user_file.cpp @@ -78,12 +78,12 @@ namespace ams::fs { int GetFileOpenMode(FileHandle handle) { const int mode = Get(handle)->GetOpenMode(); - AMS_FS_IMPL_ACCESS_LOG(ResultSuccess(), handle, AMS_FS_IMPL_ACCESS_LOG_FORMAT_OPEN_MODE, static_cast(mode)); + static_cast(AMS_FS_IMPL_ACCESS_LOG(ResultSuccess(), handle, AMS_FS_IMPL_ACCESS_LOG_FORMAT_OPEN_MODE, static_cast(mode))); return mode; } void CloseFile(FileHandle handle) { - AMS_FS_IMPL_ACCESS_LOG((delete Get(handle), ResultSuccess()), handle, AMS_FS_IMPL_ACCESS_LOG_FORMAT_NONE); + static_cast(AMS_FS_IMPL_ACCESS_LOG((delete Get(handle), ResultSuccess()), handle, AMS_FS_IMPL_ACCESS_LOG_FORMAT_NONE)); } Result QueryRange(QueryRangeInfo *out, FileHandle handle, s64 offset, s64 size) { diff --git a/libraries/libstratosphere/source/fssystem/fssystem_block_cache_buffered_storage.cpp b/libraries/libstratosphere/source/fssystem/fssystem_block_cache_buffered_storage.cpp index 90654ad09..32a8a58b1 100644 --- a/libraries/libstratosphere/source/fssystem/fssystem_block_cache_buffered_storage.cpp +++ b/libraries/libstratosphere/source/fssystem/fssystem_block_cache_buffered_storage.cpp @@ -63,7 +63,7 @@ namespace ams::fssystem { void BlockCacheBufferedStorage::Finalize() { if (m_block_cache_manager.IsInitialized()) { /* Invalidate all cache entries. */ - this->InvalidateAllCacheEntries(); + static_cast(this->InvalidateAllCacheEntries()); /* Finalize our block cache manager. */ m_block_cache_manager.Finalize(); diff --git a/libraries/libstratosphere/source/fssystem/fssystem_crypto_configuration.cpp b/libraries/libstratosphere/source/fssystem/fssystem_crypto_configuration.cpp index 23e4d0b3b..4a64b2012 100644 --- a/libraries/libstratosphere/source/fssystem/fssystem_crypto_configuration.cpp +++ b/libraries/libstratosphere/source/fssystem/fssystem_crypto_configuration.cpp @@ -269,9 +269,10 @@ namespace ams::fssystem { /* Setup the key area encryption keys. */ for (u8 i = 0; i < NcaCryptoConfiguration::KeyGenerationMax; ++i) { - spl::GenerateAesKek(std::addressof(GetNcaKekAccessKey(GetKeyTypeValue(0, i))), nca_crypto_cfg->key_area_encryption_key_source[0], KeySize, i, Option); - spl::GenerateAesKek(std::addressof(GetNcaKekAccessKey(GetKeyTypeValue(1, i))), nca_crypto_cfg->key_area_encryption_key_source[1], KeySize, i, Option); - spl::GenerateAesKek(std::addressof(GetNcaKekAccessKey(GetKeyTypeValue(2, i))), nca_crypto_cfg->key_area_encryption_key_source[2], KeySize, i, Option); + /* NOTE: Nintendo allows these to fail, since the loop tries key generations past the maximum known. */ + static_cast(spl::GenerateAesKek(std::addressof(GetNcaKekAccessKey(GetKeyTypeValue(0, i))), nca_crypto_cfg->key_area_encryption_key_source[0], KeySize, i, Option)); + static_cast(spl::GenerateAesKek(std::addressof(GetNcaKekAccessKey(GetKeyTypeValue(1, i))), nca_crypto_cfg->key_area_encryption_key_source[1], KeySize, i, Option)); + static_cast(spl::GenerateAesKek(std::addressof(GetNcaKekAccessKey(GetKeyTypeValue(2, i))), nca_crypto_cfg->key_area_encryption_key_source[2], KeySize, i, Option)); } /* Setup the header encryption key. */ diff --git a/libraries/libstratosphere/source/fssystem/fssystem_file_system_proxy_api.cpp b/libraries/libstratosphere/source/fssystem/fssystem_file_system_proxy_api.cpp index 0e6539f71..0f074400c 100644 --- a/libraries/libstratosphere/source/fssystem/fssystem_file_system_proxy_api.cpp +++ b/libraries/libstratosphere/source/fssystem/fssystem_file_system_proxy_api.cpp @@ -129,11 +129,15 @@ namespace ams::fssystem { /* Initialize the buffer manager. */ /* TODO FS-REIMPL: os::AllocateMemoryBlock(...); */ util::ConstructAt(g_buffer_manager); - GetReference(g_buffer_manager).Initialize(MaxCacheCount, reinterpret_cast(g_buffer_manager_heap), BufferManagerHeapSize, BlockSize); + const auto bm_res = GetReference(g_buffer_manager).Initialize(MaxCacheCount, reinterpret_cast(g_buffer_manager_heap), BufferManagerHeapSize, BlockSize); + R_ASSERT(bm_res); + AMS_UNUSED(bm_res); /* TODO FS-REIMPL: os::AllocateMemoryBlock(...); */ /* TODO FS-REIMPL: fssrv::storage::CreateDeviceAddressSpace(...); */ - fssystem::InitializeBufferPool(reinterpret_cast(g_device_buffer), DeviceBufferSize); + const auto ibp_res = fssystem::InitializeBufferPool(reinterpret_cast(g_device_buffer), DeviceBufferSize); + R_ASSERT(ibp_res); + AMS_UNUSED(ibp_res); /* TODO FS-REIMPL: Create Pooled Threads/Stack Usage Reporter, fssystem::RegisterThreadPool. */ @@ -231,11 +235,15 @@ namespace ams::fssystem { /* Initialize the buffer manager. */ /* TODO FS-REIMPL: os::AllocateMemoryBlock(...); */ util::ConstructAt(g_buffer_manager); - GetReference(g_buffer_manager).Initialize(MaxCacheCount, reinterpret_cast(g_buffer_manager_heap), BufferManagerHeapSize, BlockSize); + const auto bm_res = GetReference(g_buffer_manager).Initialize(MaxCacheCount, reinterpret_cast(g_buffer_manager_heap), BufferManagerHeapSize, BlockSize); + R_ASSERT(bm_res); + AMS_UNUSED(bm_res); /* TODO FS-REIMPL: os::AllocateMemoryBlock(...); */ /* TODO FS-REIMPL: fssrv::storage::CreateDeviceAddressSpace(...); */ - fssystem::InitializeBufferPool(reinterpret_cast(g_device_buffer), DeviceBufferSize); + const auto ibp_res = fssystem::InitializeBufferPool(reinterpret_cast(g_device_buffer), DeviceBufferSize); + R_ASSERT(ibp_res); + AMS_UNUSED(ibp_res); /* TODO FS-REIMPL: Create Pooled Threads/Stack Usage Reporter, fssystem::RegisterThreadPool. */ diff --git a/libraries/libstratosphere/source/htc/server/driver/htc_htclow_driver.cpp b/libraries/libstratosphere/source/htc/server/driver/htc_htclow_driver.cpp index 6ede55b28..865d9e206 100644 --- a/libraries/libstratosphere/source/htc/server/driver/htc_htclow_driver.cpp +++ b/libraries/libstratosphere/source/htc/server/driver/htc_htclow_driver.cpp @@ -89,7 +89,7 @@ namespace ams::htc::server::driver { void HtclowDriver::Shutdown(htclow::ChannelId channel) { /* Shut down the channel. */ - m_manager->Shutdown(GetHtclowChannel(channel, m_module_id)); + static_cast(m_manager->Shutdown(GetHtclowChannel(channel, m_module_id))); } Result HtclowDriver::Send(s64 *out, const void *src, s64 src_size, htclow::ChannelId channel) { diff --git a/libraries/libstratosphere/source/htc/server/rpc/htc_htcmisc_rpc_server.hpp b/libraries/libstratosphere/source/htc/server/rpc/htc_htcmisc_rpc_server.hpp index 3b98dd0e7..0469af6c4 100644 --- a/libraries/libstratosphere/source/htc/server/rpc/htc_htcmisc_rpc_server.hpp +++ b/libraries/libstratosphere/source/htc/server/rpc/htc_htcmisc_rpc_server.hpp @@ -37,7 +37,7 @@ namespace ams::htc::server::rpc { u8 m_driver_receive_buffer[4_KB]; u8 m_driver_send_buffer[4_KB]; private: - static void ReceiveThreadEntry(void *arg) { static_cast(arg)->ReceiveThread(); } + static void ReceiveThreadEntry(void *arg) { static_cast(static_cast(arg)->ReceiveThread()); } Result ReceiveThread(); public: diff --git a/libraries/libstratosphere/source/htc/server/rpc/htc_rpc_client.hpp b/libraries/libstratosphere/source/htc/server/rpc/htc_rpc_client.hpp index 3a943fb4c..aaed670e0 100644 --- a/libraries/libstratosphere/source/htc/server/rpc/htc_rpc_client.hpp +++ b/libraries/libstratosphere/source/htc/server/rpc/htc_rpc_client.hpp @@ -71,8 +71,8 @@ namespace ams::htc::server::rpc { char m_receive_buffer[BufferSize]; char m_send_buffer[BufferSize]; private: - static void ReceiveThreadEntry(void *arg) { static_cast(arg)->ReceiveThread(); } - static void SendThreadEntry(void *arg) { static_cast(arg)->SendThread(); } + static void ReceiveThreadEntry(void *arg) { static_cast(static_cast(arg)->ReceiveThread()); } + static void SendThreadEntry(void *arg) { static_cast(static_cast(arg)->SendThread()); } Result ReceiveThread(); Result SendThread(); diff --git a/libraries/libstratosphere/source/htcfs/htcfs_client_impl.cpp b/libraries/libstratosphere/source/htcfs/htcfs_client_impl.cpp index 2dc9c2709..50fa2ee81 100644 --- a/libraries/libstratosphere/source/htcfs/htcfs_client_impl.cpp +++ b/libraries/libstratosphere/source/htcfs/htcfs_client_impl.cpp @@ -53,7 +53,7 @@ namespace ams::htcfs { void ClientImpl::Start() { /* Create our thread. */ - os::CreateThread(std::addressof(m_monitor_thread), ThreadEntry, this, g_monitor_thread_stack, sizeof(g_monitor_thread_stack), AMS_GET_SYSTEM_THREAD_PRIORITY(htc, HtcfsMonitor)); + R_ABORT_UNLESS(os::CreateThread(std::addressof(m_monitor_thread), ThreadEntry, this, g_monitor_thread_stack, sizeof(g_monitor_thread_stack), AMS_GET_SYSTEM_THREAD_PRIORITY(htc, HtcfsMonitor))); /* Set thread name pointer. */ os::SetThreadNamePointer(std::addressof(m_monitor_thread), AMS_GET_SYSTEM_THREAD_NAME(htc, HtcfsMonitor)); diff --git a/libraries/libstratosphere/source/htcfs/htcfs_directory_service_object.cpp b/libraries/libstratosphere/source/htcfs/htcfs_directory_service_object.cpp index a24c066a1..3b4ef5285 100644 --- a/libraries/libstratosphere/source/htcfs/htcfs_directory_service_object.cpp +++ b/libraries/libstratosphere/source/htcfs/htcfs_directory_service_object.cpp @@ -22,7 +22,7 @@ namespace ams::htcfs { DirectoryServiceObject::DirectoryServiceObject(s32 handle) : m_handle(handle) { /* ... */ } DirectoryServiceObject::~DirectoryServiceObject() { - htcfs::GetClient().CloseDirectory(m_handle); + static_cast(htcfs::GetClient().CloseDirectory(m_handle)); } Result DirectoryServiceObject::GetEntryCount(ams::sf::Out out) { diff --git a/libraries/libstratosphere/source/htcfs/htcfs_file_service_object.cpp b/libraries/libstratosphere/source/htcfs/htcfs_file_service_object.cpp index 974542dd1..c6bc89e32 100644 --- a/libraries/libstratosphere/source/htcfs/htcfs_file_service_object.cpp +++ b/libraries/libstratosphere/source/htcfs/htcfs_file_service_object.cpp @@ -22,7 +22,7 @@ namespace ams::htcfs { FileServiceObject::FileServiceObject(s32 handle) : m_handle(handle) { /* ... */ } FileServiceObject::~FileServiceObject() { - htcfs::GetClient().CloseFile(m_handle); + static_cast(htcfs::GetClient().CloseFile(m_handle)); } Result FileServiceObject::ReadFile(ams::sf::Out out, s64 offset, const ams::sf::OutNonSecureBuffer &buffer, ams::fs::ReadOption option) { diff --git a/libraries/libstratosphere/source/htclow/driver/htclow_driver_manager.cpp b/libraries/libstratosphere/source/htclow/driver/htclow_driver_manager.cpp index 5167925ab..e467e4254 100644 --- a/libraries/libstratosphere/source/htclow/driver/htclow_driver_manager.cpp +++ b/libraries/libstratosphere/source/htclow/driver/htclow_driver_manager.cpp @@ -32,15 +32,15 @@ namespace ams::htclow::driver { m_open_driver = m_debug_driver; break; case impl::DriverType::Socket: - m_socket_driver.Open(); + R_TRY(m_socket_driver.Open()); m_open_driver = std::addressof(m_socket_driver); break; case impl::DriverType::Usb: - m_usb_driver.Open(); + R_TRY(m_usb_driver.Open()); m_open_driver = std::addressof(m_usb_driver); break; case impl::DriverType::PlainChannel: - //m_plain_channel_driver.Open(); + //R_TRY(m_plain_channel_driver.Open()); //m_open_driver = std::addressof(m_plain_channel_driver); //break; R_THROW(htclow::ResultUnknownDriverType()); diff --git a/libraries/libstratosphere/source/htclow/driver/htclow_socket_discovery_manager.cpp b/libraries/libstratosphere/source/htclow/driver/htclow_socket_discovery_manager.cpp index f864efc1d..033e8356b 100644 --- a/libraries/libstratosphere/source/htclow/driver/htclow_socket_discovery_manager.cpp +++ b/libraries/libstratosphere/source/htclow/driver/htclow_socket_discovery_manager.cpp @@ -67,14 +67,20 @@ namespace ams::htclow::driver { } void SocketDiscoveryManager::ThreadFunc() { - for (this->DoDiscovery(); !m_driver_closed; this->DoDiscovery()) { - /* Check if the driver is closed five times. */ + /* Do discovery. */ + static_cast(this->DoDiscovery()); + + while (!m_driver_closed) { + /* Check if the driver is closed 5 times. */ for (size_t i = 0; i < 5; ++i) { os::SleepThread(TimeSpan::FromSeconds(1)); if (m_driver_closed) { return; } } + + /* Do discovery. */ + static_cast(this->DoDiscovery()); } } diff --git a/libraries/libstratosphere/source/htclow/driver/htclow_usb_impl.cpp b/libraries/libstratosphere/source/htclow/driver/htclow_usb_impl.cpp index 24aac8f60..703b27db6 100644 --- a/libraries/libstratosphere/source/htclow/driver/htclow_usb_impl.cpp +++ b/libraries/libstratosphere/source/htclow/driver/htclow_usb_impl.cpp @@ -407,11 +407,11 @@ namespace ams::htclow::driver { g_usb_break_event.Signal(); os::WaitThread(std::addressof(g_usb_indication_thread)); os::DestroyThread(std::addressof(g_usb_indication_thread)); - g_ds_client.DisableDevice(); - g_ds_endpoints[1].Finalize(); - g_ds_endpoints[0].Finalize(); - g_ds_interface.Finalize(); - g_ds_client.Finalize(); + static_cast(g_ds_client.DisableDevice()); + static_cast(g_ds_endpoints[1].Finalize()); + static_cast(g_ds_endpoints[0].Finalize()); + static_cast(g_ds_interface.Finalize()); + static_cast(g_ds_client.Finalize()); g_usb_interface_initialized = false; } @@ -454,8 +454,8 @@ namespace ams::htclow::driver { void CancelUsbSendReceive() { if (g_usb_interface_initialized) { - g_ds_endpoints[0].Cancel(); - g_ds_endpoints[1].Cancel(); + static_cast(g_ds_endpoints[0].Cancel()); + static_cast(g_ds_endpoints[1].Cancel()); } } diff --git a/libraries/libstratosphere/source/htclow/htclow_channel.cpp b/libraries/libstratosphere/source/htclow/htclow_channel.cpp index 464fe47e5..e1a3ec4e4 100644 --- a/libraries/libstratosphere/source/htclow/htclow_channel.cpp +++ b/libraries/libstratosphere/source/htclow/htclow_channel.cpp @@ -34,7 +34,7 @@ namespace ams::htclow { } void Channel::Close() { - m_manager->Close(impl::ConvertChannelType(m_channel)); + static_cast(m_manager->Close(impl::ConvertChannelType(m_channel))); } ChannelState Channel::GetChannelState() { @@ -72,7 +72,7 @@ namespace ams::htclow { } void Channel::Shutdown() { - m_manager->Shutdown(impl::ConvertChannelType(m_channel)); + static_cast(m_manager->Shutdown(impl::ConvertChannelType(m_channel))); } Result Channel::Receive(s64 *out, void *dst, s64 size, ReceiveOption option) { @@ -221,7 +221,7 @@ namespace ams::htclow { /* Perform the wait. */ if (event != nullptr) { if (os::WaitAny(event, m_manager->GetTaskEvent(task_id)) == 0) { - m_manager->WaitReceiveEnd(task_id); + static_cast(m_manager->WaitReceiveEnd(task_id)); R_THROW(htclow::ResultChannelWaitCancelled()); } } else { diff --git a/libraries/libstratosphere/source/htclow/htclow_worker.cpp b/libraries/libstratosphere/source/htclow/htclow_worker.cpp index 4e725e2ee..3ae088cc5 100644 --- a/libraries/libstratosphere/source/htclow/htclow_worker.cpp +++ b/libraries/libstratosphere/source/htclow/htclow_worker.cpp @@ -64,13 +64,13 @@ namespace ams::htclow { } void Worker::ReceiveThread() { - this->ProcessReceive(); + static_cast(this->ProcessReceive()); m_driver->CancelSendReceive(); this->Cancel(); } void Worker::SendThread() { - this->ProcessSend(); + static_cast(this->ProcessSend()); m_driver->CancelSendReceive(); this->Cancel(); } @@ -114,7 +114,9 @@ namespace ams::htclow { } /* Process the received packet. */ - m_service->ProcessReceivePacket(header, m_receive_packet_body, header.body_size); + if (R_FAILED(m_service->ProcessReceivePacket(header, m_receive_packet_body, header.body_size))) { + /* TODO: PrintIgnorePacket */ + } R_SUCCEED(); } @@ -129,7 +131,9 @@ namespace ams::htclow { } /* Process the received packet. */ - m_mux->ProcessReceivePacket(header, m_receive_packet_body, header.body_size); + if (R_FAILED(m_mux->ProcessReceivePacket(header, m_receive_packet_body, header.body_size))) { + /* TODO: PrintIgnorePacket */ + } R_SUCCEED(); } diff --git a/libraries/libstratosphere/source/htclow/mux/htclow_mux.cpp b/libraries/libstratosphere/source/htclow/mux/htclow_mux.cpp index 16b223f36..93d42c23c 100644 --- a/libraries/libstratosphere/source/htclow/mux/htclow_mux.cpp +++ b/libraries/libstratosphere/source/htclow/mux/htclow_mux.cpp @@ -71,7 +71,9 @@ namespace ams::htclow::mux { R_RETURN(m_channel_impl_map[it->second].ProcessReceivePacket(header, body, body_size)); } else { if (header.packet_type == PacketType_Data || header.packet_type == PacketType_MaxData) { - this->SendErrorPacket(header.channel); + if (R_FAILED(this->SendErrorPacket(header.channel))) { + /* Nintendo doesn't do anything here. */ + } } R_THROW(htclow::ResultChannelNotExist()); } diff --git a/libraries/libstratosphere/source/htcs/client/htcs_virtual_socket_collection.cpp b/libraries/libstratosphere/source/htcs/client/htcs_virtual_socket_collection.cpp index 525939c6f..2f853d1c7 100644 --- a/libraries/libstratosphere/source/htcs/client/htcs_virtual_socket_collection.cpp +++ b/libraries/libstratosphere/source/htcs/client/htcs_virtual_socket_collection.cpp @@ -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; } diff --git a/libraries/libstratosphere/source/htcs/htcs_socket.cpp b/libraries/libstratosphere/source/htcs/htcs_socket.cpp index 8b28b1a17..b9d633be9 100644 --- a/libraries/libstratosphere/source/htcs/htcs_socket.cpp +++ b/libraries/libstratosphere/source/htcs/htcs_socket.cpp @@ -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(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(g_manager->GetDefaultHostName(std::addressof(name))); return name; } @@ -472,7 +472,7 @@ namespace ams::htcs { s32 close(sf::SharedPointer socket, s32 &last_error) { s32 res; - socket->Close(std::addressof(last_error), std::addressof(res)); + static_cast(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(socket->Bind(std::addressof(last_error), std::addressof(res), null_terminated_address)); return res; } s32 listen(sf::SharedPointer socket, s32 backlog_count, s32 &last_error) { s32 res; - socket->Listen(std::addressof(last_error), std::addressof(res), backlog_count); + static_cast(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(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 socket, s32 command, s32 value, s32 &last_error) { s32 res; - socket->Fcntl(std::addressof(last_error), std::addressof(res), command, value); + static_cast(socket->Fcntl(std::addressof(last_error), std::addressof(res), command, value)); return res; } s32 shutdown(sf::SharedPointer socket, s32 how, s32 &last_error) { s32 res; - socket->Shutdown(std::addressof(last_error), std::addressof(res), how); + static_cast(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(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(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(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(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(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(socket->SendResults(std::addressof(last_error), std::addressof(res), task_id)); } else { /* Set error. */ last_error = HTCS_EINTR; diff --git a/libraries/libstratosphere/source/htcs/impl/htcs_manager_impl.cpp b/libraries/libstratosphere/source/htcs/impl/htcs_manager_impl.cpp index 760007416..ae0e74447 100644 --- a/libraries/libstratosphere/source/htcs/impl/htcs_manager_impl.cpp +++ b/libraries/libstratosphere/source/htcs/impl/htcs_manager_impl.cpp @@ -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(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{}, Span{}, Span{}, task_id); + static_cast(m_service.SelectEnd(std::addressof(err), std::addressof(empty), Span{}, Span{}, Span{}, task_id)); if (handle != os::InvalidNativeHandle) { os::SystemEventType event; diff --git a/libraries/libstratosphere/source/htcs/impl/htcs_service.cpp b/libraries/libstratosphere/source/htcs/impl/htcs_service.cpp index 4b57f7a5c..9c6c4c40b 100644 --- a/libraries/libstratosphere/source/htcs/impl/htcs_service.cpp +++ b/libraries/libstratosphere/source/htcs/impl/htcs_service.cpp @@ -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(task_id, desc)); /* Continue the task. */ - m_rpc_client->ReceiveContinue(task_id, buffer, buffer_size); + static_cast(m_rpc_client->ReceiveContinue(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(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(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(task_id, std::addressof(err), out_size)); @@ -347,6 +361,9 @@ namespace ams::htcs::impl { /* Verify the task. */ R_TRY(m_rpc_client->VerifyTaskIdWithHandle(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 read_handles, Span write_handles, Span exception_handles, u32 task_id) { + /* Wait for the task to complete. */ + this->WaitTask(task_id); + /* Finish the task. */ htcs::SocketError err; bool empty; diff --git a/libraries/libvapours/include/vapours/results/results_common.hpp b/libraries/libvapours/include/vapours/results/results_common.hpp index 67d81faad..5d07c3b11 100644 --- a/libraries/libvapours/include/vapours/results/results_common.hpp +++ b/libraries/libvapours/include/vapours/results/results_common.hpp @@ -53,7 +53,7 @@ namespace ams { return (v >> ofs) & ~(~BaseType() << num); } public: - static constexpr ALWAYS_INLINE BaseType MakeValue(BaseType module, BaseType description) { + [[nodiscard]] static constexpr ALWAYS_INLINE BaseType MakeValue(BaseType module, BaseType description) { return (module) | (description << ModuleBits); } @@ -63,23 +63,23 @@ namespace ams { static_assert(description < (1 << DescriptionBits), "Invalid Description"); }; - static constexpr ALWAYS_INLINE BaseType GetModuleFromValue(BaseType value) { + [[nodiscard]] static constexpr ALWAYS_INLINE BaseType GetModuleFromValue(BaseType value) { return GetBitsValue(value, 0, ModuleBits); } - static constexpr ALWAYS_INLINE BaseType GetDescriptionFromValue(BaseType value) { + [[nodiscard]] static constexpr ALWAYS_INLINE BaseType GetDescriptionFromValue(BaseType value) { return GetBitsValue(value, ModuleBits, DescriptionBits); } - static constexpr ALWAYS_INLINE BaseType GetReservedFromValue(BaseType value) { + [[nodiscard]] static constexpr ALWAYS_INLINE BaseType GetReservedFromValue(BaseType value) { return GetBitsValue(value, ModuleBits + DescriptionBits, ReservedBits); } - static constexpr ALWAYS_INLINE BaseType MaskReservedFromValue(BaseType value) { + [[nodiscard]] static constexpr ALWAYS_INLINE BaseType MaskReservedFromValue(BaseType value) { return value & ~(~(~BaseType() << ReservedBits) << (ModuleBits + DescriptionBits)); } - static constexpr ALWAYS_INLINE BaseType MergeValueWithReserved(BaseType value, BaseType reserved) { + [[nodiscard]] static constexpr ALWAYS_INLINE BaseType MergeValueWithReserved(BaseType value, BaseType reserved) { return (value << 0) | (reserved << (ModuleBits + DescriptionBits)); } }; @@ -90,8 +90,8 @@ namespace ams { using BaseType = typename ResultTraits::BaseType; static constexpr BaseType SuccessValue = ResultTraits::SuccessValue; public: - constexpr ALWAYS_INLINE BaseType GetModule(this auto const &self) { return ResultTraits::GetModuleFromValue(self.GetValue()); } - constexpr ALWAYS_INLINE BaseType GetDescription(this auto const &self) { return ResultTraits::GetDescriptionFromValue(self.GetValue()); } + [[nodiscard]] constexpr ALWAYS_INLINE BaseType GetModule(this auto const &self) { return ResultTraits::GetModuleFromValue(self.GetValue()); } + [[nodiscard]] constexpr ALWAYS_INLINE BaseType GetDescription(this auto const &self) { return ResultTraits::GetDescriptionFromValue(self.GetValue()); } }; class ResultInternalAccessor; @@ -100,7 +100,7 @@ namespace ams { class ResultSuccess; - class Result final : public result::impl::ResultBase { + class [[nodiscard]] Result final : public result::impl::ResultBase { friend class result::impl::ResultInternalAccessor; public: using Base = typename result::impl::ResultBase; @@ -115,16 +115,17 @@ namespace ams { constexpr ALWAYS_INLINE Result(typename Base::BaseType v) : m_value(v) { static_assert(std::is_same::value); } constexpr ALWAYS_INLINE operator ResultSuccess() const; - static constexpr ALWAYS_INLINE bool CanAccept(Result) { return true; } - constexpr ALWAYS_INLINE bool IsSuccess() const { return m_value == Base::SuccessValue; } - constexpr ALWAYS_INLINE bool IsFailure() const { return !this->IsSuccess(); } - constexpr ALWAYS_INLINE typename Base::BaseType GetModule() const { return Base::GetModule(); } - constexpr ALWAYS_INLINE typename Base::BaseType GetDescription() const { return Base::GetDescription(); } + [[nodiscard]] static constexpr ALWAYS_INLINE bool CanAccept(Result) { return true; } - constexpr ALWAYS_INLINE typename Base::BaseType GetInnerValue() const { return ::ams::result::impl::ResultTraits::MaskReservedFromValue(m_value); } + [[nodiscard]] constexpr ALWAYS_INLINE bool IsSuccess() const { return m_value == Base::SuccessValue; } + [[nodiscard]] constexpr ALWAYS_INLINE bool IsFailure() const { return !this->IsSuccess(); } + [[nodiscard]] constexpr ALWAYS_INLINE typename Base::BaseType GetModule() const { return Base::GetModule(); } + [[nodiscard]] constexpr ALWAYS_INLINE typename Base::BaseType GetDescription() const { return Base::GetDescription(); } - constexpr ALWAYS_INLINE typename Base::BaseType GetValue() const { return m_value; } + [[nodiscard]] constexpr ALWAYS_INLINE typename Base::BaseType GetInnerValue() const { return ::ams::result::impl::ResultTraits::MaskReservedFromValue(m_value); } + + [[nodiscard]] constexpr ALWAYS_INLINE typename Base::BaseType GetValue() const { return m_value; } }; static_assert(sizeof(Result) == sizeof(Result::Base::BaseType), "sizeof(Result) == sizeof(Result::Base::BaseType)"); static_assert(std::is_trivially_destructible::value, "std::is_trivially_destructible::value"); @@ -137,20 +138,20 @@ namespace ams { class ResultInternalAccessor { public: - static constexpr ALWAYS_INLINE Result MakeResult(ResultTraits::BaseType value) { + [[nodiscard]] static constexpr ALWAYS_INLINE Result MakeResult(ResultTraits::BaseType value) { return Result(value); } - static constexpr ALWAYS_INLINE ResultTraits::BaseType GetReserved(Result result) { + [[nodiscard]] static constexpr ALWAYS_INLINE ResultTraits::BaseType GetReserved(Result result) { return ResultTraits::GetReservedFromValue(result.m_value); } - static constexpr ALWAYS_INLINE Result MergeReserved(Result result, ResultTraits::BaseType reserved) { + [[nodiscard]] static constexpr ALWAYS_INLINE Result MergeReserved(Result result, ResultTraits::BaseType reserved) { return Result(ResultTraits::MergeValueWithReserved(ResultTraits::MaskReservedFromValue(result.m_value), reserved)); } }; - constexpr ALWAYS_INLINE Result MakeResult(ResultTraits::BaseType value) { + [[nodiscard]] constexpr ALWAYS_INLINE Result MakeResult(ResultTraits::BaseType value) { return ResultInternalAccessor::MakeResult(value); } @@ -161,12 +162,12 @@ namespace ams { using Base = typename result::impl::ResultBase; public: constexpr ALWAYS_INLINE operator Result() const { return result::impl::MakeResult(Base::SuccessValue); } - static constexpr ALWAYS_INLINE bool CanAccept(Result result) { return result.IsSuccess(); } + [[nodiscard]] static constexpr ALWAYS_INLINE bool CanAccept(Result result) { return result.IsSuccess(); } - constexpr ALWAYS_INLINE bool IsSuccess() const { return true; } - constexpr ALWAYS_INLINE bool IsFailure() const { return !this->IsSuccess(); } + [[nodiscard]] constexpr ALWAYS_INLINE bool IsSuccess() const { return true; } + [[nodiscard]] constexpr ALWAYS_INLINE bool IsFailure() const { return !this->IsSuccess(); } - constexpr ALWAYS_INLINE typename Base::BaseType GetValue() const { return Base::SuccessValue; } + [[nodiscard]] constexpr ALWAYS_INLINE typename Base::BaseType GetValue() const { return Base::SuccessValue; } }; namespace result::impl { @@ -203,10 +204,10 @@ namespace ams { return ResultSuccess(); } - constexpr ALWAYS_INLINE bool IsSuccess() const { return false; } - constexpr ALWAYS_INLINE bool IsFailure() const { return !this->IsSuccess(); } + [[nodiscard]] constexpr ALWAYS_INLINE bool IsSuccess() const { return false; } + [[nodiscard]] constexpr ALWAYS_INLINE bool IsFailure() const { return !this->IsSuccess(); } - constexpr ALWAYS_INLINE typename Base::BaseType GetValue() const { return Value; } + [[nodiscard]] constexpr ALWAYS_INLINE typename Base::BaseType GetValue() const { return Value; } }; template @@ -223,7 +224,7 @@ namespace ams { static constexpr typename ResultTraits::BaseType StartValue = ResultTraits::MakeStaticValue::value; static constexpr typename ResultTraits::BaseType EndValue = ResultTraits::MakeStaticValue::value; public: - static constexpr ALWAYS_INLINE bool Includes(Result result) { + [[nodiscard]] static constexpr ALWAYS_INLINE bool Includes(Result result) { if constexpr (UseDirectValueComparison) { const auto inner_value = result.GetInnerValue(); if constexpr (StartValue == EndValue) { diff --git a/libraries/libvapours/source/sdmmc/impl/sdmmc_mmc_device_accessor.cpp b/libraries/libvapours/source/sdmmc/impl/sdmmc_mmc_device_accessor.cpp index 2e2b84292..6b7f7f273 100644 --- a/libraries/libvapours/source/sdmmc/impl/sdmmc_mmc_device_accessor.cpp +++ b/libraries/libvapours/source/sdmmc/impl/sdmmc_mmc_device_accessor.cpp @@ -432,7 +432,7 @@ namespace ams::sdmmc::impl { /* If the mmc is manufactured by toshiba, try to enable bkops auto. */ if (is_toshiba && !IsBkopAutoEnable(static_cast(wb))) { /* NOTE: Nintendo does not check the result of this. */ - this->EnableBkopsAuto(); + static_cast(this->EnableBkopsAuto()); } /* Extend the bus speed to as fast as we can. */ @@ -689,7 +689,7 @@ namespace ams::sdmmc::impl { m_mmc_device.GetCid(cid, sizeof(cid)); if (IsToshibaMmc(cid)) { /* NOTE: Nintendo does not check the result of this operation. */ - this->CancelToshibaMmcModel(); + static_cast(this->CancelToshibaMmcModel()); } } diff --git a/libraries/libvapours/source/sdmmc/impl/sdmmc_sd_card_device_accessor.cpp b/libraries/libvapours/source/sdmmc/impl/sdmmc_sd_card_device_accessor.cpp index 69467e54a..39c11b596 100644 --- a/libraries/libvapours/source/sdmmc/impl/sdmmc_sd_card_device_accessor.cpp +++ b/libraries/libvapours/source/sdmmc/impl/sdmmc_sd_card_device_accessor.cpp @@ -558,11 +558,11 @@ namespace ams::sdmmc::impl { /* NOTE: Nintendo accepts a failure. */ if (R_SUCCEEDED(this->IssueCommandAppCmd(DeviceState_Tran))) { /* NOTE: Nintendo does not check the result of this. */ - this->IssueCommandClearCardDetect(); + static_cast(this->IssueCommandClearCardDetect()); } /* NOTE: Nintendo does not check the result of this. */ - BaseDeviceAccessor::IssueCommandSendStatus(); + static_cast(BaseDeviceAccessor::IssueCommandSendStatus()); } Result SdCardDeviceAccessor::StartupSdCardDevice(BusWidth max_bw, SpeedMode max_sm, void *wb, size_t wb_size) { diff --git a/libraries/libvapours/source/sdmmc/impl/sdmmc_sd_host_standard_controller.cpp b/libraries/libvapours/source/sdmmc/impl/sdmmc_sd_host_standard_controller.cpp index 35b3a3907..3ef29782a 100644 --- a/libraries/libvapours/source/sdmmc/impl/sdmmc_sd_host_standard_controller.cpp +++ b/libraries/libvapours/source/sdmmc/impl/sdmmc_sd_host_standard_controller.cpp @@ -369,7 +369,7 @@ namespace ams::sdmmc::impl { /* Otherwise, check if we've timed out. */ if (!timer.Update()) { - this->AbortTransaction(); + static_cast(this->AbortTransaction()); R_THROW(sdmmc::ResultCommandInhibitCmdSoftwareTimeout()); } } @@ -389,7 +389,7 @@ namespace ams::sdmmc::impl { /* Otherwise, check if we've timed out. */ if (!timer.Update()) { - this->AbortTransaction(); + static_cast(this->AbortTransaction()); R_THROW(sdmmc::ResultCommandInhibitDatSoftwareTimeout()); } } @@ -458,7 +458,7 @@ namespace ams::sdmmc::impl { this->ClearInterrupt(); if (R_FAILED(result)) { - this->AbortTransaction(); + static_cast(this->AbortTransaction()); } R_RETURN(result); @@ -467,7 +467,7 @@ namespace ams::sdmmc::impl { R_RETURN(result); } else { /* If the device wasn't removed, cancel our transaction. */ - this->AbortTransaction(); + static_cast(this->AbortTransaction()); R_THROW(sdmmc::ResultCommandCompleteSoftwareTimeout()); } } @@ -489,12 +489,12 @@ namespace ams::sdmmc::impl { } else if (sdmmc::ResultNoWaitedInterrupt::Includes(result)) { /* Otherwise, if the wait for the interrupt isn't done, update the timer and check for timeout. */ if (!timer.Update()) { - this->AbortTransaction(); + static_cast(this->AbortTransaction()); R_THROW(sdmmc::ResultCommandCompleteSoftwareTimeout()); } } else { /* Otherwise, we have a generic failure. */ - this->AbortTransaction(); + static_cast(this->AbortTransaction()); R_RETURN(result); } } @@ -537,7 +537,7 @@ namespace ams::sdmmc::impl { } } else { /* Abort the transaction. */ - this->AbortTransaction(); + static_cast(this->AbortTransaction()); R_RETURN(result); } @@ -548,7 +548,7 @@ namespace ams::sdmmc::impl { } else { /* Otherwise, timeout if the transfer hasn't advanced. */ if (last_block_count != reg::Read(m_registers->block_count)) { - this->AbortTransaction(); + static_cast(this->AbortTransaction()); R_THROW(sdmmc::ResultTransferCompleteSoftwareTimeout()); } } @@ -589,14 +589,14 @@ namespace ams::sdmmc::impl { if (!timer.Update()) { /* Only timeout if the transfer hasn't advanced. */ if (last_block_count != reg::Read(m_registers->block_count)) { - this->AbortTransaction(); + static_cast(this->AbortTransaction()); R_THROW(sdmmc::ResultTransferCompleteSoftwareTimeout()); } break; } } else { /* Otherwise, we have a generic failure. */ - this->AbortTransaction(); + static_cast(this->AbortTransaction()); R_RETURN(result); } } @@ -624,7 +624,7 @@ namespace ams::sdmmc::impl { /* Otherwise, check if we're timed out. */ if (!timer.Update()) { - this->AbortTransaction(); + static_cast(this->AbortTransaction()); R_THROW(sdmmc::ResultBusySoftwareTimeout()); } } diff --git a/libraries/libvapours/source/sdmmc/impl/sdmmc_sdmmc_controller.board.nintendo_nx.cpp b/libraries/libvapours/source/sdmmc/impl/sdmmc_sdmmc_controller.board.nintendo_nx.cpp index a3e6e149a..c3d7a3766 100644 --- a/libraries/libvapours/source/sdmmc/impl/sdmmc_sdmmc_controller.board.nintendo_nx.cpp +++ b/libraries/libvapours/source/sdmmc/impl/sdmmc_sdmmc_controller.board.nintendo_nx.cpp @@ -471,7 +471,7 @@ namespace ams::sdmmc::impl { SdHostStandardController::EnsureControl(); WaitMicroSeconds(1); - SdHostStandardController::AbortTransaction(); + static_cast(SdHostStandardController::AbortTransaction()); } reg::ReadWrite(m_sdmmc_registers->sd_host_standard_registers.clock_control, SD_REG_BITS_ENUM(CLOCK_CONTROL_SD_CLOCK_ENABLE, ENABLE)); @@ -520,7 +520,7 @@ namespace ams::sdmmc::impl { /* Otherwise, check if we timed out. */ if (!timer.Update()) { - SdHostStandardController::AbortTransaction(); + static_cast(SdHostStandardController::AbortTransaction()); R_THROW(sdmmc::ResultIssueTuningCommandSoftwareTimeout()); } } @@ -857,7 +857,8 @@ namespace ams::sdmmc::impl { R_TRY(this->CheckRemoved()); /* Issue the command. */ - this->IssueTuningCommand(command_index); + /* NOTE: Nintendo does not check the result of this call. */ + static_cast(this->IssueTuningCommand(command_index)); /* Check if tuning is done. */ if (i >= num_tries) { @@ -902,7 +903,8 @@ namespace ams::sdmmc::impl { /* If we're at 3.3V, lower to 1.8V. */ if (m_current_bus_power == BusPower_3_3V) { /* pcv::ChangeVoltage(pcv::PowerControlTarget_SdCard, 1800000); */ - m_power_controller->LowerBusPower(); + /* NOTE: Nintendo does not check the result of this call. */ + static_cast(m_power_controller->LowerBusPower()); /* Set our bus power. */ m_current_bus_power = BusPower_1_8V; @@ -913,7 +915,8 @@ namespace ams::sdmmc::impl { /* pcv::PowerOff(pcv::PowerControlTarget_SdCard); */ - m_power_controller->PowerOff(); + /* NOTE: Nintendo does not check the result of this call. */ + static_cast(m_power_controller->PowerOff()); /* Set our bus power. */ m_current_bus_power = BusPower_Off; @@ -1276,7 +1279,8 @@ namespace ams::sdmmc::impl { R_UNLESS(m_current_bus_power == BusPower_1_8V, pcv::ResultIllegalRequest()); /* Disable vddio, and wait 4 ms. */ - this->ControlVddioSdmmc1(BusPower_Off); + /* NOTE: Nintendo does not check the result of this call. */ + static_cast(this->ControlVddioSdmmc1(BusPower_Off)); WaitMicroSeconds(4000); /* Set the SD power GPIO to low. */ diff --git a/utilities/erpt.py b/utilities/erpt.py index a69e6e915..cad52b4a3 100644 --- a/utilities/erpt.py +++ b/utilities/erpt.py @@ -223,8 +223,8 @@ CATEGORIES = { 124 : 'NvHostErrInfo', 125 : 'RunningUlaInfo', 126 : 'InternalPanelInfo', - 127 : 'ResourceLimitLimitInfo', - 128 : 'ResourceLimitPeakInfo', + 127 : 'ResourceLimitInfo', + # 128 : 'ResourceLimitPeakInfoDeprecated', 129 : 'TouchScreenInfo', 130 : 'AcpUserAccountSettingsInfo', 131 : 'AudioDeviceInfo',