From 8118be6615bed2453e91f815ad16f418a87f3dac Mon Sep 17 00:00:00 2001 From: Weiyi Wang Date: Tue, 20 Nov 2018 22:48:19 -0500 Subject: [PATCH] Kernel: pass in MemorySystem --- src/core/core.cpp | 2 +- src/core/hle/kernel/kernel.cpp | 2 +- src/core/hle/kernel/kernel.h | 8 +++++++- src/tests/core/arm/arm_test_common.cpp | 3 ++- src/tests/core/hle/kernel/hle_ipc.cpp | 6 ++++-- src/tests/core/memory/memory.cpp | 3 ++- 6 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/core/core.cpp b/src/core/core.cpp index 6d8265db82..2d150a9cc3 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -176,7 +176,7 @@ System::ResultStatus System::Init(EmuWindow& emu_window, u32 system_mode) { timing = std::make_unique(); - kernel = std::make_unique(system_mode); + kernel = std::make_unique(*memory, system_mode); if (Settings::values.use_cpu_jit) { #ifdef ARCHITECTURE_x86_64 diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index 1c174d2ea2..5633d9bbce 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp @@ -16,7 +16,7 @@ namespace Kernel { /// Initialize the kernel -KernelSystem::KernelSystem(u32 system_mode) { +KernelSystem::KernelSystem(Memory::MemorySystem& memory, u32 system_mode) : memory(memory) { MemoryInit(system_mode); resource_limits = std::make_unique(*this); diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h index cf6e95fe44..7864ec8f9d 100644 --- a/src/core/hle/kernel/kernel.h +++ b/src/core/hle/kernel/kernel.h @@ -23,6 +23,10 @@ namespace SharedPage { class Handler; } +namespace Memory { +class MemorySystem; +} + namespace Kernel { class AddressArbiter; @@ -73,7 +77,7 @@ using SharedPtr = boost::intrusive_ptr; class KernelSystem { public: - explicit KernelSystem(u32 system_mode); + explicit KernelSystem(Memory::MemorySystem& memory, u32 system_mode); ~KernelSystem(); /** @@ -220,6 +224,8 @@ public: /// Map of named ports managed by the kernel, which can be retrieved using the ConnectToPort std::unordered_map> named_ports; + Memory::MemorySystem& memory; + private: void MemoryInit(u32 mem_type); diff --git a/src/tests/core/arm/arm_test_common.cpp b/src/tests/core/arm/arm_test_common.cpp index 58b60f506c..61b4e1addf 100644 --- a/src/tests/core/arm/arm_test_common.cpp +++ b/src/tests/core/arm/arm_test_common.cpp @@ -20,7 +20,8 @@ TestEnvironment::TestEnvironment(bool mutable_memory_) // so we need to create the kernel object there. // Change this when all global states are eliminated. Core::System::GetInstance().timing = std::make_unique(); - Core::System::GetInstance().kernel = std::make_unique(0); + Memory::MemorySystem memory; + Core::System::GetInstance().kernel = std::make_unique(memory, 0); kernel = Core::System::GetInstance().kernel.get(); kernel->SetCurrentProcess(kernel->CreateProcess(kernel->CreateCodeSet("", 0))); diff --git a/src/tests/core/hle/kernel/hle_ipc.cpp b/src/tests/core/hle/kernel/hle_ipc.cpp index 86de36db48..1167cd1262 100644 --- a/src/tests/core/hle/kernel/hle_ipc.cpp +++ b/src/tests/core/hle/kernel/hle_ipc.cpp @@ -23,7 +23,8 @@ static SharedPtr MakeObject(Kernel::KernelSystem& kernel) { TEST_CASE("HLERequestContext::PopulateFromIncomingCommandBuffer", "[core][kernel]") { // HACK: see comments of member timing Core::System::GetInstance().timing = std::make_unique(); - Kernel::KernelSystem kernel(0); + Memory::MemorySystem memory; + Kernel::KernelSystem kernel(memory, 0); auto session = std::get>(kernel.CreateSessionPair()); HLERequestContext context(std::move(session)); @@ -235,7 +236,8 @@ TEST_CASE("HLERequestContext::PopulateFromIncomingCommandBuffer", "[core][kernel TEST_CASE("HLERequestContext::WriteToOutgoingCommandBuffer", "[core][kernel]") { // HACK: see comments of member timing Core::System::GetInstance().timing = std::make_unique(); - Kernel::KernelSystem kernel(0); + Memory::MemorySystem memory; + Kernel::KernelSystem kernel(memory, 0); auto session = std::get>(kernel.CreateSessionPair()); HLERequestContext context(std::move(session)); diff --git a/src/tests/core/memory/memory.cpp b/src/tests/core/memory/memory.cpp index 196cd78eff..88ad5d7443 100644 --- a/src/tests/core/memory/memory.cpp +++ b/src/tests/core/memory/memory.cpp @@ -13,7 +13,8 @@ TEST_CASE("Memory::IsValidVirtualAddress", "[core][memory]") { // HACK: see comments of member timing Core::System::GetInstance().timing = std::make_unique(); - Kernel::KernelSystem kernel(0); + Memory::MemorySystem memory; + Kernel::KernelSystem kernel(memory, 0); SECTION("these regions should not be mapped on an empty process") { auto process = kernel.CreateProcess(kernel.CreateCodeSet("", 0)); CHECK(Memory::IsValidVirtualAddress(*process, Memory::PROCESS_IMAGE_VADDR) == false);