1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 22:47:44 +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:
Andreas Kling 2019-11-03 20:37:03 +01:00
parent 9e03f3ce20
commit 2cfc43c982
5 changed files with 42 additions and 39 deletions

View file

@ -122,7 +122,7 @@ Region* Process::allocate_region(VirtualAddress vaddr, size_t size, const String
if (!range.is_valid())
return nullptr;
m_regions.append(Region::create_user_accessible(range, name, prot_to_region_access_flags(prot)));
MM.map_region(*this, m_regions.last());
m_regions.last().map(*this);
if (commit)
m_regions.last().commit();
return &m_regions.last();
@ -134,7 +134,7 @@ Region* Process::allocate_file_backed_region(VirtualAddress vaddr, size_t size,
if (!range.is_valid())
return nullptr;
m_regions.append(Region::create_user_accessible(range, inode, name, prot_to_region_access_flags(prot)));
MM.map_region(*this, m_regions.last());
m_regions.last().map(*this);
return &m_regions.last();
}
@ -145,7 +145,7 @@ Region* Process::allocate_region_with_vmo(VirtualAddress vaddr, size_t size, Non
return nullptr;
offset_in_vmo &= PAGE_MASK;
m_regions.append(Region::create_user_accessible(range, move(vmo), offset_in_vmo, name, prot_to_region_access_flags(prot)));
MM.map_region(*this, m_regions.last());
m_regions.last().map(*this);
return &m_regions.last();
}
@ -259,7 +259,7 @@ int Process::sys$munmap(void* addr, size_t size)
}
// We manually unmap the old region here, specifying that we *don't* want the VM deallocated.
MM.unmap_region(*old_region, false);
old_region->unmap(Region::ShouldDeallocateVirtualMemoryRange::No);
deallocate_region(*old_region);
// Instead we give back the unwanted VM manually.
@ -267,7 +267,7 @@ int Process::sys$munmap(void* addr, size_t size)
// And finally we map the new region(s).
for (auto* new_region : new_regions) {
MM.map_region(*this, *new_region);
new_region->map(*this);
}
return 0;
}
@ -313,7 +313,7 @@ Process* Process::fork(RegisterDump& regs)
dbg() << "fork: cloning Region{" << &region << "} '" << region.name() << "' @ " << region.vaddr();
#endif
child->m_regions.append(region.clone());
MM.map_region(*child, child->m_regions.last());
child->m_regions.last().map(*child);
if (&region == m_master_tls_region)
child->m_master_tls_region = &child->m_regions.last();