diff --git a/libraries/libmesosphere/include/mesosphere/kern_k_auto_object.hpp b/libraries/libmesosphere/include/mesosphere/kern_k_auto_object.hpp index f066b595c..37f3f245b 100644 --- a/libraries/libmesosphere/include/mesosphere/kern_k_auto_object.hpp +++ b/libraries/libmesosphere/include/mesosphere/kern_k_auto_object.hpp @@ -204,15 +204,20 @@ namespace ams::kern { this->obj = nullptr; } - template + template requires (std::derived_from || std::derived_from) constexpr ALWAYS_INLINE KScopedAutoObject(KScopedAutoObject &&rhs) { - if constexpr (std::same_as) { + if constexpr (std::derived_from) { + /* Upcast. */ this->obj = rhs.obj; rhs.obj = nullptr; } else { - T *derived = rhs.obj->template DynamicCast(); - if (derived == nullptr) { - rhs.obj->Close(); + /* Downcast. */ + T *derived = nullptr; + if (rhs.obj != nullptr) { + derived = rhs.obj->template DynamicCast(); + if (derived == nullptr) { + rhs.obj->Close(); + } } this->obj = derived; @@ -220,16 +225,7 @@ namespace ams::kern { } } - template - constexpr ALWAYS_INLINE KScopedAutoObject &operator=(KScopedAutoObject &&rhs) { - if constexpr (!std::same_as) { - T *derived = rhs.obj->template DynamicCast(); - if (derived == nullptr) { - rhs.obj->Close(); - } - rhs.obj = nullptr; - } - + constexpr ALWAYS_INLINE KScopedAutoObject &operator=(KScopedAutoObject &&rhs) { rhs.Swap(*this); return *this; } diff --git a/libraries/libmesosphere/source/kern_k_scheduler.cpp b/libraries/libmesosphere/source/kern_k_scheduler.cpp index 2ea8af2a6..b98aa4490 100644 --- a/libraries/libmesosphere/source/kern_k_scheduler.cpp +++ b/libraries/libmesosphere/source/kern_k_scheduler.cpp @@ -252,6 +252,7 @@ namespace ams::kern { /* Switch the current process, if we're switching processes. */ if (KProcess *next_process = next_thread->GetOwnerProcess(); next_process != cur_process) { + MESOSPHERE_LOG("!!! PROCESS SWITCH !!! %s -> %s\n", cur_process != nullptr ? cur_process->GetName() : nullptr, next_process != nullptr ? next_process->GetName() : nullptr); KProcess::Switch(cur_process, next_process); }