diff --git a/Kernel/VM/AnonymousVMObject.cpp b/Kernel/VM/AnonymousVMObject.cpp index ad14cf75b7..c89993a841 100644 --- a/Kernel/VM/AnonymousVMObject.cpp +++ b/Kernel/VM/AnonymousVMObject.cpp @@ -81,6 +81,11 @@ RefPtr AnonymousVMObject::create_with_size(size_t size, Alloc return adopt(*new AnonymousVMObject(size, commit)); } +NonnullRefPtr AnonymousVMObject::create_with_physical_pages(NonnullRefPtrVector physical_pages) +{ + return adopt(*new AnonymousVMObject(physical_pages)); +} + NonnullRefPtr AnonymousVMObject::create_with_physical_page(PhysicalPage& page) { return adopt(*new AnonymousVMObject(page)); @@ -127,6 +132,15 @@ AnonymousVMObject::AnonymousVMObject(PhysicalPage& page) physical_pages()[0] = page; } +AnonymousVMObject::AnonymousVMObject(NonnullRefPtrVector physical_pages) + : VMObject() + , m_volatile_ranges_cache({ 0, page_count() }) +{ + for (auto& page : physical_pages) { + m_physical_pages.append(page); + } +} + AnonymousVMObject::AnonymousVMObject(const AnonymousVMObject& other) : VMObject(other) , m_volatile_ranges_cache({ 0, page_count() }) // do *not* clone this diff --git a/Kernel/VM/AnonymousVMObject.h b/Kernel/VM/AnonymousVMObject.h index 4dbaf1f266..6b33e8488f 100644 --- a/Kernel/VM/AnonymousVMObject.h +++ b/Kernel/VM/AnonymousVMObject.h @@ -43,6 +43,7 @@ public: static RefPtr create_with_size(size_t, AllocationStrategy); static RefPtr create_for_physical_range(PhysicalAddress paddr, size_t size); static NonnullRefPtr create_with_physical_page(PhysicalPage& page); + static NonnullRefPtr create_with_physical_pages(NonnullRefPtrVector); virtual RefPtr clone() override; RefPtr allocate_committed_page(size_t); @@ -119,6 +120,7 @@ private: explicit AnonymousVMObject(size_t, AllocationStrategy); explicit AnonymousVMObject(PhysicalAddress, size_t); explicit AnonymousVMObject(PhysicalPage&); + explicit AnonymousVMObject(NonnullRefPtrVector); explicit AnonymousVMObject(const AnonymousVMObject&); virtual const char* class_name() const override { return "AnonymousVMObject"; } diff --git a/Kernel/VM/VMObject.cpp b/Kernel/VM/VMObject.cpp index 77c66e94f8..d6d3aa80f7 100644 --- a/Kernel/VM/VMObject.cpp +++ b/Kernel/VM/VMObject.cpp @@ -35,6 +35,11 @@ VMObject::VMObject(const VMObject& other) MM.register_vmobject(*this); } +VMObject::VMObject() +{ + MM.register_vmobject(*this); +} + VMObject::VMObject(size_t size) { m_physical_pages.resize(ceil_div(size, static_cast(PAGE_SIZE))); diff --git a/Kernel/VM/VMObject.h b/Kernel/VM/VMObject.h index 2c5fa709cb..8f4ccb4548 100644 --- a/Kernel/VM/VMObject.h +++ b/Kernel/VM/VMObject.h @@ -88,6 +88,7 @@ public: } protected: + VMObject(); explicit VMObject(size_t); explicit VMObject(const VMObject&);