mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 04:28:13 +00:00
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.
This commit is contained in:
parent
12b6e69150
commit
7c87891c06
28 changed files with 198 additions and 128 deletions
|
@ -38,7 +38,7 @@ KResultOr<FlatPtr> Process::sys$socket(int domain, int type, int protocol)
|
|||
|
||||
if ((type & SOCK_TYPE_MASK) == SOCK_RAW && !is_superuser())
|
||||
return EACCES;
|
||||
int fd = alloc_fd();
|
||||
int fd = m_fds.allocate();
|
||||
if (fd < 0)
|
||||
return fd;
|
||||
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)
|
||||
{
|
||||
auto description = file_description(sockfd);
|
||||
auto description = fds().file_description(sockfd);
|
||||
if (!description)
|
||||
return EBADF;
|
||||
if (!description->is_socket())
|
||||
|
@ -67,7 +67,7 @@ KResultOr<FlatPtr> Process::sys$listen(int sockfd, int backlog)
|
|||
{
|
||||
if (backlog < 0)
|
||||
return EINVAL;
|
||||
auto description = file_description(sockfd);
|
||||
auto description = fds().file_description(sockfd);
|
||||
if (!description)
|
||||
return EBADF;
|
||||
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)))
|
||||
return EFAULT;
|
||||
|
||||
int accepted_socket_fd = alloc_fd();
|
||||
int accepted_socket_fd = m_fds.allocate();
|
||||
if (accepted_socket_fd < 0)
|
||||
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)
|
||||
return EBADF;
|
||||
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)
|
||||
{
|
||||
int fd = alloc_fd();
|
||||
int fd = m_fds.allocate();
|
||||
if (fd < 0)
|
||||
return fd;
|
||||
auto description = file_description(sockfd);
|
||||
auto description = fds().file_description(sockfd);
|
||||
if (!description)
|
||||
return EBADF;
|
||||
if (!description->is_socket())
|
||||
|
@ -168,7 +168,7 @@ KResultOr<FlatPtr> Process::sys$shutdown(int sockfd, int how)
|
|||
REQUIRE_PROMISE(stdio);
|
||||
if (how & ~SHUT_RDWR)
|
||||
return EINVAL;
|
||||
auto description = file_description(sockfd);
|
||||
auto description = fds().file_description(sockfd);
|
||||
if (!description)
|
||||
return EBADF;
|
||||
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);
|
||||
socklen_t addr_length = msg.msg_namelen;
|
||||
|
||||
auto description = file_description(sockfd);
|
||||
auto description = fds().file_description(sockfd);
|
||||
if (!description)
|
||||
return EBADF;
|
||||
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<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)
|
||||
return EBADF;
|
||||
if (!description->is_socket())
|
||||
|
@ -301,7 +301,7 @@ int Process::get_sock_or_peer_name(const Params& params)
|
|||
if (addrlen_value <= 0)
|
||||
return EINVAL;
|
||||
|
||||
auto description = file_description(params.sockfd);
|
||||
auto description = fds().file_description(params.sockfd);
|
||||
if (!description)
|
||||
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)))
|
||||
return EFAULT;
|
||||
|
||||
auto description = file_description(sockfd);
|
||||
auto description = fds().file_description(sockfd);
|
||||
if (!description)
|
||||
return EBADF;
|
||||
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))
|
||||
return EFAULT;
|
||||
Userspace<const void*> user_value((FlatPtr)params.value);
|
||||
auto description = file_description(params.sockfd);
|
||||
auto description = fds().file_description(params.sockfd);
|
||||
if (!description)
|
||||
return EBADF;
|
||||
if (!description->is_socket())
|
||||
|
@ -401,12 +401,12 @@ KResultOr<FlatPtr> Process::sys$socketpair(Userspace<const Syscall::SC_socketpai
|
|||
auto pair = result.value();
|
||||
|
||||
int fds[2];
|
||||
fds[0] = alloc_fd();
|
||||
fds[0] = m_fds.allocate();
|
||||
if (fds[0] < 0)
|
||||
return ENFILE;
|
||||
setup_socket_fd(fds[0], pair.description1, params.type);
|
||||
|
||||
fds[1] = alloc_fd();
|
||||
fds[1] = m_fds.allocate();
|
||||
if (fds[1] < 0) {
|
||||
// FIXME: This leaks fds[0]
|
||||
return ENFILE;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue