1
0
Fork 0

Merge pull request #4389 from wwylele/kernel-global-4

Kernel: clean up the rest of global states
This commit is contained in:
Weiyi Wang 2018-11-01 14:09:27 -04:00 committed by GitHub
commit 7c3d325aff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 113 additions and 108 deletions

View File

@ -103,8 +103,6 @@ add_library(core STATIC
hle/applets/mint.h hle/applets/mint.h
hle/applets/swkbd.cpp hle/applets/swkbd.cpp
hle/applets/swkbd.h hle/applets/swkbd.h
hle/config_mem.cpp
hle/config_mem.h
hle/function_wrappers.h hle/function_wrappers.h
hle/ipc.h hle/ipc.h
hle/ipc_helpers.h hle/ipc_helpers.h
@ -114,6 +112,8 @@ add_library(core STATIC
hle/kernel/client_port.h hle/kernel/client_port.h
hle/kernel/client_session.cpp hle/kernel/client_session.cpp
hle/kernel/client_session.h hle/kernel/client_session.h
hle/kernel/config_mem.cpp
hle/kernel/config_mem.h
hle/kernel/errors.h hle/kernel/errors.h
hle/kernel/event.cpp hle/kernel/event.cpp
hle/kernel/event.h hle/kernel/event.h
@ -144,6 +144,8 @@ add_library(core STATIC
hle/kernel/session.h hle/kernel/session.h
hle/kernel/shared_memory.cpp hle/kernel/shared_memory.cpp
hle/kernel/shared_memory.h hle/kernel/shared_memory.h
hle/kernel/shared_page.cpp
hle/kernel/shared_page.h
hle/kernel/svc.cpp hle/kernel/svc.cpp
hle/kernel/svc.h hle/kernel/svc.h
hle/kernel/thread.cpp hle/kernel/thread.cpp
@ -386,8 +388,6 @@ add_library(core STATIC
hle/service/ssl_c.h hle/service/ssl_c.h
hle/service/y2r_u.cpp hle/service/y2r_u.cpp
hle/service/y2r_u.h hle/service/y2r_u.h
hle/shared_page.cpp
hle/shared_page.h
hw/aes/arithmetic128.cpp hw/aes/arithmetic128.cpp
hw/aes/arithmetic128.h hw/aes/arithmetic128.h
hw/aes/ccm.cpp hw/aes/ccm.cpp

View File

@ -194,7 +194,6 @@ System::ResultStatus System::Init(EmuWindow& emu_window, u32 system_mode) {
#endif #endif
service_manager = std::make_shared<Service::SM::ServiceManager>(*this); service_manager = std::make_shared<Service::SM::ServiceManager>(*this);
shared_page_handler = std::make_shared<SharedPage::Handler>();
archive_manager = std::make_unique<Service::FS::ArchiveManager>(*this); archive_manager = std::make_unique<Service::FS::ArchiveManager>(*this);
HW::Init(); HW::Init();
@ -257,7 +256,6 @@ void System::Shutdown() {
// Shutdown emulation session // Shutdown emulation session
GDBStub::Shutdown(); GDBStub::Shutdown();
VideoCore::Shutdown(); VideoCore::Shutdown();
Service::Shutdown();
kernel.reset(); kernel.reset();
HW::Shutdown(); HW::Shutdown();
telemetry_session.reset(); telemetry_session.reset();

View File

@ -8,7 +8,6 @@
#include <string> #include <string>
#include "common/common_types.h" #include "common/common_types.h"
#include "core/frontend/applets/swkbd.h" #include "core/frontend/applets/swkbd.h"
#include "core/hle/shared_page.h"
#include "core/loader/loader.h" #include "core/loader/loader.h"
#include "core/memory.h" #include "core/memory.h"
#include "core/perf_stats.h" #include "core/perf_stats.h"
@ -203,10 +202,6 @@ public:
return registered_swkbd; return registered_swkbd;
} }
std::shared_ptr<SharedPage::Handler> GetSharedPageHandler() const {
return shared_page_handler;
}
private: private:
/** /**
* Initialize the emulated system. * Initialize the emulated system.
@ -246,9 +241,6 @@ private:
std::unique_ptr<RPC::RPCServer> rpc_server; std::unique_ptr<RPC::RPCServer> rpc_server;
#endif #endif
/// Shared Page
std::shared_ptr<SharedPage::Handler> shared_page_handler;
std::unique_ptr<Service::FS::ArchiveManager> archive_manager; std::unique_ptr<Service::FS::ArchiveManager> archive_manager;
public: // HACK: this is temporary exposed for tests, public: // HACK: this is temporary exposed for tests,

View File

@ -3,15 +3,13 @@
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <cstring> #include <cstring>
#include "core/hle/config_mem.h" #include "core/hle/kernel/config_mem.h"
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
namespace ConfigMem { namespace ConfigMem {
ConfigMemDef config_mem; Handler::Handler() {
void Init() {
std::memset(&config_mem, 0, sizeof(config_mem)); std::memset(&config_mem, 0, sizeof(config_mem));
// Values extracted from firmware 11.2.0-35E // Values extracted from firmware 11.2.0-35E
@ -28,4 +26,8 @@ void Init() {
config_mem.firm_ctr_sdk_ver = 0x0000F297; config_mem.firm_ctr_sdk_ver = 0x0000F297;
} }
ConfigMemDef& Handler::GetConfigMem() {
return config_mem;
}
} // namespace ConfigMem } // namespace ConfigMem

View File

@ -49,8 +49,13 @@ struct ConfigMemDef {
static_assert(sizeof(ConfigMemDef) == Memory::CONFIG_MEMORY_SIZE, static_assert(sizeof(ConfigMemDef) == Memory::CONFIG_MEMORY_SIZE,
"Config Memory structure size is wrong"); "Config Memory structure size is wrong");
extern ConfigMemDef config_mem; class Handler {
public:
Handler();
ConfigMemDef& GetConfigMem();
void Init(); private:
ConfigMemDef config_mem;
};
} // namespace ConfigMem } // namespace ConfigMem

View File

@ -2,23 +2,22 @@
// Licensed under GPLv2 or any later version // Licensed under GPLv2 or any later version
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "core/hle/config_mem.h" #include "core/hle/kernel/client_port.h"
#include "core/hle/kernel/config_mem.h"
#include "core/hle/kernel/handle_table.h" #include "core/hle/kernel/handle_table.h"
#include "core/hle/kernel/kernel.h" #include "core/hle/kernel/kernel.h"
#include "core/hle/kernel/memory.h" #include "core/hle/kernel/memory.h"
#include "core/hle/kernel/process.h" #include "core/hle/kernel/process.h"
#include "core/hle/kernel/resource_limit.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/thread.h"
#include "core/hle/kernel/timer.h" #include "core/hle/kernel/timer.h"
#include "core/hle/shared_page.h"
namespace Kernel { namespace Kernel {
/// Initialize the kernel /// Initialize the kernel
KernelSystem::KernelSystem(u32 system_mode) { KernelSystem::KernelSystem(u32 system_mode) {
ConfigMem::Init(); MemoryInit(system_mode);
Kernel::MemoryInit(system_mode);
resource_limits = std::make_unique<ResourceLimitList>(*this); resource_limits = std::make_unique<ResourceLimitList>(*this);
thread_manager = std::make_unique<ThreadManager>(); thread_manager = std::make_unique<ThreadManager>();
@ -26,9 +25,7 @@ KernelSystem::KernelSystem(u32 system_mode) {
} }
/// Shutdown the kernel /// Shutdown the kernel
KernelSystem::~KernelSystem() { KernelSystem::~KernelSystem() = default;
Kernel::MemoryShutdown();
}
ResourceLimitList& KernelSystem::ResourceLimit() { ResourceLimitList& KernelSystem::ResourceLimit() {
return *resource_limits; return *resource_limits;
@ -66,4 +63,16 @@ const TimerManager& KernelSystem::GetTimerManager() const {
return *timer_manager; return *timer_manager;
} }
SharedPage::Handler& KernelSystem::GetSharedPageHandler() {
return *shared_page_handler;
}
const SharedPage::Handler& KernelSystem::GetSharedPageHandler() const {
return *shared_page_handler;
}
void KernelSystem::AddNamedPort(std::string name, SharedPtr<ClientPort> port) {
named_ports.emplace(std::move(name), std::move(port));
}
} // namespace Kernel } // namespace Kernel

View File

@ -4,14 +4,25 @@
#pragma once #pragma once
#include <array>
#include <atomic> #include <atomic>
#include <memory> #include <memory>
#include <string> #include <string>
#include <unordered_map>
#include <vector> #include <vector>
#include <boost/smart_ptr/intrusive_ptr.hpp> #include <boost/smart_ptr/intrusive_ptr.hpp>
#include "common/common_types.h" #include "common/common_types.h"
#include "core/hle/kernel/memory.h"
#include "core/hle/result.h" #include "core/hle/result.h"
namespace ConfigMem {
class Handler;
}
namespace SharedPage {
class Handler;
}
namespace Kernel { namespace Kernel {
class AddressArbiter; class AddressArbiter;
@ -30,6 +41,7 @@ class ResourceLimitList;
class SharedMemory; class SharedMemory;
class ThreadManager; class ThreadManager;
class TimerManager; class TimerManager;
class VMManager;
enum class ResetType { enum class ResetType {
OneShot, OneShot,
@ -195,7 +207,24 @@ public:
TimerManager& GetTimerManager(); TimerManager& GetTimerManager();
const TimerManager& GetTimerManager() const; const TimerManager& GetTimerManager() const;
void MapSharedPages(VMManager& address_space);
SharedPage::Handler& GetSharedPageHandler();
const SharedPage::Handler& GetSharedPageHandler() const;
MemoryRegionInfo* GetMemoryRegion(MemoryRegion region);
std::array<MemoryRegionInfo, 3> memory_regions;
/// Adds a port to the named port table
void AddNamedPort(std::string name, SharedPtr<ClientPort> port);
/// Map of named ports managed by the kernel, which can be retrieved using the ConnectToPort
std::unordered_map<std::string, SharedPtr<ClientPort>> named_ports;
private: private:
void MemoryInit(u32 mem_type);
std::unique_ptr<ResourceLimitList> resource_limits; std::unique_ptr<ResourceLimitList> resource_limits;
std::atomic<u32> next_object_id{0}; std::atomic<u32> next_object_id{0};
@ -210,6 +239,9 @@ private:
std::unique_ptr<ThreadManager> thread_manager; std::unique_ptr<ThreadManager> thread_manager;
std::unique_ptr<TimerManager> timer_manager; std::unique_ptr<TimerManager> timer_manager;
std::unique_ptr<ConfigMem::Handler> config_mem_handler;
std::unique_ptr<SharedPage::Handler> shared_page_handler;
}; };
} // namespace Kernel } // namespace Kernel

View File

@ -12,8 +12,10 @@
#include "common/common_types.h" #include "common/common_types.h"
#include "common/logging/log.h" #include "common/logging/log.h"
#include "core/core.h" #include "core/core.h"
#include "core/hle/config_mem.h" #include "core/hle/kernel/config_mem.h"
#include "core/hle/kernel/memory.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/kernel/vm_manager.h"
#include "core/hle/result.h" #include "core/hle/result.h"
#include "core/memory.h" #include "core/memory.h"
@ -23,8 +25,6 @@
namespace Kernel { namespace Kernel {
MemoryRegionInfo memory_regions[3];
/// Size of the APPLICATION, SYSTEM and BASE memory regions (respectively) for each system /// Size of the APPLICATION, SYSTEM and BASE memory regions (respectively) for each system
/// memory configuration type. /// memory configuration type.
static const u32 memory_region_sizes[8][3] = { static const u32 memory_region_sizes[8][3] = {
@ -41,7 +41,7 @@ static const u32 memory_region_sizes[8][3] = {
{0x0B200000, 0x02E00000, 0x02000000}, // 7 {0x0B200000, 0x02E00000, 0x02000000}, // 7
}; };
void MemoryInit(u32 mem_type) { void KernelSystem::MemoryInit(u32 mem_type) {
// TODO(yuriks): On the n3DS, all o3DS configurations (<=5) are forced to 6 instead. // TODO(yuriks): On the n3DS, all o3DS configurations (<=5) are forced to 6 instead.
ASSERT_MSG(mem_type <= 5, "New 3DS memory configuration aren't supported yet!"); ASSERT_MSG(mem_type <= 5, "New 3DS memory configuration aren't supported yet!");
ASSERT(mem_type != 1); ASSERT(mem_type != 1);
@ -64,25 +64,19 @@ void MemoryInit(u32 mem_type) {
// We must've allocated the entire FCRAM by the end // We must've allocated the entire FCRAM by the end
ASSERT(base == Memory::FCRAM_SIZE); ASSERT(base == Memory::FCRAM_SIZE);
using ConfigMem::config_mem; config_mem_handler = std::make_unique<ConfigMem::Handler>();
auto& config_mem = config_mem_handler->GetConfigMem();
config_mem.app_mem_type = mem_type; config_mem.app_mem_type = mem_type;
// app_mem_malloc does not always match the configured size for memory_region[0]: in case the // app_mem_malloc does not always match the configured size for memory_region[0]: in case the
// n3DS type override is in effect it reports the size the game expects, not the real one. // n3DS type override is in effect it reports the size the game expects, not the real one.
config_mem.app_mem_alloc = memory_region_sizes[mem_type][0]; config_mem.app_mem_alloc = memory_region_sizes[mem_type][0];
config_mem.sys_mem_alloc = memory_regions[1].size; config_mem.sys_mem_alloc = memory_regions[1].size;
config_mem.base_mem_alloc = memory_regions[2].size; config_mem.base_mem_alloc = memory_regions[2].size;
shared_page_handler = std::make_unique<SharedPage::Handler>();
} }
void MemoryShutdown() { MemoryRegionInfo* KernelSystem::GetMemoryRegion(MemoryRegion region) {
for (auto& region : memory_regions) {
region.base = 0;
region.size = 0;
region.used = 0;
region.linear_heap_memory = nullptr;
}
}
MemoryRegionInfo* GetMemoryRegion(MemoryRegion region) {
switch (region) { switch (region) {
case MemoryRegion::APPLICATION: case MemoryRegion::APPLICATION:
return &memory_regions[0]; return &memory_regions[0];
@ -152,21 +146,20 @@ void HandleSpecialMapping(VMManager& address_space, const AddressMapping& mappin
mapping.read_only ? VMAPermission::Read : VMAPermission::ReadWrite); mapping.read_only ? VMAPermission::Read : VMAPermission::ReadWrite);
} }
void MapSharedPages(VMManager& address_space) { void KernelSystem::MapSharedPages(VMManager& address_space) {
auto cfg_mem_vma = address_space auto cfg_mem_vma =
.MapBackingMemory(Memory::CONFIG_MEMORY_VADDR, address_space
reinterpret_cast<u8*>(&ConfigMem::config_mem), .MapBackingMemory(Memory::CONFIG_MEMORY_VADDR,
Memory::CONFIG_MEMORY_SIZE, MemoryState::Shared) reinterpret_cast<u8*>(&config_mem_handler->GetConfigMem()),
.Unwrap(); Memory::CONFIG_MEMORY_SIZE, MemoryState::Shared)
.Unwrap();
address_space.Reprotect(cfg_mem_vma, VMAPermission::Read); address_space.Reprotect(cfg_mem_vma, VMAPermission::Read);
auto shared_page_vma = auto shared_page_vma =
address_space address_space
.MapBackingMemory( .MapBackingMemory(Memory::SHARED_PAGE_VADDR,
Memory::SHARED_PAGE_VADDR, reinterpret_cast<u8*>(&shared_page_handler->GetSharedPage()),
reinterpret_cast<u8*>( Memory::SHARED_PAGE_SIZE, MemoryState::Shared)
&Core::System::GetInstance().GetSharedPageHandler()->GetSharedPage()),
Memory::SHARED_PAGE_SIZE, MemoryState::Shared)
.Unwrap(); .Unwrap();
address_space.Reprotect(shared_page_vma, VMAPermission::Read); address_space.Reprotect(shared_page_vma, VMAPermission::Read);
} }

View File

@ -5,11 +5,12 @@
#pragma once #pragma once
#include <memory> #include <memory>
#include <vector>
#include "common/common_types.h" #include "common/common_types.h"
#include "core/hle/kernel/process.h"
namespace Kernel { namespace Kernel {
struct AddressMapping;
class VMManager; class VMManager;
struct MemoryRegionInfo { struct MemoryRegionInfo {
@ -20,12 +21,6 @@ struct MemoryRegionInfo {
std::shared_ptr<std::vector<u8>> linear_heap_memory; std::shared_ptr<std::vector<u8>> linear_heap_memory;
}; };
void MemoryInit(u32 mem_type);
void MemoryShutdown();
MemoryRegionInfo* GetMemoryRegion(MemoryRegion region);
void HandleSpecialMapping(VMManager& address_space, const AddressMapping& mapping); void HandleSpecialMapping(VMManager& address_space, const AddressMapping& mapping);
void MapSharedPages(VMManager& address_space);
extern MemoryRegionInfo memory_regions[3];
} // namespace Kernel } // namespace Kernel

View File

@ -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) { 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, auto MapSegment = [&](CodeSet::Segment& segment, VMAPermission permissions,
MemoryState memory_state) { MemoryState memory_state) {
@ -143,7 +143,7 @@ void Process::Run(s32 main_thread_priority, u32 stack_size) {
memory_region->used += stack_size; memory_region->used += stack_size;
// Map special address mappings // Map special address mappings
MapSharedPages(vm_manager); kernel.MapSharedPages(vm_manager);
for (const auto& mapping : address_mappings) { for (const auto& mapping : address_mappings) {
HandleSpecialMapping(vm_manager, mapping); HandleSpecialMapping(vm_manager, mapping);
} }

View File

@ -5,8 +5,8 @@
#include <chrono> #include <chrono>
#include <cstring> #include <cstring>
#include "core/core_timing.h" #include "core/core_timing.h"
#include "core/hle/kernel/shared_page.h"
#include "core/hle/service/ptm/ptm.h" #include "core/hle/service/ptm/ptm.h"
#include "core/hle/shared_page.h"
#include "core/movie.h" #include "core/movie.h"
#include "core/settings.h" #include "core/settings.h"

View File

@ -235,8 +235,10 @@ static ResultCode ConnectToPort(Handle* out_handle, VAddr port_name_address) {
LOG_TRACE(Kernel_SVC, "called port_name={}", port_name); LOG_TRACE(Kernel_SVC, "called port_name={}", port_name);
auto it = Service::g_kernel_named_ports.find(port_name); KernelSystem& kernel = Core::System::GetInstance().Kernel();
if (it == Service::g_kernel_named_ports.end()) {
auto it = kernel.named_ports.find(port_name);
if (it == kernel.named_ports.end()) {
LOG_WARNING(Kernel_SVC, "tried to connect to unknown port: {}", port_name); LOG_WARNING(Kernel_SVC, "tried to connect to unknown port: {}", port_name);
return ERR_NOT_FOUND; return ERR_NOT_FOUND;
} }
@ -247,9 +249,7 @@ static ResultCode ConnectToPort(Handle* out_handle, VAddr port_name_address) {
CASCADE_RESULT(client_session, client_port->Connect()); CASCADE_RESULT(client_session, client_port->Connect());
// Return the client session // Return the client session
CASCADE_RESULT(*out_handle, CASCADE_RESULT(*out_handle, kernel.GetCurrentProcess()->handle_table.Create(client_session));
Core::System::GetInstance().Kernel().GetCurrentProcess()->handle_table.Create(
client_session));
return RESULT_SUCCESS; return RESULT_SUCCESS;
} }
@ -1233,22 +1233,24 @@ static ResultCode AcceptSession(Handle* out_server_session, Handle server_port_h
static ResultCode GetSystemInfo(s64* out, u32 type, s32 param) { static ResultCode GetSystemInfo(s64* out, u32 type, s32 param) {
LOG_TRACE(Kernel_SVC, "called type={} param={}", type, param); LOG_TRACE(Kernel_SVC, "called type={} param={}", type, param);
KernelSystem& kernel = Core::System::GetInstance().Kernel();
switch ((SystemInfoType)type) { switch ((SystemInfoType)type) {
case SystemInfoType::REGION_MEMORY_USAGE: case SystemInfoType::REGION_MEMORY_USAGE:
switch ((SystemInfoMemUsageRegion)param) { switch ((SystemInfoMemUsageRegion)param) {
case SystemInfoMemUsageRegion::ALL: case SystemInfoMemUsageRegion::ALL:
*out = GetMemoryRegion(MemoryRegion::APPLICATION)->used + *out = kernel.GetMemoryRegion(MemoryRegion::APPLICATION)->used +
GetMemoryRegion(MemoryRegion::SYSTEM)->used + kernel.GetMemoryRegion(MemoryRegion::SYSTEM)->used +
GetMemoryRegion(MemoryRegion::BASE)->used; kernel.GetMemoryRegion(MemoryRegion::BASE)->used;
break; break;
case SystemInfoMemUsageRegion::APPLICATION: case SystemInfoMemUsageRegion::APPLICATION:
*out = GetMemoryRegion(MemoryRegion::APPLICATION)->used; *out = kernel.GetMemoryRegion(MemoryRegion::APPLICATION)->used;
break; break;
case SystemInfoMemUsageRegion::SYSTEM: case SystemInfoMemUsageRegion::SYSTEM:
*out = GetMemoryRegion(MemoryRegion::SYSTEM)->used; *out = kernel.GetMemoryRegion(MemoryRegion::SYSTEM)->used;
break; break;
case SystemInfoMemUsageRegion::BASE: case SystemInfoMemUsageRegion::BASE:
*out = GetMemoryRegion(MemoryRegion::BASE)->used; *out = kernel.GetMemoryRegion(MemoryRegion::BASE)->used;
break; break;
default: default:
LOG_ERROR(Kernel_SVC, "unknown GetSystemInfo type=0 region: param={}", param); LOG_ERROR(Kernel_SVC, "unknown GetSystemInfo type=0 region: param={}", param);

View File

@ -5,7 +5,6 @@
#include <algorithm> #include <algorithm>
#include "common/assert.h" #include "common/assert.h"
#include "common/logging/log.h" #include "common/logging/log.h"
#include "core/hle/config_mem.h"
#include "core/hle/kernel/errors.h" #include "core/hle/kernel/errors.h"
#include "core/hle/kernel/kernel.h" #include "core/hle/kernel/kernel.h"
#include "core/hle/kernel/memory.h" #include "core/hle/kernel/memory.h"
@ -13,7 +12,6 @@
#include "core/hle/kernel/resource_limit.h" #include "core/hle/kernel/resource_limit.h"
#include "core/hle/kernel/thread.h" #include "core/hle/kernel/thread.h"
#include "core/hle/kernel/timer.h" #include "core/hle/kernel/timer.h"
#include "core/hle/shared_page.h"
namespace Kernel { namespace Kernel {

View File

@ -11,6 +11,7 @@
#include "core/hle/ipc_helpers.h" #include "core/hle/ipc_helpers.h"
#include "core/hle/kernel/handle_table.h" #include "core/hle/kernel/handle_table.h"
#include "core/hle/kernel/shared_memory.h" #include "core/hle/kernel/shared_memory.h"
#include "core/hle/kernel/shared_page.h"
#include "core/hle/result.h" #include "core/hle/result.h"
#include "core/hle/service/gsp/gsp_gpu.h" #include "core/hle/service/gsp/gsp_gpu.h"
#include "core/hw/gpu.h" #include "core/hw/gpu.h"
@ -731,7 +732,7 @@ void GSP_GPU::SetLedForceOff(Kernel::HLERequestContext& ctx) {
u8 state = rp.Pop<u8>(); u8 state = rp.Pop<u8>();
system.GetSharedPageHandler()->Set3DLed(state); system.Kernel().GetSharedPageHandler().Set3DLed(state);
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(RESULT_SUCCESS); rb.Push(RESULT_SUCCESS);

View File

@ -20,6 +20,7 @@
#include "core/hle/ipc_helpers.h" #include "core/hle/ipc_helpers.h"
#include "core/hle/kernel/event.h" #include "core/hle/kernel/event.h"
#include "core/hle/kernel/shared_memory.h" #include "core/hle/kernel/shared_memory.h"
#include "core/hle/kernel/shared_page.h"
#include "core/hle/lock.h" #include "core/hle/lock.h"
#include "core/hle/result.h" #include "core/hle/result.h"
#include "core/hle/service/nwm/nwm_uds.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.Kernel().GetSharedPageHandler().SetMacAddress(mac);
system.GetSharedPageHandler()->SetWifiLinkLevel(SharedPage::WifiLinkLevel::BEST); system.Kernel().GetSharedPageHandler().SetWifiLinkLevel(SharedPage::WifiLinkLevel::BEST);
} }
NWM_UDS::~NWM_UDS() { NWM_UDS::~NWM_UDS() {

View File

@ -61,8 +61,6 @@ using Kernel::SharedPtr;
namespace Service { namespace Service {
std::unordered_map<std::string, SharedPtr<ClientPort>> g_kernel_named_ports;
const std::array<ServiceModuleInfo, 40> service_module_map{ const std::array<ServiceModuleInfo, 40> service_module_map{
{{"FS", 0x00040130'00001102, FS::InstallInterfaces}, {{"FS", 0x00040130'00001102, FS::InstallInterfaces},
{"PM", 0x00040130'00001202, PM::InstallInterfaces}, {"PM", 0x00040130'00001202, PM::InstallInterfaces},
@ -149,7 +147,7 @@ void ServiceFrameworkBase::InstallAsNamedPort(Kernel::KernelSystem& kernel) {
SharedPtr<ClientPort> client_port; SharedPtr<ClientPort> client_port;
std::tie(server_port, client_port) = kernel.CreatePortPair(max_sessions, service_name); std::tie(server_port, client_port) = kernel.CreatePortPair(max_sessions, service_name);
server_port->SetHleHandler(shared_from_this()); server_port->SetHleHandler(shared_from_this());
AddNamedPort(service_name, std::move(client_port)); kernel.AddNamedPort(service_name, std::move(client_port));
} }
void ServiceFrameworkBase::RegisterHandlersBase(const FunctionInfoBase* functions, std::size_t n) { void ServiceFrameworkBase::RegisterHandlersBase(const FunctionInfoBase* functions, std::size_t n) {
@ -214,11 +212,6 @@ void ServiceFrameworkBase::HandleSyncRequest(SharedPtr<ServerSession> server_ses
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
// Module interface // Module interface
// TODO(yuriks): Move to kernel
void AddNamedPort(std::string name, SharedPtr<ClientPort> port) {
g_kernel_named_ports.emplace(std::move(name), std::move(port));
}
static bool AttemptLLE(const ServiceModuleInfo& service_module) { static bool AttemptLLE(const ServiceModuleInfo& service_module) {
if (!Settings::values.lle_modules.at(service_module.name)) if (!Settings::values.lle_modules.at(service_module.name))
return false; return false;
@ -247,10 +240,4 @@ void Init(Core::System& core) {
LOG_DEBUG(Service, "initialized OK"); LOG_DEBUG(Service, "initialized OK");
} }
/// Shutdown ServiceManager
void Shutdown() {
g_kernel_named_ports.clear();
LOG_DEBUG(Service, "shutdown OK");
}
} // namespace Service } // namespace Service

View File

@ -8,7 +8,6 @@
#include <cstddef> #include <cstddef>
#include <functional> #include <functional>
#include <string> #include <string>
#include <unordered_map>
#include <boost/container/flat_map.hpp> #include <boost/container/flat_map.hpp>
#include "common/common_types.h" #include "common/common_types.h"
#include "core/hle/kernel/hle_ipc.h" #include "core/hle/kernel/hle_ipc.h"
@ -187,12 +186,6 @@ private:
/// Initialize ServiceManager /// Initialize ServiceManager
void Init(Core::System& system); void Init(Core::System& system);
/// Shutdown ServiceManager
void Shutdown();
/// Map of named ports managed by the kernel, which can be retrieved using the ConnectToPort SVC.
extern std::unordered_map<std::string, Kernel::SharedPtr<Kernel::ClientPort>> g_kernel_named_ports;
struct ServiceModuleInfo { struct ServiceModuleInfo {
std::string name; std::string name;
u64 title_id; u64 title_id;
@ -201,7 +194,4 @@ struct ServiceModuleInfo {
extern const std::array<ServiceModuleInfo, 40> service_module_map; extern const std::array<ServiceModuleInfo, 40> service_module_map;
/// Adds a port to the named port table
void AddNamedPort(std::string name, Kernel::SharedPtr<Kernel::ClientPort> port);
} // namespace Service } // namespace Service

View File

@ -305,7 +305,7 @@ u8* GetPhysicalPointer(PAddr address) {
target_pointer = Core::DSP().GetDspMemory().data() + offset_into_region; target_pointer = Core::DSP().GetDspMemory().data() + offset_into_region;
break; break;
case FCRAM_PADDR: 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 && if (offset_into_region >= region.base &&
offset_into_region < region.base + region.size) { offset_into_region < region.base + region.size) {
target_pointer = target_pointer =

View File

@ -6,7 +6,7 @@
#include "core/core_timing.h" #include "core/core_timing.h"
#include "core/hle/kernel/memory.h" #include "core/hle/kernel/memory.h"
#include "core/hle/kernel/process.h" #include "core/hle/kernel/process.h"
#include "core/hle/shared_page.h" #include "core/hle/kernel/shared_page.h"
#include "core/memory.h" #include "core/memory.h"
TEST_CASE("Memory::IsValidVirtualAddress", "[core][memory]") { TEST_CASE("Memory::IsValidVirtualAddress", "[core][memory]") {
@ -25,7 +25,7 @@ TEST_CASE("Memory::IsValidVirtualAddress", "[core][memory]") {
SECTION("CONFIG_MEMORY_VADDR and SHARED_PAGE_VADDR should be valid after mapping them") { SECTION("CONFIG_MEMORY_VADDR and SHARED_PAGE_VADDR should be valid after mapping them") {
auto process = kernel.CreateProcess(kernel.CreateCodeSet("", 0)); auto process = kernel.CreateProcess(kernel.CreateCodeSet("", 0));
Kernel::MapSharedPages(process->vm_manager); kernel.MapSharedPages(process->vm_manager);
CHECK(Memory::IsValidVirtualAddress(*process, Memory::CONFIG_MEMORY_VADDR) == true); CHECK(Memory::IsValidVirtualAddress(*process, Memory::CONFIG_MEMORY_VADDR) == true);
CHECK(Memory::IsValidVirtualAddress(*process, Memory::SHARED_PAGE_VADDR) == true); CHECK(Memory::IsValidVirtualAddress(*process, Memory::SHARED_PAGE_VADDR) == true);
} }
@ -47,7 +47,7 @@ TEST_CASE("Memory::IsValidVirtualAddress", "[core][memory]") {
SECTION("Unmapping a VAddr should make it invalid") { SECTION("Unmapping a VAddr should make it invalid") {
auto process = kernel.CreateProcess(kernel.CreateCodeSet("", 0)); auto process = kernel.CreateProcess(kernel.CreateCodeSet("", 0));
Kernel::MapSharedPages(process->vm_manager); kernel.MapSharedPages(process->vm_manager);
process->vm_manager.UnmapRange(Memory::CONFIG_MEMORY_VADDR, Memory::CONFIG_MEMORY_SIZE); process->vm_manager.UnmapRange(Memory::CONFIG_MEMORY_VADDR, Memory::CONFIG_MEMORY_SIZE);
CHECK(Memory::IsValidVirtualAddress(*process, Memory::CONFIG_MEMORY_VADDR) == false); CHECK(Memory::IsValidVirtualAddress(*process, Memory::CONFIG_MEMORY_VADDR) == false);
} }