diff options
author | Tom <tomut@yahoo.com> | 2020-08-20 09:36:06 -0600 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-08-21 11:47:35 +0200 |
commit | f48feae0b2a300992479abf0b2ded85e45ac6045 (patch) | |
tree | d0b01169a60261135ee15a8d4a6abd01785a7bec /Kernel/Devices/VMWareBackdoor.cpp | |
parent | 527c8047fe0a08ade2e17fd096ad9b4ebc103ec5 (diff) | |
download | serenity-f48feae0b2a300992479abf0b2ded85e45ac6045.zip |
Kernel: Switch singletons to use new Singleton class
Fixes #3226
Diffstat (limited to 'Kernel/Devices/VMWareBackdoor.cpp')
-rw-r--r-- | Kernel/Devices/VMWareBackdoor.cpp | 51 |
1 files changed, 30 insertions, 21 deletions
diff --git a/Kernel/Devices/VMWareBackdoor.cpp b/Kernel/Devices/VMWareBackdoor.cpp index 20efb8e8fe..8ba15600da 100644 --- a/Kernel/Devices/VMWareBackdoor.cpp +++ b/Kernel/Devices/VMWareBackdoor.cpp @@ -25,12 +25,14 @@ */ #include <AK/Assertions.h> +#include <AK/OwnPtr.h> #include <AK/String.h> #include <Kernel/Arch/i386/CPU.h> #include <Kernel/CommandLine.h> #include <Kernel/Devices/VMWareBackdoor.h> #include <Kernel/API/MousePacket.h> #include <Kernel/IO.h> +#include <Kernel/Singleton.h> namespace Kernel { @@ -80,33 +82,40 @@ inline void vmware_high_bandwidth_get(VMWareCommand& command) : "+a"(command.ax), "+b"(command.bx), "+c"(command.cx), "+d"(command.dx), "+S"(command.si), "+D"(command.di)); } -static VMWareBackdoor* s_vmware_backdoor; - -static bool detect_presence() +class VMWareBackdoorDetector { - VMWareCommand command; - command.bx = ~VMWARE_MAGIC; - command.command = VMWARE_CMD_GETVERSION; - vmware_out(command); - if (command.bx != VMWARE_MAGIC || command.ax == 0xFFFFFFFF) - return false; - return true; -} +public: + VMWareBackdoorDetector() + { + if (detect_presence()) + m_backdoor = make<VMWareBackdoor>(); + } -VMWareBackdoor* VMWareBackdoor::initialize() -{ - ASSERT(s_vmware_backdoor == nullptr); - if (!detect_presence()) - return nullptr; + VMWareBackdoor* get_instance() + { + return m_backdoor.ptr(); + } - s_vmware_backdoor = new VMWareBackdoor; - klog() << "VMWare backdoor opened."; - return s_vmware_backdoor; -} +private: + static bool detect_presence() + { + VMWareCommand command; + command.bx = ~VMWARE_MAGIC; + command.command = VMWARE_CMD_GETVERSION; + vmware_out(command); + if (command.bx != VMWARE_MAGIC || command.ax == 0xFFFFFFFF) + return false; + return true; + } + + OwnPtr<VMWareBackdoor> m_backdoor; +}; + +static auto s_vmware_backdoor = make_singleton<VMWareBackdoorDetector>(); VMWareBackdoor* VMWareBackdoor::the() { - return s_vmware_backdoor; + return s_vmware_backdoor->get_instance(); } VMWareBackdoor::VMWareBackdoor() |