diff options
Diffstat (limited to 'Kernel/Syscalls/socket.cpp')
-rw-r--r-- | Kernel/Syscalls/socket.cpp | 45 |
1 files changed, 10 insertions, 35 deletions
diff --git a/Kernel/Syscalls/socket.cpp b/Kernel/Syscalls/socket.cpp index 179562784d..2794f907b6 100644 --- a/Kernel/Syscalls/socket.cpp +++ b/Kernel/Syscalls/socket.cpp @@ -48,9 +48,7 @@ KResultOr<FlatPtr> Process::sys$socket(int domain, int type, int protocol) KResultOr<FlatPtr> Process::sys$bind(int sockfd, Userspace<const sockaddr*> address, socklen_t address_length) { VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this) - auto description = fds().file_description(sockfd); - if (!description) - return EBADF; + auto description = TRY(fds().file_description(sockfd)); if (!description->is_socket()) return ENOTSOCK; auto& socket = *description->socket(); @@ -63,9 +61,7 @@ KResultOr<FlatPtr> Process::sys$listen(int sockfd, int backlog) VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this) if (backlog < 0) return EINVAL; - auto description = fds().file_description(sockfd); - if (!description) - return EBADF; + auto description = TRY(fds().file_description(sockfd)); if (!description->is_socket()) return ENOTSOCK; auto& socket = *description->socket(); @@ -92,9 +88,7 @@ KResultOr<FlatPtr> Process::sys$accept4(Userspace<const Syscall::SC_accept4_para } auto fd_allocation = TRY(m_fds.allocate()); - auto accepting_socket_description = fds().file_description(accepting_socket_fd); - if (!accepting_socket_description) - return EBADF; + auto accepting_socket_description = TRY(fds().file_description(accepting_socket_fd)); if (!accepting_socket_description->is_socket()) return ENOTSOCK; auto& socket = *accepting_socket_description->socket(); @@ -138,15 +132,11 @@ KResultOr<FlatPtr> Process::sys$accept4(Userspace<const Syscall::SC_accept4_para KResultOr<FlatPtr> Process::sys$connect(int sockfd, Userspace<const sockaddr*> user_address, socklen_t user_address_size) { VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this) - auto description = fds().file_description(sockfd); - if (!description) - return EBADF; + auto description = TRY(fds().file_description(sockfd)); if (!description->is_socket()) return ENOTSOCK; - auto& socket = *description->socket(); REQUIRE_PROMISE_FOR_SOCKET_DOMAIN(socket.domain()); - return socket.connect(*description, user_address, user_address_size, description->is_blocking() ? ShouldBlock::Yes : ShouldBlock::No); } @@ -156,12 +146,9 @@ KResultOr<FlatPtr> Process::sys$shutdown(int sockfd, int how) REQUIRE_PROMISE(stdio); if (how & ~SHUT_RDWR) return EINVAL; - auto description = fds().file_description(sockfd); - if (!description) - return EBADF; + auto description = TRY(fds().file_description(sockfd)); if (!description->is_socket()) return ENOTSOCK; - auto& socket = *description->socket(); REQUIRE_PROMISE_FOR_SOCKET_DOMAIN(socket.domain()); return socket.shutdown(how); @@ -186,9 +173,7 @@ KResultOr<FlatPtr> Process::sys$sendmsg(int sockfd, Userspace<const struct msghd Userspace<const sockaddr*> user_addr((FlatPtr)msg.msg_name); socklen_t addr_length = msg.msg_namelen; - auto description = fds().file_description(sockfd); - if (!description) - return EBADF; + auto description = TRY(fds().file_description(sockfd)); if (!description->is_socket()) return ENOTSOCK; auto& socket = *description->socket(); @@ -222,9 +207,7 @@ KResultOr<FlatPtr> Process::sys$recvmsg(int sockfd, Userspace<struct msghdr*> us Userspace<sockaddr*> user_addr((FlatPtr)msg.msg_name); Userspace<socklen_t*> user_addr_length(msg.msg_name ? (FlatPtr)&user_msg.unsafe_userspace_ptr()->msg_namelen : 0); - auto description = fds().file_description(sockfd); - if (!description) - return EBADF; + auto description = TRY(fds().file_description(sockfd)); if (!description->is_socket()) return ENOTSOCK; auto& socket = *description->socket(); @@ -282,10 +265,7 @@ KResult Process::get_sock_or_peer_name(const Params& params) if (addrlen_value <= 0) return EINVAL; - auto description = fds().file_description(params.sockfd); - if (!description) - return EBADF; - + auto description = TRY(fds().file_description(params.sockfd)); if (!description->is_socket()) return ENOTSOCK; @@ -330,13 +310,10 @@ KResultOr<FlatPtr> Process::sys$getsockopt(Userspace<const Syscall::SC_getsockop socklen_t value_size; TRY(copy_from_user(&value_size, params.value_size, sizeof(socklen_t))); - auto description = fds().file_description(sockfd); - if (!description) - return EBADF; + auto description = TRY(fds().file_description(sockfd)); if (!description->is_socket()) return ENOTSOCK; auto& socket = *description->socket(); - REQUIRE_PROMISE_FOR_SOCKET_DOMAIN(socket.domain()); return socket.getsockopt(*description, level, option, user_value, user_value_size); } @@ -347,9 +324,7 @@ KResultOr<FlatPtr> Process::sys$setsockopt(Userspace<const Syscall::SC_setsockop auto params = TRY(copy_typed_from_user(user_params)); Userspace<const void*> user_value((FlatPtr)params.value); - auto description = fds().file_description(params.sockfd); - if (!description) - return EBADF; + auto description = TRY(fds().file_description(params.sockfd)); if (!description->is_socket()) return ENOTSOCK; auto& socket = *description->socket(); |