Atmosphere/stratosphere/loader/source/ldr_launch_record.cpp

81 lines
2.6 KiB
C++
Raw Normal View History

2019-06-26 22:46:19 +00:00
/*
* Copyright (c) Atmosphère-NX
2019-06-26 22:46:19 +00:00
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* 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 <stratosphere.hpp>
2019-06-26 22:46:19 +00:00
#include "ldr_launch_record.hpp"
namespace ams::ldr {
2019-06-26 22:46:19 +00:00
namespace {
2021-01-18 06:03:26 +00:00
static constexpr size_t MaxBootPrograms = 0x50;
constinit std::array<ncm::ProgramId, MaxBootPrograms> g_launched_boot_programs = [] {
std::array<ncm::ProgramId, MaxBootPrograms> arr = {};
for (size_t i = 0; i < MaxBootPrograms; ++i) {
arr[i] = ncm::InvalidProgramId;
}
return arr;
}();
constinit bool g_boot_programs_done = false;
bool HasLaunchedBootProgramImpl(ncm::ProgramId program_id) {
for (const auto &launched : g_launched_boot_programs) {
if (launched == program_id) {
return true;
}
}
return false;
}
void SetLaunchedBootProgramImpl(ncm::ProgramId program_id) {
for (size_t i = 0; i < MaxBootPrograms; ++i) {
if (g_launched_boot_programs[i] == ncm::InvalidProgramId) {
g_launched_boot_programs[i] = program_id;
return;
2021-01-18 06:03:26 +00:00
}
}
AMS_ABORT("Too many boot programs");
}
2019-06-26 22:46:19 +00:00
}
/* Launch Record API. */
2021-01-18 06:03:26 +00:00
bool HasLaunchedBootProgram(ncm::ProgramId program_id) {
return HasLaunchedBootProgramImpl(program_id);
2019-06-26 22:46:19 +00:00
}
2021-01-18 06:03:26 +00:00
void SetLaunchedBootProgram(ncm::ProgramId program_id) {
if (!g_boot_programs_done) {
SetLaunchedBootProgramImpl(program_id);
if (program_id == ncm::SystemAppletId::Qlaunch) {
g_boot_programs_done = true;
}
}
2019-06-26 22:46:19 +00:00
}
}
/* Loader wants to override this libstratosphere function, which is weakly linked. */
/* This is necessary to prevent circular dependencies. */
namespace ams::pm::info {
2019-06-26 22:46:19 +00:00
2021-01-18 06:03:26 +00:00
Result HasLaunchedBootProgram(bool *out, ncm::ProgramId program_id) {
*out = ldr::HasLaunchedBootProgram(program_id);
return ResultSuccess();
2019-06-26 22:46:19 +00:00
}
}