From ece96807c4bbf65f0a0a57987e3086442d4b53dd Mon Sep 17 00:00:00 2001 From: Weiyi Wang Date: Thu, 25 Oct 2018 21:07:15 -0400 Subject: [PATCH] Kernel: move memory_regions into Kernel instance --- src/core/hle/kernel/kernel.cpp | 4 +--- src/core/hle/kernel/kernel.h | 6 ++++++ src/core/hle/kernel/memory.cpp | 14 ++------------ src/core/hle/kernel/memory.h | 7 ++----- src/core/hle/kernel/process.cpp | 2 +- src/core/hle/kernel/svc.cpp | 14 ++++++++------ src/core/memory.cpp | 2 +- 7 files changed, 21 insertions(+), 28 deletions(-) diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index 8b5621ca6..704b7b709 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp @@ -24,9 +24,7 @@ KernelSystem::KernelSystem(u32 system_mode) { } /// Shutdown the kernel -KernelSystem::~KernelSystem() { - Kernel::MemoryShutdown(); -} +KernelSystem::~KernelSystem() = default; ResourceLimitList& KernelSystem::ResourceLimit() { return *resource_limits; diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h index 69e7fdbd9..7d7560e50 100644 --- a/src/core/hle/kernel/kernel.h +++ b/src/core/hle/kernel/kernel.h @@ -4,12 +4,14 @@ #pragma once +#include #include #include #include #include #include #include "common/common_types.h" +#include "core/hle/kernel/memory.h" #include "core/hle/result.h" namespace ConfigMem { @@ -209,6 +211,10 @@ public: SharedPage::Handler& GetSharedPageHandler(); const SharedPage::Handler& GetSharedPageHandler() const; + MemoryRegionInfo* GetMemoryRegion(MemoryRegion region); + + std::array memory_regions; + private: void MemoryInit(u32 mem_type); diff --git a/src/core/hle/kernel/memory.cpp b/src/core/hle/kernel/memory.cpp index caa30c837..3a2e9957a 100644 --- a/src/core/hle/kernel/memory.cpp +++ b/src/core/hle/kernel/memory.cpp @@ -14,6 +14,7 @@ #include "core/core.h" #include "core/hle/kernel/config_mem.h" #include "core/hle/kernel/memory.h" +#include "core/hle/kernel/process.h" #include "core/hle/kernel/shared_page.h" #include "core/hle/kernel/vm_manager.h" #include "core/hle/result.h" @@ -24,8 +25,6 @@ namespace Kernel { -MemoryRegionInfo memory_regions[3]; - /// Size of the APPLICATION, SYSTEM and BASE memory regions (respectively) for each system /// memory configuration type. static const u32 memory_region_sizes[8][3] = { @@ -77,16 +76,7 @@ void KernelSystem::MemoryInit(u32 mem_type) { shared_page_handler = std::make_unique(); } -void MemoryShutdown() { - for (auto& region : memory_regions) { - region.base = 0; - region.size = 0; - region.used = 0; - region.linear_heap_memory = nullptr; - } -} - -MemoryRegionInfo* GetMemoryRegion(MemoryRegion region) { +MemoryRegionInfo* KernelSystem::GetMemoryRegion(MemoryRegion region) { switch (region) { case MemoryRegion::APPLICATION: return &memory_regions[0]; diff --git a/src/core/hle/kernel/memory.h b/src/core/hle/kernel/memory.h index a39a53977..14a38bdb9 100644 --- a/src/core/hle/kernel/memory.h +++ b/src/core/hle/kernel/memory.h @@ -5,11 +5,12 @@ #pragma once #include +#include #include "common/common_types.h" -#include "core/hle/kernel/process.h" namespace Kernel { +struct AddressMapping; class VMManager; struct MemoryRegionInfo { @@ -20,10 +21,6 @@ struct MemoryRegionInfo { std::shared_ptr> linear_heap_memory; }; -void MemoryShutdown(); -MemoryRegionInfo* GetMemoryRegion(MemoryRegion region); - void HandleSpecialMapping(VMManager& address_space, const AddressMapping& mapping); -extern MemoryRegionInfo memory_regions[3]; } // namespace Kernel diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp index 9b45c77f1..c41d4ebd9 100644 --- a/src/core/hle/kernel/process.cpp +++ b/src/core/hle/kernel/process.cpp @@ -115,7 +115,7 @@ void Process::ParseKernelCaps(const u32* kernel_caps, std::size_t len) { } void Process::Run(s32 main_thread_priority, u32 stack_size) { - memory_region = GetMemoryRegion(flags.memory_region); + memory_region = kernel.GetMemoryRegion(flags.memory_region); auto MapSegment = [&](CodeSet::Segment& segment, VMAPermission permissions, MemoryState memory_state) { diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 07079fc4d..9dc6f2700 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp @@ -1233,22 +1233,24 @@ static ResultCode AcceptSession(Handle* out_server_session, Handle server_port_h static ResultCode GetSystemInfo(s64* out, u32 type, s32 param) { LOG_TRACE(Kernel_SVC, "called type={} param={}", type, param); + KernelSystem& kernel = Core::System::GetInstance().Kernel(); + switch ((SystemInfoType)type) { case SystemInfoType::REGION_MEMORY_USAGE: switch ((SystemInfoMemUsageRegion)param) { case SystemInfoMemUsageRegion::ALL: - *out = GetMemoryRegion(MemoryRegion::APPLICATION)->used + - GetMemoryRegion(MemoryRegion::SYSTEM)->used + - GetMemoryRegion(MemoryRegion::BASE)->used; + *out = kernel.GetMemoryRegion(MemoryRegion::APPLICATION)->used + + kernel.GetMemoryRegion(MemoryRegion::SYSTEM)->used + + kernel.GetMemoryRegion(MemoryRegion::BASE)->used; break; case SystemInfoMemUsageRegion::APPLICATION: - *out = GetMemoryRegion(MemoryRegion::APPLICATION)->used; + *out = kernel.GetMemoryRegion(MemoryRegion::APPLICATION)->used; break; case SystemInfoMemUsageRegion::SYSTEM: - *out = GetMemoryRegion(MemoryRegion::SYSTEM)->used; + *out = kernel.GetMemoryRegion(MemoryRegion::SYSTEM)->used; break; case SystemInfoMemUsageRegion::BASE: - *out = GetMemoryRegion(MemoryRegion::BASE)->used; + *out = kernel.GetMemoryRegion(MemoryRegion::BASE)->used; break; default: LOG_ERROR(Kernel_SVC, "unknown GetSystemInfo type=0 region: param={}", param); diff --git a/src/core/memory.cpp b/src/core/memory.cpp index 0054dc75e..eed279c9a 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp @@ -305,7 +305,7 @@ u8* GetPhysicalPointer(PAddr address) { target_pointer = Core::DSP().GetDspMemory().data() + offset_into_region; break; case FCRAM_PADDR: - for (const auto& region : Kernel::memory_regions) { + for (const auto& region : Core::System::GetInstance().Kernel().memory_regions) { if (offset_into_region >= region.base && offset_into_region < region.base + region.size) { target_pointer =