diff options
author | Liav A <liavalb@gmail.com> | 2022-08-19 13:29:43 +0300 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-08-21 10:56:48 +0100 |
commit | 5331d243c690c70e431e2f8d260eacab19946c2b (patch) | |
tree | 26722cb60573c7ce1a7b2835e2d89f540a973d2f | |
parent | 0eaee045cfb0a08abda443e6b9bd9dfd0949f43c (diff) | |
download | serenity-5331d243c690c70e431e2f8d260eacab19946c2b.zip |
Kernel/Syscall: Make anon_create to not use Process::allocate_fd method
Instead, allocate when acquiring the lock on m_fds struct, which is
safer to do in terms of safely mutating the m_fds struct, because we
don't use the big process lock in this syscall.
-rw-r--r-- | Kernel/Syscalls/anon_create.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/Kernel/Syscalls/anon_create.cpp b/Kernel/Syscalls/anon_create.cpp index 334e7e9797..c87196b8b5 100644 --- a/Kernel/Syscalls/anon_create.cpp +++ b/Kernel/Syscalls/anon_create.cpp @@ -25,7 +25,6 @@ ErrorOr<FlatPtr> Process::sys$anon_create(size_t size, int options) if (size > NumericLimits<ssize_t>::max()) return EINVAL; - auto new_fd = TRY(allocate_fd()); auto vmobject = TRY(Memory::AnonymousVMObject::try_create_purgeable_with_size(size, AllocationStrategy::AllocateNow)); auto anon_file = TRY(AnonymousFile::try_create(move(vmobject))); auto description = TRY(OpenFileDescription::try_create(move(anon_file))); @@ -37,8 +36,11 @@ ErrorOr<FlatPtr> Process::sys$anon_create(size_t size, int options) if (options & O_CLOEXEC) fd_flags |= FD_CLOEXEC; - m_fds.with_exclusive([&](auto& fds) { fds[new_fd.fd].set(move(description), fd_flags); }); - return new_fd.fd; + return m_fds.with_exclusive([&](auto& fds) -> ErrorOr<FlatPtr> { + auto new_fd = TRY(fds.allocate()); + fds[new_fd.fd].set(move(description), fd_flags); + return new_fd.fd; + }); } } |