summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-03-01 11:08:28 +0100
committerAndreas Kling <kling@serenityos.org>2020-03-01 11:23:10 +0100
commit48bbfe51fba186f995aefd7cfc5b1fc6ddf8ab01 (patch)
treef6e51c72a2cd2efaca47941aea9ee87bc701eb46
parent88b334135b37304e76bd2fbd4745001138563a46 (diff)
downloadserenity-48bbfe51fba186f995aefd7cfc5b1fc6ddf8ab01.zip
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.
-rw-r--r--Kernel/VM/PrivateInodeVMObject.h2
-rw-r--r--Kernel/VM/Region.cpp6
-rw-r--r--Kernel/VM/SharedInodeVMObject.h2
-rw-r--r--Kernel/VM/VMObject.h2
4 files changed, 12 insertions, 0 deletions
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<VMObject> 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> 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> 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<VMObject> 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<RefPtr<PhysicalPage>>& physical_pages() const { return m_physical_pages; }