diff --git a/libraries/libmesosphere/include/mesosphere/kern_common.hpp b/libraries/libmesosphere/include/mesosphere/kern_common.hpp index db9679f6b..71f621e91 100644 --- a/libraries/libmesosphere/include/mesosphere/kern_common.hpp +++ b/libraries/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/libraries/libstratosphere/include/stratosphere/ams/ams_exosphere_api.hpp b/libraries/libstratosphere/include/stratosphere/ams/ams_exosphere_api.hpp index b4e8e548c..eb80efef4 100644 --- a/libraries/libstratosphere/include/stratosphere/ams/ams_exosphere_api.hpp +++ b/libraries/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/libraries/libstratosphere/include/stratosphere/dd/dd_io_mappings.hpp b/libraries/libstratosphere/include/stratosphere/dd/dd_io_mappings.hpp index ca2aa0051..4cd493b28 100644 --- a/libraries/libstratosphere/include/stratosphere/dd/dd_io_mappings.hpp +++ b/libraries/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/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_utility.hpp b/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_utility.hpp index 46151d93c..ce71ebc95 100644 --- a/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_utility.hpp +++ b/libraries/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/libraries/libstratosphere/include/stratosphere/kvdb/kvdb_auto_buffer.hpp b/libraries/libstratosphere/include/stratosphere/kvdb/kvdb_auto_buffer.hpp index 921589eeb..bb5378b70 100644 --- a/libraries/libstratosphere/include/stratosphere/kvdb/kvdb_auto_buffer.hpp +++ b/libraries/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/libraries/libstratosphere/include/stratosphere/kvdb/kvdb_bounded_string.hpp b/libraries/libstratosphere/include/stratosphere/kvdb/kvdb_bounded_string.hpp index 1fcb8d8c7..7d0aec0b0 100644 --- a/libraries/libstratosphere/include/stratosphere/kvdb/kvdb_bounded_string.hpp +++ b/libraries/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/libraries/libstratosphere/include/stratosphere/kvdb/kvdb_file_key_value_cache.hpp b/libraries/libstratosphere/include/stratosphere/kvdb/kvdb_file_key_value_cache.hpp index bd4ad8398..c98c25188 100644 --- a/libraries/libstratosphere/include/stratosphere/kvdb/kvdb_file_key_value_cache.hpp +++ b/libraries/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/libraries/libstratosphere/include/stratosphere/kvdb/kvdb_file_key_value_store.hpp b/libraries/libstratosphere/include/stratosphere/kvdb/kvdb_file_key_value_store.hpp index 7bf2b5fd2..e772897ec 100644 --- a/libraries/libstratosphere/include/stratosphere/kvdb/kvdb_file_key_value_store.hpp +++ b/libraries/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/libraries/libstratosphere/include/stratosphere/kvdb/kvdb_memory_key_value_store.hpp b/libraries/libstratosphere/include/stratosphere/kvdb/kvdb_memory_key_value_store.hpp index 5a6e27029..00a10dfe0 100644 --- a/libraries/libstratosphere/include/stratosphere/kvdb/kvdb_memory_key_value_store.hpp +++ b/libraries/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/libraries/libstratosphere/include/stratosphere/map/map_types.hpp b/libraries/libstratosphere/include/stratosphere/map/map_types.hpp index 32dff024a..830e887df 100644 --- a/libraries/libstratosphere/include/stratosphere/map/map_types.hpp +++ b/libraries/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/libraries/libstratosphere/include/stratosphere/os/os_common_types.hpp b/libraries/libstratosphere/include/stratosphere/os/os_common_types.hpp index 0da1423a2..e085177a1 100644 --- a/libraries/libstratosphere/include/stratosphere/os/os_common_types.hpp +++ b/libraries/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/libraries/libstratosphere/include/stratosphere/os/os_condvar.hpp b/libraries/libstratosphere/include/stratosphere/os/os_condvar.hpp index 557579168..9e31022b3 100644 --- a/libraries/libstratosphere/include/stratosphere/os/os_condvar.hpp +++ b/libraries/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/libraries/libstratosphere/include/stratosphere/os/os_managed_handle.hpp b/libraries/libstratosphere/include/stratosphere/os/os_managed_handle.hpp index b64e16614..673997578 100644 --- a/libraries/libstratosphere/include/stratosphere/os/os_managed_handle.hpp +++ b/libraries/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/libraries/libstratosphere/include/stratosphere/os/os_thread.hpp b/libraries/libstratosphere/include/stratosphere/os/os_thread.hpp index 397906f1c..4dab3d8eb 100644 --- a/libraries/libstratosphere/include/stratosphere/os/os_thread.hpp +++ b/libraries/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/libraries/libstratosphere/include/stratosphere/ro/ro_types.hpp b/libraries/libstratosphere/include/stratosphere/ro/ro_types.hpp index 7e893ac06..8119ad8a4 100644 --- a/libraries/libstratosphere/include/stratosphere/ro/ro_types.hpp +++ b/libraries/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/libraries/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_domain_manager.hpp b/libraries/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_domain_manager.hpp index c513c1fb6..4878a350a 100644 --- a/libraries/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_domain_manager.hpp +++ b/libraries/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/libraries/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_domain_service_object.hpp b/libraries/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_domain_service_object.hpp index f9da178df..34680b2fe 100644 --- a/libraries/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_domain_service_object.hpp +++ b/libraries/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/libraries/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_manager.hpp b/libraries/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_manager.hpp index 1ba56d4a4..11af973c6 100644 --- a/libraries/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_manager.hpp +++ b/libraries/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/libraries/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_session_manager.hpp b/libraries/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_session_manager.hpp index 83bfd0ba6..23278f8fa 100644 --- a/libraries/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_session_manager.hpp +++ b/libraries/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/libraries/libstratosphere/include/stratosphere/sf/impl/sf_impl_command_serialization.hpp b/libraries/libstratosphere/include/stratosphere/sf/impl/sf_impl_command_serialization.hpp index ff721afc8..1f347ca40 100644 --- a/libraries/libstratosphere/include/stratosphere/sf/impl/sf_impl_command_serialization.hpp +++ b/libraries/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/libraries/libstratosphere/include/stratosphere/sf/sf_out.hpp b/libraries/libstratosphere/include/stratosphere/sf/sf_out.hpp index 282094582..b5fb1e6f1 100644 --- a/libraries/libstratosphere/include/stratosphere/sf/sf_out.hpp +++ b/libraries/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/libraries/libstratosphere/include/stratosphere/sm/sm_scoped_holder.hpp b/libraries/libstratosphere/include/stratosphere/sm/sm_scoped_holder.hpp index 1e0502c95..a0cd09e0f 100644 --- a/libraries/libstratosphere/include/stratosphere/sm/sm_scoped_holder.hpp +++ b/libraries/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/libraries/libstratosphere/source/ams/ams_emummc_api.cpp b/libraries/libstratosphere/source/ams/ams_emummc_api.cpp index b7eba504e..df18d5b3e 100644 --- a/libraries/libstratosphere/source/ams/ams_emummc_api.cpp +++ b/libraries/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/libraries/libstratosphere/source/ams/ams_environment.cpp b/libraries/libstratosphere/source/ams/ams_environment.cpp index b4900636b..fd7fc062c 100644 --- a/libraries/libstratosphere/source/ams/ams_environment.cpp +++ b/libraries/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/libraries/libstratosphere/source/ams/ams_exosphere_api.cpp b/libraries/libstratosphere/source/ams/ams_exosphere_api.cpp index 1e77bb4fe..18f6a69ae 100644 --- a/libraries/libstratosphere/source/ams/ams_exosphere_api.cpp +++ b/libraries/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/libraries/libstratosphere/source/boot2/boot2_api.cpp b/libraries/libstratosphere/source/boot2/boot2_api.cpp index dd287c1b4..14a594772 100644 --- a/libraries/libstratosphere/source/boot2/boot2_api.cpp +++ b/libraries/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/libraries/libstratosphere/source/cfg/cfg_override.cpp b/libraries/libstratosphere/source/cfg/cfg_override.cpp index 2790d7c60..e1159b82c 100644 --- a/libraries/libstratosphere/source/cfg/cfg_override.cpp +++ b/libraries/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/libraries/libstratosphere/source/cfg/cfg_privileged_process.cpp b/libraries/libstratosphere/source/cfg/cfg_privileged_process.cpp index 409a6ff86..87d9b378e 100644 --- a/libraries/libstratosphere/source/cfg/cfg_privileged_process.cpp +++ b/libraries/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/libraries/libstratosphere/source/cfg/cfg_sd_card.cpp b/libraries/libstratosphere/source/cfg/cfg_sd_card.cpp index d2f5f3189..3c644a351 100644 --- a/libraries/libstratosphere/source/cfg/cfg_sd_card.cpp +++ b/libraries/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/libraries/libstratosphere/source/dd/dd_io_mappings.cpp b/libraries/libstratosphere/source/dd/dd_io_mappings.cpp index 0922346cd..2095b2101 100644 --- a/libraries/libstratosphere/source/dd/dd_io_mappings.cpp +++ b/libraries/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/libraries/libstratosphere/source/diag/diag_assertion_impl.cpp b/libraries/libstratosphere/source/diag/diag_assertion_impl.cpp new file mode 100644 index 000000000..33fb125c8 --- /dev/null +++ b/libraries/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/libraries/libstratosphere/source/fs/fs_path_tool.cpp b/libraries/libstratosphere/source/fs/fs_path_tool.cpp index 7167e87c6..fdd64dbdc 100644 --- a/libraries/libstratosphere/source/fs/fs_path_tool.cpp +++ b/libraries/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/libraries/libstratosphere/source/fssrv/fssrv_filesystem_interface_adapter.cpp b/libraries/libstratosphere/source/fssrv/fssrv_filesystem_interface_adapter.cpp index 35653c124..75b2dbd15 100644 --- a/libraries/libstratosphere/source/fssrv/fssrv_filesystem_interface_adapter.cpp +++ b/libraries/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/libraries/libstratosphere/source/fssystem/fssystem_directory_redirection_filesystem.cpp b/libraries/libstratosphere/source/fssystem/fssystem_directory_redirection_filesystem.cpp index c3cb0902b..45eb64a2e 100644 --- a/libraries/libstratosphere/source/fssystem/fssystem_directory_redirection_filesystem.cpp +++ b/libraries/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/libraries/libstratosphere/source/fssystem/fssystem_directory_savedata_filesystem.cpp b/libraries/libstratosphere/source/fssystem/fssystem_directory_savedata_filesystem.cpp index 34195f227..9cc3d15db 100644 --- a/libraries/libstratosphere/source/fssystem/fssystem_directory_savedata_filesystem.cpp +++ b/libraries/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/libraries/libstratosphere/source/fssystem/fssystem_subdirectory_filesystem.cpp b/libraries/libstratosphere/source/fssystem/fssystem_subdirectory_filesystem.cpp index cd2b39777..7ea7f723d 100644 --- a/libraries/libstratosphere/source/fssystem/fssystem_subdirectory_filesystem.cpp +++ b/libraries/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/libraries/libstratosphere/source/fssystem/fssystem_utility.cpp b/libraries/libstratosphere/source/fssystem/fssystem_utility.cpp index 3ad5d5827..da2dde88a 100644 --- a/libraries/libstratosphere/source/fssystem/fssystem_utility.cpp +++ b/libraries/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/libraries/libstratosphere/source/hid/hid_api.cpp b/libraries/libstratosphere/source/hid/hid_api.cpp index 24bdaff35..909202928 100644 --- a/libraries/libstratosphere/source/hid/hid_api.cpp +++ b/libraries/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/libraries/libstratosphere/source/kvdb/kvdb_archive.cpp b/libraries/libstratosphere/source/kvdb/kvdb_archive.cpp index 8065af3bc..f3f365752 100644 --- a/libraries/libstratosphere/source/kvdb/kvdb_archive.cpp +++ b/libraries/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/libraries/libstratosphere/source/kvdb/kvdb_file_key_value_store.cpp b/libraries/libstratosphere/source/kvdb/kvdb_file_key_value_store.cpp index 5a884f94d..6a980f3ad 100644 --- a/libraries/libstratosphere/source/kvdb/kvdb_file_key_value_store.cpp +++ b/libraries/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/libraries/libstratosphere/source/map/map_api.cpp b/libraries/libstratosphere/source/map/map_api.cpp index 5c482c903..04b560492 100644 --- a/libraries/libstratosphere/source/map/map_api.cpp +++ b/libraries/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/libraries/libstratosphere/source/os/impl/os_inter_process_event.cpp b/libraries/libstratosphere/source/os/impl/os_inter_process_event.cpp index 31d66487e..e933a55bd 100644 --- a/libraries/libstratosphere/source/os/impl/os_inter_process_event.cpp +++ b/libraries/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/libraries/libstratosphere/source/os/impl/os_random_impl.os.horizon.cpp b/libraries/libstratosphere/source/os/impl/os_random_impl.os.horizon.cpp index fe45e2c22..2bc7544a8 100644 --- a/libraries/libstratosphere/source/os/impl/os_random_impl.os.horizon.cpp +++ b/libraries/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/libraries/libstratosphere/source/os/impl/os_waitable_holder_of_inter_process_event.hpp b/libraries/libstratosphere/source/os/impl/os_waitable_holder_of_inter_process_event.hpp index 9923e422c..99adfdde1 100644 --- a/libraries/libstratosphere/source/os/impl/os_waitable_holder_of_inter_process_event.hpp +++ b/libraries/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/libraries/libstratosphere/source/os/impl/os_waitable_holder_of_interrupt_event.hpp b/libraries/libstratosphere/source/os/impl/os_waitable_holder_of_interrupt_event.hpp index ff789c40b..66ae893af 100644 --- a/libraries/libstratosphere/source/os/impl/os_waitable_holder_of_interrupt_event.hpp +++ b/libraries/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/libraries/libstratosphere/source/os/impl/os_waitable_manager_impl.cpp b/libraries/libstratosphere/source/os/impl/os_waitable_manager_impl.cpp index 2d6f0aad6..5f9b73b5e 100644 --- a/libraries/libstratosphere/source/os/impl/os_waitable_manager_impl.cpp +++ b/libraries/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/libraries/libstratosphere/source/os/os_interrupt_event.cpp b/libraries/libstratosphere/source/os/os_interrupt_event.cpp index faf7841ce..efdee1a75 100644 --- a/libraries/libstratosphere/source/os/os_interrupt_event.cpp +++ b/libraries/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/libraries/libstratosphere/source/os/os_message_queue.cpp b/libraries/libstratosphere/source/os/os_message_queue.cpp index 3dcb3e5c3..9421bccac 100644 --- a/libraries/libstratosphere/source/os/os_message_queue.cpp +++ b/libraries/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/libraries/libstratosphere/source/os/os_semaphore.cpp b/libraries/libstratosphere/source/os/os_semaphore.cpp index 2c14333cc..64415467d 100644 --- a/libraries/libstratosphere/source/os/os_semaphore.cpp +++ b/libraries/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/libraries/libstratosphere/source/os/os_system_event.cpp b/libraries/libstratosphere/source/os/os_system_event.cpp index f9324aeea..403001960 100644 --- a/libraries/libstratosphere/source/os/os_system_event.cpp +++ b/libraries/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/libraries/libstratosphere/source/os/os_waitable_holder.cpp b/libraries/libstratosphere/source/os/os_waitable_holder.cpp index 9de4d2ea6..c986b2e89 100644 --- a/libraries/libstratosphere/source/os/os_waitable_holder.cpp +++ b/libraries/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/libraries/libstratosphere/source/os/os_waitable_manager.cpp b/libraries/libstratosphere/source/os/os_waitable_manager.cpp index 8aff8ebc2..56f67fb84 100644 --- a/libraries/libstratosphere/source/os/os_waitable_manager.cpp +++ b/libraries/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/libraries/libstratosphere/source/patcher/patcher_api.cpp b/libraries/libstratosphere/source/patcher/patcher_api.cpp index 2c22a6cba..1809b13c0 100644 --- a/libraries/libstratosphere/source/patcher/patcher_api.cpp +++ b/libraries/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/libraries/libstratosphere/source/pm/pm_boot_mode_api.cpp b/libraries/libstratosphere/source/pm/pm_boot_mode_api.cpp index 7fdf55acf..273ef56f2 100644 --- a/libraries/libstratosphere/source/pm/pm_boot_mode_api.cpp +++ b/libraries/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/libraries/libstratosphere/source/pm/pm_info_api.cpp b/libraries/libstratosphere/source/pm/pm_info_api.cpp index 6e62fb581..94f3da321 100644 --- a/libraries/libstratosphere/source/pm/pm_info_api.cpp +++ b/libraries/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/libraries/libstratosphere/source/result/result_on_assertion.cpp b/libraries/libstratosphere/source/result/result_on_assertion.cpp index 01165359d..7d7d13724 100644 --- a/libraries/libstratosphere/source/result/result_on_assertion.cpp +++ b/libraries/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/libraries/libstratosphere/source/settings/settings_fwdbg_api.cpp b/libraries/libstratosphere/source/settings/settings_fwdbg_api.cpp index 575529b2d..31e6b1951 100644 --- a/libraries/libstratosphere/source/settings/settings_fwdbg_api.cpp +++ b/libraries/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/libraries/libstratosphere/source/sf/cmif/sf_cmif_domain_manager.cpp b/libraries/libstratosphere/source/sf/cmif/sf_cmif_domain_manager.cpp index 5be09edcb..7b9d1dcfc 100644 --- a/libraries/libstratosphere/source/sf/cmif/sf_cmif_domain_manager.cpp +++ b/libraries/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/libraries/libstratosphere/source/sf/cmif/sf_cmif_domain_service_object.cpp b/libraries/libstratosphere/source/sf/cmif/sf_cmif_domain_service_object.cpp index d18f071f6..e87d6bb8f 100644 --- a/libraries/libstratosphere/source/sf/cmif/sf_cmif_domain_service_object.cpp +++ b/libraries/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/libraries/libstratosphere/source/sf/cmif/sf_cmif_service_dispatch.cpp b/libraries/libstratosphere/source/sf/cmif/sf_cmif_service_dispatch.cpp index 125e31233..d8f08b6fb 100644 --- a/libraries/libstratosphere/source/sf/cmif/sf_cmif_service_dispatch.cpp +++ b/libraries/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/libraries/libstratosphere/source/sf/hipc/sf_hipc_api.cpp b/libraries/libstratosphere/source/sf/hipc/sf_hipc_api.cpp index cf512efa9..4b109f96f 100644 --- a/libraries/libstratosphere/source/sf/hipc/sf_hipc_api.cpp +++ b/libraries/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/libraries/libstratosphere/source/sf/hipc/sf_hipc_mitm_query_api.cpp b/libraries/libstratosphere/source/sf/hipc/sf_hipc_mitm_query_api.cpp index 86f8db496..8d5ae412c 100644 --- a/libraries/libstratosphere/source/sf/hipc/sf_hipc_mitm_query_api.cpp +++ b/libraries/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/libraries/libstratosphere/source/sf/hipc/sf_hipc_server_domain_session_manager.cpp b/libraries/libstratosphere/source/sf/hipc/sf_hipc_server_domain_session_manager.cpp index 636556c0b..2177bd237 100644 --- a/libraries/libstratosphere/source/sf/hipc/sf_hipc_server_domain_session_manager.cpp +++ b/libraries/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/libraries/libstratosphere/source/sf/hipc/sf_hipc_server_manager.cpp b/libraries/libstratosphere/source/sf/hipc/sf_hipc_server_manager.cpp index ac5cda691..1c6aef2e2 100644 --- a/libraries/libstratosphere/source/sf/hipc/sf_hipc_server_manager.cpp +++ b/libraries/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/libraries/libstratosphere/source/sf/hipc/sf_hipc_server_session_manager.cpp b/libraries/libstratosphere/source/sf/hipc/sf_hipc_server_session_manager.cpp index 562f26fbc..43ebb0c88 100644 --- a/libraries/libstratosphere/source/sf/hipc/sf_hipc_server_session_manager.cpp +++ b/libraries/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/libraries/libstratosphere/source/sm/sm_utils.hpp b/libraries/libstratosphere/source/sm/sm_utils.hpp index a1b21d877..1db2bb6b4 100644 --- a/libraries/libstratosphere/source/sm/sm_utils.hpp +++ b/libraries/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/libraries/libstratosphere/source/spl/smc/spl_smc.cpp b/libraries/libstratosphere/source/spl/smc/spl_smc.cpp index f493f8c00..232be11e8 100644 --- a/libraries/libstratosphere/source/spl/smc/spl_smc.cpp +++ b/libraries/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/libraries/libstratosphere/source/spl/spl_api.cpp b/libraries/libstratosphere/source/spl/spl_api.cpp index f0e8f782d..cdbae0343 100644 --- a/libraries/libstratosphere/source/spl/spl_api.cpp +++ b/libraries/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/libraries/libstratosphere/source/updater/updater_api.cpp b/libraries/libstratosphere/source/updater/updater_api.cpp index c355b7c66..33c417188 100644 --- a/libraries/libstratosphere/source/updater/updater_api.cpp +++ b/libraries/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/libraries/libstratosphere/source/updater/updater_bis_management.cpp b/libraries/libstratosphere/source/updater/updater_bis_management.cpp index 371433c6e..709396aca 100644 --- a/libraries/libstratosphere/source/updater/updater_bis_management.cpp +++ b/libraries/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/libraries/libstratosphere/source/updater/updater_bis_management.hpp b/libraries/libstratosphere/source/updater/updater_bis_management.hpp index 47ab53db2..d0fdbd25d 100644 --- a/libraries/libstratosphere/source/updater/updater_bis_management.hpp +++ b/libraries/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/libraries/libstratosphere/source/updater/updater_bis_save.cpp b/libraries/libstratosphere/source/updater/updater_bis_save.cpp index a9bc74e22..20618f49e 100644 --- a/libraries/libstratosphere/source/updater/updater_bis_save.cpp +++ b/libraries/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/libraries/libstratosphere/source/updater/updater_paths.cpp b/libraries/libstratosphere/source/updater/updater_paths.cpp index 98e78837b..f6a436d5d 100644 --- a/libraries/libstratosphere/source/updater/updater_paths.cpp +++ b/libraries/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/libraries/libstratosphere/source/util/util_compression.cpp b/libraries/libstratosphere/source/util/util_compression.cpp index 0037447a2..217c70f1b 100644 --- a/libraries/libstratosphere/source/util/util_compression.cpp +++ b/libraries/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/libraries/libstratosphere/source/util/util_ini.cpp b/libraries/libstratosphere/source/util/util_ini.cpp index e171f7cad..ed92fd8bc 100644 --- a/libraries/libstratosphere/source/util/util_ini.cpp +++ b/libraries/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/libraries/libvapours/include/vapours.hpp b/libraries/libvapours/include/vapours.hpp index c3b59686c..4db67f4e8 100644 --- a/libraries/libvapours/include/vapours.hpp +++ b/libraries/libvapours/include/vapours.hpp @@ -15,8 +15,8 @@ */ #pragma once -#include -#include +#include +#include #include #include diff --git a/libraries/libvapours/include/vapours/assert.hpp b/libraries/libvapours/include/vapours/assert.hpp new file mode 100644 index 000000000..b4fe1fbee --- /dev/null +++ b/libraries/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/libraries/libvapours/include/vapours/common.hpp b/libraries/libvapours/include/vapours/common.hpp new file mode 100644 index 000000000..5bd762731 --- /dev/null +++ b/libraries/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/libraries/libvapours/include/vapours/crypto/crypto_memory_compare.hpp b/libraries/libvapours/include/vapours/crypto/crypto_memory_compare.hpp index e4af47985..4798f7d4f 100644 --- a/libraries/libvapours/include/vapours/crypto/crypto_memory_compare.hpp +++ b/libraries/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/libraries/libvapours/include/vapours/crypto/impl/crypto_memory_compare.arch.arm64.hpp b/libraries/libvapours/include/vapours/crypto/impl/crypto_memory_compare.arch.arm64.hpp index 0e655d722..f1a1350f7 100644 --- a/libraries/libvapours/include/vapours/crypto/impl/crypto_memory_compare.arch.arm64.hpp +++ b/libraries/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/libraries/libvapours/include/vapours/defines.hpp b/libraries/libvapours/include/vapours/defines.hpp index b5ddcce6b..d76052c43 100644 --- a/libraries/libvapours/include/vapours/defines.hpp +++ b/libraries/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/libraries/libvapours/include/vapours/literals.hpp b/libraries/libvapours/include/vapours/literals.hpp index 35a32e17f..ddd22a6b6 100644 --- a/libraries/libvapours/include/vapours/literals.hpp +++ b/libraries/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/libraries/libvapours/include/vapours/results.hpp b/libraries/libvapours/include/vapours/results.hpp index b3d6275d0..3cdae3a8d 100644 --- a/libraries/libvapours/include/vapours/results.hpp +++ b/libraries/libvapours/include/vapours/results.hpp @@ -15,7 +15,8 @@ */ #pragma once -#include +#include +#include #include /* Utilities. */ diff --git a/libraries/libvapours/include/vapours/results/results_common.hpp b/libraries/libvapours/include/vapours/results/results_common.hpp index 936fa6deb..74517f274 100644 --- a/libraries/libvapours/include/vapours/results/results_common.hpp +++ b/libraries/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/libraries/libvapours/include/vapours/svc.hpp b/libraries/libvapours/include/vapours/svc.hpp index 93d965956..b26487520 100644 --- a/libraries/libvapours/include/vapours/svc.hpp +++ b/libraries/libvapours/include/vapours/svc.hpp @@ -15,7 +15,8 @@ */ #pragma once -#include +#include +#include #include #include diff --git a/libraries/libvapours/include/vapours/svc/codegen/impl/svc_codegen_impl_common.hpp b/libraries/libvapours/include/vapours/svc/codegen/impl/svc_codegen_impl_common.hpp index 6e2bf8d7f..97f6f5d22 100644 --- a/libraries/libvapours/include/vapours/svc/codegen/impl/svc_codegen_impl_common.hpp +++ b/libraries/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/libraries/libvapours/include/vapours/svc/svc_common.hpp b/libraries/libvapours/include/vapours/svc/svc_common.hpp index c32d3fdd8..e5e3c3353 100644 --- a/libraries/libvapours/include/vapours/svc/svc_common.hpp +++ b/libraries/libvapours/include/vapours/svc/svc_common.hpp @@ -15,6 +15,8 @@ */ #pragma once +#include +#include #include namespace ams::svc { diff --git a/libraries/libvapours/include/vapours/svc/svc_tick.hpp b/libraries/libvapours/include/vapours/svc/svc_tick.hpp index bc393cffa..ecdfd53bd 100644 --- a/libraries/libvapours/include/vapours/svc/svc_tick.hpp +++ b/libraries/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/libraries/libvapours/include/vapours/timespan.hpp b/libraries/libvapours/include/vapours/timespan.hpp index dbe6a0055..51d755c32 100644 --- a/libraries/libvapours/include/vapours/timespan.hpp +++ b/libraries/libvapours/include/vapours/timespan.hpp @@ -15,7 +15,8 @@ */ #pragma once -#include +#include +#include #include namespace ams { diff --git a/libraries/libvapours/include/vapours/util.hpp b/libraries/libvapours/include/vapours/util.hpp index 8cdae1847..c59ea8afb 100644 --- a/libraries/libvapours/include/vapours/util.hpp +++ b/libraries/libvapours/include/vapours/util.hpp @@ -15,7 +15,8 @@ */ #pragma once -#include +#include +#include #include #include diff --git a/libraries/libvapours/include/vapours/util/util_alignment.hpp b/libraries/libvapours/include/vapours/util/util_alignment.hpp index d800d94bf..8c3a24e5b 100644 --- a/libraries/libvapours/include/vapours/util/util_alignment.hpp +++ b/libraries/libvapours/include/vapours/util/util_alignment.hpp @@ -15,7 +15,8 @@ */ #pragma once -#include "../defines.hpp" +#include +#include namespace ams::util { diff --git a/libraries/libvapours/include/vapours/util/util_bitpack.hpp b/libraries/libvapours/include/vapours/util/util_bitpack.hpp index 844ce6a06..8c992c3f2 100644 --- a/libraries/libvapours/include/vapours/util/util_bitpack.hpp +++ b/libraries/libvapours/include/vapours/util/util_bitpack.hpp @@ -15,7 +15,8 @@ */ #pragma once -#include "../defines.hpp" +#include +#include namespace ams::util { diff --git a/libraries/libvapours/include/vapours/util/util_bitset.hpp b/libraries/libvapours/include/vapours/util/util_bitset.hpp index e3f9ae732..85a6bcc58 100644 --- a/libraries/libvapours/include/vapours/util/util_bitset.hpp +++ b/libraries/libvapours/include/vapours/util/util_bitset.hpp @@ -15,7 +15,8 @@ */ #pragma once -#include "../defines.hpp" +#include +#include namespace ams::util { diff --git a/libraries/libvapours/include/vapours/util/util_bitutil.hpp b/libraries/libvapours/include/vapours/util/util_bitutil.hpp index 64e32e38f..536aa0723 100644 --- a/libraries/libvapours/include/vapours/util/util_bitutil.hpp +++ b/libraries/libvapours/include/vapours/util/util_bitutil.hpp @@ -15,7 +15,8 @@ */ #pragma once -#include "../defines.hpp" +#include +#include namespace ams::util { diff --git a/libraries/libvapours/include/vapours/util/util_fourcc.hpp b/libraries/libvapours/include/vapours/util/util_fourcc.hpp index efd0be8e7..5b805e03b 100644 --- a/libraries/libvapours/include/vapours/util/util_fourcc.hpp +++ b/libraries/libvapours/include/vapours/util/util_fourcc.hpp @@ -15,7 +15,8 @@ */ #pragma once -#include "../defines.hpp" +#include +#include namespace ams::util { diff --git a/libraries/libvapours/include/vapours/util/util_intrusive_list.hpp b/libraries/libvapours/include/vapours/util/util_intrusive_list.hpp index 771aa3843..b19edb70f 100644 --- a/libraries/libvapours/include/vapours/util/util_intrusive_list.hpp +++ b/libraries/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/libraries/libvapours/include/vapours/util/util_intrusive_red_black_tree.hpp b/libraries/libvapours/include/vapours/util/util_intrusive_red_black_tree.hpp index 8d63f1982..4244f93d3 100644 --- a/libraries/libvapours/include/vapours/util/util_intrusive_red_black_tree.hpp +++ b/libraries/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/libraries/libvapours/include/vapours/util/util_parent_of_member.hpp b/libraries/libvapours/include/vapours/util/util_parent_of_member.hpp index 66f9b1b99..9276b0613 100644 --- a/libraries/libvapours/include/vapours/util/util_parent_of_member.hpp +++ b/libraries/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/libraries/libvapours/include/vapours/util/util_scope_guard.hpp b/libraries/libvapours/include/vapours/util/util_scope_guard.hpp index 0c8f1cbb5..def2186b6 100644 --- a/libraries/libvapours/include/vapours/util/util_scope_guard.hpp +++ b/libraries/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/libraries/libvapours/include/vapours/util/util_size.hpp b/libraries/libvapours/include/vapours/util/util_size.hpp index c1753bfad..e9f642b44 100644 --- a/libraries/libvapours/include/vapours/util/util_size.hpp +++ b/libraries/libvapours/include/vapours/util/util_size.hpp @@ -15,7 +15,8 @@ */ #pragma once -#include "../defines.hpp" +#include +#include namespace ams::util { diff --git a/libraries/libvapours/include/vapours/util/util_specialization_of.hpp b/libraries/libvapours/include/vapours/util/util_specialization_of.hpp index ce3454def..cf0fb6e2a 100644 --- a/libraries/libvapours/include/vapours/util/util_specialization_of.hpp +++ b/libraries/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/libraries/libvapours/include/vapours/util/util_tinymt.hpp b/libraries/libvapours/include/vapours/util/util_tinymt.hpp index 6a2c97e99..7611c9b7c 100644 --- a/libraries/libvapours/include/vapours/util/util_tinymt.hpp +++ b/libraries/libvapours/include/vapours/util/util_tinymt.hpp @@ -15,7 +15,8 @@ */ #pragma once -#include +#include +#include namespace ams::util { diff --git a/libraries/libvapours/include/vapours/util/util_typed_storage.hpp b/libraries/libvapours/include/vapours/util/util_typed_storage.hpp index 4bbb16b2b..de1db3f80 100644 --- a/libraries/libvapours/include/vapours/util/util_typed_storage.hpp +++ b/libraries/libvapours/include/vapours/util/util_typed_storage.hpp @@ -15,7 +15,8 @@ */ #pragma once -#include "../defines.hpp" +#include +#include namespace ams::util { diff --git a/stratosphere/ams_mitm/source/amsmitm_debug.cpp b/stratosphere/ams_mitm/source/amsmitm_debug.cpp index a1e5c3106..28798e0a5 100644 --- a/stratosphere/ams_mitm/source/amsmitm_debug.cpp +++ b/stratosphere/ams_mitm/source/amsmitm_debug.cpp @@ -48,7 +48,7 @@ namespace ams::mitm { g_throw_result = res; g_threw = true; - R_ASSERT(g_debug_throw_thread.Start()); + R_ABORT_UNLESS(g_debug_throw_thread.Start()); } } diff --git a/stratosphere/ams_mitm/source/amsmitm_fs_utils.cpp b/stratosphere/ams_mitm/source/amsmitm_fs_utils.cpp index 3f10eaeb4..e622610b9 100644 --- a/stratosphere/ams_mitm/source/amsmitm_fs_utils.cpp +++ b/stratosphere/ams_mitm/source/amsmitm_fs_utils.cpp @@ -71,7 +71,7 @@ namespace ams::mitm::fs { } void OpenGlobalSdCardFileSystem() { - R_ASSERT(fsOpenSdCardFileSystem(&g_sd_filesystem)); + R_ABORT_UNLESS(fsOpenSdCardFileSystem(&g_sd_filesystem)); } Result CreateSdFile(const char *path, s64 size, s32 option) { diff --git a/stratosphere/ams_mitm/source/amsmitm_initialization.cpp b/stratosphere/ams_mitm/source/amsmitm_initialization.cpp index c84f1c3b7..8ed331785 100644 --- a/stratosphere/ams_mitm/source/amsmitm_initialization.cpp +++ b/stratosphere/ams_mitm/source/amsmitm_initialization.cpp @@ -92,10 +92,10 @@ namespace ams::mitm { /* Read the calibration binary. */ { FsStorage calibration_binary_storage; - R_ASSERT(fsOpenBisStorage(&calibration_binary_storage, FsBisPartitionId_CalibrationBinary)); + R_ABORT_UNLESS(fsOpenBisStorage(&calibration_binary_storage, FsBisPartitionId_CalibrationBinary)); ON_SCOPE_EXIT { fsStorageClose(&calibration_binary_storage); }; - R_ASSERT(fsStorageRead(&calibration_binary_storage, 0, g_calibration_binary_storage_backup, CalibrationBinarySize)); + R_ABORT_UNLESS(fsStorageRead(&calibration_binary_storage, 0, g_calibration_binary_storage_backup, CalibrationBinarySize)); } /* Copy serial number from partition. */ @@ -109,16 +109,16 @@ namespace ams::mitm { GetBackupFileName(calibration_binary_backup_name, sizeof(calibration_binary_backup_name), serial_number, "PRODINFO.bin"); mitm::fs::CreateAtmosphereSdFile(calibration_binary_backup_name, CalibrationBinarySize, ams::fs::CreateOption_None); - R_ASSERT(mitm::fs::OpenAtmosphereSdFile(&g_calibration_binary_file, calibration_binary_backup_name, ams::fs::OpenMode_ReadWrite)); + R_ABORT_UNLESS(mitm::fs::OpenAtmosphereSdFile(&g_calibration_binary_file, calibration_binary_backup_name, ams::fs::OpenMode_ReadWrite)); s64 file_size = 0; - R_ASSERT(fsFileGetSize(&g_calibration_binary_file, &file_size)); + R_ABORT_UNLESS(fsFileGetSize(&g_calibration_binary_file, &file_size)); bool is_file_backup_valid = file_size == CalibrationBinarySize; if (is_file_backup_valid) { u64 read_size = 0; - R_ASSERT(fsFileRead(&g_calibration_binary_file, 0, g_calibration_binary_file_backup, CalibrationBinarySize, FsReadOption_None, &read_size)); - AMS_ASSERT(read_size == CalibrationBinarySize); + R_ABORT_UNLESS(fsFileRead(&g_calibration_binary_file, 0, g_calibration_binary_file_backup, CalibrationBinarySize, FsReadOption_None, &read_size)); + AMS_ABORT_UNLESS(read_size == CalibrationBinarySize); is_file_backup_valid &= std::memcmp(g_calibration_binary_file_backup, "CAL0", 4) == 0; is_file_backup_valid &= std::memcmp(g_calibration_binary_file_backup + 0x250, serial_number, 0x18) == 0; const u32 cal_bin_size = *reinterpret_cast(g_calibration_binary_file_backup + 0x8); @@ -132,8 +132,8 @@ namespace ams::mitm { } if (!is_file_backup_valid) { - R_ASSERT(fsFileSetSize(&g_calibration_binary_file, CalibrationBinarySize)); - R_ASSERT(fsFileWrite(&g_calibration_binary_file, 0, g_calibration_binary_storage_backup, CalibrationBinarySize, FsWriteOption_Flush)); + R_ABORT_UNLESS(fsFileSetSize(&g_calibration_binary_file, CalibrationBinarySize)); + R_ABORT_UNLESS(fsFileWrite(&g_calibration_binary_file, 0, g_calibration_binary_storage_backup, CalibrationBinarySize, FsWriteOption_Flush)); } /* Note: g_calibration_binary_file is intentionally not closed here. This prevents any other process from opening it. */ @@ -145,7 +145,7 @@ namespace ams::mitm { { u64 key_generation = 0; if (hos::GetVersion() >= hos::Version_500) { - R_ASSERT(splGetConfig(SplConfigItem_NewKeyGeneration, &key_generation)); + R_ABORT_UNLESS(splGetConfig(SplConfigItem_NewKeyGeneration, &key_generation)); } u8 bis_keys[4][2][0x10]; @@ -155,15 +155,15 @@ namespace ams::mitm { for (size_t partition = 0; partition < 4; partition++) { if (partition == 0) { for (size_t i = 0; i < 2; i++) { - R_ASSERT(splFsGenerateSpecificAesKey(BisKeySources[partition][i], key_generation, i, bis_keys[partition][i])); + R_ABORT_UNLESS(splFsGenerateSpecificAesKey(BisKeySources[partition][i], key_generation, i, bis_keys[partition][i])); } } else { const u32 option = (partition == 3 && spl::IsRecoveryBoot()) ? 0x4 : 0x1; u8 access_key[0x10]; - R_ASSERT(splCryptoGenerateAesKek(BisKekSource, key_generation, option, access_key)); + R_ABORT_UNLESS(splCryptoGenerateAesKek(BisKekSource, key_generation, option, access_key)); for (size_t i = 0; i < 2; i++) { - R_ASSERT(splCryptoGenerateAesKey(access_key, BisKeySources[partition][i], bis_keys[partition][i])); + R_ABORT_UNLESS(splCryptoGenerateAesKey(access_key, BisKeySources[partition][i], bis_keys[partition][i])); } } } @@ -172,9 +172,9 @@ namespace ams::mitm { GetBackupFileName(bis_keys_backup_name, sizeof(bis_keys_backup_name), serial_number, "BISKEYS.bin"); mitm::fs::CreateAtmosphereSdFile(bis_keys_backup_name, sizeof(bis_keys), ams::fs::CreateOption_None); - R_ASSERT(mitm::fs::OpenAtmosphereSdFile(&g_bis_key_file, bis_keys_backup_name, ams::fs::OpenMode_ReadWrite)); - R_ASSERT(fsFileSetSize(&g_bis_key_file, sizeof(bis_keys))); - R_ASSERT(fsFileWrite(&g_bis_key_file, 0, bis_keys, sizeof(bis_keys), FsWriteOption_Flush)); + R_ABORT_UNLESS(mitm::fs::OpenAtmosphereSdFile(&g_bis_key_file, bis_keys_backup_name, ams::fs::OpenMode_ReadWrite)); + R_ABORT_UNLESS(fsFileSetSize(&g_bis_key_file, sizeof(bis_keys))); + R_ABORT_UNLESS(fsFileWrite(&g_bis_key_file, 0, bis_keys, sizeof(bis_keys), FsWriteOption_Flush)); /* NOTE: g_bis_key_file is intentionally not closed here. This prevents any other process from opening it. */ } } @@ -226,14 +226,14 @@ namespace ams::mitm { /* Connect to set:sys. */ sm::DoWithSession([]() { - R_ASSERT(setsysInitialize()); + R_ABORT_UNLESS(setsysInitialize()); }); /* Load settings off the SD card. */ settings::fwdbg::InitializeSdCardKeyValueStore(); /* Ensure that we reboot using the user's preferred method. */ - R_ASSERT(mitm::bpc::DetectPreferredRebootFunctionality()); + R_ABORT_UNLESS(mitm::bpc::DetectPreferredRebootFunctionality()); /* Signal to waiters that we are ready. */ g_init_event.Signal(); @@ -242,7 +242,7 @@ namespace ams::mitm { } void StartInitialize() { - R_ASSERT(g_initialize_thread.Start()); + R_ABORT_UNLESS(g_initialize_thread.Start()); } bool IsInitialized() { diff --git a/stratosphere/ams_mitm/source/amsmitm_main.cpp b/stratosphere/ams_mitm/source/amsmitm_main.cpp index 315c27393..e2dd87f91 100644 --- a/stratosphere/ams_mitm/source/amsmitm_main.cpp +++ b/stratosphere/ams_mitm/source/amsmitm_main.cpp @@ -78,10 +78,10 @@ void __appInit(void) { hos::SetVersionForLibnx(); sm::DoWithSession([&]() { - R_ASSERT(fsInitialize()); - R_ASSERT(pmdmntInitialize()); - R_ASSERT(pminfoInitialize()); - R_ASSERT(splFsInitialize()); + R_ABORT_UNLESS(fsInitialize()); + R_ABORT_UNLESS(pmdmntInitialize()); + R_ABORT_UNLESS(pminfoInitialize()); + R_ABORT_UNLESS(splFsInitialize()); }); ams::CheckApiVersion(); diff --git a/stratosphere/ams_mitm/source/amsmitm_module_management.cpp b/stratosphere/ams_mitm/source/amsmitm_module_management.cpp index 1d199472b..317b5103f 100644 --- a/stratosphere/ams_mitm/source/amsmitm_module_management.cpp +++ b/stratosphere/ams_mitm/source/amsmitm_module_management.cpp @@ -72,12 +72,12 @@ namespace ams::mitm { /* Create thread for each module. */ for (u32 i = 0; i < static_cast(ModuleId_Count); i++) { const ModuleDefinition &cur_module = g_module_definitions[i]; - R_ASSERT(g_module_threads[i].Initialize(cur_module.main, nullptr, cur_module.stack_mem, cur_module.stack_size, cur_module.priority)); + R_ABORT_UNLESS(g_module_threads[i].Initialize(cur_module.main, nullptr, cur_module.stack_mem, cur_module.stack_size, cur_module.priority)); } /* Start thread for each module. */ for (u32 i = 0; i < static_cast(ModuleId_Count); i++) { - R_ASSERT(g_module_threads[i].Start()); + R_ABORT_UNLESS(g_module_threads[i].Start()); } } diff --git a/stratosphere/ams_mitm/source/bpc_mitm/bpcmitm_module.cpp b/stratosphere/ams_mitm/source/bpc_mitm/bpcmitm_module.cpp index 83025a7fd..fcd1f7dbe 100644 --- a/stratosphere/ams_mitm/source/bpc_mitm/bpcmitm_module.cpp +++ b/stratosphere/ams_mitm/source/bpc_mitm/bpcmitm_module.cpp @@ -44,13 +44,13 @@ namespace ams::mitm::bpc { /* Create bpc:ams. */ { Handle bpcams_h; - R_ASSERT(svcManageNamedPort(&bpcams_h, AtmosphereServiceName.name, AtmosphereMaxSessions)); + R_ABORT_UNLESS(svcManageNamedPort(&bpcams_h, AtmosphereServiceName.name, AtmosphereMaxSessions)); g_server_manager.RegisterServer(bpcams_h); } /* Create bpc mitm. */ const sm::ServiceName service_name = (hos::GetVersion() >= hos::Version_200) ? MitmServiceName : DeprecatedMitmServiceName; - R_ASSERT(g_server_manager.RegisterMitmServer(service_name)); + R_ABORT_UNLESS(g_server_manager.RegisterMitmServer(service_name)); /* Loop forever, servicing our services. */ g_server_manager.LoopProcess(); diff --git a/stratosphere/ams_mitm/source/fs_mitm/fs_mitm_service.cpp b/stratosphere/ams_mitm/source/fs_mitm/fs_mitm_service.cpp index 6419be0f0..9b9065e4f 100644 --- a/stratosphere/ams_mitm/source/fs_mitm/fs_mitm_service.cpp +++ b/stratosphere/ams_mitm/source/fs_mitm/fs_mitm_service.cpp @@ -60,7 +60,7 @@ namespace ams::mitm::fs { bool GetSettingsItemBooleanValue(const char *name, const char *key) { u8 tmp = 0; - AMS_ASSERT(settings::fwdbg::GetSettingsItemValue(&tmp, sizeof(tmp), name, key) == sizeof(tmp)); + AMS_ABORT_UNLESS(settings::fwdbg::GetSettingsItemValue(&tmp, sizeof(tmp), name, key) == sizeof(tmp)); return (tmp != 0); } diff --git a/stratosphere/ams_mitm/source/fs_mitm/fsmitm_layered_romfs_storage.cpp b/stratosphere/ams_mitm/source/fs_mitm/fsmitm_layered_romfs_storage.cpp index f38b0e807..ce3e4da42 100644 --- a/stratosphere/ams_mitm/source/fs_mitm/fsmitm_layered_romfs_storage.cpp +++ b/stratosphere/ams_mitm/source/fs_mitm/fsmitm_layered_romfs_storage.cpp @@ -45,14 +45,14 @@ namespace ams::mitm::fs { std::scoped_lock lk(g_mq_lock); if (!g_started_req_thread) { - R_ASSERT(g_romfs_initializer_thread.Start()); + R_ABORT_UNLESS(g_romfs_initializer_thread.Start()); g_started_req_thread = true; } g_req_mq.Send(storage_uptr); uintptr_t ack = 0; g_ack_mq.Receive(&ack); - AMS_ASSERT(ack == storage_uptr); + AMS_ABORT_UNLESS(ack == storage_uptr); } } @@ -70,7 +70,7 @@ namespace ams::mitm::fs { } void LayeredRomfsStorage::BeginInitialize() { - AMS_ASSERT(!this->started_initialize); + AMS_ABORT_UNLESS(!this->started_initialize); RequestInitializeStorage(reinterpret_cast(this)); this->started_initialize = true; } @@ -123,27 +123,27 @@ namespace ams::mitm::fs { size_t read_so_far = 0; while (read_so_far < size) { const auto &cur_source = *it; - AMS_ASSERT(offset >= cur_source.virtual_offset); + AMS_ABORT_UNLESS(offset >= cur_source.virtual_offset); if (offset < cur_source.virtual_offset + cur_source.size) { const s64 offset_within_source = offset - cur_source.virtual_offset; const size_t cur_read_size = std::min(size - read_so_far, size_t(cur_source.size - offset_within_source)); switch (cur_source.source_type) { case romfs::DataSourceType::Storage: - R_ASSERT(this->storage_romfs->Read(cur_source.storage_source_info.offset + offset_within_source, cur_dst, cur_read_size)); + R_ABORT_UNLESS(this->storage_romfs->Read(cur_source.storage_source_info.offset + offset_within_source, cur_dst, cur_read_size)); break; case romfs::DataSourceType::File: - R_ASSERT(this->file_romfs->Read(cur_source.file_source_info.offset + offset_within_source, cur_dst, cur_read_size)); + R_ABORT_UNLESS(this->file_romfs->Read(cur_source.file_source_info.offset + offset_within_source, cur_dst, cur_read_size)); break; case romfs::DataSourceType::LooseSdFile: { FsFile file; - R_ASSERT(mitm::fs::OpenAtmosphereSdRomfsFile(&file, this->program_id, cur_source.loose_source_info.path, OpenMode_Read)); + R_ABORT_UNLESS(mitm::fs::OpenAtmosphereSdRomfsFile(&file, this->program_id, cur_source.loose_source_info.path, OpenMode_Read)); ON_SCOPE_EXIT { fsFileClose(&file); }; u64 out_read = 0; - R_ASSERT(fsFileRead(&file, offset_within_source, cur_dst, cur_read_size, FsReadOption_None, &out_read)); - AMS_ASSERT(out_read == cur_read_size); + R_ABORT_UNLESS(fsFileRead(&file, offset_within_source, cur_dst, cur_read_size, FsReadOption_None, &out_read)); + AMS_ABORT_UNLESS(out_read == cur_read_size); } break; case romfs::DataSourceType::Memory: @@ -152,8 +152,8 @@ namespace ams::mitm::fs { case romfs::DataSourceType::Metadata: { size_t out_read = 0; - R_ASSERT(cur_source.metadata_source_info.file->Read(&out_read, offset_within_source, cur_dst, cur_read_size)); - AMS_ASSERT(out_read == cur_read_size); + R_ABORT_UNLESS(cur_source.metadata_source_info.file->Read(&out_read, offset_within_source, cur_dst, cur_read_size)); + AMS_ABORT_UNLESS(out_read == cur_read_size); } break; AMS_UNREACHABLE_DEFAULT_CASE(); diff --git a/stratosphere/ams_mitm/source/fs_mitm/fsmitm_module.cpp b/stratosphere/ams_mitm/source/fs_mitm/fsmitm_module.cpp index e97cfeb1f..78f6e9d35 100644 --- a/stratosphere/ams_mitm/source/fs_mitm/fsmitm_module.cpp +++ b/stratosphere/ams_mitm/source/fs_mitm/fsmitm_module.cpp @@ -51,14 +51,14 @@ namespace ams::mitm::fs { if constexpr (NumExtraThreads > 0) { const u32 priority = os::GetCurrentThreadPriority(); for (size_t i = 0; i < NumExtraThreads; i++) { - R_ASSERT(g_extra_threads[i].Initialize(LoopServerThread, nullptr, g_extra_thread_stacks[i], ThreadStackSize, priority)); + R_ABORT_UNLESS(g_extra_threads[i].Initialize(LoopServerThread, nullptr, g_extra_thread_stacks[i], ThreadStackSize, priority)); } } /* Start extra threads. */ if constexpr (NumExtraThreads > 0) { for (size_t i = 0; i < NumExtraThreads; i++) { - R_ASSERT(g_extra_threads[i].Start()); + R_ABORT_UNLESS(g_extra_threads[i].Start()); } } @@ -68,7 +68,7 @@ namespace ams::mitm::fs { /* Wait for extra threads to finish. */ if constexpr (NumExtraThreads > 0) { for (size_t i = 0; i < NumExtraThreads; i++) { - R_ASSERT(g_extra_threads[i].Join()); + R_ABORT_UNLESS(g_extra_threads[i].Join()); } } } @@ -77,7 +77,7 @@ namespace ams::mitm::fs { void MitmModule::ThreadFunction(void *arg) { /* Create fs mitm. */ - R_ASSERT(g_server_manager.RegisterMitmServer(MitmServiceName)); + R_ABORT_UNLESS(g_server_manager.RegisterMitmServer(MitmServiceName)); /* Process for the server. */ ProcessForServerOnAllThreads(); diff --git a/stratosphere/ams_mitm/source/fs_mitm/fsmitm_romfs.cpp b/stratosphere/ams_mitm/source/fs_mitm/fsmitm_romfs.cpp index 973f5ed43..efe895e18 100644 --- a/stratosphere/ams_mitm/source/fs_mitm/fsmitm_romfs.cpp +++ b/stratosphere/ams_mitm/source/fs_mitm/fsmitm_romfs.cpp @@ -117,14 +117,14 @@ namespace ams::mitm::fs { __attribute__((noinline)) void OpenFileSystemRomfsDirectory(FsDir *out, ncm::ProgramId program_id, BuildDirectoryContext *parent, fs::OpenDirectoryMode mode, FsFileSystem *fs) { std::scoped_lock lk(g_fs_romfs_path_lock); parent->GetPath(g_fs_romfs_path_buffer); - R_ASSERT(mitm::fs::OpenAtmosphereRomfsDirectory(out, program_id, g_fs_romfs_path_buffer, mode, fs)); + R_ABORT_UNLESS(mitm::fs::OpenAtmosphereRomfsDirectory(out, program_id, g_fs_romfs_path_buffer, mode, fs)); } } Builder::Builder(ncm::ProgramId pr_id) : program_id(pr_id), num_dirs(0), num_files(0), dir_table_size(0), file_table_size(0), dir_hash_table_size(0), file_hash_table_size(0), file_partition_size(0) { auto res = this->directories.emplace(std::make_unique(BuildDirectoryContext::RootTag{})); - AMS_ASSERT(res.second); + AMS_ABORT_UNLESS(res.second); this->root = res.first->get(); this->num_dirs = 1; this->dir_table_size = 0x18; @@ -172,14 +172,14 @@ namespace ams::mitm::fs { { OpenFileSystemRomfsDirectory(&dir, this->program_id, parent, OpenDirectoryMode_Directory, fs); ON_SCOPE_EXIT { fsDirClose(&dir); }; - R_ASSERT(fsDirGetEntryCount(&dir, &num_child_dirs)); + R_ABORT_UNLESS(fsDirGetEntryCount(&dir, &num_child_dirs)); } - AMS_ASSERT(num_child_dirs >= 0); + AMS_ABORT_UNLESS(num_child_dirs >= 0); { BuildDirectoryContext **child_dirs = reinterpret_cast(std::malloc(sizeof(BuildDirectoryContext *) * num_child_dirs)); ON_SCOPE_EXIT { std::free(child_dirs); }; - AMS_ASSERT(child_dirs != nullptr); + AMS_ABORT_UNLESS(child_dirs != nullptr); s64 cur_child_dir_ind = 0; { @@ -188,25 +188,25 @@ namespace ams::mitm::fs { s64 read_entries = 0; while (true) { - R_ASSERT(fsDirRead(&dir, &read_entries, 1, &this->dir_entry)); + R_ABORT_UNLESS(fsDirRead(&dir, &read_entries, 1, &this->dir_entry)); if (read_entries != 1) { break; } - AMS_ASSERT(this->dir_entry.type == FsDirEntryType_Dir || this->dir_entry.type == FsDirEntryType_File); + AMS_ABORT_UNLESS(this->dir_entry.type == FsDirEntryType_Dir || this->dir_entry.type == FsDirEntryType_File); if (this->dir_entry.type == FsDirEntryType_Dir) { BuildDirectoryContext *real_child = nullptr; this->AddDirectory(&real_child, parent, std::make_unique(this->dir_entry.name, strlen(this->dir_entry.name))); - AMS_ASSERT(real_child != nullptr); + AMS_ABORT_UNLESS(real_child != nullptr); child_dirs[cur_child_dir_ind++] = real_child; - AMS_ASSERT(cur_child_dir_ind <= num_child_dirs); + AMS_ABORT_UNLESS(cur_child_dir_ind <= num_child_dirs); } else /* if (this->dir_entry.type == FsDirEntryType_File) */ { this->AddFile(parent, std::make_unique(this->dir_entry.name, strlen(this->dir_entry.name), this->dir_entry.file_size, 0, this->cur_source_type)); } } } - AMS_ASSERT(num_child_dirs == cur_child_dir_ind); + AMS_ABORT_UNLESS(num_child_dirs == cur_child_dir_ind); for (s64 i = 0; i < num_child_dirs; i++) { this->VisitDirectory(fs, child_dirs[i]); } @@ -232,7 +232,7 @@ namespace ams::mitm::fs { while (true) { BuildDirectoryContext *real_child = nullptr; this->AddDirectory(&real_child, parent, std::make_unique(cur_child->name, cur_child->name_size)); - AMS_ASSERT(real_child != nullptr); + AMS_ABORT_UNLESS(real_child != nullptr); this->VisitDirectory(real_child, cur_child_offset, dir_table, dir_table_size, file_table, file_table_size); @@ -249,7 +249,7 @@ namespace ams::mitm::fs { void Builder::AddSdFiles() { /* Open Sd Card filesystem. */ FsFileSystem sd_filesystem; - R_ASSERT(fsOpenSdCardFileSystem(&sd_filesystem)); + R_ABORT_UNLESS(fsOpenSdCardFileSystem(&sd_filesystem)); ON_SCOPE_EXIT { fsFsClose(&sd_filesystem); }; /* If there is no romfs folder on the SD, don't bother continuing. */ @@ -267,16 +267,16 @@ namespace ams::mitm::fs { void Builder::AddStorageFiles(ams::fs::IStorage *storage, DataSourceType source_type) { Header header; - R_ASSERT(storage->Read(0, &header, sizeof(Header))); - AMS_ASSERT(header.header_size == sizeof(Header)); + R_ABORT_UNLESS(storage->Read(0, &header, sizeof(Header))); + AMS_ABORT_UNLESS(header.header_size == sizeof(Header)); /* Read tables. */ void *tables = std::malloc(header.dir_table_size + header.file_table_size); ON_SCOPE_EXIT { std::free(tables); }; void *dir_table = tables; void *file_table = reinterpret_cast(reinterpret_cast(tables) + header.dir_table_size); - R_ASSERT(storage->Read(header.dir_table_ofs, dir_table, size_t(header.dir_table_size))); - R_ASSERT(storage->Read(header.file_table_ofs, file_table, size_t(header.file_table_size))); + R_ABORT_UNLESS(storage->Read(header.dir_table_ofs, dir_table, size_t(header.dir_table_size))); + R_ABORT_UNLESS(storage->Read(header.file_table_ofs, file_table, size_t(header.file_table_size))); this->cur_source_type = source_type; this->VisitDirectory(this->root, 0x0, dir_table, size_t(header.dir_table_size), file_table, size_t(header.file_table_size)); @@ -288,7 +288,7 @@ namespace ams::mitm::fs { /* Open an SD card filesystem. */ FsFileSystem sd_filesystem; - R_ASSERT(fsOpenSdCardFileSystem(&sd_filesystem)); + R_ABORT_UNLESS(fsOpenSdCardFileSystem(&sd_filesystem)); ON_SCOPE_EXIT { fsFsClose(&sd_filesystem); }; /* Calculate hash table sizes. */ @@ -304,7 +304,7 @@ namespace ams::mitm::fs { /* Open metadata file. */ const size_t metadata_size = this->dir_hash_table_size + this->dir_table_size + this->file_hash_table_size + this->file_table_size; FsFile metadata_file; - R_ASSERT(mitm::fs::CreateAndOpenAtmosphereSdFile(&metadata_file, this->program_id, "romfs_metadata.bin", metadata_size)); + R_ABORT_UNLESS(mitm::fs::CreateAndOpenAtmosphereSdFile(&metadata_file, this->program_id, "romfs_metadata.bin", metadata_size)); /* Ensure later hash tables will have correct defaults. */ static_assert(EmptyEntry == 0xFFFFFFFF); @@ -328,7 +328,7 @@ namespace ams::mitm::fs { if (prev_file != nullptr && prev_file->source_type == cur_file->source_type && is_storage_or_file) { const s64 expected = this->file_partition_size - prev_file->offset + prev_file->orig_offset; if (expected != cur_file->orig_offset) { - AMS_ASSERT(expected <= cur_file->orig_offset); + AMS_ABORT_UNLESS(expected <= cur_file->orig_offset); this->file_partition_size += cur_file->orig_offset - expected; } } @@ -431,8 +431,8 @@ namespace ams::mitm::fs { } /* Write to file. */ - R_ASSERT(fsFileWrite(&metadata_file, this->dir_hash_table_size + this->dir_table_size, file_hash_table, this->file_hash_table_size, FsWriteOption_None)); - R_ASSERT(fsFileWrite(&metadata_file, this->dir_hash_table_size + this->dir_table_size + this->file_hash_table_size, file_table, this->file_table_size, FsWriteOption_None)); + R_ABORT_UNLESS(fsFileWrite(&metadata_file, this->dir_hash_table_size + this->dir_table_size, file_hash_table, this->file_hash_table_size, FsWriteOption_None)); + R_ABORT_UNLESS(fsFileWrite(&metadata_file, this->dir_hash_table_size + this->dir_table_size + this->file_hash_table_size, file_table, this->file_table_size, FsWriteOption_None)); } /* Populate directory tables. */ @@ -472,8 +472,8 @@ namespace ams::mitm::fs { } /* Write to file. */ - R_ASSERT(fsFileWrite(&metadata_file, 0, dir_hash_table, this->dir_hash_table_size, FsWriteOption_None)); - R_ASSERT(fsFileWrite(&metadata_file, this->dir_hash_table_size, dir_table, this->dir_table_size, FsWriteOption_None)); + R_ABORT_UNLESS(fsFileWrite(&metadata_file, 0, dir_hash_table, this->dir_hash_table_size, FsWriteOption_None)); + R_ABORT_UNLESS(fsFileWrite(&metadata_file, this->dir_hash_table_size, dir_table, this->dir_table_size, FsWriteOption_None)); } /* Delete maps. */ @@ -495,7 +495,7 @@ namespace ams::mitm::fs { /* Save metadata to the SD card, to save on memory space. */ { - R_ASSERT(fsFileFlush(&metadata_file)); + R_ABORT_UNLESS(fsFileFlush(&metadata_file)); out_infos->emplace_back(header->dir_hash_table_ofs, metadata_size, DataSourceType::Metadata, new RemoteFile(metadata_file)); } } diff --git a/stratosphere/ams_mitm/source/fs_mitm/fsmitm_romfs.hpp b/stratosphere/ams_mitm/source/fs_mitm/fsmitm_romfs.hpp index 5f2be0ae0..edb30bbf3 100644 --- a/stratosphere/ams_mitm/source/fs_mitm/fsmitm_romfs.hpp +++ b/stratosphere/ams_mitm/source/fs_mitm/fsmitm_romfs.hpp @@ -78,7 +78,7 @@ namespace ams::mitm::fs::romfs { } void Cleanup() { - AMS_ASSERT(!this->cleaned_up); + AMS_ABORT_UNLESS(!this->cleaned_up); this->cleaned_up = true; switch (this->source_type) { diff --git a/stratosphere/ams_mitm/source/hid_mitm/hidmitm_module.cpp b/stratosphere/ams_mitm/source/hid_mitm/hidmitm_module.cpp index 9306f5a40..64ced1781 100644 --- a/stratosphere/ams_mitm/source/hid_mitm/hidmitm_module.cpp +++ b/stratosphere/ams_mitm/source/hid_mitm/hidmitm_module.cpp @@ -58,7 +58,7 @@ namespace ams::mitm::hid { } /* Create hid mitm. */ - R_ASSERT(g_server_manager.RegisterMitmServer(MitmServiceName)); + R_ABORT_UNLESS(g_server_manager.RegisterMitmServer(MitmServiceName)); /* Loop forever, servicing our services. */ g_server_manager.LoopProcess(); diff --git a/stratosphere/ams_mitm/source/ns_mitm/nsmitm_module.cpp b/stratosphere/ams_mitm/source/ns_mitm/nsmitm_module.cpp index d18fc0541..4dd2f2756 100644 --- a/stratosphere/ams_mitm/source/ns_mitm/nsmitm_module.cpp +++ b/stratosphere/ams_mitm/source/ns_mitm/nsmitm_module.cpp @@ -38,9 +38,9 @@ namespace ams::mitm::ns { /* Create mitm servers. */ if (hos::GetVersion() < hos::Version_300) { - R_ASSERT(g_server_manager.RegisterMitmServer(NsAmMitmServiceName)); + R_ABORT_UNLESS(g_server_manager.RegisterMitmServer(NsAmMitmServiceName)); } else { - R_ASSERT(g_server_manager.RegisterMitmServer(NsWebMitmServiceName)); + R_ABORT_UNLESS(g_server_manager.RegisterMitmServer(NsWebMitmServiceName)); } /* Loop forever, servicing our services. */ diff --git a/stratosphere/ams_mitm/source/set_mitm/setmitm_module.cpp b/stratosphere/ams_mitm/source/set_mitm/setmitm_module.cpp index 15d5859fa..7b386ea2e 100644 --- a/stratosphere/ams_mitm/source/set_mitm/setmitm_module.cpp +++ b/stratosphere/ams_mitm/source/set_mitm/setmitm_module.cpp @@ -42,8 +42,8 @@ namespace ams::mitm::settings { mitm::WaitInitialized(); /* Create mitm servers. */ - R_ASSERT(g_server_manager.RegisterMitmServer(SetMitmServiceName)); - R_ASSERT(g_server_manager.RegisterMitmServer(SetSysMitmServiceName)); + R_ABORT_UNLESS(g_server_manager.RegisterMitmServer(SetMitmServiceName)); + R_ABORT_UNLESS(g_server_manager.RegisterMitmServer(SetSysMitmServiceName)); /* Loop forever, servicing our services. */ g_server_manager.LoopProcess(); diff --git a/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.cpp b/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.cpp index 862352030..fc3425dce 100644 --- a/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.cpp +++ b/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.cpp @@ -35,17 +35,17 @@ namespace ams::mitm::settings { } /* Mount firmware version data archive. */ - R_ASSERT(romfsMountFromDataArchive(static_cast(ncm::ProgramId::ArchiveSystemVersion), NcmStorageId_BuiltInSystem, "sysver")); + R_ABORT_UNLESS(romfsMountFromDataArchive(static_cast(ncm::ProgramId::ArchiveSystemVersion), NcmStorageId_BuiltInSystem, "sysver")); { ON_SCOPE_EXIT { romfsUnmount("sysver"); }; /* Firmware version file must exist. */ FILE *fp = fopen("sysver:/file", "rb"); - AMS_ASSERT(fp != nullptr); + AMS_ABORT_UNLESS(fp != nullptr); ON_SCOPE_EXIT { fclose(fp); }; /* Must be possible to read firmware version from file. */ - AMS_ASSERT(fread(&g_firmware_version, sizeof(g_firmware_version), 1, fp) == 1); + AMS_ABORT_UNLESS(fread(&g_firmware_version, sizeof(g_firmware_version), 1, fp) == 1); g_ams_firmware_version = g_firmware_version; } diff --git a/stratosphere/ams_mitm/source/set_mitm/settings_fwdbg_api_override.cpp b/stratosphere/ams_mitm/source/set_mitm/settings_fwdbg_api_override.cpp index e050c0d25..4a0b971f4 100644 --- a/stratosphere/ams_mitm/source/set_mitm/settings_fwdbg_api_override.cpp +++ b/stratosphere/ams_mitm/source/set_mitm/settings_fwdbg_api_override.cpp @@ -25,7 +25,7 @@ namespace ams::settings::fwdbg { return size; } - R_ASSERT(setsysGetSettingsItemValueSize(name, key, &size)); + R_ABORT_UNLESS(setsysGetSettingsItemValueSize(name, key, &size)); return size; } @@ -36,7 +36,7 @@ namespace ams::settings::fwdbg { return size; } - R_ASSERT(setsysGetSettingsItemValue(name, key, dst, dst_size, &size)); + R_ABORT_UNLESS(setsysGetSettingsItemValue(name, key, dst, dst_size, &size)); return size; } diff --git a/stratosphere/ams_mitm/source/set_mitm/settings_sd_kvs.cpp b/stratosphere/ams_mitm/source/set_mitm/settings_sd_kvs.cpp index d79c1eb10..5122f3f0c 100644 --- a/stratosphere/ams_mitm/source/set_mitm/settings_sd_kvs.cpp +++ b/stratosphere/ams_mitm/source/set_mitm/settings_sd_kvs.cpp @@ -52,8 +52,8 @@ namespace ams::settings::fwdbg { } inline bool operator<(const SdKeyValueStoreEntry &lhs, const SdKeyValueStoreEntry &rhs) { - AMS_ASSERT(lhs.HasValue()); - AMS_ASSERT(rhs.HasValue()); + AMS_ABORT_UNLESS(lhs.HasValue()); + AMS_ABORT_UNLESS(rhs.HasValue()); char lhs_name_key[SettingsNameLengthMax + 1 + SettingsItemKeyLengthMax + 1]; char rhs_name_key[SettingsNameLengthMax + 1 + SettingsItemKeyLengthMax + 1]; @@ -76,7 +76,7 @@ namespace ams::settings::fwdbg { size_t g_num_entries; constexpr bool IsValidSettingsFormat(const char *str, size_t len) { - AMS_ASSERT(str != nullptr); + AMS_ABORT_UNLESS(str != nullptr); if (len > 0 && str[len - 1] == '.') { return false; @@ -306,63 +306,63 @@ namespace ams::settings::fwdbg { void LoadDefaultCustomSettings() { /* Disable uploading error reports to Nintendo. */ - R_ASSERT(ParseSettingsItemValue("eupld", "upload_enabled", "u8!0x0")); + R_ABORT_UNLESS(ParseSettingsItemValue("eupld", "upload_enabled", "u8!0x0")); /* Control whether RO should ease its validation of NROs. */ /* (note: this is normally not necessary, and ips patches can be used.) */ - R_ASSERT(ParseSettingsItemValue("ro", "ease_nro_restriction", "u8!0x0")); + R_ABORT_UNLESS(ParseSettingsItemValue("ro", "ease_nro_restriction", "u8!0x0")); /* Atmosphere custom settings. */ /* Reboot from fatal automatically after some number of milliseconds. */ /* If field is not present or 0, fatal will wait indefinitely for user input. */ - R_ASSERT(ParseSettingsItemValue("atmosphere", "fatal_auto_reboot_interval", "u64!0x0")); + R_ABORT_UNLESS(ParseSettingsItemValue("atmosphere", "fatal_auto_reboot_interval", "u64!0x0")); /* Make the power menu's "reboot" button reboot to payload. */ /* Set to "normal" for normal reboot, "rcm" for rcm reboot. */ - R_ASSERT(ParseSettingsItemValue("atmosphere", "power_menu_reboot_function", "str!payload")); + R_ABORT_UNLESS(ParseSettingsItemValue("atmosphere", "power_menu_reboot_function", "str!payload")); /* Enable writing to BIS partitions for HBL. */ /* This is probably undesirable for normal usage. */ - R_ASSERT(ParseSettingsItemValue("atmosphere", "enable_hbl_bis_write", "u8!0x0")); + R_ABORT_UNLESS(ParseSettingsItemValue("atmosphere", "enable_hbl_bis_write", "u8!0x0")); /* Enable HBL to read the CAL0 partition. */ /* This is probably undesirable for normal usage. */ - R_ASSERT(ParseSettingsItemValue("atmosphere", "enable_hbl_cal_read", "u8!0x0")); + R_ABORT_UNLESS(ParseSettingsItemValue("atmosphere", "enable_hbl_cal_read", "u8!0x0")); /* Controls whether dmnt cheats should be toggled on or off by */ /* default. 1 = toggled on by default, 0 = toggled off by default. */ - R_ASSERT(ParseSettingsItemValue("atmosphere", "dmnt_cheats_enabled_by_default", "u8!0x1")); + R_ABORT_UNLESS(ParseSettingsItemValue("atmosphere", "dmnt_cheats_enabled_by_default", "u8!0x1")); /* Controls whether dmnt should always save cheat toggle state */ /* for restoration on new game launch. 1 = always save toggles, */ /* 0 = only save toggles if toggle file exists. */ - R_ASSERT(ParseSettingsItemValue("atmosphere", "dmnt_always_save_cheat_toggles", "u8!0x0")); + R_ABORT_UNLESS(ParseSettingsItemValue("atmosphere", "dmnt_always_save_cheat_toggles", "u8!0x0")); /* Controls whether fs.mitm should redirect save files */ /* to directories on the sd card. */ /* 0 = Do not redirect, 1 = Redirect. */ /* NOTE: EXPERIMENTAL */ /* If you do not know what you are doing, do not touch this yet. */ - R_ASSERT(ParseSettingsItemValue("atmosphere", "fsmitm_redirect_saves_to_sd", "u8!0x0")); + R_ABORT_UNLESS(ParseSettingsItemValue("atmosphere", "fsmitm_redirect_saves_to_sd", "u8!0x0")); /* Controls whether to enable the deprecated hid mitm */ /* to fix compatibility with old homebrew. */ /* 0 = Do not enable, 1 = Enable. */ /* Please note this setting may be removed in a future release of Atmosphere. */ - R_ASSERT(ParseSettingsItemValue("atmosphere", "enable_deprecated_hid_mitm", "u8!0x0")); + R_ABORT_UNLESS(ParseSettingsItemValue("atmosphere", "enable_deprecated_hid_mitm", "u8!0x0")); /* Hbloader custom settings. */ /* Controls the size of the homebrew heap when running as applet. */ /* If set to zero, all available applet memory is used as heap. */ /* The default is zero. */ - R_ASSERT(ParseSettingsItemValue("hbloader", "applet_heap_size", "u64!0x0")); + R_ABORT_UNLESS(ParseSettingsItemValue("hbloader", "applet_heap_size", "u64!0x0")); /* Controls the amount of memory to reserve when running as applet */ /* for usage by other applets. This setting has no effect if */ /* applet_heap_size is non-zero. The default is 0x8600000. */ - R_ASSERT(ParseSettingsItemValue("hbloader", "applet_heap_reservation_size", "u64!0x8600000")); + R_ABORT_UNLESS(ParseSettingsItemValue("hbloader", "applet_heap_reservation_size", "u64!0x8600000")); } } diff --git a/stratosphere/boot/source/boot_boot_reason.cpp b/stratosphere/boot/source/boot_boot_reason.cpp index acbb74f03..26796968d 100644 --- a/stratosphere/boot/source/boot_boot_reason.cpp +++ b/stratosphere/boot/source/boot_boot_reason.cpp @@ -72,16 +72,16 @@ namespace ams::boot { /* Get values from PMIC. */ { PmicDriver pmic_driver; - R_ASSERT(pmic_driver.GetPowerIntr(&power_intr)); - R_ASSERT(pmic_driver.GetNvErc(&nv_erc)); - R_ASSERT(pmic_driver.GetAcOk(&ac_ok)); + R_ABORT_UNLESS(pmic_driver.GetPowerIntr(&power_intr)); + R_ABORT_UNLESS(pmic_driver.GetNvErc(&nv_erc)); + R_ABORT_UNLESS(pmic_driver.GetAcOk(&ac_ok)); } /* Get values from RTC. */ { RtcDriver rtc_driver; - R_ASSERT(rtc_driver.GetRtcIntr(&rtc_intr)); - R_ASSERT(rtc_driver.GetRtcIntrM(&rtc_intr_m)); + R_ABORT_UNLESS(rtc_driver.GetRtcIntr(&rtc_intr)); + R_ABORT_UNLESS(rtc_driver.GetRtcIntrM(&rtc_intr_m)); } /* Set global derived boot reason. */ @@ -94,14 +94,14 @@ namespace ams::boot { boot_reason_value.rtc_intr = rtc_intr & ~rtc_intr_m; boot_reason_value.nv_erc = nv_erc; boot_reason_value.boot_reason = g_boot_reason; - R_ASSERT(splSetBootReason(boot_reason_value.value)); + R_ABORT_UNLESS(splSetBootReason(boot_reason_value.value)); } g_detected_boot_reason = true; } u32 GetBootReason() { - AMS_ASSERT(g_detected_boot_reason); + AMS_ABORT_UNLESS(g_detected_boot_reason); return g_boot_reason; } diff --git a/stratosphere/boot/source/boot_bq24193_charger.hpp b/stratosphere/boot/source/boot_bq24193_charger.hpp index c9f385055..7a59b3f99 100644 --- a/stratosphere/boot/source/boot_bq24193_charger.hpp +++ b/stratosphere/boot/source/boot_bq24193_charger.hpp @@ -40,8 +40,8 @@ namespace ams::boot::bq24193 { constexpr u32 ChargeVoltageLimitMax = 4208; inline u8 EncodeChargeVoltageLimit(u32 voltage) { - AMS_ASSERT(voltage >= ChargeVoltageLimitMin); - AMS_ASSERT(voltage <= ChargeVoltageLimitMax); + AMS_ABORT_UNLESS(voltage >= ChargeVoltageLimitMin); + AMS_ABORT_UNLESS(voltage <= ChargeVoltageLimitMax); voltage -= ChargeVoltageLimitMin; voltage >>= 4; @@ -56,8 +56,8 @@ namespace ams::boot::bq24193 { constexpr u32 FastChargeCurrentLimitMax = 4544; inline u8 EncodeFastChargeCurrentLimit(u32 current) { - AMS_ASSERT(current >= FastChargeCurrentLimitMin); - AMS_ASSERT(current <= FastChargeCurrentLimitMax); + AMS_ABORT_UNLESS(current >= FastChargeCurrentLimitMin); + AMS_ABORT_UNLESS(current <= FastChargeCurrentLimitMax); current -= FastChargeCurrentLimitMin; current >>= 6; @@ -83,8 +83,8 @@ namespace ams::boot::bq24193 { constexpr u32 PreChargeCurrentLimitMax = 2048; inline u8 EncodePreChargeCurrentLimit(u32 current) { - AMS_ASSERT(current >= PreChargeCurrentLimitMin); - AMS_ASSERT(current <= PreChargeCurrentLimitMax); + AMS_ABORT_UNLESS(current >= PreChargeCurrentLimitMin); + AMS_ABORT_UNLESS(current <= PreChargeCurrentLimitMax); current -= PreChargeCurrentLimitMin; current >>= 7; @@ -99,8 +99,8 @@ namespace ams::boot::bq24193 { constexpr u32 TerminationCurrentLimitMax = 2048; inline u8 EncodeTerminationCurrentLimit(u32 current) { - AMS_ASSERT(current >= TerminationCurrentLimitMin); - AMS_ASSERT(current <= TerminationCurrentLimitMax); + AMS_ABORT_UNLESS(current >= TerminationCurrentLimitMin); + AMS_ABORT_UNLESS(current <= TerminationCurrentLimitMax); current -= TerminationCurrentLimitMin; current >>= 7; @@ -115,8 +115,8 @@ namespace ams::boot::bq24193 { constexpr u32 MinimumSystemVoltageLimitMax = 3700; inline u8 EncodeMinimumSystemVoltageLimit(u32 voltage) { - AMS_ASSERT(voltage >= MinimumSystemVoltageLimitMin); - AMS_ASSERT(voltage <= MinimumSystemVoltageLimitMax); + AMS_ABORT_UNLESS(voltage >= MinimumSystemVoltageLimitMin); + AMS_ABORT_UNLESS(voltage <= MinimumSystemVoltageLimitMax); voltage -= MinimumSystemVoltageLimitMin; voltage /= 100; diff --git a/stratosphere/boot/source/boot_calibration.cpp b/stratosphere/boot/source/boot_calibration.cpp index 2322660a9..8ae084e52 100644 --- a/stratosphere/boot/source/boot_calibration.cpp +++ b/stratosphere/boot/source/boot_calibration.cpp @@ -35,7 +35,7 @@ namespace ams::boot { 0xA001, 0x6C00, 0x7800, 0xB401, 0x5000, 0x9C01, 0x8801, 0x4400 }; - AMS_ASSERT(data != nullptr); + AMS_ABORT_UNLESS(data != nullptr); u16 crc16 = 0x55AA; const u8 *data_u8 = reinterpret_cast(data); diff --git a/stratosphere/boot/source/boot_display.cpp b/stratosphere/boot/source/boot_display.cpp index 479c57661..aa5828e8f 100644 --- a/stratosphere/boot/source/boot_display.cpp +++ b/stratosphere/boot/source/boot_display.cpp @@ -126,12 +126,12 @@ namespace ams::boot { armDCacheFlush(g_frame_buffer, FrameBufferSize); /* Create Address Space. */ - R_ASSERT(svcCreateDeviceAddressSpace(&g_dc_das_hnd, 0, (1ul << 32))); + R_ABORT_UNLESS(svcCreateDeviceAddressSpace(&g_dc_das_hnd, 0, (1ul << 32))); /* Attach it to the DC. */ - R_ASSERT(svcAttachDeviceAddressSpace(svc::DeviceName_Dc, g_dc_das_hnd)); + R_ABORT_UNLESS(svcAttachDeviceAddressSpace(svc::DeviceName_Dc, g_dc_das_hnd)); /* Map the framebuffer for the DC as read-only. */ - R_ASSERT(svcMapDeviceAddressSpaceAligned(g_dc_das_hnd, dd::GetCurrentProcessHandle(), frame_buffer_aligned, FrameBufferSize, FrameBufferPaddr, 1)); + R_ABORT_UNLESS(svcMapDeviceAddressSpaceAligned(g_dc_das_hnd, dd::GetCurrentProcessHandle(), frame_buffer_aligned, FrameBufferSize, FrameBufferPaddr, 1)); } } @@ -140,11 +140,11 @@ namespace ams::boot { const uintptr_t frame_buffer_aligned = reinterpret_cast(g_frame_buffer); /* Unmap the framebuffer from the DC. */ - R_ASSERT(svcUnmapDeviceAddressSpace(g_dc_das_hnd, dd::GetCurrentProcessHandle(), frame_buffer_aligned, FrameBufferSize, FrameBufferPaddr)); + R_ABORT_UNLESS(svcUnmapDeviceAddressSpace(g_dc_das_hnd, dd::GetCurrentProcessHandle(), frame_buffer_aligned, FrameBufferSize, FrameBufferPaddr)); /* Detach address space from the DC. */ - R_ASSERT(svcDetachDeviceAddressSpace(svc::DeviceName_Dc, g_dc_das_hnd)); + R_ABORT_UNLESS(svcDetachDeviceAddressSpace(svc::DeviceName_Dc, g_dc_das_hnd)); /* Close the address space. */ - R_ASSERT(svcCloseHandle(g_dc_das_hnd)); + R_ABORT_UNLESS(svcCloseHandle(g_dc_das_hnd)); g_dc_das_hnd = INVALID_HANDLE; g_frame_buffer = nullptr; } diff --git a/stratosphere/boot/source/boot_i2c_utils.cpp b/stratosphere/boot/source/boot_i2c_utils.cpp index 9ca6ebce1..47185d438 100644 --- a/stratosphere/boot/source/boot_i2c_utils.cpp +++ b/stratosphere/boot/source/boot_i2c_utils.cpp @@ -42,21 +42,21 @@ namespace ams::boot { } Result ReadI2cRegister(i2c::driver::Session &session, u8 *dst, size_t dst_size, const u8 *cmd, size_t cmd_size) { - AMS_ASSERT(dst != nullptr && dst_size > 0); - AMS_ASSERT(cmd != nullptr && cmd_size > 0); + AMS_ABORT_UNLESS(dst != nullptr && dst_size > 0); + AMS_ABORT_UNLESS(cmd != nullptr && cmd_size > 0); u8 cmd_list[i2c::CommandListFormatter::MaxCommandListSize]; i2c::CommandListFormatter formatter(cmd_list, sizeof(cmd_list)); - R_ASSERT(formatter.EnqueueSendCommand(I2cTransactionOption_Start, cmd, cmd_size)); - R_ASSERT(formatter.EnqueueReceiveCommand(static_cast(I2cTransactionOption_Start | I2cTransactionOption_Stop), dst_size)); + R_ABORT_UNLESS(formatter.EnqueueSendCommand(I2cTransactionOption_Start, cmd, cmd_size)); + R_ABORT_UNLESS(formatter.EnqueueReceiveCommand(static_cast(I2cTransactionOption_Start | I2cTransactionOption_Stop), dst_size)); return RetryUntilSuccess([&]() { return i2c::driver::ExecuteCommandList(session, dst, dst_size, cmd_list, formatter.GetCurrentSize()); }); } Result WriteI2cRegister(i2c::driver::Session &session, const u8 *src, size_t src_size, const u8 *cmd, size_t cmd_size) { - AMS_ASSERT(src != nullptr && src_size > 0); - AMS_ASSERT(cmd != nullptr && cmd_size > 0); + AMS_ABORT_UNLESS(src != nullptr && src_size > 0); + AMS_ABORT_UNLESS(cmd != nullptr && cmd_size > 0); u8 cmd_list[0x20]; diff --git a/stratosphere/boot/source/boot_main.cpp b/stratosphere/boot/source/boot_main.cpp index beb62a76f..d14059023 100644 --- a/stratosphere/boot/source/boot_main.cpp +++ b/stratosphere/boot/source/boot_main.cpp @@ -90,9 +90,9 @@ void __appInit(void) { /* Initialize services we need (TODO: NCM) */ sm::DoWithSession([&]() { - R_ASSERT(fsInitialize()); - R_ASSERT(splInitialize()); - R_ASSERT(pmshellInitialize()); + R_ABORT_UNLESS(fsInitialize()); + R_ABORT_UNLESS(splInitialize()); + R_ABORT_UNLESS(pmshellInitialize()); }); ams::CheckApiVersion(); @@ -147,7 +147,7 @@ int main(int argc, char **argv) boot::CheckAndRepairBootImages(); /* Tell PM to start boot2. */ - R_ASSERT(pmshellNotifyBootFinished()); + R_ABORT_UNLESS(pmshellNotifyBootFinished()); return 0; } diff --git a/stratosphere/boot/source/boot_pmc_wrapper.cpp b/stratosphere/boot/source/boot_pmc_wrapper.cpp index be38949a9..e88a0ae8f 100644 --- a/stratosphere/boot/source/boot_pmc_wrapper.cpp +++ b/stratosphere/boot/source/boot_pmc_wrapper.cpp @@ -32,19 +32,19 @@ namespace ams::boot { inline u32 ReadWriteRegisterImpl(uintptr_t phys_addr, u32 value, u32 mask) { u32 out_value; - R_ASSERT(spl::smc::ConvertResult(spl::smc::AtmosphereReadWriteRegister(phys_addr, mask, value, &out_value))); + R_ABORT_UNLESS(spl::smc::ConvertResult(spl::smc::AtmosphereReadWriteRegister(phys_addr, mask, value, &out_value))); return out_value; } } u32 ReadPmcRegister(u32 phys_addr) { - AMS_ASSERT(IsValidPmcAddress(phys_addr)); + AMS_ABORT_UNLESS(IsValidPmcAddress(phys_addr)); return ReadWriteRegisterImpl(phys_addr, 0, 0); } void WritePmcRegister(u32 phys_addr, u32 value, u32 mask) { - AMS_ASSERT(IsValidPmcAddress(phys_addr)); + AMS_ABORT_UNLESS(IsValidPmcAddress(phys_addr)); ReadWriteRegisterImpl(phys_addr, value, mask); } diff --git a/stratosphere/boot/source/boot_pmic_driver.cpp b/stratosphere/boot/source/boot_pmic_driver.cpp index dbc4ed408..4b390301b 100644 --- a/stratosphere/boot/source/boot_pmic_driver.cpp +++ b/stratosphere/boot/source/boot_pmic_driver.cpp @@ -19,11 +19,11 @@ namespace ams::boot { void PmicDriver::ShutdownSystem() { - R_ASSERT(this->ShutdownSystem(false)); + R_ABORT_UNLESS(this->ShutdownSystem(false)); } void PmicDriver::RebootSystem() { - R_ASSERT(this->ShutdownSystem(true)); + R_ABORT_UNLESS(this->ShutdownSystem(true)); } Result PmicDriver::GetAcOk(bool *out) { @@ -61,17 +61,17 @@ namespace ams::boot { /* Get value, set or clear software reset mask. */ u8 on_off_2_val = 0; - R_ASSERT(ReadI2cRegister(this->i2c_session, &on_off_2_val, sizeof(on_off_2_val), &on_off_2_addr, sizeof(on_off_2_addr))); + R_ABORT_UNLESS(ReadI2cRegister(this->i2c_session, &on_off_2_val, sizeof(on_off_2_val), &on_off_2_addr, sizeof(on_off_2_addr))); if (reboot) { on_off_2_val |= 0x80; } else { on_off_2_val &= ~0x80; } - R_ASSERT(WriteI2cRegister(this->i2c_session, &on_off_2_val, sizeof(on_off_2_val), &on_off_2_addr, sizeof(on_off_2_addr))); + R_ABORT_UNLESS(WriteI2cRegister(this->i2c_session, &on_off_2_val, sizeof(on_off_2_val), &on_off_2_addr, sizeof(on_off_2_addr))); /* Get value, set software reset mask. */ u8 on_off_1_val = 0; - R_ASSERT(ReadI2cRegister(this->i2c_session, &on_off_1_val, sizeof(on_off_1_val), &on_off_1_addr, sizeof(on_off_1_addr))); + R_ABORT_UNLESS(ReadI2cRegister(this->i2c_session, &on_off_1_val, sizeof(on_off_1_val), &on_off_1_addr, sizeof(on_off_1_addr))); on_off_1_val |= 0x80; /* Finalize the battery. */ @@ -81,11 +81,11 @@ namespace ams::boot { } /* Actually write the value to trigger shutdown/reset. */ - R_ASSERT(WriteI2cRegister(this->i2c_session, &on_off_1_val, sizeof(on_off_1_val), &on_off_1_addr, sizeof(on_off_1_addr))); + R_ABORT_UNLESS(WriteI2cRegister(this->i2c_session, &on_off_1_val, sizeof(on_off_1_val), &on_off_1_addr, sizeof(on_off_1_addr))); /* Allow up to 5 seconds for shutdown/reboot to take place. */ svcSleepThread(5'000'000'000ul); - AMS_ASSERT(false); + AMS_ABORT_UNLESS(false); } void PmicDriver::FinalizeBattery(BatteryDriver *battery_driver) { diff --git a/stratosphere/boot/source/gpio/gpio_initial_configuration.cpp b/stratosphere/boot/source/gpio/gpio_initial_configuration.cpp index abe34f4f8..60a2cc747 100644 --- a/stratosphere/boot/source/gpio/gpio_initial_configuration.cpp +++ b/stratosphere/boot/source/gpio/gpio_initial_configuration.cpp @@ -79,7 +79,7 @@ namespace ams::gpio { } /* Ensure we found an appropriate config. */ - AMS_ASSERT(configs != nullptr); + AMS_ABORT_UNLESS(configs != nullptr); for (size_t i = 0; i < num_configs; i++) { /* Configure the GPIO. */ diff --git a/stratosphere/boot/source/gpio/gpio_utils.cpp b/stratosphere/boot/source/gpio/gpio_utils.cpp index 590899a91..cba922c16 100644 --- a/stratosphere/boot/source/gpio/gpio_utils.cpp +++ b/stratosphere/boot/source/gpio/gpio_utils.cpp @@ -33,7 +33,7 @@ namespace ams::gpio { /* Helpers. */ inline u32 GetPadDescriptor(u32 gpio_pad_name) { - AMS_ASSERT(gpio_pad_name < PadNameMax); + AMS_ABORT_UNLESS(gpio_pad_name < PadNameMax); return Map[gpio_pad_name]; } diff --git a/stratosphere/boot/source/i2c/driver/i2c_api.cpp b/stratosphere/boot/source/i2c/driver/i2c_api.cpp index d95861308..06565597e 100644 --- a/stratosphere/boot/source/i2c/driver/i2c_api.cpp +++ b/stratosphere/boot/source/i2c/driver/i2c_api.cpp @@ -83,7 +83,7 @@ namespace ams::i2c::driver { } inline void CheckInitialized() { - AMS_ASSERT(GetResourceManager().IsInitialized()); + AMS_ABORT_UNLESS(GetResourceManager().IsInitialized()); } } @@ -100,7 +100,7 @@ namespace ams::i2c::driver { /* Session management. */ void OpenSession(Session *out_session, I2cDevice device) { CheckInitialized(); - AMS_ASSERT(impl::IsDeviceSupported(device)); + AMS_ABORT_UNLESS(impl::IsDeviceSupported(device)); const auto bus = impl::GetDeviceBus(device); const auto slave_address = impl::GetDeviceSlaveAddress(device); @@ -119,8 +119,8 @@ namespace ams::i2c::driver { /* Communication. */ Result Send(Session &session, const void *src, size_t size, I2cTransactionOption option) { CheckInitialized(); - AMS_ASSERT(src != nullptr); - AMS_ASSERT(size > 0); + AMS_ABORT_UNLESS(src != nullptr); + AMS_ABORT_UNLESS(size > 0); std::scoped_lock lk(GetResourceManager().GetTransactionMutex(impl::ConvertFromIndex(session.bus_idx))); return GetResourceManager().GetSession(session.session_id).DoTransactionWithRetry(nullptr, src, size, option, impl::Command::Send); @@ -128,8 +128,8 @@ namespace ams::i2c::driver { Result Receive(Session &session, void *dst, size_t size, I2cTransactionOption option) { CheckInitialized(); - AMS_ASSERT(dst != nullptr); - AMS_ASSERT(size > 0); + AMS_ABORT_UNLESS(dst != nullptr); + AMS_ABORT_UNLESS(size > 0); std::scoped_lock lk(GetResourceManager().GetTransactionMutex(impl::ConvertFromIndex(session.bus_idx))); return GetResourceManager().GetSession(session.session_id).DoTransactionWithRetry(dst, nullptr, size, option, impl::Command::Receive); @@ -137,8 +137,8 @@ namespace ams::i2c::driver { Result ExecuteCommandList(Session &session, void *dst, size_t size, const void *cmd_list, size_t cmd_list_size) { CheckInitialized(); - AMS_ASSERT(dst != nullptr && size > 0); - AMS_ASSERT(cmd_list != nullptr && cmd_list_size > 0); + AMS_ABORT_UNLESS(dst != nullptr && size > 0); + AMS_ABORT_UNLESS(cmd_list != nullptr && cmd_list_size > 0); u8 *cur_dst = static_cast(dst); const u8 *cur_cmd = static_cast(cmd_list); @@ -146,7 +146,7 @@ namespace ams::i2c::driver { while (cur_cmd < cmd_list_end) { Command cmd = static_cast((*cur_cmd) & 3); - AMS_ASSERT(cmd < Command::Count); + AMS_ABORT_UNLESS(cmd < Command::Count); R_TRY(g_cmd_handlers[static_cast(cmd)](&cur_cmd, &cur_dst, session)); } diff --git a/stratosphere/boot/source/i2c/driver/impl/i2c_bus_accessor.cpp b/stratosphere/boot/source/i2c/driver/impl/i2c_bus_accessor.cpp index 386a73c33..1cb79f720 100644 --- a/stratosphere/boot/source/i2c/driver/impl/i2c_bus_accessor.cpp +++ b/stratosphere/boot/source/i2c/driver/impl/i2c_bus_accessor.cpp @@ -25,7 +25,7 @@ namespace ams::i2c::driver::impl { /* Ensure we're good if this isn't our first session. */ if (this->open_sessions > 1) { - AMS_ASSERT(this->speed_mode == speed_mode); + AMS_ABORT_UNLESS(this->speed_mode == speed_mode); return; } @@ -240,8 +240,8 @@ namespace ams::i2c::driver::impl { 0x46, 0x74, 0x7C, 0x98, 0x55, 0x5F }; const auto index = ConvertToIndex(bus); - AMS_ASSERT(index < util::size(s_interrupts)); - R_ASSERT(this->interrupt_event.Initialize(s_interrupts[index], false)); + AMS_ABORT_UNLESS(index < util::size(s_interrupts)); + R_ABORT_UNLESS(this->interrupt_event.Initialize(s_interrupts[index], false)); } void BusAccessor::SetClock(SpeedMode speed_mode) { @@ -293,17 +293,17 @@ namespace ams::i2c::driver::impl { reg::Read(&this->i2c_registers->I2C_I2C_CNFG_0); if (this->pcv_module != PcvModule_I2C5) { - R_ASSERT(pcv::SetReset(this->pcv_module, true)); - R_ASSERT(pcv::SetClockRate(this->pcv_module, (408'000'000) / (src_div + 1))); - R_ASSERT(pcv::SetReset(this->pcv_module, false)); + R_ABORT_UNLESS(pcv::SetReset(this->pcv_module, true)); + R_ABORT_UNLESS(pcv::SetClockRate(this->pcv_module, (408'000'000) / (src_div + 1))); + R_ABORT_UNLESS(pcv::SetReset(this->pcv_module, false)); } } void BusAccessor::ResetController() const { if (this->pcv_module != PcvModule_I2C5) { - R_ASSERT(pcv::SetReset(this->pcv_module, true)); - R_ASSERT(pcv::SetClockRate(this->pcv_module, 81'600'000)); - R_ASSERT(pcv::SetReset(this->pcv_module, false)); + R_ABORT_UNLESS(pcv::SetReset(this->pcv_module, true)); + R_ABORT_UNLESS(pcv::SetClockRate(this->pcv_module, 81'600'000)); + R_ABORT_UNLESS(pcv::SetReset(this->pcv_module, false)); } } @@ -362,7 +362,7 @@ namespace ams::i2c::driver::impl { } void BusAccessor::DisableClock() { - R_ASSERT(pcv::SetClockEnabled(this->pcv_module, false)); + R_ABORT_UNLESS(pcv::SetClockEnabled(this->pcv_module, false)); } void BusAccessor::SetPacketMode() { diff --git a/stratosphere/boot/source/i2c/driver/impl/i2c_device_config.cpp b/stratosphere/boot/source/i2c/driver/impl/i2c_device_config.cpp index 11e03e504..e1affe153 100644 --- a/stratosphere/boot/source/i2c/driver/impl/i2c_device_config.cpp +++ b/stratosphere/boot/source/i2c/driver/impl/i2c_device_config.cpp @@ -84,37 +84,37 @@ namespace ams::i2c::driver::impl { Bus GetDeviceBus(I2cDevice dev) { const size_t dev_idx = GetDeviceIndex(dev); - AMS_ASSERT(dev_idx != DeviceInvalidIndex); + AMS_ABORT_UNLESS(dev_idx != DeviceInvalidIndex); return g_device_configs[dev_idx].bus; } u32 GetDeviceSlaveAddress(I2cDevice dev) { const size_t dev_idx = GetDeviceIndex(dev); - AMS_ASSERT(dev_idx != DeviceInvalidIndex); + AMS_ABORT_UNLESS(dev_idx != DeviceInvalidIndex); return g_device_configs[dev_idx].slave_address; } AddressingMode GetDeviceAddressingMode(I2cDevice dev) { const size_t dev_idx = GetDeviceIndex(dev); - AMS_ASSERT(dev_idx != DeviceInvalidIndex); + AMS_ABORT_UNLESS(dev_idx != DeviceInvalidIndex); return g_device_configs[dev_idx].addressing_mode; } SpeedMode GetDeviceSpeedMode(I2cDevice dev) { const size_t dev_idx = GetDeviceIndex(dev); - AMS_ASSERT(dev_idx != DeviceInvalidIndex); + AMS_ABORT_UNLESS(dev_idx != DeviceInvalidIndex); return g_device_configs[dev_idx].speed_mode; } u32 GetDeviceMaxRetries(I2cDevice dev) { const size_t dev_idx = GetDeviceIndex(dev); - AMS_ASSERT(dev_idx != DeviceInvalidIndex); + AMS_ABORT_UNLESS(dev_idx != DeviceInvalidIndex); return g_device_configs[dev_idx].max_retries; } u64 GetDeviceRetryWaitTime(I2cDevice dev) { const size_t dev_idx = GetDeviceIndex(dev); - AMS_ASSERT(dev_idx != DeviceInvalidIndex); + AMS_ABORT_UNLESS(dev_idx != DeviceInvalidIndex); return g_device_configs[dev_idx].retry_wait_time; } diff --git a/stratosphere/boot/source/i2c/driver/impl/i2c_driver_types.hpp b/stratosphere/boot/source/i2c/driver/impl/i2c_driver_types.hpp index ca437c0b9..43d59cb20 100644 --- a/stratosphere/boot/source/i2c/driver/impl/i2c_driver_types.hpp +++ b/stratosphere/boot/source/i2c/driver/impl/i2c_driver_types.hpp @@ -39,7 +39,7 @@ namespace ams::i2c::driver::impl { } constexpr inline Bus ConvertFromIndex(size_t idx) { - AMS_ASSERT(idx < static_cast(Bus::Count)); + AMS_ABORT_UNLESS(idx < static_cast(Bus::Count)); return static_cast(idx); } diff --git a/stratosphere/boot/source/i2c/driver/impl/i2c_resource_manager.cpp b/stratosphere/boot/source/i2c/driver/impl/i2c_resource_manager.cpp index 1cc0675fd..db93a3dfd 100644 --- a/stratosphere/boot/source/i2c/driver/impl/i2c_resource_manager.cpp +++ b/stratosphere/boot/source/i2c/driver/impl/i2c_resource_manager.cpp @@ -25,7 +25,7 @@ namespace ams::i2c::driver::impl { void ResourceManager::Finalize() { std::scoped_lock lk(this->initialize_mutex); - AMS_ASSERT(this->ref_cnt > 0); + AMS_ABORT_UNLESS(this->ref_cnt > 0); this->ref_cnt--; if (this->ref_cnt > 0) { return; @@ -55,11 +55,11 @@ namespace ams::i2c::driver::impl { /* Get, open session. */ { std::scoped_lock lk(this->session_open_mutex); - AMS_ASSERT(out_session != nullptr); - AMS_ASSERT(bus < Bus::Count); + AMS_ABORT_UNLESS(out_session != nullptr); + AMS_ABORT_UNLESS(bus < Bus::Count); session_id = GetFreeSessionId(); - AMS_ASSERT(session_id != InvalidSessionId); + AMS_ABORT_UNLESS(session_id != InvalidSessionId); if ((bus == Bus::I2C2 || bus == Bus::I2C3) && (this->bus_accessors[ConvertToIndex(Bus::I2C2)].GetOpenSessions() == 0 && this->bus_accessors[ConvertToIndex(Bus::I2C3)].GetOpenSessions() == 0)) { @@ -74,8 +74,8 @@ namespace ams::i2c::driver::impl { this->sessions[session_id].Start(); if (need_enable_ldo6) { pcv::Initialize(); - R_ASSERT(pcv::SetVoltageValue(10, 2'900'000)); - R_ASSERT(pcv::SetVoltageEnabled(10, true)); + R_ABORT_UNLESS(pcv::SetVoltageValue(10, 2'900'000)); + R_ABORT_UNLESS(pcv::SetVoltageEnabled(10, true)); pcv::Finalize(); svcSleepThread(560'000ul); } @@ -86,7 +86,7 @@ namespace ams::i2c::driver::impl { /* Get, open session. */ { std::scoped_lock lk(this->session_open_mutex); - AMS_ASSERT(this->sessions[session.session_id].IsOpen()); + AMS_ABORT_UNLESS(this->sessions[session.session_id].IsOpen()); this->sessions[session.session_id].Close(); @@ -98,14 +98,14 @@ namespace ams::i2c::driver::impl { if (need_disable_ldo6) { pcv::Initialize(); - R_ASSERT(pcv::SetVoltageEnabled(10, false)); + R_ABORT_UNLESS(pcv::SetVoltageEnabled(10, false)); pcv::Finalize(); } } void ResourceManager::SuspendBuses() { - AMS_ASSERT(this->ref_cnt > 0); + AMS_ABORT_UNLESS(this->ref_cnt > 0); if (!this->suspended) { { @@ -118,19 +118,19 @@ namespace ams::i2c::driver::impl { } } pcv::Initialize(); - R_ASSERT(pcv::SetVoltageEnabled(10, false)); + R_ABORT_UNLESS(pcv::SetVoltageEnabled(10, false)); pcv::Finalize(); } } void ResourceManager::ResumeBuses() { - AMS_ASSERT(this->ref_cnt > 0); + AMS_ABORT_UNLESS(this->ref_cnt > 0); if (this->suspended) { if (this->bus_accessors[ConvertToIndex(Bus::I2C2)].GetOpenSessions() > 0 || this->bus_accessors[ConvertToIndex(Bus::I2C3)].GetOpenSessions() > 0) { pcv::Initialize(); - R_ASSERT(pcv::SetVoltageValue(10, 2'900'000)); - R_ASSERT(pcv::SetVoltageEnabled(10, true)); + R_ABORT_UNLESS(pcv::SetVoltageValue(10, 2'900'000)); + R_ABORT_UNLESS(pcv::SetVoltageEnabled(10, true)); pcv::Finalize(); svcSleepThread(1'560'000ul); } @@ -147,7 +147,7 @@ namespace ams::i2c::driver::impl { } void ResourceManager::SuspendPowerBus() { - AMS_ASSERT(this->ref_cnt > 0); + AMS_ABORT_UNLESS(this->ref_cnt > 0); std::scoped_lock lk(this->session_open_mutex); if (!this->power_bus_suspended) { @@ -159,7 +159,7 @@ namespace ams::i2c::driver::impl { } void ResourceManager::ResumePowerBus() { - AMS_ASSERT(this->ref_cnt > 0); + AMS_ABORT_UNLESS(this->ref_cnt > 0); std::scoped_lock lk(this->session_open_mutex); if (this->power_bus_suspended) { diff --git a/stratosphere/boot/source/i2c/i2c_command_list.hpp b/stratosphere/boot/source/i2c/i2c_command_list.hpp index 171dbb1d7..cf904b5b7 100644 --- a/stratosphere/boot/source/i2c/i2c_command_list.hpp +++ b/stratosphere/boot/source/i2c/i2c_command_list.hpp @@ -39,7 +39,7 @@ namespace ams::i2c { size_t cur_index = 0; public: CommandListFormatter(void *cmd_list, size_t cmd_list_size) : cmd_list(static_cast(cmd_list)), cmd_list_size(cmd_list_size) { - AMS_ASSERT(cmd_list_size <= MaxCommandListSize); + AMS_ABORT_UNLESS(cmd_list_size <= MaxCommandListSize); } ~CommandListFormatter() { this->cmd_list = nullptr; diff --git a/stratosphere/boot/source/pinmux/pinmux_initial_configuration.cpp b/stratosphere/boot/source/pinmux/pinmux_initial_configuration.cpp index 665d03198..47964833d 100644 --- a/stratosphere/boot/source/pinmux/pinmux_initial_configuration.cpp +++ b/stratosphere/boot/source/pinmux/pinmux_initial_configuration.cpp @@ -62,7 +62,7 @@ namespace ams::pinmux { } /* Ensure we found an appropriate config. */ - AMS_ASSERT(configs != nullptr); + AMS_ABORT_UNLESS(configs != nullptr); for (size_t i = 0; i < num_configs; i++) { UpdatePad(configs[i].name, configs[i].val, configs[i].mask); diff --git a/stratosphere/boot/source/pinmux/pinmux_utils.cpp b/stratosphere/boot/source/pinmux/pinmux_utils.cpp index ba938af24..8c9b0433d 100644 --- a/stratosphere/boot/source/pinmux/pinmux_utils.cpp +++ b/stratosphere/boot/source/pinmux/pinmux_utils.cpp @@ -30,12 +30,12 @@ namespace ams::pinmux { /* Helpers. */ inline const Definition *GetDefinition(u32 pinmux_name) { - AMS_ASSERT(pinmux_name < PadNameMax); + AMS_ABORT_UNLESS(pinmux_name < PadNameMax); return &Map[pinmux_name]; } inline const DrivePadDefinition *GetDrivePadDefinition(u32 drivepad_name) { - AMS_ASSERT(drivepad_name < DrivePadNameMax); + AMS_ABORT_UNLESS(drivepad_name < DrivePadNameMax); return &DrivePadMap[drivepad_name]; } @@ -101,7 +101,7 @@ namespace ams::pinmux { u32 pinmux_val = reg::Read(pinmux_reg); /* This PINMUX register is locked */ - AMS_ASSERT((pinmux_val & 0x80) == 0); + AMS_ABORT_UNLESS((pinmux_val & 0x80) == 0); u32 pm_val = (pinmux_config_val & 0x07); diff --git a/stratosphere/boot2/source/boot2_main.cpp b/stratosphere/boot2/source/boot2_main.cpp index 19525fcda..00f62adc8 100644 --- a/stratosphere/boot2/source/boot2_main.cpp +++ b/stratosphere/boot2/source/boot2_main.cpp @@ -71,15 +71,15 @@ void __appInit(void) { /* Initialize services we need. */ sm::DoWithSession([&]() { - R_ASSERT(fsInitialize()); - R_ASSERT(pmbmInitialize()); - R_ASSERT(pminfoInitialize()); - R_ASSERT(pmshellInitialize()); - R_ASSERT(setsysInitialize()); - R_ASSERT(gpioInitialize()); + R_ABORT_UNLESS(fsInitialize()); + R_ABORT_UNLESS(pmbmInitialize()); + R_ABORT_UNLESS(pminfoInitialize()); + R_ABORT_UNLESS(pmshellInitialize()); + R_ABORT_UNLESS(setsysInitialize()); + R_ABORT_UNLESS(gpioInitialize()); }); - R_ASSERT(fsdevMountSdmc()); + R_ABORT_UNLESS(fsdevMountSdmc()); ams::CheckApiVersion(); } diff --git a/stratosphere/creport/source/creport_main.cpp b/stratosphere/creport/source/creport_main.cpp index 8cd578b9c..025210fc6 100644 --- a/stratosphere/creport/source/creport_main.cpp +++ b/stratosphere/creport/source/creport_main.cpp @@ -72,10 +72,10 @@ void __appInit(void) { hos::SetVersionForLibnx(); sm::DoWithSession([&]() { - R_ASSERT(fsInitialize()); + R_ABORT_UNLESS(fsInitialize()); }); - R_ASSERT(fsdevMountSdmc()); + R_ABORT_UNLESS(fsdevMountSdmc()); } void __appExit(void) { diff --git a/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_api.cpp b/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_api.cpp index 9c9f73469..3b3ede1ab 100644 --- a/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_api.cpp +++ b/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_api.cpp @@ -123,10 +123,10 @@ namespace ams::dmnt::cheat::impl { void CloseActiveCheatProcess() { if (this->cheat_process_debug_handle != INVALID_HANDLE) { /* Knock out the debug events thread. */ - R_ASSERT(this->debug_events_thread.CancelSynchronization()); + R_ABORT_UNLESS(this->debug_events_thread.CancelSynchronization()); /* Close resources. */ - R_ASSERT(svcCloseHandle(this->cheat_process_debug_handle)); + R_ABORT_UNLESS(svcCloseHandle(this->cheat_process_debug_handle)); this->cheat_process_debug_handle = INVALID_HANDLE; /* Save cheat toggles. */ @@ -176,18 +176,18 @@ namespace ams::dmnt::cheat::impl { Handle HookToCreateApplicationProcess() const { Handle h = INVALID_HANDLE; - R_ASSERT(pm::dmnt::HookToCreateApplicationProcess(&h)); + R_ABORT_UNLESS(pm::dmnt::HookToCreateApplicationProcess(&h)); return h; } void StartProcess(os::ProcessId process_id) const { - R_ASSERT(pm::dmnt::StartProcess(process_id)); + R_ABORT_UNLESS(pm::dmnt::StartProcess(process_id)); } public: CheatProcessManager() { /* Create cheat process detection event. */ - R_ASSERT(this->cheat_process_event.InitializeAsInterProcessEvent()); + R_ABORT_UNLESS(this->cheat_process_event.InitializeAsInterProcessEvent()); /* Learn whether we should enable cheats by default. */ { @@ -203,14 +203,14 @@ namespace ams::dmnt::cheat::impl { } /* Spawn application detection thread, spawn cheat vm thread. */ - R_ASSERT(this->detect_thread.Initialize(&CheatProcessManager::DetectLaunchThread, this, this->detect_thread_stack, ThreadStackSize, DetectThreadPriority)); - R_ASSERT(this->vm_thread.Initialize(&CheatProcessManager::VirtualMachineThread, this, this->vm_thread_stack, ThreadStackSize, VirtualMachineThreadPriority)); - R_ASSERT(this->debug_events_thread.Initialize(&CheatProcessManager::DebugEventsThread, this, this->debug_events_thread_stack, ThreadStackSize, DebugEventsThreadPriority)); + R_ABORT_UNLESS(this->detect_thread.Initialize(&CheatProcessManager::DetectLaunchThread, this, this->detect_thread_stack, ThreadStackSize, DetectThreadPriority)); + R_ABORT_UNLESS(this->vm_thread.Initialize(&CheatProcessManager::VirtualMachineThread, this, this->vm_thread_stack, ThreadStackSize, VirtualMachineThreadPriority)); + R_ABORT_UNLESS(this->debug_events_thread.Initialize(&CheatProcessManager::DebugEventsThread, this, this->debug_events_thread_stack, ThreadStackSize, DebugEventsThreadPriority)); /* Start threads. */ - R_ASSERT(this->detect_thread.Start()); - R_ASSERT(this->vm_thread.Start()); - R_ASSERT(this->debug_events_thread.Start()); + R_ABORT_UNLESS(this->detect_thread.Start()); + R_ABORT_UNLESS(this->vm_thread.Start()); + R_ABORT_UNLESS(this->debug_events_thread.Start()); } bool GetHasActiveCheatProcess() { @@ -588,9 +588,9 @@ namespace ams::dmnt::cheat::impl { } } - #define R_ASSERT_IF_NEW_PROCESS(res) \ + #define R_ABORT_UNLESS_IF_NEW_PROCESS(res) \ if (on_process_launch) { \ - R_ASSERT(res); \ + R_ABORT_UNLESS(res); \ } else { \ R_TRY(res); \ } @@ -610,7 +610,7 @@ namespace ams::dmnt::cheat::impl { } /* Get the application process's ID. */ - R_ASSERT_IF_NEW_PROCESS(pm::dmnt::GetApplicationProcessId(&this->cheat_process_metadata.process_id)); + R_ABORT_UNLESS_IF_NEW_PROCESS(pm::dmnt::GetApplicationProcessId(&this->cheat_process_metadata.process_id)); auto proc_guard = SCOPE_GUARD { if (on_process_launch) { this->StartProcess(this->cheat_process_metadata.process_id); @@ -623,14 +623,14 @@ namespace ams::dmnt::cheat::impl { Handle proc_h = INVALID_HANDLE; ncm::ProgramLocation loc = {}; cfg::OverrideStatus status = {}; - ON_SCOPE_EXIT { if (proc_h != INVALID_HANDLE) { R_ASSERT(svcCloseHandle(proc_h)); } }; + ON_SCOPE_EXIT { if (proc_h != INVALID_HANDLE) { R_ABORT_UNLESS(svcCloseHandle(proc_h)); } }; - R_ASSERT_IF_NEW_PROCESS(pm::dmnt::AtmosphereGetProcessInfo(&proc_h, &loc, &status, this->cheat_process_metadata.process_id)); + R_ABORT_UNLESS_IF_NEW_PROCESS(pm::dmnt::AtmosphereGetProcessInfo(&proc_h, &loc, &status, this->cheat_process_metadata.process_id)); this->cheat_process_metadata.program_id = loc.program_id; { map::AddressSpaceInfo as_info; - R_ASSERT(map::GetProcessAddressSpaceInfo(&as_info, proc_h)); + R_ABORT_UNLESS(map::GetProcessAddressSpaceInfo(&as_info, proc_h)); this->cheat_process_metadata.heap_extents.base = as_info.heap_base; this->cheat_process_metadata.heap_extents.size = as_info.heap_size; this->cheat_process_metadata.alias_extents.base = as_info.alias_base; @@ -651,7 +651,7 @@ namespace ams::dmnt::cheat::impl { s32 num_modules; /* TODO: ldr::dmnt:: */ - R_ASSERT_IF_NEW_PROCESS(ldrDmntGetProcessModuleInfo(static_cast(this->cheat_process_metadata.process_id), proc_modules, util::size(proc_modules), &num_modules)); + R_ABORT_UNLESS_IF_NEW_PROCESS(ldrDmntGetProcessModuleInfo(static_cast(this->cheat_process_metadata.process_id), proc_modules, util::size(proc_modules), &num_modules)); /* All applications must have two modules. */ /* Only accept one (which means we're attaching to HBL) */ @@ -678,7 +678,7 @@ namespace ams::dmnt::cheat::impl { } /* Open a debug handle. */ - R_ASSERT_IF_NEW_PROCESS(svcDebugActiveProcess(&this->cheat_process_debug_handle, static_cast(this->cheat_process_metadata.process_id))); + R_ABORT_UNLESS_IF_NEW_PROCESS(svcDebugActiveProcess(&this->cheat_process_debug_handle, static_cast(this->cheat_process_metadata.process_id))); /* Cancel process guard. */ proc_guard.Cancel(); @@ -697,7 +697,7 @@ namespace ams::dmnt::cheat::impl { return ResultSuccess(); } - #undef R_ASSERT_IF_NEW_PROCESS + #undef R_ABORT_UNLESS_IF_NEW_PROCESS bool CheatProcessManager::ParseCheats(const char *s, size_t len) { /* Trigger a VM reload. */ diff --git a/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_debug_events_manager.cpp b/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_debug_events_manager.cpp index 095fbe27f..6abb50762 100644 --- a/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_debug_events_manager.cpp +++ b/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_debug_events_manager.cpp @@ -42,7 +42,7 @@ namespace ams::dmnt::cheat::impl { Handle debug_handle = this_ptr->WaitReceiveHandle(current_core); /* Continue events on the correct core. */ - R_ASSERT(this_ptr->ContinueDebugEvent(debug_handle)); + R_ABORT_UNLESS(this_ptr->ContinueDebugEvent(debug_handle)); /* Signal that we've continued. */ this_ptr->SignalContinued(); @@ -57,7 +57,7 @@ namespace ams::dmnt::cheat::impl { if (dbg_event.type == svc::DebugEvent_AttachThread) { u64 out64 = 0; u32 out32 = 0; - R_ASSERT(svcGetDebugThreadParam(&out64, &out32, debug_handle, dbg_event.info.attach_thread.thread_id, DebugThreadParam_CurrentCore)); + R_ABORT_UNLESS(svcGetDebugThreadParam(&out64, &out32, debug_handle, dbg_event.info.attach_thread.thread_id, DebugThreadParam_CurrentCore)); target_core = out32; } @@ -94,13 +94,13 @@ namespace ams::dmnt::cheat::impl { DebugEventsManager() : message_queues{os::MessageQueue(1), os::MessageQueue(1), os::MessageQueue(1), os::MessageQueue(1)}, thread_stacks{} { for (size_t i = 0; i < NumCores; i++) { /* Create thread. */ - R_ASSERT(this->threads[i].Initialize(&DebugEventsManager::PerCoreThreadFunction, reinterpret_cast(this), this->thread_stacks[i], ThreadStackSize, ThreadPriority, i)); + R_ABORT_UNLESS(this->threads[i].Initialize(&DebugEventsManager::PerCoreThreadFunction, reinterpret_cast(this), this->thread_stacks[i], ThreadStackSize, ThreadPriority, i)); /* Set core mask. */ - R_ASSERT(svcSetThreadCoreMask(this->threads[i].GetHandle(), i, (1u << i))); + R_ABORT_UNLESS(svcSetThreadCoreMask(this->threads[i].GetHandle(), i, (1u << i))); /* Start thread. */ - R_ASSERT(this->threads[i].Start()); + R_ABORT_UNLESS(this->threads[i].Start()); } } diff --git a/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_vm.cpp b/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_vm.cpp index 2bf053bef..f568d7970 100644 --- a/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_vm.cpp +++ b/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_vm.cpp @@ -630,7 +630,7 @@ namespace ams::dmnt::cheat::impl { /* However, I don't actually believe it is possible for this to happen. */ /* I guess we'll throw a fatal error here, so as to encourage me to fix the VM */ /* in the event that someone triggers it? I don't know how you'd do that. */ - R_ASSERT(ResultVirtualMachineInvalidConditionDepth()); + R_ABORT_UNLESS(ResultVirtualMachineInvalidConditionDepth()); } } diff --git a/stratosphere/dmnt/source/dmnt_main.cpp b/stratosphere/dmnt/source/dmnt_main.cpp index be2c1cc5f..25ab804f6 100644 --- a/stratosphere/dmnt/source/dmnt_main.cpp +++ b/stratosphere/dmnt/source/dmnt_main.cpp @@ -63,22 +63,22 @@ void __appInit(void) { hos::SetVersionForLibnx(); sm::DoWithSession([&]() { - R_ASSERT(pmdmntInitialize()); - R_ASSERT(pminfoInitialize()); - R_ASSERT(ldrDmntInitialize()); + R_ABORT_UNLESS(pmdmntInitialize()); + R_ABORT_UNLESS(pminfoInitialize()); + R_ABORT_UNLESS(ldrDmntInitialize()); /* TODO: We provide this on every sysver via ro. Do we need a shim? */ if (hos::GetVersion() >= hos::Version_300) { - R_ASSERT(roDmntInitialize()); + R_ABORT_UNLESS(roDmntInitialize()); } - R_ASSERT(nsdevInitialize()); - R_ASSERT(lrInitialize()); - R_ASSERT(setInitialize()); - R_ASSERT(setsysInitialize()); - R_ASSERT(hidInitialize()); - R_ASSERT(fsInitialize()); + R_ABORT_UNLESS(nsdevInitialize()); + R_ABORT_UNLESS(lrInitialize()); + R_ABORT_UNLESS(setInitialize()); + R_ABORT_UNLESS(setsysInitialize()); + R_ABORT_UNLESS(hidInitialize()); + R_ABORT_UNLESS(fsInitialize()); }); - R_ASSERT(fsdevMountSdmc()); + R_ABORT_UNLESS(fsdevMountSdmc()); ams::CheckApiVersion(); } @@ -132,8 +132,8 @@ int main(int argc, char **argv) { /* Create services. */ /* TODO: Implement rest of dmnt:- in ams.tma development branch. */ - /* R_ASSERT((g_server_manager.RegisterServer(DebugMonitorServiceName, DebugMonitorMaxSessions))); */ - R_ASSERT((g_server_manager.RegisterServer(CheatServiceName, CheatMaxSessions))); + /* R_ABORT_UNLESS((g_server_manager.RegisterServer(DebugMonitorServiceName, DebugMonitorMaxSessions))); */ + R_ABORT_UNLESS((g_server_manager.RegisterServer(CheatServiceName, CheatMaxSessions))); /* Loop forever, servicing our services. */ /* Nintendo loops four threads processing on the manager -- we'll loop an extra fifth for our cheat service. */ @@ -143,14 +143,14 @@ int main(int argc, char **argv) if constexpr (NumExtraThreads > 0) { const u32 priority = os::GetCurrentThreadPriority(); for (size_t i = 0; i < NumExtraThreads; i++) { - R_ASSERT(g_extra_threads[i].Initialize(LoopServerThread, nullptr, g_extra_thread_stacks[i], ThreadStackSize, priority)); + R_ABORT_UNLESS(g_extra_threads[i].Initialize(LoopServerThread, nullptr, g_extra_thread_stacks[i], ThreadStackSize, priority)); } } /* Start extra threads. */ if constexpr (NumExtraThreads > 0) { for (size_t i = 0; i < NumExtraThreads; i++) { - R_ASSERT(g_extra_threads[i].Start()); + R_ABORT_UNLESS(g_extra_threads[i].Start()); } } @@ -160,7 +160,7 @@ int main(int argc, char **argv) /* Wait for extra threads to finish. */ if constexpr (NumExtraThreads > 0) { for (size_t i = 0; i < NumExtraThreads; i++) { - R_ASSERT(g_extra_threads[i].Join()); + R_ABORT_UNLESS(g_extra_threads[i].Join()); } } } diff --git a/stratosphere/fatal/source/fatal_config.cpp b/stratosphere/fatal/source/fatal_config.cpp index 27312aad4..85c251213 100644 --- a/stratosphere/fatal/source/fatal_config.cpp +++ b/stratosphere/fatal/source/fatal_config.cpp @@ -25,7 +25,7 @@ namespace ams::fatal::srv { /* Event creator. */ Handle GetFatalDirtyEventReadableHandle() { Event evt; - R_ASSERT(setsysBindFatalDirtyFlagEvent(&evt)); + R_ABORT_UNLESS(setsysBindFatalDirtyFlagEvent(&evt)); return evt.revent; } diff --git a/stratosphere/fatal/source/fatal_event_manager.cpp b/stratosphere/fatal/source/fatal_event_manager.cpp index 41e5d75a9..eabbe1e69 100644 --- a/stratosphere/fatal/source/fatal_event_manager.cpp +++ b/stratosphere/fatal/source/fatal_event_manager.cpp @@ -20,7 +20,7 @@ namespace ams::fatal::srv { FatalEventManager::FatalEventManager() { /* Just create all the events. */ for (size_t i = 0; i < FatalEventManager::NumFatalEvents; i++) { - R_ASSERT(eventCreate(&this->events[i], true)); + R_ABORT_UNLESS(eventCreate(&this->events[i], true)); } } diff --git a/stratosphere/fatal/source/fatal_main.cpp b/stratosphere/fatal/source/fatal_main.cpp index 5f73ce62a..50afb99a1 100644 --- a/stratosphere/fatal/source/fatal_main.cpp +++ b/stratosphere/fatal/source/fatal_main.cpp @@ -76,27 +76,27 @@ void __appInit(void) { hos::SetVersionForLibnx(); sm::DoWithSession([&]() { - R_ASSERT(setInitialize()); - R_ASSERT(setsysInitialize()); - R_ASSERT(pminfoInitialize()); - R_ASSERT(i2cInitialize()); - R_ASSERT(bpcInitialize()); + R_ABORT_UNLESS(setInitialize()); + R_ABORT_UNLESS(setsysInitialize()); + R_ABORT_UNLESS(pminfoInitialize()); + R_ABORT_UNLESS(i2cInitialize()); + R_ABORT_UNLESS(bpcInitialize()); if (hos::GetVersion() >= hos::Version_800) { - R_ASSERT(clkrstInitialize()); + R_ABORT_UNLESS(clkrstInitialize()); } else { - R_ASSERT(pcvInitialize()); + R_ABORT_UNLESS(pcvInitialize()); } - R_ASSERT(lblInitialize()); - R_ASSERT(psmInitialize()); - R_ASSERT(spsmInitialize()); - R_ASSERT(plInitialize()); - R_ASSERT(gpioInitialize()); - R_ASSERT(fsInitialize()); + R_ABORT_UNLESS(lblInitialize()); + R_ABORT_UNLESS(psmInitialize()); + R_ABORT_UNLESS(spsmInitialize()); + R_ABORT_UNLESS(plInitialize()); + R_ABORT_UNLESS(gpioInitialize()); + R_ABORT_UNLESS(fsInitialize()); }); - R_ASSERT(fsdevMountSdmc()); + R_ABORT_UNLESS(fsdevMountSdmc()); /* fatal cannot throw fatal, so don't do: ams::CheckApiVersion(); */ } @@ -144,14 +144,14 @@ namespace { int main(int argc, char **argv) { /* Load shared font. */ - R_ASSERT(fatal::srv::font::InitializeSharedFont()); + R_ABORT_UNLESS(fatal::srv::font::InitializeSharedFont()); /* Check whether we should throw fatal due to repair process. */ fatal::srv::CheckRepairStatus(); /* Create services. */ - R_ASSERT((g_server_manager.RegisterServer(PrivateServiceName, PrivateMaxSessions))); - R_ASSERT((g_server_manager.RegisterServer(UserServiceName, UserMaxSessions))); + R_ABORT_UNLESS((g_server_manager.RegisterServer(PrivateServiceName, PrivateMaxSessions))); + R_ABORT_UNLESS((g_server_manager.RegisterServer(UserServiceName, UserMaxSessions))); /* Add dirty event holder. */ /* TODO: s_server_manager.AddWaitable(ams::fatal::srv::GetFatalDirtyEvent()); */ @@ -167,7 +167,7 @@ int main(int argc, char **argv) g_server_manager.AddUserWaitableHolder(signaled_holder); } else { /* A server/session was signaled. Have the manager handle it. */ - R_ASSERT(g_server_manager.Process(signaled_holder)); + R_ABORT_UNLESS(g_server_manager.Process(signaled_holder)); } } diff --git a/stratosphere/fatal/source/fatal_service.cpp b/stratosphere/fatal/source/fatal_service.cpp index 2f36e430c..3f895cac6 100644 --- a/stratosphere/fatal/source/fatal_service.cpp +++ b/stratosphere/fatal/source/fatal_service.cpp @@ -39,8 +39,8 @@ namespace ams::fatal::srv { public: ServiceContext() { this->context.ClearState(); - R_ASSERT(eventCreate(&this->context.erpt_event, false)); - R_ASSERT(eventCreate(&this->context.battery_event, false)); + R_ABORT_UNLESS(eventCreate(&this->context.erpt_event, false)); + R_ABORT_UNLESS(eventCreate(&this->context.battery_event, false)); this->has_thrown = false; } diff --git a/stratosphere/fatal/source/fatal_task.cpp b/stratosphere/fatal/source/fatal_task.cpp index 13069b784..725d14b36 100644 --- a/stratosphere/fatal/source/fatal_task.cpp +++ b/stratosphere/fatal/source/fatal_task.cpp @@ -42,8 +42,8 @@ namespace ams::fatal::srv { public: TaskThread() { /* ... */ } void StartTask(ITask *task) { - R_ASSERT(this->thread.Initialize(&RunTaskImpl, task, task->GetStack(), task->GetStackSize(), TaskThreadPriority)); - R_ASSERT(this->thread.Start()); + R_ABORT_UNLESS(this->thread.Initialize(&RunTaskImpl, task, task->GetStack(), task->GetStackSize(), TaskThreadPriority)); + R_ABORT_UNLESS(this->thread.Start()); } }; @@ -57,7 +57,7 @@ namespace ams::fatal::srv { public: TaskManager() { /* ... */ } void StartTask(ITask *task) { - AMS_ASSERT(this->task_count < MaxTasks); + AMS_ABORT_UNLESS(this->task_count < MaxTasks); this->task_threads[this->task_count++].StartTask(task); } }; diff --git a/stratosphere/fatal/source/fatal_task_screen.cpp b/stratosphere/fatal/source/fatal_task_screen.cpp index 460a823b7..5b94b9e2a 100644 --- a/stratosphere/fatal/source/fatal_task_screen.cpp +++ b/stratosphere/fatal/source/fatal_task_screen.cpp @@ -182,7 +182,7 @@ namespace ams::fatal::srv { /* Prepare screen for drawing. */ sm::DoWithSession([&]() { - R_ASSERT(PrepareScreenForDrawing()); + R_ABORT_UNLESS(PrepareScreenForDrawing()); }); /* Dequeue a buffer. */ diff --git a/stratosphere/loader/source/ldr_content_management.cpp b/stratosphere/loader/source/ldr_content_management.cpp index 0fefd4060..31cccea05 100644 --- a/stratosphere/loader/source/ldr_content_management.cpp +++ b/stratosphere/loader/source/ldr_content_management.cpp @@ -56,7 +56,7 @@ namespace ams::ldr { Result MountNspFileSystem(const char *device_name, const char *path) { FsFileSystem fs; R_TRY(fsOpenFileSystemWithId(&fs, 0, FsFileSystemType_ApplicationPackage, path)); - AMS_ASSERT(fsdevMountDevice(device_name, fs) >= 0); + AMS_ABORT_UNLESS(fsdevMountDevice(device_name, fs) >= 0); return ResultSuccess(); } @@ -150,7 +150,7 @@ namespace ams::ldr { /* Try to mount the content path. */ FsFileSystem fs; R_TRY(fsldrOpenCodeFileSystem(static_cast(loc.program_id), path, &fs)); - AMS_ASSERT(fsdevMountDevice(CodeFileSystemDeviceName, fs) != -1); + AMS_ABORT_UNLESS(fsdevMountDevice(CodeFileSystemDeviceName, fs) != -1); /* Note that we mounted code. */ this->is_code_mounted = true; @@ -190,7 +190,7 @@ namespace ams::ldr { /* Check if we're ready to mount the SD card. */ if (!g_has_mounted_sd_card) { if (is_sd_initialized) { - R_ASSERT(MountSdCardFileSystem()); + R_ABORT_UNLESS(MountSdCardFileSystem()); g_has_mounted_sd_card = true; } } @@ -219,7 +219,7 @@ namespace ams::ldr { } void ScopedCodeMount::InitializeOverrideStatus(const ncm::ProgramLocation &loc) { - AMS_ASSERT(!this->has_status); + AMS_ABORT_UNLESS(!this->has_status); this->override_status = cfg::CaptureOverrideStatus(loc.program_id); this->has_status = true; } diff --git a/stratosphere/loader/source/ldr_content_management.hpp b/stratosphere/loader/source/ldr_content_management.hpp index ce6fc7e11..9aa0f0a96 100644 --- a/stratosphere/loader/source/ldr_content_management.hpp +++ b/stratosphere/loader/source/ldr_content_management.hpp @@ -45,7 +45,7 @@ namespace ams::ldr { } const cfg::OverrideStatus &GetOverrideStatus() const { - AMS_ASSERT(this->has_status); + AMS_ABORT_UNLESS(this->has_status); return this->override_status; } diff --git a/stratosphere/loader/source/ldr_ecs.cpp b/stratosphere/loader/source/ldr_ecs.cpp index abb0267a4..29127e870 100644 --- a/stratosphere/loader/source/ldr_ecs.cpp +++ b/stratosphere/loader/source/ldr_ecs.cpp @@ -92,7 +92,7 @@ namespace ams::ldr::ecs { R_UNLESS(g_map.size() < MaxExternalContentSourceCount, ldr::ResultTooManyArguments()); /* Clear any sources. */ - R_ASSERT(Clear(program_id)); + R_ABORT_UNLESS(Clear(program_id)); /* Generate mountpoint. */ char device_name[DeviceNameSizeMax]; diff --git a/stratosphere/loader/source/ldr_loader_service.cpp b/stratosphere/loader/source/ldr_loader_service.cpp index c3f1574e9..2f4405a6c 100644 --- a/stratosphere/loader/source/ldr_loader_service.cpp +++ b/stratosphere/loader/source/ldr_loader_service.cpp @@ -102,7 +102,7 @@ namespace ams::ldr { } void LoaderService::AtmosphereClearExternalContentSource(ncm::ProgramId program_id) { - R_ASSERT(ecs::Clear(program_id)); + R_ABORT_UNLESS(ecs::Clear(program_id)); } void LoaderService::AtmosphereHasLaunchedProgram(sf::Out out, ncm::ProgramId program_id) { diff --git a/stratosphere/loader/source/ldr_main.cpp b/stratosphere/loader/source/ldr_main.cpp index 17c0b6797..b9c5b5162 100644 --- a/stratosphere/loader/source/ldr_main.cpp +++ b/stratosphere/loader/source/ldr_main.cpp @@ -72,9 +72,9 @@ void __appInit(void) { /* Initialize services we need. */ sm::DoWithSession([&]() { - R_ASSERT(fsInitialize()); - R_ASSERT(lrInitialize()); - R_ASSERT(fsldrInitialize()); + R_ABORT_UNLESS(fsInitialize()); + R_ABORT_UNLESS(lrInitialize()); + R_ABORT_UNLESS(fsldrInitialize()); }); ams::CheckApiVersion(); @@ -115,9 +115,9 @@ namespace { int main(int argc, char **argv) { /* Add services to manager. */ - R_ASSERT((g_server_manager.RegisterServer(ProcessManagerServiceName, ProcessManagerMaxSessions))); - R_ASSERT((g_server_manager.RegisterServer(ShellServiceName, ShellMaxSessions))); - R_ASSERT((g_server_manager.RegisterServer(DebugMonitorServiceName, DebugMonitorMaxSessions))); + R_ABORT_UNLESS((g_server_manager.RegisterServer(ProcessManagerServiceName, ProcessManagerMaxSessions))); + R_ABORT_UNLESS((g_server_manager.RegisterServer(ShellServiceName, ShellMaxSessions))); + R_ABORT_UNLESS((g_server_manager.RegisterServer(DebugMonitorServiceName, DebugMonitorMaxSessions))); /* Loop forever, servicing our services. */ g_server_manager.LoopProcess(); diff --git a/stratosphere/loader/source/ldr_process_creation.cpp b/stratosphere/loader/source/ldr_process_creation.cpp index 769d656e1..a6e156e1f 100644 --- a/stratosphere/loader/source/ldr_process_creation.cpp +++ b/stratosphere/loader/source/ldr_process_creation.cpp @@ -48,7 +48,7 @@ namespace ams::ldr { }; constexpr const char *GetNsoName(size_t idx) { - AMS_ASSERT(idx < Nso_Count); + AMS_ABORT_UNLESS(idx < Nso_Count); constexpr const char *NsoNames[Nso_Count] = { "rtld", @@ -606,7 +606,7 @@ namespace ams::ldr { } /* Clear the ECS entry for the program. */ - R_ASSERT(ecs::Clear(loc.program_id)); + R_ABORT_UNLESS(ecs::Clear(loc.program_id)); /* Note that we've created the program. */ SetLaunchedProgram(loc.program_id); diff --git a/stratosphere/pm/source/impl/pm_process_manager.cpp b/stratosphere/pm/source/impl/pm_process_manager.cpp index a9b674e8c..a403c7820 100644 --- a/stratosphere/pm/source/impl/pm_process_manager.cpp +++ b/stratosphere/pm/source/impl/pm_process_manager.cpp @@ -165,8 +165,8 @@ namespace ams::pm::impl { std::scoped_lock lk(this->lock); const size_t index = this->GetProcessInfoIndex(process_info); - AMS_ASSERT(index < MaxProcessInfos); - AMS_ASSERT(this->process_info_allocated[index]); + AMS_ABORT_UNLESS(index < MaxProcessInfos); + AMS_ABORT_UNLESS(this->process_info_allocated[index]); process_info->~ProcessInfo(); this->process_info_allocated[index] = false; @@ -308,7 +308,7 @@ namespace ams::pm::impl { /* Make new process info. */ void *process_info_storage = g_process_info_allocator.AllocateProcessInfoStorage(); - AMS_ASSERT(process_info_storage != nullptr); + AMS_ABORT_UNLESS(process_info_storage != nullptr); ProcessInfo *process_info = new (process_info_storage) ProcessInfo(process_handle, process_id, pin_id, location, override_status); /* Link new process info. */ @@ -374,7 +374,7 @@ namespace ams::pm::impl { const ProcessState old_state = process_info->GetState(); { u64 tmp = 0; - R_ASSERT(svcGetProcessInfo(&tmp, process_info->GetHandle(), ProcessInfoType_ProcessState)); + R_ABORT_UNLESS(svcGetProcessInfo(&tmp, process_info->GetHandle(), ProcessInfoType_ProcessState)); process_info->SetState(static_cast(tmp)); } const ProcessState new_state = process_info->GetState(); @@ -452,16 +452,16 @@ namespace ams::pm::impl { /* Initialization. */ Result InitializeProcessManager() { /* Create events. */ - R_ASSERT(g_process_event.InitializeAsInterProcessEvent()); - R_ASSERT(g_hook_to_create_process_event.InitializeAsInterProcessEvent()); - R_ASSERT(g_hook_to_create_application_process_event.InitializeAsInterProcessEvent()); - R_ASSERT(g_boot_finished_event.InitializeAsInterProcessEvent()); + R_ABORT_UNLESS(g_process_event.InitializeAsInterProcessEvent()); + R_ABORT_UNLESS(g_hook_to_create_process_event.InitializeAsInterProcessEvent()); + R_ABORT_UNLESS(g_hook_to_create_application_process_event.InitializeAsInterProcessEvent()); + R_ABORT_UNLESS(g_boot_finished_event.InitializeAsInterProcessEvent()); /* Initialize resource limits. */ R_TRY(resource::InitializeResourceManager()); /* Start thread. */ - R_ASSERT(g_process_track_thread.Start()); + R_ABORT_UNLESS(g_process_track_thread.Start()); return ResultSuccess(); } @@ -711,7 +711,7 @@ namespace ams::pm::impl { /* In 8.0.0, Nintendo added this command, which signals that the boot sysmodule has finished. */ /* Nintendo only signals it in safe mode FIRM, and this function aborts on normal FIRM. */ /* We will signal it always, but only allow this function to succeed on safe mode. */ - AMS_ASSERT(spl::IsRecoveryBoot()); + AMS_ABORT_UNLESS(spl::IsRecoveryBoot()); *out = g_boot_finished_event.GetReadableHandle(); return ResultSuccess(); } diff --git a/stratosphere/pm/source/impl/pm_resource_manager.cpp b/stratosphere/pm/source/impl/pm_resource_manager.cpp index a6d639632..48132b641 100644 --- a/stratosphere/pm/source/impl/pm_resource_manager.cpp +++ b/stratosphere/pm/source/impl/pm_resource_manager.cpp @@ -147,7 +147,7 @@ namespace ams::pm::resource { u64 value = 0; while (true) { - R_ASSERT(svcGetResourceLimitCurrentValue(&value, reslimit_hnd, resource)); + R_ABORT_UNLESS(svcGetResourceLimitCurrentValue(&value, reslimit_hnd, resource)); if (value == 0) { break; } @@ -159,7 +159,7 @@ namespace ams::pm::resource { void WaitApplicationMemoryAvailable() { u64 value = 0; while (true) { - R_ASSERT(svcGetSystemInfo(&value, SystemInfoType_UsedPhysicalMemorySize, INVALID_HANDLE, PhysicalMemoryInfo_Application)); + R_ABORT_UNLESS(svcGetSystemInfo(&value, SystemInfoType_UsedPhysicalMemorySize, INVALID_HANDLE, PhysicalMemoryInfo_Application)); if (value == 0) { break; } @@ -175,10 +175,10 @@ namespace ams::pm::resource { for (size_t i = 0; i < ResourceLimitGroup_Count; i++) { if (i == ResourceLimitGroup_System) { u64 value = 0; - R_ASSERT(svcGetInfo(&value, InfoType_ResourceLimit, INVALID_HANDLE, 0)); + R_ABORT_UNLESS(svcGetInfo(&value, InfoType_ResourceLimit, INVALID_HANDLE, 0)); g_resource_limit_handles[i] = static_cast(value); } else { - R_ASSERT(svcCreateResourceLimit(&g_resource_limit_handles[i])); + R_ABORT_UNLESS(svcCreateResourceLimit(&g_resource_limit_handles[i])); } } @@ -210,7 +210,7 @@ namespace ams::pm::resource { if (hos::GetVersion() >= hos::Version_700) { /* See how many threads we have available. */ u64 total_threads_available = 0; - R_ASSERT(svcGetResourceLimitLimitValue(&total_threads_available, GetResourceLimitHandle(ResourceLimitGroup_System), LimitableResource_Threads)); + R_ABORT_UNLESS(svcGetResourceLimitLimitValue(&total_threads_available, GetResourceLimitHandle(ResourceLimitGroup_System), LimitableResource_Threads)); /* See how many threads we're expecting. */ const size_t total_threads_allocated = g_resource_limits[ResourceLimitGroup_System][LimitableResource_Threads] - @@ -218,7 +218,7 @@ namespace ams::pm::resource { g_resource_limits[ResourceLimitGroup_Applet][LimitableResource_Threads]; /* Ensure we don't over-commit threads. */ - AMS_ASSERT(total_threads_allocated <= total_threads_available); + AMS_ABORT_UNLESS(total_threads_allocated <= total_threads_available); /* Set number of extra threads. */ g_extra_application_threads_available = total_threads_available - total_threads_allocated; @@ -231,18 +231,18 @@ namespace ams::pm::resource { /* Get total memory available. */ u64 total_memory = 0; - R_ASSERT(svcGetResourceLimitLimitValue(&total_memory, GetResourceLimitHandle(ResourceLimitGroup_System), LimitableResource_Memory)); + R_ABORT_UNLESS(svcGetResourceLimitLimitValue(&total_memory, GetResourceLimitHandle(ResourceLimitGroup_System), LimitableResource_Memory)); /* Get and save application + applet memory. */ - R_ASSERT(svcGetSystemInfo(&g_memory_resource_limits[spl::MemoryArrangement_Dynamic][ResourceLimitGroup_Application], SystemInfoType_TotalPhysicalMemorySize, INVALID_HANDLE, PhysicalMemoryInfo_Application)); - R_ASSERT(svcGetSystemInfo(&g_memory_resource_limits[spl::MemoryArrangement_Dynamic][ResourceLimitGroup_Applet], SystemInfoType_TotalPhysicalMemorySize, INVALID_HANDLE, PhysicalMemoryInfo_Applet)); + R_ABORT_UNLESS(svcGetSystemInfo(&g_memory_resource_limits[spl::MemoryArrangement_Dynamic][ResourceLimitGroup_Application], SystemInfoType_TotalPhysicalMemorySize, INVALID_HANDLE, PhysicalMemoryInfo_Application)); + R_ABORT_UNLESS(svcGetSystemInfo(&g_memory_resource_limits[spl::MemoryArrangement_Dynamic][ResourceLimitGroup_Applet], SystemInfoType_TotalPhysicalMemorySize, INVALID_HANDLE, PhysicalMemoryInfo_Applet)); const u64 application_size = g_memory_resource_limits[spl::MemoryArrangement_Dynamic][ResourceLimitGroup_Application]; const u64 applet_size = g_memory_resource_limits[spl::MemoryArrangement_Dynamic][ResourceLimitGroup_Applet]; const u64 reserved_non_system_size = (application_size + applet_size + ReservedMemorySize600); /* Ensure there's enough memory for the system region. */ - AMS_ASSERT(reserved_non_system_size < total_memory); + AMS_ABORT_UNLESS(reserved_non_system_size < total_memory); g_memory_resource_limits[spl::MemoryArrangement_Dynamic][ResourceLimitGroup_System] = total_memory - reserved_non_system_size; } else { @@ -267,7 +267,7 @@ namespace ams::pm::resource { std::scoped_lock lk(g_resource_limit_lock); for (size_t group = 0; group < ResourceLimitGroup_Count; group++) { - R_ASSERT(SetResourceLimitLimitValues(static_cast(group), g_memory_resource_limits[g_memory_arrangement][group])); + R_ABORT_UNLESS(SetResourceLimitLimitValues(static_cast(group), g_memory_resource_limits[g_memory_arrangement][group])); } } @@ -286,10 +286,10 @@ namespace ams::pm::resource { /* Starting in 5.0.0, PM does not allow for only one of the sets to fail. */ if (boost_size < g_system_memory_boost_size) { R_TRY(svcSetUnsafeLimit(boost_size)); - R_ASSERT(SetMemoryResourceLimitLimitValue(ResourceLimitGroup_Application, new_app_size)); + R_ABORT_UNLESS(SetMemoryResourceLimitLimitValue(ResourceLimitGroup_Application, new_app_size)); } else { R_TRY(SetMemoryResourceLimitLimitValue(ResourceLimitGroup_Application, new_app_size)); - R_ASSERT(svcSetUnsafeLimit(boost_size)); + R_ABORT_UNLESS(svcSetUnsafeLimit(boost_size)); } } else { const u64 new_sys_size = g_memory_resource_limits[g_memory_arrangement][ResourceLimitGroup_System] + boost_size; @@ -340,8 +340,8 @@ namespace ams::pm::resource { Result GetResourceLimitValues(u64 *out_cur, u64 *out_lim, ResourceLimitGroup group, LimitableResource resource) { /* Do not allow out of bounds access. */ - AMS_ASSERT(group < ResourceLimitGroup_Count); - AMS_ASSERT(resource < LimitableResource_Count); + AMS_ABORT_UNLESS(group < ResourceLimitGroup_Count); + AMS_ABORT_UNLESS(resource < LimitableResource_Count); const Handle reslimit_hnd = GetResourceLimitHandle(group); R_TRY(svcGetResourceLimitCurrentValue(out_cur, reslimit_hnd, resource)); diff --git a/stratosphere/pm/source/pm_main.cpp b/stratosphere/pm/source/pm_main.cpp index 6b078232e..46e8fd594 100644 --- a/stratosphere/pm/source/pm_main.cpp +++ b/stratosphere/pm/source/pm_main.cpp @@ -87,12 +87,12 @@ namespace { /* Get a debug handle. */ os::ManagedHandle debug_handle; - R_ASSERT(svcDebugActiveProcess(debug_handle.GetPointer(), static_cast(process_id))); + R_ABORT_UNLESS(svcDebugActiveProcess(debug_handle.GetPointer(), static_cast(process_id))); /* Loop until we get the event that tells us about the process. */ svc::DebugEventInfo d; while (true) { - R_ASSERT(svcGetDebugEvent(reinterpret_cast(&d), debug_handle.Get())); + R_ABORT_UNLESS(svcGetDebugEvent(reinterpret_cast(&d), debug_handle.Get())); if (d.type == svc::DebugEvent_AttachProcess) { return ncm::ProgramId{d.info.attach_process.program_id}; } @@ -117,7 +117,7 @@ namespace { /* Get list of processes, register all privileged ones. */ u32 num_pids; os::ProcessId pids[ProcessCountMax]; - R_ASSERT(svcGetProcessList(&num_pids, reinterpret_cast(pids), ProcessCountMax)); + R_ABORT_UNLESS(svcGetProcessList(&num_pids, reinterpret_cast(pids), ProcessCountMax)); for (size_t i = 0; i < num_pids; i++) { if (min_priv_process_id <= pids[i] && pids[i] <= max_priv_process_id) { RegisterPrivilegedProcess(pids[i]); @@ -131,19 +131,19 @@ void __appInit(void) { hos::SetVersionForLibnx(); sm::DoWithSession([&]() { - R_ASSERT(fsprInitialize()); - R_ASSERT(smManagerInitialize()); + R_ABORT_UNLESS(fsprInitialize()); + R_ABORT_UNLESS(smManagerInitialize()); /* This works around a bug with process permissions on < 4.0.0. */ /* It also informs SM of privileged process information. */ RegisterPrivilegedProcesses(); /* Use AMS manager extension to tell SM that FS has been worked around. */ - R_ASSERT(sm::manager::EndInitialDefers()); + R_ABORT_UNLESS(sm::manager::EndInitialDefers()); - R_ASSERT(lrInitialize()); - R_ASSERT(ldrPmInitialize()); - R_ASSERT(splInitialize()); + R_ABORT_UNLESS(lrInitialize()); + R_ABORT_UNLESS(ldrPmInitialize()); + R_ABORT_UNLESS(splInitialize()); }); ams::CheckApiVersion(); @@ -187,20 +187,20 @@ namespace { int main(int argc, char **argv) { /* Initialize process manager implementation. */ - R_ASSERT(pm::impl::InitializeProcessManager()); + R_ABORT_UNLESS(pm::impl::InitializeProcessManager()); /* Create Services. */ /* NOTE: Extra sessions have been added to pm:bm and pm:info to facilitate access by the rest of stratosphere. */ /* Also Note: PM was rewritten in 5.0.0, so the shell and dmnt services are different before/after. */ if (hos::GetVersion() >= hos::Version_500) { - R_ASSERT((g_server_manager.RegisterServer(ShellServiceName, ShellMaxSessions))); - R_ASSERT((g_server_manager.RegisterServer(DebugMonitorServiceName, DebugMonitorMaxSessions))); + R_ABORT_UNLESS((g_server_manager.RegisterServer(ShellServiceName, ShellMaxSessions))); + R_ABORT_UNLESS((g_server_manager.RegisterServer(DebugMonitorServiceName, DebugMonitorMaxSessions))); } else { - R_ASSERT((g_server_manager.RegisterServer(ShellServiceName, ShellMaxSessions))); - R_ASSERT((g_server_manager.RegisterServer(DebugMonitorServiceName, DebugMonitorMaxSessions))); + R_ABORT_UNLESS((g_server_manager.RegisterServer(ShellServiceName, ShellMaxSessions))); + R_ABORT_UNLESS((g_server_manager.RegisterServer(DebugMonitorServiceName, DebugMonitorMaxSessions))); } - R_ASSERT((g_server_manager.RegisterServer(BootModeServiceName, BootModeMaxSessions))); - R_ASSERT((g_server_manager.RegisterServer(InformationServiceName, InformationMaxSessions))); + R_ABORT_UNLESS((g_server_manager.RegisterServer(BootModeServiceName, BootModeMaxSessions))); + R_ABORT_UNLESS((g_server_manager.RegisterServer(InformationServiceName, InformationMaxSessions))); /* Loop forever, servicing our services. */ g_server_manager.LoopProcess(); diff --git a/stratosphere/pm/source/pm_shell_service.cpp b/stratosphere/pm/source/pm_shell_service.cpp index 3f3efe253..9b471707a 100644 --- a/stratosphere/pm/source/pm_shell_service.cpp +++ b/stratosphere/pm/source/pm_shell_service.cpp @@ -37,11 +37,11 @@ namespace ams::pm::shell { } void ShellServiceBase::GetProcessEventHandle(sf::OutCopyHandle out) { - R_ASSERT(impl::GetProcessEventHandle(out.GetHandlePointer())); + R_ABORT_UNLESS(impl::GetProcessEventHandle(out.GetHandlePointer())); } void ShellServiceBase::GetProcessEventInfo(sf::Out out) { - R_ASSERT(impl::GetProcessEventInfo(out.GetPointer())); + R_ABORT_UNLESS(impl::GetProcessEventInfo(out.GetPointer())); } Result ShellServiceBase::CleanupProcess(os::ProcessId process_id) { @@ -53,7 +53,7 @@ namespace ams::pm::shell { } void ShellServiceBase::NotifyBootFinished() { - R_ASSERT(impl::NotifyBootFinished()); + R_ABORT_UNLESS(impl::NotifyBootFinished()); } Result ShellServiceBase::GetApplicationProcessIdForShell(sf::Out out) { @@ -69,7 +69,7 @@ namespace ams::pm::shell { } void ShellServiceBase::GetBootFinishedEventHandle(sf::OutCopyHandle out) { - R_ASSERT(impl::GetBootFinishedEventHandle(out.GetHandlePointer())); + R_ABORT_UNLESS(impl::GetBootFinishedEventHandle(out.GetHandlePointer())); } } diff --git a/stratosphere/ro/source/impl/ro_service_impl.cpp b/stratosphere/ro/source/impl/ro_service_impl.cpp index fb0f4ed13..99f00e24c 100644 --- a/stratosphere/ro/source/impl/ro_service_impl.cpp +++ b/stratosphere/ro/source/impl/ro_service_impl.cpp @@ -83,10 +83,10 @@ namespace ams::ro::impl { ncm::ProgramId program_id = ncm::ProgramId::Invalid; if (hos::GetVersion() >= hos::Version_300) { /* 3.0.0+: Use svcGetInfo. */ - R_ASSERT(svcGetInfo(&program_id.value, InfoType_ProgramId, process_h, 0)); + R_ABORT_UNLESS(svcGetInfo(&program_id.value, InfoType_ProgramId, process_h, 0)); } else { /* 1.0.0-2.3.0: We're not inside loader, so ask pm. */ - R_ASSERT(pm::info::GetProgramId(&program_id, os::GetProcessId(process_h))); + R_ABORT_UNLESS(pm::info::GetProgramId(&program_id, os::GetProcessId(process_h))); } return program_id; } @@ -240,7 +240,7 @@ namespace ams::ro::impl { return nullptr; } - AMS_ASSERT(context_id < MaxSessions); + AMS_ABORT_UNLESS(context_id < MaxSessions); return &g_process_contexts[context_id]; } @@ -267,7 +267,7 @@ namespace ams::ro::impl { } } /* Failure to find a free context is actually an abort condition. */ - AMS_ASSERT(false); + AMS_ABORT_UNLESS(false); } void FreeContext(size_t context_id) { @@ -367,7 +367,7 @@ namespace ams::ro::impl { Result LoadNrr(size_t context_id, Handle process_h, u64 nrr_address, u64 nrr_size, ModuleType expected_type, bool enforce_type) { /* Get context. */ ProcessContext *context = GetContextById(context_id); - AMS_ASSERT(context != nullptr); + AMS_ABORT_UNLESS(context != nullptr); /* Get program id. */ const ncm::ProgramId program_id = context->GetProgramId(process_h); @@ -397,7 +397,7 @@ namespace ams::ro::impl { Result UnloadNrr(size_t context_id, u64 nrr_address) { /* Get context. */ ProcessContext *context = GetContextById(context_id); - AMS_ASSERT(context != nullptr); + AMS_ABORT_UNLESS(context != nullptr); /* Validate address. */ R_UNLESS(util::IsAligned(nrr_address, os::MemoryPageSize), ResultInvalidAddress()); @@ -419,7 +419,7 @@ namespace ams::ro::impl { Result LoadNro(u64 *out_address, size_t context_id, u64 nro_address, u64 nro_size, u64 bss_address, u64 bss_size) { /* Get context. */ ProcessContext *context = GetContextById(context_id); - AMS_ASSERT(context != nullptr); + AMS_ABORT_UNLESS(context != nullptr); /* Validate address/size. */ R_TRY(ValidateAddressAndNonZeroSize(nro_address, nro_size)); @@ -465,7 +465,7 @@ namespace ams::ro::impl { Result UnloadNro(size_t context_id, u64 nro_address) { /* Get context. */ ProcessContext *context = GetContextById(context_id); - AMS_ASSERT(context != nullptr); + AMS_ABORT_UNLESS(context != nullptr); /* Validate address. */ R_UNLESS(util::IsAligned(nro_address, os::MemoryPageSize), ResultInvalidAddress()); diff --git a/stratosphere/ro/source/ro_main.cpp b/stratosphere/ro/source/ro_main.cpp index e548f4837..b27ddb87a 100644 --- a/stratosphere/ro/source/ro_main.cpp +++ b/stratosphere/ro/source/ro_main.cpp @@ -62,15 +62,15 @@ void __appInit(void) { hos::SetVersionForLibnx(); sm::DoWithSession([&]() { - R_ASSERT(setsysInitialize()); - R_ASSERT(fsInitialize()); - R_ASSERT(splInitialize()); + R_ABORT_UNLESS(setsysInitialize()); + R_ABORT_UNLESS(fsInitialize()); + R_ABORT_UNLESS(splInitialize()); if (hos::GetVersion() < hos::Version_300) { - R_ASSERT(pminfoInitialize()); + R_ABORT_UNLESS(pminfoInitialize()); } }); - R_ASSERT(fsdevMountSdmc()); + R_ABORT_UNLESS(fsdevMountSdmc()); ams::CheckApiVersion(); } @@ -118,11 +118,11 @@ int main(int argc, char **argv) } /* Create services. */ - R_ASSERT((g_server_manager.RegisterServer(DebugMonitorServiceName, DebugMonitorMaxSessions))); + R_ABORT_UNLESS((g_server_manager.RegisterServer(DebugMonitorServiceName, DebugMonitorMaxSessions))); - R_ASSERT((g_server_manager.RegisterServer(ForSelfServiceName, ForSelfMaxSessions))); + R_ABORT_UNLESS((g_server_manager.RegisterServer(ForSelfServiceName, ForSelfMaxSessions))); if (hos::GetVersion() >= hos::Version_700) { - R_ASSERT((g_server_manager.RegisterServer(ForOthersServiceName, ForOthersMaxSessions))); + R_ABORT_UNLESS((g_server_manager.RegisterServer(ForOthersServiceName, ForOthersMaxSessions))); } /* Loop forever, servicing our services. */ diff --git a/stratosphere/sm/source/impl/sm_service_manager.cpp b/stratosphere/sm/source/impl/sm_service_manager.cpp index 6bdba77e4..e5b5e49b9 100644 --- a/stratosphere/sm/source/impl/sm_service_manager.cpp +++ b/stratosphere/sm/source/impl/sm_service_manager.cpp @@ -161,11 +161,11 @@ namespace ams::sm::impl { cfg::GetInitialProcessRange(&this->min, &this->max); /* Ensure range is sane. */ - AMS_ASSERT(this->min <= this->max); + AMS_ABORT_UNLESS(this->min <= this->max); } bool IsInitialProcess(os::ProcessId process_id) const { - AMS_ASSERT(process_id != os::InvalidProcessId); + AMS_ABORT_UNLESS(process_id != os::InvalidProcessId); return this->min <= process_id && process_id <= this->max; } }; @@ -228,7 +228,7 @@ namespace ams::sm::impl { void GetMitmProcessInfo(MitmProcessInfo *out_info, os::ProcessId process_id) { /* Anything that can request a mitm session must have a process info. */ const auto process_info = GetProcessInfo(process_id); - AMS_ASSERT(process_info != nullptr); + AMS_ABORT_UNLESS(process_info != nullptr); /* Write to output. */ out_info->process_id = process_id; @@ -383,7 +383,7 @@ namespace ams::sm::impl { GetMitmProcessInfo(&client_info, process_id); if (!IsMitmDisallowed(client_info.program_id)) { /* We're mitm'd. Assert, because mitm service host dead is an error state. */ - R_ASSERT(GetMitmServiceHandleImpl(out, service_info, client_info)); + R_ABORT_UNLESS(GetMitmServiceHandleImpl(out, service_info, client_info)); return ResultSuccess(); } } diff --git a/stratosphere/sm/source/sm_dmnt_service.cpp b/stratosphere/sm/source/sm_dmnt_service.cpp index adcd27c0a..584bc5928 100644 --- a/stratosphere/sm/source/sm_dmnt_service.cpp +++ b/stratosphere/sm/source/sm_dmnt_service.cpp @@ -23,7 +23,7 @@ namespace ams::sm { } void DmntService::AtmosphereListRecords(const sf::OutArray &records, sf::Out out_count, u64 offset) { - R_ASSERT(impl::ListServiceRecords(records.GetPointer(), out_count.GetPointer(), offset, records.GetSize())); + R_ABORT_UNLESS(impl::ListServiceRecords(records.GetPointer(), out_count.GetPointer(), offset, records.GetSize())); } void DmntService::AtmosphereGetRecordSize(sf::Out record_size) { diff --git a/stratosphere/sm/source/sm_main.cpp b/stratosphere/sm/source/sm_main.cpp index 2e2921078..3fc050a3e 100644 --- a/stratosphere/sm/source/sm_main.cpp +++ b/stratosphere/sm/source/sm_main.cpp @@ -95,14 +95,14 @@ int main(int argc, char **argv) /* Create sm:, (and thus allow things to register to it). */ { Handle sm_h; - R_ASSERT(svcManageNamedPort(&sm_h, "sm:", 0x40)); + R_ABORT_UNLESS(svcManageNamedPort(&sm_h, "sm:", 0x40)); g_server_manager.RegisterServer(sm_h); } /* Create sm:m manually. */ { Handle smm_h; - R_ASSERT(sm::impl::RegisterServiceForSelf(&smm_h, sm::ServiceName::Encode("sm:m"), 1)); + R_ABORT_UNLESS(sm::impl::RegisterServiceForSelf(&smm_h, sm::ServiceName::Encode("sm:m"), 1)); g_server_manager.RegisterServer(smm_h); } @@ -110,7 +110,7 @@ int main(int argc, char **argv) /* Create sm:dmnt manually. */ { Handle smdmnt_h; - R_ASSERT(sm::impl::RegisterServiceForSelf(&smdmnt_h, sm::ServiceName::Encode("sm:dmnt"), 1)); + R_ABORT_UNLESS(sm::impl::RegisterServiceForSelf(&smdmnt_h, sm::ServiceName::Encode("sm:dmnt"), 1)); g_server_manager.RegisterServer(smdmnt_h); } diff --git a/stratosphere/sm/source/sm_manager_service.cpp b/stratosphere/sm/source/sm_manager_service.cpp index 5b30355d6..7e6af932f 100644 --- a/stratosphere/sm/source/sm_manager_service.cpp +++ b/stratosphere/sm/source/sm_manager_service.cpp @@ -27,11 +27,11 @@ namespace ams::sm { } void ManagerService::AtmosphereEndInitDefers() { - R_ASSERT(impl::EndInitialDefers()); + R_ABORT_UNLESS(impl::EndInitialDefers()); } void ManagerService::AtmosphereHasMitm(sf::Out out, ServiceName service) { - R_ASSERT(impl::HasMitm(out.GetPointer(), service)); + R_ABORT_UNLESS(impl::HasMitm(out.GetPointer(), service)); } Result ManagerService::AtmosphereRegisterProcess(os::ProcessId process_id, ncm::ProgramId program_id, cfg::OverrideStatus override_status, const sf::InBuffer &acid_sac, const sf::InBuffer &aci_sac) { diff --git a/stratosphere/spl/source/spl_api_impl.cpp b/stratosphere/spl/source/spl_api_impl.cpp index 314a6f6ab..8b7765705 100644 --- a/stratosphere/spl/source/spl_api_impl.cpp +++ b/stratosphere/spl/source/spl_api_impl.cpp @@ -88,10 +88,10 @@ namespace ams::spl::impl { u32 perm; public: DeviceAddressSpaceMapHelper(Handle h, u64 dst, u64 src, size_t sz, u32 p) : das_hnd(h), dst_addr(dst), src_addr(src), size(sz), perm(p) { - R_ASSERT(svcMapDeviceAddressSpaceAligned(this->das_hnd, dd::GetCurrentProcessHandle(), this->src_addr, this->size, this->dst_addr, this->perm)); + R_ABORT_UNLESS(svcMapDeviceAddressSpaceAligned(this->das_hnd, dd::GetCurrentProcessHandle(), this->src_addr, this->size, this->dst_addr, this->perm)); } ~DeviceAddressSpaceMapHelper() { - R_ASSERT(svcUnmapDeviceAddressSpace(this->das_hnd, dd::GetCurrentProcessHandle(), this->src_addr, this->size, this->dst_addr)); + R_ABORT_UNLESS(svcUnmapDeviceAddressSpace(this->das_hnd, dd::GetCurrentProcessHandle(), this->src_addr, this->size, this->dst_addr)); } }; @@ -122,33 +122,33 @@ namespace ams::spl::impl { /* Initialization functionality. */ void InitializeCtrDrbg() { u8 seed[CtrDrbg::SeedSize]; - AMS_ASSERT(smc::GenerateRandomBytes(seed, sizeof(seed)) == smc::Result::Success); + AMS_ABORT_UNLESS(smc::GenerateRandomBytes(seed, sizeof(seed)) == smc::Result::Success); g_drbg.Initialize(seed); } void InitializeSeEvents() { u64 irq_num; - AMS_ASSERT(smc::GetConfig(&irq_num, 1, SplConfigItem_SecurityEngineIrqNumber) == smc::Result::Success); - R_ASSERT(g_se_event.Initialize(irq_num)); + AMS_ABORT_UNLESS(smc::GetConfig(&irq_num, 1, SplConfigItem_SecurityEngineIrqNumber) == smc::Result::Success); + R_ABORT_UNLESS(g_se_event.Initialize(irq_num)); - R_ASSERT(g_se_keyslot_available_event.InitializeAsInterProcessEvent()); + R_ABORT_UNLESS(g_se_keyslot_available_event.InitializeAsInterProcessEvent()); g_se_keyslot_available_event.Signal(); } void InitializeDeviceAddressSpace() { /* Create Address Space. */ - R_ASSERT(svcCreateDeviceAddressSpace(&g_se_das_hnd, 0, (1ul << 32))); + R_ABORT_UNLESS(svcCreateDeviceAddressSpace(&g_se_das_hnd, 0, (1ul << 32))); /* Attach it to the SE. */ - R_ASSERT(svcAttachDeviceAddressSpace(svc::DeviceName_Se, g_se_das_hnd)); + R_ABORT_UNLESS(svcAttachDeviceAddressSpace(svc::DeviceName_Se, g_se_das_hnd)); const u64 work_buffer_addr = reinterpret_cast(g_work_buffer); g_se_mapped_work_buffer_addr = WorkBufferMapBase + (work_buffer_addr % DeviceAddressSpaceAlign); /* Map the work buffer for the SE. */ - R_ASSERT(svcMapDeviceAddressSpaceAligned(g_se_das_hnd, dd::GetCurrentProcessHandle(), work_buffer_addr, sizeof(g_work_buffer), g_se_mapped_work_buffer_addr, 3)); + R_ABORT_UNLESS(svcMapDeviceAddressSpaceAligned(g_se_das_hnd, dd::GetCurrentProcessHandle(), work_buffer_addr, sizeof(g_work_buffer), g_se_mapped_work_buffer_addr, 3)); } /* RSA OAEP implementation helpers. */ diff --git a/stratosphere/spl/source/spl_main.cpp b/stratosphere/spl/source/spl_main.cpp index e07dc6357..f08a6a165 100644 --- a/stratosphere/spl/source/spl_main.cpp +++ b/stratosphere/spl/source/spl_main.cpp @@ -133,18 +133,18 @@ int main(int argc, char **argv) spl::impl::Initialize(); /* Create services. */ - R_ASSERT(g_server_manager.RegisterServer(RandomServiceName, RandomMaxSessions)); + R_ABORT_UNLESS(g_server_manager.RegisterServer(RandomServiceName, RandomMaxSessions)); if (hos::GetVersion() >= hos::Version_400) { - R_ASSERT(g_server_manager.RegisterServer(GeneralServiceName, GeneralMaxSessions)); - R_ASSERT(g_server_manager.RegisterServer(CryptoServiceName, CryptoMaxSessions)); - R_ASSERT(g_server_manager.RegisterServer(SslServiceName, SslMaxSessions)); - R_ASSERT(g_server_manager.RegisterServer(EsServiceName, EsMaxSessions)); - R_ASSERT(g_server_manager.RegisterServer(FsServiceName, FsMaxSessions)); + R_ABORT_UNLESS(g_server_manager.RegisterServer(GeneralServiceName, GeneralMaxSessions)); + R_ABORT_UNLESS(g_server_manager.RegisterServer(CryptoServiceName, CryptoMaxSessions)); + R_ABORT_UNLESS(g_server_manager.RegisterServer(SslServiceName, SslMaxSessions)); + R_ABORT_UNLESS(g_server_manager.RegisterServer(EsServiceName, EsMaxSessions)); + R_ABORT_UNLESS(g_server_manager.RegisterServer(FsServiceName, FsMaxSessions)); if (hos::GetVersion() >= hos::Version_500) { - R_ASSERT(g_server_manager.RegisterServer(ManuServiceName, ManuMaxSessions)); + R_ABORT_UNLESS(g_server_manager.RegisterServer(ManuServiceName, ManuMaxSessions)); } } else { - R_ASSERT(g_server_manager.RegisterServer(DeprecatedServiceName, DeprecatedMaxSessions)); + R_ABORT_UNLESS(g_server_manager.RegisterServer(DeprecatedServiceName, DeprecatedMaxSessions)); } /* Loop forever, servicing our services. */