mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 16:18:12 +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:
parent
2d2ea05c97
commit
a9204510a4
24 changed files with 62 additions and 155 deletions
|
@ -73,12 +73,8 @@ KResultOr<FlatPtr> Process::sys$select(Userspace<const Syscall::SC_select_params
|
|||
if (block_flags == BlockFlags::None)
|
||||
continue;
|
||||
|
||||
auto description = fds().file_description(fd);
|
||||
if (!description) {
|
||||
dbgln("sys$select: Bad fd number {}", fd);
|
||||
return EBADF;
|
||||
}
|
||||
if (!fds_info.try_append({ description.release_nonnull(), block_flags }))
|
||||
auto description = TRY(fds().file_description(fd));
|
||||
if (!fds_info.try_append({ move(description), block_flags }))
|
||||
return ENOMEM;
|
||||
if (!selected_fds.try_append(fd))
|
||||
return ENOMEM;
|
||||
|
@ -162,11 +158,7 @@ KResultOr<FlatPtr> Process::sys$poll(Userspace<const Syscall::SC_poll_params*> u
|
|||
Thread::SelectBlocker::FDVector fds_info;
|
||||
for (size_t i = 0; i < params.nfds; i++) {
|
||||
auto& pfd = fds_copy[i];
|
||||
auto description = fds().file_description(pfd.fd);
|
||||
if (!description) {
|
||||
dbgln("sys$poll: Bad fd number {}", pfd.fd);
|
||||
return EBADF;
|
||||
}
|
||||
auto description = TRY(fds().file_description(pfd.fd));
|
||||
BlockFlags block_flags = BlockFlags::Exception; // always want POLLERR, POLLHUP, POLLNVAL
|
||||
if (pfd.events & POLLIN)
|
||||
block_flags |= BlockFlags::Read;
|
||||
|
@ -174,7 +166,7 @@ KResultOr<FlatPtr> Process::sys$poll(Userspace<const Syscall::SC_poll_params*> u
|
|||
block_flags |= BlockFlags::Write;
|
||||
if (pfd.events & POLLPRI)
|
||||
block_flags |= BlockFlags::ReadPriority;
|
||||
if (!fds_info.try_append({ description.release_nonnull(), block_flags }))
|
||||
if (!fds_info.try_append({ move(description), block_flags }))
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue