From e69b2572a6b25a1f5ca685f787edcdcd1b1d8a60 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 4 Apr 2023 08:15:44 +0200 Subject: [PATCH] Kernel: Move Process's TTY pointer into protected data --- Kernel/Process.cpp | 12 ++++++------ Kernel/Process.h | 3 +-- Kernel/Syscalls/setpgid.cpp | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 6003802937..1c38430aeb 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -310,7 +310,6 @@ Process::Process(NonnullOwnPtr name, NonnullRefPtr 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 name, NonnullRefPtr 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 Process::tty() { - return m_tty.with([&](auto& tty) { return tty; }); + return with_protected_data([&](auto& protected_data) { return protected_data.tty; }); } RefPtr 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 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 Process::start_tracing_from(ProcessID tracer) diff --git a/Kernel/Process.h b/Kernel/Process.h index 89ffd42e26..deec474ded 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -118,6 +118,7 @@ class Process final // FIXME: This should be a NonnullRefPtr RefPtr credentials; RefPtr process_group; + RefPtr tty; bool dumpable { false }; bool executable_is_setid { false }; Atomic has_promises { false }; @@ -857,8 +858,6 @@ private: Vector> m_arguments; Vector> m_environment; - SpinlockProtected, LockRank::None> m_tty; - LockWeakPtr m_master_tls_region; IntrusiveListNode m_jail_process_list_node; diff --git a/Kernel/Syscalls/setpgid.cpp b/Kernel/Syscalls/setpgid.cpp index e23109743d..32f908cf7e 100644 --- a/Kernel/Syscalls/setpgid.cpp +++ b/Kernel/Syscalls/setpgid.cpp @@ -38,8 +38,8 @@ ErrorOr 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 { + protected_data.tty = nullptr; protected_data.process_group = move(process_group); protected_data.sid = pid().value(); return protected_data.sid.value();