From 1e2ef59965eef56b8ccb3f1b534bf60470995425 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 4 Apr 2023 08:08:31 +0200 Subject: [PATCH] Kernel: Move Process's process group pointer into protected data Now that it's no longer using LockRefPtr, we can actually move it into protected data. (LockRefPtr couldn't be stored there because protected data is immutable at times, and LockRefPtr uses some of its own bits for locking.) --- Kernel/Process.h | 5 ++--- Kernel/Syscalls/fork.cpp | 5 +---- Kernel/Syscalls/setpgid.cpp | 8 ++++---- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/Kernel/Process.h b/Kernel/Process.h index 6916b18ed5..89ffd42e26 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -117,6 +117,7 @@ class Process final SessionID sid { 0 }; // FIXME: This should be a NonnullRefPtr RefPtr credentials; + RefPtr process_group; bool dumpable { false }; bool executable_is_setid { false }; Atomic has_promises { false }; @@ -238,7 +239,7 @@ public: bool is_session_leader() const { return sid().value() == pid().value(); } ProcessGroupID pgid() const { - return m_pg.with([&](auto& pg) { return pg ? pg->pgid() : 0; }); + return with_protected_data([](auto& protected_data) { return protected_data.process_group ? protected_data.process_group->pgid() : 0; }); } bool is_group_leader() const { return pgid().value() == pid().value(); } ProcessID ppid() const @@ -681,8 +682,6 @@ private: SpinlockProtected, LockRank::None> m_space; - SpinlockProtected, LockRank::None> m_pg; - RecursiveSpinlock mutable m_protected_data_lock; AtomicEdgeAction m_protected_data_refs; void protect_data(); diff --git a/Kernel/Syscalls/fork.cpp b/Kernel/Syscalls/fork.cpp index 8fcd8171ac..22b20a13b8 100644 --- a/Kernel/Syscalls/fork.cpp +++ b/Kernel/Syscalls/fork.cpp @@ -97,10 +97,6 @@ ErrorOr Process::sys$fork(RegisterState& regs) }); })); - child->m_pg.with([&](auto& child_pg) { - child_pg = m_pg.with([&](auto& pg) { return pg; }); - }); - with_protected_data([&](auto& my_protected_data) { child->with_mutable_protected_data([&](auto& child_protected_data) { child_protected_data.promises = my_protected_data.promises.load(); @@ -112,6 +108,7 @@ ErrorOr Process::sys$fork(RegisterState& regs) child_protected_data.umask = my_protected_data.umask; child_protected_data.signal_trampoline = my_protected_data.signal_trampoline; child_protected_data.dumpable = my_protected_data.dumpable; + child_protected_data.process_group = my_protected_data.process_group; }); }); diff --git a/Kernel/Syscalls/setpgid.cpp b/Kernel/Syscalls/setpgid.cpp index c331f39085..e23109743d 100644 --- a/Kernel/Syscalls/setpgid.cpp +++ b/Kernel/Syscalls/setpgid.cpp @@ -38,9 +38,9 @@ ErrorOr Process::sys$setsid() // Create a new Session and a new ProcessGroup. auto process_group = TRY(ProcessGroup::create(ProcessGroupID(pid().value()))); - m_pg.with([&](auto& pg) { pg = move(process_group); }); m_tty.with([](auto& tty) { tty = nullptr; }); return with_mutable_protected_data([&](auto& protected_data) -> ErrorOr { + protected_data.process_group = move(process_group); protected_data.sid = pid().value(); return protected_data.sid.value(); }); @@ -120,9 +120,8 @@ ErrorOr Process::sys$setpgid(pid_t specified_pid, pid_t specified_pgid) } // FIXME: There are more EPERM conditions to check for here.. auto process_group = TRY(ProcessGroup::find_or_create(new_pgid)); - process->m_pg.with([&](auto& pg) { pg = move(process_group); }); - return with_mutable_protected_data([&](auto& protected_data) -> ErrorOr { - auto credentials = this->credentials(); + return process->with_mutable_protected_data([&process, &process_group, new_sid, new_pgid](auto& protected_data) -> ErrorOr { + auto credentials = process->credentials(); auto new_credentials = TRY(Credentials::create( credentials->uid(), @@ -136,6 +135,7 @@ ErrorOr Process::sys$setpgid(pid_t specified_pid, pid_t specified_pgid) new_pgid)); protected_data.credentials = move(new_credentials); + protected_data.process_group = move(process_group); return 0; }); }