From 5c1d5ed51da2cf3b9463413f704ea0e740950736 Mon Sep 17 00:00:00 2001 From: sin-ack Date: Sat, 1 Oct 2022 11:28:27 +0000 Subject: [PATCH] Kernel: Implement Process::custody_for_dirfd This allows deduplicating a bunch of code that has to work with POSIX' *at syscall semantics. --- Kernel/Process.cpp | 11 +++++++++++ Kernel/Process.h | 2 ++ 2 files changed, 13 insertions(+) diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 4e21066044..1165d7ff25 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -1100,4 +1100,15 @@ RefPtr Process::executable() const return m_executable.with([](auto& executable) { return executable; }); } +ErrorOr> Process::custody_for_dirfd(int dirfd) +{ + if (dirfd == AT_FDCWD) + return current_directory(); + + auto base_description = TRY(open_file_description(dirfd)); + if (!base_description->custody()) + return EINVAL; + return *base_description->custody(); +} + } diff --git a/Kernel/Process.h b/Kernel/Process.h index bf0c1616c2..3147965db3 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -844,6 +844,8 @@ public: } private: + ErrorOr> custody_for_dirfd(int dirfd); + SpinlockProtected& thread_list() { return m_thread_list; } SpinlockProtected const& thread_list() const { return m_thread_list; }