mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-05-24 19:54:22 -04:00
loader: Use result definitions instead of magic numbers
This commit is contained in:
parent
2678735f73
commit
db19fa0f7f
12 changed files with 96 additions and 92 deletions
|
@ -86,7 +86,7 @@ Result NpdmUtils::LoadNpdmInternal(FILE *f_npdm, NpdmUtils::NpdmCache *cache) {
|
|||
|
||||
cache->info = (const NpdmUtils::NpdmInfo){0};
|
||||
|
||||
rc = 0x202;
|
||||
rc = ResultFsPathNotFound;
|
||||
if (f_npdm == NULL) {
|
||||
/* For generic "Couldn't open the file" error, just say the file doesn't exist. */
|
||||
return rc;
|
||||
|
@ -96,7 +96,7 @@ Result NpdmUtils::LoadNpdmInternal(FILE *f_npdm, NpdmUtils::NpdmCache *cache) {
|
|||
size_t npdm_size = ftell(f_npdm);
|
||||
fseek(f_npdm, 0, SEEK_SET);
|
||||
|
||||
rc = 0x609;
|
||||
rc = ResultLoaderTooLargeMeta;
|
||||
if ((npdm_size > sizeof(cache->buffer)) || (fread(cache->buffer, 1, npdm_size, f_npdm) != npdm_size)) {
|
||||
fclose(f_npdm);
|
||||
return rc;
|
||||
|
@ -104,7 +104,7 @@ Result NpdmUtils::LoadNpdmInternal(FILE *f_npdm, NpdmUtils::NpdmCache *cache) {
|
|||
|
||||
fclose(f_npdm);
|
||||
|
||||
rc = 0x809;
|
||||
rc = ResultLoaderInvalidMeta;
|
||||
if (npdm_size < sizeof(NpdmUtils::NpdmHeader)) {
|
||||
return rc;
|
||||
}
|
||||
|
@ -241,7 +241,7 @@ Result NpdmUtils::ValidateCapabilityAgainstRestrictions(u32 *restrict_caps, size
|
|||
u32 r_desc = 0;
|
||||
switch (low_bits) {
|
||||
case 3: /* Kernel flags. */
|
||||
rc = 0xCE09;
|
||||
rc = ResultLoaderInvalidCapabilityKernelFlags;
|
||||
for (size_t i = 0; i < num_restrict_caps; i++) {
|
||||
if ((restrict_caps[i] & 0xF) == 0x7) {
|
||||
r_desc = restrict_caps[i] >> 4;
|
||||
|
@ -284,7 +284,7 @@ Result NpdmUtils::ValidateCapabilityAgainstRestrictions(u32 *restrict_caps, size
|
|||
}
|
||||
break;
|
||||
case 4: /* Syscall mask. */
|
||||
rc = 0xD009;
|
||||
rc = ResultLoaderInvalidCapabilitySyscallMask;
|
||||
for (size_t i = 0; i < num_restrict_caps; i++) {
|
||||
if ((restrict_caps[i] & 0x1F) == 0xF) {
|
||||
r_desc = restrict_caps[i] >> 5;
|
||||
|
@ -305,7 +305,7 @@ Result NpdmUtils::ValidateCapabilityAgainstRestrictions(u32 *restrict_caps, size
|
|||
}
|
||||
break;
|
||||
case 6: /* Map IO/Normal. */ {
|
||||
rc = 0xD409;
|
||||
rc = ResultLoaderInvalidCapabilityMapRange;
|
||||
if (caps_remaining == 0) {
|
||||
break;
|
||||
}
|
||||
|
@ -360,7 +360,7 @@ Result NpdmUtils::ValidateCapabilityAgainstRestrictions(u32 *restrict_caps, size
|
|||
}
|
||||
break;
|
||||
case 7: /* Map Normal Page. */
|
||||
rc = 0xD609;
|
||||
rc = ResultLoaderInvalidCapabilityMapPage;
|
||||
for (size_t i = 0; i < num_restrict_caps; i++) {
|
||||
if ((restrict_caps[i] & 0xFF) == 0x7F) {
|
||||
r_desc = restrict_caps[i] >> 8;
|
||||
|
@ -391,14 +391,14 @@ Result NpdmUtils::ValidateCapabilityAgainstRestrictions(u32 *restrict_caps, size
|
|||
}
|
||||
}
|
||||
if (!found) {
|
||||
rc = 0xDE09;
|
||||
rc = ResultLoaderInvalidCapabilityInterruptPair;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 13: /* App Type. */
|
||||
rc = 0xE209;
|
||||
rc = ResultLoaderInvalidCapabilityApplicationType;
|
||||
if (num_restrict_caps) {
|
||||
for (size_t i = 0; i < num_restrict_caps; i++) {
|
||||
if ((restrict_caps[i] & 0x3FFF) == 0x1FFF) {
|
||||
|
@ -415,7 +415,7 @@ Result NpdmUtils::ValidateCapabilityAgainstRestrictions(u32 *restrict_caps, size
|
|||
}
|
||||
break;
|
||||
case 14: /* Kernel Release Version. */
|
||||
rc = 0xE409;
|
||||
rc = ResultLoaderInvalidCapabilityKernelVersion;
|
||||
if (num_restrict_caps) {
|
||||
for (size_t i = 0; i < num_restrict_caps; i++) {
|
||||
if ((restrict_caps[i] & 0x7FFF) == 0x3FFF) {
|
||||
|
@ -432,7 +432,7 @@ Result NpdmUtils::ValidateCapabilityAgainstRestrictions(u32 *restrict_caps, size
|
|||
}
|
||||
break;
|
||||
case 15: /* Handle Table Size. */
|
||||
rc = 0xE609;
|
||||
rc = ResultLoaderInvalidCapabilityHandleTable;
|
||||
for (size_t i = 0; i < num_restrict_caps; i++) {
|
||||
if ((restrict_caps[i] & 0xFFFF) == 0x7FFF) {
|
||||
r_desc = restrict_caps[i] >> 16;
|
||||
|
@ -448,7 +448,7 @@ Result NpdmUtils::ValidateCapabilityAgainstRestrictions(u32 *restrict_caps, size
|
|||
}
|
||||
break;
|
||||
case 16: /* Debug Flags. */
|
||||
rc = 0xE809;
|
||||
rc = ResultLoaderInvalidCapabilityDebugFlags;
|
||||
if (num_restrict_caps) {
|
||||
for (size_t i = 0; i < num_restrict_caps; i++) {
|
||||
if ((restrict_caps[i] & 0x1FFFF) == 0xFFFF) {
|
||||
|
@ -468,7 +468,7 @@ Result NpdmUtils::ValidateCapabilityAgainstRestrictions(u32 *restrict_caps, size
|
|||
rc = 0;
|
||||
break;
|
||||
default: /* Unrecognized Descriptor. */
|
||||
rc = 0xC809;
|
||||
rc = ResultLoaderUnknownCapability;
|
||||
break;
|
||||
}
|
||||
return rc;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue