Implement the NCM sysmodule (closes #91)

* Implement NCM

* Modernize ncm_main

* Remove unnecessary smExit

* Give access to svcCallSecureMonitor

* Stack size bump

* Fix incorrect setup for NandUser's content storage entry

* Fix a potential data abort when flushing the placeholder accessor cache

* Fix HasFile and HasDirectory

* Use r+b, not w+b

* Misc fixes

* errno begone

* Fixed more stdio error handling

* More main fixes

* Various command improvements

* Make dispatch tables great again

* Fix logic inversion

* Fixed content path generation

* Bump heap size, fix CleanupAllPlaceHolder

* Various fixes. Note: This contains debug stuff which will be removed later. I was getting tired of having to cherrypick tiny changes

* Fixed placeholder/content deletion

* Fixed incorrect content manager destruction

* Prevent automatic placeholder creation on open

* Fixed List implementation. Also lots of debug logging.

* Removed debug code

* Added a scope guard for WritePlaceHolder

* Manually prevent placeholder/content appending

* Revert "Removed debug code"

This reverts commit d6ff261fcc.

* Always cache placeholder file. Switch to ftell for preventing appending

* Universally use EnsureEnabled

* Abstract away file writing logic

* Misc cleanup

* Refactor placeholder cacheing

* Remove debug code (again)

* Revert "Remove debug code (again)"

This reverts commit 168447d80e.

* Misc changes

* Fixed file modes

* Fixed ContentId/PlaceHolderId alignment

* Improved type safety

* Fixed reinitialization

* Fixed doubleup on path creation

* Remove debug code

* Fixed 1.0.0 booting

* Correct amount of add on content

* Correct main thread stack size

* lr: Introducing registered data

* Reorder stratosphere Makefile

* Move results to libstrat

* lr: Cleanup lr_redirection

* lr: lr_manager tweaks

* lr: Imrpoved path handling and adjust ResolveAddOnContentPath order

* lr: Organise types

* Add eof newlines

* lr: Eliminate unnecessary vars

* lr: Unnecessary vars 2 electric boogaloo

* lr: Various helpers

* lr: RegisteredLocationResolver helpers

* ncm: Move ncm_types to libstrat

* ncm: Misc cleanup

* Implement NCM

* Modernize ncm_main

* Remove unnecessary smExit

* Give access to svcCallSecureMonitor

* Stack size bump

* Fix incorrect setup for NandUser's content storage entry

* Fix a potential data abort when flushing the placeholder accessor cache

* Fix HasFile and HasDirectory

* Use r+b, not w+b

* Misc fixes

* errno begone

* Fixed more stdio error handling

* More main fixes

* Various command improvements

* Make dispatch tables great again

* Fix logic inversion

* Fixed content path generation

* Bump heap size, fix CleanupAllPlaceHolder

* Various fixes. Note: This contains debug stuff which will be removed later. I was getting tired of having to cherrypick tiny changes

* Fixed placeholder/content deletion

* Fixed incorrect content manager destruction

* Prevent automatic placeholder creation on open

* Fixed List implementation. Also lots of debug logging.

* Removed debug code

* Added a scope guard for WritePlaceHolder

* Manually prevent placeholder/content appending

* Revert "Removed debug code"

This reverts commit d6ff261fcc.

* Always cache placeholder file. Switch to ftell for preventing appending

* Universally use EnsureEnabled

* Abstract away file writing logic

* Misc cleanup

* Refactor placeholder cacheing

* Remove debug code (again)

* Revert "Remove debug code (again)"

This reverts commit 168447d80e.

* Misc changes

* Fixed file modes

* Fixed ContentId/PlaceHolderId alignment

* Improved type safety

* Fixed reinitialization

* Fixed doubleup on path creation

* Remove debug code

* Fixed 1.0.0 booting

* Correct amount of add on content

* Correct main thread stack size

* lr: Introducing registered data

* Reorder stratosphere Makefile

* Move results to libstrat

* lr: Cleanup lr_redirection

* lr: lr_manager tweaks

* lr: Imrpoved path handling and adjust ResolveAddOnContentPath order

* lr: Organise types

* Add eof newlines

* lr: Eliminate unnecessary vars

* lr: Unnecessary vars 2 electric boogaloo

* lr: Various helpers

* lr: RegisteredLocationResolver helpers

* ncm: Move ncm_types to libstrat

* ncm: Misc cleanup

* Updated AddOnContentLocationResolver and RegisteredLocationResolver to 9.0.0

* Finished updating lr to 9.0.0

* Updated NCM to 9.0.0

* Fix libstrat includes

* Fixed application launching

* title_id_2 -> owner_tid

* Updated to new-ipc

* Change to using pure virtuals

* Title Id -> Program Id

* Fixed compilation against master

* std::scoped_lock<> -> std::scoped_lock

* Adopted R_UNLESS and R_CONVERT

* Prefix namespace to Results

* Adopt std::numeric_limits

* Fixed incorrect error handling in ReadFile

* Adopted AMS_ABORT_UNLESS

* Adopt util::GenerateUuid()

* Syntax improvements

* ncm_types: Address review

* Address more review comments

* Updated copyrights

* Address more feedback

* More feedback addressed

* More changes

* Move dispatch tables out of interface files

* Addressed remaining comments

* lr: move into libstratosphere

* ncm: Fix logic inversion

* lr: Add comments

* lr: Remove whitespace

* ncm: Start addressing feedback

* ncm: Cleanup InitializeContentManager

* lr: support client-side usage

* lr_service -> lr_api

* ncm: Begin refactoring content manager

* ncm: More content manager improvements

* ncm: Content manager mount improvements

* ldr: use lr bindings

* lr bindings usage: minor fixes

* ncm/lr: Pointer placement

* ncm: placeholder accessor cleanup

* ncm: minor fixes

* ncm: refactor rights cache

* ncm: content meta database cleanup

* ncm: move content meta database impl out of interface file

* ncm: Use const ContentMetaKey &

* ncm: fix other non-const ContentMetaKey references

* ncm: content meta database cleanup

* ncm: content storage fixes for 2.0.0

* ncm: add missing end of file newlines

* ncm: implement ContentMetaReader

* ncm: client-side api

* ncm: trim trailing spaces

* ncm: FS_MAX_PATH-1 -> fs::EntryNameLengthMax

* ncm: Use PathString and Path

* fs: implement accessor wrappers for ncm

* fs: implement user fs wrappers

* fs: add MountSdCard

* ncm: move to content manager impl

* ncm: fix up main

* kvdb: use fs::

* fs: Add wrappers needed for ncm

* ncm: use fs bindings, other refactoring

* ncm: minor fixes

* fsa: fix ReadFile without size output

* fs: add substorage, rom path tool

* ncm: fix dangling fsdev usage

* fs: fix bug in Commit

* fs: fixed incorrect mode check

* fs: implement Mount(System)Data

* ncm: don't delete hos

* results: add R_SUCCEED_IF

* ams-except-ncm: use R_SUCCEED_IF

* ncm: added comments

* ncm: fix api definitions

* ncm: use R_SUCCEED_IF

* pm: think of the savings

* ncm: employ kernel strats

* ncm: Nintendo has 5 MiB of heap. Give ourselves 4 to be safe, pending analysis

* ncm: refactor IDs, split types header into many headers

* ams.mitm: use fs bindings instead of stdio

* fs: SystemData uses SystemDataId

* ncm: improve meta-db accuracy

* ncm: inline getlatestkey

* fs: improve UnsupportedOperation results

* fs: modernize mount utils

* ams: misc fixes for merge-errors

* fs: improve unsupportedoperation results

* git subrepo pull emummc

subrepo:
  subdir:   "emummc"
  merged:   "d12dd546"
upstream:
  origin:   "https://github.com/m4xw/emuMMC"
  branch:   "develop"
  commit:   "d12dd546"
git-subrepo:
  version:  "0.4.1"
  origin:   "???"
  commit:   "???"

* util: add boundedmap

* ncm: minor style fixes

* ncm: don't unmount if mounting fails

* lr: bug fixes

* ncm: implement ncm.for-initialize + ncm.for-safemode

* lr: ncm::ProgramId::Invalid -> ncm::InvalidProgramId

* ncm: fix open directory mode on 1.0.0

* ncm: fix fs use, implement more of < 4.0.0 for-initialize/safemode

* ncm: implement packagedcontent -> content for building metadb

* ncm: fix save data flag management

* ncm: address some review suggestions (thanks @leoetlino!)

* updater: use fs bindings

* fs: implement MountCode

* fs: prefer make_unique to operator new

* ncm: implement remaining ContentMetaDatabaseBuilder functionality

Co-authored-by: Michael Scire <SciresM@gmail.com>
This commit is contained in:
Adubbz
2020-03-08 19:06:23 +11:00
committed by GitHub
parent f9403201f0
commit c7026b9094
254 changed files with 16876 additions and 1274 deletions

View File

@@ -1,4 +1,4 @@
MODULES := loader pm sm boot ams_mitm spl eclct.stub ro creport fatal dmnt boot2
MODULES := loader ncm pm sm boot ams_mitm spl eclct.stub ro creport fatal dmnt boot2
SUBFOLDERS := $(MODULES)

View File

@@ -40,7 +40,7 @@ extern "C" {
namespace ams {
ncm::ProgramId CurrentProgramId = ncm::ProgramId::AtmosphereMitm;
ncm::ProgramId CurrentProgramId = ncm::AtmosphereProgramId::Mitm;
namespace result {

View File

@@ -31,8 +31,8 @@ namespace ams::mitm::bpc {
* - fatal, to simplify payload reboot logic significantly
* - hbl, to allow homebrew to take advantage of the feature.
*/
return client_info.program_id == ncm::ProgramId::Am ||
client_info.program_id == ncm::ProgramId::Fatal ||
return client_info.program_id == ncm::SystemProgramId::Am ||
client_info.program_id == ncm::SystemProgramId::Fatal ||
client_info.override_status.IsHbl();
}
public:

View File

@@ -137,7 +137,7 @@ namespace ams::mitm::fs {
Result OpenWebContentFileSystem(sf::Out<std::shared_ptr<IFileSystemInterface>> &out, ncm::ProgramId client_program_id, ncm::ProgramId program_id, FsFileSystemType filesystem_type, Service *fwd, const fssrv::sf::Path *path, bool with_id, bool try_program_specific) {
/* Check first that we're a web applet opening web content. */
R_UNLESS(ncm::IsWebAppletProgramId(client_program_id), sm::mitm::ResultShouldForwardToSession());
R_UNLESS(ncm::IsWebAppletId(client_program_id), sm::mitm::ResultShouldForwardToSession());
R_UNLESS(filesystem_type == FsFileSystemType_ContentManual, sm::mitm::ResultShouldForwardToSession());
/* Try to mount the HBL web filesystem. If this succeeds then we're done. */
@@ -162,8 +162,8 @@ namespace ams::mitm::fs {
Result FsMitmService::OpenSdCardFileSystem(sf::Out<std::shared_ptr<IFileSystemInterface>> out) {
/* We only care about redirecting this for NS/emummc. */
R_UNLESS(this->client_info.program_id == ncm::ProgramId::Ns, sm::mitm::ResultShouldForwardToSession());
R_UNLESS(emummc::IsActive(), sm::mitm::ResultShouldForwardToSession());
R_UNLESS(this->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;
@@ -178,7 +178,7 @@ namespace ams::mitm::fs {
Result FsMitmService::OpenSaveDataFileSystem(sf::Out<std::shared_ptr<IFileSystemInterface>> out, u8 _space_id, const FsSaveDataAttribute &attribute) {
/* We only want to intercept saves for games, right now. */
const bool is_game_or_hbl = this->client_info.override_status.IsHbl() || ncm::IsApplicationProgramId(this->client_info.program_id);
const bool is_game_or_hbl = this->client_info.override_status.IsHbl() || ncm::IsApplicationId(this->client_info.program_id);
R_UNLESS(is_game_or_hbl, sm::mitm::ResultShouldForwardToSession());
/* Only redirect if the appropriate system setting is set. */
@@ -333,10 +333,13 @@ namespace ams::mitm::fs {
return ResultSuccess();
}
Result FsMitmService::OpenDataStorageByDataId(sf::Out<std::shared_ptr<IStorageInterface>> out, ncm::ProgramId /* TODO: ncm::DataId */ data_id, u8 storage_id) {
Result FsMitmService::OpenDataStorageByDataId(sf::Out<std::shared_ptr<IStorageInterface>> 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());
/* TODO: Decide how to handle DataId vs ProgramId for this API. */
const ncm::ProgramId data_id = {_data_id.value};
/* Only mitm if there is actually an override romfs. */
R_UNLESS(mitm::fs::HasSdRomfsContent(data_id), sm::mitm::ResultShouldForwardToSession());

View File

@@ -50,12 +50,12 @@ namespace ams::mitm::fs {
}
/* We want to mitm ns, to intercept SD card requests. */
if (program_id == ncm::ProgramId::Ns) {
if (program_id == ncm::SystemProgramId::Ns) {
return true;
}
/* We want to mitm sdb, to support sd-romfs redirection of common system archives (like system font, etc). */
if (program_id == ncm::ProgramId::Sdb) {
if (program_id == ncm::SystemProgramId::Sdb) {
return true;
}
@@ -69,7 +69,7 @@ namespace ams::mitm::fs {
/* Figure out why, and address it. */
/* TODO: This may be because pre-rewrite code really mismanaged domain objects in a way that would cause bad things. */
/* Need to verify if this is fixed now. */
if (client_info.program_id == ncm::ProgramId::AppletQlaunch || client_info.program_id == ncm::ProgramId::AppletMaintenanceMenu) {
if (client_info.program_id == ncm::SystemAppletId::Qlaunch || client_info.program_id == ncm::SystemAppletId::MaintenanceMenu) {
has_launched_qlaunch = true;
}
@@ -85,7 +85,7 @@ namespace ams::mitm::fs {
Result OpenSaveDataFileSystem(sf::Out<std::shared_ptr<IFileSystemInterface>> out, u8 space_id, const FsSaveDataAttribute &attribute);
Result OpenBisStorage(sf::Out<std::shared_ptr<IStorageInterface>> out, u32 bis_partition_id);
Result OpenDataStorageByCurrentProcess(sf::Out<std::shared_ptr<IStorageInterface>> out);
Result OpenDataStorageByDataId(sf::Out<std::shared_ptr<IStorageInterface>> out, ncm::ProgramId /* TODO: ncm::DataId */ data_id, u8 storage_id);
Result OpenDataStorageByDataId(sf::Out<std::shared_ptr<IStorageInterface>> out, ncm::DataId data_id, u8 storage_id);
public:
DEFINE_SERVICE_DISPATCH_TABLE {
MAKE_SERVICE_COMMAND_META(OpenFileSystemWithPatch, hos::Version_200),

View File

@@ -31,7 +31,7 @@ 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::ProgramId::Ns;
return this->client_info.program_id == ncm::SystemProgramId::Ns;
} else {
/* RCM bug unpatched. */
/* Allow homebrew but not NS to update the BCT pubks. */

View File

@@ -140,8 +140,7 @@ namespace ams::mitm::fs {
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), client_info(c) { /* ... */ }
Boot0Storage(FsStorage &s, const sm::MitmProcessInfo &c) : Base(s), 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;

View File

@@ -98,7 +98,7 @@ namespace ams::mitm::fs {
Result LayeredRomfsStorage::Read(s64 offset, void *buffer, size_t size) {
/* Check if we can succeed immediately. */
R_UNLESS(size >= 0, fs::ResultInvalidSize());
R_UNLESS(size > 0, ResultSuccess());
R_SUCCEED_IF(size == 0);
/* Ensure we're initialized. */
if (!this->is_initialized) {

View File

@@ -49,6 +49,16 @@ namespace ams::mitm::fs {
virtual Result GetSize(s64 *out_size) override;
virtual Result Flush() override;
virtual Result OperateRange(void *dst, size_t dst_size, ams::fs::OperationId op_id, s64 offset, s64 size, const void *src, size_t src_size) override;
virtual Result Write(s64 offset, const void *buffer, size_t size) override {
/* TODO: Better result code? */
return ams::fs::ResultUnsupportedOperation();
}
virtual Result SetSize(s64 size) override {
/* TODO: Better result code? */
return ams::fs::ResultUnsupportedOperation();
}
};
}

View File

@@ -30,7 +30,7 @@ namespace ams::mitm::ns {
/* We will mitm:
* - web applets, to facilitate hbl web browser launching.
*/
return ncm::IsWebAppletProgramId(client_info.program_id);
return ncm::IsWebAppletId(client_info.program_id);
}
public:
SF_MITM_SERVICE_OBJECT_CTOR(NsAmMitmService) { /* ... */ }

View File

@@ -59,7 +59,7 @@ namespace ams::mitm::ns {
/* We will mitm:
* - web applets, to facilitate hbl web browser launching.
*/
return ncm::IsWebAppletProgramId(client_info.program_id);
return ncm::IsWebAppletId(client_info.program_id);
}
public:
SF_MITM_SERVICE_OBJECT_CTOR(NsWebMitmService) { /* ... */ }

View File

@@ -22,12 +22,12 @@ namespace ams::mitm::settings {
Result SetMitmService::EnsureLocale() {
std::scoped_lock lk(this->lock);
const bool is_ns = this->client_info.program_id == ncm::ProgramId::Ns;
const bool is_ns = this->client_info.program_id == ncm::SystemProgramId::Ns;
if (!this->got_locale) {
std::memset(&this->locale, 0xCC, sizeof(this->locale));
ncm::ProgramId program_id = this->client_info.program_id;
if (program_id == ncm::ProgramId::Ns) {
if (is_ns) {
/* When NS asks for a locale, refresh to get the current application locale. */
os::ProcessId application_process_id;
R_TRY(pm::dmnt::GetApplicationProcessId(&application_process_id));

View File

@@ -33,8 +33,8 @@ namespace ams::mitm::settings {
/* We will mitm:
* - ns and games, to allow for overriding game locales.
*/
const bool is_game = (ncm::IsApplicationProgramId(client_info.program_id) && !client_info.override_status.IsHbl());
return client_info.program_id == ncm::ProgramId::Ns || is_game;
const bool is_game = (ncm::IsApplicationId(client_info.program_id) && !client_info.override_status.IsHbl());
return client_info.program_id == ncm::SystemProgramId::Ns || is_game;
}
public:
SF_MITM_SERVICE_OBJECT_CTOR(SetMitmService) {

View File

@@ -35,17 +35,17 @@ namespace ams::mitm::settings {
}
/* Mount firmware version data archive. */
R_ABORT_UNLESS(romfsMountFromDataArchive(static_cast<u64>(ncm::ProgramId::ArchiveSystemVersion), NcmStorageId_BuiltInSystem, "sysver"));
{
ON_SCOPE_EXIT { romfsUnmount("sysver"); };
R_ABORT_UNLESS(ams::fs::MountSystemData("sysver", ncm::SystemDataId::SystemVersion));
ON_SCOPE_EXIT { ams::fs::Unmount("sysver"); };
/* Firmware version file must exist. */
FILE *fp = fopen("sysver:/file", "rb");
AMS_ABORT_UNLESS(fp != nullptr);
ON_SCOPE_EXIT { fclose(fp); };
ams::fs::FileHandle file;
R_ABORT_UNLESS(ams::fs::OpenFile(std::addressof(file), "sysver:/file", fs::OpenMode_Read));
ON_SCOPE_EXIT { ams::fs::CloseFile(file); };
/* Must be possible to read firmware version from file. */
AMS_ABORT_UNLESS(fread(&g_firmware_version, sizeof(g_firmware_version), 1, fp) == 1);
R_ABORT_UNLESS(ams::fs::ReadFile(file, 0, std::addressof(g_firmware_version), sizeof(g_firmware_version)));
g_ams_firmware_version = g_firmware_version;
}
@@ -75,7 +75,7 @@ namespace ams::mitm::settings {
/* We want to give a special firmware version to the home menu title, and nothing else. */
/* This means Qlaunch + Maintenance Menu, and nothing else. */
if (client_info.program_id == ncm::ProgramId::AppletQlaunch || client_info.program_id == ncm::ProgramId::AppletMaintenanceMenu) {
if (client_info.program_id == ncm::SystemAppletId::Qlaunch || client_info.program_id == ncm::SystemAppletId::MaintenanceMenu) {
*out = g_ams_firmware_version;
} else {
*out = g_firmware_version;

View File

@@ -27,7 +27,7 @@ namespace ams::boot {
u64 cur_time = 0;
while (true) {
const auto retry_result = f();
R_UNLESS(R_FAILED(retry_result), ResultSuccess());
R_SUCCEED_IF(R_SUCCEEDED(retry_result));
cur_time += retry_interval;
if (cur_time < timeout) {

View File

@@ -52,7 +52,7 @@ extern "C" {
namespace ams {
ncm::ProgramId CurrentProgramId = ncm::ProgramId::Boot;
ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::Boot;
void ExceptionHandler(FatalErrorContext *ctx) {
/* We're boot sysmodule, so manually reboot to fatal error. */
@@ -100,7 +100,6 @@ void __appInit(void) {
void __appExit(void) {
/* Cleanup services. */
fsdevUnmountAll();
pmshellExit();
splExit();
fsExit();

View File

@@ -379,7 +379,8 @@ namespace ams::i2c::driver::impl {
/* Wait for flush to finish, check every ms for 5 ms. */
for (size_t i = 0; i < 5; i++) {
R_UNLESS((reg::Read(&this->i2c_registers->I2C_FIFO_CONTROL_0) & 3), ResultSuccess());
const bool flush_done = (reg::Read(&this->i2c_registers->I2C_FIFO_CONTROL_0) & 3) == 0;
R_SUCCEED_IF(flush_done);
svcSleepThread(1'000'000ul);
}
@@ -418,7 +419,8 @@ namespace ams::i2c::driver::impl {
Result BusAccessor::GetAndHandleTransactionResult() {
const auto transaction_result = this->GetTransactionResult();
R_UNLESS(R_FAILED(transaction_result), ResultSuccess());
R_SUCCEED_IF(R_SUCCEEDED(transaction_result));
this->HandleTransactionResult(transaction_result);
this->ClearInterruptMask();
this->interrupt_event.Reset();

View File

@@ -38,7 +38,7 @@ extern "C" {
namespace ams {
ncm::ProgramId CurrentProgramId = ncm::ProgramId::Boot2;
ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::Boot2;
namespace result {
@@ -79,13 +79,14 @@ void __appInit(void) {
R_ABORT_UNLESS(gpioInitialize());
});
R_ABORT_UNLESS(fsdevMountSdmc());
/* Mount the SD card. */
R_ABORT_UNLESS(fs::MountSdCard("sdmc"));
ams::CheckApiVersion();
}
void __appExit(void) {
fsdevUnmountAll();
fs::Unmount("sdmc");
gpioExit();
setsysExit();
pmshellExit();
@@ -96,6 +97,7 @@ void __appExit(void) {
int main(int argc, char **argv)
{
/* Launch all programs off of SYSTEM/the SD. */
boot2::LaunchPostSdCardBootPrograms();
}

View File

@@ -40,7 +40,7 @@ extern "C" {
namespace ams {
ncm::ProgramId CurrentProgramId = ncm::ProgramId::Creport;
ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::Creport;
namespace result {

View File

@@ -602,7 +602,7 @@ namespace ams::dmnt::cheat::impl {
{
if (this->HasActiveCheatProcess()) {
/* When forcing attach, we're done. */
R_UNLESS(on_process_launch, ResultSuccess());
R_SUCCEED_IF(!on_process_launch);
}
/* Detach from the current process, if it's open. */

View File

@@ -35,7 +35,7 @@ extern "C" {
namespace ams {
ncm::ProgramId CurrentProgramId = ncm::ProgramId::Dmnt;
ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::Dmnt;
namespace result {
@@ -71,7 +71,7 @@ void __appInit(void) {
R_ABORT_UNLESS(roDmntInitialize());
}
R_ABORT_UNLESS(nsdevInitialize());
R_ABORT_UNLESS(lrInitialize());
lr::Initialize();
R_ABORT_UNLESS(setInitialize());
R_ABORT_UNLESS(setsysInitialize());
R_ABORT_UNLESS(hidInitialize());
@@ -90,7 +90,7 @@ void __appExit(void) {
hidExit();
setsysExit();
setExit();
lrExit();
lr::Finalize();
nsdevExit();
roDmntExit();
ldrDmntExit();

View File

@@ -49,7 +49,7 @@ namespace ams::dmnt {
Result EnsureSdInitialized() {
std::scoped_lock lk(g_sd_lock);
R_UNLESS(!g_sd_initialized, ResultSuccess());
R_SUCCEED_IF(g_sd_initialized);
R_TRY(fsOpenSdCardFileSystem(&g_sd_fs));
g_sd_initialized = true;

View File

@@ -36,7 +36,7 @@ extern "C" {
namespace ams {
ncm::ProgramId CurrentProgramId = ncm::ProgramId::Eclct;
ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::Eclct;
namespace result {

View File

@@ -44,7 +44,7 @@ extern "C" {
namespace ams {
ncm::ProgramId CurrentProgramId = ncm::ProgramId::Fatal;
ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::Fatal;
namespace result {

View File

@@ -64,8 +64,8 @@ namespace ams::fatal::srv {
/* Throw implementation. */
Result ServiceContext::ThrowFatalWithCpuContext(Result result, os::ProcessId process_id, FatalPolicy policy, const CpuContext &cpu_ctx) {
/* We don't support Error Report only fatals. */
R_UNLESS(policy != FatalPolicy_ErrorReport, ResultSuccess());
/* We don't support Error-Report-only fatals. */
R_SUCCEED_IF(policy == FatalPolicy_ErrorReport);
/* Note that we've thrown fatal. */
R_TRY(this->TrySetHasThrown());
@@ -83,7 +83,7 @@ namespace ams::fatal::srv {
/* Get program id. */
pm::info::GetProgramId(&this->context.program_id, process_id);
this->context.is_creport = (this->context.program_id == ncm::ProgramId::Creport);
this->context.is_creport = (this->context.program_id == ncm::SystemProgramId::Creport);
if (!this->context.is_creport) {
/* On firmware version 2.0.0, use debugging SVCs to collect information. */

View File

@@ -23,158 +23,158 @@ constexpr u32 MakeSystemVersion(u32 major, u32 minor, u32 micro) {
}
constexpr MinimumProgramVersion g_MinimumProgramVersions810[] = {
{ncm::ProgramId::Settings, 1},
{ncm::ProgramId::Bus, 1},
{ncm::ProgramId::Audio, 1},
{ncm::ProgramId::NvServices, 1},
{ncm::ProgramId::Ns, 1},
{ncm::ProgramId::Ssl, 1},
{ncm::ProgramId::Es, 1},
{ncm::ProgramId::Creport, 1},
{ncm::ProgramId::Ro, 1},
{ncm::SystemProgramId::Settings, 1},
{ncm::SystemProgramId::Bus, 1},
{ncm::SystemProgramId::Audio, 1},
{ncm::SystemProgramId::NvServices, 1},
{ncm::SystemProgramId::Ns, 1},
{ncm::SystemProgramId::Ssl, 1},
{ncm::SystemProgramId::Es, 1},
{ncm::SystemProgramId::Creport, 1},
{ncm::SystemProgramId::Ro, 1},
};
constexpr size_t g_MinimumProgramVersionsCount810 = util::size(g_MinimumProgramVersions810);
constexpr MinimumProgramVersion g_MinimumProgramVersions900[] = {
/* All non-Development System Modules. */
{ncm::ProgramId::Usb, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Tma, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Boot2, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Settings, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Bus, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Bluetooth, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Bcat, MakeSystemVersion(9, 0, 0)},
/* {ncm::ProgramId::Dmnt, MakeSystemVersion(9, 0, 0)}, */
{ncm::ProgramId::Friends, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Nifm, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Ptm, MakeSystemVersion(9, 0, 0)},
/* {ncm::ProgramId::Shell, MakeSystemVersion(9, 0, 0)}, */
{ncm::ProgramId::BsdSockets, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Hid, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Audio, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::LogManager, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Wlan, MakeSystemVersion(9, 0, 0)},
/* {ncm::ProgramId::Cs, MakeSystemVersion(9, 0, 0)}, */
{ncm::ProgramId::Ldn, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::NvServices, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Pcv, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Ppc, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::NvnFlinger, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Pcie, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Account, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Ns, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Nfc, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Psc, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::CapSrv, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Am, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Ssl, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Nim, MakeSystemVersion(9, 0, 0)},
/* {ncm::ProgramId::Cec, MakeSystemVersion(9, 0, 0)}, */
/* {ncm::ProgramId::Tspm, MakeSystemVersion(9, 0, 0)}, */
/* {ncm::ProgramId::Spl, MakeSystemVersion(9, 0, 0)}, */
{ncm::ProgramId::Lbl, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Btm, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Erpt, MakeSystemVersion(9, 0, 0)},
/* {ncm::ProgramId::Time, MakeSystemVersion(9, 0, 0)}, */
{ncm::ProgramId::Vi, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Pctl, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Npns, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Eupld, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Glue, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Eclct, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Es, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Fatal, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Grc, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Creport, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Ro, MakeSystemVersion(9, 0, 0)},
/* {ncm::ProgramId::Profiler, MakeSystemVersion(9, 0, 0)}, */
{ncm::ProgramId::Sdb, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Migration, MakeSystemVersion(9, 0, 0)},
/* {ncm::ProgramId::Jit, MakeSystemVersion(9, 0, 0)}, */
{ncm::ProgramId::JpegDec, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::SafeMode, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Olsc, MakeSystemVersion(9, 0, 0)},
/* {ncm::ProgramId::Dt, MakeSystemVersion(9, 0, 0)}, */
/* {ncm::ProgramId::Nd, MakeSystemVersion(9, 0, 0)}, */
{ncm::ProgramId::Ngct, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Usb, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Tma, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Boot2, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Settings, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Bus, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Bluetooth, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Bcat, MakeSystemVersion(9, 0, 0)},
/* {ncm::SystemProgramId::Dmnt, MakeSystemVersion(9, 0, 0)}, */
{ncm::SystemProgramId::Friends, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Nifm, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Ptm, MakeSystemVersion(9, 0, 0)},
/* {ncm::SystemProgramId::Shell, MakeSystemVersion(9, 0, 0)}, */
{ncm::SystemProgramId::BsdSockets, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Hid, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Audio, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::LogManager, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Wlan, MakeSystemVersion(9, 0, 0)},
/* {ncm::SystemProgramId::Cs, MakeSystemVersion(9, 0, 0)}, */
{ncm::SystemProgramId::Ldn, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::NvServices, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Pcv, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Ppc, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::NvnFlinger, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Pcie, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Account, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Ns, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Nfc, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Psc, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::CapSrv, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Am, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Ssl, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Nim, MakeSystemVersion(9, 0, 0)},
/* {ncm::SystemProgramId::Cec, MakeSystemVersion(9, 0, 0)}, */
/* {ncm::SystemProgramId::Tspm, MakeSystemVersion(9, 0, 0)}, */
/* {ncm::SystemProgramId::Spl, MakeSystemVersion(9, 0, 0)}, */
{ncm::SystemProgramId::Lbl, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Btm, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Erpt, MakeSystemVersion(9, 0, 0)},
/* {ncm::SystemProgramId::Time, MakeSystemVersion(9, 0, 0)}, */
{ncm::SystemProgramId::Vi, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Pctl, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Npns, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Eupld, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Glue, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Eclct, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Es, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Fatal, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Grc, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Creport, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Ro, MakeSystemVersion(9, 0, 0)},
/* {ncm::SystemProgramId::Profiler, MakeSystemVersion(9, 0, 0)}, */
{ncm::SystemProgramId::Sdb, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Migration, MakeSystemVersion(9, 0, 0)},
/* {ncm::SystemProgramId::Jit, MakeSystemVersion(9, 0, 0)}, */
{ncm::SystemProgramId::JpegDec, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::SafeMode, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Olsc, MakeSystemVersion(9, 0, 0)},
/* {ncm::SystemProgramId::Dt, MakeSystemVersion(9, 0, 0)}, */
/* {ncm::SystemProgramId::Nd, MakeSystemVersion(9, 0, 0)}, */
{ncm::SystemProgramId::Ngct, MakeSystemVersion(9, 0, 0)},
/* All Web Applets. */
{ncm::ProgramId::AppletWeb, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::AppletShop, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::AppletOfflineWeb, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::AppletLoginShare, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::AppletWifiWebAuth, MakeSystemVersion(9, 0, 0)},
{ncm::WebAppletId::Web, MakeSystemVersion(9, 0, 0)},
{ncm::WebAppletId::Shop, MakeSystemVersion(9, 0, 0)},
{ncm::WebAppletId::OfflineWeb, MakeSystemVersion(9, 0, 0)},
{ncm::WebAppletId::LoginShare, MakeSystemVersion(9, 0, 0)},
{ncm::WebAppletId::WifiWebAuth, MakeSystemVersion(9, 0, 0)},
};
constexpr size_t g_MinimumProgramVersionsCount900 = util::size(g_MinimumProgramVersions900);
constexpr MinimumProgramVersion g_MinimumProgramVersions910[] = {
/* All non-Development System Modules. */
{ncm::ProgramId::Usb, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Tma, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Boot2, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Settings, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Bus, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Bluetooth, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Bcat, MakeSystemVersion(9, 1, 0)},
/* {ncm::ProgramId::Dmnt, MakeSystemVersion(9, 0, 0)}, */
{ncm::ProgramId::Friends, MakeSystemVersion(9, 1, 0)},
{ncm::ProgramId::Nifm, MakeSystemVersion(9, 1, 0)},
{ncm::ProgramId::Ptm, MakeSystemVersion(9, 0, 0)},
/* {ncm::ProgramId::Shell, MakeSystemVersion(9, 0, 0)}, */
{ncm::ProgramId::BsdSockets, MakeSystemVersion(9, 1, 0)},
{ncm::ProgramId::Hid, MakeSystemVersion(9, 1, 0)},
{ncm::ProgramId::Audio, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::LogManager, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Wlan, MakeSystemVersion(9, 1, 0)},
/* {ncm::ProgramId::Cs, MakeSystemVersion(9, 0, 0)}, */
{ncm::ProgramId::Ldn, MakeSystemVersion(9, 1, 0)},
{ncm::ProgramId::NvServices, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Pcv, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Ppc, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::NvnFlinger, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Pcie, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Account, MakeSystemVersion(9, 1, 0)},
{ncm::ProgramId::Ns, MakeSystemVersion(9, 1, 0)},
{ncm::ProgramId::Nfc, MakeSystemVersion(9, 1, 0)},
{ncm::ProgramId::Psc, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::CapSrv, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Am, MakeSystemVersion(9, 1, 0)},
{ncm::ProgramId::Ssl, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Nim, MakeSystemVersion(9, 1, 0)},
/* {ncm::ProgramId::Cec, MakeSystemVersion(9, 0, 0)}, */
/* {ncm::ProgramId::Tspm, MakeSystemVersion(9, 0, 0)}, */
/* {ncm::ProgramId::Spl, MakeSystemVersion(9, 0, 0)}, */
{ncm::ProgramId::Lbl, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Btm, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Erpt, MakeSystemVersion(9, 1, 0)},
/* {ncm::ProgramId::Time, MakeSystemVersion(9, 0, 0)}, */
{ncm::ProgramId::Vi, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Pctl, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Npns, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Eupld, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Glue, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Eclct, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Es, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Fatal, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Grc, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Creport, MakeSystemVersion(9, 1, 0)},
{ncm::ProgramId::Ro, MakeSystemVersion(9, 1, 0)},
/* {ncm::ProgramId::Profiler, MakeSystemVersion(9, 0, 0)}, */
{ncm::ProgramId::Sdb, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Migration, MakeSystemVersion(9, 1, 0)},
/* {ncm::ProgramId::Jit, MakeSystemVersion(9, 0, 0)}, */
{ncm::ProgramId::JpegDec, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::SafeMode, MakeSystemVersion(9, 0, 0)},
{ncm::ProgramId::Olsc, MakeSystemVersion(9, 1, 0)},
/* {ncm::ProgramId::Dt, MakeSystemVersion(9, 0, 0)}, */
/* {ncm::ProgramId::Nd, MakeSystemVersion(9, 0, 0)}, */
{ncm::ProgramId::Ngct, MakeSystemVersion(9, 1, 0)},
{ncm::SystemProgramId::Usb, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Tma, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Boot2, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Settings, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Bus, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Bluetooth, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Bcat, MakeSystemVersion(9, 1, 0)},
/* {ncm::SystemProgramId::Dmnt, MakeSystemVersion(9, 0, 0)}, */
{ncm::SystemProgramId::Friends, MakeSystemVersion(9, 1, 0)},
{ncm::SystemProgramId::Nifm, MakeSystemVersion(9, 1, 0)},
{ncm::SystemProgramId::Ptm, MakeSystemVersion(9, 0, 0)},
/* {ncm::SystemProgramId::Shell, MakeSystemVersion(9, 0, 0)}, */
{ncm::SystemProgramId::BsdSockets, MakeSystemVersion(9, 1, 0)},
{ncm::SystemProgramId::Hid, MakeSystemVersion(9, 1, 0)},
{ncm::SystemProgramId::Audio, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::LogManager, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Wlan, MakeSystemVersion(9, 1, 0)},
/* {ncm::SystemProgramId::Cs, MakeSystemVersion(9, 0, 0)}, */
{ncm::SystemProgramId::Ldn, MakeSystemVersion(9, 1, 0)},
{ncm::SystemProgramId::NvServices, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Pcv, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Ppc, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::NvnFlinger, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Pcie, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Account, MakeSystemVersion(9, 1, 0)},
{ncm::SystemProgramId::Ns, MakeSystemVersion(9, 1, 0)},
{ncm::SystemProgramId::Nfc, MakeSystemVersion(9, 1, 0)},
{ncm::SystemProgramId::Psc, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::CapSrv, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Am, MakeSystemVersion(9, 1, 0)},
{ncm::SystemProgramId::Ssl, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Nim, MakeSystemVersion(9, 1, 0)},
/* {ncm::SystemProgramId::Cec, MakeSystemVersion(9, 0, 0)}, */
/* {ncm::SystemProgramId::Tspm, MakeSystemVersion(9, 0, 0)}, */
/* {ncm::SystemProgramId::Spl, MakeSystemVersion(9, 0, 0)}, */
{ncm::SystemProgramId::Lbl, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Btm, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Erpt, MakeSystemVersion(9, 1, 0)},
/* {ncm::SystemProgramId::Time, MakeSystemVersion(9, 0, 0)}, */
{ncm::SystemProgramId::Vi, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Pctl, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Npns, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Eupld, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Glue, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Eclct, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Es, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Fatal, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Grc, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Creport, MakeSystemVersion(9, 1, 0)},
{ncm::SystemProgramId::Ro, MakeSystemVersion(9, 1, 0)},
/* {ncm::SystemProgramId::Profiler, MakeSystemVersion(9, 0, 0)}, */
{ncm::SystemProgramId::Sdb, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Migration, MakeSystemVersion(9, 1, 0)},
/* {ncm::SystemProgramId::Jit, MakeSystemVersion(9, 0, 0)}, */
{ncm::SystemProgramId::JpegDec, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::SafeMode, MakeSystemVersion(9, 0, 0)},
{ncm::SystemProgramId::Olsc, MakeSystemVersion(9, 1, 0)},
/* {ncm::SystemProgramId::Dt, MakeSystemVersion(9, 0, 0)}, */
/* {ncm::SystemProgramId::Nd, MakeSystemVersion(9, 0, 0)}, */
{ncm::SystemProgramId::Ngct, MakeSystemVersion(9, 1, 0)},
/* All Web Applets. */
{ncm::ProgramId::AppletWeb, MakeSystemVersion(9, 1, 0)},
{ncm::ProgramId::AppletShop, MakeSystemVersion(9, 1, 0)},
{ncm::ProgramId::AppletOfflineWeb, MakeSystemVersion(9, 1, 0)},
{ncm::ProgramId::AppletLoginShare, MakeSystemVersion(9, 1, 0)},
{ncm::ProgramId::AppletWifiWebAuth, MakeSystemVersion(9, 1, 0)},
{ncm::WebAppletId::Web, MakeSystemVersion(9, 1, 0)},
{ncm::WebAppletId::Shop, MakeSystemVersion(9, 1, 0)},
{ncm::WebAppletId::OfflineWeb, MakeSystemVersion(9, 1, 0)},
{ncm::WebAppletId::LoginShare, MakeSystemVersion(9, 1, 0)},
{ncm::WebAppletId::WifiWebAuth, MakeSystemVersion(9, 1, 0)},
};
constexpr size_t g_MinimumProgramVersionsCount910 = util::size(g_MinimumProgramVersions910);

View File

@@ -264,52 +264,54 @@ namespace ams::ldr {
/* Redirection API. */
Result ResolveContentPath(char *out_path, const ncm::ProgramLocation &loc) {
char path[FS_MAX_PATH];
lr::Path path;
/* Try to get the path from the registered resolver. */
LrRegisteredLocationResolver reg;
R_TRY(lrOpenRegisteredLocationResolver(&reg));
ON_SCOPE_EXIT { serviceClose(&reg.s); };
lr::RegisteredLocationResolver reg;
R_TRY(lr::OpenRegisteredLocationResolver(std::addressof(reg)));
R_TRY_CATCH(lrRegLrResolveProgramPath(&reg, static_cast<u64>(loc.program_id), path)) {
R_TRY_CATCH(reg.ResolveProgramPath(std::addressof(path), loc.program_id)) {
R_CATCH(lr::ResultProgramNotFound) {
/* Program wasn't found via registered resolver, fall back to the normal resolver. */
LrLocationResolver lr;
R_TRY(lrOpenLocationResolver(static_cast<NcmStorageId>(loc.storage_id), &lr));
ON_SCOPE_EXIT { serviceClose(&lr.s); };
R_TRY(lrLrResolveProgramPath(&lr, static_cast<u64>(loc.program_id), path));
lr::LocationResolver lr;
R_TRY(lr::OpenLocationResolver(std::addressof(lr), static_cast<ncm::StorageId>(loc.storage_id)));
R_TRY(lr.ResolveProgramPath(std::addressof(path), loc.program_id));
}
} R_END_TRY_CATCH;
std::strncpy(out_path, path, FS_MAX_PATH);
out_path[FS_MAX_PATH - 1] = '\0';
std::strncpy(out_path, path.str, fs::EntryNameLengthMax);
out_path[fs::EntryNameLengthMax - 1] = '\0';
FixFileSystemPath(out_path);
return ResultSuccess();
}
Result RedirectContentPath(const char *path, const ncm::ProgramLocation &loc) {
LrLocationResolver lr;
R_TRY(lrOpenLocationResolver(static_cast<NcmStorageId>(loc.storage_id), &lr));
ON_SCOPE_EXIT { serviceClose(&lr.s); };
/* Copy in path. */
lr::Path lr_path;
std::strncpy(lr_path.str, path, sizeof(lr_path.str));
lr_path.str[sizeof(lr_path.str) - 1] = '\0';
return lrLrRedirectProgramPath(&lr, static_cast<u64>(loc.program_id), path);
/* Redirect the path. */
lr::LocationResolver lr;
R_TRY(lr::OpenLocationResolver(std::addressof(lr), static_cast<ncm::StorageId>(loc.storage_id)));
lr.RedirectProgramPath(lr_path, loc.program_id);
return ResultSuccess();
}
Result RedirectHtmlDocumentPathForHbl(const ncm::ProgramLocation &loc) {
char path[FS_MAX_PATH];
lr::Path path;
/* Open a location resolver. */
LrLocationResolver lr;
R_TRY(lrOpenLocationResolver(static_cast<NcmStorageId>(loc.storage_id), &lr));
ON_SCOPE_EXIT { serviceClose(&lr.s); };
lr::LocationResolver lr;
R_TRY(lr::OpenLocationResolver(std::addressof(lr), static_cast<ncm::StorageId>(loc.storage_id)));
/* If there's already a Html Document path, we don't need to set one. */
R_UNLESS(R_FAILED(lrLrResolveApplicationHtmlDocumentPath(&lr, static_cast<u64>(loc.program_id), path)), ResultSuccess());
R_SUCCEED_IF(R_SUCCEEDED(lr.ResolveApplicationHtmlDocumentPath(std::addressof(path), loc.program_id)));
/* We just need to set this to any valid NCA path. Let's use the executable path. */
R_TRY(lrLrResolveProgramPath(&lr, static_cast<u64>(loc.program_id), path));
R_TRY(lrLrRedirectApplicationHtmlDocumentPath(&lr, static_cast<u64>(loc.program_id), static_cast<u64>(loc.program_id), path));
R_TRY(lr.ResolveProgramPath(std::addressof(path), loc.program_id));
lr.RedirectApplicationHtmlDocumentPath(path, loc.program_id, loc.program_id);
return ResultSuccess();
}

View File

@@ -39,7 +39,7 @@ extern "C" {
namespace ams {
ncm::ProgramId CurrentProgramId = ncm::ProgramId::Loader;
ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::Loader;
namespace result {
@@ -73,7 +73,7 @@ void __appInit(void) {
/* Initialize services we need. */
sm::DoWithSession([&]() {
R_ABORT_UNLESS(fsInitialize());
R_ABORT_UNLESS(lrInitialize());
lr::Initialize();
R_ABORT_UNLESS(fsldrInitialize());
});
@@ -84,7 +84,7 @@ void __appExit(void) {
/* Cleanup services. */
fsdevUnmountAll();
fsldrExit();
lrExit();
lr::Finalize();
fsExit();
}

View File

@@ -84,7 +84,10 @@ namespace ams::ldr {
#include "ldr_anti_downgrade_tables.inc"
Result ValidateProgramVersion(ncm::ProgramId program_id, u32 version) {
R_UNLESS(hos::GetVersion() >= hos::Version_810, ResultSuccess());
/* No version verification is done before 8.1.0. */
R_SUCCEED_IF(hos::GetVersion() < hos::Version_810);
/* Do version-dependent validation, if compiled to do so. */
#ifdef LDR_VALIDATE_PROCESS_VERSION
const MinimumProgramVersion *entries = nullptr;
size_t num_entries = 0;

122
stratosphere/ncm/Makefile Normal file
View File

@@ -0,0 +1,122 @@
#---------------------------------------------------------------------------------
# pull in common stratosphere sysmodule configuration
#---------------------------------------------------------------------------------
include $(dir $(abspath $(lastword $(MAKEFILE_LIST))))/../../libraries/config/templates/stratosphere.mk
#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------
export OUTPUT := $(CURDIR)/$(TARGET)
export TOPDIR := $(CURDIR)
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
export DEPSDIR := $(CURDIR)/$(BUILD)
CFILES := $(foreach dir,$(SOURCES),$(filter-out $(notdir $(wildcard $(dir)/*.arch.*.c)) $(notdir $(wildcard $(dir)/*.board.*.c)) $(notdir $(wildcard $(dir)/*.os.*.c)), \
$(notdir $(wildcard $(dir)/*.c))))
CFILES += $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.arch.$(ATMOSPHERE_ARCH_NAME).c)))
CFILES += $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.board.$(ATMOSPHERE_BOARD_NAME).c)))
CFILES += $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.os.$(ATMOSPHERE_OS_NAME).c)))
CPPFILES := $(foreach dir,$(SOURCES),$(filter-out $(notdir $(wildcard $(dir)/*.arch.*.cpp)) $(notdir $(wildcard $(dir)/*.board.*.cpp)) $(notdir $(wildcard $(dir)/*.os.*.cpp)), \
$(notdir $(wildcard $(dir)/*.cpp))))
CPPFILES += $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.arch.$(ATMOSPHERE_ARCH_NAME).cpp)))
CPPFILES += $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.board.$(ATMOSPHERE_BOARD_NAME).cpp)))
CPPFILES += $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.os.$(ATMOSPHERE_OS_NAME).cpp)))
SFILES := $(foreach dir,$(SOURCES),$(filter-out $(notdir $(wildcard $(dir)/*.arch.*.s)) $(notdir $(wildcard $(dir)/*.board.*.s)) $(notdir $(wildcard $(dir)/*.os.*.s)), \
$(notdir $(wildcard $(dir)/*.s))))
SFILES += $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.arch.$(ATMOSPHERE_ARCH_NAME).s)))
SFILES += $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.board.$(ATMOSPHERE_BOARD_NAME).s)))
SFILES += $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.os.$(ATMOSPHERE_OS_NAME).s)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
export LD := $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
export LD := $(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------
export OFILES := $(addsuffix .o,$(BINFILES)) \
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I$(CURDIR)/$(BUILD)
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
export BUILD_EXEFS_SRC := $(TOPDIR)/$(EXEFS_SRC)
ifeq ($(strip $(CONFIG_JSON)),)
jsons := $(wildcard *.json)
ifneq (,$(findstring $(TARGET).json,$(jsons)))
export APP_JSON := $(TOPDIR)/$(TARGET).json
else
ifneq (,$(findstring config.json,$(jsons)))
export APP_JSON := $(TOPDIR)/config.json
endif
endif
else
export APP_JSON := $(TOPDIR)/$(CONFIG_JSON)
endif
.PHONY: $(BUILD) clean all
#---------------------------------------------------------------------------------
all: $(BUILD)
$(BUILD):
@[ -d $@ ] || mkdir -p $@
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) $(TARGET).kip $(TARGET).elf
#---------------------------------------------------------------------------------
else
.PHONY: all
DEPENDS := $(OFILES:.o=.d)
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
all : $(OUTPUT).kip
$(OUTPUT).kip : $(OUTPUT).elf
$(OUTPUT).elf : $(OFILES)
#---------------------------------------------------------------------------------
# you need a rule like this for each extension you use as binary data
#---------------------------------------------------------------------------------
%.bin.o : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
-include $(DEPENDS)
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------

67
stratosphere/ncm/ncm.json Normal file
View File

@@ -0,0 +1,67 @@
{
"name": "NCM",
"title_id": "0x0100000000000002",
"main_thread_stack_size": "0x00004000",
"main_thread_priority": 49,
"default_cpu_id": 3,
"process_category": 1,
"kernel_capabilities": [
{
"type": "handle_table_size",
"value": 128
}, {
"type": "syscalls",
"value": {
"svcSetHeapSize" : "0x01",
"svcSetMemoryPermission" : "0x02",
"svcSetMemoryAttribute" : "0x03",
"svcMapMemory" : "0x04",
"svcUnmapMemory" : "0x05",
"svcQueryMemory" : "0x06",
"svcExitProcess" : "0x07",
"svcCreateThread" : "0x08",
"svcStartThread" : "0x09",
"svcExitThread" : "0x0A",
"svcSleepThread" : "0x0B",
"svcGetThreadPriority" : "0x0C",
"svcSetThreadPriority" : "0x0D",
"svcGetThreadCoreMask" : "0x0E",
"svcSetThreadCoreMask" : "0x0F",
"svcGetCurrentProcessorNumber" : "0x10",
"svcSignalEvent" : "0x11",
"svcClearEvent" : "0x12",
"svcMapSharedMemory" : "0x13",
"svcUnmapSharedMemory" : "0x14",
"svcCreateTransferMemory" : "0x15",
"svcCloseHandle" : "0x16",
"svcResetSignal" : "0x17",
"svcWaitSynchronization" : "0x18",
"svcCancelSynchronization" : "0x19",
"svcArbitrateLock" : "0x1A",
"svcArbitrateUnlock" : "0x1B",
"svcWaitProcessWideKeyAtomic" : "0x1C",
"svcSignalProcessWideKey" : "0x1D",
"svcGetSystemTick" : "0x1E",
"svcConnectToNamedPort" : "0x1F",
"svcSendSyncRequestLight" : "0x20",
"svcSendSyncRequest" : "0x21",
"svcSendSyncRequestWithUserBuffer" : "0x22",
"svcSendAsyncRequestWithUserBuffer" : "0x23",
"svcGetProcessId" : "0x24",
"svcGetThreadId" : "0x25",
"svcBreak" : "0x26",
"svcOutputDebugString" : "0x27",
"svcReturnFromException" : "0x28",
"svcGetInfo" : "0x29",
"svcWaitForAddress" : "0x34",
"svcSignalToAddress" : "0x35",
"svcCreateSession" : "0x40",
"svcAcceptSession" : "0x41",
"svcReplyAndReceiveLight" : "0x42",
"svcReplyAndReceive" : "0x43",
"svcReplyAndReceiveWithUserBuffer" : "0x44",
"svcCallSecureMonitor" : "0x7F"
}
}
]
}

View File

@@ -0,0 +1,231 @@
/*
* Copyright (c) 2019-2020 Adubbz, Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stratosphere.hpp>
extern "C" {
extern u32 __start__;
u32 __nx_applet_type = AppletType_None;
#define INNER_HEAP_SIZE 0x400000
size_t nx_inner_heap_size = INNER_HEAP_SIZE;
char nx_inner_heap[INNER_HEAP_SIZE];
void __libnx_initheap(void);
void __appInit(void);
void __appExit(void);
/* Exception handling. */
alignas(16) u8 __nx_exception_stack[ams::os::MemoryPageSize];
u64 __nx_exception_stack_size = sizeof(__nx_exception_stack);
void __libnx_exception_handler(ThreadExceptionDump *ctx);
}
namespace ams {
ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::Ncm;
namespace result {
bool CallFatalOnResultAssertion = false;
}
}
using namespace ams;
void __libnx_exception_handler(ThreadExceptionDump *ctx) {
ams::CrashHandler(ctx);
}
void __libnx_initheap(void) {
void * addr = nx_inner_heap;
size_t size = nx_inner_heap_size;
/* Newlib */
extern char *fake_heap_start;
extern char *fake_heap_end;
fake_heap_start = (char*)addr;
fake_heap_end = (char*)addr + size;
}
void __appInit(void) {
hos::SetVersionForLibnx();
sm::DoWithSession([&]() {
R_ABORT_UNLESS(fsInitialize());
R_ABORT_UNLESS(splInitialize());
});
ams::CheckApiVersion();
}
void __appExit(void) {
/* Cleanup services. */
splExit();
fsExit();
}
namespace {
struct ContentManagerServerOptions {
static constexpr size_t PointerBufferSize = 0x400;
static constexpr size_t MaxDomains = 0;
static constexpr size_t MaxDomainObjects = 0;
};
constexpr inline size_t ContentManagerNumServers = 1;
constexpr inline size_t ContentManagerManagerSessions = 16;
constexpr inline size_t ContentManagerExtraSessions = 16;
constexpr inline size_t ContentManagerMaxSessions = ContentManagerManagerSessions + ContentManagerExtraSessions;
constexpr inline sm::ServiceName ContentManagerServiceName = sm::ServiceName::Encode("ncm");
class ContentManagerServerManager : public sf::hipc::ServerManager<ContentManagerNumServers, ContentManagerServerOptions, ContentManagerMaxSessions> {
private:
static constexpr size_t ThreadStackSize = 0x4000;
static constexpr int ThreadPriority = 0x15;
using ServiceType = ncm::ContentManagerImpl;
private:
os::StaticThread<ThreadStackSize> thread;
std::shared_ptr<ServiceType> ncm_manager;
private:
static void ThreadFunction(void *_this) {
reinterpret_cast<ContentManagerServerManager *>(_this)->LoopProcess();
}
public:
ContentManagerServerManager(ServiceType *m)
: thread(ThreadFunction, this, ThreadPriority), ncm_manager()
{
/* ... */
}
ams::Result Initialize(std::shared_ptr<ServiceType> manager_obj) {
this->ncm_manager = manager_obj;
return this->RegisterServer<ServiceType>(ContentManagerServiceName, ContentManagerManagerSessions, this->ncm_manager);
}
ams::Result StartThreads() {
return this->thread.Start();
}
void Wait() {
this->thread.Join();
}
};
struct LocationResolverServerOptions {
static constexpr size_t PointerBufferSize = 0x400;
static constexpr size_t MaxDomains = 0;
static constexpr size_t MaxDomainObjects = 0;
};
constexpr inline size_t LocationResolverNumServers = 1;
constexpr inline size_t LocationResolverManagerSessions = 16;
constexpr inline size_t LocationResolverExtraSessions = 16;
constexpr inline size_t LocationResolverMaxSessions = LocationResolverManagerSessions + LocationResolverExtraSessions;
constexpr inline sm::ServiceName LocationResolverServiceName = sm::ServiceName::Encode("lr");
class LocationResolverServerManager : public sf::hipc::ServerManager<LocationResolverNumServers, LocationResolverServerOptions, LocationResolverMaxSessions> {
private:
static constexpr size_t ThreadStackSize = 0x4000;
static constexpr int ThreadPriority = 0x15;
using ServiceType = lr::LocationResolverManagerImpl;
private:
os::StaticThread<ThreadStackSize> thread;
std::shared_ptr<ServiceType> lr_manager;
private:
static void ThreadFunction(void *_this) {
reinterpret_cast<LocationResolverServerManager *>(_this)->LoopProcess();
}
public:
LocationResolverServerManager(ServiceType *m)
: thread(ThreadFunction, this, ThreadPriority), lr_manager(sf::ServiceObjectTraits<ServiceType>::SharedPointerHelper::GetEmptyDeleteSharedPointer(m))
{
/* ... */
}
ams::Result Initialize() {
return this->RegisterServer<ServiceType>(LocationResolverServiceName, LocationResolverManagerSessions, this->lr_manager);
}
ams::Result StartThreads() {
return this->thread.Start();
}
void Wait() {
this->thread.Join();
}
};
ncm::ContentManagerImpl g_ncm_manager_service_object;
ContentManagerServerManager g_ncm_server_manager(std::addressof(g_ncm_manager_service_object));
lr::LocationResolverManagerImpl g_lr_manager_service_object;
LocationResolverServerManager g_lr_server_manager(std::addressof(g_lr_manager_service_object));
ALWAYS_INLINE std::shared_ptr<ncm::ContentManagerImpl> GetSharedPointerToContentManager() {
return sf::ServiceObjectTraits<ncm::ContentManagerImpl>::SharedPointerHelper::GetEmptyDeleteSharedPointer(std::addressof(g_ncm_manager_service_object));
}
/* Compile-time configuration. */
#ifdef NCM_BUILD_FOR_INTITIALIZE
constexpr inline bool BuildSystemDatabase = true;
#else
constexpr inline bool BuildSystemDatabase = false;
#endif
#ifdef NCM_BUILD_FOR_SAFEMODE
constexpr inline bool ImportSystemDatabaseFromSignedSystemPartitionOnSdCard = true;
#else
constexpr inline bool ImportSystemDatabaseFromSignedSystemPartitionOnSdCard = false;
#endif
static_assert(!(BuildSystemDatabase && ImportSystemDatabaseFromSignedSystemPartitionOnSdCard), "Invalid NCM build configuration!");
constexpr inline ncm::ContentManagerConfig ManagerConfig = { BuildSystemDatabase, ImportSystemDatabaseFromSignedSystemPartitionOnSdCard };
}
int main(int argc, char **argv)
{
/* Create and initialize the content manager. */
auto content_manager = GetSharedPointerToContentManager();
R_ABORT_UNLESS(content_manager->Initialize(ManagerConfig));
/* Initialize ncm's server and start threads. */
R_ABORT_UNLESS(g_ncm_server_manager.Initialize(content_manager));
R_ABORT_UNLESS(g_ncm_server_manager.StartThreads());
/* Initialize ncm api. */
ncm::InitializeWithObject(content_manager);
/* Initialize lr's server and start threads. */
R_ABORT_UNLESS(g_lr_server_manager.Initialize());
R_ABORT_UNLESS(g_lr_server_manager.StartThreads());
/* Wait indefinitely. */
g_ncm_server_manager.Wait();
g_lr_server_manager.Wait();
return 0;
}

View File

@@ -352,7 +352,7 @@ namespace ams::pm::impl {
/* Process hooks/signaling. */
if (location.program_id == g_program_id_hook) {
g_hook_to_create_process_event.Signal();
g_program_id_hook = ncm::ProgramId::Invalid;
g_program_id_hook = ncm::InvalidProgramId;
} else if (is_application && g_application_hook) {
g_hook_to_create_application_process_event.Signal();
g_application_hook = false;
@@ -666,7 +666,7 @@ namespace ams::pm::impl {
*out_hook = INVALID_HANDLE;
{
ncm::ProgramId old_value = ncm::ProgramId::Invalid;
ncm::ProgramId old_value = ncm::InvalidProgramId;
R_UNLESS(g_program_id_hook.compare_exchange_strong(old_value, program_id), pm::ResultDebugHookInUse());
}
@@ -688,7 +688,7 @@ namespace ams::pm::impl {
Result ClearHook(u32 which) {
if (which & HookType_ProgramId) {
g_program_id_hook = ncm::ProgramId::Invalid;
g_program_id_hook = ncm::InvalidProgramId;
}
if (which & HookType_Application) {
g_application_hook = false;

View File

@@ -41,7 +41,7 @@ extern "C" {
namespace ams {
ncm::ProgramId CurrentProgramId = ncm::ProgramId::Pm;
ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::Pm;
namespace result {
@@ -141,7 +141,6 @@ void __appInit(void) {
/* Use AMS manager extension to tell SM that FS has been worked around. */
R_ABORT_UNLESS(sm::manager::EndInitialDefers());
R_ABORT_UNLESS(lrInitialize());
R_ABORT_UNLESS(ldrPmInitialize());
R_ABORT_UNLESS(splInitialize());
});
@@ -153,7 +152,6 @@ void __appExit(void) {
/* Cleanup services. */
splExit();
ldrPmExit();
lrExit();
smManagerExit();
fsprExit();
}

View File

@@ -87,7 +87,7 @@ namespace ams::ro::impl {
process_h = other_process_h;
}
ncm::ProgramId program_id = ncm::ProgramId::Invalid;
ncm::ProgramId program_id = ncm::InvalidProgramId;
if (hos::GetVersion() >= hos::Version_300) {
/* 3.0.0+: Use svcGetInfo. */
R_ABORT_UNLESS(svcGetInfo(&program_id.value, InfoType_ProgramId, process_h, 0));

View File

@@ -34,7 +34,7 @@ extern "C" {
namespace ams {
ncm::ProgramId CurrentProgramId = ncm::ProgramId::Ro;
ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::Ro;
namespace result {

View File

@@ -239,10 +239,13 @@ namespace ams::sm::impl {
bool IsMitmDisallowed(ncm::ProgramId program_id) {
/* Mitm used on certain programs can prevent the boot process from completing. */
/* TODO: Is there a way to do this that's less hardcoded? Needs design thought. */
return program_id == ncm::ProgramId::Loader ||
program_id == ncm::ProgramId::Boot ||
program_id == ncm::ProgramId::AtmosphereMitm ||
program_id == ncm::ProgramId::Creport;
return program_id == ncm::SystemProgramId::Loader ||
program_id == ncm::SystemProgramId::Pm ||
program_id == ncm::SystemProgramId::Spl ||
program_id == ncm::SystemProgramId::Boot ||
program_id == ncm::SystemProgramId::Ncm ||
program_id == ncm::AtmosphereProgramId::Mitm ||
program_id == ncm::SystemProgramId::Creport;
}
Result AddFutureMitmDeclaration(ServiceName service) {
@@ -297,7 +300,7 @@ namespace ams::sm::impl {
is_valid &= std::memcmp(&ac_service, &service, access_control.GetServiceNameSize() - 1) == 0;
}
R_UNLESS(!is_valid, ResultSuccess());
R_SUCCEED_IF(is_valid);
}
access_control = access_control.GetNextEntry();
}

View File

@@ -40,7 +40,7 @@ extern "C" {
namespace ams {
ncm::ProgramId CurrentProgramId = ncm::ProgramId::Sm;
ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::Sm;
namespace result {

View File

@@ -19,7 +19,7 @@
namespace ams::sm {
Result ManagerService::RegisterProcess(os::ProcessId process_id, const sf::InBuffer &acid_sac, const sf::InBuffer &aci_sac) {
return impl::RegisterProcess(process_id, ncm::ProgramId::Invalid, cfg::OverrideStatus{}, acid_sac.GetPointer(), acid_sac.GetSize(), aci_sac.GetPointer(), aci_sac.GetSize());
return impl::RegisterProcess(process_id, ncm::InvalidProgramId, cfg::OverrideStatus{}, acid_sac.GetPointer(), acid_sac.GetSize(), aci_sac.GetPointer(), aci_sac.GetSize());
}
Result ManagerService::UnregisterProcess(os::ProcessId process_id) {

View File

@@ -46,7 +46,7 @@ extern "C" {
namespace ams {
ncm::ProgramId CurrentProgramId = ncm::ProgramId::Spl;
ncm::ProgramId CurrentProgramId = ncm::SystemProgramId::Spl;
namespace result {