summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/svc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hle/kernel/svc.cpp')
-rw-r--r--src/core/hle/kernel/svc.cpp294
1 files changed, 144 insertions, 150 deletions
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index 71ed17790..8655506b0 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -58,8 +58,8 @@ constexpr bool IsValidAddressRange(VAddr address, u64 size) {
58// Helper function that performs the common sanity checks for svcMapMemory 58// Helper function that performs the common sanity checks for svcMapMemory
59// and svcUnmapMemory. This is doable, as both functions perform their sanitizing 59// and svcUnmapMemory. This is doable, as both functions perform their sanitizing
60// in the same order. 60// in the same order.
61ResultCode MapUnmapMemorySanityChecks(const KPageTable& manager, VAddr dst_addr, VAddr src_addr, 61Result MapUnmapMemorySanityChecks(const KPageTable& manager, VAddr dst_addr, VAddr src_addr,
62 u64 size) { 62 u64 size) {
63 if (!Common::Is4KBAligned(dst_addr)) { 63 if (!Common::Is4KBAligned(dst_addr)) {
64 LOG_ERROR(Kernel_SVC, "Destination address is not aligned to 4KB, 0x{:016X}", dst_addr); 64 LOG_ERROR(Kernel_SVC, "Destination address is not aligned to 4KB, 0x{:016X}", dst_addr);
65 return ResultInvalidAddress; 65 return ResultInvalidAddress;
@@ -135,7 +135,7 @@ enum class ResourceLimitValueType {
135} // Anonymous namespace 135} // Anonymous namespace
136 136
137/// Set the process heap to a given Size. It can both extend and shrink the heap. 137/// Set the process heap to a given Size. It can both extend and shrink the heap.
138static ResultCode SetHeapSize(Core::System& system, VAddr* out_address, u64 size) { 138static Result SetHeapSize(Core::System& system, VAddr* out_address, u64 size) {
139 LOG_TRACE(Kernel_SVC, "called, heap_size=0x{:X}", size); 139 LOG_TRACE(Kernel_SVC, "called, heap_size=0x{:X}", size);
140 140
141 // Validate size. 141 // Validate size.
@@ -148,9 +148,9 @@ static ResultCode SetHeapSize(Core::System& system, VAddr* out_address, u64 size
148 return ResultSuccess; 148 return ResultSuccess;
149} 149}
150 150
151static ResultCode SetHeapSize32(Core::System& system, u32* heap_addr, u32 heap_size) { 151static Result SetHeapSize32(Core::System& system, u32* heap_addr, u32 heap_size) {
152 VAddr temp_heap_addr{}; 152 VAddr temp_heap_addr{};
153 const ResultCode result{SetHeapSize(system, &temp_heap_addr, heap_size)}; 153 const Result result{SetHeapSize(system, &temp_heap_addr, heap_size)};
154 *heap_addr = static_cast<u32>(temp_heap_addr); 154 *heap_addr = static_cast<u32>(temp_heap_addr);
155 return result; 155 return result;
156} 156}
@@ -166,8 +166,8 @@ constexpr bool IsValidSetMemoryPermission(MemoryPermission perm) {
166 } 166 }
167} 167}
168 168
169static ResultCode SetMemoryPermission(Core::System& system, VAddr address, u64 size, 169static Result SetMemoryPermission(Core::System& system, VAddr address, u64 size,
170 MemoryPermission perm) { 170 MemoryPermission perm) {
171 LOG_DEBUG(Kernel_SVC, "called, address=0x{:016X}, size=0x{:X}, perm=0x{:08X", address, size, 171 LOG_DEBUG(Kernel_SVC, "called, address=0x{:016X}, size=0x{:X}, perm=0x{:08X", address, size,
172 perm); 172 perm);
173 173
@@ -188,8 +188,8 @@ static ResultCode SetMemoryPermission(Core::System& system, VAddr address, u64 s
188 return page_table.SetMemoryPermission(address, size, perm); 188 return page_table.SetMemoryPermission(address, size, perm);
189} 189}
190 190
191static ResultCode SetMemoryAttribute(Core::System& system, VAddr address, u64 size, u32 mask, 191static Result SetMemoryAttribute(Core::System& system, VAddr address, u64 size, u32 mask,
192 u32 attr) { 192 u32 attr) {
193 LOG_DEBUG(Kernel_SVC, 193 LOG_DEBUG(Kernel_SVC,
194 "called, address=0x{:016X}, size=0x{:X}, mask=0x{:08X}, attribute=0x{:08X}", address, 194 "called, address=0x{:016X}, size=0x{:X}, mask=0x{:08X}, attribute=0x{:08X}", address,
195 size, mask, attr); 195 size, mask, attr);
@@ -213,19 +213,19 @@ static ResultCode SetMemoryAttribute(Core::System& system, VAddr address, u64 si
213 return page_table.SetMemoryAttribute(address, size, mask, attr); 213 return page_table.SetMemoryAttribute(address, size, mask, attr);
214} 214}
215 215
216static ResultCode SetMemoryAttribute32(Core::System& system, u32 address, u32 size, u32 mask, 216static Result SetMemoryAttribute32(Core::System& system, u32 address, u32 size, u32 mask,
217 u32 attr) { 217 u32 attr) {
218 return SetMemoryAttribute(system, address, size, mask, attr); 218 return SetMemoryAttribute(system, address, size, mask, attr);
219} 219}
220 220
221/// Maps a memory range into a different range. 221/// Maps a memory range into a different range.
222static ResultCode MapMemory(Core::System& system, VAddr dst_addr, VAddr src_addr, u64 size) { 222static Result MapMemory(Core::System& system, VAddr dst_addr, VAddr src_addr, u64 size) {
223 LOG_TRACE(Kernel_SVC, "called, dst_addr=0x{:X}, src_addr=0x{:X}, size=0x{:X}", dst_addr, 223 LOG_TRACE(Kernel_SVC, "called, dst_addr=0x{:X}, src_addr=0x{:X}, size=0x{:X}", dst_addr,
224 src_addr, size); 224 src_addr, size);
225 225
226 auto& page_table{system.Kernel().CurrentProcess()->PageTable()}; 226 auto& page_table{system.Kernel().CurrentProcess()->PageTable()};
227 227
228 if (const ResultCode result{MapUnmapMemorySanityChecks(page_table, dst_addr, src_addr, size)}; 228 if (const Result result{MapUnmapMemorySanityChecks(page_table, dst_addr, src_addr, size)};
229 result.IsError()) { 229 result.IsError()) {
230 return result; 230 return result;
231 } 231 }
@@ -233,18 +233,18 @@ static ResultCode MapMemory(Core::System& system, VAddr dst_addr, VAddr src_addr
233 return page_table.MapMemory(dst_addr, src_addr, size); 233 return page_table.MapMemory(dst_addr, src_addr, size);
234} 234}
235 235
236static ResultCode MapMemory32(Core::System& system, u32 dst_addr, u32 src_addr, u32 size) { 236static Result MapMemory32(Core::System& system, u32 dst_addr, u32 src_addr, u32 size) {
237 return MapMemory(system, dst_addr, src_addr, size); 237 return MapMemory(system, dst_addr, src_addr, size);
238} 238}
239 239
240/// Unmaps a region that was previously mapped with svcMapMemory 240/// Unmaps a region that was previously mapped with svcMapMemory
241static ResultCode UnmapMemory(Core::System& system, VAddr dst_addr, VAddr src_addr, u64 size) { 241static Result UnmapMemory(Core::System& system, VAddr dst_addr, VAddr src_addr, u64 size) {
242 LOG_TRACE(Kernel_SVC, "called, dst_addr=0x{:X}, src_addr=0x{:X}, size=0x{:X}", dst_addr, 242 LOG_TRACE(Kernel_SVC, "called, dst_addr=0x{:X}, src_addr=0x{:X}, size=0x{:X}", dst_addr,
243 src_addr, size); 243 src_addr, size);
244 244
245 auto& page_table{system.Kernel().CurrentProcess()->PageTable()}; 245 auto& page_table{system.Kernel().CurrentProcess()->PageTable()};
246 246
247 if (const ResultCode result{MapUnmapMemorySanityChecks(page_table, dst_addr, src_addr, size)}; 247 if (const Result result{MapUnmapMemorySanityChecks(page_table, dst_addr, src_addr, size)};
248 result.IsError()) { 248 result.IsError()) {
249 return result; 249 return result;
250 } 250 }
@@ -252,12 +252,12 @@ static ResultCode UnmapMemory(Core::System& system, VAddr dst_addr, VAddr src_ad
252 return page_table.UnmapMemory(dst_addr, src_addr, size); 252 return page_table.UnmapMemory(dst_addr, src_addr, size);
253} 253}
254 254
255static ResultCode UnmapMemory32(Core::System& system, u32 dst_addr, u32 src_addr, u32 size) { 255static Result UnmapMemory32(Core::System& system, u32 dst_addr, u32 src_addr, u32 size) {
256 return UnmapMemory(system, dst_addr, src_addr, size); 256 return UnmapMemory(system, dst_addr, src_addr, size);
257} 257}
258 258
259/// Connect to an OS service given the port name, returns the handle to the port to out 259/// Connect to an OS service given the port name, returns the handle to the port to out
260static ResultCode ConnectToNamedPort(Core::System& system, Handle* out, VAddr port_name_address) { 260static Result ConnectToNamedPort(Core::System& system, Handle* out, VAddr port_name_address) {
261 auto& memory = system.Memory(); 261 auto& memory = system.Memory();
262 if (!memory.IsValidVirtualAddress(port_name_address)) { 262 if (!memory.IsValidVirtualAddress(port_name_address)) {
263 LOG_ERROR(Kernel_SVC, 263 LOG_ERROR(Kernel_SVC,
@@ -307,14 +307,14 @@ static ResultCode ConnectToNamedPort(Core::System& system, Handle* out, VAddr po
307 return ResultSuccess; 307 return ResultSuccess;
308} 308}
309 309
310static ResultCode ConnectToNamedPort32(Core::System& system, Handle* out_handle, 310static Result ConnectToNamedPort32(Core::System& system, Handle* out_handle,
311 u32 port_name_address) { 311 u32 port_name_address) {
312 312
313 return ConnectToNamedPort(system, out_handle, port_name_address); 313 return ConnectToNamedPort(system, out_handle, port_name_address);
314} 314}
315 315
316/// Makes a blocking IPC call to an OS service. 316/// Makes a blocking IPC call to an OS service.
317static ResultCode SendSyncRequest(Core::System& system, Handle handle) { 317static Result SendSyncRequest(Core::System& system, Handle handle) {
318 auto& kernel = system.Kernel(); 318 auto& kernel = system.Kernel();
319 319
320 // Create the wait queue. 320 // Create the wait queue.
@@ -339,12 +339,12 @@ static ResultCode SendSyncRequest(Core::System& system, Handle handle) {
339 return GetCurrentThread(kernel).GetWaitResult(); 339 return GetCurrentThread(kernel).GetWaitResult();
340} 340}
341 341
342static ResultCode SendSyncRequest32(Core::System& system, Handle handle) { 342static Result SendSyncRequest32(Core::System& system, Handle handle) {
343 return SendSyncRequest(system, handle); 343 return SendSyncRequest(system, handle);
344} 344}
345 345
346/// Get the ID for the specified thread. 346/// Get the ID for the specified thread.
347static ResultCode GetThreadId(Core::System& system, u64* out_thread_id, Handle thread_handle) { 347static Result GetThreadId(Core::System& system, u64* out_thread_id, Handle thread_handle) {
348 // Get the thread from its handle. 348 // Get the thread from its handle.
349 KScopedAutoObject thread = 349 KScopedAutoObject thread =
350 system.Kernel().CurrentProcess()->GetHandleTable().GetObject<KThread>(thread_handle); 350 system.Kernel().CurrentProcess()->GetHandleTable().GetObject<KThread>(thread_handle);
@@ -355,10 +355,10 @@ static ResultCode GetThreadId(Core::System& system, u64* out_thread_id, Handle t
355 return ResultSuccess; 355 return ResultSuccess;
356} 356}
357 357
358static ResultCode GetThreadId32(Core::System& system, u32* out_thread_id_low, 358static Result GetThreadId32(Core::System& system, u32* out_thread_id_low, u32* out_thread_id_high,
359 u32* out_thread_id_high, Handle thread_handle) { 359 Handle thread_handle) {
360 u64 out_thread_id{}; 360 u64 out_thread_id{};
361 const ResultCode result{GetThreadId(system, &out_thread_id, thread_handle)}; 361 const Result result{GetThreadId(system, &out_thread_id, thread_handle)};
362 362
363 *out_thread_id_low = static_cast<u32>(out_thread_id >> 32); 363 *out_thread_id_low = static_cast<u32>(out_thread_id >> 32);
364 *out_thread_id_high = static_cast<u32>(out_thread_id & std::numeric_limits<u32>::max()); 364 *out_thread_id_high = static_cast<u32>(out_thread_id & std::numeric_limits<u32>::max());
@@ -367,7 +367,7 @@ static ResultCode GetThreadId32(Core::System& system, u32* out_thread_id_low,
367} 367}
368 368
369/// Gets the ID of the specified process or a specified thread's owning process. 369/// Gets the ID of the specified process or a specified thread's owning process.
370static ResultCode GetProcessId(Core::System& system, u64* out_process_id, Handle handle) { 370static Result GetProcessId(Core::System& system, u64* out_process_id, Handle handle) {
371 LOG_DEBUG(Kernel_SVC, "called handle=0x{:08X}", handle); 371 LOG_DEBUG(Kernel_SVC, "called handle=0x{:08X}", handle);
372 372
373 // Get the object from the handle table. 373 // Get the object from the handle table.
@@ -398,8 +398,8 @@ static ResultCode GetProcessId(Core::System& system, u64* out_process_id, Handle
398 return ResultSuccess; 398 return ResultSuccess;
399} 399}
400 400
401static ResultCode GetProcessId32(Core::System& system, u32* out_process_id_low, 401static Result GetProcessId32(Core::System& system, u32* out_process_id_low,
402 u32* out_process_id_high, Handle handle) { 402 u32* out_process_id_high, Handle handle) {
403 u64 out_process_id{}; 403 u64 out_process_id{};
404 const auto result = GetProcessId(system, &out_process_id, handle); 404 const auto result = GetProcessId(system, &out_process_id, handle);
405 *out_process_id_low = static_cast<u32>(out_process_id); 405 *out_process_id_low = static_cast<u32>(out_process_id);
@@ -408,8 +408,8 @@ static ResultCode GetProcessId32(Core::System& system, u32* out_process_id_low,
408} 408}
409 409
410/// Wait for the given handles to synchronize, timeout after the specified nanoseconds 410/// Wait for the given handles to synchronize, timeout after the specified nanoseconds
411static ResultCode WaitSynchronization(Core::System& system, s32* index, VAddr handles_address, 411static Result WaitSynchronization(Core::System& system, s32* index, VAddr handles_address,
412 s32 num_handles, s64 nano_seconds) { 412 s32 num_handles, s64 nano_seconds) {
413 LOG_TRACE(Kernel_SVC, "called handles_address=0x{:X}, num_handles={}, nano_seconds={}", 413 LOG_TRACE(Kernel_SVC, "called handles_address=0x{:X}, num_handles={}, nano_seconds={}",
414 handles_address, num_handles, nano_seconds); 414 handles_address, num_handles, nano_seconds);
415 415
@@ -444,14 +444,14 @@ static ResultCode WaitSynchronization(Core::System& system, s32* index, VAddr ha
444 nano_seconds); 444 nano_seconds);
445} 445}
446 446
447static ResultCode WaitSynchronization32(Core::System& system, u32 timeout_low, u32 handles_address, 447static Result WaitSynchronization32(Core::System& system, u32 timeout_low, u32 handles_address,
448 s32 num_handles, u32 timeout_high, s32* index) { 448 s32 num_handles, u32 timeout_high, s32* index) {
449 const s64 nano_seconds{(static_cast<s64>(timeout_high) << 32) | static_cast<s64>(timeout_low)}; 449 const s64 nano_seconds{(static_cast<s64>(timeout_high) << 32) | static_cast<s64>(timeout_low)};
450 return WaitSynchronization(system, index, handles_address, num_handles, nano_seconds); 450 return WaitSynchronization(system, index, handles_address, num_handles, nano_seconds);
451} 451}
452 452
453/// Resumes a thread waiting on WaitSynchronization 453/// Resumes a thread waiting on WaitSynchronization
454static ResultCode CancelSynchronization(Core::System& system, Handle handle) { 454static Result CancelSynchronization(Core::System& system, Handle handle) {
455 LOG_TRACE(Kernel_SVC, "called handle=0x{:X}", handle); 455 LOG_TRACE(Kernel_SVC, "called handle=0x{:X}", handle);
456 456
457 // Get the thread from its handle. 457 // Get the thread from its handle.
@@ -464,13 +464,12 @@ static ResultCode CancelSynchronization(Core::System& system, Handle handle) {
464 return ResultSuccess; 464 return ResultSuccess;
465} 465}
466 466
467static ResultCode CancelSynchronization32(Core::System& system, Handle handle) { 467static Result CancelSynchronization32(Core::System& system, Handle handle) {
468 return CancelSynchronization(system, handle); 468 return CancelSynchronization(system, handle);
469} 469}
470 470
471/// Attempts to locks a mutex 471/// Attempts to locks a mutex
472static ResultCode ArbitrateLock(Core::System& system, Handle thread_handle, VAddr address, 472static Result ArbitrateLock(Core::System& system, Handle thread_handle, VAddr address, u32 tag) {
473 u32 tag) {
474 LOG_TRACE(Kernel_SVC, "called thread_handle=0x{:08X}, address=0x{:X}, tag=0x{:08X}", 473 LOG_TRACE(Kernel_SVC, "called thread_handle=0x{:08X}, address=0x{:X}, tag=0x{:08X}",
475 thread_handle, address, tag); 474 thread_handle, address, tag);
476 475
@@ -488,13 +487,12 @@ static ResultCode ArbitrateLock(Core::System& system, Handle thread_handle, VAdd
488 return system.Kernel().CurrentProcess()->WaitForAddress(thread_handle, address, tag); 487 return system.Kernel().CurrentProcess()->WaitForAddress(thread_handle, address, tag);
489} 488}
490 489
491static ResultCode ArbitrateLock32(Core::System& system, Handle thread_handle, u32 address, 490static Result ArbitrateLock32(Core::System& system, Handle thread_handle, u32 address, u32 tag) {
492 u32 tag) {
493 return ArbitrateLock(system, thread_handle, address, tag); 491 return ArbitrateLock(system, thread_handle, address, tag);
494} 492}
495 493
496/// Unlock a mutex 494/// Unlock a mutex
497static ResultCode ArbitrateUnlock(Core::System& system, VAddr address) { 495static Result ArbitrateUnlock(Core::System& system, VAddr address) {
498 LOG_TRACE(Kernel_SVC, "called address=0x{:X}", address); 496 LOG_TRACE(Kernel_SVC, "called address=0x{:X}", address);
499 497
500 // Validate the input address. 498 // Validate the input address.
@@ -512,7 +510,7 @@ static ResultCode ArbitrateUnlock(Core::System& system, VAddr address) {
512 return system.Kernel().CurrentProcess()->SignalToAddress(address); 510 return system.Kernel().CurrentProcess()->SignalToAddress(address);
513} 511}
514 512
515static ResultCode ArbitrateUnlock32(Core::System& system, u32 address) { 513static Result ArbitrateUnlock32(Core::System& system, u32 address) {
516 return ArbitrateUnlock(system, address); 514 return ArbitrateUnlock(system, address);
517} 515}
518 516
@@ -655,8 +653,8 @@ static void OutputDebugString32(Core::System& system, u32 address, u32 len) {
655} 653}
656 654
657/// Gets system/memory information for the current process 655/// Gets system/memory information for the current process
658static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, Handle handle, 656static Result GetInfo(Core::System& system, u64* result, u64 info_id, Handle handle,
659 u64 info_sub_id) { 657 u64 info_sub_id) {
660 LOG_TRACE(Kernel_SVC, "called info_id=0x{:X}, info_sub_id=0x{:X}, handle=0x{:08X}", info_id, 658 LOG_TRACE(Kernel_SVC, "called info_id=0x{:X}, info_sub_id=0x{:X}, handle=0x{:08X}", info_id,
661 info_sub_id, handle); 659 info_sub_id, handle);
662 660
@@ -943,12 +941,12 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, Handle
943 } 941 }
944} 942}
945 943
946static ResultCode GetInfo32(Core::System& system, u32* result_low, u32* result_high, u32 sub_id_low, 944static Result GetInfo32(Core::System& system, u32* result_low, u32* result_high, u32 sub_id_low,
947 u32 info_id, u32 handle, u32 sub_id_high) { 945 u32 info_id, u32 handle, u32 sub_id_high) {
948 const u64 sub_id{u64{sub_id_low} | (u64{sub_id_high} << 32)}; 946 const u64 sub_id{u64{sub_id_low} | (u64{sub_id_high} << 32)};
949 u64 res_value{}; 947 u64 res_value{};
950 948
951 const ResultCode result{GetInfo(system, &res_value, info_id, handle, sub_id)}; 949 const Result result{GetInfo(system, &res_value, info_id, handle, sub_id)};
952 *result_high = static_cast<u32>(res_value >> 32); 950 *result_high = static_cast<u32>(res_value >> 32);
953 *result_low = static_cast<u32>(res_value & std::numeric_limits<u32>::max()); 951 *result_low = static_cast<u32>(res_value & std::numeric_limits<u32>::max());
954 952
@@ -956,7 +954,7 @@ static ResultCode GetInfo32(Core::System& system, u32* result_low, u32* result_h
956} 954}
957 955
958/// Maps memory at a desired address 956/// Maps memory at a desired address
959static ResultCode MapPhysicalMemory(Core::System& system, VAddr addr, u64 size) { 957static Result MapPhysicalMemory(Core::System& system, VAddr addr, u64 size) {
960 LOG_DEBUG(Kernel_SVC, "called, addr=0x{:016X}, size=0x{:X}", addr, size); 958 LOG_DEBUG(Kernel_SVC, "called, addr=0x{:016X}, size=0x{:X}", addr, size);
961 959
962 if (!Common::Is4KBAligned(addr)) { 960 if (!Common::Is4KBAligned(addr)) {
@@ -1004,12 +1002,12 @@ static ResultCode MapPhysicalMemory(Core::System& system, VAddr addr, u64 size)
1004 return page_table.MapPhysicalMemory(addr, size); 1002 return page_table.MapPhysicalMemory(addr, size);
1005} 1003}
1006 1004
1007static ResultCode MapPhysicalMemory32(Core::System& system, u32 addr, u32 size) { 1005static Result MapPhysicalMemory32(Core::System& system, u32 addr, u32 size) {
1008 return MapPhysicalMemory(system, addr, size); 1006 return MapPhysicalMemory(system, addr, size);
1009} 1007}
1010 1008
1011/// Unmaps memory previously mapped via MapPhysicalMemory 1009/// Unmaps memory previously mapped via MapPhysicalMemory
1012static ResultCode UnmapPhysicalMemory(Core::System& system, VAddr addr, u64 size) { 1010static Result UnmapPhysicalMemory(Core::System& system, VAddr addr, u64 size) {
1013 LOG_DEBUG(Kernel_SVC, "called, addr=0x{:016X}, size=0x{:X}", addr, size); 1011 LOG_DEBUG(Kernel_SVC, "called, addr=0x{:016X}, size=0x{:X}", addr, size);
1014 1012
1015 if (!Common::Is4KBAligned(addr)) { 1013 if (!Common::Is4KBAligned(addr)) {
@@ -1057,13 +1055,13 @@ static ResultCode UnmapPhysicalMemory(Core::System& system, VAddr addr, u64 size
1057 return page_table.UnmapPhysicalMemory(addr, size); 1055 return page_table.UnmapPhysicalMemory(addr, size);
1058} 1056}
1059 1057
1060static ResultCode UnmapPhysicalMemory32(Core::System& system, u32 addr, u32 size) { 1058static Result UnmapPhysicalMemory32(Core::System& system, u32 addr, u32 size) {
1061 return UnmapPhysicalMemory(system, addr, size); 1059 return UnmapPhysicalMemory(system, addr, size);
1062} 1060}
1063 1061
1064/// Sets the thread activity 1062/// Sets the thread activity
1065static ResultCode SetThreadActivity(Core::System& system, Handle thread_handle, 1063static Result SetThreadActivity(Core::System& system, Handle thread_handle,
1066 ThreadActivity thread_activity) { 1064 ThreadActivity thread_activity) {
1067 LOG_DEBUG(Kernel_SVC, "called, handle=0x{:08X}, activity=0x{:08X}", thread_handle, 1065 LOG_DEBUG(Kernel_SVC, "called, handle=0x{:08X}, activity=0x{:08X}", thread_handle,
1068 thread_activity); 1066 thread_activity);
1069 1067
@@ -1088,13 +1086,13 @@ static ResultCode SetThreadActivity(Core::System& system, Handle thread_handle,
1088 return ResultSuccess; 1086 return ResultSuccess;
1089} 1087}
1090 1088
1091static ResultCode SetThreadActivity32(Core::System& system, Handle thread_handle, 1089static Result SetThreadActivity32(Core::System& system, Handle thread_handle,
1092 Svc::ThreadActivity thread_activity) { 1090 Svc::ThreadActivity thread_activity) {
1093 return SetThreadActivity(system, thread_handle, thread_activity); 1091 return SetThreadActivity(system, thread_handle, thread_activity);
1094} 1092}
1095 1093
1096/// Gets the thread context 1094/// Gets the thread context
1097static ResultCode GetThreadContext(Core::System& system, VAddr out_context, Handle thread_handle) { 1095static Result GetThreadContext(Core::System& system, VAddr out_context, Handle thread_handle) {
1098 LOG_DEBUG(Kernel_SVC, "called, out_context=0x{:08X}, thread_handle=0x{:X}", out_context, 1096 LOG_DEBUG(Kernel_SVC, "called, out_context=0x{:08X}, thread_handle=0x{:X}", out_context,
1099 thread_handle); 1097 thread_handle);
1100 1098
@@ -1151,12 +1149,12 @@ static ResultCode GetThreadContext(Core::System& system, VAddr out_context, Hand
1151 return ResultSuccess; 1149 return ResultSuccess;
1152} 1150}
1153 1151
1154static ResultCode GetThreadContext32(Core::System& system, u32 out_context, Handle thread_handle) { 1152static Result GetThreadContext32(Core::System& system, u32 out_context, Handle thread_handle) {
1155 return GetThreadContext(system, out_context, thread_handle); 1153 return GetThreadContext(system, out_context, thread_handle);
1156} 1154}
1157 1155
1158/// Gets the priority for the specified thread 1156/// Gets the priority for the specified thread
1159static ResultCode GetThreadPriority(Core::System& system, u32* out_priority, Handle handle) { 1157static Result GetThreadPriority(Core::System& system, u32* out_priority, Handle handle) {
1160 LOG_TRACE(Kernel_SVC, "called"); 1158 LOG_TRACE(Kernel_SVC, "called");
1161 1159
1162 // Get the thread from its handle. 1160 // Get the thread from its handle.
@@ -1169,12 +1167,12 @@ static ResultCode GetThreadPriority(Core::System& system, u32* out_priority, Han
1169 return ResultSuccess; 1167 return ResultSuccess;
1170} 1168}
1171 1169
1172static ResultCode GetThreadPriority32(Core::System& system, u32* out_priority, Handle handle) { 1170static Result GetThreadPriority32(Core::System& system, u32* out_priority, Handle handle) {
1173 return GetThreadPriority(system, out_priority, handle); 1171 return GetThreadPriority(system, out_priority, handle);
1174} 1172}
1175 1173
1176/// Sets the priority for the specified thread 1174/// Sets the priority for the specified thread
1177static ResultCode SetThreadPriority(Core::System& system, Handle thread_handle, u32 priority) { 1175static Result SetThreadPriority(Core::System& system, Handle thread_handle, u32 priority) {
1178 // Get the current process. 1176 // Get the current process.
1179 KProcess& process = *system.Kernel().CurrentProcess(); 1177 KProcess& process = *system.Kernel().CurrentProcess();
1180 1178
@@ -1192,7 +1190,7 @@ static ResultCode SetThreadPriority(Core::System& system, Handle thread_handle,
1192 return ResultSuccess; 1190 return ResultSuccess;
1193} 1191}
1194 1192
1195static ResultCode SetThreadPriority32(Core::System& system, Handle thread_handle, u32 priority) { 1193static Result SetThreadPriority32(Core::System& system, Handle thread_handle, u32 priority) {
1196 return SetThreadPriority(system, thread_handle, priority); 1194 return SetThreadPriority(system, thread_handle, priority);
1197} 1195}
1198 1196
@@ -1252,8 +1250,8 @@ constexpr bool IsValidUnmapFromOwnerCodeMemoryPermission(Svc::MemoryPermission p
1252 1250
1253} // Anonymous namespace 1251} // Anonymous namespace
1254 1252
1255static ResultCode MapSharedMemory(Core::System& system, Handle shmem_handle, VAddr address, 1253static Result MapSharedMemory(Core::System& system, Handle shmem_handle, VAddr address, u64 size,
1256 u64 size, Svc::MemoryPermission map_perm) { 1254 Svc::MemoryPermission map_perm) {
1257 LOG_TRACE(Kernel_SVC, 1255 LOG_TRACE(Kernel_SVC,
1258 "called, shared_memory_handle=0x{:X}, addr=0x{:X}, size=0x{:X}, permissions=0x{:08X}", 1256 "called, shared_memory_handle=0x{:X}, addr=0x{:X}, size=0x{:X}, permissions=0x{:08X}",
1259 shmem_handle, address, size, map_perm); 1257 shmem_handle, address, size, map_perm);
@@ -1293,13 +1291,13 @@ static ResultCode MapSharedMemory(Core::System& system, Handle shmem_handle, VAd
1293 return ResultSuccess; 1291 return ResultSuccess;
1294} 1292}
1295 1293
1296static ResultCode MapSharedMemory32(Core::System& system, Handle shmem_handle, u32 address, 1294static Result MapSharedMemory32(Core::System& system, Handle shmem_handle, u32 address, u32 size,
1297 u32 size, Svc::MemoryPermission map_perm) { 1295 Svc::MemoryPermission map_perm) {
1298 return MapSharedMemory(system, shmem_handle, address, size, map_perm); 1296 return MapSharedMemory(system, shmem_handle, address, size, map_perm);
1299} 1297}
1300 1298
1301static ResultCode UnmapSharedMemory(Core::System& system, Handle shmem_handle, VAddr address, 1299static Result UnmapSharedMemory(Core::System& system, Handle shmem_handle, VAddr address,
1302 u64 size) { 1300 u64 size) {
1303 // Validate the address/size. 1301 // Validate the address/size.
1304 R_UNLESS(Common::IsAligned(address, PageSize), ResultInvalidAddress); 1302 R_UNLESS(Common::IsAligned(address, PageSize), ResultInvalidAddress);
1305 R_UNLESS(Common::IsAligned(size, PageSize), ResultInvalidSize); 1303 R_UNLESS(Common::IsAligned(size, PageSize), ResultInvalidSize);
@@ -1326,13 +1324,13 @@ static ResultCode UnmapSharedMemory(Core::System& system, Handle shmem_handle, V
1326 return ResultSuccess; 1324 return ResultSuccess;
1327} 1325}
1328 1326
1329static ResultCode UnmapSharedMemory32(Core::System& system, Handle shmem_handle, u32 address, 1327static Result UnmapSharedMemory32(Core::System& system, Handle shmem_handle, u32 address,
1330 u32 size) { 1328 u32 size) {
1331 return UnmapSharedMemory(system, shmem_handle, address, size); 1329 return UnmapSharedMemory(system, shmem_handle, address, size);
1332} 1330}
1333 1331
1334static ResultCode SetProcessMemoryPermission(Core::System& system, Handle process_handle, 1332static Result SetProcessMemoryPermission(Core::System& system, Handle process_handle, VAddr address,
1335 VAddr address, u64 size, Svc::MemoryPermission perm) { 1333 u64 size, Svc::MemoryPermission perm) {
1336 LOG_TRACE(Kernel_SVC, 1334 LOG_TRACE(Kernel_SVC,
1337 "called, process_handle=0x{:X}, addr=0x{:X}, size=0x{:X}, permissions=0x{:08X}", 1335 "called, process_handle=0x{:X}, addr=0x{:X}, size=0x{:X}, permissions=0x{:08X}",
1338 process_handle, address, size, perm); 1336 process_handle, address, size, perm);
@@ -1361,8 +1359,8 @@ static ResultCode SetProcessMemoryPermission(Core::System& system, Handle proces
1361 return page_table.SetProcessMemoryPermission(address, size, perm); 1359 return page_table.SetProcessMemoryPermission(address, size, perm);
1362} 1360}
1363 1361
1364static ResultCode MapProcessMemory(Core::System& system, VAddr dst_address, Handle process_handle, 1362static Result MapProcessMemory(Core::System& system, VAddr dst_address, Handle process_handle,
1365 VAddr src_address, u64 size) { 1363 VAddr src_address, u64 size) {
1366 LOG_TRACE(Kernel_SVC, 1364 LOG_TRACE(Kernel_SVC,
1367 "called, dst_address=0x{:X}, process_handle=0x{:X}, src_address=0x{:X}, size=0x{:X}", 1365 "called, dst_address=0x{:X}, process_handle=0x{:X}, src_address=0x{:X}, size=0x{:X}",
1368 dst_address, process_handle, src_address, size); 1366 dst_address, process_handle, src_address, size);
@@ -1391,7 +1389,7 @@ static ResultCode MapProcessMemory(Core::System& system, VAddr dst_address, Hand
1391 ResultInvalidMemoryRegion); 1389 ResultInvalidMemoryRegion);
1392 1390
1393 // Create a new page group. 1391 // Create a new page group.
1394 KPageLinkedList pg; 1392 KPageGroup pg;
1395 R_TRY(src_pt.MakeAndOpenPageGroup( 1393 R_TRY(src_pt.MakeAndOpenPageGroup(
1396 std::addressof(pg), src_address, size / PageSize, KMemoryState::FlagCanMapProcess, 1394 std::addressof(pg), src_address, size / PageSize, KMemoryState::FlagCanMapProcess,
1397 KMemoryState::FlagCanMapProcess, KMemoryPermission::None, KMemoryPermission::None, 1395 KMemoryState::FlagCanMapProcess, KMemoryPermission::None, KMemoryPermission::None,
@@ -1404,8 +1402,8 @@ static ResultCode MapProcessMemory(Core::System& system, VAddr dst_address, Hand
1404 return ResultSuccess; 1402 return ResultSuccess;
1405} 1403}
1406 1404
1407static ResultCode UnmapProcessMemory(Core::System& system, VAddr dst_address, Handle process_handle, 1405static Result UnmapProcessMemory(Core::System& system, VAddr dst_address, Handle process_handle,
1408 VAddr src_address, u64 size) { 1406 VAddr src_address, u64 size) {
1409 LOG_TRACE(Kernel_SVC, 1407 LOG_TRACE(Kernel_SVC,
1410 "called, dst_address=0x{:X}, process_handle=0x{:X}, src_address=0x{:X}, size=0x{:X}", 1408 "called, dst_address=0x{:X}, process_handle=0x{:X}, src_address=0x{:X}, size=0x{:X}",
1411 dst_address, process_handle, src_address, size); 1409 dst_address, process_handle, src_address, size);
@@ -1439,7 +1437,7 @@ static ResultCode UnmapProcessMemory(Core::System& system, VAddr dst_address, Ha
1439 return ResultSuccess; 1437 return ResultSuccess;
1440} 1438}
1441 1439
1442static ResultCode CreateCodeMemory(Core::System& system, Handle* out, VAddr address, size_t size) { 1440static Result CreateCodeMemory(Core::System& system, Handle* out, VAddr address, size_t size) {
1443 LOG_TRACE(Kernel_SVC, "called, address=0x{:X}, size=0x{:X}", address, size); 1441 LOG_TRACE(Kernel_SVC, "called, address=0x{:X}, size=0x{:X}", address, size);
1444 1442
1445 // Get kernel instance. 1443 // Get kernel instance.
@@ -1474,12 +1472,12 @@ static ResultCode CreateCodeMemory(Core::System& system, Handle* out, VAddr addr
1474 return ResultSuccess; 1472 return ResultSuccess;
1475} 1473}
1476 1474
1477static ResultCode CreateCodeMemory32(Core::System& system, Handle* out, u32 address, u32 size) { 1475static Result CreateCodeMemory32(Core::System& system, Handle* out, u32 address, u32 size) {
1478 return CreateCodeMemory(system, out, address, size); 1476 return CreateCodeMemory(system, out, address, size);
1479} 1477}
1480 1478
1481static ResultCode ControlCodeMemory(Core::System& system, Handle code_memory_handle, u32 operation, 1479static Result ControlCodeMemory(Core::System& system, Handle code_memory_handle, u32 operation,
1482 VAddr address, size_t size, Svc::MemoryPermission perm) { 1480 VAddr address, size_t size, Svc::MemoryPermission perm) {
1483 1481
1484 LOG_TRACE(Kernel_SVC, 1482 LOG_TRACE(Kernel_SVC,
1485 "called, code_memory_handle=0x{:X}, operation=0x{:X}, address=0x{:X}, size=0x{:X}, " 1483 "called, code_memory_handle=0x{:X}, operation=0x{:X}, address=0x{:X}, size=0x{:X}, "
@@ -1557,15 +1555,13 @@ static ResultCode ControlCodeMemory(Core::System& system, Handle code_memory_han
1557 return ResultSuccess; 1555 return ResultSuccess;
1558} 1556}
1559 1557
1560static ResultCode ControlCodeMemory32(Core::System& system, Handle code_memory_handle, 1558static Result ControlCodeMemory32(Core::System& system, Handle code_memory_handle, u32 operation,
1561 u32 operation, u64 address, u64 size, 1559 u64 address, u64 size, Svc::MemoryPermission perm) {
1562 Svc::MemoryPermission perm) {
1563 return ControlCodeMemory(system, code_memory_handle, operation, address, size, perm); 1560 return ControlCodeMemory(system, code_memory_handle, operation, address, size, perm);
1564} 1561}
1565 1562
1566static ResultCode QueryProcessMemory(Core::System& system, VAddr memory_info_address, 1563static Result QueryProcessMemory(Core::System& system, VAddr memory_info_address,
1567 VAddr page_info_address, Handle process_handle, 1564 VAddr page_info_address, Handle process_handle, VAddr address) {
1568 VAddr address) {
1569 LOG_TRACE(Kernel_SVC, "called process=0x{:08X} address={:X}", process_handle, address); 1565 LOG_TRACE(Kernel_SVC, "called process=0x{:08X} address={:X}", process_handle, address);
1570 const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); 1566 const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable();
1571 KScopedAutoObject process = handle_table.GetObject<KProcess>(process_handle); 1567 KScopedAutoObject process = handle_table.GetObject<KProcess>(process_handle);
@@ -1593,8 +1589,8 @@ static ResultCode QueryProcessMemory(Core::System& system, VAddr memory_info_add
1593 return ResultSuccess; 1589 return ResultSuccess;
1594} 1590}
1595 1591
1596static ResultCode QueryMemory(Core::System& system, VAddr memory_info_address, 1592static Result QueryMemory(Core::System& system, VAddr memory_info_address, VAddr page_info_address,
1597 VAddr page_info_address, VAddr query_address) { 1593 VAddr query_address) {
1598 LOG_TRACE(Kernel_SVC, 1594 LOG_TRACE(Kernel_SVC,
1599 "called, memory_info_address=0x{:016X}, page_info_address=0x{:016X}, " 1595 "called, memory_info_address=0x{:016X}, page_info_address=0x{:016X}, "
1600 "query_address=0x{:016X}", 1596 "query_address=0x{:016X}",
@@ -1604,13 +1600,13 @@ static ResultCode QueryMemory(Core::System& system, VAddr memory_info_address,
1604 query_address); 1600 query_address);
1605} 1601}
1606 1602
1607static ResultCode QueryMemory32(Core::System& system, u32 memory_info_address, 1603static Result QueryMemory32(Core::System& system, u32 memory_info_address, u32 page_info_address,
1608 u32 page_info_address, u32 query_address) { 1604 u32 query_address) {
1609 return QueryMemory(system, memory_info_address, page_info_address, query_address); 1605 return QueryMemory(system, memory_info_address, page_info_address, query_address);
1610} 1606}
1611 1607
1612static ResultCode MapProcessCodeMemory(Core::System& system, Handle process_handle, u64 dst_address, 1608static Result MapProcessCodeMemory(Core::System& system, Handle process_handle, u64 dst_address,
1613 u64 src_address, u64 size) { 1609 u64 src_address, u64 size) {
1614 LOG_DEBUG(Kernel_SVC, 1610 LOG_DEBUG(Kernel_SVC,
1615 "called. process_handle=0x{:08X}, dst_address=0x{:016X}, " 1611 "called. process_handle=0x{:08X}, dst_address=0x{:016X}, "
1616 "src_address=0x{:016X}, size=0x{:016X}", 1612 "src_address=0x{:016X}, size=0x{:016X}",
@@ -1677,8 +1673,8 @@ static ResultCode MapProcessCodeMemory(Core::System& system, Handle process_hand
1677 return page_table.MapCodeMemory(dst_address, src_address, size); 1673 return page_table.MapCodeMemory(dst_address, src_address, size);
1678} 1674}
1679 1675
1680static ResultCode UnmapProcessCodeMemory(Core::System& system, Handle process_handle, 1676static Result UnmapProcessCodeMemory(Core::System& system, Handle process_handle, u64 dst_address,
1681 u64 dst_address, u64 src_address, u64 size) { 1677 u64 src_address, u64 size) {
1682 LOG_DEBUG(Kernel_SVC, 1678 LOG_DEBUG(Kernel_SVC,
1683 "called. process_handle=0x{:08X}, dst_address=0x{:016X}, src_address=0x{:016X}, " 1679 "called. process_handle=0x{:08X}, dst_address=0x{:016X}, src_address=0x{:016X}, "
1684 "size=0x{:016X}", 1680 "size=0x{:016X}",
@@ -1770,8 +1766,8 @@ constexpr bool IsValidVirtualCoreId(int32_t core_id) {
1770} // Anonymous namespace 1766} // Anonymous namespace
1771 1767
1772/// Creates a new thread 1768/// Creates a new thread
1773static ResultCode CreateThread(Core::System& system, Handle* out_handle, VAddr entry_point, u64 arg, 1769static Result CreateThread(Core::System& system, Handle* out_handle, VAddr entry_point, u64 arg,
1774 VAddr stack_bottom, u32 priority, s32 core_id) { 1770 VAddr stack_bottom, u32 priority, s32 core_id) {
1775 LOG_DEBUG(Kernel_SVC, 1771 LOG_DEBUG(Kernel_SVC,
1776 "called entry_point=0x{:08X}, arg=0x{:08X}, stack_bottom=0x{:08X}, " 1772 "called entry_point=0x{:08X}, arg=0x{:08X}, stack_bottom=0x{:08X}, "
1777 "priority=0x{:08X}, core_id=0x{:08X}", 1773 "priority=0x{:08X}, core_id=0x{:08X}",
@@ -1842,13 +1838,13 @@ static ResultCode CreateThread(Core::System& system, Handle* out_handle, VAddr e
1842 return ResultSuccess; 1838 return ResultSuccess;
1843} 1839}
1844 1840
1845static ResultCode CreateThread32(Core::System& system, Handle* out_handle, u32 priority, 1841static Result CreateThread32(Core::System& system, Handle* out_handle, u32 priority,
1846 u32 entry_point, u32 arg, u32 stack_top, s32 processor_id) { 1842 u32 entry_point, u32 arg, u32 stack_top, s32 processor_id) {
1847 return CreateThread(system, out_handle, entry_point, arg, stack_top, priority, processor_id); 1843 return CreateThread(system, out_handle, entry_point, arg, stack_top, priority, processor_id);
1848} 1844}
1849 1845
1850/// Starts the thread for the provided handle 1846/// Starts the thread for the provided handle
1851static ResultCode StartThread(Core::System& system, Handle thread_handle) { 1847static Result StartThread(Core::System& system, Handle thread_handle) {
1852 LOG_DEBUG(Kernel_SVC, "called thread=0x{:08X}", thread_handle); 1848 LOG_DEBUG(Kernel_SVC, "called thread=0x{:08X}", thread_handle);
1853 1849
1854 // Get the thread from its handle. 1850 // Get the thread from its handle.
@@ -1866,7 +1862,7 @@ static ResultCode StartThread(Core::System& system, Handle thread_handle) {
1866 return ResultSuccess; 1862 return ResultSuccess;
1867} 1863}
1868 1864
1869static ResultCode StartThread32(Core::System& system, Handle thread_handle) { 1865static Result StartThread32(Core::System& system, Handle thread_handle) {
1870 return StartThread(system, thread_handle); 1866 return StartThread(system, thread_handle);
1871} 1867}
1872 1868
@@ -1917,8 +1913,8 @@ static void SleepThread32(Core::System& system, u32 nanoseconds_low, u32 nanosec
1917} 1913}
1918 1914
1919/// Wait process wide key atomic 1915/// Wait process wide key atomic
1920static ResultCode WaitProcessWideKeyAtomic(Core::System& system, VAddr address, VAddr cv_key, 1916static Result WaitProcessWideKeyAtomic(Core::System& system, VAddr address, VAddr cv_key, u32 tag,
1921 u32 tag, s64 timeout_ns) { 1917 s64 timeout_ns) {
1922 LOG_TRACE(Kernel_SVC, "called address={:X}, cv_key={:X}, tag=0x{:08X}, timeout_ns={}", address, 1918 LOG_TRACE(Kernel_SVC, "called address={:X}, cv_key={:X}, tag=0x{:08X}, timeout_ns={}", address,
1923 cv_key, tag, timeout_ns); 1919 cv_key, tag, timeout_ns);
1924 1920
@@ -1953,8 +1949,8 @@ static ResultCode WaitProcessWideKeyAtomic(Core::System& system, VAddr address,
1953 address, Common::AlignDown(cv_key, sizeof(u32)), tag, timeout); 1949 address, Common::AlignDown(cv_key, sizeof(u32)), tag, timeout);
1954} 1950}
1955 1951
1956static ResultCode WaitProcessWideKeyAtomic32(Core::System& system, u32 address, u32 cv_key, u32 tag, 1952static Result WaitProcessWideKeyAtomic32(Core::System& system, u32 address, u32 cv_key, u32 tag,
1957 u32 timeout_ns_low, u32 timeout_ns_high) { 1953 u32 timeout_ns_low, u32 timeout_ns_high) {
1958 const auto timeout_ns = static_cast<s64>(timeout_ns_low | (u64{timeout_ns_high} << 32)); 1954 const auto timeout_ns = static_cast<s64>(timeout_ns_low | (u64{timeout_ns_high} << 32));
1959 return WaitProcessWideKeyAtomic(system, address, cv_key, tag, timeout_ns); 1955 return WaitProcessWideKeyAtomic(system, address, cv_key, tag, timeout_ns);
1960} 1956}
@@ -1999,8 +1995,8 @@ constexpr bool IsValidArbitrationType(Svc::ArbitrationType type) {
1999} // namespace 1995} // namespace
2000 1996
2001// Wait for an address (via Address Arbiter) 1997// Wait for an address (via Address Arbiter)
2002static ResultCode WaitForAddress(Core::System& system, VAddr address, Svc::ArbitrationType arb_type, 1998static Result WaitForAddress(Core::System& system, VAddr address, Svc::ArbitrationType arb_type,
2003 s32 value, s64 timeout_ns) { 1999 s32 value, s64 timeout_ns) {
2004 LOG_TRACE(Kernel_SVC, "called, address=0x{:X}, arb_type=0x{:X}, value=0x{:X}, timeout_ns={}", 2000 LOG_TRACE(Kernel_SVC, "called, address=0x{:X}, arb_type=0x{:X}, value=0x{:X}, timeout_ns={}",
2005 address, arb_type, value, timeout_ns); 2001 address, arb_type, value, timeout_ns);
2006 2002
@@ -2037,15 +2033,15 @@ static ResultCode WaitForAddress(Core::System& system, VAddr address, Svc::Arbit
2037 return system.Kernel().CurrentProcess()->WaitAddressArbiter(address, arb_type, value, timeout); 2033 return system.Kernel().CurrentProcess()->WaitAddressArbiter(address, arb_type, value, timeout);
2038} 2034}
2039 2035
2040static ResultCode WaitForAddress32(Core::System& system, u32 address, Svc::ArbitrationType arb_type, 2036static Result WaitForAddress32(Core::System& system, u32 address, Svc::ArbitrationType arb_type,
2041 s32 value, u32 timeout_ns_low, u32 timeout_ns_high) { 2037 s32 value, u32 timeout_ns_low, u32 timeout_ns_high) {
2042 const auto timeout = static_cast<s64>(timeout_ns_low | (u64{timeout_ns_high} << 32)); 2038 const auto timeout = static_cast<s64>(timeout_ns_low | (u64{timeout_ns_high} << 32));
2043 return WaitForAddress(system, address, arb_type, value, timeout); 2039 return WaitForAddress(system, address, arb_type, value, timeout);
2044} 2040}
2045 2041
2046// Signals to an address (via Address Arbiter) 2042// Signals to an address (via Address Arbiter)
2047static ResultCode SignalToAddress(Core::System& system, VAddr address, Svc::SignalType signal_type, 2043static Result SignalToAddress(Core::System& system, VAddr address, Svc::SignalType signal_type,
2048 s32 value, s32 count) { 2044 s32 value, s32 count) {
2049 LOG_TRACE(Kernel_SVC, "called, address=0x{:X}, signal_type=0x{:X}, value=0x{:X}, count=0x{:X}", 2045 LOG_TRACE(Kernel_SVC, "called, address=0x{:X}, signal_type=0x{:X}, value=0x{:X}, count=0x{:X}",
2050 address, signal_type, value, count); 2046 address, signal_type, value, count);
2051 2047
@@ -2086,8 +2082,8 @@ static void SynchronizePreemptionState(Core::System& system) {
2086 } 2082 }
2087} 2083}
2088 2084
2089static ResultCode SignalToAddress32(Core::System& system, u32 address, Svc::SignalType signal_type, 2085static Result SignalToAddress32(Core::System& system, u32 address, Svc::SignalType signal_type,
2090 s32 value, s32 count) { 2086 s32 value, s32 count) {
2091 return SignalToAddress(system, address, signal_type, value, count); 2087 return SignalToAddress(system, address, signal_type, value, count);
2092} 2088}
2093 2089
@@ -2125,7 +2121,7 @@ static void GetSystemTick32(Core::System& system, u32* time_low, u32* time_high)
2125} 2121}
2126 2122
2127/// Close a handle 2123/// Close a handle
2128static ResultCode CloseHandle(Core::System& system, Handle handle) { 2124static Result CloseHandle(Core::System& system, Handle handle) {
2129 LOG_TRACE(Kernel_SVC, "Closing handle 0x{:08X}", handle); 2125 LOG_TRACE(Kernel_SVC, "Closing handle 0x{:08X}", handle);
2130 2126
2131 // Remove the handle. 2127 // Remove the handle.
@@ -2135,12 +2131,12 @@ static ResultCode CloseHandle(Core::System& system, Handle handle) {
2135 return ResultSuccess; 2131 return ResultSuccess;
2136} 2132}
2137 2133
2138static ResultCode CloseHandle32(Core::System& system, Handle handle) { 2134static Result CloseHandle32(Core::System& system, Handle handle) {
2139 return CloseHandle(system, handle); 2135 return CloseHandle(system, handle);
2140} 2136}
2141 2137
2142/// Clears the signaled state of an event or process. 2138/// Clears the signaled state of an event or process.
2143static ResultCode ResetSignal(Core::System& system, Handle handle) { 2139static Result ResetSignal(Core::System& system, Handle handle) {
2144 LOG_DEBUG(Kernel_SVC, "called handle 0x{:08X}", handle); 2140 LOG_DEBUG(Kernel_SVC, "called handle 0x{:08X}", handle);
2145 2141
2146 // Get the current handle table. 2142 // Get the current handle table.
@@ -2167,7 +2163,7 @@ static ResultCode ResetSignal(Core::System& system, Handle handle) {
2167 return ResultInvalidHandle; 2163 return ResultInvalidHandle;
2168} 2164}
2169 2165
2170static ResultCode ResetSignal32(Core::System& system, Handle handle) { 2166static Result ResetSignal32(Core::System& system, Handle handle) {
2171 return ResetSignal(system, handle); 2167 return ResetSignal(system, handle);
2172} 2168}
2173 2169
@@ -2187,8 +2183,8 @@ constexpr bool IsValidTransferMemoryPermission(MemoryPermission perm) {
2187} // Anonymous namespace 2183} // Anonymous namespace
2188 2184
2189/// Creates a TransferMemory object 2185/// Creates a TransferMemory object
2190static ResultCode CreateTransferMemory(Core::System& system, Handle* out, VAddr address, u64 size, 2186static Result CreateTransferMemory(Core::System& system, Handle* out, VAddr address, u64 size,
2191 MemoryPermission map_perm) { 2187 MemoryPermission map_perm) {
2192 auto& kernel = system.Kernel(); 2188 auto& kernel = system.Kernel();
2193 2189
2194 // Validate the size. 2190 // Validate the size.
@@ -2234,13 +2230,13 @@ static ResultCode CreateTransferMemory(Core::System& system, Handle* out, VAddr
2234 return ResultSuccess; 2230 return ResultSuccess;
2235} 2231}
2236 2232
2237static ResultCode CreateTransferMemory32(Core::System& system, Handle* out, u32 address, u32 size, 2233static Result CreateTransferMemory32(Core::System& system, Handle* out, u32 address, u32 size,
2238 MemoryPermission map_perm) { 2234 MemoryPermission map_perm) {
2239 return CreateTransferMemory(system, out, address, size, map_perm); 2235 return CreateTransferMemory(system, out, address, size, map_perm);
2240} 2236}
2241 2237
2242static ResultCode GetThreadCoreMask(Core::System& system, Handle thread_handle, s32* out_core_id, 2238static Result GetThreadCoreMask(Core::System& system, Handle thread_handle, s32* out_core_id,
2243 u64* out_affinity_mask) { 2239 u64* out_affinity_mask) {
2244 LOG_TRACE(Kernel_SVC, "called, handle=0x{:08X}", thread_handle); 2240 LOG_TRACE(Kernel_SVC, "called, handle=0x{:08X}", thread_handle);
2245 2241
2246 // Get the thread from its handle. 2242 // Get the thread from its handle.
@@ -2254,8 +2250,8 @@ static ResultCode GetThreadCoreMask(Core::System& system, Handle thread_handle,
2254 return ResultSuccess; 2250 return ResultSuccess;
2255} 2251}
2256 2252
2257static ResultCode GetThreadCoreMask32(Core::System& system, Handle thread_handle, s32* out_core_id, 2253static Result GetThreadCoreMask32(Core::System& system, Handle thread_handle, s32* out_core_id,
2258 u32* out_affinity_mask_low, u32* out_affinity_mask_high) { 2254 u32* out_affinity_mask_low, u32* out_affinity_mask_high) {
2259 u64 out_affinity_mask{}; 2255 u64 out_affinity_mask{};
2260 const auto result = GetThreadCoreMask(system, thread_handle, out_core_id, &out_affinity_mask); 2256 const auto result = GetThreadCoreMask(system, thread_handle, out_core_id, &out_affinity_mask);
2261 *out_affinity_mask_high = static_cast<u32>(out_affinity_mask >> 32); 2257 *out_affinity_mask_high = static_cast<u32>(out_affinity_mask >> 32);
@@ -2263,8 +2259,8 @@ static ResultCode GetThreadCoreMask32(Core::System& system, Handle thread_handle
2263 return result; 2259 return result;
2264} 2260}
2265 2261
2266static ResultCode SetThreadCoreMask(Core::System& system, Handle thread_handle, s32 core_id, 2262static Result SetThreadCoreMask(Core::System& system, Handle thread_handle, s32 core_id,
2267 u64 affinity_mask) { 2263 u64 affinity_mask) {
2268 // Determine the core id/affinity mask. 2264 // Determine the core id/affinity mask.
2269 if (core_id == IdealCoreUseProcessValue) { 2265 if (core_id == IdealCoreUseProcessValue) {
2270 core_id = system.Kernel().CurrentProcess()->GetIdealCoreId(); 2266 core_id = system.Kernel().CurrentProcess()->GetIdealCoreId();
@@ -2295,13 +2291,13 @@ static ResultCode SetThreadCoreMask(Core::System& system, Handle thread_handle,
2295 return ResultSuccess; 2291 return ResultSuccess;
2296} 2292}
2297 2293
2298static ResultCode SetThreadCoreMask32(Core::System& system, Handle thread_handle, s32 core_id, 2294static Result SetThreadCoreMask32(Core::System& system, Handle thread_handle, s32 core_id,
2299 u32 affinity_mask_low, u32 affinity_mask_high) { 2295 u32 affinity_mask_low, u32 affinity_mask_high) {
2300 const auto affinity_mask = u64{affinity_mask_low} | (u64{affinity_mask_high} << 32); 2296 const auto affinity_mask = u64{affinity_mask_low} | (u64{affinity_mask_high} << 32);
2301 return SetThreadCoreMask(system, thread_handle, core_id, affinity_mask); 2297 return SetThreadCoreMask(system, thread_handle, core_id, affinity_mask);
2302} 2298}
2303 2299
2304static ResultCode SignalEvent(Core::System& system, Handle event_handle) { 2300static Result SignalEvent(Core::System& system, Handle event_handle) {
2305 LOG_DEBUG(Kernel_SVC, "called, event_handle=0x{:08X}", event_handle); 2301 LOG_DEBUG(Kernel_SVC, "called, event_handle=0x{:08X}", event_handle);
2306 2302
2307 // Get the current handle table. 2303 // Get the current handle table.
@@ -2314,11 +2310,11 @@ static ResultCode SignalEvent(Core::System& system, Handle event_handle) {
2314 return writable_event->Signal(); 2310 return writable_event->Signal();
2315} 2311}
2316 2312
2317static ResultCode SignalEvent32(Core::System& system, Handle event_handle) { 2313static Result SignalEvent32(Core::System& system, Handle event_handle) {
2318 return SignalEvent(system, event_handle); 2314 return SignalEvent(system, event_handle);
2319} 2315}
2320 2316
2321static ResultCode ClearEvent(Core::System& system, Handle event_handle) { 2317static Result ClearEvent(Core::System& system, Handle event_handle) {
2322 LOG_TRACE(Kernel_SVC, "called, event_handle=0x{:08X}", event_handle); 2318 LOG_TRACE(Kernel_SVC, "called, event_handle=0x{:08X}", event_handle);
2323 2319
2324 // Get the current handle table. 2320 // Get the current handle table.
@@ -2345,11 +2341,11 @@ static ResultCode ClearEvent(Core::System& system, Handle event_handle) {
2345 return ResultInvalidHandle; 2341 return ResultInvalidHandle;
2346} 2342}
2347 2343
2348static ResultCode ClearEvent32(Core::System& system, Handle event_handle) { 2344static Result ClearEvent32(Core::System& system, Handle event_handle) {
2349 return ClearEvent(system, event_handle); 2345 return ClearEvent(system, event_handle);
2350} 2346}
2351 2347
2352static ResultCode CreateEvent(Core::System& system, Handle* out_write, Handle* out_read) { 2348static Result CreateEvent(Core::System& system, Handle* out_write, Handle* out_read) {
2353 LOG_DEBUG(Kernel_SVC, "called"); 2349 LOG_DEBUG(Kernel_SVC, "called");
2354 2350
2355 // Get the kernel reference and handle table. 2351 // Get the kernel reference and handle table.
@@ -2394,11 +2390,11 @@ static ResultCode CreateEvent(Core::System& system, Handle* out_write, Handle* o
2394 return ResultSuccess; 2390 return ResultSuccess;
2395} 2391}
2396 2392
2397static ResultCode CreateEvent32(Core::System& system, Handle* out_write, Handle* out_read) { 2393static Result CreateEvent32(Core::System& system, Handle* out_write, Handle* out_read) {
2398 return CreateEvent(system, out_write, out_read); 2394 return CreateEvent(system, out_write, out_read);
2399} 2395}
2400 2396
2401static ResultCode GetProcessInfo(Core::System& system, u64* out, Handle process_handle, u32 type) { 2397static Result GetProcessInfo(Core::System& system, u64* out, Handle process_handle, u32 type) {
2402 LOG_DEBUG(Kernel_SVC, "called, handle=0x{:08X}, type=0x{:X}", process_handle, type); 2398 LOG_DEBUG(Kernel_SVC, "called, handle=0x{:08X}, type=0x{:X}", process_handle, type);
2403 2399
2404 // This function currently only allows retrieving a process' status. 2400 // This function currently only allows retrieving a process' status.
@@ -2424,7 +2420,7 @@ static ResultCode GetProcessInfo(Core::System& system, u64* out, Handle process_
2424 return ResultSuccess; 2420 return ResultSuccess;
2425} 2421}
2426 2422
2427static ResultCode CreateResourceLimit(Core::System& system, Handle* out_handle) { 2423static Result CreateResourceLimit(Core::System& system, Handle* out_handle) {
2428 LOG_DEBUG(Kernel_SVC, "called"); 2424 LOG_DEBUG(Kernel_SVC, "called");
2429 2425
2430 // Create a new resource limit. 2426 // Create a new resource limit.
@@ -2447,9 +2443,8 @@ static ResultCode CreateResourceLimit(Core::System& system, Handle* out_handle)
2447 return ResultSuccess; 2443 return ResultSuccess;
2448} 2444}
2449 2445
2450static ResultCode GetResourceLimitLimitValue(Core::System& system, u64* out_limit_value, 2446static Result GetResourceLimitLimitValue(Core::System& system, u64* out_limit_value,
2451 Handle resource_limit_handle, 2447 Handle resource_limit_handle, LimitableResource which) {
2452 LimitableResource which) {
2453 LOG_DEBUG(Kernel_SVC, "called, resource_limit_handle={:08X}, which={}", resource_limit_handle, 2448 LOG_DEBUG(Kernel_SVC, "called, resource_limit_handle={:08X}, which={}", resource_limit_handle,
2454 which); 2449 which);
2455 2450
@@ -2468,9 +2463,8 @@ static ResultCode GetResourceLimitLimitValue(Core::System& system, u64* out_limi
2468 return ResultSuccess; 2463 return ResultSuccess;
2469} 2464}
2470 2465
2471static ResultCode GetResourceLimitCurrentValue(Core::System& system, u64* out_current_value, 2466static Result GetResourceLimitCurrentValue(Core::System& system, u64* out_current_value,
2472 Handle resource_limit_handle, 2467 Handle resource_limit_handle, LimitableResource which) {
2473 LimitableResource which) {
2474 LOG_DEBUG(Kernel_SVC, "called, resource_limit_handle={:08X}, which={}", resource_limit_handle, 2468 LOG_DEBUG(Kernel_SVC, "called, resource_limit_handle={:08X}, which={}", resource_limit_handle,
2475 which); 2469 which);
2476 2470
@@ -2489,8 +2483,8 @@ static ResultCode GetResourceLimitCurrentValue(Core::System& system, u64* out_cu
2489 return ResultSuccess; 2483 return ResultSuccess;
2490} 2484}
2491 2485
2492static ResultCode SetResourceLimitLimitValue(Core::System& system, Handle resource_limit_handle, 2486static Result SetResourceLimitLimitValue(Core::System& system, Handle resource_limit_handle,
2493 LimitableResource which, u64 limit_value) { 2487 LimitableResource which, u64 limit_value) {
2494 LOG_DEBUG(Kernel_SVC, "called, resource_limit_handle={:08X}, which={}, limit_value={}", 2488 LOG_DEBUG(Kernel_SVC, "called, resource_limit_handle={:08X}, which={}, limit_value={}",
2495 resource_limit_handle, which, limit_value); 2489 resource_limit_handle, which, limit_value);
2496 2490
@@ -2509,8 +2503,8 @@ static ResultCode SetResourceLimitLimitValue(Core::System& system, Handle resour
2509 return ResultSuccess; 2503 return ResultSuccess;
2510} 2504}
2511 2505
2512static ResultCode GetProcessList(Core::System& system, u32* out_num_processes, 2506static Result GetProcessList(Core::System& system, u32* out_num_processes, VAddr out_process_ids,
2513 VAddr out_process_ids, u32 out_process_ids_size) { 2507 u32 out_process_ids_size) {
2514 LOG_DEBUG(Kernel_SVC, "called. out_process_ids=0x{:016X}, out_process_ids_size={}", 2508 LOG_DEBUG(Kernel_SVC, "called. out_process_ids=0x{:016X}, out_process_ids_size={}",
2515 out_process_ids, out_process_ids_size); 2509 out_process_ids, out_process_ids_size);
2516 2510
@@ -2546,8 +2540,8 @@ static ResultCode GetProcessList(Core::System& system, u32* out_num_processes,
2546 return ResultSuccess; 2540 return ResultSuccess;
2547} 2541}
2548 2542
2549static ResultCode GetThreadList(Core::System& system, u32* out_num_threads, VAddr out_thread_ids, 2543static Result GetThreadList(Core::System& system, u32* out_num_threads, VAddr out_thread_ids,
2550 u32 out_thread_ids_size, Handle debug_handle) { 2544 u32 out_thread_ids_size, Handle debug_handle) {
2551 // TODO: Handle this case when debug events are supported. 2545 // TODO: Handle this case when debug events are supported.
2552 UNIMPLEMENTED_IF(debug_handle != InvalidHandle); 2546 UNIMPLEMENTED_IF(debug_handle != InvalidHandle);
2553 2547
@@ -2586,9 +2580,9 @@ static ResultCode GetThreadList(Core::System& system, u32* out_num_threads, VAdd
2586 return ResultSuccess; 2580 return ResultSuccess;
2587} 2581}
2588 2582
2589static ResultCode FlushProcessDataCache32([[maybe_unused]] Core::System& system, 2583static Result FlushProcessDataCache32([[maybe_unused]] Core::System& system,
2590 [[maybe_unused]] Handle handle, 2584 [[maybe_unused]] Handle handle, [[maybe_unused]] u32 address,
2591 [[maybe_unused]] u32 address, [[maybe_unused]] u32 size) { 2585 [[maybe_unused]] u32 size) {
2592 // Note(Blinkhawk): For emulation purposes of the data cache this is mostly a no-op, 2586 // Note(Blinkhawk): For emulation purposes of the data cache this is mostly a no-op,
2593 // as all emulation is done in the same cache level in host architecture, thus data cache 2587 // as all emulation is done in the same cache level in host architecture, thus data cache
2594 // does not need flushing. 2588 // does not need flushing.