kernel: Store FD_CLOEXEC in the file descriptor itself
All checks were successful
continuous-integration/drone/pr Build is passing
All checks were successful
continuous-integration/drone/pr Build is passing
Closes #39.
This commit is contained in:
parent
72c94d1e57
commit
3021fffb07
@ -100,7 +100,7 @@ Result<u64> sys_execve(Registers* regs, SyscallArgs args)
|
||||
{
|
||||
auto& descriptor = current->fd_table[i];
|
||||
if (!descriptor.has_value()) continue;
|
||||
if (descriptor->description->flags & O_CLOEXEC) { descriptor = {}; }
|
||||
if (descriptor->flags & O_CLOEXEC) { descriptor = {}; }
|
||||
}
|
||||
|
||||
if (VFS::is_setuid(inode)) current->auth.euid = current->auth.suid = inode->metadata().uid;
|
||||
|
@ -124,28 +124,28 @@ Result<u64> sys_fcntl(Registers*, SyscallArgs args)
|
||||
|
||||
current->fd_table[new_fd] = descriptor;
|
||||
|
||||
if (is_cloexec) current->fd_table[new_fd]->flags() |= O_CLOEXEC;
|
||||
if (is_cloexec) current->fd_table[new_fd]->flags |= O_CLOEXEC;
|
||||
else
|
||||
current->fd_table[new_fd]->flags() &= ~O_CLOEXEC;
|
||||
current->fd_table[new_fd]->flags &= ~O_CLOEXEC;
|
||||
|
||||
return (u64)new_fd;
|
||||
}
|
||||
case F_GETFD: return (u64) !!(descriptor.flags() & O_CLOEXEC);
|
||||
case F_GETFD: return (u64) !!(descriptor.flags & O_CLOEXEC);
|
||||
case F_SETFD: {
|
||||
int arg = (int)args[2];
|
||||
if (arg == FD_CLOEXEC) descriptor.flags() |= O_CLOEXEC;
|
||||
if (arg == FD_CLOEXEC) descriptor.flags |= O_CLOEXEC;
|
||||
else
|
||||
descriptor.flags() &= ~O_CLOEXEC;
|
||||
descriptor.flags &= ~O_CLOEXEC;
|
||||
return 0;
|
||||
}
|
||||
case F_GETFL: return (u64)(descriptor.flags() & ~O_CLOEXEC);
|
||||
case F_GETFL: return (u64)descriptor.status_flags();
|
||||
case F_SETFL: {
|
||||
int arg = (int)args[2];
|
||||
|
||||
descriptor.flags() &= ~(O_APPEND | O_NONBLOCK);
|
||||
descriptor.status_flags() &= ~(O_APPEND | O_NONBLOCK);
|
||||
arg &= (O_APPEND | O_NONBLOCK);
|
||||
|
||||
descriptor.flags() |= arg;
|
||||
descriptor.status_flags() |= arg;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -189,7 +189,7 @@ Result<u64> sys_dup2(Registers*, SyscallArgs args)
|
||||
if (newfd == oldfd) return (u64)newfd;
|
||||
|
||||
current->fd_table[newfd] = descriptor;
|
||||
current->fd_table[newfd]->flags() &= ~O_CLOEXEC;
|
||||
current->fd_table[newfd]->flags &= ~O_CLOEXEC;
|
||||
|
||||
return (u64)newfd;
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include <bits/open-flags.h>
|
||||
|
||||
// These flags are needed after open(), the rest only affect open().
|
||||
constexpr int FLAGS_TO_KEEP = O_RDWR | O_APPEND | O_NONBLOCK | O_CLOEXEC;
|
||||
constexpr int FLAGS_TO_KEEP = O_RDWR | O_APPEND | O_NONBLOCK;
|
||||
|
||||
Result<u64> sys_openat(Registers*, SyscallArgs args)
|
||||
{
|
||||
@ -87,7 +87,8 @@ Result<u64> sys_openat(Registers*, SyscallArgs args)
|
||||
kdbgln("openat: opening file %s from dirfd %d, flags %d, mode %#o = fd %d", path.chars(), dirfd, flags, mode, fd);
|
||||
#endif
|
||||
|
||||
current->fd_table[fd] = FileDescriptor { TRY(make_shared<OpenFileDescription>(inode, flags & FLAGS_TO_KEEP)), 0 };
|
||||
current->fd_table[fd] =
|
||||
FileDescriptor { TRY(make_shared<OpenFileDescription>(inode, flags & FLAGS_TO_KEEP)), 0, flags & O_CLOEXEC };
|
||||
|
||||
return (u64)fd;
|
||||
}
|
||||
|
@ -41,6 +41,7 @@ struct FileDescriptor
|
||||
{
|
||||
SharedPtr<OpenFileDescription> description;
|
||||
usize offset { 0 };
|
||||
int flags { 0 };
|
||||
|
||||
bool should_append();
|
||||
bool should_block();
|
||||
@ -52,7 +53,7 @@ struct FileDescriptor
|
||||
return description->inode;
|
||||
}
|
||||
|
||||
int& flags()
|
||||
int& status_flags()
|
||||
{
|
||||
return description->flags;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user