mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 22:17:42 +00:00
Kernel: Turn Process::FileDescriptionAndFlags into a proper class
This commit is contained in:
parent
f2a152e930
commit
2e2de125e5
8 changed files with 34 additions and 24 deletions
|
@ -488,7 +488,7 @@ RefPtr<FileDescription> Process::file_description(int fd) const
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
if (static_cast<size_t>(fd) < m_fds.size())
|
if (static_cast<size_t>(fd) < m_fds.size())
|
||||||
return m_fds[fd].description.ptr();
|
return m_fds[fd].description();
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -497,7 +497,7 @@ int Process::fd_flags(int fd) const
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return -1;
|
return -1;
|
||||||
if (static_cast<size_t>(fd) < m_fds.size())
|
if (static_cast<size_t>(fd) < m_fds.size())
|
||||||
return m_fds[fd].flags;
|
return m_fds[fd].flags();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -800,14 +800,14 @@ Thread* Process::create_kernel_thread(void (*entry)(), u32 priority, const Strin
|
||||||
|
|
||||||
void Process::FileDescriptionAndFlags::clear()
|
void Process::FileDescriptionAndFlags::clear()
|
||||||
{
|
{
|
||||||
description = nullptr;
|
m_description = nullptr;
|
||||||
flags = 0;
|
m_flags = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Process::FileDescriptionAndFlags::set(NonnullRefPtr<FileDescription>&& d, u32 f)
|
void Process::FileDescriptionAndFlags::set(NonnullRefPtr<FileDescription>&& description, u32 flags)
|
||||||
{
|
{
|
||||||
description = move(d);
|
m_description = move(description);
|
||||||
flags = f;
|
m_flags = flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
KBuffer Process::backtrace(ProcessInspectionHandle& handle) const
|
KBuffer Process::backtrace(ProcessInspectionHandle& handle) const
|
||||||
|
|
|
@ -573,12 +573,22 @@ private:
|
||||||
|
|
||||||
static const int m_max_open_file_descriptors { FD_SETSIZE };
|
static const int m_max_open_file_descriptors { FD_SETSIZE };
|
||||||
|
|
||||||
struct FileDescriptionAndFlags {
|
class FileDescriptionAndFlags {
|
||||||
operator bool() const { return !!description; }
|
public:
|
||||||
|
operator bool() const { return !!m_description; }
|
||||||
|
|
||||||
|
FileDescription* description() { return m_description; }
|
||||||
|
const FileDescription* description() const { return m_description; }
|
||||||
|
|
||||||
|
u32 flags() const { return m_flags; }
|
||||||
|
void set_flags(u32 flags) { m_flags = flags; }
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
void set(NonnullRefPtr<FileDescription>&& d, u32 f = 0);
|
void set(NonnullRefPtr<FileDescription>&&, u32 flags = 0);
|
||||||
RefPtr<FileDescription> description;
|
|
||||||
u32 flags { 0 };
|
private:
|
||||||
|
RefPtr<FileDescription> m_description;
|
||||||
|
u32 m_flags { 0 };
|
||||||
};
|
};
|
||||||
Vector<FileDescriptionAndFlags> m_fds;
|
Vector<FileDescriptionAndFlags> m_fds;
|
||||||
|
|
||||||
|
|
|
@ -221,13 +221,13 @@ bool Thread::SelectBlocker::should_unblock(Thread& thread, time_t now_sec, long
|
||||||
for (int fd : m_select_read_fds) {
|
for (int fd : m_select_read_fds) {
|
||||||
if (!process.m_fds[fd])
|
if (!process.m_fds[fd])
|
||||||
continue;
|
continue;
|
||||||
if (process.m_fds[fd].description->can_read())
|
if (process.m_fds[fd].description()->can_read())
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
for (int fd : m_select_write_fds) {
|
for (int fd : m_select_write_fds) {
|
||||||
if (!process.m_fds[fd])
|
if (!process.m_fds[fd])
|
||||||
continue;
|
continue;
|
||||||
if (process.m_fds[fd].description->can_write())
|
if (process.m_fds[fd].description()->can_write())
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -244,10 +244,10 @@ int Process::do_exec(NonnullRefPtr<FileDescription> main_program_description, Ve
|
||||||
disown_all_shared_buffers();
|
disown_all_shared_buffers();
|
||||||
|
|
||||||
for (size_t i = 0; i < m_fds.size(); ++i) {
|
for (size_t i = 0; i < m_fds.size(); ++i) {
|
||||||
auto& daf = m_fds[i];
|
auto& description_and_flags = m_fds[i];
|
||||||
if (daf.description && daf.flags & FD_CLOEXEC) {
|
if (description_and_flags.description() && description_and_flags.flags() & FD_CLOEXEC) {
|
||||||
daf.description->close();
|
description_and_flags.description()->close();
|
||||||
daf = {};
|
description_and_flags = {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,9 +52,9 @@ int Process::sys$fcntl(int fd, int cmd, u32 arg)
|
||||||
return new_fd;
|
return new_fd;
|
||||||
}
|
}
|
||||||
case F_GETFD:
|
case F_GETFD:
|
||||||
return m_fds[fd].flags;
|
return m_fds[fd].flags();
|
||||||
case F_SETFD:
|
case F_SETFD:
|
||||||
m_fds[fd].flags = arg;
|
m_fds[fd].set_flags(arg);
|
||||||
break;
|
break;
|
||||||
case F_GETFL:
|
case F_GETFL:
|
||||||
return description->file_flags();
|
return description->file_flags();
|
||||||
|
|
|
@ -46,12 +46,12 @@ int Process::sys$pipe(int pipefd[2], int flags)
|
||||||
|
|
||||||
int reader_fd = alloc_fd();
|
int reader_fd = alloc_fd();
|
||||||
m_fds[reader_fd].set(fifo->open_direction(FIFO::Direction::Reader), fd_flags);
|
m_fds[reader_fd].set(fifo->open_direction(FIFO::Direction::Reader), fd_flags);
|
||||||
m_fds[reader_fd].description->set_readable(true);
|
m_fds[reader_fd].description()->set_readable(true);
|
||||||
copy_to_user(&pipefd[0], &reader_fd);
|
copy_to_user(&pipefd[0], &reader_fd);
|
||||||
|
|
||||||
int writer_fd = alloc_fd();
|
int writer_fd = alloc_fd();
|
||||||
m_fds[writer_fd].set(fifo->open_direction(FIFO::Direction::Writer), fd_flags);
|
m_fds[writer_fd].set(fifo->open_direction(FIFO::Direction::Writer), fd_flags);
|
||||||
m_fds[writer_fd].description->set_writable(true);
|
m_fds[writer_fd].description()->set_writable(true);
|
||||||
copy_to_user(&pipefd[1], &writer_fd);
|
copy_to_user(&pipefd[1], &writer_fd);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -115,7 +115,7 @@ int Process::sys$accept(int accepting_socket_fd, sockaddr* user_address, socklen
|
||||||
// NOTE: The accepted socket inherits fd flags from the accepting socket.
|
// NOTE: The accepted socket inherits fd flags from the accepting socket.
|
||||||
// I'm not sure if this matches other systems but it makes sense to me.
|
// I'm not sure if this matches other systems but it makes sense to me.
|
||||||
accepted_socket_description->set_blocking(accepting_socket_description->is_blocking());
|
accepted_socket_description->set_blocking(accepting_socket_description->is_blocking());
|
||||||
m_fds[accepted_socket_fd].set(move(accepted_socket_description), m_fds[accepting_socket_fd].flags);
|
m_fds[accepted_socket_fd].set(move(accepted_socket_description), m_fds[accepting_socket_fd].flags());
|
||||||
|
|
||||||
// NOTE: Moving this state to Completed is what causes connect() to unblock on the client side.
|
// NOTE: Moving this state to Completed is what causes connect() to unblock on the client side.
|
||||||
accepted_socket->set_setup_state(Socket::SetupState::Completed);
|
accepted_socket->set_setup_state(Socket::SetupState::Completed);
|
||||||
|
|
|
@ -53,7 +53,7 @@ int Process::sys$watch_file(const char* user_path, size_t path_length)
|
||||||
return fd;
|
return fd;
|
||||||
|
|
||||||
m_fds[fd].set(FileDescription::create(*InodeWatcher::create(inode)));
|
m_fds[fd].set(FileDescription::create(*InodeWatcher::create(inode)));
|
||||||
m_fds[fd].description->set_readable(true);
|
m_fds[fd].description()->set_readable(true);
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue