Date: Thu, 9 Jul 2020 10:52:02 +0000 (UTC) From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r363039 - stable/12/sys/compat/linuxkpi/common/src Message-ID: <202007091052.069Aq2m8069338@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kib Date: Thu Jul 9 10:52:02 2020 New Revision: 363039 URL: https://svnweb.freebsd.org/changeset/base/363039 Log: MFC r362886: linuxkpi: improvements for linux_pid_task() and linux_get_pid_task(). Modified: stable/12/sys/compat/linuxkpi/common/src/linux_current.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/compat/linuxkpi/common/src/linux_current.c ============================================================================== --- stable/12/sys/compat/linuxkpi/common/src/linux_current.c Thu Jul 9 10:50:06 2020 (r363038) +++ stable/12/sys/compat/linuxkpi/common/src/linux_current.c Thu Jul 9 10:52:02 2020 (r363039) @@ -155,65 +155,52 @@ linuxkpi_thread_dtor(void *arg __unused, struct thread put_task_struct(ts); } -struct task_struct * -linux_pid_task(pid_t pid) +static struct task_struct * +linux_get_pid_task_int(pid_t pid, const bool do_get) { struct thread *td; struct proc *p; + struct task_struct *ts; - /* try to find corresponding thread */ - td = tdfind(pid, -1); - if (td != NULL) { - struct task_struct *ts = td->td_lkpi_task; - PROC_UNLOCK(td->td_proc); - return (ts); - } - - /* try to find corresponding procedure */ - p = pfind(pid); - if (p != NULL) { - FOREACH_THREAD_IN_PROC(p, td) { - struct task_struct *ts = td->td_lkpi_task; - if (ts != NULL) { - PROC_UNLOCK(p); - return (ts); + if (pid > PID_MAX) { + /* try to find corresponding thread */ + td = tdfind(pid, -1); + if (td != NULL) { + ts = td->td_lkpi_task; + if (do_get && ts != NULL) + get_task_struct(ts); + PROC_UNLOCK(td->td_proc); + return (ts); + } + } else { + /* try to find corresponding procedure */ + p = pfind(pid); + if (p != NULL) { + FOREACH_THREAD_IN_PROC(p, td) { + ts = td->td_lkpi_task; + if (ts != NULL) { + if (do_get) + get_task_struct(ts); + PROC_UNLOCK(p); + return (ts); + } } + PROC_UNLOCK(p); } - PROC_UNLOCK(p); } return (NULL); } struct task_struct * -linux_get_pid_task(pid_t pid) +linux_pid_task(pid_t pid) { - struct thread *td; - struct proc *p; + return (linux_get_pid_task_int(pid, false)); +} - /* try to find corresponding thread */ - td = tdfind(pid, -1); - if (td != NULL) { - struct task_struct *ts = td->td_lkpi_task; - if (ts != NULL) - get_task_struct(ts); - PROC_UNLOCK(td->td_proc); - return (ts); - } - - /* try to find corresponding procedure */ - p = pfind(pid); - if (p != NULL) { - FOREACH_THREAD_IN_PROC(p, td) { - struct task_struct *ts = td->td_lkpi_task; - if (ts != NULL) { - get_task_struct(ts); - PROC_UNLOCK(p); - return (ts); - } - } - PROC_UNLOCK(p); - } - return (NULL); +struct task_struct * +linux_get_pid_task(pid_t pid) +{ + return (linux_get_pid_task_int(pid, true)); } bool
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202007091052.069Aq2m8069338>