mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:17:36 +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
|
@ -13,7 +13,8 @@ ErrorOr<FlatPtr> Process::sys$pipe(int pipefd[2], int flags)
|
|||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||
TRY(require_promise(Pledge::stdio));
|
||||
if (fds().open_count() + 2 > OpenFileDescriptions::max_open())
|
||||
auto open_count = fds().with([](auto& fds) { return fds.open_count(); });
|
||||
if (open_count + 2 > OpenFileDescriptions::max_open())
|
||||
return EMFILE;
|
||||
// Reject flags other than O_CLOEXEC, O_NONBLOCK
|
||||
if ((flags & (O_CLOEXEC | O_NONBLOCK)) != flags)
|
||||
|
@ -22,8 +23,14 @@ ErrorOr<FlatPtr> Process::sys$pipe(int pipefd[2], int flags)
|
|||
u32 fd_flags = (flags & O_CLOEXEC) ? FD_CLOEXEC : 0;
|
||||
auto fifo = TRY(FIFO::try_create(uid()));
|
||||
|
||||
auto reader_fd_allocation = TRY(m_fds.allocate());
|
||||
auto writer_fd_allocation = TRY(m_fds.allocate());
|
||||
ScopedDescriptionAllocation reader_fd_allocation;
|
||||
ScopedDescriptionAllocation writer_fd_allocation;
|
||||
|
||||
TRY(m_fds.with([&](auto& fds) -> ErrorOr<void> {
|
||||
reader_fd_allocation = TRY(fds.allocate());
|
||||
writer_fd_allocation = TRY(fds.allocate());
|
||||
return {};
|
||||
}));
|
||||
|
||||
auto reader_description = TRY(fifo->open_direction(FIFO::Direction::Reader));
|
||||
auto writer_description = TRY(fifo->open_direction(FIFO::Direction::Writer));
|
||||
|
@ -35,8 +42,11 @@ ErrorOr<FlatPtr> Process::sys$pipe(int pipefd[2], int flags)
|
|||
writer_description->set_blocking(false);
|
||||
}
|
||||
|
||||
m_fds[reader_fd_allocation.fd].set(move(reader_description), fd_flags);
|
||||
m_fds[writer_fd_allocation.fd].set(move(writer_description), fd_flags);
|
||||
TRY(m_fds.with([&](auto& fds) -> ErrorOr<void> {
|
||||
fds[reader_fd_allocation.fd].set(move(reader_description), fd_flags);
|
||||
fds[writer_fd_allocation.fd].set(move(writer_description), fd_flags);
|
||||
return {};
|
||||
}));
|
||||
|
||||
TRY(copy_to_user(&pipefd[0], &reader_fd_allocation.fd));
|
||||
TRY(copy_to_user(&pipefd[1], &writer_fd_allocation.fd));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue