From 1e9368c770fd4f5c92e15978735e4767a7aea5a5 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Sat, 22 Feb 2020 23:05:14 -0800 Subject: [PATCH] ams: revamp assertion system --- .../include/mesosphere/kern_common.hpp | 4 +- .../stratosphere/ams/ams_exosphere_api.hpp | 2 +- .../stratosphere/dd/dd_io_mappings.hpp | 2 +- .../fssystem/fssystem_utility.hpp | 2 +- .../stratosphere/kvdb/kvdb_auto_buffer.hpp | 2 +- .../stratosphere/kvdb/kvdb_bounded_string.hpp | 6 +- .../kvdb/kvdb_file_key_value_cache.hpp | 14 +- .../kvdb/kvdb_file_key_value_store.hpp | 2 +- .../kvdb/kvdb_memory_key_value_store.hpp | 4 +- .../include/stratosphere/map/map_types.hpp | 4 +- .../stratosphere/os/os_common_types.hpp | 2 +- .../include/stratosphere/os/os_condvar.hpp | 2 +- .../stratosphere/os/os_managed_handle.hpp | 2 +- .../include/stratosphere/os/os_thread.hpp | 4 +- .../include/stratosphere/ro/ro_types.hpp | 2 +- .../sf/cmif/sf_cmif_domain_manager.hpp | 2 +- .../sf/cmif/sf_cmif_domain_service_object.hpp | 4 +- .../sf/hipc/sf_hipc_server_manager.hpp | 22 +-- .../hipc/sf_hipc_server_session_manager.hpp | 4 +- .../sf/impl/sf_impl_command_serialization.hpp | 6 +- .../include/stratosphere/sf/sf_out.hpp | 2 +- .../stratosphere/sm/sm_scoped_holder.hpp | 4 +- libstratosphere/source/ams/ams_emummc_api.cpp | 2 +- .../source/ams/ams_environment.cpp | 4 +- .../source/ams/ams_exosphere_api.cpp | 10 +- libstratosphere/source/boot2/boot2_api.cpp | 18 +-- libstratosphere/source/cfg/cfg_override.cpp | 2 - .../source/cfg/cfg_privileged_process.cpp | 8 +- libstratosphere/source/cfg/cfg_sd_card.cpp | 6 +- libstratosphere/source/dd/dd_io_mappings.cpp | 2 +- .../source/diag/diag_assertion_impl.cpp | 135 ++++++++++++++++++ libstratosphere/source/fs/fs_path_tool.cpp | 10 +- .../fssrv_filesystem_interface_adapter.cpp | 8 +- ...ystem_directory_redirection_filesystem.cpp | 8 +- ...fssystem_directory_savedata_filesystem.cpp | 4 +- .../fssystem_subdirectory_filesystem.cpp | 6 +- .../source/fssystem/fssystem_utility.cpp | 4 +- libstratosphere/source/hid/hid_api.cpp | 4 +- libstratosphere/source/kvdb/kvdb_archive.cpp | 26 ++-- .../source/kvdb/kvdb_file_key_value_store.cpp | 4 +- libstratosphere/source/map/map_api.cpp | 6 +- .../source/os/impl/os_inter_process_event.cpp | 28 ++-- .../os/impl/os_random_impl.os.horizon.cpp | 4 +- ...waitable_holder_of_inter_process_event.hpp | 2 +- .../os_waitable_holder_of_interrupt_event.hpp | 2 +- .../os/impl/os_waitable_manager_impl.cpp | 6 +- .../source/os/os_interrupt_event.cpp | 16 +-- .../source/os/os_message_queue.cpp | 8 +- libstratosphere/source/os/os_semaphore.cpp | 4 +- libstratosphere/source/os/os_system_event.cpp | 26 ++-- .../source/os/os_waitable_holder.cpp | 6 +- .../source/os/os_waitable_manager.cpp | 10 +- .../source/patcher/patcher_api.cpp | 12 +- .../source/pm/pm_boot_mode_api.cpp | 4 +- libstratosphere/source/pm/pm_info_api.cpp | 2 +- .../source/result/result_on_assertion.cpp | 41 ++++-- .../source/settings/settings_fwdbg_api.cpp | 4 +- .../source/sf/cmif/sf_cmif_domain_manager.cpp | 20 +-- .../sf/cmif/sf_cmif_domain_service_object.cpp | 6 +- .../sf/cmif/sf_cmif_service_dispatch.cpp | 4 +- .../source/sf/hipc/sf_hipc_api.cpp | 6 +- .../source/sf/hipc/sf_hipc_mitm_query_api.cpp | 6 +- .../sf_hipc_server_domain_session_manager.cpp | 22 +-- .../source/sf/hipc/sf_hipc_server_manager.cpp | 20 +-- .../hipc/sf_hipc_server_session_manager.cpp | 16 +-- libstratosphere/source/sm/sm_utils.hpp | 6 +- libstratosphere/source/spl/smc/spl_smc.cpp | 4 +- libstratosphere/source/spl/spl_api.cpp | 10 +- .../source/updater/updater_api.cpp | 14 +- .../source/updater/updater_bis_management.cpp | 22 +-- .../source/updater/updater_bis_management.hpp | 8 +- .../source/updater/updater_bis_save.cpp | 6 +- .../source/updater/updater_paths.cpp | 2 +- .../source/util/util_compression.cpp | 8 +- libstratosphere/source/util/util_ini.cpp | 6 +- libvapours/include/vapours.hpp | 4 +- libvapours/include/vapours/assert.hpp | 76 ++++++++++ libvapours/include/vapours/common.hpp | 31 ++++ .../vapours/crypto/crypto_memory_compare.hpp | 5 +- .../impl/crypto_memory_compare.arch.arm64.hpp | 2 +- libvapours/include/vapours/defines.hpp | 4 - libvapours/include/vapours/literals.hpp | 3 +- libvapours/include/vapours/results.hpp | 3 +- .../vapours/results/results_common.hpp | 61 ++++++-- libvapours/include/vapours/svc.hpp | 3 +- .../codegen/impl/svc_codegen_impl_common.hpp | 3 + libvapours/include/vapours/svc/svc_common.hpp | 2 + libvapours/include/vapours/svc/svc_tick.hpp | 4 +- libvapours/include/vapours/timespan.hpp | 3 +- libvapours/include/vapours/util.hpp | 3 +- .../include/vapours/util/util_alignment.hpp | 3 +- .../include/vapours/util/util_bitpack.hpp | 3 +- .../include/vapours/util/util_bitset.hpp | 3 +- .../include/vapours/util/util_bitutil.hpp | 3 +- .../include/vapours/util/util_fourcc.hpp | 3 +- .../vapours/util/util_intrusive_list.hpp | 4 +- .../util/util_intrusive_red_black_tree.hpp | 4 +- .../vapours/util/util_parent_of_member.hpp | 5 +- .../include/vapours/util/util_scope_guard.hpp | 5 +- libvapours/include/vapours/util/util_size.hpp | 3 +- .../vapours/util/util_specialization_of.hpp | 3 +- .../include/vapours/util/util_tinymt.hpp | 3 +- .../vapours/util/util_typed_storage.hpp | 3 +- 103 files changed, 648 insertions(+), 330 deletions(-) create mode 100644 libstratosphere/source/diag/diag_assertion_impl.cpp create mode 100644 libvapours/include/vapours/assert.hpp create mode 100644 libvapours/include/vapours/common.hpp diff --git a/libmesosphere/include/mesosphere/kern_common.hpp b/libmesosphere/include/mesosphere/kern_common.hpp index db9679f6..71f621e9 100644 --- a/libmesosphere/include/mesosphere/kern_common.hpp +++ b/libmesosphere/include/mesosphere/kern_common.hpp @@ -22,11 +22,11 @@ namespace ams::kern { } -#if 1 +#if 1 || defined(AMS_BUILD_FOR_AUDITING) #define MESOSPHERE_BUILD_FOR_AUDITING #endif -#ifdef MESOSPHERE_BUILD_FOR_AUDITING +#if defined(MESOSPHERE_BUILD_FOR_AUDITING) || defined(AMS_BUILD_FOR_DEBUGGING) #define MESOSPHERE_BUILD_FOR_DEBUGGING #endif diff --git a/libstratosphere/include/stratosphere/ams/ams_exosphere_api.hpp b/libstratosphere/include/stratosphere/ams/ams_exosphere_api.hpp index b4e8e548..eb80efef 100644 --- a/libstratosphere/include/stratosphere/ams/ams_exosphere_api.hpp +++ b/libstratosphere/include/stratosphere/ams/ams_exosphere_api.hpp @@ -40,7 +40,7 @@ namespace ams { const u32 build_version = exosphere::GetVersion(ATMOSPHERE_RELEASE_VERSION); if (runtime_version < build_version) { - R_ASSERT(exosphere::ResultVersionMismatch()); + R_ABORT_UNLESS(exosphere::ResultVersionMismatch()); } } diff --git a/libstratosphere/include/stratosphere/dd/dd_io_mappings.hpp b/libstratosphere/include/stratosphere/dd/dd_io_mappings.hpp index ca2aa005..4cd493b2 100644 --- a/libstratosphere/include/stratosphere/dd/dd_io_mappings.hpp +++ b/libstratosphere/include/stratosphere/dd/dd_io_mappings.hpp @@ -29,7 +29,7 @@ namespace ams::dd { inline uintptr_t GetIoMapping(uintptr_t phys_addr, size_t size) { const uintptr_t io_mapping = QueryIoMapping(phys_addr, size); - AMS_ASSERT(io_mapping); + AMS_ABORT_UNLESS(io_mapping); return io_mapping; } diff --git a/libstratosphere/include/stratosphere/fssystem/fssystem_utility.hpp b/libstratosphere/include/stratosphere/fssystem/fssystem_utility.hpp index 46151d93..ce71ebc9 100644 --- a/libstratosphere/include/stratosphere/fssystem/fssystem_utility.hpp +++ b/libstratosphere/include/stratosphere/fssystem/fssystem_utility.hpp @@ -83,7 +83,7 @@ namespace ams::fssystem { /* Iteration API */ template Result IterateDirectoryRecursively(fs::fsa::IFileSystem *fs, const char *root_path, char *work_path, size_t work_path_size, fs::DirectoryEntry *dir_ent_buf, OnEnterDir on_enter_dir, OnExitDir on_exit_dir, OnFile on_file) { - AMS_ASSERT(work_path_size >= fs::EntryNameLengthMax + 1); + AMS_ABORT_UNLESS(work_path_size >= fs::EntryNameLengthMax + 1); /* Get size of the root path. */ size_t root_path_len = strnlen(root_path, fs::EntryNameLengthMax + 1); diff --git a/libstratosphere/include/stratosphere/kvdb/kvdb_auto_buffer.hpp b/libstratosphere/include/stratosphere/kvdb/kvdb_auto_buffer.hpp index 921589ee..bb5378b7 100644 --- a/libstratosphere/include/stratosphere/kvdb/kvdb_auto_buffer.hpp +++ b/libstratosphere/include/stratosphere/kvdb/kvdb_auto_buffer.hpp @@ -66,7 +66,7 @@ namespace ams::kvdb { Result Initialize(size_t size) { /* Check that we're not already initialized. */ - AMS_ASSERT(this->buffer == nullptr); + AMS_ABORT_UNLESS(this->buffer == nullptr); /* Allocate a buffer. */ this->buffer = static_cast(std::malloc(size)); diff --git a/libstratosphere/include/stratosphere/kvdb/kvdb_bounded_string.hpp b/libstratosphere/include/stratosphere/kvdb/kvdb_bounded_string.hpp index 1fcb8d8c..7d0aec0b 100644 --- a/libstratosphere/include/stratosphere/kvdb/kvdb_bounded_string.hpp +++ b/libstratosphere/include/stratosphere/kvdb/kvdb_bounded_string.hpp @@ -28,7 +28,7 @@ namespace ams::kvdb { private: /* Utility. */ static inline void CheckLength(size_t len) { - AMS_ASSERT(len < N); + AMS_ABORT_UNLESS(len < N); } public: /* Constructors. */ @@ -109,8 +109,8 @@ namespace ams::kvdb { /* Substring utilities. */ void GetSubstring(char *dst, size_t dst_size, size_t offset, size_t length) const { /* Make sure output buffer can hold the substring. */ - AMS_ASSERT(offset + length <= GetLength()); - AMS_ASSERT(dst_size > length); + AMS_ABORT_UNLESS(offset + length <= GetLength()); + AMS_ABORT_UNLESS(dst_size > length); /* Copy substring to dst. */ std::strncpy(dst, this->buffer + offset, length); dst[length] = 0; diff --git a/libstratosphere/include/stratosphere/kvdb/kvdb_file_key_value_cache.hpp b/libstratosphere/include/stratosphere/kvdb/kvdb_file_key_value_cache.hpp index bd4ad839..c98c2518 100644 --- a/libstratosphere/include/stratosphere/kvdb/kvdb_file_key_value_cache.hpp +++ b/libstratosphere/include/stratosphere/kvdb/kvdb_file_key_value_cache.hpp @@ -54,7 +54,7 @@ namespace ams::kvdb { } private: void RemoveIndex(size_t i) { - AMS_ASSERT(i < this->GetCount()); + AMS_ABORT_UNLESS(i < this->GetCount()); std::memmove(this->keys + i, this->keys + i + 1, sizeof(*this->keys) * (this->GetCount() - (i + 1))); this->DecrementCount(); } @@ -71,8 +71,8 @@ namespace ams::kvdb { Result Initialize(const char *path, void *buf, size_t size) { /* Only initialize once, and ensure we have sufficient memory. */ - AMS_ASSERT(this->keys == nullptr); - AMS_ASSERT(size >= BufferSize); + AMS_ABORT_UNLESS(this->keys == nullptr); + AMS_ABORT_UNLESS(size >= BufferSize); /* Setup member variables. */ this->keys = static_cast(buf); @@ -127,23 +127,23 @@ namespace ams::kvdb { } Key Get(size_t i) const { - AMS_ASSERT(i < this->GetCount()); + AMS_ABORT_UNLESS(i < this->GetCount()); return this->keys[i]; } Key Peek() const { - AMS_ASSERT(!this->IsEmpty()); + AMS_ABORT_UNLESS(!this->IsEmpty()); return this->Get(0); } void Push(const Key &key) { - AMS_ASSERT(!this->IsFull()); + AMS_ABORT_UNLESS(!this->IsFull()); this->keys[this->GetCount()] = key; this->IncrementCount(); } Key Pop() { - AMS_ASSERT(!this->IsEmpty()); + AMS_ABORT_UNLESS(!this->IsEmpty()); this->RemoveIndex(0); } diff --git a/libstratosphere/include/stratosphere/kvdb/kvdb_file_key_value_store.hpp b/libstratosphere/include/stratosphere/kvdb/kvdb_file_key_value_store.hpp index 7bf2b5fd..e772897e 100644 --- a/libstratosphere/include/stratosphere/kvdb/kvdb_file_key_value_store.hpp +++ b/libstratosphere/include/stratosphere/kvdb/kvdb_file_key_value_store.hpp @@ -92,7 +92,7 @@ namespace ams::kvdb { static_assert(std::is_pod::value && !std::is_pointer::value, "Invalid FileKeyValueStore Value!"); size_t size = 0; R_TRY(this->Get(&size, out_value, sizeof(Value), key)); - AMS_ASSERT(size >= sizeof(Value)); + AMS_ABORT_UNLESS(size >= sizeof(Value)); return ResultSuccess(); } diff --git a/libstratosphere/include/stratosphere/kvdb/kvdb_memory_key_value_store.hpp b/libstratosphere/include/stratosphere/kvdb/kvdb_memory_key_value_store.hpp index 5a6e2702..00a10dfe 100644 --- a/libstratosphere/include/stratosphere/kvdb/kvdb_memory_key_value_store.hpp +++ b/libstratosphere/include/stratosphere/kvdb/kvdb_memory_key_value_store.hpp @@ -45,7 +45,7 @@ namespace ams::kvdb { Value *GetValuePointer() { /* Size check. Note: Nintendo does not size check. */ if constexpr (!std::is_same::value) { - AMS_ASSERT(sizeof(Value) <= this->value_size); + AMS_ABORT_UNLESS(sizeof(Value) <= this->value_size); /* Ensure we only get pod. */ static_assert(std::is_pod::value, "KeyValueStore Values must be pod"); } @@ -56,7 +56,7 @@ namespace ams::kvdb { const Value *GetValuePointer() const { /* Size check. Note: Nintendo does not size check. */ if constexpr (!std::is_same::value) { - AMS_ASSERT(sizeof(Value) <= this->value_size); + AMS_ABORT_UNLESS(sizeof(Value) <= this->value_size); /* Ensure we only get pod. */ static_assert(std::is_pod::value, "KeyValueStore Values must be pod"); } diff --git a/libstratosphere/include/stratosphere/map/map_types.hpp b/libstratosphere/include/stratosphere/map/map_types.hpp index 32dff024..830e887d 100644 --- a/libstratosphere/include/stratosphere/map/map_types.hpp +++ b/libstratosphere/include/stratosphere/map/map_types.hpp @@ -53,7 +53,7 @@ namespace ams::map { ~AutoCloseMap() { if (this->process_handle != INVALID_HANDLE && R_SUCCEEDED(this->result)) { - R_ASSERT(svcUnmapProcessMemory(this->mapped_address, this->process_handle, this->base_address, this->size)); + R_ABORT_UNLESS(svcUnmapProcessMemory(this->mapped_address, this->process_handle, this->base_address, this->size)); } } @@ -88,7 +88,7 @@ namespace ams::map { ~MappedCodeMemory() { if (this->process_handle != INVALID_HANDLE && R_SUCCEEDED(this->result) && this->size > 0) { - R_ASSERT(svcUnmapProcessCodeMemory(this->process_handle, this->dst_address, this->src_address, this->size)); + R_ABORT_UNLESS(svcUnmapProcessCodeMemory(this->process_handle, this->dst_address, this->src_address, this->size)); } } diff --git a/libstratosphere/include/stratosphere/os/os_common_types.hpp b/libstratosphere/include/stratosphere/os/os_common_types.hpp index 0da1423a..e085177a 100644 --- a/libstratosphere/include/stratosphere/os/os_common_types.hpp +++ b/libstratosphere/include/stratosphere/os/os_common_types.hpp @@ -50,7 +50,7 @@ namespace ams::os { NX_INLINE os::ProcessId GetProcessId(::Handle process_handle) { os::ProcessId process_id; - R_ASSERT(TryGetProcessId(&process_id, process_handle)); + R_ABORT_UNLESS(TryGetProcessId(&process_id, process_handle)); return process_id; } diff --git a/libstratosphere/include/stratosphere/os/os_condvar.hpp b/libstratosphere/include/stratosphere/os/os_condvar.hpp index 55757916..9e31022b 100644 --- a/libstratosphere/include/stratosphere/os/os_condvar.hpp +++ b/libstratosphere/include/stratosphere/os/os_condvar.hpp @@ -47,7 +47,7 @@ namespace ams::os { } void Wait(::Mutex *m) { - R_ASSERT(condvarWait(&this->cv, m)); + R_ABORT_UNLESS(condvarWait(&this->cv, m)); } ConditionVariableStatus TimedWait(os::Mutex *m, u64 timeout) { diff --git a/libstratosphere/include/stratosphere/os/os_managed_handle.hpp b/libstratosphere/include/stratosphere/os/os_managed_handle.hpp index b64e1661..67399757 100644 --- a/libstratosphere/include/stratosphere/os/os_managed_handle.hpp +++ b/libstratosphere/include/stratosphere/os/os_managed_handle.hpp @@ -28,7 +28,7 @@ namespace ams::os { ManagedHandle(Handle h) : hnd(h) { /* ... */ } ~ManagedHandle() { if (this->hnd != INVALID_HANDLE) { - R_ASSERT(svcCloseHandle(this->hnd)); + R_ABORT_UNLESS(svcCloseHandle(this->hnd)); this->hnd = INVALID_HANDLE; } } diff --git a/libstratosphere/include/stratosphere/os/os_thread.hpp b/libstratosphere/include/stratosphere/os/os_thread.hpp index 397906f1..4dab3d8e 100644 --- a/libstratosphere/include/stratosphere/os/os_thread.hpp +++ b/libstratosphere/include/stratosphere/os/os_thread.hpp @@ -71,7 +71,7 @@ namespace ams::os { constexpr StaticThread() : stack_mem{}, thr{} { /* ... */ } constexpr StaticThread(ThreadFunc entry, void *arg, int prio, int cpuid = -2) : StaticThread() { - R_ASSERT(this->Initialize(entry, arg, prio, cpuid)); + R_ABORT_UNLESS(this->Initialize(entry, arg, prio, cpuid)); } Result Initialize(ThreadFunc entry, void *arg, int prio, int cpuid = -2) { @@ -103,7 +103,7 @@ namespace ams::os { NX_INLINE u32 GetCurrentThreadPriority() { u32 prio; - R_ASSERT(svcGetThreadPriority(&prio, CUR_THREAD_HANDLE)); + R_ABORT_UNLESS(svcGetThreadPriority(&prio, CUR_THREAD_HANDLE)); return prio; } diff --git a/libstratosphere/include/stratosphere/ro/ro_types.hpp b/libstratosphere/include/stratosphere/ro/ro_types.hpp index 7e893ac0..8119ad8a 100644 --- a/libstratosphere/include/stratosphere/ro/ro_types.hpp +++ b/libstratosphere/include/stratosphere/ro/ro_types.hpp @@ -61,7 +61,7 @@ namespace ams::ro { ModuleType GetType() const { const ModuleType type = static_cast(this->type); - AMS_ASSERT(type < ModuleType::Count); + AMS_ABORT_UNLESS(type < ModuleType::Count); return type; } diff --git a/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_domain_manager.hpp b/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_domain_manager.hpp index c513c1fb..4878a350 100644 --- a/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_domain_manager.hpp +++ b/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_domain_manager.hpp @@ -87,7 +87,7 @@ namespace ams::sf::cmif { inline DomainObjectId GetId(Entry *e) { const size_t index = e - this->entries; - AMS_ASSERT(index < this->num_entries); + AMS_ABORT_UNLESS(index < this->num_entries); return DomainObjectId{ u32(index + 1) }; } diff --git a/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_domain_service_object.hpp b/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_domain_service_object.hpp index f9da178d..34680b2f 100644 --- a/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_domain_service_object.hpp +++ b/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_domain_service_object.hpp @@ -41,8 +41,8 @@ namespace ams::sf::cmif { ServerMessageRuntimeMetadata impl_metadata; public: DomainServiceObjectProcessor(ServerDomainBase *d, DomainObjectId *in_obj_ids, size_t num_in_objs) : domain(d), in_object_ids(in_obj_ids), num_in_objects(num_in_objs) { - AMS_ASSERT(this->domain != nullptr); - AMS_ASSERT(this->in_object_ids != nullptr); + AMS_ABORT_UNLESS(this->domain != nullptr); + AMS_ABORT_UNLESS(this->in_object_ids != nullptr); this->impl_processor = nullptr; this->out_object_ids = nullptr; this->impl_metadata = {}; diff --git a/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_manager.hpp b/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_manager.hpp index 1ba56d4a..11af973c 100644 --- a/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_manager.hpp +++ b/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_manager.hpp @@ -83,11 +83,11 @@ namespace ams::sf::hipc { virtual ~Server() override { if (this->service_managed) { if constexpr (IsMitmServer) { - R_ASSERT(sm::mitm::UninstallMitm(this->service_name)); + R_ABORT_UNLESS(sm::mitm::UninstallMitm(this->service_name)); } else { - R_ASSERT(sm::UnregisterService(this->service_name)); + R_ABORT_UNLESS(sm::UnregisterService(this->service_name)); } - R_ASSERT(svcCloseHandle(this->port_handle)); + R_ABORT_UNLESS(svcCloseHandle(this->port_handle)); } } @@ -106,7 +106,7 @@ namespace ams::sf::hipc { /* Get mitm forward session. */ sm::MitmProcessInfo client_info; - R_ASSERT(sm::mitm::AcknowledgeSession(forward_service.get(), &client_info, this->service_name)); + R_ABORT_UNLESS(sm::mitm::AcknowledgeSession(forward_service.get(), &client_info, this->service_name)); *out_obj = std::move(cmif::ServiceObjectHolder(std::move(MakeShared(std::shared_ptr<::Service>(forward_service), client_info)))); *out_fsrv = std::move(forward_service); @@ -149,7 +149,7 @@ namespace ams::sf::hipc { void RegisterServerImpl(Handle port_handle, sm::ServiceName service_name, bool managed, cmif::ServiceObjectHolder &&static_holder) { /* Allocate server memory. */ auto *server = this->AllocateServer(); - AMS_ASSERT(server != nullptr); + AMS_ABORT_UNLESS(server != nullptr); new (server) Server(port_handle, service_name, managed, std::forward(static_holder)); if constexpr (!ServiceObjectTraits::IsMitmServiceObject) { @@ -273,13 +273,13 @@ namespace ams::sf::hipc { private: constexpr inline size_t GetServerIndex(const ServerBase *server) const { const size_t i = server - GetPointer(this->server_storages[0]); - AMS_ASSERT(i < MaxServers); + AMS_ABORT_UNLESS(i < MaxServers); return i; } constexpr inline size_t GetSessionIndex(const ServerSession *session) const { const size_t i = session - GetPointer(this->session_storages[0]); - AMS_ASSERT(i < MaxSessions); + AMS_ABORT_UNLESS(i < MaxSessions); return i; } @@ -301,7 +301,7 @@ namespace ams::sf::hipc { virtual void FreeSession(ServerSession *session) override final { std::scoped_lock lk(this->resource_mutex); const size_t index = this->GetSessionIndex(session); - AMS_ASSERT(this->session_allocated[index]); + AMS_ABORT_UNLESS(this->session_allocated[index]); this->session_allocated[index] = false; } @@ -319,7 +319,7 @@ namespace ams::sf::hipc { virtual void DestroyServer(ServerBase *server) override final { std::scoped_lock lk(this->resource_mutex); const size_t index = this->GetServerIndex(server); - AMS_ASSERT(this->server_allocated[index]); + AMS_ABORT_UNLESS(this->server_allocated[index]); server->~ServerBase(); this->server_allocated[index] = false; } @@ -339,8 +339,8 @@ namespace ams::sf::hipc { std::scoped_lock lk(this->resource_mutex); DomainStorage *ptr = static_cast(domain); const size_t index = ptr - this->domain_storages; - AMS_ASSERT(index < ManagerOptions::MaxDomains); - AMS_ASSERT(this->domain_allocated[index]); + AMS_ABORT_UNLESS(index < ManagerOptions::MaxDomains); + AMS_ABORT_UNLESS(this->domain_allocated[index]); this->domain_allocated[index] = false; } diff --git a/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_session_manager.hpp b/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_session_manager.hpp index 83bfd0ba..23278f8f 100644 --- a/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_session_manager.hpp +++ b/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_session_manager.hpp @@ -58,14 +58,14 @@ namespace ams::sf::hipc { this->is_closed = false; this->has_received = false; this->forward_service = nullptr; - AMS_ASSERT(!this->IsMitmSession()); + AMS_ABORT_UNLESS(!this->IsMitmSession()); } ServerSession(Handle h, cmif::ServiceObjectHolder &&obj, std::shared_ptr<::Service> &&fsrv) : WaitableHolder(h), srv_obj_holder(std::move(obj)), session_handle(h) { this->is_closed = false; this->has_received = false; this->forward_service = std::move(fsrv); - AMS_ASSERT(this->IsMitmSession()); + AMS_ABORT_UNLESS(this->IsMitmSession()); } bool IsMitmSession() const { diff --git a/libstratosphere/include/stratosphere/sf/impl/sf_impl_command_serialization.hpp b/libstratosphere/include/stratosphere/sf/impl/sf_impl_command_serialization.hpp index ff721afc..1f347ca4 100644 --- a/libstratosphere/include/stratosphere/sf/impl/sf_impl_command_serialization.hpp +++ b/libstratosphere/include/stratosphere/sf/impl/sf_impl_command_serialization.hpp @@ -797,8 +797,8 @@ namespace ams::sf::impl { return; } Handle server_handle, client_handle; - R_ASSERT(sf::hipc::CreateSession(&server_handle, &client_handle)); - R_ASSERT(manager->RegisterSession(server_handle, std::move(object))); + R_ABORT_UNLESS(sf::hipc::CreateSession(&server_handle, &client_handle)); + R_ABORT_UNLESS(manager->RegisterSession(server_handle, std::move(object))); response.move_handles[Index] = client_handle; } @@ -1013,7 +1013,7 @@ namespace ams::sf::impl { /* Fake buffer. This is either InData or OutData, but serializing over buffers. */ constexpr auto Attributes = CommandMeta::BufferAttributes[Info.buffer_index]; if constexpr (Attributes & SfBufferAttr_In) { - /* TODO: AMS_ASSERT()? N does not bother. */ + /* TODO: AMS_ABORT_UNLESS()? N does not bother. */ return *reinterpret_cast(buffers[Info.buffer_index].GetAddress()); } else if constexpr (Attributes & SfBufferAttr_Out) { return T(buffers[Info.buffer_index]); diff --git a/libstratosphere/include/stratosphere/sf/sf_out.hpp b/libstratosphere/include/stratosphere/sf/sf_out.hpp index 28209458..b5fb1e6f 100644 --- a/libstratosphere/include/stratosphere/sf/sf_out.hpp +++ b/libstratosphere/include/stratosphere/sf/sf_out.hpp @@ -44,7 +44,7 @@ namespace ams::sf { public: constexpr Out(uintptr_t p) : ptr(reinterpret_cast(p)) { /* ... */ } constexpr Out(T *p) : ptr(p) { /* ... */ } - constexpr Out(const cmif::PointerAndSize &pas) : ptr(reinterpret_cast(pas.GetAddress())) { /* TODO: Is AMS_ASSERT(pas.GetSize() >= sizeof(T)); necessary? */ } + constexpr Out(const cmif::PointerAndSize &pas) : ptr(reinterpret_cast(pas.GetAddress())) { /* TODO: Is AMS_ABORT_UNLESS(pas.GetSize() >= sizeof(T)); necessary? */ } void SetValue(const T& value) const { *this->ptr = value; diff --git a/libstratosphere/include/stratosphere/sm/sm_scoped_holder.hpp b/libstratosphere/include/stratosphere/sm/sm_scoped_holder.hpp index 1e0502c9..a0cd09e0 100644 --- a/libstratosphere/include/stratosphere/sm/sm_scoped_holder.hpp +++ b/libstratosphere/include/stratosphere/sm/sm_scoped_holder.hpp @@ -62,7 +62,7 @@ namespace ams::sm { } Result Initialize() { - AMS_ASSERT(!this->has_initialized); + AMS_ABORT_UNLESS(!this->has_initialized); sm::DoWithSession([&]() { this->result = Initializer(); @@ -73,7 +73,7 @@ namespace ams::sm { } void Finalize() { - AMS_ASSERT(this->has_initialized); + AMS_ABORT_UNLESS(this->has_initialized); Finalizer(); this->has_initialized = false; } diff --git a/libstratosphere/source/ams/ams_emummc_api.cpp b/libstratosphere/source/ams/ams_emummc_api.cpp index b7eba504..df18d5b3 100644 --- a/libstratosphere/source/ams/ams_emummc_api.cpp +++ b/libstratosphere/source/ams/ams_emummc_api.cpp @@ -82,7 +82,7 @@ namespace ams::emummc { } *paths = reinterpret_cast(&path_storage); /* Retrieve paths from secure monitor. */ - AMS_ASSERT(spl::smc::AtmosphereGetEmummcConfig(&g_exo_config, paths, 0) == spl::smc::Result::Success); + AMS_ABORT_UNLESS(spl::smc::AtmosphereGetEmummcConfig(&g_exo_config, paths, 0) == spl::smc::Result::Success); const Storage storage = static_cast(g_exo_config.base_cfg.type); g_is_emummc = g_exo_config.base_cfg.magic == StorageMagic && storage != Storage_Emmc; diff --git a/libstratosphere/source/ams/ams_environment.cpp b/libstratosphere/source/ams/ams_environment.cpp index b4900636..fd7fc062 100644 --- a/libstratosphere/source/ams/ams_environment.cpp +++ b/libstratosphere/source/ams/ams_environment.cpp @@ -37,8 +37,8 @@ namespace ams { extern ncm::ProgramId CurrentProgramId; void WEAK_SYMBOL ExceptionHandler(FatalErrorContext *ctx) { - R_ASSERT(amsBpcInitialize()); - R_ASSERT(amsBpcRebootToFatalError(ctx)); + R_ABORT_UNLESS(amsBpcInitialize()); + R_ABORT_UNLESS(amsBpcRebootToFatalError(ctx)); while (1) { /* ... */ } } diff --git a/libstratosphere/source/ams/ams_exosphere_api.cpp b/libstratosphere/source/ams/ams_exosphere_api.cpp index 1e77bb4f..18f6a69a 100644 --- a/libstratosphere/source/ams/ams_exosphere_api.cpp +++ b/libstratosphere/source/ams/ams_exosphere_api.cpp @@ -23,22 +23,22 @@ namespace ams::exosphere { ApiInfo GetApiInfo() { u64 exosphere_cfg; if (spl::smc::GetConfig(&exosphere_cfg, 1, SplConfigItem_ExosphereApiVersion) != spl::smc::Result::Success) { - R_ASSERT(ResultNotPresent()); + R_ABORT_UNLESS(ResultNotPresent()); } return ApiInfo{ util::BitPack64(exosphere_cfg) }; } void ForceRebootToRcm() { - R_ASSERT(spl::smc::ConvertResult(spl::smc::SetConfig(SplConfigItem_ExosphereNeedsReboot, 1))); + R_ABORT_UNLESS(spl::smc::ConvertResult(spl::smc::SetConfig(SplConfigItem_ExosphereNeedsReboot, 1))); } void ForceRebootToIramPayload() { - R_ASSERT(spl::smc::ConvertResult(spl::smc::SetConfig(SplConfigItem_ExosphereNeedsReboot, 2))); + R_ABORT_UNLESS(spl::smc::ConvertResult(spl::smc::SetConfig(SplConfigItem_ExosphereNeedsReboot, 2))); } void ForceShutdown() { - R_ASSERT(spl::smc::ConvertResult(spl::smc::SetConfig(SplConfigItem_ExosphereNeedsShutdown, 1))); + R_ABORT_UNLESS(spl::smc::ConvertResult(spl::smc::SetConfig(SplConfigItem_ExosphereNeedsShutdown, 1))); } void CopyToIram(uintptr_t iram_dst, const void *dram_src, size_t size) { @@ -62,7 +62,7 @@ namespace ams::exosphere { bool IsRcmBugPatched() { bool rcm_bug_patched; - R_ASSERT(GetRcmBugPatched(&rcm_bug_patched)); + R_ABORT_UNLESS(GetRcmBugPatched(&rcm_bug_patched)); return rcm_bug_patched; } diff --git a/libstratosphere/source/boot2/boot2_api.cpp b/libstratosphere/source/boot2/boot2_api.cpp index dd287c1b..14a59477 100644 --- a/libstratosphere/source/boot2/boot2_api.cpp +++ b/libstratosphere/source/boot2/boot2_api.cpp @@ -140,9 +140,9 @@ namespace ams::boot2 { /* Launch, lightly validate result. */ { const auto launch_result = pm::shell::LaunchProgram(&process_id, loc, launch_flags); - AMS_ASSERT(!(svc::ResultOutOfResource::Includes(launch_result))); - AMS_ASSERT(!(svc::ResultOutOfMemory::Includes(launch_result))); - AMS_ASSERT(!(svc::ResultLimitReached::Includes(launch_result))); + AMS_ABORT_UNLESS(!(svc::ResultOutOfResource::Includes(launch_result))); + AMS_ABORT_UNLESS(!(svc::ResultOutOfMemory::Includes(launch_result))); + AMS_ABORT_UNLESS(!(svc::ResultLimitReached::Includes(launch_result))); } if (out_process_id) { @@ -265,10 +265,10 @@ namespace ams::boot2 { } /* Don't allow invalid lines. */ - AMS_ASSERT(name_len <= sizeof(sm::ServiceName)); + AMS_ABORT_UNLESS(name_len <= sizeof(sm::ServiceName)); /* Declare the service. */ - R_ASSERT(sm::mitm::DeclareFutureMitm(sm::ServiceName::Encode(mitm_list + offset, name_len))); + R_ABORT_UNLESS(sm::mitm::DeclareFutureMitm(sm::ServiceName::Encode(mitm_list + offset, name_len))); /* Advance to the next line. */ offset += name_len; @@ -296,7 +296,7 @@ namespace ams::boot2 { /* This code is normally run by PM. */ /* Wait until fs.mitm has installed itself. We want this to happen as early as possible. */ - R_ASSERT(sm::mitm::WaitMitm(sm::ServiceName::Encode("fsp-srv"))); + R_ABORT_UNLESS(sm::mitm::WaitMitm(sm::ServiceName::Encode("fsp-srv"))); /* Launch programs required to mount the SD card. */ LaunchList(PreSdCardLaunchPrograms, NumPreSdCardLaunchPrograms); @@ -305,11 +305,11 @@ namespace ams::boot2 { cfg::WaitSdCardRequiredServicesReady(); /* Wait for other atmosphere mitm modules to initialize. */ - R_ASSERT(sm::mitm::WaitMitm(sm::ServiceName::Encode("set:sys"))); + R_ABORT_UNLESS(sm::mitm::WaitMitm(sm::ServiceName::Encode("set:sys"))); if (hos::GetVersion() >= hos::Version_200) { - R_ASSERT(sm::mitm::WaitMitm(sm::ServiceName::Encode("bpc"))); + R_ABORT_UNLESS(sm::mitm::WaitMitm(sm::ServiceName::Encode("bpc"))); } else { - R_ASSERT(sm::mitm::WaitMitm(sm::ServiceName::Encode("bpc:c"))); + R_ABORT_UNLESS(sm::mitm::WaitMitm(sm::ServiceName::Encode("bpc:c"))); } /* Launch Atmosphere boot2, using NcmStorageId_None to force SD card boot. */ diff --git a/libstratosphere/source/cfg/cfg_override.cpp b/libstratosphere/source/cfg/cfg_override.cpp index 2790d7c6..e1159b82 100644 --- a/libstratosphere/source/cfg/cfg_override.cpp +++ b/libstratosphere/source/cfg/cfg_override.cpp @@ -84,8 +84,6 @@ namespace ams::cfg { .override_any_app = true, }; - bool g_loaded_override_config = false; - char g_hbl_sd_path[0x100] = "/atmosphere/hbl.nsp"; /* Helpers. */ diff --git a/libstratosphere/source/cfg/cfg_privileged_process.cpp b/libstratosphere/source/cfg/cfg_privileged_process.cpp index 409a6ff8..87d9b378 100644 --- a/libstratosphere/source/cfg/cfg_privileged_process.cpp +++ b/libstratosphere/source/cfg/cfg_privileged_process.cpp @@ -35,12 +35,12 @@ namespace ams::cfg { os::ProcessId min = os::InvalidProcessId, max = os::InvalidProcessId; if (hos::GetVersion() >= hos::Version_500) { /* On 5.0.0+, we can get precise limits from svcGetSystemInfo. */ - R_ASSERT(svcGetSystemInfo(reinterpret_cast(&min), SystemInfoType_InitialProcessIdRange, INVALID_HANDLE, InitialProcessIdRangeInfo_Minimum)); - R_ASSERT(svcGetSystemInfo(reinterpret_cast(&max), SystemInfoType_InitialProcessIdRange, INVALID_HANDLE, InitialProcessIdRangeInfo_Maximum)); + R_ABORT_UNLESS(svcGetSystemInfo(reinterpret_cast(&min), SystemInfoType_InitialProcessIdRange, INVALID_HANDLE, InitialProcessIdRangeInfo_Minimum)); + R_ABORT_UNLESS(svcGetSystemInfo(reinterpret_cast(&max), SystemInfoType_InitialProcessIdRange, INVALID_HANDLE, InitialProcessIdRangeInfo_Maximum)); } else if (hos::GetVersion() >= hos::Version_400) { /* On 4.0.0-4.1.0, we can get the precise limits from normal svcGetInfo. */ - R_ASSERT(svcGetInfo(reinterpret_cast(&min), InfoType_InitialProcessIdRange, INVALID_HANDLE, InitialProcessIdRangeInfo_Minimum)); - R_ASSERT(svcGetInfo(reinterpret_cast(&max), InfoType_InitialProcessIdRange, INVALID_HANDLE, InitialProcessIdRangeInfo_Maximum)); + R_ABORT_UNLESS(svcGetInfo(reinterpret_cast(&min), InfoType_InitialProcessIdRange, INVALID_HANDLE, InitialProcessIdRangeInfo_Minimum)); + R_ABORT_UNLESS(svcGetInfo(reinterpret_cast(&max), InfoType_InitialProcessIdRange, INVALID_HANDLE, InitialProcessIdRangeInfo_Maximum)); } else { /* On < 4.0.0, we just use hardcoded extents. */ min = InitialProcessIdMinDeprecated; diff --git a/libstratosphere/source/cfg/cfg_sd_card.cpp b/libstratosphere/source/cfg/cfg_sd_card.cpp index d2f5f318..3c644a35 100644 --- a/libstratosphere/source/cfg/cfg_sd_card.cpp +++ b/libstratosphere/source/cfg/cfg_sd_card.cpp @@ -49,20 +49,20 @@ namespace ams::cfg { void WaitSdCardServicesReadyImpl() { for (size_t i = 0; i < NumRequiredServicesForSdCardAccess; i++) { - R_ASSERT(sm::WaitService(RequiredServicesForSdCardAccess[i])); + R_ABORT_UNLESS(sm::WaitService(RequiredServicesForSdCardAccess[i])); } } Result TryInitializeSdCard() { R_TRY(CheckSdCardServicesReady()); - R_ASSERT(fsOpenSdCardFileSystem(&g_sd_card_filesystem)); + R_ABORT_UNLESS(fsOpenSdCardFileSystem(&g_sd_card_filesystem)); g_sd_card_initialized = true; return ResultSuccess(); } void InitializeSdCard() { WaitSdCardServicesReadyImpl(); - R_ASSERT(fsOpenSdCardFileSystem(&g_sd_card_filesystem)); + R_ABORT_UNLESS(fsOpenSdCardFileSystem(&g_sd_card_filesystem)); g_sd_card_initialized = true; } diff --git a/libstratosphere/source/dd/dd_io_mappings.cpp b/libstratosphere/source/dd/dd_io_mappings.cpp index 0922346c..2095b210 100644 --- a/libstratosphere/source/dd/dd_io_mappings.cpp +++ b/libstratosphere/source/dd/dd_io_mappings.cpp @@ -34,7 +34,7 @@ namespace ams::dd { inline u32 ReadWriteRegisterImpl(uintptr_t phys_addr, u32 value, u32 mask) { u32 out_value; - R_ASSERT(svcReadWriteRegister(&out_value, phys_addr, mask, value)); + R_ABORT_UNLESS(svcReadWriteRegister(&out_value, phys_addr, mask, value)); return out_value; } diff --git a/libstratosphere/source/diag/diag_assertion_impl.cpp b/libstratosphere/source/diag/diag_assertion_impl.cpp new file mode 100644 index 00000000..33fb125c --- /dev/null +++ b/libstratosphere/source/diag/diag_assertion_impl.cpp @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include + +namespace ams { + + extern ncm::ProgramId CurrentProgramId; + +} + +namespace ams::diag { + + namespace { + + inline NORETURN void AbortWithValue(u64 debug) { + /* Just perform a data abort. */ + register u64 addr __asm__("x27") = FatalErrorContext::StdAbortMagicAddress; + register u64 val __asm__("x28") = FatalErrorContext::StdAbortMagicValue; + while (true) { + __asm__ __volatile__ ( + "mov x0, %[debug]\n" + "str %[val], [%[addr]]\n" + : + : [debug]"r"(debug), [val]"r"(val), [addr]"r"(addr) + : "x0" + ); + } + __builtin_unreachable(); + } + + ALWAYS_INLINE void DebugLog(const char *format, ...) __attribute__((format(printf, 1, 2))); + +#ifdef AMS_ENABLE_DEBUG_PRINT + os::Mutex g_debug_log_lock; + char g_debug_buffer[0x400]; + + void DebugLogImpl(const char *format, ::std::va_list vl) { + std::scoped_lock lk(g_debug_log_lock); + + std::vsnprintf(g_debug_buffer, sizeof(g_debug_buffer), format, vl); + + svc::OutputDebugString(g_debug_buffer, strlen(g_debug_buffer)); + } + + void DebugLog(const char *format, ...) __attribute__((format(printf, 1, 2))) { + ::std::va_list vl; + va_start(vl, format); + DebugLogImpl(format, vl); + va_end(vl); + } + +#else + void DebugLog(const char *format, ...) { /* ... */ } +#endif + + } + + NORETURN WEAK_SYMBOL void AssertionFailureImpl(const char *file, int line, const char *func, const char *expr, u64 value, const char *format, ...) { + DebugLog("%016lx: Assertion Failure\n", static_cast(ams::CurrentProgramId)); + DebugLog(" Location: %s:%d\n", file, line); + DebugLog(" Function: %s\n", func); + DebugLog(" Expression: %s\n", expr); + DebugLog(" Value: %016lx\n", value); + DebugLog("\n"); +#ifdef AMS_ENABLE_DEBUG_PRINT + { + ::std::va_list vl; + va_start(vl, format); + DebugLogImpl(format, vl); + va_end(vl); + } +#endif + DebugLog("\n"); + + AbortWithValue(value); + } + + NORETURN WEAK_SYMBOL void AssertionFailureImpl(const char *file, int line, const char *func, const char *expr, u64 value) { + DebugLog("%016lx: Assertion Failure\n", static_cast(ams::CurrentProgramId)); + DebugLog(" Location: %s:%d\n", file, line); + DebugLog(" Function: %s\n", func); + DebugLog(" Expression: %s\n", expr); + DebugLog(" Value: %016lx\n", value); + DebugLog("\n"); + DebugLog("\n"); + + AbortWithValue(value); + } + + NORETURN WEAK_SYMBOL void AbortImpl(const char *file, int line, const char *func, const char *expr, u64 value, const char *format, ...) { + DebugLog("%016lx: Abort Called\n", static_cast(ams::CurrentProgramId)); + DebugLog(" Location: %s:%d\n", file, line); + DebugLog(" Function: %s\n", func); + DebugLog(" Expression: %s\n", expr); + DebugLog(" Value: %016lx\n", value); + DebugLog("\n"); +#ifdef AMS_ENABLE_DEBUG_PRINT + { + ::std::va_list vl; + va_start(vl, format); + DebugLogImpl(format, vl); + va_end(vl); + } +#endif + DebugLog("\n"); + + AbortWithValue(value); + } + + NORETURN WEAK_SYMBOL void AbortImpl(const char *file, int line, const char *func, const char *expr, u64 value) { + DebugLog("%016lx: Abort Called\n", static_cast(ams::CurrentProgramId)); + DebugLog(" Location: %s:%d\n", file, line); + DebugLog(" Function: %s\n", func); + DebugLog(" Expression: %s\n", expr); + DebugLog(" Value: %016lx\n", value); + DebugLog("\n"); + DebugLog("\n"); + + AbortWithValue(value); + } + +} diff --git a/libstratosphere/source/fs/fs_path_tool.cpp b/libstratosphere/source/fs/fs_path_tool.cpp index 7167e87c..fdd64dbd 100644 --- a/libstratosphere/source/fs/fs_path_tool.cpp +++ b/libstratosphere/source/fs/fs_path_tool.cpp @@ -71,8 +71,8 @@ namespace ams::fs { if (IsCurrentDirectory(&src[i])) { skip_next_sep = true; } else if (IsParentDirectory(&src[i])) { - AMS_ASSERT(IsSeparator(out[0])); - AMS_ASSERT(IsSeparator(out[len - 1])); + AMS_ABORT_UNLESS(IsSeparator(out[0])); + AMS_ABORT_UNLESS(IsSeparator(out[len - 1])); R_UNLESS(len != 1, fs::ResultDirectoryUnobtainable()); /* Walk up a directory. */ @@ -120,7 +120,7 @@ namespace ams::fs { /* Assert normalized. */ bool normalized = false; - AMS_ASSERT(unc_preserved || (R_SUCCEEDED(IsNormalized(&normalized, out)) && normalized)); + AMS_ABORT_UNLESS(unc_preserved || (R_SUCCEEDED(IsNormalized(&normalized, out)) && normalized)); return ResultSuccess(); } @@ -216,8 +216,8 @@ namespace ams::fs { } bool PathTool::IsSubPath(const char *lhs, const char *rhs) { - AMS_ASSERT(lhs != nullptr); - AMS_ASSERT(rhs != nullptr); + AMS_ABORT_UNLESS(lhs != nullptr); + AMS_ABORT_UNLESS(rhs != nullptr); /* Special case certain paths. */ if (IsSeparator(lhs[0]) && !IsSeparator(lhs[1]) && IsSeparator(rhs[0]) && IsSeparator(rhs[1])) { diff --git a/libstratosphere/source/fssrv/fssrv_filesystem_interface_adapter.cpp b/libstratosphere/source/fssrv/fssrv_filesystem_interface_adapter.cpp index 35653c12..75b2dbd1 100644 --- a/libstratosphere/source/fssrv/fssrv_filesystem_interface_adapter.cpp +++ b/libstratosphere/source/fssrv/fssrv_filesystem_interface_adapter.cpp @@ -29,7 +29,7 @@ namespace ams::fssrv::impl { } void FileInterfaceAdapter::InvalidateCache() { - AMS_ASSERT(this->parent_filesystem->IsDeepRetryEnabled()); + AMS_ABORT_UNLESS(this->parent_filesystem->IsDeepRetryEnabled()); std::scoped_lock scoped_write_lock(this->parent_filesystem->GetReadWriteLockForCacheInvalidation()); this->base_file->OperateRange(nullptr, 0, fs::OperationId::InvalidateCache, 0, std::numeric_limits::max(), nullptr, 0); } @@ -129,7 +129,7 @@ namespace ams::fssrv::impl { bool FileSystemInterfaceAdapter::IsAccessFailureDetectionObserved() const { /* TODO: This calls into fssrv::FileSystemProxyImpl, which we don't have yet. */ - AMS_ASSERT(false); + AMS_ABORT_UNLESS(false); } std::optional> FileSystemInterfaceAdapter::AcquireCacheInvalidationReadLock() { @@ -238,7 +238,7 @@ namespace ams::fssrv::impl { std::unique_lock open_count_semaphore; if (this->open_count_limited) { /* TODO: This calls into fssrv::FileSystemProxyImpl, which we don't have yet. */ - AMS_ASSERT(false); + AMS_ABORT_UNLESS(false); } PathNormalizer normalizer(path.str); @@ -267,7 +267,7 @@ namespace ams::fssrv::impl { std::unique_lock open_count_semaphore; if (this->open_count_limited) { /* TODO: This calls into fssrv::FileSystemProxyImpl, which we don't have yet. */ - AMS_ASSERT(false); + AMS_ABORT_UNLESS(false); } PathNormalizer normalizer(path.str); diff --git a/libstratosphere/source/fssystem/fssystem_directory_redirection_filesystem.cpp b/libstratosphere/source/fssystem/fssystem_directory_redirection_filesystem.cpp index c3cb0902..45eb64a2 100644 --- a/libstratosphere/source/fssystem/fssystem_directory_redirection_filesystem.cpp +++ b/libstratosphere/source/fssystem/fssystem_directory_redirection_filesystem.cpp @@ -22,7 +22,7 @@ namespace ams::fssystem { { this->before_dir = nullptr; this->after_dir = nullptr; - R_ASSERT(this->Initialize(before, after)); + R_ABORT_UNLESS(this->Initialize(before, after)); } DirectoryRedirectionFileSystem::DirectoryRedirectionFileSystem(std::unique_ptr fs, const char *before, const char *after, bool unc) @@ -30,7 +30,7 @@ namespace ams::fssystem { { this->before_dir = nullptr; this->after_dir = nullptr; - R_ASSERT(this->Initialize(before, after)); + R_ABORT_UNLESS(this->Initialize(before, after)); } DirectoryRedirectionFileSystem::~DirectoryRedirectionFileSystem() { @@ -57,7 +57,7 @@ namespace ams::fssystem { /* Ensure terminating '/' */ if (!PathTool::IsSeparator(normalized_path[normalized_path_len - 1])) { - AMS_ASSERT(normalized_path_len + 2 <= sizeof(normalized_path)); + AMS_ABORT_UNLESS(normalized_path_len + 2 <= sizeof(normalized_path)); normalized_path[normalized_path_len] = StringTraits::DirectorySeparator; normalized_path[normalized_path_len + 1] = StringTraits::NullTerminator; @@ -67,7 +67,7 @@ namespace ams::fssystem { /* Allocate new path. */ const size_t size = normalized_path_len + 1; char *new_dir = static_cast(std::malloc(size)); - AMS_ASSERT(new_dir != nullptr); + AMS_ABORT_UNLESS(new_dir != nullptr); /* TODO: custom ResultAllocationFailure? */ /* Copy path in. */ diff --git a/libstratosphere/source/fssystem/fssystem_directory_savedata_filesystem.cpp b/libstratosphere/source/fssystem/fssystem_directory_savedata_filesystem.cpp index 34195f22..9cc3d15d 100644 --- a/libstratosphere/source/fssystem/fssystem_directory_savedata_filesystem.cpp +++ b/libstratosphere/source/fssystem/fssystem_directory_savedata_filesystem.cpp @@ -134,7 +134,7 @@ namespace ams::fssystem { /* TODO: Return a result here? Nintendo does not, but they have other allocation failed results. */ /* Consider returning ResultFsAllocationFailureInDirectorySaveDataFileSystem? */ - AMS_ASSERT(false); + AMS_ABORT_UNLESS(false); } Result DirectorySaveDataFileSystem::SynchronizeDirectory(const char *dst, const char *src) { @@ -173,7 +173,7 @@ namespace ams::fssystem { this->open_writable_files--; /* Nintendo does not check this, but I think it's sensible to do so. */ - AMS_ASSERT(this->open_writable_files >= 0); + AMS_ABORT_UNLESS(this->open_writable_files >= 0); } Result DirectorySaveDataFileSystem::CopySaveFromFileSystem(fs::fsa::IFileSystem *save_fs) { diff --git a/libstratosphere/source/fssystem/fssystem_subdirectory_filesystem.cpp b/libstratosphere/source/fssystem/fssystem_subdirectory_filesystem.cpp index cd2b3977..7ea7f723 100644 --- a/libstratosphere/source/fssystem/fssystem_subdirectory_filesystem.cpp +++ b/libstratosphere/source/fssystem/fssystem_subdirectory_filesystem.cpp @@ -21,14 +21,14 @@ namespace ams::fssystem { : PathResolutionFileSystem(fs, unc) { this->base_path = nullptr; - R_ASSERT(this->Initialize(bp)); + R_ABORT_UNLESS(this->Initialize(bp)); } SubDirectoryFileSystem::SubDirectoryFileSystem(std::unique_ptr fs, const char *bp, bool unc) : PathResolutionFileSystem(std::move(fs), unc) { this->base_path = nullptr; - R_ASSERT(this->Initialize(bp)); + R_ABORT_UNLESS(this->Initialize(bp)); } SubDirectoryFileSystem::~SubDirectoryFileSystem() { @@ -48,7 +48,7 @@ namespace ams::fssystem { /* Ensure terminating '/' */ if (!PathTool::IsSeparator(normalized_path[normalized_path_len - 1])) { - AMS_ASSERT(normalized_path_len + 2 <= sizeof(normalized_path)); + AMS_ABORT_UNLESS(normalized_path_len + 2 <= sizeof(normalized_path)); normalized_path[normalized_path_len] = StringTraits::DirectorySeparator; normalized_path[normalized_path_len + 1] = StringTraits::NullTerminator; diff --git a/libstratosphere/source/fssystem/fssystem_utility.cpp b/libstratosphere/source/fssystem/fssystem_utility.cpp index 3ad5d582..da2dde88 100644 --- a/libstratosphere/source/fssystem/fssystem_utility.cpp +++ b/libstratosphere/source/fssystem/fssystem_utility.cpp @@ -40,7 +40,7 @@ namespace ams::fssystem { char dst_path[fs::EntryNameLengthMax + 1]; const size_t original_size = static_cast(std::snprintf(dst_path, sizeof(dst_path), "%s%s", dst_parent_path, entry->name)); /* TODO: Error code? N aborts here. */ - AMS_ASSERT(original_size < sizeof(dst_path)); + AMS_ABORT_UNLESS(original_size < sizeof(dst_path)); R_TRY(dst_fs->CreateFile(dst_path, entry->file_size)); R_TRY(dst_fs->OpenFile(&dst_file, dst_path, fs::OpenMode_Write)); @@ -64,7 +64,7 @@ namespace ams::fssystem { Result CopyDirectoryRecursively(fs::fsa::IFileSystem *dst_fs, fs::fsa::IFileSystem *src_fs, const char *dst_path, const char *src_path, void *work_buf, size_t work_buf_size) { char dst_path_buf[fs::EntryNameLengthMax + 1]; const size_t original_size = static_cast(std::snprintf(dst_path_buf, sizeof(dst_path_buf), "%s", dst_path)); - AMS_ASSERT(original_size < sizeof(dst_path_buf)); + AMS_ABORT_UNLESS(original_size < sizeof(dst_path_buf)); return IterateDirectoryRecursively(src_fs, src_path, [&](const char *path, const fs::DirectoryEntry &entry) -> Result { /* On Enter Directory */ diff --git a/libstratosphere/source/hid/hid_api.cpp b/libstratosphere/source/hid/hid_api.cpp index 24bdaff3..90920292 100644 --- a/libstratosphere/source/hid/hid_api.cpp +++ b/libstratosphere/source/hid/hid_api.cpp @@ -25,10 +25,10 @@ namespace ams::hid { /* Helper. */ void InitializeHid() { - R_ASSERT(smInitialize()); + R_ABORT_UNLESS(smInitialize()); ON_SCOPE_EXIT { smExit(); }; { - R_ASSERT(hidInitialize()); + R_ABORT_UNLESS(hidInitialize()); } } diff --git a/libstratosphere/source/kvdb/kvdb_archive.cpp b/libstratosphere/source/kvdb/kvdb_archive.cpp index 8065af3b..f3f36575 100644 --- a/libstratosphere/source/kvdb/kvdb_archive.cpp +++ b/libstratosphere/source/kvdb/kvdb_archive.cpp @@ -84,7 +84,7 @@ namespace ams::kvdb { Result ArchiveReader::ReadEntryCount(size_t *out) { /* This should only be called at the start of reading stream. */ - AMS_ASSERT(this->offset == 0); + AMS_ABORT_UNLESS(this->offset == 0); /* Read and validate header. */ ArchiveHeader header; @@ -97,7 +97,7 @@ namespace ams::kvdb { Result ArchiveReader::GetEntrySize(size_t *out_key_size, size_t *out_value_size) { /* This should only be called after ReadEntryCount. */ - AMS_ASSERT(this->offset != 0); + AMS_ABORT_UNLESS(this->offset != 0); /* Peek the next entry header. */ ArchiveEntryHeader header; @@ -111,7 +111,7 @@ namespace ams::kvdb { Result ArchiveReader::ReadEntry(void *out_key, size_t key_size, void *out_value, size_t value_size) { /* This should only be called after ReadEntryCount. */ - AMS_ASSERT(this->offset != 0); + AMS_ABORT_UNLESS(this->offset != 0); /* Read the next entry header. */ ArchiveEntryHeader header; @@ -119,11 +119,11 @@ namespace ams::kvdb { R_TRY(header.Validate()); /* Key size and Value size must be correct. */ - AMS_ASSERT(key_size == header.key_size); - AMS_ASSERT(value_size == header.value_size); + AMS_ABORT_UNLESS(key_size == header.key_size); + AMS_ABORT_UNLESS(value_size == header.value_size); - R_ASSERT(this->Read(out_key, key_size)); - R_ASSERT(this->Read(out_value, value_size)); + R_ABORT_UNLESS(this->Read(out_key, key_size)); + R_ABORT_UNLESS(this->Read(out_value, value_size)); return ResultSuccess(); } @@ -140,20 +140,20 @@ namespace ams::kvdb { void ArchiveWriter::WriteHeader(size_t entry_count) { /* This should only be called at start of write. */ - AMS_ASSERT(this->offset == 0); + AMS_ABORT_UNLESS(this->offset == 0); ArchiveHeader header = ArchiveHeader::Make(entry_count); - R_ASSERT(this->Write(&header, sizeof(header))); + R_ABORT_UNLESS(this->Write(&header, sizeof(header))); } void ArchiveWriter::WriteEntry(const void *key, size_t key_size, const void *value, size_t value_size) { /* This should only be called after writing header. */ - AMS_ASSERT(this->offset != 0); + AMS_ABORT_UNLESS(this->offset != 0); ArchiveEntryHeader header = ArchiveEntryHeader::Make(key_size, value_size); - R_ASSERT(this->Write(&header, sizeof(header))); - R_ASSERT(this->Write(key, key_size)); - R_ASSERT(this->Write(value, value_size)); + R_ABORT_UNLESS(this->Write(&header, sizeof(header))); + R_ABORT_UNLESS(this->Write(key, key_size)); + R_ABORT_UNLESS(this->Write(value, value_size)); } /* Size helper functionality. */ diff --git a/libstratosphere/source/kvdb/kvdb_file_key_value_store.cpp b/libstratosphere/source/kvdb/kvdb_file_key_value_store.cpp index 5a884f94..6a980f3a 100644 --- a/libstratosphere/source/kvdb/kvdb_file_key_value_store.cpp +++ b/libstratosphere/source/kvdb/kvdb_file_key_value_store.cpp @@ -53,7 +53,7 @@ namespace ams::kvdb { this->backing_buffer_free_offset = 0; this->count = 0; this->entries = static_castentries)>(this->Allocate(sizeof(*this->entries) * this->capacity)); - AMS_ASSERT(this->entries != nullptr); + AMS_ABORT_UNLESS(this->entries != nullptr); } std::optional FileKeyValueStore::Cache::TryGet(void *out_value, size_t max_out_size, const void *key, size_t key_size) { @@ -100,7 +100,7 @@ namespace ams::kvdb { } /* Ensure key size is small enough. */ - AMS_ASSERT(key_size <= MaxKeySize); + AMS_ABORT_UNLESS(key_size <= MaxKeySize); /* If we're at capacity, invalidate the cache. */ if (this->count == this->capacity) { diff --git a/libstratosphere/source/map/map_api.cpp b/libstratosphere/source/map/map_api.cpp index 5c482c90..04b56049 100644 --- a/libstratosphere/source/map/map_api.cpp +++ b/libstratosphere/source/map/map_api.cpp @@ -73,7 +73,7 @@ namespace ams::map { R_UNLESS(cur_base != address_space.alias_end, svc::ResultOutOfMemory()); cur_base = address_space.alias_end; } else { - R_ASSERT(svcQueryMemory(&mem_info, &page_info, cur_base)); + R_ABORT_UNLESS(svcQueryMemory(&mem_info, &page_info, cur_base)); if (mem_info.type == 0 && mem_info.addr - cur_base + mem_info.size >= size) { *out_address = cur_base; return ResultSuccess(); @@ -205,9 +205,9 @@ namespace ams::map { /* Nintendo doesn't validate SVC return values at all. */ /* TODO: Should we allow these to fail? */ - R_ASSERT(svcQueryProcessMemory(&mem_info, &page_info, process_handle, address - 1)); + R_ABORT_UNLESS(svcQueryProcessMemory(&mem_info, &page_info, process_handle, address - 1)); if (mem_info.type == MemType_Unmapped && address - GuardRegionSize >= mem_info.addr) { - R_ASSERT(svcQueryProcessMemory(&mem_info, &page_info, process_handle, address + size)); + R_ABORT_UNLESS(svcQueryProcessMemory(&mem_info, &page_info, process_handle, address + size)); return mem_info.type == MemType_Unmapped && address + size + GuardRegionSize <= mem_info.addr + mem_info.size; } diff --git a/libstratosphere/source/os/impl/os_inter_process_event.cpp b/libstratosphere/source/os/impl/os_inter_process_event.cpp index 31d66487..e933a55b 100644 --- a/libstratosphere/source/os/impl/os_inter_process_event.cpp +++ b/libstratosphere/source/os/impl/os_inter_process_event.cpp @@ -31,7 +31,7 @@ namespace ams::os::impl { } InterProcessEvent::InterProcessEvent(bool autoclear) : is_initialized(false) { - R_ASSERT(this->Initialize(autoclear)); + R_ABORT_UNLESS(this->Initialize(autoclear)); } InterProcessEvent::~InterProcessEvent() { @@ -39,7 +39,7 @@ namespace ams::os::impl { } Result InterProcessEvent::Initialize(bool autoclear) { - AMS_ASSERT(!this->is_initialized); + AMS_ABORT_UNLESS(!this->is_initialized); Handle rh, wh; R_TRY(CreateEventHandles(&rh, &wh)); this->Initialize(rh, true, wh, true, autoclear); @@ -47,8 +47,8 @@ namespace ams::os::impl { } void InterProcessEvent::Initialize(Handle read_handle, bool manage_read_handle, Handle write_handle, bool manage_write_handle, bool autoclear) { - AMS_ASSERT(!this->is_initialized); - AMS_ASSERT(read_handle != INVALID_HANDLE || write_handle != INVALID_HANDLE); + AMS_ABORT_UNLESS(!this->is_initialized); + AMS_ABORT_UNLESS(read_handle != INVALID_HANDLE || write_handle != INVALID_HANDLE); this->read_handle = read_handle; this->manage_read_handle = manage_read_handle; this->write_handle = write_handle; @@ -58,40 +58,40 @@ namespace ams::os::impl { } Handle InterProcessEvent::DetachReadableHandle() { - AMS_ASSERT(this->is_initialized); + AMS_ABORT_UNLESS(this->is_initialized); const Handle handle = this->read_handle; - AMS_ASSERT(handle != INVALID_HANDLE); + AMS_ABORT_UNLESS(handle != INVALID_HANDLE); this->read_handle = INVALID_HANDLE; this->manage_read_handle = false; return handle; } Handle InterProcessEvent::DetachWritableHandle() { - AMS_ASSERT(this->is_initialized); + AMS_ABORT_UNLESS(this->is_initialized); const Handle handle = this->write_handle; - AMS_ASSERT(handle != INVALID_HANDLE); + AMS_ABORT_UNLESS(handle != INVALID_HANDLE); this->write_handle = INVALID_HANDLE; this->manage_write_handle = false; return handle; } Handle InterProcessEvent::GetReadableHandle() const { - AMS_ASSERT(this->is_initialized); + AMS_ABORT_UNLESS(this->is_initialized); return this->read_handle; } Handle InterProcessEvent::GetWritableHandle() const { - AMS_ASSERT(this->is_initialized); + AMS_ABORT_UNLESS(this->is_initialized); return this->write_handle; } void InterProcessEvent::Finalize() { if (this->is_initialized) { if (this->manage_read_handle && this->read_handle != INVALID_HANDLE) { - R_ASSERT(svcCloseHandle(this->read_handle)); + R_ABORT_UNLESS(svcCloseHandle(this->read_handle)); } if (this->manage_write_handle && this->write_handle != INVALID_HANDLE) { - R_ASSERT(svcCloseHandle(this->write_handle)); + R_ABORT_UNLESS(svcCloseHandle(this->write_handle)); } } this->read_handle = INVALID_HANDLE; @@ -102,7 +102,7 @@ namespace ams::os::impl { } void InterProcessEvent::Signal() { - R_ASSERT(svcSignalEvent(this->GetWritableHandle())); + R_ABORT_UNLESS(svcSignalEvent(this->GetWritableHandle())); } void InterProcessEvent::Reset() { @@ -110,7 +110,7 @@ namespace ams::os::impl { if (handle == INVALID_HANDLE) { handle = this->GetWritableHandle(); } - R_ASSERT(svcClearEvent(handle)); + R_ABORT_UNLESS(svcClearEvent(handle)); } void InterProcessEvent::Wait() { diff --git a/libstratosphere/source/os/impl/os_random_impl.os.horizon.cpp b/libstratosphere/source/os/impl/os_random_impl.os.horizon.cpp index fe45e2c2..2bc7544a 100644 --- a/libstratosphere/source/os/impl/os_random_impl.os.horizon.cpp +++ b/libstratosphere/source/os/impl/os_random_impl.os.horizon.cpp @@ -25,8 +25,8 @@ namespace ams::os::impl { /* Nintendo does not check the result of these invocations, but we will for safety. */ /* Nintendo uses entropy values 0, 1 to seed the public TinyMT random, and values */ /* 2, 3 to seed os::detail::RngManager's private TinyMT random. */ - R_ASSERT(svcGetInfo(reinterpret_cast(&seed[0]), InfoType_RandomEntropy, INVALID_HANDLE, 0)); - R_ASSERT(svcGetInfo(reinterpret_cast(&seed[2]), InfoType_RandomEntropy, INVALID_HANDLE, 1)); + R_ABORT_UNLESS(svcGetInfo(reinterpret_cast(&seed[0]), InfoType_RandomEntropy, INVALID_HANDLE, 0)); + R_ABORT_UNLESS(svcGetInfo(reinterpret_cast(&seed[2]), InfoType_RandomEntropy, INVALID_HANDLE, 1)); mt->Initialize(seed, util::size(seed)); } diff --git a/libstratosphere/source/os/impl/os_waitable_holder_of_inter_process_event.hpp b/libstratosphere/source/os/impl/os_waitable_holder_of_inter_process_event.hpp index 9923e422..99adfdde 100644 --- a/libstratosphere/source/os/impl/os_waitable_holder_of_inter_process_event.hpp +++ b/libstratosphere/source/os/impl/os_waitable_holder_of_inter_process_event.hpp @@ -31,7 +31,7 @@ namespace ams::os::impl { } virtual Handle GetHandle() const override { - AMS_ASSERT(this->event->is_initialized); + AMS_ABORT_UNLESS(this->event->is_initialized); return this->event->GetReadableHandle(); } }; diff --git a/libstratosphere/source/os/impl/os_waitable_holder_of_interrupt_event.hpp b/libstratosphere/source/os/impl/os_waitable_holder_of_interrupt_event.hpp index ff789c40..66ae893a 100644 --- a/libstratosphere/source/os/impl/os_waitable_holder_of_interrupt_event.hpp +++ b/libstratosphere/source/os/impl/os_waitable_holder_of_interrupt_event.hpp @@ -30,7 +30,7 @@ namespace ams::os::impl { } virtual Handle GetHandle() const override { - AMS_ASSERT(this->event->is_initialized); + AMS_ABORT_UNLESS(this->event->is_initialized); return this->event->handle.Get(); } }; diff --git a/libstratosphere/source/os/impl/os_waitable_manager_impl.cpp b/libstratosphere/source/os/impl/os_waitable_manager_impl.cpp index 2d6f0aad..5f9b73b5 100644 --- a/libstratosphere/source/os/impl/os_waitable_manager_impl.cpp +++ b/libstratosphere/source/os/impl/os_waitable_manager_impl.cpp @@ -64,7 +64,7 @@ namespace ams::os::impl{ index = WaitTimedOut; } else { index = this->WaitSynchronization(object_handles, count, min_timeout); - AMS_ASSERT(index != WaitInvalid); + AMS_ABORT_UNLESS(index != WaitInvalid); } switch (index) { @@ -115,7 +115,7 @@ namespace ams::os::impl{ for (WaitableHolderBase &holder_base : this->waitable_list) { if (Handle handle = holder_base.GetHandle(); handle != INVALID_HANDLE) { - AMS_ASSERT(count < MaximumHandleCount); + AMS_ABORT_UNLESS(count < MaximumHandleCount); out_handles[count] = handle; out_objects[count] = &holder_base; @@ -170,7 +170,7 @@ namespace ams::os::impl{ if (this->signaled_holder == nullptr) { this->signaled_holder = holder_base; - R_ASSERT(svcCancelSynchronization(this->waiting_thread_handle)); + R_ABORT_UNLESS(svcCancelSynchronization(this->waiting_thread_handle)); } } diff --git a/libstratosphere/source/os/os_interrupt_event.cpp b/libstratosphere/source/os/os_interrupt_event.cpp index faf7841c..efdee1a7 100644 --- a/libstratosphere/source/os/os_interrupt_event.cpp +++ b/libstratosphere/source/os/os_interrupt_event.cpp @@ -18,7 +18,7 @@ namespace ams::os { Result InterruptEvent::Initialize(u32 interrupt_id, bool autoclear) { - AMS_ASSERT(!this->is_initialized); + AMS_ABORT_UNLESS(!this->is_initialized); this->auto_clear = autoclear; const auto type = this->auto_clear ? svc::InterruptType_Edge : svc::InterruptType_Level; @@ -29,23 +29,23 @@ namespace ams::os { } void InterruptEvent::Finalize() { - AMS_ASSERT(this->is_initialized); - R_ASSERT(svcCloseHandle(this->handle.Move())); + AMS_ABORT_UNLESS(this->is_initialized); + R_ABORT_UNLESS(svcCloseHandle(this->handle.Move())); this->auto_clear = true; this->is_initialized = false; } InterruptEvent::InterruptEvent(u32 interrupt_id, bool autoclear) { this->is_initialized = false; - R_ASSERT(this->Initialize(interrupt_id, autoclear)); + R_ABORT_UNLESS(this->Initialize(interrupt_id, autoclear)); } void InterruptEvent::Reset() { - R_ASSERT(svcClearEvent(this->handle.Get())); + R_ABORT_UNLESS(svcClearEvent(this->handle.Get())); } void InterruptEvent::Wait() { - AMS_ASSERT(this->is_initialized); + AMS_ABORT_UNLESS(this->is_initialized); while (true) { /* Continuously wait, until success. */ @@ -65,7 +65,7 @@ namespace ams::os { } bool InterruptEvent::TryWait() { - AMS_ASSERT(this->is_initialized); + AMS_ABORT_UNLESS(this->is_initialized); if (this->auto_clear) { /* Auto-clear. Just try to reset. */ @@ -86,7 +86,7 @@ namespace ams::os { } bool InterruptEvent::TimedWait(u64 ns) { - AMS_ASSERT(this->is_initialized); + AMS_ABORT_UNLESS(this->is_initialized); TimeoutHelper timeout_helper(ns); while (true) { diff --git a/libstratosphere/source/os/os_message_queue.cpp b/libstratosphere/source/os/os_message_queue.cpp index 3dcb3e5c..9421bcca 100644 --- a/libstratosphere/source/os/os_message_queue.cpp +++ b/libstratosphere/source/os/os_message_queue.cpp @@ -29,7 +29,7 @@ namespace ams::os { void MessageQueue::SendInternal(uintptr_t data) { /* Ensure we don't corrupt the queue, but this should never happen. */ - AMS_ASSERT(this->count < this->capacity); + AMS_ABORT_UNLESS(this->count < this->capacity); /* Write data to tail of queue. */ this->buffer[(this->count++ + this->offset) % this->capacity] = data; @@ -37,7 +37,7 @@ namespace ams::os { void MessageQueue::SendNextInternal(uintptr_t data) { /* Ensure we don't corrupt the queue, but this should never happen. */ - AMS_ASSERT(this->count < this->capacity); + AMS_ABORT_UNLESS(this->count < this->capacity); /* Write data to head of queue. */ this->offset = (this->offset + this->capacity - 1) % this->capacity; @@ -47,7 +47,7 @@ namespace ams::os { uintptr_t MessageQueue::ReceiveInternal() { /* Ensure we don't corrupt the queue, but this should never happen. */ - AMS_ASSERT(this->count > 0); + AMS_ABORT_UNLESS(this->count > 0); uintptr_t data = this->buffer[this->offset]; this->offset = (this->offset + 1) % this->capacity; @@ -57,7 +57,7 @@ namespace ams::os { inline uintptr_t MessageQueue::PeekInternal() { /* Ensure we don't corrupt the queue, but this should never happen. */ - AMS_ASSERT(this->count > 0); + AMS_ABORT_UNLESS(this->count > 0); return this->buffer[this->offset]; } diff --git a/libstratosphere/source/os/os_semaphore.cpp b/libstratosphere/source/os/os_semaphore.cpp index 2c14333c..64415467 100644 --- a/libstratosphere/source/os/os_semaphore.cpp +++ b/libstratosphere/source/os/os_semaphore.cpp @@ -65,7 +65,7 @@ namespace ams::os { void Semaphore::Release() { std::scoped_lock lk(this->mutex); - AMS_ASSERT(this->count + 1 <= this->max_count); + AMS_ABORT_UNLESS(this->count + 1 <= this->max_count); this->count++; this->condvar.Signal(); @@ -75,7 +75,7 @@ namespace ams::os { void Semaphore::Release(int count) { std::scoped_lock lk(this->mutex); - AMS_ASSERT(this->count + count <= this->max_count); + AMS_ABORT_UNLESS(this->count + count <= this->max_count); this->count += count; this->condvar.Broadcast(); diff --git a/libstratosphere/source/os/os_system_event.cpp b/libstratosphere/source/os/os_system_event.cpp index f9324aee..40300196 100644 --- a/libstratosphere/source/os/os_system_event.cpp +++ b/libstratosphere/source/os/os_system_event.cpp @@ -20,9 +20,9 @@ namespace ams::os { SystemEvent::SystemEvent(bool inter_process, bool autoclear) : state(SystemEventState::Uninitialized) { if (inter_process) { - R_ASSERT(this->InitializeAsInterProcessEvent(autoclear)); + R_ABORT_UNLESS(this->InitializeAsInterProcessEvent(autoclear)); } else { - R_ASSERT(this->InitializeAsEvent(autoclear)); + R_ABORT_UNLESS(this->InitializeAsEvent(autoclear)); } } @@ -35,34 +35,34 @@ namespace ams::os { } Event &SystemEvent::GetEvent() { - AMS_ASSERT(this->state == SystemEventState::Event); + AMS_ABORT_UNLESS(this->state == SystemEventState::Event); return GetReference(this->storage_for_event); } const Event &SystemEvent::GetEvent() const { - AMS_ASSERT(this->state == SystemEventState::Event); + AMS_ABORT_UNLESS(this->state == SystemEventState::Event); return GetReference(this->storage_for_event); } impl::InterProcessEvent &SystemEvent::GetInterProcessEvent() { - AMS_ASSERT(this->state == SystemEventState::InterProcessEvent); + AMS_ABORT_UNLESS(this->state == SystemEventState::InterProcessEvent); return GetReference(this->storage_for_inter_process_event); } const impl::InterProcessEvent &SystemEvent::GetInterProcessEvent() const { - AMS_ASSERT(this->state == SystemEventState::InterProcessEvent); + AMS_ABORT_UNLESS(this->state == SystemEventState::InterProcessEvent); return GetReference(this->storage_for_inter_process_event); } Result SystemEvent::InitializeAsEvent(bool autoclear) { - AMS_ASSERT(this->state == SystemEventState::Uninitialized); + AMS_ABORT_UNLESS(this->state == SystemEventState::Uninitialized); new (GetPointer(this->storage_for_event)) Event(autoclear); this->state = SystemEventState::Event; return ResultSuccess(); } Result SystemEvent::InitializeAsInterProcessEvent(bool autoclear) { - AMS_ASSERT(this->state == SystemEventState::Uninitialized); + AMS_ABORT_UNLESS(this->state == SystemEventState::Uninitialized); new (GetPointer(this->storage_for_inter_process_event)) impl::InterProcessEvent(); this->state = SystemEventState::InterProcessEvent; @@ -77,7 +77,7 @@ namespace ams::os { } void SystemEvent::AttachHandles(Handle read_handle, bool manage_read_handle, Handle write_handle, bool manage_write_handle, bool autoclear) { - AMS_ASSERT(this->state == SystemEventState::Uninitialized); + AMS_ABORT_UNLESS(this->state == SystemEventState::Uninitialized); new (GetPointer(this->storage_for_inter_process_event)) impl::InterProcessEvent(); this->state = SystemEventState::InterProcessEvent; this->GetInterProcessEvent().Initialize(read_handle, manage_read_handle, write_handle, manage_write_handle, autoclear); @@ -92,22 +92,22 @@ namespace ams::os { } Handle SystemEvent::DetachReadableHandle() { - AMS_ASSERT(this->state == SystemEventState::InterProcessEvent); + AMS_ABORT_UNLESS(this->state == SystemEventState::InterProcessEvent); return this->GetInterProcessEvent().DetachReadableHandle(); } Handle SystemEvent::DetachWritableHandle() { - AMS_ASSERT(this->state == SystemEventState::InterProcessEvent); + AMS_ABORT_UNLESS(this->state == SystemEventState::InterProcessEvent); return this->GetInterProcessEvent().DetachWritableHandle(); } Handle SystemEvent::GetReadableHandle() const { - AMS_ASSERT(this->state == SystemEventState::InterProcessEvent); + AMS_ABORT_UNLESS(this->state == SystemEventState::InterProcessEvent); return this->GetInterProcessEvent().GetReadableHandle(); } Handle SystemEvent::GetWritableHandle() const { - AMS_ASSERT(this->state == SystemEventState::InterProcessEvent); + AMS_ABORT_UNLESS(this->state == SystemEventState::InterProcessEvent); return this->GetInterProcessEvent().GetWritableHandle(); } diff --git a/libstratosphere/source/os/os_waitable_holder.cpp b/libstratosphere/source/os/os_waitable_holder.cpp index 9de4d2ea..c986b2e8 100644 --- a/libstratosphere/source/os/os_waitable_holder.cpp +++ b/libstratosphere/source/os/os_waitable_holder.cpp @@ -20,7 +20,7 @@ namespace ams::os { WaitableHolder::WaitableHolder(Handle handle) { /* Don't allow invalid handles. */ - AMS_ASSERT(handle != INVALID_HANDLE); + AMS_ABORT_UNLESS(handle != INVALID_HANDLE); /* Initialize appropriate holder. */ new (GetPointer(this->impl_storage)) impl::WaitableHolderOfHandle(handle); @@ -98,7 +98,7 @@ namespace ams::os { auto holder_base = reinterpret_cast(GetPointer(this->impl_storage)); /* Don't allow destruction of a linked waitable holder. */ - AMS_ASSERT(!holder_base->IsLinkedToManager()); + AMS_ABORT_UNLESS(!holder_base->IsLinkedToManager()); holder_base->~WaitableHolderBase(); } @@ -107,7 +107,7 @@ namespace ams::os { auto holder_base = reinterpret_cast(GetPointer(this->impl_storage)); /* Don't allow unlinking of an unlinked holder. */ - AMS_ASSERT(holder_base->IsLinkedToManager()); + AMS_ABORT_UNLESS(holder_base->IsLinkedToManager()); holder_base->GetManager()->UnlinkWaitableHolder(*holder_base); holder_base->SetManager(nullptr); diff --git a/libstratosphere/source/os/os_waitable_manager.cpp b/libstratosphere/source/os/os_waitable_manager.cpp index 8aff8ebc..56f67fb8 100644 --- a/libstratosphere/source/os/os_waitable_manager.cpp +++ b/libstratosphere/source/os/os_waitable_manager.cpp @@ -27,7 +27,7 @@ namespace ams::os { auto &impl = GetReference(this->impl_storage); /* Don't allow destruction of a non-empty waitable holder. */ - AMS_ASSERT(impl.IsEmpty()); + AMS_ABORT_UNLESS(impl.IsEmpty()); impl.~WaitableManagerImpl(); } @@ -38,7 +38,7 @@ namespace ams::os { auto &impl = GetReference(this->impl_storage); /* Don't allow waiting on empty list. */ - AMS_ASSERT(!impl.IsEmpty()); + AMS_ABORT_UNLESS(!impl.IsEmpty()); return reinterpret_cast(impl.WaitAny()); } @@ -47,7 +47,7 @@ namespace ams::os { auto &impl = GetReference(this->impl_storage); /* Don't allow waiting on empty list. */ - AMS_ASSERT(!impl.IsEmpty()); + AMS_ABORT_UNLESS(!impl.IsEmpty()); return reinterpret_cast(impl.TryWaitAny()); } @@ -56,7 +56,7 @@ namespace ams::os { auto &impl = GetReference(this->impl_storage); /* Don't allow waiting on empty list. */ - AMS_ASSERT(!impl.IsEmpty()); + AMS_ABORT_UNLESS(!impl.IsEmpty()); return reinterpret_cast(impl.TimedWaitAny(timeout)); } @@ -67,7 +67,7 @@ namespace ams::os { auto holder_base = reinterpret_cast(GetPointer(holder->impl_storage)); /* Don't allow double-linking a holder. */ - AMS_ASSERT(!holder_base->IsLinkedToManager()); + AMS_ABORT_UNLESS(!holder_base->IsLinkedToManager()); impl.LinkWaitableHolder(*holder_base); holder_base->SetManager(&impl); diff --git a/libstratosphere/source/patcher/patcher_api.cpp b/libstratosphere/source/patcher/patcher_api.cpp index 2c22a6cb..1809b13c 100644 --- a/libstratosphere/source/patcher/patcher_api.cpp +++ b/libstratosphere/source/patcher/patcher_api.cpp @@ -92,11 +92,11 @@ namespace ams::patcher { void ApplyIpsPatch(u8 *mapped_module, size_t mapped_size, size_t protected_size, size_t offset, bool is_ips32, FILE *f_ips) { /* Validate offset/protected size. */ - AMS_ASSERT(offset <= protected_size); + AMS_ABORT_UNLESS(offset <= protected_size); u8 buffer[sizeof(Ips32TailMagic)]; while (true) { - AMS_ASSERT(fread(buffer, is_ips32 ? sizeof(Ips32TailMagic) : sizeof(IpsTailMagic), 1, f_ips) == 1); + AMS_ABORT_UNLESS(fread(buffer, is_ips32 ? sizeof(Ips32TailMagic) : sizeof(IpsTailMagic), 1, f_ips) == 1); if (IsIpsTail(is_ips32, buffer)) { break; @@ -106,18 +106,18 @@ namespace ams::patcher { u32 patch_offset = GetIpsPatchOffset(is_ips32, buffer); /* Size of patch. */ - AMS_ASSERT(fread(buffer, 2, 1, f_ips) == 1); + AMS_ABORT_UNLESS(fread(buffer, 2, 1, f_ips) == 1); u32 patch_size = GetIpsPatchSize(is_ips32, buffer); /* Check for RLE encoding. */ if (patch_size == 0) { /* Size of RLE. */ - AMS_ASSERT(fread(buffer, 2, 1, f_ips) == 1); + AMS_ABORT_UNLESS(fread(buffer, 2, 1, f_ips) == 1); u32 rle_size = (buffer[0] << 8) | (buffer[1]); /* Value for RLE. */ - AMS_ASSERT(fread(buffer, 1, 1, f_ips) == 1); + AMS_ABORT_UNLESS(fread(buffer, 1, 1, f_ips) == 1); /* Ensure we don't write to protected region. */ if (patch_offset < protected_size) { @@ -160,7 +160,7 @@ namespace ams::patcher { if (patch_offset + read_size > mapped_size) { read_size = mapped_size - patch_offset; } - AMS_ASSERT(fread(mapped_module + patch_offset, read_size, 1, f_ips) == 1); + AMS_ABORT_UNLESS(fread(mapped_module + patch_offset, read_size, 1, f_ips) == 1); if (patch_size > read_size) { fseek(f_ips, patch_size - read_size, SEEK_CUR); } diff --git a/libstratosphere/source/pm/pm_boot_mode_api.cpp b/libstratosphere/source/pm/pm_boot_mode_api.cpp index 7fdf55ac..273ef56f 100644 --- a/libstratosphere/source/pm/pm_boot_mode_api.cpp +++ b/libstratosphere/source/pm/pm_boot_mode_api.cpp @@ -21,12 +21,12 @@ namespace ams::pm::bm { /* Both functions should be weakly linked, so that they can be overridden by ams::boot2 as needed. */ BootMode WEAK_SYMBOL GetBootMode() { PmBootMode boot_mode = PmBootMode_Normal; - R_ASSERT(pmbmGetBootMode(&boot_mode)); + R_ABORT_UNLESS(pmbmGetBootMode(&boot_mode)); return static_cast(boot_mode); } void WEAK_SYMBOL SetMaintenanceBoot() { - R_ASSERT(pmbmSetMaintenanceBoot()); + R_ABORT_UNLESS(pmbmSetMaintenanceBoot()); } } diff --git a/libstratosphere/source/pm/pm_info_api.cpp b/libstratosphere/source/pm/pm_info_api.cpp index 6e62fb58..94f3da32 100644 --- a/libstratosphere/source/pm/pm_info_api.cpp +++ b/libstratosphere/source/pm/pm_info_api.cpp @@ -69,7 +69,7 @@ namespace ams::pm::info { bool HasLaunchedProgram(ncm::ProgramId program_id) { bool has_launched = false; - R_ASSERT(HasLaunchedProgram(&has_launched, program_id)); + R_ABORT_UNLESS(HasLaunchedProgram(&has_launched, program_id)); return has_launched; } diff --git a/libstratosphere/source/result/result_on_assertion.cpp b/libstratosphere/source/result/result_on_assertion.cpp index 01165359..7d7d1372 100644 --- a/libstratosphere/source/result/result_on_assertion.cpp +++ b/libstratosphere/source/result/result_on_assertion.cpp @@ -23,15 +23,38 @@ namespace ams::result { namespace ams::result::impl { - NORETURN WEAK_SYMBOL void OnResultAssertion(Result result) { - /* Assert that we should call fatal on result assertion. */ - /* If we shouldn't fatal, this will std::abort(); */ - /* If we should, we'll continue onwards. */ - AMS_ASSERT((ams::result::CallFatalOnResultAssertion)); + NORETURN WEAK_SYMBOL void OnResultAbort(const char *file, int line, const char *func, const char *expr, Result result) { + /* Assert that we should call fatal on result assertion. */ + /* If we shouldn't fatal, this will abort(); */ + /* If we should, we'll continue onwards. */ + if (!ams::result::CallFatalOnResultAssertion) { + ::ams::diag::AbortImpl(file, line, func, expr, result.GetValue(), "Result Abort: %203d-%04d", result.GetModule(), result.GetDescription()); + } - /* TODO: ams::fatal:: */ - fatalThrow(result.GetValue()); - while (true) { /* ... */ } - } + /* TODO: ams::fatal:: */ + fatalThrow(result.GetValue()); + while (true) { /* ... */ } + } + + NORETURN WEAK_SYMBOL void OnResultAbort(Result result) { + OnResultAbort("", 0, "", "", result); + } + + NORETURN WEAK_SYMBOL void OnResultAssertion(const char *file, int line, const char *func, const char *expr, Result result) { + /* Assert that we should call fatal on result assertion. */ + /* If we shouldn't fatal, this will assert(); */ + /* If we should, we'll continue onwards. */ + if (!ams::result::CallFatalOnResultAssertion) { + ::ams::diag::AssertionFailureImpl(file, line, func, expr, result.GetValue(), "Result Assertion: %203d-%04d", result.GetModule(), result.GetDescription()); + } + + /* TODO: ams::fatal:: */ + fatalThrow(result.GetValue()); + while (true) { /* ... */ } + } + + NORETURN WEAK_SYMBOL void OnResultAssertion(Result result) { + OnResultAssertion("", 0, "", "", result); + } } \ No newline at end of file diff --git a/libstratosphere/source/settings/settings_fwdbg_api.cpp b/libstratosphere/source/settings/settings_fwdbg_api.cpp index 575529b2..31e6b195 100644 --- a/libstratosphere/source/settings/settings_fwdbg_api.cpp +++ b/libstratosphere/source/settings/settings_fwdbg_api.cpp @@ -22,13 +22,13 @@ namespace ams::settings::fwdbg { size_t WEAK_SYMBOL GetSettingsItemValueSize(const char *name, const char *key) { u64 size = 0; - R_ASSERT(setsysGetSettingsItemValueSize(name, key, &size)); + R_ABORT_UNLESS(setsysGetSettingsItemValueSize(name, key, &size)); return size; } size_t WEAK_SYMBOL GetSettingsItemValue(void *dst, size_t dst_size, const char *name, const char *key) { u64 size = 0; - R_ASSERT(setsysGetSettingsItemValue(name, key, dst, dst_size, &size)); + R_ABORT_UNLESS(setsysGetSettingsItemValue(name, key, dst, dst_size, &size)); return size; } diff --git a/libstratosphere/source/sf/cmif/sf_cmif_domain_manager.cpp b/libstratosphere/source/sf/cmif/sf_cmif_domain_manager.cpp index 5be09edc..7b9d1dcf 100644 --- a/libstratosphere/source/sf/cmif/sf_cmif_domain_manager.cpp +++ b/libstratosphere/source/sf/cmif/sf_cmif_domain_manager.cpp @@ -22,7 +22,7 @@ namespace ams::sf::cmif { Entry *entry = &this->entries.front(); { std::scoped_lock lk(this->manager->entry_owner_lock); - AMS_ASSERT(entry->owner == this); + AMS_ABORT_UNLESS(entry->owner == this); entry->owner = nullptr; } entry->object.Reset(); @@ -41,7 +41,7 @@ namespace ams::sf::cmif { for (size_t i = 0; i < count; i++) { Entry *entry = this->manager->entry_manager.AllocateEntry(); R_UNLESS(entry != nullptr, sf::cmif::ResultOutOfDomainEntries()); - AMS_ASSERT(entry->owner == nullptr); + AMS_ABORT_UNLESS(entry->owner == nullptr); out_ids[i] = this->manager->entry_manager.GetId(entry); } return ResultSuccess(); @@ -54,18 +54,18 @@ namespace ams::sf::cmif { void ServerDomainManager::Domain::UnreserveIds(const DomainObjectId *ids, size_t count) { for (size_t i = 0; i < count; i++) { Entry *entry = this->manager->entry_manager.GetEntry(ids[i]); - AMS_ASSERT(entry != nullptr); - AMS_ASSERT(entry->owner == nullptr); + AMS_ABORT_UNLESS(entry != nullptr); + AMS_ABORT_UNLESS(entry->owner == nullptr); this->manager->entry_manager.FreeEntry(entry); } } void ServerDomainManager::Domain::RegisterObject(DomainObjectId id, ServiceObjectHolder &&obj) { Entry *entry = this->manager->entry_manager.GetEntry(id); - AMS_ASSERT(entry != nullptr); + AMS_ABORT_UNLESS(entry != nullptr); { std::scoped_lock lk(this->manager->entry_owner_lock); - AMS_ASSERT(entry->owner == nullptr); + AMS_ABORT_UNLESS(entry->owner == nullptr); entry->owner = this; this->entries.push_back(*entry); } @@ -135,8 +135,8 @@ namespace ams::sf::cmif { void ServerDomainManager::EntryManager::FreeEntry(Entry *entry) { std::scoped_lock lk(this->lock); - AMS_ASSERT(entry->owner == nullptr); - AMS_ASSERT(!entry->object); + AMS_ABORT_UNLESS(entry->owner == nullptr); + AMS_ABORT_UNLESS(!entry->object); this->free_list.push_front(*entry); } @@ -148,8 +148,8 @@ namespace ams::sf::cmif { const auto id = ids[i]; Entry *entry = this->GetEntry(id); if (id != InvalidDomainObjectId) { - AMS_ASSERT(entry != nullptr); - AMS_ASSERT(entry->owner == nullptr); + AMS_ABORT_UNLESS(entry != nullptr); + AMS_ABORT_UNLESS(entry->owner == nullptr); this->free_list.erase(this->free_list.iterator_to(*entry)); } } diff --git a/libstratosphere/source/sf/cmif/sf_cmif_domain_service_object.cpp b/libstratosphere/source/sf/cmif/sf_cmif_domain_service_object.cpp index d18f071f..e87d6bb8 100644 --- a/libstratosphere/source/sf/cmif/sf_cmif_domain_service_object.cpp +++ b/libstratosphere/source/sf/cmif/sf_cmif_domain_service_object.cpp @@ -132,7 +132,7 @@ namespace ams::sf::cmif { /* Write out header. */ constexpr size_t out_header_size = sizeof(CmifDomainOutHeader); const size_t impl_out_data_total_size = this->GetImplOutDataTotalSize(); - AMS_ASSERT(out_header_size + impl_out_data_total_size + sizeof(DomainObjectId) * this->GetOutObjectCount() <= raw_data.GetSize()); + AMS_ABORT_UNLESS(out_header_size + impl_out_data_total_size + sizeof(DomainObjectId) * this->GetOutObjectCount() <= raw_data.GetSize()); *reinterpret_cast(raw_data.GetPointer()) = CmifDomainOutHeader{ .num_out_objects = static_cast(this->GetOutObjectCount()), }; /* Set output raw data. */ @@ -150,7 +150,7 @@ namespace ams::sf::cmif { /* Write out header. */ constexpr size_t out_header_size = sizeof(CmifDomainOutHeader); const size_t impl_out_headers_size = this->GetImplOutHeadersSize(); - AMS_ASSERT(out_header_size + impl_out_headers_size <= raw_data.GetSize()); + AMS_ABORT_UNLESS(out_header_size + impl_out_headers_size <= raw_data.GetSize()); *reinterpret_cast(raw_data.GetPointer()) = CmifDomainOutHeader{ .num_out_objects = 0, }; /* Set output raw data. */ @@ -186,7 +186,7 @@ namespace ams::sf::cmif { } } /* TODO: Can we make this error non-fatal? It isn't for N, since they can reserve IDs earlier due to not having to worry about mitm. */ - R_ASSERT(this->domain->ReserveIds(reservations, num_unreserved_ids)); + R_ABORT_UNLESS(this->domain->ReserveIds(reservations, num_unreserved_ids)); this->domain->ReserveSpecificIds(specific_ids, num_specific_ids); } diff --git a/libstratosphere/source/sf/cmif/sf_cmif_service_dispatch.cpp b/libstratosphere/source/sf/cmif/sf_cmif_service_dispatch.cpp index 125e3123..d8f08b6f 100644 --- a/libstratosphere/source/sf/cmif/sf_cmif_service_dispatch.cpp +++ b/libstratosphere/source/sf/cmif/sf_cmif_service_dispatch.cpp @@ -46,7 +46,7 @@ namespace ams::sf::cmif { /* Forward forwardable results, otherwise ensure we can send result to user. */ R_TRY_CATCH(command_result) { R_CATCH_RETHROW(sf::impl::ResultRequestContextChanged) - R_CATCH_ALL() { AMS_ASSERT(out_header != nullptr); } + R_CATCH_ALL() { AMS_ABORT_UNLESS(out_header != nullptr); } } R_END_TRY_CATCH; /* Write output header to raw data. */ @@ -93,7 +93,7 @@ namespace ams::sf::cmif { return ctx.session->ForwardRequest(ctx); } R_CATCH_RETHROW(sf::impl::ResultRequestContextChanged) - R_CATCH_ALL() { AMS_ASSERT(out_header != nullptr); } + R_CATCH_ALL() { AMS_ABORT_UNLESS(out_header != nullptr); } } R_END_TRY_CATCH; /* Write output header to raw data. */ diff --git a/libstratosphere/source/sf/hipc/sf_hipc_api.cpp b/libstratosphere/source/sf/hipc/sf_hipc_api.cpp index cf512efa..4b109f96 100644 --- a/libstratosphere/source/sf/hipc/sf_hipc_api.cpp +++ b/libstratosphere/source/sf/hipc/sf_hipc_api.cpp @@ -22,7 +22,7 @@ namespace ams::sf::hipc { NX_INLINE Result ReceiveImpl(Handle session_handle, void *message_buf, size_t message_buf_size) { s32 unused_index; if (message_buf == armGetTls()) { - /* Consider: AMS_ASSERT(message_buf_size == TlsMessageBufferSize); */ + /* Consider: AMS_ABORT_UNLESS(message_buf_size == TlsMessageBufferSize); */ return svcReplyAndReceive(&unused_index, &session_handle, 1, INVALID_HANDLE, U64_MAX); } else { return svcReplyAndReceiveWithUserBuffer(&unused_index, message_buf, message_buf_size, &session_handle, 1, INVALID_HANDLE, U64_MAX); @@ -32,7 +32,7 @@ namespace ams::sf::hipc { NX_INLINE Result ReplyImpl(Handle session_handle, void *message_buf, size_t message_buf_size) { s32 unused_index; if (message_buf == armGetTls()) { - /* Consider: AMS_ASSERT(message_buf_size == TlsMessageBufferSize); */ + /* Consider: AMS_ABORT_UNLESS(message_buf_size == TlsMessageBufferSize); */ return svcReplyAndReceive(&unused_index, &session_handle, 0, session_handle, 0); } else { return svcReplyAndReceiveWithUserBuffer(&unused_index, message_buf, message_buf_size, &session_handle, 0, session_handle, 0); @@ -73,7 +73,7 @@ namespace ams::sf::hipc { R_CONVERT(svc::ResultSessionClosed, ResultSuccess()) } R_END_TRY_CATCH; /* ReplyImpl should *always* return an error. */ - AMS_ASSERT(false); + AMS_ABORT_UNLESS(false); } Result CreateSession(Handle *out_server_handle, Handle *out_client_handle) { diff --git a/libstratosphere/source/sf/hipc/sf_hipc_mitm_query_api.cpp b/libstratosphere/source/sf/hipc/sf_hipc_mitm_query_api.cpp index 86f8db49..8d5ae412 100644 --- a/libstratosphere/source/sf/hipc/sf_hipc_mitm_query_api.cpp +++ b/libstratosphere/source/sf/hipc/sf_hipc_mitm_query_api.cpp @@ -66,11 +66,11 @@ namespace ams::sf::hipc::impl { g_constructed_server = true; } - R_ASSERT(GetPointer(g_query_server_storage)->RegisterSession(query_handle, cmif::ServiceObjectHolder(std::make_shared(query_func)))); + R_ABORT_UNLESS(GetPointer(g_query_server_storage)->RegisterSession(query_handle, cmif::ServiceObjectHolder(std::make_shared(query_func)))); if (!g_registered_any) { - R_ASSERT(g_query_server_process_thread.Initialize(&QueryServerProcessThreadMain, GetPointer(g_query_server_storage), QueryServerProcessThreadPriority)); - R_ASSERT(g_query_server_process_thread.Start()); + R_ABORT_UNLESS(g_query_server_process_thread.Initialize(&QueryServerProcessThreadMain, GetPointer(g_query_server_storage), QueryServerProcessThreadPriority)); + R_ABORT_UNLESS(g_query_server_process_thread.Start()); g_registered_any = true; } } diff --git a/libstratosphere/source/sf/hipc/sf_hipc_server_domain_session_manager.cpp b/libstratosphere/source/sf/hipc/sf_hipc_server_domain_session_manager.cpp index 636556c0..2177bd23 100644 --- a/libstratosphere/source/sf/hipc/sf_hipc_server_domain_session_manager.cpp +++ b/libstratosphere/source/sf/hipc/sf_hipc_server_domain_session_manager.cpp @@ -40,16 +40,16 @@ namespace ams::sf::hipc { /* Create new session handles. */ Handle server_handle; - R_ASSERT(hipc::CreateSession(&server_handle, out_client_handle)); + R_ABORT_UNLESS(hipc::CreateSession(&server_handle, out_client_handle)); /* Register with manager. */ if (!is_mitm_session) { - R_ASSERT(tagged_manager->RegisterSession(server_handle, std::move(clone))); + R_ABORT_UNLESS(tagged_manager->RegisterSession(server_handle, std::move(clone))); } else { /* Clone the forward service. */ std::shared_ptr<::Service> new_forward_service = std::move(ServerSession::CreateForwardService()); - R_ASSERT(serviceClone(this->session->forward_service.get(), new_forward_service.get())); - R_ASSERT(tagged_manager->RegisterMitmSession(server_handle, std::move(clone), std::move(new_forward_service))); + R_ABORT_UNLESS(serviceClone(this->session->forward_service.get(), new_forward_service.get())); + R_ABORT_UNLESS(tagged_manager->RegisterMitmSession(server_handle, std::move(clone), std::move(new_forward_service))); } return ResultSuccess(); @@ -71,7 +71,7 @@ namespace ams::sf::hipc { if (this->is_mitm_session) { /* If we're a mitm session, we need to convert the remote session to domain. */ - AMS_ASSERT(session->forward_service->own_handle); + AMS_ABORT_UNLESS(session->forward_service->own_handle); R_TRY(serviceConvertToDomain(session->forward_service.get())); /* The object ID reservation cannot fail here, as that would cause desynchronization from target domain. */ @@ -90,8 +90,8 @@ namespace ams::sf::hipc { new_holder = cmif::ServiceObjectHolder(std::move(std::shared_ptr(domain_ptr, cmif::ServerDomainManager::DestroyDomainServiceObject))); } - AMS_ASSERT(object_id != cmif::InvalidDomainObjectId); - AMS_ASSERT(static_cast(new_holder)); + AMS_ABORT_UNLESS(object_id != cmif::InvalidDomainObjectId); + AMS_ABORT_UNLESS(static_cast(new_holder)); /* We succeeded! */ domain_guard.Cancel(); @@ -117,10 +117,10 @@ namespace ams::sf::hipc { if (!this->is_mitm_session || object_id.value != serviceGetObjectId(this->session->forward_service.get())) { /* Create new session handles. */ Handle server_handle; - R_ASSERT(hipc::CreateSession(&server_handle, out.GetHandlePointer())); + R_ABORT_UNLESS(hipc::CreateSession(&server_handle, out.GetHandlePointer())); /* Register. */ - R_ASSERT(this->manager->RegisterSession(server_handle, std::move(object))); + R_ABORT_UNLESS(this->manager->RegisterSession(server_handle, std::move(object))); } else { /* Copy from the target domain. */ Handle new_forward_target; @@ -128,12 +128,12 @@ namespace ams::sf::hipc { /* Create new session handles. */ Handle server_handle; - R_ASSERT(hipc::CreateSession(&server_handle, out.GetHandlePointer())); + R_ABORT_UNLESS(hipc::CreateSession(&server_handle, out.GetHandlePointer())); /* Register. */ std::shared_ptr<::Service> new_forward_service = std::move(ServerSession::CreateForwardService()); serviceCreate(new_forward_service.get(), new_forward_target); - R_ASSERT(this->manager->RegisterMitmSession(server_handle, std::move(object), std::move(new_forward_service))); + R_ABORT_UNLESS(this->manager->RegisterMitmSession(server_handle, std::move(object), std::move(new_forward_service))); } return ResultSuccess(); diff --git a/libstratosphere/source/sf/hipc/sf_hipc_server_manager.cpp b/libstratosphere/source/sf/hipc/sf_hipc_server_manager.cpp index ac5cda69..1c6aef2e 100644 --- a/libstratosphere/source/sf/hipc/sf_hipc_server_manager.cpp +++ b/libstratosphere/source/sf/hipc/sf_hipc_server_manager.cpp @@ -76,14 +76,14 @@ namespace ams::sf::hipc { void ServerManagerBase::AddUserWaitableHolder(os::WaitableHolder *waitable) { const auto user_data_tag = static_cast(waitable->GetUserData()); - AMS_ASSERT(user_data_tag != UserDataTag::Server); - AMS_ASSERT(user_data_tag != UserDataTag::MitmServer); - AMS_ASSERT(user_data_tag != UserDataTag::Session); + AMS_ABORT_UNLESS(user_data_tag != UserDataTag::Server); + AMS_ABORT_UNLESS(user_data_tag != UserDataTag::MitmServer); + AMS_ABORT_UNLESS(user_data_tag != UserDataTag::Session); this->RegisterToWaitList(waitable); } Result ServerManagerBase::ProcessForServer(os::WaitableHolder *holder) { - AMS_ASSERT(static_cast(holder->GetUserData()) == UserDataTag::Server); + AMS_ABORT_UNLESS(static_cast(holder->GetUserData()) == UserDataTag::Server); ServerBase *server = static_cast(holder); ON_SCOPE_EXIT { this->RegisterToWaitList(server); }; @@ -94,14 +94,14 @@ namespace ams::sf::hipc { server->CreateSessionObjectHolder(&obj, &fsrv); /* Not a mitm server, so we must have no forward service. */ - AMS_ASSERT(fsrv == nullptr); + AMS_ABORT_UNLESS(fsrv == nullptr); /* Try to accept. */ return this->AcceptSession(server->port_handle, std::move(obj)); } Result ServerManagerBase::ProcessForMitmServer(os::WaitableHolder *holder) { - AMS_ASSERT(static_cast(holder->GetUserData()) == UserDataTag::MitmServer); + AMS_ABORT_UNLESS(static_cast(holder->GetUserData()) == UserDataTag::MitmServer); ServerBase *server = static_cast(holder); ON_SCOPE_EXIT { this->RegisterToWaitList(server); }; @@ -112,20 +112,20 @@ namespace ams::sf::hipc { server->CreateSessionObjectHolder(&obj, &fsrv); /* Mitm server, so we must have forward service. */ - AMS_ASSERT(fsrv != nullptr); + AMS_ABORT_UNLESS(fsrv != nullptr); /* Try to accept. */ return this->AcceptMitmSession(server->port_handle, std::move(obj), std::move(fsrv)); } Result ServerManagerBase::ProcessForSession(os::WaitableHolder *holder) { - AMS_ASSERT(static_cast(holder->GetUserData()) == UserDataTag::Session); + AMS_ABORT_UNLESS(static_cast(holder->GetUserData()) == UserDataTag::Session); ServerSession *session = static_cast(holder); cmif::PointerAndSize tls_message(armGetTls(), hipc::TlsMessageBufferSize); const cmif::PointerAndSize &saved_message = session->saved_message; - AMS_ASSERT(tls_message.GetSize() == saved_message.GetSize()); + AMS_ABORT_UNLESS(tls_message.GetSize() == saved_message.GetSize()); if (!session->has_received) { R_TRY(this->ReceiveRequest(session, tls_message)); session->has_received = true; @@ -208,7 +208,7 @@ namespace ams::sf::hipc { if (!waitable) { return false; } - R_ASSERT(this->Process(waitable)); + R_ABORT_UNLESS(this->Process(waitable)); return true; } diff --git a/libstratosphere/source/sf/hipc/sf_hipc_server_session_manager.cpp b/libstratosphere/source/sf/hipc/sf_hipc_server_session_manager.cpp index 562f26fb..43ebb0c8 100644 --- a/libstratosphere/source/sf/hipc/sf_hipc_server_session_manager.cpp +++ b/libstratosphere/source/sf/hipc/sf_hipc_server_session_manager.cpp @@ -40,10 +40,10 @@ namespace ams::sf::hipc { } Result ServerSession::ForwardRequest(const cmif::ServiceDispatchContext &ctx) const { - AMS_ASSERT(this->IsMitmSession()); + AMS_ABORT_UNLESS(this->IsMitmSession()); /* TODO: Support non-TLS messages? */ - AMS_ASSERT(this->saved_message.GetPointer() != nullptr); - AMS_ASSERT(this->saved_message.GetSize() == TlsMessageBufferSize); + AMS_ABORT_UNLESS(this->saved_message.GetPointer() != nullptr); + AMS_ABORT_UNLESS(this->saved_message.GetSize() == TlsMessageBufferSize); /* Copy saved TLS in. */ std::memcpy(armGetTls(), this->saved_message.GetPointer(), this->saved_message.GetSize()); @@ -78,7 +78,7 @@ namespace ams::sf::hipc { void ServerSessionManager::CloseSessionImpl(ServerSession *session) { const Handle session_handle = session->session_handle; this->DestroySession(session); - R_ASSERT(svcCloseHandle(session_handle)); + R_ABORT_UNLESS(svcCloseHandle(session_handle)); } Result ServerSessionManager::RegisterSessionImpl(ServerSession *session_memory, Handle session_handle, cmif::ServiceObjectHolder &&obj) { @@ -99,7 +99,7 @@ namespace ams::sf::hipc { bool succeeded = false; ON_SCOPE_EXIT { if (!succeeded) { - R_ASSERT(svcCloseHandle(session_handle)); + R_ABORT_UNLESS(svcCloseHandle(session_handle)); } }; /* Register session. */ @@ -115,7 +115,7 @@ namespace ams::sf::hipc { session_memory->pointer_buffer = this->GetSessionPointerBuffer(session_memory); session_memory->saved_message = this->GetSessionSavedMessageBuffer(session_memory); /* Validate session pointer buffer. */ - AMS_ASSERT(session_memory->pointer_buffer.GetSize() >= session_memory->forward_service->pointer_buffer_size); + AMS_ABORT_UNLESS(session_memory->pointer_buffer.GetSize() >= session_memory->forward_service->pointer_buffer_size); session_memory->pointer_buffer = cmif::PointerAndSize(session_memory->pointer_buffer.GetAddress(), session_memory->forward_service->pointer_buffer_size); /* Register to wait list. */ this->RegisterSessionToWaitList(session_memory); @@ -129,7 +129,7 @@ namespace ams::sf::hipc { bool succeeded = false; ON_SCOPE_EXIT { if (!succeeded) { - R_ASSERT(svcCloseHandle(mitm_session_handle)); + R_ABORT_UNLESS(svcCloseHandle(mitm_session_handle)); } }; /* Register session. */ @@ -291,7 +291,7 @@ namespace ams::sf::hipc { { ON_SCOPE_EXIT { for (size_t i = 0; i < handles_to_close.num_handles; i++) { - R_ASSERT(svcCloseHandle(handles_to_close.handles[i])); + R_ABORT_UNLESS(svcCloseHandle(handles_to_close.handles[i])); } }; R_TRY(hipc::Reply(session->session_handle, out_message)); diff --git a/libstratosphere/source/sm/sm_utils.hpp b/libstratosphere/source/sm/sm_utils.hpp index a1b21d87..1db2bb6b 100644 --- a/libstratosphere/source/sm/sm_utils.hpp +++ b/libstratosphere/source/sm/sm_utils.hpp @@ -29,7 +29,7 @@ namespace ams::sm::impl { Result DoWithUserSession(F f) { std::scoped_lock lk(GetUserSessionMutex()); { - R_ASSERT(smInitialize()); + R_ABORT_UNLESS(smInitialize()); ON_SCOPE_EXIT { smExit(); }; return f(); @@ -40,7 +40,7 @@ namespace ams::sm::impl { Result DoWithMitmAcknowledgementSession(F f) { std::scoped_lock lk(GetMitmAcknowledgementSessionMutex()); { - R_ASSERT(smAtmosphereMitmInitialize()); + R_ABORT_UNLESS(smAtmosphereMitmInitialize()); ON_SCOPE_EXIT { smAtmosphereMitmExit(); }; return f(); @@ -52,7 +52,7 @@ namespace ams::sm::impl { Service srv; { std::scoped_lock lk(GetPerThreadSessionMutex()); - R_ASSERT(smAtmosphereOpenSession(&srv)); + R_ABORT_UNLESS(smAtmosphereOpenSession(&srv)); } { ON_SCOPE_EXIT { smAtmosphereCloseSession(&srv); }; diff --git a/libstratosphere/source/spl/smc/spl_smc.cpp b/libstratosphere/source/spl/smc/spl_smc.cpp index f493f8c0..232be11e 100644 --- a/libstratosphere/source/spl/smc/spl_smc.cpp +++ b/libstratosphere/source/spl/smc/spl_smc.cpp @@ -349,7 +349,7 @@ namespace ams::spl::smc { } Result AtmosphereWriteAddress(void *dst, const void *src, size_t size) { - AMS_ASSERT(size <= sizeof(u64)); + AMS_ABORT_UNLESS(size <= sizeof(u64)); SecmonArgs args; args.X[0] = static_cast(FunctionId::AtmosphereWriteAddress); @@ -363,7 +363,7 @@ namespace ams::spl::smc { Result AtmosphereGetEmummcConfig(void *out_config, void *out_paths, u32 storage_id) { const u64 paths = reinterpret_cast(out_paths); - AMS_ASSERT(util::IsAligned(paths, os::MemoryPageSize)); + AMS_ABORT_UNLESS(util::IsAligned(paths, os::MemoryPageSize)); SecmonArgs args = {}; args.X[0] = static_cast(FunctionId::AtmosphereGetEmummcConfig); diff --git a/libstratosphere/source/spl/spl_api.cpp b/libstratosphere/source/spl/spl_api.cpp index f0e8f782..cdbae034 100644 --- a/libstratosphere/source/spl/spl_api.cpp +++ b/libstratosphere/source/spl/spl_api.cpp @@ -19,13 +19,13 @@ namespace ams::spl { HardwareType GetHardwareType() { u64 out_val = 0; - R_ASSERT(splGetConfig(SplConfigItem_HardwareType, &out_val)); + R_ABORT_UNLESS(splGetConfig(SplConfigItem_HardwareType, &out_val)); return static_cast(out_val); } MemoryArrangement GetMemoryArrangement() { u64 arrange = 0; - R_ASSERT(splGetConfig(SplConfigItem_MemoryArrange, &arrange)); + R_ABORT_UNLESS(splGetConfig(SplConfigItem_MemoryArrange, &arrange)); arrange &= 0x3F; switch (arrange) { case 2: @@ -43,19 +43,19 @@ namespace ams::spl { bool IsDevelopmentHardware() { bool is_dev_hardware; - R_ASSERT(splIsDevelopment(&is_dev_hardware)); + R_ABORT_UNLESS(splIsDevelopment(&is_dev_hardware)); return is_dev_hardware; } bool IsDevelopmentFunctionEnabled() { u64 val = 0; - R_ASSERT(splGetConfig(SplConfigItem_IsDebugMode, &val)); + R_ABORT_UNLESS(splGetConfig(SplConfigItem_IsDebugMode, &val)); return val != 0; } bool IsRecoveryBoot() { u64 val = 0; - R_ASSERT(splGetConfig(SplConfigItem_IsRecoveryBoot, &val)); + R_ABORT_UNLESS(splGetConfig(SplConfigItem_IsRecoveryBoot, &val)); return val != 0; } diff --git a/libstratosphere/source/updater/updater_api.cpp b/libstratosphere/source/updater/updater_api.cpp index c355b7c6..33c41718 100644 --- a/libstratosphere/source/updater/updater_api.cpp +++ b/libstratosphere/source/updater/updater_api.cpp @@ -133,7 +133,7 @@ namespace ams::updater { Result GetBootImagePackageDataId(u64 *out_data_id, BootModeType mode, void *work_buffer, size_t work_buffer_size) { /* Ensure we can read content metas. */ constexpr size_t MaxContentMetas = 0x40; - AMS_ASSERT(work_buffer_size >= sizeof(NcmContentMetaKey) * MaxContentMetas); + AMS_ABORT_UNLESS(work_buffer_size >= sizeof(NcmContentMetaKey) * MaxContentMetas); /* Open NAND System meta database, list contents. */ NcmContentMetaDatabase meta_db; @@ -150,7 +150,7 @@ namespace ams::updater { return ResultBootImagePackageNotFound(); } - AMS_ASSERT(total_entries == written_entries); + AMS_ABORT_UNLESS(total_entries == written_entries); /* Output is sorted, return the lowest valid exfat entry. */ if (total_entries > 1) { @@ -187,7 +187,7 @@ namespace ams::updater { R_TRY_CATCH(romfsMountFromDataArchive(data_id, NcmStorageId_BuiltInSystem, GetBootImagePackageMountPath())) { R_CONVERT(fs::ResultTargetNotFound, ResultBootImagePackageNotFound()) } R_END_TRY_CATCH; - ON_SCOPE_EXIT { R_ASSERT(romfsUnmount(GetBootImagePackageMountPath())); }; + ON_SCOPE_EXIT { R_ABORT_UNLESS(romfsUnmount(GetBootImagePackageMountPath())); }; /* Read and validate hashes of boot images. */ { @@ -240,7 +240,7 @@ namespace ams::updater { R_TRY_CATCH(romfsMountFromDataArchive(data_id, NcmStorageId_BuiltInSystem, GetBootImagePackageMountPath())) { R_CONVERT(fs::ResultTargetNotFound, ResultBootImagePackageNotFound()) } R_END_TRY_CATCH; - ON_SCOPE_EXIT { R_ASSERT(romfsUnmount(GetBootImagePackageMountPath())); }; + ON_SCOPE_EXIT { R_ABORT_UNLESS(romfsUnmount(GetBootImagePackageMountPath())); }; /* Read and validate hashes of boot images. */ { @@ -308,7 +308,7 @@ namespace ams::updater { R_TRY_CATCH(romfsMountFromDataArchive(data_id, NcmStorageId_BuiltInSystem, GetBootImagePackageMountPath())) { R_CONVERT(fs::ResultTargetNotFound, ResultBootImagePackageNotFound()) } R_END_TRY_CATCH; - ON_SCOPE_EXIT { R_ASSERT(romfsUnmount(GetBootImagePackageMountPath())); }; + ON_SCOPE_EXIT { R_ABORT_UNLESS(romfsUnmount(GetBootImagePackageMountPath())); }; { Boot0Accessor boot0_accessor; @@ -363,7 +363,7 @@ namespace ams::updater { R_TRY_CATCH(romfsMountFromDataArchive(data_id, NcmStorageId_BuiltInSystem, GetBootImagePackageMountPath())) { R_CONVERT(fs::ResultTargetNotFound, ResultBootImagePackageNotFound()) } R_END_TRY_CATCH; - ON_SCOPE_EXIT { R_ASSERT(romfsUnmount(GetBootImagePackageMountPath())); }; + ON_SCOPE_EXIT { R_ABORT_UNLESS(romfsUnmount(GetBootImagePackageMountPath())); }; { Boot0Accessor boot0_accessor; @@ -509,7 +509,7 @@ namespace ams::updater { /* Get a session to ncm. */ sm::ScopedServiceHolder ncm_holder; - R_ASSERT(ncm_holder.GetResult()); + R_ABORT_UNLESS(ncm_holder.GetResult()); /* Verify normal, verify safe as needed. */ if (verification_state.needs_verify_normal) { diff --git a/libstratosphere/source/updater/updater_bis_management.cpp b/libstratosphere/source/updater/updater_bis_management.cpp index 371433c6..709396ac 100644 --- a/libstratosphere/source/updater/updater_bis_management.cpp +++ b/libstratosphere/source/updater/updater_bis_management.cpp @@ -31,18 +31,18 @@ namespace ams::updater { } Result BisAccessor::Read(void *dst, size_t size, u64 offset) { - AMS_ASSERT((offset % SectorAlignment) == 0); + AMS_ABORT_UNLESS((offset % SectorAlignment) == 0); return fsStorageRead(&this->storage, offset, dst, size); } Result BisAccessor::Write(u64 offset, const void *src, size_t size) { - AMS_ASSERT((offset % SectorAlignment) == 0); + AMS_ABORT_UNLESS((offset % SectorAlignment) == 0); return fsStorageWrite(&this->storage, offset, src, size); } Result BisAccessor::Write(u64 offset, size_t size, const char *bip_path, void *work_buffer, size_t work_buffer_size) { - AMS_ASSERT((offset % SectorAlignment) == 0); - AMS_ASSERT((work_buffer_size % SectorAlignment) == 0); + AMS_ABORT_UNLESS((offset % SectorAlignment) == 0); + AMS_ABORT_UNLESS((work_buffer_size % SectorAlignment) == 0); FILE *bip_fp = fopen(bip_path, "rb"); if (bip_fp == NULL) { @@ -59,7 +59,7 @@ namespace ams::updater { return fsdevGetLastResult(); } } - AMS_ASSERT(written + read_size <= size); + AMS_ABORT_UNLESS(written + read_size <= size); size_t aligned_size = ((read_size + SectorAlignment - 1) / SectorAlignment) * SectorAlignment; R_TRY(this->Write(offset + written, work_buffer, aligned_size)); @@ -73,8 +73,8 @@ namespace ams::updater { } Result BisAccessor::Clear(u64 offset, u64 size, void *work_buffer, size_t work_buffer_size) { - AMS_ASSERT((offset % SectorAlignment) == 0); - AMS_ASSERT((work_buffer_size % SectorAlignment) == 0); + AMS_ABORT_UNLESS((offset % SectorAlignment) == 0); + AMS_ABORT_UNLESS((work_buffer_size % SectorAlignment) == 0); std::memset(work_buffer, 0, work_buffer_size); @@ -88,8 +88,8 @@ namespace ams::updater { } Result BisAccessor::GetHash(void *dst, u64 offset, u64 size, u64 hash_size, void *work_buffer, size_t work_buffer_size) { - AMS_ASSERT((offset % SectorAlignment) == 0); - AMS_ASSERT((work_buffer_size % SectorAlignment) == 0); + AMS_ABORT_UNLESS((offset % SectorAlignment) == 0); + AMS_ABORT_UNLESS((work_buffer_size % SectorAlignment) == 0); Sha256Context sha_ctx; sha256ContextCreate(&sha_ctx); @@ -109,12 +109,12 @@ namespace ams::updater { size_t Boot0Accessor::GetBootloaderVersion(void *bct) { u32 version = *reinterpret_cast(reinterpret_cast(bct) + BctVersionOffset); - AMS_ASSERT(version <= BctVersionMax); + AMS_ABORT_UNLESS(version <= BctVersionMax); return static_cast(version); } size_t Boot0Accessor::GetEksIndex(size_t bootloader_version) { - AMS_ASSERT(bootloader_version <= BctVersionMax); + AMS_ABORT_UNLESS(bootloader_version <= BctVersionMax); return (bootloader_version > 0) ? bootloader_version - 1 : 0; } diff --git a/libstratosphere/source/updater/updater_bis_management.hpp b/libstratosphere/source/updater/updater_bis_management.hpp index 47ab53db..d0fdbd25 100644 --- a/libstratosphere/source/updater/updater_bis_management.hpp +++ b/libstratosphere/source/updater/updater_bis_management.hpp @@ -136,13 +136,13 @@ namespace ams::updater { } } - AMS_ASSERT(entry != nullptr); + AMS_ABORT_UNLESS(entry != nullptr); return entry; } public: Result Read(size_t *out_size, void *dst, size_t size, EnumType which) { const auto entry = FindEntry(which); - AMS_ASSERT(size >= entry->size); + AMS_ABORT_UNLESS(size >= entry->size); R_TRY(BisAccessor::Read(dst, entry->size, entry->offset)); @@ -152,8 +152,8 @@ namespace ams::updater { Result Write(const void *src, size_t size, EnumType which) { const auto entry = FindEntry(which); - AMS_ASSERT(size <= entry->size); - AMS_ASSERT((size % BisAccessor::SectorAlignment) == 0); + AMS_ABORT_UNLESS(size <= entry->size); + AMS_ABORT_UNLESS((size % BisAccessor::SectorAlignment) == 0); return BisAccessor::Write(entry->offset, src, size); } diff --git a/libstratosphere/source/updater/updater_bis_save.cpp b/libstratosphere/source/updater/updater_bis_save.cpp index a9bc74e2..20618f49 100644 --- a/libstratosphere/source/updater/updater_bis_save.cpp +++ b/libstratosphere/source/updater/updater_bis_save.cpp @@ -29,9 +29,9 @@ namespace ams::updater { } Result BisSave::Initialize(void *work_buffer, size_t work_buffer_size) { - AMS_ASSERT(work_buffer_size >= SaveSize); - AMS_ASSERT(util::IsAligned(reinterpret_cast(work_buffer), os::MemoryPageSize)); - AMS_ASSERT(util::IsAligned(work_buffer_size, 0x200)); + AMS_ABORT_UNLESS(work_buffer_size >= SaveSize); + AMS_ABORT_UNLESS(util::IsAligned(reinterpret_cast(work_buffer), os::MemoryPageSize)); + AMS_ABORT_UNLESS(util::IsAligned(work_buffer_size, 0x200)); R_TRY(this->accessor.Initialize()); this->save_buffer = work_buffer; diff --git a/libstratosphere/source/updater/updater_paths.cpp b/libstratosphere/source/updater/updater_paths.cpp index 98e78837..f6a436d5 100644 --- a/libstratosphere/source/updater/updater_paths.cpp +++ b/libstratosphere/source/updater/updater_paths.cpp @@ -30,7 +30,7 @@ namespace ams::updater { constexpr const char *Package2PathA = "bip:/a/package2"; const char *ChooseCandidatePath(const char * const *candidates, size_t num_candidates) { - AMS_ASSERT(num_candidates > 0); + AMS_ABORT_UNLESS(num_candidates > 0); for (size_t i = 0; i < num_candidates; i++) { struct stat buf; diff --git a/libstratosphere/source/util/util_compression.cpp b/libstratosphere/source/util/util_compression.cpp index 0037447a..217c70f1 100644 --- a/libstratosphere/source/util/util_compression.cpp +++ b/libstratosphere/source/util/util_compression.cpp @@ -21,8 +21,8 @@ namespace ams::util { /* Compression utilities. */ int CompressLZ4(void *dst, size_t dst_size, const void *src, size_t src_size) { /* Size checks. */ - AMS_ASSERT(dst_size <= std::numeric_limits::max()); - AMS_ASSERT(src_size <= std::numeric_limits::max()); + AMS_ABORT_UNLESS(dst_size <= std::numeric_limits::max()); + AMS_ABORT_UNLESS(src_size <= std::numeric_limits::max()); /* This is just a thin wrapper around LZ4. */ return LZ4_compress_default(reinterpret_cast(src), reinterpret_cast(dst), static_cast(src_size), static_cast(dst_size)); @@ -31,8 +31,8 @@ namespace ams::util { /* Decompression utilities. */ int DecompressLZ4(void *dst, size_t dst_size, const void *src, size_t src_size) { /* Size checks. */ - AMS_ASSERT(dst_size <= std::numeric_limits::max()); - AMS_ASSERT(src_size <= std::numeric_limits::max()); + AMS_ABORT_UNLESS(dst_size <= std::numeric_limits::max()); + AMS_ABORT_UNLESS(src_size <= std::numeric_limits::max()); /* This is just a thin wrapper around LZ4. */ return LZ4_decompress_safe(reinterpret_cast(src), reinterpret_cast(dst), static_cast(src_size), static_cast(dst_size)); diff --git a/libstratosphere/source/util/util_ini.cpp b/libstratosphere/source/util/util_ini.cpp index e171f7ca..ed92fd8b 100644 --- a/libstratosphere/source/util/util_ini.cpp +++ b/libstratosphere/source/util/util_ini.cpp @@ -31,7 +31,7 @@ namespace ams::util::ini { explicit FsFileContext(FsFile *f) : f(f), offset(0) { s64 size; - R_ASSERT(fsFileGetSize(this->f, &size)); + R_ABORT_UNLESS(fsFileGetSize(this->f, &size)); this->num_left = size_t(size); } }; @@ -46,8 +46,8 @@ namespace ams::util::ini { /* Read as many bytes as we can. */ size_t try_read = std::min(size_t(num - 1), ctx->num_left); size_t actually_read; - R_ASSERT(fsFileRead(ctx->f, ctx->offset, str, try_read, FsReadOption_None, &actually_read)); - AMS_ASSERT(actually_read == try_read); + R_ABORT_UNLESS(fsFileRead(ctx->f, ctx->offset, str, try_read, FsReadOption_None, &actually_read)); + AMS_ABORT_UNLESS(actually_read == try_read); /* Only "read" up to the first \n. */ size_t offset = actually_read; diff --git a/libvapours/include/vapours.hpp b/libvapours/include/vapours.hpp index c3b59686..4db67f4e 100644 --- a/libvapours/include/vapours.hpp +++ b/libvapours/include/vapours.hpp @@ -15,8 +15,8 @@ */ #pragma once -#include -#include +#include +#include #include #include diff --git a/libvapours/include/vapours/assert.hpp b/libvapours/include/vapours/assert.hpp new file mode 100644 index 00000000..b4fe1fbe --- /dev/null +++ b/libvapours/include/vapours/assert.hpp @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once +#include + +namespace ams::impl { + + template + ALWAYS_INLINE void UnusedImpl(ArgTypes... args) { + (static_cast(args), ...); + } + +} + +namespace ams::diag { + + NORETURN NOINLINE void AssertionFailureImpl(const char *file, int line, const char *func, const char *expr, u64 value, const char *format, ...) __attribute__((format(printf, 6, 7))); + NORETURN NOINLINE void AssertionFailureImpl(const char *file, int line, const char *func, const char *expr, u64 value); + + NORETURN NOINLINE void AbortImpl(const char *file, int line, const char *func, const char *expr, u64 value, const char *format, ...) __attribute__((format(printf, 6, 7))); + NORETURN NOINLINE void AbortImpl(const char *file, int line, const char *func, const char *expr, u64 value); + +} + +#define AMS_UNUSED(...) ::ams::impl::UnusedImpl(__VA_ARGS__) + +#ifdef AMS_ENABLE_DEBUG_PRINT +#define AMS_CALL_ASSERT_FAIL_IMPL(cond, ...) ::ams::diag::AssertionFailureImpl(__FILE__, __LINE__, __PRETTY_FUNCTION__, cond, 0, ## __VA_ARGS__) +#define AMS_CALL_ABORT_IMPL(cond, ...) ::ams::diag::AbortImpl(__FILE__, __LINE__, __PRETTY_FUNCTION__, cond, 0, ## __VA_ARGS__) +#else +#define AMS_CALL_ASSERT_FAIL_IMPL(cond, ...) ::ams::diag::AssertionFailureImpl("", 0, "", "", 0) +#define AMS_CALL_ABORT_IMPL(cond, ...) ::ams::diag::AbortImpl("", 0, "", "", 0) +#endif + +#ifdef AMS_ENABLE_ASSERTIONS +#define AMS_ASSERT_IMPL(expr, ...) \ + ({ \ + if (const bool __tmp_ams_assert_val = (expr); AMS_UNLIKELY(!__tmp_ams_assert_val)) { \ + AMS_CALL_ASSERT_FAIL_IMPL(#expr, ## __VA_ARGS__); \ + } \ + }) +#else +#define AMS_ASSERT_IMPL(expr, ...) AMS_UNUSED(expr, ## __VA_ARGS__) +#endif + +#define AMS_ASSERT(expr, ...) AMS_ASSERT_IMPL(expr, ## __VA_ARGS__) + +#define AMS_UNREACHABLE_DEFAULT_CASE() default: AMS_CALL_ABORT_IMPL("Unreachable default case entered") + +#ifdef AMS_BUILD_FOR_AUDITING +#define AMS_AUDIT(expr, ...) AMS_ASSERT(expr, ## __VA_ARGS__) +#else +#define AMS_AUDIT(expr, ...) AMS_UNUSED(expr, ## __VA_ARGS__) +#endif + +#define AMS_ABORT(...) AMS_CALL_ABORT_IMPL("", ## __VA_ARGS__) + +#define AMS_ABORT_UNLESS(expr, ...) \ + ({ \ + if (const bool __tmp_ams_assert_val = (expr); AMS_UNLIKELY(!__tmp_ams_assert_val)) { \ + AMS_CALL_ABORT_IMPL(#expr, ##__VA_ARGS__); \ + } \ + }) diff --git a/libvapours/include/vapours/common.hpp b/libvapours/include/vapours/common.hpp new file mode 100644 index 00000000..5bd76273 --- /dev/null +++ b/libvapours/include/vapours/common.hpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once +#include +#include + +#if 0 +#define AMS_BUILD_FOR_AUDITING +#endif + +#ifdef AMS_BUILD_FOR_AUDITING +#define AMS_BUILD_FOR_DEBUGGING +#endif + +#ifdef AMS_BUILD_FOR_DEBUGGING +#define AMS_ENABLE_ASSERTIONS +#define AMS_ENABLE_DEBUG_PRINT +#endif diff --git a/libvapours/include/vapours/crypto/crypto_memory_compare.hpp b/libvapours/include/vapours/crypto/crypto_memory_compare.hpp index e4af4798..4798f7d4 100644 --- a/libvapours/include/vapours/crypto/crypto_memory_compare.hpp +++ b/libvapours/include/vapours/crypto/crypto_memory_compare.hpp @@ -15,7 +15,8 @@ */ #pragma once -#include +#include +#include #include #ifdef ATMOSPHERE_ARCH_ARM64 @@ -30,7 +31,7 @@ namespace ams::crypto { - bool IsSameBytes(const void *lhs, const void *rhs, size_t size) { + inline bool IsSameBytes(const void *lhs, const void *rhs, size_t size) { return impl::IsSameBytes(lhs, rhs, size); } diff --git a/libvapours/include/vapours/crypto/impl/crypto_memory_compare.arch.arm64.hpp b/libvapours/include/vapours/crypto/impl/crypto_memory_compare.arch.arm64.hpp index 0e655d72..f1a1350f 100644 --- a/libvapours/include/vapours/crypto/impl/crypto_memory_compare.arch.arm64.hpp +++ b/libvapours/include/vapours/crypto/impl/crypto_memory_compare.arch.arm64.hpp @@ -20,7 +20,7 @@ namespace ams::crypto::impl { - bool IsSameBytes(const void *lhs, const void *rhs, size_t size) { + inline bool IsSameBytes(const void *lhs, const void *rhs, size_t size) { bool result; u8 xor_acc, ltmp, rtmp; size_t index; diff --git a/libvapours/include/vapours/defines.hpp b/libvapours/include/vapours/defines.hpp index b5ddcce6..d76052c4 100644 --- a/libvapours/include/vapours/defines.hpp +++ b/libvapours/include/vapours/defines.hpp @@ -18,10 +18,6 @@ /* Any broadly useful language defines should go here. */ -#define AMS_ASSERT(expr) do { if (!(expr)) { std::abort(); } } while (0) - -#define AMS_UNREACHABLE_DEFAULT_CASE() default: std::abort() - #define NON_COPYABLE(cls) \ cls(const cls&) = delete; \ cls& operator=(const cls&) = delete diff --git a/libvapours/include/vapours/literals.hpp b/libvapours/include/vapours/literals.hpp index 35a32e17..ddd22a6b 100644 --- a/libvapours/include/vapours/literals.hpp +++ b/libvapours/include/vapours/literals.hpp @@ -14,7 +14,8 @@ * along with this program. If not, see . */ #pragma once -#include +#include +#include namespace ams { inline namespace literals { diff --git a/libvapours/include/vapours/results.hpp b/libvapours/include/vapours/results.hpp index b3d6275d..3cdae3a8 100644 --- a/libvapours/include/vapours/results.hpp +++ b/libvapours/include/vapours/results.hpp @@ -15,7 +15,8 @@ */ #pragma once -#include +#include +#include #include /* Utilities. */ diff --git a/libvapours/include/vapours/results/results_common.hpp b/libvapours/include/vapours/results/results_common.hpp index 936fa6de..74517f27 100644 --- a/libvapours/include/vapours/results/results_common.hpp +++ b/libvapours/include/vapours/results/results_common.hpp @@ -15,7 +15,8 @@ */ #pragma once -#include +#include +#include namespace ams { @@ -31,7 +32,7 @@ namespace ams { static constexpr BaseType ReservedBits = 10; static_assert(ModuleBits + DescriptionBits + ReservedBits == sizeof(BaseType) * CHAR_BIT, "ModuleBits + DescriptionBits + ReservedBits == sizeof(BaseType) * CHAR_BIT"); public: - NX_CONSTEXPR BaseType MakeValue(BaseType module, BaseType description) { + static constexpr ALWAYS_INLINE BaseType MakeValue(BaseType module, BaseType description) { return (module) | (description << ModuleBits); } @@ -41,11 +42,11 @@ namespace ams { static_assert(description < (1 << DescriptionBits), "Invalid Description"); }; - NX_CONSTEXPR BaseType GetModuleFromValue(BaseType value) { + static constexpr ALWAYS_INLINE BaseType GetModuleFromValue(BaseType value) { return value & ~(~BaseType() << ModuleBits); } - NX_CONSTEXPR BaseType GetDescriptionFromValue(BaseType value) { + static constexpr ALWAYS_INLINE BaseType GetDescriptionFromValue(BaseType value) { return ((value >> ModuleBits) & ~(~BaseType() << DescriptionBits)); } }; @@ -126,13 +127,16 @@ namespace ams { namespace result::impl { - NORETURN void OnResultAssertion(Result result); + NORETURN NOINLINE void OnResultAssertion(const char *file, int line, const char *func, const char *expr, Result result); + NORETURN NOINLINE void OnResultAssertion(Result result); + NORETURN NOINLINE void OnResultAbort(const char *file, int line, const char *func, const char *expr, Result result); + NORETURN NOINLINE void OnResultAbort(Result result); } constexpr ALWAYS_INLINE Result::operator ResultSuccess() const { if (!ResultSuccess::CanAccept(*this)) { - result::impl::OnResultAssertion(*this); + result::impl::OnResultAbort(*this); } return ResultSuccess(); } @@ -149,7 +153,7 @@ namespace ams { static_assert(Value != Base::SuccessValue, "Value != Base::SuccessValue"); public: constexpr operator Result() const { return MakeResult(Value); } - constexpr operator ResultSuccess() const { OnResultAssertion(Value); } + constexpr operator ResultSuccess() const { OnResultAbort(Value); } constexpr ALWAYS_INLINE bool IsSuccess() const { return false; } constexpr ALWAYS_INLINE bool IsFailure() const { return !this->IsSuccess(); } @@ -216,18 +220,39 @@ namespace ams { /// Evaluates an expression that returns a result, and returns the result if it would fail. #define R_TRY(res_expr) \ ({ \ - const auto _tmp_r_try_rc = res_expr; \ + const auto _tmp_r_try_rc = (res_expr); \ if (R_FAILED(_tmp_r_try_rc)) { \ return _tmp_r_try_rc; \ } \ }) -/// Evaluates an expression that returns a result, and fatals the result if it would fail. +#ifdef AMS_ENABLE_DEBUG_PRINT +#define AMS_CALL_ON_RESULT_ASSERTION_IMPL(cond, val) ::ams::result::impl::OnResultAssertion(__FILE__, __LINE__, __PRETTY_FUNCTION__, cond, val) +#define AMS_CALL_ON_RESULT_ABORT_IMPL(cond, val) ::ams::result::impl::OnResultAbort(__FILE__, __LINE__, __PRETTY_FUNCTION__, cond, val) +#else +#define AMS_CALL_ON_RESULT_ASSERTION_IMPL(cond, val) ::ams::result::impl::OnResultAssertion("", 0, "", "", val) +#define AMS_CALL_ON_RESULT_ABORT_IMPL(cond, val) ::ams::result::impl::OnResultAbort("", 0, "", "", val) +#endif + +/// Evaluates an expression that returns a result, and asserts the result if it would fail. +#ifdef AMS_ENABLE_ASSERTIONS #define R_ASSERT(res_expr) \ ({ \ - const auto _tmp_r_assert_rc = res_expr; \ - if (R_FAILED(_tmp_r_assert_rc)) { \ - ::ams::result::impl::OnResultAssertion(_tmp_r_assert_rc); \ + const auto _tmp_r_assert_rc = (res_expr); \ + if (AMS_UNLIKELY(R_FAILED(_tmp_r_assert_rc))) { \ + AMS_CALL_ON_RESULT_ASSERTION_IMPL(#res_expr, _tmp_r_assert_rc); \ + } \ + }) +#else +#define R_ASSERT(res_expr) AMS_UNUSED((res_expr)); +#endif + +/// Evaluates an expression that returns a result, and aborts if the result would fail. +#define R_ABORT_UNLESS(res_expr) \ + ({ \ + const auto _tmp_r_abort_rc = (res_expr); \ + if (AMS_UNLIKELY(R_FAILED(_tmp_r_abort_rc))) { \ + AMS_CALL_ON_RESULT_ABORT_IMPL(#res_expr, _tmp_r_abort_rc); \ } \ }) @@ -244,14 +269,14 @@ namespace ams { #define R_TRY_CATCH(res_expr) \ ({ \ - const auto R_CURRENT_RESULT = res_expr; \ + const auto R_CURRENT_RESULT = (res_expr); \ if (R_FAILED(R_CURRENT_RESULT)) { \ if (false) namespace ams::result::impl { template - NX_CONSTEXPR bool AnyIncludes(Result result) { + constexpr ALWAYS_INLINE bool AnyIncludes(Result result) { return (Rs::Includes(result) || ...); } @@ -287,3 +312,11 @@ namespace ams::result::impl { } \ } \ }) + + +#define R_END_TRY_CATCH_WITH_ABORT_UNLESS \ + else { \ + R_ABORT_UNLESS(R_CURRENT_RESULT); \ + } \ + } \ + }) diff --git a/libvapours/include/vapours/svc.hpp b/libvapours/include/vapours/svc.hpp index 93d96595..b2648752 100644 --- a/libvapours/include/vapours/svc.hpp +++ b/libvapours/include/vapours/svc.hpp @@ -15,7 +15,8 @@ */ #pragma once -#include +#include +#include #include #include diff --git a/libvapours/include/vapours/svc/codegen/impl/svc_codegen_impl_common.hpp b/libvapours/include/vapours/svc/codegen/impl/svc_codegen_impl_common.hpp index 6e2bf8d7..97f6f5d2 100644 --- a/libvapours/include/vapours/svc/codegen/impl/svc_codegen_impl_common.hpp +++ b/libvapours/include/vapours/svc/codegen/impl/svc_codegen_impl_common.hpp @@ -14,6 +14,9 @@ * along with this program. If not, see . */ #pragma once +#include +#include +#include namespace ams::svc::codegen::impl { diff --git a/libvapours/include/vapours/svc/svc_common.hpp b/libvapours/include/vapours/svc/svc_common.hpp index c32d3fdd..e5e3c335 100644 --- a/libvapours/include/vapours/svc/svc_common.hpp +++ b/libvapours/include/vapours/svc/svc_common.hpp @@ -15,6 +15,8 @@ */ #pragma once +#include +#include #include namespace ams::svc { diff --git a/libvapours/include/vapours/svc/svc_tick.hpp b/libvapours/include/vapours/svc/svc_tick.hpp index bc393cff..ecdfd53b 100644 --- a/libvapours/include/vapours/svc/svc_tick.hpp +++ b/libvapours/include/vapours/svc/svc_tick.hpp @@ -15,8 +15,8 @@ */ #pragma once -#include "svc_common.hpp" -#include "svc_select_hardware_constants.hpp" +#include +#include namespace ams::svc { diff --git a/libvapours/include/vapours/timespan.hpp b/libvapours/include/vapours/timespan.hpp index dbe6a005..51d755c3 100644 --- a/libvapours/include/vapours/timespan.hpp +++ b/libvapours/include/vapours/timespan.hpp @@ -15,7 +15,8 @@ */ #pragma once -#include +#include +#include #include namespace ams { diff --git a/libvapours/include/vapours/util.hpp b/libvapours/include/vapours/util.hpp index 8cdae184..c59ea8af 100644 --- a/libvapours/include/vapours/util.hpp +++ b/libvapours/include/vapours/util.hpp @@ -15,7 +15,8 @@ */ #pragma once -#include +#include +#include #include #include diff --git a/libvapours/include/vapours/util/util_alignment.hpp b/libvapours/include/vapours/util/util_alignment.hpp index d800d94b..8c3a24e5 100644 --- a/libvapours/include/vapours/util/util_alignment.hpp +++ b/libvapours/include/vapours/util/util_alignment.hpp @@ -15,7 +15,8 @@ */ #pragma once -#include "../defines.hpp" +#include +#include namespace ams::util { diff --git a/libvapours/include/vapours/util/util_bitpack.hpp b/libvapours/include/vapours/util/util_bitpack.hpp index 844ce6a0..8c992c3f 100644 --- a/libvapours/include/vapours/util/util_bitpack.hpp +++ b/libvapours/include/vapours/util/util_bitpack.hpp @@ -15,7 +15,8 @@ */ #pragma once -#include "../defines.hpp" +#include +#include namespace ams::util { diff --git a/libvapours/include/vapours/util/util_bitset.hpp b/libvapours/include/vapours/util/util_bitset.hpp index e3f9ae73..85a6bcc5 100644 --- a/libvapours/include/vapours/util/util_bitset.hpp +++ b/libvapours/include/vapours/util/util_bitset.hpp @@ -15,7 +15,8 @@ */ #pragma once -#include "../defines.hpp" +#include +#include namespace ams::util { diff --git a/libvapours/include/vapours/util/util_bitutil.hpp b/libvapours/include/vapours/util/util_bitutil.hpp index 64e32e38..536aa072 100644 --- a/libvapours/include/vapours/util/util_bitutil.hpp +++ b/libvapours/include/vapours/util/util_bitutil.hpp @@ -15,7 +15,8 @@ */ #pragma once -#include "../defines.hpp" +#include +#include namespace ams::util { diff --git a/libvapours/include/vapours/util/util_fourcc.hpp b/libvapours/include/vapours/util/util_fourcc.hpp index efd0be8e..5b805e03 100644 --- a/libvapours/include/vapours/util/util_fourcc.hpp +++ b/libvapours/include/vapours/util/util_fourcc.hpp @@ -15,7 +15,8 @@ */ #pragma once -#include "../defines.hpp" +#include +#include namespace ams::util { diff --git a/libvapours/include/vapours/util/util_intrusive_list.hpp b/libvapours/include/vapours/util/util_intrusive_list.hpp index 771aa384..b19edb70 100644 --- a/libvapours/include/vapours/util/util_intrusive_list.hpp +++ b/libvapours/include/vapours/util/util_intrusive_list.hpp @@ -15,7 +15,9 @@ */ #pragma once -#include "util_parent_of_member.hpp" +#include +#include +#include namespace ams::util { diff --git a/libvapours/include/vapours/util/util_intrusive_red_black_tree.hpp b/libvapours/include/vapours/util/util_intrusive_red_black_tree.hpp index 8d63f198..4244f93d 100644 --- a/libvapours/include/vapours/util/util_intrusive_red_black_tree.hpp +++ b/libvapours/include/vapours/util/util_intrusive_red_black_tree.hpp @@ -16,7 +16,9 @@ #pragma once #include -#include "util_parent_of_member.hpp" +#include +#include +#include namespace ams::util { diff --git a/libvapours/include/vapours/util/util_parent_of_member.hpp b/libvapours/include/vapours/util/util_parent_of_member.hpp index 66f9b1b9..9276b061 100644 --- a/libvapours/include/vapours/util/util_parent_of_member.hpp +++ b/libvapours/include/vapours/util/util_parent_of_member.hpp @@ -15,8 +15,9 @@ */ #pragma once -#include "../defines.hpp" -#include "util_typed_storage.hpp" +#include +#include +#include namespace ams::util { diff --git a/libvapours/include/vapours/util/util_scope_guard.hpp b/libvapours/include/vapours/util/util_scope_guard.hpp index 0c8f1cbb..def2186b 100644 --- a/libvapours/include/vapours/util/util_scope_guard.hpp +++ b/libvapours/include/vapours/util/util_scope_guard.hpp @@ -16,7 +16,8 @@ /* Scope guard logic lovingly taken from Andrei Alexandrescu's "Systemic Error Handling in C++" */ #pragma once -#include "../defines.hpp" +#include +#include namespace ams::util { @@ -54,5 +55,5 @@ namespace ams::util { } -#define SCOPE_GUARD ::ams::util::impl::ScopeGuardOnExit() + [&]() ALWAYS_INLINE_LAMBDA +#define SCOPE_GUARD ::ams::util::impl::ScopeGuardOnExit() + [&]() ALWAYS_INLINE_LAMBDA #define ON_SCOPE_EXIT auto ANONYMOUS_VARIABLE(SCOPE_EXIT_STATE_) = SCOPE_GUARD diff --git a/libvapours/include/vapours/util/util_size.hpp b/libvapours/include/vapours/util/util_size.hpp index c1753bfa..e9f642b4 100644 --- a/libvapours/include/vapours/util/util_size.hpp +++ b/libvapours/include/vapours/util/util_size.hpp @@ -15,7 +15,8 @@ */ #pragma once -#include "../defines.hpp" +#include +#include namespace ams::util { diff --git a/libvapours/include/vapours/util/util_specialization_of.hpp b/libvapours/include/vapours/util/util_specialization_of.hpp index ce3454de..cf0fb6e2 100644 --- a/libvapours/include/vapours/util/util_specialization_of.hpp +++ b/libvapours/include/vapours/util/util_specialization_of.hpp @@ -15,7 +15,8 @@ */ #pragma once -#include "../defines.hpp" +#include +#include namespace ams::util { diff --git a/libvapours/include/vapours/util/util_tinymt.hpp b/libvapours/include/vapours/util/util_tinymt.hpp index 6a2c97e9..7611c9b7 100644 --- a/libvapours/include/vapours/util/util_tinymt.hpp +++ b/libvapours/include/vapours/util/util_tinymt.hpp @@ -15,7 +15,8 @@ */ #pragma once -#include +#include +#include namespace ams::util { diff --git a/libvapours/include/vapours/util/util_typed_storage.hpp b/libvapours/include/vapours/util/util_typed_storage.hpp index 4bbb16b2..de1db3f8 100644 --- a/libvapours/include/vapours/util/util_typed_storage.hpp +++ b/libvapours/include/vapours/util/util_typed_storage.hpp @@ -15,7 +15,8 @@ */ #pragma once -#include "../defines.hpp" +#include +#include namespace ams::util {