ams: revamp assertion system

This commit is contained in:
Michael Scire
2020-02-22 23:05:14 -08:00
parent 9572fb2ce3
commit 40400aee1f
168 changed files with 1014 additions and 696 deletions

View File

@@ -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());

View File

@@ -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<ro::DebugMonitorService>(DebugMonitorServiceName, DebugMonitorMaxSessions)));
R_ABORT_UNLESS((g_server_manager.RegisterServer<ro::DebugMonitorService>(DebugMonitorServiceName, DebugMonitorMaxSessions)));
R_ASSERT((g_server_manager.RegisterServer<ro::Service, +MakeRoServiceForSelf>(ForSelfServiceName, ForSelfMaxSessions)));
R_ABORT_UNLESS((g_server_manager.RegisterServer<ro::Service, +MakeRoServiceForSelf>(ForSelfServiceName, ForSelfMaxSessions)));
if (hos::GetVersion() >= hos::Version_700) {
R_ASSERT((g_server_manager.RegisterServer<ro::Service, +MakeRoServiceForOthers>(ForOthersServiceName, ForOthersMaxSessions)));
R_ABORT_UNLESS((g_server_manager.RegisterServer<ro::Service, +MakeRoServiceForOthers>(ForOthersServiceName, ForOthersMaxSessions)));
}
/* Loop forever, servicing our services. */