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));
|
|
|
|
}
|
2020-01-17 21:59:20 +03:00
|
|
|
static NonnullRefPtr<PageDirectory> create_kernel_page_directory() { return adopt(*new PageDirectory); }
|
2019-12-25 04:46:17 +03:00
|
|
|
static RefPtr<PageDirectory> find_by_cr3(u32);
|
2019-08-06 12:19:16 +03:00
|
|
|
|
2019-04-03 16:13:07 +03:00
|
|
|
~PageDirectory();
|
|
|
|
|
2019-12-25 13:22:16 +03:00
|
|
|
u32 cr3() const { return m_directory_table->paddr().get(); }
|
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);
|
2020-01-17 21:59:20 +03:00
|
|
|
PageDirectory();
|
2019-04-03 16:13:07 +03:00
|
|
|
|
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-12-25 13:22:16 +03:00
|
|
|
RefPtr<PhysicalPage> m_directory_table;
|
|
|
|
RefPtr<PhysicalPage> m_directory_pages[4];
|
2019-06-21 19:37:47 +03:00
|
|
|
HashMap<unsigned, RefPtr<PhysicalPage>> m_physical_pages;
|
2019-04-03 16:13:07 +03:00
|
|
|
};
|