summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorTom <tomut@yahoo.com>2020-08-21 11:00:51 -0600
committerAndreas Kling <kling@serenityos.org>2020-08-22 10:46:24 +0200
commit8a75e0b892ab8e1c4765ac4e2f7289b258f1bf5a (patch)
treecc69a6a1f51d885ae63c1d32a878bcd5416b6274 /Kernel
parentf0906250a181c831508a45434b9f645ff98f33e4 (diff)
downloadserenity-8a75e0b892ab8e1c4765ac4e2f7289b258f1bf5a.zip
Kernel: Fix regression where MemoryManager is initialized twice
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.
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/VM/MemoryManager.cpp11
-rw-r--r--Kernel/VM/MemoryManager.h2
2 files changed, 7 insertions, 6 deletions
diff --git a/Kernel/VM/MemoryManager.cpp b/Kernel/VM/MemoryManager.cpp
index 9c984de81e..19a91a4d2a 100644
--- a/Kernel/VM/MemoryManager.cpp
+++ b/Kernel/VM/MemoryManager.cpp
@@ -26,7 +26,6 @@
#include <AK/Assertions.h>
#include <AK/Memory.h>
-#include <AK/Singleton.h>
#include <AK/StringView.h>
#include <Kernel/Arch/i386/CPU.h>
#include <Kernel/CMOS.h>
@@ -51,7 +50,11 @@ extern FlatPtr end_of_kernel_bss;
namespace Kernel {
-static auto s_the = AK::make_singleton<MemoryManager>();
+// NOTE: We can NOT use AK::Singleton for this class, because
+// MemoryManager::initialize is called *before* global constructors are
+// run. If we do, then AK::Singleton would get re-initialized, causing
+// the memory manager to be initialized twice!
+static MemoryManager* s_the;
RecursiveSpinLock s_mm_lock;
MemoryManager& MM
@@ -61,8 +64,6 @@ MemoryManager& MM
MemoryManager::MemoryManager()
{
- ASSERT(!s_the.is_initialized());
-
ScopedSpinLock lock(s_mm_lock);
m_kernel_page_directory = PageDirectory::create_kernel_page_directory();
parse_memory_map();
@@ -220,7 +221,7 @@ void MemoryManager::initialize(u32 cpu)
Processor::current().set_mm_data(*mm_data);
if (cpu == 0)
- s_the.ensure_instance();
+ s_the = new MemoryManager;
}
Region* MemoryManager::kernel_region_from_vaddr(VirtualAddress vaddr)
diff --git a/Kernel/VM/MemoryManager.h b/Kernel/VM/MemoryManager.h
index 13e796e251..a7a324ed0d 100644
--- a/Kernel/VM/MemoryManager.h
+++ b/Kernel/VM/MemoryManager.h
@@ -85,7 +85,6 @@ class MemoryManager {
friend Optional<KBuffer> procfs$memstat(InodeIdentifier);
public:
- MemoryManager();
static MemoryManager& the();
static void initialize(u32 cpu);
@@ -161,6 +160,7 @@ public:
PageDirectory& kernel_page_directory() { return *m_kernel_page_directory; }
private:
+ MemoryManager();
~MemoryManager();
enum class AccessSpace { Kernel,