mirror of
https://github.com/RGBCube/serenity
synced 2025-05-16 16:04:58 +00:00
Implement address validation by querying the task's page directory.
This is way better than walking the region lists. I suppose we could even let the hardware trigger a page fault and handle that. That'll be the next step in the evolution here I guess.
This commit is contained in:
parent
f76fcd1e62
commit
0f70b9105f
5 changed files with 82 additions and 34 deletions
|
@ -90,12 +90,12 @@ auto MemoryManager::ensurePTE(dword* page_directory, LinearAddress laddr) -> Pag
|
|||
#endif
|
||||
if (pageDirectoryIndex == 0) {
|
||||
pde.setPageTableBase((dword)m_pageTableZero);
|
||||
pde.setUserAllowed(true);
|
||||
pde.setUserAllowed(false);
|
||||
pde.setPresent(true);
|
||||
pde.setWritable(true);
|
||||
} else if (pageDirectoryIndex == 1) {
|
||||
pde.setPageTableBase((dword)m_pageTableOne);
|
||||
pde.setUserAllowed(true);
|
||||
pde.setUserAllowed(false);
|
||||
pde.setPresent(true);
|
||||
pde.setWritable(true);
|
||||
} else {
|
||||
|
@ -135,7 +135,7 @@ void MemoryManager::identityMap(LinearAddress linearAddress, size_t length)
|
|||
auto pteAddress = linearAddress.offset(offset);
|
||||
auto pte = ensurePTE(m_kernel_page_directory, pteAddress);
|
||||
pte.setPhysicalPageBase(pteAddress.get());
|
||||
pte.setUserAllowed(true);
|
||||
pte.setUserAllowed(false);
|
||||
pte.setPresent(true);
|
||||
pte.setWritable(true);
|
||||
flushTLB(pteAddress);
|
||||
|
@ -375,6 +375,38 @@ bool MemoryManager::mapRegion(Task& task, Task::Region& region)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool MemoryManager::validate_user_read(const Task& task, LinearAddress laddr) const
|
||||
{
|
||||
dword pageDirectoryIndex = (laddr.get() >> 22) & 0x3ff;
|
||||
dword pageTableIndex = (laddr.get() >> 12) & 0x3ff;
|
||||
auto pde = PageDirectoryEntry(&task.m_pageDirectory[pageDirectoryIndex]);
|
||||
if (!pde.isPresent())
|
||||
return false;
|
||||
auto pte = PageTableEntry(&pde.pageTableBase()[pageTableIndex]);
|
||||
if (!pte.isPresent())
|
||||
return false;
|
||||
if (!pte.isUserAllowed())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MemoryManager::validate_user_write(const Task& task, LinearAddress laddr) const
|
||||
{
|
||||
dword pageDirectoryIndex = (laddr.get() >> 22) & 0x3ff;
|
||||
dword pageTableIndex = (laddr.get() >> 12) & 0x3ff;
|
||||
auto pde = PageDirectoryEntry(&task.m_pageDirectory[pageDirectoryIndex]);
|
||||
if (!pde.isPresent())
|
||||
return false;
|
||||
auto pte = PageTableEntry(&pde.pageTableBase()[pageTableIndex]);
|
||||
if (!pte.isPresent())
|
||||
return false;
|
||||
if (!pte.isUserAllowed())
|
||||
return false;
|
||||
if (!pte.isWritable())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MemoryManager::mapRegionsForTask(Task& task)
|
||||
{
|
||||
ASSERT_INTERRUPTS_DISABLED();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue