summaryrefslogtreecommitdiff
path: root/Kernel/Memory/PageDirectory.h
diff options
context:
space:
mode:
authorcreator1creeper1 <creator1creeper1@airmail.cc>2022-01-16 17:03:06 +0100
committerBrian Gianforcaro <b.gianfo@gmail.com>2022-01-16 12:08:57 -0800
commit326c6130a5dcc12dab281eaedd4dbc6e90f4cfe4 (patch)
treef1b05ac346096c771681ae5d943604fc285b11bb /Kernel/Memory/PageDirectory.h
parent3a6d4d14e1aea29a066fc8a86e993b0a117b67bc (diff)
downloadserenity-326c6130a5dcc12dab281eaedd4dbc6e90f4cfe4.zip
Kernel: Don't access directory table of uninitialized PageDirectory
PageDirectory gets initialized step-by-step in PageDirectory::try_create_for_userspace(). This initialization may fail anywhere in this function - for example, we may not be able to allocate a directory table, in which case PageDirectory::try_create_for_userspace() will return a null pointer. We recognize this condition and early-return ENOMEM. However, at this point, we need to correctly destruct the only partially initialized PageDirectory. Previously, PageDirectory::~PageDirectory() would assume that the object it was destructing was always fully initialized. It now uses the new helper PageDirectory::is_cr3_initialized() to correctly recognize when the directory table was not yet initialized. This helper checks if the pointer to the directory table is null. Only if it is not null does the destructor try to fetch the directory table using PageDirectory::cr3().
Diffstat (limited to 'Kernel/Memory/PageDirectory.h')
-rw-r--r--Kernel/Memory/PageDirectory.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/Kernel/Memory/PageDirectory.h b/Kernel/Memory/PageDirectory.h
index 9a7e564ca7..eaabce7dcc 100644
--- a/Kernel/Memory/PageDirectory.h
+++ b/Kernel/Memory/PageDirectory.h
@@ -37,6 +37,15 @@ public:
#endif
}
+ bool is_cr3_initialized() const
+ {
+#if ARCH(X86_64)
+ return m_pml4t;
+#else
+ return m_directory_table;
+#endif
+ }
+
VirtualRangeAllocator& range_allocator() { return m_range_allocator; }
VirtualRangeAllocator const& range_allocator() const { return m_range_allocator; }