mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-04-22 12:34:47 +00:00
ams-except-ncm: use R_SUCCEED_IF
This commit is contained in:
parent
8d1d1f7999
commit
06ba2ed8de
22 changed files with 81 additions and 46 deletions
|
@ -262,8 +262,8 @@ namespace ams::kern::arch::arm64 {
|
|||
R_UNLESS(entry.handler != nullptr, svc::ResultInvalidState());
|
||||
|
||||
/* If auto-cleared, we can succeed immediately. */
|
||||
R_UNLESS(entry.manually_cleared, ResultSuccess());
|
||||
R_UNLESS(entry.needs_clear, ResultSuccess());
|
||||
R_SUCCEED_IF(!entry.manually_cleared);
|
||||
R_SUCCEED_IF(!entry.needs_clear);
|
||||
|
||||
/* Clear and enable. */
|
||||
entry.needs_clear = false;
|
||||
|
@ -277,8 +277,8 @@ namespace ams::kern::arch::arm64 {
|
|||
R_UNLESS(entry.handler != nullptr, svc::ResultInvalidState());
|
||||
|
||||
/* If auto-cleared, we can succeed immediately. */
|
||||
R_UNLESS(entry.manually_cleared, ResultSuccess());
|
||||
R_UNLESS(entry.needs_clear, ResultSuccess());
|
||||
R_SUCCEED_IF(!entry.manually_cleared);
|
||||
R_SUCCEED_IF(!entry.needs_clear);
|
||||
|
||||
/* Clear and set priority. */
|
||||
entry.needs_clear = false;
|
||||
|
|
|
@ -832,7 +832,7 @@ namespace ams::kern::arch::arm64 {
|
|||
L1PageTableEntry *l1_entry = impl.GetL1Entry(virt_addr);
|
||||
if (l1_entry->IsBlock()) {
|
||||
/* If our block size is too big, don't bother. */
|
||||
R_UNLESS(block_size < L1BlockSize, ResultSuccess());
|
||||
R_SUCCEED_IF(block_size >= L1BlockSize);
|
||||
|
||||
/* Get the addresses we're working with. */
|
||||
const KProcessAddress block_virt_addr = util::AlignDown(GetInteger(virt_addr), L1BlockSize);
|
||||
|
@ -859,10 +859,10 @@ namespace ams::kern::arch::arm64 {
|
|||
}
|
||||
|
||||
/* If we don't have an l1 table, we're done. */
|
||||
R_UNLESS(l1_entry->IsTable(), ResultSuccess());
|
||||
R_SUCCEED_IF(!l1_entry->IsTable());
|
||||
|
||||
/* We want to separate L2 contiguous blocks into L2 blocks, so check that our size permits that. */
|
||||
R_UNLESS(block_size < L2ContiguousBlockSize, ResultSuccess());
|
||||
R_SUCCEED_IF(block_size >= L2ContiguousBlockSize);
|
||||
|
||||
L2PageTableEntry *l2_entry = impl.GetL2Entry(l1_entry, virt_addr);
|
||||
if (l2_entry->IsBlock()) {
|
||||
|
@ -878,7 +878,7 @@ namespace ams::kern::arch::arm64 {
|
|||
}
|
||||
|
||||
/* We want to separate L2 blocks into L3 contiguous blocks, so check that our size permits that. */
|
||||
R_UNLESS(block_size < L2BlockSize, ResultSuccess());
|
||||
R_SUCCEED_IF(block_size >= L2BlockSize);
|
||||
|
||||
/* Get the addresses we're working with. */
|
||||
const KProcessAddress block_virt_addr = util::AlignDown(GetInteger(virt_addr), L2BlockSize);
|
||||
|
@ -905,10 +905,10 @@ namespace ams::kern::arch::arm64 {
|
|||
}
|
||||
|
||||
/* If we don't have an L3 table, we're done. */
|
||||
R_UNLESS(l2_entry->IsTable(), ResultSuccess());
|
||||
R_SUCCEED_IF(!l2_entry->IsTable());
|
||||
|
||||
/* We want to separate L3 contiguous blocks into L2 blocks, so check that our size permits that. */
|
||||
R_UNLESS(block_size < L3ContiguousBlockSize, ResultSuccess());
|
||||
R_SUCCEED_IF(block_size >= L3ContiguousBlockSize);
|
||||
|
||||
/* If we're contiguous, try to separate. */
|
||||
L3PageTableEntry *l3_entry = impl.GetL3Entry(l2_entry, virt_addr);
|
||||
|
|
|
@ -257,7 +257,7 @@ namespace ams::kern::board::nintendo::nx {
|
|||
const WordType clear_bit = (this->state[i] + 1) ^ (this->state[i]);
|
||||
this->state[i] |= clear_bit;
|
||||
out[num_reserved++] = static_cast<u8>(BitsPerWord * i + BitsPerWord - 1 - ClearLeadingZero(clear_bit));
|
||||
R_UNLESS(num_reserved != num_desired, ResultSuccess());
|
||||
R_SUCCEED_IF(num_reserved == num_desired);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -211,7 +211,9 @@ namespace ams::kern {
|
|||
/* Validate this is a capability we can act on. */
|
||||
const auto type = GetCapabilityType(cap);
|
||||
R_UNLESS(type != CapabilityType::Invalid, svc::ResultInvalidArgument());
|
||||
R_UNLESS(type != CapabilityType::Padding, ResultSuccess());
|
||||
|
||||
/* If the type is padding, we have no work to do. */
|
||||
R_SUCCEED_IF(type == CapabilityType::Padding);
|
||||
|
||||
/* Check that we haven't already processed this capability. */
|
||||
const auto flag = GetCapabilityFlag(type);
|
||||
|
|
|
@ -38,7 +38,7 @@ namespace ams::kern {
|
|||
|
||||
Result KPageGroup::AddBlock(KVirtualAddress addr, size_t num_pages) {
|
||||
/* Succeed immediately if we're adding no pages. */
|
||||
R_UNLESS(num_pages != 0, ResultSuccess());
|
||||
R_SUCCEED_IF(num_pages == 0);
|
||||
|
||||
/* Check for overflow. */
|
||||
MESOSPHERE_ASSERT(addr < addr + num_pages * PageSize);
|
||||
|
@ -46,7 +46,7 @@ namespace ams::kern {
|
|||
/* Try to just append to the last block. */
|
||||
if (!this->block_list.empty()) {
|
||||
auto it = --(this->block_list.end());
|
||||
R_UNLESS(!it->TryConcatenate(addr, num_pages), ResultSuccess());
|
||||
R_SUCCEED_IF(it->TryConcatenate(addr, num_pages));
|
||||
}
|
||||
|
||||
/* Allocate a new block. */
|
||||
|
|
|
@ -28,17 +28,27 @@ namespace ams::fs {
|
|||
MemoryStorage(void *b, s64 sz) : buf(static_cast<u8 *>(b)), size(sz) { /* .. */ }
|
||||
public:
|
||||
virtual Result Read(s64 offset, void *buffer, size_t size) override {
|
||||
R_UNLESS(size != 0, ResultSuccess());
|
||||
/* Succeed immediately on zero-sized read. */
|
||||
R_SUCCEED_IF(size == 0);
|
||||
|
||||
/* Validate arguments. */
|
||||
R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument());
|
||||
R_UNLESS(IStorage::IsRangeValid(offset, size, this->size), fs::ResultOutOfRange());
|
||||
|
||||
/* Copy from memory. */
|
||||
std::memcpy(buffer, this->buf + offset, size);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
virtual Result Write(s64 offset, const void *buffer, size_t size) override{
|
||||
R_UNLESS(size != 0, ResultSuccess());
|
||||
virtual Result Write(s64 offset, const void *buffer, size_t size) override {
|
||||
/* Succeed immediately on zero-sized write. */
|
||||
R_SUCCEED_IF(size == 0);
|
||||
|
||||
/* Validate arguments. */
|
||||
R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument());
|
||||
R_UNLESS(IStorage::IsRangeValid(offset, size, this->size), fs::ResultOutOfRange());
|
||||
|
||||
/* Copy to memory. */
|
||||
std::memcpy(this->buf + offset, buffer, size);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
|
|
@ -69,16 +69,27 @@ namespace ams::fs {
|
|||
}
|
||||
public:
|
||||
virtual Result Read(s64 offset, void *buffer, size_t size) override {
|
||||
/* Ensure we're initialized. */
|
||||
R_UNLESS(this->IsValid(), fs::ResultNotInitialized());
|
||||
R_UNLESS(size != 0, ResultSuccess());
|
||||
|
||||
/* Succeed immediately on zero-sized operation. */
|
||||
R_SUCCEED_IF(size == 0);
|
||||
|
||||
|
||||
/* Validate arguments and read. */
|
||||
R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument());
|
||||
R_UNLESS(IStorage::IsRangeValid(offset, size, this->size), fs::ResultOutOfRange());
|
||||
return this->base_storage->Read(this->offset + offset, buffer, size);
|
||||
}
|
||||
|
||||
virtual Result Write(s64 offset, const void *buffer, size_t size) override{
|
||||
/* Ensure we're initialized. */
|
||||
R_UNLESS(this->IsValid(), fs::ResultNotInitialized());
|
||||
R_UNLESS(size != 0, ResultSuccess());
|
||||
|
||||
/* Succeed immediately on zero-sized operation. */
|
||||
R_SUCCEED_IF(size == 0);
|
||||
|
||||
/* Validate arguments and write. */
|
||||
R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument());
|
||||
R_UNLESS(IStorage::IsRangeValid(offset, size, this->size), fs::ResultOutOfRange());
|
||||
return this->base_storage->Write(this->offset + offset, buffer, size);
|
||||
|
@ -90,15 +101,17 @@ namespace ams::fs {
|
|||
}
|
||||
|
||||
virtual Result SetSize(s64 size) override {
|
||||
/* Ensure we're initialized and validate arguments. */
|
||||
R_UNLESS(this->IsValid(), fs::ResultNotInitialized());
|
||||
R_UNLESS(this->resizable, fs::ResultUnsupportedOperation());
|
||||
R_UNLESS(IStorage::IsOffsetAndSizeValid(this->offset, size), fs::ResultInvalidSize());
|
||||
|
||||
/* Ensure that we're allowed to set size. */
|
||||
s64 cur_size;
|
||||
R_TRY(this->base_storage->GetSize(std::addressof(cur_size)));
|
||||
|
||||
R_UNLESS(cur_size == this->offset + this->size, fs::ResultUnsupportedOperation());
|
||||
|
||||
/* Set the size. */
|
||||
R_TRY(this->base_storage->SetSize(this->offset + size));
|
||||
|
||||
this->size = size;
|
||||
|
@ -106,14 +119,21 @@ namespace ams::fs {
|
|||
}
|
||||
|
||||
virtual Result GetSize(s64 *out) override {
|
||||
/* Ensure we're initialized. */
|
||||
R_UNLESS(this->IsValid(), fs::ResultNotInitialized());
|
||||
|
||||
*out = this->size;
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
virtual Result OperateRange(void *dst, size_t dst_size, OperationId op_id, s64 offset, s64 size, const void *src, size_t src_size) override {
|
||||
/* Ensure we're initialized. */
|
||||
R_UNLESS(this->IsValid(), fs::ResultNotInitialized());
|
||||
R_UNLESS(size != 0, ResultSuccess());
|
||||
|
||||
/* Succeed immediately on zero-sized operation. */
|
||||
R_SUCCEED_IF(size == 0);
|
||||
|
||||
/* Validate arguments and operate. */
|
||||
R_UNLESS(IStorage::IsOffsetAndSizeValid(offset, size), fs::ResultOutOfRange());
|
||||
return this->base_storage->OperateRange(dst, dst_size, op_id, this->offset + offset, size, src, src_size);
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ namespace ams::spl {
|
|||
|
||||
constexpr inline ::ams::Result ConvertResult(Result smc_result) {
|
||||
/* smc::Result::Success becomes ResultSuccess() directly. */
|
||||
R_UNLESS(smc_result != Result::Success, ResultSuccess());
|
||||
R_SUCCEED_IF(smc_result == smc::Result::Success);
|
||||
|
||||
/* Convert to the list of known SecureMonitorErrors. */
|
||||
const auto converted = R_MAKE_NAMESPACE_RESULT(::ams::spl, static_cast<u32>(smc_result));
|
||||
|
|
|
@ -18,13 +18,13 @@
|
|||
namespace ams::fs {
|
||||
|
||||
Result FileStorage::UpdateSize() {
|
||||
R_UNLESS(this->size == InvalidSize, ResultSuccess());
|
||||
R_SUCCEED_IF(this->size != InvalidSize);
|
||||
return this->base_file->GetSize(&this->size);
|
||||
}
|
||||
|
||||
Result FileStorage::Read(s64 offset, void *buffer, size_t size) {
|
||||
/* Immediately succeed if there's nothing to read. */
|
||||
R_UNLESS(size > 0, ResultSuccess());
|
||||
R_SUCCEED_IF(size == 0);
|
||||
|
||||
/* Validate buffer. */
|
||||
R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument());
|
||||
|
@ -41,7 +41,7 @@ namespace ams::fs {
|
|||
|
||||
Result FileStorage::Write(s64 offset, const void *buffer, size_t size) {
|
||||
/* Immediately succeed if there's nothing to write. */
|
||||
R_UNLESS(size > 0, ResultSuccess());
|
||||
R_SUCCEED_IF(size == 0);
|
||||
|
||||
/* Validate buffer. */
|
||||
R_UNLESS(buffer != nullptr, fs::ResultNullptrArgument());
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace ams::fs {
|
|||
const char c = *(cur++);
|
||||
|
||||
/* If terminated, we're done. */
|
||||
R_UNLESS(c != StringTraits::NullTerminator, ResultSuccess());
|
||||
R_SUCCEED_IF(PathTool::IsNullTerminator(c));
|
||||
|
||||
/* TODO: Nintendo converts the path from utf-8 to utf-32, one character at a time. */
|
||||
/* We should do this. */
|
||||
|
|
|
@ -178,7 +178,7 @@ namespace ams::fssystem {
|
|||
|
||||
Result DirectorySaveDataFileSystem::CopySaveFromFileSystem(fs::fsa::IFileSystem *save_fs) {
|
||||
/* If the input save is null, there's nothing to copy. */
|
||||
R_UNLESS(save_fs != nullptr, ResultSuccess());
|
||||
R_SUCCEED_IF(save_fs == nullptr);
|
||||
|
||||
/* Get a work buffer to work with. */
|
||||
std::unique_ptr<u8[]> work_buf;
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace ams::lr {
|
|||
|
||||
Result ContentLocationResolverImpl::ResolveProgramPath(sf::Out<Path> out, ncm::ProgramId id) {
|
||||
/* Use a redirection if present. */
|
||||
R_UNLESS(!this->program_redirector.FindRedirection(out.GetPointer(), id), ResultSuccess());
|
||||
R_SUCCEED_IF(this->program_redirector.FindRedirection(out.GetPointer(), id));
|
||||
|
||||
/* Find the latest program content for the program id. */
|
||||
ncm::ContentId program_content_id;
|
||||
|
@ -164,7 +164,7 @@ namespace ams::lr {
|
|||
|
||||
Result ContentLocationResolverImpl::ResolveProgramPathForDebug(sf::Out<Path> out, ncm::ProgramId id) {
|
||||
/* Use a redirection if present. */
|
||||
R_UNLESS(!this->debug_program_redirector.FindRedirection(out.GetPointer(), id), ResultSuccess());
|
||||
R_SUCCEED_IF(this->debug_program_redirector.FindRedirection(out.GetPointer(), id));
|
||||
|
||||
/* Otherwise find the path for the program id. */
|
||||
R_TRY_CATCH(this->ResolveProgramPath(out.GetPointer(), id)) {
|
||||
|
|
|
@ -128,13 +128,11 @@ namespace ams::lr {
|
|||
}
|
||||
|
||||
Result RedirectOnlyLocationResolverImpl::ResolveProgramPathForDebug(sf::Out<Path> out, ncm::ProgramId id) {
|
||||
/* Use a redirection if present. */
|
||||
R_UNLESS(!this->debug_program_redirector.FindRedirection(out.GetPointer(), id), ResultSuccess());
|
||||
/* If a debug program redirection is present, use it. */
|
||||
R_SUCCEED_IF(this->debug_program_redirector.FindRedirection(out.GetPointer(), id));
|
||||
|
||||
/* Otherwise find the path for the program id. */
|
||||
R_TRY_CATCH(this->ResolveProgramPath(out.GetPointer(), id)) {
|
||||
R_CONVERT(ResultProgramNotFound, lr::ResultDebugProgramNotFound())
|
||||
} R_END_TRY_CATCH;
|
||||
/* Otherwise, try to find a normal program redirection. */
|
||||
R_UNLESS(this->program_redirector.FindRedirection(out.GetPointer(), id), lr::ResultDebugProgramNotFound());
|
||||
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
|
|
@ -98,7 +98,7 @@ namespace ams::mitm::fs {
|
|||
Result LayeredRomfsStorage::Read(s64 offset, void *buffer, size_t size) {
|
||||
/* Check if we can succeed immediately. */
|
||||
R_UNLESS(size >= 0, fs::ResultInvalidSize());
|
||||
R_UNLESS(size > 0, ResultSuccess());
|
||||
R_SUCCEED_IF(size == 0);
|
||||
|
||||
/* Ensure we're initialized. */
|
||||
if (!this->is_initialized) {
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace ams::boot {
|
|||
u64 cur_time = 0;
|
||||
while (true) {
|
||||
const auto retry_result = f();
|
||||
R_UNLESS(R_FAILED(retry_result), ResultSuccess());
|
||||
R_SUCCEED_IF(R_SUCCEEDED(retry_result));
|
||||
|
||||
cur_time += retry_interval;
|
||||
if (cur_time < timeout) {
|
||||
|
|
|
@ -379,7 +379,8 @@ namespace ams::i2c::driver::impl {
|
|||
|
||||
/* Wait for flush to finish, check every ms for 5 ms. */
|
||||
for (size_t i = 0; i < 5; i++) {
|
||||
R_UNLESS((reg::Read(&this->i2c_registers->I2C_FIFO_CONTROL_0) & 3), ResultSuccess());
|
||||
const bool flush_done = (reg::Read(&this->i2c_registers->I2C_FIFO_CONTROL_0) & 3) == 0;
|
||||
R_SUCCEED_IF(flush_done);
|
||||
svcSleepThread(1'000'000ul);
|
||||
}
|
||||
|
||||
|
@ -418,7 +419,8 @@ namespace ams::i2c::driver::impl {
|
|||
|
||||
Result BusAccessor::GetAndHandleTransactionResult() {
|
||||
const auto transaction_result = this->GetTransactionResult();
|
||||
R_UNLESS(R_FAILED(transaction_result), ResultSuccess());
|
||||
R_SUCCEED_IF(R_SUCCEEDED(transaction_result));
|
||||
|
||||
this->HandleTransactionResult(transaction_result);
|
||||
this->ClearInterruptMask();
|
||||
this->interrupt_event.Reset();
|
||||
|
|
|
@ -602,7 +602,7 @@ namespace ams::dmnt::cheat::impl {
|
|||
{
|
||||
if (this->HasActiveCheatProcess()) {
|
||||
/* When forcing attach, we're done. */
|
||||
R_UNLESS(on_process_launch, ResultSuccess());
|
||||
R_SUCCEED_IF(!on_process_launch);
|
||||
}
|
||||
|
||||
/* Detach from the current process, if it's open. */
|
||||
|
|
|
@ -49,7 +49,7 @@ namespace ams::dmnt {
|
|||
|
||||
Result EnsureSdInitialized() {
|
||||
std::scoped_lock lk(g_sd_lock);
|
||||
R_UNLESS(!g_sd_initialized, ResultSuccess());
|
||||
R_SUCCEED_IF(g_sd_initialized);
|
||||
|
||||
R_TRY(fsOpenSdCardFileSystem(&g_sd_fs));
|
||||
g_sd_initialized = true;
|
||||
|
|
|
@ -64,8 +64,8 @@ namespace ams::fatal::srv {
|
|||
|
||||
/* Throw implementation. */
|
||||
Result ServiceContext::ThrowFatalWithCpuContext(Result result, os::ProcessId process_id, FatalPolicy policy, const CpuContext &cpu_ctx) {
|
||||
/* We don't support Error Report only fatals. */
|
||||
R_UNLESS(policy != FatalPolicy_ErrorReport, ResultSuccess());
|
||||
/* We don't support Error-Report-only fatals. */
|
||||
R_SUCCEED_IF(policy == FatalPolicy_ErrorReport);
|
||||
|
||||
/* Note that we've thrown fatal. */
|
||||
R_TRY(this->TrySetHasThrown());
|
||||
|
|
|
@ -307,7 +307,7 @@ namespace ams::ldr {
|
|||
R_TRY(lr::OpenLocationResolver(std::addressof(lr), static_cast<ncm::StorageId>(loc.storage_id)));
|
||||
|
||||
/* If there's already a Html Document path, we don't need to set one. */
|
||||
R_UNLESS(R_FAILED(lr.ResolveApplicationHtmlDocumentPath(std::addressof(path), loc.program_id)), ResultSuccess());
|
||||
R_SUCCEED_IF(R_SUCCEEDED(lr.ResolveApplicationHtmlDocumentPath(std::addressof(path), loc.program_id)));
|
||||
|
||||
/* We just need to set this to any valid NCA path. Let's use the executable path. */
|
||||
R_TRY(lr.ResolveProgramPath(std::addressof(path), loc.program_id));
|
||||
|
|
|
@ -84,7 +84,10 @@ namespace ams::ldr {
|
|||
#include "ldr_anti_downgrade_tables.inc"
|
||||
|
||||
Result ValidateProgramVersion(ncm::ProgramId program_id, u32 version) {
|
||||
R_UNLESS(hos::GetVersion() >= hos::Version_810, ResultSuccess());
|
||||
/* No version verification is done before 8.1.0. */
|
||||
R_SUCCEED_IF(hos::GetVersion() < hos::Version_810);
|
||||
|
||||
/* Do version-dependent validation, if compiled to do so. */
|
||||
#ifdef LDR_VALIDATE_PROCESS_VERSION
|
||||
const MinimumProgramVersion *entries = nullptr;
|
||||
size_t num_entries = 0;
|
||||
|
|
|
@ -297,7 +297,7 @@ namespace ams::sm::impl {
|
|||
is_valid &= std::memcmp(&ac_service, &service, access_control.GetServiceNameSize() - 1) == 0;
|
||||
}
|
||||
|
||||
R_UNLESS(!is_valid, ResultSuccess());
|
||||
R_SUCCEED_IF(is_valid);
|
||||
}
|
||||
access_control = access_control.GetNextEntry();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue