1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:17:44 +00:00

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.
This commit is contained in:
Andreas Kling 2020-03-01 11:08:28 +01:00
parent 88b334135b
commit 48bbfe51fb
4 changed files with 12 additions and 0 deletions

View file

@ -42,6 +42,8 @@ public:
virtual NonnullRefPtr<VMObject> clone() override; virtual NonnullRefPtr<VMObject> clone() override;
private: private:
virtual bool is_private_inode() const override { return true; }
explicit PrivateInodeVMObject(Inode&, size_t); explicit PrivateInodeVMObject(Inode&, size_t);
explicit PrivateInodeVMObject(const PrivateInodeVMObject&); explicit PrivateInodeVMObject(const PrivateInodeVMObject&);

View file

@ -71,6 +71,9 @@ NonnullOwnPtr<Region> Region::clone()
#ifdef MM_DEBUG #ifdef MM_DEBUG
dbg() << "Region::clone(): Sharing " << name() << " (" << vaddr() << ")"; dbg() << "Region::clone(): Sharing " << name() << " (" << vaddr() << ")";
#endif #endif
if (vmobject().is_inode())
ASSERT(vmobject().is_shared_inode());
// Create a new region backed by the same VMObject. // 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); auto region = Region::create_user_accessible(m_range, m_vmobject, m_offset_in_vmobject, m_name, m_access);
region->set_mmap(m_mmap); region->set_mmap(m_mmap);
@ -78,6 +81,9 @@ NonnullOwnPtr<Region> Region::clone()
return region; return region;
} }
if (vmobject().is_inode())
ASSERT(vmobject().is_private_inode());
#ifdef MM_DEBUG #ifdef MM_DEBUG
dbg() << "Region::clone(): CoWing " << name() << " (" << vaddr() << ")"; dbg() << "Region::clone(): CoWing " << name() << " (" << vaddr() << ")";
#endif #endif

View file

@ -42,6 +42,8 @@ public:
virtual NonnullRefPtr<VMObject> clone() override; virtual NonnullRefPtr<VMObject> clone() override;
private: private:
virtual bool is_shared_inode() const override { return true; }
explicit SharedInodeVMObject(Inode&, size_t); explicit SharedInodeVMObject(Inode&, size_t);
explicit SharedInodeVMObject(const SharedInodeVMObject&); explicit SharedInodeVMObject(const SharedInodeVMObject&);

View file

@ -52,6 +52,8 @@ public:
virtual bool is_anonymous() const { return false; } virtual bool is_anonymous() const { return false; }
virtual bool is_purgeable() const { return false; } virtual bool is_purgeable() const { return false; }
virtual bool is_inode() 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(); } size_t page_count() const { return m_physical_pages.size(); }
const FixedArray<RefPtr<PhysicalPage>>& physical_pages() const { return m_physical_pages; } const FixedArray<RefPtr<PhysicalPage>>& physical_pages() const { return m_physical_pages; }