diff --git a/src/core/core.cpp b/src/core/core.cpp index 9e8936728a..959fe7719d 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -22,6 +22,7 @@ #include "core/device_memory.h" #include "core/file_sys/bis_factory.h" #include "core/file_sys/fs_filesystem.h" +#include "core/file_sys/fssrv/fssrv_program_registry_impl.h" #include "core/file_sys/patch_manager.h" #include "core/file_sys/registered_cache.h" #include "core/file_sys/romfs_factory.h" @@ -137,8 +138,9 @@ FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs, struct System::Impl { explicit Impl(System& system) - : kernel{system}, fs_controller{system}, hid_core{}, room_network{}, cpu_manager{system}, - reporter{system}, applet_manager{system}, frontend_applets{system}, profile_manager{} {} + : kernel{system}, fs_controller{system}, program_registry{system}, hid_core{}, + room_network{}, cpu_manager{system}, reporter{system}, applet_manager{system}, + frontend_applets{system}, profile_manager{} {} void Initialize(System& system) { device_memory = std::make_unique(); @@ -470,6 +472,7 @@ struct System::Impl { services.reset(); service_manager.reset(); fs_controller.Reset(); + program_registry.Reset(); cheat_engine.reset(); telemetry_session.reset(); core_timing.ClearPendingEvents(); @@ -556,6 +559,7 @@ struct System::Impl { /// ContentProviderUnion instance std::unique_ptr content_provider; Service::FileSystem::FileSystemController fs_controller; + FileSys::FsSrv::ProgramRegistryImpl program_registry; /// AppLoader used to load the current executing application std::unique_ptr app_loader; std::unique_ptr gpu_core; @@ -939,6 +943,14 @@ void System::ClearContentProvider(FileSys::ContentProviderUnionSlot slot) { impl->content_provider->ClearSlot(slot); } +FileSys::FsSrv::ProgramRegistryImpl& System::GetProgramRegistry() { + return impl->program_registry; +} + +const FileSys::FsSrv::ProgramRegistryImpl& System::GetProgramRegistry() const { + return impl->program_registry; +} + const Reporter& System::GetReporter() const { return impl->reporter; } diff --git a/src/core/core.h b/src/core/core.h index 90826bd3a1..d9ff1e3b7a 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -24,6 +24,10 @@ class ContentProvider; class ContentProviderUnion; enum class ContentProviderUnionSlot; class VfsFilesystem; + +namespace FsSrv { +class ProgramRegistryImpl; +} } // namespace FileSys namespace Kernel { @@ -373,6 +377,9 @@ public: void ClearContentProvider(FileSys::ContentProviderUnionSlot slot); + [[nodiscard]] FileSys::FsSrv::ProgramRegistryImpl& GetProgramRegistry(); + [[nodiscard]] const FileSys::FsSrv::ProgramRegistryImpl& GetProgramRegistry() const; + [[nodiscard]] const Reporter& GetReporter() const; [[nodiscard]] Service::Glue::ARPManager& GetARPManager(); diff --git a/src/core/file_sys/fssrv/fssrv_program_registry_impl.cpp b/src/core/file_sys/fssrv/fssrv_program_registry_impl.cpp index 9073d08db0..1bf5055da3 100644 --- a/src/core/file_sys/fssrv/fssrv_program_registry_impl.cpp +++ b/src/core/file_sys/fssrv/fssrv_program_registry_impl.cpp @@ -9,35 +9,21 @@ namespace FileSys::FsSrv { -namespace { -constinit ProgramRegistryServiceImpl* g_impl = nullptr; -} - // TODO: Move this to a common types file constexpr u64 InvalidProcessIdProgramRegistry = 0xffffffffffffffffULL; ProgramRegistryImpl::ProgramRegistryImpl(Core::System& system_) - : m_process_id(InvalidProcessIdProgramRegistry), system{system_} {} + : m_process_id(InvalidProcessIdProgramRegistry), system{system_}, + service_impl{std::make_unique( + system, ProgramRegistryServiceImpl::Configuration{})} {} ProgramRegistryImpl::~ProgramRegistryImpl() {} -void ProgramRegistryImpl::Initialize(ProgramRegistryServiceImpl* service) { - // Check pre-conditions - ASSERT(service != nullptr); - ASSERT(g_impl == nullptr); - - // Set the global service - g_impl = service; -} - Result ProgramRegistryImpl::RegisterProgram(u64 process_id, u64 program_id, u8 storage_id, const InBuffer data, s64 data_size, const InBuffer desc, s64 desc_size) { - // Check pre-conditions - ASSERT(g_impl != nullptr); - // Check that we're allowed to register R_UNLESS(FsSrv::Impl::IsInitialProgram(system, m_process_id), ResultPermissionDenied); @@ -46,19 +32,16 @@ Result ProgramRegistryImpl::RegisterProgram(u64 process_id, u64 program_id, u8 s R_UNLESS(desc.size() >= static_cast(desc_size), ResultInvalidSize); // Register the program - R_RETURN(g_impl->RegisterProgramInfo(process_id, program_id, storage_id, data.data(), data_size, - desc.data(), desc_size)); + R_RETURN(service_impl->RegisterProgramInfo(process_id, program_id, storage_id, data.data(), + data_size, desc.data(), desc_size)); } Result ProgramRegistryImpl::UnregisterProgram(u64 process_id) { - // Check pre-conditions - ASSERT(g_impl != nullptr); - // Check that we're allowed to register R_UNLESS(FsSrv::Impl::IsInitialProgram(system, m_process_id), ResultPermissionDenied); // Unregister the program - R_RETURN(g_impl->UnregisterProgramInfo(process_id)); + R_RETURN(service_impl->UnregisterProgramInfo(process_id)); } Result ProgramRegistryImpl::SetCurrentProcess(const Service::ClientProcessId& client_pid) { @@ -74,4 +57,9 @@ Result ProgramRegistryImpl::SetEnabledProgramVerification(bool enabled) { R_THROW(ResultNotImplemented); } +void ProgramRegistryImpl::Reset() { + service_impl = std::make_unique( + system, ProgramRegistryServiceImpl::Configuration{}); +} + } // namespace FileSys::FsSrv diff --git a/src/core/file_sys/fssrv/fssrv_program_registry_impl.h b/src/core/file_sys/fssrv/fssrv_program_registry_impl.h index c01d374285..dba7b2531a 100644 --- a/src/core/file_sys/fssrv/fssrv_program_registry_impl.h +++ b/src/core/file_sys/fssrv/fssrv_program_registry_impl.h @@ -29,8 +29,6 @@ public: ProgramRegistryImpl(Core::System& system_); ~ProgramRegistryImpl(); - static void Initialize(ProgramRegistryServiceImpl* service); - Result RegisterProgram(u64 process_id, u64 program_id, u8 storage_id, const InBuffer data, s64 data_size, const InBuffer desc, s64 desc_size); @@ -38,9 +36,13 @@ public: Result SetCurrentProcess(const Service::ClientProcessId& client_pid); Result SetEnabledProgramVerification(bool enabled); + void Reset(); + private: u64 m_process_id; Core::System& system; + + std::unique_ptr service_impl; }; } // namespace FileSys::FsSrv diff --git a/src/core/file_sys/fssrv/fssrv_program_registry_service.cpp b/src/core/file_sys/fssrv/fssrv_program_registry_service.cpp index 151eb5740c..f757ffcf3f 100644 --- a/src/core/file_sys/fssrv/fssrv_program_registry_service.cpp +++ b/src/core/file_sys/fssrv/fssrv_program_registry_service.cpp @@ -3,9 +3,7 @@ #include "core/core.h" #include "core/file_sys/fssrv/fssrv_program_registry_service.h" -#include "core/file_sys/fssrv/impl/fssrv_program_index_map_info_manager.h" #include "core/file_sys/fssrv/impl/fssrv_program_info.h" -#include "core/file_sys/fssrv/impl/fssrv_program_registry_manager.h" namespace FileSys::FsSrv { diff --git a/src/core/file_sys/fssrv/fssrv_program_registry_service.h b/src/core/file_sys/fssrv/fssrv_program_registry_service.h index 69243eb731..50bcec0933 100644 --- a/src/core/file_sys/fssrv/fssrv_program_registry_service.h +++ b/src/core/file_sys/fssrv/fssrv_program_registry_service.h @@ -5,6 +5,8 @@ #include #include "core/file_sys/fs_program_index_map_info.h" +#include "core/file_sys/fssrv/impl/fssrv_program_index_map_info_manager.h" +#include "core/file_sys/fssrv/impl/fssrv_program_registry_manager.h" #include "core/hle/result.h" namespace Core { @@ -15,8 +17,6 @@ namespace FileSys::FsSrv { namespace Impl { class ProgramInfo; -class ProgramRegistryManager; -class ProgramIndexMapInfoManager; } // namespace Impl class ProgramRegistryServiceImpl { diff --git a/src/core/hle/service/filesystem/fsp/fs_i_program_registry.cpp b/src/core/hle/service/filesystem/fsp/fs_i_program_registry.cpp index bc5a8d325b..0226164f63 100644 --- a/src/core/hle/service/filesystem/fsp/fs_i_program_registry.cpp +++ b/src/core/hle/service/filesystem/fsp/fs_i_program_registry.cpp @@ -7,7 +7,7 @@ namespace Service::FileSystem { IProgramRegistry::IProgramRegistry(Core::System& system_) - : ServiceFramework{system_, "fsp:pr"}, registry{system_} { + : ServiceFramework{system_, "fsp:pr"}, registry{system_.GetProgramRegistry()} { // clang-format off static const FunctionInfo functions[] = { {0, C<&IProgramRegistry::RegisterProgram>, "RegisterProgram"}, diff --git a/src/core/hle/service/filesystem/fsp/fs_i_program_registry.h b/src/core/hle/service/filesystem/fsp/fs_i_program_registry.h index 0f80b91151..bc6f0f6baa 100644 --- a/src/core/hle/service/filesystem/fsp/fs_i_program_registry.h +++ b/src/core/hle/service/filesystem/fsp/fs_i_program_registry.h @@ -30,7 +30,7 @@ public: Result SetEnabledProgramVerification(bool enabled); private: - FileSys::FsSrv::ProgramRegistryImpl registry; + FileSys::FsSrv::ProgramRegistryImpl& registry; }; } // namespace Service::FileSystem