2019-04-03 13:13:07 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/HashMap.h>
|
2019-06-21 16:45:35 +00:00
|
|
|
#include <AK/RefPtr.h>
|
2019-06-21 16:58:45 +00:00
|
|
|
#include <AK/RefCounted.h>
|
2019-05-28 09:53:16 +00:00
|
|
|
#include <Kernel/VM/PhysicalPage.h>
|
|
|
|
#include <Kernel/VM/RangeAllocator.h>
|
2019-04-03 13:13:07 +00:00
|
|
|
|
2019-06-21 13:29:31 +00:00
|
|
|
class PageDirectory : public RefCounted<PageDirectory> {
|
2019-04-03 13:13:07 +00:00
|
|
|
friend class MemoryManager;
|
2019-05-28 09:53:16 +00:00
|
|
|
|
2019-04-03 13:13:07 +00:00
|
|
|
public:
|
2019-06-21 16:37:47 +00:00
|
|
|
static NonnullRefPtr<PageDirectory> create_for_userspace(const RangeAllocator* parent_range_allocator = nullptr) { return adopt(*new PageDirectory(parent_range_allocator)); }
|
|
|
|
static NonnullRefPtr<PageDirectory> create_at_fixed_address(PhysicalAddress paddr) { return adopt(*new PageDirectory(paddr)); }
|
2019-04-03 13:13:07 +00:00
|
|
|
~PageDirectory();
|
|
|
|
|
2019-07-03 19:17:35 +00:00
|
|
|
u32 cr3() const { return m_directory_page->paddr().get(); }
|
2019-06-26 19:45:56 +00:00
|
|
|
PageDirectoryEntry* entries() { return reinterpret_cast<PageDirectoryEntry*>(cr3()); }
|
2019-04-03 13:13:07 +00:00
|
|
|
|
2019-06-07 10:56:50 +00:00
|
|
|
void flush(VirtualAddress);
|
2019-04-03 13:13:07 +00:00
|
|
|
|
2019-05-20 02:46:29 +00:00
|
|
|
RangeAllocator& range_allocator() { return m_range_allocator; }
|
|
|
|
|
2019-04-03 13:13:07 +00:00
|
|
|
private:
|
2019-05-22 11:24:28 +00:00
|
|
|
explicit PageDirectory(const RangeAllocator* parent_range_allocator);
|
2019-04-03 13:13:07 +00:00
|
|
|
explicit PageDirectory(PhysicalAddress);
|
|
|
|
|
2019-05-20 02:46:29 +00:00
|
|
|
RangeAllocator m_range_allocator;
|
2019-06-21 16:37:47 +00:00
|
|
|
RefPtr<PhysicalPage> m_directory_page;
|
|
|
|
HashMap<unsigned, RefPtr<PhysicalPage>> m_physical_pages;
|
2019-04-03 13:13:07 +00:00
|
|
|
};
|