mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-01 20:10:28 +00:00
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.
This commit is contained in:
parent
9a1dfe70fe
commit
2a4e410b63
Notes:
sideshowbarker
2024-07-17 20:50:05 +09:00
Author: https://github.com/creator1creeper1 Commit: https://github.com/SerenityOS/serenity/commit/2a4e410b634 Pull-request: https://github.com/SerenityOS/serenity/pull/11843 Reviewed-by: https://github.com/IdanHo ✅ Reviewed-by: https://github.com/bgianfo
2 changed files with 10 additions and 8 deletions
|
@ -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))
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -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; }
|
||||
|
||||
|
|
Loading…
Reference in a new issue