From 263290d48caa86f1149e6f2f9a570a36188362c2 Mon Sep 17 00:00:00 2001 From: Weiyi Wang Date: Thu, 25 Oct 2018 11:23:52 -0400 Subject: [PATCH] HLE: move SharedPage into Kernel similar to config_mem, kernel is responsible for setting up this --- src/core/CMakeLists.txt | 4 ++-- src/core/core.cpp | 1 - src/core/core.h | 8 -------- src/core/hle/kernel/kernel.cpp | 10 +++++++++- src/core/hle/kernel/kernel.h | 8 ++++++++ src/core/hle/kernel/memory.cpp | 11 ++++++----- src/core/hle/{ => kernel}/shared_page.cpp | 2 +- src/core/hle/{ => kernel}/shared_page.h | 0 src/core/hle/kernel/wait_object.cpp | 1 - src/core/hle/service/gsp/gsp_gpu.cpp | 3 ++- src/core/hle/service/nwm/nwm_uds.cpp | 5 +++-- src/tests/core/memory/memory.cpp | 2 +- 12 files changed, 32 insertions(+), 23 deletions(-) rename src/core/hle/{ => kernel}/shared_page.cpp (99%) rename src/core/hle/{ => kernel}/shared_page.h (100%) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 2366556883..2ccdaea275 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -144,6 +144,8 @@ add_library(core STATIC hle/kernel/session.h hle/kernel/shared_memory.cpp hle/kernel/shared_memory.h + hle/kernel/shared_page.cpp + hle/kernel/shared_page.h hle/kernel/svc.cpp hle/kernel/svc.h hle/kernel/thread.cpp @@ -386,8 +388,6 @@ add_library(core STATIC hle/service/ssl_c.h hle/service/y2r_u.cpp hle/service/y2r_u.h - hle/shared_page.cpp - hle/shared_page.h hw/aes/arithmetic128.cpp hw/aes/arithmetic128.h hw/aes/ccm.cpp diff --git a/src/core/core.cpp b/src/core/core.cpp index be9796aeb2..a06a9b5491 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -194,7 +194,6 @@ System::ResultStatus System::Init(EmuWindow& emu_window, u32 system_mode) { #endif service_manager = std::make_shared(*this); - shared_page_handler = std::make_shared(); archive_manager = std::make_unique(*this); HW::Init(); diff --git a/src/core/core.h b/src/core/core.h index ea986f433a..0cb53475fb 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -8,7 +8,6 @@ #include #include "common/common_types.h" #include "core/frontend/applets/swkbd.h" -#include "core/hle/shared_page.h" #include "core/loader/loader.h" #include "core/memory.h" #include "core/perf_stats.h" @@ -203,10 +202,6 @@ public: return registered_swkbd; } - std::shared_ptr GetSharedPageHandler() const { - return shared_page_handler; - } - private: /** * Initialize the emulated system. @@ -246,9 +241,6 @@ private: std::unique_ptr rpc_server; #endif - /// Shared Page - std::shared_ptr shared_page_handler; - std::unique_ptr archive_manager; public: // HACK: this is temporary exposed for tests, diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index e491dfa506..8b5621ca68 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp @@ -8,9 +8,9 @@ #include "core/hle/kernel/memory.h" #include "core/hle/kernel/process.h" #include "core/hle/kernel/resource_limit.h" +#include "core/hle/kernel/shared_page.h" #include "core/hle/kernel/thread.h" #include "core/hle/kernel/timer.h" -#include "core/hle/shared_page.h" namespace Kernel { @@ -64,4 +64,12 @@ const TimerManager& KernelSystem::GetTimerManager() const { return *timer_manager; } +SharedPage::Handler& KernelSystem::GetSharedPageHandler() { + return *shared_page_handler; +} + +const SharedPage::Handler& KernelSystem::GetSharedPageHandler() const { + return *shared_page_handler; +} + } // namespace Kernel diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h index e001fa8b7d..69e7fdbd97 100644 --- a/src/core/hle/kernel/kernel.h +++ b/src/core/hle/kernel/kernel.h @@ -16,6 +16,10 @@ namespace ConfigMem { class Handler; } +namespace SharedPage { +class Handler; +} + namespace Kernel { class AddressArbiter; @@ -202,6 +206,9 @@ public: void MapSharedPages(VMManager& address_space); + SharedPage::Handler& GetSharedPageHandler(); + const SharedPage::Handler& GetSharedPageHandler() const; + private: void MemoryInit(u32 mem_type); @@ -221,6 +228,7 @@ private: std::unique_ptr timer_manager; std::unique_ptr config_mem_handler; + std::unique_ptr shared_page_handler; }; } // namespace Kernel diff --git a/src/core/hle/kernel/memory.cpp b/src/core/hle/kernel/memory.cpp index e8c3265699..caa30c8379 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/shared_page.h" #include "core/hle/kernel/vm_manager.h" #include "core/hle/result.h" #include "core/memory.h" @@ -72,6 +73,8 @@ void KernelSystem::MemoryInit(u32 mem_type) { config_mem.app_mem_alloc = memory_region_sizes[mem_type][0]; config_mem.sys_mem_alloc = memory_regions[1].size; config_mem.base_mem_alloc = memory_regions[2].size; + + shared_page_handler = std::make_unique(); } void MemoryShutdown() { @@ -164,11 +167,9 @@ void KernelSystem::MapSharedPages(VMManager& address_space) { auto shared_page_vma = address_space - .MapBackingMemory( - Memory::SHARED_PAGE_VADDR, - reinterpret_cast( - &Core::System::GetInstance().GetSharedPageHandler()->GetSharedPage()), - Memory::SHARED_PAGE_SIZE, MemoryState::Shared) + .MapBackingMemory(Memory::SHARED_PAGE_VADDR, + reinterpret_cast(&shared_page_handler->GetSharedPage()), + Memory::SHARED_PAGE_SIZE, MemoryState::Shared) .Unwrap(); address_space.Reprotect(shared_page_vma, VMAPermission::Read); } diff --git a/src/core/hle/shared_page.cpp b/src/core/hle/kernel/shared_page.cpp similarity index 99% rename from src/core/hle/shared_page.cpp rename to src/core/hle/kernel/shared_page.cpp index 962293609c..831782458a 100644 --- a/src/core/hle/shared_page.cpp +++ b/src/core/hle/kernel/shared_page.cpp @@ -5,8 +5,8 @@ #include #include #include "core/core_timing.h" +#include "core/hle/kernel/shared_page.h" #include "core/hle/service/ptm/ptm.h" -#include "core/hle/shared_page.h" #include "core/movie.h" #include "core/settings.h" diff --git a/src/core/hle/shared_page.h b/src/core/hle/kernel/shared_page.h similarity index 100% rename from src/core/hle/shared_page.h rename to src/core/hle/kernel/shared_page.h diff --git a/src/core/hle/kernel/wait_object.cpp b/src/core/hle/kernel/wait_object.cpp index 17902d76c9..d64b7def76 100644 --- a/src/core/hle/kernel/wait_object.cpp +++ b/src/core/hle/kernel/wait_object.cpp @@ -12,7 +12,6 @@ #include "core/hle/kernel/resource_limit.h" #include "core/hle/kernel/thread.h" #include "core/hle/kernel/timer.h" -#include "core/hle/shared_page.h" namespace Kernel { diff --git a/src/core/hle/service/gsp/gsp_gpu.cpp b/src/core/hle/service/gsp/gsp_gpu.cpp index a6b4826e2b..8ed79ebca7 100644 --- a/src/core/hle/service/gsp/gsp_gpu.cpp +++ b/src/core/hle/service/gsp/gsp_gpu.cpp @@ -11,6 +11,7 @@ #include "core/hle/ipc_helpers.h" #include "core/hle/kernel/handle_table.h" #include "core/hle/kernel/shared_memory.h" +#include "core/hle/kernel/shared_page.h" #include "core/hle/result.h" #include "core/hle/service/gsp/gsp_gpu.h" #include "core/hw/gpu.h" @@ -731,7 +732,7 @@ void GSP_GPU::SetLedForceOff(Kernel::HLERequestContext& ctx) { u8 state = rp.Pop(); - system.GetSharedPageHandler()->Set3DLed(state); + system.Kernel().GetSharedPageHandler().Set3DLed(state); IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); rb.Push(RESULT_SUCCESS); diff --git a/src/core/hle/service/nwm/nwm_uds.cpp b/src/core/hle/service/nwm/nwm_uds.cpp index 735f485a83..92d712263e 100644 --- a/src/core/hle/service/nwm/nwm_uds.cpp +++ b/src/core/hle/service/nwm/nwm_uds.cpp @@ -20,6 +20,7 @@ #include "core/hle/ipc_helpers.h" #include "core/hle/kernel/event.h" #include "core/hle/kernel/shared_memory.h" +#include "core/hle/kernel/shared_page.h" #include "core/hle/lock.h" #include "core/hle/result.h" #include "core/hle/service/nwm/nwm_uds.h" @@ -1407,8 +1408,8 @@ NWM_UDS::NWM_UDS(Core::System& system) : ServiceFramework("nwm::UDS"), system(sy } } - system.GetSharedPageHandler()->SetMacAddress(mac); - system.GetSharedPageHandler()->SetWifiLinkLevel(SharedPage::WifiLinkLevel::BEST); + system.Kernel().GetSharedPageHandler().SetMacAddress(mac); + system.Kernel().GetSharedPageHandler().SetWifiLinkLevel(SharedPage::WifiLinkLevel::BEST); } NWM_UDS::~NWM_UDS() { diff --git a/src/tests/core/memory/memory.cpp b/src/tests/core/memory/memory.cpp index de18480072..150ec8f66b 100644 --- a/src/tests/core/memory/memory.cpp +++ b/src/tests/core/memory/memory.cpp @@ -6,7 +6,7 @@ #include "core/core_timing.h" #include "core/hle/kernel/memory.h" #include "core/hle/kernel/process.h" -#include "core/hle/shared_page.h" +#include "core/hle/kernel/shared_page.h" #include "core/memory.h" TEST_CASE("Memory::IsValidVirtualAddress", "[core][memory]") {