kernel: Make the poll() system call actually work

This commit is contained in:
apio 2023-08-02 17:18:38 +02:00
parent f8cb6e03df
commit df4227eab8
Signed by: apio
GPG Key ID: B8A7D06E42258954
2 changed files with 10 additions and 6 deletions

View File

@ -1,3 +1,4 @@
#include "Log.h"
#include "fs/VFS.h"
#include "memory/MemoryManager.h"
#include "sys/Syscall.h"
@ -24,6 +25,7 @@ Result<u64> sys_poll(Registers* regs, SyscallArgs args)
auto maybe_inode = current->resolve_fd(fd);
if (maybe_inode.has_error())
{
kwarnln("poll: fd %lu (%d) is not valid, storing POLLNVAL", i, fd);
kfds[i].revents |= POLLNVAL;
TRY(inodes.try_append({}));
}
@ -32,7 +34,7 @@ Result<u64> sys_poll(Registers* regs, SyscallArgs args)
}
bool infinite = timeout < 0;
int fds_with_events;
nfds_t fds_with_events;
do {
fds_with_events = 0;
@ -51,7 +53,7 @@ Result<u64> sys_poll(Registers* regs, SyscallArgs args)
if (!fds_with_events && (timeout > 0 || infinite))
{
kernel_sleep(10);
timeout -= (int)current->sleep_ticks_left;
timeout -= (10 - (int)current->sleep_ticks_left);
if (current->interrupted)
{
guard.deactivate();
@ -62,7 +64,9 @@ Result<u64> sys_poll(Registers* regs, SyscallArgs args)
}
continue;
}
} while (false);
break;
} while (1);
MemoryManager::copy_to_user(fds, kfds, nfds * sizeof(pollfd));

View File

@ -5,9 +5,9 @@
#include <bits/fixed-size-types.h>
#define POLLIN 0
#define POLLERR 1
#define POLLNVAL 2
#define POLLIN (1 << 0)
#define POLLERR (1 << 1)
#define POLLNVAL (1 << 2)
typedef __u64_t nfds_t;