mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:27:45 +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
|
@ -24,7 +24,7 @@ KResultOr<FlatPtr> Process::sys$anon_create(size_t size, int options)
|
|||
if (size > NumericLimits<ssize_t>::max())
|
||||
return EINVAL;
|
||||
|
||||
int new_fd = alloc_fd();
|
||||
int new_fd = m_fds.allocate();
|
||||
if (new_fd < 0)
|
||||
return new_fd;
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ KResultOr<FlatPtr> Process::sys$chdir(Userspace<const char*> user_path, size_t p
|
|||
KResultOr<FlatPtr> Process::sys$fchdir(int fd)
|
||||
{
|
||||
REQUIRE_PROMISE(stdio);
|
||||
auto description = file_description(fd);
|
||||
auto description = fds().file_description(fd);
|
||||
if (!description)
|
||||
return EBADF;
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ KResultOr<FlatPtr> Process::sys$chmod(Userspace<const char*> user_path, size_t p
|
|||
KResultOr<FlatPtr> Process::sys$fchmod(int fd, mode_t mode)
|
||||
{
|
||||
REQUIRE_PROMISE(fattr);
|
||||
auto description = file_description(fd);
|
||||
auto description = fds().file_description(fd);
|
||||
if (!description)
|
||||
return EBADF;
|
||||
return description->chmod(mode);
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace Kernel {
|
|||
KResultOr<FlatPtr> Process::sys$fchown(int fd, uid_t uid, gid_t gid)
|
||||
{
|
||||
REQUIRE_PROMISE(chown);
|
||||
auto description = file_description(fd);
|
||||
auto description = fds().file_description(fd);
|
||||
if (!description)
|
||||
return EBADF;
|
||||
return description->chown(uid, gid);
|
||||
|
|
|
@ -12,12 +12,12 @@ namespace Kernel {
|
|||
KResultOr<FlatPtr> Process::sys$dup2(int old_fd, int new_fd)
|
||||
{
|
||||
REQUIRE_PROMISE(stdio);
|
||||
auto description = file_description(old_fd);
|
||||
auto description = fds().file_description(old_fd);
|
||||
if (!description)
|
||||
return EBADF;
|
||||
if (old_fd == new_fd)
|
||||
return new_fd;
|
||||
if (new_fd < 0 || new_fd >= m_max_open_file_descriptors)
|
||||
if (new_fd < 0 || static_cast<size_t>(new_fd) >= fds().max_open())
|
||||
return EINVAL;
|
||||
m_fds[new_fd].set(*description);
|
||||
return new_fd;
|
||||
|
|
|
@ -573,15 +573,14 @@ KResult Process::do_exec(NonnullRefPtr<FileDescription> main_program_description
|
|||
|
||||
clear_futex_queues_on_exec();
|
||||
|
||||
for (size_t i = 0; i < m_fds.size(); ++i) {
|
||||
auto& description_and_flags = m_fds[i];
|
||||
if (description_and_flags.description() && description_and_flags.flags() & FD_CLOEXEC)
|
||||
description_and_flags = {};
|
||||
}
|
||||
fds().change_each([&](auto& file_description_metadata) {
|
||||
if (file_description_metadata.is_valid() && file_description_metadata.flags() & FD_CLOEXEC)
|
||||
file_description_metadata = {};
|
||||
});
|
||||
|
||||
int main_program_fd = -1;
|
||||
if (interpreter_description) {
|
||||
main_program_fd = alloc_fd();
|
||||
main_program_fd = m_fds.allocate();
|
||||
VERIFY(main_program_fd >= 0);
|
||||
auto seek_result = main_program_description->seek(0, SEEK_SET);
|
||||
VERIFY(!seek_result.is_error());
|
||||
|
|
|
@ -14,7 +14,7 @@ KResultOr<FlatPtr> Process::sys$fcntl(int fd, int cmd, u32 arg)
|
|||
{
|
||||
REQUIRE_PROMISE(stdio);
|
||||
dbgln_if(IO_DEBUG, "sys$fcntl: fd={}, cmd={}, arg={}", fd, cmd, arg);
|
||||
auto description = file_description(fd);
|
||||
auto description = fds().file_description(fd);
|
||||
if (!description)
|
||||
return EBADF;
|
||||
// NOTE: The FD flags are not shared between FileDescription objects.
|
||||
|
@ -24,7 +24,7 @@ KResultOr<FlatPtr> Process::sys$fcntl(int fd, int cmd, u32 arg)
|
|||
int arg_fd = (int)arg;
|
||||
if (arg_fd < 0)
|
||||
return EINVAL;
|
||||
int new_fd = alloc_fd(arg_fd);
|
||||
int new_fd = fds().allocate(arg_fd);
|
||||
if (new_fd < 0)
|
||||
return new_fd;
|
||||
m_fds[new_fd].set(*description);
|
||||
|
|
|
@ -17,7 +17,7 @@ KResultOr<FlatPtr> Process::sys$ftruncate(int fd, Userspace<off_t*> userspace_le
|
|||
return EFAULT;
|
||||
if (length < 0)
|
||||
return EINVAL;
|
||||
auto description = file_description(fd);
|
||||
auto description = fds().file_description(fd);
|
||||
if (!description)
|
||||
return EBADF;
|
||||
if (!description->is_writable())
|
||||
|
|
|
@ -14,7 +14,7 @@ KResultOr<FlatPtr> Process::sys$get_dir_entries(int fd, Userspace<void*> user_bu
|
|||
REQUIRE_PROMISE(stdio);
|
||||
if (user_size > NumericLimits<ssize_t>::max())
|
||||
return EINVAL;
|
||||
auto description = file_description(fd);
|
||||
auto description = fds().file_description(fd);
|
||||
if (!description)
|
||||
return EBADF;
|
||||
auto buffer = UserOrKernelBuffer::for_user_buffer(user_buffer, static_cast<size_t>(user_size));
|
||||
|
|
|
@ -17,7 +17,7 @@ KResultOr<FlatPtr> Process::sys$create_inode_watcher(u32 flags)
|
|||
{
|
||||
REQUIRE_PROMISE(rpath);
|
||||
|
||||
int fd = alloc_fd();
|
||||
int fd = m_fds.allocate();
|
||||
if (fd < 0)
|
||||
return fd;
|
||||
|
||||
|
@ -48,7 +48,7 @@ KResultOr<FlatPtr> Process::sys$inode_watcher_add_watch(Userspace<const Syscall:
|
|||
if (!copy_from_user(¶ms, user_params))
|
||||
return EFAULT;
|
||||
|
||||
auto description = file_description(params.fd);
|
||||
auto description = fds().file_description(params.fd);
|
||||
if (!description)
|
||||
return EBADF;
|
||||
if (!description->is_inode_watcher())
|
||||
|
@ -75,7 +75,7 @@ KResultOr<FlatPtr> Process::sys$inode_watcher_add_watch(Userspace<const Syscall:
|
|||
|
||||
KResultOr<FlatPtr> Process::sys$inode_watcher_remove_watch(int fd, int wd)
|
||||
{
|
||||
auto description = file_description(fd);
|
||||
auto description = fds().file_description(fd);
|
||||
if (!description)
|
||||
return EBADF;
|
||||
if (!description->is_inode_watcher())
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace Kernel {
|
|||
|
||||
KResultOr<FlatPtr> Process::sys$ioctl(int fd, unsigned request, FlatPtr arg)
|
||||
{
|
||||
auto description = file_description(fd);
|
||||
auto description = fds().file_description(fd);
|
||||
if (!description)
|
||||
return EBADF;
|
||||
if (request == FIONBIO) {
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace Kernel {
|
|||
KResultOr<FlatPtr> Process::sys$lseek(int fd, Userspace<off_t*> userspace_offset, int whence)
|
||||
{
|
||||
REQUIRE_PROMISE(stdio);
|
||||
auto description = file_description(fd);
|
||||
auto description = fds().file_description(fd);
|
||||
if (!description)
|
||||
return EBADF;
|
||||
off_t offset;
|
||||
|
|
|
@ -224,7 +224,7 @@ KResultOr<FlatPtr> Process::sys$mmap(Userspace<const Syscall::SC_mmap_params*> u
|
|||
return EINVAL;
|
||||
if (static_cast<size_t>(offset) & ~PAGE_MASK)
|
||||
return EINVAL;
|
||||
auto description = file_description(fd);
|
||||
auto description = fds().file_description(fd);
|
||||
if (!description)
|
||||
return EBADF;
|
||||
if (description->is_directory())
|
||||
|
|
|
@ -36,7 +36,7 @@ KResultOr<FlatPtr> Process::sys$mount(Userspace<const Syscall::SC_mount_params*>
|
|||
if (fs_type.is_null())
|
||||
return EFAULT;
|
||||
|
||||
auto description = file_description(source_fd);
|
||||
auto description = fds().file_description(source_fd);
|
||||
if (!description.is_null())
|
||||
dbgln("mount {}: source fd {} @ {}", fs_type, source_fd, target);
|
||||
else
|
||||
|
|
|
@ -44,7 +44,7 @@ KResultOr<FlatPtr> Process::sys$open(Userspace<const Syscall::SC_open_params*> u
|
|||
return path.error();
|
||||
|
||||
dbgln_if(IO_DEBUG, "sys$open(dirfd={}, path='{}', options={}, mode={})", dirfd, path.value()->view(), options, mode);
|
||||
int fd = alloc_fd();
|
||||
int fd = m_fds.allocate();
|
||||
if (fd < 0)
|
||||
return fd;
|
||||
|
||||
|
@ -52,7 +52,7 @@ KResultOr<FlatPtr> Process::sys$open(Userspace<const Syscall::SC_open_params*> u
|
|||
if (dirfd == AT_FDCWD) {
|
||||
base = current_directory();
|
||||
} else {
|
||||
auto base_description = file_description(dirfd);
|
||||
auto base_description = fds().file_description(dirfd);
|
||||
if (!base_description)
|
||||
return EBADF;
|
||||
if (!base_description->is_directory())
|
||||
|
@ -78,7 +78,7 @@ KResultOr<FlatPtr> Process::sys$open(Userspace<const Syscall::SC_open_params*> u
|
|||
KResultOr<FlatPtr> Process::sys$close(int fd)
|
||||
{
|
||||
REQUIRE_PROMISE(stdio);
|
||||
auto description = file_description(fd);
|
||||
auto description = fds().file_description(fd);
|
||||
dbgln_if(IO_DEBUG, "sys$close({}) {}", fd, description.ptr());
|
||||
if (!description)
|
||||
return EBADF;
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace Kernel {
|
|||
KResultOr<FlatPtr> Process::sys$pipe(int pipefd[2], int flags)
|
||||
{
|
||||
REQUIRE_PROMISE(stdio);
|
||||
if (number_of_open_file_descriptors() + 2 > max_open_file_descriptors())
|
||||
if (fds().open_count() + 2 > fds().max_open())
|
||||
return EMFILE;
|
||||
// Reject flags other than O_CLOEXEC.
|
||||
if ((flags & O_CLOEXEC) != flags)
|
||||
|
@ -29,13 +29,13 @@ KResultOr<FlatPtr> Process::sys$pipe(int pipefd[2], int flags)
|
|||
if (open_writer_result.is_error())
|
||||
return open_writer_result.error();
|
||||
|
||||
int reader_fd = alloc_fd();
|
||||
int reader_fd = m_fds.allocate();
|
||||
m_fds[reader_fd].set(open_reader_result.release_value(), fd_flags);
|
||||
m_fds[reader_fd].description()->set_readable(true);
|
||||
if (!copy_to_user(&pipefd[0], &reader_fd))
|
||||
return EFAULT;
|
||||
|
||||
int writer_fd = alloc_fd();
|
||||
int writer_fd = m_fds.allocate();
|
||||
m_fds[writer_fd].set(open_writer_result.release_value(), fd_flags);
|
||||
m_fds[writer_fd].description()->set_writable(true);
|
||||
if (!copy_to_user(&pipefd[1], &writer_fd))
|
||||
|
|
|
@ -34,7 +34,7 @@ KResultOr<FlatPtr> Process::sys$readv(int fd, Userspace<const struct iovec*> iov
|
|||
return EINVAL;
|
||||
}
|
||||
|
||||
auto description = file_description(fd);
|
||||
auto description = fds().file_description(fd);
|
||||
if (!description)
|
||||
return EBADF;
|
||||
|
||||
|
@ -76,7 +76,7 @@ KResultOr<FlatPtr> Process::sys$read(int fd, Userspace<u8*> buffer, size_t size)
|
|||
if (size > NumericLimits<ssize_t>::max())
|
||||
return EINVAL;
|
||||
dbgln_if(IO_DEBUG, "sys$read({}, {}, {})", fd, buffer.ptr(), size);
|
||||
auto description = file_description(fd);
|
||||
auto description = fds().file_description(fd);
|
||||
if (!description)
|
||||
return EBADF;
|
||||
if (!description->is_readable())
|
||||
|
|
|
@ -61,7 +61,7 @@ KResultOr<FlatPtr> Process::sys$select(Userspace<const Syscall::SC_select_params
|
|||
return EFAULT;
|
||||
|
||||
Thread::SelectBlocker::FDVector fds_info;
|
||||
Vector<int, FD_SETSIZE> fds;
|
||||
Vector<int, FD_SETSIZE> selected_fds;
|
||||
for (int fd = 0; fd < params.nfds; fd++) {
|
||||
auto block_flags = BlockFlags::None;
|
||||
if (params.readfds && FD_ISSET(fd, &fds_read))
|
||||
|
@ -73,14 +73,14 @@ KResultOr<FlatPtr> Process::sys$select(Userspace<const Syscall::SC_select_params
|
|||
if (block_flags == BlockFlags::None)
|
||||
continue;
|
||||
|
||||
auto description = file_description(fd);
|
||||
auto description = fds().file_description(fd);
|
||||
if (!description) {
|
||||
dbgln("sys$select: Bad fd number {}", fd);
|
||||
return EBADF;
|
||||
}
|
||||
if (!fds_info.try_append({ description.release_nonnull(), block_flags }))
|
||||
return ENOMEM;
|
||||
if (!fds.try_append(fd))
|
||||
if (!selected_fds.try_append(fd))
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
|
@ -105,15 +105,15 @@ KResultOr<FlatPtr> Process::sys$select(Userspace<const Syscall::SC_select_params
|
|||
if (fd_entry.unblocked_flags == BlockFlags::None)
|
||||
continue;
|
||||
if (params.readfds && has_flag(fd_entry.unblocked_flags, BlockFlags::Read)) {
|
||||
FD_SET(fds[i], &fds_read);
|
||||
FD_SET(selected_fds[i], &fds_read);
|
||||
marked_fd_count++;
|
||||
}
|
||||
if (params.writefds && has_flag(fd_entry.unblocked_flags, BlockFlags::Write)) {
|
||||
FD_SET(fds[i], &fds_write);
|
||||
FD_SET(selected_fds[i], &fds_write);
|
||||
marked_fd_count++;
|
||||
}
|
||||
if (params.exceptfds && has_flag(fd_entry.unblocked_flags, BlockFlags::Exception)) {
|
||||
FD_SET(fds[i], &fds_except);
|
||||
FD_SET(selected_fds[i], &fds_except);
|
||||
marked_fd_count++;
|
||||
}
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ KResultOr<FlatPtr> Process::sys$poll(Userspace<const Syscall::SC_poll_params*> u
|
|||
if (!copy_from_user(¶ms, user_params))
|
||||
return EFAULT;
|
||||
|
||||
if (params.nfds >= m_max_open_file_descriptors)
|
||||
if (params.nfds >= fds().max_open())
|
||||
return ENOBUFS;
|
||||
|
||||
Thread::BlockTimeout timeout;
|
||||
|
@ -165,7 +165,7 @@ KResultOr<FlatPtr> Process::sys$poll(Userspace<const Syscall::SC_poll_params*> u
|
|||
Thread::SelectBlocker::FDVector fds_info;
|
||||
for (size_t i = 0; i < params.nfds; i++) {
|
||||
auto& pfd = fds_copy[i];
|
||||
auto description = file_description(pfd.fd);
|
||||
auto description = fds().file_description(pfd.fd);
|
||||
if (!description) {
|
||||
dbgln("sys$poll: Bad fd number {}", pfd.fd);
|
||||
return EBADF;
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace Kernel {
|
|||
KResultOr<FlatPtr> Process::sys$sendfd(int sockfd, int fd)
|
||||
{
|
||||
REQUIRE_PROMISE(sendfd);
|
||||
auto socket_description = file_description(sockfd);
|
||||
auto socket_description = fds().file_description(sockfd);
|
||||
if (!socket_description)
|
||||
return EBADF;
|
||||
if (!socket_description->is_socket())
|
||||
|
@ -24,7 +24,7 @@ KResultOr<FlatPtr> Process::sys$sendfd(int sockfd, int fd)
|
|||
if (!socket.is_connected())
|
||||
return ENOTCONN;
|
||||
|
||||
auto passing_descriptor = file_description(fd);
|
||||
auto passing_descriptor = fds().file_description(fd);
|
||||
if (!passing_descriptor)
|
||||
return EBADF;
|
||||
|
||||
|
@ -35,7 +35,7 @@ KResultOr<FlatPtr> Process::sys$sendfd(int sockfd, int fd)
|
|||
KResultOr<FlatPtr> Process::sys$recvfd(int sockfd, int options)
|
||||
{
|
||||
REQUIRE_PROMISE(recvfd);
|
||||
auto socket_description = file_description(sockfd);
|
||||
auto socket_description = fds().file_description(sockfd);
|
||||
if (!socket_description)
|
||||
return EBADF;
|
||||
if (!socket_description->is_socket())
|
||||
|
@ -44,7 +44,7 @@ KResultOr<FlatPtr> Process::sys$recvfd(int sockfd, int options)
|
|||
if (!socket.is_local())
|
||||
return EAFNOSUPPORT;
|
||||
|
||||
int new_fd = alloc_fd();
|
||||
int new_fd = m_fds.allocate();
|
||||
if (new_fd < 0)
|
||||
return new_fd;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace Kernel {
|
|||
KResultOr<FlatPtr> Process::sys$fstat(int fd, Userspace<stat*> user_statbuf)
|
||||
{
|
||||
REQUIRE_PROMISE(stdio);
|
||||
auto description = file_description(fd);
|
||||
auto description = fds().file_description(fd);
|
||||
if (!description)
|
||||
return EBADF;
|
||||
stat buffer = {};
|
||||
|
@ -38,7 +38,7 @@ KResultOr<FlatPtr> Process::sys$stat(Userspace<const Syscall::SC_stat_params*> u
|
|||
if (params.dirfd == AT_FDCWD) {
|
||||
base = current_directory();
|
||||
} else {
|
||||
auto base_description = file_description(params.dirfd);
|
||||
auto base_description = fds().file_description(params.dirfd);
|
||||
if (!base_description)
|
||||
return EBADF;
|
||||
if (!base_description->is_directory())
|
||||
|
|
|
@ -87,7 +87,7 @@ KResultOr<FlatPtr> Process::sys$fstatvfs(int fd, statvfs* buf)
|
|||
{
|
||||
REQUIRE_PROMISE(stdio);
|
||||
|
||||
auto description = file_description(fd);
|
||||
auto description = fds().file_description(fd);
|
||||
if (!description)
|
||||
return EBADF;
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ KResultOr<FlatPtr> Process::sys$sysconf(int name)
|
|||
case _SC_NPROCESSORS_ONLN:
|
||||
return Processor::processor_count();
|
||||
case _SC_OPEN_MAX:
|
||||
return max_open_file_descriptors();
|
||||
return fds().max_open();
|
||||
case _SC_PAGESIZE:
|
||||
return PAGE_SIZE;
|
||||
case _SC_TTY_NAME_MAX:
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace Kernel {
|
|||
KResultOr<FlatPtr> Process::sys$ttyname(int fd, Userspace<char*> buffer, size_t size)
|
||||
{
|
||||
REQUIRE_PROMISE(tty);
|
||||
auto description = file_description(fd);
|
||||
auto description = fds().file_description(fd);
|
||||
if (!description)
|
||||
return EBADF;
|
||||
if (!description->is_tty())
|
||||
|
@ -30,7 +30,7 @@ KResultOr<FlatPtr> Process::sys$ttyname(int fd, Userspace<char*> buffer, size_t
|
|||
KResultOr<FlatPtr> Process::sys$ptsname(int fd, Userspace<char*> buffer, size_t size)
|
||||
{
|
||||
REQUIRE_PROMISE(tty);
|
||||
auto description = file_description(fd);
|
||||
auto description = fds().file_description(fd);
|
||||
if (!description)
|
||||
return EBADF;
|
||||
auto* master_pty = description->master_pty();
|
||||
|
|
|
@ -33,7 +33,7 @@ KResultOr<FlatPtr> Process::sys$writev(int fd, Userspace<const struct iovec*> io
|
|||
return EINVAL;
|
||||
}
|
||||
|
||||
auto description = file_description(fd);
|
||||
auto description = fds().file_description(fd);
|
||||
if (!description)
|
||||
return EBADF;
|
||||
|
||||
|
@ -105,7 +105,7 @@ KResultOr<FlatPtr> Process::sys$write(int fd, Userspace<const u8*> data, size_t
|
|||
return EINVAL;
|
||||
|
||||
dbgln_if(IO_DEBUG, "sys$write({}, {}, {})", fd, data.ptr(), size);
|
||||
auto description = file_description(fd);
|
||||
auto description = fds().file_description(fd);
|
||||
if (!description)
|
||||
return EBADF;
|
||||
if (!description->is_writable())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue