diff --git a/thermosphere/src/defines.hpp b/thermosphere/src/defines.hpp index d715c0142..4a19bf083 100644 --- a/thermosphere/src/defines.hpp +++ b/thermosphere/src/defines.hpp @@ -26,3 +26,11 @@ #include "preprocessor.h" #include "debug_log.h" + +#define SINGLETON(cl) \ + NON_COPYABLE(cl);\ + NON_MOVEABLE(cl);\ + private:\ + static cl instance;\ + public:\ + static cl &GetInstance() { return instance; } diff --git a/thermosphere/src/hvisor_hw_breakpoint_manager.hpp b/thermosphere/src/hvisor_hw_breakpoint_manager.hpp index 9967e4a97..6aff005e2 100644 --- a/thermosphere/src/hvisor_hw_breakpoint_manager.hpp +++ b/thermosphere/src/hvisor_hw_breakpoint_manager.hpp @@ -21,14 +21,10 @@ namespace ams::hvisor { class HwBreakpointManager final : public HwStopPointManager { + SINGLETON(HwBreakpointManager); protected: virtual bool FindPredicate(const cpu::DebugRegisterPair &pair, uintptr_t addr, size_t, cpu::DebugRegisterPair::LoadStoreControl) const; - private: - static HwBreakpointManager instance; - public: - static HwBreakpointManager &GetInstance() { return instance; } - public: virtual void ReloadOnAllCores() const; static void ReloadOnAllCoresSgiHandler(); diff --git a/thermosphere/src/hvisor_irq_manager.hpp b/thermosphere/src/hvisor_irq_manager.hpp index 4099a8c66..78364422e 100644 --- a/thermosphere/src/hvisor_irq_manager.hpp +++ b/thermosphere/src/hvisor_irq_manager.hpp @@ -25,11 +25,9 @@ namespace ams::hvisor { class IrqManager final { - NON_COPYABLE(IrqManager); - NON_MOVEABLE(IrqManager); + SINGLETON(IrqManager); friend class VirtualGic; private: - static IrqManager instance; static constexpr u8 hostPriority = 0; static constexpr u8 guestPriority = 1; @@ -92,8 +90,6 @@ namespace ams::hvisor { gicd->sgir = GicV2Distributor::ForwardToAllOthers << 24 | id; } - static IrqManager &GetInstance() { return instance; } - static void HandleInterrupt(ExceptionStackFrame *frame); public: diff --git a/thermosphere/src/hvisor_sw_breakpoint_manager.hpp b/thermosphere/src/hvisor_sw_breakpoint_manager.hpp index 4d8a9e7fe..bf27ea3e5 100644 --- a/thermosphere/src/hvisor_sw_breakpoint_manager.hpp +++ b/thermosphere/src/hvisor_sw_breakpoint_manager.hpp @@ -24,8 +24,7 @@ namespace ams::hvisor { class SwBreakpointManager { - NON_COPYABLE(SwBreakpointManager); - NON_MOVEABLE(SwBreakpointManager); + SINGLETON(SwBreakpointManager); private: struct Breakpoint { uintptr_t address; @@ -35,8 +34,6 @@ namespace ams::hvisor { bool applied; }; - private: - static SwBreakpointManager instance; private: mutable RecursiveSpinlock m_lock{}; std::atomic m_triedToApplyOrRevertBreakpoint{}; @@ -55,9 +52,6 @@ namespace ams::hvisor { bool Apply(size_t id); bool Revert(size_t id); - public: - static SwBreakpointManager &GetInstance() { return instance; } - public: int Add(uintptr_t addr, bool persistent); int Remove(uintptr_t addr, bool keepPersistent); diff --git a/thermosphere/src/hvisor_watchpoint_manager.hpp b/thermosphere/src/hvisor_watchpoint_manager.hpp index a0bf1373a..242085fbf 100644 --- a/thermosphere/src/hvisor_watchpoint_manager.hpp +++ b/thermosphere/src/hvisor_watchpoint_manager.hpp @@ -21,14 +21,10 @@ namespace ams::hvisor { class WatchpointManager final : public HwStopPointManager { + SINGLETON(WatchpointManager); protected: virtual bool FindPredicate(const cpu::DebugRegisterPair &pair, uintptr_t addr, size_t size, cpu::DebugRegisterPair::LoadStoreControl direction) const; - private: - static WatchpointManager instance; - public: - static WatchpointManager &GetInstance() { return instance; } - public: virtual void ReloadOnAllCores() const; static void ReloadOnAllCoresSgiHandler();