mirror of
https://github.com/RGBCube/serenity
synced 2025-07-10 09:47:35 +00:00
Kernel: Rename "descriptor" to "description" where appropriate.
Now that FileDescription is called that, variables of that type should not be called "descriptor". This is kinda wordy but we'll get used to it.
This commit is contained in:
parent
1c5677032a
commit
c1bbd40b9e
17 changed files with 285 additions and 285 deletions
|
@ -32,10 +32,10 @@ Retained<FIFO> FIFO::create(uid_t uid)
|
||||||
|
|
||||||
Retained<FileDescription> FIFO::open_direction(FIFO::Direction direction)
|
Retained<FileDescription> FIFO::open_direction(FIFO::Direction direction)
|
||||||
{
|
{
|
||||||
auto descriptor = FileDescription::create(this);
|
auto description = FileDescription::create(this);
|
||||||
attach(direction);
|
attach(direction);
|
||||||
descriptor->set_fifo_direction({}, direction);
|
description->set_fifo_direction({}, direction);
|
||||||
return descriptor;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
FIFO::FIFO(uid_t uid)
|
FIFO::FIFO(uid_t uid)
|
||||||
|
|
|
@ -17,9 +17,9 @@
|
||||||
|
|
||||||
Retained<FileDescription> FileDescription::create(RetainPtr<Custody>&& custody)
|
Retained<FileDescription> FileDescription::create(RetainPtr<Custody>&& custody)
|
||||||
{
|
{
|
||||||
auto descriptor = adopt(*new FileDescription(InodeFile::create(custody->inode())));
|
auto description = adopt(*new FileDescription(InodeFile::create(custody->inode())));
|
||||||
descriptor->m_custody = move(custody);
|
description->m_custody = move(custody);
|
||||||
return descriptor;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
Retained<FileDescription> FileDescription::create(RetainPtr<File>&& file, SocketRole role)
|
Retained<FileDescription> FileDescription::create(RetainPtr<File>&& file, SocketRole role)
|
||||||
|
@ -60,20 +60,20 @@ void FileDescription::set_socket_role(SocketRole role)
|
||||||
|
|
||||||
Retained<FileDescription> FileDescription::clone()
|
Retained<FileDescription> FileDescription::clone()
|
||||||
{
|
{
|
||||||
RetainPtr<FileDescription> descriptor;
|
RetainPtr<FileDescription> description;
|
||||||
if (is_fifo()) {
|
if (is_fifo()) {
|
||||||
descriptor = fifo()->open_direction(m_fifo_direction);
|
description = fifo()->open_direction(m_fifo_direction);
|
||||||
} else {
|
} else {
|
||||||
descriptor = FileDescription::create(m_file.copy_ref(), m_socket_role);
|
description = FileDescription::create(m_file.copy_ref(), m_socket_role);
|
||||||
descriptor->m_custody = m_custody.copy_ref();
|
description->m_custody = m_custody.copy_ref();
|
||||||
descriptor->m_inode = m_inode.copy_ref();
|
description->m_inode = m_inode.copy_ref();
|
||||||
}
|
}
|
||||||
ASSERT(descriptor);
|
ASSERT(description);
|
||||||
descriptor->m_current_offset = m_current_offset;
|
description->m_current_offset = m_current_offset;
|
||||||
descriptor->m_is_blocking = m_is_blocking;
|
description->m_is_blocking = m_is_blocking;
|
||||||
descriptor->m_should_append = m_should_append;
|
description->m_should_append = m_should_append;
|
||||||
descriptor->m_file_flags = m_file_flags;
|
description->m_file_flags = m_file_flags;
|
||||||
return *descriptor;
|
return *description;
|
||||||
}
|
}
|
||||||
|
|
||||||
KResult FileDescription::fstat(stat& buffer)
|
KResult FileDescription::fstat(stat& buffer)
|
||||||
|
|
|
@ -13,32 +13,32 @@ InodeFile::~InodeFile()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t InodeFile::read(FileDescription& descriptor, byte* buffer, ssize_t count)
|
ssize_t InodeFile::read(FileDescription& description, byte* buffer, ssize_t count)
|
||||||
{
|
{
|
||||||
return m_inode->read_bytes(descriptor.offset(), count, buffer, &descriptor);
|
return m_inode->read_bytes(description.offset(), count, buffer, &description);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t InodeFile::write(FileDescription& descriptor, const byte* data, ssize_t count)
|
ssize_t InodeFile::write(FileDescription& description, const byte* data, ssize_t count)
|
||||||
{
|
{
|
||||||
return m_inode->write_bytes(descriptor.offset(), count, data, &descriptor);
|
return m_inode->write_bytes(description.offset(), count, data, &description);
|
||||||
}
|
}
|
||||||
|
|
||||||
KResultOr<Region*> InodeFile::mmap(Process& process, FileDescription& descriptor, VirtualAddress preferred_vaddr, size_t offset, size_t size, int prot)
|
KResultOr<Region*> InodeFile::mmap(Process& process, FileDescription& description, VirtualAddress preferred_vaddr, size_t offset, size_t size, int prot)
|
||||||
{
|
{
|
||||||
ASSERT(offset == 0);
|
ASSERT(offset == 0);
|
||||||
// FIXME: If PROT_EXEC, check that the underlying file system isn't mounted noexec.
|
// FIXME: If PROT_EXEC, check that the underlying file system isn't mounted noexec.
|
||||||
InterruptDisabler disabler;
|
InterruptDisabler disabler;
|
||||||
auto* region = process.allocate_file_backed_region(preferred_vaddr, size, inode(), descriptor.absolute_path(), prot);
|
auto* region = process.allocate_file_backed_region(preferred_vaddr, size, inode(), description.absolute_path(), prot);
|
||||||
if (!region)
|
if (!region)
|
||||||
return KResult(-ENOMEM);
|
return KResult(-ENOMEM);
|
||||||
return region;
|
return region;
|
||||||
}
|
}
|
||||||
|
|
||||||
String InodeFile::absolute_path(const FileDescription& descriptor) const
|
String InodeFile::absolute_path(const FileDescription& description) const
|
||||||
{
|
{
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
ASSERT(descriptor.custody());
|
ASSERT(description.custody());
|
||||||
return descriptor.absolute_path();
|
return description.absolute_path();
|
||||||
}
|
}
|
||||||
|
|
||||||
KResult InodeFile::truncate(off_t size)
|
KResult InodeFile::truncate(off_t size)
|
||||||
|
|
|
@ -189,10 +189,10 @@ ByteBuffer procfs$pid_fds(InodeIdentifier identifier)
|
||||||
return {};
|
return {};
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
for (int i = 0; i < process.max_open_file_descriptors(); ++i) {
|
for (int i = 0; i < process.max_open_file_descriptors(); ++i) {
|
||||||
auto* descriptor = process.file_description(i);
|
auto* description = process.file_description(i);
|
||||||
if (!descriptor)
|
if (!description)
|
||||||
continue;
|
continue;
|
||||||
builder.appendf("% 3u %s\n", i, descriptor->absolute_path().characters());
|
builder.appendf("% 3u %s\n", i, description->absolute_path().characters());
|
||||||
}
|
}
|
||||||
return builder.to_byte_buffer();
|
return builder.to_byte_buffer();
|
||||||
}
|
}
|
||||||
|
@ -204,10 +204,10 @@ ByteBuffer procfs$pid_fd_entry(InodeIdentifier identifier)
|
||||||
return {};
|
return {};
|
||||||
auto& process = handle->process();
|
auto& process = handle->process();
|
||||||
int fd = to_fd(identifier);
|
int fd = to_fd(identifier);
|
||||||
auto* descriptor = process.file_description(fd);
|
auto* description = process.file_description(fd);
|
||||||
if (!descriptor)
|
if (!description)
|
||||||
return {};
|
return {};
|
||||||
return descriptor->absolute_path().to_byte_buffer();
|
return description->absolute_path().to_byte_buffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuffer procfs$pid_vm(InodeIdentifier identifier)
|
ByteBuffer procfs$pid_vm(InodeIdentifier identifier)
|
||||||
|
@ -831,7 +831,7 @@ InodeMetadata ProcFSInode::metadata() const
|
||||||
return metadata;
|
return metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t ProcFSInode::read_bytes(off_t offset, ssize_t count, byte* buffer, FileDescription* descriptor) const
|
ssize_t ProcFSInode::read_bytes(off_t offset, ssize_t count, byte* buffer, FileDescription* description) const
|
||||||
{
|
{
|
||||||
#ifdef PROCFS_DEBUG
|
#ifdef PROCFS_DEBUG
|
||||||
dbgprintf("ProcFS: read_bytes %u\n", index());
|
dbgprintf("ProcFS: read_bytes %u\n", index());
|
||||||
|
@ -855,19 +855,19 @@ ssize_t ProcFSInode::read_bytes(off_t offset, ssize_t count, byte* buffer, FileD
|
||||||
ASSERT(read_callback);
|
ASSERT(read_callback);
|
||||||
|
|
||||||
ByteBuffer generated_data;
|
ByteBuffer generated_data;
|
||||||
if (!descriptor) {
|
if (!description) {
|
||||||
generated_data = (*read_callback)(identifier());
|
generated_data = (*read_callback)(identifier());
|
||||||
} else {
|
} else {
|
||||||
if (!descriptor->generator_cache())
|
if (!description->generator_cache())
|
||||||
descriptor->generator_cache() = (*read_callback)(identifier());
|
description->generator_cache() = (*read_callback)(identifier());
|
||||||
generated_data = descriptor->generator_cache();
|
generated_data = description->generator_cache();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto& data = generated_data;
|
auto& data = generated_data;
|
||||||
ssize_t nread = min(static_cast<off_t>(data.size() - offset), static_cast<off_t>(count));
|
ssize_t nread = min(static_cast<off_t>(data.size() - offset), static_cast<off_t>(count));
|
||||||
memcpy(buffer, data.pointer() + offset, nread);
|
memcpy(buffer, data.pointer() + offset, nread);
|
||||||
if (nread == 0 && descriptor && descriptor->generator_cache())
|
if (nread == 0 && description && description->generator_cache())
|
||||||
descriptor->generator_cache().clear();
|
description->generator_cache().clear();
|
||||||
return nread;
|
return nread;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -936,8 +936,8 @@ bool ProcFSInode::traverse_as_directory(Function<bool(const FS::DirectoryEntry&)
|
||||||
return false;
|
return false;
|
||||||
auto& process = handle->process();
|
auto& process = handle->process();
|
||||||
for (int i = 0; i < process.max_open_file_descriptors(); ++i) {
|
for (int i = 0; i < process.max_open_file_descriptors(); ++i) {
|
||||||
auto* descriptor = process.file_description(i);
|
auto* description = process.file_description(i);
|
||||||
if (!descriptor)
|
if (!description)
|
||||||
continue;
|
continue;
|
||||||
char name[16];
|
char name[16];
|
||||||
int name_length = ksprintf(name, "%u", i);
|
int name_length = ksprintf(name, "%u", i);
|
||||||
|
|
|
@ -185,7 +185,7 @@ InodeMetadata SynthFSInode::metadata() const
|
||||||
return m_metadata;
|
return m_metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t SynthFSInode::read_bytes(off_t offset, ssize_t count, byte* buffer, FileDescription* descriptor) const
|
ssize_t SynthFSInode::read_bytes(off_t offset, ssize_t count, byte* buffer, FileDescription* description) const
|
||||||
{
|
{
|
||||||
LOCKER(m_lock);
|
LOCKER(m_lock);
|
||||||
#ifdef SYNTHFS_DEBUG
|
#ifdef SYNTHFS_DEBUG
|
||||||
|
@ -196,20 +196,20 @@ ssize_t SynthFSInode::read_bytes(off_t offset, ssize_t count, byte* buffer, File
|
||||||
|
|
||||||
ByteBuffer generated_data;
|
ByteBuffer generated_data;
|
||||||
if (m_generator) {
|
if (m_generator) {
|
||||||
if (!descriptor) {
|
if (!description) {
|
||||||
generated_data = m_generator(const_cast<SynthFSInode&>(*this));
|
generated_data = m_generator(const_cast<SynthFSInode&>(*this));
|
||||||
} else {
|
} else {
|
||||||
if (!descriptor->generator_cache())
|
if (!description->generator_cache())
|
||||||
descriptor->generator_cache() = m_generator(const_cast<SynthFSInode&>(*this));
|
description->generator_cache() = m_generator(const_cast<SynthFSInode&>(*this));
|
||||||
generated_data = descriptor->generator_cache();
|
generated_data = description->generator_cache();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* data = generated_data ? &generated_data : &m_data;
|
auto* data = generated_data ? &generated_data : &m_data;
|
||||||
ssize_t nread = min(static_cast<off_t>(data->size() - offset), static_cast<off_t>(count));
|
ssize_t nread = min(static_cast<off_t>(data->size() - offset), static_cast<off_t>(count));
|
||||||
memcpy(buffer, data->pointer() + offset, nread);
|
memcpy(buffer, data->pointer() + offset, nread);
|
||||||
if (nread == 0 && descriptor && descriptor->generator_cache())
|
if (nread == 0 && description && description->generator_cache())
|
||||||
descriptor->generator_cache().clear();
|
description->generator_cache().clear();
|
||||||
return nread;
|
return nread;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -157,8 +157,8 @@ void load_ksyms()
|
||||||
{
|
{
|
||||||
auto result = VFS::the().open("/kernel.map", 0, 0, VFS::the().root_custody());
|
auto result = VFS::the().open("/kernel.map", 0, 0, VFS::the().root_custody());
|
||||||
ASSERT(!result.is_error());
|
ASSERT(!result.is_error());
|
||||||
auto descriptor = result.value();
|
auto description = result.value();
|
||||||
auto buffer = descriptor->read_entire_file();
|
auto buffer = description->read_entire_file();
|
||||||
ASSERT(buffer);
|
ASSERT(buffer);
|
||||||
load_ksyms_from_data(buffer);
|
load_ksyms_from_data(buffer);
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,7 +89,7 @@ KResult IPv4Socket::bind(const sockaddr* address, socklen_t address_size)
|
||||||
return protocol_bind();
|
return protocol_bind();
|
||||||
}
|
}
|
||||||
|
|
||||||
KResult IPv4Socket::connect(FileDescription& descriptor, const sockaddr* address, socklen_t address_size, ShouldBlock should_block)
|
KResult IPv4Socket::connect(FileDescription& description, const sockaddr* address, socklen_t address_size, ShouldBlock should_block)
|
||||||
{
|
{
|
||||||
ASSERT(!m_bound);
|
ASSERT(!m_bound);
|
||||||
if (address_size != sizeof(sockaddr_in))
|
if (address_size != sizeof(sockaddr_in))
|
||||||
|
@ -101,7 +101,7 @@ KResult IPv4Socket::connect(FileDescription& descriptor, const sockaddr* address
|
||||||
m_peer_address = IPv4Address((const byte*)&ia.sin_addr.s_addr);
|
m_peer_address = IPv4Address((const byte*)&ia.sin_addr.s_addr);
|
||||||
m_peer_port = ntohs(ia.sin_port);
|
m_peer_port = ntohs(ia.sin_port);
|
||||||
|
|
||||||
return protocol_connect(descriptor, should_block);
|
return protocol_connect(description, should_block);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IPv4Socket::attach(FileDescription&)
|
void IPv4Socket::attach(FileDescription&)
|
||||||
|
@ -114,23 +114,23 @@ void IPv4Socket::detach(FileDescription&)
|
||||||
--m_attached_fds;
|
--m_attached_fds;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IPv4Socket::can_read(FileDescription& descriptor) const
|
bool IPv4Socket::can_read(FileDescription& description) const
|
||||||
{
|
{
|
||||||
if (descriptor.socket_role() == SocketRole::Listener)
|
if (description.socket_role() == SocketRole::Listener)
|
||||||
return can_accept();
|
return can_accept();
|
||||||
if (protocol_is_disconnected())
|
if (protocol_is_disconnected())
|
||||||
return true;
|
return true;
|
||||||
return m_can_read;
|
return m_can_read;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t IPv4Socket::read(FileDescription& descriptor, byte* buffer, ssize_t size)
|
ssize_t IPv4Socket::read(FileDescription& description, byte* buffer, ssize_t size)
|
||||||
{
|
{
|
||||||
return recvfrom(descriptor, buffer, size, 0, nullptr, 0);
|
return recvfrom(description, buffer, size, 0, nullptr, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t IPv4Socket::write(FileDescription& descriptor, const byte* data, ssize_t size)
|
ssize_t IPv4Socket::write(FileDescription& description, const byte* data, ssize_t size)
|
||||||
{
|
{
|
||||||
return sendto(descriptor, data, size, 0, nullptr, 0);
|
return sendto(description, data, size, 0, nullptr, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IPv4Socket::can_write(FileDescription&) const
|
bool IPv4Socket::can_write(FileDescription&) const
|
||||||
|
@ -184,7 +184,7 @@ ssize_t IPv4Socket::sendto(FileDescription&, const void* data, size_t data_lengt
|
||||||
return protocol_send(data, data_length);
|
return protocol_send(data, data_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t IPv4Socket::recvfrom(FileDescription& descriptor, void* buffer, size_t buffer_length, int flags, sockaddr* addr, socklen_t* addr_length)
|
ssize_t IPv4Socket::recvfrom(FileDescription& description, void* buffer, size_t buffer_length, int flags, sockaddr* addr, socklen_t* addr_length)
|
||||||
{
|
{
|
||||||
(void)flags;
|
(void)flags;
|
||||||
if (addr_length && *addr_length < sizeof(sockaddr_in))
|
if (addr_length && *addr_length < sizeof(sockaddr_in))
|
||||||
|
@ -212,7 +212,7 @@ ssize_t IPv4Socket::recvfrom(FileDescription& descriptor, void* buffer, size_t b
|
||||||
}
|
}
|
||||||
|
|
||||||
load_receive_deadline();
|
load_receive_deadline();
|
||||||
current->block(Thread::BlockedReceive, descriptor);
|
current->block(Thread::BlockedReceive, description);
|
||||||
|
|
||||||
LOCKER(lock());
|
LOCKER(lock());
|
||||||
if (!m_can_read) {
|
if (!m_can_read) {
|
||||||
|
|
|
@ -71,7 +71,7 @@ KResult LocalSocket::bind(const sockaddr* address, socklen_t address_size)
|
||||||
return KSuccess;
|
return KSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
KResult LocalSocket::connect(FileDescription& descriptor, const sockaddr* address, socklen_t address_size, ShouldBlock)
|
KResult LocalSocket::connect(FileDescription& description, const sockaddr* address, socklen_t address_size, ShouldBlock)
|
||||||
{
|
{
|
||||||
ASSERT(!m_bound);
|
ASSERT(!m_bound);
|
||||||
if (address_size != sizeof(sockaddr_un))
|
if (address_size != sizeof(sockaddr_un))
|
||||||
|
@ -87,10 +87,10 @@ KResult LocalSocket::connect(FileDescription& descriptor, const sockaddr* addres
|
||||||
kprintf("%s(%u) LocalSocket{%p} connect(%s)\n", current->process().name().characters(), current->pid(), this, safe_address);
|
kprintf("%s(%u) LocalSocket{%p} connect(%s)\n", current->process().name().characters(), current->pid(), this, safe_address);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
auto descriptor_or_error = VFS::the().open(safe_address, 0, 0, current->process().current_directory());
|
auto description_or_error = VFS::the().open(safe_address, 0, 0, current->process().current_directory());
|
||||||
if (descriptor_or_error.is_error())
|
if (description_or_error.is_error())
|
||||||
return KResult(-ECONNREFUSED);
|
return KResult(-ECONNREFUSED);
|
||||||
m_file = move(descriptor_or_error.value());
|
m_file = move(description_or_error.value());
|
||||||
|
|
||||||
ASSERT(m_file->inode());
|
ASSERT(m_file->inode());
|
||||||
if (!m_file->inode()->socket())
|
if (!m_file->inode()->socket())
|
||||||
|
@ -103,12 +103,12 @@ KResult LocalSocket::connect(FileDescription& descriptor, const sockaddr* addres
|
||||||
if (result.is_error())
|
if (result.is_error())
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
return current->wait_for_connect(descriptor);
|
return current->wait_for_connect(description);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalSocket::attach(FileDescription& descriptor)
|
void LocalSocket::attach(FileDescription& description)
|
||||||
{
|
{
|
||||||
switch (descriptor.socket_role()) {
|
switch (description.socket_role()) {
|
||||||
case SocketRole::Accepted:
|
case SocketRole::Accepted:
|
||||||
++m_accepted_fds_open;
|
++m_accepted_fds_open;
|
||||||
break;
|
break;
|
||||||
|
@ -123,9 +123,9 @@ void LocalSocket::attach(FileDescription& descriptor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalSocket::detach(FileDescription& descriptor)
|
void LocalSocket::detach(FileDescription& description)
|
||||||
{
|
{
|
||||||
switch (descriptor.socket_role()) {
|
switch (description.socket_role()) {
|
||||||
case SocketRole::Accepted:
|
case SocketRole::Accepted:
|
||||||
ASSERT(m_accepted_fds_open);
|
ASSERT(m_accepted_fds_open);
|
||||||
--m_accepted_fds_open;
|
--m_accepted_fds_open;
|
||||||
|
@ -143,30 +143,30 @@ void LocalSocket::detach(FileDescription& descriptor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LocalSocket::can_read(FileDescription& descriptor) const
|
bool LocalSocket::can_read(FileDescription& description) const
|
||||||
{
|
{
|
||||||
auto role = descriptor.socket_role();
|
auto role = description.socket_role();
|
||||||
if (role == SocketRole::Listener)
|
if (role == SocketRole::Listener)
|
||||||
return can_accept();
|
return can_accept();
|
||||||
if (role == SocketRole::Accepted)
|
if (role == SocketRole::Accepted)
|
||||||
return !has_attached_peer(descriptor) || !m_for_server.is_empty();
|
return !has_attached_peer(description) || !m_for_server.is_empty();
|
||||||
if (role == SocketRole::Connected)
|
if (role == SocketRole::Connected)
|
||||||
return !has_attached_peer(descriptor) || !m_for_client.is_empty();
|
return !has_attached_peer(description) || !m_for_client.is_empty();
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t LocalSocket::read(FileDescription& descriptor, byte* buffer, ssize_t size)
|
ssize_t LocalSocket::read(FileDescription& description, byte* buffer, ssize_t size)
|
||||||
{
|
{
|
||||||
auto role = descriptor.socket_role();
|
auto role = description.socket_role();
|
||||||
if (role == SocketRole::Accepted) {
|
if (role == SocketRole::Accepted) {
|
||||||
if (!descriptor.is_blocking()) {
|
if (!description.is_blocking()) {
|
||||||
if (m_for_server.is_empty())
|
if (m_for_server.is_empty())
|
||||||
return -EAGAIN;
|
return -EAGAIN;
|
||||||
}
|
}
|
||||||
return m_for_server.read(buffer, size);
|
return m_for_server.read(buffer, size);
|
||||||
}
|
}
|
||||||
if (role == SocketRole::Connected) {
|
if (role == SocketRole::Connected) {
|
||||||
if (!descriptor.is_blocking()) {
|
if (!description.is_blocking()) {
|
||||||
if (m_for_client.is_empty())
|
if (m_for_client.is_empty())
|
||||||
return -EAGAIN;
|
return -EAGAIN;
|
||||||
}
|
}
|
||||||
|
@ -175,41 +175,41 @@ ssize_t LocalSocket::read(FileDescription& descriptor, byte* buffer, ssize_t siz
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LocalSocket::has_attached_peer(const FileDescription& descriptor) const
|
bool LocalSocket::has_attached_peer(const FileDescription& description) const
|
||||||
{
|
{
|
||||||
if (descriptor.socket_role() == SocketRole::Accepted)
|
if (description.socket_role() == SocketRole::Accepted)
|
||||||
return m_connected_fds_open || m_connecting_fds_open;
|
return m_connected_fds_open || m_connecting_fds_open;
|
||||||
if (descriptor.socket_role() == SocketRole::Connected)
|
if (description.socket_role() == SocketRole::Connected)
|
||||||
return m_accepted_fds_open;
|
return m_accepted_fds_open;
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t LocalSocket::write(FileDescription& descriptor, const byte* data, ssize_t size)
|
ssize_t LocalSocket::write(FileDescription& description, const byte* data, ssize_t size)
|
||||||
{
|
{
|
||||||
if (!has_attached_peer(descriptor))
|
if (!has_attached_peer(description))
|
||||||
return -EPIPE;
|
return -EPIPE;
|
||||||
if (descriptor.socket_role() == SocketRole::Accepted)
|
if (description.socket_role() == SocketRole::Accepted)
|
||||||
return m_for_client.write(data, size);
|
return m_for_client.write(data, size);
|
||||||
if (descriptor.socket_role() == SocketRole::Connected)
|
if (description.socket_role() == SocketRole::Connected)
|
||||||
return m_for_server.write(data, size);
|
return m_for_server.write(data, size);
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LocalSocket::can_write(FileDescription& descriptor) const
|
bool LocalSocket::can_write(FileDescription& description) const
|
||||||
{
|
{
|
||||||
if (descriptor.socket_role() == SocketRole::Accepted)
|
if (description.socket_role() == SocketRole::Accepted)
|
||||||
return !has_attached_peer(descriptor) || m_for_client.bytes_in_write_buffer() < 16384;
|
return !has_attached_peer(description) || m_for_client.bytes_in_write_buffer() < 16384;
|
||||||
if (descriptor.socket_role() == SocketRole::Connected)
|
if (description.socket_role() == SocketRole::Connected)
|
||||||
return !has_attached_peer(descriptor) || m_for_server.bytes_in_write_buffer() < 16384;
|
return !has_attached_peer(description) || m_for_server.bytes_in_write_buffer() < 16384;
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t LocalSocket::sendto(FileDescription& descriptor, const void* data, size_t data_size, int, const sockaddr*, socklen_t)
|
ssize_t LocalSocket::sendto(FileDescription& description, const void* data, size_t data_size, int, const sockaddr*, socklen_t)
|
||||||
{
|
{
|
||||||
return write(descriptor, (const byte*)data, data_size);
|
return write(description, (const byte*)data, data_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t LocalSocket::recvfrom(FileDescription& descriptor, void* buffer, size_t buffer_size, int, sockaddr*, socklen_t*)
|
ssize_t LocalSocket::recvfrom(FileDescription& description, void* buffer, size_t buffer_size, int, sockaddr*, socklen_t*)
|
||||||
{
|
{
|
||||||
return read(descriptor, (byte*)buffer, buffer_size);
|
return read(description, (byte*)buffer, buffer_size);
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,7 +142,7 @@ static const char* to_string(SocketRole role)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String Socket::absolute_path(const FileDescription& descriptor) const
|
String Socket::absolute_path(const FileDescription& description) const
|
||||||
{
|
{
|
||||||
return String::format("socket:%x (role: %s)", this, to_string(descriptor.socket_role()));
|
return String::format("socket:%x (role: %s)", this, to_string(description.socket_role()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,7 +147,7 @@ NetworkOrdered<word> TCPSocket::compute_tcp_checksum(const IPv4Address& source,
|
||||||
return ~(checksum & 0xffff);
|
return ~(checksum & 0xffff);
|
||||||
}
|
}
|
||||||
|
|
||||||
KResult TCPSocket::protocol_connect(FileDescription& descriptor, ShouldBlock should_block)
|
KResult TCPSocket::protocol_connect(FileDescription& description, ShouldBlock should_block)
|
||||||
{
|
{
|
||||||
auto* adapter = adapter_for_route_to(peer_address());
|
auto* adapter = adapter_for_route_to(peer_address());
|
||||||
if (!adapter)
|
if (!adapter)
|
||||||
|
@ -162,7 +162,7 @@ KResult TCPSocket::protocol_connect(FileDescription& descriptor, ShouldBlock sho
|
||||||
m_state = State::Connecting;
|
m_state = State::Connecting;
|
||||||
|
|
||||||
if (should_block == ShouldBlock::Yes) {
|
if (should_block == ShouldBlock::Yes) {
|
||||||
current->block(Thread::BlockedConnect, descriptor);
|
current->block(Thread::BlockedConnect, description);
|
||||||
ASSERT(is_connected());
|
ASSERT(is_connected());
|
||||||
return KSuccess;
|
return KSuccess;
|
||||||
}
|
}
|
||||||
|
|
|
@ -190,10 +190,10 @@ void* Process::sys$mmap(const Syscall::SC_mmap_params* params)
|
||||||
}
|
}
|
||||||
if (offset & ~PAGE_MASK)
|
if (offset & ~PAGE_MASK)
|
||||||
return (void*)-EINVAL;
|
return (void*)-EINVAL;
|
||||||
auto* descriptor = file_description(fd);
|
auto* description = file_description(fd);
|
||||||
if (!descriptor)
|
if (!description)
|
||||||
return (void*)-EBADF;
|
return (void*)-EBADF;
|
||||||
auto region_or_error = descriptor->mmap(*this, VirtualAddress((dword)addr), offset, size, prot);
|
auto region_or_error = description->mmap(*this, VirtualAddress((dword)addr), offset, size, prot);
|
||||||
if (region_or_error.is_error())
|
if (region_or_error.is_error())
|
||||||
return (void*)(int)region_or_error.error();
|
return (void*)(int)region_or_error.error();
|
||||||
auto region = region_or_error.value();
|
auto region = region_or_error.value();
|
||||||
|
@ -314,8 +314,8 @@ int Process::do_exec(String path, Vector<String> arguments, Vector<String> envir
|
||||||
auto result = VFS::the().open(path, 0, 0, current_directory());
|
auto result = VFS::the().open(path, 0, 0, current_directory());
|
||||||
if (result.is_error())
|
if (result.is_error())
|
||||||
return result.error();
|
return result.error();
|
||||||
auto descriptor = result.value();
|
auto description = result.value();
|
||||||
auto metadata = descriptor->metadata();
|
auto metadata = description->metadata();
|
||||||
|
|
||||||
if (!metadata.may_execute(m_euid, m_gids))
|
if (!metadata.may_execute(m_euid, m_gids))
|
||||||
return -EACCES;
|
return -EACCES;
|
||||||
|
@ -332,8 +332,8 @@ int Process::do_exec(String path, Vector<String> arguments, Vector<String> envir
|
||||||
#endif
|
#endif
|
||||||
ProcessPagingScope paging_scope(*this);
|
ProcessPagingScope paging_scope(*this);
|
||||||
|
|
||||||
auto vmo = VMObject::create_file_backed(descriptor->inode());
|
auto vmo = VMObject::create_file_backed(description->inode());
|
||||||
vmo->set_name(descriptor->absolute_path());
|
vmo->set_name(description->absolute_path());
|
||||||
RetainPtr<Region> region = allocate_region_with_vmo(VirtualAddress(), metadata.size, vmo.copy_ref(), 0, vmo->name(), PROT_READ);
|
RetainPtr<Region> region = allocate_region_with_vmo(VirtualAddress(), metadata.size, vmo.copy_ref(), 0, vmo->name(), PROT_READ);
|
||||||
ASSERT(region);
|
ASSERT(region);
|
||||||
|
|
||||||
|
@ -388,7 +388,7 @@ int Process::do_exec(String path, Vector<String> arguments, Vector<String> envir
|
||||||
}
|
}
|
||||||
|
|
||||||
m_elf_loader = move(loader);
|
m_elf_loader = move(loader);
|
||||||
m_executable = descriptor->custody();
|
m_executable = description->custody();
|
||||||
|
|
||||||
if (metadata.is_setuid())
|
if (metadata.is_setuid())
|
||||||
m_euid = metadata.uid;
|
m_euid = metadata.uid;
|
||||||
|
@ -403,8 +403,8 @@ int Process::do_exec(String path, Vector<String> arguments, Vector<String> envir
|
||||||
|
|
||||||
for (int i = 0; i < m_fds.size(); ++i) {
|
for (int i = 0; i < m_fds.size(); ++i) {
|
||||||
auto& daf = m_fds[i];
|
auto& daf = m_fds[i];
|
||||||
if (daf.descriptor && daf.flags & FD_CLOEXEC) {
|
if (daf.description && daf.flags & FD_CLOEXEC) {
|
||||||
daf.descriptor->close();
|
daf.description->close();
|
||||||
daf = {};
|
daf = {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -605,12 +605,12 @@ Process::Process(String&& name, uid_t uid, gid_t gid, pid_t ppid, RingLevel ring
|
||||||
if (fork_parent) {
|
if (fork_parent) {
|
||||||
m_fds.resize(fork_parent->m_fds.size());
|
m_fds.resize(fork_parent->m_fds.size());
|
||||||
for (int i = 0; i < fork_parent->m_fds.size(); ++i) {
|
for (int i = 0; i < fork_parent->m_fds.size(); ++i) {
|
||||||
if (!fork_parent->m_fds[i].descriptor)
|
if (!fork_parent->m_fds[i].description)
|
||||||
continue;
|
continue;
|
||||||
#ifdef FORK_DEBUG
|
#ifdef FORK_DEBUG
|
||||||
dbgprintf("fork: cloning fd %u... (%p) istty? %u\n", i, fork_parent->m_fds[i].descriptor.ptr(), fork_parent->m_fds[i].descriptor->is_tty());
|
dbgprintf("fork: cloning fd %u... (%p) istty? %u\n", i, fork_parent->m_fds[i].description.ptr(), fork_parent->m_fds[i].description->is_tty());
|
||||||
#endif
|
#endif
|
||||||
m_fds[i].descriptor = fork_parent->m_fds[i].descriptor->clone();
|
m_fds[i].description = fork_parent->m_fds[i].description->clone();
|
||||||
m_fds[i].flags = fork_parent->m_fds[i].flags;
|
m_fds[i].flags = fork_parent->m_fds[i].flags;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -769,7 +769,7 @@ FileDescription* Process::file_description(int fd)
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
if (fd < m_fds.size())
|
if (fd < m_fds.size())
|
||||||
return m_fds[fd].descriptor.ptr();
|
return m_fds[fd].description.ptr();
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -778,7 +778,7 @@ const FileDescription* Process::file_description(int fd) const
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
if (fd < m_fds.size())
|
if (fd < m_fds.size())
|
||||||
return m_fds[fd].descriptor.ptr();
|
return m_fds[fd].description.ptr();
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -788,18 +788,18 @@ ssize_t Process::sys$get_dir_entries(int fd, void* buffer, ssize_t size)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
if (!validate_write(buffer, size))
|
if (!validate_write(buffer, size))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
auto* descriptor = file_description(fd);
|
auto* description = file_description(fd);
|
||||||
if (!descriptor)
|
if (!description)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
return descriptor->get_dir_entries((byte*)buffer, size);
|
return description->get_dir_entries((byte*)buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Process::sys$lseek(int fd, off_t offset, int whence)
|
int Process::sys$lseek(int fd, off_t offset, int whence)
|
||||||
{
|
{
|
||||||
auto* descriptor = file_description(fd);
|
auto* description = file_description(fd);
|
||||||
if (!descriptor)
|
if (!description)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
return descriptor->seek(offset, whence);
|
return description->seek(offset, whence);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Process::sys$ttyname_r(int fd, char* buffer, ssize_t size)
|
int Process::sys$ttyname_r(int fd, char* buffer, ssize_t size)
|
||||||
|
@ -808,12 +808,12 @@ int Process::sys$ttyname_r(int fd, char* buffer, ssize_t size)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
if (!validate_write(buffer, size))
|
if (!validate_write(buffer, size))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
auto* descriptor = file_description(fd);
|
auto* description = file_description(fd);
|
||||||
if (!descriptor)
|
if (!description)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
if (!descriptor->is_tty())
|
if (!description->is_tty())
|
||||||
return -ENOTTY;
|
return -ENOTTY;
|
||||||
auto tty_name = descriptor->tty()->tty_name();
|
auto tty_name = description->tty()->tty_name();
|
||||||
if (size < tty_name.length() + 1)
|
if (size < tty_name.length() + 1)
|
||||||
return -ERANGE;
|
return -ERANGE;
|
||||||
strcpy(buffer, tty_name.characters());
|
strcpy(buffer, tty_name.characters());
|
||||||
|
@ -826,10 +826,10 @@ int Process::sys$ptsname_r(int fd, char* buffer, ssize_t size)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
if (!validate_write(buffer, size))
|
if (!validate_write(buffer, size))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
auto* descriptor = file_description(fd);
|
auto* description = file_description(fd);
|
||||||
if (!descriptor)
|
if (!description)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
auto* master_pty = descriptor->master_pty();
|
auto* master_pty = description->master_pty();
|
||||||
if (!master_pty)
|
if (!master_pty)
|
||||||
return -ENOTTY;
|
return -ENOTTY;
|
||||||
auto pts_name = master_pty->pts_name();
|
auto pts_name = master_pty->pts_name();
|
||||||
|
@ -849,13 +849,13 @@ ssize_t Process::sys$writev(int fd, const struct iovec* iov, int iov_count)
|
||||||
|
|
||||||
// FIXME: Return EINVAL if sum of iovecs is greater than INT_MAX
|
// FIXME: Return EINVAL if sum of iovecs is greater than INT_MAX
|
||||||
|
|
||||||
auto* descriptor = file_description(fd);
|
auto* description = file_description(fd);
|
||||||
if (!descriptor)
|
if (!description)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
int nwritten = 0;
|
int nwritten = 0;
|
||||||
for (int i = 0; i < iov_count; ++i) {
|
for (int i = 0; i < iov_count; ++i) {
|
||||||
int rc = do_write(*descriptor, (const byte*)iov[i].iov_base, iov[i].iov_len);
|
int rc = do_write(*description, (const byte*)iov[i].iov_base, iov[i].iov_len);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
if (nwritten == 0)
|
if (nwritten == 0)
|
||||||
return rc;
|
return rc;
|
||||||
|
@ -873,32 +873,32 @@ ssize_t Process::sys$writev(int fd, const struct iovec* iov, int iov_count)
|
||||||
return nwritten;
|
return nwritten;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t Process::do_write(FileDescription& descriptor, const byte* data, int data_size)
|
ssize_t Process::do_write(FileDescription& description, const byte* data, int data_size)
|
||||||
{
|
{
|
||||||
ssize_t nwritten = 0;
|
ssize_t nwritten = 0;
|
||||||
if (!descriptor.is_blocking()) {
|
if (!description.is_blocking()) {
|
||||||
if (!descriptor.can_write())
|
if (!description.can_write())
|
||||||
return -EAGAIN;
|
return -EAGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (descriptor.should_append()) {
|
if (description.should_append()) {
|
||||||
#ifdef IO_DEBUG
|
#ifdef IO_DEBUG
|
||||||
dbgprintf("seeking to end (O_APPEND)\n");
|
dbgprintf("seeking to end (O_APPEND)\n");
|
||||||
#endif
|
#endif
|
||||||
descriptor.seek(0, SEEK_END);
|
description.seek(0, SEEK_END);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (nwritten < data_size) {
|
while (nwritten < data_size) {
|
||||||
#ifdef IO_DEBUG
|
#ifdef IO_DEBUG
|
||||||
dbgprintf("while %u < %u\n", nwritten, size);
|
dbgprintf("while %u < %u\n", nwritten, size);
|
||||||
#endif
|
#endif
|
||||||
if (!descriptor.can_write()) {
|
if (!description.can_write()) {
|
||||||
#ifdef IO_DEBUG
|
#ifdef IO_DEBUG
|
||||||
dbgprintf("block write on %d\n", fd);
|
dbgprintf("block write on %d\n", fd);
|
||||||
#endif
|
#endif
|
||||||
current->block(Thread::State::BlockedWrite, descriptor);
|
current->block(Thread::State::BlockedWrite, description);
|
||||||
}
|
}
|
||||||
ssize_t rc = descriptor.write(data + nwritten, data_size - nwritten);
|
ssize_t rc = description.write(data + nwritten, data_size - nwritten);
|
||||||
#ifdef IO_DEBUG
|
#ifdef IO_DEBUG
|
||||||
dbgprintf(" -> write returned %d\n", rc);
|
dbgprintf(" -> write returned %d\n", rc);
|
||||||
#endif
|
#endif
|
||||||
|
@ -930,10 +930,10 @@ ssize_t Process::sys$write(int fd, const byte* data, ssize_t size)
|
||||||
#ifdef DEBUG_IO
|
#ifdef DEBUG_IO
|
||||||
dbgprintf("%s(%u): sys$write(%d, %p, %u)\n", name().characters(), pid(), fd, data, size);
|
dbgprintf("%s(%u): sys$write(%d, %p, %u)\n", name().characters(), pid(), fd, data, size);
|
||||||
#endif
|
#endif
|
||||||
auto* descriptor = file_description(fd);
|
auto* description = file_description(fd);
|
||||||
if (!descriptor)
|
if (!description)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
auto nwritten = do_write(*descriptor, data, size);
|
auto nwritten = do_write(*description, data, size);
|
||||||
if (current->has_unmasked_pending_signals()) {
|
if (current->has_unmasked_pending_signals()) {
|
||||||
current->block(Thread::State::BlockedSignal);
|
current->block(Thread::State::BlockedSignal);
|
||||||
if (nwritten == 0)
|
if (nwritten == 0)
|
||||||
|
@ -953,25 +953,25 @@ ssize_t Process::sys$read(int fd, byte* buffer, ssize_t size)
|
||||||
#ifdef DEBUG_IO
|
#ifdef DEBUG_IO
|
||||||
dbgprintf("%s(%u) sys$read(%d, %p, %u)\n", name().characters(), pid(), fd, buffer, size);
|
dbgprintf("%s(%u) sys$read(%d, %p, %u)\n", name().characters(), pid(), fd, buffer, size);
|
||||||
#endif
|
#endif
|
||||||
auto* descriptor = file_description(fd);
|
auto* description = file_description(fd);
|
||||||
if (!descriptor)
|
if (!description)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
if (descriptor->is_blocking()) {
|
if (description->is_blocking()) {
|
||||||
if (!descriptor->can_read()) {
|
if (!description->can_read()) {
|
||||||
current->block(Thread::State::BlockedRead, *descriptor);
|
current->block(Thread::State::BlockedRead, *description);
|
||||||
if (current->m_was_interrupted_while_blocked)
|
if (current->m_was_interrupted_while_blocked)
|
||||||
return -EINTR;
|
return -EINTR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return descriptor->read(buffer, size);
|
return description->read(buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Process::sys$close(int fd)
|
int Process::sys$close(int fd)
|
||||||
{
|
{
|
||||||
auto* descriptor = file_description(fd);
|
auto* description = file_description(fd);
|
||||||
if (!descriptor)
|
if (!description)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
int rc = descriptor->close();
|
int rc = description->close();
|
||||||
m_fds[fd] = {};
|
m_fds[fd] = {};
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
@ -1008,8 +1008,8 @@ int Process::sys$fcntl(int fd, int cmd, dword arg)
|
||||||
(void)cmd;
|
(void)cmd;
|
||||||
(void)arg;
|
(void)arg;
|
||||||
dbgprintf("sys$fcntl: fd=%d, cmd=%d, arg=%u\n", fd, cmd, arg);
|
dbgprintf("sys$fcntl: fd=%d, cmd=%d, arg=%u\n", fd, cmd, arg);
|
||||||
auto* descriptor = file_description(fd);
|
auto* description = file_description(fd);
|
||||||
if (!descriptor)
|
if (!description)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
// NOTE: The FD flags are not shared between FileDescription objects.
|
// NOTE: The FD flags are not shared between FileDescription objects.
|
||||||
// This means that dup() doesn't copy the FD_CLOEXEC flag!
|
// This means that dup() doesn't copy the FD_CLOEXEC flag!
|
||||||
|
@ -1021,7 +1021,7 @@ int Process::sys$fcntl(int fd, int cmd, dword arg)
|
||||||
int new_fd = alloc_fd(arg_fd);
|
int new_fd = alloc_fd(arg_fd);
|
||||||
if (new_fd < 0)
|
if (new_fd < 0)
|
||||||
return new_fd;
|
return new_fd;
|
||||||
m_fds[new_fd].set(*descriptor);
|
m_fds[new_fd].set(*description);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case F_GETFD:
|
case F_GETFD:
|
||||||
|
@ -1030,9 +1030,9 @@ int Process::sys$fcntl(int fd, int cmd, dword arg)
|
||||||
m_fds[fd].flags = arg;
|
m_fds[fd].flags = arg;
|
||||||
break;
|
break;
|
||||||
case F_GETFL:
|
case F_GETFL:
|
||||||
return descriptor->file_flags();
|
return description->file_flags();
|
||||||
case F_SETFL:
|
case F_SETFL:
|
||||||
descriptor->set_file_flags(arg);
|
description->set_file_flags(arg);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
|
@ -1044,10 +1044,10 @@ int Process::sys$fstat(int fd, stat* statbuf)
|
||||||
{
|
{
|
||||||
if (!validate_write_typed(statbuf))
|
if (!validate_write_typed(statbuf))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
auto* descriptor = file_description(fd);
|
auto* description = file_description(fd);
|
||||||
if (!descriptor)
|
if (!description)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
return descriptor->fstat(*statbuf);
|
return description->fstat(*statbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Process::sys$lstat(const char* path, stat* statbuf)
|
int Process::sys$lstat(const char* path, stat* statbuf)
|
||||||
|
@ -1076,12 +1076,12 @@ int Process::sys$readlink(const char* path, char* buffer, ssize_t size)
|
||||||
auto result = VFS::the().open(path, O_RDONLY | O_NOFOLLOW_NOERROR, 0, current_directory());
|
auto result = VFS::the().open(path, O_RDONLY | O_NOFOLLOW_NOERROR, 0, current_directory());
|
||||||
if (result.is_error())
|
if (result.is_error())
|
||||||
return result.error();
|
return result.error();
|
||||||
auto descriptor = result.value();
|
auto description = result.value();
|
||||||
|
|
||||||
if (!descriptor->metadata().is_symlink())
|
if (!description->metadata().is_symlink())
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
auto contents = descriptor->read_entire_file();
|
auto contents = description->read_entire_file();
|
||||||
if (!contents)
|
if (!contents)
|
||||||
return -EIO; // FIXME: Get a more detailed error from VFS.
|
return -EIO; // FIXME: Get a more detailed error from VFS.
|
||||||
|
|
||||||
|
@ -1118,8 +1118,8 @@ int Process::sys$getcwd(char* buffer, ssize_t size)
|
||||||
int Process::number_of_open_file_descriptors() const
|
int Process::number_of_open_file_descriptors() const
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (auto& descriptor : m_fds) {
|
for (auto& description : m_fds) {
|
||||||
if (descriptor)
|
if (description)
|
||||||
++count;
|
++count;
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
|
@ -1138,12 +1138,12 @@ int Process::sys$open(const char* path, int options, mode_t mode)
|
||||||
auto result = VFS::the().open(path, options, mode & ~umask(), current_directory());
|
auto result = VFS::the().open(path, options, mode & ~umask(), current_directory());
|
||||||
if (result.is_error())
|
if (result.is_error())
|
||||||
return result.error();
|
return result.error();
|
||||||
auto descriptor = result.value();
|
auto description = result.value();
|
||||||
if (options & O_DIRECTORY && !descriptor->is_directory())
|
if (options & O_DIRECTORY && !description->is_directory())
|
||||||
return -ENOTDIR; // FIXME: This should be handled by VFS::open.
|
return -ENOTDIR; // FIXME: This should be handled by VFS::open.
|
||||||
descriptor->set_file_flags(options);
|
description->set_file_flags(options);
|
||||||
dword fd_flags = (options & O_CLOEXEC) ? FD_CLOEXEC : 0;
|
dword fd_flags = (options & O_CLOEXEC) ? FD_CLOEXEC : 0;
|
||||||
m_fds[fd].set(move(descriptor), fd_flags);
|
m_fds[fd].set(move(description), fd_flags);
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1233,10 +1233,10 @@ int Process::sys$uname(utsname* buf)
|
||||||
|
|
||||||
int Process::sys$isatty(int fd)
|
int Process::sys$isatty(int fd)
|
||||||
{
|
{
|
||||||
auto* descriptor = file_description(fd);
|
auto* description = file_description(fd);
|
||||||
if (!descriptor)
|
if (!description)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
if (!descriptor->is_tty())
|
if (!description->is_tty())
|
||||||
return -ENOTTY;
|
return -ENOTTY;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -1613,10 +1613,10 @@ int Process::sys$setpgid(pid_t specified_pid, pid_t specified_pgid)
|
||||||
|
|
||||||
int Process::sys$ioctl(int fd, unsigned request, unsigned arg)
|
int Process::sys$ioctl(int fd, unsigned request, unsigned arg)
|
||||||
{
|
{
|
||||||
auto* descriptor = file_description(fd);
|
auto* description = file_description(fd);
|
||||||
if (!descriptor)
|
if (!description)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
return descriptor->file().ioctl(*descriptor, request, arg);
|
return description->file().ioctl(*description, request, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Process::sys$getdtablesize()
|
int Process::sys$getdtablesize()
|
||||||
|
@ -1626,24 +1626,24 @@ int Process::sys$getdtablesize()
|
||||||
|
|
||||||
int Process::sys$dup(int old_fd)
|
int Process::sys$dup(int old_fd)
|
||||||
{
|
{
|
||||||
auto* descriptor = file_description(old_fd);
|
auto* description = file_description(old_fd);
|
||||||
if (!descriptor)
|
if (!description)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
int new_fd = alloc_fd(0);
|
int new_fd = alloc_fd(0);
|
||||||
if (new_fd < 0)
|
if (new_fd < 0)
|
||||||
return new_fd;
|
return new_fd;
|
||||||
m_fds[new_fd].set(*descriptor);
|
m_fds[new_fd].set(*description);
|
||||||
return new_fd;
|
return new_fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Process::sys$dup2(int old_fd, int new_fd)
|
int Process::sys$dup2(int old_fd, int new_fd)
|
||||||
{
|
{
|
||||||
auto* descriptor = file_description(old_fd);
|
auto* description = file_description(old_fd);
|
||||||
if (!descriptor)
|
if (!description)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
if (new_fd < 0 || new_fd >= m_max_open_file_descriptors)
|
if (new_fd < 0 || new_fd >= m_max_open_file_descriptors)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
m_fds[new_fd].set(*descriptor);
|
m_fds[new_fd].set(*description);
|
||||||
return new_fd;
|
return new_fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1812,14 +1812,14 @@ int Process::sys$select(const Syscall::SC_select_params* params)
|
||||||
return;
|
return;
|
||||||
FD_ZERO(fds);
|
FD_ZERO(fds);
|
||||||
for (int fd : vector) {
|
for (int fd : vector) {
|
||||||
if (auto* descriptor = file_description(fd); descriptor && should_mark(*descriptor)) {
|
if (auto* description = file_description(fd); description && should_mark(*description)) {
|
||||||
FD_SET(fd, fds);
|
FD_SET(fd, fds);
|
||||||
++marked_fd_count;
|
++marked_fd_count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
mark_fds(params->readfds, current->m_select_read_fds, [](auto& descriptor) { return descriptor.can_read(); });
|
mark_fds(params->readfds, current->m_select_read_fds, [](auto& description) { return description.can_read(); });
|
||||||
mark_fds(params->writefds, current->m_select_write_fds, [](auto& descriptor) { return descriptor.can_write(); });
|
mark_fds(params->writefds, current->m_select_write_fds, [](auto& description) { return description.can_write(); });
|
||||||
// FIXME: We should also mark params->exceptfds as appropriate.
|
// FIXME: We should also mark params->exceptfds as appropriate.
|
||||||
return marked_fd_count;
|
return marked_fd_count;
|
||||||
}
|
}
|
||||||
|
@ -1864,15 +1864,15 @@ int Process::sys$poll(pollfd* fds, int nfds, int timeout)
|
||||||
int fds_with_revents = 0;
|
int fds_with_revents = 0;
|
||||||
|
|
||||||
for (int i = 0; i < nfds; ++i) {
|
for (int i = 0; i < nfds; ++i) {
|
||||||
auto* descriptor = file_description(fds[i].fd);
|
auto* description = file_description(fds[i].fd);
|
||||||
if (!descriptor) {
|
if (!description) {
|
||||||
fds[i].revents = POLLNVAL;
|
fds[i].revents = POLLNVAL;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
fds[i].revents = 0;
|
fds[i].revents = 0;
|
||||||
if (fds[i].events & POLLIN && descriptor->can_read())
|
if (fds[i].events & POLLIN && description->can_read())
|
||||||
fds[i].revents |= POLLIN;
|
fds[i].revents |= POLLIN;
|
||||||
if (fds[i].events & POLLOUT && descriptor->can_write())
|
if (fds[i].events & POLLOUT && description->can_write())
|
||||||
fds[i].revents |= POLLOUT;
|
fds[i].revents |= POLLOUT;
|
||||||
|
|
||||||
if (fds[i].revents)
|
if (fds[i].revents)
|
||||||
|
@ -1940,18 +1940,18 @@ int Process::sys$chmod(const char* pathname, mode_t mode)
|
||||||
|
|
||||||
int Process::sys$fchmod(int fd, mode_t mode)
|
int Process::sys$fchmod(int fd, mode_t mode)
|
||||||
{
|
{
|
||||||
auto* descriptor = file_description(fd);
|
auto* description = file_description(fd);
|
||||||
if (!descriptor)
|
if (!description)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
return descriptor->fchmod(mode);
|
return description->fchmod(mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Process::sys$fchown(int fd, uid_t uid, gid_t gid)
|
int Process::sys$fchown(int fd, uid_t uid, gid_t gid)
|
||||||
{
|
{
|
||||||
auto* descriptor = file_description(fd);
|
auto* description = file_description(fd);
|
||||||
if (!descriptor)
|
if (!description)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
return descriptor->chown(uid, gid);
|
return description->chown(uid, gid);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Process::sys$chown(const char* pathname, uid_t uid, gid_t gid)
|
int Process::sys$chown(const char* pathname, uid_t uid, gid_t gid)
|
||||||
|
@ -2047,13 +2047,13 @@ int Process::sys$socket(int domain, int type, int protocol)
|
||||||
auto result = Socket::create(domain, type, protocol);
|
auto result = Socket::create(domain, type, protocol);
|
||||||
if (result.is_error())
|
if (result.is_error())
|
||||||
return result.error();
|
return result.error();
|
||||||
auto descriptor = FileDescription::create(*result.value());
|
auto description = FileDescription::create(*result.value());
|
||||||
unsigned flags = 0;
|
unsigned flags = 0;
|
||||||
if (type & SOCK_CLOEXEC)
|
if (type & SOCK_CLOEXEC)
|
||||||
flags |= FD_CLOEXEC;
|
flags |= FD_CLOEXEC;
|
||||||
if (type & SOCK_NONBLOCK)
|
if (type & SOCK_NONBLOCK)
|
||||||
descriptor->set_blocking(false);
|
description->set_blocking(false);
|
||||||
m_fds[fd].set(move(descriptor), flags);
|
m_fds[fd].set(move(description), flags);
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2061,27 +2061,27 @@ int Process::sys$bind(int sockfd, const sockaddr* address, socklen_t address_len
|
||||||
{
|
{
|
||||||
if (!validate_read(address, address_length))
|
if (!validate_read(address, address_length))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
auto* descriptor = file_description(sockfd);
|
auto* description = file_description(sockfd);
|
||||||
if (!descriptor)
|
if (!description)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
if (!descriptor->is_socket())
|
if (!description->is_socket())
|
||||||
return -ENOTSOCK;
|
return -ENOTSOCK;
|
||||||
auto& socket = *descriptor->socket();
|
auto& socket = *description->socket();
|
||||||
return socket.bind(address, address_length);
|
return socket.bind(address, address_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Process::sys$listen(int sockfd, int backlog)
|
int Process::sys$listen(int sockfd, int backlog)
|
||||||
{
|
{
|
||||||
auto* descriptor = file_description(sockfd);
|
auto* description = file_description(sockfd);
|
||||||
if (!descriptor)
|
if (!description)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
if (!descriptor->is_socket())
|
if (!description->is_socket())
|
||||||
return -ENOTSOCK;
|
return -ENOTSOCK;
|
||||||
auto& socket = *descriptor->socket();
|
auto& socket = *description->socket();
|
||||||
auto result = socket.listen(backlog);
|
auto result = socket.listen(backlog);
|
||||||
if (result.is_error())
|
if (result.is_error())
|
||||||
return result;
|
return result;
|
||||||
descriptor->set_socket_role(SocketRole::Listener);
|
description->set_socket_role(SocketRole::Listener);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2094,25 +2094,25 @@ int Process::sys$accept(int accepting_socket_fd, sockaddr* address, socklen_t* a
|
||||||
int accepted_socket_fd = alloc_fd();
|
int accepted_socket_fd = alloc_fd();
|
||||||
if (accepted_socket_fd < 0)
|
if (accepted_socket_fd < 0)
|
||||||
return accepted_socket_fd;
|
return accepted_socket_fd;
|
||||||
auto* accepting_socket_descriptor = file_description(accepting_socket_fd);
|
auto* accepting_socket_description = file_description(accepting_socket_fd);
|
||||||
if (!accepting_socket_descriptor)
|
if (!accepting_socket_description)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
if (!accepting_socket_descriptor->is_socket())
|
if (!accepting_socket_description->is_socket())
|
||||||
return -ENOTSOCK;
|
return -ENOTSOCK;
|
||||||
auto& socket = *accepting_socket_descriptor->socket();
|
auto& socket = *accepting_socket_description->socket();
|
||||||
if (!socket.can_accept()) {
|
if (!socket.can_accept()) {
|
||||||
ASSERT(!accepting_socket_descriptor->is_blocking());
|
ASSERT(!accepting_socket_description->is_blocking());
|
||||||
return -EAGAIN;
|
return -EAGAIN;
|
||||||
}
|
}
|
||||||
auto accepted_socket = socket.accept();
|
auto accepted_socket = socket.accept();
|
||||||
ASSERT(accepted_socket);
|
ASSERT(accepted_socket);
|
||||||
bool success = accepted_socket->get_local_address(address, address_size);
|
bool success = accepted_socket->get_local_address(address, address_size);
|
||||||
ASSERT(success);
|
ASSERT(success);
|
||||||
auto accepted_socket_descriptor = FileDescription::create(move(accepted_socket), SocketRole::Accepted);
|
auto accepted_socket_description = FileDescription::create(move(accepted_socket), SocketRole::Accepted);
|
||||||
// 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_descriptor->set_blocking(accepting_socket_descriptor->is_blocking());
|
accepted_socket_description->set_blocking(accepting_socket_description->is_blocking());
|
||||||
m_fds[accepted_socket_fd].set(move(accepted_socket_descriptor), m_fds[accepting_socket_fd].flags);
|
m_fds[accepted_socket_fd].set(move(accepted_socket_description), m_fds[accepting_socket_fd].flags);
|
||||||
return accepted_socket_fd;
|
return accepted_socket_fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2123,21 +2123,21 @@ int Process::sys$connect(int sockfd, const sockaddr* address, socklen_t address_
|
||||||
int fd = alloc_fd();
|
int fd = alloc_fd();
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return fd;
|
return fd;
|
||||||
auto* descriptor = file_description(sockfd);
|
auto* description = file_description(sockfd);
|
||||||
if (!descriptor)
|
if (!description)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
if (!descriptor->is_socket())
|
if (!description->is_socket())
|
||||||
return -ENOTSOCK;
|
return -ENOTSOCK;
|
||||||
if (descriptor->socket_role() == SocketRole::Connected)
|
if (description->socket_role() == SocketRole::Connected)
|
||||||
return -EISCONN;
|
return -EISCONN;
|
||||||
auto& socket = *descriptor->socket();
|
auto& socket = *description->socket();
|
||||||
descriptor->set_socket_role(SocketRole::Connecting);
|
description->set_socket_role(SocketRole::Connecting);
|
||||||
auto result = socket.connect(*descriptor, address, address_size, descriptor->is_blocking() ? ShouldBlock::Yes : ShouldBlock::No);
|
auto result = socket.connect(*description, address, address_size, description->is_blocking() ? ShouldBlock::Yes : ShouldBlock::No);
|
||||||
if (result.is_error()) {
|
if (result.is_error()) {
|
||||||
descriptor->set_socket_role(SocketRole::None);
|
description->set_socket_role(SocketRole::None);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
descriptor->set_socket_role(SocketRole::Connected);
|
description->set_socket_role(SocketRole::Connected);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2157,14 +2157,14 @@ ssize_t Process::sys$sendto(const Syscall::SC_sendto_params* params)
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
if (addr && !validate_read(addr, addr_length))
|
if (addr && !validate_read(addr, addr_length))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
auto* descriptor = file_description(sockfd);
|
auto* description = file_description(sockfd);
|
||||||
if (!descriptor)
|
if (!description)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
if (!descriptor->is_socket())
|
if (!description->is_socket())
|
||||||
return -ENOTSOCK;
|
return -ENOTSOCK;
|
||||||
auto& socket = *descriptor->socket();
|
auto& socket = *description->socket();
|
||||||
kprintf("sendto %p (%u), flags=%u, addr: %p (%u)\n", data, data_length, flags, addr, addr_length);
|
kprintf("sendto %p (%u), flags=%u, addr: %p (%u)\n", data, data_length, flags, addr, addr_length);
|
||||||
return socket.sendto(*descriptor, data, data_length, flags, addr, addr_length);
|
return socket.sendto(*description, data, data_length, flags, addr, addr_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t Process::sys$recvfrom(const Syscall::SC_recvfrom_params* params)
|
ssize_t Process::sys$recvfrom(const Syscall::SC_recvfrom_params* params)
|
||||||
|
@ -2189,20 +2189,20 @@ ssize_t Process::sys$recvfrom(const Syscall::SC_recvfrom_params* params)
|
||||||
} else if (addr) {
|
} else if (addr) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
auto* descriptor = file_description(sockfd);
|
auto* description = file_description(sockfd);
|
||||||
if (!descriptor)
|
if (!description)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
if (!descriptor->is_socket())
|
if (!description->is_socket())
|
||||||
return -ENOTSOCK;
|
return -ENOTSOCK;
|
||||||
auto& socket = *descriptor->socket();
|
auto& socket = *description->socket();
|
||||||
|
|
||||||
bool original_blocking = descriptor->is_blocking();
|
bool original_blocking = description->is_blocking();
|
||||||
if (flags & MSG_DONTWAIT)
|
if (flags & MSG_DONTWAIT)
|
||||||
descriptor->set_blocking(false);
|
description->set_blocking(false);
|
||||||
|
|
||||||
auto nrecv = socket.recvfrom(*descriptor, buffer, buffer_length, flags, addr, addr_length);
|
auto nrecv = socket.recvfrom(*description, buffer, buffer_length, flags, addr, addr_length);
|
||||||
if (flags & MSG_DONTWAIT)
|
if (flags & MSG_DONTWAIT)
|
||||||
descriptor->set_blocking(original_blocking);
|
description->set_blocking(original_blocking);
|
||||||
|
|
||||||
return nrecv;
|
return nrecv;
|
||||||
}
|
}
|
||||||
|
@ -2218,14 +2218,14 @@ int Process::sys$getsockname(int sockfd, sockaddr* addr, socklen_t* addrlen)
|
||||||
if (!validate_write(addr, *addrlen))
|
if (!validate_write(addr, *addrlen))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
|
|
||||||
auto* descriptor = file_description(sockfd);
|
auto* description = file_description(sockfd);
|
||||||
if (!descriptor)
|
if (!description)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
if (!descriptor->is_socket())
|
if (!description->is_socket())
|
||||||
return -ENOTSOCK;
|
return -ENOTSOCK;
|
||||||
|
|
||||||
auto& socket = *descriptor->socket();
|
auto& socket = *description->socket();
|
||||||
if (!socket.get_local_address(addr, addrlen))
|
if (!socket.get_local_address(addr, addrlen))
|
||||||
return -EINVAL; // FIXME: Should this be another error? I'm not sure.
|
return -EINVAL; // FIXME: Should this be another error? I'm not sure.
|
||||||
|
|
||||||
|
@ -2243,14 +2243,14 @@ int Process::sys$getpeername(int sockfd, sockaddr* addr, socklen_t* addrlen)
|
||||||
if (!validate_write(addr, *addrlen))
|
if (!validate_write(addr, *addrlen))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
|
|
||||||
auto* descriptor = file_description(sockfd);
|
auto* description = file_description(sockfd);
|
||||||
if (!descriptor)
|
if (!description)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
if (!descriptor->is_socket())
|
if (!description->is_socket())
|
||||||
return -ENOTSOCK;
|
return -ENOTSOCK;
|
||||||
|
|
||||||
auto& socket = *descriptor->socket();
|
auto& socket = *description->socket();
|
||||||
|
|
||||||
if (!socket.is_connected())
|
if (!socket.is_connected())
|
||||||
return -ENOTCONN;
|
return -ENOTCONN;
|
||||||
|
@ -2318,12 +2318,12 @@ int Process::sys$getsockopt(const Syscall::SC_getsockopt_params* params)
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
if (!validate_write(value, *value_size))
|
if (!validate_write(value, *value_size))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
auto* descriptor = file_description(sockfd);
|
auto* description = file_description(sockfd);
|
||||||
if (!descriptor)
|
if (!description)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
if (!descriptor->is_socket())
|
if (!description->is_socket())
|
||||||
return -ENOTSOCK;
|
return -ENOTSOCK;
|
||||||
auto& socket = *descriptor->socket();
|
auto& socket = *description->socket();
|
||||||
return socket.getsockopt(level, option, value, value_size);
|
return socket.getsockopt(level, option, value, value_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2339,12 +2339,12 @@ int Process::sys$setsockopt(const Syscall::SC_setsockopt_params* params)
|
||||||
|
|
||||||
if (!validate_read(value, value_size))
|
if (!validate_read(value, value_size))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
auto* descriptor = file_description(sockfd);
|
auto* description = file_description(sockfd);
|
||||||
if (!descriptor)
|
if (!description)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
if (!descriptor->is_socket())
|
if (!description->is_socket())
|
||||||
return -ENOTSOCK;
|
return -ENOTSOCK;
|
||||||
auto& socket = *descriptor->socket();
|
auto& socket = *description->socket();
|
||||||
return socket.setsockopt(level, option, value, value_size);
|
return socket.setsockopt(level, option, value, value_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2682,8 +2682,8 @@ int Process::sys$shm_open(const char* name, int flags, mode_t mode)
|
||||||
auto shm_or_error = SharedMemory::open(String(name), flags, mode);
|
auto shm_or_error = SharedMemory::open(String(name), flags, mode);
|
||||||
if (shm_or_error.is_error())
|
if (shm_or_error.is_error())
|
||||||
return shm_or_error.error();
|
return shm_or_error.error();
|
||||||
auto descriptor = FileDescription::create(shm_or_error.value().ptr());
|
auto description = FileDescription::create(shm_or_error.value().ptr());
|
||||||
m_fds[fd].set(move(descriptor), FD_CLOEXEC);
|
m_fds[fd].set(move(description), FD_CLOEXEC);
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2696,11 +2696,11 @@ int Process::sys$shm_unlink(const char* name)
|
||||||
|
|
||||||
int Process::sys$ftruncate(int fd, off_t length)
|
int Process::sys$ftruncate(int fd, off_t length)
|
||||||
{
|
{
|
||||||
auto* descriptor = file_description(fd);
|
auto* description = file_description(fd);
|
||||||
if (!descriptor)
|
if (!description)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
// FIXME: Check that fd is writable, otherwise EINVAL.
|
// FIXME: Check that fd is writable, otherwise EINVAL.
|
||||||
return descriptor->truncate(length);
|
return description->truncate(length);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Process::sys$systrace(pid_t pid)
|
int Process::sys$systrace(pid_t pid)
|
||||||
|
@ -2714,8 +2714,8 @@ int Process::sys$systrace(pid_t pid)
|
||||||
int fd = alloc_fd();
|
int fd = alloc_fd();
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return fd;
|
return fd;
|
||||||
auto descriptor = FileDescription::create(peer->ensure_tracer());
|
auto description = FileDescription::create(peer->ensure_tracer());
|
||||||
m_fds[fd].set(move(descriptor), 0);
|
m_fds[fd].set(move(description), 0);
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2728,13 +2728,13 @@ ProcessTracer& Process::ensure_tracer()
|
||||||
|
|
||||||
void Process::FileDescriptionAndFlags::clear()
|
void Process::FileDescriptionAndFlags::clear()
|
||||||
{
|
{
|
||||||
descriptor = nullptr;
|
description = nullptr;
|
||||||
flags = 0;
|
flags = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Process::FileDescriptionAndFlags::set(Retained<FileDescription>&& d, dword f)
|
void Process::FileDescriptionAndFlags::set(Retained<FileDescription>&& d, dword f)
|
||||||
{
|
{
|
||||||
descriptor = move(d);
|
description = move(d);
|
||||||
flags = f;
|
flags = f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -305,10 +305,10 @@ private:
|
||||||
Priority m_priority { NormalPriority };
|
Priority m_priority { NormalPriority };
|
||||||
|
|
||||||
struct FileDescriptionAndFlags {
|
struct FileDescriptionAndFlags {
|
||||||
operator bool() const { return !!descriptor; }
|
operator bool() const { return !!description; }
|
||||||
void clear();
|
void clear();
|
||||||
void set(Retained<FileDescription>&& d, dword f = 0);
|
void set(Retained<FileDescription>&& d, dword f = 0);
|
||||||
RetainPtr<FileDescription> descriptor;
|
RetainPtr<FileDescription> description;
|
||||||
dword flags { 0 };
|
dword flags { 0 };
|
||||||
};
|
};
|
||||||
Vector<FileDescriptionAndFlags> m_fds;
|
Vector<FileDescriptionAndFlags> m_fds;
|
||||||
|
|
|
@ -96,34 +96,34 @@ bool Scheduler::pick_next()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (thread.state() == Thread::BlockedRead) {
|
if (thread.state() == Thread::BlockedRead) {
|
||||||
ASSERT(thread.m_blocked_descriptor);
|
ASSERT(thread.m_blocked_description);
|
||||||
// FIXME: Block until the amount of data wanted is available.
|
// FIXME: Block until the amount of data wanted is available.
|
||||||
if (thread.m_blocked_descriptor->can_read())
|
if (thread.m_blocked_description->can_read())
|
||||||
thread.unblock();
|
thread.unblock();
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (thread.state() == Thread::BlockedWrite) {
|
if (thread.state() == Thread::BlockedWrite) {
|
||||||
ASSERT(thread.m_blocked_descriptor != -1);
|
ASSERT(thread.m_blocked_description != -1);
|
||||||
if (thread.m_blocked_descriptor->can_write())
|
if (thread.m_blocked_description->can_write())
|
||||||
thread.unblock();
|
thread.unblock();
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (thread.state() == Thread::BlockedConnect) {
|
if (thread.state() == Thread::BlockedConnect) {
|
||||||
auto& descriptor = *thread.m_blocked_descriptor;
|
auto& description = *thread.m_blocked_description;
|
||||||
auto& socket = *descriptor.socket();
|
auto& socket = *description.socket();
|
||||||
if (socket.is_connected())
|
if (socket.is_connected())
|
||||||
thread.unblock();
|
thread.unblock();
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (thread.state() == Thread::BlockedReceive) {
|
if (thread.state() == Thread::BlockedReceive) {
|
||||||
auto& descriptor = *thread.m_blocked_descriptor;
|
auto& description = *thread.m_blocked_description;
|
||||||
auto& socket = *descriptor.socket();
|
auto& socket = *description.socket();
|
||||||
// FIXME: Block until the amount of data wanted is available.
|
// FIXME: Block until the amount of data wanted is available.
|
||||||
bool timed_out = now_sec > socket.receive_deadline().tv_sec || (now_sec == socket.receive_deadline().tv_sec && now_usec >= socket.receive_deadline().tv_usec);
|
bool timed_out = now_sec > socket.receive_deadline().tv_sec || (now_sec == socket.receive_deadline().tv_sec && now_usec >= socket.receive_deadline().tv_usec);
|
||||||
if (timed_out || descriptor.can_read()) {
|
if (timed_out || description.can_read()) {
|
||||||
thread.unblock();
|
thread.unblock();
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
}
|
}
|
||||||
|
@ -138,13 +138,13 @@ bool Scheduler::pick_next()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int fd : thread.m_select_read_fds) {
|
for (int fd : thread.m_select_read_fds) {
|
||||||
if (process.m_fds[fd].descriptor->can_read()) {
|
if (process.m_fds[fd].description->can_read()) {
|
||||||
thread.unblock();
|
thread.unblock();
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int fd : thread.m_select_write_fds) {
|
for (int fd : thread.m_select_write_fds) {
|
||||||
if (process.m_fds[fd].descriptor->can_write()) {
|
if (process.m_fds[fd].description->can_write()) {
|
||||||
thread.unblock();
|
thread.unblock();
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,9 +96,9 @@ void MasterPTY::close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int MasterPTY::ioctl(FileDescription& descriptor, unsigned request, unsigned arg)
|
int MasterPTY::ioctl(FileDescription& description, unsigned request, unsigned arg)
|
||||||
{
|
{
|
||||||
if (request == TIOCSWINSZ)
|
if (request == TIOCSWINSZ)
|
||||||
return m_slave->ioctl(descriptor, request, arg);
|
return m_slave->ioctl(description, request, arg);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,18 +46,18 @@ bool SlavePTY::can_write(FileDescription&) const
|
||||||
return m_master->can_write_from_slave();
|
return m_master->can_write_from_slave();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SlavePTY::can_read(FileDescription& descriptor) const
|
bool SlavePTY::can_read(FileDescription& description) const
|
||||||
{
|
{
|
||||||
if (m_master->is_closed())
|
if (m_master->is_closed())
|
||||||
return true;
|
return true;
|
||||||
return TTY::can_read(descriptor);
|
return TTY::can_read(description);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t SlavePTY::read(FileDescription& descriptor, byte* buffer, ssize_t size)
|
ssize_t SlavePTY::read(FileDescription& description, byte* buffer, ssize_t size)
|
||||||
{
|
{
|
||||||
if (m_master->is_closed())
|
if (m_master->is_closed())
|
||||||
return 0;
|
return 0;
|
||||||
return TTY::read(descriptor, buffer, size);
|
return TTY::read(description, buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SlavePTY::close()
|
void SlavePTY::close()
|
||||||
|
|
|
@ -99,7 +99,7 @@ Thread::~Thread()
|
||||||
|
|
||||||
void Thread::unblock()
|
void Thread::unblock()
|
||||||
{
|
{
|
||||||
m_blocked_descriptor = nullptr;
|
m_blocked_description = nullptr;
|
||||||
if (current == this) {
|
if (current == this) {
|
||||||
set_state(Thread::Running);
|
set_state(Thread::Running);
|
||||||
return;
|
return;
|
||||||
|
@ -129,9 +129,9 @@ void Thread::block(Thread::State new_state)
|
||||||
process().big_lock().lock();
|
process().big_lock().lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Thread::block(Thread::State new_state, FileDescription& descriptor)
|
void Thread::block(Thread::State new_state, FileDescription& description)
|
||||||
{
|
{
|
||||||
m_blocked_descriptor = &descriptor;
|
m_blocked_description = &description;
|
||||||
block(new_state);
|
block(new_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,7 +192,7 @@ void Thread::finalize()
|
||||||
dbgprintf("Finalizing Thread %u in %s(%u)\n", tid(), m_process.name().characters(), pid());
|
dbgprintf("Finalizing Thread %u in %s(%u)\n", tid(), m_process.name().characters(), pid());
|
||||||
set_state(Thread::State::Dead);
|
set_state(Thread::State::Dead);
|
||||||
|
|
||||||
m_blocked_descriptor = nullptr;
|
m_blocked_description = nullptr;
|
||||||
|
|
||||||
if (this == &m_process.main_thread())
|
if (this == &m_process.main_thread())
|
||||||
m_process.finalize();
|
m_process.finalize();
|
||||||
|
@ -530,13 +530,13 @@ Thread* Thread::clone(Process& process)
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
|
||||||
KResult Thread::wait_for_connect(FileDescription& descriptor)
|
KResult Thread::wait_for_connect(FileDescription& description)
|
||||||
{
|
{
|
||||||
ASSERT(descriptor.is_socket());
|
ASSERT(description.is_socket());
|
||||||
auto& socket = *descriptor.socket();
|
auto& socket = *description.socket();
|
||||||
if (socket.is_connected())
|
if (socket.is_connected())
|
||||||
return KSuccess;
|
return KSuccess;
|
||||||
block(Thread::State::BlockedConnect, descriptor);
|
block(Thread::State::BlockedConnect, description);
|
||||||
Scheduler::yield();
|
Scheduler::yield();
|
||||||
if (!socket.is_connected())
|
if (!socket.is_connected())
|
||||||
return KResult(-ECONNREFUSED);
|
return KResult(-ECONNREFUSED);
|
||||||
|
|
|
@ -179,7 +179,7 @@ private:
|
||||||
RetainPtr<Region> m_kernel_stack_region;
|
RetainPtr<Region> m_kernel_stack_region;
|
||||||
RetainPtr<Region> m_kernel_stack_for_signal_handler_region;
|
RetainPtr<Region> m_kernel_stack_for_signal_handler_region;
|
||||||
pid_t m_waitee_pid { -1 };
|
pid_t m_waitee_pid { -1 };
|
||||||
RetainPtr<FileDescription> m_blocked_descriptor;
|
RetainPtr<FileDescription> m_blocked_description;
|
||||||
timeval m_select_timeout;
|
timeval m_select_timeout;
|
||||||
SignalActionData m_signal_action_data[32];
|
SignalActionData m_signal_action_data[32];
|
||||||
Region* m_signal_stack_user_region { nullptr };
|
Region* m_signal_stack_user_region { nullptr };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue