From ad480ff18bccb43d1cd29c86f1bb99c4888dfd8d Mon Sep 17 00:00:00 2001 From: creator1creeper1 Date: Wed, 12 Jan 2022 17:59:46 +0100 Subject: [PATCH] Kernel: Make InodeVMOBject construction OOM-aware This commit moves the allocation of the resources required for InodeVMObject from its constructors to the constructors of its child classes. We're making this change to give the child classes the chance to expose the fallibility of the allocation. --- Kernel/Memory/InodeVMObject.cpp | 8 ++++---- Kernel/Memory/InodeVMObject.h | 4 ++-- Kernel/Memory/PrivateInodeVMObject.cpp | 4 ++-- Kernel/Memory/SharedInodeVMObject.cpp | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Kernel/Memory/InodeVMObject.cpp b/Kernel/Memory/InodeVMObject.cpp index 23e13af7199..da88ba70842 100644 --- a/Kernel/Memory/InodeVMObject.cpp +++ b/Kernel/Memory/InodeVMObject.cpp @@ -9,15 +9,15 @@ namespace Kernel::Memory { -InodeVMObject::InodeVMObject(Inode& inode, size_t size) - : VMObject(VMObject::must_create_physical_pages_but_fixme_should_propagate_errors(size)) +InodeVMObject::InodeVMObject(Inode& inode, FixedArray>&& new_physical_pages) + : VMObject(move(new_physical_pages)) , m_inode(inode) , m_dirty_pages(page_count(), false) { } -InodeVMObject::InodeVMObject(InodeVMObject const& other) - : VMObject(other.must_clone_physical_pages_but_fixme_should_propagate_errors()) +InodeVMObject::InodeVMObject(InodeVMObject const& other, FixedArray>&& new_physical_pages) + : VMObject(move(new_physical_pages)) , m_inode(other.m_inode) , m_dirty_pages(page_count(), false) { diff --git a/Kernel/Memory/InodeVMObject.h b/Kernel/Memory/InodeVMObject.h index d8c46b7a2a0..33898faf109 100644 --- a/Kernel/Memory/InodeVMObject.h +++ b/Kernel/Memory/InodeVMObject.h @@ -28,8 +28,8 @@ public: u32 executable_mappings() const; protected: - explicit InodeVMObject(Inode&, size_t); - explicit InodeVMObject(InodeVMObject const&); + explicit InodeVMObject(Inode&, FixedArray>&&); + explicit InodeVMObject(InodeVMObject const&, FixedArray>&&); InodeVMObject& operator=(InodeVMObject const&) = delete; InodeVMObject& operator=(InodeVMObject&&) = delete; diff --git a/Kernel/Memory/PrivateInodeVMObject.cpp b/Kernel/Memory/PrivateInodeVMObject.cpp index cd552bc34f8..16573fc2dd5 100644 --- a/Kernel/Memory/PrivateInodeVMObject.cpp +++ b/Kernel/Memory/PrivateInodeVMObject.cpp @@ -20,12 +20,12 @@ ErrorOr> PrivateInodeVMObject::try_clone() } PrivateInodeVMObject::PrivateInodeVMObject(Inode& inode, size_t size) - : InodeVMObject(inode, size) + : InodeVMObject(inode, VMObject::must_create_physical_pages_but_fixme_should_propagate_errors(size)) { } PrivateInodeVMObject::PrivateInodeVMObject(PrivateInodeVMObject const& other) - : InodeVMObject(other) + : InodeVMObject(other, other.must_clone_physical_pages_but_fixme_should_propagate_errors()) { } diff --git a/Kernel/Memory/SharedInodeVMObject.cpp b/Kernel/Memory/SharedInodeVMObject.cpp index 9d31e82fc79..48a6c272175 100644 --- a/Kernel/Memory/SharedInodeVMObject.cpp +++ b/Kernel/Memory/SharedInodeVMObject.cpp @@ -26,12 +26,12 @@ ErrorOr> SharedInodeVMObject::try_clone() } SharedInodeVMObject::SharedInodeVMObject(Inode& inode, size_t size) - : InodeVMObject(inode, size) + : InodeVMObject(inode, VMObject::must_create_physical_pages_but_fixme_should_propagate_errors(size)) { } SharedInodeVMObject::SharedInodeVMObject(SharedInodeVMObject const& other) - : InodeVMObject(other) + : InodeVMObject(other, other.must_clone_physical_pages_but_fixme_should_propagate_errors()) { }