strat: always use explicit result namespacing

This commit is contained in:
Michael Scire 2021-10-09 10:36:21 -07:00
parent 303c6eb5f9
commit b0e520112b
29 changed files with 237 additions and 237 deletions

View file

@ -122,25 +122,25 @@ namespace ams::settings::fwdbg {
}
Result ValidateSettingsName(const char *name) {
R_UNLESS(name != nullptr, ResultNullSettingsName());
R_UNLESS(name != nullptr, settings::ResultNullSettingsName());
const size_t len = strnlen(name, SettingsNameLengthMax + 1);
R_UNLESS(len > 0, ResultEmptySettingsName());
R_UNLESS(len <= SettingsNameLengthMax, ResultTooLongSettingsName());
R_UNLESS(IsValidSettingsFormat(name, len), ResultInvalidFormatSettingsName());
R_UNLESS(len > 0, settings::ResultEmptySettingsName());
R_UNLESS(len <= SettingsNameLengthMax, settings::ResultTooLongSettingsName());
R_UNLESS(IsValidSettingsFormat(name, len), settings::ResultInvalidFormatSettingsName());
return ResultSuccess();
}
Result ValidateSettingsItemKey(const char *key) {
R_UNLESS(key != nullptr, ResultNullSettingsName());
R_UNLESS(key != nullptr, settings::ResultNullSettingsName());
const size_t len = strnlen(key, SettingsItemKeyLengthMax + 1);
R_UNLESS(len > 0, ResultEmptySettingsItemKey());
R_UNLESS(len <= SettingsNameLengthMax, ResultTooLongSettingsItemKey());
R_UNLESS(IsValidSettingsFormat(key, len), ResultInvalidFormatSettingsItemKey());
R_UNLESS(len > 0, settings::ResultEmptySettingsItemKey());
R_UNLESS(len <= SettingsNameLengthMax, settings::ResultTooLongSettingsItemKey());
R_UNLESS(IsValidSettingsFormat(key, len), settings::ResultInvalidFormatSettingsItemKey());
return ResultSuccess();
}
Result AllocateValue(void **out, size_t size) {
R_UNLESS(g_allocated_value_storage_size + size <= sizeof(g_value_storage), ResultSettingsItemValueAllocationFailed());
R_UNLESS(g_allocated_value_storage_size + size <= sizeof(g_value_storage), settings::ResultSettingsItemValueAllocationFailed());
*out = g_value_storage + g_allocated_value_storage_size;
g_allocated_value_storage_size += size;
@ -158,7 +158,7 @@ namespace ams::settings::fwdbg {
return ResultSuccess();
}
}
return ResultSettingsItemKeyAllocationFailed();
return settings::ResultSettingsItemKeyAllocationFailed();
}
Result FindSettingsItemKey(const char **out, const char *key) {
@ -172,7 +172,7 @@ namespace ams::settings::fwdbg {
return ResultSuccess();
}
}
return ResultSettingsItemKeyAllocationFailed();
return settings::ResultSettingsItemKeyAllocationFailed();
}
template<typename T>
@ -196,8 +196,8 @@ namespace ams::settings::fwdbg {
auto *begin = g_entries;
auto *end = begin + g_num_entries;
auto it = std::lower_bound(begin, end, test_entry);
R_UNLESS(it != end, ResultSettingsItemNotFound());
R_UNLESS(*it == test_entry, ResultSettingsItemNotFound());
R_UNLESS(it != end, settings::ResultSettingsItemNotFound());
R_UNLESS(*it == test_entry, settings::ResultSettingsItemNotFound());
*out = &*it;
return ResultSuccess();
@ -208,7 +208,7 @@ namespace ams::settings::fwdbg {
const char *value_str = delimiter + 1;
const char *type = val_tup;
R_UNLESS(delimiter != nullptr, ResultInvalidFormatSettingsItemValue());
R_UNLESS(delimiter != nullptr, settings::ResultInvalidFormatSettingsItemValue());
while (std::isspace(static_cast<unsigned char>(*type)) && type != delimiter) {
type++;
@ -216,8 +216,8 @@ namespace ams::settings::fwdbg {
const size_t type_len = delimiter - type;
const size_t value_len = strlen(value_str);
R_UNLESS(type_len > 0, ResultInvalidFormatSettingsItemValue());
R_UNLESS(value_len > 0, ResultInvalidFormatSettingsItemValue());
R_UNLESS(type_len > 0, settings::ResultInvalidFormatSettingsItemValue());
R_UNLESS(value_len > 0, settings::ResultInvalidFormatSettingsItemValue());
/* Create new value. */
SdKeyValueStoreEntry new_value = {};
@ -232,9 +232,9 @@ namespace ams::settings::fwdbg {
std::memcpy(new_value.value, value_str, size);
new_value.value_size = size;
} else if (strncasecmp(type, "hex", type_len) == 0 || strncasecmp(type, "bytes", type_len) == 0) {
R_UNLESS(value_len > 0, ResultInvalidFormatSettingsItemValue());
R_UNLESS(value_len % 2 == 0, ResultInvalidFormatSettingsItemValue());
R_UNLESS(IsHexadecimal(value_str), ResultInvalidFormatSettingsItemValue());
R_UNLESS(value_len > 0, settings::ResultInvalidFormatSettingsItemValue());
R_UNLESS(value_len % 2 == 0, settings::ResultInvalidFormatSettingsItemValue());
R_UNLESS(IsHexadecimal(value_str), settings::ResultInvalidFormatSettingsItemValue());
const size_t size = value_len / 2;
R_TRY(AllocateValue(&new_value.value, size));
@ -253,7 +253,7 @@ namespace ams::settings::fwdbg {
} else if (strncasecmp(type, "u64", type_len) == 0) {
R_TRY((ParseSettingsItemIntegralValue<u64>(new_value, value_str)));
} else {
return ResultInvalidFormatSettingsItemValue();
return settings::ResultInvalidFormatSettingsItemValue();
}
/* Insert the entry. */
@ -266,7 +266,7 @@ namespace ams::settings::fwdbg {
}
}
R_UNLESS(inserted, ResultSettingsItemValueAllocationFailed());
R_UNLESS(inserted, settings::ResultSettingsItemValueAllocationFailed());
return ResultSuccess();
}
@ -429,7 +429,7 @@ namespace ams::settings::fwdbg {
}
Result GetSdCardKeyValueStoreSettingsItemValue(size_t *out_size, void *dst, size_t dst_size, const char *name, const char *key) {
R_UNLESS(dst != nullptr, ResultNullSettingsItemValueBuffer());
R_UNLESS(dst != nullptr, settings::ResultNullSettingsItemValueBuffer());
SdKeyValueStoreEntry *entry = nullptr;
R_TRY(GetEntry(&entry, name, key));

View file

@ -229,29 +229,29 @@ namespace ams::creport {
void CrashReport::HandleDebugEventInfoException(const svc::DebugEventInfo &d) {
switch (d.info.exception.type) {
case svc::DebugException_UndefinedInstruction:
this->result = ResultUndefinedInstruction();
this->result = creport::ResultUndefinedInstruction();
break;
case svc::DebugException_InstructionAbort:
this->result = ResultInstructionAbort();
this->result = creport::ResultInstructionAbort();
break;
case svc::DebugException_DataAbort:
this->result = ResultDataAbort();
this->result = creport::ResultDataAbort();
break;
case svc::DebugException_AlignmentFault:
this->result = ResultAlignmentFault();
this->result = creport::ResultAlignmentFault();
break;
case svc::DebugException_UserBreak:
this->result = ResultUserBreak();
this->result = creport::ResultUserBreak();
/* Try to parse out the user break result. */
if (hos::GetVersion() >= hos::Version_5_0_0) {
svc::ReadDebugProcessMemory(reinterpret_cast<uintptr_t>(std::addressof(this->result)), this->debug_handle, d.info.exception.specific.user_break.address, sizeof(this->result));
}
break;
case svc::DebugException_UndefinedSystemCall:
this->result = ResultUndefinedSystemCall();
this->result = creport::ResultUndefinedSystemCall();
break;
case svc::DebugException_MemorySystemError:
this->result = ResultMemorySystemError();
this->result = creport::ResultMemorySystemError();
break;
case svc::DebugException_DebuggerAttached:
case svc::DebugException_BreakPoint:

View file

@ -27,7 +27,7 @@ namespace ams::creport {
private:
os::NativeHandle debug_handle = os::InvalidNativeHandle;
bool has_extra_info = true;
Result result = ResultIncompleteReport();
Result result = creport::ResultIncompleteReport();
/* Meta, used for building module/thread list. */
ThreadTlsMap thread_tls_map = {};

View file

@ -36,7 +36,7 @@ namespace ams::dmnt::cheat {
}
Result CheatService::ForceOpenCheatProcess() {
R_UNLESS(R_SUCCEEDED(dmnt::cheat::impl::ForceOpenCheatProcess()), ResultCheatNotAttached());
R_UNLESS(R_SUCCEEDED(dmnt::cheat::impl::ForceOpenCheatProcess()), dmnt::cheat::ResultCheatNotAttached());
return ResultSuccess();
}
@ -61,17 +61,17 @@ namespace ams::dmnt::cheat {
}
Result CheatService::GetCheatProcessMappings(const sf::OutArray<svc::MemoryInfo> &mappings, sf::Out<u64> out_count, u64 offset) {
R_UNLESS(mappings.GetPointer() != nullptr, ResultCheatNullBuffer());
R_UNLESS(mappings.GetPointer() != nullptr, dmnt::cheat::ResultCheatNullBuffer());
return dmnt::cheat::impl::GetCheatProcessMappings(mappings.GetPointer(), mappings.GetSize(), out_count.GetPointer(), offset);
}
Result CheatService::ReadCheatProcessMemory(const sf::OutBuffer &buffer, u64 address, u64 out_size) {
R_UNLESS(buffer.GetPointer() != nullptr, ResultCheatNullBuffer());
R_UNLESS(buffer.GetPointer() != nullptr, dmnt::cheat::ResultCheatNullBuffer());
return dmnt::cheat::impl::ReadCheatProcessMemory(address, buffer.GetPointer(), std::min(out_size, buffer.GetSize()));
}
Result CheatService::WriteCheatProcessMemory(const sf::InBuffer &buffer, u64 address, u64 in_size) {
R_UNLESS(buffer.GetPointer() != nullptr, ResultCheatNullBuffer());
R_UNLESS(buffer.GetPointer() != nullptr, dmnt::cheat::ResultCheatNullBuffer());
return dmnt::cheat::impl::WriteCheatProcessMemory(address, buffer.GetPointer(), std::min(in_size, buffer.GetSize()));
}
@ -88,7 +88,7 @@ namespace ams::dmnt::cheat {
}
Result CheatService::GetCheats(const sf::OutArray<CheatEntry> &cheats, sf::Out<u64> out_count, u64 offset) {
R_UNLESS(cheats.GetPointer() != nullptr, ResultCheatNullBuffer());
R_UNLESS(cheats.GetPointer() != nullptr, dmnt::cheat::ResultCheatNullBuffer());
return dmnt::cheat::impl::GetCheats(cheats.GetPointer(), cheats.GetSize(), out_count.GetPointer(), offset);
}
@ -133,7 +133,7 @@ namespace ams::dmnt::cheat {
}
Result CheatService::GetFrozenAddresses(const sf::OutArray<FrozenAddressEntry> &addresses, sf::Out<u64> out_count, u64 offset) {
R_UNLESS(addresses.GetPointer() != nullptr, ResultCheatNullBuffer());
R_UNLESS(addresses.GetPointer() != nullptr, dmnt::cheat::ResultCheatNullBuffer());
return dmnt::cheat::impl::GetFrozenAddresses(addresses.GetPointer(), addresses.GetSize(), out_count.GetPointer(), offset);
}
@ -143,9 +143,9 @@ namespace ams::dmnt::cheat {
Result CheatService::EnableFrozenAddress(sf::Out<u64> out_value, u64 address, u64 width) {
/* Width needs to be a power of two <= 8. */
R_UNLESS(width > 0, ResultFrozenAddressInvalidWidth());
R_UNLESS(width <= sizeof(u64), ResultFrozenAddressInvalidWidth());
R_UNLESS((width & (width - 1)) == 0, ResultFrozenAddressInvalidWidth());
R_UNLESS(width > 0, dmnt::cheat::ResultFrozenAddressInvalidWidth());
R_UNLESS(width <= sizeof(u64), dmnt::cheat::ResultFrozenAddressInvalidWidth());
R_UNLESS((width & (width - 1)) == 0, dmnt::cheat::ResultFrozenAddressInvalidWidth());
return dmnt::cheat::impl::EnableFrozenAddress(out_value.GetPointer(), address, width);
}

View file

@ -231,7 +231,7 @@ namespace ams::dmnt::cheat::impl {
}
Result EnsureCheatProcess() {
R_UNLESS(this->HasActiveCheatProcess(), ResultCheatNotAttached());
R_UNLESS(this->HasActiveCheatProcess(), dmnt::cheat::ResultCheatNotAttached());
return ResultSuccess();
}
@ -480,8 +480,8 @@ namespace ams::dmnt::cheat::impl {
R_TRY(this->EnsureCheatProcess());
const CheatEntry *entry = this->GetCheatEntryById(cheat_id);
R_UNLESS(entry != nullptr, ResultCheatUnknownId());
R_UNLESS(entry->definition.num_opcodes != 0, ResultCheatUnknownId());
R_UNLESS(entry != nullptr, dmnt::cheat::ResultCheatUnknownId());
R_UNLESS(entry->definition.num_opcodes != 0, dmnt::cheat::ResultCheatUnknownId());
*out_cheat = *entry;
return ResultSuccess();
@ -493,10 +493,10 @@ namespace ams::dmnt::cheat::impl {
R_TRY(this->EnsureCheatProcess());
CheatEntry *entry = this->GetCheatEntryById(cheat_id);
R_UNLESS(entry != nullptr, ResultCheatUnknownId());
R_UNLESS(entry->definition.num_opcodes != 0, ResultCheatUnknownId());
R_UNLESS(entry != nullptr, dmnt::cheat::ResultCheatUnknownId());
R_UNLESS(entry->definition.num_opcodes != 0, dmnt::cheat::ResultCheatUnknownId());
R_UNLESS(cheat_id != 0, ResultCheatCannotDisable());
R_UNLESS(cheat_id != 0, dmnt::cheat::ResultCheatCannotDisable());
entry->enabled = !entry->enabled;
@ -511,11 +511,11 @@ namespace ams::dmnt::cheat::impl {
R_TRY(this->EnsureCheatProcess());
R_UNLESS(def.num_opcodes != 0, ResultCheatInvalid());
R_UNLESS(def.num_opcodes <= util::size(def.opcodes), ResultCheatInvalid());
R_UNLESS(def.num_opcodes != 0, dmnt::cheat::ResultCheatInvalid());
R_UNLESS(def.num_opcodes <= util::size(def.opcodes), dmnt::cheat::ResultCheatInvalid());
CheatEntry *new_entry = this->GetFreeCheatEntry();
R_UNLESS(new_entry != nullptr, ResultCheatOutOfResource());
R_UNLESS(new_entry != nullptr, dmnt::cheat::ResultCheatOutOfResource());
new_entry->enabled = enabled;
new_entry->definition = def;
@ -533,7 +533,7 @@ namespace ams::dmnt::cheat::impl {
std::scoped_lock lk(this->cheat_lock);
R_TRY(this->EnsureCheatProcess());
R_UNLESS(cheat_id < MaxCheatCount, ResultCheatUnknownId());
R_UNLESS(cheat_id < MaxCheatCount, dmnt::cheat::ResultCheatUnknownId());
this->ResetCheatEntry(cheat_id);
@ -548,8 +548,8 @@ namespace ams::dmnt::cheat::impl {
R_TRY(this->EnsureCheatProcess());
R_UNLESS(def.num_opcodes != 0, ResultCheatInvalid());
R_UNLESS(def.num_opcodes <= util::size(def.opcodes), ResultCheatInvalid());
R_UNLESS(def.num_opcodes != 0, dmnt::cheat::ResultCheatInvalid());
R_UNLESS(def.num_opcodes <= util::size(def.opcodes), dmnt::cheat::ResultCheatInvalid());
CheatEntry *master_entry = this->cheat_entries + 0;
@ -566,7 +566,7 @@ namespace ams::dmnt::cheat::impl {
std::scoped_lock lk(this->cheat_lock);
R_TRY(this->EnsureCheatProcess());
R_UNLESS(which < CheatVirtualMachine::NumStaticRegisters, ResultCheatInvalid());
R_UNLESS(which < CheatVirtualMachine::NumStaticRegisters, dmnt::cheat::ResultCheatInvalid());
*out = this->cheat_vm.GetStaticRegister(which);
return ResultSuccess();
@ -576,7 +576,7 @@ namespace ams::dmnt::cheat::impl {
std::scoped_lock lk(this->cheat_lock);
R_TRY(this->EnsureCheatProcess());
R_UNLESS(which < CheatVirtualMachine::NumStaticRegisters, ResultCheatInvalid());
R_UNLESS(which < CheatVirtualMachine::NumStaticRegisters, dmnt::cheat::ResultCheatInvalid());
this->cheat_vm.SetStaticRegister(which, value);
return ResultSuccess();
@ -629,7 +629,7 @@ namespace ams::dmnt::cheat::impl {
R_TRY(this->EnsureCheatProcess());
const auto it = this->frozen_addresses_map.find_key(address);
R_UNLESS(it != this->frozen_addresses_map.end(), ResultFrozenAddressNotFound());
R_UNLESS(it != this->frozen_addresses_map.end(), dmnt::cheat::ResultFrozenAddressNotFound());
frz_addr->address = it->GetAddress();
frz_addr->value = it->GetValue();
@ -642,14 +642,14 @@ namespace ams::dmnt::cheat::impl {
R_TRY(this->EnsureCheatProcess());
const auto it = this->frozen_addresses_map.find_key(address);
R_UNLESS(it == this->frozen_addresses_map.end(), ResultFrozenAddressAlreadyExists());
R_UNLESS(it == this->frozen_addresses_map.end(), dmnt::cheat::ResultFrozenAddressAlreadyExists());
FrozenAddressValue value = {};
value.width = width;
R_TRY(this->ReadCheatProcessMemoryUnsafe(address, &value.value, width));
FrozenAddressMapEntry *entry = AllocateFrozenAddress(address, value);
R_UNLESS(entry != nullptr, ResultFrozenAddressOutOfResource());
R_UNLESS(entry != nullptr, dmnt::cheat::ResultFrozenAddressOutOfResource());
this->frozen_addresses_map.insert(*entry);
*out_value = value.value;
@ -662,7 +662,7 @@ namespace ams::dmnt::cheat::impl {
R_TRY(this->EnsureCheatProcess());
const auto it = this->frozen_addresses_map.find_key(address);
R_UNLESS(it != this->frozen_addresses_map.end(), ResultFrozenAddressNotFound());
R_UNLESS(it != this->frozen_addresses_map.end(), dmnt::cheat::ResultFrozenAddressNotFound());
FrozenAddressMapEntry *entry = std::addressof(*it);
this->frozen_addresses_map.erase(it);
@ -820,7 +820,7 @@ namespace ams::dmnt::cheat::impl {
/* If new process launch, we may not want to actually attach. */
if (on_process_launch) {
R_UNLESS(status.IsCheatEnabled(), ResultCheatNotAttached());
R_UNLESS(status.IsCheatEnabled(), dmnt::cheat::ResultCheatNotAttached());
}
}
@ -841,7 +841,7 @@ namespace ams::dmnt::cheat::impl {
} else if (num_modules == 1 && !on_process_launch) {
proc_module = &proc_modules[0];
} else {
return ResultCheatNotAttached();
return dmnt::cheat::ResultCheatNotAttached();
}
this->cheat_process_metadata.main_nso_extents.base = proc_module->base_address;
@ -853,7 +853,7 @@ namespace ams::dmnt::cheat::impl {
if (!this->LoadCheats(this->cheat_process_metadata.program_id, this->cheat_process_metadata.main_nso_build_id) ||
!this->LoadCheatToggles(this->cheat_process_metadata.program_id)) {
/* If new process launch, require success. */
R_UNLESS(!on_process_launch, ResultCheatNotAttached());
R_UNLESS(!on_process_launch, dmnt::cheat::ResultCheatNotAttached());
}
/* Open a debug handle. */

View file

@ -29,7 +29,7 @@ namespace ams::fatal::srv {
std::scoped_lock lk{this->lock};
/* Only allow GetEvent to succeed NumFatalEvents times. */
R_UNLESS(this->num_events_gotten < FatalEventManager::NumFatalEvents, ResultTooManyEvents());
R_UNLESS(this->num_events_gotten < FatalEventManager::NumFatalEvents, fatal::ResultTooManyEvents());
*out = std::addressof(this->events[this->num_events_gotten++]);
return ResultSuccess();

View file

@ -35,7 +35,7 @@ namespace ams::fatal::srv {
bool has_thrown;
private:
Result TrySetHasThrown() {
R_UNLESS(!this->has_thrown, ResultAlreadyThrown());
R_UNLESS(!this->has_thrown, fatal::ResultAlreadyThrown());
this->has_thrown = true;
return ResultSuccess();
}

View file

@ -107,7 +107,7 @@ namespace ams::ldr {
}
Result LoaderService::GetProcessModuleInfo(sf::Out<u32> count, const sf::OutPointerArray<ModuleInfo> &out, os::ProcessId process_id) {
R_UNLESS(out.GetSize() <= std::numeric_limits<s32>::max(), ResultInvalidSize());
R_UNLESS(out.GetSize() <= std::numeric_limits<s32>::max(), ldr::ResultInvalidSize());
return ldr::ro::GetProcessModuleInfo(count.GetPointer(), out.GetPointer(), out.GetSize(), process_id);
}

View file

@ -43,16 +43,16 @@ namespace ams::ldr {
/* Helpers. */
Result ValidateSubregion(size_t allowed_start, size_t allowed_end, size_t start, size_t size, size_t min_size = 0) {
R_UNLESS(size >= min_size, ResultInvalidMeta());
R_UNLESS(allowed_start <= start, ResultInvalidMeta());
R_UNLESS(start <= allowed_end, ResultInvalidMeta());
R_UNLESS(start + size <= allowed_end, ResultInvalidMeta());
R_UNLESS(size >= min_size, ldr::ResultInvalidMeta());
R_UNLESS(allowed_start <= start, ldr::ResultInvalidMeta());
R_UNLESS(start <= allowed_end, ldr::ResultInvalidMeta());
R_UNLESS(start + size <= allowed_end, ldr::ResultInvalidMeta());
return ResultSuccess();
}
Result ValidateNpdm(const Npdm *npdm, size_t size) {
/* Validate magic. */
R_UNLESS(npdm->magic == Npdm::Magic, ResultInvalidMeta());
R_UNLESS(npdm->magic == Npdm::Magic, ldr::ResultInvalidMeta());
/* Validate flags. */
u32 mask;
@ -69,7 +69,7 @@ namespace ams::ldr {
/* We set the "DisableDeviceAddressSpaceMerge" bit on all versions, so be permissive with it. */
mask &= ~0x20;
R_UNLESS(!(npdm->flags & mask), ResultInvalidMeta());
R_UNLESS(!(npdm->flags & mask), ldr::ResultInvalidMeta());
/* Validate Acid extents. */
R_TRY(ValidateSubregion(sizeof(Npdm), size, npdm->acid_offset, npdm->acid_size, sizeof(Acid)));
@ -82,11 +82,11 @@ namespace ams::ldr {
Result ValidateAcid(const Acid *acid, size_t size) {
/* Validate magic. */
R_UNLESS(acid->magic == Acid::Magic, ResultInvalidMeta());
R_UNLESS(acid->magic == Acid::Magic, ldr::ResultInvalidMeta());
/* Validate that the acid is for production if not development. */
if (!IsDevelopmentForAcidProductionCheck()) {
R_UNLESS((acid->flags & Acid::AcidFlag_Production) != 0, ResultInvalidMeta());
R_UNLESS((acid->flags & Acid::AcidFlag_Production) != 0, ldr::ResultInvalidMeta());
}
/* Validate Fac, Sac, Kac. */
@ -99,7 +99,7 @@ namespace ams::ldr {
Result ValidateAci(const Aci *aci, size_t size) {
/* Validate magic. */
R_UNLESS(aci->magic == Aci::Magic, ResultInvalidMeta());
R_UNLESS(aci->magic == Aci::Magic, ldr::ResultInvalidMeta());
/* Validate Fah, Sac, Kac. */
R_TRY(ValidateSubregion(sizeof(Aci), size, aci->fah_offset, aci->fah_size));
@ -130,7 +130,7 @@ namespace ams::ldr {
const u8 *msg = meta->acid->modulus;
const size_t msg_size = meta->acid->size;
const bool is_signature_valid = crypto::VerifyRsa2048PssSha256(sig, sig_size, mod, mod_size, exp, exp_size, msg, msg_size);
R_UNLESS(is_signature_valid || !IsEnabledProgramVerification(), ResultInvalidAcidSignature());
R_UNLESS(is_signature_valid || !IsEnabledProgramVerification(), ldr::ResultInvalidAcidSignature());
meta->check_verification_data = is_signature_valid;
return ResultSuccess();
@ -147,12 +147,12 @@ namespace ams::ldr {
R_TRY(fs::GetFileSize(std::addressof(npdm_size), file));
/* Read data into cache buffer. */
R_UNLESS(npdm_size <= static_cast<s64>(MetaCacheBufferSize), ResultTooLargeMeta());
R_UNLESS(npdm_size <= static_cast<s64>(MetaCacheBufferSize), ldr::ResultTooLargeMeta());
R_TRY(fs::ReadFile(file, 0, cache->buffer, npdm_size));
}
/* Ensure size is big enough. */
R_UNLESS(npdm_size >= static_cast<s64>(sizeof(Npdm)), ResultInvalidMeta());
R_UNLESS(npdm_size >= static_cast<s64>(sizeof(Npdm)), ldr::ResultInvalidMeta());
/* Validate the meta. */
{

View file

@ -120,7 +120,7 @@ namespace ams::ldr {
for (size_t i = 0; i < num_entries; i++) {
if (entries[i].program_id == program_id) {
R_UNLESS(entries[i].version <= version, ResultInvalidVersion());
R_UNLESS(entries[i].version <= version, ldr::ResultInvalidVersion());
}
}
#else
@ -142,7 +142,7 @@ namespace ams::ldr {
#define COPY_ACCESS_CONTROL(source, which) \
({ \
const size_t size = meta->source->which##_size; \
R_UNLESS(offset + size <= sizeof(out->ac_buffer), ResultInternalError()); \
R_UNLESS(offset + size <= sizeof(out->ac_buffer), ldr::ResultInternalError()); \
out->source##_##which##_size = size; \
std::memcpy(out->ac_buffer + offset, meta->source##_##which, size); \
offset += size; \
@ -189,7 +189,7 @@ namespace ams::ldr {
/* Read NSO header. */
size_t read_size;
R_TRY(fs::ReadFile(std::addressof(read_size), file, 0, nso_headers + i, sizeof(*nso_headers)));
R_UNLESS(read_size == sizeof(*nso_headers), ResultInvalidNso());
R_UNLESS(read_size == sizeof(*nso_headers), ldr::ResultInvalidNso());
has_nso[i] = true;
}
@ -200,18 +200,18 @@ namespace ams::ldr {
Result ValidateNsoHeaders(const NsoHeader *nso_headers, const bool *has_nso) {
/* We must always have a main. */
R_UNLESS(has_nso[Nso_Main], ResultInvalidNso());
R_UNLESS(has_nso[Nso_Main], ldr::ResultInvalidNso());
/* If we don't have an RTLD, we must only have a main. */
if (!has_nso[Nso_Rtld]) {
for (size_t i = Nso_Main + 1; i < Nso_Count; i++) {
R_UNLESS(!has_nso[i], ResultInvalidNso());
R_UNLESS(!has_nso[i], ldr::ResultInvalidNso());
}
}
/* All NSOs must have zero text offset. */
for (size_t i = 0; i < Nso_Count; i++) {
R_UNLESS(nso_headers[i].text_dst_offset == 0, ResultInvalidNso());
R_UNLESS(nso_headers[i].text_dst_offset == 0, ldr::ResultInvalidNso());
}
return ResultSuccess();
@ -222,8 +222,8 @@ namespace ams::ldr {
R_TRY(ValidateProgramVersion(loc.program_id, meta->npdm->version));
/* Validate program id. */
R_UNLESS(meta->aci->program_id >= meta->acid->program_id_min, ResultInvalidProgramId());
R_UNLESS(meta->aci->program_id <= meta->acid->program_id_max, ResultInvalidProgramId());
R_UNLESS(meta->aci->program_id >= meta->acid->program_id_min, ldr::ResultInvalidProgramId());
R_UNLESS(meta->aci->program_id <= meta->acid->program_id_max, ldr::ResultInvalidProgramId());
/* Validate the kernel capabilities. */
R_TRY(caps::ValidateCapabilities(meta->acid_kac, meta->acid->kac_size, meta->aci_kac, meta->aci->kac_size));
@ -240,7 +240,7 @@ namespace ams::ldr {
const size_t hsh_size = sizeof(code_verification_data.target_hash);
const bool is_signature_valid = crypto::VerifyRsa2048PssSha256WithHash(sig, sig_size, mod, mod_size, exp, exp_size, hsh, hsh_size);
R_UNLESS(is_signature_valid, ResultInvalidNcaSignature());
R_UNLESS(is_signature_valid, ldr::ResultInvalidNcaSignature());
}
/* All good. */
@ -272,7 +272,7 @@ namespace ams::ldr {
flags |= svc::CreateProcessFlag_AddressSpace64Bit;
break;
default:
return ResultInvalidMeta();
return ldr::ResultInvalidMeta();
}
/* Set Enable Debug. */
@ -317,7 +317,7 @@ namespace ams::ldr {
flags |= svc::CreateProcessFlag_PoolPartitionSystemNonSecure;
break;
default:
return ResultInvalidMeta();
return ldr::ResultInvalidMeta();
}
} else if (hos::GetVersion() >= hos::Version_4_0_0) {
/* On 4.0.0+, the corresponding bit was simply "UseSecureMemory". */
@ -351,18 +351,18 @@ namespace ams::ldr {
/* 3.0.0+ System Resource Size. */
if (hos::GetVersion() >= hos::Version_3_0_0) {
/* Validate size is aligned. */
R_UNLESS(util::IsAligned(meta->npdm->system_resource_size, os::MemoryBlockUnitSize), ResultInvalidSize());
R_UNLESS(util::IsAligned(meta->npdm->system_resource_size, os::MemoryBlockUnitSize), ldr::ResultInvalidSize());
/* Validate system resource usage. */
if (meta->npdm->system_resource_size) {
/* Process must be 64-bit. */
R_UNLESS((out->flags & svc::CreateProcessFlag_AddressSpace64Bit), ResultInvalidMeta());
R_UNLESS((out->flags & svc::CreateProcessFlag_AddressSpace64Bit), ldr::ResultInvalidMeta());
/* Process must be application or applet. */
R_UNLESS(IsApplication(meta) || IsApplet(meta), ResultInvalidMeta());
R_UNLESS(IsApplication(meta) || IsApplet(meta), ldr::ResultInvalidMeta());
/* Size must be less than or equal to max. */
R_UNLESS(meta->npdm->system_resource_size <= SystemResourceSizeMax, ResultInvalidMeta());
R_UNLESS(meta->npdm->system_resource_size <= SystemResourceSizeMax, ldr::ResultInvalidMeta());
}
out->system_resource_num_pages = meta->npdm->system_resource_size >> 12;
}
@ -541,19 +541,19 @@ namespace ams::ldr {
}
/* Validate size. */
R_UNLESS(file_size <= segment->size, ResultInvalidNso());
R_UNLESS(segment->size <= std::numeric_limits<s32>::max(), ResultInvalidNso());
R_UNLESS(file_size <= segment->size, ldr::ResultInvalidNso());
R_UNLESS(segment->size <= std::numeric_limits<s32>::max(), ldr::ResultInvalidNso());
/* Load data from file. */
uintptr_t load_address = is_compressed ? map_end - file_size : map_base;
size_t read_size;
R_TRY(fs::ReadFile(std::addressof(read_size), file, segment->file_offset, reinterpret_cast<void *>(load_address), file_size));
R_UNLESS(read_size == file_size, ResultInvalidNso());
R_UNLESS(read_size == file_size, ldr::ResultInvalidNso());
/* Uncompress if necessary. */
if (is_compressed) {
bool decompressed = (util::DecompressLZ4(reinterpret_cast<void *>(map_base), segment->size, reinterpret_cast<const void *>(load_address), file_size) == static_cast<int>(segment->size));
R_UNLESS(decompressed, ResultInvalidNso());
R_UNLESS(decompressed, ldr::ResultInvalidNso());
}
/* Check hash if necessary. */
@ -561,7 +561,7 @@ namespace ams::ldr {
u8 hash[crypto::Sha256Generator::HashSize];
crypto::GenerateSha256Hash(hash, sizeof(hash), reinterpret_cast<void *>(map_base), segment->size);
R_UNLESS(std::memcmp(hash, file_hash, sizeof(hash)) == 0, ResultInvalidNso());
R_UNLESS(std::memcmp(hash, file_hash, sizeof(hash)) == 0, ldr::ResultInvalidNso());
}
return ResultSuccess();