diff options
author | Tom <tomut@yahoo.com> | 2020-08-24 19:35:19 -0600 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-08-25 09:48:48 +0200 |
commit | d89582880ed81c38df67687eadfc0764b6ce5ddd (patch) | |
tree | 3ff52c4e8808c5167ee37d5bf0a6669e9a18dfb4 /Kernel/Devices/VMWareBackdoor.cpp | |
parent | ba6e4fb77f00587d2bd57865a00b1a4526684741 (diff) | |
download | serenity-d89582880ed81c38df67687eadfc0764b6ce5ddd.zip |
Kernel: Switch singletons to use new Singleton class
MemoryManager cannot use the Singleton class because
MemoryManager::initialize is called before the global constructors
are run. That caused the Singleton to be re-initialized, causing
it to create another MemoryManager instance.
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..d1686da6c5 100644 --- a/Kernel/Devices/VMWareBackdoor.cpp +++ b/Kernel/Devices/VMWareBackdoor.cpp @@ -25,6 +25,8 @@ */ #include <AK/Assertions.h> +#include <AK/OwnPtr.h> +#include <AK/Singleton.h> #include <AK/String.h> #include <Kernel/Arch/i386/CPU.h> #include <Kernel/CommandLine.h> @@ -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 AK::Singleton<VMWareBackdoorDetector> s_vmware_backdoor; VMWareBackdoor* VMWareBackdoor::the() { - return s_vmware_backdoor; + return s_vmware_backdoor->get_instance(); } VMWareBackdoor::VMWareBackdoor() |