diff --git a/stratosphere/fs_mitm/source/fsmitm_main.cpp b/stratosphere/fs_mitm/source/fsmitm_main.cpp index c96462eaa..28b47fbfb 100644 --- a/stratosphere/fs_mitm/source/fsmitm_main.cpp +++ b/stratosphere/fs_mitm/source/fsmitm_main.cpp @@ -26,8 +26,6 @@ #include "fsmitm_utils.hpp" -#include "setsys_mitm_service.hpp" - extern "C" { extern u32 __start__; @@ -63,11 +61,6 @@ void __appInit(void) { fatalSimple(MAKERESULT(Module_Libnx, LibnxError_InitFail_SM)); } - rc = smMitMInitialize(); - if (R_FAILED(rc)) { - fatalSimple(MAKERESULT(Module_Libnx, LibnxError_InitFail_SM)); - } - rc = fsInitialize(); if (R_FAILED(rc)) { fatalSimple(MAKERESULT(Module_Libnx, LibnxError_InitFail_FS)); @@ -78,7 +71,6 @@ void __appInit(void) { void __appExit(void) { /* Cleanup services. */ fsExit(); - smMitMExit(); smExit(); } @@ -87,27 +79,12 @@ struct FsMitmManagerOptions { static const size_t MaxDomains = 0x10; static const size_t MaxDomainObjects = 0x4000; }; - using FsMitmManager = WaitableManager; -void CreateSettingsMitMServer(void *arg) { - auto server_manager = (FsMitmManager *)arg; - - Result rc; - if (R_FAILED((rc = setsysInitialize()))) { - fatalSimple(rc); - } - - AddMitmServerToManager(server_manager, "set:sys", 5); - - svcExitThread(); -} - int main(int argc, char **argv) { Thread sd_initializer_thread = {0}; Thread hid_initializer_thread = {0}; - Thread set_mitm_setup_thread = {0}; consoleDebugInit(debugDevice_SVC); if (R_FAILED(threadCreate(&sd_initializer_thread, &Utils::InitializeSdThreadFunc, NULL, 0x4000, 0x15, 0))) { @@ -129,15 +106,7 @@ int main(int argc, char **argv) /* Create fsp-srv mitm. */ AddMitmServerToManager(server_manager, "fsp-srv", 61); - - /* Create set:sys mitm server, delayed until set:sys is available. */ - if (R_FAILED(threadCreate(&set_mitm_setup_thread, &CreateSettingsMitMServer, server_manager, 0x4000, 0x15, 0))) { - /* TODO: Panic. */ - } - if (R_FAILED(threadStart(&set_mitm_setup_thread))) { - /* TODO: Panic. */ - } - + /* Loop forever, servicing our services. */ server_manager->Process(); diff --git a/stratosphere/fs_mitm/source/fsmitm_service.cpp b/stratosphere/fs_mitm/source/fsmitm_service.cpp index da19d5778..75e575067 100644 --- a/stratosphere/fs_mitm/source/fsmitm_service.cpp +++ b/stratosphere/fs_mitm/source/fsmitm_service.cpp @@ -48,6 +48,15 @@ Result FsMitmService::OpenDataStorageByCurrentProcess(Out storage = nullptr; u32 out_domain_id = 0; Result rc = 0; + + ON_SCOPE_EXIT { + if (R_SUCCEEDED(rc)) { + out_storage.SetValue(std::move(storage)); + if (out_storage.IsDomain()) { + out_storage.ChangeObjectId(out_domain_id); + } + } + }; if (this->romfs_storage != nullptr) { if (out_storage.IsDomain()) { @@ -83,13 +92,6 @@ Result FsMitmService::OpenDataStorageByCurrentProcess(Out. - */ - -#include -#include -#include "setsys_mitm_service.hpp" - -#include "debug.hpp" - -static HosMutex g_version_mutex; -static bool g_got_version = false; -static SetSysFirmwareVersion g_fw_version = {0}; - -static Result _GetFirmwareVersion(SetSysFirmwareVersion *out) { - std::lock_guard lock(g_version_mutex); - if (!g_got_version) { - Result rc = setsysGetFirmwareVersion(&g_fw_version); - if (R_FAILED(rc)) { - return rc; - } - - /* Modify the output firmware version. */ - { - u32 major, minor, micro; - char display_version[sizeof(g_fw_version.display_version)] = {0}; - - GetAtmosphereApiVersion(&major, &minor, µ, nullptr, nullptr); - snprintf(display_version, sizeof(display_version), "%s (AMS %u.%u.%u)", g_fw_version.display_version, major, minor, micro); - - memcpy(g_fw_version.display_version, display_version, sizeof(g_fw_version.display_version)); - } - - g_got_version = true; - } - - *out = g_fw_version; - return 0; -} - -void SetSysMitmService::PostProcess(IMitmServiceObject *obj, IpcResponseContext *ctx) { - /* No commands need postprocessing. */ -} - -Result SetSysMitmService::GetFirmwareVersion(OutPointerWithServerSize out) { - Result rc = _GetFirmwareVersion(out.pointer); - - /* GetFirmwareVersion sanitizes these fields. */ - out.pointer->revision_major = 0; - out.pointer->revision_minor = 0; - - return rc; -} - -Result SetSysMitmService::GetFirmwareVersion2(OutPointerWithServerSize out) { - return _GetFirmwareVersion(out.pointer); -} \ No newline at end of file diff --git a/stratosphere/fs_mitm/source/setsys_mitm_service.hpp b/stratosphere/fs_mitm/source/setsys_mitm_service.hpp deleted file mode 100644 index b62bdcb69..000000000 --- a/stratosphere/fs_mitm/source/setsys_mitm_service.hpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2018 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 -#include "fsmitm_utils.hpp" - -enum SetSysCmd : u32 { - SetSysCmd_GetFirmwareVersion = 3, - SetSysCmd_GetFirmwareVersion2 = 4, -}; - -class SetSysMitmService : public IMitmServiceObject { - public: - SetSysMitmService(std::shared_ptr s) : IMitmServiceObject(s) { - /* ... */ - } - - static bool ShouldMitm(u64 pid, u64 tid) { - /* Only MitM qlaunch, maintenance. */ - return tid == 0x0100000000001000ULL || tid == 0x0100000000001015ULL; - } - - static void PostProcess(IMitmServiceObject *obj, IpcResponseContext *ctx); - - protected: - /* Overridden commands. */ - Result GetFirmwareVersion(OutPointerWithServerSize out); - Result GetFirmwareVersion2(OutPointerWithServerSize out); - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MakeServiceCommandMeta(), - MakeServiceCommandMeta(), - }; -}; diff --git a/stratosphere/libstratosphere/include/stratosphere/mitm/mitm_query_service.hpp b/stratosphere/libstratosphere/include/stratosphere/mitm/mitm_query_service.hpp index a007cdc82..621c4cfb6 100644 --- a/stratosphere/libstratosphere/include/stratosphere/mitm/mitm_query_service.hpp +++ b/stratosphere/libstratosphere/include/stratosphere/mitm/mitm_query_service.hpp @@ -44,7 +44,7 @@ class MitmQueryService : public IServiceObject { } public: DEFINE_SERVICE_DISPATCH_TABLE { - MakeServiceCommandMeta(), - MakeServiceCommandMeta(), + MakeServiceCommandMeta::ShouldMitm>(), + MakeServiceCommandMeta::AssociatePidToTid>(), }; }; \ No newline at end of file diff --git a/stratosphere/libstratosphere/include/stratosphere/mitm/mitm_server.hpp b/stratosphere/libstratosphere/include/stratosphere/mitm/mitm_server.hpp index 5380fae26..dc7dbac6e 100644 --- a/stratosphere/libstratosphere/include/stratosphere/mitm/mitm_server.hpp +++ b/stratosphere/libstratosphere/include/stratosphere/mitm/mitm_server.hpp @@ -93,8 +93,8 @@ template static void AddMitmServerToManager(SessionManagerBase *manager, const char *srv_name, unsigned int max_sessions) { Handle query_h; auto *srv = new MitmServer(&query_h, srv_name, max_sessions); - manager->AddWaitable(srv); manager->AddSession(query_h, std::move(ServiceObjectHolder(std::move(std::make_shared>())))); + manager->AddWaitable(srv); }