Parcourir la source

Kernel: Move Process's TTY pointer into protected data

Andreas Kling il y a 2 ans
Parent
commit
e69b2572a6
3 fichiers modifiés avec 8 ajouts et 9 suppressions
  1. 6 6
      Kernel/Process.cpp
  2. 1 2
      Kernel/Process.h
  3. 1 1
      Kernel/Syscalls/setpgid.cpp

+ 6 - 6
Kernel/Process.cpp

@@ -310,7 +310,6 @@ Process::Process(NonnullOwnPtr<KString> name, NonnullRefPtr<Credentials> credent
     , m_is_kernel_process(is_kernel_process)
     , m_executable(move(executable))
     , m_current_directory(move(current_directory))
-    , m_tty(tty)
     , m_unveil_data(move(unveil_tree))
     , m_exec_unveil_data(move(exec_unveil_tree))
     , m_wait_blocker_set(*this)
@@ -320,6 +319,7 @@ Process::Process(NonnullOwnPtr<KString> name, NonnullRefPtr<Credentials> credent
         protected_data.pid = allocate_pid();
         protected_data.ppid = ppid;
         protected_data.credentials = move(credentials);
+        protected_data.tty = move(tty);
     });
 
     if constexpr (PROCESS_DEBUG) {
@@ -758,7 +758,7 @@ void Process::finalize()
             TimerQueue::the().cancel_timer(timer.release_nonnull());
     });
     m_fds.with_exclusive([](auto& fds) { fds.clear(); });
-    m_tty.with([](auto& tty) { tty = nullptr; });
+    with_mutable_protected_data([&](auto& protected_data) { protected_data.tty = nullptr; });
     m_executable.with([](auto& executable) { executable = nullptr; });
     m_jail_process_list.with([this](auto& list_ptr) {
         if (list_ptr) {
@@ -835,7 +835,7 @@ void Process::die()
     // getting an EOF when the last process using the slave PTY dies.
     // If the master PTY owner relies on an EOF to know when to wait() on a
     // slave owner, we have to allow the PTY pair to be torn down.
-    m_tty.with([](auto& tty) { tty = nullptr; });
+    with_mutable_protected_data([&](auto& protected_data) { protected_data.tty = nullptr; });
 
     VERIFY(m_threads_for_coredump.is_empty());
     for_each_thread([&](auto& thread) {
@@ -943,17 +943,17 @@ void Process::OpenFileDescriptionAndFlags::set(NonnullRefPtr<OpenFileDescription
 
 RefPtr<TTY> Process::tty()
 {
-    return m_tty.with([&](auto& tty) { return tty; });
+    return with_protected_data([&](auto& protected_data) { return protected_data.tty; });
 }
 
 RefPtr<TTY const> Process::tty() const
 {
-    return m_tty.with([&](auto& tty) { return tty; });
+    return with_protected_data([&](auto& protected_data) { return protected_data.tty; });
 }
 
 void Process::set_tty(RefPtr<TTY> new_tty)
 {
-    m_tty.with([&](auto& tty) { swap(tty, new_tty); });
+    with_mutable_protected_data([&](auto& protected_data) { protected_data.tty = move(new_tty); });
 }
 
 ErrorOr<void> Process::start_tracing_from(ProcessID tracer)

+ 1 - 2
Kernel/Process.h

@@ -118,6 +118,7 @@ class Process final
         // FIXME: This should be a NonnullRefPtr
         RefPtr<Credentials> credentials;
         RefPtr<ProcessGroup> process_group;
+        RefPtr<TTY> tty;
         bool dumpable { false };
         bool executable_is_setid { false };
         Atomic<bool> has_promises { false };
@@ -857,8 +858,6 @@ private:
     Vector<NonnullOwnPtr<KString>> m_arguments;
     Vector<NonnullOwnPtr<KString>> m_environment;
 
-    SpinlockProtected<RefPtr<TTY>, LockRank::None> m_tty;
-
     LockWeakPtr<Memory::Region> m_master_tls_region;
 
     IntrusiveListNode<Process> m_jail_process_list_node;

+ 1 - 1
Kernel/Syscalls/setpgid.cpp

@@ -38,8 +38,8 @@ ErrorOr<FlatPtr> Process::sys$setsid()
     // Create a new Session and a new ProcessGroup.
 
     auto process_group = TRY(ProcessGroup::create(ProcessGroupID(pid().value())));
-    m_tty.with([](auto& tty) { tty = nullptr; });
     return with_mutable_protected_data([&](auto& protected_data) -> ErrorOr<FlatPtr> {
+        protected_data.tty = nullptr;
         protected_data.process_group = move(process_group);
         protected_data.sid = pid().value();
         return protected_data.sid.value();