1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:38:11 +00:00

Kernel: Don't copy a Vector<FileDescriptionAndFlags>

Instead of copying a Vector everytime we need to enumerate a Process'
file descriptions, we can just temporarily lock so it won't change.
This commit is contained in:
Liav A 2021-06-22 21:22:17 +03:00 committed by Andreas Kling
parent 12b6e69150
commit 7c87891c06
28 changed files with 198 additions and 128 deletions

View file

@ -13,7 +13,7 @@ namespace Kernel {
KResultOr<FlatPtr> Process::sys$pipe(int pipefd[2], int flags)
{
REQUIRE_PROMISE(stdio);
if (number_of_open_file_descriptors() + 2 > max_open_file_descriptors())
if (fds().open_count() + 2 > fds().max_open())
return EMFILE;
// Reject flags other than O_CLOEXEC.
if ((flags & O_CLOEXEC) != flags)
@ -29,13 +29,13 @@ KResultOr<FlatPtr> Process::sys$pipe(int pipefd[2], int flags)
if (open_writer_result.is_error())
return open_writer_result.error();
int reader_fd = alloc_fd();
int reader_fd = m_fds.allocate();
m_fds[reader_fd].set(open_reader_result.release_value(), fd_flags);
m_fds[reader_fd].description()->set_readable(true);
if (!copy_to_user(&pipefd[0], &reader_fd))
return EFAULT;
int writer_fd = alloc_fd();
int writer_fd = m_fds.allocate();
m_fds[writer_fd].set(open_writer_result.release_value(), fd_flags);
m_fds[writer_fd].description()->set_writable(true);
if (!copy_to_user(&pipefd[1], &writer_fd))