diff options
author | Andreas Kling <kling@serenityos.org> | 2021-07-11 17:38:28 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-11 17:42:31 +0200 |
commit | 59049ae4b760ae0f5cdad0d326eeaca9d2192fb9 (patch) | |
tree | 0fb73ad38ffabe9788e31922ed10b0d563cec2e0 | |
parent | 373b8d7cfa5cc08203a884fdd2026221f76c49b5 (diff) | |
download | serenity-59049ae4b760ae0f5cdad0d326eeaca9d2192fb9.zip |
Kernel: Store VMObject physical pages in a FixedArray
Let's enforce the invariant that VMObjects don't shrink or grow by
storing the pages in a FixedArray.
-rw-r--r-- | Kernel/VM/AnonymousVMObject.cpp | 6 | ||||
-rw-r--r-- | Kernel/VM/VMObject.cpp | 7 | ||||
-rw-r--r-- | Kernel/VM/VMObject.h | 4 |
3 files changed, 6 insertions, 11 deletions
diff --git a/Kernel/VM/AnonymousVMObject.cpp b/Kernel/VM/AnonymousVMObject.cpp index 9b479f8e51..01cd64ae51 100644 --- a/Kernel/VM/AnonymousVMObject.cpp +++ b/Kernel/VM/AnonymousVMObject.cpp @@ -117,11 +117,11 @@ AnonymousVMObject::AnonymousVMObject(PhysicalPage& page) } AnonymousVMObject::AnonymousVMObject(NonnullRefPtrVector<PhysicalPage> physical_pages) - : VMObject() + : VMObject(physical_pages.size()) , m_volatile_ranges_cache({ 0, page_count() }) { - for (auto& page : physical_pages) { - m_physical_pages.append(page); + for (size_t i = 0; i < physical_pages.size(); ++i) { + m_physical_pages[i] = physical_pages[i]; } } diff --git a/Kernel/VM/VMObject.cpp b/Kernel/VM/VMObject.cpp index 5908b4a7ce..99cf074b9c 100644 --- a/Kernel/VM/VMObject.cpp +++ b/Kernel/VM/VMObject.cpp @@ -15,14 +15,9 @@ VMObject::VMObject(const VMObject& other) MM.register_vmobject(*this); } -VMObject::VMObject() -{ - MM.register_vmobject(*this); -} - VMObject::VMObject(size_t size) + : m_physical_pages(ceil_div(size, static_cast<size_t>(PAGE_SIZE))) { - m_physical_pages.resize(ceil_div(size, static_cast<size_t>(PAGE_SIZE))); MM.register_vmobject(*this); } diff --git a/Kernel/VM/VMObject.h b/Kernel/VM/VMObject.h index 58ae7276c3..4cdd64c9c6 100644 --- a/Kernel/VM/VMObject.h +++ b/Kernel/VM/VMObject.h @@ -6,6 +6,7 @@ #pragma once +#include <AK/FixedArray.h> #include <AK/HashTable.h> #include <AK/IntrusiveList.h> #include <AK/RefCounted.h> @@ -61,7 +62,6 @@ public: } protected: - VMObject(); explicit VMObject(size_t); explicit VMObject(const VMObject&); @@ -69,7 +69,7 @@ protected: void for_each_region(Callback); IntrusiveListNode<VMObject> m_list_node; - Vector<RefPtr<PhysicalPage>, 16> m_physical_pages; + FixedArray<RefPtr<PhysicalPage>> m_physical_pages; Lock m_paging_lock { "VMObject" }; mutable SpinLock<u8> m_lock; |