strat: replace kernel/dbg magic numbers with result defs

This commit is contained in:
Michael Scire 2019-03-28 16:57:18 -07:00
parent 285feba42b
commit acffae6643
13 changed files with 52 additions and 33 deletions

View file

@ -142,7 +142,9 @@ Result LayeredRomFS::Read(void *buffer, size_t size, u64 offset) {
}
break;
default:
fatalSimple(0xF601);
/* TODO: Better error. */
fatalSimple(ResultKernelConnectionClosed);
break;
}
read_so_far += cur_read_size;
offset += cur_read_size;

View file

@ -43,7 +43,7 @@ void RomFSBuildContext::VisitDirectory(FsFileSystem *filesys, RomFSBuildDirector
child->path = new char[child->path_len + 1];
strcpy(child->path, parent->path);
if (child->path_len > FS_MAX_PATH - 1) {
fatalSimple(0xF601);
fatalSimple(ResultFsTooLongPath);
}
strcat(child->path + parent->path_len, "/");
strcat(child->path + parent->path_len, this->dir_entry.name);
@ -62,7 +62,7 @@ void RomFSBuildContext::VisitDirectory(FsFileSystem *filesys, RomFSBuildDirector
child->path = new char[child->path_len + 1];
strcpy(child->path, parent->path);
if (child->path_len > FS_MAX_PATH - 1) {
fatalSimple(0xF601);
fatalSimple(ResultFsTooLongPath);
}
strcat(child->path + parent->path_len, "/");
strcat(child->path + parent->path_len, this->dir_entry.name);
@ -116,7 +116,7 @@ void RomFSBuildContext::VisitDirectory(RomFSBuildDirectoryContext *parent, u32 p
child->path = new char[child->path_len + 1];
strcpy(child->path, parent->path);
if (child->path_len > FS_MAX_PATH - 1) {
fatalSimple(0xF601);
fatalSimple(ResultFsTooLongPath);
}
strcat(child->path + parent->path_len, "/");
strncat(child->path + parent->path_len, cur_file->name, cur_file->name_size);
@ -146,7 +146,7 @@ void RomFSBuildContext::VisitDirectory(RomFSBuildDirectoryContext *parent, u32 p
child->path = new char[child->path_len + 1];
strcpy(child->path, parent->path);
if (child->path_len > FS_MAX_PATH - 1) {
fatalSimple(0xF601);
fatalSimple(ResultFsTooLongPath);
}
strcat(child->path + parent->path_len, "/");
strncat(child->path + parent->path_len, cur_child->name, cur_child->name_size);
@ -157,7 +157,8 @@ void RomFSBuildContext::VisitDirectory(RomFSBuildDirectoryContext *parent, u32 p
delete child;
}
if (real == NULL) {
fatalSimple(0xF601);
/* TODO: Better error. */
fatalSimple(ResultKernelConnectionClosed);
}
this->VisitDirectory(real, cur_child_offset, dir_table, dir_table_size, file_table, file_table_size);
@ -278,7 +279,8 @@ void RomFSBuildContext::Build(std::vector<RomFSSourceInfo> *out_infos) {
if (expected != cur_file->orig_offset) {
if (expected > cur_file->orig_offset) {
/* This case should NEVER happen. */
fatalSimple(0xF601);
/* TODO: Better error. */
fatalSimple(ResultKernelConnectionClosed);
}
this->file_partition_size += cur_file->orig_offset - expected;
}
@ -348,7 +350,9 @@ void RomFSBuildContext::Build(std::vector<RomFSSourceInfo> *out_infos) {
}
break;
default:
fatalSimple(0xF601);
/* TODO: Better error. */
fatalSimple(ResultKernelConnectionClosed);
break;
}
}

View file

@ -81,7 +81,9 @@ struct RomFSSourceInfo {
case RomFSDataSource::MetaData:
case RomFSDataSource::Memory:
default:
fatalSimple(0xF601);
/* TODO: Better error. */
fatalSimple(ResultKernelConnectionClosed);
break;
}
}
@ -97,7 +99,9 @@ struct RomFSSourceInfo {
case RomFSDataSource::BaseRomFS:
case RomFSDataSource::FileRomFS:
default:
fatalSimple(0xF601);
/* TODO: Better error. */
fatalSimple(ResultKernelConnectionClosed);
break;
}
}
@ -110,7 +114,9 @@ struct RomFSSourceInfo {
case RomFSDataSource::BaseRomFS:
case RomFSDataSource::FileRomFS:
default:
fatalSimple(0xF601);
/* TODO: Better error. */
fatalSimple(ResultKernelConnectionClosed);
break;
}
}
@ -127,7 +133,9 @@ struct RomFSSourceInfo {
std::free((void*)this->memory_source_info.data);
break;
default:
fatalSimple(0xF601);
/* TODO: Better error. */
fatalSimple(ResultKernelConnectionClosed);
break;
}
}

