From 8d10584a516026ee01eab7ea920ff22c572d3a9b Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Thu, 28 Jan 2021 00:15:24 -0800 Subject: [PATCH 1/3] result: always prefer diag::Abort to fatal --- .../source/result/result_on_assertion.cpp | 28 +++---------------- stratosphere/ams_mitm/source/amsmitm_main.cpp | 6 ---- stratosphere/boot/source/boot_main.cpp | 6 ---- stratosphere/boot2/source/boot2_main.cpp | 6 ---- stratosphere/creport/source/creport_main.cpp | 6 ---- stratosphere/dmnt/source/dmnt_main.cpp | 6 ---- stratosphere/eclct.stub/source/eclct_stub.cpp | 6 ---- stratosphere/erpt/source/erpt_main.cpp | 6 ---- stratosphere/fatal/source/fatal_main.cpp | 6 ---- stratosphere/jpegdec/source/jpegdec_main.cpp | 6 ---- stratosphere/loader/source/ldr_main.cpp | 6 ---- stratosphere/ncm/source/ncm_main.cpp | 6 ---- stratosphere/pgl/source/pgl_main.cpp | 6 ---- stratosphere/pm/source/pm_main.cpp | 6 ---- stratosphere/ro/source/ro_main.cpp | 6 ---- stratosphere/sm/source/sm_main.cpp | 6 ---- stratosphere/spl/source/spl_main.cpp | 6 ---- 17 files changed, 4 insertions(+), 120 deletions(-) diff --git a/libraries/libstratosphere/source/result/result_on_assertion.cpp b/libraries/libstratosphere/source/result/result_on_assertion.cpp index 7705c561f..6d4337ef5 100644 --- a/libraries/libstratosphere/source/result/result_on_assertion.cpp +++ b/libraries/libstratosphere/source/result/result_on_assertion.cpp @@ -15,25 +15,12 @@ */ #include -namespace ams::result { - - extern bool CallFatalOnResultAssertion; - -} - namespace ams::result::impl { 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()); + ::ams::diag::AbortImpl(file, line, func, expr, result.GetValue(), "Result Abort: %203d-%04d", result.GetModule(), result.GetDescription()); AMS_INFINITE_LOOP(); + __builtin_unreachable(); } NORETURN WEAK_SYMBOL void OnResultAbort(Result result) { @@ -41,16 +28,9 @@ namespace ams::result::impl { } 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()); + ::ams::diag::AssertionFailureImpl(file, line, func, expr, result.GetValue(), "Result Assertion: %203d-%04d", result.GetModule(), result.GetDescription()); AMS_INFINITE_LOOP(); + __builtin_unreachable(); } NORETURN WEAK_SYMBOL void OnResultAssertion(Result result) { diff --git a/stratosphere/ams_mitm/source/amsmitm_main.cpp b/stratosphere/ams_mitm/source/amsmitm_main.cpp index ca06e7108..6f2757132 100644 --- a/stratosphere/ams_mitm/source/amsmitm_main.cpp +++ b/stratosphere/ams_mitm/source/amsmitm_main.cpp @@ -47,12 +47,6 @@ namespace ams { ncm::ProgramId CurrentProgramId = ncm::AtmosphereProgramId::Mitm; - namespace result { - - bool CallFatalOnResultAssertion = false; - - } - /* Override. */ void ExceptionHandler(FatalErrorContext *ctx) { /* We're bpc-mitm (or ams_mitm, anyway), so manually reboot to fatal error. */ diff --git a/stratosphere/boot/source/boot_main.cpp b/stratosphere/boot/source/boot_main.cpp index 2bf22a8ab..c7a2cb69e 100644 --- a/stratosphere/boot/source/boot_main.cpp +++ b/stratosphere/boot/source/boot_main.cpp @@ -63,12 +63,6 @@ namespace ams { boot::RebootForFatalError(ctx); } - namespace result { - - bool CallFatalOnResultAssertion = false; - - } - } using namespace ams; diff --git a/stratosphere/boot2/source/boot2_main.cpp b/stratosphere/boot2/source/boot2_main.cpp index 869453149..8c2efe241 100644 --- a/stratosphere/boot2/source/boot2_main.cpp +++ b/stratosphere/boot2/source/boot2_main.cpp @@ -43,12 +43,6 @@ namespace ams { ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::Boot2; - namespace result { - - bool CallFatalOnResultAssertion = false; - - } - } using namespace ams; diff --git a/stratosphere/creport/source/creport_main.cpp b/stratosphere/creport/source/creport_main.cpp index 57fa0dbe8..847da6cff 100644 --- a/stratosphere/creport/source/creport_main.cpp +++ b/stratosphere/creport/source/creport_main.cpp @@ -46,12 +46,6 @@ namespace ams { ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::Creport; - namespace result { - - bool CallFatalOnResultAssertion = true; - - } - } using namespace ams; diff --git a/stratosphere/dmnt/source/dmnt_main.cpp b/stratosphere/dmnt/source/dmnt_main.cpp index cf21b599c..bfa05f9bf 100644 --- a/stratosphere/dmnt/source/dmnt_main.cpp +++ b/stratosphere/dmnt/source/dmnt_main.cpp @@ -41,12 +41,6 @@ namespace ams { ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::Dmnt; - namespace result { - - bool CallFatalOnResultAssertion = false; - - } - } using namespace ams; diff --git a/stratosphere/eclct.stub/source/eclct_stub.cpp b/stratosphere/eclct.stub/source/eclct_stub.cpp index fe9e52254..172e308e9 100644 --- a/stratosphere/eclct.stub/source/eclct_stub.cpp +++ b/stratosphere/eclct.stub/source/eclct_stub.cpp @@ -38,12 +38,6 @@ namespace ams { ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::Eclct; - namespace result { - - bool CallFatalOnResultAssertion = false; - - } - } using namespace ams; diff --git a/stratosphere/erpt/source/erpt_main.cpp b/stratosphere/erpt/source/erpt_main.cpp index 5f8a72252..2a0597bb9 100644 --- a/stratosphere/erpt/source/erpt_main.cpp +++ b/stratosphere/erpt/source/erpt_main.cpp @@ -43,12 +43,6 @@ namespace ams { ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::Erpt; - namespace result { - - bool CallFatalOnResultAssertion = false; - - } - } using namespace ams; diff --git a/stratosphere/fatal/source/fatal_main.cpp b/stratosphere/fatal/source/fatal_main.cpp index 40c63975d..cb2a32a69 100644 --- a/stratosphere/fatal/source/fatal_main.cpp +++ b/stratosphere/fatal/source/fatal_main.cpp @@ -50,12 +50,6 @@ namespace ams { ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::Fatal; - namespace result { - - bool CallFatalOnResultAssertion = false; - - } - } using namespace ams; diff --git a/stratosphere/jpegdec/source/jpegdec_main.cpp b/stratosphere/jpegdec/source/jpegdec_main.cpp index 1936a5664..560e240b9 100644 --- a/stratosphere/jpegdec/source/jpegdec_main.cpp +++ b/stratosphere/jpegdec/source/jpegdec_main.cpp @@ -39,12 +39,6 @@ extern "C" { namespace ams { ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::JpegDec; - namespace result { - - bool CallFatalOnResultAssertion = true; - - } - } using namespace ams; diff --git a/stratosphere/loader/source/ldr_main.cpp b/stratosphere/loader/source/ldr_main.cpp index 284ce33d8..ba7b9b273 100644 --- a/stratosphere/loader/source/ldr_main.cpp +++ b/stratosphere/loader/source/ldr_main.cpp @@ -45,12 +45,6 @@ namespace ams { ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::Loader; - namespace result { - - bool CallFatalOnResultAssertion = false; - - } - } using namespace ams; diff --git a/stratosphere/ncm/source/ncm_main.cpp b/stratosphere/ncm/source/ncm_main.cpp index 39a6e2c7d..0b31c0bf5 100644 --- a/stratosphere/ncm/source/ncm_main.cpp +++ b/stratosphere/ncm/source/ncm_main.cpp @@ -43,12 +43,6 @@ namespace ams { ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::Ncm; - namespace result { - - bool CallFatalOnResultAssertion = false; - - } - } using namespace ams; diff --git a/stratosphere/pgl/source/pgl_main.cpp b/stratosphere/pgl/source/pgl_main.cpp index 1126d82c8..eab2d4285 100644 --- a/stratosphere/pgl/source/pgl_main.cpp +++ b/stratosphere/pgl/source/pgl_main.cpp @@ -43,12 +43,6 @@ namespace ams { ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::Pgl; - namespace result { - - bool CallFatalOnResultAssertion = false; - - } - } using namespace ams; diff --git a/stratosphere/pm/source/pm_main.cpp b/stratosphere/pm/source/pm_main.cpp index 11bf6dbd8..caabc856b 100644 --- a/stratosphere/pm/source/pm_main.cpp +++ b/stratosphere/pm/source/pm_main.cpp @@ -48,12 +48,6 @@ namespace ams { ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::Pm; - namespace result { - - bool CallFatalOnResultAssertion = false; - - } - } using namespace ams; diff --git a/stratosphere/ro/source/ro_main.cpp b/stratosphere/ro/source/ro_main.cpp index 3cd4b900f..d49e28409 100644 --- a/stratosphere/ro/source/ro_main.cpp +++ b/stratosphere/ro/source/ro_main.cpp @@ -40,12 +40,6 @@ namespace ams { ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::Ro; - namespace result { - - bool CallFatalOnResultAssertion = true; - - } - } using namespace ams; diff --git a/stratosphere/sm/source/sm_main.cpp b/stratosphere/sm/source/sm_main.cpp index 14c8ae7b3..16070d43c 100644 --- a/stratosphere/sm/source/sm_main.cpp +++ b/stratosphere/sm/source/sm_main.cpp @@ -47,12 +47,6 @@ namespace ams { ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::Sm; - namespace result { - - bool CallFatalOnResultAssertion = false; - - } - } using namespace ams; diff --git a/stratosphere/spl/source/spl_main.cpp b/stratosphere/spl/source/spl_main.cpp index e24a35deb..1fe05c15c 100644 --- a/stratosphere/spl/source/spl_main.cpp +++ b/stratosphere/spl/source/spl_main.cpp @@ -53,12 +53,6 @@ namespace ams { ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::Spl; - namespace result { - - bool CallFatalOnResultAssertion = false; - - } - } using namespace ams; From b5f72b9f20e0f4af62a5c62dccdda070736a736e Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Thu, 28 Jan 2021 14:28:45 -0800 Subject: [PATCH 2/3] fssystem: fix bug in BufferedStorage --- .../source/fssystem/save/fssystem_buffered_storage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/libstratosphere/source/fssystem/save/fssystem_buffered_storage.cpp b/libraries/libstratosphere/source/fssystem/save/fssystem_buffered_storage.cpp index c43e06f3e..aff6b45b3 100644 --- a/libraries/libstratosphere/source/fssystem/save/fssystem_buffered_storage.cpp +++ b/libraries/libstratosphere/source/fssystem/save/fssystem_buffered_storage.cpp @@ -899,7 +899,7 @@ namespace ams::fssystem::save { const s64 cur_offset_end = offset + *size; size_t cur_size = 0; - if (!util::IsAligned(offset, this->block_size)) { + if (!util::IsAligned(cur_offset_end, this->block_size)) { const s64 aligned_size = cur_offset_end - util::AlignDown(cur_offset_end, this->block_size); cur_size = std::min(aligned_size, static_cast(*size)); } else if (*size < this->block_size) { From a28c60970f5cfc661429300dc71255b068b1fbc5 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Thu, 28 Jan 2021 17:47:26 -0800 Subject: [PATCH 3/3] kern: fix scheduler update semantics in KLightLock::LockSlowPath --- libraries/libmesosphere/source/kern_k_light_lock.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/libmesosphere/source/kern_k_light_lock.cpp b/libraries/libmesosphere/source/kern_k_light_lock.cpp index d7c423092..06f73ea5b 100644 --- a/libraries/libmesosphere/source/kern_k_light_lock.cpp +++ b/libraries/libmesosphere/source/kern_k_light_lock.cpp @@ -43,7 +43,6 @@ namespace ams::kern { if (owner_thread->IsSuspended()) { owner_thread->ContinueIfHasKernelWaiters(); - KScheduler::SetSchedulerUpdateNeeded(); } } @@ -53,6 +52,7 @@ namespace ams::kern { KThread *owner_thread = cur_thread->GetLockOwner(); if (AMS_UNLIKELY(owner_thread)) { owner_thread->RemoveWaiter(cur_thread); + KScheduler::SetSchedulerUpdateNeeded(); } } }