1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 12:48:10 +00:00

Revert "Kernel: Switch singletons to use new Singleton class"

This reverts commit f48feae0b2.
This commit is contained in:
Andreas Kling 2020-08-22 17:53:34 +02:00
parent 0addcb45b8
commit 2fd9e72264
44 changed files with 146 additions and 184 deletions

View file

@ -27,33 +27,29 @@
#include <Kernel/Console.h> #include <Kernel/Console.h>
#include <Kernel/IO.h> #include <Kernel/IO.h>
#include <Kernel/kstdio.h> #include <Kernel/kstdio.h>
#include <Kernel/Singleton.h>
#include <Kernel/SpinLock.h> #include <Kernel/SpinLock.h>
// Bytes output to 0xE9 end up on the Bochs console. It's very handy. // Bytes output to 0xE9 end up on the Bochs console. It's very handy.
#define CONSOLE_OUT_TO_E9 #define CONSOLE_OUT_TO_E9
static auto s_the = Kernel::make_singleton<Console>(); static Console* s_the;
static Kernel::SpinLock g_console_lock; static Kernel::SpinLock g_console_lock;
void Console::initialize()
{
s_the.ensure_instance();
}
Console& Console::the() Console& Console::the()
{ {
ASSERT(s_the);
return *s_the; return *s_the;
} }
bool Console::is_initialized() bool Console::is_initialized()
{ {
return s_the.is_initialized(); return s_the != nullptr;
} }
Console::Console() Console::Console()
: CharacterDevice(5, 1) : CharacterDevice(5, 1)
{ {
s_the = this;
} }
Console::~Console() Console::~Console()

View file

@ -34,7 +34,6 @@ class Console final : public Kernel::CharacterDevice {
AK_MAKE_ETERNAL AK_MAKE_ETERNAL
public: public:
static Console& the(); static Console& the();
static void initialize();
static bool is_initialized(); static bool is_initialized();
Console(); Console();

View file

@ -29,7 +29,6 @@
#include <Kernel/IO.h> #include <Kernel/IO.h>
#include <Kernel/PCI/Access.h> #include <Kernel/PCI/Access.h>
#include <Kernel/Process.h> #include <Kernel/Process.h>
#include <Kernel/Singleton.h>
#include <Kernel/VM/AnonymousVMObject.h> #include <Kernel/VM/AnonymousVMObject.h>
#include <Kernel/VM/MemoryManager.h> #include <Kernel/VM/MemoryManager.h>
#include <LibC/errno_numbers.h> #include <LibC/errno_numbers.h>
@ -57,12 +56,7 @@ namespace Kernel {
#define VBE_DISPI_ENABLED 0x01 #define VBE_DISPI_ENABLED 0x01
#define VBE_DISPI_LFB_ENABLED 0x40 #define VBE_DISPI_LFB_ENABLED 0x40
static auto s_the = make_singleton<BXVGADevice>(); static BXVGADevice* s_the;
void BXVGADevice::initialize()
{
s_the.ensure_instance();
}
BXVGADevice& BXVGADevice::the() BXVGADevice& BXVGADevice::the()
{ {
@ -73,6 +67,7 @@ BXVGADevice::BXVGADevice()
: BlockDevice(29, 0) : BlockDevice(29, 0)
{ {
s_the = this;
m_framebuffer_address = PhysicalAddress(find_framebuffer_address()); m_framebuffer_address = PhysicalAddress(find_framebuffer_address());
set_safe_resolution(); set_safe_resolution();
} }

View file

@ -36,7 +36,6 @@ namespace Kernel {
class BXVGADevice final : public BlockDevice { class BXVGADevice final : public BlockDevice {
AK_MAKE_ETERNAL AK_MAKE_ETERNAL
public: public:
static void initialize();
static BXVGADevice& the(); static BXVGADevice& the();
BXVGADevice(); BXVGADevice();

View file

@ -26,15 +26,16 @@
#include <Kernel/Devices/Device.h> #include <Kernel/Devices/Device.h>
#include <Kernel/FileSystem/InodeMetadata.h> #include <Kernel/FileSystem/InodeMetadata.h>
#include <Kernel/Singleton.h>
#include <LibC/errno_numbers.h> #include <LibC/errno_numbers.h>
namespace Kernel { namespace Kernel {
static auto s_all_devices = make_singleton<HashMap<u32, Device*>>(); static HashMap<u32, Device*>* s_all_devices;
HashMap<u32, Device*>& Device::all_devices() HashMap<u32, Device*>& Device::all_devices()
{ {
if (s_all_devices == nullptr)
s_all_devices = new HashMap<u32, Device*>;
return *s_all_devices; return *s_all_devices;
} }

View file

@ -31,7 +31,6 @@
#include <Kernel/Arch/i386/CPU.h> #include <Kernel/Arch/i386/CPU.h>
#include <Kernel/Devices/KeyboardDevice.h> #include <Kernel/Devices/KeyboardDevice.h>
#include <Kernel/IO.h> #include <Kernel/IO.h>
#include <Kernel/Singleton.h>
#include <Kernel/TTY/VirtualConsole.h> #include <Kernel/TTY/VirtualConsole.h>
//#define KEYBOARD_DEBUG //#define KEYBOARD_DEBUG
@ -336,15 +335,11 @@ void KeyboardDevice::handle_irq(const RegisterState&)
} }
} }
static auto s_the = make_singleton<KeyboardDevice>(); static KeyboardDevice* s_the;
void KeyboardDevice::initialize()
{
s_the.ensure_instance();
}
KeyboardDevice& KeyboardDevice::the() KeyboardDevice& KeyboardDevice::the()
{ {
ASSERT(s_the);
return *s_the; return *s_the;
} }
@ -352,6 +347,8 @@ KeyboardDevice::KeyboardDevice()
: IRQHandler(IRQ_KEYBOARD) : IRQHandler(IRQ_KEYBOARD)
, CharacterDevice(85, 1) , CharacterDevice(85, 1)
{ {
s_the = this;
// Empty the buffer of any pending data. // Empty the buffer of any pending data.
// I don't care what you've been pressing until now! // I don't care what you've been pressing until now!
while (IO::in8(I8042_STATUS) & I8042_BUFFER_FULL) while (IO::in8(I8042_STATUS) & I8042_BUFFER_FULL)

View file

@ -45,7 +45,6 @@ class KeyboardDevice final : public IRQHandler
public: public:
using Event = KeyEvent; using Event = KeyEvent;
static void initialize();
static KeyboardDevice& the(); static KeyboardDevice& the();
virtual ~KeyboardDevice() override; virtual ~KeyboardDevice() override;

View file

@ -26,25 +26,21 @@
#include "NullDevice.h" #include "NullDevice.h"
#include <AK/StdLibExtras.h> #include <AK/StdLibExtras.h>
#include <Kernel/Singleton.h>
namespace Kernel { namespace Kernel {
static auto s_the = make_singleton<NullDevice>(); static NullDevice* s_the;
void NullDevice::initialize()
{
s_the.ensure_instance();
}
NullDevice& NullDevice::the() NullDevice& NullDevice::the()
{ {
ASSERT(s_the);
return *s_the; return *s_the;
} }
NullDevice::NullDevice() NullDevice::NullDevice()
: CharacterDevice(1, 3) : CharacterDevice(1, 3)
{ {
s_the = this;
} }
NullDevice::~NullDevice() NullDevice::~NullDevice()

View file

@ -36,7 +36,6 @@ public:
NullDevice(); NullDevice();
virtual ~NullDevice() override; virtual ~NullDevice() override;
static void initialize();
static NullDevice& the(); static NullDevice& the();
private: private:

View file

@ -31,7 +31,6 @@
#include <Kernel/FileSystem/ProcFS.h> #include <Kernel/FileSystem/ProcFS.h>
#include <Kernel/IO.h> #include <Kernel/IO.h>
#include <Kernel/Process.h> #include <Kernel/Process.h>
#include <Kernel/Singleton.h>
#include <Kernel/VM/MemoryManager.h> #include <Kernel/VM/MemoryManager.h>
namespace Kernel { namespace Kernel {
@ -107,12 +106,13 @@ namespace Kernel {
#define PCI_Mass_Storage_Class 0x1 #define PCI_Mass_Storage_Class 0x1
#define PCI_IDE_Controller_Subclass 0x1 #define PCI_IDE_Controller_Subclass 0x1
static auto s_pata_lock = make_singleton<Lock>();
static Lock& s_lock() static Lock& s_lock()
{ {
return *s_pata_lock; static Lock* lock;
if (!lock)
lock = new Lock;
return *lock;
}; };
OwnPtr<PATAChannel> PATAChannel::create(ChannelType type, bool force_pio) OwnPtr<PATAChannel> PATAChannel::create(ChannelType type, bool force_pio)

View file

@ -28,7 +28,6 @@
#include <Kernel/Devices/PS2MouseDevice.h> #include <Kernel/Devices/PS2MouseDevice.h>
#include <Kernel/Devices/VMWareBackdoor.h> #include <Kernel/Devices/VMWareBackdoor.h>
#include <Kernel/IO.h> #include <Kernel/IO.h>
#include <Kernel/Singleton.h>
namespace Kernel { namespace Kernel {
@ -57,12 +56,13 @@ namespace Kernel {
//#define PS2MOUSE_DEBUG //#define PS2MOUSE_DEBUG
static auto s_the = make_singleton<PS2MouseDevice>(); static PS2MouseDevice* s_the;
PS2MouseDevice::PS2MouseDevice() PS2MouseDevice::PS2MouseDevice()
: IRQHandler(IRQ_MOUSE) : IRQHandler(IRQ_MOUSE)
, CharacterDevice(10, 1) , CharacterDevice(10, 1)
{ {
s_the = this;
initialize(); initialize();
} }
@ -70,11 +70,6 @@ PS2MouseDevice::~PS2MouseDevice()
{ {
} }
void PS2MouseDevice::create()
{
s_the.ensure_instance();
}
PS2MouseDevice& PS2MouseDevice::the() PS2MouseDevice& PS2MouseDevice::the()
{ {
return *s_the; return *s_the;

View file

@ -40,7 +40,6 @@ public:
PS2MouseDevice(); PS2MouseDevice();
virtual ~PS2MouseDevice() override; virtual ~PS2MouseDevice() override;
static void create();
static PS2MouseDevice& the(); static PS2MouseDevice& the();
// ^CharacterDevice // ^CharacterDevice

View file

@ -31,7 +31,6 @@
#include <Kernel/VM/AnonymousVMObject.h> #include <Kernel/VM/AnonymousVMObject.h>
#include <Kernel/VM/MemoryManager.h> #include <Kernel/VM/MemoryManager.h>
#include <Kernel/IO.h> #include <Kernel/IO.h>
#include <Kernel/Singleton.h>
//#define SB16_DEBUG //#define SB16_DEBUG
@ -77,12 +76,13 @@ void SB16::set_sample_rate(uint16_t hz)
dsp_write((u8)hz); dsp_write((u8)hz);
} }
static auto s_the = make_singleton<SB16>(); static SB16* s_the;
SB16::SB16() SB16::SB16()
: IRQHandler(SB16_DEFAULT_IRQ) : IRQHandler(SB16_DEFAULT_IRQ)
, CharacterDevice(42, 42) // ### ? , CharacterDevice(42, 42) // ### ?
{ {
s_the = this;
initialize(); initialize();
} }
@ -90,11 +90,6 @@ SB16::~SB16()
{ {
} }
void SB16::create()
{
s_the.ensure_instance();
}
SB16& SB16::the() SB16& SB16::the()
{ {
return *s_the; return *s_the;

View file

@ -42,7 +42,6 @@ public:
SB16(); SB16();
virtual ~SB16() override; virtual ~SB16() override;
static void create();
static SB16& the(); static SB16& the();
// ^CharacterDevice // ^CharacterDevice

View file

@ -25,14 +25,12 @@
*/ */
#include <AK/Assertions.h> #include <AK/Assertions.h>
#include <AK/OwnPtr.h>
#include <AK/String.h> #include <AK/String.h>
#include <Kernel/Arch/i386/CPU.h> #include <Kernel/Arch/i386/CPU.h>
#include <Kernel/CommandLine.h> #include <Kernel/CommandLine.h>
#include <Kernel/Devices/VMWareBackdoor.h> #include <Kernel/Devices/VMWareBackdoor.h>
#include <Kernel/API/MousePacket.h> #include <Kernel/API/MousePacket.h>
#include <Kernel/IO.h> #include <Kernel/IO.h>
#include <Kernel/Singleton.h>
namespace Kernel { namespace Kernel {
@ -82,40 +80,33 @@ 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)); : "+a"(command.ax), "+b"(command.bx), "+c"(command.cx), "+d"(command.dx), "+S"(command.si), "+D"(command.di));
} }
class VMWareBackdoorDetector static VMWareBackdoor* s_vmware_backdoor;
static bool detect_presence()
{ {
public: VMWareCommand command;
VMWareBackdoorDetector() command.bx = ~VMWARE_MAGIC;
{ command.command = VMWARE_CMD_GETVERSION;
if (detect_presence()) vmware_out(command);
m_backdoor = make<VMWareBackdoor>(); if (command.bx != VMWARE_MAGIC || command.ax == 0xFFFFFFFF)
} return false;
return true;
}
VMWareBackdoor* get_instance() VMWareBackdoor* VMWareBackdoor::initialize()
{ {
return m_backdoor.ptr(); ASSERT(s_vmware_backdoor == nullptr);
} if (!detect_presence())
return nullptr;
private: s_vmware_backdoor = new VMWareBackdoor;
static bool detect_presence() klog() << "VMWare backdoor opened.";
{ return s_vmware_backdoor;
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() VMWareBackdoor* VMWareBackdoor::the()
{ {
return s_vmware_backdoor->get_instance(); return s_vmware_backdoor;
} }
VMWareBackdoor::VMWareBackdoor() VMWareBackdoor::VMWareBackdoor()

View file

@ -63,9 +63,9 @@ class VMWareBackdoor {
AK_MAKE_ETERNAL; AK_MAKE_ETERNAL;
public: public:
VMWareBackdoor();
static VMWareBackdoor* the(); static VMWareBackdoor* the();
static VMWareBackdoor* initialize();
bool vmmouse_is_absolute() const; bool vmmouse_is_absolute() const;
void enable_absolute_vmmouse(); void enable_absolute_vmmouse();
void disable_absolute_vmmouse(); void disable_absolute_vmmouse();
@ -76,6 +76,7 @@ public:
private: private:
void send_high_bandwidth(VMWareCommand& command); void send_high_bandwidth(VMWareCommand& command);
void get_high_bandwidth(VMWareCommand& command); void get_high_bandwidth(VMWareCommand& command);
VMWareBackdoor();
bool detect_vmmouse(); bool detect_vmmouse();
bool m_vmmouse_absolute { false }; bool m_vmmouse_absolute { false };
}; };

View file

@ -28,7 +28,6 @@
#include <AK/StringView.h> #include <AK/StringView.h>
#include <Kernel/FileSystem/DevPtsFS.h> #include <Kernel/FileSystem/DevPtsFS.h>
#include <Kernel/FileSystem/VirtualFileSystem.h> #include <Kernel/FileSystem/VirtualFileSystem.h>
#include <Kernel/Singleton.h>
#include <Kernel/TTY/SlavePTY.h> #include <Kernel/TTY/SlavePTY.h>
namespace Kernel { namespace Kernel {
@ -46,10 +45,14 @@ DevPtsFS::~DevPtsFS()
{ {
} }
static auto s_ptys = make_singleton<HashTable<unsigned>>(); static HashTable<unsigned>* ptys;
bool DevPtsFS::initialize() bool DevPtsFS::initialize()
{ {
if (ptys == nullptr) {
ptys = new HashTable<unsigned>();
}
m_root_inode = adopt(*new DevPtsFSInode(*this, 1)); m_root_inode = adopt(*new DevPtsFSInode(*this, 1));
m_root_inode->m_metadata.inode = { fsid(), 1 }; m_root_inode->m_metadata.inode = { fsid(), 1 };
m_root_inode->m_metadata.mode = 0040555; m_root_inode->m_metadata.mode = 0040555;
@ -101,12 +104,12 @@ RefPtr<Inode> DevPtsFS::get_inode(InodeIdentifier inode_id) const
void DevPtsFS::register_slave_pty(SlavePTY& slave_pty) void DevPtsFS::register_slave_pty(SlavePTY& slave_pty)
{ {
s_ptys->set(slave_pty.index()); ptys->set(slave_pty.index());
} }
void DevPtsFS::unregister_slave_pty(SlavePTY& slave_pty) void DevPtsFS::unregister_slave_pty(SlavePTY& slave_pty)
{ {
s_ptys->remove(slave_pty.index()); ptys->remove(slave_pty.index());
} }
DevPtsFSInode::DevPtsFSInode(DevPtsFS& fs, unsigned index) DevPtsFSInode::DevPtsFSInode(DevPtsFS& fs, unsigned index)
@ -141,7 +144,7 @@ KResult DevPtsFSInode::traverse_as_directory(Function<bool(const FS::DirectoryEn
callback({ ".", identifier(), 0 }); callback({ ".", identifier(), 0 });
callback({ "..", identifier(), 0 }); callback({ "..", identifier(), 0 });
for (unsigned pty_index : *s_ptys) { for (unsigned pty_index : *ptys) {
String name = String::number(pty_index); String name = String::number(pty_index);
InodeIdentifier identifier = { fsid(), pty_index_to_inode_index(pty_index) }; InodeIdentifier identifier = { fsid(), pty_index_to_inode_index(pty_index) };
callback({ name, identifier, 0 }); callback({ name, identifier, 0 });
@ -154,7 +157,7 @@ KResultOr<size_t> DevPtsFSInode::directory_entry_count() const
{ {
ASSERT(identifier().index() == 1); ASSERT(identifier().index() == 1);
return 2 + s_ptys->size(); return 2 + ptys->size();
} }
RefPtr<Inode> DevPtsFSInode::lookup(StringView name) RefPtr<Inode> DevPtsFSInode::lookup(StringView name)
@ -167,7 +170,7 @@ RefPtr<Inode> DevPtsFSInode::lookup(StringView name)
auto& fs = static_cast<DevPtsFS&>(this->fs()); auto& fs = static_cast<DevPtsFS&>(this->fs());
auto pty_index = name.to_uint(); auto pty_index = name.to_uint();
if (pty_index.has_value() && s_ptys->contains(pty_index.value())) { if (pty_index.has_value() && ptys->contains(pty_index.value())) {
return fs.get_inode({ fsid(), pty_index_to_inode_index(pty_index.value()) }); return fs.get_inode({ fsid(), pty_index_to_inode_index(pty_index.value()) });
} }

View file

@ -31,17 +31,17 @@
#include <Kernel/FileSystem/FileDescription.h> #include <Kernel/FileSystem/FileDescription.h>
#include <Kernel/Lock.h> #include <Kernel/Lock.h>
#include <Kernel/Process.h> #include <Kernel/Process.h>
#include <Kernel/Singleton.h>
#include <Kernel/Thread.h> #include <Kernel/Thread.h>
//#define FIFO_DEBUG //#define FIFO_DEBUG
namespace Kernel { namespace Kernel {
static auto s_table = make_singleton<Lockable<HashTable<FIFO*>>>();
static Lockable<HashTable<FIFO*>>& all_fifos() static Lockable<HashTable<FIFO*>>& all_fifos()
{ {
static Lockable<HashTable<FIFO*>>* s_table;
if (!s_table)
s_table = new Lockable<HashTable<FIFO*>>;
return *s_table; return *s_table;
} }

View file

@ -31,17 +31,18 @@
#include <Kernel/FileSystem/FileSystem.h> #include <Kernel/FileSystem/FileSystem.h>
#include <Kernel/FileSystem/Inode.h> #include <Kernel/FileSystem/Inode.h>
#include <Kernel/Net/LocalSocket.h> #include <Kernel/Net/LocalSocket.h>
#include <Kernel/Singleton.h>
#include <Kernel/VM/MemoryManager.h> #include <Kernel/VM/MemoryManager.h>
#include <LibC/errno_numbers.h> #include <LibC/errno_numbers.h>
namespace Kernel { namespace Kernel {
static u32 s_lastFileSystemID; static u32 s_lastFileSystemID;
static auto s_fs_map = make_singleton<HashMap<u32, FS*>>(); static HashMap<u32, FS*>* s_fs_map;
static HashMap<u32, FS*>& all_fses() static HashMap<u32, FS*>& all_fses()
{ {
if (!s_fs_map)
s_fs_map = new HashMap<u32, FS*>();
return *s_fs_map; return *s_fs_map;
} }

View file

@ -33,19 +33,20 @@
#include <Kernel/FileSystem/VirtualFileSystem.h> #include <Kernel/FileSystem/VirtualFileSystem.h>
#include <Kernel/KBufferBuilder.h> #include <Kernel/KBufferBuilder.h>
#include <Kernel/Net/LocalSocket.h> #include <Kernel/Net/LocalSocket.h>
#include <Kernel/Singleton.h>
#include <Kernel/VM/SharedInodeVMObject.h> #include <Kernel/VM/SharedInodeVMObject.h>
namespace Kernel { namespace Kernel {
static SpinLock s_all_inodes_lock; static SpinLock s_all_inodes_lock;
static auto s_list = make_singleton<InlineLinkedList<Inode>>();
InlineLinkedList<Inode>& Inode::all_with_lock() InlineLinkedList<Inode>& Inode::all_with_lock()
{ {
ASSERT(s_all_inodes_lock.is_locked()); ASSERT(s_all_inodes_lock.is_locked());
return *s_list; static InlineLinkedList<Inode>* list;
if (!list)
list = new InlineLinkedList<Inode>;
return *list;
} }
void Inode::sync() void Inode::sync()

View file

@ -34,24 +34,19 @@
#include <Kernel/FileSystem/VirtualFileSystem.h> #include <Kernel/FileSystem/VirtualFileSystem.h>
#include <Kernel/KSyms.h> #include <Kernel/KSyms.h>
#include <Kernel/Process.h> #include <Kernel/Process.h>
#include <Kernel/Singleton.h>
#include <LibC/errno_numbers.h> #include <LibC/errno_numbers.h>
//#define VFS_DEBUG //#define VFS_DEBUG
namespace Kernel { namespace Kernel {
static auto s_the = make_singleton<VFS>(); static VFS* s_the;
static constexpr int symlink_recursion_limit { 5 }; // FIXME: increase? static constexpr int symlink_recursion_limit { 5 }; // FIXME: increase?
static constexpr int root_mount_flags = MS_NODEV | MS_NOSUID | MS_RDONLY; static constexpr int root_mount_flags = MS_NODEV | MS_NOSUID | MS_RDONLY;
void VFS::initialize()
{
s_the.ensure_instance();
}
VFS& VFS::the() VFS& VFS::the()
{ {
ASSERT(s_the);
return *s_the; return *s_the;
} }
@ -60,6 +55,7 @@ VFS::VFS()
#ifdef VFS_DEBUG #ifdef VFS_DEBUG
klog() << "VFS: Constructing VFS"; klog() << "VFS: Constructing VFS";
#endif #endif
s_the = this;
} }
VFS::~VFS() VFS::~VFS()

View file

@ -78,7 +78,6 @@ public:
int m_flags; int m_flags;
}; };
static void initialize();
static VFS& the(); static VFS& the();
VFS(); VFS();

View file

@ -34,7 +34,6 @@
#include <Kernel/IO.h> #include <Kernel/IO.h>
#include <Kernel/Interrupts/APIC.h> #include <Kernel/Interrupts/APIC.h>
#include <Kernel/Interrupts/SpuriousInterruptHandler.h> #include <Kernel/Interrupts/SpuriousInterruptHandler.h>
#include <Kernel/Singleton.h>
#include <Kernel/Thread.h> #include <Kernel/Thread.h>
#include <Kernel/VM/MemoryManager.h> #include <Kernel/VM/MemoryManager.h>
#include <Kernel/VM/PageDirectory.h> #include <Kernel/VM/PageDirectory.h>
@ -69,7 +68,7 @@
namespace Kernel { namespace Kernel {
static auto s_apic = make_singleton<APIC>(); static APIC* s_apic;
class APICIPIInterruptHandler final : public GenericInterruptHandler { class APICIPIInterruptHandler final : public GenericInterruptHandler {
public: public:
@ -133,7 +132,7 @@ private:
bool APIC::initialized() bool APIC::initialized()
{ {
return s_apic.is_initialized(); return (s_apic != nullptr);
} }
APIC& APIC::the() APIC& APIC::the()
@ -145,7 +144,7 @@ APIC& APIC::the()
void APIC::initialize() void APIC::initialize()
{ {
ASSERT(!APIC::initialized()); ASSERT(!APIC::initialized());
s_apic.ensure_instance(); s_apic = new APIC();
} }
PhysicalAddress APIC::get_base() PhysicalAddress APIC::get_base()

View file

@ -25,7 +25,6 @@
*/ */
#include <AK/StringBuilder.h> #include <AK/StringBuilder.h>
#include <Kernel/Singleton.h>
#include <Kernel/FileSystem/FileDescription.h> #include <Kernel/FileSystem/FileDescription.h>
#include <Kernel/Net/ARP.h> #include <Kernel/Net/ARP.h>
#include <Kernel/Net/ICMP.h> #include <Kernel/Net/ICMP.h>
@ -46,10 +45,11 @@
namespace Kernel { namespace Kernel {
static auto s_table = make_singleton<Lockable<HashTable<IPv4Socket*>>>();
Lockable<HashTable<IPv4Socket*>>& IPv4Socket::all_sockets() Lockable<HashTable<IPv4Socket*>>& IPv4Socket::all_sockets()
{ {
static Lockable<HashTable<IPv4Socket*>>* s_table;
if (!s_table)
s_table = new Lockable<HashTable<IPv4Socket*>>;
return *s_table; return *s_table;
} }

View file

@ -29,7 +29,6 @@
#include <Kernel/FileSystem/VirtualFileSystem.h> #include <Kernel/FileSystem/VirtualFileSystem.h>
#include <Kernel/Net/LocalSocket.h> #include <Kernel/Net/LocalSocket.h>
#include <Kernel/Process.h> #include <Kernel/Process.h>
#include <Kernel/Singleton.h>
#include <Kernel/StdLib.h> #include <Kernel/StdLib.h>
#include <Kernel/UnixTypes.h> #include <Kernel/UnixTypes.h>
#include <LibC/errno_numbers.h> #include <LibC/errno_numbers.h>
@ -38,10 +37,11 @@
namespace Kernel { namespace Kernel {
static auto s_list = make_singleton<Lockable<InlineLinkedList<LocalSocket>>>();
Lockable<InlineLinkedList<LocalSocket>>& LocalSocket::all_sockets() Lockable<InlineLinkedList<LocalSocket>>& LocalSocket::all_sockets()
{ {
static Lockable<InlineLinkedList<LocalSocket>>* s_list;
if (!s_list)
s_list = new Lockable<InlineLinkedList<LocalSocket>>();
return *s_list; return *s_list;
} }

View file

@ -25,15 +25,15 @@
*/ */
#include <Kernel/Net/LoopbackAdapter.h> #include <Kernel/Net/LoopbackAdapter.h>
#include <Kernel/Singleton.h>
namespace Kernel { namespace Kernel {
static auto s_loopback = make_singleton<LoopbackAdapter>();
LoopbackAdapter& LoopbackAdapter::the() LoopbackAdapter& LoopbackAdapter::the()
{ {
return *s_loopback; static LoopbackAdapter* the;
if (!the)
the = new LoopbackAdapter;
return *the;
} }
LoopbackAdapter::LoopbackAdapter() LoopbackAdapter::LoopbackAdapter()

View file

@ -33,13 +33,15 @@ namespace Kernel {
class LoopbackAdapter final : public NetworkAdapter { class LoopbackAdapter final : public NetworkAdapter {
AK_MAKE_ETERNAL AK_MAKE_ETERNAL
public: public:
LoopbackAdapter();
static LoopbackAdapter& the(); static LoopbackAdapter& the();
virtual ~LoopbackAdapter() override; virtual ~LoopbackAdapter() override;
virtual void send_raw(ReadonlyBytes) override; virtual void send_raw(ReadonlyBytes) override;
virtual const char* class_name() const override { return "LoopbackAdapter"; } virtual const char* class_name() const override { return "LoopbackAdapter"; }
private:
LoopbackAdapter();
}; };
} }

View file

@ -33,16 +33,16 @@
#include <Kernel/Net/LoopbackAdapter.h> #include <Kernel/Net/LoopbackAdapter.h>
#include <Kernel/Net/NetworkAdapter.h> #include <Kernel/Net/NetworkAdapter.h>
#include <Kernel/Random.h> #include <Kernel/Random.h>
#include <Kernel/Singleton.h>
#include <Kernel/StdLib.h> #include <Kernel/StdLib.h>
namespace Kernel { namespace Kernel {
static auto s_table = make_singleton<Lockable<HashTable<NetworkAdapter*>>>();
static Lockable<HashTable<NetworkAdapter*>>& all_adapters() static Lockable<HashTable<NetworkAdapter*>>& all_adapters()
{ {
return *s_table; static Lockable<HashTable<NetworkAdapter*>>* table;
if (!table)
table = new Lockable<HashTable<NetworkAdapter*>>;
return *table;
} }
void NetworkAdapter::for_each(Function<void(NetworkAdapter&)> callback) void NetworkAdapter::for_each(Function<void(NetworkAdapter&)> callback)

View file

@ -28,17 +28,17 @@
#include <Kernel/Net/LoopbackAdapter.h> #include <Kernel/Net/LoopbackAdapter.h>
#include <Kernel/Net/Routing.h> #include <Kernel/Net/Routing.h>
#include <Kernel/Thread.h> #include <Kernel/Thread.h>
#include <Kernel/Singleton.h>
//#define ROUTING_DEBUG //#define ROUTING_DEBUG
namespace Kernel { namespace Kernel {
static auto s_arp_table = make_singleton<Lockable<HashMap<IPv4Address, MACAddress>>>();
Lockable<HashMap<IPv4Address, MACAddress>>& arp_table() Lockable<HashMap<IPv4Address, MACAddress>>& arp_table()
{ {
return *s_arp_table; static Lockable<HashMap<IPv4Address, MACAddress>>* the;
if (!the)
the = new Lockable<HashMap<IPv4Address, MACAddress>>;
return *the;
} }
bool RoutingDecision::is_zero() const bool RoutingDecision::is_zero() const

View file

@ -33,7 +33,6 @@
#include <Kernel/Net/TCPSocket.h> #include <Kernel/Net/TCPSocket.h>
#include <Kernel/Process.h> #include <Kernel/Process.h>
#include <Kernel/Random.h> #include <Kernel/Random.h>
#include <Kernel/Singleton.h>
//#define TCP_SOCKET_DEBUG //#define TCP_SOCKET_DEBUG
@ -71,10 +70,11 @@ Lockable<HashMap<IPv4SocketTuple, RefPtr<TCPSocket>>>& TCPSocket::closing_socket
return *s_map; return *s_map;
} }
static auto s_map = make_singleton<Lockable<HashMap<IPv4SocketTuple, TCPSocket*>>>();
Lockable<HashMap<IPv4SocketTuple, TCPSocket*>>& TCPSocket::sockets_by_tuple() Lockable<HashMap<IPv4SocketTuple, TCPSocket*>>& TCPSocket::sockets_by_tuple()
{ {
static Lockable<HashMap<IPv4SocketTuple, TCPSocket*>>* s_map;
if (!s_map)
s_map = new Lockable<HashMap<IPv4SocketTuple, TCPSocket*>>;
return *s_map; return *s_map;
} }

View file

@ -31,7 +31,6 @@
#include <Kernel/Net/UDPSocket.h> #include <Kernel/Net/UDPSocket.h>
#include <Kernel/Process.h> #include <Kernel/Process.h>
#include <Kernel/Random.h> #include <Kernel/Random.h>
#include <Kernel/Singleton.h>
namespace Kernel { namespace Kernel {
@ -42,10 +41,11 @@ void UDPSocket::for_each(Function<void(const UDPSocket&)> callback)
callback(*it.value); callback(*it.value);
} }
static auto s_map = make_singleton<Lockable<HashMap<u16, UDPSocket*>>>();
Lockable<HashMap<u16, UDPSocket*>>& UDPSocket::sockets_by_port() Lockable<HashMap<u16, UDPSocket*>>& UDPSocket::sockets_by_port()
{ {
static Lockable<HashMap<u16, UDPSocket*>>* s_map;
if (!s_map)
s_map = new Lockable<HashMap<u16, UDPSocket*>>;
return *s_map; return *s_map;
} }

View file

@ -28,15 +28,17 @@
#include <Kernel/Arch/i386/CPU.h> #include <Kernel/Arch/i386/CPU.h>
#include <Kernel/Devices/RandomDevice.h> #include <Kernel/Devices/RandomDevice.h>
#include <Kernel/Random.h> #include <Kernel/Random.h>
#include <Kernel/Singleton.h>
#include <Kernel/Time/TimeManagement.h> #include <Kernel/Time/TimeManagement.h>
namespace Kernel { namespace Kernel {
static auto s_the = make_singleton<KernelRng>(); static KernelRng* s_the;
KernelRng& KernelRng::the() KernelRng& KernelRng::the()
{ {
if (!s_the) {
s_the = new KernelRng;
}
return *s_the; return *s_the;
} }

View file

@ -127,7 +127,6 @@ class KernelRng : public Lockable<FortunaPRNG<Crypto::Cipher::AESCipher, Crypto:
AK_MAKE_ETERNAL; AK_MAKE_ETERNAL;
public: public:
KernelRng();
static KernelRng& the(); static KernelRng& the();
void wait_for_entropy(); void wait_for_entropy();
@ -135,6 +134,8 @@ public:
void wake_if_ready(); void wake_if_ready();
private: private:
KernelRng();
WaitQueue m_seed_queue; WaitQueue m_seed_queue;
}; };

View file

@ -25,16 +25,16 @@
*/ */
#include <Kernel/Process.h> #include <Kernel/Process.h>
#include <Kernel/Singleton.h>
#include <Kernel/SharedBuffer.h> #include <Kernel/SharedBuffer.h>
namespace Kernel { namespace Kernel {
static auto s_map = make_singleton<Lockable<HashMap<int, NonnullOwnPtr<SharedBuffer>>>>();
Lockable<HashMap<int, NonnullOwnPtr<SharedBuffer>>>& shared_buffers() Lockable<HashMap<int, NonnullOwnPtr<SharedBuffer>>>& shared_buffers()
{ {
return *s_map; static Lockable<HashMap<int, NonnullOwnPtr<SharedBuffer>>>* map;
if (!map)
map = new Lockable<HashMap<int, NonnullOwnPtr<SharedBuffer>>>;
return *map;
} }
void SharedBuffer::sanity_check(const char* what) void SharedBuffer::sanity_check(const char* what)

View file

@ -28,7 +28,6 @@
#include "MasterPTY.h" #include "MasterPTY.h"
#include <Kernel/FileSystem/FileDescription.h> #include <Kernel/FileSystem/FileDescription.h>
#include <Kernel/Process.h> #include <Kernel/Process.h>
#include <Kernel/Singleton.h>
#include <LibC/errno_numbers.h> #include <LibC/errno_numbers.h>
//#define PTMX_DEBUG //#define PTMX_DEBUG
@ -36,16 +35,18 @@
namespace Kernel { namespace Kernel {
static const unsigned s_max_pty_pairs = 8; static const unsigned s_max_pty_pairs = 8;
static auto s_the = make_singleton<PTYMultiplexer>(); static PTYMultiplexer* s_the;
PTYMultiplexer& PTYMultiplexer::the() PTYMultiplexer& PTYMultiplexer::the()
{ {
ASSERT(s_the);
return *s_the; return *s_the;
} }
PTYMultiplexer::PTYMultiplexer() PTYMultiplexer::PTYMultiplexer()
: CharacterDevice(5, 2) : CharacterDevice(5, 2)
{ {
s_the = this;
m_freelist.ensure_capacity(s_max_pty_pairs); m_freelist.ensure_capacity(s_max_pty_pairs);
for (int i = s_max_pty_pairs; i > 0; --i) for (int i = s_max_pty_pairs; i > 0; --i)
m_freelist.unchecked_append(i - 1); m_freelist.unchecked_append(i - 1);

View file

@ -40,10 +40,6 @@ public:
PTYMultiplexer(); PTYMultiplexer();
virtual ~PTYMultiplexer() override; virtual ~PTYMultiplexer() override;
static void initialize()
{
the();
}
static PTYMultiplexer& the(); static PTYMultiplexer& the();
// ^CharacterDevice // ^CharacterDevice

View file

@ -32,7 +32,6 @@
#include <Kernel/Time/HardwareTimer.h> #include <Kernel/Time/HardwareTimer.h>
#include <Kernel/Time/PIT.h> #include <Kernel/Time/PIT.h>
#include <Kernel/Time/RTC.h> #include <Kernel/Time/RTC.h>
#include <Kernel/Singleton.h>
#include <Kernel/Time/TimeManagement.h> #include <Kernel/Time/TimeManagement.h>
#include <Kernel/VM/MemoryManager.h> #include <Kernel/VM/MemoryManager.h>
@ -40,11 +39,12 @@
namespace Kernel { namespace Kernel {
static auto s_the = make_singleton<TimeManagement>(); static TimeManagement* s_time_management;
TimeManagement& TimeManagement::the() TimeManagement& TimeManagement::the()
{ {
return *s_the; ASSERT(s_time_management);
return *s_time_management;
} }
bool TimeManagement::is_system_timer(const HardwareTimer& timer) const bool TimeManagement::is_system_timer(const HardwareTimer& timer) const
@ -65,9 +65,11 @@ time_t TimeManagement::epoch_time() const
void TimeManagement::initialize() void TimeManagement::initialize()
{ {
ASSERT(!s_the.is_initialized()); ASSERT(!s_time_management);
s_the.ensure_instance(); if (kernel_command_line().lookup("time").value_or("modern") == "legacy")
s_time_management = new TimeManagement(false);
else
s_time_management = new TimeManagement(true);
} }
time_t TimeManagement::seconds_since_boot() const time_t TimeManagement::seconds_since_boot() const
{ {
@ -88,9 +90,8 @@ time_t TimeManagement::boot_time() const
return RTC::boot_time(); return RTC::boot_time();
} }
TimeManagement::TimeManagement() TimeManagement::TimeManagement(bool probe_non_legacy_hardware_timers)
{ {
bool probe_non_legacy_hardware_timers = !(kernel_command_line().lookup("time").value_or("modern") == "legacy");
if (ACPI::is_enabled()) { if (ACPI::is_enabled()) {
if (!ACPI::Parser::the()->x86_specific_flags().cmos_rtc_not_present) { if (!ACPI::Parser::the()->x86_specific_flags().cmos_rtc_not_present) {
RTC::initialize(); RTC::initialize();
@ -116,8 +117,7 @@ TimeManagement::TimeManagement()
timeval TimeManagement::now_as_timeval() timeval TimeManagement::now_as_timeval()
{ {
auto* time_management = s_the.ptr(); return { s_time_management->epoch_time(), (suseconds_t)s_time_management->ticks_this_second() * (suseconds_t)1000 };
return { time_management->epoch_time(), (suseconds_t)time_management->ticks_this_second() * (suseconds_t)1000 };
} }
Vector<HardwareTimer*> TimeManagement::scan_and_initialize_periodic_timers() Vector<HardwareTimer*> TimeManagement::scan_and_initialize_periodic_timers()

View file

@ -42,7 +42,6 @@ class TimeManagement {
AK_MAKE_ETERNAL; AK_MAKE_ETERNAL;
public: public:
TimeManagement();
static bool initialized(); static bool initialized();
static void initialize(); static void initialize();
static TimeManagement& the(); static TimeManagement& the();
@ -64,6 +63,7 @@ public:
static timeval now_as_timeval(); static timeval now_as_timeval();
private: private:
explicit TimeManagement(bool probe_non_legacy_hardware_timers);
bool probe_and_set_legacy_hardware_timers(); bool probe_and_set_legacy_hardware_timers();
bool probe_and_set_non_legacy_hardware_timers(); bool probe_and_set_non_legacy_hardware_timers();
Vector<HardwareTimer*> scan_and_initialize_periodic_timers(); Vector<HardwareTimer*> scan_and_initialize_periodic_timers();

View file

@ -28,16 +28,17 @@
#include <AK/NonnullOwnPtr.h> #include <AK/NonnullOwnPtr.h>
#include <AK/OwnPtr.h> #include <AK/OwnPtr.h>
#include <Kernel/Scheduler.h> #include <Kernel/Scheduler.h>
#include <Kernel/Singleton.h>
#include <Kernel/Time/TimeManagement.h> #include <Kernel/Time/TimeManagement.h>
#include <Kernel/TimerQueue.h> #include <Kernel/TimerQueue.h>
namespace Kernel { namespace Kernel {
static auto s_the = make_singleton<TimerQueue>(); static TimerQueue* s_the;
TimerQueue& TimerQueue::the() TimerQueue& TimerQueue::the()
{ {
if (!s_the)
s_the = new TimerQueue;
return *s_the; return *s_the;
} }

View file

@ -56,7 +56,6 @@ struct Timer {
class TimerQueue { class TimerQueue {
public: public:
TimerQueue();
static TimerQueue& the(); static TimerQueue& the();
TimerId add_timer(NonnullOwnPtr<Timer>&&); TimerId add_timer(NonnullOwnPtr<Timer>&&);
@ -65,6 +64,8 @@ public:
void fire(); void fire();
private: private:
TimerQueue();
void update_next_timer_due(); void update_next_timer_due();
u64 microseconds_to_ticks(u64 micro_seconds) { return micro_seconds * (m_ticks_per_second / 1'000'000); } u64 microseconds_to_ticks(u64 micro_seconds) { return micro_seconds * (m_ticks_per_second / 1'000'000); }

View file

@ -39,7 +39,6 @@
#include <Kernel/VM/PhysicalRegion.h> #include <Kernel/VM/PhysicalRegion.h>
#include <Kernel/VM/PurgeableVMObject.h> #include <Kernel/VM/PurgeableVMObject.h>
#include <Kernel/VM/SharedInodeVMObject.h> #include <Kernel/VM/SharedInodeVMObject.h>
#include <Kernel/Singleton.h>
#include <Kernel/StdLib.h> #include <Kernel/StdLib.h>
//#define MM_DEBUG //#define MM_DEBUG
@ -51,7 +50,7 @@ extern FlatPtr end_of_kernel_bss;
namespace Kernel { namespace Kernel {
static auto s_the = make_singleton<MemoryManager>(); static MemoryManager* s_the;
RecursiveSpinLock s_mm_lock; RecursiveSpinLock s_mm_lock;
MemoryManager& MM MemoryManager& MM
@ -61,8 +60,6 @@ MemoryManager& MM
MemoryManager::MemoryManager() MemoryManager::MemoryManager()
{ {
ASSERT(!s_the.is_initialized());
ScopedSpinLock lock(s_mm_lock); ScopedSpinLock lock(s_mm_lock);
m_kernel_page_directory = PageDirectory::create_kernel_page_directory(); m_kernel_page_directory = PageDirectory::create_kernel_page_directory();
parse_memory_map(); parse_memory_map();
@ -220,7 +217,7 @@ void MemoryManager::initialize(u32 cpu)
Processor::current().set_mm_data(*mm_data); Processor::current().set_mm_data(*mm_data);
if (cpu == 0) if (cpu == 0)
s_the.ensure_instance(); s_the = new MemoryManager;
} }
Region* MemoryManager::kernel_region_from_vaddr(VirtualAddress vaddr) Region* MemoryManager::kernel_region_from_vaddr(VirtualAddress vaddr)

View file

@ -85,7 +85,6 @@ class MemoryManager {
friend Optional<KBuffer> procfs$memstat(InodeIdentifier); friend Optional<KBuffer> procfs$memstat(InodeIdentifier);
public: public:
MemoryManager();
static MemoryManager& the(); static MemoryManager& the();
static void initialize(u32 cpu); static void initialize(u32 cpu);
@ -161,6 +160,7 @@ public:
PageDirectory& kernel_page_directory() { return *m_kernel_page_directory; } PageDirectory& kernel_page_directory() { return *m_kernel_page_directory; }
private: private:
MemoryManager();
~MemoryManager(); ~MemoryManager();
enum class AccessSpace { Kernel, enum class AccessSpace { Kernel,

View file

@ -27,7 +27,6 @@
#include <AK/Memory.h> #include <AK/Memory.h>
#include <Kernel/Process.h> #include <Kernel/Process.h>
#include <Kernel/Random.h> #include <Kernel/Random.h>
#include <Kernel/Singleton.h>
#include <Kernel/Thread.h> #include <Kernel/Thread.h>
#include <Kernel/VM/MemoryManager.h> #include <Kernel/VM/MemoryManager.h>
#include <Kernel/VM/PageDirectory.h> #include <Kernel/VM/PageDirectory.h>
@ -38,12 +37,13 @@ static const FlatPtr userspace_range_base = 0x00800000;
static const FlatPtr userspace_range_ceiling = 0xbe000000; static const FlatPtr userspace_range_ceiling = 0xbe000000;
static const FlatPtr kernelspace_range_base = 0xc0800000; static const FlatPtr kernelspace_range_base = 0xc0800000;
static auto s_cr3_map = make_singleton<HashMap<u32, PageDirectory*>>();
static HashMap<u32, PageDirectory*>& cr3_map() static HashMap<u32, PageDirectory*>& cr3_map()
{ {
ASSERT_INTERRUPTS_DISABLED(); ASSERT_INTERRUPTS_DISABLED();
return *s_cr3_map; static HashMap<u32, PageDirectory*>* map;
if (!map)
map = new HashMap<u32, PageDirectory*>;
return *map;
} }
RefPtr<PageDirectory> PageDirectory::find_by_cr3(u32 cr3) RefPtr<PageDirectory> PageDirectory::find_by_cr3(u32 cr3)

View file

@ -135,10 +135,10 @@ extern "C" [[noreturn]] void init()
InterruptManagement::initialize(); InterruptManagement::initialize();
ACPI::initialize(); ACPI::initialize();
VFS::initialize(); new VFS;
KeyboardDevice::initialize(); new KeyboardDevice;
PS2MouseDevice::create(); new PS2MouseDevice;
Console::initialize(); new Console;
klog() << "Starting SerenityOS..."; klog() << "Starting SerenityOS...";
@ -146,7 +146,7 @@ extern "C" [[noreturn]] void init()
TimeManagement::initialize(); TimeManagement::initialize();
NullDevice::initialize(); new NullDevice;
if (!get_serial_debug()) if (!get_serial_debug())
new SerialDevice(SERIAL_COM1_ADDR, 64); new SerialDevice(SERIAL_COM1_ADDR, 64);
new SerialDevice(SERIAL_COM2_ADDR, 65); new SerialDevice(SERIAL_COM2_ADDR, 65);
@ -228,7 +228,7 @@ void init_stage2()
}); });
if (bxvga_found) { if (bxvga_found) {
BXVGADevice::initialize(); new BXVGADevice;
} else { } else {
if (multiboot_info_ptr->framebuffer_type == MULTIBOOT_FRAMEBUFFER_TYPE_RGB || multiboot_info_ptr->framebuffer_type == MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT) { if (multiboot_info_ptr->framebuffer_type == MULTIBOOT_FRAMEBUFFER_TYPE_RGB || multiboot_info_ptr->framebuffer_type == MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT) {
new MBVGADevice( new MBVGADevice(
@ -237,7 +237,7 @@ void init_stage2()
multiboot_info_ptr->framebuffer_width, multiboot_info_ptr->framebuffer_width,
multiboot_info_ptr->framebuffer_height); multiboot_info_ptr->framebuffer_height);
} else { } else {
BXVGADevice::initialize(); new BXVGADevice;
} }
} }
} }
@ -252,8 +252,9 @@ void init_stage2()
new ZeroDevice; new ZeroDevice;
new FullDevice; new FullDevice;
new RandomDevice; new RandomDevice;
PTYMultiplexer::initialize(); new PTYMultiplexer;
new SB16; new SB16;
VMWareBackdoor::initialize();
bool force_pio = kernel_command_line().contains("force_pio"); bool force_pio = kernel_command_line().contains("force_pio");