View file

@ -40,8 +40,8 @@ Result DebugMonitorService::GetProcessId(Out<u64> out_pid, Handle hnd) {
Result DebugMonitorService::GetProcessHandle(Out<Handle> out_hnd, u64 pid) {
Result rc = svcDebugActiveProcess(out_hnd.GetPointer(), pid);
if (rc == 0xF401) {
rc = 0x4B7;
if (rc == ResultKernelAlreadyExists) {
rc = ResultDebugAlreadyAttached;
}
return rc;
}

View file

@ -104,7 +104,8 @@ static void FixPath(char *dst, size_t dst_size, InBuffer<char> &path) {
Result DebugMonitorService::TargetIO_FileOpen(OutBuffer<u64> out_hnd, InBuffer<char> path, int open_mode, u32 create_mode) {
if (out_hnd.num_elements != 1) {
return 0xF601;
/* Serialization error. */
return ResultKernelConnectionClosed;
}
Result rc = EnsureSdInitialized();
@ -151,7 +152,8 @@ Result DebugMonitorService::TargetIO_FileOpen(OutBuffer<u64> out_hnd, InBuffer<c
Result DebugMonitorService::TargetIO_FileClose(InBuffer<u64> hnd) {
if (hnd.num_elements != 1) {
return 0xF601;
/* Serialization error. */
return ResultKernelConnectionClosed;
}
return CloseFileByHandle(hnd[0]);
@ -159,7 +161,8 @@ Result DebugMonitorService::TargetIO_FileClose(InBuffer<u64> hnd) {
Result DebugMonitorService::TargetIO_FileRead(InBuffer<u64> hnd, OutBuffer<u8, BufferType_Type1> out_data, Out<u32> out_read, u64 offset) {
if (hnd.num_elements != 1) {
return 0xF601;
/* Serialization error. */
return ResultKernelConnectionClosed;
}
FsFile f;
@ -176,7 +179,8 @@ Result DebugMonitorService::TargetIO_FileRead(InBuffer<u64> hnd, OutBuffer<u8, B
Result DebugMonitorService::TargetIO_FileWrite(InBuffer<u64> hnd, InBuffer<u8, BufferType_Type1> data, Out<u32> out_written, u64 offset) {
if (hnd.num_elements != 1) {
return 0xF601;
/* Serialization error. */
return ResultKernelConnectionClosed;
}
FsFile f;
@ -201,7 +205,8 @@ Result DebugMonitorService::TargetIO_FileSetAttributes(InBuffer<char> path, InBu
Result DebugMonitorService::TargetIO_FileGetInformation(InBuffer<char> path, OutBuffer<u64> out_info, Out<int> is_directory) {
if (out_info.num_elements != 4) {
return 0xF601;
/* Serialization error. */
return ResultKernelConnectionClosed;
}
Result rc = EnsureSdInitialized();

@ -1 +1 @@
Subproject commit d448c03c5d65a413b68e504d93929ef161858dcb
Subproject commit a3ca9cf1a352899b3a4289e210f094997cbacbaf

View file

@ -50,7 +50,7 @@ Result MapUtils::LocateSpaceForMapModern(u64 *out, u64 out_size) {
cur_base = address_space.addspace_base;
rc = 0xD001;
rc = ResultKernelOutOfMemory;
cur_end = cur_base + out_size;
if (cur_end <= cur_base) {
return rc;
@ -103,7 +103,7 @@ Result MapUtils::LocateSpaceForMapDeprecated(u64 *out, u64 out_size) {
return rc;
}
rc = 0xD001;
rc = ResultKernelOutOfMemory;
while (true) {
if (mem_info.type == 0x10) {
return rc;
@ -152,7 +152,7 @@ Result MapUtils::MapCodeMemoryForProcessModern(Handle process_h, u64 base_addres
break;
}
rc = svcMapProcessCodeMemory(process_h, try_address, base_address, size);
if (rc != 0xD401) {
if (rc != ResultKernelInvalidMemoryState) {
break;
}
}
@ -181,7 +181,7 @@ Result MapUtils::MapCodeMemoryForProcessDeprecated(Handle process_h, bool is_64_
for (unsigned int i = 0; i < 0x200; i++) {
try_address = addspace_base + (RandomUtils::GetRandomU64((u64)(addspace_size - size) >> 12) << 12);
rc = svcMapProcessCodeMemory(process_h, try_address, base_address, size);
if (rc != 0xD401) {
if (rc != ResultKernelInvalidMemoryState) {
break;
}
}

View file

@ -209,7 +209,7 @@ Result NsoUtils::CalculateNsoLoadExtents(u32 addspace_type, u32 args_size, NsoLo
break;
default:
/* TODO: Panic. */
return 0xD001;
return ResultKernelOutOfMemory;
}
} else {
if (addspace_type & 2) {
@ -221,7 +221,7 @@ Result NsoUtils::CalculateNsoLoadExtents(u32 addspace_type, u32 args_size, NsoLo
}
}
if (extents->total_size > addspace_size) {
return 0xD001;
return ResultKernelOutOfMemory;
}
u64 aslr_slide = 0;

View file

@ -62,15 +62,15 @@ static void LaunchTitle(Boot2KnownTitleId title_id, FsStorageId storage_id, u32
Result rc = Registration::LaunchProcessByTidSid(Registration::TidSid{(u64)title_id, storage_id}, launch_flags, &local_pid);
switch (rc) {
case 0xCE01:
case ResultKernelResourceExhausted:
/* Out of resource! */
std::abort();
break;
case 0xDE01:
case ResultKernelOutOfMemory:
/* Out of memory! */
std::abort();
break;
case 0xD001:
case ResultKernelLimitReached:
/* Limit Reached! */
std::abort();
break;

View file

@ -89,7 +89,7 @@ Result DebugMonitorService::AtmosphereGetProcessInfo(Out<CopiedHandle> proc_hand
Result DebugMonitorService::AtmosphereGetCurrentLimitInfo(Out<u64> cur_val, Out<u64> lim_val, u32 category, u32 resource) {
Result rc;
if(category > ResourceLimitUtils::ResourceLimitCategory::ResourceLimitCategory_Applet) {
return 0xF001;
return ResultKernelInvalidEnumValue;
}
Handle limit_h = ResourceLimitUtils::GetResourceLimitHandleByCategory((ResourceLimitUtils::ResourceLimitCategory) category);

View file

@ -275,7 +275,7 @@ Result Registration::HandleSignaledProcess(std::shared_ptr<Registration::Process
} else {
FinalizeExitedProcess(process);
}
return 0xF601;
return ResultKernelConnectionClosed;
case ProcessState_DebugSuspended:
if (process->flags & PROCESSFLAGS_NOTIFYDEBUGEVENTS) {
process->flags |= (PROCESSFLAGS_DEBUGEVENTPENDING | PROCESSFLAGS_DEBUGSUSPENDED);

View file

@ -276,7 +276,7 @@ Result ResourceLimitUtils::BoostSystemMemoryResourceLimit(u64 boost_size) {
}
}
} else {
rc = 0xF601;
rc = ResultKernelConnectionClosed;
}
if (R_SUCCEEDED(rc)) {
g_system_boost_size = boost_size;

View file

@ -282,7 +282,7 @@ Result Registration::GetServiceHandle(u64 pid, u64 service, Handle *out) {
}
}
if (R_FAILED(rc)) {
if ((rc & 0x3FFFFF) == 0xE01) {
if ((rc & 0x3FFFFF) == ResultKernelOutOfSessions) {
return ResultSmInsufficientSessions;
}
}