stratosphere: only hold sm sessions open when needed
This commit is contained in:
@@ -94,19 +94,20 @@ Result ContentManagement::MountCode(u64 tid, FsStorageId sid) {
|
||||
}
|
||||
|
||||
/* Always re-initialize fsp-ldr, in case it's closed */
|
||||
if (R_FAILED(rc = fsldrInitialize())) {
|
||||
DoWithSmSession([&]() {
|
||||
rc = fsldrInitialize();
|
||||
});
|
||||
if (R_FAILED(rc)) {
|
||||
return rc;
|
||||
}
|
||||
ON_SCOPE_EXIT { fsldrExit(); };
|
||||
|
||||
if (R_FAILED(rc = fsldrOpenCodeFileSystem(tid, path, &g_CodeFileSystem))) {
|
||||
fsldrExit();
|
||||
return rc;
|
||||
}
|
||||
|
||||
fsdevMountDevice("code", g_CodeFileSystem);
|
||||
TryMountHblNspOnSd();
|
||||
|
||||
fsldrExit();
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -372,17 +373,21 @@ void ContentManagement::RefreshConfigurationData() {
|
||||
void ContentManagement::TryMountSdCard() {
|
||||
/* Mount SD card, if psc, bus, and pcv have been created. */
|
||||
if (!g_has_initialized_fs_dev && HasCreatedTitle(TitleId_Psc) && HasCreatedTitle(TitleId_Bus) && HasCreatedTitle(TitleId_Pcv)) {
|
||||
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])))) {
|
||||
return;
|
||||
} else {
|
||||
svcCloseHandle(tmp_hnd);
|
||||
bool can_mount = true;
|
||||
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])))) {
|
||||
can_mount = false;
|
||||
break;
|
||||
} else {
|
||||
svcCloseHandle(tmp_hnd);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (R_SUCCEEDED(fsdevMountSdmc())) {
|
||||
if (can_mount && R_SUCCEEDED(fsdevMountSdmc())) {
|
||||
g_has_initialized_fs_dev = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <switch.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -24,13 +24,19 @@ Result HidManagement::GetKeysHeld(u64 *keys) {
|
||||
if (!ContentManagement::HasCreatedTitle(TitleId_Hid)) {
|
||||
return MAKERESULT(Module_Libnx, LibnxError_InitFail_HID);
|
||||
}
|
||||
|
||||
if (!serviceIsActive(hidGetSessionService()) && R_FAILED(hidInitialize())) {
|
||||
return MAKERESULT(Module_Libnx, LibnxError_InitFail_HID);
|
||||
|
||||
if (!serviceIsActive(hidGetSessionService())) {
|
||||
Result rc;
|
||||
DoWithSmSession([&]() {
|
||||
rc = hidInitialize();
|
||||
});
|
||||
if (R_FAILED(rc)) {
|
||||
return MAKERESULT(Module_Libnx, LibnxError_InitFail_HID);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
hidScanInput();
|
||||
*keys = hidKeysHeld(CONTROLLER_P1_AUTO);
|
||||
|
||||
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
@@ -36,7 +36,7 @@ extern "C" {
|
||||
#define INNER_HEAP_SIZE 0x30000
|
||||
size_t nx_inner_heap_size = INNER_HEAP_SIZE;
|
||||
char nx_inner_heap[INNER_HEAP_SIZE];
|
||||
|
||||
|
||||
void __libnx_initheap(void);
|
||||
void __appInit(void);
|
||||
void __appExit(void);
|
||||
@@ -68,30 +68,28 @@ void __libnx_initheap(void) {
|
||||
|
||||
void __appInit(void) {
|
||||
Result rc;
|
||||
|
||||
|
||||
SetFirmwareVersionForLibnx();
|
||||
|
||||
/* Initialize services we need (TODO: SPL) */
|
||||
rc = smInitialize();
|
||||
if (R_FAILED(rc)) {
|
||||
std::abort();
|
||||
}
|
||||
|
||||
rc = fsInitialize();
|
||||
if (R_FAILED(rc)) {
|
||||
std::abort();
|
||||
}
|
||||
|
||||
rc = lrInitialize();
|
||||
if (R_FAILED(rc)) {
|
||||
std::abort();
|
||||
}
|
||||
|
||||
rc = fsldrInitialize();
|
||||
if (R_FAILED(rc)) {
|
||||
std::abort();
|
||||
}
|
||||
|
||||
DoWithSmSession([&]() {
|
||||
rc = fsInitialize();
|
||||
if (R_FAILED(rc)) {
|
||||
std::abort();
|
||||
}
|
||||
|
||||
rc = lrInitialize();
|
||||
if (R_FAILED(rc)) {
|
||||
std::abort();
|
||||
}
|
||||
|
||||
rc = fsldrInitialize();
|
||||
if (R_FAILED(rc)) {
|
||||
std::abort();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
CheckAtmosphereVersion(CURRENT_ATMOSPHERE_VERSION);
|
||||
}
|
||||
|
||||
@@ -101,7 +99,6 @@ void __appExit(void) {
|
||||
fsldrExit();
|
||||
lrExit();
|
||||
fsExit();
|
||||
smExit();
|
||||
}
|
||||
|
||||
struct LoaderServerOptions {
|
||||
@@ -124,12 +121,12 @@ int main(int argc, char **argv)
|
||||
/* On 1.0.0-2.3.0, Loader services ldr:ro instead of ro. */
|
||||
server_manager->AddWaitable(new ServiceServer<RelocatableObjectsService>("ldr:ro", 0x20));
|
||||
}
|
||||
|
||||
|
||||
/* Loop forever, servicing our services. */
|
||||
server_manager->Process();
|
||||
|
||||
|
||||
delete server_manager;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user