summaryrefslogtreecommitdiff
path: root/Kernel/Memory/SharedInodeVMObject.cpp
diff options
context:
space:
mode:
authorcreator1creeper1 <creator1creeper1@airmail.cc>2022-01-12 20:52:39 +0100
committerIdan Horowitz <idan.horowitz@gmail.com>2022-01-15 22:16:00 +0200
commit2a4e410b634e23f87dc985dccea276469d99f8f1 (patch)
tree96b7180723f8bcff3d41ec1d54476792744e2e3a /Kernel/Memory/SharedInodeVMObject.cpp
parent9a1dfe70fe57e37e82ae62f6690fa7153eacaaed (diff)
downloadserenity-2a4e410b634e23f87dc985dccea276469d99f8f1.zip
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.
Diffstat (limited to 'Kernel/Memory/SharedInodeVMObject.cpp')
-rw-r--r--Kernel/Memory/SharedInodeVMObject.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/Kernel/Memory/SharedInodeVMObject.cpp b/Kernel/Memory/SharedInodeVMObject.cpp
index 48a6c27217..650455ef06 100644
--- a/Kernel/Memory/SharedInodeVMObject.cpp
+++ b/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))
{
}