From 83025080c89deb575d0e72d55a0e335ab7c00f1c Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Sun, 20 Jan 2019 17:00:35 -0800 Subject: [PATCH] sm: change InstallMitM to wait for registration instead of 0xE15 --- stratosphere/fs_mitm/source/fsmitm_main.cpp | 13 ++++++++----- stratosphere/libstratosphere | 2 +- stratosphere/pm/source/pm_boot2.cpp | 8 ++++++-- stratosphere/set_mitm/source/setmitm_main.cpp | 15 +++++++++------ stratosphere/sm/source/sm_registration.cpp | 2 +- 5 files changed, 25 insertions(+), 15 deletions(-) diff --git a/stratosphere/fs_mitm/source/fsmitm_main.cpp b/stratosphere/fs_mitm/source/fsmitm_main.cpp index 24fa8b647..40808a34c 100644 --- a/stratosphere/fs_mitm/source/fsmitm_main.cpp +++ b/stratosphere/fs_mitm/source/fsmitm_main.cpp @@ -62,11 +62,6 @@ void __appInit(void) { fatalSimple(MAKERESULT(Module_Libnx, LibnxError_InitFail_SM)); } - rc = fsInitialize(); - if (R_FAILED(rc)) { - fatalSimple(MAKERESULT(Module_Libnx, LibnxError_InitFail_FS)); - } - CheckAtmosphereVersion(CURRENT_ATMOSPHERE_VERSION); } @@ -94,6 +89,14 @@ int main(int argc, char **argv) /* Create fsp-srv mitm. */ AddMitmServerToManager(server_manager, "fsp-srv", 61); + + /* Connect to FS */ + { + Result rc = fsInitialize(); + if (R_FAILED(rc)) { + fatalSimple(MAKERESULT(Module_Libnx, LibnxError_InitFail_FS)); + } + } if (R_FAILED(threadCreate(&sd_initializer_thread, &Utils::InitializeSdThreadFunc, NULL, 0x4000, 0x15, 0))) { /* TODO: Panic. */ diff --git a/stratosphere/libstratosphere b/stratosphere/libstratosphere index 05015b935..f9d38856f 160000 --- a/stratosphere/libstratosphere +++ b/stratosphere/libstratosphere @@ -1 +1 @@ -Subproject commit 05015b9354d3df80e0836aa95d1d4dcfc2aef4b7 +Subproject commit f9d38856f335c4cb0ed3c7253d9319a965815af2 diff --git a/stratosphere/pm/source/pm_boot2.cpp b/stratosphere/pm/source/pm_boot2.cpp index 864f2d9ff..5a88f10bb 100644 --- a/stratosphere/pm/source/pm_boot2.cpp +++ b/stratosphere/pm/source/pm_boot2.cpp @@ -123,8 +123,7 @@ static void MountSdCard() { fsdevMountSdmc(); } -void EmbeddedBoot2::Main() { - /* Wait until fs.mitm has installed itself. We want this to happen as early as possible. */ +static void WaitForFsMitm() { bool fs_mitm_installed = false; Result rc = smManagerAmsInitialize(); @@ -138,6 +137,11 @@ void EmbeddedBoot2::Main() { svcSleepThread(1000ull); } smManagerAmsExit(); +} + +void EmbeddedBoot2::Main() { + /* Wait until fs.mitm has installed itself. We want this to happen as early as possible. */ + WaitForFsMitm(); /* psc, bus, pcv is the minimal set of required titles to get SD card. */ /* bus depends on pcie, and pcv depends on settings. */ diff --git a/stratosphere/set_mitm/source/setmitm_main.cpp b/stratosphere/set_mitm/source/setmitm_main.cpp index 0a7b0a295..3fea764dd 100644 --- a/stratosphere/set_mitm/source/setmitm_main.cpp +++ b/stratosphere/set_mitm/source/setmitm_main.cpp @@ -60,11 +60,6 @@ void __appInit(void) { fatalSimple(MAKERESULT(Module_Libnx, LibnxError_InitFail_SM)); } - rc = setsysInitialize(); - if (R_FAILED(rc)) { - fatalSimple(rc); - } - CheckAtmosphereVersion(CURRENT_ATMOSPHERE_VERSION); } @@ -89,8 +84,16 @@ int main(int argc, char **argv) /* TODO: What's a good timeout value to use here? */ auto server_manager = new SetMitmManager(1); - /* Create fsp-srv mitm. */ + /* Create set:sys mitm. */ AddMitmServerToManager(server_manager, "set:sys", 4); + + /* Connect to set:sys. */ + { + Result rc = setsysInitialize(); + if (R_FAILED(rc)) { + fatalSimple(rc); + } + } /* Loop forever, servicing our services. */ server_manager->Process(); diff --git a/stratosphere/sm/source/sm_registration.cpp b/stratosphere/sm/source/sm_registration.cpp index c9957e315..33fcc6eec 100644 --- a/stratosphere/sm/source/sm_registration.cpp +++ b/stratosphere/sm/source/sm_registration.cpp @@ -467,7 +467,7 @@ Result Registration::InstallMitmForPid(u64 pid, u64 service, Handle *out, Handle /* Verify the service exists. */ Registration::Service *target_service = GetService(service); if (target_service == NULL) { - return 0xE15; + return RESULT_DEFER_SESSION; } /* Verify the service isn't already being mitm'd. */