mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-12-22 18:32:05 +00:00
ldr: optimize memory usage for tracking system programs
This commit is contained in:
parent
6eee3f5fe7
commit
08d9de6907
1 changed files with 30 additions and 2 deletions
|
@ -22,15 +22,43 @@ namespace ams::ldr {
|
|||
/* Global cache. */
|
||||
std::set<u64> g_launched_programs;
|
||||
|
||||
constexpr size_t NumSystemProgramIds = ncm::SystemProgramId::End.value - ncm::SystemProgramId::Start.value + 1;
|
||||
static_assert(util::IsPowerOfTwo(NumSystemProgramIds));
|
||||
static_assert(util::IsAligned(NumSystemProgramIds, BITSIZEOF(u64)));
|
||||
|
||||
bool IsTrackableSystemProgramId(ncm::ProgramId program_id) {
|
||||
return ncm::SystemProgramId::Start <= program_id && program_id <= ncm::SystemProgramId::End;
|
||||
}
|
||||
|
||||
u64 g_system_launch_records[NumSystemProgramIds / BITSIZEOF(u64)];
|
||||
|
||||
void SetLaunchedSystemProgram(ncm::SystemProgramId program_id) {
|
||||
const u64 val = program_id.value - ncm::SystemProgramId::Start.value;
|
||||
g_system_launch_records[val / BITSIZEOF(u64)] |= (1ul << (val % BITSIZEOF(u64)));
|
||||
}
|
||||
|
||||
bool HasLaunchedSystemProgram(ncm::SystemProgramId program_id) {
|
||||
const u64 val = program_id.value - ncm::SystemProgramId::Start.value;
|
||||
return (g_system_launch_records[val / BITSIZEOF(u64)] & (1ul << (val % BITSIZEOF(u64)))) != 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Launch Record API. */
|
||||
bool HasLaunchedProgram(ncm::ProgramId program_id) {
|
||||
return g_launched_programs.find(static_cast<u64>(program_id)) != g_launched_programs.end();
|
||||
if (IsTrackableSystemProgramId(program_id)) {
|
||||
return HasLaunchedSystemProgram(ncm::SystemProgramId{program_id.value});
|
||||
} else {
|
||||
return g_launched_programs.find(static_cast<u64>(program_id)) != g_launched_programs.end();
|
||||
}
|
||||
}
|
||||
|
||||
void SetLaunchedProgram(ncm::ProgramId program_id) {
|
||||
g_launched_programs.insert(static_cast<u64>(program_id));
|
||||
if (IsTrackableSystemProgramId(program_id)) {
|
||||
SetLaunchedSystemProgram(ncm::SystemProgramId{program_id.value});
|
||||
} else {
|
||||
g_launched_programs.insert(static_cast<u64>(program_id));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue