|
@@ -38,7 +38,7 @@ KResultOr<FlatPtr> Process::sys$socket(int domain, int type, int protocol)
|
|
|
|
|
|
if ((type & SOCK_TYPE_MASK) == SOCK_RAW && !is_superuser())
|
|
if ((type & SOCK_TYPE_MASK) == SOCK_RAW && !is_superuser())
|
|
return EACCES;
|
|
return EACCES;
|
|
- int fd = alloc_fd();
|
|
|
|
|
|
+ int fd = m_fds.allocate();
|
|
if (fd < 0)
|
|
if (fd < 0)
|
|
return fd;
|
|
return fd;
|
|
auto result = Socket::create(domain, type, protocol);
|
|
auto result = Socket::create(domain, type, protocol);
|
|
@@ -53,7 +53,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)
|
|
KResultOr<FlatPtr> Process::sys$bind(int sockfd, Userspace<const sockaddr*> address, socklen_t address_length)
|
|
{
|
|
{
|
|
- auto description = file_description(sockfd);
|
|
|
|
|
|
+ auto description = fds().file_description(sockfd);
|
|
if (!description)
|
|
if (!description)
|
|
return EBADF;
|
|
return EBADF;
|
|
if (!description->is_socket())
|
|
if (!description->is_socket())
|
|
@@ -67,7 +67,7 @@ KResultOr<FlatPtr> Process::sys$listen(int sockfd, int backlog)
|
|
{
|
|
{
|
|
if (backlog < 0)
|
|
if (backlog < 0)
|
|
return EINVAL;
|
|
return EINVAL;
|
|
- auto description = file_description(sockfd);
|
|
|
|
|
|
+ auto description = fds().file_description(sockfd);
|
|
if (!description)
|
|
if (!description)
|
|
return EBADF;
|
|
return EBADF;
|
|
if (!description->is_socket())
|
|
if (!description->is_socket())
|
|
@@ -96,10 +96,10 @@ KResultOr<FlatPtr> Process::sys$accept4(Userspace<const Syscall::SC_accept4_para
|
|
if (user_address && !copy_from_user(&address_size, static_ptr_cast<const socklen_t*>(user_address_size)))
|
|
if (user_address && !copy_from_user(&address_size, static_ptr_cast<const socklen_t*>(user_address_size)))
|
|
return EFAULT;
|
|
return EFAULT;
|
|
|
|
|
|
- int accepted_socket_fd = alloc_fd();
|
|
|
|
|
|
+ int accepted_socket_fd = m_fds.allocate();
|
|
if (accepted_socket_fd < 0)
|
|
if (accepted_socket_fd < 0)
|
|
return accepted_socket_fd;
|
|
return accepted_socket_fd;
|
|
- auto accepting_socket_description = file_description(accepting_socket_fd);
|
|
|
|
|
|
+ auto accepting_socket_description = fds().file_description(accepting_socket_fd);
|
|
if (!accepting_socket_description)
|
|
if (!accepting_socket_description)
|
|
return EBADF;
|
|
return EBADF;
|
|
if (!accepting_socket_description->is_socket())
|
|
if (!accepting_socket_description->is_socket())
|
|
@@ -148,10 +148,10 @@ 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)
|
|
KResultOr<FlatPtr> Process::sys$connect(int sockfd, Userspace<const sockaddr*> user_address, socklen_t user_address_size)
|
|
{
|
|
{
|
|
- int fd = alloc_fd();
|
|
|
|
|
|
+ int fd = m_fds.allocate();
|
|
if (fd < 0)
|
|
if (fd < 0)
|
|
return fd;
|
|
return fd;
|
|
- auto description = file_description(sockfd);
|
|
|
|
|
|
+ auto description = fds().file_description(sockfd);
|
|
if (!description)
|
|
if (!description)
|
|
return EBADF;
|
|
return EBADF;
|
|
if (!description->is_socket())
|
|
if (!description->is_socket())
|
|
@@ -168,7 +168,7 @@ KResultOr<FlatPtr> Process::sys$shutdown(int sockfd, int how)
|
|
REQUIRE_PROMISE(stdio);
|
|
REQUIRE_PROMISE(stdio);
|
|
if (how & ~SHUT_RDWR)
|
|
if (how & ~SHUT_RDWR)
|
|
return EINVAL;
|
|
return EINVAL;
|
|
- auto description = file_description(sockfd);
|
|
|
|
|
|
+ auto description = fds().file_description(sockfd);
|
|
if (!description)
|
|
if (!description)
|
|
return EBADF;
|
|
return EBADF;
|
|
if (!description->is_socket())
|
|
if (!description->is_socket())
|
|
@@ -199,7 +199,7 @@ KResultOr<FlatPtr> Process::sys$sendmsg(int sockfd, Userspace<const struct msghd
|
|
Userspace<const sockaddr*> user_addr((FlatPtr)msg.msg_name);
|
|
Userspace<const sockaddr*> user_addr((FlatPtr)msg.msg_name);
|
|
socklen_t addr_length = msg.msg_namelen;
|
|
socklen_t addr_length = msg.msg_namelen;
|
|
|
|
|
|
- auto description = file_description(sockfd);
|
|
|
|
|
|
+ auto description = fds().file_description(sockfd);
|
|
if (!description)
|
|
if (!description)
|
|
return EBADF;
|
|
return EBADF;
|
|
if (!description->is_socket())
|
|
if (!description->is_socket())
|
|
@@ -236,7 +236,7 @@ KResultOr<FlatPtr> Process::sys$recvmsg(int sockfd, Userspace<struct msghdr*> us
|
|
Userspace<sockaddr*> user_addr((FlatPtr)msg.msg_name);
|
|
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);
|
|
Userspace<socklen_t*> user_addr_length(msg.msg_name ? (FlatPtr)&user_msg.unsafe_userspace_ptr()->msg_namelen : 0);
|
|
|
|
|
|
- auto description = file_description(sockfd);
|
|
|
|
|
|
+ auto description = fds().file_description(sockfd);
|
|
if (!description)
|
|
if (!description)
|
|
return EBADF;
|
|
return EBADF;
|
|
if (!description->is_socket())
|
|
if (!description->is_socket())
|
|
@@ -301,7 +301,7 @@ int Process::get_sock_or_peer_name(const Params& params)
|
|
if (addrlen_value <= 0)
|
|
if (addrlen_value <= 0)
|
|
return EINVAL;
|
|
return EINVAL;
|
|
|
|
|
|
- auto description = file_description(params.sockfd);
|
|
|
|
|
|
+ auto description = fds().file_description(params.sockfd);
|
|
if (!description)
|
|
if (!description)
|
|
return EBADF;
|
|
return EBADF;
|
|
|
|
|
|
@@ -356,7 +356,7 @@ KResultOr<FlatPtr> Process::sys$getsockopt(Userspace<const Syscall::SC_getsockop
|
|
if (!copy_from_user(&value_size, params.value_size, sizeof(socklen_t)))
|
|
if (!copy_from_user(&value_size, params.value_size, sizeof(socklen_t)))
|
|
return EFAULT;
|
|
return EFAULT;
|
|
|
|
|
|
- auto description = file_description(sockfd);
|
|
|
|
|
|
+ auto description = fds().file_description(sockfd);
|
|
if (!description)
|
|
if (!description)
|
|
return EBADF;
|
|
return EBADF;
|
|
if (!description->is_socket())
|
|
if (!description->is_socket())
|
|
@@ -373,7 +373,7 @@ KResultOr<FlatPtr> Process::sys$setsockopt(Userspace<const Syscall::SC_setsockop
|
|
if (!copy_from_user(¶ms, user_params))
|
|
if (!copy_from_user(¶ms, user_params))
|
|
return EFAULT;
|
|
return EFAULT;
|
|
Userspace<const void*> user_value((FlatPtr)params.value);
|
|
Userspace<const void*> user_value((FlatPtr)params.value);
|
|
- auto description = file_description(params.sockfd);
|
|
|
|
|
|
+ auto description = fds().file_description(params.sockfd);
|
|
if (!description)
|
|
if (!description)
|
|
return EBADF;
|
|
return EBADF;
|
|
if (!description->is_socket())
|
|
if (!description->is_socket())
|
|
@@ -401,12 +401,12 @@ KResultOr<FlatPtr> Process::sys$socketpair(Userspace<const Syscall::SC_socketpai
|
|
auto pair = result.value();
|
|
auto pair = result.value();
|
|
|
|
|
|
int fds[2];
|
|
int fds[2];
|
|
- fds[0] = alloc_fd();
|
|
|
|
|
|
+ fds[0] = m_fds.allocate();
|
|
if (fds[0] < 0)
|
|
if (fds[0] < 0)
|
|
return ENFILE;
|
|
return ENFILE;
|
|
setup_socket_fd(fds[0], pair.description1, params.type);
|
|
setup_socket_fd(fds[0], pair.description1, params.type);
|
|
|
|
|
|
- fds[1] = alloc_fd();
|
|
|
|
|
|
+ fds[1] = m_fds.allocate();
|
|
if (fds[1] < 0) {
|
|
if (fds[1] < 0) {
|
|
// FIXME: This leaks fds[0]
|
|
// FIXME: This leaks fds[0]
|
|
return ENFILE;
|
|
return ENFILE;
|