core/memory: Migrate over GetPointerFromVMA() to the Memory class
Now that everything else is migrated over, this is essentially just code relocation and conversion of a global accessor to the class member variable. All that remains is to migrate over the page table.
This commit is contained in:
parent
e4c381b885
commit
50a518be69
1 changed files with 36 additions and 36 deletions
|
@ -22,42 +22,6 @@
|
||||||
namespace Memory {
|
namespace Memory {
|
||||||
namespace {
|
namespace {
|
||||||
Common::PageTable* current_page_table = nullptr;
|
Common::PageTable* current_page_table = nullptr;
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a pointer to the exact memory at the virtual address (i.e. not page aligned)
|
|
||||||
* using a VMA from the current process
|
|
||||||
*/
|
|
||||||
u8* GetPointerFromVMA(const Kernel::Process& process, VAddr vaddr) {
|
|
||||||
const auto& vm_manager = process.VMManager();
|
|
||||||
|
|
||||||
const auto it = vm_manager.FindVMA(vaddr);
|
|
||||||
DEBUG_ASSERT(vm_manager.IsValidHandle(it));
|
|
||||||
|
|
||||||
u8* direct_pointer = nullptr;
|
|
||||||
const auto& vma = it->second;
|
|
||||||
switch (vma.type) {
|
|
||||||
case Kernel::VMAType::AllocatedMemoryBlock:
|
|
||||||
direct_pointer = vma.backing_block->data() + vma.offset;
|
|
||||||
break;
|
|
||||||
case Kernel::VMAType::BackingMemory:
|
|
||||||
direct_pointer = vma.backing_memory;
|
|
||||||
break;
|
|
||||||
case Kernel::VMAType::Free:
|
|
||||||
return nullptr;
|
|
||||||
default:
|
|
||||||
UNREACHABLE();
|
|
||||||
}
|
|
||||||
|
|
||||||
return direct_pointer + (vaddr - vma.base);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a pointer to the exact memory at the virtual address (i.e. not page aligned)
|
|
||||||
* using a VMA from the current process.
|
|
||||||
*/
|
|
||||||
u8* GetPointerFromVMA(VAddr vaddr) {
|
|
||||||
return ::Memory::GetPointerFromVMA(*Core::System::GetInstance().CurrentProcess(), vaddr);
|
|
||||||
}
|
|
||||||
} // Anonymous namespace
|
} // Anonymous namespace
|
||||||
|
|
||||||
// Implementation class used to keep the specifics of the memory subsystem hidden
|
// Implementation class used to keep the specifics of the memory subsystem hidden
|
||||||
|
@ -135,6 +99,42 @@ struct Memory::Impl {
|
||||||
return IsValidVirtualAddress(*system.CurrentProcess(), vaddr);
|
return IsValidVirtualAddress(*system.CurrentProcess(), vaddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a pointer to the exact memory at the virtual address (i.e. not page aligned)
|
||||||
|
* using a VMA from the current process
|
||||||
|
*/
|
||||||
|
u8* GetPointerFromVMA(const Kernel::Process& process, VAddr vaddr) {
|
||||||
|
const auto& vm_manager = process.VMManager();
|
||||||
|
|
||||||
|
const auto it = vm_manager.FindVMA(vaddr);
|
||||||
|
DEBUG_ASSERT(vm_manager.IsValidHandle(it));
|
||||||
|
|
||||||
|
u8* direct_pointer = nullptr;
|
||||||
|
const auto& vma = it->second;
|
||||||
|
switch (vma.type) {
|
||||||
|
case Kernel::VMAType::AllocatedMemoryBlock:
|
||||||
|
direct_pointer = vma.backing_block->data() + vma.offset;
|
||||||
|
break;
|
||||||
|
case Kernel::VMAType::BackingMemory:
|
||||||
|
direct_pointer = vma.backing_memory;
|
||||||
|
break;
|
||||||
|
case Kernel::VMAType::Free:
|
||||||
|
return nullptr;
|
||||||
|
default:
|
||||||
|
UNREACHABLE();
|
||||||
|
}
|
||||||
|
|
||||||
|
return direct_pointer + (vaddr - vma.base);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a pointer to the exact memory at the virtual address (i.e. not page aligned)
|
||||||
|
* using a VMA from the current process.
|
||||||
|
*/
|
||||||
|
u8* GetPointerFromVMA(VAddr vaddr) {
|
||||||
|
return GetPointerFromVMA(*system.CurrentProcess(), vaddr);
|
||||||
|
}
|
||||||
|
|
||||||
u8* GetPointer(const VAddr vaddr) {
|
u8* GetPointer(const VAddr vaddr) {
|
||||||
u8* const page_pointer = current_page_table->pointers[vaddr >> PAGE_BITS];
|
u8* const page_pointer = current_page_table->pointers[vaddr >> PAGE_BITS];
|
||||||
if (page_pointer != nullptr) {
|
if (page_pointer != nullptr) {
|
||||||
|
|
Loading…
Reference in a new issue