From 728c3fbd14252bd746f97dbb5441063992074b6b Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 21 Aug 2022 01:04:35 +0200 Subject: Kernel: Use RefPtr instead of LockRefPtr for Custody By protecting all the RefPtr objects that may be accessed from multiple threads at the same time (with spinlocks), we remove the need for using LockRefPtr (which is basically a RefPtr with a built-in spinlock.) --- Kernel/Process.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'Kernel/Process.cpp') diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 5adb6d85e7..c069d0f0ed 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -222,7 +222,7 @@ void Process::unprotect_data() }); } -ErrorOr> Process::try_create(LockRefPtr& first_thread, NonnullOwnPtr name, UserID uid, GroupID gid, ProcessID ppid, bool is_kernel_process, LockRefPtr current_directory, LockRefPtr executable, TTY* tty, Process* fork_parent) +ErrorOr> Process::try_create(LockRefPtr& first_thread, NonnullOwnPtr name, UserID uid, GroupID gid, ProcessID ppid, bool is_kernel_process, RefPtr current_directory, RefPtr executable, TTY* tty, Process* fork_parent) { auto space = TRY(Memory::AddressSpace::try_create(fork_parent ? &fork_parent->address_space() : nullptr)); auto unveil_tree = UnveilNode { TRY(KString::try_create("/"sv)), UnveilMetadata(TRY(KString::try_create("/"sv))) }; @@ -232,10 +232,10 @@ ErrorOr> Process::try_create(LockRefPtr& firs return process; } -Process::Process(NonnullOwnPtr name, NonnullRefPtr credentials, ProcessID ppid, bool is_kernel_process, LockRefPtr current_directory, LockRefPtr executable, TTY* tty, UnveilNode unveil_tree) +Process::Process(NonnullOwnPtr name, NonnullRefPtr credentials, ProcessID ppid, bool is_kernel_process, RefPtr current_directory, RefPtr executable, TTY* tty, UnveilNode unveil_tree) : m_name(move(name)) , m_is_kernel_process(is_kernel_process) - , m_executable(move(executable)) + , m_executable(LockRank::None, move(executable)) , m_current_directory(LockRank::None, move(current_directory)) , m_tty(tty) , m_unveil_data(LockRank::None, move(unveil_tree)) @@ -537,9 +537,9 @@ siginfo_t Process::wait_info() const return siginfo; } -NonnullLockRefPtr Process::current_directory() +NonnullRefPtr Process::current_directory() { - return m_current_directory.with([&](auto& current_directory) -> NonnullLockRefPtr { + return m_current_directory.with([&](auto& current_directory) -> NonnullRefPtr { if (!current_directory) current_directory = VirtualFileSystem::the().root_custody(); return *current_directory; @@ -642,7 +642,7 @@ void Process::finalize() TimerQueue::the().cancel_timer(m_alarm_timer.release_nonnull()); m_fds.with_exclusive([](auto& fds) { fds.clear(); }); m_tty = nullptr; - m_executable = nullptr; + m_executable.with([](auto& executable) { executable = nullptr; }); m_arguments.clear(); m_environment.clear(); @@ -971,4 +971,14 @@ NonnullRefPtr Process::credentials() const return *m_protected_values.credentials; } +RefPtr Process::executable() +{ + return m_executable.with([](auto& executable) { return executable; }); +} + +RefPtr Process::executable() const +{ + return m_executable.with([](auto& executable) { return executable; }); +} + } -- cgit v1.2.3