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.)
This commit is contained in:
Andreas Kling 2023-04-04 08:08:31 +02:00
parent 1c77803845
commit 1e2ef59965
3 changed files with 7 additions and 11 deletions

View file

@ -117,6 +117,7 @@ class Process final
SessionID sid { 0 };
// FIXME: This should be a NonnullRefPtr
RefPtr<Credentials> credentials;
RefPtr<ProcessGroup> process_group;
bool dumpable { false };
bool executable_is_setid { false };
Atomic<bool> 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<OwnPtr<Memory::AddressSpace>, LockRank::None> m_space;
SpinlockProtected<RefPtr<ProcessGroup>, LockRank::None> m_pg;
RecursiveSpinlock<LockRank::None> mutable m_protected_data_lock;
AtomicEdgeAction<u32> m_protected_data_refs;
void protect_data();

View file

@ -97,10 +97,6 @@ ErrorOr<FlatPtr> 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<FlatPtr> 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;
});
});

View file

@ -38,9 +38,9 @@ ErrorOr<FlatPtr> 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<FlatPtr> {
protected_data.process_group = move(process_group);
protected_data.sid = pid().value();
return protected_data.sid.value();
});
@ -120,9 +120,8 @@ ErrorOr<FlatPtr> 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<FlatPtr> {
auto credentials = this->credentials();
return process->with_mutable_protected_data([&process, &process_group, new_sid, new_pgid](auto& protected_data) -> ErrorOr<FlatPtr> {
auto credentials = process->credentials();
auto new_credentials = TRY(Credentials::create(
credentials->uid(),
@ -136,6 +135,7 @@ ErrorOr<FlatPtr> 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;
});
}