diff options
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() |