mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 22:27:42 +00:00
Kernel: Stop using *LockRefPtr for TTY
TTY was only stored in Process::m_tty, so make that a SpinlockProtected.
This commit is contained in:
parent
350e5f9261
commit
1c77803845
6 changed files with 35 additions and 20 deletions
|
@ -26,7 +26,7 @@ ErrorOr<NonnullRefPtr<OpenFileDescription>> SelfTTYDevice::open(int options)
|
||||||
if (!Process::has_current())
|
if (!Process::has_current())
|
||||||
return Error::from_errno(ESRCH);
|
return Error::from_errno(ESRCH);
|
||||||
auto& current_process = Process::current();
|
auto& current_process = Process::current();
|
||||||
LockRefPtr<TTY> tty = current_process.tty();
|
auto tty = current_process.tty();
|
||||||
if (!tty)
|
if (!tty)
|
||||||
return Error::from_errno(ENXIO);
|
return Error::from_errno(ENXIO);
|
||||||
auto description = TRY(OpenFileDescription::try_create(*tty));
|
auto description = TRY(OpenFileDescription::try_create(*tty));
|
||||||
|
|
|
@ -65,7 +65,10 @@ ErrorOr<void> SysFSOverallProcesses::try_generate(KBufferBuilder& builder)
|
||||||
}
|
}
|
||||||
|
|
||||||
TRY(process_object.add("pid"sv, process.pid().value()));
|
TRY(process_object.add("pid"sv, process.pid().value()));
|
||||||
TRY(process_object.add("pgid"sv, process.tty() ? process.tty()->pgid().value() : 0));
|
ProcessGroupID tty_pgid = 0;
|
||||||
|
if (auto tty = process.tty())
|
||||||
|
tty_pgid = tty->pgid();
|
||||||
|
TRY(process_object.add("pgid"sv, tty_pgid.value()));
|
||||||
TRY(process_object.add("pgp"sv, process.pgid().value()));
|
TRY(process_object.add("pgp"sv, process.pgid().value()));
|
||||||
TRY(process_object.add("sid"sv, process.sid().value()));
|
TRY(process_object.add("sid"sv, process.sid().value()));
|
||||||
auto credentials = process.credentials();
|
auto credentials = process.credentials();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
|
* Copyright (c) 2018-2023, Andreas Kling <kling@serenityos.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -208,7 +208,7 @@ void Process::register_new(Process& process)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<Process::ProcessAndFirstThread> Process::create_user_process(StringView path, UserID uid, GroupID gid, Vector<NonnullOwnPtr<KString>> arguments, Vector<NonnullOwnPtr<KString>> environment, TTY* tty)
|
ErrorOr<Process::ProcessAndFirstThread> Process::create_user_process(StringView path, UserID uid, GroupID gid, Vector<NonnullOwnPtr<KString>> arguments, Vector<NonnullOwnPtr<KString>> environment, RefPtr<TTY> tty)
|
||||||
{
|
{
|
||||||
auto parts = path.split_view('/');
|
auto parts = path.split_view('/');
|
||||||
if (arguments.is_empty()) {
|
if (arguments.is_empty()) {
|
||||||
|
@ -284,7 +284,7 @@ void Process::unprotect_data()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<Process::ProcessAndFirstThread> Process::create(NonnullOwnPtr<KString> name, UserID uid, GroupID gid, ProcessID ppid, bool is_kernel_process, RefPtr<Custody> current_directory, RefPtr<Custody> executable, TTY* tty, Process* fork_parent)
|
ErrorOr<Process::ProcessAndFirstThread> Process::create(NonnullOwnPtr<KString> name, UserID uid, GroupID gid, ProcessID ppid, bool is_kernel_process, RefPtr<Custody> current_directory, RefPtr<Custody> executable, RefPtr<TTY> tty, Process* fork_parent)
|
||||||
{
|
{
|
||||||
OwnPtr<Memory::AddressSpace> new_address_space;
|
OwnPtr<Memory::AddressSpace> new_address_space;
|
||||||
if (fork_parent) {
|
if (fork_parent) {
|
||||||
|
@ -305,7 +305,7 @@ ErrorOr<Process::ProcessAndFirstThread> Process::create(NonnullOwnPtr<KString> n
|
||||||
return ProcessAndFirstThread { move(process), move(first_thread) };
|
return ProcessAndFirstThread { move(process), move(first_thread) };
|
||||||
}
|
}
|
||||||
|
|
||||||
Process::Process(NonnullOwnPtr<KString> name, NonnullRefPtr<Credentials> credentials, ProcessID ppid, bool is_kernel_process, RefPtr<Custody> current_directory, RefPtr<Custody> executable, TTY* tty, UnveilNode unveil_tree, UnveilNode exec_unveil_tree)
|
Process::Process(NonnullOwnPtr<KString> name, NonnullRefPtr<Credentials> credentials, ProcessID ppid, bool is_kernel_process, RefPtr<Custody> current_directory, RefPtr<Custody> executable, RefPtr<TTY> tty, UnveilNode unveil_tree, UnveilNode exec_unveil_tree)
|
||||||
: m_name(move(name))
|
: m_name(move(name))
|
||||||
, m_is_kernel_process(is_kernel_process)
|
, m_is_kernel_process(is_kernel_process)
|
||||||
, m_executable(move(executable))
|
, m_executable(move(executable))
|
||||||
|
@ -758,7 +758,7 @@ void Process::finalize()
|
||||||
TimerQueue::the().cancel_timer(timer.release_nonnull());
|
TimerQueue::the().cancel_timer(timer.release_nonnull());
|
||||||
});
|
});
|
||||||
m_fds.with_exclusive([](auto& fds) { fds.clear(); });
|
m_fds.with_exclusive([](auto& fds) { fds.clear(); });
|
||||||
m_tty = nullptr;
|
m_tty.with([](auto& tty) { tty = nullptr; });
|
||||||
m_executable.with([](auto& executable) { executable = nullptr; });
|
m_executable.with([](auto& executable) { executable = nullptr; });
|
||||||
m_jail_process_list.with([this](auto& list_ptr) {
|
m_jail_process_list.with([this](auto& list_ptr) {
|
||||||
if (list_ptr) {
|
if (list_ptr) {
|
||||||
|
@ -835,7 +835,7 @@ void Process::die()
|
||||||
// getting an EOF when the last process using the slave PTY dies.
|
// 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
|
// 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.
|
// slave owner, we have to allow the PTY pair to be torn down.
|
||||||
m_tty = nullptr;
|
m_tty.with([](auto& tty) { tty = nullptr; });
|
||||||
|
|
||||||
VERIFY(m_threads_for_coredump.is_empty());
|
VERIFY(m_threads_for_coredump.is_empty());
|
||||||
for_each_thread([&](auto& thread) {
|
for_each_thread([&](auto& thread) {
|
||||||
|
@ -941,9 +941,19 @@ void Process::OpenFileDescriptionAndFlags::set(NonnullRefPtr<OpenFileDescription
|
||||||
m_flags = flags;
|
m_flags = flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Process::set_tty(TTY* tty)
|
RefPtr<TTY> Process::tty()
|
||||||
{
|
{
|
||||||
m_tty = tty;
|
return m_tty.with([&](auto& tty) { return tty; });
|
||||||
|
}
|
||||||
|
|
||||||
|
RefPtr<TTY const> Process::tty() const
|
||||||
|
{
|
||||||
|
return m_tty.with([&](auto& tty) { return tty; });
|
||||||
|
}
|
||||||
|
|
||||||
|
void Process::set_tty(RefPtr<TTY> new_tty)
|
||||||
|
{
|
||||||
|
m_tty.with([&](auto& tty) { swap(tty, new_tty); });
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<void> Process::start_tracing_from(ProcessID tracer)
|
ErrorOr<void> Process::start_tracing_from(ProcessID tracer)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
|
* Copyright (c) 2018-2023, Andreas Kling <kling@serenityos.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -198,7 +198,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<ProcessAndFirstThread> create_kernel_process(NonnullOwnPtr<KString> name, void (*entry)(void*), void* entry_data = nullptr, u32 affinity = THREAD_AFFINITY_DEFAULT, RegisterProcess do_register = RegisterProcess::Yes);
|
static ErrorOr<ProcessAndFirstThread> create_kernel_process(NonnullOwnPtr<KString> name, void (*entry)(void*), void* entry_data = nullptr, u32 affinity = THREAD_AFFINITY_DEFAULT, RegisterProcess do_register = RegisterProcess::Yes);
|
||||||
static ErrorOr<ProcessAndFirstThread> create_user_process(StringView path, UserID, GroupID, Vector<NonnullOwnPtr<KString>> arguments, Vector<NonnullOwnPtr<KString>> environment, TTY*);
|
static ErrorOr<ProcessAndFirstThread> create_user_process(StringView path, UserID, GroupID, Vector<NonnullOwnPtr<KString>> arguments, Vector<NonnullOwnPtr<KString>> environment, RefPtr<TTY>);
|
||||||
static void register_new(Process&);
|
static void register_new(Process&);
|
||||||
|
|
||||||
~Process();
|
~Process();
|
||||||
|
@ -466,8 +466,9 @@ public:
|
||||||
[[noreturn]] void crash(int signal, Optional<RegisterState const&> regs, bool out_of_memory = false);
|
[[noreturn]] void crash(int signal, Optional<RegisterState const&> regs, bool out_of_memory = false);
|
||||||
[[nodiscard]] siginfo_t wait_info() const;
|
[[nodiscard]] siginfo_t wait_info() const;
|
||||||
|
|
||||||
const TTY* tty() const { return m_tty; }
|
RefPtr<TTY> tty();
|
||||||
void set_tty(TTY*);
|
RefPtr<TTY const> tty() const;
|
||||||
|
void set_tty(RefPtr<TTY>);
|
||||||
|
|
||||||
clock_t m_ticks_in_user { 0 };
|
clock_t m_ticks_in_user { 0 };
|
||||||
clock_t m_ticks_in_kernel { 0 };
|
clock_t m_ticks_in_kernel { 0 };
|
||||||
|
@ -604,8 +605,8 @@ private:
|
||||||
bool add_thread(Thread&);
|
bool add_thread(Thread&);
|
||||||
bool remove_thread(Thread&);
|
bool remove_thread(Thread&);
|
||||||
|
|
||||||
Process(NonnullOwnPtr<KString> name, NonnullRefPtr<Credentials>, ProcessID ppid, bool is_kernel_process, RefPtr<Custody> current_directory, RefPtr<Custody> executable, TTY* tty, UnveilNode unveil_tree, UnveilNode exec_unveil_tree);
|
Process(NonnullOwnPtr<KString> name, NonnullRefPtr<Credentials>, ProcessID ppid, bool is_kernel_process, RefPtr<Custody> current_directory, RefPtr<Custody> executable, RefPtr<TTY> tty, UnveilNode unveil_tree, UnveilNode exec_unveil_tree);
|
||||||
static ErrorOr<ProcessAndFirstThread> create(NonnullOwnPtr<KString> name, UserID, GroupID, ProcessID ppid, bool is_kernel_process, RefPtr<Custody> current_directory = nullptr, RefPtr<Custody> executable = nullptr, TTY* = nullptr, Process* fork_parent = nullptr);
|
static ErrorOr<ProcessAndFirstThread> create(NonnullOwnPtr<KString> name, UserID, GroupID, ProcessID ppid, bool is_kernel_process, RefPtr<Custody> current_directory = nullptr, RefPtr<Custody> executable = nullptr, RefPtr<TTY> = nullptr, Process* fork_parent = nullptr);
|
||||||
ErrorOr<NonnullRefPtr<Thread>> attach_resources(NonnullOwnPtr<Memory::AddressSpace>&&, Process* fork_parent);
|
ErrorOr<NonnullRefPtr<Thread>> attach_resources(NonnullOwnPtr<Memory::AddressSpace>&&, Process* fork_parent);
|
||||||
static ProcessID allocate_pid();
|
static ProcessID allocate_pid();
|
||||||
|
|
||||||
|
@ -857,7 +858,7 @@ private:
|
||||||
Vector<NonnullOwnPtr<KString>> m_arguments;
|
Vector<NonnullOwnPtr<KString>> m_arguments;
|
||||||
Vector<NonnullOwnPtr<KString>> m_environment;
|
Vector<NonnullOwnPtr<KString>> m_environment;
|
||||||
|
|
||||||
LockRefPtr<TTY> m_tty;
|
SpinlockProtected<RefPtr<TTY>, LockRank::None> m_tty;
|
||||||
|
|
||||||
LockWeakPtr<Memory::Region> m_master_tls_region;
|
LockWeakPtr<Memory::Region> m_master_tls_region;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
* Copyright (c) 2018-2023, Andreas Kling <kling@serenityos.org>
|
||||||
* Copyright (c) 2023, Idan Horowitz <idan.horowitz@serenityos.org>
|
* Copyright (c) 2023, Idan Horowitz <idan.horowitz@serenityos.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
@ -11,6 +11,7 @@
|
||||||
#include <Kernel/PerformanceManager.h>
|
#include <Kernel/PerformanceManager.h>
|
||||||
#include <Kernel/Process.h>
|
#include <Kernel/Process.h>
|
||||||
#include <Kernel/Scheduler.h>
|
#include <Kernel/Scheduler.h>
|
||||||
|
#include <Kernel/TTY/TTY.h>
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
|
@ -21,7 +22,7 @@ ErrorOr<FlatPtr> Process::sys$fork(RegisterState& regs)
|
||||||
|
|
||||||
auto child_name = TRY(name().with([](auto& name) { return name->try_clone(); }));
|
auto child_name = TRY(name().with([](auto& name) { return name->try_clone(); }));
|
||||||
auto credentials = this->credentials();
|
auto credentials = this->credentials();
|
||||||
auto child_and_first_thread = TRY(Process::create(move(child_name), credentials->uid(), credentials->gid(), pid(), m_is_kernel_process, current_directory(), executable(), m_tty, this));
|
auto child_and_first_thread = TRY(Process::create(move(child_name), credentials->uid(), credentials->gid(), pid(), m_is_kernel_process, current_directory(), executable(), tty(), this));
|
||||||
auto& child = child_and_first_thread.process;
|
auto& child = child_and_first_thread.process;
|
||||||
auto& child_first_thread = child_and_first_thread.first_thread;
|
auto& child_first_thread = child_and_first_thread.first_thread;
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ ErrorOr<FlatPtr> Process::sys$setsid()
|
||||||
|
|
||||||
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_pg.with([&](auto& pg) { pg = move(process_group); });
|
||||||
m_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.sid = pid().value();
|
protected_data.sid = pid().value();
|
||||||
return protected_data.sid.value();
|
return protected_data.sid.value();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue