From 3a55a1b592d816d44de12c5bdd40e1e1f9adc01e Mon Sep 17 00:00:00 2001 From: Liav A Date: Sat, 9 Sep 2023 18:12:49 +0300 Subject: [PATCH] Kernel: Use Process::get_thread_from_thread_list in Syscalls/thread.cpp Some syscalls could be simplified by using the non-static method Process::get_thread_from_thread_list which should ensure that the specified tid is of a Thread in the same Process of the current Thread. --- Kernel/Syscalls/thread.cpp | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/Kernel/Syscalls/thread.cpp b/Kernel/Syscalls/thread.cpp index ac67899f31..1567c6d43d 100644 --- a/Kernel/Syscalls/thread.cpp +++ b/Kernel/Syscalls/thread.cpp @@ -125,10 +125,7 @@ ErrorOr Process::sys$detach_thread(pid_t tid) { VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this); TRY(require_promise(Pledge::thread)); - auto thread = Thread::from_tid(tid); - if (!thread || thread->pid() != pid()) - return ESRCH; - + auto thread = TRY(get_thread_from_thread_list(tid)); if (!thread->is_joinable()) return EINVAL; @@ -141,10 +138,7 @@ ErrorOr Process::sys$join_thread(pid_t tid, Userspace exit_valu VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this); TRY(require_promise(Pledge::thread)); - auto thread = Thread::from_tid(tid); - if (!thread || thread->pid() != pid()) - return ESRCH; - + auto thread = TRY(get_thread_from_thread_list(tid)); auto* current_thread = Thread::current(); if (thread == current_thread) return EDEADLK; @@ -179,10 +173,7 @@ ErrorOr Process::sys$kill_thread(pid_t tid, int signal) if (signal < 0 || signal >= NSIG) return EINVAL; - auto thread = Thread::from_tid(tid); - if (!thread || thread->pid() != pid()) - return ESRCH; - + auto thread = TRY(get_thread_from_thread_list(tid)); if (signal != 0) thread->send_signal(signal, &Process::current());