1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-12-23 02:42:09 +00:00

Loader: Add support for exefs redirection to code nsp on SD.

This commit is contained in:
Michael Scire 2018-07-29 16:35:43 -07:00
parent 44e2412ae6
commit 3a2520a3b7
4 changed files with 34 additions and 5 deletions

View file

@ -20,6 +20,10 @@ Result ContentManagement::MountCode(u64 tid, FsStorageId sid) {
TryMountSdCard();
}
if (kernelAbove200() && g_has_initialized_fs_dev && R_SUCCEEDED(MountCodeNspOnSd(tid))) {
return 0x0;
}
if (R_FAILED(rc = ResolveContentPath(path, tid, sid))) {
return rc;
@ -53,6 +57,18 @@ Result ContentManagement::UnmountCode() {
return 0;
}
Result ContentManagement::MountCodeNspOnSd(u64 tid) {
char path[FS_MAX_PATH+1] = {0};
snprintf(path, FS_MAX_PATH, "sdmc:/atmosphere/titles/%016lx/exefs.nsp", tid);
Result rc = fsOpenFileSystemWithId(&g_CodeFileSystem, 0, FsFileSystemType_ApplicationPackage, path);
if (R_SUCCEEDED(rc)) {
fsdevMountDevice("code", g_CodeFileSystem);
}
return rc;
}
Result ContentManagement::MountCodeForTidSid(Registration::TidSid *tid_sid) {
return MountCode(tid_sid->title_id, tid_sid->storage_id);
}

View file

@ -6,6 +6,7 @@
class ContentManagement {
public:
static Result MountCode(u64 tid, FsStorageId sid);
static Result MountCodeNspOnSd(u64 tid);
static Result UnmountCode();
static Result MountCodeForTidSid(Registration::TidSid *tid_sid);

View file

@ -93,6 +93,7 @@ Result ProcessCreation::CreateProcess(Handle *out_process_h, u64 index, char *nc
Registration::Process *target_process;
Handle process_h = 0;
u64 process_id = 0;
bool mounted_code = false;
Result rc;
/* Get the process from the registration queue. */
@ -107,6 +108,11 @@ Result ProcessCreation::CreateProcess(Handle *out_process_h, u64 index, char *nc
if (R_FAILED(rc)) {
return rc;
}
mounted_code = true;
} else {
if (R_SUCCEEDED(ContentManagement::MountCodeNspOnSd(target_process->tid_sid.title_id))) {
mounted_code = true;
}
}
/* Load the process's NPDM. */
@ -193,11 +199,13 @@ Result ProcessCreation::CreateProcess(Handle *out_process_h, u64 index, char *nc
rc = 0;
CREATE_PROCESS_END:
if (mounted_code) {
if (R_SUCCEEDED(rc) && target_process->tid_sid.storage_id != FsStorageId_None) {
rc = ContentManagement::UnmountCode();
} else {
ContentManagement::UnmountCode();
}
}
if (R_SUCCEEDED(rc)) {
*out_process_h = process_h;
} else {

View file

@ -111,17 +111,21 @@ std::tuple<Result> ProcessManagerService::unregister_title(u64 index) {
Result ProcessManagerService::populate_program_info_buffer(ProcessManagerService::ProgramInfo *out, Registration::TidSid *tid_sid) {
NpdmUtils::NpdmInfo info;
Result rc;
bool mounted_code = false;
if (tid_sid->storage_id != FsStorageId_None) {
rc = ContentManagement::MountCodeForTidSid(tid_sid);
if (R_FAILED(rc)) {
return rc;
}
mounted_code = true;
} else if (R_SUCCEEDED(ContentManagement::MountCodeNspOnSd(tid_sid->title_id))) {
mounted_code = true;
}
rc = NpdmUtils::LoadNpdm(tid_sid->title_id, &info);
if (tid_sid->storage_id != FsStorageId_None) {
if (mounted_code) {
ContentManagement::UnmountCode();
}