1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-11-10 06:01:52 +00:00

strat: use TitleId defs instead of magics.

This commit is contained in:
Michael Scire 2019-03-28 21:36:08 -07:00
parent 4167dfea14
commit 9427a5cf46
13 changed files with 77 additions and 146 deletions

View file

@ -37,7 +37,7 @@ class BpcMitmService : public IMitmServiceObject {
* - fatal, to simplify payload reboot logic significantly
* - applications, to allow homebrew to take advantage of the feature.
*/
return tid == 0x0100000000000023ull || tid == 0x0100000000000034ull || Utils::IsHblTid(tid);
return tid == TitleId_Am || tid == TitleId_Fatal || TitleIdIsApplication(tid) || Utils::IsHblTid(tid);
}
static void PostProcess(IMitmServiceObject *obj, IpcResponseContext *ctx);

View file

@ -24,7 +24,7 @@ static HosMutex g_boot0_mutex;
static u8 g_boot0_bct_buffer[Boot0Storage::BctEndOffset];
bool Boot0Storage::CanModifyBctPubks() {
return this->title_id != 0x010000000000001FULL;
return this->title_id != TitleId_Ns;
}
Result Boot0Storage::Read(void *_buffer, size_t size, u64 offset) {

View file

@ -177,7 +177,7 @@ Result FsMitmService::OpenBisStorage(Out<std::shared_ptr<IStorageInterface>> out
FsStorage bis_storage;
rc = fsOpenBisStorageFwd(this->forward_service.get(), &bis_storage, bis_partition_id);
if (R_SUCCEEDED(rc)) {
const bool is_sysmodule = this->title_id < 0x0100000000001000ul;
const bool is_sysmodule = TitleIdIsSystem(this->title_id);
const bool has_bis_write_flag = Utils::HasFlag(this->title_id, "bis_write");
const bool has_cal0_read_flag = Utils::HasFlag(this->title_id, "cal_read");
if (bis_partition_id == BisStorageId_Boot0) {

View file

@ -45,7 +45,7 @@ class FsMitmService : public IMitmServiceObject {
if (Utils::HasSdDisableMitMFlag(this->title_id)) {
this->should_override_contents = false;
} else {
this->should_override_contents = (this->title_id >= 0x0100000000010000ULL || Utils::HasSdMitMFlag(this->title_id)) && Utils::HasOverrideButton(this->title_id);
this->should_override_contents = (this->title_id >= TitleId_ApplicationStart || Utils::HasSdMitMFlag(this->title_id)) && Utils::HasOverrideButton(this->title_id);
}
}
@ -59,11 +59,11 @@ class FsMitmService : public IMitmServiceObject {
/* TODO: intercepting everything seems to cause issues with sleep mode, for some reason. */
/* Figure out why, and address it. */
if (tid == 0x0100000000001000ULL) {
if (tid == TitleId_AppletQlaunch) {
has_launched_qlaunch = true;
}
return has_launched_qlaunch || tid == 0x010000000000001FULL || tid >= 0x0100000000010000ULL || Utils::HasSdMitMFlag(tid);
return has_launched_qlaunch || tid == TitleId_Ns || tid >= TitleId_ApplicationStart || Utils::HasSdMitMFlag(tid);
}
static void PostProcess(IMitmServiceObject *obj, IpcResponseContext *ctx);

View file

@ -32,13 +32,13 @@ void VersionManager::Initialize() {
}
/* Mount firmware version data archive. */
if (R_SUCCEEDED(romfsMountFromDataArchive(0x0100000000000809ul, FsStorageId_NandSystem, "809"))) {
ON_SCOPE_EXIT { romfsUnmount("809"); };
if (R_SUCCEEDED(romfsMountFromDataArchive(TitleId_ArchiveSystemVersion, FsStorageId_NandSystem, "sysver"))) {
ON_SCOPE_EXIT { romfsUnmount("sysver"); };
SetSysFirmwareVersion fw_ver;
/* Firmware version file must exist. */
FILE *f = fopen("809:/file", "rb");
FILE *f = fopen("sysver:/file", "rb");
if (f == NULL) {
std::abort();
}
@ -75,7 +75,7 @@ Result VersionManager::GetFirmwareVersion(u64 title_id, SetSysFirmwareVersion *o
VersionManager::Initialize();
/* Report atmosphere string to qlaunch, maintenance and nothing else. */
if (title_id == 0x0100000000001000ULL || title_id == 0x0100000000001015ULL) {
if (title_id == TitleId_AppletQlaunch || title_id == TitleId_AppletMaintenanceMenu) {
*out = g_ams_fw_version;
} else {
*out = g_fw_version;

View file

@ -52,7 +52,7 @@ static HblOverrideConfig g_hbl_override_config = {
.key_combination = KEY_L,
.override_by_default = true
},
.title_id = 0x010000000000100D,
.title_id = TitleId_AppletPhotoViewer,
.override_any_app = false
};
@ -380,11 +380,11 @@ Result Utils::SaveSdFileForAtmosphere(u64 title_id, const char *fn, void *data,
}
bool Utils::IsHblTid(u64 tid) {
return (g_hbl_override_config.override_any_app && IsApplicationTid(tid)) || (tid == g_hbl_override_config.title_id);
return (g_hbl_override_config.override_any_app && TitleIdIsApplication(tid)) || (tid == g_hbl_override_config.title_id);
}
bool Utils::IsWebAppletTid(u64 tid) {
return tid == 0x010000000000100Aul || tid == 0x010000000000100Ful || tid == 0x0100000000001010ul || tid == 0x0100000000001011ul;
return tid == TitleId_AppletWeb || tid == TitleId_AppletOfflineWeb || tid == TitleId_AppletLoginShare || tid == TitleId_AppletWifiWebAuth;
}
bool Utils::HasTitleFlag(u64 tid, const char *flag) {
@ -469,7 +469,7 @@ static bool HasOverrideKey(OverrideKey *cfg) {
bool Utils::HasOverrideButton(u64 tid) {
if ((!IsApplicationTid(tid)) || (!IsSdInitialized())) {
if ((!TitleIdIsApplication(tid)) || (!IsSdInitialized())) {
/* Disable button override disable for non-applications. */
return true;
}

View file

@ -61,7 +61,7 @@ Result ThrowFatalImpl(u32 error, u64 pid, FatalType policy, FatalCpuContext *cpu
/* Get title id. On failure, it'll be zero. */
u64 title_id = 0;
pminfoGetTitleId(&title_id, pid);
ctx.is_creport = title_id == 0x0100000000000036;
ctx.is_creport = title_id == TitleId_Creport;
/* Support for ams creport. TODO: Make this its own command? */
if (ctx.is_creport && !cpu_ctx->is_aarch32 && cpu_ctx->aarch64_ctx.afsr0 != 0) {

@ -1 +1 @@
Subproject commit 4c51a406173066bbc139c41ea39b8886ce299ebb
Subproject commit 5fcc1469c7c514ed4b2e40a4f8128a19b26df9ae

View file

@ -55,7 +55,7 @@ static HblOverrideConfig g_hbl_override_config = {
.key_combination = KEY_R,
.override_by_default = true
},
.title_id = 0x010000000000100D,
.title_id = TitleId_AppletPhotoViewer,
.override_any_app = false
};
@ -371,7 +371,7 @@ void ContentManagement::RefreshConfigurationData() {
void ContentManagement::TryMountSdCard() {
/* Mount SD card, if psc, bus, and pcv have been created. */
if (!g_has_initialized_fs_dev && HasCreatedTitle(0x0100000000000021) && HasCreatedTitle(0x010000000000000A) && HasCreatedTitle(0x010000000000001A)) {
if (!g_has_initialized_fs_dev && HasCreatedTitle(TitleId_Psc) && HasCreatedTitle(TitleId_Bus) && HasCreatedTitle(TitleId_Pcv)) {
Handle tmp_hnd = 0;
static const char * const required_active_services[] = {"pcv", "gpio", "pinmux", "psc:c"};
for (unsigned int i = 0; i < sizeof(required_active_services) / sizeof(required_active_services[0]); i++) {
@ -389,7 +389,7 @@ void ContentManagement::TryMountSdCard() {
}
static bool IsHBLTitleId(u64 tid) {
return ((g_hbl_override_config.override_any_app && IsApplicationTid(tid)) || (tid == g_hbl_override_config.title_id));
return ((g_hbl_override_config.override_any_app && TitleIdIsApplication(tid)) || (tid == g_hbl_override_config.title_id));
}
OverrideKey ContentManagement::GetTitleOverrideKey(u64 tid) {
@ -416,7 +416,7 @@ static bool ShouldOverrideContents(OverrideKey *cfg) {
}
bool ContentManagement::ShouldOverrideContentsWithHBL(u64 tid) {
if (g_mounted_hbl_nsp && tid >= 0x0100000000001000 && HasCreatedTitle(0x0100000000001000)) {
if (g_mounted_hbl_nsp && tid >= TitleId_AppletStart && HasCreatedTitle(TitleId_AppletQlaunch)) {
/* Return whether we should override contents with HBL. */
return IsHBLTitleId(tid) && ShouldOverrideContents(&g_hbl_override_config.override_key);
} else {
@ -427,7 +427,7 @@ bool ContentManagement::ShouldOverrideContentsWithHBL(u64 tid) {
bool ContentManagement::ShouldOverrideContentsWithSD(u64 tid) {
if (g_has_initialized_fs_dev) {
if (tid >= 0x0100000000001000 && HasCreatedTitle(0x0100000000001000)) {
if (tid >= TitleId_AppletStart && HasCreatedTitle(TitleId_AppletQlaunch)) {
/* Check whether we should override with non-HBL. */
OverrideKey title_cfg = GetTitleOverrideKey(tid);
return ShouldOverrideContents(&title_cfg);

View file

@ -21,7 +21,7 @@
#include "ldr_hid.hpp"
Result HidManagement::GetKeysHeld(u64 *keys) {
if (!ContentManagement::HasCreatedTitle(0x0100000000000013)) {
if (!ContentManagement::HasCreatedTitle(TitleId_Hid)) {
return MAKERESULT(Module_Libnx, LibnxError_InitFail_HID);
}

View file

@ -27,7 +27,7 @@
#include "pm_registration.hpp"
#include "pm_boot_mode.hpp"
static std::vector<Boot2KnownTitleId> g_launched_titles;
static std::vector<u64> g_launched_titles;
static bool IsHexadecimal(const char *str) {
while (*str) {
@ -40,11 +40,11 @@ static bool IsHexadecimal(const char *str) {
return true;
}
static bool HasLaunchedTitle(Boot2KnownTitleId title_id) {
static bool HasLaunchedTitle(u64 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) {
static void SetLaunchedTitle(u64 title_id) {
g_launched_titles.push_back(title_id);
}
@ -52,7 +52,7 @@ static void ClearLaunchedTitles() {
g_launched_titles.clear();
}
static void LaunchTitle(Boot2KnownTitleId title_id, FsStorageId storage_id, u32 launch_flags, u64 *pid) {
static void LaunchTitle(u64 title_id, FsStorageId storage_id, u32 launch_flags, u64 *pid) {
u64 local_pid = 0;
/* Don't launch a title twice during boot2. */
@ -60,7 +60,7 @@ static void LaunchTitle(Boot2KnownTitleId title_id, FsStorageId storage_id, u32
return;
}
Result rc = Registration::LaunchProcessByTidSid(Registration::TidSid{(u64)title_id, storage_id}, launch_flags, &local_pid);
Result rc = Registration::LaunchProcessByTidSid(Registration::TidSid{title_id, storage_id}, launch_flags, &local_pid);
switch (rc) {
case ResultKernelResourceExhausted:
/* Out of resource! */
@ -125,46 +125,46 @@ static bool IsMaintenanceMode() {
return false;
}
static const std::tuple<Boot2KnownTitleId, bool> g_additional_launch_programs[] = {
{Boot2KnownTitleId::am, true}, /* am */
{Boot2KnownTitleId::nvservices, true}, /* nvservices */
{Boot2KnownTitleId::nvnflinger, true}, /* nvnflinger */
{Boot2KnownTitleId::vi, true}, /* vi */
{Boot2KnownTitleId::ns, true}, /* ns */
{Boot2KnownTitleId::lm, true}, /* lm */
{Boot2KnownTitleId::ppc, true}, /* ppc */
{Boot2KnownTitleId::ptm, true}, /* ptm */
{Boot2KnownTitleId::hid, true}, /* hid */
{Boot2KnownTitleId::audio, true}, /* audio */
{Boot2KnownTitleId::lbl, true}, /* lbl */
{Boot2KnownTitleId::wlan, true}, /* wlan */
{Boot2KnownTitleId::bluetooth, true}, /* bluetooth */
{Boot2KnownTitleId::bsdsockets, true}, /* bsdsockets */
{Boot2KnownTitleId::nifm, true}, /* nifm */
{Boot2KnownTitleId::ldn, true}, /* ldn */
{Boot2KnownTitleId::account, true}, /* account */
{Boot2KnownTitleId::friends, false}, /* friends */
{Boot2KnownTitleId::nfc, true}, /* nfc */
{Boot2KnownTitleId::jpegdec, true}, /* jpegdec */
{Boot2KnownTitleId::capsrv, true}, /* capsrv */
{Boot2KnownTitleId::ssl, true}, /* ssl */
{Boot2KnownTitleId::nim, true}, /* nim */
{Boot2KnownTitleId::bcat, false}, /* bcat */
{Boot2KnownTitleId::erpt, true}, /* erpt */
{Boot2KnownTitleId::es, true}, /* es */
{Boot2KnownTitleId::pctl, true}, /* pctl */
{Boot2KnownTitleId::btm, true}, /* btm */
{Boot2KnownTitleId::eupld, false}, /* eupld */
{Boot2KnownTitleId::glue, true}, /* glue */
/* {Boot2KnownTitleId::eclct, true}, */ /* eclct */ /* Skip launching error collection in Atmosphere to lessen telemetry. */
{Boot2KnownTitleId::npns, false}, /* npns */
{Boot2KnownTitleId::fatal, true}, /* fatal */
{Boot2KnownTitleId::ro, true}, /* ro */
{Boot2KnownTitleId::profiler, true}, /* profiler */
{Boot2KnownTitleId::sdb, true}, /* sdb */
{Boot2KnownTitleId::migration, true}, /* migration */
{Boot2KnownTitleId::grc, true}, /* grc */
{Boot2KnownTitleId::olsc, true}, /* olsc */
static const std::tuple<u64, bool> g_additional_launch_programs[] = {
{TitleId_Am, true}, /* am */
{TitleId_NvServices, true}, /* nvservices */
{TitleId_NvnFlinger, true}, /* nvnflinger */
{TitleId_Vi, true}, /* vi */
{TitleId_Ns, true}, /* ns */
{TitleId_LogManager, true}, /* lm */
{TitleId_Ppc, true}, /* ppc */
{TitleId_Ptm, true}, /* ptm */
{TitleId_Hid, true}, /* hid */
{TitleId_Audio, true}, /* audio */
{TitleId_Lbl, true}, /* lbl */
{TitleId_Wlan, true}, /* wlan */
{TitleId_Bluetooth, true}, /* bluetooth */
{TitleId_BsdSockets, true}, /* bsdsockets */
{TitleId_Nifm, true}, /* nifm */
{TitleId_Ldn, true}, /* ldn */
{TitleId_Account, true}, /* account */
{TitleId_Friends, false}, /* friends */
{TitleId_Nfc, true}, /* nfc */
{TitleId_JpegDec, true}, /* jpegdec */
{TitleId_CapSrv, true}, /* capsrv */
{TitleId_Ssl, true}, /* ssl */
{TitleId_Nim, true}, /* nim */
{TitleId_Bcat, false}, /* bcat */
{TitleId_Erpt, true}, /* erpt */
{TitleId_Es, true}, /* es */
{TitleId_Pctl, true}, /* pctl */
{TitleId_Btm, true}, /* btm */
{TitleId_Eupld, false}, /* eupld */
{TitleId_Glue, true}, /* glue */
/* {TitleId_Eclct, true}, */ /* eclct */ /* Skip launching error collection in Atmosphere to lessen telemetry. */
{TitleId_Npns, false}, /* npns */
{TitleId_Fatal, true}, /* fatal */
{TitleId_Ro, true}, /* ro */
{TitleId_Profiler, true}, /* profiler */
{TitleId_Sdb, true}, /* sdb */
{TitleId_Migration, true}, /* migration */
{TitleId_Grc, true}, /* grc */
{TitleId_Olsc, true}, /* olsc */
};
static void MountSdCard() {
@ -206,15 +206,15 @@ void EmbeddedBoot2::Main() {
/* psc, bus, pcv is the minimal set of required titles to get SD card. */
/* bus depends on pcie, and pcv depends on settings. */
/* Launch psc. */
LaunchTitle(Boot2KnownTitleId::psc, FsStorageId_NandSystem, 0, NULL);
LaunchTitle(TitleId_Psc, FsStorageId_NandSystem, 0, NULL);
/* Launch pcie. */
LaunchTitle(Boot2KnownTitleId::pcie, FsStorageId_NandSystem, 0, NULL);
LaunchTitle(TitleId_Pcie, FsStorageId_NandSystem, 0, NULL);
/* Launch bus. */
LaunchTitle(Boot2KnownTitleId::bus, FsStorageId_NandSystem, 0, NULL);
LaunchTitle(TitleId_Bus, FsStorageId_NandSystem, 0, NULL);
/* Launch settings. */
LaunchTitle(Boot2KnownTitleId::settings, FsStorageId_NandSystem, 0, NULL);
LaunchTitle(TitleId_Settings, FsStorageId_NandSystem, 0, NULL);
/* Launch pcv. */
LaunchTitle(Boot2KnownTitleId::pcv, FsStorageId_NandSystem, 0, NULL);
LaunchTitle(TitleId_Pcv, FsStorageId_NandSystem, 0, NULL);
/* At this point, the SD card can be mounted. */
MountSdCard();
@ -234,18 +234,18 @@ void EmbeddedBoot2::Main() {
}
/* Launch usb. */
LaunchTitle(Boot2KnownTitleId::usb, FsStorageId_NandSystem, 0, NULL);
LaunchTitle(TitleId_Usb, FsStorageId_NandSystem, 0, NULL);
/* Launch tma. */
LaunchTitle(Boot2KnownTitleId::tma, FsStorageId_NandSystem, 0, NULL);
LaunchTitle(TitleId_Tma, FsStorageId_NandSystem, 0, NULL);
/* Launch Atmosphere dmnt, using FsStorageId_None to force SD card boot. */
LaunchTitle(Boot2KnownTitleId::dmnt, FsStorageId_None, 0, NULL);
LaunchTitle(TitleId_Dmnt, FsStorageId_None, 0, NULL);
/* Launch default programs. */
for (auto &launch_program : g_additional_launch_programs) {
if (!maintenance || std::get<bool>(launch_program)) {
LaunchTitle(std::get<Boot2KnownTitleId>(launch_program), FsStorageId_NandSystem, 0, NULL);
LaunchTitle(std::get<u64>(launch_program), FsStorageId_NandSystem, 0, NULL);
}
}
@ -255,7 +255,7 @@ void EmbeddedBoot2::Main() {
if (titles_dir != NULL) {
while ((ent = readdir(titles_dir)) != NULL) {
if (strlen(ent->d_name) == 0x10 && IsHexadecimal(ent->d_name)) {
Boot2KnownTitleId title_id = (Boot2KnownTitleId)strtoul(ent->d_name, NULL, 16);
u64 title_id = (u64)strtoul(ent->d_name, NULL, 16);
if (HasLaunchedTitle(title_id)) {
continue;
}

View file

@ -16,73 +16,6 @@
#pragma once
enum class Boot2KnownTitleId : u64 {
fs = 0x0100000000000000UL,
loader = 0x0100000000000001UL,
ncm = 0x0100000000000002UL,
pm = 0x0100000000000003UL,
sm = 0x0100000000000004UL,
boot = 0x0100000000000005UL,
usb = 0x0100000000000006UL,
tma = 0x0100000000000007UL,
boot2 = 0x0100000000000008UL,
settings = 0x0100000000000009UL,
bus = 0x010000000000000AUL,
bluetooth = 0x010000000000000BUL,
bcat = 0x010000000000000CUL,
dmnt = 0x010000000000000DUL,
friends = 0x010000000000000EUL,
nifm = 0x010000000000000FUL,
ptm = 0x0100000000000010UL,
shell = 0x0100000000000011UL,
bsdsockets = 0x0100000000000012UL,
hid = 0x0100000000000013UL,
audio = 0x0100000000000014UL,
lm = 0x0100000000000015UL,
wlan = 0x0100000000000016UL,
cs = 0x0100000000000017UL,
ldn = 0x0100000000000018UL,
nvservices = 0x0100000000000019UL,
pcv = 0x010000000000001AUL,
ppc = 0x010000000000001BUL,
nvnflinger = 0x010000000000001CUL,
pcie = 0x010000000000001DUL,
account = 0x010000000000001EUL,
ns = 0x010000000000001FUL,
nfc = 0x0100000000000020UL,
psc = 0x0100000000000021UL,
capsrv = 0x0100000000000022UL,
am = 0x0100000000000023UL,
ssl = 0x0100000000000024UL,
nim = 0x0100000000000025UL,
spl = 0x0100000000000028UL,
lbl = 0x0100000000000029UL,
btm = 0x010000000000002AUL,
erpt = 0x010000000000002BUL,
vi = 0x010000000000002DUL,
pctl = 0x010000000000002EUL,
npns = 0x010000000000002FUL,
eupld = 0x0100000000000030UL,
glue = 0x0100000000000031UL,
eclct = 0x0100000000000032UL,
es = 0x0100000000000033UL,
fatal = 0x0100000000000034UL,
grc = 0x0100000000000035UL,
creport = 0x0100000000000036UL,
ro = 0x0100000000000037UL,
profiler = 0x0100000000000038UL,
sdb = 0x0100000000000039UL,
migration = 0x010000000000003AUL,
jit = 0x010000000000003BUL,
jpegdec = 0x010000000000003CUL,
safemode = 0x010000000000003DUL,
olsc = 0x010000000000003EUL,
/* atmosphere extensions */
ams_set_mitm = 0x0100000000000032UL,
};
class EmbeddedBoot2 {
public:
static void Main();

View file

@ -20,8 +20,6 @@
#include "pm_registration.hpp"
#define BOOT2_TITLE_ID (0x0100000000000008ULL)
enum ShellCmd {
Shell_Cmd_LaunchProcess = 0,
Shell_Cmd_TerminateProcessId = 1,