Kernel: Add GeneralAllocator::paddr_of
Yoy can now query physical address of a virtual address for general allocator allocation
This commit is contained in:
@@ -51,9 +51,11 @@ namespace Kernel
|
||||
{
|
||||
vaddr_t vaddr = allocation.address + i * PAGE_SIZE;
|
||||
m_page_table.map_page_at(allocation.pages[i], vaddr, PageTable::Flags::UserSupervisor | PageTable::Flags::ReadWrite | PageTable::Flags::Present);
|
||||
m_page_table.invalidate(vaddr);
|
||||
}
|
||||
|
||||
if (&m_page_table == &PageTable::current())
|
||||
m_page_table.load();
|
||||
|
||||
m_page_table.unlock();
|
||||
|
||||
MUST(m_allocations.push_back(BAN::move(allocation)));
|
||||
@@ -121,4 +123,25 @@ namespace Kernel
|
||||
return allocator;
|
||||
}
|
||||
|
||||
BAN::Optional<paddr_t> GeneralAllocator::paddr_of(vaddr_t vaddr)
|
||||
{
|
||||
for (auto& allocation : m_allocations)
|
||||
{
|
||||
if (!allocation.contains(vaddr))
|
||||
continue;
|
||||
|
||||
size_t offset = vaddr - allocation.address;
|
||||
size_t page_index = offset / PAGE_SIZE;
|
||||
size_t page_offset = offset % PAGE_SIZE;
|
||||
return allocation.pages[page_index] + page_offset;
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
bool GeneralAllocator::Allocation::contains(vaddr_t vaddr)
|
||||
{
|
||||
return this->address <= vaddr && vaddr < this->address + this->pages.size() * PAGE_SIZE;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user