diff options
Diffstat (limited to 'src/core/hle')
| -rw-r--r-- | src/core/hle/kernel/client_port.cpp | 4 | ||||
| -rw-r--r-- | src/core/hle/kernel/client_session.cpp | 4 | ||||
| -rw-r--r-- | src/core/hle/kernel/errors.h | 43 | ||||
| -rw-r--r-- | src/core/hle/kernel/handle_table.cpp | 10 | ||||
| -rw-r--r-- | src/core/hle/kernel/hle_ipc.cpp | 2 | ||||
| -rw-r--r-- | src/core/hle/kernel/k_address_arbiter.cpp | 28 | ||||
| -rw-r--r-- | src/core/hle/kernel/k_condition_variable.cpp | 20 | ||||
| -rw-r--r-- | src/core/hle/kernel/k_readable_event.cpp | 3 | ||||
| -rw-r--r-- | src/core/hle/kernel/k_resource_limit.cpp | 2 | ||||
| -rw-r--r-- | src/core/hle/kernel/k_synchronization_object.cpp | 8 | ||||
| -rw-r--r-- | src/core/hle/kernel/k_thread.cpp | 30 | ||||
| -rw-r--r-- | src/core/hle/kernel/kernel.cpp | 2 | ||||
| -rw-r--r-- | src/core/hle/kernel/memory/memory_manager.cpp | 6 | ||||
| -rw-r--r-- | src/core/hle/kernel/memory/page_table.cpp | 48 | ||||
| -rw-r--r-- | src/core/hle/kernel/process.cpp | 5 | ||||
| -rw-r--r-- | src/core/hle/kernel/process_capability.cpp | 34 | ||||
| -rw-r--r-- | src/core/hle/kernel/server_port.cpp | 4 | ||||
| -rw-r--r-- | src/core/hle/kernel/svc.cpp | 196 | ||||
| -rw-r--r-- | src/core/hle/kernel/svc_results.h | 21 | ||||
| -rw-r--r-- | src/core/hle/service/ldr/ldr.cpp | 6 | 
20 files changed, 222 insertions, 254 deletions
| diff --git a/src/core/hle/kernel/client_port.cpp b/src/core/hle/kernel/client_port.cpp index f8f005f15..0b6957e31 100644 --- a/src/core/hle/kernel/client_port.cpp +++ b/src/core/hle/kernel/client_port.cpp @@ -4,11 +4,11 @@  #include "core/hle/kernel/client_port.h"  #include "core/hle/kernel/client_session.h" -#include "core/hle/kernel/errors.h"  #include "core/hle/kernel/hle_ipc.h"  #include "core/hle/kernel/object.h"  #include "core/hle/kernel/server_port.h"  #include "core/hle/kernel/session.h" +#include "core/hle/kernel/svc_results.h"  namespace Kernel { @@ -21,7 +21,7 @@ std::shared_ptr<ServerPort> ClientPort::GetServerPort() const {  ResultVal<std::shared_ptr<ClientSession>> ClientPort::Connect() {      if (active_sessions >= max_sessions) { -        return ERR_MAX_CONNECTIONS_REACHED; +        return ResultMaxConnectionsReached;      }      active_sessions++; diff --git a/src/core/hle/kernel/client_session.cpp b/src/core/hle/kernel/client_session.cpp index a2be1a8f6..e230f365a 100644 --- a/src/core/hle/kernel/client_session.cpp +++ b/src/core/hle/kernel/client_session.cpp @@ -3,11 +3,11 @@  // Refer to the license.txt file included.  #include "core/hle/kernel/client_session.h" -#include "core/hle/kernel/errors.h"  #include "core/hle/kernel/hle_ipc.h"  #include "core/hle/kernel/k_thread.h"  #include "core/hle/kernel/server_session.h"  #include "core/hle/kernel/session.h" +#include "core/hle/kernel/svc_results.h"  #include "core/hle/result.h"  namespace Kernel { @@ -43,7 +43,7 @@ ResultCode ClientSession::SendSyncRequest(std::shared_ptr<KThread> thread,                                            Core::Timing::CoreTiming& core_timing) {      // Keep ServerSession alive until we're done working with it.      if (!parent->Server()) { -        return ERR_SESSION_CLOSED_BY_REMOTE; +        return ResultSessionClosedByRemote;      }      // Signal the server session that new data is available diff --git a/src/core/hle/kernel/errors.h b/src/core/hle/kernel/errors.h deleted file mode 100644 index 7d32a39f0..000000000 --- a/src/core/hle/kernel/errors.h +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2018 yuzu emulator team -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#pragma once - -#include "core/hle/result.h" - -namespace Kernel { - -// Confirmed Switch kernel error codes - -constexpr ResultCode ERR_MAX_CONNECTIONS_REACHED{ErrorModule::Kernel, 7}; -constexpr ResultCode ERR_INVALID_CAPABILITY_DESCRIPTOR{ErrorModule::Kernel, 14}; -constexpr ResultCode ERR_THREAD_TERMINATING{ErrorModule::Kernel, 59}; -constexpr ResultCode ERR_TERMINATION_REQUESTED{ErrorModule::Kernel, 59}; -constexpr ResultCode ERR_INVALID_SIZE{ErrorModule::Kernel, 101}; -constexpr ResultCode ERR_INVALID_ADDRESS{ErrorModule::Kernel, 102}; -constexpr ResultCode ERR_OUT_OF_RESOURCES{ErrorModule::Kernel, 103}; -constexpr ResultCode ERR_OUT_OF_MEMORY{ErrorModule::Kernel, 104}; -constexpr ResultCode ERR_HANDLE_TABLE_FULL{ErrorModule::Kernel, 105}; -constexpr ResultCode ERR_INVALID_ADDRESS_STATE{ErrorModule::Kernel, 106}; -constexpr ResultCode ERR_INVALID_CURRENT_MEMORY{ErrorModule::Kernel, 106}; -constexpr ResultCode ERR_INVALID_MEMORY_PERMISSIONS{ErrorModule::Kernel, 108}; -constexpr ResultCode ERR_INVALID_MEMORY_RANGE{ErrorModule::Kernel, 110}; -constexpr ResultCode ERR_INVALID_PROCESSOR_ID{ErrorModule::Kernel, 113}; -constexpr ResultCode ERR_INVALID_THREAD_PRIORITY{ErrorModule::Kernel, 112}; -constexpr ResultCode ERR_INVALID_HANDLE{ErrorModule::Kernel, 114}; -constexpr ResultCode ERR_INVALID_POINTER{ErrorModule::Kernel, 115}; -constexpr ResultCode ERR_INVALID_COMBINATION{ErrorModule::Kernel, 116}; -constexpr ResultCode RESULT_TIMEOUT{ErrorModule::Kernel, 117}; -constexpr ResultCode ERR_SYNCHRONIZATION_CANCELED{ErrorModule::Kernel, 118}; -constexpr ResultCode ERR_CANCELLED{ErrorModule::Kernel, 118}; -constexpr ResultCode ERR_OUT_OF_RANGE{ErrorModule::Kernel, 119}; -constexpr ResultCode ERR_INVALID_ENUM_VALUE{ErrorModule::Kernel, 120}; -constexpr ResultCode ERR_NOT_FOUND{ErrorModule::Kernel, 121}; -constexpr ResultCode ERR_BUSY{ErrorModule::Kernel, 122}; -constexpr ResultCode ERR_SESSION_CLOSED_BY_REMOTE{ErrorModule::Kernel, 123}; -constexpr ResultCode ERR_INVALID_STATE{ErrorModule::Kernel, 125}; -constexpr ResultCode ERR_RESERVED_VALUE{ErrorModule::Kernel, 126}; -constexpr ResultCode ERR_RESOURCE_LIMIT_EXCEEDED{ErrorModule::Kernel, 132}; - -} // namespace Kernel diff --git a/src/core/hle/kernel/handle_table.cpp b/src/core/hle/kernel/handle_table.cpp index 1a2fa9cd8..f96d34078 100644 --- a/src/core/hle/kernel/handle_table.cpp +++ b/src/core/hle/kernel/handle_table.cpp @@ -6,12 +6,12 @@  #include "common/assert.h"  #include "common/logging/log.h"  #include "core/core.h" -#include "core/hle/kernel/errors.h"  #include "core/hle/kernel/handle_table.h"  #include "core/hle/kernel/k_scheduler.h"  #include "core/hle/kernel/k_thread.h"  #include "core/hle/kernel/kernel.h"  #include "core/hle/kernel/process.h" +#include "core/hle/kernel/svc_results.h"  namespace Kernel {  namespace { @@ -33,7 +33,7 @@ HandleTable::~HandleTable() = default;  ResultCode HandleTable::SetSize(s32 handle_table_size) {      if (static_cast<u32>(handle_table_size) > MAX_COUNT) {          LOG_ERROR(Kernel, "Handle table size {} is greater than {}", handle_table_size, MAX_COUNT); -        return ERR_OUT_OF_MEMORY; +        return ResultOutOfMemory;      }      // Values less than or equal to zero indicate to use the maximum allowable @@ -53,7 +53,7 @@ ResultVal<Handle> HandleTable::Create(std::shared_ptr<Object> obj) {      const u16 slot = next_free_slot;      if (slot >= table_size) {          LOG_ERROR(Kernel, "Unable to allocate Handle, too many slots in use."); -        return ERR_HANDLE_TABLE_FULL; +        return ResultHandleTableFull;      }      next_free_slot = generations[slot]; @@ -76,7 +76,7 @@ ResultVal<Handle> HandleTable::Duplicate(Handle handle) {      std::shared_ptr<Object> object = GetGeneric(handle);      if (object == nullptr) {          LOG_ERROR(Kernel, "Tried to duplicate invalid handle: {:08X}", handle); -        return ERR_INVALID_HANDLE; +        return ResultInvalidHandle;      }      return Create(std::move(object));  } @@ -84,7 +84,7 @@ ResultVal<Handle> HandleTable::Duplicate(Handle handle) {  ResultCode HandleTable::Close(Handle handle) {      if (!IsValid(handle)) {          LOG_ERROR(Kernel, "Handle is not valid! handle={:08X}", handle); -        return ERR_INVALID_HANDLE; +        return ResultInvalidHandle;      }      const u16 slot = GetSlot(handle); diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp index 7ec62cf18..161d9f782 100644 --- a/src/core/hle/kernel/hle_ipc.cpp +++ b/src/core/hle/kernel/hle_ipc.cpp @@ -14,7 +14,6 @@  #include "common/common_types.h"  #include "common/logging/log.h"  #include "core/hle/ipc_helpers.h" -#include "core/hle/kernel/errors.h"  #include "core/hle/kernel/handle_table.h"  #include "core/hle/kernel/hle_ipc.h"  #include "core/hle/kernel/k_readable_event.h" @@ -26,6 +25,7 @@  #include "core/hle/kernel/object.h"  #include "core/hle/kernel/process.h"  #include "core/hle/kernel/server_session.h" +#include "core/hle/kernel/svc_results.h"  #include "core/hle/kernel/time_manager.h"  #include "core/memory.h" diff --git a/src/core/hle/kernel/k_address_arbiter.cpp b/src/core/hle/kernel/k_address_arbiter.cpp index d0e90fd60..7018f56da 100644 --- a/src/core/hle/kernel/k_address_arbiter.cpp +++ b/src/core/hle/kernel/k_address_arbiter.cpp @@ -120,10 +120,10 @@ ResultCode KAddressArbiter::SignalAndIncrementIfEqual(VAddr addr, s32 value, s32          s32 user_value{};          if (!UpdateIfEqual(system, &user_value, addr, value, value + 1)) {              LOG_ERROR(Kernel, "Invalid current memory!"); -            return Svc::ResultInvalidCurrentMemory; +            return ResultInvalidCurrentMemory;          }          if (user_value != value) { -            return Svc::ResultInvalidState; +            return ResultInvalidState;          }          auto it = thread_tree.nfind_light({addr, -1}); @@ -189,10 +189,10 @@ ResultCode KAddressArbiter::SignalAndModifyByWaitingCountIfEqual(VAddr addr, s32          if (!succeeded) {              LOG_ERROR(Kernel, "Invalid current memory!"); -            return Svc::ResultInvalidCurrentMemory; +            return ResultInvalidCurrentMemory;          }          if (user_value != value) { -            return Svc::ResultInvalidState; +            return ResultInvalidState;          }          while ((it != thread_tree.end()) && (count <= 0 || num_waiters < count) && @@ -221,11 +221,11 @@ ResultCode KAddressArbiter::WaitIfLessThan(VAddr addr, s32 value, bool decrement          // Check that the thread isn't terminating.          if (cur_thread->IsTerminationRequested()) {              slp.CancelSleep(); -            return Svc::ResultTerminationRequested; +            return ResultTerminationRequested;          }          // Set the synced object. -        cur_thread->SetSyncedObject(nullptr, Svc::ResultTimedOut); +        cur_thread->SetSyncedObject(nullptr, ResultTimedOut);          // Read the value from userspace.          s32 user_value{}; @@ -238,19 +238,19 @@ ResultCode KAddressArbiter::WaitIfLessThan(VAddr addr, s32 value, bool decrement          if (!succeeded) {              slp.CancelSleep(); -            return Svc::ResultInvalidCurrentMemory; +            return ResultInvalidCurrentMemory;          }          // Check that the value is less than the specified one.          if (user_value >= value) {              slp.CancelSleep(); -            return Svc::ResultInvalidState; +            return ResultInvalidState;          }          // Check that the timeout is non-zero.          if (timeout == 0) {              slp.CancelSleep(); -            return Svc::ResultTimedOut; +            return ResultTimedOut;          }          // Set the arbiter. @@ -288,29 +288,29 @@ ResultCode KAddressArbiter::WaitIfEqual(VAddr addr, s32 value, s64 timeout) {          // Check that the thread isn't terminating.          if (cur_thread->IsTerminationRequested()) {              slp.CancelSleep(); -            return Svc::ResultTerminationRequested; +            return ResultTerminationRequested;          }          // Set the synced object. -        cur_thread->SetSyncedObject(nullptr, Svc::ResultTimedOut); +        cur_thread->SetSyncedObject(nullptr, ResultTimedOut);          // Read the value from userspace.          s32 user_value{};          if (!ReadFromUser(system, &user_value, addr)) {              slp.CancelSleep(); -            return Svc::ResultInvalidCurrentMemory; +            return ResultInvalidCurrentMemory;          }          // Check that the value is equal.          if (value != user_value) {              slp.CancelSleep(); -            return Svc::ResultInvalidState; +            return ResultInvalidState;          }          // Check that the timeout is non-zero.          if (timeout == 0) {              slp.CancelSleep(); -            return Svc::ResultTimedOut; +            return ResultTimedOut;          }          // Set the arbiter. diff --git a/src/core/hle/kernel/k_condition_variable.cpp b/src/core/hle/kernel/k_condition_variable.cpp index f0ad8b390..170d8fa0d 100644 --- a/src/core/hle/kernel/k_condition_variable.cpp +++ b/src/core/hle/kernel/k_condition_variable.cpp @@ -92,10 +92,10 @@ ResultCode KConditionVariable::SignalToAddress(VAddr addr) {          // Write the value to userspace.          if (!WriteToUser(system, addr, std::addressof(next_value))) {              if (next_owner_thread) { -                next_owner_thread->SetSyncedObject(nullptr, Svc::ResultInvalidCurrentMemory); +                next_owner_thread->SetSyncedObject(nullptr, ResultInvalidCurrentMemory);              } -            return Svc::ResultInvalidCurrentMemory; +            return ResultInvalidCurrentMemory;          }      } @@ -114,20 +114,20 @@ ResultCode KConditionVariable::WaitForAddress(Handle handle, VAddr addr, u32 val              cur_thread->SetSyncedObject(nullptr, RESULT_SUCCESS);              // Check if the thread should terminate. -            R_UNLESS(!cur_thread->IsTerminationRequested(), Svc::ResultTerminationRequested); +            R_UNLESS(!cur_thread->IsTerminationRequested(), ResultTerminationRequested);              {                  // Read the tag from userspace.                  u32 test_tag{};                  R_UNLESS(ReadFromUser(system, std::addressof(test_tag), addr), -                         Svc::ResultInvalidCurrentMemory); +                         ResultInvalidCurrentMemory);                  // If the tag isn't the handle (with wait mask), we're done.                  R_UNLESS(test_tag == (handle | Svc::HandleWaitMask), RESULT_SUCCESS);                  // Get the lock owner thread.                  owner_thread = kernel.CurrentProcess()->GetHandleTable().Get<KThread>(handle); -                R_UNLESS(owner_thread, Svc::ResultInvalidHandle); +                R_UNLESS(owner_thread, ResultInvalidHandle);                  // Update the lock.                  cur_thread->SetAddressKey(addr, value); @@ -191,13 +191,13 @@ KThread* KConditionVariable::SignalImpl(KThread* thread) {                  thread_to_close = owner_thread.get();              } else {                  // The lock was tagged with a thread that doesn't exist. -                thread->SetSyncedObject(nullptr, Svc::ResultInvalidState); +                thread->SetSyncedObject(nullptr, ResultInvalidState);                  thread->Wakeup();              }          }      } else {          // If the address wasn't accessible, note so. -        thread->SetSyncedObject(nullptr, Svc::ResultInvalidCurrentMemory); +        thread->SetSyncedObject(nullptr, ResultInvalidCurrentMemory);          thread->Wakeup();      } @@ -263,12 +263,12 @@ ResultCode KConditionVariable::Wait(VAddr addr, u64 key, u32 value, s64 timeout)          KScopedSchedulerLockAndSleep slp{kernel, cur_thread, timeout};          // Set the synced object. -        cur_thread->SetSyncedObject(nullptr, Svc::ResultTimedOut); +        cur_thread->SetSyncedObject(nullptr, ResultTimedOut);          // Check that the thread isn't terminating.          if (cur_thread->IsTerminationRequested()) {              slp.CancelSleep(); -            return Svc::ResultTerminationRequested; +            return ResultTerminationRequested;          }          // Update the value and process for the next owner. @@ -302,7 +302,7 @@ ResultCode KConditionVariable::Wait(VAddr addr, u64 key, u32 value, s64 timeout)              // Write the value to userspace.              if (!WriteToUser(system, addr, std::addressof(next_value))) {                  slp.CancelSleep(); -                return Svc::ResultInvalidCurrentMemory; +                return ResultInvalidCurrentMemory;              }          } diff --git a/src/core/hle/kernel/k_readable_event.cpp b/src/core/hle/kernel/k_readable_event.cpp index d8a42dbaf..4b4d34857 100644 --- a/src/core/hle/kernel/k_readable_event.cpp +++ b/src/core/hle/kernel/k_readable_event.cpp @@ -6,7 +6,6 @@  #include "common/assert.h"  #include "common/common_funcs.h"  #include "common/logging/log.h" -#include "core/hle/kernel/errors.h"  #include "core/hle/kernel/k_readable_event.h"  #include "core/hle/kernel/k_scheduler.h"  #include "core/hle/kernel/k_thread.h" @@ -47,7 +46,7 @@ ResultCode KReadableEvent::Reset() {      KScopedSchedulerLock lk{kernel};      if (!is_signaled) { -        return Svc::ResultInvalidState; +        return ResultInvalidState;      }      is_signaled = false; diff --git a/src/core/hle/kernel/k_resource_limit.cpp b/src/core/hle/kernel/k_resource_limit.cpp index ab2ab683f..d7a4a38e6 100644 --- a/src/core/hle/kernel/k_resource_limit.cpp +++ b/src/core/hle/kernel/k_resource_limit.cpp @@ -75,7 +75,7 @@ s64 KResourceLimit::GetFreeValue(LimitableResource which) const {  ResultCode KResourceLimit::SetLimitValue(LimitableResource which, s64 value) {      const auto index = static_cast<std::size_t>(which);      KScopedLightLock lk(lock); -    R_UNLESS(current_values[index] <= value, Svc::ResultInvalidState); +    R_UNLESS(current_values[index] <= value, ResultInvalidState);      limit_values[index] = value; diff --git a/src/core/hle/kernel/k_synchronization_object.cpp b/src/core/hle/kernel/k_synchronization_object.cpp index 140cc46a7..82f72a0fe 100644 --- a/src/core/hle/kernel/k_synchronization_object.cpp +++ b/src/core/hle/kernel/k_synchronization_object.cpp @@ -40,20 +40,20 @@ ResultCode KSynchronizationObject::Wait(KernelCore& kernel, s32* out_index,          // Check if the timeout is zero.          if (timeout == 0) {              slp.CancelSleep(); -            return Svc::ResultTimedOut; +            return ResultTimedOut;          }          // Check if the thread should terminate.          if (thread->IsTerminationRequested()) {              slp.CancelSleep(); -            return Svc::ResultTerminationRequested; +            return ResultTerminationRequested;          }          // Check if waiting was canceled.          if (thread->IsWaitCancelled()) {              slp.CancelSleep();              thread->ClearWaitCancelled(); -            return Svc::ResultCancelled; +            return ResultCancelled;          }          // Add the waiters. @@ -75,7 +75,7 @@ ResultCode KSynchronizationObject::Wait(KernelCore& kernel, s32* out_index,          // Mark the thread as waiting.          thread->SetCancellable(); -        thread->SetSyncedObject(nullptr, Svc::ResultTimedOut); +        thread->SetSyncedObject(nullptr, ResultTimedOut);          thread->SetState(ThreadState::Waiting);          thread->SetWaitReasonForDebugging(ThreadWaitReasonForDebugging::Synchronization);      } diff --git a/src/core/hle/kernel/k_thread.cpp b/src/core/hle/kernel/k_thread.cpp index b59259c4f..e5620da5a 100644 --- a/src/core/hle/kernel/k_thread.cpp +++ b/src/core/hle/kernel/k_thread.cpp @@ -18,7 +18,6 @@  #include "core/core.h"  #include "core/cpu_manager.h"  #include "core/hardware_properties.h" -#include "core/hle/kernel/errors.h"  #include "core/hle/kernel/handle_table.h"  #include "core/hle/kernel/k_condition_variable.h"  #include "core/hle/kernel/k_resource_limit.h" @@ -127,7 +126,7 @@ ResultCode KThread::Initialize(KThreadFunction func, uintptr_t arg, VAddr user_s      // Set core ID and wait result.      core_id = phys_core; -    wait_result = Svc::ResultNoSynchronizationObject; +    wait_result = ResultNoSynchronizationObject;      // Set priorities.      priority = prio; @@ -238,7 +237,7 @@ void KThread::Finalize() {          while (it != waiter_list.end()) {              // The thread shouldn't be a kernel waiter.              it->SetLockOwner(nullptr); -            it->SetSyncedObject(nullptr, Svc::ResultInvalidState); +            it->SetSyncedObject(nullptr, ResultInvalidState);              it->Wakeup();              it = waiter_list.erase(it);          } @@ -447,7 +446,7 @@ ResultCode KThread::SetCoreMask(s32 core_id, u64 v_affinity_mask) {          // If the core id is no-update magic, preserve the ideal core id.          if (core_id == Svc::IdealCoreNoUpdate) {              core_id = virtual_ideal_core_id; -            R_UNLESS(((1ULL << core_id) & v_affinity_mask) != 0, Svc::ResultInvalidCombination); +            R_UNLESS(((1ULL << core_id) & v_affinity_mask) != 0, ResultInvalidCombination);          }          // Set the virtual core/affinity mask. @@ -526,7 +525,7 @@ ResultCode KThread::SetCoreMask(s32 core_id, u64 v_affinity_mask) {                  if (GetStackParameters().is_pinned) {                      // Verify that the current thread isn't terminating.                      R_UNLESS(!GetCurrentThread(kernel).IsTerminationRequested(), -                             Svc::ResultTerminationRequested); +                             ResultTerminationRequested);                      // Note that the thread was pinned.                      thread_is_pinned = true; @@ -604,7 +603,7 @@ void KThread::WaitCancel() {              sleeping_queue->WakeupThread(this);              wait_cancelled = true;          } else { -            SetSyncedObject(nullptr, Svc::ResultCancelled); +            SetSyncedObject(nullptr, ResultCancelled);              SetState(ThreadState::Runnable);              wait_cancelled = false;          } @@ -663,12 +662,12 @@ ResultCode KThread::SetActivity(Svc::ThreadActivity activity) {          // Verify our state.          const auto cur_state = GetState();          R_UNLESS((cur_state == ThreadState::Waiting || cur_state == ThreadState::Runnable), -                 Svc::ResultInvalidState); +                 ResultInvalidState);          // Either pause or resume.          if (activity == Svc::ThreadActivity::Paused) {              // Verify that we're not suspended. -            R_UNLESS(!IsSuspendRequested(SuspendType::Thread), Svc::ResultInvalidState); +            R_UNLESS(!IsSuspendRequested(SuspendType::Thread), ResultInvalidState);              // Suspend.              RequestSuspend(SuspendType::Thread); @@ -676,7 +675,7 @@ ResultCode KThread::SetActivity(Svc::ThreadActivity activity) {              ASSERT(activity == Svc::ThreadActivity::Runnable);              // Verify that we're suspended. -            R_UNLESS(IsSuspendRequested(SuspendType::Thread), Svc::ResultInvalidState); +            R_UNLESS(IsSuspendRequested(SuspendType::Thread), ResultInvalidState);              // Resume.              Resume(SuspendType::Thread); @@ -698,7 +697,7 @@ ResultCode KThread::SetActivity(Svc::ThreadActivity activity) {              if (GetStackParameters().is_pinned) {                  // Verify that the current thread isn't terminating.                  R_UNLESS(!GetCurrentThread(kernel).IsTerminationRequested(), -                         Svc::ResultTerminationRequested); +                         ResultTerminationRequested);                  // Note that the thread was pinned and not current.                  thread_is_pinned = true; @@ -745,7 +744,7 @@ ResultCode KThread::GetThreadContext3(std::vector<u8>& out) {          KScopedSchedulerLock sl{kernel};          // Verify that we're suspended. -        R_UNLESS(IsSuspendRequested(SuspendType::Thread), Svc::ResultInvalidState); +        R_UNLESS(IsSuspendRequested(SuspendType::Thread), ResultInvalidState);          // If we're not terminating, get the thread's user context.          if (!IsTerminationRequested()) { @@ -905,12 +904,11 @@ ResultCode KThread::Run() {          KScopedSchedulerLock lk{kernel};          // If either this thread or the current thread are requesting termination, note it. -        R_UNLESS(!IsTerminationRequested(), Svc::ResultTerminationRequested); -        R_UNLESS(!GetCurrentThread(kernel).IsTerminationRequested(), -                 Svc::ResultTerminationRequested); +        R_UNLESS(!IsTerminationRequested(), ResultTerminationRequested); +        R_UNLESS(!GetCurrentThread(kernel).IsTerminationRequested(), ResultTerminationRequested);          // Ensure our thread state is correct. -        R_UNLESS(GetState() == ThreadState::Initialized, Svc::ResultInvalidState); +        R_UNLESS(GetState() == ThreadState::Initialized, ResultInvalidState);          // If the current thread has been asked to suspend, suspend it and retry.          if (GetCurrentThread(kernel).IsSuspended()) { @@ -962,7 +960,7 @@ ResultCode KThread::Sleep(s64 timeout) {          // Check if the thread should terminate.          if (IsTerminationRequested()) {              slp.CancelSleep(); -            return Svc::ResultTerminationRequested; +            return ResultTerminationRequested;          }          // Mark the thread as waiting. diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index b20c2d13a..8da5a5c86 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp @@ -26,7 +26,6 @@  #include "core/device_memory.h"  #include "core/hardware_properties.h"  #include "core/hle/kernel/client_port.h" -#include "core/hle/kernel/errors.h"  #include "core/hle/kernel/handle_table.h"  #include "core/hle/kernel/k_resource_limit.h"  #include "core/hle/kernel/k_scheduler.h" @@ -39,6 +38,7 @@  #include "core/hle/kernel/process.h"  #include "core/hle/kernel/service_thread.h"  #include "core/hle/kernel/shared_memory.h" +#include "core/hle/kernel/svc_results.h"  #include "core/hle/kernel/time_manager.h"  #include "core/hle/lock.h"  #include "core/hle/result.h" diff --git a/src/core/hle/kernel/memory/memory_manager.cpp b/src/core/hle/kernel/memory/memory_manager.cpp index acf13585c..77f135cdc 100644 --- a/src/core/hle/kernel/memory/memory_manager.cpp +++ b/src/core/hle/kernel/memory/memory_manager.cpp @@ -8,9 +8,9 @@  #include "common/assert.h"  #include "common/common_types.h"  #include "common/scope_exit.h" -#include "core/hle/kernel/errors.h"  #include "core/hle/kernel/memory/memory_manager.h"  #include "core/hle/kernel/memory/page_linked_list.h" +#include "core/hle/kernel/svc_results.h"  namespace Kernel::Memory { @@ -95,7 +95,7 @@ ResultCode MemoryManager::Allocate(PageLinkedList& page_list, std::size_t num_pa      // Choose a heap based on our page size request      const s32 heap_index{PageHeap::GetBlockIndex(num_pages)};      if (heap_index < 0) { -        return ERR_OUT_OF_MEMORY; +        return ResultOutOfMemory;      }      // TODO (bunnei): Support multiple managers @@ -140,7 +140,7 @@ ResultCode MemoryManager::Allocate(PageLinkedList& page_list, std::size_t num_pa      // Only succeed if we allocated as many pages as we wanted      if (num_pages) { -        return ERR_OUT_OF_MEMORY; +        return ResultOutOfMemory;      }      // We succeeded! diff --git a/src/core/hle/kernel/memory/page_table.cpp b/src/core/hle/kernel/memory/page_table.cpp index 7de91c768..5947fc748 100644 --- a/src/core/hle/kernel/memory/page_table.cpp +++ b/src/core/hle/kernel/memory/page_table.cpp @@ -6,7 +6,6 @@  #include "common/assert.h"  #include "common/scope_exit.h"  #include "core/core.h" -#include "core/hle/kernel/errors.h"  #include "core/hle/kernel/k_resource_limit.h"  #include "core/hle/kernel/kernel.h"  #include "core/hle/kernel/memory/address_space_info.h" @@ -16,6 +15,7 @@  #include "core/hle/kernel/memory/page_table.h"  #include "core/hle/kernel/memory/system_control.h"  #include "core/hle/kernel/process.h" +#include "core/hle/kernel/svc_results.h"  #include "core/memory.h"  namespace Kernel::Memory { @@ -141,7 +141,7 @@ ResultCode PageTable::InitializeForProcess(FileSys::ProgramAddressSpaceType as_t          (alias_region_size + heap_region_size + stack_region_size + kernel_map_region_size)};      if (alloc_size < needed_size) {          UNREACHABLE(); -        return ERR_OUT_OF_MEMORY; +        return ResultOutOfMemory;      }      const std::size_t remaining_size{alloc_size - needed_size}; @@ -277,11 +277,11 @@ ResultCode PageTable::MapProcessCode(VAddr addr, std::size_t num_pages, MemorySt      const u64 size{num_pages * PageSize};      if (!CanContain(addr, size, state)) { -        return ERR_INVALID_ADDRESS_STATE; +        return ResultInvalidCurrentMemory;      }      if (IsRegionMapped(addr, size)) { -        return ERR_INVALID_ADDRESS_STATE; +        return ResultInvalidCurrentMemory;      }      PageLinkedList page_linked_list; @@ -307,7 +307,7 @@ ResultCode PageTable::MapProcessCodeMemory(VAddr dst_addr, VAddr src_addr, std::                                    MemoryAttribute::None, MemoryAttribute::IpcAndDeviceMapped));      if (IsRegionMapped(dst_addr, size)) { -        return ERR_INVALID_ADDRESS_STATE; +        return ResultInvalidCurrentMemory;      }      PageLinkedList page_linked_list; @@ -415,7 +415,7 @@ ResultCode PageTable::MapPhysicalMemory(VAddr addr, std::size_t size) {      if (process->GetResourceLimit() &&          !process->GetResourceLimit()->Reserve(LimitableResource::PhysicalMemory, remaining_size)) { -        return ERR_RESOURCE_LIMIT_EXCEEDED; +        return ResultResourceLimitedExceeded;      }      PageLinkedList page_linked_list; @@ -454,12 +454,12 @@ ResultCode PageTable::UnmapPhysicalMemory(VAddr addr, std::size_t size) {      block_manager->IterateForRange(addr, end_addr, [&](const MemoryInfo& info) {          if (info.state == MemoryState::Normal) {              if (info.attribute != MemoryAttribute::None) { -                result = ERR_INVALID_ADDRESS_STATE; +                result = ResultInvalidCurrentMemory;                  return;              }              mapped_size += GetSizeInRange(info, addr, end_addr);          } else if (info.state != MemoryState::Free) { -            result = ERR_INVALID_ADDRESS_STATE; +            result = ResultInvalidCurrentMemory;          }      }); @@ -526,7 +526,7 @@ ResultCode PageTable::Map(VAddr dst_addr, VAddr src_addr, std::size_t size) {          MemoryAttribute::Mask, MemoryAttribute::None, MemoryAttribute::IpcAndDeviceMapped));      if (IsRegionMapped(dst_addr, size)) { -        return ERR_INVALID_ADDRESS_STATE; +        return ResultInvalidCurrentMemory;      }      PageLinkedList page_linked_list; @@ -577,7 +577,7 @@ ResultCode PageTable::Unmap(VAddr dst_addr, VAddr src_addr, std::size_t size) {      AddRegionToPages(dst_addr, num_pages, dst_pages);      if (!dst_pages.IsEqual(src_pages)) { -        return ERR_INVALID_MEMORY_RANGE; +        return ResultInvalidMemoryRange;      }      { @@ -626,11 +626,11 @@ ResultCode PageTable::MapPages(VAddr addr, PageLinkedList& page_linked_list, Mem      const std::size_t size{num_pages * PageSize};      if (!CanContain(addr, size, state)) { -        return ERR_INVALID_ADDRESS_STATE; +        return ResultInvalidCurrentMemory;      }      if (IsRegionMapped(addr, num_pages * PageSize)) { -        return ERR_INVALID_ADDRESS_STATE; +        return ResultInvalidCurrentMemory;      }      CASCADE_CODE(MapPages(addr, page_linked_list, perm)); @@ -768,7 +768,7 @@ ResultCode PageTable::SetHeapCapacity(std::size_t new_heap_capacity) {  ResultVal<VAddr> PageTable::SetHeapSize(std::size_t size) {      if (size > heap_region_end - heap_region_start) { -        return ERR_OUT_OF_MEMORY; +        return ResultOutOfMemory;      }      const u64 previous_heap_size{GetHeapSize()}; @@ -784,7 +784,7 @@ ResultVal<VAddr> PageTable::SetHeapSize(std::size_t size) {          auto process{system.Kernel().CurrentProcess()};          if (process->GetResourceLimit() && delta != 0 &&              !process->GetResourceLimit()->Reserve(LimitableResource::PhysicalMemory, delta)) { -            return ERR_RESOURCE_LIMIT_EXCEEDED; +            return ResultResourceLimitedExceeded;          }          PageLinkedList page_linked_list; @@ -794,7 +794,7 @@ ResultVal<VAddr> PageTable::SetHeapSize(std::size_t size) {              system.Kernel().MemoryManager().Allocate(page_linked_list, num_pages, memory_pool));          if (IsRegionMapped(current_heap_addr, delta)) { -            return ERR_INVALID_ADDRESS_STATE; +            return ResultInvalidCurrentMemory;          }          CASCADE_CODE( @@ -816,17 +816,17 @@ ResultVal<VAddr> PageTable::AllocateAndMapMemory(std::size_t needed_num_pages, s      std::lock_guard lock{page_table_lock};      if (!CanContain(region_start, region_num_pages * PageSize, state)) { -        return ERR_INVALID_ADDRESS_STATE; +        return ResultInvalidCurrentMemory;      }      if (region_num_pages <= needed_num_pages) { -        return ERR_OUT_OF_MEMORY; +        return ResultOutOfMemory;      }      const VAddr addr{          AllocateVirtualMemory(region_start, region_num_pages, needed_num_pages, align)};      if (!addr) { -        return ERR_OUT_OF_MEMORY; +        return ResultOutOfMemory;      }      if (is_map_only) { @@ -1105,13 +1105,13 @@ constexpr ResultCode PageTable::CheckMemoryState(const MemoryInfo& info, MemoryS                                                   MemoryAttribute attr) const {      // Validate the states match expectation      if ((info.state & state_mask) != state) { -        return ERR_INVALID_ADDRESS_STATE; +        return ResultInvalidCurrentMemory;      }      if ((info.perm & perm_mask) != perm) { -        return ERR_INVALID_ADDRESS_STATE; +        return ResultInvalidCurrentMemory;      }      if ((info.attribute & attr_mask) != attr) { -        return ERR_INVALID_ADDRESS_STATE; +        return ResultInvalidCurrentMemory;      }      return RESULT_SUCCESS; @@ -1138,14 +1138,14 @@ ResultCode PageTable::CheckMemoryState(MemoryState* out_state, MemoryPermission*      while (true) {          // Validate the current block          if (!(info.state == first_state)) { -            return ERR_INVALID_ADDRESS_STATE; +            return ResultInvalidCurrentMemory;          }          if (!(info.perm == first_perm)) { -            return ERR_INVALID_ADDRESS_STATE; +            return ResultInvalidCurrentMemory;          }          if (!((info.attribute | static_cast<MemoryAttribute>(ignore_attr)) ==                (first_attr | static_cast<MemoryAttribute>(ignore_attr)))) { -            return ERR_INVALID_ADDRESS_STATE; +            return ResultInvalidCurrentMemory;          }          // Validate against the provided masks diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp index 2286b292d..39dc3898a 100644 --- a/src/core/hle/kernel/process.cpp +++ b/src/core/hle/kernel/process.cpp @@ -14,7 +14,6 @@  #include "core/device_memory.h"  #include "core/file_sys/program_metadata.h"  #include "core/hle/kernel/code_set.h" -#include "core/hle/kernel/errors.h"  #include "core/hle/kernel/k_resource_limit.h"  #include "core/hle/kernel/k_scheduler.h"  #include "core/hle/kernel/k_thread.h" @@ -248,8 +247,8 @@ ResultCode Process::Reset() {      KScopedSchedulerLock sl{kernel};      // Validate that we're in a state that we can reset. -    R_UNLESS(status != ProcessStatus::Exited, Svc::ResultInvalidState); -    R_UNLESS(is_signaled, Svc::ResultInvalidState); +    R_UNLESS(status != ProcessStatus::Exited, ResultInvalidState); +    R_UNLESS(is_signaled, ResultInvalidState);      // Clear signaled.      is_signaled = false; diff --git a/src/core/hle/kernel/process_capability.cpp b/src/core/hle/kernel/process_capability.cpp index 0566311b6..7c567049e 100644 --- a/src/core/hle/kernel/process_capability.cpp +++ b/src/core/hle/kernel/process_capability.cpp @@ -6,10 +6,10 @@  #include "common/bit_util.h"  #include "common/logging/log.h" -#include "core/hle/kernel/errors.h"  #include "core/hle/kernel/handle_table.h"  #include "core/hle/kernel/memory/page_table.h"  #include "core/hle/kernel/process_capability.h" +#include "core/hle/kernel/svc_results.h"  namespace Kernel {  namespace { @@ -123,13 +123,13 @@ ResultCode ProcessCapabilities::ParseCapabilities(const u32* capabilities,              // If there's only one, then there's a problem.              if (i >= num_capabilities) {                  LOG_ERROR(Kernel, "Invalid combination! i={}", i); -                return ERR_INVALID_COMBINATION; +                return ResultInvalidCombination;              }              const auto size_flags = capabilities[i];              if (GetCapabilityType(size_flags) != CapabilityType::MapPhysical) {                  LOG_ERROR(Kernel, "Invalid capability type! size_flags={}", size_flags); -                return ERR_INVALID_COMBINATION; +                return ResultInvalidCombination;              }              const auto result = HandleMapPhysicalFlags(descriptor, size_flags, page_table); @@ -159,7 +159,7 @@ ResultCode ProcessCapabilities::ParseSingleFlagCapability(u32& set_flags, u32& s      const auto type = GetCapabilityType(flag);      if (type == CapabilityType::Unset) { -        return ERR_INVALID_CAPABILITY_DESCRIPTOR; +        return ResultInvalidCapabilityDescriptor;      }      // Bail early on ignorable entries, as one would expect, @@ -176,7 +176,7 @@ ResultCode ProcessCapabilities::ParseSingleFlagCapability(u32& set_flags, u32& s          LOG_ERROR(Kernel,                    "Attempted to initialize flags that may only be initialized once. set_flags={}",                    set_flags); -        return ERR_INVALID_COMBINATION; +        return ResultInvalidCombination;      }      set_flags |= set_flag; @@ -202,7 +202,7 @@ ResultCode ProcessCapabilities::ParseSingleFlagCapability(u32& set_flags, u32& s      }      LOG_ERROR(Kernel, "Invalid capability type! type={}", type); -    return ERR_INVALID_CAPABILITY_DESCRIPTOR; +    return ResultInvalidCapabilityDescriptor;  }  void ProcessCapabilities::Clear() { @@ -225,7 +225,7 @@ ResultCode ProcessCapabilities::HandlePriorityCoreNumFlags(u32 flags) {      if (priority_mask != 0 || core_mask != 0) {          LOG_ERROR(Kernel, "Core or priority mask are not zero! priority_mask={}, core_mask={}",                    priority_mask, core_mask); -        return ERR_INVALID_CAPABILITY_DESCRIPTOR; +        return ResultInvalidCapabilityDescriptor;      }      const u32 core_num_min = (flags >> 16) & 0xFF; @@ -233,7 +233,7 @@ ResultCode ProcessCapabilities::HandlePriorityCoreNumFlags(u32 flags) {      if (core_num_min > core_num_max) {          LOG_ERROR(Kernel, "Core min is greater than core max! core_num_min={}, core_num_max={}",                    core_num_min, core_num_max); -        return ERR_INVALID_COMBINATION; +        return ResultInvalidCombination;      }      const u32 priority_min = (flags >> 10) & 0x3F; @@ -242,13 +242,13 @@ ResultCode ProcessCapabilities::HandlePriorityCoreNumFlags(u32 flags) {          LOG_ERROR(Kernel,                    "Priority min is greater than priority max! priority_min={}, priority_max={}",                    core_num_min, priority_max); -        return ERR_INVALID_COMBINATION; +        return ResultInvalidCombination;      }      // The switch only has 4 usable cores.      if (core_num_max >= 4) {          LOG_ERROR(Kernel, "Invalid max cores specified! core_num_max={}", core_num_max); -        return ERR_INVALID_PROCESSOR_ID; +        return ResultInvalidCoreId;      }      const auto make_mask = [](u64 min, u64 max) { @@ -269,7 +269,7 @@ ResultCode ProcessCapabilities::HandleSyscallFlags(u32& set_svc_bits, u32 flags)      // If we've already set this svc before, bail.      if ((set_svc_bits & svc_bit) != 0) { -        return ERR_INVALID_COMBINATION; +        return ResultInvalidCombination;      }      set_svc_bits |= svc_bit; @@ -283,7 +283,7 @@ ResultCode ProcessCapabilities::HandleSyscallFlags(u32& set_svc_bits, u32 flags)          if (svc_number >= svc_capabilities.size()) {              LOG_ERROR(Kernel, "Process svc capability is out of range! svc_number={}", svc_number); -            return ERR_OUT_OF_RANGE; +            return ResultOutOfRange;          }          svc_capabilities[svc_number] = true; @@ -321,7 +321,7 @@ ResultCode ProcessCapabilities::HandleInterruptFlags(u32 flags) {          if (interrupt >= interrupt_capabilities.size()) {              LOG_ERROR(Kernel, "Process interrupt capability is out of range! svc_number={}",                        interrupt); -            return ERR_OUT_OF_RANGE; +            return ResultOutOfRange;          }          interrupt_capabilities[interrupt] = true; @@ -334,7 +334,7 @@ ResultCode ProcessCapabilities::HandleProgramTypeFlags(u32 flags) {      const u32 reserved = flags >> 17;      if (reserved != 0) {          LOG_ERROR(Kernel, "Reserved value is non-zero! reserved={}", reserved); -        return ERR_RESERVED_VALUE; +        return ResultReservedValue;      }      program_type = static_cast<ProgramType>((flags >> 14) & 0b111); @@ -354,7 +354,7 @@ ResultCode ProcessCapabilities::HandleKernelVersionFlags(u32 flags) {          LOG_ERROR(Kernel,                    "Kernel version is non zero or flags are too small! major_version={}, flags={}",                    major_version, flags); -        return ERR_INVALID_CAPABILITY_DESCRIPTOR; +        return ResultInvalidCapabilityDescriptor;      }      kernel_version = flags; @@ -365,7 +365,7 @@ ResultCode ProcessCapabilities::HandleHandleTableFlags(u32 flags) {      const u32 reserved = flags >> 26;      if (reserved != 0) {          LOG_ERROR(Kernel, "Reserved value is non-zero! reserved={}", reserved); -        return ERR_RESERVED_VALUE; +        return ResultReservedValue;      }      handle_table_size = static_cast<s32>((flags >> 16) & 0x3FF); @@ -376,7 +376,7 @@ ResultCode ProcessCapabilities::HandleDebugFlags(u32 flags) {      const u32 reserved = flags >> 19;      if (reserved != 0) {          LOG_ERROR(Kernel, "Reserved value is non-zero! reserved={}", reserved); -        return ERR_RESERVED_VALUE; +        return ResultReservedValue;      }      is_debuggable = (flags & 0x20000) != 0; diff --git a/src/core/hle/kernel/server_port.cpp b/src/core/hle/kernel/server_port.cpp index fe7a483c4..5d17346ad 100644 --- a/src/core/hle/kernel/server_port.cpp +++ b/src/core/hle/kernel/server_port.cpp @@ -5,11 +5,11 @@  #include <tuple>  #include "common/assert.h"  #include "core/hle/kernel/client_port.h" -#include "core/hle/kernel/errors.h"  #include "core/hle/kernel/k_thread.h"  #include "core/hle/kernel/object.h"  #include "core/hle/kernel/server_port.h"  #include "core/hle/kernel/server_session.h" +#include "core/hle/kernel/svc_results.h"  namespace Kernel { @@ -18,7 +18,7 @@ ServerPort::~ServerPort() = default;  ResultVal<std::shared_ptr<ServerSession>> ServerPort::Accept() {      if (pending_sessions.empty()) { -        return ERR_NOT_FOUND; +        return ResultNotFound;      }      auto session = std::move(pending_sessions.back()); diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 26650a513..4ef3c7ac5 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp @@ -23,7 +23,6 @@  #include "core/cpu_manager.h"  #include "core/hle/kernel/client_port.h"  #include "core/hle/kernel/client_session.h" -#include "core/hle/kernel/errors.h"  #include "core/hle/kernel/handle_table.h"  #include "core/hle/kernel/k_address_arbiter.h"  #include "core/hle/kernel/k_condition_variable.h" @@ -71,49 +70,49 @@ ResultCode MapUnmapMemorySanityChecks(const Memory::PageTable& manager, VAddr ds                                        VAddr src_addr, u64 size) {      if (!Common::Is4KBAligned(dst_addr)) {          LOG_ERROR(Kernel_SVC, "Destination address is not aligned to 4KB, 0x{:016X}", dst_addr); -        return ERR_INVALID_ADDRESS; +        return ResultInvalidAddress;      }      if (!Common::Is4KBAligned(src_addr)) {          LOG_ERROR(Kernel_SVC, "Source address is not aligned to 4KB, 0x{:016X}", src_addr); -        return ERR_INVALID_SIZE; +        return ResultInvalidSize;      }      if (size == 0) {          LOG_ERROR(Kernel_SVC, "Size is 0"); -        return ERR_INVALID_SIZE; +        return ResultInvalidSize;      }      if (!Common::Is4KBAligned(size)) {          LOG_ERROR(Kernel_SVC, "Size is not aligned to 4KB, 0x{:016X}", size); -        return ERR_INVALID_SIZE; +        return ResultInvalidSize;      }      if (!IsValidAddressRange(dst_addr, size)) {          LOG_ERROR(Kernel_SVC,                    "Destination is not a valid address range, addr=0x{:016X}, size=0x{:016X}",                    dst_addr, size); -        return ERR_INVALID_ADDRESS_STATE; +        return ResultInvalidCurrentMemory;      }      if (!IsValidAddressRange(src_addr, size)) {          LOG_ERROR(Kernel_SVC, "Source is not a valid address range, addr=0x{:016X}, size=0x{:016X}",                    src_addr, size); -        return ERR_INVALID_ADDRESS_STATE; +        return ResultInvalidCurrentMemory;      }      if (!manager.IsInsideAddressSpace(src_addr, size)) {          LOG_ERROR(Kernel_SVC,                    "Source is not within the address space, addr=0x{:016X}, size=0x{:016X}",                    src_addr, size); -        return ERR_INVALID_ADDRESS_STATE; +        return ResultInvalidCurrentMemory;      }      if (manager.IsOutsideStackRegion(dst_addr, size)) {          LOG_ERROR(Kernel_SVC,                    "Destination is not within the stack region, addr=0x{:016X}, size=0x{:016X}",                    dst_addr, size); -        return ERR_INVALID_MEMORY_RANGE; +        return ResultInvalidMemoryRange;      }      if (manager.IsInsideHeapRegion(dst_addr, size)) { @@ -121,7 +120,7 @@ ResultCode MapUnmapMemorySanityChecks(const Memory::PageTable& manager, VAddr ds                    "Destination does not fit within the heap region, addr=0x{:016X}, "                    "size=0x{:016X}",                    dst_addr, size); -        return ERR_INVALID_MEMORY_RANGE; +        return ResultInvalidMemoryRange;      }      if (manager.IsInsideAliasRegion(dst_addr, size)) { @@ -129,7 +128,7 @@ ResultCode MapUnmapMemorySanityChecks(const Memory::PageTable& manager, VAddr ds                    "Destination does not fit within the map region, addr=0x{:016X}, "                    "size=0x{:016X}",                    dst_addr, size); -        return ERR_INVALID_MEMORY_RANGE; +        return ResultInvalidMemoryRange;      }      return RESULT_SUCCESS; @@ -146,7 +145,7 @@ ResultVal<s64> RetrieveResourceLimitValue(Core::System& system, Handle resource_      const auto type = static_cast<LimitableResource>(resource_type);      if (!IsValidResourceType(type)) {          LOG_ERROR(Kernel_SVC, "Invalid resource limit type: '{}'", resource_type); -        return ERR_INVALID_ENUM_VALUE; +        return ResultInvalidEnumValue;      }      const auto* const current_process = system.Kernel().CurrentProcess(); @@ -157,7 +156,7 @@ ResultVal<s64> RetrieveResourceLimitValue(Core::System& system, Handle resource_      if (!resource_limit_object) {          LOG_ERROR(Kernel_SVC, "Handle to non-existent resource limit instance used. Handle={:08X}",                    resource_limit); -        return ERR_INVALID_HANDLE; +        return ResultInvalidHandle;      }      if (value_type == ResourceLimitValueType::CurrentValue) { @@ -177,12 +176,12 @@ static ResultCode SetHeapSize(Core::System& system, VAddr* heap_addr, u64 heap_s      if ((heap_size % 0x200000) != 0) {          LOG_ERROR(Kernel_SVC, "The heap size is not a multiple of 2MB, heap_size=0x{:016X}",                    heap_size); -        return ERR_INVALID_SIZE; +        return ResultInvalidSize;      }      if (heap_size >= 0x200000000) {          LOG_ERROR(Kernel_SVC, "The heap size is not less than 8GB, heap_size=0x{:016X}", heap_size); -        return ERR_INVALID_SIZE; +        return ResultInvalidSize;      }      auto& page_table{system.Kernel().CurrentProcess()->PageTable()}; @@ -208,19 +207,19 @@ static ResultCode SetMemoryAttribute(Core::System& system, VAddr address, u64 si      if (!Common::Is4KBAligned(address)) {          LOG_ERROR(Kernel_SVC, "Address not page aligned (0x{:016X})", address); -        return ERR_INVALID_ADDRESS; +        return ResultInvalidAddress;      }      if (size == 0 || !Common::Is4KBAligned(size)) {          LOG_ERROR(Kernel_SVC, "Invalid size (0x{:X}). Size must be non-zero and page aligned.",                    size); -        return ERR_INVALID_ADDRESS; +        return ResultInvalidAddress;      }      if (!IsValidAddressRange(address, size)) {          LOG_ERROR(Kernel_SVC, "Address range overflowed (Address: 0x{:016X}, Size: 0x{:016X})",                    address, size); -        return ERR_INVALID_ADDRESS_STATE; +        return ResultInvalidCurrentMemory;      }      const auto attributes{static_cast<Memory::MemoryAttribute>(mask | attribute)}; @@ -229,7 +228,7 @@ static ResultCode SetMemoryAttribute(Core::System& system, VAddr address, u64 si          LOG_ERROR(Kernel_SVC,                    "Memory attribute doesn't match the given mask (Attribute: 0x{:X}, Mask: {:X}",                    attribute, mask); -        return ERR_INVALID_COMBINATION; +        return ResultInvalidCombination;      }      auto& page_table{system.Kernel().CurrentProcess()->PageTable()}; @@ -293,7 +292,7 @@ static ResultCode ConnectToNamedPort(Core::System& system, Handle* out_handle,          LOG_ERROR(Kernel_SVC,                    "Port Name Address is not a valid virtual address, port_name_address=0x{:016X}",                    port_name_address); -        return ERR_NOT_FOUND; +        return ResultNotFound;      }      static constexpr std::size_t PortNameMaxLength = 11; @@ -302,7 +301,7 @@ static ResultCode ConnectToNamedPort(Core::System& system, Handle* out_handle,      if (port_name.size() > PortNameMaxLength) {          LOG_ERROR(Kernel_SVC, "Port name is too long, expected {} but got {}", PortNameMaxLength,                    port_name.size()); -        return ERR_OUT_OF_RANGE; +        return ResultOutOfRange;      }      LOG_TRACE(Kernel_SVC, "called port_name={}", port_name); @@ -311,7 +310,7 @@ static ResultCode ConnectToNamedPort(Core::System& system, Handle* out_handle,      const auto it = kernel.FindNamedPort(port_name);      if (!kernel.IsValidNamedPort(it)) {          LOG_WARNING(Kernel_SVC, "tried to connect to unknown port: {}", port_name); -        return ERR_NOT_FOUND; +        return ResultNotFound;      }      ASSERT(kernel.CurrentProcess()->GetResourceLimit()->Reserve(LimitableResource::Sessions, 1)); @@ -340,7 +339,7 @@ static ResultCode SendSyncRequest(Core::System& system, Handle handle) {      std::shared_ptr<ClientSession> session = handle_table.Get<ClientSession>(handle);      if (!session) {          LOG_ERROR(Kernel_SVC, "called with invalid handle=0x{:08X}", handle); -        return ERR_INVALID_HANDLE; +        return ResultInvalidHandle;      }      LOG_TRACE(Kernel_SVC, "called handle=0x{:08X}({})", handle, session->GetName()); @@ -405,7 +404,7 @@ static ResultCode GetProcessId(Core::System& system, u64* process_id, Handle han          const Process* const owner_process = thread->GetOwnerProcess();          if (!owner_process) {              LOG_ERROR(Kernel_SVC, "Non-existent owning process encountered."); -            return ERR_INVALID_HANDLE; +            return ResultInvalidHandle;          }          *process_id = owner_process->GetProcessID(); @@ -415,7 +414,7 @@ static ResultCode GetProcessId(Core::System& system, u64* process_id, Handle han      // NOTE: This should also handle debug objects before returning.      LOG_ERROR(Kernel_SVC, "Handle does not exist, handle=0x{:08X}", handle); -    return ERR_INVALID_HANDLE; +    return ResultInvalidHandle;  }  static ResultCode GetProcessId32(Core::System& system, u32* process_id_low, u32* process_id_high, @@ -438,7 +437,7 @@ static ResultCode WaitSynchronization(Core::System& system, s32* index, VAddr ha          LOG_ERROR(Kernel_SVC,                    "Handle address is not a valid virtual address, handle_address=0x{:016X}",                    handles_address); -        return ERR_INVALID_POINTER; +        return ResultInvalidPointer;      }      static constexpr u64 MaxHandles = 0x40; @@ -446,7 +445,7 @@ static ResultCode WaitSynchronization(Core::System& system, s32* index, VAddr ha      if (handle_count > MaxHandles) {          LOG_ERROR(Kernel_SVC, "Handle count specified is too large, expected {} but got {}",                    MaxHandles, handle_count); -        return ERR_OUT_OF_RANGE; +        return ResultOutOfRange;      }      auto& kernel = system.Kernel(); @@ -459,7 +458,7 @@ static ResultCode WaitSynchronization(Core::System& system, s32* index, VAddr ha          if (object == nullptr) {              LOG_ERROR(Kernel_SVC, "Object is a nullptr"); -            return ERR_INVALID_HANDLE; +            return ResultInvalidHandle;          }          objects[i] = object.get(); @@ -481,6 +480,7 @@ static ResultCode CancelSynchronization(Core::System& system, Handle thread_hand      // Get the thread from its handle.      const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable();      std::shared_ptr<KThread> thread = handle_table.Get<KThread>(thread_handle); +      if (!thread) {          LOG_ERROR(Kernel_SVC, "Invalid thread handle provided (handle={:08X})", thread_handle);          return ResultInvalidHandle; @@ -525,6 +525,7 @@ static ResultCode ArbitrateUnlock(Core::System& system, VAddr address) {      LOG_TRACE(Kernel_SVC, "called address=0x{:X}", address);      // Validate the input address. +      if (Memory::IsKernelAddress(address)) {          LOG_ERROR(Kernel_SVC,                    "Attempting to arbitrate an unlock on a kernel address (address={:08X})", @@ -735,7 +736,7 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, u64 ha          if (info_sub_id != 0) {              LOG_ERROR(Kernel_SVC, "Info sub id is non zero! info_id={}, info_sub_id={}", info_id,                        info_sub_id); -            return ERR_INVALID_ENUM_VALUE; +            return ResultInvalidEnumValue;          }          const auto& current_process_handle_table = @@ -744,7 +745,7 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, u64 ha          if (!process) {              LOG_ERROR(Kernel_SVC, "Process is not valid! info_id={}, info_sub_id={}, handle={:08X}",                        info_id, info_sub_id, handle); -            return ERR_INVALID_HANDLE; +            return ResultInvalidHandle;          }          switch (info_id_type) { @@ -826,7 +827,7 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, u64 ha          }          LOG_ERROR(Kernel_SVC, "Unimplemented svcGetInfo id=0x{:016X}", info_id); -        return ERR_INVALID_ENUM_VALUE; +        return ResultInvalidEnumValue;      }      case GetInfoType::IsCurrentProcessBeingDebugged: @@ -836,13 +837,13 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, u64 ha      case GetInfoType::RegisterResourceLimit: {          if (handle != 0) {              LOG_ERROR(Kernel, "Handle is non zero! handle={:08X}", handle); -            return ERR_INVALID_HANDLE; +            return ResultInvalidHandle;          }          if (info_sub_id != 0) {              LOG_ERROR(Kernel, "Info sub id is non zero! info_id={}, info_sub_id={}", info_id,                        info_sub_id); -            return ERR_INVALID_COMBINATION; +            return ResultInvalidCombination;          }          Process* const current_process = system.Kernel().CurrentProcess(); @@ -867,13 +868,13 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, u64 ha          if (handle != 0) {              LOG_ERROR(Kernel_SVC, "Process Handle is non zero, expected 0 result but got {:016X}",                        handle); -            return ERR_INVALID_HANDLE; +            return ResultInvalidHandle;          }          if (info_sub_id >= Process::RANDOM_ENTROPY_SIZE) {              LOG_ERROR(Kernel_SVC, "Entropy size is out of range, expected {} but got {}",                        Process::RANDOM_ENTROPY_SIZE, info_sub_id); -            return ERR_INVALID_COMBINATION; +            return ResultInvalidCombination;          }          *result = system.Kernel().CurrentProcess()->GetRandomEntropy(info_sub_id); @@ -890,7 +891,7 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, u64 ha          if (info_sub_id != 0xFFFFFFFFFFFFFFFF && info_sub_id >= num_cpus) {              LOG_ERROR(Kernel_SVC, "Core count is out of range, expected {} but got {}", num_cpus,                        info_sub_id); -            return ERR_INVALID_COMBINATION; +            return ResultInvalidCombination;          }          const auto thread = system.Kernel().CurrentProcess()->GetHandleTable().Get<KThread>( @@ -898,7 +899,7 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, u64 ha          if (!thread) {              LOG_ERROR(Kernel_SVC, "Thread handle does not exist, handle=0x{:08X}",                        static_cast<Handle>(handle)); -            return ERR_INVALID_HANDLE; +            return ResultInvalidHandle;          }          const auto& core_timing = system.CoreTiming(); @@ -922,7 +923,7 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, u64 ha      default:          LOG_ERROR(Kernel_SVC, "Unimplemented svcGetInfo id=0x{:016X}", info_id); -        return ERR_INVALID_ENUM_VALUE; +        return ResultInvalidEnumValue;      }  } @@ -945,22 +946,22 @@ static ResultCode MapPhysicalMemory(Core::System& system, VAddr addr, u64 size)      if (!Common::Is4KBAligned(addr)) {          LOG_ERROR(Kernel_SVC, "Address is not aligned to 4KB, 0x{:016X}", addr); -        return ERR_INVALID_ADDRESS; +        return ResultInvalidAddress;      }      if (!Common::Is4KBAligned(size)) {          LOG_ERROR(Kernel_SVC, "Size is not aligned to 4KB, 0x{:X}", size); -        return ERR_INVALID_SIZE; +        return ResultInvalidSize;      }      if (size == 0) {          LOG_ERROR(Kernel_SVC, "Size is zero"); -        return ERR_INVALID_SIZE; +        return ResultInvalidSize;      }      if (!(addr < addr + size)) {          LOG_ERROR(Kernel_SVC, "Size causes 64-bit overflow of address"); -        return ERR_INVALID_MEMORY_RANGE; +        return ResultInvalidMemoryRange;      }      Process* const current_process{system.Kernel().CurrentProcess()}; @@ -968,21 +969,21 @@ static ResultCode MapPhysicalMemory(Core::System& system, VAddr addr, u64 size)      if (current_process->GetSystemResourceSize() == 0) {          LOG_ERROR(Kernel_SVC, "System Resource Size is zero"); -        return ERR_INVALID_STATE; +        return ResultInvalidState;      }      if (!page_table.IsInsideAddressSpace(addr, size)) {          LOG_ERROR(Kernel_SVC,                    "Address is not within the address space, addr=0x{:016X}, size=0x{:016X}", addr,                    size); -        return ERR_INVALID_MEMORY_RANGE; +        return ResultInvalidMemoryRange;      }      if (page_table.IsOutsideAliasRegion(addr, size)) {          LOG_ERROR(Kernel_SVC,                    "Address is not within the alias region, addr=0x{:016X}, size=0x{:016X}", addr,                    size); -        return ERR_INVALID_MEMORY_RANGE; +        return ResultInvalidMemoryRange;      }      return page_table.MapPhysicalMemory(addr, size); @@ -999,22 +1000,22 @@ static ResultCode UnmapPhysicalMemory(Core::System& system, VAddr addr, u64 size      if (!Common::Is4KBAligned(addr)) {          LOG_ERROR(Kernel_SVC, "Address is not aligned to 4KB, 0x{:016X}", addr); -        return ERR_INVALID_ADDRESS; +        return ResultInvalidAddress;      }      if (!Common::Is4KBAligned(size)) {          LOG_ERROR(Kernel_SVC, "Size is not aligned to 4KB, 0x{:X}", size); -        return ERR_INVALID_SIZE; +        return ResultInvalidSize;      }      if (size == 0) {          LOG_ERROR(Kernel_SVC, "Size is zero"); -        return ERR_INVALID_SIZE; +        return ResultInvalidSize;      }      if (!(addr < addr + size)) {          LOG_ERROR(Kernel_SVC, "Size causes 64-bit overflow of address"); -        return ERR_INVALID_MEMORY_RANGE; +        return ResultInvalidMemoryRange;      }      Process* const current_process{system.Kernel().CurrentProcess()}; @@ -1022,21 +1023,21 @@ static ResultCode UnmapPhysicalMemory(Core::System& system, VAddr addr, u64 size      if (current_process->GetSystemResourceSize() == 0) {          LOG_ERROR(Kernel_SVC, "System Resource Size is zero"); -        return ERR_INVALID_STATE; +        return ResultInvalidState;      }      if (!page_table.IsInsideAddressSpace(addr, size)) {          LOG_ERROR(Kernel_SVC,                    "Address is not within the address space, addr=0x{:016X}, size=0x{:016X}", addr,                    size); -        return ERR_INVALID_MEMORY_RANGE; +        return ResultInvalidMemoryRange;      }      if (page_table.IsOutsideAliasRegion(addr, size)) {          LOG_ERROR(Kernel_SVC,                    "Address is not within the alias region, addr=0x{:016X}, size=0x{:016X}", addr,                    size); -        return ERR_INVALID_MEMORY_RANGE; +        return ResultInvalidMemoryRange;      }      return page_table.UnmapPhysicalMemory(addr, size); @@ -1206,23 +1207,23 @@ static ResultCode MapSharedMemory(Core::System& system, Handle shared_memory_han      if (!Common::Is4KBAligned(addr)) {          LOG_ERROR(Kernel_SVC, "Address is not aligned to 4KB, addr=0x{:016X}", addr); -        return ERR_INVALID_ADDRESS; +        return ResultInvalidAddress;      }      if (size == 0) {          LOG_ERROR(Kernel_SVC, "Size is 0"); -        return ERR_INVALID_SIZE; +        return ResultInvalidSize;      }      if (!Common::Is4KBAligned(size)) {          LOG_ERROR(Kernel_SVC, "Size is not aligned to 4KB, size=0x{:016X}", size); -        return ERR_INVALID_SIZE; +        return ResultInvalidSize;      }      if (!IsValidAddressRange(addr, size)) {          LOG_ERROR(Kernel_SVC, "Region is not a valid address range, addr=0x{:016X}, size=0x{:016X}",                    addr, size); -        return ERR_INVALID_ADDRESS_STATE; +        return ResultInvalidCurrentMemory;      }      const auto permission_type = static_cast<Memory::MemoryPermission>(permissions); @@ -1230,7 +1231,7 @@ static ResultCode MapSharedMemory(Core::System& system, Handle shared_memory_han          Memory::MemoryPermission::ReadAndWrite) {          LOG_ERROR(Kernel_SVC, "Expected Read or ReadWrite permission but got permissions=0x{:08X}",                    permissions); -        return ERR_INVALID_MEMORY_PERMISSIONS; +        return ResultInvalidMemoryPermissions;      }      auto* const current_process{system.Kernel().CurrentProcess()}; @@ -1241,7 +1242,7 @@ static ResultCode MapSharedMemory(Core::System& system, Handle shared_memory_han                    "Addr does not fit within the valid region, addr=0x{:016X}, "                    "size=0x{:016X}",                    addr, size); -        return ERR_INVALID_MEMORY_RANGE; +        return ResultInvalidMemoryRange;      }      if (page_table.IsInsideHeapRegion(addr, size)) { @@ -1249,7 +1250,7 @@ static ResultCode MapSharedMemory(Core::System& system, Handle shared_memory_han                    "Addr does not fit within the heap region, addr=0x{:016X}, "                    "size=0x{:016X}",                    addr, size); -        return ERR_INVALID_MEMORY_RANGE; +        return ResultInvalidMemoryRange;      }      if (page_table.IsInsideAliasRegion(addr, size)) { @@ -1257,14 +1258,14 @@ static ResultCode MapSharedMemory(Core::System& system, Handle shared_memory_han                    "Address does not fit within the map region, addr=0x{:016X}, "                    "size=0x{:016X}",                    addr, size); -        return ERR_INVALID_MEMORY_RANGE; +        return ResultInvalidMemoryRange;      }      auto shared_memory{current_process->GetHandleTable().Get<SharedMemory>(shared_memory_handle)};      if (!shared_memory) {          LOG_ERROR(Kernel_SVC, "Shared memory does not exist, shared_memory_handle=0x{:08X}",                    shared_memory_handle); -        return ERR_INVALID_HANDLE; +        return ResultInvalidHandle;      }      return shared_memory->Map(*current_process, addr, size, permission_type); @@ -1285,7 +1286,7 @@ static ResultCode QueryProcessMemory(Core::System& system, VAddr memory_info_add      if (!process) {          LOG_ERROR(Kernel_SVC, "Process handle does not exist, process_handle=0x{:08X}",                    process_handle); -        return ERR_INVALID_HANDLE; +        return ResultInvalidHandle;      }      auto& memory{system.Memory()}; @@ -1332,18 +1333,18 @@ static ResultCode MapProcessCodeMemory(Core::System& system, Handle process_hand      if (!Common::Is4KBAligned(src_address)) {          LOG_ERROR(Kernel_SVC, "src_address is not page-aligned (src_address=0x{:016X}).",                    src_address); -        return ERR_INVALID_ADDRESS; +        return ResultInvalidAddress;      }      if (!Common::Is4KBAligned(dst_address)) {          LOG_ERROR(Kernel_SVC, "dst_address is not page-aligned (dst_address=0x{:016X}).",                    dst_address); -        return ERR_INVALID_ADDRESS; +        return ResultInvalidAddress;      }      if (size == 0 || !Common::Is4KBAligned(size)) {          LOG_ERROR(Kernel_SVC, "Size is zero or not page-aligned (size=0x{:016X})", size); -        return ERR_INVALID_SIZE; +        return ResultInvalidSize;      }      if (!IsValidAddressRange(dst_address, size)) { @@ -1351,7 +1352,7 @@ static ResultCode MapProcessCodeMemory(Core::System& system, Handle process_hand                    "Destination address range overflows the address space (dst_address=0x{:016X}, "                    "size=0x{:016X}).",                    dst_address, size); -        return ERR_INVALID_ADDRESS_STATE; +        return ResultInvalidCurrentMemory;      }      if (!IsValidAddressRange(src_address, size)) { @@ -1359,7 +1360,7 @@ static ResultCode MapProcessCodeMemory(Core::System& system, Handle process_hand                    "Source address range overflows the address space (src_address=0x{:016X}, "                    "size=0x{:016X}).",                    src_address, size); -        return ERR_INVALID_ADDRESS_STATE; +        return ResultInvalidCurrentMemory;      }      const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); @@ -1367,7 +1368,7 @@ static ResultCode MapProcessCodeMemory(Core::System& system, Handle process_hand      if (!process) {          LOG_ERROR(Kernel_SVC, "Invalid process handle specified (handle=0x{:08X}).",                    process_handle); -        return ERR_INVALID_HANDLE; +        return ResultInvalidHandle;      }      auto& page_table = process->PageTable(); @@ -1376,7 +1377,7 @@ static ResultCode MapProcessCodeMemory(Core::System& system, Handle process_hand                    "Source address range is not within the address space (src_address=0x{:016X}, "                    "size=0x{:016X}).",                    src_address, size); -        return ERR_INVALID_ADDRESS_STATE; +        return ResultInvalidCurrentMemory;      }      if (!page_table.IsInsideASLRRegion(dst_address, size)) { @@ -1384,7 +1385,7 @@ static ResultCode MapProcessCodeMemory(Core::System& system, Handle process_hand                    "Destination address range is not within the ASLR region (dst_address=0x{:016X}, "                    "size=0x{:016X}).",                    dst_address, size); -        return ERR_INVALID_MEMORY_RANGE; +        return ResultInvalidMemoryRange;      }      return page_table.MapProcessCodeMemory(dst_address, src_address, size); @@ -1400,18 +1401,18 @@ static ResultCode UnmapProcessCodeMemory(Core::System& system, Handle process_ha      if (!Common::Is4KBAligned(dst_address)) {          LOG_ERROR(Kernel_SVC, "dst_address is not page-aligned (dst_address=0x{:016X}).",                    dst_address); -        return ERR_INVALID_ADDRESS; +        return ResultInvalidAddress;      }      if (!Common::Is4KBAligned(src_address)) {          LOG_ERROR(Kernel_SVC, "src_address is not page-aligned (src_address=0x{:016X}).",                    src_address); -        return ERR_INVALID_ADDRESS; +        return ResultInvalidAddress;      }      if (size == 0 || Common::Is4KBAligned(size)) {          LOG_ERROR(Kernel_SVC, "Size is zero or not page-aligned (size=0x{:016X}).", size); -        return ERR_INVALID_SIZE; +        return ResultInvalidSize;      }      if (!IsValidAddressRange(dst_address, size)) { @@ -1419,7 +1420,7 @@ static ResultCode UnmapProcessCodeMemory(Core::System& system, Handle process_ha                    "Destination address range overflows the address space (dst_address=0x{:016X}, "                    "size=0x{:016X}).",                    dst_address, size); -        return ERR_INVALID_ADDRESS_STATE; +        return ResultInvalidCurrentMemory;      }      if (!IsValidAddressRange(src_address, size)) { @@ -1427,7 +1428,7 @@ static ResultCode UnmapProcessCodeMemory(Core::System& system, Handle process_ha                    "Source address range overflows the address space (src_address=0x{:016X}, "                    "size=0x{:016X}).",                    src_address, size); -        return ERR_INVALID_ADDRESS_STATE; +        return ResultInvalidCurrentMemory;      }      const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); @@ -1435,7 +1436,7 @@ static ResultCode UnmapProcessCodeMemory(Core::System& system, Handle process_ha      if (!process) {          LOG_ERROR(Kernel_SVC, "Invalid process handle specified (handle=0x{:08X}).",                    process_handle); -        return ERR_INVALID_HANDLE; +        return ResultInvalidHandle;      }      auto& page_table = process->PageTable(); @@ -1444,7 +1445,7 @@ static ResultCode UnmapProcessCodeMemory(Core::System& system, Handle process_ha                    "Source address range is not within the address space (src_address=0x{:016X}, "                    "size=0x{:016X}).",                    src_address, size); -        return ERR_INVALID_ADDRESS_STATE; +        return ResultInvalidCurrentMemory;      }      if (!page_table.IsInsideASLRRegion(dst_address, size)) { @@ -1452,7 +1453,7 @@ static ResultCode UnmapProcessCodeMemory(Core::System& system, Handle process_ha                    "Destination address range is not within the ASLR region (dst_address=0x{:016X}, "                    "size=0x{:016X}).",                    dst_address, size); -        return ERR_INVALID_MEMORY_RANGE; +        return ResultInvalidMemoryRange;      }      return page_table.UnmapProcessCodeMemory(dst_address, src_address, size); @@ -1844,7 +1845,7 @@ static ResultCode ResetSignal(Core::System& system, Handle handle) {      LOG_ERROR(Kernel_SVC, "invalid handle (0x{:08X})", handle); -    return Svc::ResultInvalidHandle; +    return ResultInvalidHandle;  }  static ResultCode ResetSignal32(Core::System& system, Handle handle) { @@ -1860,18 +1861,18 @@ static ResultCode CreateTransferMemory(Core::System& system, Handle* handle, VAd      if (!Common::Is4KBAligned(addr)) {          LOG_ERROR(Kernel_SVC, "Address ({:016X}) is not page aligned!", addr); -        return ERR_INVALID_ADDRESS; +        return ResultInvalidAddress;      }      if (!Common::Is4KBAligned(size) || size == 0) {          LOG_ERROR(Kernel_SVC, "Size ({:016X}) is not page aligned or equal to zero!", size); -        return ERR_INVALID_ADDRESS; +        return ResultInvalidAddress;      }      if (!IsValidAddressRange(addr, size)) {          LOG_ERROR(Kernel_SVC, "Address and size cause overflow! (address={:016X}, size={:016X})",                    addr, size); -        return ERR_INVALID_ADDRESS_STATE; +        return ResultInvalidCurrentMemory;      }      const auto perms{static_cast<Memory::MemoryPermission>(permissions)}; @@ -1879,7 +1880,7 @@ static ResultCode CreateTransferMemory(Core::System& system, Handle* handle, VAd          perms == Memory::MemoryPermission::Write) {          LOG_ERROR(Kernel_SVC, "Invalid memory permissions for transfer memory! (perms={:08X})",                    permissions); -        return ERR_INVALID_MEMORY_PERMISSIONS; +        return ResultInvalidMemoryPermissions;      }      auto& kernel = system.Kernel(); @@ -1989,7 +1990,6 @@ static ResultCode SetThreadCoreMask(Core::System& system, Handle thread_handle,          LOG_ERROR(Kernel_SVC, "Unable to successfully set core mask (result={})", set_result.raw);          return set_result;      } -      return RESULT_SUCCESS;  } @@ -2043,7 +2043,7 @@ static ResultCode ClearEvent(Core::System& system, Handle event_handle) {      LOG_ERROR(Kernel_SVC, "Event handle does not exist, event_handle=0x{:08X}", event_handle); -    return Svc::ResultInvalidHandle; +    return ResultInvalidHandle;  }  static ResultCode ClearEvent32(Core::System& system, Handle event_handle) { @@ -2106,13 +2106,13 @@ static ResultCode GetProcessInfo(Core::System& system, u64* out, Handle process_      if (!process) {          LOG_ERROR(Kernel_SVC, "Process handle does not exist, process_handle=0x{:08X}",                    process_handle); -        return ERR_INVALID_HANDLE; +        return ResultInvalidHandle;      }      const auto info_type = static_cast<InfoType>(type);      if (info_type != InfoType::Status) {          LOG_ERROR(Kernel_SVC, "Expected info_type to be Status but got {} instead", type); -        return ERR_INVALID_ENUM_VALUE; +        return ResultInvalidEnumValue;      }      *out = static_cast<u64>(process->GetStatus()); @@ -2174,7 +2174,7 @@ static ResultCode SetResourceLimitLimitValue(Core::System& system, Handle resour      const auto type = static_cast<LimitableResource>(resource_type);      if (!IsValidResourceType(type)) {          LOG_ERROR(Kernel_SVC, "Invalid resource limit type: '{}'", resource_type); -        return ERR_INVALID_ENUM_VALUE; +        return ResultInvalidEnumValue;      }      auto* const current_process = system.Kernel().CurrentProcess(); @@ -2185,16 +2185,16 @@ static ResultCode SetResourceLimitLimitValue(Core::System& system, Handle resour      if (!resource_limit_object) {          LOG_ERROR(Kernel_SVC, "Handle to non-existent resource limit instance used. Handle={:08X}",                    resource_limit); -        return ERR_INVALID_HANDLE; +        return ResultInvalidHandle;      }      const auto set_result = resource_limit_object->SetLimitValue(type, static_cast<s64>(value));      if (set_result.IsError()) { -        LOG_ERROR( -            Kernel_SVC, -            "Attempted to lower resource limit ({}) for category '{}' below its current value ({})", -            resource_limit_object->GetLimitValue(type), resource_type, -            resource_limit_object->GetCurrentValue(type)); +        LOG_ERROR(Kernel_SVC, +                  "Attempted to lower resource limit ({}) for category '{}' below its current " +                  "value ({})", +                  resource_limit_object->GetLimitValue(type), resource_type, +                  resource_limit_object->GetCurrentValue(type));          return set_result;      } @@ -2211,7 +2211,7 @@ static ResultCode GetProcessList(Core::System& system, u32* out_num_processes,          LOG_ERROR(Kernel_SVC,                    "Supplied size outside [0, 0x0FFFFFFF] range. out_process_ids_size={}",                    out_process_ids_size); -        return ERR_OUT_OF_RANGE; +        return ResultOutOfRange;      }      const auto& kernel = system.Kernel(); @@ -2221,7 +2221,7 @@ static ResultCode GetProcessList(Core::System& system, u32* out_num_processes,                                          out_process_ids, total_copy_size)) {          LOG_ERROR(Kernel_SVC, "Address range outside address space. begin=0x{:016X}, end=0x{:016X}",                    out_process_ids, out_process_ids + total_copy_size); -        return ERR_INVALID_ADDRESS_STATE; +        return ResultInvalidCurrentMemory;      }      auto& memory = system.Memory(); @@ -2250,7 +2250,7 @@ static ResultCode GetThreadList(Core::System& system, u32* out_num_threads, VAdd      if ((out_thread_ids_size & 0xF0000000) != 0) {          LOG_ERROR(Kernel_SVC, "Supplied size outside [0, 0x0FFFFFFF] range. size={}",                    out_thread_ids_size); -        return ERR_OUT_OF_RANGE; +        return ResultOutOfRange;      }      const auto* const current_process = system.Kernel().CurrentProcess(); @@ -2260,7 +2260,7 @@ static ResultCode GetThreadList(Core::System& system, u32* out_num_threads, VAdd          !current_process->PageTable().IsInsideAddressSpace(out_thread_ids, total_copy_size)) {          LOG_ERROR(Kernel_SVC, "Address range outside address space. begin=0x{:016X}, end=0x{:016X}",                    out_thread_ids, out_thread_ids + total_copy_size); -        return ERR_INVALID_ADDRESS_STATE; +        return ResultInvalidCurrentMemory;      }      auto& memory = system.Memory(); diff --git a/src/core/hle/kernel/svc_results.h b/src/core/hle/kernel/svc_results.h index 204cd989d..a26d9f2c9 100644 --- a/src/core/hle/kernel/svc_results.h +++ b/src/core/hle/kernel/svc_results.h @@ -1,4 +1,4 @@ -// Copyright 2020 yuzu emulator team +// Copyright 2018 yuzu emulator team  // Licensed under GPLv2 or any later version  // Refer to the license.txt file included. @@ -6,21 +6,36 @@  #include "core/hle/result.h" -namespace Kernel::Svc { +namespace Kernel { +// Confirmed Switch kernel error codes + +constexpr ResultCode ResultMaxConnectionsReached{ErrorModule::Kernel, 7}; +constexpr ResultCode ResultInvalidCapabilityDescriptor{ErrorModule::Kernel, 14};  constexpr ResultCode ResultNoSynchronizationObject{ErrorModule::Kernel, 57};  constexpr ResultCode ResultTerminationRequested{ErrorModule::Kernel, 59}; +constexpr ResultCode ResultInvalidSize{ErrorModule::Kernel, 101};  constexpr ResultCode ResultInvalidAddress{ErrorModule::Kernel, 102};  constexpr ResultCode ResultOutOfResource{ErrorModule::Kernel, 103}; +constexpr ResultCode ResultOutOfMemory{ErrorModule::Kernel, 104}; +constexpr ResultCode ResultHandleTableFull{ErrorModule::Kernel, 105};  constexpr ResultCode ResultInvalidCurrentMemory{ErrorModule::Kernel, 106}; +constexpr ResultCode ResultInvalidMemoryPermissions{ErrorModule::Kernel, 108}; +constexpr ResultCode ResultInvalidMemoryRange{ErrorModule::Kernel, 110};  constexpr ResultCode ResultInvalidPriority{ErrorModule::Kernel, 112};  constexpr ResultCode ResultInvalidCoreId{ErrorModule::Kernel, 113};  constexpr ResultCode ResultInvalidHandle{ErrorModule::Kernel, 114}; +constexpr ResultCode ResultInvalidPointer{ErrorModule::Kernel, 115};  constexpr ResultCode ResultInvalidCombination{ErrorModule::Kernel, 116};  constexpr ResultCode ResultTimedOut{ErrorModule::Kernel, 117};  constexpr ResultCode ResultCancelled{ErrorModule::Kernel, 118}; +constexpr ResultCode ResultOutOfRange{ErrorModule::Kernel, 119};  constexpr ResultCode ResultInvalidEnumValue{ErrorModule::Kernel, 120}; +constexpr ResultCode ResultNotFound{ErrorModule::Kernel, 121};  constexpr ResultCode ResultBusy{ErrorModule::Kernel, 122}; +constexpr ResultCode ResultSessionClosedByRemote{ErrorModule::Kernel, 123};  constexpr ResultCode ResultInvalidState{ErrorModule::Kernel, 125}; +constexpr ResultCode ResultReservedValue{ErrorModule::Kernel, 126}; +constexpr ResultCode ResultResourceLimitedExceeded{ErrorModule::Kernel, 132}; -} // namespace Kernel::Svc +} // namespace Kernel diff --git a/src/core/hle/service/ldr/ldr.cpp b/src/core/hle/service/ldr/ldr.cpp index 9da786b4e..c724d2554 100644 --- a/src/core/hle/service/ldr/ldr.cpp +++ b/src/core/hle/service/ldr/ldr.cpp @@ -11,10 +11,10 @@  #include "common/scope_exit.h"  #include "core/core.h"  #include "core/hle/ipc_helpers.h" -#include "core/hle/kernel/errors.h"  #include "core/hle/kernel/memory/page_table.h"  #include "core/hle/kernel/memory/system_control.h"  #include "core/hle/kernel/process.h" +#include "core/hle/kernel/svc_results.h"  #include "core/hle/service/ldr/ldr.h"  #include "core/hle/service/service.h"  #include "core/loader/nro.h" @@ -330,7 +330,7 @@ public:              const VAddr addr{GetRandomMapRegion(page_table, size)};              const ResultCode result{page_table.MapProcessCodeMemory(addr, baseAddress, size)}; -            if (result == Kernel::ERR_INVALID_ADDRESS_STATE) { +            if (result == Kernel::ResultInvalidCurrentMemory) {                  continue;              } @@ -361,7 +361,7 @@ public:                  const ResultCode result{                      page_table.MapProcessCodeMemory(addr + nro_size, bss_addr, bss_size)}; -                if (result == Kernel::ERR_INVALID_ADDRESS_STATE) { +                if (result == Kernel::ResultInvalidCurrentMemory) {                      continue;                  } | 
