Преглед изворни кода

Kernel: Make SharedInodeVMObject construction OOM-aware

This commit moves the allocation of the resources required for
SharedInodeVMObject from its constructors to its factory functions.

We're making this change to expose the fallibility of the allocation.
creator1creeper1 пре 3 година
родитељ
комит
2a4e410b63
2 измењених фајлова са 10 додато и 8 уклоњено
  1. 8 6
      Kernel/Memory/SharedInodeVMObject.cpp
  2. 2 2
      Kernel/Memory/SharedInodeVMObject.h

+ 8 - 6
Kernel/Memory/SharedInodeVMObject.cpp

@@ -15,23 +15,25 @@ ErrorOr<NonnullRefPtr<SharedInodeVMObject>> SharedInodeVMObject::try_create_with
     size_t size = inode.size();
     if (auto shared_vmobject = inode.shared_vmobject())
         return shared_vmobject.release_nonnull();
-    auto vmobject = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) SharedInodeVMObject(inode, size)));
+    auto new_physical_pages = TRY(VMObject::try_create_physical_pages(size));
+    auto vmobject = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) SharedInodeVMObject(inode, move(new_physical_pages))));
     vmobject->inode().set_shared_vmobject(*vmobject);
     return vmobject;
 }
 
 ErrorOr<NonnullRefPtr<VMObject>> SharedInodeVMObject::try_clone()
 {
-    return adopt_nonnull_ref_or_enomem<VMObject>(new (nothrow) SharedInodeVMObject(*this));
+    auto new_physical_pages = TRY(this->try_clone_physical_pages());
+    return adopt_nonnull_ref_or_enomem<VMObject>(new (nothrow) SharedInodeVMObject(*this, move(new_physical_pages)));
 }
 
-SharedInodeVMObject::SharedInodeVMObject(Inode& inode, size_t size)
-    : InodeVMObject(inode, VMObject::must_create_physical_pages_but_fixme_should_propagate_errors(size))
+SharedInodeVMObject::SharedInodeVMObject(Inode& inode, FixedArray<RefPtr<PhysicalPage>>&& new_physical_pages)
+    : InodeVMObject(inode, move(new_physical_pages))
 {
 }
 
-SharedInodeVMObject::SharedInodeVMObject(SharedInodeVMObject const& other)
-    : InodeVMObject(other, other.must_clone_physical_pages_but_fixme_should_propagate_errors())
+SharedInodeVMObject::SharedInodeVMObject(SharedInodeVMObject const& other, FixedArray<RefPtr<PhysicalPage>>&& new_physical_pages)
+    : InodeVMObject(other, move(new_physical_pages))
 {
 }
 

+ 2 - 2
Kernel/Memory/SharedInodeVMObject.h

@@ -23,8 +23,8 @@ public:
 private:
     virtual bool is_shared_inode() const override { return true; }
 
-    explicit SharedInodeVMObject(Inode&, size_t);
-    explicit SharedInodeVMObject(SharedInodeVMObject const&);
+    explicit SharedInodeVMObject(Inode&, FixedArray<RefPtr<PhysicalPage>>&&);
+    explicit SharedInodeVMObject(SharedInodeVMObject const&, FixedArray<RefPtr<PhysicalPage>>&&);
 
     virtual StringView class_name() const override { return "SharedInodeVMObject"sv; }