summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Chloe2021-02-13 10:43:01 +1100
committerGravatar GitHub2021-02-12 15:43:01 -0800
commit37939482fb93d2155d8625596f2b1145d4f6e8e3 (patch)
tree0c18a00c0f9be5cc87b50ff46c439765d9f7db46 /src
parentMerge pull request #5902 from lioncash/core-warn (diff)
downloadyuzu-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')
-rw-r--r--src/core/CMakeLists.txt3
-rw-r--r--src/core/hle/kernel/client_port.cpp4
-rw-r--r--src/core/hle/kernel/client_session.cpp4
-rw-r--r--src/core/hle/kernel/errors.h43
-rw-r--r--src/core/hle/kernel/handle_table.cpp10
-rw-r--r--src/core/hle/kernel/hle_ipc.cpp2
-rw-r--r--src/core/hle/kernel/k_address_arbiter.cpp28
-rw-r--r--src/core/hle/kernel/k_condition_variable.cpp20
-rw-r--r--src/core/hle/kernel/k_readable_event.cpp3
-rw-r--r--src/core/hle/kernel/k_resource_limit.cpp2
-rw-r--r--src/core/hle/kernel/k_synchronization_object.cpp8
-rw-r--r--src/core/hle/kernel/k_thread.cpp30
-rw-r--r--src/core/hle/kernel/kernel.cpp2
-rw-r--r--src/core/hle/kernel/memory/memory_manager.cpp6
-rw-r--r--src/core/hle/kernel/memory/page_table.cpp48
-rw-r--r--src/core/hle/kernel/process.cpp5
-rw-r--r--src/core/hle/kernel/process_capability.cpp34
-rw-r--r--src/core/hle/kernel/server_port.cpp4
-rw-r--r--src/core/hle/kernel/svc.cpp196
-rw-r--r--src/core/hle/kernel/svc_results.h21
-rw-r--r--src/core/hle/service/ldr/ldr.cpp6
21 files changed, 223 insertions, 256 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index 987076956..52151e788 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -148,7 +148,7 @@ add_library(core STATIC
148 hle/kernel/client_session.h 148 hle/kernel/client_session.h
149 hle/kernel/code_set.cpp 149 hle/kernel/code_set.cpp
150 hle/kernel/code_set.h 150 hle/kernel/code_set.h
151 hle/kernel/errors.h 151 hle/kernel/svc_results.h
152 hle/kernel/global_scheduler_context.cpp 152 hle/kernel/global_scheduler_context.cpp
153 hle/kernel/global_scheduler_context.h 153 hle/kernel/global_scheduler_context.h
154 hle/kernel/handle_table.cpp 154 hle/kernel/handle_table.cpp
@@ -223,7 +223,6 @@ add_library(core STATIC
223 hle/kernel/svc.cpp 223 hle/kernel/svc.cpp
224 hle/kernel/svc.h 224 hle/kernel/svc.h
225 hle/kernel/svc_common.h 225 hle/kernel/svc_common.h
226 hle/kernel/svc_results.h
227 hle/kernel/svc_types.h 226 hle/kernel/svc_types.h
228 hle/kernel/svc_wrap.h 227 hle/kernel/svc_wrap.h
229 hle/kernel/time_manager.cpp 228 hle/kernel/time_manager.cpp
diff --git a/src/core/hle/kernel/client_port.cpp b/src/core/hle/kernel/client_port.cpp
index f8f005f15..0b6957e31 100644
--- a/src/core/hle/kernel/client_port.cpp
+++ b/src/core/hle/kernel/client_port.cpp
@@ -4,11 +4,11 @@
4 4
5#include "core/hle/kernel/client_port.h" 5#include "core/hle/kernel/client_port.h"
6#include "core/hle/kernel/client_session.h" 6#include "core/hle/kernel/client_session.h"
7#include "core/hle/kernel/errors.h"
8#include "core/hle/kernel/hle_ipc.h" 7#include "core/hle/kernel/hle_ipc.h"
9#include "core/hle/kernel/object.h" 8#include "core/hle/kernel/object.h"
10#include "core/hle/kernel/server_port.h" 9#include "core/hle/kernel/server_port.h"
11#include "core/hle/kernel/session.h" 10#include "core/hle/kernel/session.h"
11#include "core/hle/kernel/svc_results.h"
12 12
13namespace Kernel { 13namespace Kernel {
14 14
@@ -21,7 +21,7 @@ std::shared_ptr<ServerPort> ClientPort::GetServerPort() const {
21 21
22ResultVal<std::shared_ptr<ClientSession>> ClientPort::Connect() { 22ResultVal<std::shared_ptr<ClientSession>> ClientPort::Connect() {
23 if (active_sessions >= max_sessions) { 23 if (active_sessions >= max_sessions) {
24 return ERR_MAX_CONNECTIONS_REACHED; 24 return ResultMaxConnectionsReached;
25 } 25 }
26 active_sessions++; 26 active_sessions++;
27 27
diff --git a/src/core/hle/kernel/client_session.cpp b/src/core/hle/kernel/client_session.cpp
index a2be1a8f6..e230f365a 100644
--- a/src/core/hle/kernel/client_session.cpp
+++ b/src/core/hle/kernel/client_session.cpp
@@ -3,11 +3,11 @@
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include "core/hle/kernel/client_session.h" 5#include "core/hle/kernel/client_session.h"
6#include "core/hle/kernel/errors.h"
7#include "core/hle/kernel/hle_ipc.h" 6#include "core/hle/kernel/hle_ipc.h"
8#include "core/hle/kernel/k_thread.h" 7#include "core/hle/kernel/k_thread.h"
9#include "core/hle/kernel/server_session.h" 8#include "core/hle/kernel/server_session.h"
10#include "core/hle/kernel/session.h" 9#include "core/hle/kernel/session.h"
10#include "core/hle/kernel/svc_results.h"
11#include "core/hle/result.h" 11#include "core/hle/result.h"
12 12
13namespace Kernel { 13namespace Kernel {
@@ -43,7 +43,7 @@ ResultCode ClientSession::SendSyncRequest(std::shared_ptr<KThread> thread,
43 Core::Timing::CoreTiming& core_timing) { 43 Core::Timing::CoreTiming& core_timing) {
44 // Keep ServerSession alive until we're done working with it. 44 // Keep ServerSession alive until we're done working with it.
45 if (!parent->Server()) { 45 if (!parent->Server()) {
46 return ERR_SESSION_CLOSED_BY_REMOTE; 46 return ResultSessionClosedByRemote;
47 } 47 }
48 48
49 // Signal the server session that new data is available 49 // Signal the server session that new data is available
diff --git a/src/core/hle/kernel/errors.h b/src/core/hle/kernel/errors.h
deleted file mode 100644
index 7d32a39f0..000000000
--- a/src/core/hle/kernel/errors.h
+++ /dev/null
@@ -1,43 +0,0 @@
1// Copyright 2018 yuzu emulator team
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include "core/hle/result.h"
8
9namespace Kernel {
10
11// Confirmed Switch kernel error codes
12
13constexpr ResultCode ERR_MAX_CONNECTIONS_REACHED{ErrorModule::Kernel, 7};
14constexpr ResultCode ERR_INVALID_CAPABILITY_DESCRIPTOR{ErrorModule::Kernel, 14};
15constexpr ResultCode ERR_THREAD_TERMINATING{ErrorModule::Kernel, 59};
16constexpr ResultCode ERR_TERMINATION_REQUESTED{ErrorModule::Kernel, 59};
17constexpr ResultCode ERR_INVALID_SIZE{ErrorModule::Kernel, 101};
18constexpr ResultCode ERR_INVALID_ADDRESS{ErrorModule::Kernel, 102};
19constexpr ResultCode ERR_OUT_OF_RESOURCES{ErrorModule::Kernel, 103};
20constexpr ResultCode ERR_OUT_OF_MEMORY{ErrorModule::Kernel, 104};
21constexpr ResultCode ERR_HANDLE_TABLE_FULL{ErrorModule::Kernel, 105};
22constexpr ResultCode ERR_INVALID_ADDRESS_STATE{ErrorModule::Kernel, 106};
23constexpr ResultCode ERR_INVALID_CURRENT_MEMORY{ErrorModule::Kernel, 106};
24constexpr ResultCode ERR_INVALID_MEMORY_PERMISSIONS{ErrorModule::Kernel, 108};
25constexpr ResultCode ERR_INVALID_MEMORY_RANGE{ErrorModule::Kernel, 110};
26constexpr ResultCode ERR_INVALID_PROCESSOR_ID{ErrorModule::Kernel, 113};
27constexpr ResultCode ERR_INVALID_THREAD_PRIORITY{ErrorModule::Kernel, 112};
28constexpr ResultCode ERR_INVALID_HANDLE{ErrorModule::Kernel, 114};
29constexpr ResultCode ERR_INVALID_POINTER{ErrorModule::Kernel, 115};
30constexpr ResultCode ERR_INVALID_COMBINATION{ErrorModule::Kernel, 116};
31constexpr ResultCode RESULT_TIMEOUT{ErrorModule::Kernel, 117};
32constexpr ResultCode ERR_SYNCHRONIZATION_CANCELED{ErrorModule::Kernel, 118};
33constexpr ResultCode ERR_CANCELLED{ErrorModule::Kernel, 118};
34constexpr ResultCode ERR_OUT_OF_RANGE{ErrorModule::Kernel, 119};
35constexpr ResultCode ERR_INVALID_ENUM_VALUE{ErrorModule::Kernel, 120};
36constexpr ResultCode ERR_NOT_FOUND{ErrorModule::Kernel, 121};
37constexpr ResultCode ERR_BUSY{ErrorModule::Kernel, 122};
38constexpr ResultCode ERR_SESSION_CLOSED_BY_REMOTE{ErrorModule::Kernel, 123};
39constexpr ResultCode ERR_INVALID_STATE{ErrorModule::Kernel, 125};
40constexpr ResultCode ERR_RESERVED_VALUE{ErrorModule::Kernel, 126};
41constexpr ResultCode ERR_RESOURCE_LIMIT_EXCEEDED{ErrorModule::Kernel, 132};
42
43} // namespace Kernel
diff --git a/src/core/hle/kernel/handle_table.cpp b/src/core/hle/kernel/handle_table.cpp
index 1a2fa9cd8..f96d34078 100644
--- a/src/core/hle/kernel/handle_table.cpp
+++ b/src/core/hle/kernel/handle_table.cpp
@@ -6,12 +6,12 @@
6#include "common/assert.h" 6#include "common/assert.h"
7#include "common/logging/log.h" 7#include "common/logging/log.h"
8#include "core/core.h" 8#include "core/core.h"
9#include "core/hle/kernel/errors.h"
10#include "core/hle/kernel/handle_table.h" 9#include "core/hle/kernel/handle_table.h"
11#include "core/hle/kernel/k_scheduler.h" 10#include "core/hle/kernel/k_scheduler.h"
12#include "core/hle/kernel/k_thread.h" 11#include "core/hle/kernel/k_thread.h"
13#include "core/hle/kernel/kernel.h" 12#include "core/hle/kernel/kernel.h"
14#include "core/hle/kernel/process.h" 13#include "core/hle/kernel/process.h"
14#include "core/hle/kernel/svc_results.h"
15 15
16namespace Kernel { 16namespace Kernel {
17namespace { 17namespace {
@@ -33,7 +33,7 @@ HandleTable::~HandleTable() = default;
33ResultCode HandleTable::SetSize(s32 handle_table_size) { 33ResultCode HandleTable::SetSize(s32 handle_table_size) {
34 if (static_cast<u32>(handle_table_size) > MAX_COUNT) { 34 if (static_cast<u32>(handle_table_size) > MAX_COUNT) {
35 LOG_ERROR(Kernel, "Handle table size {} is greater than {}", handle_table_size, MAX_COUNT); 35 LOG_ERROR(Kernel, "Handle table size {} is greater than {}", handle_table_size, MAX_COUNT);
36 return ERR_OUT_OF_MEMORY; 36 return ResultOutOfMemory;
37 } 37 }
38 38
39 // Values less than or equal to zero indicate to use the maximum allowable 39 // Values less than or equal to zero indicate to use the maximum allowable
@@ -53,7 +53,7 @@ ResultVal<Handle> HandleTable::Create(std::shared_ptr<Object> obj) {
53 const u16 slot = next_free_slot; 53 const u16 slot = next_free_slot;
54 if (slot >= table_size) { 54 if (slot >= table_size) {
55 LOG_ERROR(Kernel, "Unable to allocate Handle, too many slots in use."); 55 LOG_ERROR(Kernel, "Unable to allocate Handle, too many slots in use.");
56 return ERR_HANDLE_TABLE_FULL; 56 return ResultHandleTableFull;
57 } 57 }
58 next_free_slot = generations[slot]; 58 next_free_slot = generations[slot];
59 59
@@ -76,7 +76,7 @@ ResultVal<Handle> HandleTable::Duplicate(Handle handle) {
76 std::shared_ptr<Object> object = GetGeneric(handle); 76 std::shared_ptr<Object> object = GetGeneric(handle);
77 if (object == nullptr) { 77 if (object == nullptr) {
78 LOG_ERROR(Kernel, "Tried to duplicate invalid handle: {:08X}", handle); 78 LOG_ERROR(Kernel, "Tried to duplicate invalid handle: {:08X}", handle);
79 return ERR_INVALID_HANDLE; 79 return ResultInvalidHandle;
80 } 80 }
81 return Create(std::move(object)); 81 return Create(std::move(object));
82} 82}
@@ -84,7 +84,7 @@ ResultVal<Handle> HandleTable::Duplicate(Handle handle) {
84ResultCode HandleTable::Close(Handle handle) { 84ResultCode HandleTable::Close(Handle handle) {
85 if (!IsValid(handle)) { 85 if (!IsValid(handle)) {
86 LOG_ERROR(Kernel, "Handle is not valid! handle={:08X}", handle); 86 LOG_ERROR(Kernel, "Handle is not valid! handle={:08X}", handle);
87 return ERR_INVALID_HANDLE; 87 return ResultInvalidHandle;
88 } 88 }
89 89
90 const u16 slot = GetSlot(handle); 90 const u16 slot = GetSlot(handle);
diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp
index 7ec62cf18..161d9f782 100644
--- a/src/core/hle/kernel/hle_ipc.cpp
+++ b/src/core/hle/kernel/hle_ipc.cpp
@@ -14,7 +14,6 @@
14#include "common/common_types.h" 14#include "common/common_types.h"
15#include "common/logging/log.h" 15#include "common/logging/log.h"
16#include "core/hle/ipc_helpers.h" 16#include "core/hle/ipc_helpers.h"
17#include "core/hle/kernel/errors.h"
18#include "core/hle/kernel/handle_table.h" 17#include "core/hle/kernel/handle_table.h"
19#include "core/hle/kernel/hle_ipc.h" 18#include "core/hle/kernel/hle_ipc.h"
20#include "core/hle/kernel/k_readable_event.h" 19#include "core/hle/kernel/k_readable_event.h"
@@ -26,6 +25,7 @@
26#include "core/hle/kernel/object.h" 25#include "core/hle/kernel/object.h"
27#include "core/hle/kernel/process.h" 26#include "core/hle/kernel/process.h"
28#include "core/hle/kernel/server_session.h" 27#include "core/hle/kernel/server_session.h"
28#include "core/hle/kernel/svc_results.h"
29#include "core/hle/kernel/time_manager.h" 29#include "core/hle/kernel/time_manager.h"
30#include "core/memory.h" 30#include "core/memory.h"
31 31
diff --git a/src/core/hle/kernel/k_address_arbiter.cpp b/src/core/hle/kernel/k_address_arbiter.cpp
index d0e90fd60..7018f56da 100644
--- a/src/core/hle/kernel/k_address_arbiter.cpp
+++ b/src/core/hle/kernel/k_address_arbiter.cpp
@@ -120,10 +120,10 @@ ResultCode KAddressArbiter::SignalAndIncrementIfEqual(VAddr addr, s32 value, s32
120 s32 user_value{}; 120 s32 user_value{};
121 if (!UpdateIfEqual(system, &user_value, addr, value, value + 1)) { 121 if (!UpdateIfEqual(system, &user_value, addr, value, value + 1)) {
122 LOG_ERROR(Kernel, "Invalid current memory!"); 122 LOG_ERROR(Kernel, "Invalid current memory!");
123 return Svc::ResultInvalidCurrentMemory; 123 return ResultInvalidCurrentMemory;
124 } 124 }
125 if (user_value != value) { 125 if (user_value != value) {
126 return Svc::ResultInvalidState; 126 return ResultInvalidState;
127 } 127 }
128 128
129 auto it = thread_tree.nfind_light({addr, -1}); 129 auto it = thread_tree.nfind_light({addr, -1});
@@ -189,10 +189,10 @@ ResultCode KAddressArbiter::SignalAndModifyByWaitingCountIfEqual(VAddr addr, s32
189 189
190 if (!succeeded) { 190 if (!succeeded) {
191 LOG_ERROR(Kernel, "Invalid current memory!"); 191 LOG_ERROR(Kernel, "Invalid current memory!");
192 return Svc::ResultInvalidCurrentMemory; 192 return ResultInvalidCurrentMemory;
193 } 193 }
194 if (user_value != value) { 194 if (user_value != value) {
195 return Svc::ResultInvalidState; 195 return ResultInvalidState;
196 } 196 }
197 197
198 while ((it != thread_tree.end()) && (count <= 0 || num_waiters < count) && 198 while ((it != thread_tree.end()) && (count <= 0 || num_waiters < count) &&
@@ -221,11 +221,11 @@ ResultCode KAddressArbiter::WaitIfLessThan(VAddr addr, s32 value, bool decrement
221 // Check that the thread isn't terminating. 221 // Check that the thread isn't terminating.
222 if (cur_thread->IsTerminationRequested()) { 222 if (cur_thread->IsTerminationRequested()) {
223 slp.CancelSleep(); 223 slp.CancelSleep();
224 return Svc::ResultTerminationRequested; 224 return ResultTerminationRequested;
225 } 225 }
226 226
227 // Set the synced object. 227 // Set the synced object.
228 cur_thread->SetSyncedObject(nullptr, Svc::ResultTimedOut); 228 cur_thread->SetSyncedObject(nullptr, ResultTimedOut);
229 229
230 // Read the value from userspace. 230 // Read the value from userspace.
231 s32 user_value{}; 231 s32 user_value{};
@@ -238,19 +238,19 @@ ResultCode KAddressArbiter::WaitIfLessThan(VAddr addr, s32 value, bool decrement
238 238
239 if (!succeeded) { 239 if (!succeeded) {
240 slp.CancelSleep(); 240 slp.CancelSleep();
241 return Svc::ResultInvalidCurrentMemory; 241 return ResultInvalidCurrentMemory;
242 } 242 }
243 243
244 // Check that the value is less than the specified one. 244 // Check that the value is less than the specified one.
245 if (user_value >= value) { 245 if (user_value >= value) {
246 slp.CancelSleep(); 246 slp.CancelSleep();
247 return Svc::ResultInvalidState; 247 return ResultInvalidState;
248 } 248 }
249 249
250 // Check that the timeout is non-zero. 250 // Check that the timeout is non-zero.
251 if (timeout == 0) { 251 if (timeout == 0) {
252 slp.CancelSleep(); 252 slp.CancelSleep();
253 return Svc::ResultTimedOut; 253 return ResultTimedOut;
254 } 254 }
255 255
256 // Set the arbiter. 256 // Set the arbiter.
@@ -288,29 +288,29 @@ ResultCode KAddressArbiter::WaitIfEqual(VAddr addr, s32 value, s64 timeout) {
288 // Check that the thread isn't terminating. 288 // Check that the thread isn't terminating.
289 if (cur_thread->IsTerminationRequested()) { 289 if (cur_thread->IsTerminationRequested()) {
290 slp.CancelSleep(); 290 slp.CancelSleep();
291 return Svc::ResultTerminationRequested; 291 return ResultTerminationRequested;
292 } 292 }
293 293
294 // Set the synced object. 294 // Set the synced object.
295 cur_thread->SetSyncedObject(nullptr, Svc::ResultTimedOut); 295 cur_thread->SetSyncedObject(nullptr, ResultTimedOut);
296 296
297 // Read the value from userspace. 297 // Read the value from userspace.
298 s32 user_value{}; 298 s32 user_value{};
299 if (!ReadFromUser(system, &user_value, addr)) { 299 if (!ReadFromUser(system, &user_value, addr)) {
300 slp.CancelSleep(); 300 slp.CancelSleep();
301 return Svc::ResultInvalidCurrentMemory; 301 return ResultInvalidCurrentMemory;
302 } 302 }
303 303
304 // Check that the value is equal. 304 // Check that the value is equal.
305 if (value != user_value) { 305 if (value != user_value) {
306 slp.CancelSleep(); 306 slp.CancelSleep();
307 return Svc::ResultInvalidState; 307 return ResultInvalidState;
308 } 308 }
309 309
310 // Check that the timeout is non-zero. 310 // Check that the timeout is non-zero.
311 if (timeout == 0) { 311 if (timeout == 0) {
312 slp.CancelSleep(); 312 slp.CancelSleep();
313 return Svc::ResultTimedOut; 313 return ResultTimedOut;
314 } 314 }
315 315
316 // Set the arbiter. 316 // Set the arbiter.
diff --git a/src/core/hle/kernel/k_condition_variable.cpp b/src/core/hle/kernel/k_condition_variable.cpp
index f0ad8b390..170d8fa0d 100644
--- a/src/core/hle/kernel/k_condition_variable.cpp
+++ b/src/core/hle/kernel/k_condition_variable.cpp
@@ -92,10 +92,10 @@ ResultCode KConditionVariable::SignalToAddress(VAddr addr) {
92 // Write the value to userspace. 92 // Write the value to userspace.
93 if (!WriteToUser(system, addr, std::addressof(next_value))) { 93 if (!WriteToUser(system, addr, std::addressof(next_value))) {
94 if (next_owner_thread) { 94 if (next_owner_thread) {
95 next_owner_thread->SetSyncedObject(nullptr, Svc::ResultInvalidCurrentMemory); 95 next_owner_thread->SetSyncedObject(nullptr, ResultInvalidCurrentMemory);
96 } 96 }
97 97
98 return Svc::ResultInvalidCurrentMemory; 98 return ResultInvalidCurrentMemory;
99 } 99 }
100 } 100 }
101 101
@@ -114,20 +114,20 @@ ResultCode KConditionVariable::WaitForAddress(Handle handle, VAddr addr, u32 val
114 cur_thread->SetSyncedObject(nullptr, RESULT_SUCCESS); 114 cur_thread->SetSyncedObject(nullptr, RESULT_SUCCESS);
115 115
116 // Check if the thread should terminate. 116 // Check if the thread should terminate.
117 R_UNLESS(!cur_thread->IsTerminationRequested(), Svc::ResultTerminationRequested); 117 R_UNLESS(!cur_thread->IsTerminationRequested(), ResultTerminationRequested);
118 118
119 { 119 {
120 // Read the tag from userspace. 120 // Read the tag from userspace.
121 u32 test_tag{}; 121 u32 test_tag{};
122 R_UNLESS(ReadFromUser(system, std::addressof(test_tag), addr), 122 R_UNLESS(ReadFromUser(system, std::addressof(test_tag), addr),
123 Svc::ResultInvalidCurrentMemory); 123 ResultInvalidCurrentMemory);
124 124
125 // If the tag isn't the handle (with wait mask), we're done. 125 // If the tag isn't the handle (with wait mask), we're done.
126 R_UNLESS(test_tag == (handle | Svc::HandleWaitMask), RESULT_SUCCESS); 126 R_UNLESS(test_tag == (handle | Svc::HandleWaitMask), RESULT_SUCCESS);
127 127
128 // Get the lock owner thread. 128 // Get the lock owner thread.
129 owner_thread = kernel.CurrentProcess()->GetHandleTable().Get<KThread>(handle); 129 owner_thread = kernel.CurrentProcess()->GetHandleTable().Get<KThread>(handle);
130 R_UNLESS(owner_thread, Svc::ResultInvalidHandle); 130 R_UNLESS(owner_thread, ResultInvalidHandle);
131 131
132 // Update the lock. 132 // Update the lock.
133 cur_thread->SetAddressKey(addr, value); 133 cur_thread->SetAddressKey(addr, value);
@@ -191,13 +191,13 @@ KThread* KConditionVariable::SignalImpl(KThread* thread) {
191 thread_to_close = owner_thread.get(); 191 thread_to_close = owner_thread.get();
192 } else { 192 } else {
193 // The lock was tagged with a thread that doesn't exist. 193 // The lock was tagged with a thread that doesn't exist.
194 thread->SetSyncedObject(nullptr, Svc::ResultInvalidState); 194 thread->SetSyncedObject(nullptr, ResultInvalidState);
195 thread->Wakeup(); 195 thread->Wakeup();
196 } 196 }
197 } 197 }
198 } else { 198 } else {
199 // If the address wasn't accessible, note so. 199 // If the address wasn't accessible, note so.
200 thread->SetSyncedObject(nullptr, Svc::ResultInvalidCurrentMemory); 200 thread->SetSyncedObject(nullptr, ResultInvalidCurrentMemory);
201 thread->Wakeup(); 201 thread->Wakeup();
202 } 202 }
203 203
@@ -263,12 +263,12 @@ ResultCode KConditionVariable::Wait(VAddr addr, u64 key, u32 value, s64 timeout)
263 KScopedSchedulerLockAndSleep slp{kernel, cur_thread, timeout}; 263 KScopedSchedulerLockAndSleep slp{kernel, cur_thread, timeout};
264 264
265 // Set the synced object. 265 // Set the synced object.
266 cur_thread->SetSyncedObject(nullptr, Svc::ResultTimedOut); 266 cur_thread->SetSyncedObject(nullptr, ResultTimedOut);
267 267
268 // Check that the thread isn't terminating. 268 // Check that the thread isn't terminating.
269 if (cur_thread->IsTerminationRequested()) { 269 if (cur_thread->IsTerminationRequested()) {
270 slp.CancelSleep(); 270 slp.CancelSleep();
271 return Svc::ResultTerminationRequested; 271 return ResultTerminationRequested;
272 } 272 }
273 273
274 // Update the value and process for the next owner. 274 // Update the value and process for the next owner.
@@ -302,7 +302,7 @@ ResultCode KConditionVariable::Wait(VAddr addr, u64 key, u32 value, s64 timeout)
302 // Write the value to userspace. 302 // Write the value to userspace.
303 if (!WriteToUser(system, addr, std::addressof(next_value))) { 303 if (!WriteToUser(system, addr, std::addressof(next_value))) {
304 slp.CancelSleep(); 304 slp.CancelSleep();
305 return Svc::ResultInvalidCurrentMemory; 305 return ResultInvalidCurrentMemory;
306 } 306 }
307 } 307 }
308 308
diff --git a/src/core/hle/kernel/k_readable_event.cpp b/src/core/hle/kernel/k_readable_event.cpp
index d8a42dbaf..4b4d34857 100644
--- a/src/core/hle/kernel/k_readable_event.cpp
+++ b/src/core/hle/kernel/k_readable_event.cpp
@@ -6,7 +6,6 @@
6#include "common/assert.h" 6#include "common/assert.h"
7#include "common/common_funcs.h" 7#include "common/common_funcs.h"
8#include "common/logging/log.h" 8#include "common/logging/log.h"
9#include "core/hle/kernel/errors.h"
10#include "core/hle/kernel/k_readable_event.h" 9#include "core/hle/kernel/k_readable_event.h"
11#include "core/hle/kernel/k_scheduler.h" 10#include "core/hle/kernel/k_scheduler.h"
12#include "core/hle/kernel/k_thread.h" 11#include "core/hle/kernel/k_thread.h"
@@ -47,7 +46,7 @@ ResultCode KReadableEvent::Reset() {
47 KScopedSchedulerLock lk{kernel}; 46 KScopedSchedulerLock lk{kernel};
48 47
49 if (!is_signaled) { 48 if (!is_signaled) {
50 return Svc::ResultInvalidState; 49 return ResultInvalidState;
51 } 50 }
52 51
53 is_signaled = false; 52 is_signaled = false;
diff --git a/src/core/hle/kernel/k_resource_limit.cpp b/src/core/hle/kernel/k_resource_limit.cpp
index ab2ab683f..d7a4a38e6 100644
--- a/src/core/hle/kernel/k_resource_limit.cpp
+++ b/src/core/hle/kernel/k_resource_limit.cpp
@@ -75,7 +75,7 @@ s64 KResourceLimit::GetFreeValue(LimitableResource which) const {
75ResultCode KResourceLimit::SetLimitValue(LimitableResource which, s64 value) { 75ResultCode KResourceLimit::SetLimitValue(LimitableResource which, s64 value) {
76 const auto index = static_cast<std::size_t>(which); 76 const auto index = static_cast<std::size_t>(which);
77 KScopedLightLock lk(lock); 77 KScopedLightLock lk(lock);
78 R_UNLESS(current_values[index] <= value, Svc::ResultInvalidState); 78 R_UNLESS(current_values[index] <= value, ResultInvalidState);
79 79
80 limit_values[index] = value; 80 limit_values[index] = value;
81 81
diff --git a/src/core/hle/kernel/k_synchronization_object.cpp b/src/core/hle/kernel/k_synchronization_object.cpp
index 140cc46a7..82f72a0fe 100644
--- a/src/core/hle/kernel/k_synchronization_object.cpp
+++ b/src/core/hle/kernel/k_synchronization_object.cpp
@@ -40,20 +40,20 @@ ResultCode KSynchronizationObject::Wait(KernelCore& kernel, s32* out_index,
40 // Check if the timeout is zero. 40 // Check if the timeout is zero.
41 if (timeout == 0) { 41 if (timeout == 0) {
42 slp.CancelSleep(); 42 slp.CancelSleep();
43 return Svc::ResultTimedOut; 43 return ResultTimedOut;
44 } 44 }
45 45
46 // Check if the thread should terminate. 46 // Check if the thread should terminate.
47 if (thread->IsTerminationRequested()) { 47 if (thread->IsTerminationRequested()) {
48 slp.CancelSleep(); 48 slp.CancelSleep();
49 return Svc::ResultTerminationRequested; 49 return ResultTerminationRequested;
50 } 50 }
51 51
52 // Check if waiting was canceled. 52 // Check if waiting was canceled.
53 if (thread->IsWaitCancelled()) { 53 if (thread->IsWaitCancelled()) {
54 slp.CancelSleep(); 54 slp.CancelSleep();
55 thread->ClearWaitCancelled(); 55 thread->ClearWaitCancelled();
56 return Svc::ResultCancelled; 56 return ResultCancelled;
57 } 57 }
58 58
59 // Add the waiters. 59 // Add the waiters.
@@ -75,7 +75,7 @@ ResultCode KSynchronizationObject::Wait(KernelCore& kernel, s32* out_index,
75 75
76 // Mark the thread as waiting. 76 // Mark the thread as waiting.
77 thread->SetCancellable(); 77 thread->SetCancellable();
78 thread->SetSyncedObject(nullptr, Svc::ResultTimedOut); 78 thread->SetSyncedObject(nullptr, ResultTimedOut);
79 thread->SetState(ThreadState::Waiting); 79 thread->SetState(ThreadState::Waiting);
80 thread->SetWaitReasonForDebugging(ThreadWaitReasonForDebugging::Synchronization); 80 thread->SetWaitReasonForDebugging(ThreadWaitReasonForDebugging::Synchronization);
81 } 81 }
diff --git a/src/core/hle/kernel/k_thread.cpp b/src/core/hle/kernel/k_thread.cpp
index b59259c4f..e5620da5a 100644
--- a/src/core/hle/kernel/k_thread.cpp
+++ b/src/core/hle/kernel/k_thread.cpp
@@ -18,7 +18,6 @@
18#include "core/core.h" 18#include "core/core.h"
19#include "core/cpu_manager.h" 19#include "core/cpu_manager.h"
20#include "core/hardware_properties.h" 20#include "core/hardware_properties.h"
21#include "core/hle/kernel/errors.h"
22#include "core/hle/kernel/handle_table.h" 21#include "core/hle/kernel/handle_table.h"
23#include "core/hle/kernel/k_condition_variable.h" 22#include "core/hle/kernel/k_condition_variable.h"
24#include "core/hle/kernel/k_resource_limit.h" 23#include "core/hle/kernel/k_resource_limit.h"
@@ -127,7 +126,7 @@ ResultCode KThread::Initialize(KThreadFunction func, uintptr_t arg, VAddr user_s
127 126
128 // Set core ID and wait result. 127 // Set core ID and wait result.
129 core_id = phys_core; 128 core_id = phys_core;
130 wait_result = Svc::ResultNoSynchronizationObject; 129 wait_result = ResultNoSynchronizationObject;
131 130
132 // Set priorities. 131 // Set priorities.
133 priority = prio; 132 priority = prio;
@@ -238,7 +237,7 @@ void KThread::Finalize() {
238 while (it != waiter_list.end()) { 237 while (it != waiter_list.end()) {
239 // The thread shouldn't be a kernel waiter. 238 // The thread shouldn't be a kernel waiter.
240 it->SetLockOwner(nullptr); 239 it->SetLockOwner(nullptr);
241 it->SetSyncedObject(nullptr, Svc::ResultInvalidState); 240 it->SetSyncedObject(nullptr, ResultInvalidState);
242 it->Wakeup(); 241 it->Wakeup();
243 it = waiter_list.erase(it); 242 it = waiter_list.erase(it);
244 } 243 }
@@ -447,7 +446,7 @@ ResultCode KThread::SetCoreMask(s32 core_id, u64 v_affinity_mask) {
447 // If the core id is no-update magic, preserve the ideal core id. 446 // If the core id is no-update magic, preserve the ideal core id.
448 if (core_id == Svc::IdealCoreNoUpdate) { 447 if (core_id == Svc::IdealCoreNoUpdate) {
449 core_id = virtual_ideal_core_id; 448 core_id = virtual_ideal_core_id;
450 R_UNLESS(((1ULL << core_id) & v_affinity_mask) != 0, Svc::ResultInvalidCombination); 449 R_UNLESS(((1ULL << core_id) & v_affinity_mask) != 0, ResultInvalidCombination);
451 } 450 }
452 451
453 // Set the virtual core/affinity mask. 452 // Set the virtual core/affinity mask.
@@ -526,7 +525,7 @@ ResultCode KThread::SetCoreMask(s32 core_id, u64 v_affinity_mask) {
526 if (GetStackParameters().is_pinned) { 525 if (GetStackParameters().is_pinned) {
527 // Verify that the current thread isn't terminating. 526 // Verify that the current thread isn't terminating.
528 R_UNLESS(!GetCurrentThread(kernel).IsTerminationRequested(), 527 R_UNLESS(!GetCurrentThread(kernel).IsTerminationRequested(),
529 Svc::ResultTerminationRequested); 528 ResultTerminationRequested);
530 529
531 // Note that the thread was pinned. 530 // Note that the thread was pinned.
532 thread_is_pinned = true; 531 thread_is_pinned = true;
@@ -604,7 +603,7 @@ void KThread::WaitCancel() {
604 sleeping_queue->WakeupThread(this); 603 sleeping_queue->WakeupThread(this);
605 wait_cancelled = true; 604 wait_cancelled = true;
606 } else { 605 } else {
607 SetSyncedObject(nullptr, Svc::ResultCancelled); 606 SetSyncedObject(nullptr, ResultCancelled);
608 SetState(ThreadState::Runnable); 607 SetState(ThreadState::Runnable);
609 wait_cancelled = false; 608 wait_cancelled = false;
610 } 609 }
@@ -663,12 +662,12 @@ ResultCode KThread::SetActivity(Svc::ThreadActivity activity) {
663 // Verify our state. 662 // Verify our state.
664 const auto cur_state = GetState(); 663 const auto cur_state = GetState();
665 R_UNLESS((cur_state == ThreadState::Waiting || cur_state == ThreadState::Runnable), 664 R_UNLESS((cur_state == ThreadState::Waiting || cur_state == ThreadState::Runnable),
666 Svc::ResultInvalidState); 665 ResultInvalidState);
667 666
668 // Either pause or resume. 667 // Either pause or resume.
669 if (activity == Svc::ThreadActivity::Paused) { 668 if (activity == Svc::ThreadActivity::Paused) {
670 // Verify that we're not suspended. 669 // Verify that we're not suspended.
671 R_UNLESS(!IsSuspendRequested(SuspendType::Thread), Svc::ResultInvalidState); 670 R_UNLESS(!IsSuspendRequested(SuspendType::Thread), ResultInvalidState);
672 671
673 // Suspend. 672 // Suspend.
674 RequestSuspend(SuspendType::Thread); 673 RequestSuspend(SuspendType::Thread);
@@ -676,7 +675,7 @@ ResultCode KThread::SetActivity(Svc::ThreadActivity activity) {
676 ASSERT(activity == Svc::ThreadActivity::Runnable); 675 ASSERT(activity == Svc::ThreadActivity::Runnable);
677 676
678 // Verify that we're suspended. 677 // Verify that we're suspended.
679 R_UNLESS(IsSuspendRequested(SuspendType::Thread), Svc::ResultInvalidState); 678 R_UNLESS(IsSuspendRequested(SuspendType::Thread), ResultInvalidState);
680 679
681 // Resume. 680 // Resume.
682 Resume(SuspendType::Thread); 681 Resume(SuspendType::Thread);
@@ -698,7 +697,7 @@ ResultCode KThread::SetActivity(Svc::ThreadActivity activity) {
698 if (GetStackParameters().is_pinned) { 697 if (GetStackParameters().is_pinned) {
699 // Verify that the current thread isn't terminating. 698 // Verify that the current thread isn't terminating.
700 R_UNLESS(!GetCurrentThread(kernel).IsTerminationRequested(), 699 R_UNLESS(!GetCurrentThread(kernel).IsTerminationRequested(),
701 Svc::ResultTerminationRequested); 700 ResultTerminationRequested);
702 701
703 // Note that the thread was pinned and not current. 702 // Note that the thread was pinned and not current.
704 thread_is_pinned = true; 703 thread_is_pinned = true;
@@ -745,7 +744,7 @@ ResultCode KThread::GetThreadContext3(std::vector<u8>& out) {
745 KScopedSchedulerLock sl{kernel}; 744 KScopedSchedulerLock sl{kernel};
746 745
747 // Verify that we're suspended. 746 // Verify that we're suspended.
748 R_UNLESS(IsSuspendRequested(SuspendType::Thread), Svc::ResultInvalidState); 747 R_UNLESS(IsSuspendRequested(SuspendType::Thread), ResultInvalidState);
749 748
750 // If we're not terminating, get the thread's user context. 749 // If we're not terminating, get the thread's user context.
751 if (!IsTerminationRequested()) { 750 if (!IsTerminationRequested()) {
@@ -905,12 +904,11 @@ ResultCode KThread::Run() {
905 KScopedSchedulerLock lk{kernel}; 904 KScopedSchedulerLock lk{kernel};
906 905
907 // If either this thread or the current thread are requesting termination, note it. 906 // If either this thread or the current thread are requesting termination, note it.
908 R_UNLESS(!IsTerminationRequested(), Svc::ResultTerminationRequested); 907 R_UNLESS(!IsTerminationRequested(), ResultTerminationRequested);
909 R_UNLESS(!GetCurrentThread(kernel).IsTerminationRequested(), 908 R_UNLESS(!GetCurrentThread(kernel).IsTerminationRequested(), ResultTerminationRequested);
910 Svc::ResultTerminationRequested);
911 909
912 // Ensure our thread state is correct. 910 // Ensure our thread state is correct.
913 R_UNLESS(GetState() == ThreadState::Initialized, Svc::ResultInvalidState); 911 R_UNLESS(GetState() == ThreadState::Initialized, ResultInvalidState);
914 912
915 // If the current thread has been asked to suspend, suspend it and retry. 913 // If the current thread has been asked to suspend, suspend it and retry.
916 if (GetCurrentThread(kernel).IsSuspended()) { 914 if (GetCurrentThread(kernel).IsSuspended()) {
@@ -962,7 +960,7 @@ ResultCode KThread::Sleep(s64 timeout) {
962 // Check if the thread should terminate. 960 // Check if the thread should terminate.
963 if (IsTerminationRequested()) { 961 if (IsTerminationRequested()) {
964 slp.CancelSleep(); 962 slp.CancelSleep();
965 return Svc::ResultTerminationRequested; 963 return ResultTerminationRequested;
966 } 964 }
967 965
968 // Mark the thread as waiting. 966 // Mark the thread as waiting.
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp
index b20c2d13a..8da5a5c86 100644
--- a/src/core/hle/kernel/kernel.cpp
+++ b/src/core/hle/kernel/kernel.cpp
@@ -26,7 +26,6 @@
26#include "core/device_memory.h" 26#include "core/device_memory.h"
27#include "core/hardware_properties.h" 27#include "core/hardware_properties.h"
28#include "core/hle/kernel/client_port.h" 28#include "core/hle/kernel/client_port.h"
29#include "core/hle/kernel/errors.h"
30#include "core/hle/kernel/handle_table.h" 29#include "core/hle/kernel/handle_table.h"
31#include "core/hle/kernel/k_resource_limit.h" 30#include "core/hle/kernel/k_resource_limit.h"
32#include "core/hle/kernel/k_scheduler.h" 31#include "core/hle/kernel/k_scheduler.h"
@@ -39,6 +38,7 @@
39#include "core/hle/kernel/process.h" 38#include "core/hle/kernel/process.h"
40#include "core/hle/kernel/service_thread.h" 39#include "core/hle/kernel/service_thread.h"
41#include "core/hle/kernel/shared_memory.h" 40#include "core/hle/kernel/shared_memory.h"
41#include "core/hle/kernel/svc_results.h"
42#include "core/hle/kernel/time_manager.h" 42#include "core/hle/kernel/time_manager.h"
43#include "core/hle/lock.h" 43#include "core/hle/lock.h"
44#include "core/hle/result.h" 44#include "core/hle/result.h"
diff --git a/src/core/hle/kernel/memory/memory_manager.cpp b/src/core/hle/kernel/memory/memory_manager.cpp
index acf13585c..77f135cdc 100644
--- a/src/core/hle/kernel/memory/memory_manager.cpp
+++ b/src/core/hle/kernel/memory/memory_manager.cpp
@@ -8,9 +8,9 @@
8#include "common/assert.h" 8#include "common/assert.h"
9#include "common/common_types.h" 9#include "common/common_types.h"
10#include "common/scope_exit.h" 10#include "common/scope_exit.h"
11#include "core/hle/kernel/errors.h"
12#include "core/hle/kernel/memory/memory_manager.h" 11#include "core/hle/kernel/memory/memory_manager.h"
13#include "core/hle/kernel/memory/page_linked_list.h" 12#include "core/hle/kernel/memory/page_linked_list.h"
13#include "core/hle/kernel/svc_results.h"
14 14
15namespace Kernel::Memory { 15namespace Kernel::Memory {
16 16
@@ -95,7 +95,7 @@ ResultCode MemoryManager::Allocate(PageLinkedList& page_list, std::size_t num_pa
95 // Choose a heap based on our page size request 95 // Choose a heap based on our page size request
96 const s32 heap_index{PageHeap::GetBlockIndex(num_pages)}; 96 const s32 heap_index{PageHeap::GetBlockIndex(num_pages)};
97 if (heap_index < 0) { 97 if (heap_index < 0) {
98 return ERR_OUT_OF_MEMORY; 98 return ResultOutOfMemory;
99 } 99 }
100 100
101 // TODO (bunnei): Support multiple managers 101 // TODO (bunnei): Support multiple managers
@@ -140,7 +140,7 @@ ResultCode MemoryManager::Allocate(PageLinkedList& page_list, std::size_t num_pa
140 140
141 // Only succeed if we allocated as many pages as we wanted 141 // Only succeed if we allocated as many pages as we wanted
142 if (num_pages) { 142 if (num_pages) {
143 return ERR_OUT_OF_MEMORY; 143 return ResultOutOfMemory;
144 } 144 }
145 145
146 // We succeeded! 146 // We succeeded!
diff --git a/src/core/hle/kernel/memory/page_table.cpp b/src/core/hle/kernel/memory/page_table.cpp
index 7de91c768..5947fc748 100644
--- a/src/core/hle/kernel/memory/page_table.cpp
+++ b/src/core/hle/kernel/memory/page_table.cpp
@@ -6,7 +6,6 @@
6#include "common/assert.h" 6#include "common/assert.h"
7#include "common/scope_exit.h" 7#include "common/scope_exit.h"
8#include "core/core.h" 8#include "core/core.h"
9#include "core/hle/kernel/errors.h"
10#include "core/hle/kernel/k_resource_limit.h" 9#include "core/hle/kernel/k_resource_limit.h"
11#include "core/hle/kernel/kernel.h" 10#include "core/hle/kernel/kernel.h"
12#include "core/hle/kernel/memory/address_space_info.h" 11#include "core/hle/kernel/memory/address_space_info.h"
@@ -16,6 +15,7 @@
16#include "core/hle/kernel/memory/page_table.h" 15#include "core/hle/kernel/memory/page_table.h"
17#include "core/hle/kernel/memory/system_control.h" 16#include "core/hle/kernel/memory/system_control.h"
18#include "core/hle/kernel/process.h" 17#include "core/hle/kernel/process.h"
18#include "core/hle/kernel/svc_results.h"
19#include "core/memory.h" 19#include "core/memory.h"
20 20
21namespace Kernel::Memory { 21namespace Kernel::Memory {
@@ -141,7 +141,7 @@ ResultCode PageTable::InitializeForProcess(FileSys::ProgramAddressSpaceType as_t
141 (alias_region_size + heap_region_size + stack_region_size + kernel_map_region_size)}; 141 (alias_region_size + heap_region_size + stack_region_size + kernel_map_region_size)};
142 if (alloc_size < needed_size) { 142 if (alloc_size < needed_size) {
143 UNREACHABLE(); 143 UNREACHABLE();
144 return ERR_OUT_OF_MEMORY; 144 return ResultOutOfMemory;
145 } 145 }
146 146
147 const std::size_t remaining_size{alloc_size - needed_size}; 147 const std::size_t remaining_size{alloc_size - needed_size};
@@ -277,11 +277,11 @@ ResultCode PageTable::MapProcessCode(VAddr addr, std::size_t num_pages, MemorySt
277 const u64 size{num_pages * PageSize}; 277 const u64 size{num_pages * PageSize};
278 278
279 if (!CanContain(addr, size, state)) { 279 if (!CanContain(addr, size, state)) {
280 return ERR_INVALID_ADDRESS_STATE; 280 return ResultInvalidCurrentMemory;
281 } 281 }
282 282
283 if (IsRegionMapped(addr, size)) { 283 if (IsRegionMapped(addr, size)) {
284 return ERR_INVALID_ADDRESS_STATE; 284 return ResultInvalidCurrentMemory;
285 } 285 }
286 286
287 PageLinkedList page_linked_list; 287 PageLinkedList page_linked_list;
@@ -307,7 +307,7 @@ ResultCode PageTable::MapProcessCodeMemory(VAddr dst_addr, VAddr src_addr, std::
307 MemoryAttribute::None, MemoryAttribute::IpcAndDeviceMapped)); 307 MemoryAttribute::None, MemoryAttribute::IpcAndDeviceMapped));
308 308
309 if (IsRegionMapped(dst_addr, size)) { 309 if (IsRegionMapped(dst_addr, size)) {
310 return ERR_INVALID_ADDRESS_STATE; 310 return ResultInvalidCurrentMemory;
311 } 311 }
312 312
313 PageLinkedList page_linked_list; 313 PageLinkedList page_linked_list;
@@ -415,7 +415,7 @@ ResultCode PageTable::MapPhysicalMemory(VAddr addr, std::size_t size) {
415 415
416 if (process->GetResourceLimit() && 416 if (process->GetResourceLimit() &&
417 !process->GetResourceLimit()->Reserve(LimitableResource::PhysicalMemory, remaining_size)) { 417 !process->GetResourceLimit()->Reserve(LimitableResource::PhysicalMemory, remaining_size)) {
418 return ERR_RESOURCE_LIMIT_EXCEEDED; 418 return ResultResourceLimitedExceeded;
419 } 419 }
420 420
421 PageLinkedList page_linked_list; 421 PageLinkedList page_linked_list;
@@ -454,12 +454,12 @@ ResultCode PageTable::UnmapPhysicalMemory(VAddr addr, std::size_t size) {
454 block_manager->IterateForRange(addr, end_addr, [&](const MemoryInfo& info) { 454 block_manager->IterateForRange(addr, end_addr, [&](const MemoryInfo& info) {
455 if (info.state == MemoryState::Normal) { 455 if (info.state == MemoryState::Normal) {
456 if (info.attribute != MemoryAttribute::None) { 456 if (info.attribute != MemoryAttribute::None) {
457 result = ERR_INVALID_ADDRESS_STATE; 457 result = ResultInvalidCurrentMemory;
458 return; 458 return;
459 } 459 }
460 mapped_size += GetSizeInRange(info, addr, end_addr); 460 mapped_size += GetSizeInRange(info, addr, end_addr);
461 } else if (info.state != MemoryState::Free) { 461 } else if (info.state != MemoryState::Free) {
462 result = ERR_INVALID_ADDRESS_STATE; 462 result = ResultInvalidCurrentMemory;
463 } 463 }
464 }); 464 });
465 465
@@ -526,7 +526,7 @@ ResultCode PageTable::Map(VAddr dst_addr, VAddr src_addr, std::size_t size) {
526 MemoryAttribute::Mask, MemoryAttribute::None, MemoryAttribute::IpcAndDeviceMapped)); 526 MemoryAttribute::Mask, MemoryAttribute::None, MemoryAttribute::IpcAndDeviceMapped));
527 527
528 if (IsRegionMapped(dst_addr, size)) { 528 if (IsRegionMapped(dst_addr, size)) {
529 return ERR_INVALID_ADDRESS_STATE; 529 return ResultInvalidCurrentMemory;
530 } 530 }
531 531
532 PageLinkedList page_linked_list; 532 PageLinkedList page_linked_list;
@@ -577,7 +577,7 @@ ResultCode PageTable::Unmap(VAddr dst_addr, VAddr src_addr, std::size_t size) {
577 AddRegionToPages(dst_addr, num_pages, dst_pages); 577 AddRegionToPages(dst_addr, num_pages, dst_pages);
578 578
579 if (!dst_pages.IsEqual(src_pages)) { 579 if (!dst_pages.IsEqual(src_pages)) {
580 return ERR_INVALID_MEMORY_RANGE; 580 return ResultInvalidMemoryRange;
581 } 581 }
582 582
583 { 583 {
@@ -626,11 +626,11 @@ ResultCode PageTable::MapPages(VAddr addr, PageLinkedList& page_linked_list, Mem
626 const std::size_t size{num_pages * PageSize}; 626 const std::size_t size{num_pages * PageSize};
627 627
628 if (!CanContain(addr, size, state)) { 628 if (!CanContain(addr, size, state)) {
629 return ERR_INVALID_ADDRESS_STATE; 629 return ResultInvalidCurrentMemory;
630 } 630 }
631 631
632 if (IsRegionMapped(addr, num_pages * PageSize)) { 632 if (IsRegionMapped(addr, num_pages * PageSize)) {
633 return ERR_INVALID_ADDRESS_STATE; 633 return ResultInvalidCurrentMemory;
634 } 634 }
635 635
636 CASCADE_CODE(MapPages(addr, page_linked_list, perm)); 636 CASCADE_CODE(MapPages(addr, page_linked_list, perm));
@@ -768,7 +768,7 @@ ResultCode PageTable::SetHeapCapacity(std::size_t new_heap_capacity) {
768ResultVal<VAddr> PageTable::SetHeapSize(std::size_t size) { 768ResultVal<VAddr> PageTable::SetHeapSize(std::size_t size) {
769 769
770 if (size > heap_region_end - heap_region_start) { 770 if (size > heap_region_end - heap_region_start) {
771 return ERR_OUT_OF_MEMORY; 771 return ResultOutOfMemory;
772 } 772 }
773 773
774 const u64 previous_heap_size{GetHeapSize()}; 774 const u64 previous_heap_size{GetHeapSize()};
@@ -784,7 +784,7 @@ ResultVal<VAddr> PageTable::SetHeapSize(std::size_t size) {
784 auto process{system.Kernel().CurrentProcess()}; 784 auto process{system.Kernel().CurrentProcess()};
785 if (process->GetResourceLimit() && delta != 0 && 785 if (process->GetResourceLimit() && delta != 0 &&
786 !process->GetResourceLimit()->Reserve(LimitableResource::PhysicalMemory, delta)) { 786 !process->GetResourceLimit()->Reserve(LimitableResource::PhysicalMemory, delta)) {
787 return ERR_RESOURCE_LIMIT_EXCEEDED; 787 return ResultResourceLimitedExceeded;
788 } 788 }
789 789
790 PageLinkedList page_linked_list; 790 PageLinkedList page_linked_list;
@@ -794,7 +794,7 @@ ResultVal<VAddr> PageTable::SetHeapSize(std::size_t size) {
794 system.Kernel().MemoryManager().Allocate(page_linked_list, num_pages, memory_pool)); 794 system.Kernel().MemoryManager().Allocate(page_linked_list, num_pages, memory_pool));
795 795
796 if (IsRegionMapped(current_heap_addr, delta)) { 796 if (IsRegionMapped(current_heap_addr, delta)) {
797 return ERR_INVALID_ADDRESS_STATE; 797 return ResultInvalidCurrentMemory;
798 } 798 }
799 799
800 CASCADE_CODE( 800 CASCADE_CODE(
@@ -816,17 +816,17 @@ ResultVal<VAddr> PageTable::AllocateAndMapMemory(std::size_t needed_num_pages, s
816 std::lock_guard lock{page_table_lock}; 816 std::lock_guard lock{page_table_lock};
817 817
818 if (!CanContain(region_start, region_num_pages * PageSize, state)) { 818 if (!CanContain(region_start, region_num_pages * PageSize, state)) {
819 return ERR_INVALID_ADDRESS_STATE; 819 return ResultInvalidCurrentMemory;
820 } 820 }
821 821
822 if (region_num_pages <= needed_num_pages) { 822 if (region_num_pages <= needed_num_pages) {
823 return ERR_OUT_OF_MEMORY; 823 return ResultOutOfMemory;
824 } 824 }
825 825
826 const VAddr addr{ 826 const VAddr addr{
827 AllocateVirtualMemory(region_start, region_num_pages, needed_num_pages, align)}; 827 AllocateVirtualMemory(region_start, region_num_pages, needed_num_pages, align)};
828 if (!addr) { 828 if (!addr) {
829 return ERR_OUT_OF_MEMORY; 829 return ResultOutOfMemory;
830 } 830 }
831 831
832 if (is_map_only) { 832 if (is_map_only) {
@@ -1105,13 +1105,13 @@ constexpr ResultCode PageTable::CheckMemoryState(const MemoryInfo& info, MemoryS
1105 MemoryAttribute attr) const { 1105 MemoryAttribute attr) const {
1106 // Validate the states match expectation 1106 // Validate the states match expectation
1107 if ((info.state & state_mask) != state) { 1107 if ((info.state & state_mask) != state) {
1108 return ERR_INVALID_ADDRESS_STATE; 1108 return ResultInvalidCurrentMemory;
1109 } 1109 }
1110 if ((info.perm & perm_mask) != perm) { 1110 if ((info.perm & perm_mask) != perm) {
1111 return ERR_INVALID_ADDRESS_STATE; 1111 return ResultInvalidCurrentMemory;
1112 } 1112 }
1113 if ((info.attribute & attr_mask) != attr) { 1113 if ((info.attribute & attr_mask) != attr) {
1114 return ERR_INVALID_ADDRESS_STATE; 1114 return ResultInvalidCurrentMemory;
1115 } 1115 }
1116 1116
1117 return RESULT_SUCCESS; 1117 return RESULT_SUCCESS;
@@ -1138,14 +1138,14 @@ ResultCode PageTable::CheckMemoryState(MemoryState* out_state, MemoryPermission*
1138 while (true) { 1138 while (true) {
1139 // Validate the current block 1139 // Validate the current block
1140 if (!(info.state == first_state)) { 1140 if (!(info.state == first_state)) {
1141 return ERR_INVALID_ADDRESS_STATE; 1141 return ResultInvalidCurrentMemory;
1142 } 1142 }
1143 if (!(info.perm == first_perm)) { 1143 if (!(info.perm == first_perm)) {
1144 return ERR_INVALID_ADDRESS_STATE; 1144 return ResultInvalidCurrentMemory;
1145 } 1145 }
1146 if (!((info.attribute | static_cast<MemoryAttribute>(ignore_attr)) == 1146 if (!((info.attribute | static_cast<MemoryAttribute>(ignore_attr)) ==
1147 (first_attr | static_cast<MemoryAttribute>(ignore_attr)))) { 1147 (first_attr | static_cast<MemoryAttribute>(ignore_attr)))) {
1148 return ERR_INVALID_ADDRESS_STATE; 1148 return ResultInvalidCurrentMemory;
1149 } 1149 }
1150 1150
1151 // Validate against the provided masks 1151 // Validate against the provided masks
diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp
index 2286b292d..39dc3898a 100644
--- a/src/core/hle/kernel/process.cpp
+++ b/src/core/hle/kernel/process.cpp
@@ -14,7 +14,6 @@
14#include "core/device_memory.h" 14#include "core/device_memory.h"
15#include "core/file_sys/program_metadata.h" 15#include "core/file_sys/program_metadata.h"
16#include "core/hle/kernel/code_set.h" 16#include "core/hle/kernel/code_set.h"
17#include "core/hle/kernel/errors.h"
18#include "core/hle/kernel/k_resource_limit.h" 17#include "core/hle/kernel/k_resource_limit.h"
19#include "core/hle/kernel/k_scheduler.h" 18#include "core/hle/kernel/k_scheduler.h"
20#include "core/hle/kernel/k_thread.h" 19#include "core/hle/kernel/k_thread.h"
@@ -248,8 +247,8 @@ ResultCode Process::Reset() {
248 KScopedSchedulerLock sl{kernel}; 247 KScopedSchedulerLock sl{kernel};
249 248
250 // Validate that we're in a state that we can reset. 249 // Validate that we're in a state that we can reset.
251 R_UNLESS(status != ProcessStatus::Exited, Svc::ResultInvalidState); 250 R_UNLESS(status != ProcessStatus::Exited, ResultInvalidState);
252 R_UNLESS(is_signaled, Svc::ResultInvalidState); 251 R_UNLESS(is_signaled, ResultInvalidState);
253 252
254 // Clear signaled. 253 // Clear signaled.
255 is_signaled = false; 254 is_signaled = false;
diff --git a/src/core/hle/kernel/process_capability.cpp b/src/core/hle/kernel/process_capability.cpp
index 0566311b6..7c567049e 100644
--- a/src/core/hle/kernel/process_capability.cpp
+++ b/src/core/hle/kernel/process_capability.cpp
@@ -6,10 +6,10 @@
6 6
7#include "common/bit_util.h" 7#include "common/bit_util.h"
8#include "common/logging/log.h" 8#include "common/logging/log.h"
9#include "core/hle/kernel/errors.h"
10#include "core/hle/kernel/handle_table.h" 9#include "core/hle/kernel/handle_table.h"
11#include "core/hle/kernel/memory/page_table.h" 10#include "core/hle/kernel/memory/page_table.h"
12#include "core/hle/kernel/process_capability.h" 11#include "core/hle/kernel/process_capability.h"
12#include "core/hle/kernel/svc_results.h"
13 13
14namespace Kernel { 14namespace Kernel {
15namespace { 15namespace {
@@ -123,13 +123,13 @@ ResultCode ProcessCapabilities::ParseCapabilities(const u32* capabilities,
123 // If there's only one, then there's a problem. 123 // If there's only one, then there's a problem.
124 if (i >= num_capabilities) { 124 if (i >= num_capabilities) {
125 LOG_ERROR(Kernel, "Invalid combination! i={}", i); 125 LOG_ERROR(Kernel, "Invalid combination! i={}", i);
126 return ERR_INVALID_COMBINATION; 126 return ResultInvalidCombination;
127 } 127 }
128 128
129 const auto size_flags = capabilities[i]; 129 const auto size_flags = capabilities[i];
130 if (GetCapabilityType(size_flags) != CapabilityType::MapPhysical) { 130 if (GetCapabilityType(size_flags) != CapabilityType::MapPhysical) {
131 LOG_ERROR(Kernel, "Invalid capability type! size_flags={}", size_flags); 131 LOG_ERROR(Kernel, "Invalid capability type! size_flags={}", size_flags);
132 return ERR_INVALID_COMBINATION; 132 return ResultInvalidCombination;
133 } 133 }
134 134
135 const auto result = HandleMapPhysicalFlags(descriptor, size_flags, page_table); 135 const auto result = HandleMapPhysicalFlags(descriptor, size_flags, page_table);
@@ -159,7 +159,7 @@ ResultCode ProcessCapabilities::ParseSingleFlagCapability(u32& set_flags, u32& s
159 const auto type = GetCapabilityType(flag); 159 const auto type = GetCapabilityType(flag);
160 160
161 if (type == CapabilityType::Unset) { 161 if (type == CapabilityType::Unset) {
162 return ERR_INVALID_CAPABILITY_DESCRIPTOR; 162 return ResultInvalidCapabilityDescriptor;
163 } 163 }
164 164
165 // Bail early on ignorable entries, as one would expect, 165 // Bail early on ignorable entries, as one would expect,
@@ -176,7 +176,7 @@ ResultCode ProcessCapabilities::ParseSingleFlagCapability(u32& set_flags, u32& s
176 LOG_ERROR(Kernel, 176 LOG_ERROR(Kernel,
177 "Attempted to initialize flags that may only be initialized once. set_flags={}", 177 "Attempted to initialize flags that may only be initialized once. set_flags={}",
178 set_flags); 178 set_flags);
179 return ERR_INVALID_COMBINATION; 179 return ResultInvalidCombination;
180 } 180 }
181 set_flags |= set_flag; 181 set_flags |= set_flag;
182 182
@@ -202,7 +202,7 @@ ResultCode ProcessCapabilities::ParseSingleFlagCapability(u32& set_flags, u32& s
202 } 202 }
203 203
204 LOG_ERROR(Kernel, "Invalid capability type! type={}", type); 204 LOG_ERROR(Kernel, "Invalid capability type! type={}", type);
205 return ERR_INVALID_CAPABILITY_DESCRIPTOR; 205 return ResultInvalidCapabilityDescriptor;
206} 206}
207 207
208void ProcessCapabilities::Clear() { 208void ProcessCapabilities::Clear() {
@@ -225,7 +225,7 @@ ResultCode ProcessCapabilities::HandlePriorityCoreNumFlags(u32 flags) {
225 if (priority_mask != 0 || core_mask != 0) { 225 if (priority_mask != 0 || core_mask != 0) {
226 LOG_ERROR(Kernel, "Core or priority mask are not zero! priority_mask={}, core_mask={}", 226 LOG_ERROR(Kernel, "Core or priority mask are not zero! priority_mask={}, core_mask={}",
227 priority_mask, core_mask); 227 priority_mask, core_mask);
228 return ERR_INVALID_CAPABILITY_DESCRIPTOR; 228 return ResultInvalidCapabilityDescriptor;
229 } 229 }
230 230
231 const u32 core_num_min = (flags >> 16) & 0xFF; 231 const u32 core_num_min = (flags >> 16) & 0xFF;
@@ -233,7 +233,7 @@ ResultCode ProcessCapabilities::HandlePriorityCoreNumFlags(u32 flags) {
233 if (core_num_min > core_num_max) { 233 if (core_num_min > core_num_max) {
234 LOG_ERROR(Kernel, "Core min is greater than core max! core_num_min={}, core_num_max={}", 234 LOG_ERROR(Kernel, "Core min is greater than core max! core_num_min={}, core_num_max={}",
235 core_num_min, core_num_max); 235 core_num_min, core_num_max);
236 return ERR_INVALID_COMBINATION; 236 return ResultInvalidCombination;
237 } 237 }
238 238
239 const u32 priority_min = (flags >> 10) & 0x3F; 239 const u32 priority_min = (flags >> 10) & 0x3F;
@@ -242,13 +242,13 @@ ResultCode ProcessCapabilities::HandlePriorityCoreNumFlags(u32 flags) {
242 LOG_ERROR(Kernel, 242 LOG_ERROR(Kernel,
243 "Priority min is greater than priority max! priority_min={}, priority_max={}", 243 "Priority min is greater than priority max! priority_min={}, priority_max={}",
244 core_num_min, priority_max); 244 core_num_min, priority_max);
245 return ERR_INVALID_COMBINATION; 245 return ResultInvalidCombination;
246 } 246 }
247 247
248 // The switch only has 4 usable cores. 248 // The switch only has 4 usable cores.
249 if (core_num_max >= 4) { 249 if (core_num_max >= 4) {
250 LOG_ERROR(Kernel, "Invalid max cores specified! core_num_max={}", core_num_max); 250 LOG_ERROR(Kernel, "Invalid max cores specified! core_num_max={}", core_num_max);
251 return ERR_INVALID_PROCESSOR_ID; 251 return ResultInvalidCoreId;
252 } 252 }
253 253
254 const auto make_mask = [](u64 min, u64 max) { 254 const auto make_mask = [](u64 min, u64 max) {
@@ -269,7 +269,7 @@ ResultCode ProcessCapabilities::HandleSyscallFlags(u32& set_svc_bits, u32 flags)
269 269
270 // If we've already set this svc before, bail. 270 // If we've already set this svc before, bail.
271 if ((set_svc_bits & svc_bit) != 0) { 271 if ((set_svc_bits & svc_bit) != 0) {
272 return ERR_INVALID_COMBINATION; 272 return ResultInvalidCombination;
273 } 273 }
274 set_svc_bits |= svc_bit; 274 set_svc_bits |= svc_bit;
275 275
@@ -283,7 +283,7 @@ ResultCode ProcessCapabilities::HandleSyscallFlags(u32& set_svc_bits, u32 flags)
283 283
284 if (svc_number >= svc_capabilities.size()) { 284 if (svc_number >= svc_capabilities.size()) {
285 LOG_ERROR(Kernel, "Process svc capability is out of range! svc_number={}", svc_number); 285 LOG_ERROR(Kernel, "Process svc capability is out of range! svc_number={}", svc_number);
286 return ERR_OUT_OF_RANGE; 286 return ResultOutOfRange;
287 } 287 }
288 288
289 svc_capabilities[svc_number] = true; 289 svc_capabilities[svc_number] = true;
@@ -321,7 +321,7 @@ ResultCode ProcessCapabilities::HandleInterruptFlags(u32 flags) {
321 if (interrupt >= interrupt_capabilities.size()) { 321 if (interrupt >= interrupt_capabilities.size()) {
322 LOG_ERROR(Kernel, "Process interrupt capability is out of range! svc_number={}", 322 LOG_ERROR(Kernel, "Process interrupt capability is out of range! svc_number={}",
323 interrupt); 323 interrupt);
324 return ERR_OUT_OF_RANGE; 324 return ResultOutOfRange;
325 } 325 }
326 326
327 interrupt_capabilities[interrupt] = true; 327 interrupt_capabilities[interrupt] = true;
@@ -334,7 +334,7 @@ ResultCode ProcessCapabilities::HandleProgramTypeFlags(u32 flags) {
334 const u32 reserved = flags >> 17; 334 const u32 reserved = flags >> 17;
335 if (reserved != 0) { 335 if (reserved != 0) {
336 LOG_ERROR(Kernel, "Reserved value is non-zero! reserved={}", reserved); 336 LOG_ERROR(Kernel, "Reserved value is non-zero! reserved={}", reserved);
337 return ERR_RESERVED_VALUE; 337 return ResultReservedValue;
338 } 338 }
339 339
340 program_type = static_cast<ProgramType>((flags >> 14) & 0b111); 340 program_type = static_cast<ProgramType>((flags >> 14) & 0b111);
@@ -354,7 +354,7 @@ ResultCode ProcessCapabilities::HandleKernelVersionFlags(u32 flags) {
354 LOG_ERROR(Kernel, 354 LOG_ERROR(Kernel,
355 "Kernel version is non zero or flags are too small! major_version={}, flags={}", 355 "Kernel version is non zero or flags are too small! major_version={}, flags={}",
356 major_version, flags); 356 major_version, flags);
357 return ERR_INVALID_CAPABILITY_DESCRIPTOR; 357 return ResultInvalidCapabilityDescriptor;
358 } 358 }
359 359
360 kernel_version = flags; 360 kernel_version = flags;
@@ -365,7 +365,7 @@ ResultCode ProcessCapabilities::HandleHandleTableFlags(u32 flags) {
365 const u32 reserved = flags >> 26; 365 const u32 reserved = flags >> 26;
366 if (reserved != 0) { 366 if (reserved != 0) {
367 LOG_ERROR(Kernel, "Reserved value is non-zero! reserved={}", reserved); 367 LOG_ERROR(Kernel, "Reserved value is non-zero! reserved={}", reserved);
368 return ERR_RESERVED_VALUE; 368 return ResultReservedValue;
369 } 369 }
370 370
371 handle_table_size = static_cast<s32>((flags >> 16) & 0x3FF); 371 handle_table_size = static_cast<s32>((flags >> 16) & 0x3FF);
@@ -376,7 +376,7 @@ ResultCode ProcessCapabilities::HandleDebugFlags(u32 flags) {
376 const u32 reserved = flags >> 19; 376 const u32 reserved = flags >> 19;
377 if (reserved != 0) { 377 if (reserved != 0) {
378 LOG_ERROR(Kernel, "Reserved value is non-zero! reserved={}", reserved); 378 LOG_ERROR(Kernel, "Reserved value is non-zero! reserved={}", reserved);
379 return ERR_RESERVED_VALUE; 379 return ResultReservedValue;
380 } 380 }
381 381
382 is_debuggable = (flags & 0x20000) != 0; 382 is_debuggable = (flags & 0x20000) != 0;
diff --git a/src/core/hle/kernel/server_port.cpp b/src/core/hle/kernel/server_port.cpp
index fe7a483c4..5d17346ad 100644
--- a/src/core/hle/kernel/server_port.cpp
+++ b/src/core/hle/kernel/server_port.cpp
@@ -5,11 +5,11 @@
5#include <tuple> 5#include <tuple>
6#include "common/assert.h" 6#include "common/assert.h"
7#include "core/hle/kernel/client_port.h" 7#include "core/hle/kernel/client_port.h"
8#include "core/hle/kernel/errors.h"
9#include "core/hle/kernel/k_thread.h" 8#include "core/hle/kernel/k_thread.h"
10#include "core/hle/kernel/object.h" 9#include "core/hle/kernel/object.h"
11#include "core/hle/kernel/server_port.h" 10#include "core/hle/kernel/server_port.h"
12#include "core/hle/kernel/server_session.h" 11#include "core/hle/kernel/server_session.h"
12#include "core/hle/kernel/svc_results.h"
13 13
14namespace Kernel { 14namespace Kernel {
15 15
@@ -18,7 +18,7 @@ ServerPort::~ServerPort() = default;
18 18
19ResultVal<std::shared_ptr<ServerSession>> ServerPort::Accept() { 19ResultVal<std::shared_ptr<ServerSession>> ServerPort::Accept() {
20 if (pending_sessions.empty()) { 20 if (pending_sessions.empty()) {
21 return ERR_NOT_FOUND; 21 return ResultNotFound;
22 } 22 }
23 23
24 auto session = std::move(pending_sessions.back()); 24 auto session = std::move(pending_sessions.back());
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index 26650a513..4ef3c7ac5 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -23,7 +23,6 @@
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
421static ResultCode GetProcessId32(Core::System& system, u32* process_id_low, u32* process_id_high, 420static 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
1850static ResultCode ResetSignal32(Core::System& system, Handle handle) { 1851static 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
2049static ResultCode ClearEvent32(Core::System& system, Handle event_handle) { 2049static 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();
diff --git a/src/core/hle/kernel/svc_results.h b/src/core/hle/kernel/svc_results.h
index 204cd989d..a26d9f2c9 100644
--- a/src/core/hle/kernel/svc_results.h
+++ b/src/core/hle/kernel/svc_results.h
@@ -1,4 +1,4 @@
1// Copyright 2020 yuzu emulator team 1// Copyright 2018 yuzu emulator team
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
@@ -6,21 +6,36 @@
6 6
7#include "core/hle/result.h" 7#include "core/hle/result.h"
8 8
9namespace Kernel::Svc { 9namespace Kernel {
10 10
11// Confirmed Switch kernel error codes
12
13constexpr ResultCode ResultMaxConnectionsReached{ErrorModule::Kernel, 7};
14constexpr ResultCode ResultInvalidCapabilityDescriptor{ErrorModule::Kernel, 14};
11constexpr ResultCode ResultNoSynchronizationObject{ErrorModule::Kernel, 57}; 15constexpr ResultCode ResultNoSynchronizationObject{ErrorModule::Kernel, 57};
12constexpr ResultCode ResultTerminationRequested{ErrorModule::Kernel, 59}; 16constexpr ResultCode ResultTerminationRequested{ErrorModule::Kernel, 59};
17constexpr ResultCode ResultInvalidSize{ErrorModule::Kernel, 101};
13constexpr ResultCode ResultInvalidAddress{ErrorModule::Kernel, 102}; 18constexpr ResultCode ResultInvalidAddress{ErrorModule::Kernel, 102};
14constexpr ResultCode ResultOutOfResource{ErrorModule::Kernel, 103}; 19constexpr ResultCode ResultOutOfResource{ErrorModule::Kernel, 103};
20constexpr ResultCode ResultOutOfMemory{ErrorModule::Kernel, 104};
21constexpr ResultCode ResultHandleTableFull{ErrorModule::Kernel, 105};
15constexpr ResultCode ResultInvalidCurrentMemory{ErrorModule::Kernel, 106}; 22constexpr ResultCode ResultInvalidCurrentMemory{ErrorModule::Kernel, 106};
23constexpr ResultCode ResultInvalidMemoryPermissions{ErrorModule::Kernel, 108};
24constexpr ResultCode ResultInvalidMemoryRange{ErrorModule::Kernel, 110};
16constexpr ResultCode ResultInvalidPriority{ErrorModule::Kernel, 112}; 25constexpr ResultCode ResultInvalidPriority{ErrorModule::Kernel, 112};
17constexpr ResultCode ResultInvalidCoreId{ErrorModule::Kernel, 113}; 26constexpr ResultCode ResultInvalidCoreId{ErrorModule::Kernel, 113};
18constexpr ResultCode ResultInvalidHandle{ErrorModule::Kernel, 114}; 27constexpr ResultCode ResultInvalidHandle{ErrorModule::Kernel, 114};
28constexpr ResultCode ResultInvalidPointer{ErrorModule::Kernel, 115};
19constexpr ResultCode ResultInvalidCombination{ErrorModule::Kernel, 116}; 29constexpr ResultCode ResultInvalidCombination{ErrorModule::Kernel, 116};
20constexpr ResultCode ResultTimedOut{ErrorModule::Kernel, 117}; 30constexpr ResultCode ResultTimedOut{ErrorModule::Kernel, 117};
21constexpr ResultCode ResultCancelled{ErrorModule::Kernel, 118}; 31constexpr ResultCode ResultCancelled{ErrorModule::Kernel, 118};
32constexpr ResultCode ResultOutOfRange{ErrorModule::Kernel, 119};
22constexpr ResultCode ResultInvalidEnumValue{ErrorModule::Kernel, 120}; 33constexpr ResultCode ResultInvalidEnumValue{ErrorModule::Kernel, 120};
34constexpr ResultCode ResultNotFound{ErrorModule::Kernel, 121};
23constexpr ResultCode ResultBusy{ErrorModule::Kernel, 122}; 35constexpr ResultCode ResultBusy{ErrorModule::Kernel, 122};
36constexpr ResultCode ResultSessionClosedByRemote{ErrorModule::Kernel, 123};
24constexpr ResultCode ResultInvalidState{ErrorModule::Kernel, 125}; 37constexpr ResultCode ResultInvalidState{ErrorModule::Kernel, 125};
38constexpr ResultCode ResultReservedValue{ErrorModule::Kernel, 126};
39constexpr ResultCode ResultResourceLimitedExceeded{ErrorModule::Kernel, 132};
25 40
26} // namespace Kernel::Svc 41} // namespace Kernel
diff --git a/src/core/hle/service/ldr/ldr.cpp b/src/core/hle/service/ldr/ldr.cpp
index 9da786b4e..c724d2554 100644
--- a/src/core/hle/service/ldr/ldr.cpp
+++ b/src/core/hle/service/ldr/ldr.cpp
@@ -11,10 +11,10 @@
11#include "common/scope_exit.h" 11#include "common/scope_exit.h"
12#include "core/core.h" 12#include "core/core.h"
13#include "core/hle/ipc_helpers.h" 13#include "core/hle/ipc_helpers.h"
14#include "core/hle/kernel/errors.h"
15#include "core/hle/kernel/memory/page_table.h" 14#include "core/hle/kernel/memory/page_table.h"
16#include "core/hle/kernel/memory/system_control.h" 15#include "core/hle/kernel/memory/system_control.h"
17#include "core/hle/kernel/process.h" 16#include "core/hle/kernel/process.h"
17#include "core/hle/kernel/svc_results.h"
18#include "core/hle/service/ldr/ldr.h" 18#include "core/hle/service/ldr/ldr.h"
19#include "core/hle/service/service.h" 19#include "core/hle/service/service.h"
20#include "core/loader/nro.h" 20#include "core/loader/nro.h"
@@ -330,7 +330,7 @@ public:
330 const VAddr addr{GetRandomMapRegion(page_table, size)}; 330 const VAddr addr{GetRandomMapRegion(page_table, size)};
331 const ResultCode result{page_table.MapProcessCodeMemory(addr, baseAddress, size)}; 331 const ResultCode result{page_table.MapProcessCodeMemory(addr, baseAddress, size)};
332 332
333 if (result == Kernel::ERR_INVALID_ADDRESS_STATE) { 333 if (result == Kernel::ResultInvalidCurrentMemory) {
334 continue; 334 continue;
335 } 335 }
336 336
@@ -361,7 +361,7 @@ public:
361 const ResultCode result{ 361 const ResultCode result{
362 page_table.MapProcessCodeMemory(addr + nro_size, bss_addr, bss_size)}; 362 page_table.MapProcessCodeMemory(addr + nro_size, bss_addr, bss_size)};
363 363
364 if (result == Kernel::ERR_INVALID_ADDRESS_STATE) { 364 if (result == Kernel::ResultInvalidCurrentMemory) {
365 continue; 365 continue;
366 } 366 }
367 367