From 39688c7d47e2d1bd0810c793ca41882214b75eb8 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Wed, 15 Sep 2021 21:50:06 -0700 Subject: [PATCH] erpt: skeleton sprofile apis --- .../libstratosphere/include/stratosphere.hpp | 1 + .../impl/ams_system_thread_definitions.hpp | 3 + .../stratosphere/erpt/erpt_ids.autogen.hpp | 14 +++ .../include/stratosphere/sprofile.hpp | 19 +++ .../stratosphere/sprofile/sprofile_types.hpp | 35 ++++++ .../sprofile/srv/sprofile_srv_api.hpp | 24 ++++ .../source/sprofile/srv/sprofile_srv_api.cpp | 110 ++++++++++++++++++ ...ile_srv_i_profile_controller_for_debug.hpp | 24 ++++ .../srv/sprofile_srv_i_profile_importer.hpp | 25 ++++ .../srv/sprofile_srv_i_profile_reader.hpp | 26 +++++ ...sprofile_srv_i_profile_update_observer.hpp | 24 ++++ .../sprofile_srv_i_service_for_bg_agent.hpp | 27 +++++ ...ofile_srv_i_service_for_system_process.hpp | 27 +++++ .../srv/sprofile_srv_profile_manager.hpp | 48 ++++++++ .../srv/sprofile_srv_service_for_bg_agent.hpp | 38 ++++++ ...profile_srv_service_for_system_process.hpp | 37 ++++++ stratosphere/erpt/erpt.json | 2 +- stratosphere/erpt/source/erpt_main.cpp | 6 + utilities/erpt.py | 3 + 19 files changed, 492 insertions(+), 1 deletion(-) create mode 100644 libraries/libstratosphere/include/stratosphere/sprofile.hpp create mode 100644 libraries/libstratosphere/include/stratosphere/sprofile/sprofile_types.hpp create mode 100644 libraries/libstratosphere/include/stratosphere/sprofile/srv/sprofile_srv_api.hpp create mode 100644 libraries/libstratosphere/source/sprofile/srv/sprofile_srv_api.cpp create mode 100644 libraries/libstratosphere/source/sprofile/srv/sprofile_srv_i_profile_controller_for_debug.hpp create mode 100644 libraries/libstratosphere/source/sprofile/srv/sprofile_srv_i_profile_importer.hpp create mode 100644 libraries/libstratosphere/source/sprofile/srv/sprofile_srv_i_profile_reader.hpp create mode 100644 libraries/libstratosphere/source/sprofile/srv/sprofile_srv_i_profile_update_observer.hpp create mode 100644 libraries/libstratosphere/source/sprofile/srv/sprofile_srv_i_service_for_bg_agent.hpp create mode 100644 libraries/libstratosphere/source/sprofile/srv/sprofile_srv_i_service_for_system_process.hpp create mode 100644 libraries/libstratosphere/source/sprofile/srv/sprofile_srv_profile_manager.hpp create mode 100644 libraries/libstratosphere/source/sprofile/srv/sprofile_srv_service_for_bg_agent.hpp create mode 100644 libraries/libstratosphere/source/sprofile/srv/sprofile_srv_service_for_system_process.hpp diff --git a/libraries/libstratosphere/include/stratosphere.hpp b/libraries/libstratosphere/include/stratosphere.hpp index c39805152..c7ef579e7 100644 --- a/libraries/libstratosphere/include/stratosphere.hpp +++ b/libraries/libstratosphere/include/stratosphere.hpp @@ -88,6 +88,7 @@ #include #include #include +#include #include #include #include diff --git a/libraries/libstratosphere/include/stratosphere/ams/impl/ams_system_thread_definitions.hpp b/libraries/libstratosphere/include/stratosphere/ams/impl/ams_system_thread_definitions.hpp index 2af496816..78795273d 100644 --- a/libraries/libstratosphere/include/stratosphere/ams/impl/ams_system_thread_definitions.hpp +++ b/libraries/libstratosphere/include/stratosphere/ams/impl/ams_system_thread_definitions.hpp @@ -168,6 +168,9 @@ namespace ams::impl { AMS_DEFINE_SYSTEM_THREAD(21, TioServer, FileServerHtcsServer); AMS_DEFINE_SYSTEM_THREAD(21, TioServer, SdCardObserver); + /* ServiceProfile */ + AMS_DEFINE_SYSTEM_THREAD(-1, sprofile, IpcServer); + #undef AMS_DEFINE_SYSTEM_THREAD diff --git a/libraries/libstratosphere/include/stratosphere/erpt/erpt_ids.autogen.hpp b/libraries/libstratosphere/include/stratosphere/erpt/erpt_ids.autogen.hpp index 7d6bf5444..57c258d6d 100644 --- a/libraries/libstratosphere/include/stratosphere/erpt/erpt_ids.autogen.hpp +++ b/libraries/libstratosphere/include/stratosphere/erpt/erpt_ids.autogen.hpp @@ -171,6 +171,9 @@ HANDLER(AcpUserAccountSettingsInfo, 130) \ HANDLER(AudioDeviceInfo, 131) \ HANDLER(AbnormalWakeInfo, 132) \ + HANDLER(ServiceProfileInfo, 133) \ + HANDLER(BluetoothAudioInfo, 134) \ + HANDLER(BluetoothPairingCountInfo, 135) \ #define AMS_ERPT_FOREACH_FIELD(HANDLER) \ HANDLER(TestU64, 0, Test, FieldType_NumericU64, FieldFlag_None ) \ @@ -812,4 +815,15 @@ HANDLER(AppletTotalActiveTime, 636, ErrorInfoAuto, FieldType_NumericI64, FieldFlag_None ) \ HANDLER(WakeCount, 637, AbnormalWakeInfo, FieldType_NumericU32, FieldFlag_None ) \ HANDLER(PredominantWakeReason, 638, AbnormalWakeInfo, FieldType_NumericU32, FieldFlag_None ) \ + HANDLER(EdidExtensionBlock2, 639, EdidInfo, FieldType_U8Array, FieldFlag_None ) \ + HANDLER(EdidExtensionBlock3, 640, EdidInfo, FieldType_U8Array, FieldFlag_None ) \ + HANDLER(LumenRequestId, 641, ErrorInfo, FieldType_String, FieldFlag_None ) \ + HANDLER(LlnwLlid, 642, ErrorInfo, FieldType_String, FieldFlag_None ) \ + HANDLER(SupportingLimitedLicenses, 643, RunningApplicationInfo, FieldType_NumericU32, FieldFlag_None ) \ + HANDLER(RuntimeLimitedLicenseUpgrade, 644, RunningApplicationInfo, FieldType_NumericU8, FieldFlag_None ) \ + HANDLER(ServiceProfileRevisionKey, 645, ServiceProfileInfo, FieldType_NumericU64, FieldFlag_None ) \ + HANDLER(BluetoothAudioConnectionCount, 646, BluetoothAudioInfo, FieldType_NumericU8, FieldFlag_None ) \ + HANDLER(BluetoothHidPairingInfoCount, 647, BluetoothPairingCountInfo, FieldType_NumericU8, FieldFlag_None ) \ + HANDLER(BluetoothAudioPairingInfoCount, 648, BluetoothPairingCountInfo, FieldType_NumericU8, FieldFlag_None ) \ + HANDLER(BluetoothLePairingInfoCount, 649, BluetoothPairingCountInfo, FieldType_NumericU8, FieldFlag_None ) \ diff --git a/libraries/libstratosphere/include/stratosphere/sprofile.hpp b/libraries/libstratosphere/include/stratosphere/sprofile.hpp new file mode 100644 index 000000000..5eb8b01e5 --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/sprofile.hpp @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once + +#include +#include \ No newline at end of file diff --git a/libraries/libstratosphere/include/stratosphere/sprofile/sprofile_types.hpp b/libraries/libstratosphere/include/stratosphere/sprofile/sprofile_types.hpp new file mode 100644 index 000000000..884be9b42 --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/sprofile/sprofile_types.hpp @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once +#include + +namespace ams::sprofile { + + struct Identifier { + u8 data[7]; + + friend bool operator==(const Identifier &lhs, const Identifier &rhs) { + return std::memcmp(lhs.data, rhs.data, sizeof(lhs.data)) == 0; + } + + friend bool operator!=(const Identifier &lhs, const Identifier &rhs) { + return !(lhs == rhs); + } + }; + static_assert(sizeof(Identifier) == 7); + static_assert(util::is_pod::value); + +} diff --git a/libraries/libstratosphere/include/stratosphere/sprofile/srv/sprofile_srv_api.hpp b/libraries/libstratosphere/include/stratosphere/sprofile/srv/sprofile_srv_api.hpp new file mode 100644 index 000000000..ef21bcaac --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/sprofile/srv/sprofile_srv_api.hpp @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once +#include + +namespace ams::sprofile::srv { + + void Initialize(); + void StartIpcServer(); + +} \ No newline at end of file diff --git a/libraries/libstratosphere/source/sprofile/srv/sprofile_srv_api.cpp b/libraries/libstratosphere/source/sprofile/srv/sprofile_srv_api.cpp new file mode 100644 index 000000000..5fc1e5100 --- /dev/null +++ b/libraries/libstratosphere/source/sprofile/srv/sprofile_srv_api.cpp @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include +#include "sprofile_srv_profile_manager.hpp" +#include "sprofile_srv_service_for_bg_agent.hpp" +#include "sprofile_srv_service_for_system_process.hpp" + +namespace ams::sprofile::srv { + + namespace { + + constexpr const ProfileManager::SaveDataInfo SaveDataInfo = { + .id = 0x8000000000000220, + .mount_name = "sprof", + .size = 0x1C0000, + .journal_size = 0x80000, + .flags = fs::SaveDataFlags_KeepAfterResettingSystemSaveData, + }; + + constexpr const sm::ServiceName ServiceNameForBgAgent = sm::ServiceName::Encode("sprof:bg"); + constexpr const sm::ServiceName ServiceNameForSystemProcess = sm::ServiceName::Encode("sprof:sp"); + + constexpr inline size_t BgAgentSessionCountMax = 2; + constexpr inline size_t SystemProcessSessionCountMax = 5; + + constexpr inline size_t SessionCountMax = BgAgentSessionCountMax + SystemProcessSessionCountMax; + + constexpr inline size_t PortCountMax = 2; + + struct ServerManagerOptions { + static constexpr size_t PointerBufferSize = 0x0; + static constexpr size_t MaxDomains = SessionCountMax; /* NOTE: Official is 3 */ + static constexpr size_t MaxDomainObjects = 16; /* NOTE: Official is 8 */ + }; + + using ServerManager = sf::hipc::ServerManager; + + constinit util::TypedStorage g_profile_manager; + + constinit util::TypedStorage> g_bg_service_object; + constinit util::TypedStorage> g_sp_service_object; + + constinit util::TypedStorage g_server_manager; + + alignas(os::ThreadStackAlignment) constinit u8 g_ipc_thread_stack[0x3000]; + constinit u8 g_heap[16_KB]; + + constinit os::ThreadType g_ipc_thread; + + constinit lmem::HeapHandle g_heap_handle; + constinit sf::ExpHeapMemoryResource g_sf_memory_resource; + + void IpcServerThreadFunction(void *) { + /* Get the server manager. */ + auto &server_manager = util::GetReference(g_server_manager); + + /* Resume processing. */ + server_manager.ResumeProcessing(); + + /* Loop processing. */ + server_manager.LoopProcess(); + } + + } + + void Initialize() { + /* Initialize heap. */ + g_heap_handle = lmem::CreateExpHeap(g_heap, sizeof(g_heap), lmem::CreateOption_ThreadSafe); + + /* Attach the memory resource to heap. */ + g_sf_memory_resource.Attach(g_heap_handle); + + /* Create the profile manager. */ + util::ConstructAt(g_profile_manager, SaveDataInfo); + + /* Create the service objects. */ + util::ConstructAt(g_bg_service_object, std::addressof(g_sf_memory_resource), util::GetPointer(g_profile_manager)); + util::ConstructAt(g_sp_service_object, std::addressof(g_sf_memory_resource), util::GetPointer(g_profile_manager)); + + /* Create the server manager. */ + util::ConstructAt(g_server_manager); + + /* Create services. */ + R_ABORT_UNLESS(util::GetReference(g_server_manager).RegisterObjectForServer(util::GetReference(g_bg_service_object).GetShared(), ServiceNameForBgAgent, BgAgentSessionCountMax)); + R_ABORT_UNLESS(util::GetReference(g_server_manager).RegisterObjectForServer(util::GetReference(g_sp_service_object).GetShared(), ServiceNameForSystemProcess, SystemProcessSessionCountMax)); + } + + void StartIpcServer() { + /* Create the ipc server thread. */ + R_ABORT_UNLESS(os::CreateThread(std::addressof(g_ipc_thread), IpcServerThreadFunction, nullptr, g_ipc_thread_stack, sizeof(g_ipc_thread_stack), AMS_GET_SYSTEM_THREAD_PRIORITY(sprofile, IpcServer))); + os::SetThreadNamePointer(std::addressof(g_ipc_thread), AMS_GET_SYSTEM_THREAD_NAME(sprofile, IpcServer)); + + /* Start the ipc server thread. */ + os::StartThread(std::addressof(g_ipc_thread)); + } + +} diff --git a/libraries/libstratosphere/source/sprofile/srv/sprofile_srv_i_profile_controller_for_debug.hpp b/libraries/libstratosphere/source/sprofile/srv/sprofile_srv_i_profile_controller_for_debug.hpp new file mode 100644 index 000000000..ca53d6640 --- /dev/null +++ b/libraries/libstratosphere/source/sprofile/srv/sprofile_srv_i_profile_controller_for_debug.hpp @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once +#include + +#define AMS_SPROFILE_I_PROFILE_CONTROLLER_FOR_DEBUG_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 2000, Result, Reset, (), ()) \ + AMS_SF_METHOD_INFO(C, H, 2001, Result, GetRaw, (sf::Out out_type, sf::Out out_value, sprofile::Identifier profile, sprofile::Identifier key), (out_type, out_value, profile, key)) + + +AMS_SF_DEFINE_INTERFACE(ams::sprofile, IProfileControllerForDebug, AMS_SPROFILE_I_PROFILE_CONTROLLER_FOR_DEBUG_INTERFACE_INFO) diff --git a/libraries/libstratosphere/source/sprofile/srv/sprofile_srv_i_profile_importer.hpp b/libraries/libstratosphere/source/sprofile/srv/sprofile_srv_i_profile_importer.hpp new file mode 100644 index 000000000..a2b77b6da --- /dev/null +++ b/libraries/libstratosphere/source/sprofile/srv/sprofile_srv_i_profile_importer.hpp @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once +#include + +/* TODO: sf::LargeData types, not buffers */ +#define AMS_SPROFILE_I_PROFILE_IMPORTER_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, ImportProfile, (const sf::InBuffer &data), (data)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, Commit, (), ()) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, ImportMetadata, (const sf::InBuffer &data), (data)) \ + +AMS_SF_DEFINE_INTERFACE(ams::sprofile, IProfileImporter, AMS_SPROFILE_I_PROFILE_IMPORTER_INTERFACE_INFO) diff --git a/libraries/libstratosphere/source/sprofile/srv/sprofile_srv_i_profile_reader.hpp b/libraries/libstratosphere/source/sprofile/srv/sprofile_srv_i_profile_reader.hpp new file mode 100644 index 000000000..032ad06bf --- /dev/null +++ b/libraries/libstratosphere/source/sprofile/srv/sprofile_srv_i_profile_reader.hpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once +#include + +#define AMS_SPROFILE_I_PROFILE_READER_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, GetSigned64, (sf::Out out, sprofile::Identifier profile, sprofile::Identifier key), (out, profile, key)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, GetUnsigned64, (sf::Out out, sprofile::Identifier profile, sprofile::Identifier key), (out, profile, key)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, GetSigned32, (sf::Out out, sprofile::Identifier profile, sprofile::Identifier key), (out, profile, key)) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, GetUnsigned32, (sf::Out out, sprofile::Identifier profile, sprofile::Identifier key), (out, profile, key)) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, GetByte, (sf::Out out, sprofile::Identifier profile, sprofile::Identifier key), (out, profile, key)) + +AMS_SF_DEFINE_INTERFACE(ams::sprofile, IProfileReader, AMS_SPROFILE_I_PROFILE_READER_INTERFACE_INFO) diff --git a/libraries/libstratosphere/source/sprofile/srv/sprofile_srv_i_profile_update_observer.hpp b/libraries/libstratosphere/source/sprofile/srv/sprofile_srv_i_profile_update_observer.hpp new file mode 100644 index 000000000..6706822e9 --- /dev/null +++ b/libraries/libstratosphere/source/sprofile/srv/sprofile_srv_i_profile_update_observer.hpp @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once +#include + +#define AMS_SPROFILE_I_PROFILE_UPDATE_OBSERVER_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, Listen, (sprofile::Identifier profile), (profile)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, Unlisten, (sprofile::Identifier profile), (profile)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, GetEventHandle, (ams::sf::OutCopyHandle out), (out)) + +AMS_SF_DEFINE_INTERFACE(ams::sprofile, IProfileUpdateObserver, AMS_SPROFILE_I_PROFILE_UPDATE_OBSERVER_INTERFACE_INFO) diff --git a/libraries/libstratosphere/source/sprofile/srv/sprofile_srv_i_service_for_bg_agent.hpp b/libraries/libstratosphere/source/sprofile/srv/sprofile_srv_i_service_for_bg_agent.hpp new file mode 100644 index 000000000..e26d91308 --- /dev/null +++ b/libraries/libstratosphere/source/sprofile/srv/sprofile_srv_i_service_for_bg_agent.hpp @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once +#include +#include "sprofile_srv_i_profile_importer.hpp" + +/* TODO: sf::LargeData types, not buffers */ +#define AMS_SPROFILE_I_SPROFILE_SERVICE_FOR_BG_AGENT_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 100, Result, OpenProfileImporter, (sf::Out> out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 200, Result, ReadMetadata, (sf::Out out_count, const sf::OutBuffer &out_buf, const sf::InBuffer &meta), (out_count, out_buf, meta)) \ + AMS_SF_METHOD_INFO(C, H, 201, Result, IsUpdateNeeded, (sf::Out out, sprofile::Identifier revision_key), (out, revision_key)) \ + AMS_SF_METHOD_INFO(C, H, 2000, Result, Reset, (), ()) + +AMS_SF_DEFINE_INTERFACE(ams::sprofile, ISprofileServiceForBgAgent, AMS_SPROFILE_I_SPROFILE_SERVICE_FOR_BG_AGENT_INTERFACE_INFO) diff --git a/libraries/libstratosphere/source/sprofile/srv/sprofile_srv_i_service_for_system_process.hpp b/libraries/libstratosphere/source/sprofile/srv/sprofile_srv_i_service_for_system_process.hpp new file mode 100644 index 000000000..483c44a57 --- /dev/null +++ b/libraries/libstratosphere/source/sprofile/srv/sprofile_srv_i_service_for_system_process.hpp @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once +#include +#include "sprofile_srv_i_profile_reader.hpp" +#include "sprofile_srv_i_profile_update_observer.hpp" +#include "sprofile_srv_i_profile_controller_for_debug.hpp" + +#define AMS_SPROFILE_I_SPROFILE_SERVICE_FOR_SYSTEM_PROCESS_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 100, Result, OpenProfileReader, (sf::Out> out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 101, Result, OpenProfileUpdateObserver, (sf::Out> out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 900, Result, OpenProfileControllerForDebug, (sf::Out> out), (out)) + +AMS_SF_DEFINE_INTERFACE(ams::sprofile, ISprofileServiceForSystemProcess, AMS_SPROFILE_I_SPROFILE_SERVICE_FOR_SYSTEM_PROCESS_INTERFACE_INFO) diff --git a/libraries/libstratosphere/source/sprofile/srv/sprofile_srv_profile_manager.hpp b/libraries/libstratosphere/source/sprofile/srv/sprofile_srv_profile_manager.hpp new file mode 100644 index 000000000..803fc906e --- /dev/null +++ b/libraries/libstratosphere/source/sprofile/srv/sprofile_srv_profile_manager.hpp @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once +#include + +namespace ams::sprofile::srv { + + class ProfileManager { + public: + struct SaveDataInfo { + u64 id; + const char *mount_name; + size_t size; + size_t journal_size; + u32 flags; + }; + private: + class UpdateObserverManager; + private: + os::SdkMutex m_general_mutex; + os::SdkMutex m_fs_mutex; + SaveDataInfo m_save_data_info; + /* TODO: util::optional m_profile_importer; */ + /* TODO: util::optional m_profile_metadata; */ + /* TODO: util::optional m_service_profile; */ + UpdateObserverManager *m_update_observer_manager; + public: + ProfileManager(const SaveDataInfo &save_data_info); + public: + /* TODO */ + private: + /* TODO */ + }; + +} diff --git a/libraries/libstratosphere/source/sprofile/srv/sprofile_srv_service_for_bg_agent.hpp b/libraries/libstratosphere/source/sprofile/srv/sprofile_srv_service_for_bg_agent.hpp new file mode 100644 index 000000000..54f78230a --- /dev/null +++ b/libraries/libstratosphere/source/sprofile/srv/sprofile_srv_service_for_bg_agent.hpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once +#include +#include "sprofile_srv_i_service_for_bg_agent.hpp" + +namespace ams::sprofile::srv { + + class ProfileManager; + + class ServiceForBgAgent { + private: + MemoryResource *m_memory_resource; + ProfileManager *m_profile_manager; + public: + constexpr ServiceForBgAgent(MemoryResource *mr, ProfileManager *pm) : m_memory_resource(mr), m_profile_manager(pm) { /* ... */ } + public: + Result OpenProfileImporter(sf::Out> out); + Result ReadMetadata(sf::Out out_count, const sf::OutBuffer &out_buf, const sf::InBuffer &meta); + Result IsUpdateNeeded(sf::Out out, Identifier revision_key); + Result Reset(); + }; + static_assert(sprofile::IsISprofileServiceForBgAgent); + +} diff --git a/libraries/libstratosphere/source/sprofile/srv/sprofile_srv_service_for_system_process.hpp b/libraries/libstratosphere/source/sprofile/srv/sprofile_srv_service_for_system_process.hpp new file mode 100644 index 000000000..33a949836 --- /dev/null +++ b/libraries/libstratosphere/source/sprofile/srv/sprofile_srv_service_for_system_process.hpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once +#include +#include "sprofile_srv_i_service_for_system_process.hpp" + +namespace ams::sprofile::srv { + + class ProfileManager; + + class ServiceForSystemProcess { + private: + MemoryResource *m_memory_resource; + ProfileManager *m_profile_manager; + public: + constexpr ServiceForSystemProcess(MemoryResource *mr, ProfileManager *pm) : m_memory_resource(mr), m_profile_manager(pm) { /* ... */ } + public: + Result OpenProfileReader(sf::Out> out); + Result OpenProfileUpdateObserver(sf::Out> out); + Result OpenProfileControllerForDebug(sf::Out> out); + }; + static_assert(sprofile::IsISprofileServiceForSystemProcess); + +} diff --git a/stratosphere/erpt/erpt.json b/stratosphere/erpt/erpt.json index 9c8f57203..3b5df1ddb 100644 --- a/stratosphere/erpt/erpt.json +++ b/stratosphere/erpt/erpt.json @@ -16,7 +16,7 @@ "permissions": "0xFFFFFFFFFFFFFFFF" }, "service_access": ["lm", "fsp-srv", "time:u", "set", "set:sys", "srepo:u", "psc:m", "csrng", "ectx:r"], - "service_host": ["erpt:r", "erpt:c"], + "service_host": ["erpt:r", "erpt:c", "sprof:sp", "sprof:bg"], "kernel_capabilities": [{ "type": "kernel_flags", "value": { diff --git a/stratosphere/erpt/source/erpt_main.cpp b/stratosphere/erpt/source/erpt_main.cpp index 85c917e49..cd7923474 100644 --- a/stratosphere/erpt/source/erpt_main.cpp +++ b/stratosphere/erpt/source/erpt_main.cpp @@ -201,6 +201,12 @@ int main(int argc, char **argv) /* Start the erpt server. */ R_ABORT_UNLESS(erpt::srv::InitializeAndStartService()); + /* Initialize the sprofile server. */ + sprofile::srv::Initialize(); + + /* Start the sprofile ipc server. */ + sprofile::srv::StartIpcServer(); + /* Wait forever. */ erpt::srv::Wait(); diff --git a/utilities/erpt.py b/utilities/erpt.py index 4793a1731..c455a5fd0 100644 --- a/utilities/erpt.py +++ b/utilities/erpt.py @@ -224,6 +224,9 @@ CATEGORIES = { 130 : 'AcpUserAccountSettingsInfo', 131 : 'AudioDeviceInfo', 132 : 'AbnormalWakeInfo', + 133 : 'ServiceProfileInfo', + 134 : 'BluetoothAudioInfo', + 135 : 'BluetoothPairingCountInfo', } FIELD_TYPES = {