#pragma once #include #include #include #include #include #include #include #include #include class Inode; class PhysicalPage; class VMObject : public Retainable, public Weakable { friend class MemoryManager; public: static Retained create_file_backed(RetainPtr&&); static Retained create_anonymous(size_t); static Retained create_for_physical_range(PhysicalAddress, size_t); Retained clone(); ~VMObject(); bool is_anonymous() const { return !m_inode; } Inode* inode() { return m_inode.ptr(); } const Inode* inode() const { return m_inode.ptr(); } size_t inode_offset() const { return m_inode_offset; } String name() const { return m_name; } void set_name(const String& name) { m_name = name; } size_t page_count() const { return m_size / PAGE_SIZE; } const Vector>& physical_pages() const { return m_physical_pages; } Vector>& physical_pages() { return m_physical_pages; } void inode_contents_changed(Badge, off_t, ssize_t, const byte*); void inode_size_changed(Badge, size_t old_size, size_t new_size); size_t size() const { return m_size; } private: VMObject(RetainPtr&&); explicit VMObject(VMObject&); explicit VMObject(size_t); VMObject(PhysicalAddress, size_t); template void for_each_region(Callback); String m_name; bool m_allow_cpu_caching { true }; off_t m_inode_offset { 0 }; size_t m_size { 0 }; RetainPtr m_inode; Vector> m_physical_pages; Lock m_paging_lock { "VMObject" }; };