summaryrefslogtreecommitdiff
path: root/Kernel/VM/PageDirectory.h
blob: b6458c1055e702609f9e4d56f01f7c1e6bda251f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#pragma once

#include <AK/HashMap.h>
#include <AK/RefCounted.h>
#include <AK/RefPtr.h>
#include <Kernel/VM/PhysicalPage.h>
#include <Kernel/VM/RangeAllocator.h>

class Process;

class PageDirectory : public RefCounted<PageDirectory> {
    friend class MemoryManager;

public:
    static NonnullRefPtr<PageDirectory> create_for_userspace(Process& process, const RangeAllocator* parent_range_allocator = nullptr)
    {
        return adopt(*new PageDirectory(process, parent_range_allocator));
    }
    static NonnullRefPtr<PageDirectory> create_at_fixed_address(PhysicalAddress paddr) { return adopt(*new PageDirectory(paddr)); }
    static RefPtr<PageDirectory> find_by_pdb(u32);

    ~PageDirectory();

    u32 cr3() const { return m_directory_page->paddr().get(); }
    PageDirectoryEntry* entries() { return reinterpret_cast<PageDirectoryEntry*>(cr3()); }

    void flush(VirtualAddress);

    RangeAllocator& range_allocator() { return m_range_allocator; }

    Process* process() { return m_process; }
    const Process* process() const { return m_process; }

private:
    PageDirectory(Process&, const RangeAllocator* parent_range_allocator);
    explicit PageDirectory(PhysicalAddress);

    Process* m_process { nullptr };
    RangeAllocator m_range_allocator;
    RefPtr<PhysicalPage> m_directory_page;
    HashMap<unsigned, RefPtr<PhysicalPage>> m_physical_pages;
};