1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 08:17:35 +00:00

Kernel: Switch singletons to use new Singleton class

Fixes #3226
This commit is contained in:
Tom 2020-08-20 09:36:06 -06:00 committed by Andreas Kling
parent 527c8047fe
commit f48feae0b2
44 changed files with 184 additions and 146 deletions

View file

@ -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()