From 1a954b2a596fdfd4fc4b5feb9b43c8147de4cc7f Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 26 Nov 2020 15:19:08 -0500 Subject: service: Eliminate usages of the global system instance Completely removes all usages of the global system instance within the services code by passing in the using system instance to the services. --- src/core/hle/service/spl/csrng.cpp | 3 ++- src/core/hle/service/spl/csrng.h | 6 +++++- src/core/hle/service/spl/module.cpp | 11 ++++++----- src/core/hle/service/spl/module.h | 9 +++++++-- src/core/hle/service/spl/spl.cpp | 3 ++- src/core/hle/service/spl/spl.h | 6 +++++- 6 files changed, 27 insertions(+), 11 deletions(-) (limited to 'src/core/hle/service/spl') diff --git a/src/core/hle/service/spl/csrng.cpp b/src/core/hle/service/spl/csrng.cpp index 674928798..1beca417c 100644 --- a/src/core/hle/service/spl/csrng.cpp +++ b/src/core/hle/service/spl/csrng.cpp @@ -6,7 +6,8 @@ namespace Service::SPL { -CSRNG::CSRNG(std::shared_ptr module) : Module::Interface(std::move(module), "csrng") { +CSRNG::CSRNG(Core::System& system_, std::shared_ptr module_) + : Interface(system_, std::move(module_), "csrng") { static const FunctionInfo functions[] = { {0, &CSRNG::GetRandomBytes, "GetRandomBytes"}, }; diff --git a/src/core/hle/service/spl/csrng.h b/src/core/hle/service/spl/csrng.h index 764d5ceb0..5c0bd2199 100644 --- a/src/core/hle/service/spl/csrng.h +++ b/src/core/hle/service/spl/csrng.h @@ -6,11 +6,15 @@ #include "core/hle/service/spl/module.h" +namespace Core { +class System; +} + namespace Service::SPL { class CSRNG final : public Module::Interface { public: - explicit CSRNG(std::shared_ptr module); + explicit CSRNG(Core::System& system_, std::shared_ptr module_); ~CSRNG() override; }; diff --git a/src/core/hle/service/spl/module.cpp b/src/core/hle/service/spl/module.cpp index 865ed3b91..dea6b0fe0 100644 --- a/src/core/hle/service/spl/module.cpp +++ b/src/core/hle/service/spl/module.cpp @@ -17,8 +17,9 @@ namespace Service::SPL { -Module::Interface::Interface(std::shared_ptr module, const char* name) - : ServiceFramework(name), module(std::move(module)), +Module::Interface::Interface(Core::System& system_, std::shared_ptr module_, + const char* name) + : ServiceFramework{system_, name}, module{std::move(module_)}, rng(Settings::values.rng_seed.GetValue().value_or(std::time(nullptr))) {} Module::Interface::~Interface() = default; @@ -38,10 +39,10 @@ void Module::Interface::GetRandomBytes(Kernel::HLERequestContext& ctx) { rb.Push(RESULT_SUCCESS); } -void InstallInterfaces(SM::ServiceManager& service_manager) { +void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system) { auto module = std::make_shared(); - std::make_shared(module)->InstallAsService(service_manager); - std::make_shared(module)->InstallAsService(service_manager); + std::make_shared(system, module)->InstallAsService(service_manager); + std::make_shared(system, module)->InstallAsService(service_manager); } } // namespace Service::SPL diff --git a/src/core/hle/service/spl/module.h b/src/core/hle/service/spl/module.h index afa1f0295..71855c1bf 100644 --- a/src/core/hle/service/spl/module.h +++ b/src/core/hle/service/spl/module.h @@ -7,13 +7,18 @@ #include #include "core/hle/service/service.h" +namespace Core { +class System; +} + namespace Service::SPL { class Module final { public: class Interface : public ServiceFramework { public: - explicit Interface(std::shared_ptr module, const char* name); + explicit Interface(Core::System& system_, std::shared_ptr module_, + const char* name); ~Interface() override; void GetRandomBytes(Kernel::HLERequestContext& ctx); @@ -27,6 +32,6 @@ public: }; /// Registers all SPL services with the specified service manager. -void InstallInterfaces(SM::ServiceManager& service_manager); +void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system); } // namespace Service::SPL diff --git a/src/core/hle/service/spl/spl.cpp b/src/core/hle/service/spl/spl.cpp index 773551464..3fabc2c79 100644 --- a/src/core/hle/service/spl/spl.cpp +++ b/src/core/hle/service/spl/spl.cpp @@ -6,7 +6,8 @@ namespace Service::SPL { -SPL::SPL(std::shared_ptr module) : Module::Interface(std::move(module), "spl:") { +SPL::SPL(Core::System& system_, std::shared_ptr module_) + : Interface(system_, std::move(module_), "spl:") { static const FunctionInfo functions[] = { {0, nullptr, "GetConfig"}, {1, nullptr, "ModularExponentiate"}, diff --git a/src/core/hle/service/spl/spl.h b/src/core/hle/service/spl/spl.h index 3637d1623..d27d16b86 100644 --- a/src/core/hle/service/spl/spl.h +++ b/src/core/hle/service/spl/spl.h @@ -6,11 +6,15 @@ #include "core/hle/service/spl/module.h" +namespace Core { +class System; +} + namespace Service::SPL { class SPL final : public Module::Interface { public: - explicit SPL(std::shared_ptr module); + explicit SPL(Core::System& system_, std::shared_ptr module_); ~SPL() override; }; -- cgit v1.2.3