summaryrefslogtreecommitdiff
path: root/Kernel/MemoryManager.h
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-01-22 05:01:00 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-01-22 05:06:22 +0100
commit2f2f28f2127b83ff3454b8b7c42cada550fdbf10 (patch)
treead3bb0ceb7c96868b014a82e6c4d6f9f4840ac27 /Kernel/MemoryManager.h
parentafccbe51a4a3490c534e910aca6fad62afc907b8 (diff)
downloadserenity-2f2f28f2127b83ff3454b8b7c42cada550fdbf10.zip
Kernel: Refactor Region/PageDirectory ownership model.
Make PageDirectory retainable and have each Region co-own the PageDirectory they're mapped into. When unmapped, Region has no associated PageDirectory. This allows Region to automatically unmap itself when destroyed.
Diffstat (limited to 'Kernel/MemoryManager.h')
-rw-r--r--Kernel/MemoryManager.h28
1 files changed, 15 insertions, 13 deletions
diff --git a/Kernel/MemoryManager.h b/Kernel/MemoryManager.h
index 46cbe89edb..d01c773c99 100644
--- a/Kernel/MemoryManager.h
+++ b/Kernel/MemoryManager.h
@@ -56,11 +56,11 @@ private:
PhysicalAddress m_paddr;
};
-class PageDirectory {
+class PageDirectory : public Retainable<PageDirectory> {
friend class MemoryManager;
public:
- PageDirectory();
- explicit PageDirectory(PhysicalAddress);
+ static RetainPtr<PageDirectory> create() { return adopt(*new PageDirectory); }
+ static RetainPtr<PageDirectory> create_at_fixed_address(PhysicalAddress paddr) { return adopt(*new PageDirectory(paddr)); }
~PageDirectory();
dword cr3() const { return m_directory_page->paddr().get(); }
@@ -69,6 +69,9 @@ public:
void flush(LinearAddress);
private:
+ PageDirectory();
+ explicit PageDirectory(PhysicalAddress);
+
RetainPtr<PhysicalPage> m_directory_page;
HashMap<unsigned, RetainPtr<PhysicalPage>> m_physical_pages;
};
@@ -145,12 +148,12 @@ public:
return size / PAGE_SIZE;
}
- bool page_in(PageDirectory&);
- int commit(Process&);
- int decommit(Process&);
+ bool page_in();
+ int commit();
size_t committed() const;
+ RetainPtr<PageDirectory> m_page_directory;
LinearAddress linearAddress;
size_t size { 0 };
size_t m_offset_in_vmo { 0 };
@@ -179,7 +182,7 @@ public:
PageFaultResponse handle_page_fault(const PageFault&);
bool map_region(Process&, Region&);
- bool unmap_region(Process&, Region&);
+ bool unmap_region(Region&);
void populate_page_directory(PageDirectory&);
@@ -203,8 +206,7 @@ private:
void unregister_region(Region&);
void map_region_at_address(PageDirectory&, Region&, LinearAddress, bool user_accessible);
- void unmap_range(PageDirectory&, LinearAddress, size_t);
- void remap_region_page(PageDirectory&, Region&, unsigned page_index_in_region, bool user_allowed);
+ void remap_region_page(Region&, unsigned page_index_in_region, bool user_allowed);
void initialize_paging();
void flush_entire_tlb();
@@ -219,9 +221,9 @@ private:
static Region* region_from_laddr(Process&, LinearAddress);
- bool copy_on_write(Process&, Region&, unsigned page_index_in_region);
- bool page_in_from_inode(PageDirectory&, Region&, unsigned page_index_in_region);
- bool zero_page(PageDirectory&, Region& region, unsigned page_index_in_region);
+ bool copy_on_write(Region&, unsigned page_index_in_region);
+ bool page_in_from_inode(Region&, unsigned page_index_in_region);
+ bool zero_page(Region& region, unsigned page_index_in_region);
byte* quickmap_page(PhysicalPage&);
void unquickmap_page();
@@ -308,7 +310,7 @@ private:
PageTableEntry ensure_pte(PageDirectory&, LinearAddress);
- OwnPtr<PageDirectory> m_kernel_page_directory;
+ RetainPtr<PageDirectory> m_kernel_page_directory;
dword* m_page_table_zero;
LinearAddress m_quickmap_addr;