stratosphere: more result cleanup

This commit is contained in:
Michael Scire 2019-06-20 02:00:59 -07:00
parent 7b6050a0cb
commit cead8a36ea
38 changed files with 158 additions and 448 deletions

View file

@ -38,7 +38,7 @@ DATA := data
INCLUDES := include ../../common/include INCLUDES := include ../../common/include
EXEFS_SRC := exefs_src EXEFS_SRC := exefs_src
DEFINES := -DDISABLE_IPC -DATMOSPHERE_GIT_BRANCH=\"$(AMSBRANCH)\" -DATMOSPHERE_GIT_REV=\"$(AMSREV)\" DEFINES := -DRESULT_ABORT_ON_ASSERT -DATMOSPHERE_GIT_BRANCH=\"$(AMSBRANCH)\" -DATMOSPHERE_GIT_REV=\"$(AMSREV)\"
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# options for code generation # options for code generation

View file

@ -36,7 +36,6 @@ static Result RetryUntilSuccess(F f) {
} }
Result Boot::ReadI2cRegister(I2cSessionImpl &session, u8 *dst, size_t dst_size, const u8 *cmd, size_t cmd_size) { Result Boot::ReadI2cRegister(I2cSessionImpl &session, u8 *dst, size_t dst_size, const u8 *cmd, size_t cmd_size) {
Result rc;
if (dst == nullptr || dst_size == 0 || cmd == nullptr || cmd_size == 0) { if (dst == nullptr || dst_size == 0 || cmd == nullptr || cmd_size == 0) {
std::abort(); std::abort();
} }
@ -44,12 +43,8 @@ Result Boot::ReadI2cRegister(I2cSessionImpl &session, u8 *dst, size_t dst_size,
u8 cmd_list[I2cCommandListFormatter::MaxCommandListSize]; u8 cmd_list[I2cCommandListFormatter::MaxCommandListSize];
I2cCommandListFormatter formatter(cmd_list, sizeof(cmd_list)); I2cCommandListFormatter formatter(cmd_list, sizeof(cmd_list));
if (R_FAILED((rc = formatter.EnqueueSendCommand(I2cTransactionOption_Start, cmd, cmd_size)))) { R_ASSERT(formatter.EnqueueSendCommand(I2cTransactionOption_Start, cmd, cmd_size));
std::abort(); R_ASSERT(formatter.EnqueueReceiveCommand(static_cast<I2cTransactionOption>(I2cTransactionOption_Start | I2cTransactionOption_Stop), dst_size));
}
if (R_FAILED((rc = formatter.EnqueueReceiveCommand(static_cast<I2cTransactionOption>(I2cTransactionOption_Start | I2cTransactionOption_Stop), dst_size)))) {
std::abort();
}
return RetryUntilSuccess([&]() { return I2cDriver::ExecuteCommandList(session, dst, dst_size, cmd_list, formatter.GetCurrentSize()); }); return RetryUntilSuccess([&]() { return I2cDriver::ExecuteCommandList(session, dst, dst_size, cmd_list, formatter.GetCurrentSize()); });
} }

View file

@ -69,26 +69,13 @@ void __libnx_initheap(void) {
} }
void __appInit(void) { void __appInit(void) {
Result rc;
SetFirmwareVersionForLibnx(); SetFirmwareVersionForLibnx();
/* Initialize services we need (TODO: NCM) */ /* Initialize services we need (TODO: NCM) */
DoWithSmSession([&]() { DoWithSmSession([&]() {
rc = fsInitialize(); R_ASSERT(fsInitialize());
if (R_FAILED(rc)) { R_ASSERT(splInitialize());
std::abort(); R_ASSERT(pmshellInitialize());
}
rc = splInitialize();
if (R_FAILED(rc)) {
std::abort();
}
rc = pmshellInitialize();
if (R_FAILED(rc)) {
std::abort();
}
}); });
CheckAtmosphereVersion(CURRENT_ATMOSPHERE_VERSION); CheckAtmosphereVersion(CURRENT_ATMOSPHERE_VERSION);

View file

@ -23,8 +23,7 @@ void Boot::CheckAndRepairBootImages() {
const BootImageUpdateType boot_image_update_type = Updater::GetBootImageUpdateType(Boot::GetHardwareType()); const BootImageUpdateType boot_image_update_type = Updater::GetBootImageUpdateType(Boot::GetHardwareType());
bool repaired_normal, repaired_safe; bool repaired_normal, repaired_safe;
Result rc = Updater::VerifyBootImagesAndRepairIfNeeded(&repaired_normal, &repaired_safe, g_boot_image_work_buffer, sizeof(g_boot_image_work_buffer), boot_image_update_type); if (R_SUCCEEDED(Updater::VerifyBootImagesAndRepairIfNeeded(&repaired_normal, &repaired_safe, g_boot_image_work_buffer, sizeof(g_boot_image_work_buffer), boot_image_update_type)) && repaired_normal) {
if (R_SUCCEEDED(rc) && repaired_normal) {
/* Nintendo only performs a reboot on successful normal repair. */ /* Nintendo only performs a reboot on successful normal repair. */
Boot::RebootSystem(); Boot::RebootSystem();
} }

View file

@ -65,21 +65,13 @@ void __libnx_initheap(void) {
} }
void __appInit(void) { void __appInit(void) {
Result rc;
SetFirmwareVersionForLibnx(); SetFirmwareVersionForLibnx();
DoWithSmSession([&]() { DoWithSmSession([&]() {
rc = fsInitialize(); R_ASSERT(fsInitialize());
if (R_FAILED(rc)) {
fatalSimple(MAKERESULT(Module_Libnx, LibnxError_InitFail_FS));
}
}); });
rc = fsdevMountSdmc(); R_ASSERT(fsdevMountSdmc());
if (R_FAILED(rc)) {
fatalSimple(MAKERESULT(Module_Libnx, LibnxError_InitFail_FS));
}
} }
void __appExit(void) { void __appExit(void) {

View file

@ -61,12 +61,7 @@ void DmntCheatDebugEventsManager::ContinueCheatProcess(Handle cheat_dbg_hnd) {
if (dbg_event.type == DebugEventType::AttachThread) { if (dbg_event.type == DebugEventType::AttachThread) {
u64 out64; u64 out64;
u32 out32; u32 out32;
Result rc = svcGetDebugThreadParam(&out64, &out32, cheat_dbg_hnd, dbg_event.info.attach_thread.thread_id, DebugThreadParam_CurrentCore); R_ASSERT(svcGetDebugThreadParam(&out64, &out32, cheat_dbg_hnd, dbg_event.info.attach_thread.thread_id, DebugThreadParam_CurrentCore));
if (R_FAILED(rc)) {
fatalSimple(rc);
}
target_core = out32; target_core = out32;
} }

View file

@ -54,15 +54,8 @@ void DmntCheatManager::StartDebugEventsThread() {
/* Spawn the debug events thread. */ /* Spawn the debug events thread. */
if (!g_has_debug_events_thread) { if (!g_has_debug_events_thread) {
Result rc; R_ASSERT(g_debug_events_thread.Initialize(&DmntCheatManager::DebugEventsThread, nullptr, 0x4000, 48));
R_ASSERT(g_debug_events_thread.Start());
if (R_FAILED((rc = g_debug_events_thread.Initialize(&DmntCheatManager::DebugEventsThread, nullptr, 0x4000, 48)))) {
return fatalSimple(rc);
}
if (R_FAILED((rc = g_debug_events_thread.Start()))) {
return fatalSimple(rc);
}
g_has_debug_events_thread = true; g_has_debug_events_thread = true;
} }
@ -799,33 +792,22 @@ Result DmntCheatManager::DisableFrozenAddress(u64 address) {
} }
Handle DmntCheatManager::PrepareDebugNextApplication() { Handle DmntCheatManager::PrepareDebugNextApplication() {
Result rc;
Handle event_h; Handle event_h;
if (R_FAILED((rc = pmdmntEnableDebugForApplication(&event_h)))) { R_ASSERT(pmdmntEnableDebugForApplication(&event_h));
fatalSimple(rc);
}
return event_h; return event_h;
} }
static void PopulateMemoryExtents(MemoryRegionExtents *extents, Handle p_h, u64 id_base, u64 id_size) { static void PopulateMemoryExtents(MemoryRegionExtents *extents, Handle p_h, u64 id_base, u64 id_size) {
Result rc;
/* Get base extent. */ /* Get base extent. */
if (R_FAILED((rc = svcGetInfo(&extents->base, id_base, p_h, 0)))) { R_ASSERT(svcGetInfo(&extents->base, id_base, p_h, 0));
fatalSimple(rc);
}
/* Get size extent. */ /* Get size extent. */
if (R_FAILED((rc = svcGetInfo(&extents->size, id_size, p_h, 0)))) { R_ASSERT(svcGetInfo(&extents->size, id_size, p_h, 0));
fatalSimple(rc);
}
} }
static void StartDebugProcess(u64 pid) { static void StartDebugProcess(u64 pid) {
Result rc = pmdmntStartProcess(pid); R_ASSERT(pmdmntStartProcess(pid));
if (R_FAILED(rc)) {
fatalSimple(rc);
}
} }
Result DmntCheatManager::ForceOpenCheatProcess() { Result DmntCheatManager::ForceOpenCheatProcess() {
@ -921,7 +903,6 @@ Result DmntCheatManager::ForceOpenCheatProcess() {
void DmntCheatManager::OnNewApplicationLaunch() { void DmntCheatManager::OnNewApplicationLaunch() {
std::scoped_lock<HosMutex> attach_lk(g_attach_lock); std::scoped_lock<HosMutex> attach_lk(g_attach_lock);
Result rc;
{ {
std::scoped_lock<HosMutex> lk(g_cheat_lock); std::scoped_lock<HosMutex> lk(g_cheat_lock);
@ -937,18 +918,14 @@ void DmntCheatManager::OnNewApplicationLaunch() {
std::scoped_lock<HosMutex> lk(g_cheat_lock); std::scoped_lock<HosMutex> lk(g_cheat_lock);
/* Get the new application's process ID. */ /* Get the new application's process ID. */
if (R_FAILED((rc = pmdmntGetApplicationPid(&g_cheat_process_metadata.process_id)))) { R_ASSERT(pmdmntGetApplicationPid(&g_cheat_process_metadata.process_id));
fatalSimple(rc);
}
/* Get process handle, use it to learn memory extents. */ /* Get process handle, use it to learn memory extents. */
{ {
Handle proc_h = 0; Handle proc_h = 0;
ON_SCOPE_EXIT { if (proc_h != 0) { svcCloseHandle(proc_h); } }; ON_SCOPE_EXIT { if (proc_h != 0) { svcCloseHandle(proc_h); } };
if (R_FAILED((rc = pmdmntAtmosphereGetProcessInfo(&proc_h, &g_cheat_process_metadata.title_id, nullptr, g_cheat_process_metadata.process_id)))) { R_ASSERT(pmdmntAtmosphereGetProcessInfo(&proc_h, &g_cheat_process_metadata.title_id, nullptr, g_cheat_process_metadata.process_id));
fatalSimple(rc);
}
/* Get memory extents. */ /* Get memory extents. */
PopulateMemoryExtents(&g_cheat_process_metadata.heap_extents, proc_h, 4, 5); PopulateMemoryExtents(&g_cheat_process_metadata.heap_extents, proc_h, 4, 5);
@ -972,9 +949,7 @@ void DmntCheatManager::OnNewApplicationLaunch() {
{ {
LoaderModuleInfo proc_modules[2]; LoaderModuleInfo proc_modules[2];
u32 num_modules; u32 num_modules;
if (R_FAILED((rc = ldrDmntGetModuleInfos(g_cheat_process_metadata.process_id, proc_modules, sizeof(proc_modules)/sizeof(proc_modules[0]), &num_modules)))) { R_ASSERT(ldrDmntGetModuleInfos(g_cheat_process_metadata.process_id, proc_modules, sizeof(proc_modules)/sizeof(proc_modules[0]), &num_modules));
fatalSimple(rc);
}
/* All applications must have two modules. */ /* All applications must have two modules. */
/* If we only have one, we must be e.g. mitming HBL. */ /* If we only have one, we must be e.g. mitming HBL. */
@ -999,9 +974,7 @@ void DmntCheatManager::OnNewApplicationLaunch() {
} }
/* Open a debug handle. */ /* Open a debug handle. */
if (R_FAILED((rc = svcDebugActiveProcess(&g_cheat_process_debug_hnd, g_cheat_process_metadata.process_id)))) { R_ASSERT(svcDebugActiveProcess(&g_cheat_process_debug_hnd, g_cheat_process_metadata.process_id));
fatalSimple(rc);
}
/* Start the process. */ /* Start the process. */
StartDebugProcess(g_cheat_process_metadata.process_id); StartDebugProcess(g_cheat_process_metadata.process_id);

View file

@ -59,64 +59,23 @@ void __libnx_initheap(void) {
} }
void __appInit(void) { void __appInit(void) {
Result rc;
SetFirmwareVersionForLibnx(); SetFirmwareVersionForLibnx();
DoWithSmSession([&]() { DoWithSmSession([&]() {
rc = pmdmntInitialize(); R_ASSERT(pmdmntInitialize());
if (R_FAILED(rc)) { R_ASSERT(ldrDmntInitialize());
fatalSimple(rc);
}
rc = ldrDmntInitialize();
if (R_FAILED(rc)) {
fatalSimple(rc);
}
/* TODO: We provide this on every sysver via ro. Do we need a shim? */ /* TODO: We provide this on every sysver via ro. Do we need a shim? */
if (GetRuntimeFirmwareVersion() >= FirmwareVersion_300) { if (GetRuntimeFirmwareVersion() >= FirmwareVersion_300) {
rc = roDmntInitialize(); R_ASSERT(roDmntInitialize());
if (R_FAILED(rc)) {
fatalSimple(rc);
}
}
rc = nsdevInitialize();
if (R_FAILED(rc)) {
fatalSimple(rc);
}
rc = lrInitialize();
if (R_FAILED(rc)) {
fatalSimple(rc);
}
rc = setInitialize();
if (R_FAILED(rc)) {
fatalSimple(rc);
}
rc = setsysInitialize();
if (R_FAILED(rc)) {
fatalSimple(rc);
}
rc = hidInitialize();
if (R_FAILED(rc)) {
fatalSimple(rc);
}
rc = fsInitialize();
if (R_FAILED(rc)) {
fatalSimple(rc);
} }
R_ASSERT(nsdevInitialize());
R_ASSERT(lrInitialize());
R_ASSERT(setInitialize());
R_ASSERT(setsysInitialize());
R_ASSERT(fsInitialize());
}); });
rc = fsdevMountSdmc(); R_ASSERT(fsdevMountSdmc());
if (R_FAILED(rc)) {
fatalSimple(rc);
}
CheckAtmosphereVersion(CURRENT_ATMOSPHERE_VERSION); CheckAtmosphereVersion(CURRENT_ATMOSPHERE_VERSION);
} }

View file

@ -31,7 +31,7 @@ DATA := data
INCLUDES := include ../../common/include INCLUDES := include ../../common/include
EXEFS_SRC := exefs_src EXEFS_SRC := exefs_src
DEFINES := -DDISABLE_IPC -DATMOSPHERE_GIT_BRANCH=\"$(AMSBRANCH)\" -DATMOSPHERE_GIT_REV=\"$(AMSREV)\" DEFINES := -DRESULT_ABORT_ON_ASSERT -DATMOSPHERE_GIT_BRANCH=\"$(AMSBRANCH)\" -DATMOSPHERE_GIT_REV=\"$(AMSREV)\"
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# options for code generation # options for code generation

View file

@ -72,83 +72,30 @@ void __libnx_initheap(void) {
} }
void __appInit(void) { void __appInit(void) {
Result rc;
SetFirmwareVersionForLibnx(); SetFirmwareVersionForLibnx();
DoWithSmSession([&]() { DoWithSmSession([&]() {
rc = setInitialize(); R_ASSERT(setInitialize());
if (R_FAILED(rc)) { R_ASSERT(setsysInitialize());
std::abort(); R_ASSERT(pminfoInitialize());
} R_ASSERT(i2cInitialize());
R_ASSERT(bpcInitialize());
rc = setsysInitialize();
if (R_FAILED(rc)) {
std::abort();
}
rc = pminfoInitialize();
if (R_FAILED(rc)) {
std::abort();
}
rc = i2cInitialize();
if (R_FAILED(rc)) {
std::abort();
}
rc = bpcInitialize();
if (R_FAILED(rc)) {
std::abort();
}
if (GetRuntimeFirmwareVersion() >= FirmwareVersion_800) { if (GetRuntimeFirmwareVersion() >= FirmwareVersion_800) {
rc = clkrstInitialize(); R_ASSERT(clkrstInitialize());
if (R_FAILED(rc)) {
std::abort();
}
} else { } else {
rc = pcvInitialize(); R_ASSERT(pcvInitialize());
if (R_FAILED(rc)) {
std::abort();
}
} }
rc = lblInitialize(); R_ASSERT(lblInitialize());
if (R_FAILED(rc)) { R_ASSERT(psmInitialize());
std::abort(); R_ASSERT(spsmInitialize());
} R_ASSERT(plInitialize());
R_ASSERT(gpioInitialize());
rc = psmInitialize(); R_ASSERT(fsInitialize());
if (R_FAILED(rc)) {
std::abort();
}
rc = spsmInitialize();
if (R_FAILED(rc)) {
std::abort();
}
rc = plInitialize();
if (R_FAILED(rc)) {
std::abort();
}
rc = gpioInitialize();
if (R_FAILED(rc)) {
std::abort();
}
rc = fsInitialize();
if (R_FAILED(rc)) {
std::abort();
}
}); });
rc = fsdevMountSdmc(); R_ASSERT(fsdevMountSdmc());
if (R_FAILED(rc)) {
std::abort();
}
/* fatal cannot throw fatal, so don't do: CheckAtmosphereVersion(CURRENT_ATMOSPHERE_VERSION); */ /* fatal cannot throw fatal, so don't do: CheckAtmosphereVersion(CURRENT_ATMOSPHERE_VERSION); */
} }

View file

@ -33,8 +33,7 @@ static size_t g_num_threads = 0;
static void RunTaskThreadFunc(void *arg) { static void RunTaskThreadFunc(void *arg) {
IFatalTask *task = reinterpret_cast<IFatalTask *>(arg); IFatalTask *task = reinterpret_cast<IFatalTask *>(arg);
Result rc = task->Run(); if (R_FAILED(task->Run())) {
if (R_FAILED(rc)) {
/* TODO: Log task failure, somehow? */ /* TODO: Log task failure, somehow? */
} }

View file

@ -122,22 +122,20 @@ void PowerButtonObserveTask::WaitForPowerButton() {
BpcSleepButtonState state; BpcSleepButtonState state;
GpioValue val; GpioValue val;
while (true) { while (true) {
Result rc = ResultSuccess;
if (config->is_auto_reboot_enabled && auto_reboot_helper.TimedOut() ) { if (config->is_auto_reboot_enabled && auto_reboot_helper.TimedOut() ) {
bpcRebootSystem(); bpcRebootSystem();
return; return;
} }
if (check_vol_up && R_SUCCEEDED((rc = gpioPadGetValue(&vol_up_btn, &val))) && val == GpioValue_Low) { if (check_vol_up && R_SUCCEEDED(gpioPadGetValue(&vol_up_btn, &val)) && val == GpioValue_Low) {
bpcRebootSystem(); bpcRebootSystem();
} }
if (check_vol_down && R_SUCCEEDED((rc = gpioPadGetValue(&vol_down_btn, &val))) && val == GpioValue_Low) { if (check_vol_down && R_SUCCEEDED(gpioPadGetValue(&vol_down_btn, &val)) && val == GpioValue_Low) {
bpcRebootSystem(); bpcRebootSystem();
} }
if ((R_SUCCEEDED(rc = bpcGetSleepButtonState(&state)) && state == BpcSleepButtonState_Held) || (config->quest_flag && reboot_helper.TimedOut())) { if ((R_SUCCEEDED(bpcGetSleepButtonState(&state)) && state == BpcSleepButtonState_Held) || (config->quest_flag && reboot_helper.TimedOut())) {
bpcRebootSystem(); bpcRebootSystem();
return; return;
} }

View file

@ -145,9 +145,7 @@ Result ShowFatalTask::ShowFatal() {
/* Prepare screen for drawing. */ /* Prepare screen for drawing. */
DoWithSmSession([&]() { DoWithSmSession([&]() {
Result rc = PrepareScreenForDrawing(); if (R_FAILED(PrepareScreenForDrawing())) {
if (R_FAILED(rc)) {
*(volatile u32 *)(0xCAFEBABE) = rc;
std::abort(); std::abort();
} }
}); });

@ -1 +1 @@
Subproject commit 3274848b5612a9fa3a7306c7c4ca0a4b041c150c Subproject commit 7c9df9cfd8293c01934050ceafc1213622645fee

View file

@ -31,7 +31,7 @@ DATA := data
INCLUDES := include ../../common/include INCLUDES := include ../../common/include
EXEFS_SRC := exefs_src EXEFS_SRC := exefs_src
DEFINES := -DDISABLE_IPC -DATMOSPHERE_GIT_BRANCH=\"$(AMSBRANCH)\" -DATMOSPHERE_GIT_REV=\"$(AMSREV)\" DEFINES := -DRESULT_ABORT_ON_ASSERT -DATMOSPHERE_GIT_BRANCH=\"$(AMSBRANCH)\" -DATMOSPHERE_GIT_REV=\"$(AMSREV)\"
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# options for code generation # options for code generation

View file

@ -92,9 +92,7 @@ Result ContentManagement::MountCode(u64 tid, FsStorageId sid) {
/* Always re-initialize fsp-ldr, in case it's closed */ /* Always re-initialize fsp-ldr, in case it's closed */
DoWithSmSession([&]() { DoWithSmSession([&]() {
if (R_FAILED(fsldrInitialize())) { R_ASSERT(fsldrInitialize());
std::abort();
}
}); });
ON_SCOPE_EXIT { fsldrExit(); }; ON_SCOPE_EXIT { fsldrExit(); };

View file

@ -26,11 +26,13 @@ Result HidManagement::GetKeysHeld(u64 *keys) {
} }
if (!serviceIsActive(hidGetSessionService())) { if (!serviceIsActive(hidGetSessionService())) {
Result rc; bool initialized = false;
DoWithSmSession([&]() { DoWithSmSession([&]() {
rc = hidInitialize(); if (R_SUCCEEDED(hidInitialize())) {
initialized = true;
}
}); });
if (R_FAILED(rc)) { if (!initialized) {
return MAKERESULT(Module_Libnx, LibnxError_InitFail_HID); return MAKERESULT(Module_Libnx, LibnxError_InitFail_HID);
} }
} }

View file

@ -66,26 +66,13 @@ void __libnx_initheap(void) {
} }
void __appInit(void) { void __appInit(void) {
Result rc;
SetFirmwareVersionForLibnx(); SetFirmwareVersionForLibnx();
/* Initialize services we need (TODO: SPL) */ /* Initialize services we need (TODO: SPL) */
DoWithSmSession([&]() { DoWithSmSession([&]() {
rc = fsInitialize(); R_ASSERT(fsInitialize());
if (R_FAILED(rc)) { R_ASSERT(lrInitialize());
std::abort(); R_ASSERT(fsldrInitialize());
}
rc = lrInitialize();
if (R_FAILED(rc)) {
std::abort();
}
rc = fsldrInitialize();
if (R_FAILED(rc)) {
std::abort();
}
}); });

View file

@ -56,9 +56,7 @@ Result MapUtils::LocateSpaceForMapModern(u64 *out, u64 out_size) {
} }
cur_base = address_space.map_end; cur_base = address_space.map_end;
} else { } else {
if (R_FAILED(svcQueryMemory(&mem_info, &page_info, cur_base))) { R_ASSERT(svcQueryMemory(&mem_info, &page_info, cur_base));
std::abort();
}
if (mem_info.type == 0 && mem_info.addr - cur_base + mem_info.size >= out_size) { if (mem_info.type == 0 && mem_info.addr - cur_base + mem_info.size >= out_size) {
*out = cur_base; *out = cur_base;
return ResultSuccess; return ResultSuccess;

View file

@ -71,9 +71,7 @@ class AutoCloseMap {
void Close() { void Close() {
if (this->mapped_address) { if (this->mapped_address) {
if (R_FAILED(svcUnmapProcessMemory(this->mapped_address, this->process_handle, this->base_address, this->size))) { R_ASSERT(svcUnmapProcessMemory(this->mapped_address, this->process_handle, this->base_address, this->size));
std::abort();
}
this->mapped_address = NULL; this->mapped_address = NULL;
} }
} }

View file

@ -165,8 +165,9 @@ Result ProcessCreation::CreateProcess(Handle *out_process_h, u64 index, char *nc
} }
ON_SCOPE_EXIT { ON_SCOPE_EXIT {
if (mounted_code) { if (mounted_code) {
if (R_FAILED(ContentManagement::UnmountCode()) && target_process->tid_sid.storage_id != FsStorageId_None) { const Result unmount_res = ContentManagement::UnmountCode();
std::abort(); if (target_process->tid_sid.storage_id != FsStorageId_None) {
R_ASSERT(unmount_res);
} }
} }
}; };

View file

@ -139,8 +139,9 @@ void Registration::AssociatePidTidForMitM(u64 index) {
} }
Handle sm_hnd; Handle sm_hnd;
Result rc = svcConnectToNamedPort(&sm_hnd, "sm:"); if (R_SUCCEEDED(svcConnectToNamedPort(&sm_hnd, "sm:"))) {
if (R_SUCCEEDED(rc)) { ON_SCOPE_EXIT { svcCloseHandle(sm_hnd); };
/* Initialize. */ /* Initialize. */
{ {
IpcCommand c; IpcCommand c;
@ -158,9 +159,10 @@ void Registration::AssociatePidTidForMitM(u64 index) {
raw->cmd_id = 0; raw->cmd_id = 0;
raw->zero = 0; raw->zero = 0;
rc = ipcDispatch(sm_hnd); if (R_FAILED(ipcDispatch(sm_hnd))) {
return;
}
if (R_SUCCEEDED(rc)) {
IpcParsedCommand r; IpcParsedCommand r;
ipcParse(&r); ipcParse(&r);
@ -169,11 +171,13 @@ void Registration::AssociatePidTidForMitM(u64 index) {
u64 result; u64 result;
} *resp = (decltype(resp))r.Raw; } *resp = (decltype(resp))r.Raw;
rc = resp->result; if (R_FAILED(resp->result)) {
return;
} }
} }
/* Associate. */ /* Associate. */
if (R_SUCCEEDED(rc)) { {
IpcCommand c; IpcCommand c;
ipcInitialize(&c); ipcInitialize(&c);
struct { struct {
@ -190,6 +194,5 @@ void Registration::AssociatePidTidForMitM(u64 index) {
ipcDispatch(sm_hnd); ipcDispatch(sm_hnd);
} }
svcCloseHandle(sm_hnd);
} }
} }

View file

@ -31,7 +31,7 @@ DATA := data
INCLUDES := include ../../common/include INCLUDES := include ../../common/include
EXEFS_SRC := exefs_src EXEFS_SRC := exefs_src
DEFINES := -DDISABLE_IPC -DATMOSPHERE_GIT_BRANCH=\"$(AMSBRANCH)\" -DATMOSPHERE_GIT_REV=\"$(AMSREV)\" DEFINES := -DRESULT_ABORT_ON_ASSERT -DATMOSPHERE_GIT_BRANCH=\"$(AMSBRANCH)\" -DATMOSPHERE_GIT_REV=\"$(AMSREV)\"
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# options for code generation # options for code generation

View file

@ -60,32 +60,27 @@ static void LaunchTitle(u64 title_id, FsStorageId storage_id, u32 launch_flags,
return; return;
} }
Result rc = Registration::LaunchProcessByTidSid(Registration::TidSid{title_id, storage_id}, launch_flags, &local_pid); switch (Registration::LaunchProcessByTidSid(Registration::TidSid{title_id, storage_id}, launch_flags, &local_pid)) {
switch (rc) {
case ResultKernelResourceExhausted: case ResultKernelResourceExhausted:
/* Out of resource! */ /* Out of resource! */
std::abort(); std::abort();
break;
case ResultKernelOutOfMemory: case ResultKernelOutOfMemory:
/* Out of memory! */ /* Out of memory! */
std::abort(); std::abort();
break;
case ResultKernelLimitReached: case ResultKernelLimitReached:
/* Limit Reached! */ /* Limit Reached! */
std::abort(); std::abort();
break;
default: default:
/* We don't care about other issues. */ /* We don't care about other issues. */
break; break;
} }
if (pid) { if (pid) {
*pid = local_pid; *pid = local_pid;
} }
if (R_SUCCEEDED(rc)) {
SetLaunchedTitle(title_id); SetLaunchedTitle(title_id);
} }
}
static bool GetGpioPadLow(GpioPadName pad) { static bool GetGpioPadLow(GpioPadName pad) {
GpioPadSession button; GpioPadSession button;
@ -105,11 +100,10 @@ static bool GetGpioPadLow(GpioPadName pad) {
static bool IsMaintenanceMode() { static bool IsMaintenanceMode() {
/* Contact set:sys, retrieve boot!force_maintenance. */ /* Contact set:sys, retrieve boot!force_maintenance. */
Result rc;
DoWithSmSession([&]() { DoWithSmSession([&]() {
rc = setsysInitialize(); R_ASSERT(setsysInitialize());
}); });
if (R_SUCCEEDED(rc)) { {
ON_SCOPE_EXIT { setsysExit(); }; ON_SCOPE_EXIT { setsysExit(); };
u8 force_maintenance = 1; u8 force_maintenance = 1;
@ -121,9 +115,9 @@ static bool IsMaintenanceMode() {
/* Contact GPIO, read plus/minus buttons. */ /* Contact GPIO, read plus/minus buttons. */
DoWithSmSession([&]() { DoWithSmSession([&]() {
rc = gpioInitialize(); R_ASSERT(gpioInitialize());
}); });
if (R_SUCCEEDED(rc)) { {
ON_SCOPE_EXIT { gpioExit(); }; ON_SCOPE_EXIT { gpioExit(); };
return GetGpioPadLow(GpioPadName_ButtonVolUp) && GetGpioPadLow(GpioPadName_ButtonVolDown); return GetGpioPadLow(GpioPadName_ButtonVolUp) && GetGpioPadLow(GpioPadName_ButtonVolDown);
@ -179,12 +173,9 @@ static void MountSdCard() {
Handle tmp_hnd = 0; Handle tmp_hnd = 0;
static const char * const required_active_services[] = {"pcv", "gpio", "pinmux", "psc:c"}; static const char * const required_active_services[] = {"pcv", "gpio", "pinmux", "psc:c"};
for (unsigned int i = 0; i < sizeof(required_active_services) / sizeof(required_active_services[0]); i++) { for (unsigned int i = 0; i < sizeof(required_active_services) / sizeof(required_active_services[0]); i++) {
if (R_FAILED(smGetServiceOriginal(&tmp_hnd, smEncodeName(required_active_services[i])))) { R_ASSERT(smGetServiceOriginal(&tmp_hnd, smEncodeName(required_active_services[i])));
std::abort();
} else {
svcCloseHandle(tmp_hnd); svcCloseHandle(tmp_hnd);
} }
}
}); });
fsdevMountSdmc(); fsdevMountSdmc();
} }
@ -192,21 +183,17 @@ static void MountSdCard() {
static void WaitForMitm(const char *service) { static void WaitForMitm(const char *service) {
bool mitm_installed = false; bool mitm_installed = false;
Result rc;
DoWithSmSession([&]() { DoWithSmSession([&]() {
if (R_FAILED((rc = smManagerAmsInitialize()))) { R_ASSERT(smManagerAmsInitialize());
std::abort();
}
}); });
ON_SCOPE_EXIT { smManagerAmsExit(); };
while (R_FAILED((rc = smManagerAmsHasMitm(&mitm_installed, service))) || !mitm_installed) { while (!mitm_installed) {
if (R_FAILED(rc)) { R_ASSERT(smManagerAmsHasMitm(&mitm_installed, service));
std::abort(); if (!mitm_installed) {
}
svcSleepThread(1000000ull); svcSleepThread(1000000ull);
} }
}
smManagerAmsExit();
} }
void EmbeddedBoot2::Main() { void EmbeddedBoot2::Main() {

View file

@ -95,51 +95,26 @@ void RegisterPrivilegedProcessesWithFs() {
} }
void __appInit(void) { void __appInit(void) {
Result rc;
SetFirmwareVersionForLibnx(); SetFirmwareVersionForLibnx();
DoWithSmSession([&]() { DoWithSmSession([&]() {
rc = fsprInitialize(); R_ASSERT(fsprInitialize());
if (R_FAILED(rc)) {
std::abort();
}
/* This works around a bug with process permissions on < 4.0.0. */ /* This works around a bug with process permissions on < 4.0.0. */
RegisterPrivilegedProcessesWithFs(); RegisterPrivilegedProcessesWithFs();
rc = smManagerAmsInitialize(); /* Use AMS manager extension to tell SM that FS has been worked around. */
if (R_SUCCEEDED(rc)) { {
R_ASSERT(smManagerAmsInitialize());
smManagerAmsEndInitialDefers(); smManagerAmsEndInitialDefers();
smManagerAmsExit(); smManagerAmsExit();
} else {
std::abort();
} }
rc = smManagerInitialize(); R_ASSERT(smManagerInitialize());
if (R_FAILED(rc)) { R_ASSERT(lrInitialize());
std::abort(); R_ASSERT(ldrPmInitialize());
} R_ASSERT(splInitialize());
R_ASSERT(fsInitialize());
rc = lrInitialize();
if (R_FAILED(rc)) {
std::abort();
}
rc = ldrPmInitialize();
if (R_FAILED(rc)) {
std::abort();
}
rc = splInitialize();
if (R_FAILED(rc)) {
std::abort();
}
rc = fsInitialize();
if (R_FAILED(rc)) {
std::abort();
}
}); });
CheckAtmosphereVersion(CURRENT_ATMOSPHERE_VERSION); CheckAtmosphereVersion(CURRENT_ATMOSPHERE_VERSION);
@ -163,12 +138,8 @@ int main(int argc, char **argv)
/* Initialize and spawn the Process Tracking thread. */ /* Initialize and spawn the Process Tracking thread. */
Registration::InitializeSystemResources(); Registration::InitializeSystemResources();
if (R_FAILED(process_track_thread.Initialize(&ProcessTracking::MainLoop, NULL, 0x4000, 0x15))) { R_ASSERT(process_track_thread.Initialize(&ProcessTracking::MainLoop, NULL, 0x4000, 0x15));
std::abort(); R_ASSERT(process_track_thread.Start());
}
if (R_FAILED(process_track_thread.Start())) {
std::abort();
}
/* Create Server Manager. */ /* Create Server Manager. */
static auto s_server_manager = WaitableManager(1); static auto s_server_manager = WaitableManager(1);

View file

@ -100,9 +100,7 @@ Result Registration::LaunchProcess(u64 *out_pid, const TidSid tid_sid, const u64
}; };
/* Get the new process's id. */ /* Get the new process's id. */
if (R_FAILED(svcGetProcessId(&new_process.pid, new_process.handle))) { R_ASSERT(svcGetProcessId(&new_process.pid, new_process.handle));
std::abort();
}
/* Register with FS. */ /* Register with FS. */
memcpy(fac, program_info.ac_buffer + program_info.acid_sac_size + program_info.aci0_sac_size, program_info.acid_fac_size); memcpy(fac, program_info.ac_buffer + program_info.acid_sac_size + program_info.aci0_sac_size, program_info.acid_fac_size);
@ -283,18 +281,10 @@ void Registration::FinalizeExitedProcess(std::shared_ptr<Registration::Process>
signal_debug_process_5x = (GetRuntimeFirmwareVersion() >= FirmwareVersion_500) && process->flags & PROCESSFLAGS_NOTIFYWHENEXITED; signal_debug_process_5x = (GetRuntimeFirmwareVersion() >= FirmwareVersion_500) && process->flags & PROCESSFLAGS_NOTIFYWHENEXITED;
/* Unregister with FS. */ /* Unregister with FS, SM, and LDR. */
if (R_FAILED(fsprUnregisterProgram(process->pid))) { R_ASSERT(fsprUnregisterProgram(process->pid));
std::abort(); R_ASSERT(smManagerUnregisterProcess(process->pid));
} R_ASSERT(ldrPmUnregisterTitle(process->ldr_queue_index));
/* Unregister with SM. */
if (R_FAILED(smManagerUnregisterProcess(process->pid))) {
std::abort();
}
/* Unregister with LDR. */
if (R_FAILED(ldrPmUnregisterTitle(process->ldr_queue_index))) {
std::abort();
}
/* Close the process's handle. */ /* Close the process's handle. */
svcCloseHandle(process->handle); svcCloseHandle(process->handle);

View file

@ -105,14 +105,10 @@ void ResourceLimitUtils::InitializeLimits() {
/* Create Resource Limits. */ /* Create Resource Limits. */
for (unsigned int i = 0; i < 3; i++) { for (unsigned int i = 0; i < 3; i++) {
if (i > 0) { if (i > 0) {
if (R_FAILED(svcCreateResourceLimit(&g_resource_limit_handles[i]))) { R_ASSERT(svcCreateResourceLimit(&g_resource_limit_handles[i]));
std::abort();
}
} else { } else {
u64 out = 0; u64 out = 0;
if (R_FAILED(svcGetInfo(&out, 9, 0, 0))) { R_ASSERT(svcGetInfo(&out, 9, 0, 0));
std::abort();
}
g_resource_limit_handles[i] = (Handle)out; g_resource_limit_handles[i] = (Handle)out;
} }
} }
@ -144,15 +140,11 @@ void ResourceLimitUtils::InitializeLimits() {
/* Get total memory available. */ /* Get total memory available. */
u64 total_memory = 0; u64 total_memory = 0;
if (R_FAILED(svcGetResourceLimitLimitValue(&total_memory, g_resource_limit_handles[0], LimitableResource_Memory))) { R_ASSERT(svcGetResourceLimitLimitValue(&total_memory, g_resource_limit_handles[0], LimitableResource_Memory));
std::abort();
}
/* Get and save application + applet memory. */ /* Get and save application + applet memory. */
if (R_FAILED(svcGetSystemInfo(&g_memory_resource_limits[g_memory_limit_type][1], 0, 0, 0)) || R_ASSERT(svcGetSystemInfo(&g_memory_resource_limits[g_memory_limit_type][1], 0, 0, 0));
R_FAILED(svcGetSystemInfo(&g_memory_resource_limits[g_memory_limit_type][2], 0, 0, 1))) { R_ASSERT(svcGetSystemInfo(&g_memory_resource_limits[g_memory_limit_type][2], 0, 0, 1));
std::abort();
}
const u64 application_size = g_memory_resource_limits[g_memory_limit_type][1]; const u64 application_size = g_memory_resource_limits[g_memory_limit_type][1];
const u64 applet_size = g_memory_resource_limits[g_memory_limit_type][2]; const u64 applet_size = g_memory_resource_limits[g_memory_limit_type][2];
@ -168,9 +160,7 @@ void ResourceLimitUtils::InitializeLimits() {
} else { } else {
/* Get memory limits. */ /* Get memory limits. */
u64 memory_arrangement; u64 memory_arrangement;
if (R_FAILED(splGetConfig(SplConfigItem_MemoryArrange, &memory_arrangement))) { R_ASSERT(splGetConfig(SplConfigItem_MemoryArrange, &memory_arrangement));
std::abort();
}
memory_arrangement &= 0x3F; memory_arrangement &= 0x3F;
switch (memory_arrangement) { switch (memory_arrangement) {
case 2: case 2:
@ -205,9 +195,7 @@ void ResourceLimitUtils::InitializeLimits() {
/* Set resource limits. */ /* Set resource limits. */
for (unsigned int i = 0; i < 3; i++) { for (unsigned int i = 0; i < 3; i++) {
g_resource_limits[i][LimitableResource_Memory] = g_memory_resource_limits[g_memory_limit_type][i]; g_resource_limits[i][LimitableResource_Memory] = g_memory_resource_limits[g_memory_limit_type][i];
if (R_FAILED(SetResourceLimits((ResourceLimitCategory)i, g_memory_resource_limits[g_memory_limit_type][i]))) { R_ASSERT(SetResourceLimits((ResourceLimitCategory)i, g_memory_resource_limits[g_memory_limit_type][i]));
std::abort();
}
} }
} }
@ -225,9 +213,7 @@ void ResourceLimitUtils::EnsureApplicationResourcesAvailable() {
if (GetRuntimeFirmwareVersion() >= FirmwareVersion_500) { if (GetRuntimeFirmwareVersion() >= FirmwareVersion_500) {
u64 result; u64 result;
do { do {
if (R_FAILED(svcGetSystemInfo(&result, 1, 0, 0))) { R_ASSERT(svcGetSystemInfo(&result, 1, 0, 0));
std::abort();
}
svcSleepThread(1000000ULL); svcSleepThread(1000000ULL);
} while (result); } while (result);
} }

View file

@ -120,7 +120,8 @@ void ShellService::GetBootFinishedEvent(Out<CopiedHandle> event) {
/* We will signal it always, but only allow this function to succeed on safe mode. */ /* We will signal it always, but only allow this function to succeed on safe mode. */
{ {
u64 is_recovery_boot = 0; u64 is_recovery_boot = 0;
if (R_FAILED(SmcGetConfig(SplConfigItem_IsRecoveryBoot, &is_recovery_boot)) || !is_recovery_boot) { R_ASSERT(SmcGetConfig(SplConfigItem_IsRecoveryBoot, &is_recovery_boot));
if (!is_recovery_boot) {
std::abort(); std::abort();
} }
} }

View file

@ -31,7 +31,7 @@ DATA := data
INCLUDES := include ../../common/include INCLUDES := include ../../common/include
EXEFS_SRC := exefs_src EXEFS_SRC := exefs_src
DEFINES := -DDISABLE_IPC -DATMOSPHERE_GIT_BRANCH=\"$(AMSBRANCH)\" -DATMOSPHERE_GIT_REV=\"$(AMSREV)\" -DINI_MAX_LINE=768 DEFINES := -DATMOSPHERE_GIT_BRANCH=\"$(AMSBRANCH)\" -DATMOSPHERE_GIT_REV=\"$(AMSREV)\" -DINI_MAX_LINE=768
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# options for code generation # options for code generation

View file

@ -61,34 +61,18 @@ void __libnx_initheap(void) {
} }
void __appInit(void) { void __appInit(void) {
Result rc;
SetFirmwareVersionForLibnx(); SetFirmwareVersionForLibnx();
DoWithSmSession([&]() { DoWithSmSession([&]() {
rc = setsysInitialize(); R_ASSERT(setsysInitialize());
if (R_FAILED(rc)) { R_ASSERT(fsInitialize());
std::abort();
}
rc = fsInitialize();
if (R_FAILED(rc)) {
std::abort();
}
if (GetRuntimeFirmwareVersion() < FirmwareVersion_300) { if (GetRuntimeFirmwareVersion() < FirmwareVersion_300) {
rc = pminfoInitialize(); R_ASSERT(pminfoInitialize());
if (R_FAILED(rc)) {
std::abort();
}
}
rc = fsdevMountSdmc();
if (R_FAILED(rc)) {
std::abort();
} }
}); });
R_ASSERT(fsdevMountSdmc());
CheckAtmosphereVersion(CURRENT_ATMOSPHERE_VERSION); CheckAtmosphereVersion(CURRENT_ATMOSPHERE_VERSION);
} }

View file

@ -25,13 +25,9 @@ bool MapUtils::CanAddGuardRegions(Handle process_handle, u64 address, u64 size)
/* Nintendo doesn't validate SVC return values at all. */ /* Nintendo doesn't validate SVC return values at all. */
/* TODO: Should we allow these to fail? */ /* TODO: Should we allow these to fail? */
if (R_FAILED(svcQueryProcessMemory(&mem_info, &page_info, process_handle, address - 1))) { R_ASSERT(svcQueryProcessMemory(&mem_info, &page_info, process_handle, address - 1));
std::abort();
}
if (mem_info.type == MemType_Unmapped && address - GuardRegionSize >= mem_info.addr) { if (mem_info.type == MemType_Unmapped && address - GuardRegionSize >= mem_info.addr) {
if (R_FAILED(svcQueryProcessMemory(&mem_info, &page_info, process_handle, address + size))) { R_ASSERT(svcQueryProcessMemory(&mem_info, &page_info, process_handle, address + size));
std::abort();
}
return mem_info.type == MemType_Unmapped && address + size + GuardRegionSize <= mem_info.addr + mem_info.size; return mem_info.type == MemType_Unmapped && address + size + GuardRegionSize <= mem_info.addr + mem_info.size;
} }
@ -50,11 +46,10 @@ Result MapUtils::MapCodeMemoryForProcess(MappedCodeMemory &out_mcm, Handle proce
if (GetRuntimeFirmwareVersion() >= FirmwareVersion_200) { if (GetRuntimeFirmwareVersion() >= FirmwareVersion_200) {
return MapCodeMemoryForProcessModern(out_mcm, process_handle, base_address, size); return MapCodeMemoryForProcessModern(out_mcm, process_handle, base_address, size);
} else { } else {
Result rc = MapCodeMemoryForProcessDeprecated(out_mcm, process_handle, true, base_address, size); if (R_FAILED(MapCodeMemoryForProcessDeprecated(out_mcm, process_handle, true, base_address, size))) {
if (R_FAILED(rc)) { R_TRY(MapCodeMemoryForProcessDeprecated(out_mcm, process_handle, false, base_address, size));
rc = MapCodeMemoryForProcessDeprecated(out_mcm, process_handle, false, base_address, size);
} }
return rc; return ResultSuccess;
} }
} }
@ -87,9 +82,7 @@ Result MapUtils::LocateSpaceForMapModern(u64 *out, u64 out_size) {
} }
cur_base = address_space.map_end; cur_base = address_space.map_end;
} else { } else {
if (R_FAILED(svcQueryMemory(&mem_info, &page_info, cur_base))) { R_ASSERT(svcQueryMemory(&mem_info, &page_info, cur_base));
std::abort();
}
if (mem_info.type == 0 && mem_info.addr - cur_base + mem_info.size >= out_size) { if (mem_info.type == 0 && mem_info.addr - cur_base + mem_info.size >= out_size) {
*out = cur_base; *out = cur_base;
return ResultSuccess; return ResultSuccess;

View file

@ -36,9 +36,7 @@ class MappedCodeMemory {
~MappedCodeMemory() { ~MappedCodeMemory() {
if (this->process_handle != INVALID_HANDLE && this->size > 0 && R_SUCCEEDED(this->result)) { if (this->process_handle != INVALID_HANDLE && this->size > 0 && R_SUCCEEDED(this->result)) {
if (R_FAILED((this->result = svcUnmapProcessCodeMemory(this->process_handle, this->dst_address, this->src_address, this->size)))) { R_ASSERT((this->result = svcUnmapProcessCodeMemory(this->process_handle, this->dst_address, this->src_address, this->size)));
std::abort();
}
} }
} }
@ -86,9 +84,7 @@ class AutoCloseMap {
~AutoCloseMap() { ~AutoCloseMap() {
if (this->process_handle != INVALID_HANDLE && R_SUCCEEDED(this->result)) { if (this->process_handle != INVALID_HANDLE && R_SUCCEEDED(this->result)) {
if (R_FAILED((this->result = svcUnmapProcessMemory(this->mapped_address, this->process_handle, this->base_address, this->size)))) { R_ASSERT((this->result = svcUnmapProcessMemory(this->mapped_address, this->process_handle, this->base_address, this->size)));
std::abort();
}
} }
} }

View file

@ -31,21 +31,15 @@ static bool g_is_development_hardware, g_is_development_function_enabled;
void Registration::Initialize() { void Registration::Initialize() {
DoWithSmSession([&]() { DoWithSmSession([&]() {
if (R_FAILED(splInitialize())) { R_ASSERT(splInitialize());
std::abort();
}
}); });
ON_SCOPE_EXIT { splExit(); }; ON_SCOPE_EXIT { splExit(); };
if (R_FAILED(splIsDevelopment(&g_is_development_hardware))) { R_ASSERT(splIsDevelopment(&g_is_development_hardware));
std::abort();
}
{ {
u64 out_val = 0; u64 out_val = 0;
if (R_FAILED(splGetConfig(SplConfigItem_IsDebugMode, &out_val))) { R_ASSERT(splGetConfig(SplConfigItem_IsDebugMode, &out_val));
std::abort();
}
g_is_development_function_enabled = out_val != 0; g_is_development_function_enabled = out_val != 0;
} }
} }

View file

@ -41,18 +41,12 @@ u64 RelocatableObjectsService::GetTitleId(Handle process_handle) {
u64 title_id = 0; u64 title_id = 0;
if (GetRuntimeFirmwareVersion() >= FirmwareVersion_300) { if (GetRuntimeFirmwareVersion() >= FirmwareVersion_300) {
/* 3.0.0+: Use svcGetInfo. */ /* 3.0.0+: Use svcGetInfo. */
if (R_FAILED(svcGetInfo(&title_id, 18, process_handle, 0))) { R_ASSERT(svcGetInfo(&title_id, 18, process_handle, 0));
std::abort();
}
} else { } else {
/* 1.0.0-2.3.0: We're not inside loader, so ask pm. */ /* 1.0.0-2.3.0: We're not inside loader, so ask pm. */
u64 process_id = 0; u64 process_id = 0;
if (R_FAILED(svcGetProcessId(&process_id, process_handle))) { R_ASSERT(svcGetProcessId(&process_id, process_handle));
std::abort(); R_ASSERT(pminfoGetTitleId(&title_id, process_id));
}
if (R_FAILED(pminfoGetTitleId(&title_id, process_id))) {
std::abort();
}
} }
return title_id; return title_id;
} }

View file

@ -31,7 +31,7 @@ DATA := data
INCLUDES := include ../../common/include INCLUDES := include ../../common/include
EXEFS_SRC := exefs_src EXEFS_SRC := exefs_src
DEFINES := -DDISABLE_IPC -DATMOSPHERE_GIT_BRANCH=\"$(AMSBRANCH)\" -DATMOSPHERE_GIT_REV=\"$(AMSREV)\" DEFINES := -DRESULT_ABORT_ON_ASSERT -DATMOSPHERE_GIT_BRANCH=\"$(AMSBRANCH)\" -DATMOSPHERE_GIT_REV=\"$(AMSREV)\"
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# options for code generation # options for code generation

View file

@ -90,18 +90,14 @@ int main(int argc, char **argv)
/* Create sm:m manually. */ /* Create sm:m manually. */
Handle smm_h; Handle smm_h;
if (R_FAILED(Registration::RegisterServiceForSelf(smEncodeName("sm:m"), 1, false, &smm_h))) { R_ASSERT(Registration::RegisterServiceForSelf(smEncodeName("sm:m"), 1, false, &smm_h));
std::abort();
}
server_manager->AddWaitable(new ExistingPortServer<ManagerService>(smm_h, 1)); server_manager->AddWaitable(new ExistingPortServer<ManagerService>(smm_h, 1));
/*===== ATMOSPHERE EXTENSION =====*/ /*===== ATMOSPHERE EXTENSION =====*/
/* Create sm:dmnt manually. */ /* Create sm:dmnt manually. */
Handle smdmnt_h; Handle smdmnt_h;
if (R_FAILED(Registration::RegisterServiceForSelf(smEncodeName("sm:dmnt"), 1, false, &smdmnt_h))) { R_ASSERT(Registration::RegisterServiceForSelf(smEncodeName("sm:dmnt"), 1, false, &smdmnt_h));
std::abort();
}
server_manager->AddWaitable(new ExistingPortServer<DmntService>(smm_h, 1));; server_manager->AddWaitable(new ExistingPortServer<DmntService>(smm_h, 1));;
/*================================*/ /*================================*/

View file

@ -31,7 +31,7 @@ DATA := data
INCLUDES := include ../../common/include INCLUDES := include ../../common/include
EXEFS_SRC := exefs_src EXEFS_SRC := exefs_src
DEFINES := -DDISABLE_IPC -DATMOSPHERE_GIT_BRANCH=\"$(AMSBRANCH)\" -DATMOSPHERE_GIT_REV=\"$(AMSREV)\" DEFINES := -DRESULT_ABORT_ON_ASSERT -DATMOSPHERE_GIT_BRANCH=\"$(AMSBRANCH)\" -DATMOSPHERE_GIT_REV=\"$(AMSREV)\"
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# options for code generation # options for code generation

View file

@ -54,14 +54,10 @@ class DeviceAddressSpaceMapHelper {
u32 perm; u32 perm;
public: public:
DeviceAddressSpaceMapHelper(Handle h, u64 dst, u64 src, size_t sz, u32 p) : das_hnd(h), dst_addr(dst), src_addr(src), size(sz), perm(p) { DeviceAddressSpaceMapHelper(Handle h, u64 dst, u64 src, size_t sz, u32 p) : das_hnd(h), dst_addr(dst), src_addr(src), size(sz), perm(p) {
if (R_FAILED(svcMapDeviceAddressSpaceAligned(this->das_hnd, CUR_PROCESS_HANDLE, this->src_addr, this->size, this->dst_addr, this->perm))) { R_ASSERT(svcMapDeviceAddressSpaceAligned(this->das_hnd, CUR_PROCESS_HANDLE, this->src_addr, this->size, this->dst_addr, this->perm));
std::abort();
}
} }
~DeviceAddressSpaceMapHelper() { ~DeviceAddressSpaceMapHelper() {
if (R_FAILED(svcUnmapDeviceAddressSpace(this->das_hnd, CUR_PROCESS_HANDLE, this->src_addr, this->size, this->dst_addr))) { R_ASSERT(svcUnmapDeviceAddressSpace(this->das_hnd, CUR_PROCESS_HANDLE, this->src_addr, this->size, this->dst_addr));
std::abort();
}
} }
}; };
@ -91,9 +87,7 @@ void SecureMonitorWrapper::InitializeSeEvents() {
u64 irq_num; u64 irq_num;
SmcWrapper::GetConfig(&irq_num, 1, SplConfigItem_SecurityEngineIrqNumber); SmcWrapper::GetConfig(&irq_num, 1, SplConfigItem_SecurityEngineIrqNumber);
Handle hnd; Handle hnd;
if (R_FAILED(svcCreateInterruptEvent(&hnd, irq_num, 1))) { R_ASSERT(svcCreateInterruptEvent(&hnd, irq_num, 1));
std::abort();
}
eventLoadRemote(&g_se_event, hnd, true); eventLoadRemote(&g_se_event, hnd, true);
g_se_keyslot_available_event = CreateWriteOnlySystemEvent(); g_se_keyslot_available_event = CreateWriteOnlySystemEvent();
@ -104,21 +98,16 @@ void SecureMonitorWrapper::InitializeDeviceAddressSpace() {
constexpr u64 DeviceName_SE = 29; constexpr u64 DeviceName_SE = 29;
/* Create Address Space. */ /* Create Address Space. */
if (R_FAILED(svcCreateDeviceAddressSpace(&g_se_das_hnd, 0, (1ul << 32)))) { R_ASSERT(svcCreateDeviceAddressSpace(&g_se_das_hnd, 0, (1ul << 32)));
std::abort();
}
/* Attach it to the SE. */ /* Attach it to the SE. */
if (R_FAILED(svcAttachDeviceAddressSpace(DeviceName_SE, g_se_das_hnd))) { R_ASSERT(svcAttachDeviceAddressSpace(DeviceName_SE, g_se_das_hnd));
std::abort();
}
const u64 work_buffer_addr = reinterpret_cast<u64>(g_work_buffer); const u64 work_buffer_addr = reinterpret_cast<u64>(g_work_buffer);
g_se_mapped_work_buffer_addr = WorkBufferMapBase + (work_buffer_addr & DeviceAddressSpaceAlignMask); g_se_mapped_work_buffer_addr = WorkBufferMapBase + (work_buffer_addr & DeviceAddressSpaceAlignMask);
/* Map the work buffer for the SE. */ /* Map the work buffer for the SE. */
if (R_FAILED(svcMapDeviceAddressSpaceAligned(g_se_das_hnd, CUR_PROCESS_HANDLE, work_buffer_addr, sizeof(g_work_buffer), g_se_mapped_work_buffer_addr, 3))) { R_ASSERT(svcMapDeviceAddressSpaceAligned(g_se_das_hnd, CUR_PROCESS_HANDLE, work_buffer_addr, sizeof(g_work_buffer), g_se_mapped_work_buffer_addr, 3));
std::abort();
}
} }
void SecureMonitorWrapper::Initialize() { void SecureMonitorWrapper::Initialize() {