Merge pull request #1577 from lioncash/err
kernel/error: Amend error return code values
This commit is contained in:
commit
c94db0e071
|
@ -14,11 +14,6 @@ namespace IPC {
|
||||||
/// Size of the command buffer area, in 32-bit words.
|
/// Size of the command buffer area, in 32-bit words.
|
||||||
constexpr std::size_t COMMAND_BUFFER_LENGTH = 0x100 / sizeof(u32);
|
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 {
|
enum class ControlCommand : u32 {
|
||||||
ConvertSessionToDomain = 0,
|
ConvertSessionToDomain = 0,
|
||||||
ConvertDomainToSession = 1,
|
ConvertDomainToSession = 1,
|
||||||
|
|
|
@ -10,11 +10,6 @@ namespace Kernel {
|
||||||
|
|
||||||
namespace ErrCodes {
|
namespace ErrCodes {
|
||||||
enum {
|
enum {
|
||||||
// TODO(Subv): Remove these 3DS OS error codes.
|
|
||||||
SessionClosedByRemote = 26,
|
|
||||||
NoPendingSessions = 35,
|
|
||||||
InvalidBufferDescriptor = 48,
|
|
||||||
|
|
||||||
// Confirmed Switch OS error codes
|
// Confirmed Switch OS error codes
|
||||||
MaxConnectionsReached = 7,
|
MaxConnectionsReached = 7,
|
||||||
InvalidSize = 101,
|
InvalidSize = 101,
|
||||||
|
@ -26,6 +21,7 @@ enum {
|
||||||
InvalidThreadPriority = 112,
|
InvalidThreadPriority = 112,
|
||||||
InvalidProcessorId = 113,
|
InvalidProcessorId = 113,
|
||||||
InvalidHandle = 114,
|
InvalidHandle = 114,
|
||||||
|
InvalidPointer = 115,
|
||||||
InvalidCombination = 116,
|
InvalidCombination = 116,
|
||||||
Timeout = 117,
|
Timeout = 117,
|
||||||
SynchronizationCanceled = 118,
|
SynchronizationCanceled = 118,
|
||||||
|
@ -33,6 +29,7 @@ enum {
|
||||||
InvalidEnumValue = 120,
|
InvalidEnumValue = 120,
|
||||||
NoSuchEntry = 121,
|
NoSuchEntry = 121,
|
||||||
AlreadyRegistered = 122,
|
AlreadyRegistered = 122,
|
||||||
|
SessionClosed = 123,
|
||||||
InvalidState = 125,
|
InvalidState = 125,
|
||||||
ResourceLimitExceeded = 132,
|
ResourceLimitExceeded = 132,
|
||||||
};
|
};
|
||||||
|
@ -41,18 +38,14 @@ enum {
|
||||||
// WARNING: The kernel is quite inconsistent in it's usage of errors code. Make sure to always
|
// 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.
|
// 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_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_PORT_NAME_TOO_LONG(ErrorModule::Kernel, ErrCodes::TooLarge);
|
||||||
constexpr ResultCode ERR_MAX_CONNECTIONS_REACHED(ErrorModule::Kernel,
|
constexpr ResultCode ERR_MAX_CONNECTIONS_REACHED(ErrorModule::Kernel,
|
||||||
ErrCodes::MaxConnectionsReached);
|
ErrCodes::MaxConnectionsReached);
|
||||||
constexpr ResultCode ERR_INVALID_ENUM_VALUE(ErrorModule::Kernel, ErrCodes::InvalidEnumValue);
|
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,
|
constexpr ResultCode ERR_INVALID_COMBINATION_KERNEL(ErrorModule::Kernel,
|
||||||
ErrCodes::InvalidCombination);
|
ErrCodes::InvalidCombination);
|
||||||
constexpr ResultCode ERR_OUT_OF_MEMORY(-1);
|
|
||||||
constexpr ResultCode ERR_INVALID_ADDRESS(ErrorModule::Kernel, ErrCodes::InvalidAddress);
|
constexpr ResultCode ERR_INVALID_ADDRESS(ErrorModule::Kernel, ErrCodes::InvalidAddress);
|
||||||
constexpr ResultCode ERR_INVALID_ADDRESS_STATE(ErrorModule::Kernel, ErrCodes::InvalidMemoryState);
|
constexpr ResultCode ERR_INVALID_ADDRESS_STATE(ErrorModule::Kernel, ErrCodes::InvalidMemoryState);
|
||||||
constexpr ResultCode ERR_INVALID_MEMORY_PERMISSIONS(ErrorModule::Kernel,
|
constexpr ResultCode ERR_INVALID_MEMORY_PERMISSIONS(ErrorModule::Kernel,
|
||||||
|
@ -65,14 +58,8 @@ constexpr ResultCode ERR_ALREADY_REGISTERED(ErrorModule::Kernel, ErrCodes::Alrea
|
||||||
constexpr ResultCode ERR_INVALID_STATE(ErrorModule::Kernel, ErrCodes::InvalidState);
|
constexpr ResultCode ERR_INVALID_STATE(ErrorModule::Kernel, ErrCodes::InvalidState);
|
||||||
constexpr ResultCode ERR_INVALID_THREAD_PRIORITY(ErrorModule::Kernel,
|
constexpr ResultCode ERR_INVALID_THREAD_PRIORITY(ErrorModule::Kernel,
|
||||||
ErrCodes::InvalidThreadPriority);
|
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.
|
|
||||||
constexpr ResultCode ERR_INVALID_HANDLE_OS(-1);
|
|
||||||
constexpr ResultCode ERR_NOT_FOUND(ErrorModule::Kernel, ErrCodes::NoSuchEntry);
|
constexpr ResultCode ERR_NOT_FOUND(ErrorModule::Kernel, ErrCodes::NoSuchEntry);
|
||||||
constexpr ResultCode RESULT_TIMEOUT(ErrorModule::Kernel, ErrCodes::Timeout);
|
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
|
} // namespace Kernel
|
||||||
|
|
|
@ -18,7 +18,7 @@ ServerPort::~ServerPort() = default;
|
||||||
|
|
||||||
ResultVal<SharedPtr<ServerSession>> ServerPort::Accept() {
|
ResultVal<SharedPtr<ServerSession>> ServerPort::Accept() {
|
||||||
if (pending_sessions.empty()) {
|
if (pending_sessions.empty()) {
|
||||||
return ERR_NO_PENDING_SESSIONS;
|
return ERR_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto session = std::move(pending_sessions.back());
|
auto session = std::move(pending_sessions.back());
|
||||||
|
@ -28,7 +28,7 @@ ResultVal<SharedPtr<ServerSession>> ServerPort::Accept() {
|
||||||
|
|
||||||
bool ServerPort::ShouldWait(Thread* thread) const {
|
bool ServerPort::ShouldWait(Thread* thread) const {
|
||||||
// If there are no pending sessions, we wait until a new one is added.
|
// 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) {
|
void ServerPort::Acquire(Thread* thread) {
|
||||||
|
|
|
@ -80,20 +80,19 @@ SharedPtr<SharedMemory> SharedMemory::CreateForApplet(
|
||||||
|
|
||||||
ResultCode SharedMemory::Map(Process* target_process, VAddr address, MemoryPermission permissions,
|
ResultCode SharedMemory::Map(Process* target_process, VAddr address, MemoryPermission permissions,
|
||||||
MemoryPermission other_permissions) {
|
MemoryPermission other_permissions) {
|
||||||
|
const MemoryPermission own_other_permissions =
|
||||||
MemoryPermission own_other_permissions =
|
|
||||||
target_process == owner_process ? this->permissions : this->other_permissions;
|
target_process == owner_process ? this->permissions : this->other_permissions;
|
||||||
|
|
||||||
// Automatically allocated memory blocks can only be mapped with other_permissions = DontCare
|
// Automatically allocated memory blocks can only be mapped with other_permissions = DontCare
|
||||||
if (base_address == 0 && other_permissions != MemoryPermission::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.
|
// Error out if the requested permissions don't match what the creator process allows.
|
||||||
if (static_cast<u32>(permissions) & ~static_cast<u32>(own_other_permissions)) {
|
if (static_cast<u32>(permissions) & ~static_cast<u32>(own_other_permissions)) {
|
||||||
LOG_ERROR(Kernel, "cannot map id={}, address=0x{:X} name={}, permissions don't match",
|
LOG_ERROR(Kernel, "cannot map id={}, address=0x{:X} name={}, permissions don't match",
|
||||||
GetObjectId(), address, name);
|
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.
|
// Error out if the provided permissions are not compatible with what the creator process needs.
|
||||||
|
|
|
@ -594,16 +594,17 @@ static ResultCode SetThreadPriority(Handle handle, u32 priority) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto* const current_process = Core::CurrentProcess();
|
const auto* const current_process = Core::CurrentProcess();
|
||||||
SharedPtr<Thread> thread = current_process->GetHandleTable().Get<Thread>(handle);
|
|
||||||
if (!thread) {
|
|
||||||
return ERR_INVALID_HANDLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Note: The kernel uses the current process's resource limit instead of
|
// Note: The kernel uses the current process's resource limit instead of
|
||||||
// the one from the thread owner's resource limit.
|
// the one from the thread owner's resource limit.
|
||||||
const ResourceLimit& resource_limit = current_process->GetResourceLimit();
|
const ResourceLimit& resource_limit = current_process->GetResourceLimit();
|
||||||
if (resource_limit.GetMaxResourceValue(ResourceType::Priority) > priority) {
|
if (resource_limit.GetMaxResourceValue(ResourceType::Priority) > priority) {
|
||||||
return ERR_NOT_AUTHORIZED;
|
return ERR_INVALID_THREAD_PRIORITY;
|
||||||
|
}
|
||||||
|
|
||||||
|
SharedPtr<Thread> thread = current_process->GetHandleTable().Get<Thread>(handle);
|
||||||
|
if (!thread) {
|
||||||
|
return ERR_INVALID_HANDLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
thread->SetPriority(priority);
|
thread->SetPriority(priority);
|
||||||
|
@ -745,7 +746,7 @@ static ResultCode CreateThread(Handle* out_handle, VAddr entry_point, u64 arg, V
|
||||||
auto* const current_process = Core::CurrentProcess();
|
auto* const current_process = Core::CurrentProcess();
|
||||||
const ResourceLimit& resource_limit = current_process->GetResourceLimit();
|
const ResourceLimit& resource_limit = current_process->GetResourceLimit();
|
||||||
if (resource_limit.GetMaxResourceValue(ResourceType::Priority) > priority) {
|
if (resource_limit.GetMaxResourceValue(ResourceType::Priority) > priority) {
|
||||||
return ERR_NOT_AUTHORIZED;
|
return ERR_INVALID_THREAD_PRIORITY;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (processor_id == THREADPROCESSORID_DEFAULT) {
|
if (processor_id == THREADPROCESSORID_DEFAULT) {
|
||||||
|
|
Loading…
Reference in a new issue