diff options
Diffstat (limited to 'src/core/memory.cpp')
| -rw-r--r-- | src/core/memory.cpp | 72 |
1 files changed, 36 insertions, 36 deletions
diff --git a/src/core/memory.cpp b/src/core/memory.cpp index 5c940a82e..a49e971aa 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp | |||
| @@ -22,42 +22,6 @@ | |||
| 22 | namespace Memory { | 22 | namespace Memory { |
| 23 | namespace { | 23 | namespace { |
| 24 | Common::PageTable* current_page_table = nullptr; | 24 | Common::PageTable* current_page_table = nullptr; |
| 25 | |||
| 26 | /** | ||
| 27 | * Gets a pointer to the exact memory at the virtual address (i.e. not page aligned) | ||
| 28 | * using a VMA from the current process | ||
| 29 | */ | ||
| 30 | u8* GetPointerFromVMA(const Kernel::Process& process, VAddr vaddr) { | ||
| 31 | const auto& vm_manager = process.VMManager(); | ||
| 32 | |||
| 33 | const auto it = vm_manager.FindVMA(vaddr); | ||
| 34 | DEBUG_ASSERT(vm_manager.IsValidHandle(it)); | ||
| 35 | |||
| 36 | u8* direct_pointer = nullptr; | ||
| 37 | const auto& vma = it->second; | ||
| 38 | switch (vma.type) { | ||
| 39 | case Kernel::VMAType::AllocatedMemoryBlock: | ||
| 40 | direct_pointer = vma.backing_block->data() + vma.offset; | ||
| 41 | break; | ||
| 42 | case Kernel::VMAType::BackingMemory: | ||
| 43 | direct_pointer = vma.backing_memory; | ||
| 44 | break; | ||
| 45 | case Kernel::VMAType::Free: | ||
| 46 | return nullptr; | ||
| 47 | default: | ||
| 48 | UNREACHABLE(); | ||
| 49 | } | ||
| 50 | |||
| 51 | return direct_pointer + (vaddr - vma.base); | ||
| 52 | } | ||
| 53 | |||
| 54 | /** | ||
| 55 | * Gets a pointer to the exact memory at the virtual address (i.e. not page aligned) | ||
| 56 | * using a VMA from the current process. | ||
| 57 | */ | ||
| 58 | u8* GetPointerFromVMA(VAddr vaddr) { | ||
| 59 | return ::Memory::GetPointerFromVMA(*Core::System::GetInstance().CurrentProcess(), vaddr); | ||
| 60 | } | ||
| 61 | } // Anonymous namespace | 25 | } // Anonymous namespace |
| 62 | 26 | ||
| 63 | // Implementation class used to keep the specifics of the memory subsystem hidden | 27 | // Implementation class used to keep the specifics of the memory subsystem hidden |
| @@ -135,6 +99,42 @@ struct Memory::Impl { | |||
| 135 | return IsValidVirtualAddress(*system.CurrentProcess(), vaddr); | 99 | return IsValidVirtualAddress(*system.CurrentProcess(), vaddr); |
| 136 | } | 100 | } |
| 137 | 101 | ||
| 102 | /** | ||
| 103 | * Gets a pointer to the exact memory at the virtual address (i.e. not page aligned) | ||
| 104 | * using a VMA from the current process | ||
| 105 | */ | ||
| 106 | u8* GetPointerFromVMA(const Kernel::Process& process, VAddr vaddr) { | ||
| 107 | const auto& vm_manager = process.VMManager(); | ||
| 108 | |||
| 109 | const auto it = vm_manager.FindVMA(vaddr); | ||
| 110 | DEBUG_ASSERT(vm_manager.IsValidHandle(it)); | ||
| 111 | |||
| 112 | u8* direct_pointer = nullptr; | ||
| 113 | const auto& vma = it->second; | ||
| 114 | switch (vma.type) { | ||
| 115 | case Kernel::VMAType::AllocatedMemoryBlock: | ||
| 116 | direct_pointer = vma.backing_block->data() + vma.offset; | ||
| 117 | break; | ||
| 118 | case Kernel::VMAType::BackingMemory: | ||
| 119 | direct_pointer = vma.backing_memory; | ||
| 120 | break; | ||
| 121 | case Kernel::VMAType::Free: | ||
| 122 | return nullptr; | ||
| 123 | default: | ||
| 124 | UNREACHABLE(); | ||
| 125 | } | ||
| 126 | |||
| 127 | return direct_pointer + (vaddr - vma.base); | ||
| 128 | } | ||
| 129 | |||
| 130 | /** | ||
| 131 | * Gets a pointer to the exact memory at the virtual address (i.e. not page aligned) | ||
| 132 | * using a VMA from the current process. | ||
| 133 | */ | ||
| 134 | u8* GetPointerFromVMA(VAddr vaddr) { | ||
| 135 | return GetPointerFromVMA(*system.CurrentProcess(), vaddr); | ||
| 136 | } | ||
| 137 | |||
| 138 | u8* GetPointer(const VAddr vaddr) { | 138 | u8* GetPointer(const VAddr vaddr) { |
| 139 | u8* const page_pointer = current_page_table->pointers[vaddr >> PAGE_BITS]; | 139 | u8* const page_pointer = current_page_table->pointers[vaddr >> PAGE_BITS]; |
| 140 | if (page_pointer != nullptr) { | 140 | if (page_pointer != nullptr) { |