summaryrefslogtreecommitdiff
path: root/Kernel/Syscalls/poll.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-01-29 02:09:18 +0100
committerAndreas Kling <kling@serenityos.org>2022-01-29 02:17:12 +0100
commitd748a3c17351926e641928816643118d4d160ded (patch)
tree83c5e1b74704a159d69bbaeeb17d22b8edf84376 /Kernel/Syscalls/poll.cpp
parentb56646e2936c98a9b9ff89adbdd2e437ce218d92 (diff)
downloadserenity-d748a3c17351926e641928816643118d4d160ded.zip
Kernel: Only lock process file descriptor table once in sys$poll()
Grab the OpenFileDescriptions mutex once and hold on to it while populating the SelectBlocker::FDVector.
Diffstat (limited to 'Kernel/Syscalls/poll.cpp')
-rw-r--r--Kernel/Syscalls/poll.cpp31
1 files changed, 17 insertions, 14 deletions
diff --git a/Kernel/Syscalls/poll.cpp b/Kernel/Syscalls/poll.cpp
index a783b72f4d..1ea55e2dad 100644
--- a/Kernel/Syscalls/poll.cpp
+++ b/Kernel/Syscalls/poll.cpp
@@ -47,20 +47,23 @@ ErrorOr<FlatPtr> Process::sys$poll(Userspace<const Syscall::SC_poll_params*> use
Thread::SelectBlocker::FDVector fds_info;
TRY(fds_info.try_ensure_capacity(params.nfds));
- for (size_t i = 0; i < params.nfds; i++) {
- auto& pfd = fds_copy[i];
- 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
- if (pfd.events & POLLIN)
- block_flags |= BlockFlags::Read;
- if (pfd.events & POLLOUT)
- block_flags |= BlockFlags::Write;
- if (pfd.events & POLLPRI)
- block_flags |= BlockFlags::ReadPriority;
- if (pfd.events & POLLWRBAND)
- block_flags |= BlockFlags::WritePriority;
- fds_info.unchecked_append({ move(description), block_flags });
- }
+ TRY(m_fds.with_shared([&](auto& fds) -> ErrorOr<void> {
+ for (size_t i = 0; i < params.nfds; i++) {
+ auto& pfd = fds_copy[i];
+ auto description = TRY(fds.open_file_description(pfd.fd));
+ BlockFlags block_flags = BlockFlags::Exception; // always want POLLERR, POLLHUP, POLLNVAL
+ if (pfd.events & POLLIN)
+ block_flags |= BlockFlags::Read;
+ if (pfd.events & POLLOUT)
+ block_flags |= BlockFlags::Write;
+ if (pfd.events & POLLPRI)
+ block_flags |= BlockFlags::ReadPriority;
+ if (pfd.events & POLLWRBAND)
+ block_flags |= BlockFlags::WritePriority;
+ fds_info.unchecked_append({ move(description), block_flags });
+ }
+ return {};
+ }));
auto* current_thread = Thread::current();