mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-06-05 01:03:43 -04:00
stratosphere: more result cleanup
This commit is contained in:
parent
7b6050a0cb
commit
cead8a36ea
38 changed files with 158 additions and 448 deletions
|
@ -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
|
||||
|
|
|
@ -60,31 +60,26 @@ 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);
|
||||
}
|
||||
SetLaunchedTitle(title_id);
|
||||
}
|
||||
|
||||
static bool GetGpioPadLow(GpioPadName pad) {
|
||||
|
@ -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,11 +173,8 @@ 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 {
|
||||
svcCloseHandle(tmp_hnd);
|
||||
}
|
||||
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);
|
||||
}
|
||||
svcSleepThread(1000000ull);
|
||||
}
|
||||
|
||||
smManagerAmsExit();
|
||||
}
|
||||
|
||||
void EmbeddedBoot2::Main() {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue