diff options
Diffstat (limited to 'Kernel/Syscalls')
-rw-r--r-- | Kernel/Syscalls/execve.cpp | 15 | ||||
-rw-r--r-- | Kernel/Syscalls/purge.cpp | 8 | ||||
-rw-r--r-- | Kernel/Syscalls/read.cpp | 3 | ||||
-rw-r--r-- | Kernel/Syscalls/select.cpp | 12 | ||||
-rw-r--r-- | Kernel/Syscalls/setuid.cpp | 6 | ||||
-rw-r--r-- | Kernel/Syscalls/socket.cpp | 6 | ||||
-rw-r--r-- | Kernel/Syscalls/write.cpp | 3 |
7 files changed, 19 insertions, 34 deletions
diff --git a/Kernel/Syscalls/execve.cpp b/Kernel/Syscalls/execve.cpp index 7889e032cd..99ca217cb9 100644 --- a/Kernel/Syscalls/execve.cpp +++ b/Kernel/Syscalls/execve.cpp @@ -100,15 +100,13 @@ static ErrorOr<FlatPtr> make_userspace_context_for_main_thread([[maybe_unused]] Vector<FlatPtr> argv_entries; for (auto& argument : arguments) { push_string_on_new_stack(argument.view()); - if (!argv_entries.try_append(new_sp)) - return ENOMEM; + TRY(argv_entries.try_append(new_sp)); } Vector<FlatPtr> env_entries; for (auto& variable : environment) { push_string_on_new_stack(variable.view()); - if (!env_entries.try_append(new_sp)) - return ENOMEM; + TRY(env_entries.try_append(new_sp)); } for (auto& value : auxiliary_values) { @@ -810,8 +808,7 @@ ErrorOr<void> Process::exec(NonnullOwnPtr<KString> path, NonnullOwnPtrVector<KSt auto shebang_words = shebang_result.release_value(); auto shebang_path = TRY(shebang_words.first().try_clone()); arguments.ptr_at(0) = move(path); - if (!arguments.try_prepend(move(shebang_words))) - return ENOMEM; + TRY(arguments.try_prepend(move(shebang_words))); return exec(move(shebang_path), move(arguments), move(environment), ++recursion_depth); } @@ -881,13 +878,11 @@ ErrorOr<FlatPtr> Process::sys$execve(Userspace<const Syscall::SC_execve_params*> if (size.has_overflow()) return EOVERFLOW; Vector<Syscall::StringArgument, 32> strings; - if (!strings.try_resize(list.length)) - return ENOMEM; + TRY(strings.try_resize(list.length)); TRY(copy_from_user(strings.data(), list.strings, size.value())); for (size_t i = 0; i < list.length; ++i) { auto string = TRY(try_copy_kstring_from_user(strings[i])); - if (!output.try_append(move(string))) - return ENOMEM; + TRY(output.try_append(move(string))); } return {}; }; diff --git a/Kernel/Syscalls/purge.cpp b/Kernel/Syscalls/purge.cpp index 8a0a05cde0..0c52501fc2 100644 --- a/Kernel/Syscalls/purge.cpp +++ b/Kernel/Syscalls/purge.cpp @@ -27,8 +27,8 @@ ErrorOr<FlatPtr> Process::sys$purge(int mode) if (vmobject.is_anonymous()) { // In the event that the append fails, only attempt to continue // the purge if we have already appended something successfully. - if (!vmobjects.try_append(static_cast<Memory::AnonymousVMObject&>(vmobject)) && vmobjects.is_empty()) { - result = ENOMEM; + if (auto append_result = vmobjects.try_append(static_cast<Memory::AnonymousVMObject&>(vmobject)); append_result.is_error() && vmobjects.is_empty()) { + result = append_result.release_error(); return IterationDecision::Break; } } @@ -50,8 +50,8 @@ ErrorOr<FlatPtr> Process::sys$purge(int mode) if (vmobject.is_inode()) { // In the event that the append fails, only attempt to continue // the purge if we have already appended something successfully. - if (!vmobjects.try_append(static_cast<Memory::InodeVMObject&>(vmobject)) && vmobjects.is_empty()) { - result = ENOMEM; + if (auto append_result = vmobjects.try_append(static_cast<Memory::InodeVMObject&>(vmobject)); append_result.is_error() && vmobjects.is_empty()) { + result = append_result.release_error(); return IterationDecision::Break; } } diff --git a/Kernel/Syscalls/read.cpp b/Kernel/Syscalls/read.cpp index c3e8700aa7..4dc7b0d15a 100644 --- a/Kernel/Syscalls/read.cpp +++ b/Kernel/Syscalls/read.cpp @@ -50,8 +50,7 @@ ErrorOr<FlatPtr> Process::sys$readv(int fd, Userspace<const struct iovec*> iov, u64 total_length = 0; Vector<iovec, 32> vecs; - if (!vecs.try_resize(iov_count)) - return ENOMEM; + TRY(vecs.try_resize(iov_count)); TRY(copy_n_from_user(vecs.data(), iov, iov_count)); for (auto& vec : vecs) { total_length += vec.iov_len; diff --git a/Kernel/Syscalls/select.cpp b/Kernel/Syscalls/select.cpp index 5bfbba84f9..2800fa440b 100644 --- a/Kernel/Syscalls/select.cpp +++ b/Kernel/Syscalls/select.cpp @@ -72,10 +72,8 @@ ErrorOr<FlatPtr> Process::sys$select(Userspace<const Syscall::SC_select_params*> continue; auto description = TRY(fds().open_file_description(fd)); - if (!fds_info.try_append({ move(description), block_flags })) - return ENOMEM; - if (!selected_fds.try_append(fd)) - return ENOMEM; + TRY(fds_info.try_append({ move(description), block_flags })); + TRY(selected_fds.try_append(fd)); } if constexpr (IO_DEBUG || POLL_SELECT_DEBUG) @@ -146,8 +144,7 @@ ErrorOr<FlatPtr> Process::sys$poll(Userspace<const Syscall::SC_poll_params*> use nfds_checked *= params.nfds; if (nfds_checked.has_overflow()) return EFAULT; - if (!fds_copy.try_resize(params.nfds)) - return ENOMEM; + TRY(fds_copy.try_resize(params.nfds)); TRY(copy_from_user(fds_copy.data(), ¶ms.fds[0], nfds_checked.value())); } @@ -162,8 +159,7 @@ ErrorOr<FlatPtr> Process::sys$poll(Userspace<const Syscall::SC_poll_params*> use block_flags |= BlockFlags::Write; if (pfd.events & POLLPRI) block_flags |= BlockFlags::ReadPriority; - if (!fds_info.try_append({ move(description), block_flags })) - return ENOMEM; + TRY(fds_info.try_append({ move(description), block_flags })); } auto current_thread = Thread::current(); diff --git a/Kernel/Syscalls/setuid.cpp b/Kernel/Syscalls/setuid.cpp index 0019465591..3b07c7aeda 100644 --- a/Kernel/Syscalls/setuid.cpp +++ b/Kernel/Syscalls/setuid.cpp @@ -169,8 +169,7 @@ ErrorOr<FlatPtr> Process::sys$setgroups(size_t count, Userspace<const gid_t*> us } Vector<gid_t> new_extra_gids; - if (!new_extra_gids.try_resize(count)) - return ENOMEM; + TRY(new_extra_gids.try_resize(count)); TRY(copy_n_from_user(new_extra_gids.data(), user_gids, count)); HashTable<gid_t> unique_extra_gids; @@ -180,8 +179,7 @@ ErrorOr<FlatPtr> Process::sys$setgroups(size_t count, Userspace<const gid_t*> us } ProtectedDataMutationScope scope { *this }; - if (!m_protected_values.extra_gids.try_resize(unique_extra_gids.size())) - return ENOMEM; + TRY(m_protected_values.extra_gids.try_resize(unique_extra_gids.size())); size_t i = 0; for (auto& extra_gid : unique_extra_gids) { if (extra_gid == gid()) diff --git a/Kernel/Syscalls/socket.cpp b/Kernel/Syscalls/socket.cpp index a710637ecd..74a2a1bf96 100644 --- a/Kernel/Syscalls/socket.cpp +++ b/Kernel/Syscalls/socket.cpp @@ -168,8 +168,7 @@ ErrorOr<FlatPtr> Process::sys$sendmsg(int sockfd, Userspace<const struct msghdr* if (msg.msg_iovlen != 1) return ENOTSUP; // FIXME: Support this :) Vector<iovec, 1> iovs; - if (!iovs.try_resize(msg.msg_iovlen)) - return ENOMEM; + TRY(iovs.try_resize(msg.msg_iovlen)); TRY(copy_n_from_user(iovs.data(), msg.msg_iov, msg.msg_iovlen)); if (iovs[0].iov_len > NumericLimits<ssize_t>::max()) return EINVAL; @@ -201,8 +200,7 @@ ErrorOr<FlatPtr> Process::sys$recvmsg(int sockfd, Userspace<struct msghdr*> user if (msg.msg_iovlen != 1) return ENOTSUP; // FIXME: Support this :) Vector<iovec, 1> iovs; - if (!iovs.try_resize(msg.msg_iovlen)) - return ENOMEM; + TRY(iovs.try_resize(msg.msg_iovlen)); TRY(copy_n_from_user(iovs.data(), msg.msg_iov, msg.msg_iovlen)); Userspace<sockaddr*> user_addr((FlatPtr)msg.msg_name); diff --git a/Kernel/Syscalls/write.cpp b/Kernel/Syscalls/write.cpp index 991d0c6802..09d4c40cfb 100644 --- a/Kernel/Syscalls/write.cpp +++ b/Kernel/Syscalls/write.cpp @@ -24,8 +24,7 @@ ErrorOr<FlatPtr> Process::sys$writev(int fd, Userspace<const struct iovec*> iov, u64 total_length = 0; Vector<iovec, 32> vecs; - if (!vecs.try_resize(iov_count)) - return ENOMEM; + TRY(vecs.try_resize(iov_count)); TRY(copy_n_from_user(vecs.data(), iov, iov_count)); for (auto& vec : vecs) { total_length += vec.iov_len; |