diff options
author | Andreas Kling <kling@serenityos.org> | 2021-07-11 19:07:00 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-11 19:09:02 +0200 |
commit | f244a25f71e1d445558aed26a0042714c4add137 (patch) | |
tree | 09c8a240f7eb348b197df130393506e0b3a3b644 | |
parent | d85bce57b3168c792422f8392cfaee098829de94 (diff) | |
download | serenity-f244a25f71e1d445558aed26a0042714c4add137.zip |
Kernel: Rename VMObject::clone() => try_clone()
And fix an unsafe dereference in SharedInodeVMObject::try_clone()
to make it OOM-safe.
-rw-r--r-- | Kernel/Graphics/VirtIOGPU/VirtIOFrameBufferDevice.cpp | 4 | ||||
-rw-r--r-- | Kernel/VM/AnonymousVMObject.cpp | 2 | ||||
-rw-r--r-- | Kernel/VM/AnonymousVMObject.h | 2 | ||||
-rw-r--r-- | Kernel/VM/ContiguousVMObject.cpp | 2 | ||||
-rw-r--r-- | Kernel/VM/ContiguousVMObject.h | 2 | ||||
-rw-r--r-- | Kernel/VM/PrivateInodeVMObject.cpp | 2 | ||||
-rw-r--r-- | Kernel/VM/PrivateInodeVMObject.h | 2 | ||||
-rw-r--r-- | Kernel/VM/Region.cpp | 2 | ||||
-rw-r--r-- | Kernel/VM/SharedInodeVMObject.cpp | 4 | ||||
-rw-r--r-- | Kernel/VM/SharedInodeVMObject.h | 2 | ||||
-rw-r--r-- | Kernel/VM/VMObject.h | 2 |
11 files changed, 13 insertions, 13 deletions
diff --git a/Kernel/Graphics/VirtIOGPU/VirtIOFrameBufferDevice.cpp b/Kernel/Graphics/VirtIOGPU/VirtIOFrameBufferDevice.cpp index 4b0ab639c3..b5d8be0c75 100644 --- a/Kernel/Graphics/VirtIOGPU/VirtIOFrameBufferDevice.cpp +++ b/Kernel/Graphics/VirtIOGPU/VirtIOFrameBufferDevice.cpp @@ -245,7 +245,7 @@ KResultOr<Region*> VirtIOFrameBufferDevice::mmap(Process& process, FileDescripti if (m_userspace_mmap_region) return ENOMEM; - auto vmobject = m_are_writes_active ? m_framebuffer->vmobject().clone() : m_framebuffer_sink_vmobject; + auto vmobject = m_are_writes_active ? m_framebuffer->vmobject().try_clone() : m_framebuffer_sink_vmobject; if (vmobject.is_null()) return ENOMEM; @@ -267,7 +267,7 @@ void VirtIOFrameBufferDevice::deactivate_writes() m_are_writes_active = false; if (m_userspace_mmap_region) { auto* region = m_userspace_mmap_region.unsafe_ptr(); - auto vm_object = m_framebuffer_sink_vmobject->clone(); + auto vm_object = m_framebuffer_sink_vmobject->try_clone(); VERIFY(vm_object); region->set_vmobject(vm_object.release_nonnull()); region->remap(); diff --git a/Kernel/VM/AnonymousVMObject.cpp b/Kernel/VM/AnonymousVMObject.cpp index 4f43684f96..c218d77121 100644 --- a/Kernel/VM/AnonymousVMObject.cpp +++ b/Kernel/VM/AnonymousVMObject.cpp @@ -13,7 +13,7 @@ namespace Kernel { -RefPtr<VMObject> AnonymousVMObject::clone() +RefPtr<VMObject> AnonymousVMObject::try_clone() { // We need to acquire our lock so we copy a sane state ScopedSpinLock lock(m_lock); diff --git a/Kernel/VM/AnonymousVMObject.h b/Kernel/VM/AnonymousVMObject.h index 5b072f45ea..72acbe7cb6 100644 --- a/Kernel/VM/AnonymousVMObject.h +++ b/Kernel/VM/AnonymousVMObject.h @@ -25,7 +25,7 @@ public: static RefPtr<AnonymousVMObject> try_create_for_physical_range(PhysicalAddress paddr, size_t size); static RefPtr<AnonymousVMObject> try_create_with_physical_page(PhysicalPage& page); static RefPtr<AnonymousVMObject> try_create_with_physical_pages(NonnullRefPtrVector<PhysicalPage>); - virtual RefPtr<VMObject> clone() override; + virtual RefPtr<VMObject> try_clone() override; RefPtr<PhysicalPage> allocate_committed_page(size_t); PageFaultResponse handle_cow_fault(size_t, VirtualAddress); diff --git a/Kernel/VM/ContiguousVMObject.cpp b/Kernel/VM/ContiguousVMObject.cpp index 3d9007c05e..5ad8f9b8a9 100644 --- a/Kernel/VM/ContiguousVMObject.cpp +++ b/Kernel/VM/ContiguousVMObject.cpp @@ -36,7 +36,7 @@ ContiguousVMObject::~ContiguousVMObject() { } -RefPtr<VMObject> ContiguousVMObject::clone() +RefPtr<VMObject> ContiguousVMObject::try_clone() { VERIFY_NOT_REACHED(); } diff --git a/Kernel/VM/ContiguousVMObject.h b/Kernel/VM/ContiguousVMObject.h index 6cc9983c7d..269c2667e6 100644 --- a/Kernel/VM/ContiguousVMObject.h +++ b/Kernel/VM/ContiguousVMObject.h @@ -22,7 +22,7 @@ private: explicit ContiguousVMObject(const ContiguousVMObject&); virtual StringView class_name() const override { return "ContiguousVMObject"sv; } - virtual RefPtr<VMObject> clone() override; + virtual RefPtr<VMObject> try_clone() override; ContiguousVMObject& operator=(const ContiguousVMObject&) = delete; ContiguousVMObject& operator=(ContiguousVMObject&&) = delete; diff --git a/Kernel/VM/PrivateInodeVMObject.cpp b/Kernel/VM/PrivateInodeVMObject.cpp index 7968475e8d..420ffc511d 100644 --- a/Kernel/VM/PrivateInodeVMObject.cpp +++ b/Kernel/VM/PrivateInodeVMObject.cpp @@ -14,7 +14,7 @@ RefPtr<PrivateInodeVMObject> PrivateInodeVMObject::try_create_with_inode(Inode& return adopt_ref_if_nonnull(new (nothrow) PrivateInodeVMObject(inode, inode.size())); } -RefPtr<VMObject> PrivateInodeVMObject::clone() +RefPtr<VMObject> PrivateInodeVMObject::try_clone() { return adopt_ref_if_nonnull(new (nothrow) PrivateInodeVMObject(*this)); } diff --git a/Kernel/VM/PrivateInodeVMObject.h b/Kernel/VM/PrivateInodeVMObject.h index a3437c1282..9faa34b695 100644 --- a/Kernel/VM/PrivateInodeVMObject.h +++ b/Kernel/VM/PrivateInodeVMObject.h @@ -19,7 +19,7 @@ public: virtual ~PrivateInodeVMObject() override; static RefPtr<PrivateInodeVMObject> try_create_with_inode(Inode&); - virtual RefPtr<VMObject> clone() override; + virtual RefPtr<VMObject> try_clone() override; private: virtual bool is_private_inode() const override { return true; } diff --git a/Kernel/VM/Region.cpp b/Kernel/VM/Region.cpp index 586a454ff5..e9abf8bfe4 100644 --- a/Kernel/VM/Region.cpp +++ b/Kernel/VM/Region.cpp @@ -100,7 +100,7 @@ OwnPtr<Region> Region::clone(Process& new_owner) if (vmobject().is_inode()) VERIFY(vmobject().is_private_inode()); - auto vmobject_clone = vmobject().clone(); + auto vmobject_clone = vmobject().try_clone(); if (!vmobject_clone) return {}; diff --git a/Kernel/VM/SharedInodeVMObject.cpp b/Kernel/VM/SharedInodeVMObject.cpp index 383e35f254..2c15b12f5c 100644 --- a/Kernel/VM/SharedInodeVMObject.cpp +++ b/Kernel/VM/SharedInodeVMObject.cpp @@ -21,9 +21,9 @@ RefPtr<SharedInodeVMObject> SharedInodeVMObject::try_create_with_inode(Inode& in return vmobject; } -RefPtr<VMObject> SharedInodeVMObject::clone() +RefPtr<VMObject> SharedInodeVMObject::try_clone() { - return adopt_ref(*new SharedInodeVMObject(*this)); + return adopt_ref_if_nonnull(new SharedInodeVMObject(*this)); } SharedInodeVMObject::SharedInodeVMObject(Inode& inode, size_t size) diff --git a/Kernel/VM/SharedInodeVMObject.h b/Kernel/VM/SharedInodeVMObject.h index cde2019555..113c7a1a5b 100644 --- a/Kernel/VM/SharedInodeVMObject.h +++ b/Kernel/VM/SharedInodeVMObject.h @@ -17,7 +17,7 @@ class SharedInodeVMObject final : public InodeVMObject { public: static RefPtr<SharedInodeVMObject> try_create_with_inode(Inode&); - virtual RefPtr<VMObject> clone() override; + virtual RefPtr<VMObject> try_clone() override; private: virtual bool is_shared_inode() const override { return true; } diff --git a/Kernel/VM/VMObject.h b/Kernel/VM/VMObject.h index e59a715534..7ca350922f 100644 --- a/Kernel/VM/VMObject.h +++ b/Kernel/VM/VMObject.h @@ -32,7 +32,7 @@ class VMObject : public RefCounted<VMObject> public: virtual ~VMObject(); - virtual RefPtr<VMObject> clone() = 0; + virtual RefPtr<VMObject> try_clone() = 0; virtual bool is_anonymous() const { return false; } virtual bool is_inode() const { return false; } |