diff options
author | bunnei <bunneidev@gmail.com> | 2018-12-21 19:45:27 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-21 19:45:27 +0100 |
commit | 59ac3346ebe605bfb0f538d9fa045b32d86168cb (patch) | |
tree | d2793ede352840b4326cc7c56fc8e7b7a3e6670f /src/core/hle/kernel/svc.cpp | |
parent | Merge pull request #1914 from lioncash/id (diff) | |
parent | kernel/svc: Handle thread handles within GetProcessId (diff) | |
download | yuzu-59ac3346ebe605bfb0f538d9fa045b32d86168cb.tar yuzu-59ac3346ebe605bfb0f538d9fa045b32d86168cb.tar.gz yuzu-59ac3346ebe605bfb0f538d9fa045b32d86168cb.tar.bz2 yuzu-59ac3346ebe605bfb0f538d9fa045b32d86168cb.tar.lz yuzu-59ac3346ebe605bfb0f538d9fa045b32d86168cb.tar.xz yuzu-59ac3346ebe605bfb0f538d9fa045b32d86168cb.tar.zst yuzu-59ac3346ebe605bfb0f538d9fa045b32d86168cb.zip |
Diffstat (limited to 'src/core/hle/kernel/svc.cpp')
-rw-r--r-- | src/core/hle/kernel/svc.cpp | 35 |
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) { } /// Get the ID for the specified thread. -static ResultCode GetThreadId(u32* thread_id, Handle thread_handle) { +static ResultCode GetThreadId(u64* thread_id, Handle thread_handle) { LOG_TRACE(Kernel_SVC, "called thread=0x{:08X}", thread_handle); const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); @@ -405,20 +405,33 @@ static ResultCode GetThreadId(u32* thread_id, Handle thread_handle) { return RESULT_SUCCESS; } -/// Get the ID of the specified process -static ResultCode GetProcessId(u32* process_id, Handle process_handle) { - LOG_TRACE(Kernel_SVC, "called process=0x{:08X}", process_handle); +/// Gets the ID of the specified process or a specified thread's owning process. +static ResultCode GetProcessId(u64* process_id, Handle handle) { + LOG_DEBUG(Kernel_SVC, "called handle=0x{:08X}", handle); const auto& handle_table = Core::CurrentProcess()->GetHandleTable(); - const SharedPtr<Process> process = handle_table.Get<Process>(process_handle); - if (!process) { - LOG_ERROR(Kernel_SVC, "Process handle does not exist, process_handle=0x{:08X}", - process_handle); - return ERR_INVALID_HANDLE; + const SharedPtr<Process> process = handle_table.Get<Process>(handle); + if (process) { + *process_id = process->GetProcessID(); + return RESULT_SUCCESS; } - *process_id = process->GetProcessID(); - return RESULT_SUCCESS; + const SharedPtr<Thread> thread = handle_table.Get<Thread>(handle); + if (thread) { + const Process* const owner_process = thread->GetOwnerProcess(); + if (!owner_process) { + LOG_ERROR(Kernel_SVC, "Non-existent owning process encountered."); + return ERR_INVALID_HANDLE; + } + + *process_id = owner_process->GetProcessID(); + return RESULT_SUCCESS; + } + + // NOTE: This should also handle debug objects before returning. + + LOG_ERROR(Kernel_SVC, "Handle does not exist, handle=0x{:08X}", handle); + return ERR_INVALID_HANDLE; } /// Default thread wakeup callback for WaitSynchronization |