1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 08:48:11 +00:00

Kernel: Make file description lookup return KResultOr

Instead of checking it at every call site (to generate EBADF), we make
file_description(fd) return a KResultOr<NonnullRefPtr<FileDescription>>.

This allows us to wrap all the calls in TRY(). :^)

The only place that got a little bit messier from this is sys$mount(),
and there's a whole bunch of things there in need of cleanup.
This commit is contained in:
Andreas Kling 2021-09-05 18:34:28 +02:00
parent 2d2ea05c97
commit a9204510a4
24 changed files with 62 additions and 155 deletions

View file

@ -452,14 +452,17 @@ Process::FileDescriptionAndFlags& Process::FileDescriptions::at(size_t i)
return m_fds_metadatas[i];
}
RefPtr<FileDescription> Process::FileDescriptions::file_description(int fd) const
KResultOr<NonnullRefPtr<FileDescription>> Process::FileDescriptions::file_description(int fd) const
{
SpinlockLocker lock(m_fds_lock);
if (fd < 0)
return nullptr;
if (static_cast<size_t>(fd) < m_fds_metadatas.size())
return m_fds_metadatas[fd].description();
return nullptr;
return EBADF;
if (static_cast<size_t>(fd) >= m_fds_metadatas.size())
return EBADF;
RefPtr description = m_fds_metadatas[fd].description();
if (!description)
return EBADF;
return description.release_nonnull();
}
void Process::FileDescriptions::enumerate(Function<void(const FileDescriptionAndFlags&)> callback) const