mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:17:44 +00:00
Kernel: Migrate process list locking to ProtectedValue
The existing recursive spinlock is repurposed for profiling only, as it was shared with the process list.
This commit is contained in:
parent
8554b66d09
commit
08891e82a5
5 changed files with 76 additions and 86 deletions
|
@ -65,8 +65,7 @@ KResult Process::do_killall(int signal)
|
|||
KResult error = KSuccess;
|
||||
|
||||
// Send the signal to all processes we have access to for.
|
||||
ScopedSpinLock lock(g_processes_lock);
|
||||
for (auto& process : processes()) {
|
||||
processes().for_each_shared([&](auto& process) {
|
||||
KResult res = KSuccess;
|
||||
if (process.pid() == pid())
|
||||
res = do_killself(signal);
|
||||
|
@ -77,7 +76,7 @@ KResult Process::do_killall(int signal)
|
|||
any_succeeded = true;
|
||||
else
|
||||
error = res;
|
||||
}
|
||||
});
|
||||
|
||||
if (any_succeeded)
|
||||
return KSuccess;
|
||||
|
@ -117,7 +116,6 @@ KResultOr<FlatPtr> Process::sys$kill(pid_t pid_or_pgid, int signal)
|
|||
return do_killself(signal);
|
||||
}
|
||||
VERIFY(pid_or_pgid >= 0);
|
||||
ScopedSpinLock lock(g_processes_lock);
|
||||
auto peer = Process::from_pid(pid_or_pgid);
|
||||
if (!peer)
|
||||
return ESRCH;
|
||||
|
|
|
@ -31,7 +31,7 @@ KResultOr<FlatPtr> Process::sys$profiling_enable(pid_t pid, u64 event_mask)
|
|||
else
|
||||
g_global_perf_events = PerformanceEventBuffer::try_create_with_size(32 * MiB).leak_ptr();
|
||||
|
||||
ScopedSpinLock lock(g_processes_lock);
|
||||
ScopedSpinLock lock(g_profiling_lock);
|
||||
if (!TimeManagement::the().enable_profile_timer())
|
||||
return ENOTSUP;
|
||||
g_profiling_all_threads = true;
|
||||
|
@ -44,7 +44,6 @@ KResultOr<FlatPtr> Process::sys$profiling_enable(pid_t pid, u64 event_mask)
|
|||
return 0;
|
||||
}
|
||||
|
||||
ScopedSpinLock lock(g_processes_lock);
|
||||
auto process = Process::from_pid(pid);
|
||||
if (!process)
|
||||
return ESRCH;
|
||||
|
@ -52,6 +51,7 @@ KResultOr<FlatPtr> Process::sys$profiling_enable(pid_t pid, u64 event_mask)
|
|||
return ESRCH;
|
||||
if (!is_superuser() && process->uid() != euid())
|
||||
return EPERM;
|
||||
ScopedSpinLock lock(g_profiling_lock);
|
||||
g_profiling_event_mask = PERF_EVENT_PROCESS_CREATE | PERF_EVENT_THREAD_CREATE | PERF_EVENT_MMAP;
|
||||
process->set_profiling(true);
|
||||
if (!process->create_perf_events_buffer_if_needed()) {
|
||||
|
@ -81,12 +81,12 @@ KResultOr<FlatPtr> Process::sys$profiling_disable(pid_t pid)
|
|||
return 0;
|
||||
}
|
||||
|
||||
ScopedSpinLock lock(g_processes_lock);
|
||||
auto process = Process::from_pid(pid);
|
||||
if (!process)
|
||||
return ESRCH;
|
||||
if (!is_superuser() && process->uid() != euid())
|
||||
return EPERM;
|
||||
ScopedSpinLock lock(g_profiling_lock);
|
||||
if (!process->is_profiling())
|
||||
return EINVAL;
|
||||
// FIXME: If we enabled the profile timer and it's not supported, how do we disable it now?
|
||||
|
@ -117,12 +117,12 @@ KResultOr<FlatPtr> Process::sys$profiling_free_buffer(pid_t pid)
|
|||
return 0;
|
||||
}
|
||||
|
||||
ScopedSpinLock lock(g_processes_lock);
|
||||
auto process = Process::from_pid(pid);
|
||||
if (!process)
|
||||
return ESRCH;
|
||||
if (!is_superuser() && process->uid() != euid())
|
||||
return EPERM;
|
||||
ScopedSpinLock lock(g_profiling_lock);
|
||||
if (process->is_profiling())
|
||||
return EINVAL;
|
||||
process->delete_perf_events_buffer();
|
||||
|
|
|
@ -16,7 +16,6 @@ KResultOr<FlatPtr> Process::sys$getsid(pid_t pid)
|
|||
REQUIRE_PROMISE(proc);
|
||||
if (pid == 0)
|
||||
return sid().value();
|
||||
ScopedSpinLock lock(g_processes_lock);
|
||||
auto process = Process::from_pid(pid);
|
||||
if (!process)
|
||||
return ESRCH;
|
||||
|
@ -51,7 +50,6 @@ KResultOr<FlatPtr> Process::sys$getpgid(pid_t pid)
|
|||
REQUIRE_PROMISE(proc);
|
||||
if (pid == 0)
|
||||
return pgid().value();
|
||||
ScopedSpinLock lock(g_processes_lock); // FIXME: Use a ProcessHandle
|
||||
auto process = Process::from_pid(pid);
|
||||
if (!process)
|
||||
return ESRCH;
|
||||
|
@ -68,7 +66,6 @@ KResultOr<FlatPtr> Process::sys$getpgrp()
|
|||
SessionID Process::get_sid_from_pgid(ProcessGroupID pgid)
|
||||
{
|
||||
// FIXME: This xor sys$setsid() uses the wrong locking mechanism.
|
||||
ScopedSpinLock lock(g_processes_lock);
|
||||
|
||||
SessionID sid { -1 };
|
||||
Process::for_each_in_pgrp(pgid, [&](auto& process) {
|
||||
|
@ -83,7 +80,7 @@ KResultOr<FlatPtr> Process::sys$setpgid(pid_t specified_pid, pid_t specified_pgi
|
|||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||
REQUIRE_PROMISE(proc);
|
||||
ScopedSpinLock lock(g_processes_lock); // FIXME: Use a ProcessHandle
|
||||
// FIXME: Use a ProcessHandle
|
||||
ProcessID pid = specified_pid ? ProcessID(specified_pid) : this->pid();
|
||||
if (specified_pgid < 0) {
|
||||
// The value of the pgid argument is less than 0, or is not a value supported by the implementation.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue