1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 23:47:45 +00:00

Kernel: Remove ProcessInspectionHandle and make Process RefCounted

By making the Process class RefCounted we don't really need
ProcessInspectionHandle anymore. This also fixes some race
conditions where a Process may be deleted while still being
used by ProcFS.

Also make sure to acquire the Process' lock when accessing
regions.

Last but not least, there's no reason why a thread can't be
scheduled while being inspected, though in practice it won't
happen anyway because the scheduler lock is held at the same
time.
This commit is contained in:
Tom 2020-08-01 20:04:56 -06:00 committed by Andreas Kling
parent 5bbf6ed46b
commit 538b985487
13 changed files with 191 additions and 273 deletions

View file

@ -139,7 +139,7 @@ int Process::sys$kill(pid_t pid, int signal)
return do_killself(signal);
}
ScopedSpinLock lock(g_processes_lock);
auto* peer = Process::from_pid(pid);
auto peer = Process::from_pid(pid);
if (!peer)
return -ESRCH;
return do_kill(*peer, signal);

View file

@ -33,7 +33,7 @@ int Process::sys$profiling_enable(pid_t pid)
{
REQUIRE_NO_PROMISES;
ScopedSpinLock lock(g_processes_lock);
auto* process = Process::from_pid(pid);
auto process = Process::from_pid(pid);
if (!process)
return -ESRCH;
if (process->is_dead())
@ -48,7 +48,7 @@ int Process::sys$profiling_enable(pid_t pid)
int Process::sys$profiling_disable(pid_t pid)
{
ScopedSpinLock lock(g_processes_lock);
auto* process = Process::from_pid(pid);
auto process = Process::from_pid(pid);
if (!process)
return -ESRCH;
if (!is_superuser() && process->uid() != m_uid)

View file

@ -121,7 +121,7 @@ int Process::sys$set_process_boost(pid_t pid, int amount)
if (amount < 0 || amount > 20)
return -EINVAL;
ScopedSpinLock lock(g_processes_lock);
auto* process = Process::from_pid(pid);
auto process = Process::from_pid(pid);
if (!process || process->is_dead())
return -ESRCH;
if (!is_superuser() && process->uid() != euid())

View file

@ -35,7 +35,7 @@ pid_t Process::sys$getsid(pid_t pid)
if (pid == 0)
return m_sid;
ScopedSpinLock lock(g_processes_lock);
auto* process = Process::from_pid(pid);
auto process = Process::from_pid(pid);
if (!process)
return -ESRCH;
if (m_sid != process->m_sid)
@ -66,7 +66,7 @@ pid_t Process::sys$getpgid(pid_t pid)
if (pid == 0)
return m_pgid;
ScopedSpinLock lock(g_processes_lock); // FIXME: Use a ProcessHandle
auto* process = Process::from_pid(pid);
auto process = Process::from_pid(pid);
if (!process)
return -ESRCH;
return process->m_pgid;
@ -81,7 +81,7 @@ pid_t Process::sys$getpgrp()
static pid_t get_sid_from_pgid(pid_t pgid)
{
ScopedSpinLock lock(g_processes_lock);
auto* group_leader = Process::from_pid(pgid);
auto group_leader = Process::from_pid(pgid);
if (!group_leader)
return -1;
return group_leader->sid();
@ -96,7 +96,7 @@ int Process::sys$setpgid(pid_t specified_pid, pid_t specified_pgid)
// The value of the pgid argument is less than 0, or is not a value supported by the implementation.
return -EINVAL;
}
auto* process = Process::from_pid(pid);
auto process = Process::from_pid(pid);
if (!process)
return -ESRCH;
if (process != this && process->ppid() != m_pid) {

View file

@ -81,7 +81,7 @@ int Process::sys$shbuf_allow_pid(int shbuf_id, pid_t peer_pid)
return -EPERM;
{
ScopedSpinLock lock(g_processes_lock);
auto* peer = Process::from_pid(peer_pid);
auto peer = Process::from_pid(peer_pid);
if (!peer)
return -ESRCH;
}

View file

@ -54,7 +54,7 @@ KResultOr<siginfo_t> Process::do_waitid(idtype_t idtype, int id, int options)
ScopedSpinLock lock(g_processes_lock);
// NOTE: If waitee was -1, m_waitee_pid will have been filled in by the scheduler.
Process* waitee_process = Process::from_pid(waitee_pid);
auto waitee_process = Process::from_pid(waitee_pid);
if (!waitee_process)
return KResult(-ECHILD);