summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Lioncash2019-11-26 18:34:30 -0500
committerGravatar Lioncash2019-11-26 21:55:39 -0500
commite7e939104bb167babec7b5f7d5d8390c85f3cbf4 (patch)
tree47b61e77bf8e0e6798b58716d38679a285e3604b /src
parentcore/memory: Migrate over GetPointerFromVMA() to the Memory class (diff)
downloadyuzu-e7e939104bb167babec7b5f7d5d8390c85f3cbf4.tar.gz
yuzu-e7e939104bb167babec7b5f7d5d8390c85f3cbf4.tar.xz
yuzu-e7e939104bb167babec7b5f7d5d8390c85f3cbf4.zip
core/memory; Migrate over SetCurrentPageTable() to the Memory class
Now that literally every other API function is converted over to the Memory class, we can just move the file-local page table into the Memory implementation class, finally getting rid of global state within the memory code.
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/kernel/kernel.cpp18
-rw-r--r--src/core/memory.cpp31
-rw-r--r--src/core/memory.h11
3 files changed, 34 insertions, 26 deletions
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp
index a9851113a..1c90546a4 100644
--- a/src/core/hle/kernel/kernel.cpp
+++ b/src/core/hle/kernel/kernel.cpp
@@ -154,6 +154,16 @@ struct KernelCore::Impl {
154 system.CoreTiming().ScheduleEvent(time_interval, preemption_event); 154 system.CoreTiming().ScheduleEvent(time_interval, preemption_event);
155 } 155 }
156 156
157 void MakeCurrentProcess(Process* process) {
158 current_process = process;
159
160 if (process == nullptr) {
161 return;
162 }
163
164 system.Memory().SetCurrentPageTable(*process);
165 }
166
157 std::atomic<u32> next_object_id{0}; 167 std::atomic<u32> next_object_id{0};
158 std::atomic<u64> next_kernel_process_id{Process::InitialKIPIDMin}; 168 std::atomic<u64> next_kernel_process_id{Process::InitialKIPIDMin};
159 std::atomic<u64> next_user_process_id{Process::ProcessIDMin}; 169 std::atomic<u64> next_user_process_id{Process::ProcessIDMin};
@@ -208,13 +218,7 @@ void KernelCore::AppendNewProcess(std::shared_ptr<Process> process) {
208} 218}
209 219
210void KernelCore::MakeCurrentProcess(Process* process) { 220void KernelCore::MakeCurrentProcess(Process* process) {
211 impl->current_process = process; 221 impl->MakeCurrentProcess(process);
212
213 if (process == nullptr) {
214 return;
215 }
216
217 Memory::SetCurrentPageTable(*process);
218} 222}
219 223
220Process* KernelCore::CurrentProcess() { 224Process* KernelCore::CurrentProcess() {
diff --git a/src/core/memory.cpp b/src/core/memory.cpp
index a49e971aa..91bf07a92 100644
--- a/src/core/memory.cpp
+++ b/src/core/memory.cpp
@@ -20,9 +20,6 @@
20#include "video_core/gpu.h" 20#include "video_core/gpu.h"
21 21
22namespace Memory { 22namespace Memory {
23namespace {
24Common::PageTable* current_page_table = nullptr;
25} // Anonymous namespace
26 23
27// Implementation class used to keep the specifics of the memory subsystem hidden 24// Implementation class used to keep the specifics of the memory subsystem hidden
28// from outside classes. This also allows modification to the internals of the memory 25// from outside classes. This also allows modification to the internals of the memory
@@ -30,6 +27,17 @@ Common::PageTable* current_page_table = nullptr;
30struct Memory::Impl { 27struct Memory::Impl {
31 explicit Impl(Core::System& system_) : system{system_} {} 28 explicit Impl(Core::System& system_) : system{system_} {}
32 29
30 void SetCurrentPageTable(Kernel::Process& process) {
31 current_page_table = &process.VMManager().page_table;
32
33 const std::size_t address_space_width = process.VMManager().GetAddressSpaceWidth();
34
35 system.ArmInterface(0).PageTableChanged(*current_page_table, address_space_width);
36 system.ArmInterface(1).PageTableChanged(*current_page_table, address_space_width);
37 system.ArmInterface(2).PageTableChanged(*current_page_table, address_space_width);
38 system.ArmInterface(3).PageTableChanged(*current_page_table, address_space_width);
39 }
40
33 void MapMemoryRegion(Common::PageTable& page_table, VAddr base, u64 size, u8* target) { 41 void MapMemoryRegion(Common::PageTable& page_table, VAddr base, u64 size, u8* target) {
34 ASSERT_MSG((size & PAGE_MASK) == 0, "non-page aligned size: {:016X}", size); 42 ASSERT_MSG((size & PAGE_MASK) == 0, "non-page aligned size: {:016X}", size);
35 ASSERT_MSG((base & PAGE_MASK) == 0, "non-page aligned base: {:016X}", base); 43 ASSERT_MSG((base & PAGE_MASK) == 0, "non-page aligned base: {:016X}", base);
@@ -575,12 +583,17 @@ struct Memory::Impl {
575 } 583 }
576 } 584 }
577 585
586 Common::PageTable* current_page_table = nullptr;
578 Core::System& system; 587 Core::System& system;
579}; 588};
580 589
581Memory::Memory(Core::System& system) : impl{std::make_unique<Impl>(system)} {} 590Memory::Memory(Core::System& system) : impl{std::make_unique<Impl>(system)} {}
582Memory::~Memory() = default; 591Memory::~Memory() = default;
583 592
593void Memory::SetCurrentPageTable(Kernel::Process& process) {
594 impl->SetCurrentPageTable(process);
595}
596
584void Memory::MapMemoryRegion(Common::PageTable& page_table, VAddr base, u64 size, u8* target) { 597void Memory::MapMemoryRegion(Common::PageTable& page_table, VAddr base, u64 size, u8* target) {
585 impl->MapMemoryRegion(page_table, base, size, target); 598 impl->MapMemoryRegion(page_table, base, size, target);
586} 599}
@@ -695,18 +708,6 @@ void Memory::RasterizerMarkRegionCached(VAddr vaddr, u64 size, bool cached) {
695 impl->RasterizerMarkRegionCached(vaddr, size, cached); 708 impl->RasterizerMarkRegionCached(vaddr, size, cached);
696} 709}
697 710
698void SetCurrentPageTable(Kernel::Process& process) {
699 current_page_table = &process.VMManager().page_table;
700
701 const std::size_t address_space_width = process.VMManager().GetAddressSpaceWidth();
702
703 auto& system = Core::System::GetInstance();
704 system.ArmInterface(0).PageTableChanged(*current_page_table, address_space_width);
705 system.ArmInterface(1).PageTableChanged(*current_page_table, address_space_width);
706 system.ArmInterface(2).PageTableChanged(*current_page_table, address_space_width);
707 system.ArmInterface(3).PageTableChanged(*current_page_table, address_space_width);
708}
709
710bool IsKernelVirtualAddress(const VAddr vaddr) { 711bool IsKernelVirtualAddress(const VAddr vaddr) {
711 return KERNEL_REGION_VADDR <= vaddr && vaddr < KERNEL_REGION_END; 712 return KERNEL_REGION_VADDR <= vaddr && vaddr < KERNEL_REGION_END;
712} 713}
diff --git a/src/core/memory.h b/src/core/memory.h
index 7878f3fb1..1428a6d60 100644
--- a/src/core/memory.h
+++ b/src/core/memory.h
@@ -59,6 +59,13 @@ public:
59 Memory& operator=(Memory&&) = default; 59 Memory& operator=(Memory&&) = default;
60 60
61 /** 61 /**
62 * Changes the currently active page table to that of the given process instance.
63 *
64 * @param process The process to use the page table of.
65 */
66 void SetCurrentPageTable(Kernel::Process& process);
67
68 /**
62 * Maps an allocated buffer onto a region of the emulated process address space. 69 * Maps an allocated buffer onto a region of the emulated process address space.
63 * 70 *
64 * @param page_table The page table of the emulated process. 71 * @param page_table The page table of the emulated process.
@@ -401,10 +408,6 @@ private:
401 std::unique_ptr<Impl> impl; 408 std::unique_ptr<Impl> impl;
402}; 409};
403 410
404/// Changes the currently active page table to that of
405/// the given process instance.
406void SetCurrentPageTable(Kernel::Process& process);
407
408/// Determines if the given VAddr is a kernel address 411/// Determines if the given VAddr is a kernel address
409bool IsKernelVirtualAddress(VAddr vaddr); 412bool IsKernelVirtualAddress(VAddr vaddr);
410 413