From 48bbfe51fba186f995aefd7cfc5b1fc6ddf8ab01 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 1 Mar 2020 11:08:28 +0100 Subject: Kernel: Add some InodeVMObject type assertions in Region::clone() Let's make sure that we're never cloning shared inode-backed objects as if they were private, and vice versa. --- Kernel/VM/PrivateInodeVMObject.h | 2 ++ Kernel/VM/Region.cpp | 6 ++++++ Kernel/VM/SharedInodeVMObject.h | 2 ++ Kernel/VM/VMObject.h | 2 ++ 4 files changed, 12 insertions(+) (limited to 'Kernel/VM') diff --git a/Kernel/VM/PrivateInodeVMObject.h b/Kernel/VM/PrivateInodeVMObject.h index 7f0d3998bc..ef65b51095 100644 --- a/Kernel/VM/PrivateInodeVMObject.h +++ b/Kernel/VM/PrivateInodeVMObject.h @@ -42,6 +42,8 @@ public: virtual NonnullRefPtr clone() override; private: + virtual bool is_private_inode() const override { return true; } + explicit PrivateInodeVMObject(Inode&, size_t); explicit PrivateInodeVMObject(const PrivateInodeVMObject&); diff --git a/Kernel/VM/Region.cpp b/Kernel/VM/Region.cpp index a9f6b69727..dbe4e363c8 100644 --- a/Kernel/VM/Region.cpp +++ b/Kernel/VM/Region.cpp @@ -71,6 +71,9 @@ NonnullOwnPtr Region::clone() #ifdef MM_DEBUG dbg() << "Region::clone(): Sharing " << name() << " (" << vaddr() << ")"; #endif + if (vmobject().is_inode()) + ASSERT(vmobject().is_shared_inode()); + // Create a new region backed by the same VMObject. auto region = Region::create_user_accessible(m_range, m_vmobject, m_offset_in_vmobject, m_name, m_access); region->set_mmap(m_mmap); @@ -78,6 +81,9 @@ NonnullOwnPtr Region::clone() return region; } + if (vmobject().is_inode()) + ASSERT(vmobject().is_private_inode()); + #ifdef MM_DEBUG dbg() << "Region::clone(): CoWing " << name() << " (" << vaddr() << ")"; #endif diff --git a/Kernel/VM/SharedInodeVMObject.h b/Kernel/VM/SharedInodeVMObject.h index f817ac673c..6f01c26fa8 100644 --- a/Kernel/VM/SharedInodeVMObject.h +++ b/Kernel/VM/SharedInodeVMObject.h @@ -42,6 +42,8 @@ public: virtual NonnullRefPtr clone() override; private: + virtual bool is_shared_inode() const override { return true; } + explicit SharedInodeVMObject(Inode&, size_t); explicit SharedInodeVMObject(const SharedInodeVMObject&); diff --git a/Kernel/VM/VMObject.h b/Kernel/VM/VMObject.h index ff62f8d0a9..c108ea95a6 100644 --- a/Kernel/VM/VMObject.h +++ b/Kernel/VM/VMObject.h @@ -52,6 +52,8 @@ public: virtual bool is_anonymous() const { return false; } virtual bool is_purgeable() const { return false; } virtual bool is_inode() const { return false; } + virtual bool is_shared_inode() const { return false; } + virtual bool is_private_inode() const { return false; } size_t page_count() const { return m_physical_pages.size(); } const FixedArray>& physical_pages() const { return m_physical_pages; } -- cgit v1.2.3