mirror of
https://github.com/RGBCube/serenity
synced 2025-05-15 12:44:58 +00:00
Protect the first 4 KB of memory.
This makes null pointers crashy, tremendously useful :^)
This commit is contained in:
parent
dd6706a1a1
commit
d5ec18027e
2 changed files with 18 additions and 1 deletions
|
@ -38,7 +38,10 @@ void MemoryManager::initializePaging()
|
|||
kprintf("MM: Page table zero @ %p\n", m_pageTableZero);
|
||||
kprintf("MM: Page table one @ %p\n", m_pageTableOne);
|
||||
|
||||
identityMap(LinearAddress(0), 4 * MB);
|
||||
// Make null dereferences crash.
|
||||
protectMap(LinearAddress(0), 4 * KB);
|
||||
|
||||
identityMap(LinearAddress(4096), 4 * MB);
|
||||
|
||||
// Put pages between 4MB and 16MB in the page freelist.
|
||||
for (size_t i = (4 * MB) + 1024; i < (16 * MB); i += PAGE_SIZE) {
|
||||
|
@ -79,6 +82,19 @@ auto MemoryManager::ensurePTE(LinearAddress linearAddress) -> PageTableEntry
|
|||
return PageTableEntry(&pde.pageTableBase()[pageTableIndex]);
|
||||
}
|
||||
|
||||
void MemoryManager::protectMap(LinearAddress linearAddress, size_t length)
|
||||
{
|
||||
// FIXME: ASSERT(linearAddress is 4KB aligned);
|
||||
for (dword offset = 0; offset < length; offset += 4096) {
|
||||
auto pteAddress = linearAddress.offset(offset);
|
||||
auto pte = ensurePTE(pteAddress);
|
||||
pte.setPhysicalPageBase(pteAddress.get());
|
||||
pte.setUserAllowed(false);
|
||||
pte.setPresent(false);
|
||||
pte.setWritable(false);
|
||||
}
|
||||
}
|
||||
|
||||
void MemoryManager::identityMap(LinearAddress linearAddress, size_t length)
|
||||
{
|
||||
// FIXME: ASSERT(linearAddress is 4KB aligned);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue