diff --git a/libraries/libmesosphere/Makefile b/libraries/libmesosphere/Makefile index 18027ae78..551e1ef47 100644 --- a/libraries/libmesosphere/Makefile +++ b/libraries/libmesosphere/Makefile @@ -140,6 +140,8 @@ $(OFILES_SRC) : $(HFILES_BIN) kern_libc_generic.o: CFLAGS += -fno-builtin +kern_k_auto_object.o: CXXFLAGS += -fno-lto + #--------------------------------------------------------------------------------- %_bin.h %.bin.o : %.bin #--------------------------------------------------------------------------------- diff --git a/libraries/libmesosphere/include/mesosphere/kern_k_auto_object.hpp b/libraries/libmesosphere/include/mesosphere/kern_k_auto_object.hpp index ad08ee659..ff8b26bcb 100644 --- a/libraries/libmesosphere/include/mesosphere/kern_k_auto_object.hpp +++ b/libraries/libmesosphere/include/mesosphere/kern_k_auto_object.hpp @@ -121,36 +121,8 @@ namespace ams::kern { } } - NOINLINE bool Open() { - MESOSPHERE_ASSERT_THIS(); - - /* Atomically increment the reference count, only if it's positive. */ - u32 cur_ref_count = m_ref_count.load(std::memory_order_acquire); - do { - if (AMS_UNLIKELY(cur_ref_count == 0)) { - MESOSPHERE_AUDIT(cur_ref_count != 0); - return false; - } - MESOSPHERE_ABORT_UNLESS(cur_ref_count < cur_ref_count + 1); - } while (!m_ref_count.compare_exchange_weak(cur_ref_count, cur_ref_count + 1, std::memory_order_relaxed)); - - return true; - } - - NOINLINE void Close() { - MESOSPHERE_ASSERT_THIS(); - - /* Atomically decrement the reference count, not allowing it to become negative. */ - u32 cur_ref_count = m_ref_count.load(std::memory_order_acquire); - do { - MESOSPHERE_ABORT_UNLESS(cur_ref_count > 0); - } while (!m_ref_count.compare_exchange_weak(cur_ref_count, cur_ref_count - 1, std::memory_order_relaxed)); - - /* If ref count hits zero, schedule the object for destruction. */ - if (cur_ref_count - 1 == 0) { - this->ScheduleDestruction(); - } - } + bool Open(); + void Close(); private: /* NOTE: This has to be defined *after* KThread is defined. */ /* Nintendo seems to handle this by defining Open/Close() in a cpp, but we'd like them to remain in headers. */ diff --git a/libraries/libmesosphere/source/kern_k_auto_object.cpp b/libraries/libmesosphere/source/kern_k_auto_object.cpp index 9ce0e58b9..07f648e4b 100644 --- a/libraries/libmesosphere/source/kern_k_auto_object.cpp +++ b/libraries/libmesosphere/source/kern_k_auto_object.cpp @@ -22,4 +22,35 @@ namespace ams::kern { return obj; } + NOINLINE bool KAutoObject::Open() { + MESOSPHERE_ASSERT_THIS(); + + /* Atomically increment the reference count, only if it's positive. */ + u32 cur_ref_count = m_ref_count.load(std::memory_order_relaxed); + do { + if (AMS_UNLIKELY(cur_ref_count == 0)) { + MESOSPHERE_AUDIT(cur_ref_count != 0); + return false; + } + MESOSPHERE_ABORT_UNLESS(cur_ref_count < cur_ref_count + 1); + } while (!m_ref_count.compare_exchange_weak(cur_ref_count, cur_ref_count + 1, std::memory_order_relaxed)); + + return true; + } + + NOINLINE void KAutoObject::Close() { + MESOSPHERE_ASSERT_THIS(); + + /* Atomically decrement the reference count, not allowing it to become negative. */ + u32 cur_ref_count = m_ref_count.load(std::memory_order_relaxed); + do { + MESOSPHERE_ABORT_UNLESS(cur_ref_count > 0); + } while (!m_ref_count.compare_exchange_weak(cur_ref_count, cur_ref_count - 1, std::memory_order_relaxed)); + + /* If ref count hits zero, schedule the object for destruction. */ + if (cur_ref_count - 1 == 0) { + this->ScheduleDestruction(); + } + } + }