diff options
| author | 2018-11-26 19:47:39 +1100 | |
|---|---|---|
| committer | 2018-11-26 19:47:39 +1100 | |
| commit | 9662ca918de8fec60a13b26bcfca1a949e550b31 (patch) | |
| tree | 482c97879a4a9eca8cf91783ecad85d9c927e3c4 /src | |
| parent | Changed logging to be "Log before execution", Added more error logging, all s... (diff) | |
| download | yuzu-9662ca918de8fec60a13b26bcfca1a949e550b31.tar.gz yuzu-9662ca918de8fec60a13b26bcfca1a949e550b31.tar.xz yuzu-9662ca918de8fec60a13b26bcfca1a949e550b31.zip | |
Improved error messages for SVCs
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/kernel/svc.cpp | 246 |
1 files changed, 170 insertions, 76 deletions
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 775afccf6..7f5640adb 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp | |||
| @@ -68,46 +68,68 @@ bool IsInsideNewMapRegion(const VMManager& vm, VAddr address, u64 size) { | |||
| 68 | // in the same order. | 68 | // in the same order. |
| 69 | ResultCode MapUnmapMemorySanityChecks(const VMManager& vm_manager, VAddr dst_addr, VAddr src_addr, | 69 | ResultCode MapUnmapMemorySanityChecks(const VMManager& vm_manager, VAddr dst_addr, VAddr src_addr, |
| 70 | u64 size) { | 70 | u64 size) { |
| 71 | if (!Common::Is4KBAligned(dst_addr) || !Common::Is4KBAligned(src_addr)) { | 71 | if (!Common::Is4KBAligned(dst_addr)) { |
| 72 | LOG_ERROR(Kernel_SVC, "Invalid address"); | 72 | LOG_ERROR(Kernel_SVC, "Destination address is not aligned to 4KB, 0x{:016X}", dst_addr); |
| 73 | return ERR_INVALID_ADDRESS; | 73 | return ERR_INVALID_ADDRESS; |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | if (size == 0 || !Common::Is4KBAligned(size)) { | 76 | if (!Common::Is4KBAligned(src_addr)) { |
| 77 | LOG_ERROR(Kernel_SVC, "Invalid size"); | 77 | LOG_ERROR(Kernel_SVC, "Source address is not aligned to 4KB, 0x{:016X}", src_addr); |
| 78 | } | ||
| 79 | |||
| 80 | if (size == 0) { | ||
| 81 | LOG_ERROR(Kernel_SVC, "Size is 0"); | ||
| 82 | return ERR_INVALID_SIZE; | ||
| 83 | } | ||
| 84 | |||
| 85 | if (!Common::Is4KBAligned(size)) { | ||
| 86 | LOG_ERROR(Kernel_SVC, "Size is not aligned to 4KB, 0x{:016X}", size); | ||
| 78 | return ERR_INVALID_SIZE; | 87 | return ERR_INVALID_SIZE; |
| 79 | } | 88 | } |
| 80 | 89 | ||
| 81 | if (!IsValidAddressRange(dst_addr, size)) { | 90 | if (!IsValidAddressRange(dst_addr, size)) { |
| 82 | LOG_ERROR(Kernel_SVC, "size is out of range"); | 91 | LOG_ERROR(Kernel_SVC, |
| 92 | "Destination is not a valid address range, addr=0x{:016X}, size=0x{:016X}", | ||
| 93 | dst_addr, size); | ||
| 83 | return ERR_INVALID_ADDRESS_STATE; | 94 | return ERR_INVALID_ADDRESS_STATE; |
| 84 | } | 95 | } |
| 85 | 96 | ||
| 86 | if (!IsValidAddressRange(src_addr, size)) { | 97 | if (!IsValidAddressRange(src_addr, size)) { |
| 87 | LOG_ERROR(Kernel_SVC, "size is out of range"); | 98 | LOG_ERROR(Kernel_SVC, "Source is not a valid address range, addr=0x{:016X}, size=0x{:016X}", |
| 99 | src_addr, size); | ||
| 88 | return ERR_INVALID_ADDRESS_STATE; | 100 | return ERR_INVALID_ADDRESS_STATE; |
| 89 | } | 101 | } |
| 90 | 102 | ||
| 91 | if (!IsInsideAddressSpace(vm_manager, src_addr, size)) { | 103 | if (!IsInsideAddressSpace(vm_manager, src_addr, size)) { |
| 92 | LOG_ERROR(Kernel_SVC, "Region is out of the address space"); | 104 | LOG_ERROR(Kernel_SVC, |
| 105 | "Source is not within the address space, addr=0x{:016X}, size=0x{:016X}", | ||
| 106 | src_addr, size); | ||
| 93 | return ERR_INVALID_ADDRESS_STATE; | 107 | return ERR_INVALID_ADDRESS_STATE; |
| 94 | } | 108 | } |
| 95 | 109 | ||
| 96 | if (!IsInsideNewMapRegion(vm_manager, dst_addr, size)) { | 110 | if (!IsInsideNewMapRegion(vm_manager, dst_addr, size)) { |
| 97 | LOG_ERROR(Kernel_SVC, "Region is out of the address space"); | 111 | LOG_ERROR(Kernel_SVC, |
| 112 | "Destination is not within the new map region, addr=0x{:016X}, size=0x{:016X}", | ||
| 113 | dst_addr, size); | ||
| 98 | return ERR_INVALID_MEMORY_RANGE; | 114 | return ERR_INVALID_MEMORY_RANGE; |
| 99 | } | 115 | } |
| 100 | 116 | ||
| 101 | const VAddr dst_end_address = dst_addr + size; | 117 | const VAddr dst_end_address = dst_addr + size; |
| 102 | if (dst_end_address > vm_manager.GetHeapRegionBaseAddress() && | 118 | if (dst_end_address > vm_manager.GetHeapRegionBaseAddress() && |
| 103 | vm_manager.GetHeapRegionEndAddress() > dst_addr) { | 119 | vm_manager.GetHeapRegionEndAddress() > dst_addr) { |
| 104 | LOG_ERROR(Kernel_SVC, "Region is not in the correct address space"); | 120 | LOG_ERROR(Kernel_SVC, |
| 121 | "Destination does not fit within the heap region, addr=0x{:016X}, " | ||
| 122 | "size=0x{:016X}, end_addr=0x{:016X}", | ||
| 123 | dst_addr, size, dst_end_address); | ||
| 105 | return ERR_INVALID_MEMORY_RANGE; | 124 | return ERR_INVALID_MEMORY_RANGE; |
| 106 | } | 125 | } |
| 107 | 126 | ||
| 108 | if (dst_end_address > vm_manager.GetMapRegionBaseAddress() && | 127 | if (dst_end_address > vm_manager.GetMapRegionBaseAddress() && |
| 109 | vm_manager.GetMapRegionEndAddress() > dst_addr) { | 128 | vm_manager.GetMapRegionEndAddress() > dst_addr) { |
| 110 | LOG_ERROR(Kernel_SVC, "Region is not in the correct address space"); | 129 | LOG_ERROR(Kernel_SVC, |
| 130 | "Destination does not fit within the map region, addr=0x{:016X}, " | ||
| 131 | "size=0x{:016X}, end_addr=0x{:016X}", | ||
| 132 | dst_addr, size, dst_end_address); | ||
| 111 | return ERR_INVALID_MEMORY_RANGE; | 133 | return ERR_INVALID_MEMORY_RANGE; |
| 112 | } | 134 | } |
| 113 | 135 | ||
| @@ -121,7 +143,10 @@ static ResultCode SetHeapSize(VAddr* heap_addr, u64 heap_size) { | |||
| 121 | 143 | ||
| 122 | // Size must be a multiple of 0x200000 (2MB) and be equal to or less than 4GB. | 144 | // Size must be a multiple of 0x200000 (2MB) and be equal to or less than 4GB. |
| 123 | if ((heap_size & 0xFFFFFFFE001FFFFF) != 0) { | 145 | if ((heap_size & 0xFFFFFFFE001FFFFF) != 0) { |
| 124 | LOG_ERROR(Kernel_SVC, "Invalid heap size"); | 146 | LOG_ERROR( |
| 147 | Kernel_SVC, | ||
| 148 | "The heap size is not a multiple of 2mb or is greater than 4GB, heap_size=0x{:016X}", | ||
| 149 | heap_size); | ||
| 125 | return ERR_INVALID_SIZE; | 150 | return ERR_INVALID_SIZE; |
| 126 | } | 151 | } |
| 127 | 152 | ||
| @@ -136,24 +161,31 @@ static ResultCode SetMemoryPermission(VAddr addr, u64 size, u32 prot) { | |||
| 136 | LOG_TRACE(Kernel_SVC, "called, addr=0x{:X}, size=0x{:X}, prot=0x{:X}", addr, size, prot); | 161 | LOG_TRACE(Kernel_SVC, "called, addr=0x{:X}, size=0x{:X}, prot=0x{:X}", addr, size, prot); |
| 137 | 162 | ||
| 138 | if (!Common::Is4KBAligned(addr)) { | 163 | if (!Common::Is4KBAligned(addr)) { |
| 139 | LOG_ERROR(Kernel_SVC, "Address is not aligned"); | 164 | LOG_ERROR(Kernel_SVC, "Address is not aligned to 4KB, addr=0x{:016X}", addr); |
| 140 | return ERR_INVALID_ADDRESS; | 165 | return ERR_INVALID_ADDRESS; |
| 141 | } | 166 | } |
| 142 | 167 | ||
| 143 | if (size == 0 || !Common::Is4KBAligned(size)) { | 168 | if (size == 0) { |
| 144 | LOG_ERROR(Kernel_SVC, "Invalid size"); | 169 | LOG_ERROR(Kernel_SVC, "Size is 0"); |
| 170 | return ERR_INVALID_SIZE; | ||
| 171 | } | ||
| 172 | |||
| 173 | if (!Common::Is4KBAligned(size)) { | ||
| 174 | LOG_ERROR(Kernel_SVC, "Size is not aligned to 4KB, size=0x{:016X}", size); | ||
| 145 | return ERR_INVALID_SIZE; | 175 | return ERR_INVALID_SIZE; |
| 146 | } | 176 | } |
| 147 | 177 | ||
| 148 | if (!IsValidAddressRange(addr, size)) { | 178 | if (!IsValidAddressRange(addr, size)) { |
| 149 | LOG_ERROR(Kernel_SVC, "Region is out of the address space"); | 179 | LOG_ERROR(Kernel_SVC, "Region is not a valid address range, addr=0x{:016X}, size=0x{:016X}", |
| 180 | addr, size); | ||
| 150 | return ERR_INVALID_ADDRESS_STATE; | 181 | return ERR_INVALID_ADDRESS_STATE; |
| 151 | } | 182 | } |
| 152 | 183 | ||
| 153 | const auto permission = static_cast<MemoryPermission>(prot); | 184 | const auto permission = static_cast<MemoryPermission>(prot); |
| 154 | if (permission != MemoryPermission::None && permission != MemoryPermission::Read && | 185 | if (permission != MemoryPermission::None && permission != MemoryPermission::Read && |
| 155 | permission != MemoryPermission::ReadWrite) { | 186 | permission != MemoryPermission::ReadWrite) { |
| 156 | LOG_ERROR(Kernel_SVC, "Incorrect memory permissions"); | 187 | LOG_ERROR(Kernel_SVC, "Invalid memory permission specified, Got memory permission=0x{:08X}", |
| 188 | static_cast<u32>(permission)); | ||
| 157 | return ERR_INVALID_MEMORY_PERMISSIONS; | 189 | return ERR_INVALID_MEMORY_PERMISSIONS; |
| 158 | } | 190 | } |
| 159 | 191 | ||
| @@ -161,13 +193,15 @@ static ResultCode SetMemoryPermission(VAddr addr, u64 size, u32 prot) { | |||
| 161 | auto& vm_manager = current_process->VMManager(); | 193 | auto& vm_manager = current_process->VMManager(); |
| 162 | 194 | ||
| 163 | if (!IsInsideAddressSpace(vm_manager, addr, size)) { | 195 | if (!IsInsideAddressSpace(vm_manager, addr, size)) { |
| 164 | LOG_ERROR(Kernel_SVC, "Region is not inside the address space"); | 196 | LOG_ERROR(Kernel_SVC, |
| 197 | "Source is not within the address space, addr=0x{:016X}, size=0x{:016X}", addr, | ||
| 198 | size); | ||
| 165 | return ERR_INVALID_ADDRESS_STATE; | 199 | return ERR_INVALID_ADDRESS_STATE; |
| 166 | } | 200 | } |
| 167 | 201 | ||
| 168 | const VMManager::VMAHandle iter = vm_manager.FindVMA(addr); | 202 | const VMManager::VMAHandle iter = vm_manager.FindVMA(addr); |
| 169 | if (iter == vm_manager.vma_map.end()) { | 203 | if (iter == vm_manager.vma_map.end()) { |
| 170 | LOG_ERROR(Kernel_SVC, "Unable to find VMA"); | 204 | LOG_ERROR(Kernel_SVC, "Unable to find VMA for address=0x{:016X}", addr); |
| 171 | return ERR_INVALID_ADDRESS_STATE; | 205 | return ERR_INVALID_ADDRESS_STATE; |
| 172 | } | 206 | } |
| 173 | 207 | ||
| @@ -197,7 +231,6 @@ static ResultCode MapMemory(VAddr dst_addr, VAddr src_addr, u64 size) { | |||
| 197 | 231 | ||
| 198 | const auto result = MapUnmapMemorySanityChecks(vm_manager, dst_addr, src_addr, size); | 232 | const auto result = MapUnmapMemorySanityChecks(vm_manager, dst_addr, src_addr, size); |
| 199 | if (result != RESULT_SUCCESS) { | 233 | if (result != RESULT_SUCCESS) { |
| 200 | LOG_ERROR(Kernel_SVC, "Map Memory failed"); | ||
| 201 | return result; | 234 | return result; |
| 202 | } | 235 | } |
| 203 | 236 | ||
| @@ -214,7 +247,6 @@ static ResultCode UnmapMemory(VAddr dst_addr, VAddr src_addr, u64 size) { | |||
| 214 | 247 | ||
| 215 | const auto result = MapUnmapMemorySanityChecks(vm_manager, dst_addr, src_addr, size); | 248 | const auto result = MapUnmapMemorySanityChecks(vm_manager, dst_addr, src_addr, size); |
| 216 | if (result != RESULT_SUCCESS) { | 249 | if (result != RESULT_SUCCESS) { |
| 217 | LOG_ERROR(Kernel_SVC, "UnmapMemory failed"); | ||
| 218 | return result; | 250 | return result; |
| 219 | } | 251 | } |
| 220 | 252 | ||
| @@ -224,7 +256,9 @@ static ResultCode UnmapMemory(VAddr dst_addr, VAddr src_addr, u64 size) { | |||
| 224 | /// Connect to an OS service given the port name, returns the handle to the port to out | 256 | /// Connect to an OS service given the port name, returns the handle to the port to out |
| 225 | static ResultCode ConnectToNamedPort(Handle* out_handle, VAddr port_name_address) { | 257 | static ResultCode ConnectToNamedPort(Handle* out_handle, VAddr port_name_address) { |
| 226 | if (!Memory::IsValidVirtualAddress(port_name_address)) { | 258 | if (!Memory::IsValidVirtualAddress(port_name_address)) { |
| 227 | LOG_ERROR(Kernel_SVC, "Invalid port name address"); | 259 | LOG_ERROR(Kernel_SVC, |
| 260 | "Port Name Address is not a valid virtual address, port_name_address=0x{:016X}", | ||
| 261 | port_name_address); | ||
| 228 | return ERR_NOT_FOUND; | 262 | return ERR_NOT_FOUND; |
| 229 | } | 263 | } |
| 230 | 264 | ||
| @@ -232,7 +266,8 @@ static ResultCode ConnectToNamedPort(Handle* out_handle, VAddr port_name_address | |||
| 232 | // Read 1 char beyond the max allowed port name to detect names that are too long. | 266 | // Read 1 char beyond the max allowed port name to detect names that are too long. |
| 233 | std::string port_name = Memory::ReadCString(port_name_address, PortNameMaxLength + 1); | 267 | std::string port_name = Memory::ReadCString(port_name_address, PortNameMaxLength + 1); |
| 234 | if (port_name.size() > PortNameMaxLength) { | 268 | if (port_name.size() > PortNameMaxLength) { |
| 235 | LOG_ERROR(Kernel_SVC, "Port name is too long"); | 269 | LOG_ERROR(Kernel_SVC, "Port name is too long, expected {} but got {}", PortNameMaxLength, |
| 270 | port_name.size()); | ||
| 236 | return ERR_OUT_OF_RANGE; | 271 | return ERR_OUT_OF_RANGE; |
| 237 | } | 272 | } |
| 238 | 273 | ||
| @@ -281,7 +316,7 @@ static ResultCode GetThreadId(u32* thread_id, Handle thread_handle) { | |||
| 281 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); | 316 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 282 | const SharedPtr<Thread> thread = handle_table.Get<Thread>(thread_handle); | 317 | const SharedPtr<Thread> thread = handle_table.Get<Thread>(thread_handle); |
| 283 | if (!thread) { | 318 | if (!thread) { |
| 284 | LOG_ERROR(Kernel_SVC, "Invalid thread handle"); | 319 | LOG_ERROR(Kernel_SVC, "Thread handle does not exist, handle=0x{:08X}", thread_handle); |
| 285 | return ERR_INVALID_HANDLE; | 320 | return ERR_INVALID_HANDLE; |
| 286 | } | 321 | } |
| 287 | 322 | ||
| @@ -296,7 +331,8 @@ static ResultCode GetProcessId(u32* process_id, Handle process_handle) { | |||
| 296 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); | 331 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 297 | const SharedPtr<Process> process = handle_table.Get<Process>(process_handle); | 332 | const SharedPtr<Process> process = handle_table.Get<Process>(process_handle); |
| 298 | if (!process) { | 333 | if (!process) { |
| 299 | LOG_ERROR(Kernel_SVC, "Invalid process"); | 334 | LOG_ERROR(Kernel_SVC, "Process handle does not exist, process_handle=0x{:08X}", |
| 335 | process_handle); | ||
| 300 | return ERR_INVALID_HANDLE; | 336 | return ERR_INVALID_HANDLE; |
| 301 | } | 337 | } |
| 302 | 338 | ||
| @@ -327,14 +363,17 @@ static ResultCode WaitSynchronization(Handle* index, VAddr handles_address, u64 | |||
| 327 | handles_address, handle_count, nano_seconds); | 363 | handles_address, handle_count, nano_seconds); |
| 328 | 364 | ||
| 329 | if (!Memory::IsValidVirtualAddress(handles_address)) { | 365 | if (!Memory::IsValidVirtualAddress(handles_address)) { |
| 330 | LOG_ERROR(Kernel_SVC, "Invalid handle address"); | 366 | LOG_ERROR(Kernel_SVC, |
| 367 | "Handle address is not a valid virtual address, handle_address=0x{:016X}", | ||
| 368 | handles_address); | ||
| 331 | return ERR_INVALID_POINTER; | 369 | return ERR_INVALID_POINTER; |
| 332 | } | 370 | } |
| 333 | 371 | ||
| 334 | static constexpr u64 MaxHandles = 0x40; | 372 | static constexpr u64 MaxHandles = 0x40; |
| 335 | 373 | ||
| 336 | if (handle_count > MaxHandles) { | 374 | if (handle_count > MaxHandles) { |
| 337 | LOG_ERROR(Kernel_SVC, "Handle count is too big"); | 375 | LOG_ERROR(Kernel_SVC, "Handle count specified is too large, expected {} but got {}", |
| 376 | MaxHandles, handle_count); | ||
| 338 | return ERR_OUT_OF_RANGE; | 377 | return ERR_OUT_OF_RANGE; |
| 339 | } | 378 | } |
| 340 | 379 | ||
| @@ -400,7 +439,8 @@ static ResultCode CancelSynchronization(Handle thread_handle) { | |||
| 400 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); | 439 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 401 | const SharedPtr<Thread> thread = handle_table.Get<Thread>(thread_handle); | 440 | const SharedPtr<Thread> thread = handle_table.Get<Thread>(thread_handle); |
| 402 | if (!thread) { | 441 | if (!thread) { |
| 403 | LOG_ERROR(Kernel_SVC, "Invalid thread handle"); | 442 | LOG_ERROR(Kernel_SVC, "Thread handle does not exist, thread_handle=0x{:08X}", |
| 443 | thread_handle); | ||
| 404 | return ERR_INVALID_HANDLE; | 444 | return ERR_INVALID_HANDLE; |
| 405 | } | 445 | } |
| 406 | 446 | ||
| @@ -419,12 +459,13 @@ static ResultCode ArbitrateLock(Handle holding_thread_handle, VAddr mutex_addr, | |||
| 419 | holding_thread_handle, mutex_addr, requesting_thread_handle); | 459 | holding_thread_handle, mutex_addr, requesting_thread_handle); |
| 420 | 460 | ||
| 421 | if (Memory::IsKernelVirtualAddress(mutex_addr)) { | 461 | if (Memory::IsKernelVirtualAddress(mutex_addr)) { |
| 422 | LOG_ERROR(Kernel_SVC, "Invalid mutex address"); | 462 | LOG_ERROR(Kernel_SVC, "Mutex Address is a kernel virtual address, mutex_addr={:016X}", |
| 463 | mutex_addr); | ||
| 423 | return ERR_INVALID_ADDRESS_STATE; | 464 | return ERR_INVALID_ADDRESS_STATE; |
| 424 | } | 465 | } |
| 425 | 466 | ||
| 426 | if (!Common::IsWordAligned(mutex_addr)) { | 467 | if (!Common::IsWordAligned(mutex_addr)) { |
| 427 | LOG_ERROR(Kernel_SVC, "Mutex address is not aligned"); | 468 | LOG_ERROR(Kernel_SVC, "Mutex Address is not word aligned, mutex_addr={:016X}", mutex_addr); |
| 428 | return ERR_INVALID_ADDRESS; | 469 | return ERR_INVALID_ADDRESS; |
| 429 | } | 470 | } |
| 430 | 471 | ||
| @@ -438,12 +479,13 @@ static ResultCode ArbitrateUnlock(VAddr mutex_addr) { | |||
| 438 | LOG_TRACE(Kernel_SVC, "called mutex_addr=0x{:X}", mutex_addr); | 479 | LOG_TRACE(Kernel_SVC, "called mutex_addr=0x{:X}", mutex_addr); |
| 439 | 480 | ||
| 440 | if (Memory::IsKernelVirtualAddress(mutex_addr)) { | 481 | if (Memory::IsKernelVirtualAddress(mutex_addr)) { |
| 441 | LOG_ERROR(Kernel_SVC, "Invalid size"); | 482 | LOG_ERROR(Kernel_SVC, "Mutex Address is a kernel virtual address, mutex_addr={:016X}", |
| 483 | mutex_addr); | ||
| 442 | return ERR_INVALID_ADDRESS_STATE; | 484 | return ERR_INVALID_ADDRESS_STATE; |
| 443 | } | 485 | } |
| 444 | 486 | ||
| 445 | if (!Common::IsWordAligned(mutex_addr)) { | 487 | if (!Common::IsWordAligned(mutex_addr)) { |
| 446 | LOG_ERROR(Kernel_SVC, "Mutex address is not aligned"); | 488 | LOG_ERROR(Kernel_SVC, "Mutex Address is not word aligned, mutex_addr={:016X}", mutex_addr); |
| 447 | return ERR_INVALID_ADDRESS; | 489 | return ERR_INVALID_ADDRESS; |
| 448 | } | 490 | } |
| 449 | 491 | ||
| @@ -634,12 +676,14 @@ static ResultCode GetInfo(u64* result, u64 info_id, u64 handle, u64 info_sub_id) | |||
| 634 | break; | 676 | break; |
| 635 | case GetInfoType::RandomEntropy: | 677 | case GetInfoType::RandomEntropy: |
| 636 | if (handle != 0) { | 678 | if (handle != 0) { |
| 637 | LOG_ERROR(Kernel_SVC, "Non zero handle specified"); | 679 | LOG_ERROR(Kernel_SVC, "Process Handle is non zero, expected 0 result but got {:016X}", |
| 680 | handle); | ||
| 638 | return ERR_INVALID_HANDLE; | 681 | return ERR_INVALID_HANDLE; |
| 639 | } | 682 | } |
| 640 | 683 | ||
| 641 | if (info_sub_id >= Process::RANDOM_ENTROPY_SIZE) { | 684 | if (info_sub_id >= Process::RANDOM_ENTROPY_SIZE) { |
| 642 | LOG_ERROR(Kernel_SVC, "Entropy size is too big"); | 685 | LOG_ERROR(Kernel_SVC, "Entropy size is out of range, expected {} but got {}", |
| 686 | Process::RANDOM_ENTROPY_SIZE, info_sub_id); | ||
| 643 | return ERR_INVALID_COMBINATION; | 687 | return ERR_INVALID_COMBINATION; |
| 644 | } | 688 | } |
| 645 | 689 | ||
| @@ -677,14 +721,16 @@ static ResultCode GetInfo(u64* result, u64 info_id, u64 handle, u64 info_sub_id) | |||
| 677 | case GetInfoType::ThreadTickCount: { | 721 | case GetInfoType::ThreadTickCount: { |
| 678 | constexpr u64 num_cpus = 4; | 722 | constexpr u64 num_cpus = 4; |
| 679 | if (info_sub_id != 0xFFFFFFFFFFFFFFFF && info_sub_id >= num_cpus) { | 723 | if (info_sub_id != 0xFFFFFFFFFFFFFFFF && info_sub_id >= num_cpus) { |
| 680 | LOG_ERROR(Kernel_SVC, "Incorrect info_sub_id"); | 724 | LOG_ERROR(Kernel_SVC, "Core count is out of range, expected {} but got {}", num_cpus, |
| 725 | info_sub_id); | ||
| 681 | return ERR_INVALID_COMBINATION; | 726 | return ERR_INVALID_COMBINATION; |
| 682 | } | 727 | } |
| 683 | 728 | ||
| 684 | const auto thread = | 729 | const auto thread = |
| 685 | current_process->GetHandleTable().Get<Thread>(static_cast<Handle>(handle)); | 730 | current_process->GetHandleTable().Get<Thread>(static_cast<Handle>(handle)); |
| 686 | if (!thread) { | 731 | if (!thread) { |
| 687 | LOG_ERROR(Kernel_SVC, "Thread is not a valid handle"); | 732 | LOG_ERROR(Kernel_SVC, "Thread handle does not exist, handle=0x{:08X}", |
| 733 | static_cast<Handle>(handle)); | ||
| 688 | return ERR_INVALID_HANDLE; | 734 | return ERR_INVALID_HANDLE; |
| 689 | } | 735 | } |
| 690 | 736 | ||
| @@ -727,17 +773,22 @@ static ResultCode GetThreadContext(VAddr thread_context, Handle handle) { | |||
| 727 | const auto* current_process = Core::CurrentProcess(); | 773 | const auto* current_process = Core::CurrentProcess(); |
| 728 | const SharedPtr<Thread> thread = current_process->GetHandleTable().Get<Thread>(handle); | 774 | const SharedPtr<Thread> thread = current_process->GetHandleTable().Get<Thread>(handle); |
| 729 | if (!thread) { | 775 | if (!thread) { |
| 730 | LOG_ERROR(Kernel_SVC, "Thread is not a valid handle"); | 776 | LOG_ERROR(Kernel_SVC, "Thread handle does not exist, handle=0x{:08X}", handle); |
| 731 | return ERR_INVALID_HANDLE; | 777 | return ERR_INVALID_HANDLE; |
| 732 | } | 778 | } |
| 733 | 779 | ||
| 734 | if (thread->GetOwnerProcess() != current_process) { | 780 | if (thread->GetOwnerProcess() != current_process) { |
| 735 | LOG_ERROR(Kernel_SVC, "Thread owner process is not the current process"); | 781 | LOG_ERROR(Kernel_SVC, |
| 782 | "The current process does not own the current thread, thread_handle={:08X} " | ||
| 783 | "thread_pid={}, " | ||
| 784 | "current_process_pid={}", | ||
| 785 | handle, thread->GetOwnerProcess()->GetProcessID(), | ||
| 786 | current_process->GetProcessID()); | ||
| 736 | return ERR_INVALID_HANDLE; | 787 | return ERR_INVALID_HANDLE; |
| 737 | } | 788 | } |
| 738 | 789 | ||
| 739 | if (thread == GetCurrentThread()) { | 790 | if (thread == GetCurrentThread()) { |
| 740 | LOG_ERROR(Kernel_SVC, "Thread is already registered"); | 791 | LOG_ERROR(Kernel_SVC, "The thread handle specified is the current running thread"); |
| 741 | return ERR_ALREADY_REGISTERED; | 792 | return ERR_ALREADY_REGISTERED; |
| 742 | } | 793 | } |
| 743 | 794 | ||
| @@ -763,7 +814,7 @@ static ResultCode GetThreadPriority(u32* priority, Handle handle) { | |||
| 763 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); | 814 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 764 | const SharedPtr<Thread> thread = handle_table.Get<Thread>(handle); | 815 | const SharedPtr<Thread> thread = handle_table.Get<Thread>(handle); |
| 765 | if (!thread) { | 816 | if (!thread) { |
| 766 | LOG_ERROR(Kernel_SVC, "Invalid thread handle"); | 817 | LOG_ERROR(Kernel_SVC, "Thread handle does not exist, handle=0x{:08X}", handle); |
| 767 | return ERR_INVALID_HANDLE; | 818 | return ERR_INVALID_HANDLE; |
| 768 | } | 819 | } |
| 769 | 820 | ||
| @@ -776,7 +827,10 @@ static ResultCode SetThreadPriority(Handle handle, u32 priority) { | |||
| 776 | LOG_TRACE(Kernel_SVC, "called"); | 827 | LOG_TRACE(Kernel_SVC, "called"); |
| 777 | 828 | ||
| 778 | if (priority > THREADPRIO_LOWEST) { | 829 | if (priority > THREADPRIO_LOWEST) { |
| 779 | LOG_ERROR(Kernel_SVC, "Priority is out of range"); | 830 | LOG_ERROR( |
| 831 | Kernel_SVC, | ||
| 832 | "An invalid priority was specified, expected {} but got {} for thread_handle={:08X}", | ||
| 833 | THREADPRIO_LOWEST, priority, handle); | ||
| 780 | return ERR_INVALID_THREAD_PRIORITY; | 834 | return ERR_INVALID_THREAD_PRIORITY; |
| 781 | } | 835 | } |
| 782 | 836 | ||
| @@ -784,7 +838,7 @@ static ResultCode SetThreadPriority(Handle handle, u32 priority) { | |||
| 784 | 838 | ||
| 785 | SharedPtr<Thread> thread = current_process->GetHandleTable().Get<Thread>(handle); | 839 | SharedPtr<Thread> thread = current_process->GetHandleTable().Get<Thread>(handle); |
| 786 | if (!thread) { | 840 | if (!thread) { |
| 787 | LOG_ERROR(Kernel_SVC, "Invalid thread handle"); | 841 | LOG_ERROR(Kernel_SVC, "Thread handle does not exist, handle=0x{:08X}", handle); |
| 788 | return ERR_INVALID_HANDLE; | 842 | return ERR_INVALID_HANDLE; |
| 789 | } | 843 | } |
| 790 | 844 | ||
| @@ -807,37 +861,46 @@ static ResultCode MapSharedMemory(Handle shared_memory_handle, VAddr addr, u64 s | |||
| 807 | shared_memory_handle, addr, size, permissions); | 861 | shared_memory_handle, addr, size, permissions); |
| 808 | 862 | ||
| 809 | if (!Common::Is4KBAligned(addr)) { | 863 | if (!Common::Is4KBAligned(addr)) { |
| 810 | LOG_ERROR(Kernel_SVC, "Address is not aligned"); | 864 | LOG_ERROR(Kernel_SVC, "Address is not aligned to 4KB, addr=0x{:016X}", addr); |
| 811 | return ERR_INVALID_ADDRESS; | 865 | return ERR_INVALID_ADDRESS; |
| 812 | } | 866 | } |
| 813 | 867 | ||
| 814 | if (size == 0 || !Common::Is4KBAligned(size)) { | 868 | if (size == 0) { |
| 815 | LOG_ERROR(Kernel_SVC, "Invalid size"); | 869 | LOG_ERROR(Kernel_SVC, "Size is 0"); |
| 870 | return ERR_INVALID_SIZE; | ||
| 871 | } | ||
| 872 | |||
| 873 | if (!Common::Is4KBAligned(size)) { | ||
| 874 | LOG_ERROR(Kernel_SVC, "Size is not aligned to 4KB, size=0x{:016X}", size); | ||
| 816 | return ERR_INVALID_SIZE; | 875 | return ERR_INVALID_SIZE; |
| 817 | } | 876 | } |
| 818 | 877 | ||
| 819 | if (!IsValidAddressRange(addr, size)) { | 878 | if (!IsValidAddressRange(addr, size)) { |
| 820 | LOG_ERROR(Kernel_SVC, "Region is not in the address space"); | 879 | LOG_ERROR(Kernel_SVC, "Region is not a valid address range, addr=0x{:016X}, size=0x{:016X}", |
| 880 | addr, size); | ||
| 821 | return ERR_INVALID_ADDRESS_STATE; | 881 | return ERR_INVALID_ADDRESS_STATE; |
| 822 | } | 882 | } |
| 823 | 883 | ||
| 824 | const auto permissions_type = static_cast<MemoryPermission>(permissions); | 884 | const auto permissions_type = static_cast<MemoryPermission>(permissions); |
| 825 | if (permissions_type != MemoryPermission::Read && | 885 | if (permissions_type != MemoryPermission::Read && |
| 826 | permissions_type != MemoryPermission::ReadWrite) { | 886 | permissions_type != MemoryPermission::ReadWrite) { |
| 827 | LOG_ERROR(Kernel_SVC, "Invalid permissions=0x{:08X}", permissions); | 887 | LOG_ERROR(Kernel_SVC, "Expected Read or ReadWrite permission but got permissions=0x{:08X}", |
| 888 | permissions); | ||
| 828 | return ERR_INVALID_MEMORY_PERMISSIONS; | 889 | return ERR_INVALID_MEMORY_PERMISSIONS; |
| 829 | } | 890 | } |
| 830 | 891 | ||
| 831 | auto* const current_process = Core::CurrentProcess(); | 892 | auto* const current_process = Core::CurrentProcess(); |
| 832 | auto shared_memory = current_process->GetHandleTable().Get<SharedMemory>(shared_memory_handle); | 893 | auto shared_memory = current_process->GetHandleTable().Get<SharedMemory>(shared_memory_handle); |
| 833 | if (!shared_memory) { | 894 | if (!shared_memory) { |
| 834 | LOG_ERROR(Kernel_SVC, "Invalid shared memory handle"); | 895 | LOG_ERROR(Kernel_SVC, "Shared memory does not exist, shared_memory_handle=0x{:08X}", |
| 896 | shared_memory_handle); | ||
| 835 | return ERR_INVALID_HANDLE; | 897 | return ERR_INVALID_HANDLE; |
| 836 | } | 898 | } |
| 837 | 899 | ||
| 838 | const auto& vm_manager = current_process->VMManager(); | 900 | const auto& vm_manager = current_process->VMManager(); |
| 839 | if (!vm_manager.IsWithinASLRRegion(addr, size)) { | 901 | if (!vm_manager.IsWithinASLRRegion(addr, size)) { |
| 840 | LOG_ERROR(Kernel_SVC, "Region is not within the ASLR region"); | 902 | LOG_ERROR(Kernel_SVC, "Region is not within the ASLR region. addr=0x{:016X}, size={:016X}", |
| 903 | addr, size); | ||
| 841 | return ERR_INVALID_MEMORY_RANGE; | 904 | return ERR_INVALID_MEMORY_RANGE; |
| 842 | } | 905 | } |
| 843 | 906 | ||
| @@ -849,30 +912,38 @@ static ResultCode UnmapSharedMemory(Handle shared_memory_handle, VAddr addr, u64 | |||
| 849 | shared_memory_handle, addr, size); | 912 | shared_memory_handle, addr, size); |
| 850 | 913 | ||
| 851 | if (!Common::Is4KBAligned(addr)) { | 914 | if (!Common::Is4KBAligned(addr)) { |
| 852 | LOG_ERROR(Kernel_SVC, "Address is not aligned"); | 915 | LOG_ERROR(Kernel_SVC, "Address is not aligned to 4KB, addr=0x{:016X}", addr); |
| 853 | return ERR_INVALID_ADDRESS; | 916 | return ERR_INVALID_ADDRESS; |
| 854 | } | 917 | } |
| 855 | 918 | ||
| 856 | if (size == 0 || !Common::Is4KBAligned(size)) { | 919 | if (size == 0) { |
| 857 | LOG_ERROR(Kernel_SVC, "Size is invalid"); | 920 | LOG_ERROR(Kernel_SVC, "Size is 0"); |
| 921 | return ERR_INVALID_SIZE; | ||
| 922 | } | ||
| 923 | |||
| 924 | if (!Common::Is4KBAligned(size)) { | ||
| 925 | LOG_ERROR(Kernel_SVC, "Size is not aligned to 4KB, size=0x{:016X}", size); | ||
| 858 | return ERR_INVALID_SIZE; | 926 | return ERR_INVALID_SIZE; |
| 859 | } | 927 | } |
| 860 | 928 | ||
| 861 | if (!IsValidAddressRange(addr, size)) { | 929 | if (!IsValidAddressRange(addr, size)) { |
| 862 | LOG_ERROR(Kernel_SVC, "Region is not in the valid address range"); | 930 | LOG_ERROR(Kernel_SVC, "Region is not a valid address range, addr=0x{:016X}, size=0x{:016X}", |
| 931 | addr, size); | ||
| 863 | return ERR_INVALID_ADDRESS_STATE; | 932 | return ERR_INVALID_ADDRESS_STATE; |
| 864 | } | 933 | } |
| 865 | 934 | ||
| 866 | auto* const current_process = Core::CurrentProcess(); | 935 | auto* const current_process = Core::CurrentProcess(); |
| 867 | auto shared_memory = current_process->GetHandleTable().Get<SharedMemory>(shared_memory_handle); | 936 | auto shared_memory = current_process->GetHandleTable().Get<SharedMemory>(shared_memory_handle); |
| 868 | if (!shared_memory) { | 937 | if (!shared_memory) { |
| 869 | LOG_ERROR(Kernel_SVC, "Shared memory is an invalid handle"); | 938 | LOG_ERROR(Kernel_SVC, "Shared memory does not exist, shared_memory_handle=0x{:08X}", |
| 939 | shared_memory_handle); | ||
| 870 | return ERR_INVALID_HANDLE; | 940 | return ERR_INVALID_HANDLE; |
| 871 | } | 941 | } |
| 872 | 942 | ||
| 873 | const auto& vm_manager = current_process->VMManager(); | 943 | const auto& vm_manager = current_process->VMManager(); |
| 874 | if (!vm_manager.IsWithinASLRRegion(addr, size)) { | 944 | if (!vm_manager.IsWithinASLRRegion(addr, size)) { |
| 875 | LOG_ERROR(Kernel_SVC, "Region is not within the ASLR region"); | 945 | LOG_ERROR(Kernel_SVC, "Region is not within the ASLR region. addr=0x{:016X}, size={:016X}", |
| 946 | addr, size); | ||
| 876 | return ERR_INVALID_MEMORY_RANGE; | 947 | return ERR_INVALID_MEMORY_RANGE; |
| 877 | } | 948 | } |
| 878 | 949 | ||
| @@ -886,7 +957,8 @@ static ResultCode QueryProcessMemory(MemoryInfo* memory_info, PageInfo* /*page_i | |||
| 886 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); | 957 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 887 | SharedPtr<Process> process = handle_table.Get<Process>(process_handle); | 958 | SharedPtr<Process> process = handle_table.Get<Process>(process_handle); |
| 888 | if (!process) { | 959 | if (!process) { |
| 889 | LOG_ERROR(Kernel_SVC, "Invalid process handle"); | 960 | LOG_ERROR(Kernel_SVC, "Process handle does not exist, process_handle=0x{:08X}", |
| 961 | process_handle); | ||
| 890 | return ERR_INVALID_HANDLE; | 962 | return ERR_INVALID_HANDLE; |
| 891 | } | 963 | } |
| 892 | auto vma = process->VMManager().FindVMA(addr); | 964 | auto vma = process->VMManager().FindVMA(addr); |
| @@ -936,7 +1008,8 @@ static ResultCode CreateThread(Handle* out_handle, VAddr entry_point, u64 arg, V | |||
| 936 | entry_point, name, arg, stack_top, priority, processor_id, *out_handle); | 1008 | entry_point, name, arg, stack_top, priority, processor_id, *out_handle); |
| 937 | 1009 | ||
| 938 | if (priority > THREADPRIO_LOWEST) { | 1010 | if (priority > THREADPRIO_LOWEST) { |
| 939 | LOG_ERROR(Kernel_SVC, "Invalid thread priority"); | 1011 | LOG_ERROR(Kernel_SVC, "An invalid priority was specified, expected {} but got {}", |
| 1012 | THREADPRIO_LOWEST, priority); | ||
| 940 | return ERR_INVALID_THREAD_PRIORITY; | 1013 | return ERR_INVALID_THREAD_PRIORITY; |
| 941 | } | 1014 | } |
| 942 | 1015 | ||
| @@ -986,7 +1059,8 @@ static ResultCode StartThread(Handle thread_handle) { | |||
| 986 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); | 1059 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 987 | const SharedPtr<Thread> thread = handle_table.Get<Thread>(thread_handle); | 1060 | const SharedPtr<Thread> thread = handle_table.Get<Thread>(thread_handle); |
| 988 | if (!thread) { | 1061 | if (!thread) { |
| 989 | LOG_ERROR(Kernel_SVC, "Thread is an invalid handle"); | 1062 | LOG_ERROR(Kernel_SVC, "Thread handle does not exist, thread_handle=0x{:08X}", |
| 1063 | thread_handle); | ||
| 990 | return ERR_INVALID_HANDLE; | 1064 | return ERR_INVALID_HANDLE; |
| 991 | } | 1065 | } |
| 992 | 1066 | ||
| @@ -1166,12 +1240,12 @@ static ResultCode WaitForAddress(VAddr address, u32 type, s32 value, s64 timeout | |||
| 1166 | address, type, value, timeout); | 1240 | address, type, value, timeout); |
| 1167 | // If the passed address is a kernel virtual address, return invalid memory state. | 1241 | // If the passed address is a kernel virtual address, return invalid memory state. |
| 1168 | if (Memory::IsKernelVirtualAddress(address)) { | 1242 | if (Memory::IsKernelVirtualAddress(address)) { |
| 1169 | LOG_ERROR(Kernel_SVC, "Address is a kernel virtual address"); | 1243 | LOG_ERROR(Kernel_SVC, "Address is a kernel virtual address, address={:016X}", address); |
| 1170 | return ERR_INVALID_ADDRESS_STATE; | 1244 | return ERR_INVALID_ADDRESS_STATE; |
| 1171 | } | 1245 | } |
| 1172 | // If the address is not properly aligned to 4 bytes, return invalid address. | 1246 | // If the address is not properly aligned to 4 bytes, return invalid address. |
| 1173 | if (address % sizeof(u32) != 0) { | 1247 | if (!Common::IsWordAligned(address)) { |
| 1174 | LOG_ERROR(Kernel_SVC, "Address is not aligned"); | 1248 | LOG_ERROR(Kernel_SVC, "Address is not word aligned, address={:016X}", address); |
| 1175 | return ERR_INVALID_ADDRESS; | 1249 | return ERR_INVALID_ADDRESS; |
| 1176 | } | 1250 | } |
| 1177 | 1251 | ||
| @@ -1183,7 +1257,10 @@ static ResultCode WaitForAddress(VAddr address, u32 type, s32 value, s64 timeout | |||
| 1183 | case AddressArbiter::ArbitrationType::WaitIfEqual: | 1257 | case AddressArbiter::ArbitrationType::WaitIfEqual: |
| 1184 | return AddressArbiter::WaitForAddressIfEqual(address, value, timeout); | 1258 | return AddressArbiter::WaitForAddressIfEqual(address, value, timeout); |
| 1185 | default: | 1259 | default: |
| 1186 | LOG_ERROR(Kernel_SVC, "Invalid arbitration type"); | 1260 | LOG_ERROR(Kernel_SVC, |
| 1261 | "Invalid arbitration type, expected WaitIfLessThan, DecrementAndWaitIfLessThan " | ||
| 1262 | "or WaitIfEqual but got {}", | ||
| 1263 | type); | ||
| 1187 | return ERR_INVALID_ENUM_VALUE; | 1264 | return ERR_INVALID_ENUM_VALUE; |
| 1188 | } | 1265 | } |
| 1189 | } | 1266 | } |
| @@ -1194,12 +1271,12 @@ static ResultCode SignalToAddress(VAddr address, u32 type, s32 value, s32 num_to | |||
| 1194 | address, type, value, num_to_wake); | 1271 | address, type, value, num_to_wake); |
| 1195 | // If the passed address is a kernel virtual address, return invalid memory state. | 1272 | // If the passed address is a kernel virtual address, return invalid memory state. |
| 1196 | if (Memory::IsKernelVirtualAddress(address)) { | 1273 | if (Memory::IsKernelVirtualAddress(address)) { |
| 1197 | LOG_ERROR(Kernel_SVC, "Address is a kernel virtual address"); | 1274 | LOG_ERROR(Kernel_SVC, "Address is a kernel virtual address, address={:016X}", address); |
| 1198 | return ERR_INVALID_ADDRESS_STATE; | 1275 | return ERR_INVALID_ADDRESS_STATE; |
| 1199 | } | 1276 | } |
| 1200 | // If the address is not properly aligned to 4 bytes, return invalid address. | 1277 | // If the address is not properly aligned to 4 bytes, return invalid address. |
| 1201 | if (address % sizeof(u32) != 0) { | 1278 | if (!Common::IsWordAligned(address)) { |
| 1202 | LOG_ERROR(Kernel_SVC, "Address is not aligned"); | 1279 | LOG_ERROR(Kernel_SVC, "Address is not word aligned, address={:016X}", address); |
| 1203 | return ERR_INVALID_ADDRESS; | 1280 | return ERR_INVALID_ADDRESS; |
| 1204 | } | 1281 | } |
| 1205 | 1282 | ||
| @@ -1212,7 +1289,10 @@ static ResultCode SignalToAddress(VAddr address, u32 type, s32 value, s32 num_to | |||
| 1212 | return AddressArbiter::ModifyByWaitingCountAndSignalToAddressIfEqual(address, value, | 1289 | return AddressArbiter::ModifyByWaitingCountAndSignalToAddressIfEqual(address, value, |
| 1213 | num_to_wake); | 1290 | num_to_wake); |
| 1214 | default: | 1291 | default: |
| 1215 | LOG_ERROR(Kernel_SVC, "Invalid arbitration type"); | 1292 | LOG_ERROR(Kernel_SVC, |
| 1293 | "Invalid signal type, expected Signal, IncrementAndSignalIfEqual " | ||
| 1294 | "or ModifyByWaitingCountAndSignalIfEqual but got {}", | ||
| 1295 | type); | ||
| 1216 | return ERR_INVALID_ENUM_VALUE; | 1296 | return ERR_INVALID_ENUM_VALUE; |
| 1217 | } | 1297 | } |
| 1218 | } | 1298 | } |
| @@ -1294,7 +1374,8 @@ static ResultCode GetThreadCoreMask(Handle thread_handle, u32* core, u64* mask) | |||
| 1294 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); | 1374 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 1295 | const SharedPtr<Thread> thread = handle_table.Get<Thread>(thread_handle); | 1375 | const SharedPtr<Thread> thread = handle_table.Get<Thread>(thread_handle); |
| 1296 | if (!thread) { | 1376 | if (!thread) { |
| 1297 | LOG_ERROR(Kernel_SVC, "Thread is an invalid handle"); | 1377 | LOG_ERROR(Kernel_SVC, "Thread handle does not exist, thread_handle=0x{:08X}", |
| 1378 | thread_handle); | ||
| 1298 | return ERR_INVALID_HANDLE; | 1379 | return ERR_INVALID_HANDLE; |
| 1299 | } | 1380 | } |
| 1300 | 1381 | ||
| @@ -1311,7 +1392,8 @@ static ResultCode SetThreadCoreMask(Handle thread_handle, u32 core, u64 mask) { | |||
| 1311 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); | 1392 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 1312 | const SharedPtr<Thread> thread = handle_table.Get<Thread>(thread_handle); | 1393 | const SharedPtr<Thread> thread = handle_table.Get<Thread>(thread_handle); |
| 1313 | if (!thread) { | 1394 | if (!thread) { |
| 1314 | LOG_ERROR(Kernel_SVC, "Thread is an invalid handle"); | 1395 | LOG_ERROR(Kernel_SVC, "Thread handle does not exist, thread_handle=0x{:08X}", |
| 1396 | thread_handle); | ||
| 1315 | return ERR_INVALID_HANDLE; | 1397 | return ERR_INVALID_HANDLE; |
| 1316 | } | 1398 | } |
| 1317 | 1399 | ||
| @@ -1336,13 +1418,14 @@ static ResultCode SetThreadCoreMask(Handle thread_handle, u32 core, u64 mask) { | |||
| 1336 | if (core == OnlyChangeMask) { | 1418 | if (core == OnlyChangeMask) { |
| 1337 | core = thread->GetIdealCore(); | 1419 | core = thread->GetIdealCore(); |
| 1338 | } else if (core >= Core::NUM_CPU_CORES && core != static_cast<u32>(-1)) { | 1420 | } else if (core >= Core::NUM_CPU_CORES && core != static_cast<u32>(-1)) { |
| 1339 | LOG_ERROR(Kernel_SVC, "Invalid processor ID specified"); | 1421 | LOG_ERROR(Kernel_SVC, "Invalid core specified, got {}", core); |
| 1340 | return ERR_INVALID_PROCESSOR_ID; | 1422 | return ERR_INVALID_PROCESSOR_ID; |
| 1341 | } | 1423 | } |
| 1342 | 1424 | ||
| 1343 | // Error out if the input core isn't enabled in the input mask. | 1425 | // Error out if the input core isn't enabled in the input mask. |
| 1344 | if (core < Core::NUM_CPU_CORES && (mask & (1ull << core)) == 0) { | 1426 | if (core < Core::NUM_CPU_CORES && (mask & (1ull << core)) == 0) { |
| 1345 | LOG_ERROR(Kernel_SVC, "Invalid core and mask"); | 1427 | LOG_ERROR(Kernel_SVC, "Core is not enabled for the current mask, core={}, mask={:016X}", |
| 1428 | core, mask); | ||
| 1346 | return ERR_INVALID_COMBINATION; | 1429 | return ERR_INVALID_COMBINATION; |
| 1347 | } | 1430 | } |
| 1348 | 1431 | ||
| @@ -1358,21 +1441,31 @@ static ResultCode CreateSharedMemory(Handle* handle, u64 size, u32 local_permiss | |||
| 1358 | 1441 | ||
| 1359 | // Size must be a multiple of 4KB and be less than or equal to | 1442 | // Size must be a multiple of 4KB and be less than or equal to |
| 1360 | // approx. 8 GB (actually (1GB - 512B) * 8) | 1443 | // approx. 8 GB (actually (1GB - 512B) * 8) |
| 1361 | if (size == 0 || (size & 0xFFFFFFFE00000FFF) != 0) { | 1444 | if (size == 0) { |
| 1362 | LOG_ERROR(Kernel_SVC, "Invalid size"); | 1445 | LOG_ERROR(Kernel_SVC, "Size is 0"); |
| 1446 | } | ||
| 1447 | if ((size & 0xFFFFFFFE00000FFF) != 0) { | ||
| 1448 | LOG_ERROR(Kernel_SVC, "Size is not a multiple of 4KB or is greater than 8GB, size={:016X}", | ||
| 1449 | size); | ||
| 1363 | return ERR_INVALID_SIZE; | 1450 | return ERR_INVALID_SIZE; |
| 1364 | } | 1451 | } |
| 1365 | 1452 | ||
| 1366 | const auto local_perms = static_cast<MemoryPermission>(local_permissions); | 1453 | const auto local_perms = static_cast<MemoryPermission>(local_permissions); |
| 1367 | if (local_perms != MemoryPermission::Read && local_perms != MemoryPermission::ReadWrite) { | 1454 | if (local_perms != MemoryPermission::Read && local_perms != MemoryPermission::ReadWrite) { |
| 1368 | LOG_ERROR(Kernel_SVC, "Invalid memory permissions"); | 1455 | LOG_ERROR(Kernel_SVC, |
| 1456 | "Invalid local memory permissions, expected Read or ReadWrite but got " | ||
| 1457 | "local_permissions={}", | ||
| 1458 | static_cast<u32>(local_permissions)); | ||
| 1369 | return ERR_INVALID_MEMORY_PERMISSIONS; | 1459 | return ERR_INVALID_MEMORY_PERMISSIONS; |
| 1370 | } | 1460 | } |
| 1371 | 1461 | ||
| 1372 | const auto remote_perms = static_cast<MemoryPermission>(remote_permissions); | 1462 | const auto remote_perms = static_cast<MemoryPermission>(remote_permissions); |
| 1373 | if (remote_perms != MemoryPermission::Read && remote_perms != MemoryPermission::ReadWrite && | 1463 | if (remote_perms != MemoryPermission::Read && remote_perms != MemoryPermission::ReadWrite && |
| 1374 | remote_perms != MemoryPermission::DontCare) { | 1464 | remote_perms != MemoryPermission::DontCare) { |
| 1375 | LOG_ERROR(Kernel_SVC, "Invalid memory permissions"); | 1465 | LOG_ERROR(Kernel_SVC, |
| 1466 | "Invalid remote memory permissions, expected Read, ReadWrite or DontCare but got " | ||
| 1467 | "remote_permissions={}", | ||
| 1468 | static_cast<u32>(remote_permissions)); | ||
| 1376 | return ERR_INVALID_MEMORY_PERMISSIONS; | 1469 | return ERR_INVALID_MEMORY_PERMISSIONS; |
| 1377 | } | 1470 | } |
| 1378 | 1471 | ||
| @@ -1392,7 +1485,7 @@ static ResultCode ClearEvent(Handle handle) { | |||
| 1392 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); | 1485 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 1393 | SharedPtr<Event> evt = handle_table.Get<Event>(handle); | 1486 | SharedPtr<Event> evt = handle_table.Get<Event>(handle); |
| 1394 | if (evt == nullptr) { | 1487 | if (evt == nullptr) { |
| 1395 | LOG_ERROR(Kernel_SVC, "Invalid event handle"); | 1488 | LOG_ERROR(Kernel_SVC, "Event handle does not exist, handle=0x{:08X}", handle); |
| 1396 | return ERR_INVALID_HANDLE; | 1489 | return ERR_INVALID_HANDLE; |
| 1397 | } | 1490 | } |
| 1398 | 1491 | ||
| @@ -1411,13 +1504,14 @@ static ResultCode GetProcessInfo(u64* out, Handle process_handle, u32 type) { | |||
| 1411 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); | 1504 | const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); |
| 1412 | const auto process = handle_table.Get<Process>(process_handle); | 1505 | const auto process = handle_table.Get<Process>(process_handle); |
| 1413 | if (!process) { | 1506 | if (!process) { |
| 1414 | LOG_ERROR(Kernel_SVC, "Invalid process handle"); | 1507 | LOG_ERROR(Kernel_SVC, "Process handle does not exist, process_handle=0x{:08X}", |
| 1508 | process_handle); | ||
| 1415 | return ERR_INVALID_HANDLE; | 1509 | return ERR_INVALID_HANDLE; |
| 1416 | } | 1510 | } |
| 1417 | 1511 | ||
| 1418 | const auto info_type = static_cast<InfoType>(type); | 1512 | const auto info_type = static_cast<InfoType>(type); |
| 1419 | if (info_type != InfoType::Status) { | 1513 | if (info_type != InfoType::Status) { |
| 1420 | LOG_ERROR(Kernel_SVC, "Info type is not status"); | 1514 | LOG_ERROR(Kernel_SVC, "Expected info_type to be Status but got {} instead", type); |
| 1421 | return ERR_INVALID_ENUM_VALUE; | 1515 | return ERR_INVALID_ENUM_VALUE; |
| 1422 | } | 1516 | } |
| 1423 | 1517 | ||