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