mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 13:36:13 +03:00
Kernel: Use non-locking {Nonnull,}RefPtr for OpenFileDescription
This patch switches away from {Nonnull,}LockRefPtr to the non-locking smart pointers throughout the kernel. I've looked at the handful of places where these were being persisted and I don't see any race situations. Note that the process file descriptor table (Process::m_fds) was already guarded via MutexProtected.
This commit is contained in:
parent
36b0ecfe9e
commit
d1371d66f7
Notes:
sideshowbarker
2024-07-17 01:00:06 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/d1371d66f7
@ -161,7 +161,7 @@ ErrorOr<size_t> ConsolePort::write(OpenFileDescription& desc, u64, UserOrKernelB
|
||||
return total_bytes_copied;
|
||||
}
|
||||
|
||||
ErrorOr<NonnullLockRefPtr<OpenFileDescription>> ConsolePort::open(int options)
|
||||
ErrorOr<NonnullRefPtr<OpenFileDescription>> ConsolePort::open(int options)
|
||||
{
|
||||
if (!m_open)
|
||||
m_console.send_open_control_message(m_port, true);
|
||||
|
@ -44,7 +44,7 @@ private:
|
||||
virtual ErrorOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
|
||||
virtual bool can_write(OpenFileDescription const&, u64) const override;
|
||||
virtual ErrorOr<size_t> write(OpenFileDescription&, u64, UserOrKernelBuffer const&, size_t) override;
|
||||
virtual ErrorOr<NonnullLockRefPtr<OpenFileDescription>> open(int options) override;
|
||||
virtual ErrorOr<NonnullRefPtr<OpenFileDescription>> open(int options) override;
|
||||
|
||||
static unsigned next_device_id;
|
||||
u16 m_receive_queue {};
|
||||
|
@ -74,7 +74,7 @@ ErrorOr<NonnullOwnPtr<Coredump>> Coredump::try_create(NonnullLockRefPtr<Process>
|
||||
return adopt_nonnull_own_or_enomem(new (nothrow) Coredump(move(process), move(description), move(regions)));
|
||||
}
|
||||
|
||||
Coredump::Coredump(NonnullLockRefPtr<Process> process, NonnullLockRefPtr<OpenFileDescription> description, Vector<FlatRegionData> regions)
|
||||
Coredump::Coredump(NonnullLockRefPtr<Process> process, NonnullRefPtr<OpenFileDescription> description, Vector<FlatRegionData> regions)
|
||||
: m_process(move(process))
|
||||
, m_description(move(description))
|
||||
, m_regions(move(regions))
|
||||
@ -93,7 +93,7 @@ Coredump::Coredump(NonnullLockRefPtr<Process> process, NonnullLockRefPtr<OpenFil
|
||||
++m_num_program_headers; // +1 for NOTE segment
|
||||
}
|
||||
|
||||
ErrorOr<NonnullLockRefPtr<OpenFileDescription>> Coredump::try_create_target_file(Process const& process, StringView output_path)
|
||||
ErrorOr<NonnullRefPtr<OpenFileDescription>> Coredump::try_create_target_file(Process const& process, StringView output_path)
|
||||
{
|
||||
auto output_directory = KLexicalPath::dirname(output_path);
|
||||
auto dump_directory = TRY(VirtualFileSystem::the().open_directory(Process::current().credentials(), output_directory, VirtualFileSystem::the().root_custody()));
|
||||
|
@ -65,8 +65,8 @@ private:
|
||||
VirtualAddress m_vaddr;
|
||||
};
|
||||
|
||||
Coredump(NonnullLockRefPtr<Process>, NonnullLockRefPtr<OpenFileDescription>, Vector<FlatRegionData>);
|
||||
static ErrorOr<NonnullLockRefPtr<OpenFileDescription>> try_create_target_file(Process const&, StringView output_path);
|
||||
Coredump(NonnullLockRefPtr<Process>, NonnullRefPtr<OpenFileDescription>, Vector<FlatRegionData>);
|
||||
static ErrorOr<NonnullRefPtr<OpenFileDescription>> try_create_target_file(Process const&, StringView output_path);
|
||||
|
||||
ErrorOr<void> write_elf_header();
|
||||
ErrorOr<void> write_program_headers(size_t notes_size);
|
||||
@ -80,7 +80,7 @@ private:
|
||||
ErrorOr<void> create_notes_metadata_data(auto&) const;
|
||||
|
||||
NonnullLockRefPtr<Process> m_process;
|
||||
NonnullLockRefPtr<OpenFileDescription> m_description;
|
||||
NonnullRefPtr<OpenFileDescription> m_description;
|
||||
size_t m_num_program_headers { 0 };
|
||||
Vector<FlatRegionData> m_regions;
|
||||
};
|
||||
|
@ -59,7 +59,7 @@ ErrorOr<NonnullOwnPtr<KString>> Device::pseudo_path(OpenFileDescription const&)
|
||||
return KString::formatted("device:{},{}", major(), minor());
|
||||
}
|
||||
|
||||
ErrorOr<NonnullLockRefPtr<OpenFileDescription>> Device::open(int options)
|
||||
ErrorOr<NonnullRefPtr<OpenFileDescription>> Device::open(int options)
|
||||
{
|
||||
TRY(Process::current().jail().with([&](auto const& my_jail) -> ErrorOr<void> {
|
||||
if (my_jail && !is_openable_by_jailed_processes())
|
||||
|
@ -43,7 +43,7 @@ public:
|
||||
MinorNumber minor() const { return m_minor; }
|
||||
|
||||
virtual ErrorOr<NonnullOwnPtr<KString>> pseudo_path(OpenFileDescription const&) const override;
|
||||
virtual ErrorOr<NonnullLockRefPtr<OpenFileDescription>> open(int options) override;
|
||||
virtual ErrorOr<NonnullRefPtr<OpenFileDescription>> open(int options) override;
|
||||
|
||||
UserID uid() const { return m_uid; }
|
||||
GroupID gid() const { return m_gid; }
|
||||
|
@ -65,7 +65,7 @@ void KCOVDevice::free_process()
|
||||
delete kcov_instance;
|
||||
}
|
||||
|
||||
ErrorOr<NonnullLockRefPtr<OpenFileDescription>> KCOVDevice::open(int options)
|
||||
ErrorOr<NonnullRefPtr<OpenFileDescription>> KCOVDevice::open(int options)
|
||||
{
|
||||
auto pid = Process::current().pid();
|
||||
if (proc_instance->get(pid).has_value())
|
||||
|
@ -23,7 +23,7 @@ public:
|
||||
|
||||
// ^File
|
||||
ErrorOr<NonnullLockRefPtr<Memory::VMObject>> vmobject_for_mmap(Process&, Memory::VirtualRange const&, u64& offset, bool shared) override;
|
||||
ErrorOr<NonnullLockRefPtr<OpenFileDescription>> open(int options) override;
|
||||
virtual ErrorOr<NonnullRefPtr<OpenFileDescription>> open(int options) override;
|
||||
|
||||
protected:
|
||||
KCOVDevice();
|
||||
|
@ -19,7 +19,7 @@ UNMAP_AFTER_INIT NonnullLockRefPtr<SelfTTYDevice> SelfTTYDevice::must_create()
|
||||
return self_tty_device_or_error.release_value();
|
||||
}
|
||||
|
||||
ErrorOr<NonnullLockRefPtr<OpenFileDescription>> SelfTTYDevice::open(int options)
|
||||
ErrorOr<NonnullRefPtr<OpenFileDescription>> SelfTTYDevice::open(int options)
|
||||
{
|
||||
// Note: If for some odd reason we try to open this device (early on boot?)
|
||||
// while there's no current Process assigned, don't fail and return an error.
|
||||
|
@ -24,7 +24,7 @@ private:
|
||||
virtual bool is_openable_by_jailed_processes() const override { return true; }
|
||||
|
||||
// ^CharacterDevice
|
||||
virtual ErrorOr<NonnullLockRefPtr<OpenFileDescription>> open(int options) override;
|
||||
virtual ErrorOr<NonnullRefPtr<OpenFileDescription>> open(int options) override;
|
||||
virtual ErrorOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
|
||||
virtual ErrorOr<size_t> write(OpenFileDescription&, u64, UserOrKernelBuffer const&, size_t) override;
|
||||
virtual bool can_read(OpenFileDescription const&, u64) const override;
|
||||
|
@ -22,7 +22,7 @@ ErrorOr<NonnullLockRefPtr<FIFO>> FIFO::try_create(UserID uid)
|
||||
return adopt_nonnull_lock_ref_or_enomem(new (nothrow) FIFO(uid, move(buffer)));
|
||||
}
|
||||
|
||||
ErrorOr<NonnullLockRefPtr<OpenFileDescription>> FIFO::open_direction(FIFO::Direction direction)
|
||||
ErrorOr<NonnullRefPtr<OpenFileDescription>> FIFO::open_direction(FIFO::Direction direction)
|
||||
{
|
||||
auto description = TRY(OpenFileDescription::try_create(*this));
|
||||
attach(direction);
|
||||
@ -30,7 +30,7 @@ ErrorOr<NonnullLockRefPtr<OpenFileDescription>> FIFO::open_direction(FIFO::Direc
|
||||
return description;
|
||||
}
|
||||
|
||||
ErrorOr<NonnullLockRefPtr<OpenFileDescription>> FIFO::open_direction_blocking(FIFO::Direction direction)
|
||||
ErrorOr<NonnullRefPtr<OpenFileDescription>> FIFO::open_direction_blocking(FIFO::Direction direction)
|
||||
{
|
||||
MutexLocker locker(m_open_lock);
|
||||
|
||||
|
@ -29,8 +29,8 @@ public:
|
||||
|
||||
UserID uid() const { return m_uid; }
|
||||
|
||||
ErrorOr<NonnullLockRefPtr<OpenFileDescription>> open_direction(Direction);
|
||||
ErrorOr<NonnullLockRefPtr<OpenFileDescription>> open_direction_blocking(Direction);
|
||||
ErrorOr<NonnullRefPtr<OpenFileDescription>> open_direction(Direction);
|
||||
ErrorOr<NonnullRefPtr<OpenFileDescription>> open_direction_blocking(Direction);
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Woverloaded-virtual"
|
||||
|
@ -15,7 +15,7 @@ namespace Kernel {
|
||||
File::File() = default;
|
||||
File::~File() = default;
|
||||
|
||||
ErrorOr<NonnullLockRefPtr<OpenFileDescription>> File::open(int options)
|
||||
ErrorOr<NonnullRefPtr<OpenFileDescription>> File::open(int options)
|
||||
{
|
||||
auto description = OpenFileDescription::try_create(*this);
|
||||
if (!description.is_error()) {
|
||||
|
@ -78,7 +78,7 @@ public:
|
||||
virtual void will_be_destroyed() { }
|
||||
virtual ~File();
|
||||
|
||||
virtual ErrorOr<NonnullLockRefPtr<OpenFileDescription>> open(int options);
|
||||
virtual ErrorOr<NonnullRefPtr<OpenFileDescription>> open(int options);
|
||||
virtual ErrorOr<void> close();
|
||||
|
||||
virtual bool can_read(OpenFileDescription const&, u64) const = 0;
|
||||
|
@ -38,6 +38,6 @@ private:
|
||||
virtual bool is_file_backed() const override { return true; }
|
||||
|
||||
IntrusiveListNode<FileBackedFileSystem> m_file_backed_file_system_node;
|
||||
mutable NonnullLockRefPtr<OpenFileDescription> m_file_description;
|
||||
NonnullRefPtr<OpenFileDescription> m_file_description;
|
||||
};
|
||||
}
|
||||
|
@ -23,19 +23,19 @@
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
ErrorOr<NonnullLockRefPtr<OpenFileDescription>> OpenFileDescription::try_create(Custody& custody)
|
||||
ErrorOr<NonnullRefPtr<OpenFileDescription>> OpenFileDescription::try_create(Custody& custody)
|
||||
{
|
||||
auto inode_file = TRY(InodeFile::create(custody.inode()));
|
||||
auto description = TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) OpenFileDescription(move(inode_file))));
|
||||
auto description = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) OpenFileDescription(move(inode_file))));
|
||||
|
||||
description->m_state.with([&](auto& state) { state.custody = custody; });
|
||||
TRY(description->attach());
|
||||
return description;
|
||||
}
|
||||
|
||||
ErrorOr<NonnullLockRefPtr<OpenFileDescription>> OpenFileDescription::try_create(File& file)
|
||||
ErrorOr<NonnullRefPtr<OpenFileDescription>> OpenFileDescription::try_create(File& file)
|
||||
{
|
||||
auto description = TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) OpenFileDescription(file)));
|
||||
auto description = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) OpenFileDescription(file)));
|
||||
TRY(description->attach());
|
||||
return description;
|
||||
}
|
||||
|
@ -26,8 +26,8 @@ public:
|
||||
|
||||
class OpenFileDescription final : public AtomicRefCounted<OpenFileDescription> {
|
||||
public:
|
||||
static ErrorOr<NonnullLockRefPtr<OpenFileDescription>> try_create(Custody&);
|
||||
static ErrorOr<NonnullLockRefPtr<OpenFileDescription>> try_create(File&);
|
||||
static ErrorOr<NonnullRefPtr<OpenFileDescription>> try_create(Custody&);
|
||||
static ErrorOr<NonnullRefPtr<OpenFileDescription>> try_create(File&);
|
||||
~OpenFileDescription();
|
||||
|
||||
Thread::FileBlocker::BlockFlags should_unblock(Thread::FileBlocker::BlockFlags) const;
|
||||
|
@ -262,7 +262,7 @@ ErrorOr<void> Process::procfs_get_fds_stats(KBufferBuilder& builder) const
|
||||
return {};
|
||||
}
|
||||
bool cloexec = file_description_metadata.flags() & FD_CLOEXEC;
|
||||
LockRefPtr<OpenFileDescription> description = file_description_metadata.description();
|
||||
auto const* description = file_description_metadata.description();
|
||||
auto description_object = TRY(array.add_object());
|
||||
TRY(description_object.add("fd"sv, count));
|
||||
// TODO: Better OOM handling.
|
||||
@ -275,7 +275,7 @@ ErrorOr<void> Process::procfs_get_fds_stats(KBufferBuilder& builder) const
|
||||
TRY(description_object.add("blocking"sv, description->is_blocking()));
|
||||
TRY(description_object.add("can_read"sv, description->can_read()));
|
||||
TRY(description_object.add("can_write"sv, description->can_write()));
|
||||
Inode* inode = description->inode();
|
||||
Inode const* inode = description->inode();
|
||||
if (inode != nullptr) {
|
||||
auto inode_object = TRY(description_object.add_object("inode"sv));
|
||||
TRY(inode_object.add("fsid"sv, inode->fsid().value()));
|
||||
|
@ -356,12 +356,12 @@ ErrorOr<NonnullLockRefPtr<FileBackedFileSystem>> VirtualFileSystem::find_already
|
||||
}));
|
||||
}
|
||||
|
||||
ErrorOr<NonnullLockRefPtr<OpenFileDescription>> VirtualFileSystem::open(Credentials const& credentials, StringView path, int options, mode_t mode, Custody& base, Optional<UidAndGid> owner)
|
||||
ErrorOr<NonnullRefPtr<OpenFileDescription>> VirtualFileSystem::open(Credentials const& credentials, StringView path, int options, mode_t mode, Custody& base, Optional<UidAndGid> owner)
|
||||
{
|
||||
return open(Process::current(), credentials, path, options, mode, base, owner);
|
||||
}
|
||||
|
||||
ErrorOr<NonnullLockRefPtr<OpenFileDescription>> VirtualFileSystem::open(Process const& process, Credentials const& credentials, StringView path, int options, mode_t mode, Custody& base, Optional<UidAndGid> owner)
|
||||
ErrorOr<NonnullRefPtr<OpenFileDescription>> VirtualFileSystem::open(Process const& process, Credentials const& credentials, StringView path, int options, mode_t mode, Custody& base, Optional<UidAndGid> owner)
|
||||
{
|
||||
if ((options & O_CREAT) && (options & O_DIRECTORY))
|
||||
return EINVAL;
|
||||
@ -476,12 +476,12 @@ ErrorOr<void> VirtualFileSystem::mknod(Credentials const& credentials, StringVie
|
||||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<NonnullLockRefPtr<OpenFileDescription>> VirtualFileSystem::create(Credentials const& credentials, StringView path, int options, mode_t mode, Custody& parent_custody, Optional<UidAndGid> owner)
|
||||
ErrorOr<NonnullRefPtr<OpenFileDescription>> VirtualFileSystem::create(Credentials const& credentials, StringView path, int options, mode_t mode, Custody& parent_custody, Optional<UidAndGid> owner)
|
||||
{
|
||||
return create(Process::current(), credentials, path, options, mode, parent_custody, owner);
|
||||
}
|
||||
|
||||
ErrorOr<NonnullLockRefPtr<OpenFileDescription>> VirtualFileSystem::create(Process const& process, Credentials const& credentials, StringView path, int options, mode_t mode, Custody& parent_custody, Optional<UidAndGid> owner)
|
||||
ErrorOr<NonnullRefPtr<OpenFileDescription>> VirtualFileSystem::create(Process const& process, Credentials const& credentials, StringView path, int options, mode_t mode, Custody& parent_custody, Optional<UidAndGid> owner)
|
||||
{
|
||||
auto basename = KLexicalPath::basename(path);
|
||||
auto parent_path = TRY(parent_custody.try_serialize_absolute_path());
|
||||
|
@ -59,10 +59,10 @@ public:
|
||||
ErrorOr<void> remount(Custody& mount_point, int new_flags);
|
||||
ErrorOr<void> unmount(Custody& mount_point);
|
||||
|
||||
ErrorOr<NonnullLockRefPtr<OpenFileDescription>> open(Credentials const&, StringView path, int options, mode_t mode, Custody& base, Optional<UidAndGid> = {});
|
||||
ErrorOr<NonnullLockRefPtr<OpenFileDescription>> open(Process const&, Credentials const&, StringView path, int options, mode_t mode, Custody& base, Optional<UidAndGid> = {});
|
||||
ErrorOr<NonnullLockRefPtr<OpenFileDescription>> create(Credentials const&, StringView path, int options, mode_t mode, Custody& parent_custody, Optional<UidAndGid> = {});
|
||||
ErrorOr<NonnullLockRefPtr<OpenFileDescription>> create(Process const&, Credentials const&, StringView path, int options, mode_t mode, Custody& parent_custody, Optional<UidAndGid> = {});
|
||||
ErrorOr<NonnullRefPtr<OpenFileDescription>> open(Credentials const&, StringView path, int options, mode_t mode, Custody& base, Optional<UidAndGid> = {});
|
||||
ErrorOr<NonnullRefPtr<OpenFileDescription>> open(Process const&, Credentials const&, StringView path, int options, mode_t mode, Custody& base, Optional<UidAndGid> = {});
|
||||
ErrorOr<NonnullRefPtr<OpenFileDescription>> create(Credentials const&, StringView path, int options, mode_t mode, Custody& parent_custody, Optional<UidAndGid> = {});
|
||||
ErrorOr<NonnullRefPtr<OpenFileDescription>> create(Process const&, Credentials const&, StringView path, int options, mode_t mode, Custody& parent_custody, Optional<UidAndGid> = {});
|
||||
ErrorOr<void> mkdir(Credentials const&, StringView path, mode_t mode, Custody& base);
|
||||
ErrorOr<void> link(Credentials const&, StringView old_path, StringView new_path, Custody& base);
|
||||
ErrorOr<void> unlink(Credentials const&, StringView path, Custody& base);
|
||||
|
@ -472,8 +472,9 @@ ErrorOr<void> LocalSocket::chown(Credentials const& credentials, OpenFileDescrip
|
||||
return {};
|
||||
}
|
||||
|
||||
Vector<NonnullLockRefPtr<OpenFileDescription>>& LocalSocket::recvfd_queue_for(OpenFileDescription const& description)
|
||||
Vector<NonnullRefPtr<OpenFileDescription>>& LocalSocket::recvfd_queue_for(OpenFileDescription const& description)
|
||||
{
|
||||
VERIFY(mutex().is_exclusively_locked_by_current_thread());
|
||||
auto role = this->role(description);
|
||||
if (role == Role::Connected)
|
||||
return m_fds_for_client;
|
||||
@ -482,8 +483,9 @@ Vector<NonnullLockRefPtr<OpenFileDescription>>& LocalSocket::recvfd_queue_for(Op
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
Vector<NonnullLockRefPtr<OpenFileDescription>>& LocalSocket::sendfd_queue_for(OpenFileDescription const& description)
|
||||
Vector<NonnullRefPtr<OpenFileDescription>>& LocalSocket::sendfd_queue_for(OpenFileDescription const& description)
|
||||
{
|
||||
VERIFY(mutex().is_exclusively_locked_by_current_thread());
|
||||
auto role = this->role(description);
|
||||
if (role == Role::Connected)
|
||||
return m_fds_for_server;
|
||||
@ -492,7 +494,7 @@ Vector<NonnullLockRefPtr<OpenFileDescription>>& LocalSocket::sendfd_queue_for(Op
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
ErrorOr<void> LocalSocket::sendfd(OpenFileDescription const& socket_description, NonnullLockRefPtr<OpenFileDescription> passing_description)
|
||||
ErrorOr<void> LocalSocket::sendfd(OpenFileDescription const& socket_description, NonnullRefPtr<OpenFileDescription> passing_description)
|
||||
{
|
||||
MutexLocker locker(mutex());
|
||||
auto role = this->role(socket_description);
|
||||
@ -506,7 +508,7 @@ ErrorOr<void> LocalSocket::sendfd(OpenFileDescription const& socket_description,
|
||||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<NonnullLockRefPtr<OpenFileDescription>> LocalSocket::recvfd(OpenFileDescription const& socket_description)
|
||||
ErrorOr<NonnullRefPtr<OpenFileDescription>> LocalSocket::recvfd(OpenFileDescription const& socket_description)
|
||||
{
|
||||
MutexLocker locker(mutex());
|
||||
auto role = this->role(socket_description);
|
||||
@ -520,10 +522,10 @@ ErrorOr<NonnullLockRefPtr<OpenFileDescription>> LocalSocket::recvfd(OpenFileDesc
|
||||
return queue.take_first();
|
||||
}
|
||||
|
||||
ErrorOr<Vector<NonnullLockRefPtr<OpenFileDescription>>> LocalSocket::recvfds(OpenFileDescription const& socket_description, int n)
|
||||
ErrorOr<Vector<NonnullRefPtr<OpenFileDescription>>> LocalSocket::recvfds(OpenFileDescription const& socket_description, int n)
|
||||
{
|
||||
MutexLocker locker(mutex());
|
||||
Vector<NonnullLockRefPtr<OpenFileDescription>> fds;
|
||||
Vector<NonnullRefPtr<OpenFileDescription>> fds;
|
||||
|
||||
auto role = this->role(socket_description);
|
||||
if (role != Role::Connected && role != Role::Accepted)
|
||||
|
@ -15,8 +15,8 @@ namespace Kernel {
|
||||
class OpenFileDescription;
|
||||
|
||||
struct SocketPair {
|
||||
NonnullLockRefPtr<OpenFileDescription> description0;
|
||||
NonnullLockRefPtr<OpenFileDescription> description1;
|
||||
NonnullRefPtr<OpenFileDescription> description0;
|
||||
NonnullRefPtr<OpenFileDescription> description1;
|
||||
};
|
||||
|
||||
class LocalSocket final : public Socket {
|
||||
@ -26,9 +26,9 @@ public:
|
||||
static ErrorOr<SocketPair> try_create_connected_pair(int type);
|
||||
virtual ~LocalSocket() override;
|
||||
|
||||
ErrorOr<void> sendfd(OpenFileDescription const& socket_description, NonnullLockRefPtr<OpenFileDescription> passing_description);
|
||||
ErrorOr<NonnullLockRefPtr<OpenFileDescription>> recvfd(OpenFileDescription const& socket_description);
|
||||
ErrorOr<Vector<NonnullLockRefPtr<OpenFileDescription>>> recvfds(OpenFileDescription const& socket_description, int n);
|
||||
ErrorOr<void> sendfd(OpenFileDescription const& socket_description, NonnullRefPtr<OpenFileDescription> passing_description);
|
||||
ErrorOr<NonnullRefPtr<OpenFileDescription>> recvfd(OpenFileDescription const& socket_description);
|
||||
ErrorOr<Vector<NonnullRefPtr<OpenFileDescription>>> recvfds(OpenFileDescription const& socket_description, int n);
|
||||
|
||||
static void for_each(Function<void(LocalSocket const&)>);
|
||||
static ErrorOr<void> try_for_each(Function<ErrorOr<void>(LocalSocket const&)>);
|
||||
@ -60,8 +60,8 @@ private:
|
||||
bool has_attached_peer(OpenFileDescription const&) const;
|
||||
DoubleBuffer* receive_buffer_for(OpenFileDescription&);
|
||||
DoubleBuffer* send_buffer_for(OpenFileDescription&);
|
||||
Vector<NonnullLockRefPtr<OpenFileDescription>>& sendfd_queue_for(OpenFileDescription const&);
|
||||
Vector<NonnullLockRefPtr<OpenFileDescription>>& recvfd_queue_for(OpenFileDescription const&);
|
||||
Vector<NonnullRefPtr<OpenFileDescription>>& sendfd_queue_for(OpenFileDescription const&);
|
||||
Vector<NonnullRefPtr<OpenFileDescription>>& recvfd_queue_for(OpenFileDescription const&);
|
||||
|
||||
void set_connect_side_role(Role connect_side_role, bool force_evaluate_block_conditions = false)
|
||||
{
|
||||
@ -101,8 +101,8 @@ private:
|
||||
NonnullOwnPtr<DoubleBuffer> m_for_client;
|
||||
NonnullOwnPtr<DoubleBuffer> m_for_server;
|
||||
|
||||
Vector<NonnullLockRefPtr<OpenFileDescription>> m_fds_for_client;
|
||||
Vector<NonnullLockRefPtr<OpenFileDescription>> m_fds_for_server;
|
||||
Vector<NonnullRefPtr<OpenFileDescription>> m_fds_for_client;
|
||||
Vector<NonnullRefPtr<OpenFileDescription>> m_fds_for_server;
|
||||
|
||||
IntrusiveListNode<LocalSocket> m_list_node;
|
||||
|
||||
|
@ -570,13 +570,13 @@ Process::OpenFileDescriptionAndFlags& Process::OpenFileDescriptions::at(size_t i
|
||||
return m_fds_metadatas[i];
|
||||
}
|
||||
|
||||
ErrorOr<NonnullLockRefPtr<OpenFileDescription>> Process::OpenFileDescriptions::open_file_description(int fd) const
|
||||
ErrorOr<NonnullRefPtr<OpenFileDescription>> Process::OpenFileDescriptions::open_file_description(int fd) const
|
||||
{
|
||||
if (fd < 0)
|
||||
return EBADF;
|
||||
if (static_cast<size_t>(fd) >= m_fds_metadatas.size())
|
||||
return EBADF;
|
||||
LockRefPtr description = m_fds_metadatas[fd].description();
|
||||
RefPtr description = m_fds_metadatas[fd].description();
|
||||
if (!description)
|
||||
return EBADF;
|
||||
return description.release_nonnull();
|
||||
@ -706,7 +706,7 @@ ErrorOr<void> Process::dump_perfcore()
|
||||
return KString::formatted("{}_{}", process_name->view(), pid().value());
|
||||
}));
|
||||
auto perfcore_filename = TRY(KString::formatted("{}.profile", base_filename));
|
||||
LockRefPtr<OpenFileDescription> description;
|
||||
RefPtr<OpenFileDescription> description;
|
||||
auto credentials = this->credentials();
|
||||
for (size_t attempt = 1; attempt <= 10; ++attempt) {
|
||||
auto description_or_error = VirtualFileSystem::the().open(*this, credentials, perfcore_filename->view(), O_CREAT | O_EXCL, 0400, current_directory(), UidAndGid { 0, 0 });
|
||||
@ -945,7 +945,7 @@ void Process::OpenFileDescriptionAndFlags::clear()
|
||||
m_flags = 0;
|
||||
}
|
||||
|
||||
void Process::OpenFileDescriptionAndFlags::set(NonnullLockRefPtr<OpenFileDescription>&& description, u32 flags)
|
||||
void Process::OpenFileDescriptionAndFlags::set(NonnullRefPtr<OpenFileDescription> description, u32 flags)
|
||||
{
|
||||
m_description = move(description);
|
||||
m_flags = flags;
|
||||
|
@ -475,7 +475,7 @@ public:
|
||||
|
||||
ErrorOr<void> exec(NonnullOwnPtr<KString> path, Vector<NonnullOwnPtr<KString>> arguments, Vector<NonnullOwnPtr<KString>> environment, Thread*& new_main_thread, InterruptsState& previous_interrupts_state, int recursion_depth = 0);
|
||||
|
||||
ErrorOr<LoadResult> load(NonnullLockRefPtr<OpenFileDescription> main_program_description, LockRefPtr<OpenFileDescription> interpreter_description, const ElfW(Ehdr) & main_program_header);
|
||||
ErrorOr<LoadResult> load(NonnullRefPtr<OpenFileDescription> main_program_description, RefPtr<OpenFileDescription> interpreter_description, const ElfW(Ehdr) & main_program_header);
|
||||
|
||||
void terminate_due_to_signal(u8 signal);
|
||||
ErrorOr<void> send_signal(u8 signal, Process* sender);
|
||||
@ -605,12 +605,12 @@ private:
|
||||
bool create_perf_events_buffer_if_needed();
|
||||
void delete_perf_events_buffer();
|
||||
|
||||
ErrorOr<void> do_exec(NonnullLockRefPtr<OpenFileDescription> main_program_description, Vector<NonnullOwnPtr<KString>> arguments, Vector<NonnullOwnPtr<KString>> environment, LockRefPtr<OpenFileDescription> interpreter_description, Thread*& new_main_thread, InterruptsState& previous_interrupts_state, const ElfW(Ehdr) & main_program_header);
|
||||
ErrorOr<void> do_exec(NonnullRefPtr<OpenFileDescription> main_program_description, Vector<NonnullOwnPtr<KString>> arguments, Vector<NonnullOwnPtr<KString>> environment, RefPtr<OpenFileDescription> interpreter_description, Thread*& new_main_thread, InterruptsState& previous_interrupts_state, const ElfW(Ehdr) & main_program_header);
|
||||
ErrorOr<FlatPtr> do_write(OpenFileDescription&, UserOrKernelBuffer const&, size_t, Optional<off_t> = {});
|
||||
|
||||
ErrorOr<FlatPtr> do_statvfs(FileSystem const& path, Custody const*, statvfs* buf);
|
||||
|
||||
ErrorOr<LockRefPtr<OpenFileDescription>> find_elf_interpreter_for_executable(StringView path, ElfW(Ehdr) const& main_executable_header, size_t main_executable_header_size, size_t file_size);
|
||||
ErrorOr<RefPtr<OpenFileDescription>> find_elf_interpreter_for_executable(StringView path, ElfW(Ehdr) const& main_executable_header, size_t main_executable_header_size, size_t file_size);
|
||||
|
||||
ErrorOr<void> do_kill(Process&, int signal);
|
||||
ErrorOr<void> do_killpg(ProcessGroupID pgrp, int signal);
|
||||
@ -704,10 +704,10 @@ public:
|
||||
void set_flags(u32 flags) { m_flags = flags; }
|
||||
|
||||
void clear();
|
||||
void set(NonnullLockRefPtr<OpenFileDescription>&&, u32 flags = 0);
|
||||
void set(NonnullRefPtr<OpenFileDescription>, u32 flags = 0);
|
||||
|
||||
private:
|
||||
LockRefPtr<OpenFileDescription> m_description;
|
||||
RefPtr<OpenFileDescription> m_description;
|
||||
bool m_is_allocated { false };
|
||||
u32 m_flags { 0 };
|
||||
};
|
||||
@ -758,7 +758,7 @@ public:
|
||||
m_fds_metadatas.clear();
|
||||
}
|
||||
|
||||
ErrorOr<NonnullLockRefPtr<OpenFileDescription>> open_file_description(int fd) const;
|
||||
ErrorOr<NonnullRefPtr<OpenFileDescription>> open_file_description(int fd) const;
|
||||
|
||||
private:
|
||||
static constexpr size_t s_max_open_file_descriptors { FD_SETSIZE };
|
||||
@ -808,12 +808,12 @@ public:
|
||||
MutexProtected<OpenFileDescriptions>& fds() { return m_fds; }
|
||||
MutexProtected<OpenFileDescriptions> const& fds() const { return m_fds; }
|
||||
|
||||
ErrorOr<NonnullLockRefPtr<OpenFileDescription>> open_file_description(int fd)
|
||||
ErrorOr<NonnullRefPtr<OpenFileDescription>> open_file_description(int fd)
|
||||
{
|
||||
return m_fds.with_shared([fd](auto& fds) { return fds.open_file_description(fd); });
|
||||
}
|
||||
|
||||
ErrorOr<NonnullLockRefPtr<OpenFileDescription>> open_file_description(int fd) const
|
||||
ErrorOr<NonnullRefPtr<OpenFileDescription>> open_file_description(int fd) const
|
||||
{
|
||||
return m_fds.with_shared([fd](auto& fds) { return fds.open_file_description(fd); });
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ ErrorOr<FlatPtr> Process::sys$anon_create(size_t size, int options)
|
||||
|
||||
return m_fds.with_exclusive([&](auto& fds) -> ErrorOr<FlatPtr> {
|
||||
auto new_fd = TRY(fds.allocate());
|
||||
fds[new_fd.fd].set(move(description), fd_flags);
|
||||
fds[new_fd.fd].set(description, fd_flags);
|
||||
return new_fd.fd;
|
||||
});
|
||||
}
|
||||
|
@ -423,8 +423,8 @@ static ErrorOr<LoadResult> load_elf_object(NonnullOwnPtr<Memory::AddressSpace> n
|
||||
}
|
||||
|
||||
ErrorOr<LoadResult>
|
||||
Process::load(NonnullLockRefPtr<OpenFileDescription> main_program_description,
|
||||
LockRefPtr<OpenFileDescription> interpreter_description, const ElfW(Ehdr) & main_program_header)
|
||||
Process::load(NonnullRefPtr<OpenFileDescription> main_program_description,
|
||||
RefPtr<OpenFileDescription> interpreter_description, const ElfW(Ehdr) & main_program_header)
|
||||
{
|
||||
auto new_space = TRY(Memory::AddressSpace::try_create(nullptr));
|
||||
|
||||
@ -471,8 +471,8 @@ void Process::clear_signal_handlers_for_exec()
|
||||
}
|
||||
}
|
||||
|
||||
ErrorOr<void> Process::do_exec(NonnullLockRefPtr<OpenFileDescription> main_program_description, Vector<NonnullOwnPtr<KString>> arguments, Vector<NonnullOwnPtr<KString>> environment,
|
||||
LockRefPtr<OpenFileDescription> interpreter_description, Thread*& new_main_thread, InterruptsState& previous_interrupts_state, const ElfW(Ehdr) & main_program_header)
|
||||
ErrorOr<void> Process::do_exec(NonnullRefPtr<OpenFileDescription> main_program_description, Vector<NonnullOwnPtr<KString>> arguments, Vector<NonnullOwnPtr<KString>> environment,
|
||||
RefPtr<OpenFileDescription> interpreter_description, Thread*& new_main_thread, InterruptsState& previous_interrupts_state, const ElfW(Ehdr) & main_program_header)
|
||||
{
|
||||
VERIFY(is_user_process());
|
||||
VERIFY(!Processor::in_critical());
|
||||
@ -784,7 +784,7 @@ static ErrorOr<Vector<NonnullOwnPtr<KString>>> find_shebang_interpreter_for_exec
|
||||
return ENOEXEC;
|
||||
}
|
||||
|
||||
ErrorOr<LockRefPtr<OpenFileDescription>> Process::find_elf_interpreter_for_executable(StringView path, ElfW(Ehdr) const& main_executable_header, size_t main_executable_header_size, size_t file_size)
|
||||
ErrorOr<RefPtr<OpenFileDescription>> Process::find_elf_interpreter_for_executable(StringView path, ElfW(Ehdr) const& main_executable_header, size_t main_executable_header_size, size_t file_size)
|
||||
{
|
||||
// Not using ErrorOr here because we'll want to do the same thing in userspace in the RTLD
|
||||
StringBuilder interpreter_path_builder;
|
||||
|
@ -196,7 +196,7 @@ ErrorOr<FlatPtr> Process::sys$mmap(Userspace<Syscall::SC_mmap_params const*> use
|
||||
|
||||
Memory::Region* region = nullptr;
|
||||
|
||||
LockRefPtr<OpenFileDescription> description;
|
||||
RefPtr<OpenFileDescription> description;
|
||||
LockRefPtr<Memory::VMObject> vmobject;
|
||||
u64 used_offset = 0;
|
||||
|
||||
|
@ -51,7 +51,7 @@ ErrorOr<FlatPtr> Process::sys$poll(Userspace<Syscall::SC_poll_params const*> use
|
||||
TRY(m_fds.with_shared([&](auto& fds) -> ErrorOr<void> {
|
||||
for (size_t i = 0; i < params.nfds; i++) {
|
||||
auto& pfd = fds_copy[i];
|
||||
LockRefPtr<OpenFileDescription> description;
|
||||
RefPtr<OpenFileDescription> description;
|
||||
auto description_or_error = fds.open_file_description(pfd.fd);
|
||||
if (!description_or_error.is_error())
|
||||
description = description_or_error.release_value();
|
||||
|
@ -13,7 +13,7 @@ namespace Kernel {
|
||||
|
||||
using BlockFlags = Thread::FileBlocker::BlockFlags;
|
||||
|
||||
static ErrorOr<NonnullLockRefPtr<OpenFileDescription>> open_readable_file_description(auto& fds, int fd)
|
||||
static ErrorOr<NonnullRefPtr<OpenFileDescription>> open_readable_file_description(auto& fds, int fd)
|
||||
{
|
||||
auto description = TRY(fds.with_shared([&](auto& fds) { return fds.open_file_description(fd); }));
|
||||
if (!description->is_readable())
|
||||
|
@ -20,7 +20,7 @@ namespace Kernel {
|
||||
TRY(require_promise(Pledge::unix)); \
|
||||
} while (0)
|
||||
|
||||
static void setup_socket_fd(Process::OpenFileDescriptions& fds, int fd, NonnullLockRefPtr<OpenFileDescription> description, int type)
|
||||
static void setup_socket_fd(Process::OpenFileDescriptions& fds, int fd, NonnullRefPtr<OpenFileDescription> description, int type)
|
||||
{
|
||||
description->set_readable(true);
|
||||
description->set_writable(true);
|
||||
@ -94,7 +94,7 @@ ErrorOr<FlatPtr> Process::sys$accept4(Userspace<Syscall::SC_accept4_params const
|
||||
TRY(copy_from_user(&address_size, static_ptr_cast<socklen_t const*>(user_address_size)));
|
||||
|
||||
ScopedDescriptionAllocation fd_allocation;
|
||||
LockRefPtr<OpenFileDescription> accepting_socket_description;
|
||||
RefPtr<OpenFileDescription> accepting_socket_description;
|
||||
|
||||
TRY(m_fds.with_exclusive([&](auto& fds) -> ErrorOr<void> {
|
||||
fd_allocation = TRY(fds.allocate());
|
||||
|
@ -38,7 +38,7 @@ ErrorOr<FlatPtr> Process::sys$utimensat(Userspace<Syscall::SC_utimensat_params c
|
||||
}
|
||||
|
||||
OwnPtr<KString> path;
|
||||
LockRefPtr<OpenFileDescription> description;
|
||||
RefPtr<OpenFileDescription> description;
|
||||
RefPtr<Custody> base;
|
||||
|
||||
auto path_or_error = get_syscall_path_argument(params.path);
|
||||
|
@ -38,9 +38,9 @@ UNMAP_AFTER_INIT void PTYMultiplexer::initialize()
|
||||
MUST(the().after_inserting());
|
||||
}
|
||||
|
||||
ErrorOr<NonnullLockRefPtr<OpenFileDescription>> PTYMultiplexer::open(int options)
|
||||
ErrorOr<NonnullRefPtr<OpenFileDescription>> PTYMultiplexer::open(int options)
|
||||
{
|
||||
return m_freelist.with([&](auto& freelist) -> ErrorOr<NonnullLockRefPtr<OpenFileDescription>> {
|
||||
return m_freelist.with([&](auto& freelist) -> ErrorOr<NonnullRefPtr<OpenFileDescription>> {
|
||||
if (freelist.is_empty())
|
||||
return EBUSY;
|
||||
|
||||
|
@ -22,7 +22,7 @@ public:
|
||||
static PTYMultiplexer& the();
|
||||
|
||||
// ^CharacterDevice
|
||||
virtual ErrorOr<NonnullLockRefPtr<OpenFileDescription>> open(int options) override;
|
||||
virtual ErrorOr<NonnullRefPtr<OpenFileDescription>> open(int options) override;
|
||||
virtual ErrorOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override { return 0; }
|
||||
virtual ErrorOr<size_t> write(OpenFileDescription&, u64, UserOrKernelBuffer const&, size_t) override { return 0; }
|
||||
virtual bool can_read(OpenFileDescription const&, u64) const override { return true; }
|
||||
|
@ -519,7 +519,7 @@ public:
|
||||
explicit OpenFileDescriptionBlocker(OpenFileDescription&, BlockFlags, BlockFlags&);
|
||||
|
||||
private:
|
||||
NonnullLockRefPtr<OpenFileDescription> m_blocked_description;
|
||||
NonnullRefPtr<OpenFileDescription> m_blocked_description;
|
||||
const BlockFlags m_flags;
|
||||
BlockFlags& m_unblocked_flags;
|
||||
bool m_did_unblock { false };
|
||||
@ -577,7 +577,7 @@ public:
|
||||
class SelectBlocker final : public FileBlocker {
|
||||
public:
|
||||
struct FDInfo {
|
||||
LockRefPtr<OpenFileDescription> description;
|
||||
RefPtr<OpenFileDescription> description;
|
||||
BlockFlags block_flags { BlockFlags::None };
|
||||
BlockFlags unblocked_flags { BlockFlags::None };
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user