From 6df09f5b7639747d9d36f0f54f785277974e6abe Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 24 Oct 2018 13:38:34 -0400 Subject: kernel/error: Add error code for closed sessions The kernel appears to return 0xF601 for this case. --- src/core/hle/kernel/errors.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/hle/kernel/errors.h b/src/core/hle/kernel/errors.h index 885259618..c87cdfa64 100644 --- a/src/core/hle/kernel/errors.h +++ b/src/core/hle/kernel/errors.h @@ -26,6 +26,7 @@ enum { InvalidThreadPriority = 112, InvalidProcessorId = 113, InvalidHandle = 114, + InvalidPointer = 115, InvalidCombination = 116, Timeout = 117, SynchronizationCanceled = 118, @@ -33,6 +34,7 @@ enum { InvalidEnumValue = 120, NoSuchEntry = 121, AlreadyRegistered = 122, + SessionClosed = 123, InvalidState = 125, ResourceLimitExceeded = 132, }; @@ -43,7 +45,7 @@ enum { // TODO(bunnei): Replace -1 with correct errors for Switch OS constexpr ResultCode ERR_HANDLE_TABLE_FULL(ErrorModule::Kernel, ErrCodes::HandleTableFull); -constexpr ResultCode ERR_SESSION_CLOSED_BY_REMOTE(-1); +constexpr ResultCode ERR_SESSION_CLOSED_BY_REMOTE(ErrorModule::Kernel, ErrCodes::SessionClosed); constexpr ResultCode ERR_PORT_NAME_TOO_LONG(ErrorModule::Kernel, ErrCodes::TooLarge); constexpr ResultCode ERR_MAX_CONNECTIONS_REACHED(ErrorModule::Kernel, ErrCodes::MaxConnectionsReached); -- cgit v1.2.3 From c7c346a15d622283d0dc2cfd4c7d3c88810e65c6 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 24 Oct 2018 13:41:09 -0400 Subject: kernel/error: Add error code for invalid pointers The kernel appears to return 0xE601 for this situation. Particularly in svcWaitSynchronization, svcReplyAndReceive, and svcGetThreadContext --- src/core/hle/kernel/errors.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/hle/kernel/errors.h b/src/core/hle/kernel/errors.h index c87cdfa64..94810d68f 100644 --- a/src/core/hle/kernel/errors.h +++ b/src/core/hle/kernel/errors.h @@ -67,7 +67,7 @@ constexpr ResultCode ERR_ALREADY_REGISTERED(ErrorModule::Kernel, ErrCodes::Alrea constexpr ResultCode ERR_INVALID_STATE(ErrorModule::Kernel, ErrCodes::InvalidState); constexpr ResultCode ERR_INVALID_THREAD_PRIORITY(ErrorModule::Kernel, ErrCodes::InvalidThreadPriority); -constexpr ResultCode ERR_INVALID_POINTER(-1); +constexpr ResultCode ERR_INVALID_POINTER(ErrorModule::Kernel, ErrCodes::InvalidPointer); constexpr ResultCode ERR_INVALID_OBJECT_ADDR(-1); constexpr ResultCode ERR_NOT_AUTHORIZED(-1); /// Alternate code returned instead of ERR_INVALID_HANDLE in some code paths. -- cgit v1.2.3 From 77328b0f1978f044f05a60cd864a4dff0c4b7493 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 24 Oct 2018 14:07:53 -0400 Subject: kernel/svc: Move and correct returned error code for invalid thread priorities in SetThreadPriority() All priority checks are supposed to occur before checking the validity of the thread handle, we're also not supposed to return ERR_NOT_AUTHORIZED here. --- src/core/hle/kernel/svc.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 9a783d524..e7e4c59b6 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp @@ -594,16 +594,17 @@ static ResultCode SetThreadPriority(Handle handle, u32 priority) { } const auto* const current_process = Core::CurrentProcess(); - SharedPtr thread = current_process->GetHandleTable().Get(handle); - if (!thread) { - return ERR_INVALID_HANDLE; - } // Note: The kernel uses the current process's resource limit instead of // the one from the thread owner's resource limit. const ResourceLimit& resource_limit = current_process->GetResourceLimit(); if (resource_limit.GetMaxResourceValue(ResourceType::Priority) > priority) { - return ERR_NOT_AUTHORIZED; + return ERR_INVALID_THREAD_PRIORITY; + } + + SharedPtr thread = current_process->GetHandleTable().Get(handle); + if (!thread) { + return ERR_INVALID_HANDLE; } thread->SetPriority(priority); -- cgit v1.2.3 From fcf8f53a631fe5f15f2b456bc34331de8e67a64b Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 24 Oct 2018 14:10:30 -0400 Subject: kernel/svc: Amend returned error code for invalid priorities in CreateThread Like with the previous change, the kernel doesn't return NOT_AUTHORIZED here. It returns INVALID_THREAD_PRIORITY. --- src/core/hle/kernel/svc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index e7e4c59b6..a5302d924 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp @@ -746,7 +746,7 @@ static ResultCode CreateThread(Handle* out_handle, VAddr entry_point, u64 arg, V auto* const current_process = Core::CurrentProcess(); const ResourceLimit& resource_limit = current_process->GetResourceLimit(); if (resource_limit.GetMaxResourceValue(ResourceType::Priority) > priority) { - return ERR_NOT_AUTHORIZED; + return ERR_INVALID_THREAD_PRIORITY; } if (processor_id == THREADPROCESSORID_DEFAULT) { -- cgit v1.2.3 From afb7e5cc05be11b98ff307157d812cf9f24616f7 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 24 Oct 2018 14:16:04 -0400 Subject: kernel/error: Remove leftover 3DS error codes These are now entirely unused and can be removed. --- src/core/hle/kernel/errors.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/core/hle/kernel/errors.h b/src/core/hle/kernel/errors.h index 94810d68f..01e4e4bad 100644 --- a/src/core/hle/kernel/errors.h +++ b/src/core/hle/kernel/errors.h @@ -10,11 +10,6 @@ namespace Kernel { namespace ErrCodes { enum { - // TODO(Subv): Remove these 3DS OS error codes. - SessionClosedByRemote = 26, - NoPendingSessions = 35, - InvalidBufferDescriptor = 48, - // Confirmed Switch OS error codes MaxConnectionsReached = 7, InvalidSize = 101, -- cgit v1.2.3 From b703aba622d1d34df06a294610fb2cfe23df9e63 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 24 Oct 2018 14:23:36 -0400 Subject: kernel/server_port: Change error case return value in Accept() to ERR_NOT_FOUND This is what the kernel does in this instance. --- src/core/hle/kernel/errors.h | 2 -- src/core/hle/kernel/server_port.cpp | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/core/hle/kernel/errors.h b/src/core/hle/kernel/errors.h index 01e4e4bad..92436ae6d 100644 --- a/src/core/hle/kernel/errors.h +++ b/src/core/hle/kernel/errors.h @@ -69,7 +69,5 @@ constexpr ResultCode ERR_NOT_AUTHORIZED(-1); constexpr ResultCode ERR_INVALID_HANDLE_OS(-1); constexpr ResultCode ERR_NOT_FOUND(ErrorModule::Kernel, ErrCodes::NoSuchEntry); constexpr ResultCode RESULT_TIMEOUT(ErrorModule::Kernel, ErrCodes::Timeout); -/// Returned when Accept() is called on a port with no sessions to be accepted. -constexpr ResultCode ERR_NO_PENDING_SESSIONS(-1); } // namespace Kernel diff --git a/src/core/hle/kernel/server_port.cpp b/src/core/hle/kernel/server_port.cpp index 3792e3e18..2c98d3c38 100644 --- a/src/core/hle/kernel/server_port.cpp +++ b/src/core/hle/kernel/server_port.cpp @@ -18,7 +18,7 @@ ServerPort::~ServerPort() = default; ResultVal> ServerPort::Accept() { if (pending_sessions.empty()) { - return ERR_NO_PENDING_SESSIONS; + return ERR_NOT_FOUND; } auto session = std::move(pending_sessions.back()); -- cgit v1.2.3 From 474bc29208c8fa5f032a235afbc5bcf94dfcc470 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 24 Oct 2018 14:24:36 -0400 Subject: kernel/server_port: Simplify emptiness check within ShouldWait() --- src/core/hle/kernel/server_port.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/hle/kernel/server_port.cpp b/src/core/hle/kernel/server_port.cpp index 2c98d3c38..d6ceeb2da 100644 --- a/src/core/hle/kernel/server_port.cpp +++ b/src/core/hle/kernel/server_port.cpp @@ -28,7 +28,7 @@ ResultVal> ServerPort::Accept() { bool ServerPort::ShouldWait(Thread* thread) const { // If there are no pending sessions, we wait until a new one is added. - return pending_sessions.size() == 0; + return pending_sessions.empty(); } void ServerPort::Acquire(Thread* thread) { -- cgit v1.2.3 From 239dfea34a08fc370028de96dc094cca66f6e961 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 24 Oct 2018 14:54:32 -0400 Subject: kernel/shared_memory: Return ERR_INVALID_MEMORY_PERMISSIONS instead of ERR_INVALID_COMBINATION This is more consistent with what the kernel does. --- src/core/hle/kernel/shared_memory.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/core/hle/kernel/shared_memory.cpp b/src/core/hle/kernel/shared_memory.cpp index d061e6155..a016a86b6 100644 --- a/src/core/hle/kernel/shared_memory.cpp +++ b/src/core/hle/kernel/shared_memory.cpp @@ -80,20 +80,19 @@ SharedPtr SharedMemory::CreateForApplet( ResultCode SharedMemory::Map(Process* target_process, VAddr address, MemoryPermission permissions, MemoryPermission other_permissions) { - - MemoryPermission own_other_permissions = + const MemoryPermission own_other_permissions = target_process == owner_process ? this->permissions : this->other_permissions; // Automatically allocated memory blocks can only be mapped with other_permissions = DontCare if (base_address == 0 && other_permissions != MemoryPermission::DontCare) { - return ERR_INVALID_COMBINATION; + return ERR_INVALID_MEMORY_PERMISSIONS; } // Error out if the requested permissions don't match what the creator process allows. if (static_cast(permissions) & ~static_cast(own_other_permissions)) { LOG_ERROR(Kernel, "cannot map id={}, address=0x{:X} name={}, permissions don't match", GetObjectId(), address, name); - return ERR_INVALID_COMBINATION; + return ERR_INVALID_MEMORY_PERMISSIONS; } // Error out if the provided permissions are not compatible with what the creator process needs. -- cgit v1.2.3 From 1fb4bebb63e2824c71259bc72b809d6c2bf48ca9 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 24 Oct 2018 14:55:55 -0400 Subject: kernel/errors: Remove now-unused, unnecessary, error codes Now that we've gotten the innaccurate error codes out of the way, we can finally toss away a bunch of these, trimming down the error codes to ones that are actually used and knocking out two TODO comments. --- src/core/hle/ipc.h | 5 ----- src/core/hle/kernel/errors.h | 8 -------- 2 files changed, 13 deletions(-) diff --git a/src/core/hle/ipc.h b/src/core/hle/ipc.h index 419f45896..ed84197b3 100644 --- a/src/core/hle/ipc.h +++ b/src/core/hle/ipc.h @@ -14,11 +14,6 @@ namespace IPC { /// Size of the command buffer area, in 32-bit words. constexpr std::size_t COMMAND_BUFFER_LENGTH = 0x100 / sizeof(u32); -// These errors are commonly returned by invalid IPC translations, so alias them here for -// convenience. -// TODO(yuriks): These will probably go away once translation is implemented inside the kernel. -constexpr auto ERR_INVALID_HANDLE = Kernel::ERR_INVALID_HANDLE_OS; - enum class ControlCommand : u32 { ConvertSessionToDomain = 0, ConvertDomainToSession = 1, diff --git a/src/core/hle/kernel/errors.h b/src/core/hle/kernel/errors.h index 92436ae6d..ee698c8a7 100644 --- a/src/core/hle/kernel/errors.h +++ b/src/core/hle/kernel/errors.h @@ -38,18 +38,14 @@ enum { // WARNING: The kernel is quite inconsistent in it's usage of errors code. Make sure to always // double check that the code matches before re-using the constant. -// TODO(bunnei): Replace -1 with correct errors for Switch OS constexpr ResultCode ERR_HANDLE_TABLE_FULL(ErrorModule::Kernel, ErrCodes::HandleTableFull); constexpr ResultCode ERR_SESSION_CLOSED_BY_REMOTE(ErrorModule::Kernel, ErrCodes::SessionClosed); constexpr ResultCode ERR_PORT_NAME_TOO_LONG(ErrorModule::Kernel, ErrCodes::TooLarge); constexpr ResultCode ERR_MAX_CONNECTIONS_REACHED(ErrorModule::Kernel, ErrCodes::MaxConnectionsReached); constexpr ResultCode ERR_INVALID_ENUM_VALUE(ErrorModule::Kernel, ErrCodes::InvalidEnumValue); -constexpr ResultCode ERR_INVALID_ENUM_VALUE_FND(-1); -constexpr ResultCode ERR_INVALID_COMBINATION(-1); constexpr ResultCode ERR_INVALID_COMBINATION_KERNEL(ErrorModule::Kernel, ErrCodes::InvalidCombination); -constexpr ResultCode ERR_OUT_OF_MEMORY(-1); constexpr ResultCode ERR_INVALID_ADDRESS(ErrorModule::Kernel, ErrCodes::InvalidAddress); constexpr ResultCode ERR_INVALID_ADDRESS_STATE(ErrorModule::Kernel, ErrCodes::InvalidMemoryState); constexpr ResultCode ERR_INVALID_MEMORY_PERMISSIONS(ErrorModule::Kernel, @@ -63,10 +59,6 @@ constexpr ResultCode ERR_INVALID_STATE(ErrorModule::Kernel, ErrCodes::InvalidSta constexpr ResultCode ERR_INVALID_THREAD_PRIORITY(ErrorModule::Kernel, ErrCodes::InvalidThreadPriority); constexpr ResultCode ERR_INVALID_POINTER(ErrorModule::Kernel, ErrCodes::InvalidPointer); -constexpr ResultCode ERR_INVALID_OBJECT_ADDR(-1); -constexpr ResultCode ERR_NOT_AUTHORIZED(-1); -/// Alternate code returned instead of ERR_INVALID_HANDLE in some code paths. -constexpr ResultCode ERR_INVALID_HANDLE_OS(-1); constexpr ResultCode ERR_NOT_FOUND(ErrorModule::Kernel, ErrCodes::NoSuchEntry); constexpr ResultCode RESULT_TIMEOUT(ErrorModule::Kernel, ErrCodes::Timeout); -- cgit v1.2.3