diff options
| author | 2021-02-13 10:43:01 +1100 | |
|---|---|---|
| committer | 2021-02-12 15:43:01 -0800 | |
| commit | 37939482fb93d2155d8625596f2b1145d4f6e8e3 (patch) | |
| tree | 0c18a00c0f9be5cc87b50ff46c439765d9f7db46 /src/core/hle/kernel/svc.cpp | |
| parent | Merge pull request #5902 from lioncash/core-warn (diff) | |
| download | yuzu-37939482fb93d2155d8625596f2b1145d4f6e8e3.tar.gz yuzu-37939482fb93d2155d8625596f2b1145d4f6e8e3.tar.xz yuzu-37939482fb93d2155d8625596f2b1145d4f6e8e3.zip | |
kernel: Unify result codes (#5890)
* kernel: Unify result codes
Drop the usage of ERR_NAME convention in kernel for ResultName. Removed seperation between svc_results.h & errors.h as we mainly include both most of the time anyways.
* oops
* rename errors to svc_results
Diffstat (limited to 'src/core/hle/kernel/svc.cpp')
| -rw-r--r-- | src/core/hle/kernel/svc.cpp | 196 |
1 files changed, 98 insertions, 98 deletions
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 @@ | |||
| 23 | #include "core/cpu_manager.h" | 23 | #include "core/cpu_manager.h" |
| 24 | #include "core/hle/kernel/client_port.h" | 24 | #include "core/hle/kernel/client_port.h" |
| 25 | #include "core/hle/kernel/client_session.h" | 25 | #include "core/hle/kernel/client_session.h" |
| 26 | #include "core/hle/kernel/errors.h" | ||
| 27 | #include "core/hle/kernel/handle_table.h" | 26 | #include "core/hle/kernel/handle_table.h" |
| 28 | #include "core/hle/kernel/k_address_arbiter.h" | 27 | #include "core/hle/kernel/k_address_arbiter.h" |
| 29 | #include "core/hle/kernel/k_condition_variable.h" | 28 | #include "core/hle/kernel/k_condition_variable.h" |
| @@ -71,49 +70,49 @@ ResultCode MapUnmapMemorySanityChecks(const Memory::PageTable& manager, VAddr ds | |||
| 71 | VAddr src_addr, u64 size) { | 70 | VAddr src_addr, u64 size) { |
| 72 | if (!Common::Is4KBAligned(dst_addr)) { | 71 | if (!Common::Is4KBAligned(dst_addr)) { |
| 73 | LOG_ERROR(Kernel_SVC, "Destination address is not aligned to 4KB, 0x{:016X}", dst_addr); | 72 | LOG_ERROR(Kernel_SVC, "Destination address is not aligned to 4KB, 0x{:016X}", dst_addr); |
| 74 | return ERR_INVALID_ADDRESS; | 73 | return ResultInvalidAddress; |
| 75 | } | 74 | } |
| 76 | 75 | ||
| 77 | if (!Common::Is4KBAligned(src_addr)) { | 76 | if (!Common::Is4KBAligned(src_addr)) { |
| 78 | LOG_ERROR(Kernel_SVC, "Source address is not aligned to 4KB, 0x{:016X}", src_addr); | 77 | LOG_ERROR(Kernel_SVC, "Source address is not aligned to 4KB, 0x{:016X}", src_addr); |
| 79 | return ERR_INVALID_SIZE; | 78 | return ResultInvalidSize; |
| 80 | } | 79 | } |
| 81 | 80 | ||
| 82 | if (size == 0) { | 81 | if (size == 0) { |
| 83 | LOG_ERROR(Kernel_SVC, "Size is 0"); | 82 | LOG_ERROR(Kernel_SVC, "Size is 0"); |
| 84 | return ERR_INVALID_SIZE; | 83 | return ResultInvalidSize; |
| 85 | } | 84 | } |
| 86 | 85 | ||
| 87 | if (!Common::Is4KBAligned(size)) { | 86 | if (!Common::Is4KBAligned(size)) { |
| 88 | LOG_ERROR(Kernel_SVC, "Size is not aligned to 4KB, 0x{:016X}", size); | 87 | LOG_ERROR(Kernel_SVC, "Size is not aligned to 4KB, 0x{:016X}", size); |
| 89 | return ERR_INVALID_SIZE; | 88 | return ResultInvalidSize; |
| 90 | } | 89 | } |
| 91 | 90 | ||
| 92 | if (!IsValidAddressRange(dst_addr, size)) { | 91 | if (!IsValidAddressRange(dst_addr, size)) { |
| 93 | LOG_ERROR(Kernel_SVC, | 92 | LOG_ERROR(Kernel_SVC, |
| 94 | "Destination is not a valid address range, addr=0x{:016X}, size=0x{:016X}", | 93 | "Destination is not a valid address range, addr=0x{:016X}, size=0x{:016X}", |
| 95 | dst_addr, size); | 94 | dst_addr, size); |
| 96 | return ERR_INVALID_ADDRESS_STATE; | 95 | return ResultInvalidCurrentMemory; |
| 97 | } | 96 | } |
| 98 | 97 | ||
| 99 | if (!IsValidAddressRange(src_addr, size)) { | 98 | if (!IsValidAddressRange(src_addr, size)) { |
| 100 | LOG_ERROR(Kernel_SVC, "Source is not a valid address range, addr=0x{:016X}, size=0x{:016X}", | 99 | LOG_ERROR(Kernel_SVC, "Source is not a valid address range, addr=0x{:016X}, size=0x{:016X}", |
| 101 | src_addr, size); | 100 | src_addr, size); |
| 102 | return ERR_INVALID_ADDRESS_STATE; | 101 | return ResultInvalidCurrentMemory; |
| 103 | } | 102 | } |
| 104 | 103 | ||
| 105 | if (!manager.IsInsideAddressSpace(src_addr, size)) { | 104 | if (!manager.IsInsideAddressSpace(src_addr, size)) { |
| 106 | LOG_ERROR(Kernel_SVC, | 105 | LOG_ERROR(Kernel_SVC, |
| 107 | "Source is not within the address space, addr=0x{:016X}, size=0x{:016X}", | 106 | "Source is not within the address space, addr=0x{:016X}, size=0x{:016X}", |
| 108 | src_addr, size); | 107 | src_addr, size); |
| 109 | return ERR_INVALID_ADDRESS_STATE; | 108 | return ResultInvalidCurrentMemory; |
| 110 | } | 109 | } |
| 111 | 110 | ||
| 112 | if (manager.IsOutsideStackRegion(dst_addr, size)) { | 111 | if (manager.IsOutsideStackRegion(dst_addr, size)) { |
| 113 | LOG_ERROR(Kernel_SVC, | 112 | LOG_ERROR(Kernel_SVC, |
| 114 | "Destination is not within the stack region, addr=0x{:016X}, size=0x{:016X}", | 113 | "Destination is not within the stack region, addr=0x{:016X}, size=0x{:016X}", |
| 115 | dst_addr, size); | 114 | dst_addr, size); |
| 116 | return ERR_INVALID_MEMORY_RANGE; | 115 | return ResultInvalidMemoryRange; |
| 117 | } | 116 | } |
| 118 | 117 | ||
| 119 | if (manager.IsInsideHeapRegion(dst_addr, size)) { | 118 | if (manager.IsInsideHeapRegion(dst_addr, size)) { |
| @@ -121,7 +120,7 @@ ResultCode MapUnmapMemorySanityChecks(const Memory::PageTable& manager, VAddr ds | |||
| 121 | "Destination does not fit within the heap region, addr=0x{:016X}, " | 120 | "Destination does not fit within the heap region, addr=0x{:016X}, " |
| 122 | "size=0x{:016X}", | 121 | "size=0x{:016X}", |
| 123 | dst_addr, size); | 122 | dst_addr, size); |
| 124 | return ERR_INVALID_MEMORY_RANGE; | 123 | return ResultInvalidMemoryRange; |
| 125 | } | 124 | } |
| 126 | 125 | ||
| 127 | if (manager.IsInsideAliasRegion(dst_addr, size)) { | 126 | if (manager.IsInsideAliasRegion(dst_addr, size)) { |
| @@ -129,7 +128,7 @@ ResultCode MapUnmapMemorySanityChecks(const Memory::PageTable& manager, VAddr ds | |||
| 129 | "Destination does not fit within the map region, addr=0x{:016X}, " | 128 | "Destination does not fit within the map region, addr=0x{:016X}, " |
| 130 | "size=0x{:016X}", | 129 | "size=0x{:016X}", |
| 131 | dst_addr, size); | 130 | dst_addr, size); |
| 132 | return ERR_INVALID_MEMORY_RANGE; | 131 | return ResultInvalidMemoryRange; |
| 133 | } | 132 | } |
| 134 | 133 | ||
| 135 | return RESULT_SUCCESS; | 134 | return RESULT_SUCCESS; |
| @@ -146,7 +145,7 @@ ResultVal<s64> RetrieveResourceLimitValue(Core::System& system, Handle resource_ | |||
| 146 | const auto type = static_cast<LimitableResource>(resource_type); | 145 | const auto type = static_cast<LimitableResource>(resource_type); |
| 147 | if (!IsValidResourceType(type)) { | 146 | if (!IsValidResourceType(type)) { |
| 148 | LOG_ERROR(Kernel_SVC, "Invalid resource limit type: '{}'", resource_type); | 147 | LOG_ERROR(Kernel_SVC, "Invalid resource limit type: '{}'", resource_type); |
| 149 | return ERR_INVALID_ENUM_VALUE; | 148 | return ResultInvalidEnumValue; |
| 150 | } | 149 | } |
| 151 | 150 | ||
| 152 | const auto* const current_process = system.Kernel().CurrentProcess(); | 151 | const auto* const current_process = system.Kernel().CurrentProcess(); |
| @@ -157,7 +156,7 @@ ResultVal<s64> RetrieveResourceLimitValue(Core::System& system, Handle resource_ | |||
| 157 | if (!resource_limit_object) { | 156 | if (!resource_limit_object) { |
| 158 | LOG_ERROR(Kernel_SVC, "Handle to non-existent resource limit instance used. Handle={:08X}", | 157 | LOG_ERROR(Kernel_SVC, "Handle to non-existent resource limit instance used. Handle={:08X}", |
| 159 | resource_limit); | 158 | resource_limit); |
| 160 | return ERR_INVALID_HANDLE; | 159 | return ResultInvalidHandle; |
| 161 | } | 160 | } |
| 162 | 161 | ||
| 163 | if (value_type == ResourceLimitValueType::CurrentValue) { | 162 | if (value_type == ResourceLimitValueType::CurrentValue) { |
| @@ -177,12 +176,12 @@ static ResultCode SetHeapSize(Core::System& system, VAddr* heap_addr, u64 heap_s | |||
| 177 | if ((heap_size % 0x200000) != 0) { | 176 | if ((heap_size % 0x200000) != 0) { |
| 178 | LOG_ERROR(Kernel_SVC, "The heap size is not a multiple of 2MB, heap_size=0x{:016X}", | 177 | LOG_ERROR(Kernel_SVC, "The heap size is not a multiple of 2MB, heap_size=0x{:016X}", |
| 179 | heap_size); | 178 | heap_size); |
| 180 | return ERR_INVALID_SIZE; | 179 | return ResultInvalidSize; |
| 181 | } | 180 | } |
| 182 | 181 | ||
| 183 | if (heap_size >= 0x200000000) { | 182 | if (heap_size >= 0x200000000) { |
| 184 | LOG_ERROR(Kernel_SVC, "The heap size is not less than 8GB, heap_size=0x{:016X}", heap_size); | 183 | LOG_ERROR(Kernel_SVC, "The heap size is not less than 8GB, heap_size=0x{:016X}", heap_size); |
| 185 | return ERR_INVALID_SIZE; | 184 | return ResultInvalidSize; |
| 186 | } | 185 | } |
| 187 | 186 | ||
| 188 | auto& page_table{system.Kernel().CurrentProcess()->PageTable()}; | 187 | auto& page_table{system.Kernel().CurrentProcess()->PageTable()}; |
| @@ -208,19 +207,19 @@ static ResultCode SetMemoryAttribute(Core::System& system, VAddr address, u64 si | |||
| 208 | 207 | ||
| 209 | if (!Common::Is4KBAligned(address)) { | 208 | if (!Common::Is4KBAligned(address)) { |
| 210 | LOG_ERROR(Kernel_SVC, "Address not page aligned (0x{:016X})", address); | 209 | LOG_ERROR(Kernel_SVC, "Address not page aligned (0x{:016X})", address); |
| 211 | return ERR_INVALID_ADDRESS; | 210 | return ResultInvalidAddress; |
| 212 | } | 211 | } |
| 213 | 212 | ||
| 214 | if (size == 0 || !Common::Is4KBAligned(size)) { | 213 | if (size == 0 || !Common::Is4KBAligned(size)) { |
| 215 | LOG_ERROR(Kernel_SVC, "Invalid size (0x{:X}). Size must be non-zero and page aligned.", | 214 | LOG_ERROR(Kernel_SVC, "Invalid size (0x{:X}). Size must be non-zero and page aligned.", |
| 216 | size); | 215 | size); |
| 217 | return ERR_INVALID_ADDRESS; | 216 | return ResultInvalidAddress; |
| 218 | } | 217 | } |
| 219 | 218 | ||
| 220 | if (!IsValidAddressRange(address, size)) { | 219 | if (!IsValidAddressRange(address, size)) { |
| 221 | LOG_ERROR(Kernel_SVC, "Address range overflowed (Address: 0x{:016X}, Size: 0x{:016X})", | 220 | LOG_ERROR(Kernel_SVC, "Address range overflowed (Address: 0x{:016X}, Size: 0x{:016X})", |
| 222 | address, size); | 221 | address, size); |
| 223 | return ERR_INVALID_ADDRESS_STATE; | 222 | return ResultInvalidCurrentMemory; |
| 224 | } | 223 | } |
| 225 | 224 | ||
| 226 | const auto attributes{static_cast<Memory::MemoryAttribute>(mask | attribute)}; | 225 | const auto attributes{static_cast<Memory::MemoryAttribute>(mask | attribute)}; |
| @@ -229,7 +228,7 @@ static ResultCode SetMemoryAttribute(Core::System& system, VAddr address, u64 si | |||
| 229 | LOG_ERROR(Kernel_SVC, | 228 | LOG_ERROR(Kernel_SVC, |
| 230 | "Memory attribute doesn't match the given mask (Attribute: 0x{:X}, Mask: {:X}", | 229 | "Memory attribute doesn't match the given mask (Attribute: 0x{:X}, Mask: {:X}", |
| 231 | attribute, mask); | 230 | attribute, mask); |
| 232 | return ERR_INVALID_COMBINATION; | 231 | return ResultInvalidCombination; |
| 233 | } | 232 | } |
| 234 | 233 | ||
| 235 | auto& page_table{system.Kernel().CurrentProcess()->PageTable()}; | 234 | auto& page_table{system.Kernel().CurrentProcess()->PageTable()}; |
| @@ -293,7 +292,7 @@ static ResultCode ConnectToNamedPort(Core::System& system, Handle* out_handle, | |||
| 293 | LOG_ERROR(Kernel_SVC, | 292 | LOG_ERROR(Kernel_SVC, |
| 294 | "Port Name Address is not a valid virtual address, port_name_address=0x{:016X}", | 293 | "Port Name Address is not a valid virtual address, port_name_address=0x{:016X}", |
| 295 | port_name_address); | 294 | port_name_address); |
| 296 | return ERR_NOT_FOUND; | 295 | return ResultNotFound; |
| 297 | } | 296 | } |
| 298 | 297 | ||
| 299 | static constexpr std::size_t PortNameMaxLength = 11; | 298 | static constexpr std::size_t PortNameMaxLength = 11; |
| @@ -302,7 +301,7 @@ static ResultCode ConnectToNamedPort(Core::System& system, Handle* out_handle, | |||
| 302 | if (port_name.size() > PortNameMaxLength) { | 301 | if (port_name.size() > PortNameMaxLength) { |
| 303 | LOG_ERROR(Kernel_SVC, "Port name is too long, expected {} but got {}", PortNameMaxLength, | 302 | LOG_ERROR(Kernel_SVC, "Port name is too long, expected {} but got {}", PortNameMaxLength, |
| 304 | port_name.size()); | 303 | port_name.size()); |
| 305 | return ERR_OUT_OF_RANGE; | 304 | return ResultOutOfRange; |
| 306 | } | 305 | } |
| 307 | 306 | ||
| 308 | LOG_TRACE(Kernel_SVC, "called port_name={}", port_name); | 307 | LOG_TRACE(Kernel_SVC, "called port_name={}", port_name); |
| @@ -311,7 +310,7 @@ static ResultCode ConnectToNamedPort(Core::System& system, Handle* out_handle, | |||
| 311 | const auto it = kernel.FindNamedPort(port_name); | 310 | const auto it = kernel.FindNamedPort(port_name); |
| 312 | if (!kernel.IsValidNamedPort(it)) { | 311 | if (!kernel.IsValidNamedPort(it)) { |
| 313 | LOG_WARNING(Kernel_SVC, "tried to connect to unknown port: {}", port_name); | 312 | LOG_WARNING(Kernel_SVC, "tried to connect to unknown port: {}", port_name); |
| 314 | return ERR_NOT_FOUND; | 313 | return ResultNotFound; |
| 315 | } | 314 | } |
| 316 | 315 | ||
| 317 | ASSERT(kernel.CurrentProcess()->GetResourceLimit()->Reserve(LimitableResource::Sessions, 1)); | 316 | ASSERT(kernel.CurrentProcess()->GetResourceLimit()->Reserve(LimitableResource::Sessions, 1)); |
| @@ -340,7 +339,7 @@ static ResultCode SendSyncRequest(Core::System& system, Handle handle) { | |||
| 340 | std::shared_ptr<ClientSession> session = handle_table.Get<ClientSession>(handle); | 339 | std::shared_ptr<ClientSession> session = handle_table.Get<ClientSession>(handle); |
| 341 | if (!session) { | 340 | if (!session) { |
| 342 | LOG_ERROR(Kernel_SVC, "called with invalid handle=0x{:08X}", handle); | 341 | LOG_ERROR(Kernel_SVC, "called with invalid handle=0x{:08X}", handle); |
| 343 | return ERR_INVALID_HANDLE; | 342 | return ResultInvalidHandle; |
| 344 | } | 343 | } |
| 345 | 344 | ||
| 346 | LOG_TRACE(Kernel_SVC, "called handle=0x{:08X}({})", handle, session->GetName()); | 345 | 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 | |||
| 405 | const Process* const owner_process = thread->GetOwnerProcess(); | 404 | const Process* const owner_process = thread->GetOwnerProcess(); |
| 406 | if (!owner_process) { | 405 | if (!owner_process) { |
| 407 | LOG_ERROR(Kernel_SVC, "Non-existent owning process encountered."); | 406 | LOG_ERROR(Kernel_SVC, "Non-existent owning process encountered."); |
| 408 | return ERR_INVALID_HANDLE; | 407 | return ResultInvalidHandle; |
| 409 | } | 408 | } |
| 410 | 409 | ||
| 411 | *process_id = owner_process->GetProcessID(); | 410 | *process_id = owner_process->GetProcessID(); |
| @@ -415,7 +414,7 @@ static ResultCode GetProcessId(Core::System& system, u64* process_id, Handle han | |||
| 415 | // NOTE: This should also handle debug objects before returning. | 414 | // NOTE: This should also handle debug objects before returning. |
| 416 | 415 | ||
| 417 | LOG_ERROR(Kernel_SVC, "Handle does not exist, handle=0x{:08X}", handle); | 416 | LOG_ERROR(Kernel_SVC, "Handle does not exist, handle=0x{:08X}", handle); |
| 418 | return ERR_INVALID_HANDLE; | 417 | return ResultInvalidHandle; |
| 419 | } | 418 | } |
| 420 | 419 | ||
| 421 | static ResultCode GetProcessId32(Core::System& system, u32* process_id_low, u32* process_id_high, | 420 | 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 | |||
| 438 | LOG_ERROR(Kernel_SVC, | 437 | LOG_ERROR(Kernel_SVC, |
| 439 | "Handle address is not a valid virtual address, handle_address=0x{:016X}", | 438 | "Handle address is not a valid virtual address, handle_address=0x{:016X}", |
| 440 | handles_address); | 439 | handles_address); |
| 441 | return ERR_INVALID_POINTER; | 440 | return ResultInvalidPointer; |
| 442 | } | 441 | } |
| 443 | 442 | ||
| 444 | static constexpr u64 MaxHandles = 0x40; | 443 | static constexpr u64 MaxHandles = 0x40; |
| @@ -446,7 +445,7 @@ static ResultCode WaitSynchronization(Core::System& system, s32* index, VAddr ha | |||
| 446 | if (handle_count > MaxHandles) { | 445 | if (handle_count > MaxHandles) { |
| 447 | LOG_ERROR(Kernel_SVC, "Handle count specified is too large, expected {} but got {}", | 446 | LOG_ERROR(Kernel_SVC, "Handle count specified is too large, expected {} but got {}", |
| 448 | MaxHandles, handle_count); | 447 | MaxHandles, handle_count); |
| 449 | return ERR_OUT_OF_RANGE; | 448 | return ResultOutOfRange; |
| 450 | } | 449 | } |
| 451 | 450 | ||
| 452 | auto& kernel = system.Kernel(); | 451 | auto& kernel = system.Kernel(); |
| @@ -459,7 +458,7 @@ static ResultCode WaitSynchronization(Core::System& system, s32* index, VAddr ha | |||
| 459 | 458 | ||
| 460 | if (object == nullptr) { | 459 | if (object == nullptr) { |
| 461 | LOG_ERROR(Kernel_SVC, "Object is a nullptr"); | 460 | LOG_ERROR(Kernel_SVC, "Object is a nullptr"); |
| 462 | return ERR_INVALID_HANDLE; | 461 | return ResultInvalidHandle; |
| 463 | } | 462 | } |
| 464 | 463 | ||
| 465 | objects[i] = object.get(); | 464 | objects[i] = object.get(); |
| @@ -481,6 +480,7 @@ static ResultCode CancelSynchronization(Core::System& system, Handle thread_hand | |||
| 481 | // Get the thread from its handle. | 480 | // Get the thread from its handle. |
| 482 | const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); | 481 | const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); |
| 483 | std::shared_ptr<KThread> thread = handle_table.Get<KThread>(thread_handle); | 482 | std::shared_ptr<KThread> thread = handle_table.Get<KThread>(thread_handle); |
| 483 | |||
| 484 | if (!thread) { | 484 | if (!thread) { |
| 485 | LOG_ERROR(Kernel_SVC, "Invalid thread handle provided (handle={:08X})", thread_handle); | 485 | LOG_ERROR(Kernel_SVC, "Invalid thread handle provided (handle={:08X})", thread_handle); |
| 486 | return ResultInvalidHandle; | 486 | return ResultInvalidHandle; |
| @@ -525,6 +525,7 @@ static ResultCode ArbitrateUnlock(Core::System& system, VAddr address) { | |||
| 525 | LOG_TRACE(Kernel_SVC, "called address=0x{:X}", address); | 525 | LOG_TRACE(Kernel_SVC, "called address=0x{:X}", address); |
| 526 | 526 | ||
| 527 | // Validate the input address. | 527 | // Validate the input address. |
| 528 | |||
| 528 | if (Memory::IsKernelAddress(address)) { | 529 | if (Memory::IsKernelAddress(address)) { |
| 529 | LOG_ERROR(Kernel_SVC, | 530 | LOG_ERROR(Kernel_SVC, |
| 530 | "Attempting to arbitrate an unlock on a kernel address (address={:08X})", | 531 | "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 | |||
| 735 | if (info_sub_id != 0) { | 736 | if (info_sub_id != 0) { |
| 736 | LOG_ERROR(Kernel_SVC, "Info sub id is non zero! info_id={}, info_sub_id={}", info_id, | 737 | LOG_ERROR(Kernel_SVC, "Info sub id is non zero! info_id={}, info_sub_id={}", info_id, |
| 737 | info_sub_id); | 738 | info_sub_id); |
| 738 | return ERR_INVALID_ENUM_VALUE; | 739 | return ResultInvalidEnumValue; |
| 739 | } | 740 | } |
| 740 | 741 | ||
| 741 | const auto& current_process_handle_table = | 742 | const auto& current_process_handle_table = |
| @@ -744,7 +745,7 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, u64 ha | |||
| 744 | if (!process) { | 745 | if (!process) { |
| 745 | LOG_ERROR(Kernel_SVC, "Process is not valid! info_id={}, info_sub_id={}, handle={:08X}", | 746 | LOG_ERROR(Kernel_SVC, "Process is not valid! info_id={}, info_sub_id={}, handle={:08X}", |
| 746 | info_id, info_sub_id, handle); | 747 | info_id, info_sub_id, handle); |
| 747 | return ERR_INVALID_HANDLE; | 748 | return ResultInvalidHandle; |
| 748 | } | 749 | } |
| 749 | 750 | ||
| 750 | switch (info_id_type) { | 751 | switch (info_id_type) { |
| @@ -826,7 +827,7 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, u64 ha | |||
| 826 | } | 827 | } |
| 827 | 828 | ||
| 828 | LOG_ERROR(Kernel_SVC, "Unimplemented svcGetInfo id=0x{:016X}", info_id); | 829 | LOG_ERROR(Kernel_SVC, "Unimplemented svcGetInfo id=0x{:016X}", info_id); |
| 829 | return ERR_INVALID_ENUM_VALUE; | 830 | return ResultInvalidEnumValue; |
| 830 | } | 831 | } |
| 831 | 832 | ||
| 832 | case GetInfoType::IsCurrentProcessBeingDebugged: | 833 | case GetInfoType::IsCurrentProcessBeingDebugged: |
| @@ -836,13 +837,13 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, u64 ha | |||
| 836 | case GetInfoType::RegisterResourceLimit: { | 837 | case GetInfoType::RegisterResourceLimit: { |
| 837 | if (handle != 0) { | 838 | if (handle != 0) { |
| 838 | LOG_ERROR(Kernel, "Handle is non zero! handle={:08X}", handle); | 839 | LOG_ERROR(Kernel, "Handle is non zero! handle={:08X}", handle); |
| 839 | return ERR_INVALID_HANDLE; | 840 | return ResultInvalidHandle; |
| 840 | } | 841 | } |
| 841 | 842 | ||
| 842 | if (info_sub_id != 0) { | 843 | if (info_sub_id != 0) { |
| 843 | LOG_ERROR(Kernel, "Info sub id is non zero! info_id={}, info_sub_id={}", info_id, | 844 | LOG_ERROR(Kernel, "Info sub id is non zero! info_id={}, info_sub_id={}", info_id, |
| 844 | info_sub_id); | 845 | info_sub_id); |
| 845 | return ERR_INVALID_COMBINATION; | 846 | return ResultInvalidCombination; |
| 846 | } | 847 | } |
| 847 | 848 | ||
| 848 | Process* const current_process = system.Kernel().CurrentProcess(); | 849 | Process* const current_process = system.Kernel().CurrentProcess(); |
| @@ -867,13 +868,13 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, u64 ha | |||
| 867 | if (handle != 0) { | 868 | if (handle != 0) { |
| 868 | LOG_ERROR(Kernel_SVC, "Process Handle is non zero, expected 0 result but got {:016X}", | 869 | LOG_ERROR(Kernel_SVC, "Process Handle is non zero, expected 0 result but got {:016X}", |
| 869 | handle); | 870 | handle); |
| 870 | return ERR_INVALID_HANDLE; | 871 | return ResultInvalidHandle; |
| 871 | } | 872 | } |
| 872 | 873 | ||
| 873 | if (info_sub_id >= Process::RANDOM_ENTROPY_SIZE) { | 874 | if (info_sub_id >= Process::RANDOM_ENTROPY_SIZE) { |
| 874 | LOG_ERROR(Kernel_SVC, "Entropy size is out of range, expected {} but got {}", | 875 | LOG_ERROR(Kernel_SVC, "Entropy size is out of range, expected {} but got {}", |
| 875 | Process::RANDOM_ENTROPY_SIZE, info_sub_id); | 876 | Process::RANDOM_ENTROPY_SIZE, info_sub_id); |
| 876 | return ERR_INVALID_COMBINATION; | 877 | return ResultInvalidCombination; |
| 877 | } | 878 | } |
| 878 | 879 | ||
| 879 | *result = system.Kernel().CurrentProcess()->GetRandomEntropy(info_sub_id); | 880 | *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 | |||
| 890 | if (info_sub_id != 0xFFFFFFFFFFFFFFFF && info_sub_id >= num_cpus) { | 891 | if (info_sub_id != 0xFFFFFFFFFFFFFFFF && info_sub_id >= num_cpus) { |
| 891 | LOG_ERROR(Kernel_SVC, "Core count is out of range, expected {} but got {}", num_cpus, | 892 | LOG_ERROR(Kernel_SVC, "Core count is out of range, expected {} but got {}", num_cpus, |
| 892 | info_sub_id); | 893 | info_sub_id); |
| 893 | return ERR_INVALID_COMBINATION; | 894 | return ResultInvalidCombination; |
| 894 | } | 895 | } |
| 895 | 896 | ||
| 896 | const auto thread = system.Kernel().CurrentProcess()->GetHandleTable().Get<KThread>( | 897 | 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 | |||
| 898 | if (!thread) { | 899 | if (!thread) { |
| 899 | LOG_ERROR(Kernel_SVC, "Thread handle does not exist, handle=0x{:08X}", | 900 | LOG_ERROR(Kernel_SVC, "Thread handle does not exist, handle=0x{:08X}", |
| 900 | static_cast<Handle>(handle)); | 901 | static_cast<Handle>(handle)); |
| 901 | return ERR_INVALID_HANDLE; | 902 | return ResultInvalidHandle; |
| 902 | } | 903 | } |
| 903 | 904 | ||
| 904 | const auto& core_timing = system.CoreTiming(); | 905 | const auto& core_timing = system.CoreTiming(); |
| @@ -922,7 +923,7 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, u64 ha | |||
| 922 | 923 | ||
| 923 | default: | 924 | default: |
| 924 | LOG_ERROR(Kernel_SVC, "Unimplemented svcGetInfo id=0x{:016X}", info_id); | 925 | LOG_ERROR(Kernel_SVC, "Unimplemented svcGetInfo id=0x{:016X}", info_id); |
| 925 | return ERR_INVALID_ENUM_VALUE; | 926 | return ResultInvalidEnumValue; |
| 926 | } | 927 | } |
| 927 | } | 928 | } |
| 928 | 929 | ||
| @@ -945,22 +946,22 @@ static ResultCode MapPhysicalMemory(Core::System& system, VAddr addr, u64 size) | |||
| 945 | 946 | ||
| 946 | if (!Common::Is4KBAligned(addr)) { | 947 | if (!Common::Is4KBAligned(addr)) { |
| 947 | LOG_ERROR(Kernel_SVC, "Address is not aligned to 4KB, 0x{:016X}", addr); | 948 | LOG_ERROR(Kernel_SVC, "Address is not aligned to 4KB, 0x{:016X}", addr); |
| 948 | return ERR_INVALID_ADDRESS; | 949 | return ResultInvalidAddress; |
| 949 | } | 950 | } |
| 950 | 951 | ||
| 951 | if (!Common::Is4KBAligned(size)) { | 952 | if (!Common::Is4KBAligned(size)) { |
| 952 | LOG_ERROR(Kernel_SVC, "Size is not aligned to 4KB, 0x{:X}", size); | 953 | LOG_ERROR(Kernel_SVC, "Size is not aligned to 4KB, 0x{:X}", size); |
| 953 | return ERR_INVALID_SIZE; | 954 | return ResultInvalidSize; |
| 954 | } | 955 | } |
| 955 | 956 | ||
| 956 | if (size == 0) { | 957 | if (size == 0) { |
| 957 | LOG_ERROR(Kernel_SVC, "Size is zero"); | 958 | LOG_ERROR(Kernel_SVC, "Size is zero"); |
| 958 | return ERR_INVALID_SIZE; | 959 | return ResultInvalidSize; |
| 959 | } | 960 | } |
| 960 | 961 | ||
| 961 | if (!(addr < addr + size)) { | 962 | if (!(addr < addr + size)) { |
| 962 | LOG_ERROR(Kernel_SVC, "Size causes 64-bit overflow of address"); | 963 | LOG_ERROR(Kernel_SVC, "Size causes 64-bit overflow of address"); |
| 963 | return ERR_INVALID_MEMORY_RANGE; | 964 | return ResultInvalidMemoryRange; |
| 964 | } | 965 | } |
| 965 | 966 | ||
| 966 | Process* const current_process{system.Kernel().CurrentProcess()}; | 967 | Process* const current_process{system.Kernel().CurrentProcess()}; |
| @@ -968,21 +969,21 @@ static ResultCode MapPhysicalMemory(Core::System& system, VAddr addr, u64 size) | |||
| 968 | 969 | ||
| 969 | if (current_process->GetSystemResourceSize() == 0) { | 970 | if (current_process->GetSystemResourceSize() == 0) { |
| 970 | LOG_ERROR(Kernel_SVC, "System Resource Size is zero"); | 971 | LOG_ERROR(Kernel_SVC, "System Resource Size is zero"); |
| 971 | return ERR_INVALID_STATE; | 972 | return ResultInvalidState; |
| 972 | } | 973 | } |
| 973 | 974 | ||
| 974 | if (!page_table.IsInsideAddressSpace(addr, size)) { | 975 | if (!page_table.IsInsideAddressSpace(addr, size)) { |
| 975 | LOG_ERROR(Kernel_SVC, | 976 | LOG_ERROR(Kernel_SVC, |
| 976 | "Address is not within the address space, addr=0x{:016X}, size=0x{:016X}", addr, | 977 | "Address is not within the address space, addr=0x{:016X}, size=0x{:016X}", addr, |
| 977 | size); | 978 | size); |
| 978 | return ERR_INVALID_MEMORY_RANGE; | 979 | return ResultInvalidMemoryRange; |
| 979 | } | 980 | } |
| 980 | 981 | ||
| 981 | if (page_table.IsOutsideAliasRegion(addr, size)) { | 982 | if (page_table.IsOutsideAliasRegion(addr, size)) { |
| 982 | LOG_ERROR(Kernel_SVC, | 983 | LOG_ERROR(Kernel_SVC, |
| 983 | "Address is not within the alias region, addr=0x{:016X}, size=0x{:016X}", addr, | 984 | "Address is not within the alias region, addr=0x{:016X}, size=0x{:016X}", addr, |
| 984 | size); | 985 | size); |
| 985 | return ERR_INVALID_MEMORY_RANGE; | 986 | return ResultInvalidMemoryRange; |
| 986 | } | 987 | } |
| 987 | 988 | ||
| 988 | return page_table.MapPhysicalMemory(addr, size); | 989 | return page_table.MapPhysicalMemory(addr, size); |
| @@ -999,22 +1000,22 @@ static ResultCode UnmapPhysicalMemory(Core::System& system, VAddr addr, u64 size | |||
| 999 | 1000 | ||
| 1000 | if (!Common::Is4KBAligned(addr)) { | 1001 | if (!Common::Is4KBAligned(addr)) { |
| 1001 | LOG_ERROR(Kernel_SVC, "Address is not aligned to 4KB, 0x{:016X}", addr); | 1002 | LOG_ERROR(Kernel_SVC, "Address is not aligned to 4KB, 0x{:016X}", addr); |
| 1002 | return ERR_INVALID_ADDRESS; | 1003 | return ResultInvalidAddress; |
| 1003 | } | 1004 | } |
| 1004 | 1005 | ||
| 1005 | if (!Common::Is4KBAligned(size)) { | 1006 | if (!Common::Is4KBAligned(size)) { |
| 1006 | LOG_ERROR(Kernel_SVC, "Size is not aligned to 4KB, 0x{:X}", size); | 1007 | LOG_ERROR(Kernel_SVC, "Size is not aligned to 4KB, 0x{:X}", size); |
| 1007 | return ERR_INVALID_SIZE; | 1008 | return ResultInvalidSize; |
| 1008 | } | 1009 | } |
| 1009 | 1010 | ||
| 1010 | if (size == 0) { | 1011 | if (size == 0) { |
| 1011 | LOG_ERROR(Kernel_SVC, "Size is zero"); | 1012 | LOG_ERROR(Kernel_SVC, "Size is zero"); |
| 1012 | return ERR_INVALID_SIZE; | 1013 | return ResultInvalidSize; |
| 1013 | } | 1014 | } |
| 1014 | 1015 | ||
| 1015 | if (!(addr < addr + size)) { | 1016 | if (!(addr < addr + size)) { |
| 1016 | LOG_ERROR(Kernel_SVC, "Size causes 64-bit overflow of address"); | 1017 | LOG_ERROR(Kernel_SVC, "Size causes 64-bit overflow of address"); |
| 1017 | return ERR_INVALID_MEMORY_RANGE; | 1018 | return ResultInvalidMemoryRange; |
| 1018 | } | 1019 | } |
| 1019 | 1020 | ||
| 1020 | Process* const current_process{system.Kernel().CurrentProcess()}; | 1021 | Process* const current_process{system.Kernel().CurrentProcess()}; |
| @@ -1022,21 +1023,21 @@ static ResultCode UnmapPhysicalMemory(Core::System& system, VAddr addr, u64 size | |||
| 1022 | 1023 | ||
| 1023 | if (current_process->GetSystemResourceSize() == 0) { | 1024 | if (current_process->GetSystemResourceSize() == 0) { |
| 1024 | LOG_ERROR(Kernel_SVC, "System Resource Size is zero"); | 1025 | LOG_ERROR(Kernel_SVC, "System Resource Size is zero"); |
| 1025 | return ERR_INVALID_STATE; | 1026 | return ResultInvalidState; |
| 1026 | } | 1027 | } |
| 1027 | 1028 | ||
| 1028 | if (!page_table.IsInsideAddressSpace(addr, size)) { | 1029 | if (!page_table.IsInsideAddressSpace(addr, size)) { |
| 1029 | LOG_ERROR(Kernel_SVC, | 1030 | LOG_ERROR(Kernel_SVC, |
| 1030 | "Address is not within the address space, addr=0x{:016X}, size=0x{:016X}", addr, | 1031 | "Address is not within the address space, addr=0x{:016X}, size=0x{:016X}", addr, |
| 1031 | size); | 1032 | size); |
| 1032 | return ERR_INVALID_MEMORY_RANGE; | 1033 | return ResultInvalidMemoryRange; |
| 1033 | } | 1034 | } |
| 1034 | 1035 | ||
| 1035 | if (page_table.IsOutsideAliasRegion(addr, size)) { | 1036 | if (page_table.IsOutsideAliasRegion(addr, size)) { |
| 1036 | LOG_ERROR(Kernel_SVC, | 1037 | LOG_ERROR(Kernel_SVC, |
| 1037 | "Address is not within the alias region, addr=0x{:016X}, size=0x{:016X}", addr, | 1038 | "Address is not within the alias region, addr=0x{:016X}, size=0x{:016X}", addr, |
| 1038 | size); | 1039 | size); |
| 1039 | return ERR_INVALID_MEMORY_RANGE; | 1040 | return ResultInvalidMemoryRange; |
| 1040 | } | 1041 | } |
| 1041 | 1042 | ||
| 1042 | return page_table.UnmapPhysicalMemory(addr, size); | 1043 | return page_table.UnmapPhysicalMemory(addr, size); |
| @@ -1206,23 +1207,23 @@ static ResultCode MapSharedMemory(Core::System& system, Handle shared_memory_han | |||
| 1206 | 1207 | ||
| 1207 | if (!Common::Is4KBAligned(addr)) { | 1208 | if (!Common::Is4KBAligned(addr)) { |
| 1208 | LOG_ERROR(Kernel_SVC, "Address is not aligned to 4KB, addr=0x{:016X}", addr); | 1209 | LOG_ERROR(Kernel_SVC, "Address is not aligned to 4KB, addr=0x{:016X}", addr); |
| 1209 | return ERR_INVALID_ADDRESS; | 1210 | return ResultInvalidAddress; |
| 1210 | } | 1211 | } |
| 1211 | 1212 | ||
| 1212 | if (size == 0) { | 1213 | if (size == 0) { |
| 1213 | LOG_ERROR(Kernel_SVC, "Size is 0"); | 1214 | LOG_ERROR(Kernel_SVC, "Size is 0"); |
| 1214 | return ERR_INVALID_SIZE; | 1215 | return ResultInvalidSize; |
| 1215 | } | 1216 | } |
| 1216 | 1217 | ||
| 1217 | if (!Common::Is4KBAligned(size)) { | 1218 | if (!Common::Is4KBAligned(size)) { |
| 1218 | LOG_ERROR(Kernel_SVC, "Size is not aligned to 4KB, size=0x{:016X}", size); | 1219 | LOG_ERROR(Kernel_SVC, "Size is not aligned to 4KB, size=0x{:016X}", size); |
| 1219 | return ERR_INVALID_SIZE; | 1220 | return ResultInvalidSize; |
| 1220 | } | 1221 | } |
| 1221 | 1222 | ||
| 1222 | if (!IsValidAddressRange(addr, size)) { | 1223 | if (!IsValidAddressRange(addr, size)) { |
| 1223 | LOG_ERROR(Kernel_SVC, "Region is not a valid address range, addr=0x{:016X}, size=0x{:016X}", | 1224 | LOG_ERROR(Kernel_SVC, "Region is not a valid address range, addr=0x{:016X}, size=0x{:016X}", |
| 1224 | addr, size); | 1225 | addr, size); |
| 1225 | return ERR_INVALID_ADDRESS_STATE; | 1226 | return ResultInvalidCurrentMemory; |
| 1226 | } | 1227 | } |
| 1227 | 1228 | ||
| 1228 | const auto permission_type = static_cast<Memory::MemoryPermission>(permissions); | 1229 | const auto permission_type = static_cast<Memory::MemoryPermission>(permissions); |
| @@ -1230,7 +1231,7 @@ static ResultCode MapSharedMemory(Core::System& system, Handle shared_memory_han | |||
| 1230 | Memory::MemoryPermission::ReadAndWrite) { | 1231 | Memory::MemoryPermission::ReadAndWrite) { |
| 1231 | LOG_ERROR(Kernel_SVC, "Expected Read or ReadWrite permission but got permissions=0x{:08X}", | 1232 | LOG_ERROR(Kernel_SVC, "Expected Read or ReadWrite permission but got permissions=0x{:08X}", |
| 1232 | permissions); | 1233 | permissions); |
| 1233 | return ERR_INVALID_MEMORY_PERMISSIONS; | 1234 | return ResultInvalidMemoryPermissions; |
| 1234 | } | 1235 | } |
| 1235 | 1236 | ||
| 1236 | auto* const current_process{system.Kernel().CurrentProcess()}; | 1237 | auto* const current_process{system.Kernel().CurrentProcess()}; |
| @@ -1241,7 +1242,7 @@ static ResultCode MapSharedMemory(Core::System& system, Handle shared_memory_han | |||
| 1241 | "Addr does not fit within the valid region, addr=0x{:016X}, " | 1242 | "Addr does not fit within the valid region, addr=0x{:016X}, " |
| 1242 | "size=0x{:016X}", | 1243 | "size=0x{:016X}", |
| 1243 | addr, size); | 1244 | addr, size); |
| 1244 | return ERR_INVALID_MEMORY_RANGE; | 1245 | return ResultInvalidMemoryRange; |
| 1245 | } | 1246 | } |
| 1246 | 1247 | ||
| 1247 | if (page_table.IsInsideHeapRegion(addr, size)) { | 1248 | if (page_table.IsInsideHeapRegion(addr, size)) { |
| @@ -1249,7 +1250,7 @@ static ResultCode MapSharedMemory(Core::System& system, Handle shared_memory_han | |||
| 1249 | "Addr does not fit within the heap region, addr=0x{:016X}, " | 1250 | "Addr does not fit within the heap region, addr=0x{:016X}, " |
| 1250 | "size=0x{:016X}", | 1251 | "size=0x{:016X}", |
| 1251 | addr, size); | 1252 | addr, size); |
| 1252 | return ERR_INVALID_MEMORY_RANGE; | 1253 | return ResultInvalidMemoryRange; |
| 1253 | } | 1254 | } |
| 1254 | 1255 | ||
| 1255 | if (page_table.IsInsideAliasRegion(addr, size)) { | 1256 | if (page_table.IsInsideAliasRegion(addr, size)) { |
| @@ -1257,14 +1258,14 @@ static ResultCode MapSharedMemory(Core::System& system, Handle shared_memory_han | |||
| 1257 | "Address does not fit within the map region, addr=0x{:016X}, " | 1258 | "Address does not fit within the map region, addr=0x{:016X}, " |
| 1258 | "size=0x{:016X}", | 1259 | "size=0x{:016X}", |
| 1259 | addr, size); | 1260 | addr, size); |
| 1260 | return ERR_INVALID_MEMORY_RANGE; | 1261 | return ResultInvalidMemoryRange; |
| 1261 | } | 1262 | } |
| 1262 | 1263 | ||
| 1263 | auto shared_memory{current_process->GetHandleTable().Get<SharedMemory>(shared_memory_handle)}; | 1264 | auto shared_memory{current_process->GetHandleTable().Get<SharedMemory>(shared_memory_handle)}; |
| 1264 | if (!shared_memory) { | 1265 | if (!shared_memory) { |
| 1265 | LOG_ERROR(Kernel_SVC, "Shared memory does not exist, shared_memory_handle=0x{:08X}", | 1266 | LOG_ERROR(Kernel_SVC, "Shared memory does not exist, shared_memory_handle=0x{:08X}", |
| 1266 | shared_memory_handle); | 1267 | shared_memory_handle); |
| 1267 | return ERR_INVALID_HANDLE; | 1268 | return ResultInvalidHandle; |
| 1268 | } | 1269 | } |
| 1269 | 1270 | ||
| 1270 | return shared_memory->Map(*current_process, addr, size, permission_type); | 1271 | return shared_memory->Map(*current_process, addr, size, permission_type); |
| @@ -1285,7 +1286,7 @@ static ResultCode QueryProcessMemory(Core::System& system, VAddr memory_info_add | |||
| 1285 | if (!process) { | 1286 | if (!process) { |
| 1286 | LOG_ERROR(Kernel_SVC, "Process handle does not exist, process_handle=0x{:08X}", | 1287 | LOG_ERROR(Kernel_SVC, "Process handle does not exist, process_handle=0x{:08X}", |
| 1287 | process_handle); | 1288 | process_handle); |
| 1288 | return ERR_INVALID_HANDLE; | 1289 | return ResultInvalidHandle; |
| 1289 | } | 1290 | } |
| 1290 | 1291 | ||
| 1291 | auto& memory{system.Memory()}; | 1292 | auto& memory{system.Memory()}; |
| @@ -1332,18 +1333,18 @@ static ResultCode MapProcessCodeMemory(Core::System& system, Handle process_hand | |||
| 1332 | if (!Common::Is4KBAligned(src_address)) { | 1333 | if (!Common::Is4KBAligned(src_address)) { |
| 1333 | LOG_ERROR(Kernel_SVC, "src_address is not page-aligned (src_address=0x{:016X}).", | 1334 | LOG_ERROR(Kernel_SVC, "src_address is not page-aligned (src_address=0x{:016X}).", |
| 1334 | src_address); | 1335 | src_address); |
| 1335 | return ERR_INVALID_ADDRESS; | 1336 | return ResultInvalidAddress; |
| 1336 | } | 1337 | } |
| 1337 | 1338 | ||
| 1338 | if (!Common::Is4KBAligned(dst_address)) { | 1339 | if (!Common::Is4KBAligned(dst_address)) { |
| 1339 | LOG_ERROR(Kernel_SVC, "dst_address is not page-aligned (dst_address=0x{:016X}).", | 1340 | LOG_ERROR(Kernel_SVC, "dst_address is not page-aligned (dst_address=0x{:016X}).", |
| 1340 | dst_address); | 1341 | dst_address); |
| 1341 | return ERR_INVALID_ADDRESS; | 1342 | return ResultInvalidAddress; |
| 1342 | } | 1343 | } |
| 1343 | 1344 | ||
| 1344 | if (size == 0 || !Common::Is4KBAligned(size)) { | 1345 | if (size == 0 || !Common::Is4KBAligned(size)) { |
| 1345 | LOG_ERROR(Kernel_SVC, "Size is zero or not page-aligned (size=0x{:016X})", size); | 1346 | LOG_ERROR(Kernel_SVC, "Size is zero or not page-aligned (size=0x{:016X})", size); |
| 1346 | return ERR_INVALID_SIZE; | 1347 | return ResultInvalidSize; |
| 1347 | } | 1348 | } |
| 1348 | 1349 | ||
| 1349 | if (!IsValidAddressRange(dst_address, size)) { | 1350 | if (!IsValidAddressRange(dst_address, size)) { |
| @@ -1351,7 +1352,7 @@ static ResultCode MapProcessCodeMemory(Core::System& system, Handle process_hand | |||
| 1351 | "Destination address range overflows the address space (dst_address=0x{:016X}, " | 1352 | "Destination address range overflows the address space (dst_address=0x{:016X}, " |
| 1352 | "size=0x{:016X}).", | 1353 | "size=0x{:016X}).", |
| 1353 | dst_address, size); | 1354 | dst_address, size); |
| 1354 | return ERR_INVALID_ADDRESS_STATE; | 1355 | return ResultInvalidCurrentMemory; |
| 1355 | } | 1356 | } |
| 1356 | 1357 | ||
| 1357 | if (!IsValidAddressRange(src_address, size)) { | 1358 | if (!IsValidAddressRange(src_address, size)) { |
| @@ -1359,7 +1360,7 @@ static ResultCode MapProcessCodeMemory(Core::System& system, Handle process_hand | |||
| 1359 | "Source address range overflows the address space (src_address=0x{:016X}, " | 1360 | "Source address range overflows the address space (src_address=0x{:016X}, " |
| 1360 | "size=0x{:016X}).", | 1361 | "size=0x{:016X}).", |
| 1361 | src_address, size); | 1362 | src_address, size); |
| 1362 | return ERR_INVALID_ADDRESS_STATE; | 1363 | return ResultInvalidCurrentMemory; |
| 1363 | } | 1364 | } |
| 1364 | 1365 | ||
| 1365 | const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); | 1366 | const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); |
| @@ -1367,7 +1368,7 @@ static ResultCode MapProcessCodeMemory(Core::System& system, Handle process_hand | |||
| 1367 | if (!process) { | 1368 | if (!process) { |
| 1368 | LOG_ERROR(Kernel_SVC, "Invalid process handle specified (handle=0x{:08X}).", | 1369 | LOG_ERROR(Kernel_SVC, "Invalid process handle specified (handle=0x{:08X}).", |
| 1369 | process_handle); | 1370 | process_handle); |
| 1370 | return ERR_INVALID_HANDLE; | 1371 | return ResultInvalidHandle; |
| 1371 | } | 1372 | } |
| 1372 | 1373 | ||
| 1373 | auto& page_table = process->PageTable(); | 1374 | auto& page_table = process->PageTable(); |
| @@ -1376,7 +1377,7 @@ static ResultCode MapProcessCodeMemory(Core::System& system, Handle process_hand | |||
| 1376 | "Source address range is not within the address space (src_address=0x{:016X}, " | 1377 | "Source address range is not within the address space (src_address=0x{:016X}, " |
| 1377 | "size=0x{:016X}).", | 1378 | "size=0x{:016X}).", |
| 1378 | src_address, size); | 1379 | src_address, size); |
| 1379 | return ERR_INVALID_ADDRESS_STATE; | 1380 | return ResultInvalidCurrentMemory; |
| 1380 | } | 1381 | } |
| 1381 | 1382 | ||
| 1382 | if (!page_table.IsInsideASLRRegion(dst_address, size)) { | 1383 | if (!page_table.IsInsideASLRRegion(dst_address, size)) { |
| @@ -1384,7 +1385,7 @@ static ResultCode MapProcessCodeMemory(Core::System& system, Handle process_hand | |||
| 1384 | "Destination address range is not within the ASLR region (dst_address=0x{:016X}, " | 1385 | "Destination address range is not within the ASLR region (dst_address=0x{:016X}, " |
| 1385 | "size=0x{:016X}).", | 1386 | "size=0x{:016X}).", |
| 1386 | dst_address, size); | 1387 | dst_address, size); |
| 1387 | return ERR_INVALID_MEMORY_RANGE; | 1388 | return ResultInvalidMemoryRange; |
| 1388 | } | 1389 | } |
| 1389 | 1390 | ||
| 1390 | return page_table.MapProcessCodeMemory(dst_address, src_address, size); | 1391 | return page_table.MapProcessCodeMemory(dst_address, src_address, size); |
| @@ -1400,18 +1401,18 @@ static ResultCode UnmapProcessCodeMemory(Core::System& system, Handle process_ha | |||
| 1400 | if (!Common::Is4KBAligned(dst_address)) { | 1401 | if (!Common::Is4KBAligned(dst_address)) { |
| 1401 | LOG_ERROR(Kernel_SVC, "dst_address is not page-aligned (dst_address=0x{:016X}).", | 1402 | LOG_ERROR(Kernel_SVC, "dst_address is not page-aligned (dst_address=0x{:016X}).", |
| 1402 | dst_address); | 1403 | dst_address); |
| 1403 | return ERR_INVALID_ADDRESS; | 1404 | return ResultInvalidAddress; |
| 1404 | } | 1405 | } |
| 1405 | 1406 | ||
| 1406 | if (!Common::Is4KBAligned(src_address)) { | 1407 | if (!Common::Is4KBAligned(src_address)) { |
| 1407 | LOG_ERROR(Kernel_SVC, "src_address is not page-aligned (src_address=0x{:016X}).", | 1408 | LOG_ERROR(Kernel_SVC, "src_address is not page-aligned (src_address=0x{:016X}).", |
| 1408 | src_address); | 1409 | src_address); |
| 1409 | return ERR_INVALID_ADDRESS; | 1410 | return ResultInvalidAddress; |
| 1410 | } | 1411 | } |
| 1411 | 1412 | ||
| 1412 | if (size == 0 || Common::Is4KBAligned(size)) { | 1413 | if (size == 0 || Common::Is4KBAligned(size)) { |
| 1413 | LOG_ERROR(Kernel_SVC, "Size is zero or not page-aligned (size=0x{:016X}).", size); | 1414 | LOG_ERROR(Kernel_SVC, "Size is zero or not page-aligned (size=0x{:016X}).", size); |
| 1414 | return ERR_INVALID_SIZE; | 1415 | return ResultInvalidSize; |
| 1415 | } | 1416 | } |
| 1416 | 1417 | ||
| 1417 | if (!IsValidAddressRange(dst_address, size)) { | 1418 | if (!IsValidAddressRange(dst_address, size)) { |
| @@ -1419,7 +1420,7 @@ static ResultCode UnmapProcessCodeMemory(Core::System& system, Handle process_ha | |||
| 1419 | "Destination address range overflows the address space (dst_address=0x{:016X}, " | 1420 | "Destination address range overflows the address space (dst_address=0x{:016X}, " |
| 1420 | "size=0x{:016X}).", | 1421 | "size=0x{:016X}).", |
| 1421 | dst_address, size); | 1422 | dst_address, size); |
| 1422 | return ERR_INVALID_ADDRESS_STATE; | 1423 | return ResultInvalidCurrentMemory; |
| 1423 | } | 1424 | } |
| 1424 | 1425 | ||
| 1425 | if (!IsValidAddressRange(src_address, size)) { | 1426 | if (!IsValidAddressRange(src_address, size)) { |
| @@ -1427,7 +1428,7 @@ static ResultCode UnmapProcessCodeMemory(Core::System& system, Handle process_ha | |||
| 1427 | "Source address range overflows the address space (src_address=0x{:016X}, " | 1428 | "Source address range overflows the address space (src_address=0x{:016X}, " |
| 1428 | "size=0x{:016X}).", | 1429 | "size=0x{:016X}).", |
| 1429 | src_address, size); | 1430 | src_address, size); |
| 1430 | return ERR_INVALID_ADDRESS_STATE; | 1431 | return ResultInvalidCurrentMemory; |
| 1431 | } | 1432 | } |
| 1432 | 1433 | ||
| 1433 | const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); | 1434 | const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); |
| @@ -1435,7 +1436,7 @@ static ResultCode UnmapProcessCodeMemory(Core::System& system, Handle process_ha | |||
| 1435 | if (!process) { | 1436 | if (!process) { |
| 1436 | LOG_ERROR(Kernel_SVC, "Invalid process handle specified (handle=0x{:08X}).", | 1437 | LOG_ERROR(Kernel_SVC, "Invalid process handle specified (handle=0x{:08X}).", |
| 1437 | process_handle); | 1438 | process_handle); |
| 1438 | return ERR_INVALID_HANDLE; | 1439 | return ResultInvalidHandle; |
| 1439 | } | 1440 | } |
| 1440 | 1441 | ||
| 1441 | auto& page_table = process->PageTable(); | 1442 | auto& page_table = process->PageTable(); |
| @@ -1444,7 +1445,7 @@ static ResultCode UnmapProcessCodeMemory(Core::System& system, Handle process_ha | |||
| 1444 | "Source address range is not within the address space (src_address=0x{:016X}, " | 1445 | "Source address range is not within the address space (src_address=0x{:016X}, " |
| 1445 | "size=0x{:016X}).", | 1446 | "size=0x{:016X}).", |
| 1446 | src_address, size); | 1447 | src_address, size); |
| 1447 | return ERR_INVALID_ADDRESS_STATE; | 1448 | return ResultInvalidCurrentMemory; |
| 1448 | } | 1449 | } |
| 1449 | 1450 | ||
| 1450 | if (!page_table.IsInsideASLRRegion(dst_address, size)) { | 1451 | if (!page_table.IsInsideASLRRegion(dst_address, size)) { |
| @@ -1452,7 +1453,7 @@ static ResultCode UnmapProcessCodeMemory(Core::System& system, Handle process_ha | |||
| 1452 | "Destination address range is not within the ASLR region (dst_address=0x{:016X}, " | 1453 | "Destination address range is not within the ASLR region (dst_address=0x{:016X}, " |
| 1453 | "size=0x{:016X}).", | 1454 | "size=0x{:016X}).", |
| 1454 | dst_address, size); | 1455 | dst_address, size); |
| 1455 | return ERR_INVALID_MEMORY_RANGE; | 1456 | return ResultInvalidMemoryRange; |
| 1456 | } | 1457 | } |
| 1457 | 1458 | ||
| 1458 | return page_table.UnmapProcessCodeMemory(dst_address, src_address, size); | 1459 | return page_table.UnmapProcessCodeMemory(dst_address, src_address, size); |
| @@ -1844,7 +1845,7 @@ static ResultCode ResetSignal(Core::System& system, Handle handle) { | |||
| 1844 | 1845 | ||
| 1845 | LOG_ERROR(Kernel_SVC, "invalid handle (0x{:08X})", handle); | 1846 | LOG_ERROR(Kernel_SVC, "invalid handle (0x{:08X})", handle); |
| 1846 | 1847 | ||
| 1847 | return Svc::ResultInvalidHandle; | 1848 | return ResultInvalidHandle; |
| 1848 | } | 1849 | } |
| 1849 | 1850 | ||
| 1850 | static ResultCode ResetSignal32(Core::System& system, Handle handle) { | 1851 | static ResultCode ResetSignal32(Core::System& system, Handle handle) { |
| @@ -1860,18 +1861,18 @@ static ResultCode CreateTransferMemory(Core::System& system, Handle* handle, VAd | |||
| 1860 | 1861 | ||
| 1861 | if (!Common::Is4KBAligned(addr)) { | 1862 | if (!Common::Is4KBAligned(addr)) { |
| 1862 | LOG_ERROR(Kernel_SVC, "Address ({:016X}) is not page aligned!", addr); | 1863 | LOG_ERROR(Kernel_SVC, "Address ({:016X}) is not page aligned!", addr); |
| 1863 | return ERR_INVALID_ADDRESS; | 1864 | return ResultInvalidAddress; |
| 1864 | } | 1865 | } |
| 1865 | 1866 | ||
| 1866 | if (!Common::Is4KBAligned(size) || size == 0) { | 1867 | if (!Common::Is4KBAligned(size) || size == 0) { |
| 1867 | LOG_ERROR(Kernel_SVC, "Size ({:016X}) is not page aligned or equal to zero!", size); | 1868 | LOG_ERROR(Kernel_SVC, "Size ({:016X}) is not page aligned or equal to zero!", size); |
| 1868 | return ERR_INVALID_ADDRESS; | 1869 | return ResultInvalidAddress; |
| 1869 | } | 1870 | } |
| 1870 | 1871 | ||
| 1871 | if (!IsValidAddressRange(addr, size)) { | 1872 | if (!IsValidAddressRange(addr, size)) { |
| 1872 | LOG_ERROR(Kernel_SVC, "Address and size cause overflow! (address={:016X}, size={:016X})", | 1873 | LOG_ERROR(Kernel_SVC, "Address and size cause overflow! (address={:016X}, size={:016X})", |
| 1873 | addr, size); | 1874 | addr, size); |
| 1874 | return ERR_INVALID_ADDRESS_STATE; | 1875 | return ResultInvalidCurrentMemory; |
| 1875 | } | 1876 | } |
| 1876 | 1877 | ||
| 1877 | const auto perms{static_cast<Memory::MemoryPermission>(permissions)}; | 1878 | const auto perms{static_cast<Memory::MemoryPermission>(permissions)}; |
| @@ -1879,7 +1880,7 @@ static ResultCode CreateTransferMemory(Core::System& system, Handle* handle, VAd | |||
| 1879 | perms == Memory::MemoryPermission::Write) { | 1880 | perms == Memory::MemoryPermission::Write) { |
| 1880 | LOG_ERROR(Kernel_SVC, "Invalid memory permissions for transfer memory! (perms={:08X})", | 1881 | LOG_ERROR(Kernel_SVC, "Invalid memory permissions for transfer memory! (perms={:08X})", |
| 1881 | permissions); | 1882 | permissions); |
| 1882 | return ERR_INVALID_MEMORY_PERMISSIONS; | 1883 | return ResultInvalidMemoryPermissions; |
| 1883 | } | 1884 | } |
| 1884 | 1885 | ||
| 1885 | auto& kernel = system.Kernel(); | 1886 | auto& kernel = system.Kernel(); |
| @@ -1989,7 +1990,6 @@ static ResultCode SetThreadCoreMask(Core::System& system, Handle thread_handle, | |||
| 1989 | LOG_ERROR(Kernel_SVC, "Unable to successfully set core mask (result={})", set_result.raw); | 1990 | LOG_ERROR(Kernel_SVC, "Unable to successfully set core mask (result={})", set_result.raw); |
| 1990 | return set_result; | 1991 | return set_result; |
| 1991 | } | 1992 | } |
| 1992 | |||
| 1993 | return RESULT_SUCCESS; | 1993 | return RESULT_SUCCESS; |
| 1994 | } | 1994 | } |
| 1995 | 1995 | ||
| @@ -2043,7 +2043,7 @@ static ResultCode ClearEvent(Core::System& system, Handle event_handle) { | |||
| 2043 | 2043 | ||
| 2044 | LOG_ERROR(Kernel_SVC, "Event handle does not exist, event_handle=0x{:08X}", event_handle); | 2044 | LOG_ERROR(Kernel_SVC, "Event handle does not exist, event_handle=0x{:08X}", event_handle); |
| 2045 | 2045 | ||
| 2046 | return Svc::ResultInvalidHandle; | 2046 | return ResultInvalidHandle; |
| 2047 | } | 2047 | } |
| 2048 | 2048 | ||
| 2049 | static ResultCode ClearEvent32(Core::System& system, Handle event_handle) { | 2049 | static ResultCode ClearEvent32(Core::System& system, Handle event_handle) { |
| @@ -2106,13 +2106,13 @@ static ResultCode GetProcessInfo(Core::System& system, u64* out, Handle process_ | |||
| 2106 | if (!process) { | 2106 | if (!process) { |
| 2107 | LOG_ERROR(Kernel_SVC, "Process handle does not exist, process_handle=0x{:08X}", | 2107 | LOG_ERROR(Kernel_SVC, "Process handle does not exist, process_handle=0x{:08X}", |
| 2108 | process_handle); | 2108 | process_handle); |
| 2109 | return ERR_INVALID_HANDLE; | 2109 | return ResultInvalidHandle; |
| 2110 | } | 2110 | } |
| 2111 | 2111 | ||
| 2112 | const auto info_type = static_cast<InfoType>(type); | 2112 | const auto info_type = static_cast<InfoType>(type); |
| 2113 | if (info_type != InfoType::Status) { | 2113 | if (info_type != InfoType::Status) { |
| 2114 | LOG_ERROR(Kernel_SVC, "Expected info_type to be Status but got {} instead", type); | 2114 | LOG_ERROR(Kernel_SVC, "Expected info_type to be Status but got {} instead", type); |
| 2115 | return ERR_INVALID_ENUM_VALUE; | 2115 | return ResultInvalidEnumValue; |
| 2116 | } | 2116 | } |
| 2117 | 2117 | ||
| 2118 | *out = static_cast<u64>(process->GetStatus()); | 2118 | *out = static_cast<u64>(process->GetStatus()); |
| @@ -2174,7 +2174,7 @@ static ResultCode SetResourceLimitLimitValue(Core::System& system, Handle resour | |||
| 2174 | const auto type = static_cast<LimitableResource>(resource_type); | 2174 | const auto type = static_cast<LimitableResource>(resource_type); |
| 2175 | if (!IsValidResourceType(type)) { | 2175 | if (!IsValidResourceType(type)) { |
| 2176 | LOG_ERROR(Kernel_SVC, "Invalid resource limit type: '{}'", resource_type); | 2176 | LOG_ERROR(Kernel_SVC, "Invalid resource limit type: '{}'", resource_type); |
| 2177 | return ERR_INVALID_ENUM_VALUE; | 2177 | return ResultInvalidEnumValue; |
| 2178 | } | 2178 | } |
| 2179 | 2179 | ||
| 2180 | auto* const current_process = system.Kernel().CurrentProcess(); | 2180 | auto* const current_process = system.Kernel().CurrentProcess(); |
| @@ -2185,16 +2185,16 @@ static ResultCode SetResourceLimitLimitValue(Core::System& system, Handle resour | |||
| 2185 | if (!resource_limit_object) { | 2185 | if (!resource_limit_object) { |
| 2186 | LOG_ERROR(Kernel_SVC, "Handle to non-existent resource limit instance used. Handle={:08X}", | 2186 | LOG_ERROR(Kernel_SVC, "Handle to non-existent resource limit instance used. Handle={:08X}", |
| 2187 | resource_limit); | 2187 | resource_limit); |
| 2188 | return ERR_INVALID_HANDLE; | 2188 | return ResultInvalidHandle; |
| 2189 | } | 2189 | } |
| 2190 | 2190 | ||
| 2191 | const auto set_result = resource_limit_object->SetLimitValue(type, static_cast<s64>(value)); | 2191 | const auto set_result = resource_limit_object->SetLimitValue(type, static_cast<s64>(value)); |
| 2192 | if (set_result.IsError()) { | 2192 | if (set_result.IsError()) { |
| 2193 | LOG_ERROR( | 2193 | LOG_ERROR(Kernel_SVC, |
| 2194 | Kernel_SVC, | 2194 | "Attempted to lower resource limit ({}) for category '{}' below its current " |
| 2195 | "Attempted to lower resource limit ({}) for category '{}' below its current value ({})", | 2195 | "value ({})", |
| 2196 | resource_limit_object->GetLimitValue(type), resource_type, | 2196 | resource_limit_object->GetLimitValue(type), resource_type, |
| 2197 | resource_limit_object->GetCurrentValue(type)); | 2197 | resource_limit_object->GetCurrentValue(type)); |
| 2198 | return set_result; | 2198 | return set_result; |
| 2199 | } | 2199 | } |
| 2200 | 2200 | ||
| @@ -2211,7 +2211,7 @@ static ResultCode GetProcessList(Core::System& system, u32* out_num_processes, | |||
| 2211 | LOG_ERROR(Kernel_SVC, | 2211 | LOG_ERROR(Kernel_SVC, |
| 2212 | "Supplied size outside [0, 0x0FFFFFFF] range. out_process_ids_size={}", | 2212 | "Supplied size outside [0, 0x0FFFFFFF] range. out_process_ids_size={}", |
| 2213 | out_process_ids_size); | 2213 | out_process_ids_size); |
| 2214 | return ERR_OUT_OF_RANGE; | 2214 | return ResultOutOfRange; |
| 2215 | } | 2215 | } |
| 2216 | 2216 | ||
| 2217 | const auto& kernel = system.Kernel(); | 2217 | const auto& kernel = system.Kernel(); |
| @@ -2221,7 +2221,7 @@ static ResultCode GetProcessList(Core::System& system, u32* out_num_processes, | |||
| 2221 | out_process_ids, total_copy_size)) { | 2221 | out_process_ids, total_copy_size)) { |
| 2222 | LOG_ERROR(Kernel_SVC, "Address range outside address space. begin=0x{:016X}, end=0x{:016X}", | 2222 | LOG_ERROR(Kernel_SVC, "Address range outside address space. begin=0x{:016X}, end=0x{:016X}", |
| 2223 | out_process_ids, out_process_ids + total_copy_size); | 2223 | out_process_ids, out_process_ids + total_copy_size); |
| 2224 | return ERR_INVALID_ADDRESS_STATE; | 2224 | return ResultInvalidCurrentMemory; |
| 2225 | } | 2225 | } |
| 2226 | 2226 | ||
| 2227 | auto& memory = system.Memory(); | 2227 | auto& memory = system.Memory(); |
| @@ -2250,7 +2250,7 @@ static ResultCode GetThreadList(Core::System& system, u32* out_num_threads, VAdd | |||
| 2250 | if ((out_thread_ids_size & 0xF0000000) != 0) { | 2250 | if ((out_thread_ids_size & 0xF0000000) != 0) { |
| 2251 | LOG_ERROR(Kernel_SVC, "Supplied size outside [0, 0x0FFFFFFF] range. size={}", | 2251 | LOG_ERROR(Kernel_SVC, "Supplied size outside [0, 0x0FFFFFFF] range. size={}", |
| 2252 | out_thread_ids_size); | 2252 | out_thread_ids_size); |
| 2253 | return ERR_OUT_OF_RANGE; | 2253 | return ResultOutOfRange; |
| 2254 | } | 2254 | } |
| 2255 | 2255 | ||
| 2256 | const auto* const current_process = system.Kernel().CurrentProcess(); | 2256 | const auto* const current_process = system.Kernel().CurrentProcess(); |
| @@ -2260,7 +2260,7 @@ static ResultCode GetThreadList(Core::System& system, u32* out_num_threads, VAdd | |||
| 2260 | !current_process->PageTable().IsInsideAddressSpace(out_thread_ids, total_copy_size)) { | 2260 | !current_process->PageTable().IsInsideAddressSpace(out_thread_ids, total_copy_size)) { |
| 2261 | LOG_ERROR(Kernel_SVC, "Address range outside address space. begin=0x{:016X}, end=0x{:016X}", | 2261 | LOG_ERROR(Kernel_SVC, "Address range outside address space. begin=0x{:016X}, end=0x{:016X}", |
| 2262 | out_thread_ids, out_thread_ids + total_copy_size); | 2262 | out_thread_ids, out_thread_ids + total_copy_size); |
| 2263 | return ERR_INVALID_ADDRESS_STATE; | 2263 | return ResultInvalidCurrentMemory; |
| 2264 | } | 2264 | } |
| 2265 | 2265 | ||
| 2266 | auto& memory = system.Memory(); | 2266 | auto& memory = system.Memory(); |