1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:57:35 +00:00

Kernel: Add mapping from page directory base (PDB) to PageDirectory

This allows the page fault code to find the owning PageDirectory and
corresponding process for faulting regions.

The mapping is implemented as a global hash map right now, which is
definitely not optimal. We can come up with something better when it
becomes necessary.
This commit is contained in:
Andreas Kling 2019-08-06 11:19:16 +02:00
parent 8d07bce12a
commit 2ad963d261
5 changed files with 60 additions and 16 deletions

View file

@ -1,17 +1,24 @@
#pragma once
#include <AK/HashMap.h>
#include <AK/RefPtr.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(const RangeAllocator* parent_range_allocator = nullptr) { return adopt(*new PageDirectory(parent_range_allocator)); }
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(); }
@ -21,10 +28,14 @@ public:
RangeAllocator& range_allocator() { return m_range_allocator; }
Process* process() { return m_process; }
const Process* process() const { return m_process; }
private:
explicit PageDirectory(const RangeAllocator* parent_range_allocator);
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;