mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-11-15 11:33:32 +01:00
pm: Don't launch titles twice due to boot2.flag
This commit is contained in:
parent
907f6fa72d
commit
8a92a63a64
2
Makefile
2
Makefile
@ -42,6 +42,8 @@ dist: all
|
||||
mkdir -p atmosphere-$(AMSVER)/atmosphere/titles/0100000000000036
|
||||
mkdir -p atmosphere-$(AMSVER)/atmosphere/titles/0100000000000034
|
||||
mkdir -p atmosphere-$(AMSVER)/atmosphere/titles/0100000000000032
|
||||
mkdir -p atmosphere-$(AMSVER)/atmosphere/titles/010000000000000D
|
||||
mkdir -p atmosphere-$(AMSVER)/atmosphere/titles/0100000000000007
|
||||
cp fusee/fusee-secondary/fusee-secondary.bin atmosphere-$(AMSVER)/atmosphere/fusee-secondary.bin
|
||||
cp common/defaults/BCT.ini atmosphere-$(AMSVER)/atmosphere/BCT.ini
|
||||
cp common/defaults/loader.ini atmosphere-$(AMSVER)/atmosphere/loader.ini
|
||||
|
@ -26,6 +26,8 @@
|
||||
#include "pm_boot2.hpp"
|
||||
#include "pm_registration.hpp"
|
||||
|
||||
static std::vector<Boot2KnownTitleId> g_launched_titles;
|
||||
|
||||
static bool IsHexadecimal(const char *str) {
|
||||
while (*str) {
|
||||
if (isxdigit(*str)) {
|
||||
@ -37,22 +39,34 @@ static bool IsHexadecimal(const char *str) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HasLaunchedTitle(Boot2KnownTitleId title_id) {
|
||||
return std::find(g_launched_titles.begin(), g_launched_titles.end(), title_id) != g_launched_titles.end();
|
||||
}
|
||||
|
||||
static void SetLaunchedTitle(Boot2KnownTitleId title_id) {
|
||||
g_launched_titles.push_back(title_id);
|
||||
}
|
||||
|
||||
static void ClearLaunchedTitles() {
|
||||
g_launched_titles.clear();
|
||||
}
|
||||
|
||||
static void LaunchTitle(Boot2KnownTitleId title_id, FsStorageId storage_id, u32 launch_flags, u64 *pid) {
|
||||
u64 local_pid;
|
||||
u64 local_pid = 0;
|
||||
|
||||
Result rc = Registration::LaunchProcessByTidSid(Registration::TidSid{(u64)title_id, storage_id}, launch_flags, &local_pid);
|
||||
switch (rc) {
|
||||
case 0xCE01:
|
||||
/* Out of resource! */
|
||||
/* TODO: Panic(). */
|
||||
std::abort();
|
||||
break;
|
||||
case 0xDE01:
|
||||
/* Out of memory! */
|
||||
/* TODO: Panic(). */
|
||||
std::abort();
|
||||
break;
|
||||
case 0xD001:
|
||||
/* Limit Reached! */
|
||||
/* TODO: Panic(). */
|
||||
std::abort();
|
||||
break;
|
||||
default:
|
||||
/* We don't care about other issues. */
|
||||
@ -61,6 +75,8 @@ static void LaunchTitle(Boot2KnownTitleId title_id, FsStorageId storage_id, u32
|
||||
if (pid) {
|
||||
*pid = local_pid;
|
||||
}
|
||||
|
||||
SetLaunchedTitle(title_id);
|
||||
}
|
||||
|
||||
static bool ShouldForceMaintenanceMode() {
|
||||
@ -178,7 +194,10 @@ void EmbeddedBoot2::Main() {
|
||||
if (titles_dir != NULL) {
|
||||
while ((ent = readdir(titles_dir)) != NULL) {
|
||||
if (strlen(ent->d_name) == 0x10 && IsHexadecimal(ent->d_name)) {
|
||||
u64 title_id = strtoul(ent->d_name, NULL, 16);
|
||||
Boot2KnownTitleId title_id = (Boot2KnownTitleId)strtoul(ent->d_name, NULL, 16);
|
||||
if (HasLaunchedTitle(title_id)) {
|
||||
continue;
|
||||
}
|
||||
char title_path[FS_MAX_PATH] = {0};
|
||||
strcpy(title_path, "sdmc:/atmosphere/titles/");
|
||||
strcat(title_path, ent->d_name);
|
||||
@ -186,7 +205,7 @@ void EmbeddedBoot2::Main() {
|
||||
FILE *f_flag = fopen(title_path, "rb");
|
||||
if (f_flag != NULL) {
|
||||
fclose(f_flag);
|
||||
LaunchTitle((Boot2KnownTitleId)title_id, FsStorageId_None, 0, NULL);
|
||||
LaunchTitle(title_id, FsStorageId_None, 0, NULL);
|
||||
} else {
|
||||
/* TODO: Deprecate this in the future. */
|
||||
memset(title_path, 0, FS_MAX_PATH);
|
||||
@ -196,7 +215,7 @@ void EmbeddedBoot2::Main() {
|
||||
f_flag = fopen(title_path, "rb");
|
||||
if (f_flag != NULL) {
|
||||
fclose(f_flag);
|
||||
LaunchTitle((Boot2KnownTitleId)title_id, FsStorageId_None, 0, NULL);
|
||||
LaunchTitle(title_id, FsStorageId_None, 0, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -204,6 +223,9 @@ void EmbeddedBoot2::Main() {
|
||||
closedir(titles_dir);
|
||||
}
|
||||
|
||||
/* Free the memory used to track what boot2 launches. */
|
||||
ClearLaunchedTitles();
|
||||
|
||||
/* We no longer need the SD card. */
|
||||
fsdevUnmountAll();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user