mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 01:20:25 +00:00
Kernel: Break region_from_vaddr() into {user,kernel}_region_from_vaddr
Sometimes you're only interested in either user OR kernel regions but not both. Let's break this into two functions so the caller can choose what he's interested in.
This commit is contained in:
parent
e27e1b3fb2
commit
8d07bce12a
Notes:
sideshowbarker
2024-07-19 12:51:34 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/8d07bce12ae
2 changed files with 30 additions and 26 deletions
|
@ -255,42 +255,43 @@ void MemoryManager::initialize()
|
|||
s_the = new MemoryManager;
|
||||
}
|
||||
|
||||
Region* MemoryManager::kernel_region_from_vaddr(VirtualAddress vaddr)
|
||||
{
|
||||
ASSERT(vaddr.get() >= 0xc0000000);
|
||||
for (auto& region : MM.m_kernel_regions) {
|
||||
if (region->contains(vaddr))
|
||||
return region;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Region* MemoryManager::user_region_from_vaddr(Process& process, VirtualAddress vaddr)
|
||||
{
|
||||
// FIXME: Use a binary search tree (maybe red/black?) or some other more appropriate data structure!
|
||||
for (auto& region : process.m_regions) {
|
||||
if (region.contains(vaddr))
|
||||
return ®ion;
|
||||
}
|
||||
dbg() << process << " Couldn't find user region for " << vaddr;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Region* MemoryManager::region_from_vaddr(Process& process, VirtualAddress vaddr)
|
||||
{
|
||||
ASSERT_INTERRUPTS_DISABLED();
|
||||
|
||||
if (vaddr.get() >= 0xc0000000) {
|
||||
for (auto& region : MM.m_kernel_regions) {
|
||||
if (region->contains(vaddr))
|
||||
return region;
|
||||
}
|
||||
}
|
||||
if (vaddr.get() >= 0xc0000000)
|
||||
return kernel_region_from_vaddr(vaddr);
|
||||
|
||||
// FIXME: Use a binary search tree (maybe red/black?) or some other more appropriate data structure!
|
||||
for (auto& region : process.m_regions) {
|
||||
if (region.contains(vaddr))
|
||||
return ®ion;
|
||||
}
|
||||
dbgprintf("%s(%u) Couldn't find region for L%x (CR3=%x)\n", process.name().characters(), process.pid(), vaddr.get(), process.page_directory().cr3());
|
||||
return nullptr;
|
||||
return user_region_from_vaddr(process, vaddr);
|
||||
}
|
||||
|
||||
const Region* MemoryManager::region_from_vaddr(const Process& process, VirtualAddress vaddr)
|
||||
{
|
||||
if (vaddr.get() >= 0xc0000000) {
|
||||
for (auto& region : MM.m_kernel_regions) {
|
||||
if (region->contains(vaddr))
|
||||
return region;
|
||||
}
|
||||
}
|
||||
if (vaddr.get() >= 0xc0000000)
|
||||
return kernel_region_from_vaddr(vaddr);
|
||||
|
||||
// FIXME: Use a binary search tree (maybe red/black?) or some other more appropriate data structure!
|
||||
for (auto& region : process.m_regions) {
|
||||
if (region.contains(vaddr))
|
||||
return ®ion;
|
||||
}
|
||||
dbgprintf("%s(%u) Couldn't find region for L%x (CR3=%x)\n", process.name().characters(), process.pid(), vaddr.get(), process.page_directory().cr3());
|
||||
return nullptr;
|
||||
return user_region_from_vaddr(const_cast<Process&>(process), vaddr);
|
||||
}
|
||||
|
||||
bool MemoryManager::zero_page(Region& region, unsigned page_index_in_region)
|
||||
|
|
|
@ -105,6 +105,9 @@ private:
|
|||
static Region* region_from_vaddr(Process&, VirtualAddress);
|
||||
static const Region* region_from_vaddr(const Process&, VirtualAddress);
|
||||
|
||||
static Region* user_region_from_vaddr(Process&, VirtualAddress);
|
||||
static Region* kernel_region_from_vaddr(VirtualAddress);
|
||||
|
||||
bool copy_on_write(Region&, unsigned page_index_in_region);
|
||||
bool page_in_from_inode(Region&, unsigned page_index_in_region);
|
||||
bool zero_page(Region& region, unsigned page_index_in_region);
|
||||
|
|
Loading…
Reference in a new issue