mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 18:28:12 +00:00
Kernel: Convert process file descriptor table to a SpinlockProtected
Instead of manually locking in the various member functions of Process::OpenFileDescriptions, simply wrap it in a SpinlockProtected.
This commit is contained in:
parent
93e90e16c3
commit
8ebec2938c
30 changed files with 257 additions and 190 deletions
|
@ -41,12 +41,12 @@ ErrorOr<FlatPtr> Process::sys$open(Userspace<const Syscall::SC_open_params*> use
|
|||
|
||||
dbgln_if(IO_DEBUG, "sys$open(dirfd={}, path='{}', options={}, mode={})", dirfd, path->view(), options, mode);
|
||||
|
||||
auto fd_allocation = TRY(m_fds.allocate());
|
||||
auto fd_allocation = TRY(allocate_fd());
|
||||
RefPtr<Custody> base;
|
||||
if (dirfd == AT_FDCWD) {
|
||||
base = current_directory();
|
||||
} else {
|
||||
auto base_description = TRY(fds().open_file_description(dirfd));
|
||||
auto base_description = TRY(open_file_description(dirfd));
|
||||
if (!base_description->is_directory())
|
||||
return ENOTDIR;
|
||||
if (!base_description->custody())
|
||||
|
@ -59,18 +59,20 @@ ErrorOr<FlatPtr> Process::sys$open(Userspace<const Syscall::SC_open_params*> use
|
|||
if (description->inode() && description->inode()->socket())
|
||||
return ENXIO;
|
||||
|
||||
u32 fd_flags = (options & O_CLOEXEC) ? FD_CLOEXEC : 0;
|
||||
m_fds[fd_allocation.fd].set(move(description), fd_flags);
|
||||
return fd_allocation.fd;
|
||||
return m_fds.with([&](auto& fds) -> ErrorOr<FlatPtr> {
|
||||
u32 fd_flags = (options & O_CLOEXEC) ? FD_CLOEXEC : 0;
|
||||
fds[fd_allocation.fd].set(move(description), fd_flags);
|
||||
return fd_allocation.fd;
|
||||
});
|
||||
}
|
||||
|
||||
ErrorOr<FlatPtr> Process::sys$close(int fd)
|
||||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||
TRY(require_promise(Pledge::stdio));
|
||||
auto description = TRY(fds().open_file_description(fd));
|
||||
auto description = TRY(open_file_description(fd));
|
||||
auto result = description->close();
|
||||
m_fds[fd] = {};
|
||||
m_fds.with([fd](auto& fds) { fds[fd] = {}; });
|
||||
if (result.is_error())
|
||||
return result.release_error();
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue