mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-01 03:57:15 +02: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:
committed by
Idan Horowitz
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
@@ -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))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user