mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 18:58:12 +00:00
Kernel: Move region map/unmap operations into the Region class
The more Region can take care of itself, the better.
This commit is contained in:
parent
9e03f3ce20
commit
2cfc43c982
5 changed files with 42 additions and 39 deletions
|
@ -41,7 +41,7 @@ Region::~Region()
|
|||
// find the address<->region mappings in an invalid state there.
|
||||
InterruptDisabler disabler;
|
||||
if (m_page_directory) {
|
||||
MM.unmap_region(*this);
|
||||
unmap(ShouldDeallocateVirtualMemoryRange::Yes);
|
||||
ASSERT(!m_page_directory);
|
||||
}
|
||||
MM.unregister_region(*this);
|
||||
|
@ -192,3 +192,31 @@ void Region::remap_page(size_t index)
|
|||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Region::unmap(ShouldDeallocateVirtualMemoryRange deallocate_range)
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
ASSERT(page_directory());
|
||||
for (size_t i = 0; i < page_count(); ++i) {
|
||||
auto vaddr = this->vaddr().offset(i * PAGE_SIZE);
|
||||
auto& pte = MM.ensure_pte(*page_directory(), vaddr);
|
||||
pte.set_physical_page_base(0);
|
||||
pte.set_present(false);
|
||||
pte.set_writable(false);
|
||||
pte.set_user_allowed(false);
|
||||
page_directory()->flush(vaddr);
|
||||
#ifdef MM_DEBUG
|
||||
auto& physical_page = region.vmobject().physical_pages()[region.first_page_index() + i];
|
||||
dbgprintf("MM: >> Unmapped V%p => P%p <<\n", vaddr, physical_page ? physical_page->paddr().get() : 0);
|
||||
#endif
|
||||
}
|
||||
if (deallocate_range == ShouldDeallocateVirtualMemoryRange::Yes)
|
||||
page_directory()->range_allocator().deallocate(range());
|
||||
release_page_directory();
|
||||
}
|
||||
|
||||
void Region::map(Process& process)
|
||||
{
|
||||
MM.map_region_at_address(process.page_directory(), *this, vaddr());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue