kernel: Make the poll() system call actually work
This commit is contained in:
parent
f8cb6e03df
commit
df4227eab8
@ -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));
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user