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.cpp33
1 files changed, 23 insertions, 10 deletions
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index bcc9864f3..030333077 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -364,20 +364,33 @@ static ResultCode GetThreadId(u64* thread_id, Handle thread_handle) {
364 return RESULT_SUCCESS; 364 return RESULT_SUCCESS;
365} 365}
366 366
367/// Get the ID of the specified process 367/// Gets the ID of the specified process or a specified thread's owning process.
368static ResultCode GetProcessId(u64* process_id, Handle process_handle) { 368static ResultCode GetProcessId(u64* process_id, Handle handle) {
369 LOG_TRACE(Kernel_SVC, "called process=0x{:08X}", process_handle); 369 LOG_DEBUG(Kernel_SVC, "called handle=0x{:08X}", handle);
370 370
371 const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); 371 const auto& handle_table = Core::CurrentProcess()->GetHandleTable();
372 const SharedPtr<Process> process = handle_table.Get<Process>(process_handle); 372 const SharedPtr<Process> process = handle_table.Get<Process>(handle);
373 if (!process) { 373 if (process) {
374 LOG_ERROR(Kernel_SVC, "Process handle does not exist, process_handle=0x{:08X}", 374 *process_id = process->GetProcessID();
375 process_handle); 375 return RESULT_SUCCESS;
376 return ERR_INVALID_HANDLE;
377 } 376 }
378 377
379 *process_id = process->GetProcessID(); 378 const SharedPtr<Thread> thread = handle_table.Get<Thread>(handle);
380 return RESULT_SUCCESS; 379 if (thread) {
380 const Process* const owner_process = thread->GetOwnerProcess();
381 if (!owner_process) {
382 LOG_ERROR(Kernel_SVC, "Non-existent owning process encountered.");
383 return ERR_INVALID_HANDLE;
384 }
385
386 *process_id = owner_process->GetProcessID();
387 return RESULT_SUCCESS;
388 }
389
390 // NOTE: This should also handle debug objects before returning.
391
392 LOG_ERROR(Kernel_SVC, "Handle does not exist, handle=0x{:08X}", handle);
393 return ERR_INVALID_HANDLE;
381} 394}
382 395
383/// Default thread wakeup callback for WaitSynchronization 396/// Default thread wakeup callback for WaitSynchronization