stratosphere: only hold sm sessions open when needed
This commit is contained in:
@@ -240,19 +240,28 @@ bool CrashReport::GetCurrentTime(u64 *out) {
|
||||
|
||||
/* Verify that pcv isn't dead. */
|
||||
{
|
||||
Handle dummy;
|
||||
if (R_SUCCEEDED(smRegisterService(&dummy, "time:s", false, 0x20))) {
|
||||
svcCloseHandle(dummy);
|
||||
bool has_time_service;
|
||||
DoWithSmSession([&]() {
|
||||
Handle dummy;
|
||||
if (R_SUCCEEDED(smRegisterService(&dummy, "time:s", false, 0x20))) {
|
||||
svcCloseHandle(dummy);
|
||||
has_time_service = false;
|
||||
} else {
|
||||
has_time_service = true;
|
||||
}
|
||||
});
|
||||
if (!has_time_service) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* Try to get the current time. */
|
||||
bool success = false;
|
||||
if (R_SUCCEEDED(timeInitialize())) {
|
||||
if (R_SUCCEEDED(timeGetCurrentTime(TimeType_LocalSystemClock, out))) {
|
||||
success = true;
|
||||
}
|
||||
bool success = true;
|
||||
DoWithSmSession([&]() {
|
||||
success &= R_SUCCEEDED(timeInitialize());
|
||||
});
|
||||
if (success) {
|
||||
success &= R_SUCCEEDED(timeGetCurrentTime(TimeType_LocalSystemClock, out));
|
||||
timeExit();
|
||||
}
|
||||
return success;
|
||||
|
||||
@@ -68,16 +68,13 @@ void __appInit(void) {
|
||||
Result rc;
|
||||
|
||||
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)) {
|
||||
fatalSimple(MAKERESULT(Module_Libnx, LibnxError_InitFail_FS));
|
||||
}
|
||||
});
|
||||
|
||||
rc = fsdevMountSdmc();
|
||||
if (R_FAILED(rc)) {
|
||||
@@ -89,7 +86,6 @@ void __appExit(void) {
|
||||
/* Cleanup services. */
|
||||
fsdevUnmountAll();
|
||||
fsExit();
|
||||
smExit();
|
||||
}
|
||||
|
||||
static u64 creport_parse_u64(char *s) {
|
||||
@@ -127,10 +123,12 @@ int main(int argc, char **argv) {
|
||||
if (g_Creport.WasSuccessful()) {
|
||||
g_Creport.SaveReport();
|
||||
|
||||
if (R_SUCCEEDED(nsdevInitialize())) {
|
||||
nsdevTerminateProcess(crashed_pid);
|
||||
nsdevExit();
|
||||
}
|
||||
DoWithSmSession([&]() {
|
||||
if (R_SUCCEEDED(nsdevInitialize())) {
|
||||
nsdevTerminateProcess(crashed_pid);
|
||||
nsdevExit();
|
||||
}
|
||||
});
|
||||
|
||||
/* Don't fatal if we have extra info. */
|
||||
if (kernelAbove500()) {
|
||||
|
||||
Reference in New Issue
Block a user