From 41f5b39f6b07fe0b2e54429458478a9caf3acabc Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Fri, 10 May 2019 03:25:07 -0700 Subject: [PATCH] stratosphere: stop using kernelAbove --- .../creport/source/creport_crash_report.cpp | 10 ++++----- stratosphere/creport/source/creport_main.cpp | 2 +- .../dmnt_cheat_debug_events_manager.cpp | 2 +- .../dmnt/source/dmnt_cheat_manager.cpp | 4 ++-- stratosphere/loader/source/ldr_map.cpp | 2 +- stratosphere/loader/source/ldr_npdm.cpp | 4 ++-- stratosphere/loader/source/ldr_nso.cpp | 2 +- .../loader/source/ldr_process_creation.cpp | 8 +++---- stratosphere/pm/source/pm_registration.cpp | 22 +++++++++---------- stratosphere/pm/source/pm_registration.hpp | 10 ++++----- stratosphere/sm/source/sm_registration.cpp | 2 +- 11 files changed, 34 insertions(+), 34 deletions(-) diff --git a/stratosphere/creport/source/creport_crash_report.cpp b/stratosphere/creport/source/creport_crash_report.cpp index e13982f4a..1e389a3ad 100644 --- a/stratosphere/creport/source/creport_crash_report.cpp +++ b/stratosphere/creport/source/creport_crash_report.cpp @@ -101,7 +101,7 @@ void CrashReport::ProcessExceptions() { void CrashReport::HandleAttachProcess(DebugEventInfo &d) { this->process_info = d.info.attach_process; - if (kernelAbove500() && IsApplication()) { + if ((GetRuntimeFirmwareVersion() >= FirmwareVersion_500) && IsApplication()) { /* Parse out user data. */ u64 address = this->process_info.user_exception_context_address; u64 userdata_address = 0; @@ -155,7 +155,7 @@ void CrashReport::HandleException(DebugEventInfo &d) { case DebugExceptionType::UserBreak: this->result = ResultCreportUserBreak; /* Try to parse out the user break result. */ - if (kernelAbove500()) { + if ((GetRuntimeFirmwareVersion() >= FirmwareVersion_500)) { Result user_result = 0; if (IsAddressReadable(d.info.exception.specific.user_break.address, sizeof(user_result))) { svcReadDebugProcessMemory(&user_result, this->debug_handle, d.info.exception.specific.user_break.address, sizeof(user_result)); @@ -186,7 +186,7 @@ void CrashReport::HandleException(DebugEventInfo &d) { void CrashReport::ProcessDyingMessage() { /* Dying message is only stored starting in 5.0.0. */ - if (!kernelAbove500()) { + if ((GetRuntimeFirmwareVersion() < FirmwareVersion_500)) { return; } @@ -318,7 +318,7 @@ void CrashReport::SaveToFile(FILE *f_report) { fprintf(f_report, " Title ID: %016lx\n", this->process_info.title_id); fprintf(f_report, " Process ID: %016lx\n", this->process_info.process_id); fprintf(f_report, " Process Flags: %08x\n", this->process_info.flags); - if (kernelAbove500()) { + if ((GetRuntimeFirmwareVersion() >= FirmwareVersion_500)) { fprintf(f_report, " User Exception Address: %s\n", this->code_list.GetFormattedAddressString(this->process_info.user_exception_context_address)); } @@ -350,7 +350,7 @@ void CrashReport::SaveToFile(FILE *f_report) { fprintf(f_report, "Crashed Thread Info:\n"); this->crashed_thread_info.SaveToFile(f_report); - if (kernelAbove500()) { + if ((GetRuntimeFirmwareVersion() >= FirmwareVersion_500)) { if (this->dying_message_size) { fprintf(f_report, "Dying Message Info:\n"); fprintf(f_report, " Address: 0x%s\n", this->code_list.GetFormattedAddressString(this->dying_message_address)); diff --git a/stratosphere/creport/source/creport_main.cpp b/stratosphere/creport/source/creport_main.cpp index 6d3423c18..a2270edc2 100644 --- a/stratosphere/creport/source/creport_main.cpp +++ b/stratosphere/creport/source/creport_main.cpp @@ -131,7 +131,7 @@ int main(int argc, char **argv) { }); /* Don't fatal if we have extra info. */ - if (kernelAbove500()) { + if ((GetRuntimeFirmwareVersion() >= FirmwareVersion_500)) { if (g_Creport.IsApplication()) { return 0; } diff --git a/stratosphere/dmnt/source/dmnt_cheat_debug_events_manager.cpp b/stratosphere/dmnt/source/dmnt_cheat_debug_events_manager.cpp index 0bb0a2abc..1a9d4c03a 100644 --- a/stratosphere/dmnt/source/dmnt_cheat_debug_events_manager.cpp +++ b/stratosphere/dmnt/source/dmnt_cheat_debug_events_manager.cpp @@ -39,7 +39,7 @@ void DmntCheatDebugEventsManager::PerCoreThreadFunc(void *arg) { } /* Continue the process, if needed. */ - if (kernelAbove300()) { + if ((GetRuntimeFirmwareVersion() >= FirmwareVersion_300)) { svcContinueDebugEvent(debug_handle, 5, nullptr, 0); } else { svcLegacyContinueDebugEvent(debug_handle, 5, 0); diff --git a/stratosphere/dmnt/source/dmnt_cheat_manager.cpp b/stratosphere/dmnt/source/dmnt_cheat_manager.cpp index 42cb5c48f..14077a702 100644 --- a/stratosphere/dmnt/source/dmnt_cheat_manager.cpp +++ b/stratosphere/dmnt/source/dmnt_cheat_manager.cpp @@ -874,7 +874,7 @@ Result DmntCheatManager::ForceOpenCheatProcess() { /* Get memory extents. */ PopulateMemoryExtents(&g_cheat_process_metadata.heap_extents, proc_h, 4, 5); PopulateMemoryExtents(&g_cheat_process_metadata.alias_extents, proc_h, 2, 3); - if (kernelAbove200()) { + if ((GetRuntimeFirmwareVersion() >= FirmwareVersion_200)) { PopulateMemoryExtents(&g_cheat_process_metadata.address_space_extents, proc_h, 12, 13); } else { g_cheat_process_metadata.address_space_extents.base = 0x08000000UL; @@ -962,7 +962,7 @@ void DmntCheatManager::OnNewApplicationLaunch() { /* Get memory extents. */ PopulateMemoryExtents(&g_cheat_process_metadata.heap_extents, proc_h, 4, 5); PopulateMemoryExtents(&g_cheat_process_metadata.alias_extents, proc_h, 2, 3); - if (kernelAbove200()) { + if ((GetRuntimeFirmwareVersion() >= FirmwareVersion_200)) { PopulateMemoryExtents(&g_cheat_process_metadata.address_space_extents, proc_h, 12, 13); } else { g_cheat_process_metadata.address_space_extents.base = 0x08000000UL; diff --git a/stratosphere/loader/source/ldr_map.cpp b/stratosphere/loader/source/ldr_map.cpp index 468a57a0b..e2cd0a48c 100644 --- a/stratosphere/loader/source/ldr_map.cpp +++ b/stratosphere/loader/source/ldr_map.cpp @@ -20,7 +20,7 @@ #include "ldr_map.hpp" Result MapUtils::LocateSpaceForMap(u64 *out, u64 out_size) { - if (kernelAbove200()) { + if ((GetRuntimeFirmwareVersion() >= FirmwareVersion_200)) { return LocateSpaceForMapModern(out, out_size); } else { return LocateSpaceForMapDeprecated(out, out_size); diff --git a/stratosphere/loader/source/ldr_npdm.cpp b/stratosphere/loader/source/ldr_npdm.cpp index 912dc772f..76634574f 100644 --- a/stratosphere/loader/source/ldr_npdm.cpp +++ b/stratosphere/loader/source/ldr_npdm.cpp @@ -208,7 +208,7 @@ Result NpdmUtils::LoadNpdm(u64 tid, NpdmInfo *out) { if (ContentManagement::ShouldOverrideContentsWithHBL(tid) && R_SUCCEEDED(LoadNpdmInternal(OpenNpdmFromExeFS(), &g_original_npdm_cache))) { NpdmInfo *original_info = &g_original_npdm_cache.info; /* Fix pool partition. */ - if (kernelAbove500()) { + if ((GetRuntimeFirmwareVersion() >= FirmwareVersion_500)) { info->acid->flags = (info->acid->flags & 0xFFFFFFC3) | (original_info->acid->flags & 0x0000003C); } /* Fix application type. */ @@ -506,7 +506,7 @@ u32 NpdmUtils::GetApplicationType(u32 *caps, size_t num_caps) { } } /* After 1.0.0, allow_debug is used as bit 4. */ - if (kernelAbove200() && (caps[i] & 0x1FFFF) == 0xFFFF) { + if ((GetRuntimeFirmwareVersion() >= FirmwareVersion_200) && (caps[i] & 0x1FFFF) == 0xFFFF) { application_type |= (caps[i] >> 15) & 4; } } diff --git a/stratosphere/loader/source/ldr_nso.cpp b/stratosphere/loader/source/ldr_nso.cpp index 8104e9353..08cef21ce 100644 --- a/stratosphere/loader/source/ldr_nso.cpp +++ b/stratosphere/loader/source/ldr_nso.cpp @@ -191,7 +191,7 @@ Result NsoUtils::CalculateNsoLoadExtents(u32 addspace_type, u32 args_size, NsoLo /* Calculate ASLR extents for address space type. */ u64 addspace_start, addspace_size; - if (kernelAbove200()) { + if ((GetRuntimeFirmwareVersion() >= FirmwareVersion_200)) { switch (addspace_type & 0xE) { case 0: case 4: diff --git a/stratosphere/loader/source/ldr_process_creation.cpp b/stratosphere/loader/source/ldr_process_creation.cpp index cf86d97fe..695e15c9b 100644 --- a/stratosphere/loader/source/ldr_process_creation.cpp +++ b/stratosphere/loader/source/ldr_process_creation.cpp @@ -64,7 +64,7 @@ Result ProcessCreation::InitializeProcessInfo(NpdmUtils::NpdmInfo *npdm, Handle } /* 3.0.0+ System Resource Size. */ - if (kernelAbove300()) { + if ((GetRuntimeFirmwareVersion() >= FirmwareVersion_300)) { if (npdm->header->system_resource_size & 0x1FFFFF) { return ResultLoaderInvalidSize; } @@ -72,7 +72,7 @@ Result ProcessCreation::InitializeProcessInfo(NpdmUtils::NpdmInfo *npdm, Handle if ((out_proc_info->process_flags & 6) == 0) { return ResultLoaderInvalidMeta; } - if (!(((application_type & 3) == 1) || (kernelAbove600() && (application_type & 3) == 2))) { + if (!(((application_type & 3) == 1) || ((GetRuntimeFirmwareVersion() >= FirmwareVersion_600) && (application_type & 3) == 2))) { return ResultLoaderInvalidMeta; } if (npdm->header->system_resource_size > 0x1FE00000) { @@ -85,7 +85,7 @@ Result ProcessCreation::InitializeProcessInfo(NpdmUtils::NpdmInfo *npdm, Handle } /* 5.0.0+ Pool Partition. */ - if (kernelAbove500()) { + if ((GetRuntimeFirmwareVersion() >= FirmwareVersion_500)) { u32 pool_partition_id = (npdm->acid->flags >> 2) & 0xF; switch (pool_partition_id) { case 0: /* Application. */ @@ -206,7 +206,7 @@ Result ProcessCreation::CreateProcess(Handle *out_process_h, u64 index, char *nc /* Update the list of registered processes with the new process. */ svcGetProcessId(&process_id, process_h); bool is_64_bit_addspace; - if (kernelAbove200()) { + if ((GetRuntimeFirmwareVersion() >= FirmwareVersion_200)) { is_64_bit_addspace = (((npdm_info.header->mmu_flags >> 1) & 5) | 2) == 3; } else { is_64_bit_addspace = (npdm_info.header->mmu_flags & 0xE) == 0x2; diff --git a/stratosphere/pm/source/pm_registration.cpp b/stratosphere/pm/source/pm_registration.cpp index 9a6cdcdeb..5c655fa44 100644 --- a/stratosphere/pm/source/pm_registration.cpp +++ b/stratosphere/pm/source/pm_registration.cpp @@ -120,13 +120,13 @@ void Registration::HandleProcessLaunch() { if (program_info.application_type & 1) { new_process.flags |= PROCESSFLAGS_APPLICATION; } - if (kernelAbove200() && LAUNCHFLAGS_NOTIYDEBUGSPECIAL(launch_flags) && (program_info.application_type & 4)) { + if ((GetRuntimeFirmwareVersion() >= FirmwareVersion_200) && LAUNCHFLAGS_NOTIYDEBUGSPECIAL(launch_flags) && (program_info.application_type & 4)) { new_process.flags |= PROCESSFLAGS_NOTIFYDEBUGSPECIAL; } if (LAUNCHFLAGS_NOTIFYWHENEXITED(launch_flags)) { new_process.flags |= PROCESSFLAGS_NOTIFYWHENEXITED; } - if (LAUNCHFLAGS_NOTIFYDEBUGEVENTS(launch_flags) && (!kernelAbove200() || (program_info.application_type & 4))) { + if (LAUNCHFLAGS_NOTIFYDEBUGEVENTS(launch_flags) && (GetRuntimeFirmwareVersion() < FirmwareVersion_200 || (program_info.application_type & 4))) { new_process.flags |= PROCESSFLAGS_NOTIFYDEBUGEVENTS; } @@ -253,7 +253,7 @@ Result Registration::HandleSignaledProcess(std::shared_ptrflags |= PROCESSFLAGS_DEBUGEVENTPENDING; g_process_event->Signal(); } - if (kernelAbove200() && process->flags & PROCESSFLAGS_NOTIFYDEBUGSPECIAL) { + if ((GetRuntimeFirmwareVersion() >= FirmwareVersion_200) && process->flags & PROCESSFLAGS_NOTIFYDEBUGSPECIAL) { process->flags &= ~(PROCESSFLAGS_NOTIFYDEBUGSPECIAL | PROCESSFLAGS_DEBUGDETACHED); process->flags |= PROCESSFLAGS_DEBUGDETACHED; } @@ -270,7 +270,7 @@ Result Registration::HandleSignaledProcess(std::shared_ptrflags & PROCESSFLAGS_NOTIFYWHENEXITED && !kernelAbove500()) { + if (process->flags & PROCESSFLAGS_NOTIFYWHENEXITED && GetRuntimeFirmwareVersion() < FirmwareVersion_500) { g_process_event->Signal(); } else { FinalizeExitedProcess(process); @@ -293,7 +293,7 @@ void Registration::FinalizeExitedProcess(std::shared_ptr { std::scoped_lock lk(GetProcessList()); - signal_debug_process_5x = kernelAbove500() && process->flags & PROCESSFLAGS_NOTIFYWHENEXITED; + signal_debug_process_5x = (GetRuntimeFirmwareVersion() >= FirmwareVersion_500) && process->flags & PROCESSFLAGS_NOTIFYWHENEXITED; /* Unregister with FS. */ if (R_FAILED(fsprUnregisterProgram(process->pid))) { @@ -427,17 +427,17 @@ void Registration::GetProcessEventType(u64 *out_pid, u64 *out_type) { std::scoped_lock lk(GetProcessList()); for (auto &p : g_process_list.processes) { - if (kernelAbove200() && p->state >= ProcessState_Running && p->flags & PROCESSFLAGS_DEBUGDETACHED) { + if ((GetRuntimeFirmwareVersion() >= FirmwareVersion_200) && p->state >= ProcessState_Running && p->flags & PROCESSFLAGS_DEBUGDETACHED) { p->flags &= ~PROCESSFLAGS_DEBUGDETACHED; *out_pid = p->pid; - *out_type = kernelAbove500() ? PROCESSEVENTTYPE_500_DEBUGDETACHED : PROCESSEVENTTYPE_DEBUGDETACHED; + *out_type = (GetRuntimeFirmwareVersion() >= FirmwareVersion_500) ? PROCESSEVENTTYPE_500_DEBUGDETACHED : PROCESSEVENTTYPE_DEBUGDETACHED; return; } if (p->flags & PROCESSFLAGS_DEBUGEVENTPENDING) { u64 old_flags = p->flags; p->flags &= ~PROCESSFLAGS_DEBUGEVENTPENDING; *out_pid = p->pid; - *out_type = kernelAbove500() ? + *out_type = (GetRuntimeFirmwareVersion() >= FirmwareVersion_500) ? ((old_flags & PROCESSFLAGS_DEBUGSUSPENDED) ? PROCESSEVENTTYPE_500_SUSPENDED : PROCESSEVENTTYPE_500_RUNNING) : @@ -448,10 +448,10 @@ void Registration::GetProcessEventType(u64 *out_pid, u64 *out_type) { } if (p->flags & PROCESSFLAGS_CRASHED) { *out_pid = p->pid; - *out_type = kernelAbove500() ? PROCESSEVENTTYPE_500_CRASH : PROCESSEVENTTYPE_CRASH; + *out_type = (GetRuntimeFirmwareVersion() >= FirmwareVersion_500) ? PROCESSEVENTTYPE_500_CRASH : PROCESSEVENTTYPE_CRASH; return; } - if (!kernelAbove500() && p->flags & PROCESSFLAGS_NOTIFYWHENEXITED && p->state == ProcessState_Exited) { + if (GetRuntimeFirmwareVersion() < FirmwareVersion_500 && p->flags & PROCESSFLAGS_NOTIFYWHENEXITED && p->state == ProcessState_Exited) { *out_pid = p->pid; *out_type = PROCESSEVENTTYPE_EXIT; return; @@ -462,7 +462,7 @@ void Registration::GetProcessEventType(u64 *out_pid, u64 *out_type) { *out_type = 0; } - if (kernelAbove500()) { + if ((GetRuntimeFirmwareVersion() >= FirmwareVersion_500)) { std::scoped_lock dead_lk(g_dead_process_list); if (g_dead_process_list.processes.size()) { diff --git a/stratosphere/pm/source/pm_registration.hpp b/stratosphere/pm/source/pm_registration.hpp index b04b4ecbb..57de135e7 100644 --- a/stratosphere/pm/source/pm_registration.hpp +++ b/stratosphere/pm/source/pm_registration.hpp @@ -23,11 +23,11 @@ class ProcessList; #define LAUNCHFLAGS_NOTIFYWHENEXITED(flags) (flags & 1) -#define LAUNCHFLAGS_STARTSUSPENDED(flags) (flags & (kernelAbove500() ? 0x10 : 0x2)) -#define LAUNCHFLAGS_ARGLOW(flags) (kernelAbove500() ? ((flags & 0x14) != 0x10) : (kernelAbove200() ? ((flags & 0x6) != 0x2) : ((flags >> 2) & 1))) -#define LAUNCHFLAGS_ARGHIGH(flags) ((flags & (kernelAbove500() ? 0x20 : 0x8)) ? 2 : 0) -#define LAUNCHFLAGS_NOTIFYDEBUGEVENTS(flags) (flags & (kernelAbove500() ? 0x8 : 0x10)) -#define LAUNCHFLAGS_NOTIYDEBUGSPECIAL(flags) (flags & (kernelAbove500() ? 0x2 : (kernelAbove200() ? 0x20 : 0x0))) +#define LAUNCHFLAGS_STARTSUSPENDED(flags) (flags & (GetRuntimeFirmwareVersion() >= FirmwareVersion_500 ? 0x10 : 0x2)) +#define LAUNCHFLAGS_ARGLOW(flags) (GetRuntimeFirmwareVersion() >= FirmwareVersion_500 ? ((flags & 0x14) != 0x10) : (GetRuntimeFirmwareVersion() >= FirmwareVersion_200 ? ((flags & 0x6) != 0x2) : ((flags >> 2) & 1))) +#define LAUNCHFLAGS_ARGHIGH(flags) ((flags & (GetRuntimeFirmwareVersion() >= FirmwareVersion_500 ? 0x20 : 0x8)) ? 2 : 0) +#define LAUNCHFLAGS_NOTIFYDEBUGEVENTS(flags) (flags & (GetRuntimeFirmwareVersion() >= FirmwareVersion_500 ? 0x8 : 0x10)) +#define LAUNCHFLAGS_NOTIYDEBUGSPECIAL(flags) (flags & (GetRuntimeFirmwareVersion() >= FirmwareVersion_500 ? 0x2 : (GetRuntimeFirmwareVersion() >= FirmwareVersion_200 ? 0x20 : 0x0))) // none of these names are official or authoritative in any way enum { diff --git a/stratosphere/sm/source/sm_registration.cpp b/stratosphere/sm/source/sm_registration.cpp index eead4cc7d..7b0ea7200 100644 --- a/stratosphere/sm/source/sm_registration.cpp +++ b/stratosphere/sm/source/sm_registration.cpp @@ -163,7 +163,7 @@ void Registration::CacheInitialProcessIdLimits() { if (g_determined_initial_process_ids) { return; } - if (kernelAbove500()) { + if ((GetRuntimeFirmwareVersion() >= FirmwareVersion_500)) { svcGetSystemInfo(&g_initial_process_id_low, 2, 0, 0); svcGetSystemInfo(&g_initial_process_id_high, 2, 0, 1); } else {