stratosphere: only hold sm sessions open when needed
This commit is contained in:
@@ -73,15 +73,12 @@ void __appInit(void) {
|
||||
|
||||
SetFirmwareVersionForLibnx();
|
||||
|
||||
rc = smInitialize();
|
||||
if (R_FAILED(rc)) {
|
||||
fatalSimple(MAKERESULT(Module_Libnx, LibnxError_InitFail_SM));
|
||||
}
|
||||
|
||||
rc = fsInitialize();
|
||||
if (R_FAILED(rc)) {
|
||||
fatalSimple(MAKERESULT(Module_Libnx, LibnxError_InitFail_FS));
|
||||
}
|
||||
DoWithSmSession([&]() {
|
||||
rc = fsInitialize();
|
||||
if (R_FAILED(rc)) {
|
||||
std::abort();
|
||||
}
|
||||
});
|
||||
|
||||
CheckAtmosphereVersion(CURRENT_ATMOSPHERE_VERSION);
|
||||
}
|
||||
@@ -89,7 +86,6 @@ void __appInit(void) {
|
||||
void __appExit(void) {
|
||||
/* Cleanup services. */
|
||||
fsExit();
|
||||
smExit();
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
@@ -100,10 +96,10 @@ int main(int argc, char **argv)
|
||||
LaunchAllMitmModules();
|
||||
|
||||
if (R_FAILED(initializer_thread.Initialize(&Utils::InitializeThreadFunc, NULL, 0x4000, 0x15))) {
|
||||
/* TODO: Panic. */
|
||||
std::abort();
|
||||
}
|
||||
if (R_FAILED(initializer_thread.Start())) {
|
||||
/* TODO: Panic. */
|
||||
std::abort();
|
||||
}
|
||||
|
||||
/* Wait for all mitm modules to end. */
|
||||
|
||||
@@ -35,12 +35,12 @@ void NsMitmMain(void *arg) {
|
||||
Utils::WaitSdInitialized();
|
||||
|
||||
/* Ensure we can talk to NS. */
|
||||
{
|
||||
DoWithSmSession([&]() {
|
||||
if (R_FAILED(nsInitialize())) {
|
||||
std::abort();
|
||||
}
|
||||
nsExit();
|
||||
}
|
||||
});
|
||||
|
||||
/* Create server manager */
|
||||
auto server_manager = new WaitableManager(1);
|
||||
|
||||
@@ -78,15 +78,17 @@ static bool IsHexadecimal(const char *str) {
|
||||
|
||||
void Utils::InitializeThreadFunc(void *args) {
|
||||
/* Get required services. */
|
||||
Handle tmp_hnd = 0;
|
||||
static const char * const required_active_services[] = {"pcv", "gpio", "pinmux", "psc:c"};
|
||||
for (unsigned int i = 0; i < sizeof(required_active_services) / sizeof(required_active_services[0]); i++) {
|
||||
if (R_FAILED(smGetServiceOriginal(&tmp_hnd, smEncodeName(required_active_services[i])))) {
|
||||
/* TODO: Panic */
|
||||
} else {
|
||||
svcCloseHandle(tmp_hnd);
|
||||
DoWithSmSession([&]() {
|
||||
Handle tmp_hnd = 0;
|
||||
static const char * const required_active_services[] = {"pcv", "gpio", "pinmux", "psc:c"};
|
||||
for (unsigned int i = 0; i < sizeof(required_active_services) / sizeof(required_active_services[0]); i++) {
|
||||
if (R_FAILED(smGetServiceOriginal(&tmp_hnd, smEncodeName(required_active_services[i])))) {
|
||||
/* TODO: Panic */
|
||||
} else {
|
||||
svcCloseHandle(tmp_hnd);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/* Mount SD. */
|
||||
while (R_FAILED(fsMountSdcard(&g_sd_filesystem))) {
|
||||
@@ -197,7 +199,11 @@ void Utils::InitializeThreadFunc(void *args) {
|
||||
Utils::RefreshConfiguration();
|
||||
|
||||
/* Initialize set:sys. */
|
||||
setsysInitialize();
|
||||
DoWithSmSession([&]() {
|
||||
if (R_FAILED(setsysInitialize())) {
|
||||
std::abort();
|
||||
}
|
||||
});
|
||||
|
||||
/* Signal SD is initialized. */
|
||||
g_has_initialized = true;
|
||||
@@ -209,13 +215,15 @@ void Utils::InitializeThreadFunc(void *args) {
|
||||
g_sd_signal.Signal();
|
||||
|
||||
/* Initialize HID. */
|
||||
{
|
||||
|
||||
while (R_FAILED(hidInitialize())) {
|
||||
while (!g_has_hid_session) {
|
||||
DoWithSmSession([&]() {
|
||||
if (R_SUCCEEDED(hidInitialize())) {
|
||||
g_has_hid_session = true;
|
||||
}
|
||||
});
|
||||
if (!g_has_hid_session) {
|
||||
svcSleepThread(1000000ULL);
|
||||
}
|
||||
|
||||
g_has_hid_session = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user