summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Lioncash2018-12-18 23:09:08 -0500
committerGravatar Lioncash2018-12-19 12:16:15 -0500
commitb74eb88c68e85d08695667eaf4603bb565c8eb64 (patch)
treec77772e3f471ecf327cdce440fe49c1df81be84d /src
parentkernel/kernel: Use correct initial PID for userland Process instances (diff)
downloadyuzu-b74eb88c68e85d08695667eaf4603bb565c8eb64.tar.gz
yuzu-b74eb88c68e85d08695667eaf4603bb565c8eb64.tar.xz
yuzu-b74eb88c68e85d08695667eaf4603bb565c8eb64.zip
kernel/svc: Handle thread handles within GetProcessId
If a thread handle is passed to svcGetProcessId, the kernel attempts to access the process ID via the thread's instance's owning process. Technically, this function should also be handling the kernel debug objects as well, however we currently don't handle those kernel objects yet, so I've left a note via a comment about it to remind myself when implementing it in the future.
Diffstat (limited to 'src')
-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