1
0
mirror of https://github.com/citra-emu/citra.git synced 2025-04-11 09:50:08 +00:00

kernel: Let the kernel handle all page table changes when switching processes

It will both change the page table in memory and notify the CPU about the change by itself. This way there is no need to call memory.SetCurrentPageTable() when kernel.setCurrentProcess() and the management is kept internally in the kernel
This commit is contained in:
bamsbamx 2019-06-26 00:39:11 +02:00
parent ac9755306c
commit dbfd830695
6 changed files with 25 additions and 11 deletions

@ -141,7 +141,6 @@ System::ResultStatus System::Load(Frontend::EmuWindow& emu_window, const std::st
return ResultStatus::ErrorLoader; return ResultStatus::ErrorLoader;
} }
} }
memory->SetCurrentPageTable(&kernel->GetCurrentProcess()->vm_manager.page_table);
cheat_engine = std::make_unique<Cheats::CheatEngine>(*this); cheat_engine = std::make_unique<Cheats::CheatEngine>(*this);
status = ResultStatus::Success; status = ResultStatus::Success;
m_emu_window = &emu_window; m_emu_window = &emu_window;
@ -179,16 +178,16 @@ System::ResultStatus System::Init(Frontend::EmuWindow& emu_window, u32 system_mo
if (Settings::values.use_cpu_jit) { if (Settings::values.use_cpu_jit) {
#ifdef ARCHITECTURE_x86_64 #ifdef ARCHITECTURE_x86_64
cpu_core = std::make_unique<ARM_Dynarmic>(this, *memory, USER32MODE); cpu_core = std::make_shared<ARM_Dynarmic>(this, *memory, USER32MODE);
#else #else
cpu_core = std::make_unique<ARM_DynCom>(this, *memory, USER32MODE); cpu_core = std::make_shared<ARM_DynCom>(this, *memory, USER32MODE);
LOG_WARNING(Core, "CPU JIT requested, but Dynarmic not available"); LOG_WARNING(Core, "CPU JIT requested, but Dynarmic not available");
#endif #endif
} else { } else {
cpu_core = std::make_unique<ARM_DynCom>(this, *memory, USER32MODE); cpu_core = std::make_shared<ARM_DynCom>(this, *memory, USER32MODE);
} }
kernel->GetThreadManager().SetCPU(*cpu_core); kernel->SetCPU(cpu_core);
if (Settings::values.enable_dsp_lle) { if (Settings::values.enable_dsp_lle) {
dsp_core = std::make_unique<AudioCore::DspLle>(*memory, dsp_core = std::make_unique<AudioCore::DspLle>(*memory,

@ -255,7 +255,7 @@ private:
std::unique_ptr<Loader::AppLoader> app_loader; std::unique_ptr<Loader::AppLoader> app_loader;
/// ARM11 CPU core /// ARM11 CPU core
std::unique_ptr<ARM_Interface> cpu_core; std::shared_ptr<ARM_Interface> cpu_core;
/// DSP core /// DSP core
std::unique_ptr<AudioCore::DspInterface> dsp_core; std::unique_ptr<AudioCore::DspInterface> dsp_core;

@ -47,7 +47,18 @@ std::shared_ptr<Process> KernelSystem::GetCurrentProcess() const {
} }
void KernelSystem::SetCurrentProcess(std::shared_ptr<Process> process) { void KernelSystem::SetCurrentProcess(std::shared_ptr<Process> process) {
current_process = std::move(process); current_process = process;
SetCurrentMemPageTable(&process->vm_manager.page_table);
}
void KernelSystem::SetCurrentMemPageTable(Memory::PageTable* page_table) {
memory.SetCurrentPageTable(page_table);
current_cpu->PageTableChanged(); // notify the CPU the page table in memory has changed
}
void KernelSystem::SetCPU(std::shared_ptr<ARM_Interface> cpu) {
current_cpu = cpu;
thread_manager->SetCPU(*cpu);
} }
ThreadManager& KernelSystem::GetThreadManager() { ThreadManager& KernelSystem::GetThreadManager() {

@ -14,6 +14,7 @@
#include "common/common_types.h" #include "common/common_types.h"
#include "core/hle/kernel/memory.h" #include "core/hle/kernel/memory.h"
#include "core/hle/result.h" #include "core/hle/result.h"
#include "core/memory.h"
namespace ConfigMem { namespace ConfigMem {
class Handler; class Handler;
@ -206,6 +207,10 @@ public:
std::shared_ptr<Process> GetCurrentProcess() const; std::shared_ptr<Process> GetCurrentProcess() const;
void SetCurrentProcess(std::shared_ptr<Process> process); void SetCurrentProcess(std::shared_ptr<Process> process);
void SetCurrentMemPageTable(Memory::PageTable* page_table);
void SetCPU(std::shared_ptr<ARM_Interface> cpu);
ThreadManager& GetThreadManager(); ThreadManager& GetThreadManager();
const ThreadManager& GetThreadManager() const; const ThreadManager& GetThreadManager() const;
@ -233,6 +238,8 @@ public:
/// Map of named ports managed by the kernel, which can be retrieved using the ConnectToPort /// Map of named ports managed by the kernel, which can be retrieved using the ConnectToPort
std::unordered_map<std::string, std::shared_ptr<ClientPort>> named_ports; std::unordered_map<std::string, std::shared_ptr<ClientPort>> named_ports;
std::shared_ptr<ARM_Interface> current_cpu;
Memory::MemorySystem& memory; Memory::MemorySystem& memory;
Core::Timing& timing; Core::Timing& timing;

@ -112,9 +112,6 @@ void ThreadManager::SwitchContext(Thread* new_thread) {
if (previous_process.get() != current_thread->owner_process) { if (previous_process.get() != current_thread->owner_process) {
kernel.SetCurrentProcess(SharedFrom(current_thread->owner_process)); kernel.SetCurrentProcess(SharedFrom(current_thread->owner_process));
kernel.memory.SetCurrentPageTable(
&current_thread->owner_process->vm_manager.page_table);
cpu->PageTableChanged(); // notify the CPU the page table in memory has changed
} }
cpu->LoadContext(new_thread->context); cpu->LoadContext(new_thread->context);

@ -28,7 +28,7 @@ TestEnvironment::TestEnvironment(bool mutable_memory_)
memory->MapIoRegion(*page_table, 0x00000000, 0x80000000, test_memory); memory->MapIoRegion(*page_table, 0x00000000, 0x80000000, test_memory);
memory->MapIoRegion(*page_table, 0x80000000, 0x80000000, test_memory); memory->MapIoRegion(*page_table, 0x80000000, 0x80000000, test_memory);
memory->SetCurrentPageTable(page_table); kernel->SetCurrentMemPageTable(page_table);
} }
TestEnvironment::~TestEnvironment() { TestEnvironment::~TestEnvironment() {