mirror of
https://github.com/RGBCube/serenity
synced 2025-05-21 15:35:07 +00:00
Kernel: Switch process file descriptor table from spinlock to mutex
There's no reason for this to use a spinlock. Instead, let's allow threads to block if someone else is using the descriptor table.
This commit is contained in:
parent
8ebec2938c
commit
b56646e293
16 changed files with 37 additions and 37 deletions
|
@ -490,7 +490,7 @@ private:
|
||||||
process_object.add("uid", process.uid().value());
|
process_object.add("uid", process.uid().value());
|
||||||
process_object.add("gid", process.gid().value());
|
process_object.add("gid", process.gid().value());
|
||||||
process_object.add("ppid", process.ppid().value());
|
process_object.add("ppid", process.ppid().value());
|
||||||
process_object.add("nfds", process.fds().with([](auto& fds) { return fds.open_count(); }));
|
process_object.add("nfds", process.fds().with_shared([](auto& fds) { return fds.open_count(); }));
|
||||||
process_object.add("name", process.name());
|
process_object.add("name", process.name());
|
||||||
process_object.add("executable", process.executable() ? TRY(process.executable()->try_serialize_absolute_path())->view() : ""sv);
|
process_object.add("executable", process.executable() ? TRY(process.executable()->try_serialize_absolute_path())->view() : ""sv);
|
||||||
process_object.add("tty", process.tty() ? process.tty()->tty_name().view() : "notty"sv);
|
process_object.add("tty", process.tty() ? process.tty()->tty_name().view() : "notty"sv);
|
||||||
|
|
|
@ -139,7 +139,7 @@ ErrorOr<NonnullRefPtr<Process>> Process::try_create_user_process(RefPtr<Thread>&
|
||||||
auto name = TRY(KString::try_create(parts.last()));
|
auto name = TRY(KString::try_create(parts.last()));
|
||||||
auto process = TRY(Process::try_create(first_thread, move(name), uid, gid, ProcessID(0), false, VirtualFileSystem::the().root_custody(), nullptr, tty));
|
auto process = TRY(Process::try_create(first_thread, move(name), uid, gid, ProcessID(0), false, VirtualFileSystem::the().root_custody(), nullptr, tty));
|
||||||
|
|
||||||
TRY(process->m_fds.with([&](auto& fds) -> ErrorOr<void> {
|
TRY(process->m_fds.with_exclusive([&](auto& fds) -> ErrorOr<void> {
|
||||||
TRY(fds.try_resize(Process::OpenFileDescriptions::max_open()));
|
TRY(fds.try_resize(Process::OpenFileDescriptions::max_open()));
|
||||||
|
|
||||||
auto& device_to_use_as_tty = tty ? (CharacterDevice&)*tty : DeviceManagement::the().null_device();
|
auto& device_to_use_as_tty = tty ? (CharacterDevice&)*tty : DeviceManagement::the().null_device();
|
||||||
|
@ -589,7 +589,7 @@ void Process::finalize()
|
||||||
|
|
||||||
if (m_alarm_timer)
|
if (m_alarm_timer)
|
||||||
TimerQueue::the().cancel_timer(m_alarm_timer.release_nonnull());
|
TimerQueue::the().cancel_timer(m_alarm_timer.release_nonnull());
|
||||||
m_fds.with([](auto& fds) { fds.clear(); });
|
m_fds.with_exclusive([](auto& fds) { fds.clear(); });
|
||||||
m_tty = nullptr;
|
m_tty = nullptr;
|
||||||
m_executable = nullptr;
|
m_executable = nullptr;
|
||||||
m_cwd = nullptr;
|
m_cwd = nullptr;
|
||||||
|
|
|
@ -746,22 +746,22 @@ public:
|
||||||
WeakPtr<Process> m_process;
|
WeakPtr<Process> m_process;
|
||||||
};
|
};
|
||||||
|
|
||||||
SpinlockProtected<OpenFileDescriptions>& fds() { return m_fds; }
|
MutexProtected<OpenFileDescriptions>& fds() { return m_fds; }
|
||||||
SpinlockProtected<OpenFileDescriptions> const& fds() const { return m_fds; }
|
MutexProtected<OpenFileDescriptions> const& fds() const { return m_fds; }
|
||||||
|
|
||||||
ErrorOr<NonnullRefPtr<OpenFileDescription>> open_file_description(int fd)
|
ErrorOr<NonnullRefPtr<OpenFileDescription>> open_file_description(int fd)
|
||||||
{
|
{
|
||||||
return m_fds.with([fd](auto& fds) { return fds.open_file_description(fd); });
|
return m_fds.with_shared([fd](auto& fds) { return fds.open_file_description(fd); });
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<NonnullRefPtr<OpenFileDescription>> open_file_description(int fd) const
|
ErrorOr<NonnullRefPtr<OpenFileDescription>> open_file_description(int fd) const
|
||||||
{
|
{
|
||||||
return m_fds.with([fd](auto& fds) { return fds.open_file_description(fd); });
|
return m_fds.with_shared([fd](auto& fds) { return fds.open_file_description(fd); });
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<ScopedDescriptionAllocation> allocate_fd()
|
ErrorOr<ScopedDescriptionAllocation> allocate_fd()
|
||||||
{
|
{
|
||||||
return m_fds.with([](auto& fds) { return fds.allocate(); });
|
return m_fds.with_exclusive([](auto& fds) { return fds.allocate(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -770,7 +770,7 @@ private:
|
||||||
|
|
||||||
SpinlockProtected<Thread::ListInProcess> m_thread_list;
|
SpinlockProtected<Thread::ListInProcess> m_thread_list;
|
||||||
|
|
||||||
SpinlockProtected<OpenFileDescriptions> m_fds;
|
MutexProtected<OpenFileDescriptions> m_fds;
|
||||||
|
|
||||||
const bool m_is_kernel_process;
|
const bool m_is_kernel_process;
|
||||||
Atomic<State> m_state { State::Running };
|
Atomic<State> m_state { State::Running };
|
||||||
|
|
|
@ -95,7 +95,7 @@ ErrorOr<void> Process::traverse_file_descriptions_directory(FileSystemID fsid, F
|
||||||
TRY(callback({ ".", { fsid, m_procfs_traits->component_index() }, 0 }));
|
TRY(callback({ ".", { fsid, m_procfs_traits->component_index() }, 0 }));
|
||||||
TRY(callback({ "..", { fsid, m_procfs_traits->component_index() }, 0 }));
|
TRY(callback({ "..", { fsid, m_procfs_traits->component_index() }, 0 }));
|
||||||
size_t count = 0;
|
size_t count = 0;
|
||||||
fds().with([&](auto& fds) {
|
fds().with_shared([&](auto& fds) {
|
||||||
fds.enumerate([&](auto& file_description_metadata) {
|
fds.enumerate([&](auto& file_description_metadata) {
|
||||||
if (!file_description_metadata.is_valid()) {
|
if (!file_description_metadata.is_valid()) {
|
||||||
count++;
|
count++;
|
||||||
|
@ -117,7 +117,7 @@ ErrorOr<NonnullRefPtr<Inode>> Process::lookup_file_descriptions_directory(const
|
||||||
if (!maybe_index.has_value())
|
if (!maybe_index.has_value())
|
||||||
return ENOENT;
|
return ENOENT;
|
||||||
|
|
||||||
if (!fds().with([&](auto& fds) { return fds.get_if_valid(*maybe_index); }))
|
if (!m_fds.with_shared([&](auto& fds) { return fds.get_if_valid(*maybe_index); }))
|
||||||
return ENOENT;
|
return ENOENT;
|
||||||
|
|
||||||
return TRY(ProcFSProcessPropertyInode::try_create_for_file_description_link(procfs, *maybe_index, pid()));
|
return TRY(ProcFSProcessPropertyInode::try_create_for_file_description_link(procfs, *maybe_index, pid()));
|
||||||
|
@ -181,7 +181,7 @@ ErrorOr<void> Process::procfs_get_fds_stats(KBufferBuilder& builder) const
|
||||||
{
|
{
|
||||||
JsonArraySerializer array { builder };
|
JsonArraySerializer array { builder };
|
||||||
|
|
||||||
return fds().with([&](auto& fds) -> ErrorOr<void> {
|
return fds().with_shared([&](auto& fds) -> ErrorOr<void> {
|
||||||
if (fds.open_count() == 0) {
|
if (fds.open_count() == 0) {
|
||||||
array.finish();
|
array.finish();
|
||||||
return {};
|
return {};
|
||||||
|
|
|
@ -37,7 +37,7 @@ ErrorOr<FlatPtr> Process::sys$anon_create(size_t size, int options)
|
||||||
if (options & O_CLOEXEC)
|
if (options & O_CLOEXEC)
|
||||||
fd_flags |= FD_CLOEXEC;
|
fd_flags |= FD_CLOEXEC;
|
||||||
|
|
||||||
m_fds.with([&](auto& fds) { fds[new_fd.fd].set(move(description), fd_flags); });
|
m_fds.with_exclusive([&](auto& fds) { fds[new_fd.fd].set(move(description), fd_flags); });
|
||||||
return new_fd.fd;
|
return new_fd.fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ ErrorOr<FlatPtr> Process::sys$dup2(int old_fd, int new_fd)
|
||||||
{
|
{
|
||||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
|
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
|
||||||
TRY(require_promise(Pledge::stdio));
|
TRY(require_promise(Pledge::stdio));
|
||||||
return m_fds.with([&](auto& fds) -> ErrorOr<FlatPtr> {
|
return m_fds.with_exclusive([&](auto& fds) -> ErrorOr<FlatPtr> {
|
||||||
auto description = TRY(fds.open_file_description(old_fd));
|
auto description = TRY(fds.open_file_description(old_fd));
|
||||||
if (old_fd == new_fd)
|
if (old_fd == new_fd)
|
||||||
return new_fd;
|
return new_fd;
|
||||||
|
|
|
@ -536,7 +536,7 @@ ErrorOr<void> Process::do_exec(NonnullRefPtr<OpenFileDescription> main_program_d
|
||||||
|
|
||||||
clear_futex_queues_on_exec();
|
clear_futex_queues_on_exec();
|
||||||
|
|
||||||
m_fds.with([&](auto& fds) {
|
m_fds.with_exclusive([&](auto& fds) {
|
||||||
fds.change_each([&](auto& file_description_metadata) {
|
fds.change_each([&](auto& file_description_metadata) {
|
||||||
if (file_description_metadata.is_valid() && file_description_metadata.flags() & FD_CLOEXEC)
|
if (file_description_metadata.is_valid() && file_description_metadata.flags() & FD_CLOEXEC)
|
||||||
file_description_metadata = {};
|
file_description_metadata = {};
|
||||||
|
@ -545,7 +545,7 @@ ErrorOr<void> Process::do_exec(NonnullRefPtr<OpenFileDescription> main_program_d
|
||||||
|
|
||||||
if (main_program_fd_allocation.has_value()) {
|
if (main_program_fd_allocation.has_value()) {
|
||||||
main_program_description->set_readable(true);
|
main_program_description->set_readable(true);
|
||||||
m_fds.with([&](auto& fds) { fds[main_program_fd_allocation->fd].set(move(main_program_description), FD_CLOEXEC); });
|
m_fds.with_exclusive([&](auto& fds) { fds[main_program_fd_allocation->fd].set(move(main_program_description), FD_CLOEXEC); });
|
||||||
}
|
}
|
||||||
|
|
||||||
new_main_thread = nullptr;
|
new_main_thread = nullptr;
|
||||||
|
|
|
@ -23,16 +23,16 @@ ErrorOr<FlatPtr> Process::sys$fcntl(int fd, int cmd, u32 arg)
|
||||||
int arg_fd = (int)arg;
|
int arg_fd = (int)arg;
|
||||||
if (arg_fd < 0)
|
if (arg_fd < 0)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
return m_fds.with([&](auto& fds) -> ErrorOr<FlatPtr> {
|
return m_fds.with_exclusive([&](auto& fds) -> ErrorOr<FlatPtr> {
|
||||||
auto fd_allocation = TRY(fds.allocate(arg_fd));
|
auto fd_allocation = TRY(fds.allocate(arg_fd));
|
||||||
fds[fd_allocation.fd].set(*description);
|
fds[fd_allocation.fd].set(*description);
|
||||||
return fd_allocation.fd;
|
return fd_allocation.fd;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
case F_GETFD:
|
case F_GETFD:
|
||||||
return m_fds.with([fd](auto& fds) { return fds[fd].flags(); });
|
return m_fds.with_exclusive([fd](auto& fds) { return fds[fd].flags(); });
|
||||||
case F_SETFD:
|
case F_SETFD:
|
||||||
m_fds.with([fd, arg](auto& fds) { fds[fd].set_flags(arg); });
|
m_fds.with_exclusive([fd, arg](auto& fds) { fds[fd].set_flags(arg); });
|
||||||
break;
|
break;
|
||||||
case F_GETFL:
|
case F_GETFL:
|
||||||
return description->file_flags();
|
return description->file_flags();
|
||||||
|
|
|
@ -23,8 +23,8 @@ ErrorOr<FlatPtr> Process::sys$fork(RegisterState& regs)
|
||||||
child->m_veil_state = m_veil_state;
|
child->m_veil_state = m_veil_state;
|
||||||
child->m_unveiled_paths = m_unveiled_paths.deep_copy();
|
child->m_unveiled_paths = m_unveiled_paths.deep_copy();
|
||||||
|
|
||||||
TRY(child->m_fds.with([&](auto& child_fds) {
|
TRY(child->m_fds.with_exclusive([&](auto& child_fds) {
|
||||||
return m_fds.with([&](auto& parent_fds) {
|
return m_fds.with_exclusive([&](auto& parent_fds) {
|
||||||
return child_fds.try_clone(parent_fds);
|
return child_fds.try_clone(parent_fds);
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -26,7 +26,7 @@ ErrorOr<FlatPtr> Process::sys$create_inode_watcher(u32 flags)
|
||||||
if (flags & static_cast<unsigned>(InodeWatcherFlags::Nonblock))
|
if (flags & static_cast<unsigned>(InodeWatcherFlags::Nonblock))
|
||||||
description->set_blocking(false);
|
description->set_blocking(false);
|
||||||
|
|
||||||
return m_fds.with([&](auto& fds) -> ErrorOr<FlatPtr> {
|
return m_fds.with_exclusive([&](auto& fds) -> ErrorOr<FlatPtr> {
|
||||||
fds[fd_allocation.fd].set(move(description));
|
fds[fd_allocation.fd].set(move(description));
|
||||||
|
|
||||||
if (flags & static_cast<unsigned>(InodeWatcherFlags::CloseOnExec))
|
if (flags & static_cast<unsigned>(InodeWatcherFlags::CloseOnExec))
|
||||||
|
|
|
@ -59,7 +59,7 @@ ErrorOr<FlatPtr> Process::sys$open(Userspace<const Syscall::SC_open_params*> use
|
||||||
if (description->inode() && description->inode()->socket())
|
if (description->inode() && description->inode()->socket())
|
||||||
return ENXIO;
|
return ENXIO;
|
||||||
|
|
||||||
return m_fds.with([&](auto& fds) -> ErrorOr<FlatPtr> {
|
return m_fds.with_exclusive([&](auto& fds) -> ErrorOr<FlatPtr> {
|
||||||
u32 fd_flags = (options & O_CLOEXEC) ? FD_CLOEXEC : 0;
|
u32 fd_flags = (options & O_CLOEXEC) ? FD_CLOEXEC : 0;
|
||||||
fds[fd_allocation.fd].set(move(description), fd_flags);
|
fds[fd_allocation.fd].set(move(description), fd_flags);
|
||||||
return fd_allocation.fd;
|
return fd_allocation.fd;
|
||||||
|
@ -72,7 +72,7 @@ ErrorOr<FlatPtr> Process::sys$close(int fd)
|
||||||
TRY(require_promise(Pledge::stdio));
|
TRY(require_promise(Pledge::stdio));
|
||||||
auto description = TRY(open_file_description(fd));
|
auto description = TRY(open_file_description(fd));
|
||||||
auto result = description->close();
|
auto result = description->close();
|
||||||
m_fds.with([fd](auto& fds) { fds[fd] = {}; });
|
m_fds.with_exclusive([fd](auto& fds) { fds[fd] = {}; });
|
||||||
if (result.is_error())
|
if (result.is_error())
|
||||||
return result.release_error();
|
return result.release_error();
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -13,7 +13,7 @@ ErrorOr<FlatPtr> Process::sys$pipe(int pipefd[2], int flags)
|
||||||
{
|
{
|
||||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||||
TRY(require_promise(Pledge::stdio));
|
TRY(require_promise(Pledge::stdio));
|
||||||
auto open_count = fds().with([](auto& fds) { return fds.open_count(); });
|
auto open_count = fds().with_shared([](auto& fds) { return fds.open_count(); });
|
||||||
if (open_count + 2 > OpenFileDescriptions::max_open())
|
if (open_count + 2 > OpenFileDescriptions::max_open())
|
||||||
return EMFILE;
|
return EMFILE;
|
||||||
// Reject flags other than O_CLOEXEC, O_NONBLOCK
|
// Reject flags other than O_CLOEXEC, O_NONBLOCK
|
||||||
|
@ -26,7 +26,7 @@ ErrorOr<FlatPtr> Process::sys$pipe(int pipefd[2], int flags)
|
||||||
ScopedDescriptionAllocation reader_fd_allocation;
|
ScopedDescriptionAllocation reader_fd_allocation;
|
||||||
ScopedDescriptionAllocation writer_fd_allocation;
|
ScopedDescriptionAllocation writer_fd_allocation;
|
||||||
|
|
||||||
TRY(m_fds.with([&](auto& fds) -> ErrorOr<void> {
|
TRY(m_fds.with_exclusive([&](auto& fds) -> ErrorOr<void> {
|
||||||
reader_fd_allocation = TRY(fds.allocate());
|
reader_fd_allocation = TRY(fds.allocate());
|
||||||
writer_fd_allocation = TRY(fds.allocate());
|
writer_fd_allocation = TRY(fds.allocate());
|
||||||
return {};
|
return {};
|
||||||
|
@ -42,7 +42,7 @@ ErrorOr<FlatPtr> Process::sys$pipe(int pipefd[2], int flags)
|
||||||
writer_description->set_blocking(false);
|
writer_description->set_blocking(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
TRY(m_fds.with([&](auto& fds) -> ErrorOr<void> {
|
TRY(m_fds.with_exclusive([&](auto& fds) -> ErrorOr<void> {
|
||||||
fds[reader_fd_allocation.fd].set(move(reader_description), fd_flags);
|
fds[reader_fd_allocation.fd].set(move(reader_description), fd_flags);
|
||||||
fds[writer_fd_allocation.fd].set(move(writer_description), fd_flags);
|
fds[writer_fd_allocation.fd].set(move(writer_description), fd_flags);
|
||||||
return {};
|
return {};
|
||||||
|
|
|
@ -49,7 +49,7 @@ ErrorOr<FlatPtr> Process::sys$poll(Userspace<const Syscall::SC_poll_params*> use
|
||||||
|
|
||||||
for (size_t i = 0; i < params.nfds; i++) {
|
for (size_t i = 0; i < params.nfds; i++) {
|
||||||
auto& pfd = fds_copy[i];
|
auto& pfd = fds_copy[i];
|
||||||
auto description = TRY(m_fds.with([&](auto& fds) { return fds.open_file_description(pfd.fd); }));
|
auto description = TRY(m_fds.with_shared([&](auto& fds) { return fds.open_file_description(pfd.fd); }));
|
||||||
BlockFlags block_flags = BlockFlags::Exception; // always want POLLERR, POLLHUP, POLLNVAL
|
BlockFlags block_flags = BlockFlags::Exception; // always want POLLERR, POLLHUP, POLLNVAL
|
||||||
if (pfd.events & POLLIN)
|
if (pfd.events & POLLIN)
|
||||||
block_flags |= BlockFlags::Read;
|
block_flags |= BlockFlags::Read;
|
||||||
|
|
|
@ -14,7 +14,7 @@ using BlockFlags = Thread::FileBlocker::BlockFlags;
|
||||||
|
|
||||||
static ErrorOr<NonnullRefPtr<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([&](auto& fds) { return fds.open_file_description(fd); }));
|
auto description = TRY(fds.with_shared([&](auto& fds) { return fds.open_file_description(fd); }));
|
||||||
if (!description->is_readable())
|
if (!description->is_readable())
|
||||||
return EBADF;
|
return EBADF;
|
||||||
if (description->is_directory())
|
if (description->is_directory())
|
||||||
|
|
|
@ -40,7 +40,7 @@ ErrorOr<FlatPtr> Process::sys$recvfd(int sockfd, int options)
|
||||||
if (!socket.is_local())
|
if (!socket.is_local())
|
||||||
return EAFNOSUPPORT;
|
return EAFNOSUPPORT;
|
||||||
|
|
||||||
auto fd_allocation = TRY(m_fds.with([](auto& fds) { return fds.allocate(); }));
|
auto fd_allocation = TRY(m_fds.with_exclusive([](auto& fds) { return fds.allocate(); }));
|
||||||
|
|
||||||
auto& local_socket = static_cast<LocalSocket&>(socket);
|
auto& local_socket = static_cast<LocalSocket&>(socket);
|
||||||
auto received_description = TRY(local_socket.recvfd(*socket_description));
|
auto received_description = TRY(local_socket.recvfd(*socket_description));
|
||||||
|
@ -49,7 +49,7 @@ ErrorOr<FlatPtr> Process::sys$recvfd(int sockfd, int options)
|
||||||
if (options & O_CLOEXEC)
|
if (options & O_CLOEXEC)
|
||||||
fd_flags |= FD_CLOEXEC;
|
fd_flags |= FD_CLOEXEC;
|
||||||
|
|
||||||
m_fds.with([&](auto& fds) { fds[fd_allocation.fd].set(move(received_description), fd_flags); });
|
m_fds.with_exclusive([&](auto& fds) { fds[fd_allocation.fd].set(move(received_description), fd_flags); });
|
||||||
return fd_allocation.fd;
|
return fd_allocation.fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ ErrorOr<FlatPtr> Process::sys$socket(int domain, int type, int protocol)
|
||||||
if ((type & SOCK_TYPE_MASK) == SOCK_RAW && !is_superuser())
|
if ((type & SOCK_TYPE_MASK) == SOCK_RAW && !is_superuser())
|
||||||
return EACCES;
|
return EACCES;
|
||||||
|
|
||||||
return m_fds.with([&](auto& fds) -> ErrorOr<FlatPtr> {
|
return m_fds.with_exclusive([&](auto& fds) -> ErrorOr<FlatPtr> {
|
||||||
auto fd_allocation = TRY(fds.allocate());
|
auto fd_allocation = TRY(fds.allocate());
|
||||||
auto socket = TRY(Socket::create(domain, type, protocol));
|
auto socket = TRY(Socket::create(domain, type, protocol));
|
||||||
auto description = TRY(OpenFileDescription::try_create(socket));
|
auto description = TRY(OpenFileDescription::try_create(socket));
|
||||||
|
@ -51,7 +51,7 @@ ErrorOr<FlatPtr> Process::sys$socket(int domain, int type, int protocol)
|
||||||
ErrorOr<FlatPtr> Process::sys$bind(int sockfd, Userspace<const sockaddr*> address, socklen_t address_length)
|
ErrorOr<FlatPtr> Process::sys$bind(int sockfd, Userspace<const sockaddr*> address, socklen_t address_length)
|
||||||
{
|
{
|
||||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||||
return m_fds.with([&](auto& fds) -> ErrorOr<FlatPtr> {
|
return m_fds.with_exclusive([&](auto& fds) -> ErrorOr<FlatPtr> {
|
||||||
auto description = TRY(fds.open_file_description(sockfd));
|
auto description = TRY(fds.open_file_description(sockfd));
|
||||||
if (!description->is_socket())
|
if (!description->is_socket())
|
||||||
return ENOTSOCK;
|
return ENOTSOCK;
|
||||||
|
@ -67,7 +67,7 @@ ErrorOr<FlatPtr> Process::sys$listen(int sockfd, int backlog)
|
||||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||||
if (backlog < 0)
|
if (backlog < 0)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
return m_fds.with([&](auto& fds) -> ErrorOr<FlatPtr> {
|
return m_fds.with_exclusive([&](auto& fds) -> ErrorOr<FlatPtr> {
|
||||||
auto description = TRY(fds.open_file_description(sockfd));
|
auto description = TRY(fds.open_file_description(sockfd));
|
||||||
if (!description->is_socket())
|
if (!description->is_socket())
|
||||||
return ENOTSOCK;
|
return ENOTSOCK;
|
||||||
|
@ -99,7 +99,7 @@ ErrorOr<FlatPtr> Process::sys$accept4(Userspace<const Syscall::SC_accept4_params
|
||||||
ScopedDescriptionAllocation fd_allocation;
|
ScopedDescriptionAllocation fd_allocation;
|
||||||
RefPtr<OpenFileDescription> accepting_socket_description;
|
RefPtr<OpenFileDescription> accepting_socket_description;
|
||||||
|
|
||||||
TRY(m_fds.with([&](auto& fds) -> ErrorOr<void> {
|
TRY(m_fds.with_exclusive([&](auto& fds) -> ErrorOr<void> {
|
||||||
fd_allocation = TRY(fds.allocate());
|
fd_allocation = TRY(fds.allocate());
|
||||||
accepting_socket_description = TRY(fds.open_file_description(accepting_socket_fd));
|
accepting_socket_description = TRY(fds.open_file_description(accepting_socket_fd));
|
||||||
return {};
|
return {};
|
||||||
|
@ -138,7 +138,7 @@ ErrorOr<FlatPtr> Process::sys$accept4(Userspace<const Syscall::SC_accept4_params
|
||||||
if (flags & SOCK_CLOEXEC)
|
if (flags & SOCK_CLOEXEC)
|
||||||
fd_flags |= FD_CLOEXEC;
|
fd_flags |= FD_CLOEXEC;
|
||||||
|
|
||||||
TRY(m_fds.with([&](auto& fds) -> ErrorOr<void> {
|
TRY(m_fds.with_exclusive([&](auto& fds) -> ErrorOr<void> {
|
||||||
fds[fd_allocation.fd].set(move(accepted_socket_description), fd_flags);
|
fds[fd_allocation.fd].set(move(accepted_socket_description), fd_flags);
|
||||||
return {};
|
return {};
|
||||||
}));
|
}));
|
||||||
|
@ -361,7 +361,7 @@ ErrorOr<FlatPtr> Process::sys$socketpair(Userspace<const Syscall::SC_socketpair_
|
||||||
|
|
||||||
auto pair = TRY(LocalSocket::try_create_connected_pair(params.type & SOCK_TYPE_MASK));
|
auto pair = TRY(LocalSocket::try_create_connected_pair(params.type & SOCK_TYPE_MASK));
|
||||||
|
|
||||||
return m_fds.with([&](auto& fds) -> ErrorOr<FlatPtr> {
|
return m_fds.with_exclusive([&](auto& fds) -> ErrorOr<FlatPtr> {
|
||||||
auto fd_allocation0 = TRY(fds.allocate());
|
auto fd_allocation0 = TRY(fds.allocate());
|
||||||
auto fd_allocation1 = TRY(fds.allocate());
|
auto fd_allocation1 = TRY(fds.allocate());
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue