diff options
author | Andreas Kling <kling@serenityos.org> | 2023-04-04 08:15:44 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-04-05 11:37:27 +0200 |
commit | e69b2572a6b25a1f5ca685f787edcdcd1b1d8a60 (patch) | |
tree | e9f0d9d70e540c5c9746a7b1055c2d06e2a70cd5 /Kernel | |
parent | 1e2ef59965eef56b8ccb3f1b534bf60470995425 (diff) | |
download | serenity-e69b2572a6b25a1f5ca685f787edcdcd1b1d8a60.zip |
Kernel: Move Process's TTY pointer into protected data
Diffstat (limited to 'Kernel')
-rw-r--r-- | Kernel/Process.cpp | 12 | ||||
-rw-r--r-- | Kernel/Process.h | 3 | ||||
-rw-r--r-- | 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<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) 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> 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; 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<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(); |