diff options
Diffstat (limited to 'src/core/hle')
53 files changed, 536 insertions, 407 deletions
diff --git a/src/core/hle/kernel/handle_table.cpp b/src/core/hle/kernel/handle_table.cpp index bdfaa977f..2cc5d536b 100644 --- a/src/core/hle/kernel/handle_table.cpp +++ b/src/core/hle/kernel/handle_table.cpp @@ -103,7 +103,7 @@ SharedPtr<Object> HandleTable::GetGeneric(Handle handle) const { if (handle == CurrentThread) { return GetCurrentThread(); } else if (handle == CurrentProcess) { - return Core::CurrentProcess(); + return Core::System::GetInstance().CurrentProcess(); } if (!IsValid(handle)) { diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index 34409e0c3..3a32d5b41 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp @@ -1140,14 +1140,15 @@ void IApplicationFunctions::PopLaunchParameter(Kernel::HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called, kind={:08X}", static_cast<u8>(kind)); if (kind == LaunchParameterKind::ApplicationSpecific && !launch_popped_application_specific) { - const auto backend = BCAT::CreateBackendFromSettings( - [this](u64 tid) { return system.GetFileSystemController().GetBCATDirectory(tid); }); - const auto build_id_full = Core::System::GetInstance().GetCurrentProcessBuildID(); + const auto backend = BCAT::CreateBackendFromSettings(system, [this](u64 tid) { + return system.GetFileSystemController().GetBCATDirectory(tid); + }); + const auto build_id_full = system.GetCurrentProcessBuildID(); u64 build_id{}; std::memcpy(&build_id, build_id_full.data(), sizeof(u64)); const auto data = - backend->GetLaunchParameter({Core::CurrentProcess()->GetTitleID(), build_id}); + backend->GetLaunchParameter({system.CurrentProcess()->GetTitleID(), build_id}); if (data.has_value()) { IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -1200,7 +1201,7 @@ void IApplicationFunctions::EnsureSaveData(Kernel::HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called, uid={:016X}{:016X}", user_id[1], user_id[0]); FileSys::SaveDataDescriptor descriptor{}; - descriptor.title_id = Core::CurrentProcess()->GetTitleID(); + descriptor.title_id = system.CurrentProcess()->GetTitleID(); descriptor.user_id = user_id; descriptor.type = FileSys::SaveDataType::SaveData; const auto res = system.GetFileSystemController().CreateSaveData( diff --git a/src/core/hle/service/am/am.h b/src/core/hle/service/am/am.h index 9169eb2bd..ccd053c13 100644 --- a/src/core/hle/service/am/am.h +++ b/src/core/hle/service/am/am.h @@ -147,6 +147,7 @@ private: void GetAccumulatedSuspendedTickValue(Kernel::HLERequestContext& ctx); void GetAccumulatedSuspendedTickChangedEvent(Kernel::HLERequestContext& ctx); + Core::System& system; std::shared_ptr<NVFlinger::NVFlinger> nvflinger; Kernel::EventPair launchable_event; Kernel::EventPair accumulated_suspended_tick_changed_event; @@ -154,8 +155,6 @@ private: u32 idle_time_detection_extension = 0; u64 num_fatal_sections_entered = 0; bool is_auto_sleep_disabled = false; - - Core::System& system; }; class ICommonStateGetter final : public ServiceFramework<ICommonStateGetter> { diff --git a/src/core/hle/service/apm/controller.cpp b/src/core/hle/service/apm/controller.cpp index 4376612eb..073d0f6fa 100644 --- a/src/core/hle/service/apm/controller.cpp +++ b/src/core/hle/service/apm/controller.cpp @@ -13,7 +13,7 @@ constexpr PerformanceConfiguration DEFAULT_PERFORMANCE_CONFIGURATION = PerformanceConfiguration::Config7; Controller::Controller(Core::Timing::CoreTiming& core_timing) - : core_timing(core_timing), configs{ + : core_timing{core_timing}, configs{ {PerformanceMode::Handheld, DEFAULT_PERFORMANCE_CONFIGURATION}, {PerformanceMode::Docked, DEFAULT_PERFORMANCE_CONFIGURATION}, } {} @@ -63,6 +63,7 @@ PerformanceConfiguration Controller::GetCurrentPerformanceConfiguration(Performa void Controller::SetClockSpeed(u32 mhz) { LOG_INFO(Service_APM, "called, mhz={:08X}", mhz); // TODO(DarkLordZach): Actually signal core_timing to change clock speed. + // TODO(Rodrigo): Remove [[maybe_unused]] when core_timing is used. } } // namespace Service::APM diff --git a/src/core/hle/service/apm/controller.h b/src/core/hle/service/apm/controller.h index 8ac80eaea..454caa6eb 100644 --- a/src/core/hle/service/apm/controller.h +++ b/src/core/hle/service/apm/controller.h @@ -50,7 +50,7 @@ enum class PerformanceMode : u8 { // system during times of high load -- this simply maps to different PerformanceConfigs to use. class Controller { public: - Controller(Core::Timing::CoreTiming& core_timing); + explicit Controller(Core::Timing::CoreTiming& core_timing); ~Controller(); void SetPerformanceConfiguration(PerformanceMode mode, PerformanceConfiguration config); @@ -62,9 +62,9 @@ public: private: void SetClockSpeed(u32 mhz); - std::map<PerformanceMode, PerformanceConfiguration> configs; + [[maybe_unused]] Core::Timing::CoreTiming& core_timing; - Core::Timing::CoreTiming& core_timing; + std::map<PerformanceMode, PerformanceConfiguration> configs; }; } // namespace Service::APM diff --git a/src/core/hle/service/audio/audout_u.cpp b/src/core/hle/service/audio/audout_u.cpp index fb84a8f13..9afefb5c6 100644 --- a/src/core/hle/service/audio/audout_u.cpp +++ b/src/core/hle/service/audio/audout_u.cpp @@ -205,7 +205,7 @@ private: AudioCore::StreamPtr stream; std::string device_name; - AudoutParams audio_params{}; + [[maybe_unused]] AudoutParams audio_params {}; /// This is the event handle used to check if the audio buffer was released Kernel::EventPair buffer_event; diff --git a/src/core/hle/service/bcat/backend/backend.cpp b/src/core/hle/service/bcat/backend/backend.cpp index 9b677debe..b86fda29a 100644 --- a/src/core/hle/service/bcat/backend/backend.cpp +++ b/src/core/hle/service/bcat/backend/backend.cpp @@ -10,13 +10,14 @@ namespace Service::BCAT { -ProgressServiceBackend::ProgressServiceBackend(std::string event_name) : impl{} { - auto& kernel{Core::System::GetInstance().Kernel()}; +ProgressServiceBackend::ProgressServiceBackend(Kernel::KernelCore& kernel, + std::string_view event_name) { event = Kernel::WritableEvent::CreateEventPair( - kernel, Kernel::ResetType::Automatic, "ProgressServiceBackend:UpdateEvent:" + event_name); + kernel, Kernel::ResetType::Automatic, + std::string("ProgressServiceBackend:UpdateEvent:").append(event_name)); } -Kernel::SharedPtr<Kernel::ReadableEvent> ProgressServiceBackend::GetEvent() { +Kernel::SharedPtr<Kernel::ReadableEvent> ProgressServiceBackend::GetEvent() const { return event.readable; } @@ -95,7 +96,7 @@ Backend::Backend(DirectoryGetter getter) : dir_getter(std::move(getter)) {} Backend::~Backend() = default; -NullBackend::NullBackend(const DirectoryGetter& getter) : Backend(std::move(getter)) {} +NullBackend::NullBackend(DirectoryGetter getter) : Backend(std::move(getter)) {} NullBackend::~NullBackend() = default; diff --git a/src/core/hle/service/bcat/backend/backend.h b/src/core/hle/service/bcat/backend/backend.h index 3f5d8b5dd..ea4b16ad0 100644 --- a/src/core/hle/service/bcat/backend/backend.h +++ b/src/core/hle/service/bcat/backend/backend.h @@ -6,12 +6,23 @@ #include <functional> #include <optional> +#include <string> +#include <string_view> + #include "common/common_types.h" #include "core/file_sys/vfs_types.h" #include "core/hle/kernel/readable_event.h" #include "core/hle/kernel/writable_event.h" #include "core/hle/result.h" +namespace Core { +class System; +} + +namespace Kernel { +class KernelCore; +} + namespace Service::BCAT { struct DeliveryCacheProgressImpl; @@ -85,14 +96,14 @@ public: void FinishDownload(ResultCode result); private: - explicit ProgressServiceBackend(std::string event_name); + explicit ProgressServiceBackend(Kernel::KernelCore& kernel, std::string_view event_name); - Kernel::SharedPtr<Kernel::ReadableEvent> GetEvent(); + Kernel::SharedPtr<Kernel::ReadableEvent> GetEvent() const; DeliveryCacheProgressImpl& GetImpl(); void SignalUpdate() const; - DeliveryCacheProgressImpl impl; + DeliveryCacheProgressImpl impl{}; Kernel::EventPair event; bool need_hle_lock = false; }; @@ -128,7 +139,7 @@ protected: // A backend of BCAT that provides no operation. class NullBackend : public Backend { public: - explicit NullBackend(const DirectoryGetter& getter); + explicit NullBackend(DirectoryGetter getter); ~NullBackend() override; bool Synchronize(TitleIDVersion title, ProgressServiceBackend& progress) override; @@ -142,6 +153,6 @@ public: std::optional<std::vector<u8>> GetLaunchParameter(TitleIDVersion title) override; }; -std::unique_ptr<Backend> CreateBackendFromSettings(DirectoryGetter getter); +std::unique_ptr<Backend> CreateBackendFromSettings(Core::System& system, DirectoryGetter getter); } // namespace Service::BCAT diff --git a/src/core/hle/service/bcat/backend/boxcat.cpp b/src/core/hle/service/bcat/backend/boxcat.cpp index e6ee0810b..918159e11 100644 --- a/src/core/hle/service/bcat/backend/boxcat.cpp +++ b/src/core/hle/service/bcat/backend/boxcat.cpp @@ -88,7 +88,7 @@ std::ostream& operator<<(std::ostream& os, DownloadResult result) { constexpr u32 PORT = 443; constexpr u32 TIMEOUT_SECONDS = 30; -constexpr u64 VFS_COPY_BLOCK_SIZE = 1ull << 24; // 4MB +[[maybe_unused]] constexpr u64 VFS_COPY_BLOCK_SIZE = 1ULL << 24; // 4MB namespace { @@ -104,14 +104,15 @@ std::string GetZIPFilePath(u64 title_id) { // If the error is something the user should know about (build ID mismatch, bad client version), // display an error. -void HandleDownloadDisplayResult(DownloadResult res) { +void HandleDownloadDisplayResult(const AM::Applets::AppletManager& applet_manager, + DownloadResult res) { if (res == DownloadResult::Success || res == DownloadResult::NoResponse || res == DownloadResult::GeneralWebError || res == DownloadResult::GeneralFSError || res == DownloadResult::NoMatchTitleId || res == DownloadResult::InvalidContentType) { return; } - const auto& frontend{Core::System::GetInstance().GetAppletManager().GetAppletFrontendSet()}; + const auto& frontend{applet_manager.GetAppletFrontendSet()}; frontend.error->ShowCustomErrorText( ResultCode(-1), "There was an error while attempting to use Boxcat.", DOWNLOAD_RESULT_LOG_MESSAGES[static_cast<std::size_t>(res)], [] {}); @@ -264,12 +265,13 @@ private: u64 build_id; }; -Boxcat::Boxcat(DirectoryGetter getter) : Backend(std::move(getter)) {} +Boxcat::Boxcat(AM::Applets::AppletManager& applet_manager_, DirectoryGetter getter) + : Backend(std::move(getter)), applet_manager{applet_manager_} {} Boxcat::~Boxcat() = default; -void SynchronizeInternal(DirectoryGetter dir_getter, TitleIDVersion title, - ProgressServiceBackend& progress, +void SynchronizeInternal(AM::Applets::AppletManager& applet_manager, DirectoryGetter dir_getter, + TitleIDVersion title, ProgressServiceBackend& progress, std::optional<std::string> dir_name = {}) { progress.SetNeedHLELock(true); @@ -295,7 +297,7 @@ void SynchronizeInternal(DirectoryGetter dir_getter, TitleIDVersion title, FileUtil::Delete(zip_path); } - HandleDownloadDisplayResult(res); + HandleDownloadDisplayResult(applet_manager, res); progress.FinishDownload(ERROR_GENERAL_BCAT_FAILURE); return; } @@ -364,17 +366,24 @@ void SynchronizeInternal(DirectoryGetter dir_getter, TitleIDVersion title, bool Boxcat::Synchronize(TitleIDVersion title, ProgressServiceBackend& progress) { is_syncing.exchange(true); - std::thread([this, title, &progress] { SynchronizeInternal(dir_getter, title, progress); }) + + std::thread([this, title, &progress] { + SynchronizeInternal(applet_manager, dir_getter, title, progress); + }) .detach(); + return true; } bool Boxcat::SynchronizeDirectory(TitleIDVersion title, std::string name, ProgressServiceBackend& progress) { is_syncing.exchange(true); - std::thread( - [this, title, name, &progress] { SynchronizeInternal(dir_getter, title, progress, name); }) + + std::thread([this, title, name, &progress] { + SynchronizeInternal(applet_manager, dir_getter, title, progress, name); + }) .detach(); + return true; } @@ -420,7 +429,7 @@ std::optional<std::vector<u8>> Boxcat::GetLaunchParameter(TitleIDVersion title) FileUtil::Delete(path); } - HandleDownloadDisplayResult(res); + HandleDownloadDisplayResult(applet_manager, res); return std::nullopt; } } @@ -495,7 +504,8 @@ Boxcat::StatusResult Boxcat::GetStatus(std::optional<std::string>& global, } return StatusResult::Success; - } catch (const nlohmann::json::parse_error& e) { + } catch (const nlohmann::json::parse_error& error) { + LOG_ERROR(Service_BCAT, "{}", error.what()); return StatusResult::ParseError; } } diff --git a/src/core/hle/service/bcat/backend/boxcat.h b/src/core/hle/service/bcat/backend/boxcat.h index 601151189..d65b42e58 100644 --- a/src/core/hle/service/bcat/backend/boxcat.h +++ b/src/core/hle/service/bcat/backend/boxcat.h @@ -9,6 +9,10 @@ #include <optional> #include "core/hle/service/bcat/backend/backend.h" +namespace Service::AM::Applets { +class AppletManager; +} + namespace Service::BCAT { struct EventStatus { @@ -20,12 +24,13 @@ struct EventStatus { /// Boxcat is yuzu's custom backend implementation of Nintendo's BCAT service. It is free to use and /// doesn't require a switch or nintendo account. The content is controlled by the yuzu team. class Boxcat final : public Backend { - friend void SynchronizeInternal(DirectoryGetter dir_getter, TitleIDVersion title, + friend void SynchronizeInternal(AM::Applets::AppletManager& applet_manager, + DirectoryGetter dir_getter, TitleIDVersion title, ProgressServiceBackend& progress, std::optional<std::string> dir_name); public: - explicit Boxcat(DirectoryGetter getter); + explicit Boxcat(AM::Applets::AppletManager& applet_manager_, DirectoryGetter getter); ~Boxcat() override; bool Synchronize(TitleIDVersion title, ProgressServiceBackend& progress) override; @@ -53,6 +58,7 @@ private: class Client; std::unique_ptr<Client> client; + AM::Applets::AppletManager& applet_manager; }; } // namespace Service::BCAT diff --git a/src/core/hle/service/bcat/bcat.cpp b/src/core/hle/service/bcat/bcat.cpp index c2f946424..8bb2528c9 100644 --- a/src/core/hle/service/bcat/bcat.cpp +++ b/src/core/hle/service/bcat/bcat.cpp @@ -6,8 +6,9 @@ namespace Service::BCAT { -BCAT::BCAT(std::shared_ptr<Module> module, FileSystem::FileSystemController& fsc, const char* name) - : Module::Interface(std::move(module), fsc, name) { +BCAT::BCAT(Core::System& system, std::shared_ptr<Module> module, + FileSystem::FileSystemController& fsc, const char* name) + : Interface(system, std::move(module), fsc, name) { // clang-format off static const FunctionInfo functions[] = { {0, &BCAT::CreateBcatService, "CreateBcatService"}, diff --git a/src/core/hle/service/bcat/bcat.h b/src/core/hle/service/bcat/bcat.h index 813073658..6354465fc 100644 --- a/src/core/hle/service/bcat/bcat.h +++ b/src/core/hle/service/bcat/bcat.h @@ -6,12 +6,16 @@ #include "core/hle/service/bcat/module.h" +namespace Core { +class System; +} + namespace Service::BCAT { class BCAT final : public Module::Interface { public: - explicit BCAT(std::shared_ptr<Module> module, FileSystem::FileSystemController& fsc, - const char* name); + explicit BCAT(Core::System& system, std::shared_ptr<Module> module, + FileSystem::FileSystemController& fsc, const char* name); ~BCAT() override; }; diff --git a/src/core/hle/service/bcat/module.cpp b/src/core/hle/service/bcat/module.cpp index b3fed56c7..6d9d1527d 100644 --- a/src/core/hle/service/bcat/module.cpp +++ b/src/core/hle/service/bcat/module.cpp @@ -35,8 +35,7 @@ using BCATDigest = std::array<u8, 0x10>; namespace { -u64 GetCurrentBuildID() { - const auto& id = Core::System::GetInstance().GetCurrentProcessBuildID(); +u64 GetCurrentBuildID(const Core::System::CurrentBuildProcessID& id) { u64 out{}; std::memcpy(&out, id.data(), sizeof(u64)); return out; @@ -125,7 +124,12 @@ private: class IBcatService final : public ServiceFramework<IBcatService> { public: - IBcatService(Backend& backend) : ServiceFramework("IBcatService"), backend(backend) { + explicit IBcatService(Core::System& system_, Backend& backend_) + : ServiceFramework("IBcatService"), system{system_}, backend{backend_}, + progress{{ + ProgressServiceBackend{system_.Kernel(), "Normal"}, + ProgressServiceBackend{system_.Kernel(), "Directory"}, + }} { // clang-format off static const FunctionInfo functions[] = { {10100, &IBcatService::RequestSyncDeliveryCache, "RequestSyncDeliveryCache"}, @@ -163,7 +167,8 @@ private: void RequestSyncDeliveryCache(Kernel::HLERequestContext& ctx) { LOG_DEBUG(Service_BCAT, "called"); - backend.Synchronize({Core::CurrentProcess()->GetTitleID(), GetCurrentBuildID()}, + backend.Synchronize({system.CurrentProcess()->GetTitleID(), + GetCurrentBuildID(system.GetCurrentProcessBuildID())}, progress.at(static_cast<std::size_t>(SyncType::Normal))); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; @@ -179,7 +184,8 @@ private: LOG_DEBUG(Service_BCAT, "called, name={}", name); - backend.SynchronizeDirectory({Core::CurrentProcess()->GetTitleID(), GetCurrentBuildID()}, + backend.SynchronizeDirectory({system.CurrentProcess()->GetTitleID(), + GetCurrentBuildID(system.GetCurrentProcessBuildID())}, name, progress.at(static_cast<std::size_t>(SyncType::Directory))); @@ -244,12 +250,10 @@ private: rb.Push(RESULT_SUCCESS); } + Core::System& system; Backend& backend; - std::array<ProgressServiceBackend, static_cast<std::size_t>(SyncType::Count)> progress{ - ProgressServiceBackend{"Normal"}, - ProgressServiceBackend{"Directory"}, - }; + std::array<ProgressServiceBackend, static_cast<std::size_t>(SyncType::Count)> progress; }; void Module::Interface::CreateBcatService(Kernel::HLERequestContext& ctx) { @@ -257,7 +261,7 @@ void Module::Interface::CreateBcatService(Kernel::HLERequestContext& ctx) { IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(RESULT_SUCCESS); - rb.PushIpcInterface<IBcatService>(*backend); + rb.PushIpcInterface<IBcatService>(system, *backend); } class IDeliveryCacheFileService final : public ServiceFramework<IDeliveryCacheFileService> { @@ -451,7 +455,7 @@ private: IPC::ResponseBuilder rb{ctx, 3}; rb.Push(RESULT_SUCCESS); - rb.Push<u32>(write_size * sizeof(DeliveryCacheDirectoryEntry)); + rb.Push(static_cast<u32>(write_size * sizeof(DeliveryCacheDirectoryEntry))); } void GetCount(Kernel::HLERequestContext& ctx) { @@ -468,7 +472,7 @@ private: IPC::ResponseBuilder rb{ctx, 3}; rb.Push(RESULT_SUCCESS); - rb.Push<u32>(files.size()); + rb.Push(static_cast<u32>(files.size())); } FileSys::VirtualDir root; @@ -525,7 +529,7 @@ private: IPC::ResponseBuilder rb{ctx, 3}; rb.Push(RESULT_SUCCESS); - rb.Push<u32>(size); + rb.Push(static_cast<u32>(size)); } FileSys::VirtualDir root; @@ -539,7 +543,7 @@ void Module::Interface::CreateDeliveryCacheStorageService(Kernel::HLERequestCont IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(RESULT_SUCCESS); rb.PushIpcInterface<IDeliveryCacheStorageService>( - fsc.GetBCATDirectory(Core::CurrentProcess()->GetTitleID())); + fsc.GetBCATDirectory(system.CurrentProcess()->GetTitleID())); } void Module::Interface::CreateDeliveryCacheStorageServiceWithApplicationId( @@ -554,33 +558,35 @@ void Module::Interface::CreateDeliveryCacheStorageServiceWithApplicationId( rb.PushIpcInterface<IDeliveryCacheStorageService>(fsc.GetBCATDirectory(title_id)); } -std::unique_ptr<Backend> CreateBackendFromSettings(DirectoryGetter getter) { - const auto backend = Settings::values.bcat_backend; - +std::unique_ptr<Backend> CreateBackendFromSettings([[maybe_unused]] Core::System& system, + DirectoryGetter getter) { #ifdef YUZU_ENABLE_BOXCAT - if (backend == "boxcat") - return std::make_unique<Boxcat>(std::move(getter)); + if (Settings::values.bcat_backend == "boxcat") { + return std::make_unique<Boxcat>(system.GetAppletManager(), std::move(getter)); + } #endif return std::make_unique<NullBackend>(std::move(getter)); } -Module::Interface::Interface(std::shared_ptr<Module> module, FileSystem::FileSystemController& fsc, - const char* name) - : ServiceFramework(name), module(std::move(module)), fsc(fsc), - backend(CreateBackendFromSettings([&fsc](u64 tid) { return fsc.GetBCATDirectory(tid); })) {} +Module::Interface::Interface(Core::System& system_, std::shared_ptr<Module> module_, + FileSystem::FileSystemController& fsc_, const char* name) + : ServiceFramework(name), fsc{fsc_}, module{std::move(module_)}, + backend{CreateBackendFromSettings(system_, + [&fsc_](u64 tid) { return fsc_.GetBCATDirectory(tid); })}, + system{system_} {} Module::Interface::~Interface() = default; void InstallInterfaces(Core::System& system) { auto module = std::make_shared<Module>(); - std::make_shared<BCAT>(module, system.GetFileSystemController(), "bcat:a") + std::make_shared<BCAT>(system, module, system.GetFileSystemController(), "bcat:a") ->InstallAsService(system.ServiceManager()); - std::make_shared<BCAT>(module, system.GetFileSystemController(), "bcat:m") + std::make_shared<BCAT>(system, module, system.GetFileSystemController(), "bcat:m") ->InstallAsService(system.ServiceManager()); - std::make_shared<BCAT>(module, system.GetFileSystemController(), "bcat:u") + std::make_shared<BCAT>(system, module, system.GetFileSystemController(), "bcat:u") ->InstallAsService(system.ServiceManager()); - std::make_shared<BCAT>(module, system.GetFileSystemController(), "bcat:s") + std::make_shared<BCAT>(system, module, system.GetFileSystemController(), "bcat:s") ->InstallAsService(system.ServiceManager()); } diff --git a/src/core/hle/service/bcat/module.h b/src/core/hle/service/bcat/module.h index 27469926a..e4ba23ba0 100644 --- a/src/core/hle/service/bcat/module.h +++ b/src/core/hle/service/bcat/module.h @@ -6,6 +6,10 @@ #include "core/hle/service/service.h" +namespace Core { +class System; +} + namespace Service { namespace FileSystem { @@ -20,8 +24,8 @@ class Module final { public: class Interface : public ServiceFramework<Interface> { public: - explicit Interface(std::shared_ptr<Module> module, FileSystem::FileSystemController& fsc, - const char* name); + explicit Interface(Core::System& system_, std::shared_ptr<Module> module_, + FileSystem::FileSystemController& fsc_, const char* name); ~Interface() override; void CreateBcatService(Kernel::HLERequestContext& ctx); @@ -33,6 +37,9 @@ public: std::shared_ptr<Module> module; std::unique_ptr<Backend> backend; + + private: + Core::System& system; }; }; diff --git a/src/core/hle/service/es/es.cpp b/src/core/hle/service/es/es.cpp index af70d174d..f77ddd739 100644 --- a/src/core/hle/service/es/es.cpp +++ b/src/core/hle/service/es/es.cpp @@ -128,7 +128,7 @@ private: void CountCommonTicket(Kernel::HLERequestContext& ctx) { LOG_DEBUG(Service_ETicket, "called"); - const auto count = keys.GetCommonTickets().size(); + const u32 count = static_cast<u32>(keys.GetCommonTickets().size()); IPC::ResponseBuilder rb{ctx, 3}; rb.Push(RESULT_SUCCESS); @@ -138,7 +138,7 @@ private: void CountPersonalizedTicket(Kernel::HLERequestContext& ctx) { LOG_DEBUG(Service_ETicket, "called"); - const auto count = keys.GetPersonalizedTickets().size(); + const u32 count = static_cast<u32>(keys.GetPersonalizedTickets().size()); IPC::ResponseBuilder rb{ctx, 3}; rb.Push(RESULT_SUCCESS); @@ -150,7 +150,7 @@ private: if (keys.GetCommonTickets().empty()) out_entries = 0; else - out_entries = ctx.GetWriteBufferSize() / sizeof(u128); + out_entries = static_cast<u32>(ctx.GetWriteBufferSize() / sizeof(u128)); LOG_DEBUG(Service_ETicket, "called, entries={:016X}", out_entries); @@ -160,7 +160,7 @@ private: std::transform(tickets.begin(), tickets.end(), std::back_inserter(ids), [](const auto& pair) { return pair.first; }); - out_entries = std::min<u32>(ids.size(), out_entries); + out_entries = static_cast<u32>(std::min<std::size_t>(ids.size(), out_entries)); ctx.WriteBuffer(ids.data(), out_entries * sizeof(u128)); IPC::ResponseBuilder rb{ctx, 3}; @@ -173,7 +173,7 @@ private: if (keys.GetPersonalizedTickets().empty()) out_entries = 0; else - out_entries = ctx.GetWriteBufferSize() / sizeof(u128); + out_entries = static_cast<u32>(ctx.GetWriteBufferSize() / sizeof(u128)); LOG_DEBUG(Service_ETicket, "called, entries={:016X}", out_entries); @@ -183,7 +183,7 @@ private: std::transform(tickets.begin(), tickets.end(), std::back_inserter(ids), [](const auto& pair) { return pair.first; }); - out_entries = std::min<u32>(ids.size(), out_entries); + out_entries = static_cast<u32>(std::min<std::size_t>(ids.size(), out_entries)); ctx.WriteBuffer(ids.data(), out_entries * sizeof(u128)); IPC::ResponseBuilder rb{ctx, 3}; diff --git a/src/core/hle/service/fatal/fatal.cpp b/src/core/hle/service/fatal/fatal.cpp index b2ebf6240..2546d7595 100644 --- a/src/core/hle/service/fatal/fatal.cpp +++ b/src/core/hle/service/fatal/fatal.cpp @@ -66,7 +66,7 @@ enum class FatalType : u32 { static void GenerateErrorReport(Core::System& system, ResultCode error_code, const FatalInfo& info) { - const auto title_id = Core::CurrentProcess()->GetTitleID(); + const auto title_id = system.CurrentProcess()->GetTitleID(); std::string crash_report = fmt::format( "Yuzu {}-{} crash report\n" "Title ID: {:016x}\n" diff --git a/src/core/hle/service/filesystem/filesystem.cpp b/src/core/hle/service/filesystem/filesystem.cpp index 7fa4e820b..11e5c56b7 100644 --- a/src/core/hle/service/filesystem/filesystem.cpp +++ b/src/core/hle/service/filesystem/filesystem.cpp @@ -241,7 +241,7 @@ ResultVal<FileSys::EntryType> VfsDirectoryServiceWrapper::GetEntryType( return FileSys::ERROR_PATH_NOT_FOUND; } -FileSystemController::FileSystemController() = default; +FileSystemController::FileSystemController(Core::System& system_) : system{system_} {} FileSystemController::~FileSystemController() = default; @@ -290,7 +290,7 @@ ResultVal<FileSys::VirtualFile> FileSystemController::OpenRomFSCurrentProcess() return ResultCode(-1); } - return romfs_factory->OpenCurrentProcess(); + return romfs_factory->OpenCurrentProcess(system.CurrentProcess()->GetTitleID()); } ResultVal<FileSys::VirtualFile> FileSystemController::OpenRomFS( @@ -447,10 +447,10 @@ FileSys::SaveDataSize FileSystemController::ReadSaveDataSize(FileSys::SaveDataTy FileSys::SaveDataSize new_size{SUFFICIENT_SAVE_DATA_SIZE, SUFFICIENT_SAVE_DATA_SIZE}; FileSys::NACP nacp; - const auto res = Core::System::GetInstance().GetAppLoader().ReadControlData(nacp); + const auto res = system.GetAppLoader().ReadControlData(nacp); if (res != Loader::ResultStatus::Success) { - FileSys::PatchManager pm{Core::CurrentProcess()->GetTitleID()}; + FileSys::PatchManager pm{system.CurrentProcess()->GetTitleID()}; auto [nacp_unique, discard] = pm.GetControlMetadata(); if (nacp_unique != nullptr) { @@ -702,10 +702,10 @@ void FileSystemController::CreateFactories(FileSys::VfsFilesystem& vfs, bool ove if (bis_factory == nullptr) { bis_factory = std::make_unique<FileSys::BISFactory>(nand_directory, load_directory, dump_directory); - Core::System::GetInstance().RegisterContentProvider( - FileSys::ContentProviderUnionSlot::SysNAND, bis_factory->GetSystemNANDContents()); - Core::System::GetInstance().RegisterContentProvider( - FileSys::ContentProviderUnionSlot::UserNAND, bis_factory->GetUserNANDContents()); + system.RegisterContentProvider(FileSys::ContentProviderUnionSlot::SysNAND, + bis_factory->GetSystemNANDContents()); + system.RegisterContentProvider(FileSys::ContentProviderUnionSlot::UserNAND, + bis_factory->GetUserNANDContents()); } if (save_data_factory == nullptr) { @@ -714,8 +714,8 @@ void FileSystemController::CreateFactories(FileSys::VfsFilesystem& vfs, bool ove if (sdmc_factory == nullptr) { sdmc_factory = std::make_unique<FileSys::SDMCFactory>(std::move(sd_directory)); - Core::System::GetInstance().RegisterContentProvider(FileSys::ContentProviderUnionSlot::SDMC, - sdmc_factory->GetSDMCContents()); + system.RegisterContentProvider(FileSys::ContentProviderUnionSlot::SDMC, + sdmc_factory->GetSDMCContents()); } } diff --git a/src/core/hle/service/filesystem/filesystem.h b/src/core/hle/service/filesystem/filesystem.h index e6b49d8a2..1b0a6a949 100644 --- a/src/core/hle/service/filesystem/filesystem.h +++ b/src/core/hle/service/filesystem/filesystem.h @@ -10,6 +10,10 @@ #include "core/file_sys/vfs.h" #include "core/hle/result.h" +namespace Core { +class System; +} + namespace FileSys { class BISFactory; class RegisteredCache; @@ -52,7 +56,7 @@ enum class ImageDirectoryId : u32 { class FileSystemController { public: - FileSystemController(); + explicit FileSystemController(Core::System& system_); ~FileSystemController(); ResultCode RegisterRomFS(std::unique_ptr<FileSys::RomFSFactory>&& factory); @@ -125,6 +129,8 @@ private: std::unique_ptr<FileSys::XCI> gamecard; std::unique_ptr<FileSys::RegisteredCache> gamecard_registered; std::unique_ptr<FileSys::PlaceholderCache> gamecard_placeholder; + + Core::System& system; }; void InstallInterfaces(Core::System& system); diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp index eb982ad49..cbd5466c1 100644 --- a/src/core/hle/service/filesystem/fsp_srv.cpp +++ b/src/core/hle/service/filesystem/fsp_srv.cpp @@ -803,7 +803,7 @@ void FSP_SRV::CreateSaveDataFileSystem(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; auto save_struct = rp.PopRaw<FileSys::SaveDataDescriptor>(); - auto save_create_struct = rp.PopRaw<std::array<u8, 0x40>>(); + [[maybe_unused]] auto save_create_struct = rp.PopRaw<std::array<u8, 0x40>>(); u128 uid = rp.PopRaw<u128>(); LOG_DEBUG(Service_FS, "called save_struct = {}, uid = {:016X}{:016X}", save_struct.DebugInfo(), diff --git a/src/core/hle/service/friend/friend.cpp b/src/core/hle/service/friend/friend.cpp index 42b4ee861..75dd9043b 100644 --- a/src/core/hle/service/friend/friend.cpp +++ b/src/core/hle/service/friend/friend.cpp @@ -237,7 +237,6 @@ private: }; Common::UUID uuid; - bool is_event_created = false; Kernel::EventPair notification_event; std::queue<SizedNotificationInfo> notifications; States states{}; diff --git a/src/core/hle/service/hid/controllers/debug_pad.cpp b/src/core/hle/service/hid/controllers/debug_pad.cpp index 8e8263f5b..1f2131ec8 100644 --- a/src/core/hle/service/hid/controllers/debug_pad.cpp +++ b/src/core/hle/service/hid/controllers/debug_pad.cpp @@ -11,11 +11,10 @@ namespace Service::HID { constexpr s32 HID_JOYSTICK_MAX = 0x7fff; -constexpr s32 HID_JOYSTICK_MIN = -0x7fff; +[[maybe_unused]] constexpr s32 HID_JOYSTICK_MIN = -0x7fff; enum class JoystickId : std::size_t { Joystick_Left, Joystick_Right }; -Controller_DebugPad::Controller_DebugPad(Core::System& system) - : ControllerBase(system), system(system) {} +Controller_DebugPad::Controller_DebugPad(Core::System& system) : ControllerBase(system) {} Controller_DebugPad::~Controller_DebugPad() = default; void Controller_DebugPad::OnInit() {} diff --git a/src/core/hle/service/hid/controllers/debug_pad.h b/src/core/hle/service/hid/controllers/debug_pad.h index 6c4de817e..555b29d76 100644 --- a/src/core/hle/service/hid/controllers/debug_pad.h +++ b/src/core/hle/service/hid/controllers/debug_pad.h @@ -89,6 +89,5 @@ private: buttons; std::array<std::unique_ptr<Input::AnalogDevice>, Settings::NativeAnalog::NUM_STICKS_HID> analogs; - Core::System& system; }; } // namespace Service::HID diff --git a/src/core/hle/service/hid/controllers/gesture.cpp b/src/core/hle/service/hid/controllers/gesture.cpp index 80da0a0d3..6e990dd00 100644 --- a/src/core/hle/service/hid/controllers/gesture.cpp +++ b/src/core/hle/service/hid/controllers/gesture.cpp @@ -10,8 +10,7 @@ namespace Service::HID { constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3BA00; -Controller_Gesture::Controller_Gesture(Core::System& system) - : ControllerBase(system), system(system) {} +Controller_Gesture::Controller_Gesture(Core::System& system) : ControllerBase(system) {} Controller_Gesture::~Controller_Gesture() = default; void Controller_Gesture::OnInit() {} diff --git a/src/core/hle/service/hid/controllers/gesture.h b/src/core/hle/service/hid/controllers/gesture.h index 396897527..f650b8338 100644 --- a/src/core/hle/service/hid/controllers/gesture.h +++ b/src/core/hle/service/hid/controllers/gesture.h @@ -59,6 +59,5 @@ private: std::array<GestureState, 17> gesture_states; }; SharedMemory shared_memory{}; - Core::System& system; }; } // namespace Service::HID diff --git a/src/core/hle/service/hid/controllers/keyboard.cpp b/src/core/hle/service/hid/controllers/keyboard.cpp index e587b2e15..358cb9329 100644 --- a/src/core/hle/service/hid/controllers/keyboard.cpp +++ b/src/core/hle/service/hid/controllers/keyboard.cpp @@ -12,8 +12,7 @@ namespace Service::HID { constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3800; constexpr u8 KEYS_PER_BYTE = 8; -Controller_Keyboard::Controller_Keyboard(Core::System& system) - : ControllerBase(system), system(system) {} +Controller_Keyboard::Controller_Keyboard(Core::System& system) : ControllerBase(system) {} Controller_Keyboard::~Controller_Keyboard() = default; void Controller_Keyboard::OnInit() {} diff --git a/src/core/hle/service/hid/controllers/keyboard.h b/src/core/hle/service/hid/controllers/keyboard.h index ef586f7eb..f3eef5936 100644 --- a/src/core/hle/service/hid/controllers/keyboard.h +++ b/src/core/hle/service/hid/controllers/keyboard.h @@ -53,6 +53,5 @@ private: keyboard_keys; std::array<std::unique_ptr<Input::ButtonDevice>, Settings::NativeKeyboard::NumKeyboardMods> keyboard_mods; - Core::System& system; }; } // namespace Service::HID diff --git a/src/core/hle/service/hid/controllers/mouse.cpp b/src/core/hle/service/hid/controllers/mouse.cpp index 88f2ca4c1..93d88ea50 100644 --- a/src/core/hle/service/hid/controllers/mouse.cpp +++ b/src/core/hle/service/hid/controllers/mouse.cpp @@ -11,7 +11,7 @@ namespace Service::HID { constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3400; -Controller_Mouse::Controller_Mouse(Core::System& system) : ControllerBase(system), system(system) {} +Controller_Mouse::Controller_Mouse(Core::System& system) : ControllerBase(system) {} Controller_Mouse::~Controller_Mouse() = default; void Controller_Mouse::OnInit() {} diff --git a/src/core/hle/service/hid/controllers/mouse.h b/src/core/hle/service/hid/controllers/mouse.h index df2da6ae3..357ab7107 100644 --- a/src/core/hle/service/hid/controllers/mouse.h +++ b/src/core/hle/service/hid/controllers/mouse.h @@ -53,6 +53,5 @@ private: std::unique_ptr<Input::MouseDevice> mouse_device; std::array<std::unique_ptr<Input::ButtonDevice>, Settings::NativeMouseButton::NumMouseButtons> mouse_button_devices; - Core::System& system; }; } // namespace Service::HID diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp index a9cd119c4..a2b25a796 100644 --- a/src/core/hle/service/hid/controllers/npad.cpp +++ b/src/core/hle/service/hid/controllers/npad.cpp @@ -20,7 +20,7 @@ namespace Service::HID { constexpr s32 HID_JOYSTICK_MAX = 0x7fff; -constexpr s32 HID_JOYSTICK_MIN = -0x7fff; +[[maybe_unused]] constexpr s32 HID_JOYSTICK_MIN = -0x7fff; constexpr std::size_t NPAD_OFFSET = 0x9A00; constexpr u32 BATTERY_FULL = 2; constexpr u32 MAX_NPAD_ID = 7; @@ -105,6 +105,8 @@ void Controller_NPad::InitNewlyAddedControler(std::size_t controller_idx) { controller.joy_styles.raw = 0; // Zero out controller.device_type.raw = 0; switch (controller_type) { + case NPadControllerType::None: + UNREACHABLE(); case NPadControllerType::Handheld: controller.joy_styles.handheld.Assign(1); controller.device_type.handheld.Assign(1); @@ -239,7 +241,7 @@ void Controller_NPad::OnRelease() {} void Controller_NPad::RequestPadStateUpdate(u32 npad_id) { const auto controller_idx = NPadIdToIndex(npad_id); - const auto controller_type = connected_controllers[controller_idx].type; + [[maybe_unused]] const auto controller_type = connected_controllers[controller_idx].type; if (!connected_controllers[controller_idx].is_connected) { return; } @@ -346,6 +348,8 @@ void Controller_NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* libnx_entry.connection_status.raw = 0; switch (controller_type) { + case NPadControllerType::None: + UNREACHABLE(); case NPadControllerType::Handheld: handheld_entry.connection_status.raw = 0; handheld_entry.connection_status.IsWired.Assign(1); diff --git a/src/core/hle/service/hid/controllers/stubbed.cpp b/src/core/hle/service/hid/controllers/stubbed.cpp index 9b829341e..9e527d176 100644 --- a/src/core/hle/service/hid/controllers/stubbed.cpp +++ b/src/core/hle/service/hid/controllers/stubbed.cpp @@ -9,8 +9,7 @@ namespace Service::HID { -Controller_Stubbed::Controller_Stubbed(Core::System& system) - : ControllerBase(system), system(system) {} +Controller_Stubbed::Controller_Stubbed(Core::System& system) : ControllerBase(system) {} Controller_Stubbed::~Controller_Stubbed() = default; void Controller_Stubbed::OnInit() {} diff --git a/src/core/hle/service/hid/controllers/stubbed.h b/src/core/hle/service/hid/controllers/stubbed.h index 37d7d8538..4fa83ac85 100644 --- a/src/core/hle/service/hid/controllers/stubbed.h +++ b/src/core/hle/service/hid/controllers/stubbed.h @@ -30,6 +30,5 @@ public: private: bool smart_update{}; std::size_t common_offset{}; - Core::System& system; }; } // namespace Service::HID diff --git a/src/core/hle/service/hid/controllers/touchscreen.cpp b/src/core/hle/service/hid/controllers/touchscreen.cpp index 25912fd69..1c6e55566 100644 --- a/src/core/hle/service/hid/controllers/touchscreen.cpp +++ b/src/core/hle/service/hid/controllers/touchscreen.cpp @@ -13,8 +13,7 @@ namespace Service::HID { constexpr std::size_t SHARED_MEMORY_OFFSET = 0x400; -Controller_Touchscreen::Controller_Touchscreen(Core::System& system) - : ControllerBase(system), system(system) {} +Controller_Touchscreen::Controller_Touchscreen(Core::System& system) : ControllerBase(system) {} Controller_Touchscreen::~Controller_Touchscreen() = default; void Controller_Touchscreen::OnInit() {} diff --git a/src/core/hle/service/hid/controllers/touchscreen.h b/src/core/hle/service/hid/controllers/touchscreen.h index 3429c84db..a1d97269e 100644 --- a/src/core/hle/service/hid/controllers/touchscreen.h +++ b/src/core/hle/service/hid/controllers/touchscreen.h @@ -69,6 +69,5 @@ private: TouchScreenSharedMemory shared_memory{}; std::unique_ptr<Input::TouchDevice> touch_device; s64_le last_touch{}; - Core::System& system; }; } // namespace Service::HID diff --git a/src/core/hle/service/hid/controllers/xpad.cpp b/src/core/hle/service/hid/controllers/xpad.cpp index 1bce044b4..27511b27b 100644 --- a/src/core/hle/service/hid/controllers/xpad.cpp +++ b/src/core/hle/service/hid/controllers/xpad.cpp @@ -10,7 +10,7 @@ namespace Service::HID { constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3C00; -Controller_XPad::Controller_XPad(Core::System& system) : ControllerBase(system), system(system) {} +Controller_XPad::Controller_XPad(Core::System& system) : ControllerBase(system) {} Controller_XPad::~Controller_XPad() = default; void Controller_XPad::OnInit() {} diff --git a/src/core/hle/service/hid/controllers/xpad.h b/src/core/hle/service/hid/controllers/xpad.h index c445ebec0..ad229787c 100644 --- a/src/core/hle/service/hid/controllers/xpad.h +++ b/src/core/hle/service/hid/controllers/xpad.h @@ -56,6 +56,5 @@ private: }; static_assert(sizeof(SharedMemory) == 0x1000, "SharedMemory is an invalid size"); SharedMemory shared_memory{}; - Core::System& system; }; } // namespace Service::HID diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index 8d76ba746..ba1da4181 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp @@ -38,8 +38,10 @@ namespace Service::HID { // Updating period for each HID device. // TODO(ogniK): Find actual polling rate of hid constexpr s64 pad_update_ticks = static_cast<s64>(Core::Timing::BASE_CLOCK_RATE / 66); -constexpr s64 accelerometer_update_ticks = static_cast<s64>(Core::Timing::BASE_CLOCK_RATE / 100); -constexpr s64 gyroscope_update_ticks = static_cast<s64>(Core::Timing::BASE_CLOCK_RATE / 100); +[[maybe_unused]] constexpr s64 accelerometer_update_ticks = + static_cast<s64>(Core::Timing::BASE_CLOCK_RATE / 100); +[[maybe_unused]] constexpr s64 gyroscope_update_ticks = + static_cast<s64>(Core::Timing::BASE_CLOCK_RATE / 100); constexpr std::size_t SHARED_MEMORY_SIZE = 0x40000; IAppletResource::IAppletResource(Core::System& system) @@ -193,7 +195,7 @@ Hid::Hid(Core::System& system) : ServiceFramework("hid"), system(system) { {101, &Hid::GetSupportedNpadStyleSet, "GetSupportedNpadStyleSet"}, {102, &Hid::SetSupportedNpadIdType, "SetSupportedNpadIdType"}, {103, &Hid::ActivateNpad, "ActivateNpad"}, - {104, nullptr, "DeactivateNpad"}, + {104, &Hid::DeactivateNpad, "DeactivateNpad"}, {106, &Hid::AcquireNpadStyleSetUpdateEventHandle, "AcquireNpadStyleSetUpdateEventHandle"}, {107, &Hid::DisconnectNpad, "DisconnectNpad"}, {108, &Hid::GetPlayerLedPattern, "GetPlayerLedPattern"}, @@ -468,6 +470,17 @@ void Hid::ActivateNpad(Kernel::HLERequestContext& ctx) { applet_resource->ActivateController(HidController::NPad); } +void Hid::DeactivateNpad(Kernel::HLERequestContext& ctx) { + IPC::RequestParser rp{ctx}; + const auto applet_resource_user_id{rp.Pop<u64>()}; + + LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); + + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(RESULT_SUCCESS); + applet_resource->DeactivateController(HidController::NPad); +} + void Hid::AcquireNpadStyleSetUpdateEventHandle(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto npad_id{rp.Pop<u32>()}; diff --git a/src/core/hle/service/hid/hid.h b/src/core/hle/service/hid/hid.h index 35b663679..01852e019 100644 --- a/src/core/hle/service/hid/hid.h +++ b/src/core/hle/service/hid/hid.h @@ -99,6 +99,7 @@ private: void GetSupportedNpadStyleSet(Kernel::HLERequestContext& ctx); void SetSupportedNpadIdType(Kernel::HLERequestContext& ctx); void ActivateNpad(Kernel::HLERequestContext& ctx); + void DeactivateNpad(Kernel::HLERequestContext& ctx); void AcquireNpadStyleSetUpdateEventHandle(Kernel::HLERequestContext& ctx); void DisconnectNpad(Kernel::HLERequestContext& ctx); void GetPlayerLedPattern(Kernel::HLERequestContext& ctx); diff --git a/src/core/hle/service/ldr/ldr.cpp b/src/core/hle/service/ldr/ldr.cpp index 3164ca26e..499376bfc 100644 --- a/src/core/hle/service/ldr/ldr.cpp +++ b/src/core/hle/service/ldr/ldr.cpp @@ -163,7 +163,7 @@ public: return; } - if (Core::CurrentProcess()->GetTitleID() != header.title_id) { + if (system.CurrentProcess()->GetTitleID() != header.title_id) { LOG_ERROR(Service_LDR, "Attempting to load NRR with title ID other than current process. (actual " "{:016X})!", @@ -327,7 +327,7 @@ public: } // Load NRO as new executable module - auto* process = Core::CurrentProcess(); + auto* process = system.CurrentProcess(); auto& vm_manager = process->VMManager(); auto map_address = vm_manager.FindFreeRegion(nro_size + bss_size); @@ -411,7 +411,7 @@ public: return; } - auto& vm_manager = Core::CurrentProcess()->VMManager(); + auto& vm_manager = system.CurrentProcess()->VMManager(); const auto& nro_info = iter->second; // Unmap the mirrored memory diff --git a/src/core/hle/service/lm/lm.cpp b/src/core/hle/service/lm/lm.cpp index 2a61593e2..435f2d286 100644 --- a/src/core/hle/service/lm/lm.cpp +++ b/src/core/hle/service/lm/lm.cpp @@ -6,8 +6,10 @@ #include <string> #include "common/logging/log.h" +#include "common/scope_exit.h" #include "core/hle/ipc_helpers.h" #include "core/hle/service/lm/lm.h" +#include "core/hle/service/lm/manager.h" #include "core/hle/service/service.h" #include "core/memory.h" @@ -15,65 +17,16 @@ namespace Service::LM { class ILogger final : public ServiceFramework<ILogger> { public: - ILogger() : ServiceFramework("ILogger") { + ILogger(Manager& manager) : ServiceFramework("ILogger"), manager(manager) { static const FunctionInfo functions[] = { - {0x00000000, &ILogger::Initialize, "Initialize"}, - {0x00000001, &ILogger::SetDestination, "SetDestination"}, + {0, &ILogger::Log, "Log"}, + {1, &ILogger::SetDestination, "SetDestination"}, }; RegisterHandlers(functions); } private: - struct MessageHeader { - enum Flags : u32_le { - IsHead = 1, - IsTail = 2, - }; - enum Severity : u32_le { - Trace, - Info, - Warning, - Error, - Critical, - }; - - u64_le pid; - u64_le threadContext; - union { - BitField<0, 16, Flags> flags; - BitField<16, 8, Severity> severity; - BitField<24, 8, u32> verbosity; - }; - u32_le payload_size; - - bool IsHeadLog() const { - return flags & Flags::IsHead; - } - bool IsTailLog() const { - return flags & Flags::IsTail; - } - }; - static_assert(sizeof(MessageHeader) == 0x18, "MessageHeader is incorrect size"); - - /// Log field type - enum class Field : u8 { - Skip = 1, - Message = 2, - Line = 3, - Filename = 4, - Function = 5, - Module = 6, - Thread = 7, - }; - - /** - * ILogger::Initialize service function - * Inputs: - * 0: 0x00000000 - * Outputs: - * 0: ResultCode - */ - void Initialize(Kernel::HLERequestContext& ctx) { + void Log(Kernel::HLERequestContext& ctx) { // This function only succeeds - Get that out of the way IPC::ResponseBuilder rb{ctx, 2}; rb.Push(RESULT_SUCCESS); @@ -85,140 +38,70 @@ private: Memory::ReadBlock(addr, &header, sizeof(MessageHeader)); addr += sizeof(MessageHeader); - if (header.IsHeadLog()) { - log_stream.str(""); - log_stream.clear(); - } - - // Parse out log metadata - u32 line{}; - std::string module; - std::string message; - std::string filename; - std::string function; - std::string thread; + FieldMap fields; while (addr < end_addr) { - const Field field{static_cast<Field>(Memory::Read8(addr++))}; - const std::size_t length{Memory::Read8(addr++)}; + const auto field = static_cast<Field>(Memory::Read8(addr++)); + const auto length = Memory::Read8(addr++); if (static_cast<Field>(Memory::Read8(addr)) == Field::Skip) { ++addr; } - switch (field) { - case Field::Skip: - break; - case Field::Message: - message = Memory::ReadCString(addr, length); - break; - case Field::Line: - line = Memory::Read32(addr); - break; - case Field::Filename: - filename = Memory::ReadCString(addr, length); - break; - case Field::Function: - function = Memory::ReadCString(addr, length); - break; - case Field::Module: - module = Memory::ReadCString(addr, length); - break; - case Field::Thread: - thread = Memory::ReadCString(addr, length); - break; - } + SCOPE_EXIT({ addr += length; }); - addr += length; - } + if (field == Field::Skip) { + continue; + } - // Empty log - nothing to do here - if (log_stream.str().empty() && message.empty()) { - return; + std::vector<u8> data(length); + Memory::ReadBlock(addr, data.data(), length); + fields.emplace(field, std::move(data)); } - // Format a nicely printable string out of the log metadata - if (!filename.empty()) { - log_stream << filename << ':'; - } - if (!module.empty()) { - log_stream << module << ':'; - } - if (!function.empty()) { - log_stream << function << ':'; - } - if (line) { - log_stream << std::to_string(line) << ':'; - } - if (!thread.empty()) { - log_stream << thread << ':'; - } - if (log_stream.str().length() > 0 && log_stream.str().back() == ':') { - log_stream << ' '; - } - log_stream << message; - - if (header.IsTailLog()) { - switch (header.severity) { - case MessageHeader::Severity::Trace: - LOG_DEBUG(Debug_Emulated, "{}", log_stream.str()); - break; - case MessageHeader::Severity::Info: - LOG_INFO(Debug_Emulated, "{}", log_stream.str()); - break; - case MessageHeader::Severity::Warning: - LOG_WARNING(Debug_Emulated, "{}", log_stream.str()); - break; - case MessageHeader::Severity::Error: - LOG_ERROR(Debug_Emulated, "{}", log_stream.str()); - break; - case MessageHeader::Severity::Critical: - LOG_CRITICAL(Debug_Emulated, "{}", log_stream.str()); - break; - } - } + manager.Log({header, std::move(fields)}); } - // This service function is intended to be used as a way to - // redirect logging output to different destinations, however, - // given we always want to see the logging output, it's sufficient - // to do nothing and return success here. void SetDestination(Kernel::HLERequestContext& ctx) { - LOG_DEBUG(Service_LM, "called"); + IPC::RequestParser rp{ctx}; + const auto destination = rp.PopEnum<DestinationFlag>(); + + LOG_DEBUG(Service_LM, "called, destination={:08X}", static_cast<u32>(destination)); + + manager.SetDestination(destination); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(RESULT_SUCCESS); } - std::ostringstream log_stream; + Manager& manager; }; class LM final : public ServiceFramework<LM> { public: - explicit LM() : ServiceFramework{"lm"} { + explicit LM(Manager& manager) : ServiceFramework{"lm"}, manager(manager) { + // clang-format off static const FunctionInfo functions[] = { - {0x00000000, &LM::OpenLogger, "OpenLogger"}, + {0, &LM::OpenLogger, "OpenLogger"}, }; + // clang-format on + RegisterHandlers(functions); } - /** - * LM::OpenLogger service function - * Inputs: - * 0: 0x00000000 - * Outputs: - * 0: ResultCode - */ +private: void OpenLogger(Kernel::HLERequestContext& ctx) { LOG_DEBUG(Service_LM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(RESULT_SUCCESS); - rb.PushIpcInterface<ILogger>(); + rb.PushIpcInterface<ILogger>(manager); } + + Manager& manager; }; -void InstallInterfaces(SM::ServiceManager& service_manager) { - std::make_shared<LM>()->InstallAsService(service_manager); +void InstallInterfaces(Core::System& system) { + std::make_shared<LM>(system.GetLogManager())->InstallAsService(system.ServiceManager()); } } // namespace Service::LM diff --git a/src/core/hle/service/lm/lm.h b/src/core/hle/service/lm/lm.h index 7806ae27b..d40410b5c 100644 --- a/src/core/hle/service/lm/lm.h +++ b/src/core/hle/service/lm/lm.h @@ -4,13 +4,13 @@ #pragma once -namespace Service::SM { -class ServiceManager; +namespace Core { +class System; } namespace Service::LM { /// Registers all LM services with the specified service manager. -void InstallInterfaces(SM::ServiceManager& service_manager); +void InstallInterfaces(Core::System& system); } // namespace Service::LM diff --git a/src/core/hle/service/lm/manager.cpp b/src/core/hle/service/lm/manager.cpp new file mode 100644 index 000000000..b67081b86 --- /dev/null +++ b/src/core/hle/service/lm/manager.cpp @@ -0,0 +1,133 @@ +// Copyright 2019 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include "common/assert.h" +#include "common/logging/log.h" +#include "common/string_util.h" +#include "core/hle/service/lm/manager.h" +#include "core/reporter.h" + +namespace Service::LM { + +std::ostream& operator<<(std::ostream& os, DestinationFlag dest) { + std::vector<std::string> array; + const auto check_single_flag = [dest, &array](DestinationFlag check, std::string name) { + if ((static_cast<u32>(check) & static_cast<u32>(dest)) != 0) { + array.emplace_back(std::move(name)); + } + }; + + check_single_flag(DestinationFlag::Default, "Default"); + check_single_flag(DestinationFlag::UART, "UART"); + check_single_flag(DestinationFlag::UARTSleeping, "UART (Sleeping)"); + + os << "["; + for (const auto& entry : array) { + os << entry << ", "; + } + return os << "]"; +} + +std::ostream& operator<<(std::ostream& os, MessageHeader::Severity severity) { + switch (severity) { + case MessageHeader::Severity::Trace: + return os << "Trace"; + case MessageHeader::Severity::Info: + return os << "Info"; + case MessageHeader::Severity::Warning: + return os << "Warning"; + case MessageHeader::Severity::Error: + return os << "Error"; + case MessageHeader::Severity::Critical: + return os << "Critical"; + default: + return os << fmt::format("{:08X}", static_cast<u32>(severity)); + } +} + +std::ostream& operator<<(std::ostream& os, Field field) { + switch (field) { + case Field::Skip: + return os << "Skip"; + case Field::Message: + return os << "Message"; + case Field::Line: + return os << "Line"; + case Field::Filename: + return os << "Filename"; + case Field::Function: + return os << "Function"; + case Field::Module: + return os << "Module"; + case Field::Thread: + return os << "Thread"; + default: + return os << fmt::format("{:08X}", static_cast<u32>(field)); + } +} + +std::string FormatField(Field type, const std::vector<u8>& data) { + switch (type) { + case Field::Skip: + return ""; + case Field::Line: + if (data.size() >= sizeof(u32)) { + u32 line; + std::memcpy(&line, data.data(), sizeof(u32)); + return fmt::format("{}", line); + } + return "[ERROR DECODING LINE NUMBER]"; + case Field::Message: + case Field::Filename: + case Field::Function: + case Field::Module: + case Field::Thread: + return Common::StringFromFixedZeroTerminatedBuffer( + reinterpret_cast<const char*>(data.data()), data.size()); + default: + UNIMPLEMENTED(); + } +} + +Manager::Manager(Core::Reporter& reporter) : reporter(reporter) {} + +Manager::~Manager() = default; + +void Manager::SetEnabled(bool enabled) { + this->enabled = enabled; +} + +void Manager::SetDestination(DestinationFlag destination) { + this->destination = destination; +} + +void Manager::Log(LogMessage message) { + if (message.header.IsHeadLog()) { + InitializeLog(); + } + + current_log.emplace_back(std::move(message)); + + if (current_log.back().header.IsTailLog()) { + FinalizeLog(); + } +} + +void Manager::Flush() { + FinalizeLog(); +} + +void Manager::InitializeLog() { + current_log.clear(); + + LOG_INFO(Service_LM, "Initialized new log session"); +} + +void Manager::FinalizeLog() { + reporter.SaveLogReport(static_cast<u32>(destination), std::move(current_log)); + + LOG_INFO(Service_LM, "Finalized current log session"); +} + +} // namespace Service::LM diff --git a/src/core/hle/service/lm/manager.h b/src/core/hle/service/lm/manager.h new file mode 100644 index 000000000..544e636ba --- /dev/null +++ b/src/core/hle/service/lm/manager.h @@ -0,0 +1,106 @@ +// Copyright 2019 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include <map> +#include <ostream> +#include <vector> +#include "common/bit_field.h" +#include "common/common_types.h" +#include "common/swap.h" + +namespace Core { +class Reporter; +} + +namespace Service::LM { + +enum class DestinationFlag : u32 { + Default = 1, + UART = 2, + UARTSleeping = 4, + + All = 0xFFFF, +}; + +struct MessageHeader { + enum Flags : u32_le { + IsHead = 1, + IsTail = 2, + }; + enum Severity : u32_le { + Trace, + Info, + Warning, + Error, + Critical, + }; + + u64_le pid; + u64_le thread_context; + union { + BitField<0, 16, Flags> flags; + BitField<16, 8, Severity> severity; + BitField<24, 8, u32> verbosity; + }; + u32_le payload_size; + + bool IsHeadLog() const { + return flags & IsHead; + } + bool IsTailLog() const { + return flags & IsTail; + } +}; +static_assert(sizeof(MessageHeader) == 0x18, "MessageHeader is incorrect size"); + +enum class Field : u8 { + Skip = 1, + Message = 2, + Line = 3, + Filename = 4, + Function = 5, + Module = 6, + Thread = 7, +}; + +std::ostream& operator<<(std::ostream& os, DestinationFlag dest); +std::ostream& operator<<(std::ostream& os, MessageHeader::Severity severity); +std::ostream& operator<<(std::ostream& os, Field field); + +using FieldMap = std::map<Field, std::vector<u8>>; + +struct LogMessage { + MessageHeader header; + FieldMap fields; +}; + +std::string FormatField(Field type, const std::vector<u8>& data); + +class Manager { +public: + explicit Manager(Core::Reporter& reporter); + ~Manager(); + + void SetEnabled(bool enabled); + void SetDestination(DestinationFlag destination); + + void Log(LogMessage message); + + void Flush(); + +private: + void InitializeLog(); + void FinalizeLog(); + + bool enabled = true; + DestinationFlag destination = DestinationFlag::All; + + std::vector<LogMessage> current_log; + + Core::Reporter& reporter; +}; + +} // namespace Service::LM diff --git a/src/core/hle/service/nfp/nfp.cpp b/src/core/hle/service/nfp/nfp.cpp index a42c22d44..aa886cd3e 100644 --- a/src/core/hle/service/nfp/nfp.cpp +++ b/src/core/hle/service/nfp/nfp.cpp @@ -18,8 +18,8 @@ namespace Service::NFP { namespace ErrCodes { -constexpr ResultCode ERR_TAG_FAILED(ErrorModule::NFP, - -1); // TODO(ogniK): Find the actual error code +[[maybe_unused]] constexpr ResultCode ERR_TAG_FAILED(ErrorModule::NFP, + -1); // TODO(ogniK): Find the actual error code constexpr ResultCode ERR_NO_APPLICATION_AREA(ErrorModule::NFP, 152); } // namespace ErrCodes @@ -35,7 +35,7 @@ Module::Interface::~Interface() = default; class IUser final : public ServiceFramework<IUser> { public: IUser(Module::Interface& nfp_interface, Core::System& system) - : ServiceFramework("NFP::IUser"), nfp_interface(nfp_interface), system(system) { + : ServiceFramework("NFP::IUser"), nfp_interface(nfp_interface) { static const FunctionInfo functions[] = { {0, &IUser::Initialize, "Initialize"}, {1, &IUser::Finalize, "Finalize"}, @@ -183,6 +183,8 @@ private: case DeviceState::TagRemoved: device_state = DeviceState::Initialized; break; + default: + break; } IPC::ResponseBuilder rb{ctx, 2}; rb.Push(RESULT_SUCCESS); @@ -324,7 +326,6 @@ private: Kernel::EventPair deactivate_event; Kernel::EventPair availability_change_event; const Module::Interface& nfp_interface; - Core::System& system; }; void Module::Interface::CreateUserInterface(Kernel::HLERequestContext& ctx) { diff --git a/src/core/hle/service/ns/pl_u.cpp b/src/core/hle/service/ns/pl_u.cpp index 7dcdb4a07..23477315f 100644 --- a/src/core/hle/service/ns/pl_u.cpp +++ b/src/core/hle/service/ns/pl_u.cpp @@ -6,13 +6,6 @@ #include <cstring> #include <vector> -#include <FontChineseSimplified.h> -#include <FontChineseTraditional.h> -#include <FontExtendedChineseSimplified.h> -#include <FontKorean.h> -#include <FontNintendoExtended.h> -#include <FontStandard.h> - #include "common/assert.h" #include "common/common_paths.h" #include "common/common_types.h" @@ -24,7 +17,9 @@ #include "core/file_sys/nca_metadata.h" #include "core/file_sys/registered_cache.h" #include "core/file_sys/romfs.h" +#include "core/file_sys/system_archive/system_archive.h" #include "core/hle/ipc_helpers.h" +#include "core/hle/kernel/physical_memory.h" #include "core/hle/kernel/shared_memory.h" #include "core/hle/service/filesystem/filesystem.h" #include "core/hle/service/ns/pl_u.h" @@ -94,15 +89,20 @@ static void DecryptSharedFont(const std::vector<u32>& input, Kernel::PhysicalMem offset += transformed_font.size() * sizeof(u32); } -static void EncryptSharedFont(const std::vector<u8>& input, Kernel::PhysicalMemory& output, - std::size_t& offset) { - ASSERT_MSG(offset + input.size() + 8 < SHARED_FONT_MEM_SIZE, "Shared fonts exceeds 17mb!"); - const u32 KEY = EXPECTED_MAGIC ^ EXPECTED_RESULT; - std::memcpy(output.data() + offset, &EXPECTED_RESULT, sizeof(u32)); // Magic header - const u32 ENC_SIZE = static_cast<u32>(input.size()) ^ KEY; - std::memcpy(output.data() + offset + sizeof(u32), &ENC_SIZE, sizeof(u32)); - std::memcpy(output.data() + offset + (sizeof(u32) * 2), input.data(), input.size()); - offset += input.size() + (sizeof(u32) * 2); +void EncryptSharedFont(const std::vector<u32>& input, std::vector<u8>& output, + std::size_t& offset) { + ASSERT_MSG(offset + (input.size() * sizeof(u32)) < SHARED_FONT_MEM_SIZE, + "Shared fonts exceeds 17mb!"); + + const auto key = Common::swap32(EXPECTED_RESULT ^ EXPECTED_MAGIC); + std::vector<u32> transformed_font(input.size() + 2); + transformed_font[0] = Common::swap32(EXPECTED_MAGIC); + transformed_font[1] = Common::swap32(input.size() * sizeof(u32)) ^ key; + std::transform(input.begin(), input.end(), transformed_font.begin() + 2, + [key](u32 in) { return in ^ key; }); + std::memcpy(output.data() + offset, transformed_font.data(), + transformed_font.size() * sizeof(u32)); + offset += transformed_font.size() * sizeof(u32); } // Helper function to make BuildSharedFontsRawRegions a bit nicer @@ -168,114 +168,49 @@ PL_U::PL_U(Core::System& system) // Attempt to load shared font data from disk const auto* nand = fsc.GetSystemNANDContents(); std::size_t offset = 0; - // Rebuild shared fonts from data ncas - if (nand->HasEntry(static_cast<u64>(FontArchives::Standard), - FileSys::ContentRecordType::Data)) { - impl->shared_font = std::make_shared<Kernel::PhysicalMemory>(SHARED_FONT_MEM_SIZE); - for (auto font : SHARED_FONTS) { - const auto nca = - nand->GetEntry(static_cast<u64>(font.first), FileSys::ContentRecordType::Data); - if (!nca) { - LOG_ERROR(Service_NS, "Failed to find {:016X}! Skipping", - static_cast<u64>(font.first)); - continue; - } - const auto romfs = nca->GetRomFS(); - if (!romfs) { - LOG_ERROR(Service_NS, "{:016X} has no RomFS! Skipping", - static_cast<u64>(font.first)); - continue; - } - const auto extracted_romfs = FileSys::ExtractRomFS(romfs); - if (!extracted_romfs) { - LOG_ERROR(Service_NS, "Failed to extract RomFS for {:016X}! Skipping", - static_cast<u64>(font.first)); - continue; - } - const auto font_fp = extracted_romfs->GetFile(font.second); - if (!font_fp) { - LOG_ERROR(Service_NS, "{:016X} has no file \"{}\"! Skipping", - static_cast<u64>(font.first), font.second); - continue; - } - std::vector<u32> font_data_u32(font_fp->GetSize() / sizeof(u32)); - font_fp->ReadBytes<u32>(font_data_u32.data(), font_fp->GetSize()); - // We need to be BigEndian as u32s for the xor encryption - std::transform(font_data_u32.begin(), font_data_u32.end(), font_data_u32.begin(), - Common::swap32); - FontRegion region{ - static_cast<u32>(offset + 8), - static_cast<u32>((font_data_u32.size() * sizeof(u32)) - - 8)}; // Font offset and size do not account for the header - DecryptSharedFont(font_data_u32, *impl->shared_font, offset); - impl->shared_font_regions.push_back(region); + // Rebuild shared fonts from data ncas or synthesize + + impl->shared_font = std::make_shared<Kernel::PhysicalMemory>(SHARED_FONT_MEM_SIZE); + for (auto font : SHARED_FONTS) { + FileSys::VirtualFile romfs; + const auto nca = + nand->GetEntry(static_cast<u64>(font.first), FileSys::ContentRecordType::Data); + if (nca) { + romfs = nca->GetRomFS(); } - } else { - impl->shared_font = std::make_shared<Kernel::PhysicalMemory>( - SHARED_FONT_MEM_SIZE); // Shared memory needs to always be allocated and a fixed size - - const std::string user_path = FileUtil::GetUserPath(FileUtil::UserPath::SysDataDir); - const std::string filepath{user_path + SHARED_FONT}; + if (!romfs) { + romfs = FileSys::SystemArchive::SynthesizeSystemArchive(static_cast<u64>(font.first)); + } - // Create path if not already created - if (!FileUtil::CreateFullPath(filepath)) { - LOG_ERROR(Service_NS, "Failed to create sharedfonts path \"{}\"!", filepath); - return; + if (!romfs) { + LOG_ERROR(Service_NS, "Failed to find or synthesize {:016X}! Skipping", + static_cast<u64>(font.first)); + continue; } - bool using_ttf = false; - for (const char* font_ttf : SHARED_FONTS_TTF) { - if (FileUtil::Exists(user_path + font_ttf)) { - using_ttf = true; - FileUtil::IOFile file(user_path + font_ttf, "rb"); - if (file.IsOpen()) { - std::vector<u8> ttf_bytes(file.GetSize()); - file.ReadBytes<u8>(ttf_bytes.data(), ttf_bytes.size()); - FontRegion region{ - static_cast<u32>(offset + 8), - static_cast<u32>(ttf_bytes.size())}; // Font offset and size do not account - // for the header - EncryptSharedFont(ttf_bytes, *impl->shared_font, offset); - impl->shared_font_regions.push_back(region); - } else { - LOG_WARNING(Service_NS, "Unable to load font: {}", font_ttf); - } - } else if (using_ttf) { - LOG_WARNING(Service_NS, "Unable to find font: {}", font_ttf); - } + const auto extracted_romfs = FileSys::ExtractRomFS(romfs); + if (!extracted_romfs) { + LOG_ERROR(Service_NS, "Failed to extract RomFS for {:016X}! Skipping", + static_cast<u64>(font.first)); + continue; } - if (using_ttf) - return; - FileUtil::IOFile file(filepath, "rb"); - - if (file.IsOpen()) { - // Read shared font data - ASSERT(file.GetSize() == SHARED_FONT_MEM_SIZE); - file.ReadBytes(impl->shared_font->data(), impl->shared_font->size()); - impl->BuildSharedFontsRawRegions(*impl->shared_font); - } else { - LOG_WARNING(Service_NS, - "Shared Font file missing. Loading open source replacement from memory"); - - // clang-format off - const std::vector<std::vector<u8>> open_source_shared_fonts_ttf = { - {std::begin(FontChineseSimplified), std::end(FontChineseSimplified)}, - {std::begin(FontChineseTraditional), std::end(FontChineseTraditional)}, - {std::begin(FontExtendedChineseSimplified), std::end(FontExtendedChineseSimplified)}, - {std::begin(FontKorean), std::end(FontKorean)}, - {std::begin(FontNintendoExtended), std::end(FontNintendoExtended)}, - {std::begin(FontStandard), std::end(FontStandard)}, - }; - // clang-format on - - for (const std::vector<u8>& font_ttf : open_source_shared_fonts_ttf) { - const FontRegion region{static_cast<u32>(offset + 8), - static_cast<u32>(font_ttf.size())}; - EncryptSharedFont(font_ttf, *impl->shared_font, offset); - impl->shared_font_regions.push_back(region); - } + const auto font_fp = extracted_romfs->GetFile(font.second); + if (!font_fp) { + LOG_ERROR(Service_NS, "{:016X} has no file \"{}\"! Skipping", + static_cast<u64>(font.first), font.second); + continue; } + std::vector<u32> font_data_u32(font_fp->GetSize() / sizeof(u32)); + font_fp->ReadBytes<u32>(font_data_u32.data(), font_fp->GetSize()); + // We need to be BigEndian as u32s for the xor encryption + std::transform(font_data_u32.begin(), font_data_u32.end(), font_data_u32.begin(), + Common::swap32); + // Font offset and size do not account for the header + const FontRegion region{static_cast<u32>(offset + 8), + static_cast<u32>((font_data_u32.size() * sizeof(u32)) - 8)}; + DecryptSharedFont(font_data_u32, *impl->shared_font, offset); + impl->shared_font_regions.push_back(region); } } @@ -324,14 +259,14 @@ void PL_U::GetSharedMemoryAddressOffset(Kernel::HLERequestContext& ctx) { void PL_U::GetSharedMemoryNativeHandle(Kernel::HLERequestContext& ctx) { // Map backing memory for the font data LOG_DEBUG(Service_NS, "called"); - Core::CurrentProcess()->VMManager().MapMemoryBlock(SHARED_FONT_MEM_VADDR, impl->shared_font, 0, - SHARED_FONT_MEM_SIZE, - Kernel::MemoryState::Shared); + system.CurrentProcess()->VMManager().MapMemoryBlock(SHARED_FONT_MEM_VADDR, impl->shared_font, 0, + SHARED_FONT_MEM_SIZE, + Kernel::MemoryState::Shared); // Create shared font memory object auto& kernel = system.Kernel(); impl->shared_font_mem = Kernel::SharedMemory::Create( - kernel, Core::CurrentProcess(), SHARED_FONT_MEM_SIZE, Kernel::MemoryPermission::ReadWrite, + kernel, system.CurrentProcess(), SHARED_FONT_MEM_SIZE, Kernel::MemoryPermission::ReadWrite, Kernel::MemoryPermission::Read, SHARED_FONT_MEM_VADDR, Kernel::MemoryRegion::BASE, "PL_U:shared_font_mem"); diff --git a/src/core/hle/service/ns/pl_u.h b/src/core/hle/service/ns/pl_u.h index 1063f4204..27161bd7a 100644 --- a/src/core/hle/service/ns/pl_u.h +++ b/src/core/hle/service/ns/pl_u.h @@ -5,6 +5,7 @@ #pragma once #include <memory> +#include <vector> #include "core/hle/service/service.h" namespace Service { @@ -15,6 +16,8 @@ class FileSystemController; namespace NS { +void EncryptSharedFont(const std::vector<u32>& input, std::vector<u8>& output, std::size_t& offset); + class PL_U final : public ServiceFramework<PL_U> { public: explicit PL_U(Core::System& system); diff --git a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp index 6bc053f27..07c88465e 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp +++ b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp @@ -45,6 +45,8 @@ u32 nvhost_as_gpu::ioctl(Ioctl command, const std::vector<u8>& input, const std: return GetVARegions(input, output); case IoctlCommand::IocUnmapBufferCommand: return UnmapBuffer(input, output); + default: + break; } if (static_cast<IoctlCommand>(command.cmd.Value()) == IoctlCommand::IocRemapCommand) diff --git a/src/core/hle/service/nvdrv/devices/nvhost_ctrl.cpp b/src/core/hle/service/nvdrv/devices/nvhost_ctrl.cpp index 708469bd5..b27ee0502 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_ctrl.cpp +++ b/src/core/hle/service/nvdrv/devices/nvhost_ctrl.cpp @@ -38,9 +38,10 @@ u32 nvhost_ctrl::ioctl(Ioctl command, const std::vector<u8>& input, const std::v return IocCtrlEventUnregister(input, output); case IoctlCommand::IocCtrlEventSignalCommand: return IocCtrlEventSignal(input, output); + default: + UNIMPLEMENTED_MSG("Unimplemented ioctl"); + return 0; } - UNIMPLEMENTED_MSG("Unimplemented ioctl"); - return 0; } u32 nvhost_ctrl::NvOsGetConfigU32(const std::vector<u8>& input, std::vector<u8>& output) { diff --git a/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.cpp b/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.cpp index 389ace76f..cc2192e5c 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.cpp +++ b/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.cpp @@ -40,9 +40,10 @@ u32 nvhost_ctrl_gpu::ioctl(Ioctl command, const std::vector<u8>& input, return FlushL2(input, output); case IoctlCommand::IocGetGpuTime: return GetGpuTime(input, output); + default: + UNIMPLEMENTED_MSG("Unimplemented ioctl"); + return 0; } - UNIMPLEMENTED_MSG("Unimplemented ioctl"); - return 0; } u32 nvhost_ctrl_gpu::GetCharacteristics(const std::vector<u8>& input, std::vector<u8>& output, diff --git a/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp b/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp index 2b8d1bef6..9de0ace22 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp +++ b/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp @@ -44,6 +44,8 @@ u32 nvhost_gpu::ioctl(Ioctl command, const std::vector<u8>& input, const std::ve return GetWaitbase(input, output); case IoctlCommand::IocChannelSetTimeoutCommand: return ChannelSetTimeout(input, output); + default: + break; } if (command.group == NVGPU_IOCTL_MAGIC) { diff --git a/src/core/hle/service/nvflinger/buffer_queue.cpp b/src/core/hle/service/nvflinger/buffer_queue.cpp index e1a07d3ee..55b68eb0c 100644 --- a/src/core/hle/service/nvflinger/buffer_queue.cpp +++ b/src/core/hle/service/nvflinger/buffer_queue.cpp @@ -14,8 +14,8 @@ namespace Service::NVFlinger { -BufferQueue::BufferQueue(u32 id, u64 layer_id) : id(id), layer_id(layer_id) { - auto& kernel = Core::System::GetInstance().Kernel(); +BufferQueue::BufferQueue(Kernel::KernelCore& kernel, u32 id, u64 layer_id) + : id(id), layer_id(layer_id) { buffer_wait_event = Kernel::WritableEvent::CreateEventPair(kernel, Kernel::ResetType::Manual, "BufferQueue NativeHandle"); } diff --git a/src/core/hle/service/nvflinger/buffer_queue.h b/src/core/hle/service/nvflinger/buffer_queue.h index 356bedb81..8f9b18547 100644 --- a/src/core/hle/service/nvflinger/buffer_queue.h +++ b/src/core/hle/service/nvflinger/buffer_queue.h @@ -15,6 +15,10 @@ #include "core/hle/kernel/writable_event.h" #include "core/hle/service/nvdrv/nvdata.h" +namespace Kernel { +class KernelCore; +} + namespace Service::NVFlinger { struct IGBPBuffer { @@ -44,7 +48,7 @@ public: NativeWindowFormat = 2, }; - BufferQueue(u32 id, u64 layer_id); + explicit BufferQueue(Kernel::KernelCore& kernel, u32 id, u64 layer_id); ~BufferQueue(); enum class BufferTransformFlags : u32 { diff --git a/src/core/hle/service/nvflinger/nvflinger.cpp b/src/core/hle/service/nvflinger/nvflinger.cpp index e00b665ea..cc9522aad 100644 --- a/src/core/hle/service/nvflinger/nvflinger.cpp +++ b/src/core/hle/service/nvflinger/nvflinger.cpp @@ -83,7 +83,7 @@ std::optional<u64> NVFlinger::CreateLayer(u64 display_id) { const u64 layer_id = next_layer_id++; const u32 buffer_queue_id = next_buffer_queue_id++; - buffer_queues.emplace_back(buffer_queue_id, layer_id); + buffer_queues.emplace_back(system.Kernel(), buffer_queue_id, layer_id); display->CreateLayer(layer_id, buffer_queues.back()); return layer_id; } diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index f2c6fe9dc..7c5302017 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp @@ -226,7 +226,7 @@ void Init(std::shared_ptr<SM::ServiceManager>& sm, Core::System& system) { LBL::InstallInterfaces(*sm); LDN::InstallInterfaces(*sm); LDR::InstallInterfaces(*sm, system); - LM::InstallInterfaces(*sm); + LM::InstallInterfaces(system); Migration::InstallInterfaces(*sm); Mii::InstallInterfaces(*sm); MM::InstallInterfaces(*sm); |