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

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

@ -13,7 +13,7 @@
* 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 <switch.h>
#include <cstdio>
#include <algorithm>
@ -33,7 +33,7 @@ bool RelocatableObjectsService::IsProcessIdValid(u64 process_id) {
if (!this->IsInitialized()) {
return false;
}
return this->context->process_id == process_id;
}
@ -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;
}
@ -61,7 +55,7 @@ Result RelocatableObjectsService::LoadNro(Out<u64> load_address, PidDescriptor p
if (!this->IsProcessIdValid(pid_desc.pid)) {
return ResultRoInvalidProcess;
}
return Registration::LoadNro(load_address.GetPointer(), this->context, nro_address, nro_size, bss_address, bss_size);
}
@ -69,7 +63,7 @@ Result RelocatableObjectsService::UnloadNro(PidDescriptor pid_desc, u64 nro_addr
if (!this->IsProcessIdValid(pid_desc.pid)) {
return ResultRoInvalidProcess;
}
return Registration::UnloadNro(this->context, nro_address);
}