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.
This commit is contained in:
Andreas Kling 2022-01-29 02:09:18 +01:00
parent b56646e293
commit d748a3c173
Notes: sideshowbarker 2024-07-17 20:03:34 +09:00

View File

@ -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();