summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/svc.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2018-12-21 13:45:27 -0500
committerGravatar GitHub2018-12-21 13:45:27 -0500
commit59ac3346ebe605bfb0f538d9fa045b32d86168cb (patch)
treed2793ede352840b4326cc7c56fc8e7b7a3e6670f /src/core/hle/kernel/svc.cpp
parentMerge pull request #1914 from lioncash/id (diff)
parentkernel/svc: Handle thread handles within GetProcessId (diff)
downloadyuzu-59ac3346ebe605bfb0f538d9fa045b32d86168cb.tar.gz
yuzu-59ac3346ebe605bfb0f538d9fa045b32d86168cb.tar.xz
yuzu-59ac3346ebe605bfb0f538d9fa045b32d86168cb.zip
Merge pull request #1925 from lioncash/pid
kernel/{process, thread}: Amend behavior related to IDs
Diffstat (limited to 'src/core/hle/kernel/svc.cpp')
-rw-r--r--src/core/hle/kernel/svc.cpp35
1 files changed, 24 insertions, 11 deletions
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index c826dfd96..28268e112 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -391,7 +391,7 @@ static ResultCode SendSyncRequest(Handle handle) {
391} 391}
392 392
393/// Get the ID for the specified thread. 393/// Get the ID for the specified thread.
394static ResultCode GetThreadId(u32* thread_id, Handle thread_handle) { 394static ResultCode GetThreadId(u64* thread_id, Handle thread_handle) {
395 LOG_TRACE(Kernel_SVC, "called thread=0x{:08X}", thread_handle); 395 LOG_TRACE(Kernel_SVC, "called thread=0x{:08X}", thread_handle);
396 396
397 const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); 397 const auto& handle_table = Core::CurrentProcess()->GetHandleTable();
@@ -405,20 +405,33 @@ static ResultCode GetThreadId(u32* thread_id, Handle thread_handle) {
405 return RESULT_SUCCESS; 405 return RESULT_SUCCESS;
406} 406}
407 407
408/// Get the ID of the specified process 408/// Gets the ID of the specified process or a specified thread's owning process.
409static ResultCode GetProcessId(u32* process_id, Handle process_handle) { 409static ResultCode GetProcessId(u64* process_id, Handle handle) {
410 LOG_TRACE(Kernel_SVC, "called process=0x{:08X}", process_handle); 410 LOG_DEBUG(Kernel_SVC, "called handle=0x{:08X}", handle);
411 411
412 const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); 412 const auto& handle_table = Core::CurrentProcess()->GetHandleTable();
413 const SharedPtr<Process> process = handle_table.Get<Process>(process_handle); 413 const SharedPtr<Process> process = handle_table.Get<Process>(handle);
414 if (!process) { 414 if (process) {
415 LOG_ERROR(Kernel_SVC, "Process handle does not exist, process_handle=0x{:08X}", 415 *process_id = process->GetProcessID();
416 process_handle); 416 return RESULT_SUCCESS;
417 return ERR_INVALID_HANDLE;
418 } 417 }
419 418
420 *process_id = process->GetProcessID(); 419 const SharedPtr<Thread> thread = handle_table.Get<Thread>(handle);
421 return RESULT_SUCCESS; 420 if (thread) {
421 const Process* const owner_process = thread->GetOwnerProcess();
422 if (!owner_process) {
423 LOG_ERROR(Kernel_SVC, "Non-existent owning process encountered.");
424 return ERR_INVALID_HANDLE;
425 }
426
427 *process_id = owner_process->GetProcessID();
428 return RESULT_SUCCESS;
429 }
430
431 // NOTE: This should also handle debug objects before returning.
432
433 LOG_ERROR(Kernel_SVC, "Handle does not exist, handle=0x{:08X}", handle);
434 return ERR_INVALID_HANDLE;
422} 435}
423 436
424/// Default thread wakeup callback for WaitSynchronization 437/// Default thread wakeup callback for WaitSynchronization