strat: use m_ for member variables
This commit is contained in:
@@ -91,14 +91,14 @@ namespace ams::mitm::socket::resolver {
|
||||
|
||||
const char *hostname = reinterpret_cast<const char *>(name.GetPointer());
|
||||
|
||||
LogDebug("[%016lx]: GetHostByNameRequest(%s)\n", this->client_info.program_id.value, hostname);
|
||||
LogDebug("[%016lx]: GetHostByNameRequest(%s)\n", m_client_info.program_id.value, hostname);
|
||||
|
||||
R_UNLESS(hostname != nullptr, sm::mitm::ResultShouldForwardToSession());
|
||||
|
||||
ams::socket::InAddrT redirect_addr = {};
|
||||
R_UNLESS(GetRedirectedHostByName(std::addressof(redirect_addr), hostname), sm::mitm::ResultShouldForwardToSession());
|
||||
|
||||
LogDebug("[%016lx]: Redirecting %s to %u.%u.%u.%u\n", this->client_info.program_id.value, hostname, (redirect_addr >> 0) & 0xFF, (redirect_addr >> 8) & 0xFF, (redirect_addr >> 16) & 0xFF, (redirect_addr >> 24) & 0xFF);
|
||||
LogDebug("[%016lx]: Redirecting %s to %u.%u.%u.%u\n", m_client_info.program_id.value, hostname, (redirect_addr >> 0) & 0xFF, (redirect_addr >> 8) & 0xFF, (redirect_addr >> 16) & 0xFF, (redirect_addr >> 24) & 0xFF);
|
||||
const auto size = SerializeRedirectedHostEnt(out_hostent.GetPointer(), out_hostent.GetSize(), hostname, redirect_addr);
|
||||
|
||||
*out_host_error = 0;
|
||||
@@ -113,7 +113,7 @@ namespace ams::mitm::socket::resolver {
|
||||
|
||||
const char *hostname = reinterpret_cast<const char *>(node.GetPointer());
|
||||
|
||||
LogDebug("[%016lx]: GetAddrInfoRequest(%s, %s)\n", this->client_info.program_id.value, reinterpret_cast<const char *>(node.GetPointer()), reinterpret_cast<const char *>(srv.GetPointer()));
|
||||
LogDebug("[%016lx]: GetAddrInfoRequest(%s, %s)\n", m_client_info.program_id.value, reinterpret_cast<const char *>(node.GetPointer()), reinterpret_cast<const char *>(srv.GetPointer()));
|
||||
|
||||
R_UNLESS(hostname != nullptr, sm::mitm::ResultShouldForwardToSession());
|
||||
|
||||
@@ -129,7 +129,7 @@ namespace ams::mitm::socket::resolver {
|
||||
}
|
||||
}
|
||||
|
||||
LogDebug("[%016lx]: Redirecting %s:%u to %u.%u.%u.%u\n", this->client_info.program_id.value, hostname, port, (redirect_addr >> 0) & 0xFF, (redirect_addr >> 8) & 0xFF, (redirect_addr >> 16) & 0xFF, (redirect_addr >> 24) & 0xFF);
|
||||
LogDebug("[%016lx]: Redirecting %s:%u to %u.%u.%u.%u\n", m_client_info.program_id.value, hostname, port, (redirect_addr >> 0) & 0xFF, (redirect_addr >> 8) & 0xFF, (redirect_addr >> 16) & 0xFF, (redirect_addr >> 24) & 0xFF);
|
||||
|
||||
const bool use_hint = serialized_hint.GetPointer() != nullptr;
|
||||
struct addrinfo hint = {};
|
||||
@@ -152,14 +152,14 @@ namespace ams::mitm::socket::resolver {
|
||||
|
||||
const char *hostname = reinterpret_cast<const char *>(name.GetPointer());
|
||||
|
||||
LogDebug("[%016lx]: GetHostByNameRequestWithOptions(%s)\n", this->client_info.program_id.value, hostname);
|
||||
LogDebug("[%016lx]: GetHostByNameRequestWithOptions(%s)\n", m_client_info.program_id.value, hostname);
|
||||
|
||||
R_UNLESS(hostname != nullptr, sm::mitm::ResultShouldForwardToSession());
|
||||
|
||||
ams::socket::InAddrT redirect_addr = {};
|
||||
R_UNLESS(GetRedirectedHostByName(std::addressof(redirect_addr), hostname), sm::mitm::ResultShouldForwardToSession());
|
||||
|
||||
LogDebug("[%016lx]: Redirecting %s to %u.%u.%u.%u\n", this->client_info.program_id.value, hostname, (redirect_addr >> 0) & 0xFF, (redirect_addr >> 8) & 0xFF, (redirect_addr >> 16) & 0xFF, (redirect_addr >> 24) & 0xFF);
|
||||
LogDebug("[%016lx]: Redirecting %s to %u.%u.%u.%u\n", m_client_info.program_id.value, hostname, (redirect_addr >> 0) & 0xFF, (redirect_addr >> 8) & 0xFF, (redirect_addr >> 16) & 0xFF, (redirect_addr >> 24) & 0xFF);
|
||||
const auto size = SerializeRedirectedHostEnt(out_hostent.GetPointer(), out_hostent.GetSize(), hostname, redirect_addr);
|
||||
|
||||
*out_host_error = 0;
|
||||
@@ -174,7 +174,7 @@ namespace ams::mitm::socket::resolver {
|
||||
|
||||
const char *hostname = reinterpret_cast<const char *>(node.GetPointer());
|
||||
|
||||
LogDebug("[%016lx]: GetAddrInfoRequestWithOptions(%s, %s)\n", this->client_info.program_id.value, hostname, reinterpret_cast<const char *>(srv.GetPointer()));
|
||||
LogDebug("[%016lx]: GetAddrInfoRequestWithOptions(%s, %s)\n", m_client_info.program_id.value, hostname, reinterpret_cast<const char *>(srv.GetPointer()));
|
||||
|
||||
R_UNLESS(hostname != nullptr, sm::mitm::ResultShouldForwardToSession());
|
||||
|
||||
@@ -190,7 +190,7 @@ namespace ams::mitm::socket::resolver {
|
||||
}
|
||||
}
|
||||
|
||||
LogDebug("[%016lx]: Redirecting %s:%u to %u.%u.%u.%u\n", this->client_info.program_id.value, hostname, port, (redirect_addr >> 0) & 0xFF, (redirect_addr >> 8) & 0xFF, (redirect_addr >> 16) & 0xFF, (redirect_addr >> 24) & 0xFF);
|
||||
LogDebug("[%016lx]: Redirecting %s:%u to %u.%u.%u.%u\n", m_client_info.program_id.value, hostname, port, (redirect_addr >> 0) & 0xFF, (redirect_addr >> 8) & 0xFF, (redirect_addr >> 16) & 0xFF, (redirect_addr >> 24) & 0xFF);
|
||||
|
||||
const bool use_hint = serialized_hint.GetPointer() != nullptr;
|
||||
struct addrinfo hint = {};
|
||||
|
||||
@@ -217,21 +217,21 @@ namespace ams::mitm::fs {
|
||||
}
|
||||
|
||||
Result FsMitmService::OpenFileSystemWithPatch(sf::Out<sf::SharedPointer<ams::fssrv::sf::IFileSystem>> out, ncm::ProgramId program_id, u32 _filesystem_type) {
|
||||
return OpenWebContentFileSystem(out, this->client_info.program_id, program_id, static_cast<FsFileSystemType>(_filesystem_type), this->forward_service.get(), nullptr, false, this->client_info.override_status.IsProgramSpecific());
|
||||
return OpenWebContentFileSystem(out, m_client_info.program_id, program_id, static_cast<FsFileSystemType>(_filesystem_type), m_forward_service.get(), nullptr, false, m_client_info.override_status.IsProgramSpecific());
|
||||
}
|
||||
|
||||
Result FsMitmService::OpenFileSystemWithId(sf::Out<sf::SharedPointer<ams::fssrv::sf::IFileSystem>> out, const fssrv::sf::Path &path, ncm::ProgramId program_id, u32 _filesystem_type) {
|
||||
return OpenWebContentFileSystem(out, this->client_info.program_id, program_id, static_cast<FsFileSystemType>(_filesystem_type), this->forward_service.get(), std::addressof(path), true, this->client_info.override_status.IsProgramSpecific());
|
||||
return OpenWebContentFileSystem(out, m_client_info.program_id, program_id, static_cast<FsFileSystemType>(_filesystem_type), m_forward_service.get(), std::addressof(path), true, m_client_info.override_status.IsProgramSpecific());
|
||||
}
|
||||
|
||||
Result FsMitmService::OpenSdCardFileSystem(sf::Out<sf::SharedPointer<ams::fssrv::sf::IFileSystem>> out) {
|
||||
/* We only care about redirecting this for NS/emummc. */
|
||||
R_UNLESS(this->client_info.program_id == ncm::SystemProgramId::Ns, sm::mitm::ResultShouldForwardToSession());
|
||||
R_UNLESS(m_client_info.program_id == ncm::SystemProgramId::Ns, sm::mitm::ResultShouldForwardToSession());
|
||||
R_UNLESS(emummc::IsActive(), sm::mitm::ResultShouldForwardToSession());
|
||||
|
||||
/* Create a new SD card filesystem. */
|
||||
FsFileSystem sd_fs;
|
||||
R_TRY(fsOpenSdCardFileSystemFwd(this->forward_service.get(), std::addressof(sd_fs)));
|
||||
R_TRY(fsOpenSdCardFileSystemFwd(m_forward_service.get(), std::addressof(sd_fs)));
|
||||
const sf::cmif::DomainObjectId target_object_id{serviceGetObjectId(std::addressof(sd_fs.s))};
|
||||
|
||||
/* Return output filesystem. */
|
||||
@@ -242,14 +242,14 @@ namespace ams::mitm::fs {
|
||||
|
||||
Result FsMitmService::OpenSaveDataFileSystem(sf::Out<sf::SharedPointer<ams::fssrv::sf::IFileSystem>> out, u8 _space_id, const fs::SaveDataAttribute &attribute) {
|
||||
/* We only want to intercept saves for games, right now. */
|
||||
const bool is_game_or_hbl = this->client_info.override_status.IsHbl() || ncm::IsApplicationId(this->client_info.program_id);
|
||||
const bool is_game_or_hbl = m_client_info.override_status.IsHbl() || ncm::IsApplicationId(m_client_info.program_id);
|
||||
R_UNLESS(is_game_or_hbl, sm::mitm::ResultShouldForwardToSession());
|
||||
|
||||
/* Only redirect if the appropriate system setting is set. */
|
||||
R_UNLESS(GetSettingsItemBooleanValue("atmosphere", "fsmitm_redirect_saves_to_sd"), sm::mitm::ResultShouldForwardToSession());
|
||||
|
||||
/* Only redirect if the specific title being accessed has a redirect save flag. */
|
||||
R_UNLESS(cfg::HasContentSpecificFlag(this->client_info.program_id, "redirect_save"), sm::mitm::ResultShouldForwardToSession());
|
||||
R_UNLESS(cfg::HasContentSpecificFlag(m_client_info.program_id, "redirect_save"), sm::mitm::ResultShouldForwardToSession());
|
||||
|
||||
/* Only redirect account savedata. */
|
||||
R_UNLESS(attribute.type == fs::SaveDataType::Account, sm::mitm::ResultShouldForwardToSession());
|
||||
@@ -260,7 +260,7 @@ namespace ams::mitm::fs {
|
||||
/* Verify we can open the save. */
|
||||
static_assert(sizeof(fs::SaveDataAttribute) == sizeof(::FsSaveDataAttribute));
|
||||
FsFileSystem save_fs;
|
||||
R_UNLESS(R_SUCCEEDED(fsOpenSaveDataFileSystemFwd(this->forward_service.get(), std::addressof(save_fs), space_id, reinterpret_cast<const FsSaveDataAttribute *>(std::addressof(attribute)))), sm::mitm::ResultShouldForwardToSession());
|
||||
R_UNLESS(R_SUCCEEDED(fsOpenSaveDataFileSystemFwd(m_forward_service.get(), std::addressof(save_fs), space_id, reinterpret_cast<const FsSaveDataAttribute *>(std::addressof(attribute)))), sm::mitm::ResultShouldForwardToSession());
|
||||
std::unique_ptr<fs::fsa::IFileSystem> save_ifs = std::make_unique<fs::RemoteFileSystem>(save_fs);
|
||||
|
||||
/* Mount the SD card using fs.mitm's session. */
|
||||
@@ -270,7 +270,7 @@ namespace ams::mitm::fs {
|
||||
std::shared_ptr<fs::fsa::IFileSystem> sd_ifs = std::make_shared<fs::RemoteFileSystem>(sd_fs);
|
||||
|
||||
/* Verify that we can open the save directory, and that it exists. */
|
||||
const ncm::ProgramId application_id = attribute.program_id == ncm::InvalidProgramId ? this->client_info.program_id : attribute.program_id;
|
||||
const ncm::ProgramId application_id = attribute.program_id == ncm::InvalidProgramId ? m_client_info.program_id : attribute.program_id;
|
||||
char save_dir_path[fs::EntryNameLengthMax + 1];
|
||||
R_TRY(mitm::fs::SaveUtil::GetDirectorySaveDataPath(save_dir_path, sizeof(save_dir_path), application_id, space_id, attribute));
|
||||
|
||||
@@ -310,11 +310,11 @@ namespace ams::mitm::fs {
|
||||
|
||||
/* Try to open a storage for the partition. */
|
||||
FsStorage bis_storage;
|
||||
R_TRY(fsOpenBisStorageFwd(this->forward_service.get(), std::addressof(bis_storage), bis_partition_id));
|
||||
R_TRY(fsOpenBisStorageFwd(m_forward_service.get(), std::addressof(bis_storage), bis_partition_id));
|
||||
const sf::cmif::DomainObjectId target_object_id{serviceGetObjectId(std::addressof(bis_storage.s))};
|
||||
|
||||
const bool is_sysmodule = ncm::IsSystemProgramId(this->client_info.program_id);
|
||||
const bool is_hbl = this->client_info.override_status.IsHbl();
|
||||
const bool is_sysmodule = ncm::IsSystemProgramId(m_client_info.program_id);
|
||||
const bool is_hbl = m_client_info.override_status.IsHbl();
|
||||
const bool can_write_bis = is_sysmodule || (is_hbl && GetSettingsItemBooleanValue("atmosphere", "enable_hbl_bis_write"));
|
||||
|
||||
/* Allow HBL to write to boot1 (safe firm) + package2. */
|
||||
@@ -327,12 +327,12 @@ namespace ams::mitm::fs {
|
||||
/* Set output storage. */
|
||||
if (bis_partition_id == FsBisPartitionId_BootPartition1Root) {
|
||||
if (IsBoot0CustomPublicKey(bis_storage)) {
|
||||
out.SetValue(MakeSharedStorage(new CustomPublicKeyBoot0Storage(bis_storage, this->client_info, spl::GetSocType())), target_object_id);
|
||||
out.SetValue(MakeSharedStorage(new CustomPublicKeyBoot0Storage(bis_storage, m_client_info, spl::GetSocType())), target_object_id);
|
||||
} else {
|
||||
out.SetValue(MakeSharedStorage(new Boot0Storage(bis_storage, this->client_info)), target_object_id);
|
||||
out.SetValue(MakeSharedStorage(new Boot0Storage(bis_storage, m_client_info)), target_object_id);
|
||||
}
|
||||
} else if (bis_partition_id == FsBisPartitionId_CalibrationBinary) {
|
||||
out.SetValue(MakeSharedStorage(new CalibrationBinaryStorage(bis_storage, this->client_info)), target_object_id);
|
||||
out.SetValue(MakeSharedStorage(new CalibrationBinaryStorage(bis_storage, m_client_info)), target_object_id);
|
||||
} else {
|
||||
if (can_write_bis || can_write_bis_for_choi_support) {
|
||||
/* We can write, so create a writable storage. */
|
||||
@@ -348,14 +348,14 @@ namespace ams::mitm::fs {
|
||||
|
||||
Result FsMitmService::OpenDataStorageByCurrentProcess(sf::Out<sf::SharedPointer<ams::fssrv::sf::IStorage>> out) {
|
||||
/* Only mitm if we should override contents for the current process. */
|
||||
R_UNLESS(this->client_info.override_status.IsProgramSpecific(), sm::mitm::ResultShouldForwardToSession());
|
||||
R_UNLESS(m_client_info.override_status.IsProgramSpecific(), sm::mitm::ResultShouldForwardToSession());
|
||||
|
||||
/* Only mitm if there is actually an override romfs. */
|
||||
R_UNLESS(mitm::fs::HasSdRomfsContent(this->client_info.program_id), sm::mitm::ResultShouldForwardToSession());
|
||||
R_UNLESS(mitm::fs::HasSdRomfsContent(m_client_info.program_id), sm::mitm::ResultShouldForwardToSession());
|
||||
|
||||
/* Try to open the process romfs. */
|
||||
FsStorage data_storage;
|
||||
R_TRY(fsOpenDataStorageByCurrentProcessFwd(this->forward_service.get(), std::addressof(data_storage)));
|
||||
R_TRY(fsOpenDataStorageByCurrentProcessFwd(m_forward_service.get(), std::addressof(data_storage)));
|
||||
const sf::cmif::DomainObjectId target_object_id{serviceGetObjectId(std::addressof(data_storage.s))};
|
||||
|
||||
/* Get a scoped lock. */
|
||||
@@ -363,7 +363,7 @@ namespace ams::mitm::fs {
|
||||
|
||||
/* Try to get a storage from the cache. */
|
||||
{
|
||||
std::shared_ptr<fs::IStorage> cached_storage = GetStorageCacheEntry(this->client_info.program_id);
|
||||
std::shared_ptr<fs::IStorage> cached_storage = GetStorageCacheEntry(m_client_info.program_id);
|
||||
if (cached_storage != nullptr) {
|
||||
out.SetValue(MakeSharedStorage(cached_storage), target_object_id);
|
||||
return ResultSuccess();
|
||||
@@ -376,17 +376,17 @@ namespace ams::mitm::fs {
|
||||
|
||||
/* Create the layered storage. */
|
||||
FsFile data_file;
|
||||
if (R_SUCCEEDED(OpenAtmosphereSdFile(std::addressof(data_file), this->client_info.program_id, "romfs.bin", OpenMode_Read))) {
|
||||
auto layered_storage = std::make_shared<LayeredRomfsStorage>(std::make_unique<ReadOnlyStorageAdapter>(new RemoteStorage(data_storage)), std::make_unique<ReadOnlyStorageAdapter>(new FileStorage(new RemoteFile(data_file))), this->client_info.program_id);
|
||||
if (R_SUCCEEDED(OpenAtmosphereSdFile(std::addressof(data_file), m_client_info.program_id, "romfs.bin", OpenMode_Read))) {
|
||||
auto layered_storage = std::make_shared<LayeredRomfsStorage>(std::make_unique<ReadOnlyStorageAdapter>(new RemoteStorage(data_storage)), std::make_unique<ReadOnlyStorageAdapter>(new FileStorage(new RemoteFile(data_file))), m_client_info.program_id);
|
||||
layered_storage->BeginInitialize();
|
||||
new_storage = std::move(layered_storage);
|
||||
} else {
|
||||
auto layered_storage = std::make_shared<LayeredRomfsStorage>(std::make_unique<ReadOnlyStorageAdapter>(new RemoteStorage(data_storage)), nullptr, this->client_info.program_id);
|
||||
auto layered_storage = std::make_shared<LayeredRomfsStorage>(std::make_unique<ReadOnlyStorageAdapter>(new RemoteStorage(data_storage)), nullptr, m_client_info.program_id);
|
||||
layered_storage->BeginInitialize();
|
||||
new_storage = std::move(layered_storage);
|
||||
}
|
||||
|
||||
SetStorageCacheEntry(this->client_info.program_id, std::addressof(new_storage));
|
||||
SetStorageCacheEntry(m_client_info.program_id, std::addressof(new_storage));
|
||||
out.SetValue(MakeSharedStorage(new_storage), target_object_id);
|
||||
}
|
||||
|
||||
@@ -395,7 +395,7 @@ namespace ams::mitm::fs {
|
||||
|
||||
Result FsMitmService::OpenDataStorageByDataId(sf::Out<sf::SharedPointer<ams::fssrv::sf::IStorage>> out, ncm::DataId _data_id, u8 storage_id) {
|
||||
/* Only mitm if we should override contents for the current process. */
|
||||
R_UNLESS(this->client_info.override_status.IsProgramSpecific(), sm::mitm::ResultShouldForwardToSession());
|
||||
R_UNLESS(m_client_info.override_status.IsProgramSpecific(), sm::mitm::ResultShouldForwardToSession());
|
||||
|
||||
/* TODO: Decide how to handle DataId vs ProgramId for this API. */
|
||||
const ncm::ProgramId data_id = {_data_id.value};
|
||||
@@ -405,7 +405,7 @@ namespace ams::mitm::fs {
|
||||
|
||||
/* Try to open the process romfs. */
|
||||
FsStorage data_storage;
|
||||
R_TRY(fsOpenDataStorageByDataIdFwd(this->forward_service.get(), std::addressof(data_storage), static_cast<u64>(data_id), static_cast<NcmStorageId>(storage_id)));
|
||||
R_TRY(fsOpenDataStorageByDataIdFwd(m_forward_service.get(), std::addressof(data_storage), static_cast<u64>(data_id), static_cast<NcmStorageId>(storage_id)));
|
||||
const sf::cmif::DomainObjectId target_object_id{serviceGetObjectId(std::addressof(data_storage.s))};
|
||||
|
||||
/* Get a scoped lock. */
|
||||
@@ -445,10 +445,10 @@ namespace ams::mitm::fs {
|
||||
|
||||
Result FsMitmService::OpenDataStorageWithProgramIndex(sf::Out<sf::SharedPointer<ams::fssrv::sf::IStorage>> out, u8 program_index) {
|
||||
/* Only mitm if we should override contents for the current process. */
|
||||
R_UNLESS(this->client_info.override_status.IsProgramSpecific(), sm::mitm::ResultShouldForwardToSession());
|
||||
R_UNLESS(m_client_info.override_status.IsProgramSpecific(), sm::mitm::ResultShouldForwardToSession());
|
||||
|
||||
/* Get the relevant program id. */
|
||||
const ncm::ProgramId program_id = g_program_index_map_info_manager.GetProgramId(this->client_info.program_id, program_index);
|
||||
const ncm::ProgramId program_id = g_program_index_map_info_manager.GetProgramId(m_client_info.program_id, program_index);
|
||||
|
||||
/* If we don't know about the program or don't have content, forward. */
|
||||
R_UNLESS(program_id != ncm::InvalidProgramId, sm::mitm::ResultShouldForwardToSession());
|
||||
@@ -456,7 +456,7 @@ namespace ams::mitm::fs {
|
||||
|
||||
/* Try to open the process romfs. */
|
||||
FsStorage data_storage;
|
||||
R_TRY(fsOpenDataStorageWithProgramIndexFwd(this->forward_service.get(), std::addressof(data_storage), program_index));
|
||||
R_TRY(fsOpenDataStorageWithProgramIndexFwd(m_forward_service.get(), std::addressof(data_storage), program_index));
|
||||
const sf::cmif::DomainObjectId target_object_id{serviceGetObjectId(std::addressof(data_storage.s))};
|
||||
|
||||
/* Get a scoped lock. */
|
||||
@@ -496,7 +496,7 @@ namespace ams::mitm::fs {
|
||||
|
||||
Result FsMitmService::RegisterProgramIndexMapInfo(const sf::InBuffer &info_buffer, s32 info_count) {
|
||||
/* Try to register with FS. */
|
||||
R_TRY(fsRegisterProgramIndexMapInfoFwd(this->forward_service.get(), info_buffer.GetPointer(), info_buffer.GetSize(), info_count));
|
||||
R_TRY(fsRegisterProgramIndexMapInfoFwd(m_forward_service.get(), info_buffer.GetPointer(), info_buffer.GetSize(), info_count));
|
||||
|
||||
/* Register with ourselves. */
|
||||
R_ABORT_UNLESS(g_program_index_map_info_manager.Reset(reinterpret_cast<const fs::ProgramIndexMapInfo *>(info_buffer.GetPointer()), info_count));
|
||||
|
||||
@@ -22,9 +22,9 @@ namespace ams::mitm::fs {
|
||||
|
||||
namespace {
|
||||
|
||||
os::SdkMutex g_boot0_access_mutex;
|
||||
constinit os::SdkMutex g_boot0_access_mutex;
|
||||
constinit bool g_custom_public_key = false;
|
||||
u8 g_boot0_bct_buffer[Boot0Storage::BctEndOffset];
|
||||
constinit u8 g_boot0_bct_buffer[Boot0Storage::BctEndOffset];
|
||||
|
||||
/* Recognize special public key (https://gist.github.com/SciresM/16b63ac1d80494522bdba2c57995257c). */
|
||||
/* P = 19 */
|
||||
@@ -59,11 +59,11 @@ namespace ams::mitm::fs {
|
||||
/* RCM bug patched. */
|
||||
/* Only allow NS to update the BCT pubks. */
|
||||
/* AutoRCM on a patched unit will cause a brick, so homebrew should NOT be allowed to write. */
|
||||
return this->client_info.program_id == ncm::SystemProgramId::Ns;
|
||||
return m_client_info.program_id == ncm::SystemProgramId::Ns;
|
||||
} else {
|
||||
/* RCM bug unpatched. */
|
||||
/* Allow homebrew but not NS to update the BCT pubks. */
|
||||
return this->client_info.override_status.IsHbl();
|
||||
return m_client_info.override_status.IsHbl();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ namespace ams::mitm::fs {
|
||||
return Base::Write(0, g_boot0_bct_buffer, BctEndOffset);
|
||||
}
|
||||
|
||||
CustomPublicKeyBoot0Storage::CustomPublicKeyBoot0Storage(FsStorage &s, const sm::MitmProcessInfo &c, spl::SocType soc) : Base(s), client_info(c), soc_type(soc) {
|
||||
CustomPublicKeyBoot0Storage::CustomPublicKeyBoot0Storage(FsStorage &s, const sm::MitmProcessInfo &c, spl::SocType soc) : Base(s), m_client_info(c), m_soc_type(soc) {
|
||||
std::scoped_lock lk{g_boot0_access_mutex};
|
||||
|
||||
/* We're custom public key. */
|
||||
@@ -157,7 +157,7 @@ namespace ams::mitm::fs {
|
||||
|
||||
/* Check if we're reading the first BCTs for NS. */
|
||||
/* If we are, we want to lie about the contents of BCT0/1 so that they validate. */
|
||||
if (offset < 0x8000 && this->client_info.program_id == ncm::SystemProgramId::Ns) {
|
||||
if (offset < 0x8000 && m_client_info.program_id == ncm::SystemProgramId::Ns) {
|
||||
R_TRY(Base::Read(0, g_boot0_bct_buffer, Boot0Storage::BctEndOffset));
|
||||
|
||||
/* Determine the readable size. */
|
||||
@@ -207,7 +207,7 @@ namespace ams::mitm::fs {
|
||||
}
|
||||
|
||||
/* On erista, we want to protect the EKS region. */
|
||||
if (this->soc_type == spl::SocType_Erista) {
|
||||
if (m_soc_type == spl::SocType_Erista) {
|
||||
if (offset <= Boot0Storage::EksStart) {
|
||||
if (offset + size < Boot0Storage::EksStart) {
|
||||
/* Fall through, no need to do anything here. */
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace ams::mitm::fs {
|
||||
class SectoredStorageAdapter : public Base {
|
||||
static_assert(std::is_base_of<ams::fs::IStorage, Base>::value);
|
||||
private:
|
||||
u8 sector_buf[SectorSize];
|
||||
u8 m_sector_buf[SectorSize];
|
||||
public:
|
||||
/* Inherit constructors. */
|
||||
using Base::Base;
|
||||
@@ -44,15 +44,15 @@ namespace ams::mitm::fs {
|
||||
return Base::Read(offset, buffer, size);
|
||||
}
|
||||
|
||||
R_TRY(Base::Read(seek, this->sector_buf, SectorSize));
|
||||
R_TRY(Base::Read(seek, m_sector_buf, SectorSize));
|
||||
|
||||
if (size + sector_ofs <= SectorSize) {
|
||||
/* Staying within the sector. */
|
||||
std::memcpy(buffer, this->sector_buf + sector_ofs, size);
|
||||
std::memcpy(buffer, m_sector_buf + sector_ofs, size);
|
||||
} else {
|
||||
/* Leaving the sector. */
|
||||
const size_t size_in_sector = SectorSize - sector_ofs;
|
||||
std::memcpy(buffer, this->sector_buf + sector_ofs, size_in_sector);
|
||||
std::memcpy(buffer, m_sector_buf + sector_ofs, size_in_sector);
|
||||
size -= size_in_sector;
|
||||
|
||||
/* Read as many guaranteed aligned sectors as we can. */
|
||||
@@ -64,8 +64,8 @@ namespace ams::mitm::fs {
|
||||
|
||||
/* Read any leftover data. */
|
||||
if (size) {
|
||||
R_TRY(Base::Read(offset + size_in_sector + aligned_remaining_size, this->sector_buf, SectorSize));
|
||||
std::memcpy(buffer + size_in_sector + aligned_remaining_size, this->sector_buf, size);
|
||||
R_TRY(Base::Read(offset + size_in_sector + aligned_remaining_size, m_sector_buf, SectorSize));
|
||||
std::memcpy(buffer + size_in_sector + aligned_remaining_size, m_sector_buf, size);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,17 +89,17 @@ namespace ams::mitm::fs {
|
||||
}
|
||||
|
||||
/* Load existing sector data. */
|
||||
R_TRY(Base::Read(seek, this->sector_buf, SectorSize));
|
||||
R_TRY(Base::Read(seek, m_sector_buf, SectorSize));
|
||||
|
||||
if (size + sector_ofs <= SectorSize) {
|
||||
/* Staying within the sector. */
|
||||
std::memcpy(this->sector_buf + sector_ofs, buffer, size);
|
||||
R_TRY(Base::Write(seek, this->sector_buf, SectorSize));
|
||||
std::memcpy(m_sector_buf + sector_ofs, buffer, size);
|
||||
R_TRY(Base::Write(seek, m_sector_buf, SectorSize));
|
||||
} else {
|
||||
/* Leaving the sector. */
|
||||
const size_t size_in_sector = SectorSize - sector_ofs;
|
||||
std::memcpy(this->sector_buf + sector_ofs, buffer, size_in_sector);
|
||||
R_TRY(Base::Write(seek, this->sector_buf, SectorSize));
|
||||
std::memcpy(m_sector_buf + sector_ofs, buffer, size_in_sector);
|
||||
R_TRY(Base::Write(seek, m_sector_buf, SectorSize));
|
||||
size -= size_in_sector;
|
||||
|
||||
/* Write as many guaranteed aligned sectors as we can. */
|
||||
@@ -111,9 +111,9 @@ namespace ams::mitm::fs {
|
||||
|
||||
/* Write any leftover data. */
|
||||
if (size) {
|
||||
R_TRY(Base::Read(offset + size_in_sector + aligned_remaining_size, this->sector_buf, SectorSize));
|
||||
std::memcpy(this->sector_buf, buffer + size_in_sector + aligned_remaining_size, size);
|
||||
R_TRY(Base::Write(offset + size_in_sector + aligned_remaining_size, this->sector_buf, SectorSize));
|
||||
R_TRY(Base::Read(offset + size_in_sector + aligned_remaining_size, m_sector_buf, SectorSize));
|
||||
std::memcpy(m_sector_buf, buffer + size_in_sector + aligned_remaining_size, size);
|
||||
R_TRY(Base::Write(offset + size_in_sector + aligned_remaining_size, m_sector_buf, SectorSize));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,11 +136,11 @@ namespace ams::mitm::fs {
|
||||
static constexpr s64 EksSize = static_cast<s64>(ams::updater::EksSize);
|
||||
static constexpr s64 EksEnd = EksStart + EksSize;
|
||||
private:
|
||||
sm::MitmProcessInfo client_info;
|
||||
sm::MitmProcessInfo m_client_info;
|
||||
private:
|
||||
bool CanModifyBctPublicKey();
|
||||
public:
|
||||
Boot0Storage(FsStorage &s, const sm::MitmProcessInfo &c) : Base(s), client_info(c) { /* ... */ }
|
||||
Boot0Storage(FsStorage &s, const sm::MitmProcessInfo &c) : Base(s), m_client_info(c) { /* ... */ }
|
||||
public:
|
||||
virtual Result Read(s64 offset, void *_buffer, size_t size) override;
|
||||
virtual Result Write(s64 offset, const void *_buffer, size_t size) override;
|
||||
@@ -150,8 +150,8 @@ namespace ams::mitm::fs {
|
||||
public:
|
||||
using Base = SectoredStorageAdapter<ams::fs::RemoteStorage, 0x200>;
|
||||
private:
|
||||
sm::MitmProcessInfo client_info;
|
||||
spl::SocType soc_type;
|
||||
sm::MitmProcessInfo m_client_info;
|
||||
spl::SocType m_soc_type;
|
||||
public:
|
||||
CustomPublicKeyBoot0Storage(FsStorage &s, const sm::MitmProcessInfo &c, spl::SocType soc);
|
||||
public:
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace ams::mitm::fs {
|
||||
R_SUCCEED_IF(size == 0);
|
||||
|
||||
/* Handle the blank region. */
|
||||
if (this->read_blank) {
|
||||
if (m_read_blank) {
|
||||
if (BlankStartOffset <= offset && offset < BlankEndOffset) {
|
||||
const size_t blank_size = std::min(size, static_cast<size_t>(BlankEndOffset - offset));
|
||||
mitm::ReadFromBlankCalibrationBinary(offset, buffer, blank_size);
|
||||
@@ -88,10 +88,10 @@ namespace ams::mitm::fs {
|
||||
R_SUCCEED_IF(size == 0);
|
||||
|
||||
/* Only allow writes if we should. */
|
||||
R_UNLESS(this->allow_writes, fs::ResultUnsupportedOperation());
|
||||
R_UNLESS(m_allow_writes, fs::ResultUnsupportedOperation());
|
||||
|
||||
/* Handle the blank region. */
|
||||
if (this->read_blank) {
|
||||
if (m_read_blank) {
|
||||
if (BlankStartOffset <= offset && offset < BlankEndOffset) {
|
||||
const size_t blank_size = std::min(size, static_cast<size_t>(BlankEndOffset - offset));
|
||||
mitm::WriteToBlankCalibrationBinary(offset, buffer, blank_size);
|
||||
|
||||
@@ -34,14 +34,14 @@ namespace ams::mitm::fs {
|
||||
static constexpr s64 FakeSecureSize = static_cast<s64>(SecureCalibrationBinaryBackupSize);
|
||||
static constexpr s64 FakeSecureEndOffset = FakeSecureStartOffset + FakeSecureSize;
|
||||
private:
|
||||
sm::MitmProcessInfo client_info;
|
||||
bool read_blank;
|
||||
bool allow_writes;
|
||||
sm::MitmProcessInfo m_client_info;
|
||||
bool m_read_blank;
|
||||
bool m_allow_writes;
|
||||
public:
|
||||
CalibrationBinaryStorage(FsStorage &s, const sm::MitmProcessInfo &c)
|
||||
: Base(s), client_info(c),
|
||||
read_blank(mitm::ShouldReadBlankCalibrationBinary()),
|
||||
allow_writes(mitm::IsWriteToCalibrationBinaryAllowed())
|
||||
: Base(s), m_client_info(c),
|
||||
m_read_blank(mitm::ShouldReadBlankCalibrationBinary()),
|
||||
m_allow_writes(mitm::IsWriteToCalibrationBinaryAllowed())
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
@@ -62,40 +62,40 @@ namespace ams::mitm::fs {
|
||||
|
||||
using namespace ams::fs;
|
||||
|
||||
LayeredRomfsStorage::LayeredRomfsStorage(std::unique_ptr<IStorage> s_r, std::unique_ptr<IStorage> f_r, ncm::ProgramId pr_id) : storage_romfs(std::move(s_r)), file_romfs(std::move(f_r)), initialize_event(os::EventClearMode_ManualClear), program_id(std::move(pr_id)), is_initialized(false), started_initialize(false) {
|
||||
LayeredRomfsStorage::LayeredRomfsStorage(std::unique_ptr<IStorage> s_r, std::unique_ptr<IStorage> f_r, ncm::ProgramId pr_id) : m_storage_romfs(std::move(s_r)), m_file_romfs(std::move(f_r)), m_initialize_event(os::EventClearMode_ManualClear), m_program_id(std::move(pr_id)), m_is_initialized(false), m_started_initialize(false) {
|
||||
/* ... */
|
||||
}
|
||||
|
||||
LayeredRomfsStorage::~LayeredRomfsStorage() {
|
||||
for (size_t i = 0; i < this->source_infos.size(); i++) {
|
||||
this->source_infos[i].Cleanup();
|
||||
for (size_t i = 0; i < m_source_infos.size(); i++) {
|
||||
m_source_infos[i].Cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
void LayeredRomfsStorage::BeginInitialize() {
|
||||
AMS_ABORT_UNLESS(!this->started_initialize);
|
||||
AMS_ABORT_UNLESS(!m_started_initialize);
|
||||
RequestInitializeStorage(reinterpret_cast<uintptr_t>(this));
|
||||
this->started_initialize = true;
|
||||
m_started_initialize = true;
|
||||
}
|
||||
|
||||
void LayeredRomfsStorage::InitializeImpl() {
|
||||
/* Build new virtual romfs. */
|
||||
romfs::Builder builder(this->program_id);
|
||||
romfs::Builder builder(m_program_id);
|
||||
|
||||
if (mitm::IsInitialized()) {
|
||||
builder.AddSdFiles();
|
||||
}
|
||||
if (this->file_romfs) {
|
||||
builder.AddStorageFiles(this->file_romfs.get(), romfs::DataSourceType::File);
|
||||
if (m_file_romfs) {
|
||||
builder.AddStorageFiles(m_file_romfs.get(), romfs::DataSourceType::File);
|
||||
}
|
||||
if (this->storage_romfs) {
|
||||
builder.AddStorageFiles(this->storage_romfs.get(), romfs::DataSourceType::Storage);
|
||||
if (m_storage_romfs) {
|
||||
builder.AddStorageFiles(m_storage_romfs.get(), romfs::DataSourceType::Storage);
|
||||
}
|
||||
|
||||
builder.Build(std::addressof(this->source_infos));
|
||||
builder.Build(std::addressof(m_source_infos));
|
||||
|
||||
this->is_initialized = true;
|
||||
this->initialize_event.Signal();
|
||||
m_is_initialized = true;
|
||||
m_initialize_event.Signal();
|
||||
}
|
||||
|
||||
Result LayeredRomfsStorage::Read(s64 offset, void *buffer, size_t size) {
|
||||
@@ -103,8 +103,8 @@ namespace ams::mitm::fs {
|
||||
R_SUCCEED_IF(size == 0);
|
||||
|
||||
/* Ensure we're initialized. */
|
||||
if (!this->is_initialized) {
|
||||
this->initialize_event.Wait();
|
||||
if (!m_is_initialized) {
|
||||
m_initialize_event.Wait();
|
||||
}
|
||||
|
||||
/* Validate offset/size. */
|
||||
@@ -116,7 +116,7 @@ namespace ams::mitm::fs {
|
||||
}
|
||||
|
||||
/* Find first source info via binary search. */
|
||||
auto it = std::lower_bound(this->source_infos.begin(), this->source_infos.end(), offset);
|
||||
auto it = std::lower_bound(m_source_infos.begin(), m_source_infos.end(), offset);
|
||||
u8 *cur_dst = static_cast<u8 *>(buffer);
|
||||
|
||||
/* Our operator < compares against start of info instead of end, so we need to subtract one from lower bound. */
|
||||
@@ -132,15 +132,15 @@ namespace ams::mitm::fs {
|
||||
const size_t cur_read_size = std::min(size - read_so_far, static_cast<size_t>(cur_source.size - offset_within_source));
|
||||
switch (cur_source.source_type) {
|
||||
case romfs::DataSourceType::Storage:
|
||||
R_ABORT_UNLESS(this->storage_romfs->Read(cur_source.storage_source_info.offset + offset_within_source, cur_dst, cur_read_size));
|
||||
R_ABORT_UNLESS(m_storage_romfs->Read(cur_source.storage_source_info.offset + offset_within_source, cur_dst, cur_read_size));
|
||||
break;
|
||||
case romfs::DataSourceType::File:
|
||||
R_ABORT_UNLESS(this->file_romfs->Read(cur_source.file_source_info.offset + offset_within_source, cur_dst, cur_read_size));
|
||||
R_ABORT_UNLESS(m_file_romfs->Read(cur_source.file_source_info.offset + offset_within_source, cur_dst, cur_read_size));
|
||||
break;
|
||||
case romfs::DataSourceType::LooseSdFile:
|
||||
{
|
||||
FsFile file;
|
||||
R_ABORT_UNLESS(mitm::fs::OpenAtmosphereSdRomfsFile(std::addressof(file), this->program_id, cur_source.loose_source_info.path, OpenMode_Read));
|
||||
R_ABORT_UNLESS(mitm::fs::OpenAtmosphereSdRomfsFile(std::addressof(file), m_program_id, cur_source.loose_source_info.path, OpenMode_Read));
|
||||
ON_SCOPE_EXIT { fsFileClose(std::addressof(file)); };
|
||||
|
||||
u64 out_read = 0;
|
||||
@@ -180,8 +180,8 @@ namespace ams::mitm::fs {
|
||||
|
||||
Result LayeredRomfsStorage::GetSize(s64 *out_size) {
|
||||
/* Ensure we're initialized. */
|
||||
if (!this->is_initialized) {
|
||||
this->initialize_event.Wait();
|
||||
if (!m_is_initialized) {
|
||||
m_initialize_event.Wait();
|
||||
}
|
||||
|
||||
*out_size = this->GetSize();
|
||||
|
||||
@@ -22,16 +22,16 @@ namespace ams::mitm::fs {
|
||||
|
||||
class LayeredRomfsStorage : public std::enable_shared_from_this<LayeredRomfsStorage>, public ams::fs::IStorage {
|
||||
private:
|
||||
std::vector<romfs::SourceInfo> source_infos;
|
||||
std::unique_ptr<ams::fs::IStorage> storage_romfs;
|
||||
std::unique_ptr<ams::fs::IStorage> file_romfs;
|
||||
os::Event initialize_event;
|
||||
ncm::ProgramId program_id;
|
||||
bool is_initialized;
|
||||
bool started_initialize;
|
||||
std::vector<romfs::SourceInfo> m_source_infos;
|
||||
std::unique_ptr<ams::fs::IStorage> m_storage_romfs;
|
||||
std::unique_ptr<ams::fs::IStorage> m_file_romfs;
|
||||
os::Event m_initialize_event;
|
||||
ncm::ProgramId m_program_id;
|
||||
bool m_is_initialized;
|
||||
bool m_started_initialize;
|
||||
protected:
|
||||
inline s64 GetSize() const {
|
||||
const auto &back = this->source_infos.back();
|
||||
const auto &back = m_source_infos.back();
|
||||
return back.virtual_offset + back.size;
|
||||
}
|
||||
public:
|
||||
|
||||
@@ -20,10 +20,10 @@ namespace ams::mitm::fs {
|
||||
|
||||
class ReadOnlyLayeredFileSystem : public ams::fs::fsa::IFileSystem {
|
||||
private:
|
||||
ams::fs::ReadOnlyFileSystem fs_1;
|
||||
ams::fs::ReadOnlyFileSystem fs_2;
|
||||
ams::fs::ReadOnlyFileSystem m_fs_1;
|
||||
ams::fs::ReadOnlyFileSystem m_fs_2;
|
||||
public:
|
||||
explicit ReadOnlyLayeredFileSystem(std::unique_ptr<ams::fs::fsa::IFileSystem> a, std::unique_ptr<ams::fs::fsa::IFileSystem> b) : fs_1(std::move(a)), fs_2(std::move(b)) { /* ... */ }
|
||||
explicit ReadOnlyLayeredFileSystem(std::unique_ptr<ams::fs::fsa::IFileSystem> a, std::unique_ptr<ams::fs::fsa::IFileSystem> b) : m_fs_1(std::move(a)), m_fs_2(std::move(b)) { /* ... */ }
|
||||
|
||||
virtual ~ReadOnlyLayeredFileSystem() { /* ... */ }
|
||||
private:
|
||||
@@ -63,18 +63,18 @@ namespace ams::mitm::fs {
|
||||
}
|
||||
|
||||
virtual Result DoGetEntryType(ams::fs::DirectoryEntryType *out, const char *path) override final {
|
||||
R_SUCCEED_IF(R_SUCCEEDED(this->fs_1.GetEntryType(out, path)));
|
||||
return this->fs_2.GetEntryType(out, path);
|
||||
R_SUCCEED_IF(R_SUCCEEDED(m_fs_1.GetEntryType(out, path)));
|
||||
return m_fs_2.GetEntryType(out, path);
|
||||
}
|
||||
|
||||
virtual Result DoOpenFile(std::unique_ptr<ams::fs::fsa::IFile> *out_file, const char *path, ams::fs::OpenMode mode) override final {
|
||||
R_SUCCEED_IF(R_SUCCEEDED(this->fs_1.OpenFile(out_file, path, mode)));
|
||||
return this->fs_2.OpenFile(out_file, path, mode);
|
||||
R_SUCCEED_IF(R_SUCCEEDED(m_fs_1.OpenFile(out_file, path, mode)));
|
||||
return m_fs_2.OpenFile(out_file, path, mode);
|
||||
}
|
||||
|
||||
virtual Result DoOpenDirectory(std::unique_ptr<ams::fs::fsa::IDirectory> *out_dir, const char *path, ams::fs::OpenDirectoryMode mode) override final {
|
||||
R_SUCCEED_IF(R_SUCCEEDED(this->fs_1.OpenDirectory(out_dir, path, mode)));
|
||||
return this->fs_2.OpenDirectory(out_dir, path, mode);
|
||||
R_SUCCEED_IF(R_SUCCEEDED(m_fs_1.OpenDirectory(out_dir, path, mode)));
|
||||
return m_fs_2.OpenDirectory(out_dir, path, mode);
|
||||
}
|
||||
|
||||
virtual Result DoCommit() override final {
|
||||
@@ -97,8 +97,8 @@ namespace ams::mitm::fs {
|
||||
}
|
||||
|
||||
virtual Result DoGetFileTimeStampRaw(ams::fs::FileTimeStampRaw *out, const char *path) {
|
||||
R_SUCCEED_IF(R_SUCCEEDED(this->fs_1.GetFileTimeStampRaw(out, path)));
|
||||
return this->fs_2.GetFileTimeStampRaw(out, path);
|
||||
R_SUCCEED_IF(R_SUCCEEDED(m_fs_1.GetFileTimeStampRaw(out, path)));
|
||||
return m_fs_2.GetFileTimeStampRaw(out, path);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -72,26 +72,26 @@ namespace ams::mitm::fs {
|
||||
static constexpr size_t MaxCachedSize = (1_MB / 4);
|
||||
static constexpr size_t FallbackCacheSize = 1_KB;
|
||||
private:
|
||||
ams::fs::IStorage *storage;
|
||||
size_t offset;
|
||||
size_t size;
|
||||
size_t cache_idx;
|
||||
void *cache;
|
||||
u8 fallback_cache[FallbackCacheSize];
|
||||
ams::fs::IStorage *m_storage;
|
||||
size_t m_offset;
|
||||
size_t m_size;
|
||||
size_t m_cache_idx;
|
||||
void *m_cache;
|
||||
u8 m_fallback_cache[FallbackCacheSize];
|
||||
private:
|
||||
ALWAYS_INLINE void Read(size_t ofs, void *dst, size_t size) {
|
||||
R_ABORT_UNLESS(this->storage->Read(this->offset + ofs, dst, size));
|
||||
R_ABORT_UNLESS(m_storage->Read(m_offset + ofs, dst, size));
|
||||
}
|
||||
ALWAYS_INLINE void ReloadCacheImpl(size_t idx) {
|
||||
const size_t rel_ofs = idx * MaxCachedSize;
|
||||
AMS_ABORT_UNLESS(rel_ofs < this->size);
|
||||
const size_t new_cache_size = std::min(this->size - rel_ofs, MaxCachedSize);
|
||||
this->Read(rel_ofs, this->cache, new_cache_size);
|
||||
this->cache_idx = idx;
|
||||
AMS_ABORT_UNLESS(rel_ofs < m_size);
|
||||
const size_t new_cache_size = std::min(m_size - rel_ofs, MaxCachedSize);
|
||||
this->Read(rel_ofs, m_cache, new_cache_size);
|
||||
m_cache_idx = idx;
|
||||
}
|
||||
|
||||
ALWAYS_INLINE void ReloadCache(size_t idx) {
|
||||
if (this->cache_idx != idx) {
|
||||
if (m_cache_idx != idx) {
|
||||
this->ReloadCacheImpl(idx);
|
||||
}
|
||||
}
|
||||
@@ -100,14 +100,14 @@ namespace ams::mitm::fs {
|
||||
return ofs / MaxCachedSize;
|
||||
}
|
||||
public:
|
||||
TableReader(ams::fs::IStorage *s, size_t ofs, size_t sz) : storage(s), offset(ofs), size(sz), cache_idx(0) {
|
||||
this->cache = std::malloc(std::min(sz, MaxCachedSize));
|
||||
AMS_ABORT_UNLESS(this->cache != nullptr);
|
||||
TableReader(ams::fs::IStorage *s, size_t ofs, size_t sz) : m_storage(s), m_offset(ofs), m_size(sz), m_cache_idx(0) {
|
||||
m_cache = std::malloc(std::min(sz, MaxCachedSize));
|
||||
AMS_ABORT_UNLESS(m_cache != nullptr);
|
||||
this->ReloadCacheImpl(0);
|
||||
}
|
||||
|
||||
~TableReader() {
|
||||
std::free(this->cache);
|
||||
std::free(m_cache);
|
||||
}
|
||||
|
||||
const Entry *GetEntry(u32 entry_offset) {
|
||||
@@ -115,10 +115,10 @@ namespace ams::mitm::fs {
|
||||
|
||||
const size_t ofs = entry_offset % MaxCachedSize;
|
||||
|
||||
const Entry *entry = reinterpret_cast<const Entry *>(reinterpret_cast<uintptr_t>(this->cache) + ofs);
|
||||
const Entry *entry = reinterpret_cast<const Entry *>(reinterpret_cast<uintptr_t>(m_cache) + ofs);
|
||||
if (AMS_UNLIKELY(this->GetCacheIndex(entry_offset) != this->GetCacheIndex(entry_offset + sizeof(Entry) + entry->name_size + sizeof(u32)))) {
|
||||
this->Read(entry_offset, this->fallback_cache, std::min(this->size - entry_offset, FallbackCacheSize));
|
||||
entry = reinterpret_cast<const Entry *>(this->fallback_cache);
|
||||
this->Read(entry_offset, m_fallback_cache, std::min(m_size - entry_offset, FallbackCacheSize));
|
||||
entry = reinterpret_cast<const Entry *>(m_fallback_cache);
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
@@ -132,38 +132,38 @@ namespace ams::mitm::fs {
|
||||
static constexpr size_t MaxCachedSize = (1_MB / 4);
|
||||
static constexpr size_t FallbackCacheSize = 1_KB;
|
||||
private:
|
||||
::FsFile *file;
|
||||
size_t offset;
|
||||
size_t size;
|
||||
size_t cache_idx;
|
||||
void *cache;
|
||||
u8 fallback_cache[FallbackCacheSize];
|
||||
size_t fallback_cache_entry_offset;
|
||||
size_t fallback_cache_entry_size;
|
||||
bool cache_dirty;
|
||||
bool fallback_cache_dirty;
|
||||
::FsFile *m_file;
|
||||
size_t m_offset;
|
||||
size_t m_size;
|
||||
size_t m_cache_idx;
|
||||
void *m_cache;
|
||||
u8 m_fallback_cache[FallbackCacheSize];
|
||||
size_t m_fallback_cache_entry_offset;
|
||||
size_t m_fallback_cache_entry_size;
|
||||
bool m_cache_dirty;
|
||||
bool m_fallback_cache_dirty;
|
||||
private:
|
||||
ALWAYS_INLINE void Read(size_t ofs, void *dst, size_t sz) {
|
||||
u64 read_size;
|
||||
R_ABORT_UNLESS(fsFileRead(this->file, this->offset + ofs, dst, sz, 0, std::addressof(read_size)));
|
||||
R_ABORT_UNLESS(fsFileRead(m_file, m_offset + ofs, dst, sz, 0, std::addressof(read_size)));
|
||||
AMS_ABORT_UNLESS(read_size == sz);
|
||||
}
|
||||
|
||||
ALWAYS_INLINE void Write(size_t ofs, const void *src, size_t sz) {
|
||||
R_ABORT_UNLESS(fsFileWrite(this->file, this->offset + ofs, src, sz, FsWriteOption_None));
|
||||
R_ABORT_UNLESS(fsFileWrite(m_file, m_offset + ofs, src, sz, FsWriteOption_None));
|
||||
}
|
||||
|
||||
ALWAYS_INLINE void Flush() {
|
||||
AMS_ABORT_UNLESS(!(this->cache_dirty && this->fallback_cache_dirty));
|
||||
AMS_ABORT_UNLESS(!(m_cache_dirty && m_fallback_cache_dirty));
|
||||
|
||||
if (this->cache_dirty) {
|
||||
const size_t ofs = this->cache_idx * MaxCachedSize;
|
||||
this->Write(ofs, this->cache, std::min(this->size - ofs, MaxCachedSize));
|
||||
this->cache_dirty = false;
|
||||
if (m_cache_dirty) {
|
||||
const size_t ofs = m_cache_idx * MaxCachedSize;
|
||||
this->Write(ofs, m_cache, std::min(m_size - ofs, MaxCachedSize));
|
||||
m_cache_dirty = false;
|
||||
}
|
||||
if (this->fallback_cache_dirty) {
|
||||
this->Write(this->fallback_cache_entry_offset, this->fallback_cache, this->fallback_cache_entry_size);
|
||||
this->fallback_cache_dirty = false;
|
||||
if (m_fallback_cache_dirty) {
|
||||
this->Write(m_fallback_cache_entry_offset, m_fallback_cache, m_fallback_cache_entry_size);
|
||||
m_fallback_cache_dirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,32 +172,32 @@ namespace ams::mitm::fs {
|
||||
}
|
||||
|
||||
ALWAYS_INLINE void RefreshCacheImpl() {
|
||||
const size_t cur_cache = this->cache_idx * MaxCachedSize;
|
||||
this->Read(cur_cache, this->cache, std::min(this->size - cur_cache, MaxCachedSize));
|
||||
const size_t cur_cache = m_cache_idx * MaxCachedSize;
|
||||
this->Read(cur_cache, m_cache, std::min(m_size - cur_cache, MaxCachedSize));
|
||||
}
|
||||
|
||||
ALWAYS_INLINE void RefreshCache(u32 entry_offset) {
|
||||
if (size_t idx = this->GetCacheIndex(entry_offset); idx != this->cache_idx || this->fallback_cache_dirty) {
|
||||
if (size_t idx = this->GetCacheIndex(entry_offset); idx != m_cache_idx || m_fallback_cache_dirty) {
|
||||
this->Flush();
|
||||
this->cache_idx = idx;
|
||||
m_cache_idx = idx;
|
||||
this->RefreshCacheImpl();
|
||||
}
|
||||
}
|
||||
public:
|
||||
TableWriter(::FsFile *f, size_t ofs, size_t sz) : file(f), offset(ofs), size(sz), cache_idx(0), fallback_cache_entry_offset(), fallback_cache_entry_size(), cache_dirty(), fallback_cache_dirty() {
|
||||
TableWriter(::FsFile *f, size_t ofs, size_t sz) : m_file(f), m_offset(ofs), m_size(sz), m_cache_idx(0), m_fallback_cache_entry_offset(), m_fallback_cache_entry_size(), m_cache_dirty(), m_fallback_cache_dirty() {
|
||||
const size_t cache_size = std::min(sz, MaxCachedSize);
|
||||
this->cache = std::malloc(cache_size);
|
||||
AMS_ABORT_UNLESS(this->cache != nullptr);
|
||||
std::memset(this->cache, 0, cache_size);
|
||||
std::memset(this->fallback_cache, 0, sizeof(this->fallback_cache));
|
||||
for (size_t cur = 0; cur < this->size; cur += MaxCachedSize) {
|
||||
this->Write(cur, this->cache, std::min(this->size - cur, MaxCachedSize));
|
||||
m_cache = std::malloc(cache_size);
|
||||
AMS_ABORT_UNLESS(m_cache != nullptr);
|
||||
std::memset(m_cache, 0, cache_size);
|
||||
std::memset(m_fallback_cache, 0, sizeof(m_fallback_cache));
|
||||
for (size_t cur = 0; cur < m_size; cur += MaxCachedSize) {
|
||||
this->Write(cur, m_cache, std::min(m_size - cur, MaxCachedSize));
|
||||
}
|
||||
}
|
||||
|
||||
~TableWriter() {
|
||||
this->Flush();
|
||||
std::free(this->cache);
|
||||
std::free(m_cache);
|
||||
}
|
||||
|
||||
Entry *GetEntry(u32 entry_offset, u32 name_len) {
|
||||
@@ -205,18 +205,18 @@ namespace ams::mitm::fs {
|
||||
|
||||
const size_t ofs = entry_offset % MaxCachedSize;
|
||||
|
||||
Entry *entry = reinterpret_cast<Entry *>(reinterpret_cast<uintptr_t>(this->cache) + ofs);
|
||||
Entry *entry = reinterpret_cast<Entry *>(reinterpret_cast<uintptr_t>(m_cache) + ofs);
|
||||
if (ofs + sizeof(Entry) + util::AlignUp(name_len, sizeof(u32)) > MaxCachedSize) {
|
||||
this->Flush();
|
||||
|
||||
this->fallback_cache_entry_offset = entry_offset;
|
||||
this->fallback_cache_entry_size = sizeof(Entry) + util::AlignUp(name_len, sizeof(u32));
|
||||
this->Read(this->fallback_cache_entry_offset, this->fallback_cache, this->fallback_cache_entry_size);
|
||||
m_fallback_cache_entry_offset = entry_offset;
|
||||
m_fallback_cache_entry_size = sizeof(Entry) + util::AlignUp(name_len, sizeof(u32));
|
||||
this->Read(m_fallback_cache_entry_offset, m_fallback_cache, m_fallback_cache_entry_size);
|
||||
|
||||
entry = reinterpret_cast<Entry *>(this->fallback_cache);
|
||||
this->fallback_cache_dirty = true;
|
||||
entry = reinterpret_cast<Entry *>(m_fallback_cache);
|
||||
m_fallback_cache_dirty = true;
|
||||
} else {
|
||||
this->cache_dirty = true;
|
||||
m_cache_dirty = true;
|
||||
}
|
||||
|
||||
return entry;
|
||||
@@ -269,12 +269,12 @@ namespace ams::mitm::fs {
|
||||
|
||||
}
|
||||
|
||||
Builder::Builder(ncm::ProgramId pr_id) : program_id(pr_id), num_dirs(0), num_files(0), dir_table_size(0), file_table_size(0), dir_hash_table_size(0), file_hash_table_size(0), file_partition_size(0) {
|
||||
auto res = this->directories.emplace(std::make_unique<BuildDirectoryContext>(BuildDirectoryContext::RootTag{}));
|
||||
Builder::Builder(ncm::ProgramId pr_id) : m_program_id(pr_id), m_num_dirs(0), m_num_files(0), m_dir_table_size(0), m_file_table_size(0), m_dir_hash_table_size(0), m_file_hash_table_size(0), m_file_partition_size(0) {
|
||||
auto res = m_directories.emplace(std::make_unique<BuildDirectoryContext>(BuildDirectoryContext::RootTag{}));
|
||||
AMS_ABORT_UNLESS(res.second);
|
||||
this->root = res.first->get();
|
||||
this->num_dirs = 1;
|
||||
this->dir_table_size = 0x18;
|
||||
m_root = res.first->get();
|
||||
m_num_dirs = 1;
|
||||
m_dir_table_size = 0x18;
|
||||
}
|
||||
|
||||
void Builder::AddDirectory(BuildDirectoryContext **out, BuildDirectoryContext *parent_ctx, std::unique_ptr<BuildDirectoryContext> child_ctx) {
|
||||
@@ -282,18 +282,18 @@ namespace ams::mitm::fs {
|
||||
child_ctx->parent = parent_ctx;
|
||||
|
||||
/* Check if the directory already exists. */
|
||||
auto existing = this->directories.find(child_ctx);
|
||||
if (existing != this->directories.end()) {
|
||||
auto existing = m_directories.find(child_ctx);
|
||||
if (existing != m_directories.end()) {
|
||||
*out = existing->get();
|
||||
return;
|
||||
}
|
||||
|
||||
/* Add a new directory. */
|
||||
this->num_dirs++;
|
||||
this->dir_table_size += sizeof(DirectoryEntry) + util::AlignUp(child_ctx->path_len, 4);
|
||||
m_num_dirs++;
|
||||
m_dir_table_size += sizeof(DirectoryEntry) + util::AlignUp(child_ctx->path_len, 4);
|
||||
|
||||
*out = child_ctx.get();
|
||||
this->directories.emplace(std::move(child_ctx));
|
||||
m_directories.emplace(std::move(child_ctx));
|
||||
}
|
||||
|
||||
void Builder::AddFile(BuildDirectoryContext *parent_ctx, std::unique_ptr<BuildFileContext> file_ctx) {
|
||||
@@ -301,14 +301,14 @@ namespace ams::mitm::fs {
|
||||
file_ctx->parent = parent_ctx;
|
||||
|
||||
/* Check if the file already exists. */
|
||||
if (this->files.find(file_ctx) != this->files.end()) {
|
||||
if (m_files.find(file_ctx) != m_files.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Add a new file. */
|
||||
this->num_files++;
|
||||
this->file_table_size += sizeof(FileEntry) + util::AlignUp(file_ctx->path_len, 4);
|
||||
this->files.emplace(std::move(file_ctx));
|
||||
m_num_files++;
|
||||
m_file_table_size += sizeof(FileEntry) + util::AlignUp(file_ctx->path_len, 4);
|
||||
m_files.emplace(std::move(file_ctx));
|
||||
}
|
||||
|
||||
void Builder::VisitDirectory(FsFileSystem *fs, BuildDirectoryContext *parent) {
|
||||
@@ -317,7 +317,7 @@ namespace ams::mitm::fs {
|
||||
/* Get number of child directories. */
|
||||
s64 num_child_dirs = 0;
|
||||
{
|
||||
OpenFileSystemRomfsDirectory(std::addressof(dir), this->program_id, parent, OpenDirectoryMode_Directory, fs);
|
||||
OpenFileSystemRomfsDirectory(std::addressof(dir), m_program_id, parent, OpenDirectoryMode_Directory, fs);
|
||||
ON_SCOPE_EXIT { fsDirClose(std::addressof(dir)); };
|
||||
R_ABORT_UNLESS(fsDirGetEntryCount(std::addressof(dir), std::addressof(num_child_dirs)));
|
||||
}
|
||||
@@ -330,27 +330,27 @@ namespace ams::mitm::fs {
|
||||
|
||||
s64 cur_child_dir_ind = 0;
|
||||
{
|
||||
OpenFileSystemRomfsDirectory(std::addressof(dir), this->program_id, parent, OpenDirectoryMode_All, fs);
|
||||
OpenFileSystemRomfsDirectory(std::addressof(dir), m_program_id, parent, OpenDirectoryMode_All, fs);
|
||||
ON_SCOPE_EXIT { fsDirClose(std::addressof(dir)); };
|
||||
|
||||
s64 read_entries = 0;
|
||||
while (true) {
|
||||
R_ABORT_UNLESS(fsDirRead(std::addressof(dir), std::addressof(read_entries), 1, std::addressof(this->dir_entry)));
|
||||
R_ABORT_UNLESS(fsDirRead(std::addressof(dir), std::addressof(read_entries), 1, std::addressof(m_dir_entry)));
|
||||
if (read_entries != 1) {
|
||||
break;
|
||||
}
|
||||
|
||||
AMS_ABORT_UNLESS(this->dir_entry.type == FsDirEntryType_Dir || this->dir_entry.type == FsDirEntryType_File);
|
||||
if (this->dir_entry.type == FsDirEntryType_Dir) {
|
||||
AMS_ABORT_UNLESS(m_dir_entry.type == FsDirEntryType_Dir || m_dir_entry.type == FsDirEntryType_File);
|
||||
if (m_dir_entry.type == FsDirEntryType_Dir) {
|
||||
AMS_ABORT_UNLESS(child_dirs != nullptr);
|
||||
|
||||
BuildDirectoryContext *real_child = nullptr;
|
||||
this->AddDirectory(std::addressof(real_child), parent, std::make_unique<BuildDirectoryContext>(this->dir_entry.name, strlen(this->dir_entry.name)));
|
||||
this->AddDirectory(std::addressof(real_child), parent, std::make_unique<BuildDirectoryContext>(m_dir_entry.name, strlen(m_dir_entry.name)));
|
||||
AMS_ABORT_UNLESS(real_child != nullptr);
|
||||
child_dirs[cur_child_dir_ind++] = real_child;
|
||||
AMS_ABORT_UNLESS(cur_child_dir_ind <= num_child_dirs);
|
||||
} else /* if (this->dir_entry.type == FsDirEntryType_File) */ {
|
||||
this->AddFile(parent, std::make_unique<BuildFileContext>(this->dir_entry.name, strlen(this->dir_entry.name), this->dir_entry.file_size, 0, this->cur_source_type));
|
||||
} else /* if (m_dir_entry.type == FsDirEntryType_File) */ {
|
||||
this->AddFile(parent, std::make_unique<BuildFileContext>(m_dir_entry.name, strlen(m_dir_entry.name), m_dir_entry.file_size, 0, m_cur_source_type));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -380,7 +380,7 @@ namespace ams::mitm::fs {
|
||||
while (cur_file_offset != EmptyEntry) {
|
||||
const FileEntry *cur_file = file_table.GetEntry(cur_file_offset);
|
||||
|
||||
this->AddFile(parent, std::make_unique<BuildFileContext>(cur_file->name, cur_file->name_size, cur_file->size, cur_file->offset, this->cur_source_type));
|
||||
this->AddFile(parent, std::make_unique<BuildFileContext>(cur_file->name, cur_file->name_size, cur_file->size, cur_file->offset, m_cur_source_type));
|
||||
|
||||
cur_file_offset = cur_file->sibling;
|
||||
}
|
||||
@@ -415,14 +415,14 @@ namespace ams::mitm::fs {
|
||||
/* If there is no romfs folder on the SD, don't bother continuing. */
|
||||
{
|
||||
FsDir dir;
|
||||
if (R_FAILED(mitm::fs::OpenAtmosphereRomfsDirectory(std::addressof(dir), this->program_id, this->root->path.get(), OpenDirectoryMode_Directory, std::addressof(sd_filesystem)))) {
|
||||
if (R_FAILED(mitm::fs::OpenAtmosphereRomfsDirectory(std::addressof(dir), m_program_id, m_root->path.get(), OpenDirectoryMode_Directory, std::addressof(sd_filesystem)))) {
|
||||
return;
|
||||
}
|
||||
fsDirClose(std::addressof(dir));
|
||||
}
|
||||
|
||||
this->cur_source_type = DataSourceType::LooseSdFile;
|
||||
this->VisitDirectory(std::addressof(sd_filesystem), this->root);
|
||||
m_cur_source_type = DataSourceType::LooseSdFile;
|
||||
this->VisitDirectory(std::addressof(sd_filesystem), m_root);
|
||||
}
|
||||
|
||||
void Builder::AddStorageFiles(ams::fs::IStorage *storage, DataSourceType source_type) {
|
||||
@@ -434,8 +434,8 @@ namespace ams::mitm::fs {
|
||||
DirectoryTableReader dir_table(storage, header.dir_table_ofs, header.dir_table_size);
|
||||
FileTableReader file_table(storage, header.file_table_ofs, header.file_table_size);
|
||||
|
||||
this->cur_source_type = source_type;
|
||||
this->VisitDirectory(this->root, 0x0, dir_table, file_table);
|
||||
m_cur_source_type = source_type;
|
||||
this->VisitDirectory(m_root, 0x0, dir_table, file_table);
|
||||
}
|
||||
|
||||
void Builder::Build(std::vector<SourceInfo> *out_infos) {
|
||||
@@ -448,19 +448,19 @@ namespace ams::mitm::fs {
|
||||
ON_SCOPE_EXIT { fsFsClose(std::addressof(sd_filesystem)); };
|
||||
|
||||
/* Calculate hash table sizes. */
|
||||
const size_t num_dir_hash_table_entries = GetHashTableSize(this->num_dirs);
|
||||
const size_t num_file_hash_table_entries = GetHashTableSize(this->num_files);
|
||||
this->dir_hash_table_size = sizeof(u32) * num_dir_hash_table_entries;
|
||||
this->file_hash_table_size = sizeof(u32) * num_file_hash_table_entries;
|
||||
const size_t num_dir_hash_table_entries = GetHashTableSize(m_num_dirs);
|
||||
const size_t num_file_hash_table_entries = GetHashTableSize(m_num_files);
|
||||
m_dir_hash_table_size = sizeof(u32) * num_dir_hash_table_entries;
|
||||
m_file_hash_table_size = sizeof(u32) * num_file_hash_table_entries;
|
||||
|
||||
/* Allocate metadata, make pointers. */
|
||||
Header *header = reinterpret_cast<Header *>(std::malloc(sizeof(Header)));
|
||||
std::memset(header, 0x00, sizeof(*header));
|
||||
|
||||
/* Open metadata file. */
|
||||
const size_t metadata_size = this->dir_hash_table_size + this->dir_table_size + this->file_hash_table_size + this->file_table_size;
|
||||
const size_t metadata_size = m_dir_hash_table_size + m_dir_table_size + m_file_hash_table_size + m_file_table_size;
|
||||
FsFile metadata_file;
|
||||
R_ABORT_UNLESS(mitm::fs::CreateAndOpenAtmosphereSdFile(std::addressof(metadata_file), this->program_id, "romfs_metadata.bin", metadata_size));
|
||||
R_ABORT_UNLESS(mitm::fs::CreateAndOpenAtmosphereSdFile(std::addressof(metadata_file), m_program_id, "romfs_metadata.bin", metadata_size));
|
||||
|
||||
/* Ensure later hash tables will have correct defaults. */
|
||||
static_assert(EmptyEntry == 0xFFFFFFFF);
|
||||
@@ -473,25 +473,25 @@ namespace ams::mitm::fs {
|
||||
u32 entry_offset = 0;
|
||||
BuildFileContext *cur_file = nullptr;
|
||||
BuildFileContext *prev_file = nullptr;
|
||||
for (const auto &it : this->files) {
|
||||
for (const auto &it : m_files) {
|
||||
cur_file = it.get();
|
||||
|
||||
/* By default, pad to 0x10 alignment. */
|
||||
this->file_partition_size = util::AlignUp(this->file_partition_size, 0x10);
|
||||
m_file_partition_size = util::AlignUp(m_file_partition_size, 0x10);
|
||||
|
||||
/* Check if extra padding is present in original source, preserve it to make our life easier. */
|
||||
const bool is_storage_or_file = cur_file->source_type == DataSourceType::Storage || cur_file->source_type == DataSourceType::File;
|
||||
if (prev_file != nullptr && prev_file->source_type == cur_file->source_type && is_storage_or_file) {
|
||||
const s64 expected = this->file_partition_size - prev_file->offset + prev_file->orig_offset;
|
||||
const s64 expected = m_file_partition_size - prev_file->offset + prev_file->orig_offset;
|
||||
if (expected != cur_file->orig_offset) {
|
||||
AMS_ABORT_UNLESS(expected <= cur_file->orig_offset);
|
||||
this->file_partition_size += cur_file->orig_offset - expected;
|
||||
m_file_partition_size += cur_file->orig_offset - expected;
|
||||
}
|
||||
}
|
||||
|
||||
/* Calculate offsets. */
|
||||
cur_file->offset = this->file_partition_size;
|
||||
this->file_partition_size += cur_file->size;
|
||||
cur_file->offset = m_file_partition_size;
|
||||
m_file_partition_size += cur_file->size;
|
||||
cur_file->entry_offset = entry_offset;
|
||||
entry_offset += sizeof(FileEntry) + util::AlignUp(cur_file->path_len, 4);
|
||||
|
||||
@@ -499,7 +499,7 @@ namespace ams::mitm::fs {
|
||||
prev_file = cur_file;
|
||||
}
|
||||
/* Assign deferred parent/sibling ownership. */
|
||||
for (auto it = this->files.rbegin(); it != this->files.rend(); it++) {
|
||||
for (auto it = m_files.rbegin(); it != m_files.rend(); it++) {
|
||||
cur_file = it->get();
|
||||
cur_file->sibling = cur_file->parent->file;
|
||||
cur_file->parent->file = cur_file;
|
||||
@@ -510,15 +510,15 @@ namespace ams::mitm::fs {
|
||||
{
|
||||
u32 entry_offset = 0;
|
||||
BuildDirectoryContext *cur_dir = nullptr;
|
||||
for (const auto &it : this->directories) {
|
||||
for (const auto &it : m_directories) {
|
||||
cur_dir = it.get();
|
||||
cur_dir->entry_offset = entry_offset;
|
||||
entry_offset += sizeof(DirectoryEntry) + util::AlignUp(cur_dir->path_len, 4);
|
||||
}
|
||||
/* Assign deferred parent/sibling ownership. */
|
||||
for (auto it = this->directories.rbegin(); it != this->directories.rend(); it++) {
|
||||
for (auto it = m_directories.rbegin(); it != m_directories.rend(); it++) {
|
||||
cur_dir = it->get();
|
||||
if (cur_dir == this->root) {
|
||||
if (cur_dir == m_root) {
|
||||
continue;
|
||||
}
|
||||
cur_dir->sibling = cur_dir->parent->child;
|
||||
@@ -529,20 +529,20 @@ namespace ams::mitm::fs {
|
||||
/* Populate file tables. */
|
||||
{
|
||||
/* Allocate the hash table. */
|
||||
void *fht_buf = std::malloc(this->file_hash_table_size);
|
||||
void *fht_buf = std::malloc(m_file_hash_table_size);
|
||||
AMS_ABORT_UNLESS(fht_buf != nullptr);
|
||||
u32 *file_hash_table = reinterpret_cast<u32 *>(fht_buf);
|
||||
std::memset(file_hash_table, 0xFF, this->file_hash_table_size);
|
||||
std::memset(file_hash_table, 0xFF, m_file_hash_table_size);
|
||||
ON_SCOPE_EXIT {
|
||||
R_ABORT_UNLESS(fsFileWrite(std::addressof(metadata_file), this->dir_hash_table_size + this->dir_table_size, file_hash_table, this->file_hash_table_size, FsWriteOption_None));
|
||||
R_ABORT_UNLESS(fsFileWrite(std::addressof(metadata_file), m_dir_hash_table_size + m_dir_table_size, file_hash_table, m_file_hash_table_size, FsWriteOption_None));
|
||||
std::free(fht_buf);
|
||||
};
|
||||
|
||||
/* Write the file table. */
|
||||
{
|
||||
FileTableWriter file_table(std::addressof(metadata_file), this->dir_hash_table_size + this->dir_table_size + this->file_hash_table_size, this->file_table_size);
|
||||
FileTableWriter file_table(std::addressof(metadata_file), m_dir_hash_table_size + m_dir_table_size + m_file_hash_table_size, m_file_table_size);
|
||||
|
||||
for (const auto &it : this->files) {
|
||||
for (const auto &it : m_files) {
|
||||
BuildFileContext *cur_file = it.get();
|
||||
FileEntry *cur_entry = file_table.GetEntry(cur_file->entry_offset, cur_file->path_len);
|
||||
|
||||
@@ -597,25 +597,25 @@ namespace ams::mitm::fs {
|
||||
/* Populate directory tables. */
|
||||
{
|
||||
/* Allocate the hash table. */
|
||||
void *dht_buf = std::malloc(this->dir_hash_table_size);
|
||||
void *dht_buf = std::malloc(m_dir_hash_table_size);
|
||||
AMS_ABORT_UNLESS(dht_buf != nullptr);
|
||||
u32 *dir_hash_table = reinterpret_cast<u32 *>(dht_buf);
|
||||
std::memset(dir_hash_table, 0xFF, this->dir_hash_table_size);
|
||||
std::memset(dir_hash_table, 0xFF, m_dir_hash_table_size);
|
||||
ON_SCOPE_EXIT {
|
||||
R_ABORT_UNLESS(fsFileWrite(std::addressof(metadata_file), 0, dir_hash_table, this->dir_hash_table_size, FsWriteOption_None));
|
||||
R_ABORT_UNLESS(fsFileWrite(std::addressof(metadata_file), 0, dir_hash_table, m_dir_hash_table_size, FsWriteOption_None));
|
||||
std::free(dht_buf);
|
||||
};
|
||||
|
||||
/* Write the file table. */
|
||||
{
|
||||
DirectoryTableWriter dir_table(std::addressof(metadata_file), this->dir_hash_table_size, this->dir_table_size);
|
||||
DirectoryTableWriter dir_table(std::addressof(metadata_file), m_dir_hash_table_size, m_dir_table_size);
|
||||
|
||||
for (const auto &it : this->directories) {
|
||||
for (const auto &it : m_directories) {
|
||||
BuildDirectoryContext *cur_dir = it.get();
|
||||
DirectoryEntry *cur_entry = dir_table.GetEntry(cur_dir->entry_offset, cur_dir->path_len);
|
||||
|
||||
/* Set entry fields. */
|
||||
cur_entry->parent = cur_dir == this->root ? 0 : cur_dir->parent->entry_offset;
|
||||
cur_entry->parent = cur_dir == m_root ? 0 : cur_dir->parent->entry_offset;
|
||||
cur_entry->sibling = (cur_dir->sibling == nullptr) ? EmptyEntry : cur_dir->sibling->entry_offset;
|
||||
cur_entry->child = (cur_dir->child == nullptr) ? EmptyEntry : cur_dir->child->entry_offset;
|
||||
cur_entry->file = (cur_dir->file == nullptr) ? EmptyEntry : cur_dir->file->entry_offset;
|
||||
@@ -639,21 +639,21 @@ namespace ams::mitm::fs {
|
||||
}
|
||||
|
||||
/* Delete maps. */
|
||||
this->root = nullptr;
|
||||
this->directories.clear();
|
||||
this->files.clear();
|
||||
m_root = nullptr;
|
||||
m_directories.clear();
|
||||
m_files.clear();
|
||||
|
||||
/* Set header fields. */
|
||||
header->header_size = sizeof(*header);
|
||||
header->file_hash_table_size = this->file_hash_table_size;
|
||||
header->file_table_size = this->file_table_size;
|
||||
header->dir_hash_table_size = this->dir_hash_table_size;
|
||||
header->dir_table_size = this->dir_table_size;
|
||||
header->file_partition_ofs = FilePartitionOffset;
|
||||
header->dir_hash_table_ofs = util::AlignUp(FilePartitionOffset + this->file_partition_size, 4);
|
||||
header->dir_table_ofs = header->dir_hash_table_ofs + header->dir_hash_table_size;
|
||||
header->file_hash_table_ofs = header->dir_table_ofs + header->dir_table_size;
|
||||
header->file_table_ofs = header->file_hash_table_ofs + header->file_hash_table_size;
|
||||
header->header_size = sizeof(*header);
|
||||
header->file_hash_table_size = m_file_hash_table_size;
|
||||
header->file_table_size = m_file_table_size;
|
||||
header->dir_hash_table_size = m_dir_hash_table_size;
|
||||
header->dir_table_size = m_dir_table_size;
|
||||
header->file_partition_ofs = FilePartitionOffset;
|
||||
header->dir_hash_table_ofs = util::AlignUp(FilePartitionOffset + m_file_partition_size, 4);
|
||||
header->dir_table_ofs = header->dir_hash_table_ofs + header->dir_hash_table_size;
|
||||
header->file_hash_table_ofs = header->dir_table_ofs + header->dir_table_size;
|
||||
header->file_table_ofs = header->file_hash_table_ofs + header->file_hash_table_size;
|
||||
|
||||
/* Save metadata to the SD card, to save on memory space. */
|
||||
{
|
||||
|
||||
@@ -202,7 +202,7 @@ namespace ams::mitm::fs::romfs {
|
||||
class DirectoryTableReader;
|
||||
class FileTableReader;
|
||||
|
||||
struct Builder {
|
||||
class Builder {
|
||||
NON_COPYABLE(Builder);
|
||||
NON_MOVEABLE(Builder);
|
||||
private:
|
||||
@@ -230,20 +230,20 @@ namespace ams::mitm::fs::romfs {
|
||||
template<typename T>
|
||||
using ContextSet = std::set<std::unique_ptr<T>, Comparator<T>>;
|
||||
private:
|
||||
ncm::ProgramId program_id;
|
||||
BuildDirectoryContext *root;
|
||||
ContextSet<BuildDirectoryContext> directories;
|
||||
ContextSet<BuildFileContext> files;
|
||||
size_t num_dirs;
|
||||
size_t num_files;
|
||||
size_t dir_table_size;
|
||||
size_t file_table_size;
|
||||
size_t dir_hash_table_size;
|
||||
size_t file_hash_table_size;
|
||||
size_t file_partition_size;
|
||||
ncm::ProgramId m_program_id;
|
||||
BuildDirectoryContext *m_root;
|
||||
ContextSet<BuildDirectoryContext> m_directories;
|
||||
ContextSet<BuildFileContext> m_files;
|
||||
size_t m_num_dirs;
|
||||
size_t m_num_files;
|
||||
size_t m_dir_table_size;
|
||||
size_t m_file_table_size;
|
||||
size_t m_dir_hash_table_size;
|
||||
size_t m_file_hash_table_size;
|
||||
size_t m_file_partition_size;
|
||||
|
||||
ams::fs::DirectoryEntry dir_entry;
|
||||
DataSourceType cur_source_type;
|
||||
ams::fs::DirectoryEntry m_dir_entry;
|
||||
DataSourceType m_cur_source_type;
|
||||
private:
|
||||
void VisitDirectory(FsFileSystem *fs, BuildDirectoryContext *parent);
|
||||
void VisitDirectory(BuildDirectoryContext *parent, u32 parent_offset, DirectoryTableReader &dir_table, FileTableReader &file_table);
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
namespace ams::mitm::ns {
|
||||
|
||||
Result NsAmMitmService::GetApplicationContentPath(const sf::OutBuffer &out_path, ncm::ProgramId application_id, u8 content_type) {
|
||||
return nsamGetApplicationContentPathFwd(this->forward_service.get(), out_path.GetPointer(), out_path.GetSize(), static_cast<u64>(application_id), static_cast<NcmContentType>(content_type));
|
||||
return nsamGetApplicationContentPathFwd(m_forward_service.get(), out_path.GetPointer(), out_path.GetSize(), static_cast<u64>(application_id), static_cast<NcmContentType>(content_type));
|
||||
}
|
||||
|
||||
Result NsAmMitmService::ResolveApplicationContentPath(ncm::ProgramId application_id, u8 content_type) {
|
||||
@@ -28,14 +28,14 @@ namespace ams::mitm::ns {
|
||||
/* This enables hbl html. */
|
||||
bool is_hbl;
|
||||
if (R_SUCCEEDED(pm::info::IsHblProgramId(&is_hbl, application_id)) && is_hbl) {
|
||||
nsamResolveApplicationContentPathFwd(this->forward_service.get(), static_cast<u64>(application_id), static_cast<NcmContentType>(content_type));
|
||||
nsamResolveApplicationContentPathFwd(m_forward_service.get(), static_cast<u64>(application_id), static_cast<NcmContentType>(content_type));
|
||||
return ResultSuccess();
|
||||
}
|
||||
return nsamResolveApplicationContentPathFwd(this->forward_service.get(), static_cast<u64>(application_id), static_cast<NcmContentType>(content_type));
|
||||
return nsamResolveApplicationContentPathFwd(m_forward_service.get(), static_cast<u64>(application_id), static_cast<NcmContentType>(content_type));
|
||||
}
|
||||
|
||||
Result NsAmMitmService::GetRunningApplicationProgramId(sf::Out<ncm::ProgramId> out, ncm::ProgramId application_id) {
|
||||
return nsamGetRunningApplicationProgramIdFwd(this->forward_service.get(), reinterpret_cast<u64 *>(out.GetPointer()), static_cast<u64>(application_id));
|
||||
return nsamGetRunningApplicationProgramIdFwd(m_forward_service.get(), reinterpret_cast<u64 *>(out.GetPointer()), static_cast<u64>(application_id));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
namespace ams::mitm::ns {
|
||||
|
||||
Result NsDocumentService::GetApplicationContentPath(const sf::OutBuffer &out_path, ncm::ProgramId application_id, u8 content_type) {
|
||||
return nswebGetApplicationContentPath(this->srv.get(), out_path.GetPointer(), out_path.GetSize(), static_cast<u64>(application_id), static_cast<NcmContentType>(content_type));
|
||||
return nswebGetApplicationContentPath(m_srv.get(), out_path.GetPointer(), out_path.GetSize(), static_cast<u64>(application_id), static_cast<NcmContentType>(content_type));
|
||||
}
|
||||
|
||||
Result NsDocumentService::ResolveApplicationContentPath(ncm::ProgramId application_id, u8 content_type) {
|
||||
@@ -27,23 +27,23 @@ namespace ams::mitm::ns {
|
||||
/* This enables hbl html. */
|
||||
bool is_hbl;
|
||||
if (R_SUCCEEDED(pm::info::IsHblProgramId(std::addressof(is_hbl), application_id)) && is_hbl) {
|
||||
nswebResolveApplicationContentPath(this->srv.get(), static_cast<u64>(application_id), static_cast<NcmContentType>(content_type));
|
||||
nswebResolveApplicationContentPath(m_srv.get(), static_cast<u64>(application_id), static_cast<NcmContentType>(content_type));
|
||||
return ResultSuccess();
|
||||
}
|
||||
return nswebResolveApplicationContentPath(this->srv.get(), static_cast<u64>(application_id), static_cast<NcmContentType>(content_type));
|
||||
return nswebResolveApplicationContentPath(m_srv.get(), static_cast<u64>(application_id), static_cast<NcmContentType>(content_type));
|
||||
}
|
||||
|
||||
Result NsDocumentService::GetRunningApplicationProgramId(sf::Out<ncm::ProgramId> out, ncm::ProgramId application_id) {
|
||||
return nswebGetRunningApplicationProgramId(this->srv.get(), reinterpret_cast<u64 *>(out.GetPointer()), static_cast<u64>(application_id));
|
||||
return nswebGetRunningApplicationProgramId(m_srv.get(), reinterpret_cast<u64 *>(out.GetPointer()), static_cast<u64>(application_id));
|
||||
}
|
||||
|
||||
Result NsWebMitmService::GetDocumentInterface(sf::Out<sf::SharedPointer<impl::IDocumentInterface>> out) {
|
||||
/* Open a document interface. */
|
||||
NsDocumentInterface doc;
|
||||
R_TRY(nsGetDocumentInterfaceFwd(this->forward_service.get(), std::addressof(doc)));
|
||||
R_TRY(nsGetDocumentInterfaceFwd(m_forward_service.get(), std::addressof(doc)));
|
||||
const sf::cmif::DomainObjectId target_object_id{serviceGetObjectId(std::addressof(doc.s))};
|
||||
|
||||
out.SetValue(sf::CreateSharedObjectEmplaced<impl::IDocumentInterface, NsDocumentService>(this->client_info, std::make_unique<NsDocumentInterface>(doc)), target_object_id);
|
||||
out.SetValue(sf::CreateSharedObjectEmplaced<impl::IDocumentInterface, NsDocumentService>(m_client_info, std::make_unique<NsDocumentInterface>(doc)), target_object_id);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
|
||||
@@ -34,13 +34,13 @@ namespace ams::mitm::ns {
|
||||
|
||||
class NsDocumentService {
|
||||
private:
|
||||
sm::MitmProcessInfo client_info;
|
||||
std::unique_ptr<::NsDocumentInterface> srv;
|
||||
sm::MitmProcessInfo m_client_info;
|
||||
std::unique_ptr<::NsDocumentInterface> m_srv;
|
||||
public:
|
||||
NsDocumentService(const sm::MitmProcessInfo &cl, std::unique_ptr<::NsDocumentInterface> s) : client_info(cl), srv(std::move(s)) { /* .. */ }
|
||||
NsDocumentService(const sm::MitmProcessInfo &cl, std::unique_ptr<::NsDocumentInterface> s) : m_client_info(cl), m_srv(std::move(s)) { /* .. */ }
|
||||
|
||||
virtual ~NsDocumentService() {
|
||||
nsDocumentInterfaceClose(this->srv.get());
|
||||
nsDocumentInterfaceClose(m_srv.get());
|
||||
}
|
||||
public:
|
||||
/* Actual command API. */
|
||||
|
||||
@@ -30,13 +30,13 @@ namespace ams::mitm::settings {
|
||||
}
|
||||
|
||||
SetMitmService::SetMitmService(std::shared_ptr<::Service> &&s, const sm::MitmProcessInfo &c) : sf::MitmServiceImplBase(std::forward<std::shared_ptr<::Service>>(s), c) {
|
||||
if (this->client_info.program_id == ncm::SystemProgramId::Ns) {
|
||||
if (m_client_info.program_id == ncm::SystemProgramId::Ns) {
|
||||
os::ProcessId application_process_id;
|
||||
if (R_SUCCEEDED(pm::dmnt::GetApplicationProcessId(std::addressof(application_process_id))) && g_application_process_id == application_process_id) {
|
||||
this->locale = g_application_locale;
|
||||
this->is_valid_language = g_valid_language;
|
||||
this->is_valid_region = g_valid_region;
|
||||
this->got_locale = true;
|
||||
m_locale = g_application_locale;
|
||||
m_is_valid_language = g_valid_language;
|
||||
m_is_valid_region = g_valid_region;
|
||||
m_got_locale = true;
|
||||
} else {
|
||||
this->InvalidateLocale();
|
||||
}
|
||||
@@ -47,16 +47,16 @@ namespace ams::mitm::settings {
|
||||
|
||||
Result SetMitmService::EnsureLocale() {
|
||||
/* Optimization: if locale has already been gotten, we can stop. */
|
||||
if (AMS_LIKELY(this->got_locale)) {
|
||||
if (AMS_LIKELY(m_got_locale)) {
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
std::scoped_lock lk(this->lock);
|
||||
std::scoped_lock lk(m_lock);
|
||||
|
||||
const bool is_ns = this->client_info.program_id == ncm::SystemProgramId::Ns;
|
||||
const bool is_ns = m_client_info.program_id == ncm::SystemProgramId::Ns;
|
||||
|
||||
if (!this->got_locale) {
|
||||
ncm::ProgramId program_id = this->client_info.program_id;
|
||||
if (!m_got_locale) {
|
||||
ncm::ProgramId program_id = m_client_info.program_id;
|
||||
os::ProcessId application_process_id = os::InvalidProcessId;
|
||||
|
||||
if (is_ns) {
|
||||
@@ -64,15 +64,15 @@ namespace ams::mitm::settings {
|
||||
R_TRY(pm::dmnt::GetApplicationProcessId(std::addressof(application_process_id)));
|
||||
R_TRY(pm::info::GetProgramId(std::addressof(program_id), application_process_id));
|
||||
}
|
||||
this->locale = cfg::GetOverrideLocale(program_id);
|
||||
this->is_valid_language = settings::IsValidLanguageCode(this->locale.language_code);
|
||||
this->is_valid_region = settings::IsValidRegionCode(this->locale.region_code);
|
||||
this->got_locale = true;
|
||||
m_locale = cfg::GetOverrideLocale(program_id);
|
||||
m_is_valid_language = settings::IsValidLanguageCode(m_locale.language_code);
|
||||
m_is_valid_region = settings::IsValidRegionCode(m_locale.region_code);
|
||||
m_got_locale = true;
|
||||
|
||||
if (is_ns) {
|
||||
g_application_locale = this->locale;
|
||||
g_valid_language = this->is_valid_language;
|
||||
g_valid_region = this->is_valid_region;
|
||||
g_application_locale = m_locale;
|
||||
g_valid_language = m_is_valid_language;
|
||||
g_valid_region = m_is_valid_region;
|
||||
g_application_process_id = application_process_id;
|
||||
}
|
||||
}
|
||||
@@ -81,30 +81,30 @@ namespace ams::mitm::settings {
|
||||
}
|
||||
|
||||
void SetMitmService::InvalidateLocale() {
|
||||
std::scoped_lock lk(this->lock);
|
||||
std::scoped_lock lk(m_lock);
|
||||
|
||||
std::memset(std::addressof(this->locale), 0xCC, sizeof(this->locale));
|
||||
this->is_valid_language = false;
|
||||
this->is_valid_region = false;
|
||||
this->got_locale = false;
|
||||
std::memset(std::addressof(m_locale), 0xCC, sizeof(m_locale));
|
||||
m_is_valid_language = false;
|
||||
m_is_valid_region = false;
|
||||
m_got_locale = false;
|
||||
}
|
||||
|
||||
Result SetMitmService::GetLanguageCode(sf::Out<settings::LanguageCode> out) {
|
||||
this->EnsureLocale();
|
||||
|
||||
/* If there's no override locale, just use the actual one. */
|
||||
if (AMS_UNLIKELY(!this->is_valid_language)) {
|
||||
if (AMS_UNLIKELY(!m_is_valid_language)) {
|
||||
static_assert(sizeof(u64) == sizeof(settings::LanguageCode));
|
||||
R_TRY(setGetLanguageCodeFwd(this->forward_service.get(), reinterpret_cast<u64 *>(std::addressof(this->locale.language_code))));
|
||||
R_TRY(setGetLanguageCodeFwd(m_forward_service.get(), reinterpret_cast<u64 *>(std::addressof(m_locale.language_code))));
|
||||
|
||||
this->is_valid_language = true;
|
||||
if (this->client_info.program_id == ncm::SystemProgramId::Ns) {
|
||||
g_application_locale.language_code = this->locale.language_code;
|
||||
m_is_valid_language = true;
|
||||
if (m_client_info.program_id == ncm::SystemProgramId::Ns) {
|
||||
g_application_locale.language_code = m_locale.language_code;
|
||||
g_valid_language = true;
|
||||
}
|
||||
}
|
||||
|
||||
out.SetValue(this->locale.language_code);
|
||||
out.SetValue(m_locale.language_code);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
@@ -112,18 +112,18 @@ namespace ams::mitm::settings {
|
||||
this->EnsureLocale();
|
||||
|
||||
/* If there's no override locale, just use the actual one. */
|
||||
if (AMS_UNLIKELY(!this->is_valid_region)) {
|
||||
if (AMS_UNLIKELY(!m_is_valid_region)) {
|
||||
static_assert(sizeof(::SetRegion) == sizeof(settings::RegionCode));
|
||||
R_TRY(setGetRegionCodeFwd(this->forward_service.get(), reinterpret_cast<::SetRegion *>(std::addressof(this->locale.region_code))));
|
||||
R_TRY(setGetRegionCodeFwd(m_forward_service.get(), reinterpret_cast<::SetRegion *>(std::addressof(m_locale.region_code))));
|
||||
|
||||
this->is_valid_region = true;
|
||||
if (this->client_info.program_id == ncm::SystemProgramId::Ns) {
|
||||
g_application_locale.region_code = this->locale.region_code;
|
||||
m_is_valid_region = true;
|
||||
if (m_client_info.program_id == ncm::SystemProgramId::Ns) {
|
||||
g_application_locale.region_code = m_locale.region_code;
|
||||
g_valid_region = true;
|
||||
}
|
||||
}
|
||||
|
||||
out.SetValue(this->locale.region_code);
|
||||
out.SetValue(m_locale.region_code);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
|
||||
@@ -26,11 +26,11 @@ namespace ams::mitm::settings {
|
||||
|
||||
class SetMitmService : public sf::MitmServiceImplBase {
|
||||
private:
|
||||
os::SdkMutex lock{};
|
||||
cfg::OverrideLocale locale;
|
||||
bool got_locale = false;
|
||||
bool is_valid_language = false;
|
||||
bool is_valid_region = false;
|
||||
os::SdkMutex m_lock{};
|
||||
cfg::OverrideLocale m_locale;
|
||||
bool m_got_locale = false;
|
||||
bool m_is_valid_language = false;
|
||||
bool m_is_valid_region = false;
|
||||
public:
|
||||
SetMitmService(std::shared_ptr<::Service> &&s, const sm::MitmProcessInfo &c);
|
||||
public:
|
||||
|
||||
@@ -90,7 +90,7 @@ namespace ams::mitm::settings {
|
||||
}
|
||||
|
||||
Result SetSysMitmService::GetFirmwareVersion(sf::Out<settings::FirmwareVersion> out) {
|
||||
R_TRY(GetFirmwareVersionImpl(out.GetPointer(), this->client_info));
|
||||
R_TRY(GetFirmwareVersionImpl(out.GetPointer(), m_client_info));
|
||||
|
||||
/* GetFirmwareVersion sanitizes the revision fields. */
|
||||
out.GetPointer()->revision_major = 0;
|
||||
@@ -99,7 +99,7 @@ namespace ams::mitm::settings {
|
||||
}
|
||||
|
||||
Result SetSysMitmService::GetFirmwareVersion2(sf::Out<settings::FirmwareVersion> out) {
|
||||
return GetFirmwareVersionImpl(out.GetPointer(), this->client_info);
|
||||
return GetFirmwareVersionImpl(out.GetPointer(), m_client_info);
|
||||
}
|
||||
|
||||
Result SetSysMitmService::GetSettingsItemValueSize(sf::Out<u64> out_size, const settings::SettingsName &name, const settings::SettingsItemKey &key) {
|
||||
@@ -122,7 +122,7 @@ namespace ams::mitm::settings {
|
||||
|
||||
Result SetSysMitmService::GetDebugModeFlag(sf::Out<bool> out) {
|
||||
/* If we're not processing for am, just return the real flag value. */
|
||||
R_UNLESS(this->client_info.program_id == ncm::SystemProgramId::Am, sm::mitm::ResultShouldForwardToSession());
|
||||
R_UNLESS(m_client_info.program_id == ncm::SystemProgramId::Am, sm::mitm::ResultShouldForwardToSession());
|
||||
|
||||
/* Retrieve the user configuration. */
|
||||
u8 en = 0;
|
||||
|
||||
@@ -79,7 +79,7 @@ namespace ams::mitm::sysupdater {
|
||||
|
||||
Result SystemUpdateApplyManager::ApplyPackageTask(ncm::PackageSystemDowngradeTask *task) {
|
||||
/* Lock the apply mutex. */
|
||||
std::scoped_lock lk(this->apply_mutex);
|
||||
std::scoped_lock lk(m_apply_mutex);
|
||||
|
||||
/* NOTE: Here, Nintendo creates a system report for the update. */
|
||||
|
||||
|
||||
@@ -20,9 +20,9 @@ namespace ams::mitm::sysupdater {
|
||||
|
||||
class SystemUpdateApplyManager {
|
||||
private:
|
||||
os::SdkMutex apply_mutex;
|
||||
os::SdkMutex m_apply_mutex;
|
||||
public:
|
||||
constexpr SystemUpdateApplyManager() : apply_mutex() { /* ... */ }
|
||||
constexpr SystemUpdateApplyManager() : m_apply_mutex() { /* ... */ }
|
||||
|
||||
Result ApplyPackageTask(ncm::PackageSystemDowngradeTask *task);
|
||||
};
|
||||
|
||||
@@ -29,10 +29,10 @@ namespace ams::mitm::sysupdater {
|
||||
}
|
||||
|
||||
AsyncPrepareSdCardUpdateImpl::~AsyncPrepareSdCardUpdateImpl() {
|
||||
if (this->thread_info) {
|
||||
os::WaitThread(this->thread_info->thread);
|
||||
os::DestroyThread(this->thread_info->thread);
|
||||
GetAsyncThreadAllocator()->Free(*this->thread_info);
|
||||
if (m_thread_info) {
|
||||
os::WaitThread(m_thread_info->thread);
|
||||
os::DestroyThread(m_thread_info->thread);
|
||||
GetAsyncThreadAllocator()->Free(*m_thread_info);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,16 +46,16 @@ namespace ams::mitm::sysupdater {
|
||||
|
||||
/* Ensure that we clean up appropriately. */
|
||||
ON_SCOPE_EXIT {
|
||||
if (!this->thread_info) {
|
||||
if (!m_thread_info) {
|
||||
GetAsyncThreadAllocator()->Free(info);
|
||||
}
|
||||
};
|
||||
|
||||
/* Create a thread for the task. */
|
||||
R_TRY(os::CreateThread(info.thread, [](void *arg) {
|
||||
auto *_this = reinterpret_cast<AsyncPrepareSdCardUpdateImpl *>(arg);
|
||||
_this->result = _this->Execute();
|
||||
_this->event.Signal();
|
||||
auto *async = reinterpret_cast<AsyncPrepareSdCardUpdateImpl *>(arg);
|
||||
async->m_result = async->Execute();
|
||||
async->m_event.Signal();
|
||||
}, this, info.stack, info.stack_size, info.priority));
|
||||
|
||||
/* Set the thread name. */
|
||||
@@ -65,16 +65,16 @@ namespace ams::mitm::sysupdater {
|
||||
os::StartThread(info.thread);
|
||||
|
||||
/* Set our thread info. */
|
||||
this->thread_info = info;
|
||||
m_thread_info = info;
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result AsyncPrepareSdCardUpdateImpl::Execute() {
|
||||
return this->task->PrepareAndExecute();
|
||||
return m_task->PrepareAndExecute();
|
||||
}
|
||||
|
||||
void AsyncPrepareSdCardUpdateImpl::CancelImpl() {
|
||||
this->task->Cancel();
|
||||
m_task->Cancel();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,16 +21,16 @@ namespace ams::mitm::sysupdater {
|
||||
|
||||
class ErrorContextHolder {
|
||||
private:
|
||||
err::ErrorContext error_context;
|
||||
err::ErrorContext m_error_context;
|
||||
public:
|
||||
constexpr ErrorContextHolder() : error_context{} { /* ... */ }
|
||||
constexpr ErrorContextHolder() : m_error_context{} { /* ... */ }
|
||||
|
||||
virtual ~ErrorContextHolder() { /* ... */ }
|
||||
|
||||
template<typename T>
|
||||
Result SaveErrorContextIfFailed(T &async, Result result) {
|
||||
if (R_FAILED(result)) {
|
||||
async.GetErrorContext(std::addressof(this->error_context));
|
||||
async.GetErrorContext(std::addressof(m_error_context));
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace ams::mitm::sysupdater {
|
||||
template<typename T>
|
||||
Result SaveInternalTaskErrorContextIfFailed(T &async, Result result) {
|
||||
if (R_FAILED(result)) {
|
||||
async.CreateErrorContext(std::addressof(this->error_context));
|
||||
async.CreateErrorContext(std::addressof(m_error_context));
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace ams::mitm::sysupdater {
|
||||
}
|
||||
|
||||
const err::ErrorContext &GetErrorContextImpl() {
|
||||
return this->error_context;
|
||||
return m_error_context;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -93,15 +93,15 @@ namespace ams::mitm::sysupdater {
|
||||
/* We don't implement the RequestServer::ManagedStop details, as we don't implement stoppable request list. */
|
||||
class AsyncPrepareSdCardUpdateImpl : public AsyncResultBase, private ErrorContextHolder {
|
||||
private:
|
||||
Result result;
|
||||
os::SystemEvent event;
|
||||
util::optional<ThreadInfo> thread_info;
|
||||
ncm::InstallTaskBase *task;
|
||||
Result m_result;
|
||||
os::SystemEvent m_event;
|
||||
util::optional<ThreadInfo> m_thread_info;
|
||||
ncm::InstallTaskBase *m_task;
|
||||
public:
|
||||
AsyncPrepareSdCardUpdateImpl(ncm::InstallTaskBase *task) : result(ResultSuccess()), event(os::EventClearMode_ManualClear, true), thread_info(), task(task) { /* ... */ }
|
||||
AsyncPrepareSdCardUpdateImpl(ncm::InstallTaskBase *task) : m_result(ResultSuccess()), m_event(os::EventClearMode_ManualClear, true), m_thread_info(), m_task(task) { /* ... */ }
|
||||
virtual ~AsyncPrepareSdCardUpdateImpl();
|
||||
|
||||
os::SystemEvent &GetEvent() { return this->event; }
|
||||
os::SystemEvent &GetEvent() { return m_event; }
|
||||
|
||||
virtual Result GetErrorContext(sf::Out<err::ErrorContext> out) override {
|
||||
*out = ErrorContextHolder::GetErrorContextImpl();
|
||||
@@ -113,7 +113,7 @@ namespace ams::mitm::sysupdater {
|
||||
Result Execute();
|
||||
|
||||
virtual void CancelImpl() override;
|
||||
virtual Result GetImpl() override { return this->result; }
|
||||
virtual Result GetImpl() override { return m_result; }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -211,16 +211,16 @@ namespace ams::mitm::sysupdater {
|
||||
}
|
||||
|
||||
bool PathView::HasPrefix(util::string_view prefix) const {
|
||||
return this->path.compare(0, prefix.length(), prefix) == 0;
|
||||
return m_path.compare(0, prefix.length(), prefix) == 0;
|
||||
}
|
||||
|
||||
bool PathView::HasSuffix(util::string_view suffix) const {
|
||||
return this->path.compare(this->path.length() - suffix.length(), suffix.length(), suffix) == 0;
|
||||
return m_path.compare(m_path.length() - suffix.length(), suffix.length(), suffix) == 0;
|
||||
}
|
||||
|
||||
util::string_view PathView::GetFileName() const {
|
||||
auto pos = this->path.find_last_of("/");
|
||||
return pos != util::string_view::npos ? this->path.substr(pos + 1) : this->path;
|
||||
auto pos = m_path.find_last_of("/");
|
||||
return pos != util::string_view::npos ? m_path.substr(pos + 1) : m_path;
|
||||
}
|
||||
|
||||
Result MountSdCardContentMeta(const char *mount_name, const char *path) {
|
||||
|
||||
@@ -20,9 +20,9 @@ namespace ams::mitm::sysupdater {
|
||||
|
||||
class PathView {
|
||||
private:
|
||||
util::string_view path;
|
||||
util::string_view m_path;
|
||||
public:
|
||||
PathView(util::string_view p) : path(p) { /* ...*/ }
|
||||
PathView(util::string_view p) : m_path(p) { /* ...*/ }
|
||||
bool HasPrefix(util::string_view prefix) const;
|
||||
bool HasSuffix(util::string_view suffix) const;
|
||||
util::string_view GetFileName() const;
|
||||
|
||||
@@ -420,18 +420,18 @@ namespace ams::mitm::sysupdater {
|
||||
|
||||
Result SystemUpdateService::RequestPrepareUpdate(sf::OutCopyHandle out_event_handle, sf::Out<sf::SharedPointer<ns::impl::IAsyncResult>> out_async) {
|
||||
/* Ensure the update is setup but not prepared. */
|
||||
R_UNLESS(this->setup_update, ns::ResultCardUpdateNotSetup());
|
||||
R_UNLESS(!this->requested_update, ns::ResultPrepareCardUpdateAlreadyRequested());
|
||||
R_UNLESS(m_setup_update, ns::ResultCardUpdateNotSetup());
|
||||
R_UNLESS(!m_requested_update, ns::ResultPrepareCardUpdateAlreadyRequested());
|
||||
|
||||
/* Create the async result. */
|
||||
auto async_result = sf::CreateSharedObjectEmplaced<ns::impl::IAsyncResult, AsyncPrepareSdCardUpdateImpl>(std::addressof(*this->update_task));
|
||||
auto async_result = sf::CreateSharedObjectEmplaced<ns::impl::IAsyncResult, AsyncPrepareSdCardUpdateImpl>(std::addressof(*m_update_task));
|
||||
R_UNLESS(async_result != nullptr, ns::ResultOutOfMaxRunningTask());
|
||||
|
||||
/* Run the task. */
|
||||
R_TRY(async_result.GetImpl().Run());
|
||||
|
||||
/* We prepared the task! */
|
||||
this->requested_update = true;
|
||||
m_requested_update = true;
|
||||
out_event_handle.SetValue(async_result.GetImpl().GetEvent().GetReadableHandle(), false);
|
||||
*out_async = std::move(async_result);
|
||||
|
||||
@@ -440,38 +440,38 @@ namespace ams::mitm::sysupdater {
|
||||
|
||||
Result SystemUpdateService::GetPrepareUpdateProgress(sf::Out<SystemUpdateProgress> out) {
|
||||
/* Ensure the update is setup. */
|
||||
R_UNLESS(this->setup_update, ns::ResultCardUpdateNotSetup());
|
||||
R_UNLESS(m_setup_update, ns::ResultCardUpdateNotSetup());
|
||||
|
||||
/* Get the progress. */
|
||||
auto install_progress = this->update_task->GetProgress();
|
||||
auto install_progress = m_update_task->GetProgress();
|
||||
out.SetValue({ .current_size = install_progress.installed_size, .total_size = install_progress.total_size });
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result SystemUpdateService::HasPreparedUpdate(sf::Out<bool> out) {
|
||||
/* Ensure the update is setup. */
|
||||
R_UNLESS(this->setup_update, ns::ResultCardUpdateNotSetup());
|
||||
R_UNLESS(m_setup_update, ns::ResultCardUpdateNotSetup());
|
||||
|
||||
out.SetValue(this->update_task->GetProgress().state == ncm::InstallProgressState::Downloaded);
|
||||
out.SetValue(m_update_task->GetProgress().state == ncm::InstallProgressState::Downloaded);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result SystemUpdateService::ApplyPreparedUpdate() {
|
||||
/* Ensure the update is setup. */
|
||||
R_UNLESS(this->setup_update, ns::ResultCardUpdateNotSetup());
|
||||
R_UNLESS(m_setup_update, ns::ResultCardUpdateNotSetup());
|
||||
|
||||
/* Ensure the update is prepared. */
|
||||
R_UNLESS(this->update_task->GetProgress().state == ncm::InstallProgressState::Downloaded, ns::ResultCardUpdateNotPrepared());
|
||||
R_UNLESS(m_update_task->GetProgress().state == ncm::InstallProgressState::Downloaded, ns::ResultCardUpdateNotPrepared());
|
||||
|
||||
/* Apply the task. */
|
||||
R_TRY(this->apply_manager.ApplyPackageTask(std::addressof(*this->update_task)));
|
||||
R_TRY(m_apply_manager.ApplyPackageTask(std::addressof(*m_update_task)));
|
||||
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result SystemUpdateService::SetupUpdateImpl(sf::NativeHandle &&transfer_memory, u64 transfer_memory_size, const ncm::Path &path, bool exfat, ncm::FirmwareVariationId firmware_variation_id) {
|
||||
/* Ensure we don't already have an update set up. */
|
||||
R_UNLESS(!this->setup_update, ns::ResultCardUpdateAlreadySetup());
|
||||
R_UNLESS(!m_setup_update, ns::ResultCardUpdateAlreadySetup());
|
||||
|
||||
/* Destroy any existing update tasks. */
|
||||
nim::SystemUpdateTaskId id;
|
||||
@@ -484,21 +484,21 @@ namespace ams::mitm::sysupdater {
|
||||
R_TRY(InitializeUpdateTask(std::move(transfer_memory), transfer_memory_size, path, exfat, firmware_variation_id));
|
||||
|
||||
/* The update is now set up. */
|
||||
this->setup_update = true;
|
||||
m_setup_update = true;
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result SystemUpdateService::InitializeUpdateTask(sf::NativeHandle &&transfer_memory, u64 transfer_memory_size, const ncm::Path &path, bool exfat, ncm::FirmwareVariationId firmware_variation_id) {
|
||||
/* Map the transfer memory. */
|
||||
const size_t tmem_buffer_size = static_cast<size_t>(transfer_memory_size);
|
||||
this->update_transfer_memory.emplace(tmem_buffer_size, transfer_memory.GetOsHandle(), transfer_memory.IsManaged());
|
||||
m_update_transfer_memory.emplace(tmem_buffer_size, transfer_memory.GetOsHandle(), transfer_memory.IsManaged());
|
||||
transfer_memory.Detach();
|
||||
|
||||
void *tmem_buffer;
|
||||
R_TRY(this->update_transfer_memory->Map(std::addressof(tmem_buffer), os::MemoryPermission_None));
|
||||
R_TRY(m_update_transfer_memory->Map(std::addressof(tmem_buffer), os::MemoryPermission_None));
|
||||
auto tmem_guard = SCOPE_GUARD {
|
||||
this->update_transfer_memory->Unmap();
|
||||
this->update_transfer_memory = util::nullopt;
|
||||
m_update_transfer_memory->Unmap();
|
||||
m_update_transfer_memory = util::nullopt;
|
||||
};
|
||||
|
||||
/* Adjust the package root. */
|
||||
@@ -510,8 +510,8 @@ namespace ams::mitm::sysupdater {
|
||||
const char *context_path = "@Sdcard:/atmosphere/update/cup.ctx";
|
||||
|
||||
/* Create and initialize the update task. */
|
||||
this->update_task.emplace();
|
||||
R_TRY(this->update_task->Initialize(package_root.str, context_path, tmem_buffer, tmem_buffer_size, exfat, firmware_variation_id));
|
||||
m_update_task.emplace();
|
||||
R_TRY(m_update_task->Initialize(package_root.str, context_path, tmem_buffer, tmem_buffer_size, exfat, firmware_variation_id));
|
||||
|
||||
/* We successfully setup the update. */
|
||||
tmem_guard.Cancel();
|
||||
|
||||
@@ -56,13 +56,13 @@ namespace ams::mitm::sysupdater {
|
||||
|
||||
class SystemUpdateService {
|
||||
private:
|
||||
SystemUpdateApplyManager apply_manager;
|
||||
util::optional<ncm::PackageSystemDowngradeTask> update_task;
|
||||
util::optional<os::TransferMemory> update_transfer_memory;
|
||||
bool setup_update;
|
||||
bool requested_update;
|
||||
SystemUpdateApplyManager m_apply_manager;
|
||||
util::optional<ncm::PackageSystemDowngradeTask> m_update_task;
|
||||
util::optional<os::TransferMemory> m_update_transfer_memory;
|
||||
bool m_setup_update;
|
||||
bool m_requested_update;
|
||||
public:
|
||||
constexpr SystemUpdateService() : apply_manager(), update_task(), update_transfer_memory(), setup_update(false), requested_update(false) { /* ... */ }
|
||||
constexpr SystemUpdateService() : m_apply_manager(), m_update_task(), m_update_transfer_memory(), m_setup_update(false), m_requested_update(false) { /* ... */ }
|
||||
private:
|
||||
Result SetupUpdateImpl(sf::NativeHandle &&transfer_memory, u64 transfer_memory_size, const ncm::Path &path, bool exfat, ncm::FirmwareVariationId firmware_variation_id);
|
||||
Result InitializeUpdateTask(sf::NativeHandle &&transfer_memory, u64 transfer_memory_size, const ncm::Path &path, bool exfat, ncm::FirmwareVariationId firmware_variation_id);
|
||||
|
||||
@@ -19,18 +19,18 @@
|
||||
namespace ams::mitm::sysupdater {
|
||||
|
||||
Result ThreadAllocator::Allocate(ThreadInfo *out) {
|
||||
std::scoped_lock lk(this->mutex);
|
||||
std::scoped_lock lk(m_mutex);
|
||||
|
||||
for (int i = 0; i < this->thread_count; ++i) {
|
||||
for (int i = 0; i < m_thread_count; ++i) {
|
||||
const u64 mask = (static_cast<u64>(1) << i);
|
||||
if ((this->bitmap & mask) == 0) {
|
||||
if ((m_bitmap & mask) == 0) {
|
||||
*out = {
|
||||
.thread = this->thread_list + i,
|
||||
.priority = this->thread_priority,
|
||||
.stack = this->stack_heap + (this->stack_size * i),
|
||||
.stack_size = this->stack_size,
|
||||
.thread = m_thread_list + i,
|
||||
.priority = m_thread_priority,
|
||||
.stack = m_stack_heap + (m_stack_size * i),
|
||||
.stack_size = m_stack_size,
|
||||
};
|
||||
this->bitmap |= mask;
|
||||
m_bitmap |= mask;
|
||||
return ResultSuccess();
|
||||
}
|
||||
}
|
||||
@@ -39,12 +39,12 @@ namespace ams::mitm::sysupdater {
|
||||
}
|
||||
|
||||
void ThreadAllocator::Free(const ThreadInfo &info) {
|
||||
std::scoped_lock lk(this->mutex);
|
||||
std::scoped_lock lk(m_mutex);
|
||||
|
||||
for (int i = 0; i < this->thread_count; ++i) {
|
||||
if (info.thread == std::addressof(this->thread_list[i])) {
|
||||
for (int i = 0; i < m_thread_count; ++i) {
|
||||
if (info.thread == std::addressof(m_thread_list[i])) {
|
||||
const u64 mask = (static_cast<u64>(1) << i);
|
||||
this->bitmap &= ~mask;
|
||||
m_bitmap &= ~mask;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,20 +28,20 @@ namespace ams::mitm::sysupdater {
|
||||
/* NOTE: Nintendo uses a util::BitArray, but this seems excessive. */
|
||||
class ThreadAllocator {
|
||||
private:
|
||||
os::ThreadType *thread_list;
|
||||
const int thread_priority;
|
||||
const int thread_count;
|
||||
u8 *stack_heap;
|
||||
const size_t stack_heap_size;
|
||||
const size_t stack_size;
|
||||
u64 bitmap;
|
||||
os::SdkMutex mutex;
|
||||
os::ThreadType *m_thread_list;
|
||||
const int m_thread_priority;
|
||||
const int m_thread_count;
|
||||
u8 *m_stack_heap;
|
||||
const size_t m_stack_heap_size;
|
||||
const size_t m_stack_size;
|
||||
u64 m_bitmap;
|
||||
os::SdkMutex m_mutex;
|
||||
public:
|
||||
constexpr ThreadAllocator(os::ThreadType *thread_list, int count, int priority, u8 *stack_heap, size_t stack_heap_size, size_t stack_size)
|
||||
: thread_list(thread_list), thread_priority(priority), thread_count(count), stack_heap(stack_heap), stack_heap_size(stack_heap_size), stack_size(stack_size), bitmap()
|
||||
: m_thread_list(thread_list), m_thread_priority(priority), m_thread_count(count), m_stack_heap(stack_heap), m_stack_heap_size(stack_heap_size), m_stack_size(stack_size), m_bitmap()
|
||||
{
|
||||
AMS_ASSERT(count <= static_cast<int>(stack_heap_size / stack_size));
|
||||
AMS_ASSERT(count <= static_cast<int>(BITSIZEOF(this->bitmap)));
|
||||
AMS_ASSERT(count <= static_cast<int>(BITSIZEOF(m_bitmap)));
|
||||
}
|
||||
|
||||
Result Allocate(ThreadInfo *out);
|
||||
|
||||
Reference in New Issue
Block a user