Explorar o código

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.)
Andreas Kling %!s(int64=2) %!d(string=hai) anos
pai
achega
1e2ef59965
Modificáronse 3 ficheiros con 7 adicións e 11 borrados
  1. 2 3
      Kernel/Process.h
  2. 1 4
      Kernel/Syscalls/fork.cpp
  3. 4 4
      Kernel/Syscalls/setpgid.cpp

+ 2 - 3
Kernel/Process.h

@@ -117,6 +117,7 @@ class Process final
         SessionID sid { 0 };
         SessionID sid { 0 };
         // FIXME: This should be a NonnullRefPtr
         // FIXME: This should be a NonnullRefPtr
         RefPtr<Credentials> credentials;
         RefPtr<Credentials> credentials;
+        RefPtr<ProcessGroup> process_group;
         bool dumpable { false };
         bool dumpable { false };
         bool executable_is_setid { false };
         bool executable_is_setid { false };
         Atomic<bool> has_promises { false };
         Atomic<bool> has_promises { false };
@@ -238,7 +239,7 @@ public:
     bool is_session_leader() const { return sid().value() == pid().value(); }
     bool is_session_leader() const { return sid().value() == pid().value(); }
     ProcessGroupID pgid() const
     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(); }
     bool is_group_leader() const { return pgid().value() == pid().value(); }
     ProcessID ppid() const
     ProcessID ppid() const
@@ -681,8 +682,6 @@ private:
 
 
     SpinlockProtected<OwnPtr<Memory::AddressSpace>, LockRank::None> m_space;
     SpinlockProtected<OwnPtr<Memory::AddressSpace>, LockRank::None> m_space;
 
 
-    SpinlockProtected<RefPtr<ProcessGroup>, LockRank::None> m_pg;
-
     RecursiveSpinlock<LockRank::None> mutable m_protected_data_lock;
     RecursiveSpinlock<LockRank::None> mutable m_protected_data_lock;
     AtomicEdgeAction<u32> m_protected_data_refs;
     AtomicEdgeAction<u32> m_protected_data_refs;
     void protect_data();
     void protect_data();

+ 1 - 4
Kernel/Syscalls/fork.cpp

@@ -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) {
     with_protected_data([&](auto& my_protected_data) {
         child->with_mutable_protected_data([&](auto& child_protected_data) {
         child->with_mutable_protected_data([&](auto& child_protected_data) {
             child_protected_data.promises = my_protected_data.promises.load();
             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.umask = my_protected_data.umask;
             child_protected_data.signal_trampoline = my_protected_data.signal_trampoline;
             child_protected_data.signal_trampoline = my_protected_data.signal_trampoline;
             child_protected_data.dumpable = my_protected_data.dumpable;
             child_protected_data.dumpable = my_protected_data.dumpable;
+            child_protected_data.process_group = my_protected_data.process_group;
         });
         });
     });
     });
 
 

+ 4 - 4
Kernel/Syscalls/setpgid.cpp

@@ -38,9 +38,9 @@ ErrorOr<FlatPtr> Process::sys$setsid()
     // Create a new Session and a new ProcessGroup.
     // Create a new Session and a new ProcessGroup.
 
 
     auto process_group = TRY(ProcessGroup::create(ProcessGroupID(pid().value())));
     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; });
     m_tty.with([](auto& tty) { tty = nullptr; });
     return with_mutable_protected_data([&](auto& protected_data) -> ErrorOr<FlatPtr> {
     return with_mutable_protected_data([&](auto& protected_data) -> ErrorOr<FlatPtr> {
+        protected_data.process_group = move(process_group);
         protected_data.sid = pid().value();
         protected_data.sid = pid().value();
         return protected_data.sid.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..
     // FIXME: There are more EPERM conditions to check for here..
     auto process_group = TRY(ProcessGroup::find_or_create(new_pgid));
     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(
         auto new_credentials = TRY(Credentials::create(
             credentials->uid(),
             credentials->uid(),
@@ -136,6 +135,7 @@ ErrorOr<FlatPtr> Process::sys$setpgid(pid_t specified_pid, pid_t specified_pgid)
             new_pgid));
             new_pgid));
 
 
         protected_data.credentials = move(new_credentials);
         protected_data.credentials = move(new_credentials);
+        protected_data.process_group = move(process_group);
         return 0;
         return 0;
     });
     });
 }
 }