From 9a1dfe70fe57e37e82ae62f6690fa7153eacaaed Mon Sep 17 00:00:00 2001 From: creator1creeper1 Date: Wed, 12 Jan 2022 20:25:39 +0100 Subject: [PATCH] Kernel: Make PrivateInodeVMObject construction OOM-aware This commit moves the allocation of the resources required for PrivateInodeVMObject from its constructors to its factory functions. We're making this change to expose the fallibility of the allocation. --- Kernel/Memory/PrivateInodeVMObject.cpp | 14 ++++++++------ Kernel/Memory/PrivateInodeVMObject.h | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Kernel/Memory/PrivateInodeVMObject.cpp b/Kernel/Memory/PrivateInodeVMObject.cpp index 16573fc2dd..adc965b791 100644 --- a/Kernel/Memory/PrivateInodeVMObject.cpp +++ b/Kernel/Memory/PrivateInodeVMObject.cpp @@ -11,21 +11,23 @@ namespace Kernel::Memory { ErrorOr> PrivateInodeVMObject::try_create_with_inode(Inode& inode) { - return adopt_nonnull_ref_or_enomem(new (nothrow) PrivateInodeVMObject(inode, inode.size())); + auto new_physical_pages = TRY(VMObject::try_create_physical_pages(inode.size())); + return adopt_nonnull_ref_or_enomem(new (nothrow) PrivateInodeVMObject(inode, move(new_physical_pages))); } ErrorOr> PrivateInodeVMObject::try_clone() { - return adopt_nonnull_ref_or_enomem(new (nothrow) PrivateInodeVMObject(*this)); + auto new_physical_pages = TRY(this->try_clone_physical_pages()); + return adopt_nonnull_ref_or_enomem(new (nothrow) PrivateInodeVMObject(*this, move(new_physical_pages))); } -PrivateInodeVMObject::PrivateInodeVMObject(Inode& inode, size_t size) - : InodeVMObject(inode, VMObject::must_create_physical_pages_but_fixme_should_propagate_errors(size)) +PrivateInodeVMObject::PrivateInodeVMObject(Inode& inode, FixedArray>&& new_physical_pages) + : InodeVMObject(inode, move(new_physical_pages)) { } -PrivateInodeVMObject::PrivateInodeVMObject(PrivateInodeVMObject const& other) - : InodeVMObject(other, other.must_clone_physical_pages_but_fixme_should_propagate_errors()) +PrivateInodeVMObject::PrivateInodeVMObject(PrivateInodeVMObject const& other, FixedArray>&& new_physical_pages) + : InodeVMObject(other, move(new_physical_pages)) { } diff --git a/Kernel/Memory/PrivateInodeVMObject.h b/Kernel/Memory/PrivateInodeVMObject.h index 273ee50f33..b3efadcc7e 100644 --- a/Kernel/Memory/PrivateInodeVMObject.h +++ b/Kernel/Memory/PrivateInodeVMObject.h @@ -23,8 +23,8 @@ public: private: virtual bool is_private_inode() const override { return true; } - explicit PrivateInodeVMObject(Inode&, size_t); - explicit PrivateInodeVMObject(PrivateInodeVMObject const&); + explicit PrivateInodeVMObject(Inode&, FixedArray>&&); + explicit PrivateInodeVMObject(PrivateInodeVMObject const&, FixedArray>&&); virtual StringView class_name() const override { return "PrivateInodeVMObject"sv; }