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
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

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 rc;
if (dst == nullptr || dst_size == 0 || cmd == nullptr || cmd_size == 0) {
std::abort();
}
@ -44,12 +43,8 @@ Result Boot::ReadI2cRegister(I2cSessionImpl &session, u8 *dst, size_t dst_size,
u8 cmd_list[I2cCommandListFormatter::MaxCommandListSize];
I2cCommandListFormatter formatter(cmd_list, sizeof(cmd_list));
if (R_FAILED((rc = formatter.EnqueueSendCommand(I2cTransactionOption_Start, cmd, cmd_size)))) {
std::abort();
}
if (R_FAILED((rc = formatter.EnqueueReceiveCommand(static_cast<I2cTransactionOption>(I2cTransactionOption_Start | I2cTransactionOption_Stop), dst_size)))) {
std::abort();
}
R_ASSERT(formatter.EnqueueSendCommand(I2cTransactionOption_Start, cmd, cmd_size));
R_ASSERT(formatter.EnqueueReceiveCommand(static_cast<I2cTransactionOption>(I2cTransactionOption_Start | I2cTransactionOption_Stop), dst_size));
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) {
Result rc;
SetFirmwareVersionForLibnx();
/* Initialize services we need (TODO: NCM) */
DoWithSmSession([&]() {
rc = fsInitialize();
if (R_FAILED(rc)) {
std::abort();
}
rc = splInitialize();
if (R_FAILED(rc)) {
std::abort();
}
rc = pmshellInitialize();
if (R_FAILED(rc)) {
std::abort();
}
R_ASSERT(fsInitialize());
R_ASSERT(splInitialize());
R_ASSERT(pmshellInitialize());
});
CheckAtmosphereVersion(CURRENT_ATMOSPHERE_VERSION);

View file

@ -23,8 +23,7 @@ void Boot::CheckAndRepairBootImages() {
const BootImageUpdateType boot_image_update_type = Updater::GetBootImageUpdateType(Boot::GetHardwareType());
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(rc) && repaired_normal) {
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) {
/* Nintendo only performs a reboot on successful normal repair. */
Boot::RebootSystem();
}

View file

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

View file

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

View file

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

View file

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

View file

@ -31,7 +31,7 @@ DATA := data
INCLUDES := include ../../common/include
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

View file

@ -72,83 +72,30 @@ void __libnx_initheap(void) {
}
void __appInit(void) {
Result rc;
SetFirmwareVersionForLibnx();
DoWithSmSession([&]() {
rc = setInitialize();
if (R_FAILED(rc)) {
std::abort();
}
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();
}
R_ASSERT(setInitialize());
R_ASSERT(setsysInitialize());
R_ASSERT(pminfoInitialize());
R_ASSERT(i2cInitialize());
R_ASSERT(bpcInitialize());
if (GetRuntimeFirmwareVersion() >= FirmwareVersion_800) {
rc = clkrstInitialize();
if (R_FAILED(rc)) {
std::abort();
}
R_ASSERT(clkrstInitialize());
} else {
rc = pcvInitialize();
if (R_FAILED(rc)) {
std::abort();
}
R_ASSERT(pcvInitialize());
}
rc = lblInitialize();
if (R_FAILED(rc)) {
std::abort();
}
rc = psmInitialize();
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();
}
R_ASSERT(lblInitialize());
R_ASSERT(psmInitialize());
R_ASSERT(spsmInitialize());
R_ASSERT(plInitialize());
R_ASSERT(gpioInitialize());
R_ASSERT(fsInitialize());
});
rc = fsdevMountSdmc();
if (R_FAILED(rc)) {
std::abort();
}
R_ASSERT(fsdevMountSdmc());
/* 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) {
IFatalTask *task = reinterpret_cast<IFatalTask *>(arg);
Result rc = task->Run();
if (R_FAILED(rc)) {
if (R_FAILED(task->Run())) {
/* TODO: Log task failure, somehow? */
}

View file

@ -122,22 +122,20 @@ void PowerButtonObserveTask::WaitForPowerButton() {
BpcSleepButtonState state;
GpioValue val;
while (true) {
Result rc = ResultSuccess;
if (config->is_auto_reboot_enabled && auto_reboot_helper.TimedOut() ) {
bpcRebootSystem();
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();
}
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();
}
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();
return;
}

View file

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

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

View file

@ -31,7 +31,7 @@ DATA := data
INCLUDES := include ../../common/include
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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -165,8 +165,9 @@ Result ProcessCreation::CreateProcess(Handle *out_process_h, u64 index, char *nc
}
ON_SCOPE_EXIT {
if (mounted_code) {
if (R_FAILED(ContentManagement::UnmountCode()) && target_process->tid_sid.storage_id != FsStorageId_None) {
std::abort();
const Result unmount_res = ContentManagement::UnmountCode();
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;
Result rc = svcConnectToNamedPort(&sm_hnd, "sm:");
if (R_SUCCEEDED(rc)) {
if (R_SUCCEEDED(svcConnectToNamedPort(&sm_hnd, "sm:"))) {
ON_SCOPE_EXIT { svcCloseHandle(sm_hnd); };
/* Initialize. */
{
IpcCommand c;
@ -158,9 +159,10 @@ void Registration::AssociatePidTidForMitM(u64 index) {
raw->cmd_id = 0;
raw->zero = 0;
rc = ipcDispatch(sm_hnd);
if (R_FAILED(ipcDispatch(sm_hnd))) {
return;
}
if (R_SUCCEEDED(rc)) {
IpcParsedCommand r;
ipcParse(&r);
@ -169,11 +171,13 @@ void Registration::AssociatePidTidForMitM(u64 index) {
u64 result;
} *resp = (decltype(resp))r.Raw;
rc = resp->result;
if (R_FAILED(resp->result)) {
return;
}
}
/* Associate. */
if (R_SUCCEEDED(rc)) {
{
IpcCommand c;
ipcInitialize(&c);
struct {
@ -190,6 +194,5 @@ void Registration::AssociatePidTidForMitM(u64 index) {
ipcDispatch(sm_hnd);
}
svcCloseHandle(sm_hnd);
}
}

View file

@ -31,7 +31,7 @@ DATA := data
INCLUDES := include ../../common/include
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

View file

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

View file

@ -95,51 +95,26 @@ void RegisterPrivilegedProcessesWithFs() {
}
void __appInit(void) {
Result rc;
SetFirmwareVersionForLibnx();
DoWithSmSession([&]() {
rc = fsprInitialize();
if (R_FAILED(rc)) {
std::abort();
}
R_ASSERT(fsprInitialize());
/* This works around a bug with process permissions on < 4.0.0. */
RegisterPrivilegedProcessesWithFs();
rc = smManagerAmsInitialize();
if (R_SUCCEEDED(rc)) {
/* Use AMS manager extension to tell SM that FS has been worked around. */
{
R_ASSERT(smManagerAmsInitialize());
smManagerAmsEndInitialDefers();
smManagerAmsExit();
} else {
std::abort();
}
rc = smManagerInitialize();
if (R_FAILED(rc)) {
std::abort();
}
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();
}
R_ASSERT(smManagerInitialize());
R_ASSERT(lrInitialize());
R_ASSERT(ldrPmInitialize());
R_ASSERT(splInitialize());
R_ASSERT(fsInitialize());
});
CheckAtmosphereVersion(CURRENT_ATMOSPHERE_VERSION);
@ -163,12 +138,8 @@ int main(int argc, char **argv)
/* Initialize and spawn the Process Tracking thread. */
Registration::InitializeSystemResources();
if (R_FAILED(process_track_thread.Initialize(&ProcessTracking::MainLoop, NULL, 0x4000, 0x15))) {
std::abort();
}
if (R_FAILED(process_track_thread.Start())) {
std::abort();
}
R_ASSERT(process_track_thread.Initialize(&ProcessTracking::MainLoop, NULL, 0x4000, 0x15));
R_ASSERT(process_track_thread.Start());
/* Create Server Manager. */
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. */
if (R_FAILED(svcGetProcessId(&new_process.pid, new_process.handle))) {
std::abort();
}
R_ASSERT(svcGetProcessId(&new_process.pid, new_process.handle));
/* Register with FS. */
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;
/* Unregister with FS. */
if (R_FAILED(fsprUnregisterProgram(process->pid))) {
std::abort();
}
/* Unregister with SM. */
if (R_FAILED(smManagerUnregisterProcess(process->pid))) {
std::abort();
}
/* Unregister with LDR. */
if (R_FAILED(ldrPmUnregisterTitle(process->ldr_queue_index))) {
std::abort();
}
/* Unregister with FS, SM, and LDR. */
R_ASSERT(fsprUnregisterProgram(process->pid));
R_ASSERT(smManagerUnregisterProcess(process->pid));
R_ASSERT(ldrPmUnregisterTitle(process->ldr_queue_index));
/* Close the process's handle. */
svcCloseHandle(process->handle);

View file

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

View file

@ -31,7 +31,7 @@ DATA := data
INCLUDES := include ../../common/include
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

View file

@ -61,34 +61,18 @@ void __libnx_initheap(void) {
}
void __appInit(void) {
Result rc;
SetFirmwareVersionForLibnx();
DoWithSmSession([&]() {
rc = setsysInitialize();
if (R_FAILED(rc)) {
std::abort();
}
rc = fsInitialize();
if (R_FAILED(rc)) {
std::abort();
}
R_ASSERT(setsysInitialize());
R_ASSERT(fsInitialize());
if (GetRuntimeFirmwareVersion() < FirmwareVersion_300) {
rc = pminfoInitialize();
if (R_FAILED(rc)) {
std::abort();
}
}
rc = fsdevMountSdmc();
if (R_FAILED(rc)) {
std::abort();
R_ASSERT(pminfoInitialize());
}
});
R_ASSERT(fsdevMountSdmc());
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. */
/* TODO: Should we allow these to fail? */
if (R_FAILED(svcQueryProcessMemory(&mem_info, &page_info, process_handle, address - 1))) {
std::abort();
}
R_ASSERT(svcQueryProcessMemory(&mem_info, &page_info, process_handle, address - 1));
if (mem_info.type == MemType_Unmapped && address - GuardRegionSize >= mem_info.addr) {
if (R_FAILED(svcQueryProcessMemory(&mem_info, &page_info, process_handle, address + size))) {
std::abort();
}
R_ASSERT(svcQueryProcessMemory(&mem_info, &page_info, process_handle, address + 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) {
return MapCodeMemoryForProcessModern(out_mcm, process_handle, base_address, size);
} else {
Result rc = MapCodeMemoryForProcessDeprecated(out_mcm, process_handle, true, base_address, size);
if (R_FAILED(rc)) {
rc = MapCodeMemoryForProcessDeprecated(out_mcm, process_handle, false, base_address, size);
if (R_FAILED(MapCodeMemoryForProcessDeprecated(out_mcm, process_handle, true, base_address, size))) {
R_TRY(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;
} else {
if (R_FAILED(svcQueryMemory(&mem_info, &page_info, cur_base))) {
std::abort();
}
R_ASSERT(svcQueryMemory(&mem_info, &page_info, cur_base));
if (mem_info.type == 0 && mem_info.addr - cur_base + mem_info.size >= out_size) {
*out = cur_base;
return ResultSuccess;

View file

@ -36,9 +36,7 @@ class MappedCodeMemory {
~MappedCodeMemory() {
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)))) {
std::abort();
}
R_ASSERT((this->result = svcUnmapProcessCodeMemory(this->process_handle, this->dst_address, this->src_address, this->size)));
}
}
@ -86,9 +84,7 @@ class AutoCloseMap {
~AutoCloseMap() {
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)))) {
std::abort();
}
R_ASSERT((this->result = svcUnmapProcessMemory(this->mapped_address, this->process_handle, this->base_address, this->size)));
}
}

View file

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

View file

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

View file

@ -31,7 +31,7 @@ DATA := data
INCLUDES := include ../../common/include
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

View file

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

View file

@ -31,7 +31,7 @@ DATA := data
INCLUDES := include ../../common/include
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

View file

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