summaryrefslogtreecommitdiff
path: root/Kernel/Syscalls/pipe.cpp
diff options
context:
space:
mode:
authorLiav A <liavalb@gmail.com>2021-06-22 21:22:17 +0300
committerAndreas Kling <kling@serenityos.org>2021-06-29 20:53:59 +0200
commit7c87891c06e37f217b5fde17a3fc869306da659b (patch)
tree3017e40cfb6fbbd01e1f0b36b483003d498c189c /Kernel/Syscalls/pipe.cpp
parent12b6e6915034a0c0d1981caf419a35c0a8cd247e (diff)
downloadserenity-7c87891c06e37f217b5fde17a3fc869306da659b.zip
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.
Diffstat (limited to 'Kernel/Syscalls/pipe.cpp')
-rw-r--r--Kernel/Syscalls/pipe.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/Kernel/Syscalls/pipe.cpp b/Kernel/Syscalls/pipe.cpp
index b289a3958a..ef70709339 100644
--- a/Kernel/Syscalls/pipe.cpp
+++ b/Kernel/Syscalls/pipe.cpp
@@ -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))